# HG changeset patch # User Lukas Stadler # Date 1399307847 -7200 # Node ID eb9fa3d34314aaca16dd8988367b449d9921d9b4 # Parent 5fcbf87a58b7e51b2d1e0b405a69259c06526879# Parent 9fa849f665cc0bfafe70c1f2210af7f2b3f39526 Merge (clean phase within PartialEscapePhase) diff -r 5fcbf87a58b7 -r eb9fa3d34314 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/EATestBase.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/EATestBase.java Mon May 05 18:36:01 2014 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/EATestBase.java Mon May 05 18:37:27 2014 +0200 @@ -127,7 +127,7 @@ /** * Runs Escape Analysis on the given snippet and makes sure that no allocations remain in the * graph. - * + * * @param snippet the name of the method whose graph should be processed * @param expectedConstantResult if this is non-null, the resulting graph needs to have the * given constant return value @@ -157,7 +157,7 @@ new InliningPhase(new CanonicalizerPhase(true)).apply(graph, context); new DeadCodeEliminationPhase().apply(graph); new CanonicalizerPhase(true).apply(graph, context); - new PartialEscapePhase(iterativeEscapeAnalysis, false, new CanonicalizerPhase(true)).apply(graph, context); + new PartialEscapePhase(iterativeEscapeAnalysis, false, new CanonicalizerPhase(true), null).apply(graph, context); returnNodes = graph.getNodes(ReturnNode.class).snapshot(); } catch (Throwable e) { throw Debug.handle(e); diff -r 5fcbf87a58b7 -r eb9fa3d34314 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/PEAReadEliminationTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/PEAReadEliminationTest.java Mon May 05 18:36:01 2014 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/PEAReadEliminationTest.java Mon May 05 18:37:27 2014 +0200 @@ -247,6 +247,6 @@ Assumptions assumptions = new Assumptions(false); HighTierContext context = new HighTierContext(getProviders(), assumptions, null, getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL); new InliningPhase(new CanonicalizerPhase(true)).apply(graph, context); - new PartialEscapePhase(false, true, new CanonicalizerPhase(true)).apply(graph, context); + new PartialEscapePhase(false, true, new CanonicalizerPhase(true), null).apply(graph, context); } } diff -r 5fcbf87a58b7 -r eb9fa3d34314 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 Mon May 05 18:36:01 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/BeginNode.java Mon May 05 18:37:27 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 5fcbf87a58b7 -r eb9fa3d34314 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/CompareNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/CompareNode.java Mon May 05 18:36:01 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/CompareNode.java Mon May 05 18:37:27 2014 +0200 @@ -23,7 +23,7 @@ package com.oracle.graal.nodes.calc; import com.oracle.graal.api.meta.*; -import com.oracle.graal.api.meta.ProfilingInfo.*; +import com.oracle.graal.api.meta.ProfilingInfo.TriState; import com.oracle.graal.compiler.common.*; import com.oracle.graal.compiler.common.calc.*; import com.oracle.graal.graph.*; @@ -92,8 +92,8 @@ @Override public TriState evaluate(ConstantReflectionProvider constantReflection, ValueNode forX, ValueNode forY) { - if (x().isConstant() && y().isConstant()) { - return TriState.get(condition().foldCondition(x().asConstant(), y().asConstant(), constantReflection, unorderedIsTrue())); + if (forX.isConstant() && forY.isConstant()) { + return TriState.get(condition().foldCondition(forX.asConstant(), forY.asConstant(), constantReflection, unorderedIsTrue())); } return TriState.UNKNOWN; } diff -r 5fcbf87a58b7 -r eb9fa3d34314 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 Mon May 05 18:36:01 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/GraphUtil.java Mon May 05 18:37:27 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 5fcbf87a58b7 -r eb9fa3d34314 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 Mon May 05 18:36:01 2014 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConvertDeoptimizeToGuardPhase.java Mon May 05 18:37:27 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 5fcbf87a58b7 -r eb9fa3d34314 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 Mon May 05 18:36:01 2014 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningUtil.java Mon May 05 18:37:27 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. * diff -r 5fcbf87a58b7 -r eb9fa3d34314 graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/EffectsPhase.java --- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/EffectsPhase.java Mon May 05 18:36:01 2014 +0200 +++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/EffectsPhase.java Mon May 05 18:37:27 2014 +0200 @@ -24,6 +24,8 @@ import static com.oracle.graal.debug.Debug.*; +import java.util.*; + import com.oracle.graal.debug.*; import com.oracle.graal.debug.Debug.Scope; import com.oracle.graal.graph.*; @@ -46,7 +48,7 @@ } private final int maxIterations; - private final CanonicalizerPhase canonicalizer; + protected final CanonicalizerPhase canonicalizer; public EffectsPhase(int maxIterations, CanonicalizerPhase canonicalizer) { this.maxIterations = maxIterations; @@ -85,19 +87,24 @@ new DeadCodeEliminationPhase().apply(graph); + Set changedNodes = listener.getChangedNodes(); for (Node node : graph.getNodes()) { if (node instanceof Simplifiable) { - listener.getChangedNodes().add(node); + changedNodes.add(node); } } - if (canonicalizer != null) { - canonicalizer.applyIncremental(graph, context, listener.getChangedNodes()); - } + postIteration(graph, context, changedNodes); } changed = true; } return changed; } + protected void postIteration(final StructuredGraph graph, final PhaseContextT context, Set changedNodes) { + if (canonicalizer != null) { + canonicalizer.applyIncremental(graph, context, changedNodes); + } + } + protected abstract Closure createEffectsClosure(PhaseContextT context, SchedulePhase schedule); } diff -r 5fcbf87a58b7 -r eb9fa3d34314 graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapePhase.java --- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapePhase.java Mon May 05 18:36:01 2014 +0200 +++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapePhase.java Mon May 05 18:37:27 2014 +0200 @@ -34,6 +34,7 @@ import com.oracle.graal.nodes.spi.*; import com.oracle.graal.nodes.virtual.*; import com.oracle.graal.options.*; +import com.oracle.graal.phases.*; import com.oracle.graal.phases.common.*; import com.oracle.graal.phases.graph.*; import com.oracle.graal.phases.schedule.*; @@ -42,7 +43,6 @@ public class PartialEscapePhase extends EffectsPhase { static class Options { - //@formatter:off @Option(help = "") public static final OptionValue OptEarlyReadElimination = new OptionValue<>(true); @@ -50,14 +50,28 @@ } private final boolean readElimination; + private final BasePhase cleanupPhase; public PartialEscapePhase(boolean iterative, CanonicalizerPhase canonicalizer) { - this(iterative, OptEarlyReadElimination.getValue(), canonicalizer); + this(iterative, OptEarlyReadElimination.getValue(), canonicalizer, null); + } + + public PartialEscapePhase(boolean iterative, CanonicalizerPhase canonicalizer, BasePhase cleanupPhase) { + this(iterative, OptEarlyReadElimination.getValue(), canonicalizer, cleanupPhase); } - public PartialEscapePhase(boolean iterative, boolean readElimination, CanonicalizerPhase canonicalizer) { + public PartialEscapePhase(boolean iterative, boolean readElimination, CanonicalizerPhase canonicalizer, BasePhase cleanupPhase) { super(iterative ? EscapeAnalysisIterations.getValue() : 1, canonicalizer); this.readElimination = readElimination; + this.cleanupPhase = cleanupPhase; + } + + @Override + protected void postIteration(StructuredGraph graph, PhaseContext context, Set changedNodes) { + super.postIteration(graph, context, changedNodes); + if (cleanupPhase != null) { + cleanupPhase.apply(graph, context); + } } @Override