# HG changeset patch # User Lukas Stadler # Date 1307548216 -7200 # Node ID 81dab15b45e5c4f228f2870621d2fd0284fb1011 # Parent 2acbbf75c9518e47b7da2d393539ccd07dc835d2 fixes to Phi.removeInput and DCE diff -r 2acbbf75c951 -r 81dab15b45e5 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompilation.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompilation.java Wed Jun 08 15:55:42 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompilation.java Wed Jun 08 17:50:16 2011 +0200 @@ -214,7 +214,11 @@ if (GraalOptions.BailoutOnException) { return new CiResult(null, new CiBailout("Exception while compiling: " + method, t), stats); } else { - throw new RuntimeException(t); + if (t instanceof RuntimeException) { + throw (RuntimeException) t; + } else { + throw new RuntimeException(t); + } } } finally { if (compiler.isObserved()) { diff -r 2acbbf75c951 -r 81dab15b45e5 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 Wed Jun 08 15:55:42 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScan.java Wed Jun 08 17:50:16 2011 +0200 @@ -834,11 +834,11 @@ if (instr instanceof Phi) { Phi phi = (Phi) instr; - TTY.println("phi block begin: " + phi.block()); - TTY.println("pred count on blockbegin: " + phi.block().predecessors().size()); + TTY.println("phi block begin: " + phi.merge()); + TTY.println("pred count on blockbegin: " + phi.merge().predecessors().size()); TTY.println("phi values: " + phi.valueCount()); TTY.println("phi block preds:"); - for (Node n : phi.block().predecessors()) { + for (Node n : phi.merge().predecessors()) { TTY.println(n.toString()); } } diff -r 2acbbf75c951 -r 81dab15b45e5 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/debug/IdealGraphPrinter.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/debug/IdealGraphPrinter.java Wed Jun 08 15:55:42 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/debug/IdealGraphPrinter.java Wed Jun 08 17:50:16 2011 +0200 @@ -135,8 +135,8 @@ for (Block block : schedule.getBlocks()) { printBlock(graph, block); } - printNoBlock(); } + printNoBlock(); stream.println(" "); stream.println(" "); @@ -163,14 +163,12 @@ } stream.printf("

%s

%n", escape(name)); } - if (nodeToBlock != null) { - Block block = nodeToBlock.get(node); - if (block != null) { - stream.printf("

%d

%n", block.blockID()); - } else { - stream.printf("

noBlock

%n"); - noBlockNodes.add(node); - } + Block block = nodeToBlock == null ? null : nodeToBlock.get(node); + if (block != null) { + stream.printf("

%d

%n", block.blockID()); + } else { + stream.printf("

noBlock

