# HG changeset patch # User Gilles Duboscq # Date 1307694454 -7200 # Node ID 7300d86deac27e94002117ed0ba06b112ab1fac5 # Parent 5f1778eb38543ca7b7ae3e2bb97058b1f2ab739b# Parent 1e13559b112db496b8a3013b8b38988d9687c6ce Merge diff -r 1e13559b112d -r 7300d86deac2 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScan.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScan.java Thu Jun 09 20:25:38 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScan.java Fri Jun 10 10:27:34 2011 +0200 @@ -2122,7 +2122,7 @@ } if (compilation.compiler.isObserved()) { - compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, label, compilation.graph, hirValid, true)); + compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, label, /*compilation.graph*/ null, hirValid, true)); } } diff -r 1e13559b112d -r 7300d86deac2 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/debug/IdealGraphPrinterObserver.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/debug/IdealGraphPrinterObserver.java Thu Jun 09 20:25:38 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/debug/IdealGraphPrinterObserver.java Fri Jun 10 10:27:34 2011 +0200 @@ -140,7 +140,7 @@ @Override public void compilationEvent(CompilationEvent event) { - if (printer != null && event.getGraph() != null) { + if (printer != null && event.getGraph() != null && event.isHIRValid()) { Graph graph = event.getGraph(); printer.print(graph, event.getLabel(), true); } diff -r 1e13559b112d -r 7300d86deac2 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java Thu Jun 09 20:25:38 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java Fri Jun 10 10:27:34 2011 +0200 @@ -70,7 +70,7 @@ public void build() { new GraphBuilderPhase(compilation, compilation.method, false, false).apply(compilation.graph); printGraph("After GraphBuilding", compilation.graph); - new DuplicationPhase().apply(compilation.graph); + //new DuplicationPhase().apply(compilation.graph); new DeadCodeEliminationPhase().apply(compilation.graph); printGraph("After DeadCodeElimination", compilation.graph); diff -r 1e13559b112d -r 7300d86deac2 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Negate.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Negate.java Thu Jun 09 20:25:38 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Negate.java Fri Jun 10 10:27:34 2011 +0200 @@ -23,6 +23,7 @@ package com.oracle.max.graal.compiler.ir; import com.oracle.max.graal.compiler.debug.*; +import com.oracle.max.graal.compiler.phases.CanonicalizerPhase.*; import com.oracle.max.graal.compiler.util.*; import com.oracle.max.graal.graph.*; import com.sun.cri.bytecode.*; @@ -32,6 +33,7 @@ * The {@code NegateOp} instruction negates its operand. */ public final class Negate extends FloatingNode { + private static final NegateCanonicalizerOp CANONICALIZER = new NegateCanonicalizerOp(); private static final int INPUT_COUNT = 2; private static final int INPUT_X = 0; @@ -103,4 +105,31 @@ Negate x = new Negate(kind, into); return x; } + + @SuppressWarnings("unchecked") + @Override + public T lookup(Class clazz) { + if (clazz == CanonicalizerOp.class) { + return (T) CANONICALIZER; + } + return super.lookup(clazz); + } + + private static class NegateCanonicalizerOp implements CanonicalizerOp { + @Override + public Node canonical(Node node) { + Negate negate = (Negate) node; + Value x = negate.x(); + Graph graph = negate.graph(); + if (x.isConstant()) { + switch (x.kind) { + case Int: return Constant.forInt(-x.asConstant().asInt(), graph); + case Long: return Constant.forLong(-x.asConstant().asLong(), graph); + case Float: return Constant.forFloat(-x.asConstant().asFloat(), graph); + case Double: return Constant.forDouble(-x.asConstant().asDouble(), graph); + } + } + return negate; + } + } } diff -r 1e13559b112d -r 7300d86deac2 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/CanonicalizerPhase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/CanonicalizerPhase.java Thu Jun 09 20:25:38 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/CanonicalizerPhase.java Fri Jun 10 10:27:34 2011 +0200 @@ -22,46 +22,30 @@ */ package com.oracle.max.graal.compiler.phases; -import java.util.*; - import com.oracle.max.graal.compiler.*; import com.oracle.max.graal.graph.*; +/* TODO (gd) Canonicalize : + * - Compare & If + * - InstanceOf (if it's not transformed into a Condition for Compare) + * - Switches + */ public class CanonicalizerPhase extends Phase { - + private static final int MAX_ITERATION_PER_NODE = 10; @Override protected void run(Graph graph) { - NodeBitMap visited = graph.createNodeBitMap(); - List nodes = new ArrayList(graph.getNodes()); - for (Node n : nodes) { - if (n == null) { - continue; - } - if (!n.isDeleted() && !visited.isMarked(n)) { - this.canonicalize(n, visited); - } - } - } - - private void canonicalize(Node n, NodeBitMap visited) { - visited.mark(n); - for (Node input : n.inputs()) { - if (input == null) { - continue; - } - if (!visited.isNew(input) && !visited.isMarked(input)) { - canonicalize(input, visited); - } - } - - CanonicalizerOp op = n.lookup(CanonicalizerOp.class); - if (op != null) { - Node canonical = op.canonical(n); - if (canonical != n) { - n.replace(canonical); - //System.out.println("-->" + n + " canonicalized to " + canonical); - GraalMetrics.NodesCanonicalized++; + NodeWorkList nodeWorkList = graph.createNodeWorkList(true, MAX_ITERATION_PER_NODE); + for (Node node : nodeWorkList) { + CanonicalizerOp op = node.lookup(CanonicalizerOp.class); + if (op != null) { + Node canonical = op.canonical(node); + if (canonical != node) { + node.replace(canonical); + nodeWorkList.replaced(canonical, node, EdgeType.USAGES); + //System.out.println("-->" + n + " canonicalized to " + canonical); + GraalMetrics.NodesCanonicalized++; + } } } } diff -r 1e13559b112d -r 7300d86deac2 graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Graph.java --- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Graph.java Thu Jun 09 20:25:38 2011 +0200 +++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Graph.java Fri Jun 10 10:27:34 2011 +0200 @@ -84,10 +84,12 @@ } while (nextNode == null || !type.isInstance(nextNode)); } + @Override public boolean hasNext() { return nextNode != null; } + @Override @SuppressWarnings("unchecked") public T next() { try { @@ -97,6 +99,7 @@ } } + @Override public void remove() { throw new UnsupportedOperationException(); } @@ -104,6 +107,7 @@ public Iterable getNodes(final Class type) { return new Iterable() { + @Override public Iterator iterator() { return new TypedNodeIterator(type, nodes.iterator()); } @@ -137,6 +141,14 @@ return new NodeFlood(this); } + public NodeWorkList createNodeWorkList() { + return new NodeWorkList(this); + } + + public NodeWorkList createNodeWorkList(boolean fill, int iterationLimitPerNode) { + return new NodeWorkList(this, fill, iterationLimitPerNode); + } + public Map addDuplicate(Collection nodes, Map replacements) { Map newNodes = new HashMap(); // create node duplicates diff -r 1e13559b112d -r 7300d86deac2 graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeBitMap.java --- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeBitMap.java Thu Jun 09 20:25:38 2011 +0200 +++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeBitMap.java Fri Jun 10 10:27:34 2011 +0200 @@ -66,6 +66,10 @@ bitMap.clear(node.id()); } + public void grow(Node node) { + bitMap.grow(node.id() + 1); + } + private void check(Node node) { assert node.graph == graph : "this node is not part of the graph"; assert !isNew(node) : "this node (" + node.id() + ") was added to the graph after creating the node bitmap (" + bitMap.length() + ")";