# HG changeset patch # User Doug Simon # Date 1362747281 -3600 # Node ID 67ee3325c285829aea57f1cc272d2fbdddfd88ae # Parent c78d5f33efaa781661ad0b3e86df913a3f6a454c added support for node lowering to set the fixed node for the next node to be lowered diff -r c78d5f33efaa -r 67ee3325c285 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/LoweringTool.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/LoweringTool.java Thu Mar 07 20:18:27 2013 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/LoweringTool.java Fri Mar 08 13:54:41 2013 +0100 @@ -48,4 +48,9 @@ * Gets the closest fixed node preceding the node currently being lowered. */ FixedWithNextNode lastFixedNode(); + + /** + * Sets the closest fixed node preceding the next node to be lowered. + */ + void setLastFixedNode(FixedWithNextNode n); } diff -r c78d5f33efaa -r 67ee3325c285 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/LoweringPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/LoweringPhase.java Thu Mar 07 20:18:27 2013 +0100 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/LoweringPhase.java Fri Mar 08 13:54:41 2013 +0100 @@ -104,6 +104,11 @@ public FixedWithNextNode lastFixedNode() { return lastFixedNode; } + + public void setLastFixedNode(FixedWithNextNode n) { + assert n == null || n.isAlive() : n; + lastFixedNode = n; + } } private final TargetDescription target; @@ -187,15 +192,15 @@ List nodes = schedule.nodesFor(b); for (Node node : nodes) { - FixedNode lastFixedNext = null; - if (node instanceof FixedWithNextNode) { + FixedNode nextFixedNode = null; + if (node instanceof FixedWithNextNode && node.isAlive()) { FixedWithNextNode fixed = (FixedWithNextNode) node; - lastFixedNext = fixed.next(); - loweringTool.lastFixedNode = fixed; + nextFixedNode = fixed.next(); + loweringTool.setLastFixedNode(fixed); } if (node.isAlive() && !processed.isMarked(node) && node instanceof Lowerable) { - if (loweringTool.lastFixedNode == null) { + if (loweringTool.lastFixedNode() == null) { // We cannot lower the node now because we don't have a fixed node to anchor the // replacements. // This can happen when previous lowerings in this lowering iteration deleted @@ -209,17 +214,17 @@ } } - if (loweringTool.lastFixedNode == node && !node.isAlive()) { - if (lastFixedNext == null) { - loweringTool.lastFixedNode = null; + if (loweringTool.lastFixedNode() == node && !node.isAlive()) { + if (nextFixedNode == null || !nextFixedNode.isAlive()) { + loweringTool.setLastFixedNode(null); } else { - Node prev = lastFixedNext.predecessor(); + Node prev = nextFixedNode.predecessor(); if (prev != node && prev instanceof FixedWithNextNode) { - loweringTool.lastFixedNode = (FixedWithNextNode) prev; - } else if (lastFixedNext instanceof FixedWithNextNode) { - loweringTool.lastFixedNode = (FixedWithNextNode) lastFixedNext; + loweringTool.setLastFixedNode((FixedWithNextNode) prev); + } else if (nextFixedNode instanceof FixedWithNextNode) { + loweringTool.setLastFixedNode((FixedWithNextNode) nextFixedNode); } else { - loweringTool.lastFixedNode = null; + loweringTool.setLastFixedNode(null); } } } diff -r c78d5f33efaa -r 67ee3325c285 graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/InstanceOfSnippetsTemplates.java --- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/InstanceOfSnippetsTemplates.java Thu Mar 07 20:18:27 2013 +0100 +++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/InstanceOfSnippetsTemplates.java Fri Mar 08 13:54:41 2013 +0100 @@ -95,7 +95,7 @@ } else { KeyAndArguments keyAndArguments = getKeyAndArguments(replacer, tool); SnippetTemplate template = cache.get(keyAndArguments.key, assumptions); - template.instantiate(runtime, instanceOf, replacer, tool.lastFixedNode(), keyAndArguments.arguments); + template.instantiate(runtime, instanceOf, replacer, tool, keyAndArguments.arguments); } } diff -r c78d5f33efaa -r 67ee3325c285 graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetTemplate.java --- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetTemplate.java Thu Mar 07 20:18:27 2013 +0100 +++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetTemplate.java Fri Mar 08 13:54:41 2013 +0100 @@ -36,6 +36,7 @@ import com.oracle.graal.nodes.calc.*; import com.oracle.graal.nodes.extended.*; import com.oracle.graal.nodes.java.*; +import com.oracle.graal.nodes.spi.*; import com.oracle.graal.nodes.type.*; import com.oracle.graal.nodes.util.*; import com.oracle.graal.phases.common.*; @@ -629,10 +630,9 @@ * @param runtime * @param replacee the node that will be replaced * @param replacer object that replaces the usages of {@code replacee} - * @param lastFixedNode the CFG of the snippet is inserted after this node * @param args the arguments to be bound to the flattened positional parameters of the snippet */ - public void instantiate(MetaAccessProvider runtime, FloatingNode replacee, UsageReplacer replacer, FixedWithNextNode lastFixedNode, SnippetTemplate.Arguments args) { + public void instantiate(MetaAccessProvider runtime, FloatingNode replacee, UsageReplacer replacer, LoweringTool tool, SnippetTemplate.Arguments args) { // Inline the snippet nodes, replacing parameters with the given args in the process String name = snippet.name == null ? "{copy}" : snippet.name + "{copy}"; @@ -644,7 +644,8 @@ Map duplicates = replaceeGraph.addDuplicates(nodes, replacements); Debug.dump(replaceeGraph, "After inlining snippet %s", snippetCopy.method()); - assert lastFixedNode != null : replaceeGraph; + FixedWithNextNode lastFixedNode = tool.lastFixedNode(); + assert lastFixedNode != null && lastFixedNode.isAlive() : replaceeGraph; FixedNode next = lastFixedNode.next(); lastFixedNode.setNext(null); FixedNode firstCFGNodeDuplicate = (FixedNode) duplicates.get(firstCFGNode); @@ -673,10 +674,14 @@ assert returnValue != null || replacee.usages().isEmpty(); replacer.replace(replacee, returnValue); + tool.setLastFixedNode(null); Node returnDuplicate = duplicates.get(returnNode); if (returnDuplicate.isAlive()) { returnDuplicate.clearInputs(); returnDuplicate.replaceAndDelete(next); + if (next != null && next.predecessor() instanceof FixedWithNextNode) { + tool.setLastFixedNode((FixedWithNextNode) next.predecessor()); + } } Debug.dump(replaceeGraph, "After lowering %s with %s", replacee, this);