%n"); + noBlockNodes.add(node); } for (Entry entry : props.entrySet()) { String key = entry.getKey().toString(); @@ -220,35 +218,37 @@ stream.printf(" %n"); ArrayList nodes = new ArrayList(block.getInstructions()); - // if this is the first block: add all locals to this block - if (nodes.get(0) == graph.start()) { - for (Node node : graph.getNodes()) { - if (node instanceof Local) { - nodes.add(node); - } - } - } - // add all framestates and phis to their blocks - for (Node node : block.getInstructions()) { - if (node instanceof Instruction && ((Instruction) node).stateAfter() != null) { - nodes.add(((Instruction) node).stateAfter()); - } - if (node instanceof Merge) { - Merge merge = (Merge) node; - if (merge.stateBefore() != null) { - nodes.add(merge.stateBefore()); - } - for (Node usage : merge.usages()) { - if (usage instanceof Phi) { - nodes.add(usage); + if (nodes.size() > 0) { + // if this is the first block: add all locals to this block + if (nodes.get(0) == graph.start()) { + for (Node node : graph.getNodes()) { + if (node instanceof Local) { + nodes.add(node); } } } - } + // add all framestates and phis to their blocks + for (Node node : block.getInstructions()) { + if (node instanceof Instruction && ((Instruction) node).stateAfter() != null) { + nodes.add(((Instruction) node).stateAfter()); + } + if (node instanceof Merge) { + Merge merge = (Merge) node; + if (merge.stateBefore() != null) { + nodes.add(merge.stateBefore()); + } + for (Node usage : merge.usages()) { + if (usage instanceof Phi) { + nodes.add(usage); + } + } + } + } - for (Node node : nodes) { - if (!omittedClasses.contains(node.getClass())) { - stream.printf(" %n", node.id()); + for (Node node : nodes) { + if (!omittedClasses.contains(node.getClass())) { + stream.printf(" %n", node.id()); + } } } stream.printf(" %n"); diff -r 2acbbf75c951 -r 81dab15b45e5 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 Wed Jun 08 15:55:42 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java Wed Jun 08 17:50:16 2011 +0200 @@ -73,8 +73,10 @@ } new GraphBuilderPhase(compilation, compilation.method, true).apply(compilation.graph); - new DuplicationPhase().apply(compilation.graph); + verifyAndPrint("After graph building"); +// new DuplicationPhase().apply(compilation.graph); new DeadCodeEliminationPhase().apply(compilation.graph); + verifyAndPrint("After dead code elimination"); if (GraalOptions.Inline) { new InliningPhase(compilation, this, GraalOptions.TraceInlining).apply(compilation.graph); @@ -89,6 +91,7 @@ if (GraalOptions.OptCanonicalizer) { new CanonicalizerPhase().apply(graph); + new DeadCodeEliminationPhase().apply(compilation.graph); verifyAndPrint("After Canonicalization"); } diff -r 2acbbf75c951 -r 81dab15b45e5 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Merge.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Merge.java Wed Jun 08 15:55:42 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Merge.java Wed Jun 08 17:50:16 2011 +0200 @@ -211,14 +211,14 @@ } /** - * Determines if a given instruction is a phi whose {@linkplain Phi#block() join block} is a given block. + * Determines if a given instruction is a phi whose {@linkplain Phi#merge() join block} is a given block. * * @param value the instruction to test * @param block the block that may be the join block of {@code value} if {@code value} is a phi * @return {@code true} if {@code value} is a phi and its join block is {@code block} */ private boolean isPhiAtBlock(Value value) { - return value instanceof Phi && ((Phi) value).block() == this; + return value instanceof Phi && ((Phi) value).merge() == this; } @@ -229,7 +229,7 @@ * @param index the index of the value in the frame state * @param value the frame state value * @param block if {@code value} is a phi, then its inputs are formatted if {@code block} is its - * {@linkplain Phi#block() join point} + * {@linkplain Phi#merge() join point} * @return the instruction representation as a string */ public String stateString(int index, Value value) { @@ -238,7 +238,7 @@ if (value instanceof Phi) { Phi phi = (Phi) value; // print phi operands - if (phi.block() == this) { + if (phi.merge() == this) { sb.append(" ["); for (int j = 0; j < phi.valueCount(); j++) { sb.append(' '); diff -r 2acbbf75c951 -r 81dab15b45e5 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Phi.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Phi.java Wed Jun 08 15:55:42 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Phi.java Wed Jun 08 17:50:16 2011 +0200 @@ -35,7 +35,7 @@ private static final int DEFAULT_MAX_VALUES = 2; private static final int INPUT_COUNT = 1; - private static final int INPUT_BLOCK = 0; + private static final int INPUT_MERGE = 0; private final int maxValues; @@ -55,31 +55,31 @@ } /** - * The join block for this phi. + * The merge node for this phi. */ - public Merge block() { - return (Merge) inputs().get(super.inputCount() + INPUT_BLOCK); + public Merge merge() { + return (Merge) inputs().get(super.inputCount() + INPUT_MERGE); } - public Value setBlock(Value n) { - return (Merge) inputs().set(super.inputCount() + INPUT_BLOCK, n); + public Value setMerge(Value n) { + return (Merge) inputs().set(super.inputCount() + INPUT_MERGE, n); } /** * Create a new Phi for the specified join block and local variable (or operand stack) slot. * @param kind the type of the variable - * @param block the join point + * @param merge the join point * @param graph */ - public Phi(CiKind kind, Merge block, Graph graph) { - this(kind, block, DEFAULT_MAX_VALUES, graph); + public Phi(CiKind kind, Merge merge, Graph graph) { + this(kind, merge, DEFAULT_MAX_VALUES, graph); } - public Phi(CiKind kind, Merge block, int maxValues, Graph graph) { + public Phi(CiKind kind, Merge merge, int maxValues, Graph graph) { super(kind, INPUT_COUNT + maxValues, SUCCESSOR_COUNT, graph); this.maxValues = maxValues; usedInputCount = 0; - setBlock(block); + setMerge(merge); } /** @@ -148,7 +148,7 @@ assert !this.isDeleted() && !y.isDeleted(); Phi phi = this; if (usedInputCount == maxValues) { - phi = new Phi(kind, block(), maxValues * 2, graph()); + phi = new Phi(kind, merge(), maxValues * 2, graph()); for (int i = 0; i < valueCount(); ++i) { phi.addInput(valueAt(i)); } @@ -166,6 +166,7 @@ for (int i = index + 1; i < valueCount(); ++i) { setValueAt(i - 1, valueAt(i)); } + setValueAt(valueCount() - 1, Node.Null); usedInputCount--; } diff -r 2acbbf75c951 -r 81dab15b45e5 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/DeadCodeEliminationPhase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/DeadCodeEliminationPhase.java Wed Jun 08 15:55:42 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/DeadCodeEliminationPhase.java Wed Jun 08 17:50:16 2011 +0200 @@ -30,14 +30,12 @@ public class DeadCodeEliminationPhase extends Phase { - private NodeBitMap alive; private NodeFlood flood; private Graph graph; @Override protected void run(Graph graph) { this.graph = graph; - this.alive = graph.createNodeBitMap(); this.flood = graph.createNodeFlood(); flood.add(graph.start()); @@ -100,13 +98,17 @@ for (Node node : graph.getNodes()) { if (node != Node.Null && flood.isMarked(node)) { for (Node input : node.inputs()) { - flood.add(input); + if (!isCFG(input)) { + flood.add(input); + } } } } for (Node current : flood) { for (Node input : current.inputs()) { - flood.add(input); + if (!isCFG(input)) { + flood.add(input); + } } } } diff -r 2acbbf75c951 -r 81dab15b45e5 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java Wed Jun 08 15:55:42 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java Wed Jun 08 17:50:16 2011 +0200 @@ -109,9 +109,10 @@ methodCount.put(method, methodCount.get(method) + 1); } } + ir.verifyAndPrint("After inlining iteration"); DeadCodeEliminationPhase dce = new DeadCodeEliminationPhase(); dce.apply(graph); - ir.verifyAndPrint("After inlining iteration"); + ir.verifyAndPrint("After inlining iteration DCE"); if (inliningSize > GraalOptions.MaximumInstructionCount) { if (trace) { @@ -199,6 +200,8 @@ parameters[0] = invoke.argument(0); } + invoke.inputs().clearAll(); + HashMap replacements = new HashMap(); ArrayList nodes = new ArrayList(); ArrayList frameStates = new ArrayList(); @@ -271,30 +274,17 @@ returnDuplicate.delete(); } -// if (invoke.next() instanceof Merge) { -// ((Merge) invoke.next()).removePhiPredecessor(invoke); -// } -// invoke.successors().clearAll(); - invoke.inputs().clearAll(); - invoke.setExceptionEdge(null); -// invoke.delete(); - - if (exceptionEdge != null) { if (unwindNode != null) { assert unwindNode.predecessors().size() == 1; assert exceptionEdge.successors().size() == 1; ExceptionObject obj = (ExceptionObject) exceptionEdge; + Unwind unwindDuplicate = (Unwind) duplicates.get(unwindNode); List usages = new ArrayList(obj.usages()); for (Node usage : usages) { - if (replacements.containsKey(unwindNode.exception())) { - usage.inputs().replace(obj, replacements.get(unwindNode.exception())); - } else { - usage.inputs().replace(obj, duplicates.get(unwindNode.exception())); - } + usage.inputs().replace(obj, unwindDuplicate.exception()); } - Node unwindDuplicate = duplicates.get(unwindNode); unwindDuplicate.inputs().clearAll(); assert unwindDuplicate.predecessors().size() == 1; @@ -303,9 +293,7 @@ unwindPred.successors().setAndClear(index, obj, 0); obj.inputs().clearAll(); - obj.delete(); unwindDuplicate.delete(); - } } diff -r 2acbbf75c951 -r 81dab15b45e5 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/schedule/Schedule.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/schedule/Schedule.java Wed Jun 08 15:55:42 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/schedule/Schedule.java Wed Jun 08 17:50:16 2011 +0200 @@ -215,9 +215,9 @@ for (Node usage : n.usages()) { if (usage instanceof Phi) { Phi phi = (Phi) usage; - Merge merge = phi.block(); + Merge merge = phi.merge(); Block mergeBlock = nodeToBlock.get(merge); - assert mergeBlock != null; + assert mergeBlock != null : "no block for merge " + merge.id(); for (int i = 0; i < phi.valueCount(); ++i) { if (phi.valueAt(i) == n) { if (mergeBlock.getPredecessors().size() == 0) { diff -r 2acbbf75c951 -r 81dab15b45e5 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/value/FrameState.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/value/FrameState.java Wed Jun 08 15:55:42 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/value/FrameState.java Wed Jun 08 17:50:16 2011 +0200 @@ -287,7 +287,7 @@ if (p != null) { if (p instanceof Phi) { Phi phi = (Phi) p; - if (phi.block() == block) { + if (phi.merge() == block) { return phi; } } @@ -307,7 +307,7 @@ Value p = localAt(i); if (p instanceof Phi) { Phi phi = (Phi) p; - if (phi.block() == block) { + if (phi.merge() == block) { return phi; } } @@ -357,11 +357,11 @@ Value x = valueAt(i); if (x != null) { Value y = other.valueAt(i); - if (x != y || ((x instanceof Phi) && ((Phi) x).block() == block)) { + if (x != y || ((x instanceof Phi) && ((Phi) x).merge() == block)) { if (typeMismatch(x, y)) { if (x instanceof Phi) { Phi phi = (Phi) x; - if (phi.block() == block) { + if (phi.merge() == block) { phi.makeDead(); } }