# HG changeset patch # User Lukas Stadler # Date 1329408512 -3600 # Node ID 97d11635f2bfb26e351ab24f8f2bc521fb397326 # Parent 6a44a26ed9e691f6625ae7e0e5d5a767057c10ab evacuate guards when deleting control splits diff -r 6a44a26ed9e6 -r 97d11635f2bf graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/BeginNode.java --- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/BeginNode.java Tue Feb 14 18:00:32 2012 -0800 +++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/BeginNode.java Thu Feb 16 17:08:32 2012 +0100 @@ -25,10 +25,11 @@ import java.util.*; import com.oracle.max.graal.graph.*; +import com.oracle.max.graal.graph.iterators.*; import com.oracle.max.graal.nodes.spi.*; import com.oracle.max.graal.nodes.type.*; -public class BeginNode extends AbstractStateSplit implements LIRLowerable, Simplifiable { +public class BeginNode extends AbstractStateSplit implements LIRLowerable, Simplifiable, Node.IterableNodeType { public BeginNode() { super(StampFactory.illegal()); } @@ -58,15 +59,28 @@ // This begin node is necessary. } else { // This begin node can be removed and all guards moved up to the preceding begin node. - Node prevBegin = prev; + if (!usages().isEmpty()) { + Node prevBegin = prev; + while (!(prevBegin instanceof BeginNode)) { + prevBegin = prevBegin.predecessor(); + } + for (Node usage : usages()) { + tool.addToWorkList(usage); + } + replaceAtUsages(prevBegin); + } + ((StructuredGraph) graph()).removeFixed(this); + } + } + + public void evacuateGuards() { + if (!usages().isEmpty()) { + Node prevBegin = predecessor(); + assert prevBegin != null; while (!(prevBegin instanceof BeginNode)) { prevBegin = prevBegin.predecessor(); } - for (Node usage : usages()) { - tool.addToWorkList(usage); - } replaceAtUsages(prevBegin); - ((StructuredGraph) graph()).removeFixed(this); } } @@ -80,4 +94,8 @@ public void generate(LIRGeneratorTool gen) { // nop } + + public NodeIterable guards() { + return usages().filter(GuardNode.class); + } } diff -r 6a44a26ed9e6 -r 97d11635f2bf graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/StructuredGraph.java --- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/StructuredGraph.java Tue Feb 14 18:00:32 2012 -0800 +++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/StructuredGraph.java Thu Feb 16 17:08:32 2012 +0100 @@ -194,6 +194,7 @@ assert node.usages().isEmpty(); assert survivingSuccessor >= 0 && survivingSuccessor < node.blockSuccessorCount() : "invalid surviving successor " + survivingSuccessor + " for " + node; BeginNode begin = node.blockSuccessor(survivingSuccessor); + begin.evacuateGuards(); FixedNode next = begin.next(); begin.setNext(null); for (int i = 0; i < node.blockSuccessorCount(); i++) { @@ -209,6 +210,7 @@ assert node.usages().isEmpty(); assert survivingSuccessor >= 0 && survivingSuccessor < node.blockSuccessorCount() : "invalid surviving successor " + survivingSuccessor + " for " + node; BeginNode begin = node.blockSuccessor(survivingSuccessor); + begin.evacuateGuards(); FixedNode next = begin.next(); begin.setNext(null); for (int i = 0; i < node.blockSuccessorCount(); i++) { @@ -241,6 +243,7 @@ assert node != null && replacement != null && node.isAlive() && replacement.isAlive() : "cannot replace " + node + " with " + replacement; assert survivingSuccessor >= 0 && survivingSuccessor < node.blockSuccessorCount() : "invalid surviving successor " + survivingSuccessor + " for " + node; BeginNode begin = node.blockSuccessor(survivingSuccessor); + begin.evacuateGuards(); FixedNode next = begin.next(); begin.setNext(null); for (int i = 0; i < node.blockSuccessorCount(); i++) { @@ -255,6 +258,7 @@ assert node != null && replacement != null && node.isAlive() && replacement.isAlive() : "cannot replace " + node + " with " + replacement; assert survivingSuccessor >= 0 && survivingSuccessor < node.blockSuccessorCount() : "invalid surviving successor " + survivingSuccessor + " for " + node; BeginNode begin = node.blockSuccessor(survivingSuccessor); + begin.evacuateGuards(); FixedNode next = begin.next(); begin.setNext(null); for (int i = 0; i < node.blockSuccessorCount(); i++) {