# HG changeset patch # User Lukas Stadler # Date 1399034829 -7200 # Node ID ef315dfdda35efd46a8504aceca62b7f860a58f4 # Parent c55f44b3c5e50ec90a0c973b56daba7d06502c22 new GraphUtil.predecessorIterable diff -r c55f44b3c5e5 -r ef315dfdda35 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/BeginNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/BeginNode.java Fri May 02 12:02:27 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/BeginNode.java Fri May 02 14:47:09 2014 +0200 @@ -32,6 +32,7 @@ import com.oracle.graal.graph.spi.*; import com.oracle.graal.nodes.extended.*; import com.oracle.graal.nodes.spi.*; +import com.oracle.graal.nodes.util.*; @NodeInfo(allowedUsageTypes = {InputType.Guard, InputType.Anchor}) public class BeginNode extends FixedWithNextNode implements LIRLowerable, Simplifiable, GuardingNode, AnchoringNode, IterableNodeType { @@ -69,12 +70,8 @@ } public static BeginNode prevBegin(FixedNode from) { - Node prevBegin = from; - while (prevBegin != null) { - if (prevBegin instanceof BeginNode) { - return (BeginNode) prevBegin; - } - prevBegin = prevBegin.predecessor(); + for (BeginNode begin : GraphUtil.predecessorIterable(from).filter(BeginNode.class)) { + return begin; } return null; } diff -r c55f44b3c5e5 -r ef315dfdda35 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/GraphUtil.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/GraphUtil.java Fri May 02 12:02:27 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/GraphUtil.java Fri May 02 14:47:09 2014 +0200 @@ -409,4 +409,32 @@ return true; } } + + /** + * Returns an iterator that will return the given node followed by all its predecessors, up + * until the point where {@link Node#predecessor()} returns null; + * + * @param start the node at which to start iterating + */ + public static NodeIterable predecessorIterable(final FixedNode start) { + return new NodeIterable() { + public Iterator iterator() { + return new Iterator() { + public FixedNode current = start; + + public boolean hasNext() { + return current != null; + } + + public FixedNode next() { + try { + return current; + } finally { + current = (FixedNode) current.predecessor(); + } + } + }; + } + }; + } } diff -r c55f44b3c5e5 -r ef315dfdda35 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConvertDeoptimizeToGuardPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConvertDeoptimizeToGuardPhase.java Fri May 02 12:02:27 2014 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConvertDeoptimizeToGuardPhase.java Fri May 02 14:47:09 2014 +0200 @@ -35,27 +35,20 @@ /** * This phase will find branches which always end with a {@link DeoptimizeNode} and replace their * {@link ControlSplitNode ControlSplitNodes} with {@link FixedGuardNode FixedGuardNodes}. - * + * * This is useful because {@link FixedGuardNode FixedGuardNodes} will be lowered to * {@link GuardNode GuardNodes} which can later be optimized more aggressively than control-flow * constructs. - * + * * This is currently only done for branches that start from a {@link IfNode}. If it encounters a * branch starting at an other kind of {@link ControlSplitNode}, it will only bring the * {@link DeoptimizeNode} as close to the {@link ControlSplitNode} as possible. - * + * */ public class ConvertDeoptimizeToGuardPhase extends Phase { private static BeginNode findBeginNode(FixedNode startNode) { - Node n = startNode; - while (true) { - if (n instanceof BeginNode) { - return (BeginNode) n; - } else { - n = n.predecessor(); - } - } + return GraphUtil.predecessorIterable(startNode).filter(BeginNode.class).first(); } @Override diff -r c55f44b3c5e5 -r ef315dfdda35 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningUtil.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningUtil.java Fri May 02 12:02:27 2014 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningUtil.java Fri May 02 14:47:09 2014 +0200 @@ -1293,17 +1293,6 @@ } } - static MonitorExitNode findPrecedingMonitorExit(UnwindNode unwind) { - Node pred = unwind.predecessor(); - while (pred != null) { - if (pred instanceof MonitorExitNode) { - return (MonitorExitNode) pred; - } - pred = pred.predecessor(); - } - return null; - } - /** * Performs an actual inlining, thereby replacing the given invoke with the given inlineGraph. *