use of org.graalvm.compiler.phases.common.ConditionalEliminationPhase in project graal by oracle.
the class ConditionAnchoringTest method test.
public void test(String name, int ids) {
StructuredGraph graph = parseEager(name, AllowAssumptions.YES);
NodeIterable<RawLoadNode> unsafeNodes = graph.getNodes().filter(RawLoadNode.class);
assertThat(unsafeNodes, hasCount(1));
// lower unsafe load
PhaseContext context = new PhaseContext(getProviders());
LoweringPhase lowering = new LoweringPhase(new CanonicalizerPhase(), StandardLoweringStage.HIGH_TIER);
lowering.apply(graph, context);
unsafeNodes = graph.getNodes().filter(RawLoadNode.class);
NodeIterable<ConditionAnchorNode> conditionAnchors = graph.getNodes().filter(ConditionAnchorNode.class);
NodeIterable<ReadNode> reads = graph.getNodes().filter(ReadNode.class);
assertThat(unsafeNodes, isEmpty());
assertThat(conditionAnchors, hasCount(1));
// 2 * ids id reads, 1 'field' access
assertThat(reads, hasCount(2 * ids + 1));
// float reads and canonicalize to give a chance to conditions to GVN
FloatingReadPhase floatingReadPhase = new FloatingReadPhase();
floatingReadPhase.apply(graph);
CanonicalizerPhase canonicalizerPhase = new CanonicalizerPhase();
canonicalizerPhase.apply(graph, context);
NodeIterable<FloatingReadNode> floatingReads = graph.getNodes().filter(FloatingReadNode.class);
// 1 id read, 1 'field' access
assertThat(floatingReads, hasCount(ids + 1));
new ConditionalEliminationPhase(false).apply(graph, context);
floatingReads = graph.getNodes().filter(FloatingReadNode.class).filter(n -> ((FloatingReadNode) n).getLocationIdentity() instanceof ObjectLocationIdentity);
conditionAnchors = graph.getNodes().filter(ConditionAnchorNode.class);
assertThat(floatingReads, hasCount(1));
assertThat(conditionAnchors, isEmpty());
FloatingReadNode readNode = floatingReads.first();
assertThat(readNode.getGuard(), instanceOf(BeginNode.class));
assertThat(readNode.getGuard().asNode().predecessor(), instanceOf(IfNode.class));
}
use of org.graalvm.compiler.phases.common.ConditionalEliminationPhase in project graal by oracle.
the class TypeSystemTest method test.
private void test(String snippet, String referenceSnippet) {
StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
DebugContext debug = graph.getDebug();
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
/*
* When using FlowSensitiveReductionPhase instead of ConditionalEliminationPhase,
* tail-duplication gets activated thus resulting in a graph with more nodes than the
* reference graph.
*/
new ConditionalEliminationPhase(false).apply(graph, new PhaseContext(getProviders()));
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
// a second canonicalizer is needed to process nested MaterializeNodes
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.NO);
new ConditionalEliminationPhase(false).apply(referenceGraph, new PhaseContext(getProviders()));
new CanonicalizerPhase().apply(referenceGraph, new PhaseContext(getProviders()));
new CanonicalizerPhase().apply(referenceGraph, new PhaseContext(getProviders()));
assertEquals(referenceGraph, graph);
}
use of org.graalvm.compiler.phases.common.ConditionalEliminationPhase in project graal by oracle.
the class ConditionalEliminationMulTest method prepareGraph.
private StructuredGraph prepareGraph(String snippet) {
StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
HighTierContext context = getDefaultHighTierContext();
new ConditionalEliminationPhase(false).apply(graph, context);
CanonicalizerPhase c = new CanonicalizerPhase();
c.apply(graph, context);
new ConditionalEliminationPhase(false).apply(graph, context);
c.apply(graph, context);
return graph;
}
use of org.graalvm.compiler.phases.common.ConditionalEliminationPhase in project graal by oracle.
the class ConditionalEliminationTest2 method testRedundantCompares.
@Test
public void testRedundantCompares() {
StructuredGraph graph = parseEager("testRedundantComparesSnippet", AllowAssumptions.YES);
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
PhaseContext context = new PhaseContext(getProviders());
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
canonicalizer.apply(graph, context);
new FloatingReadPhase().apply(graph);
new ConditionalEliminationPhase(true).apply(graph, context);
canonicalizer.apply(graph, context);
assertDeepEquals(1, graph.getNodes().filter(GuardNode.class).count());
}
use of org.graalvm.compiler.phases.common.ConditionalEliminationPhase in project graal by oracle.
the class PartialEvaluator method fastPartialEvaluation.
@SuppressWarnings({ "try", "unused" })
private void fastPartialEvaluation(CompilableTruffleAST compilable, TruffleInliningPlan inliningDecision, StructuredGraph graph, PhaseContext baseContext, HighTierContext tierContext) {
DebugContext debug = graph.getDebug();
doGraphPE(compilable, graph, tierContext, inliningDecision);
debug.dump(DebugContext.BASIC_LEVEL, graph, "After Partial Evaluation");
graph.maybeCompress();
// Perform deoptimize to guard conversion.
new ConvertDeoptimizeToGuardPhase().apply(graph, tierContext);
for (MethodCallTargetNode methodCallTargetNode : graph.getNodes(MethodCallTargetNode.TYPE)) {
StructuredGraph inlineGraph = providers.getReplacements().getSubstitution(methodCallTargetNode.targetMethod(), methodCallTargetNode.invoke().bci(), graph.trackNodeSourcePosition(), methodCallTargetNode.asNode().getNodeSourcePosition());
if (inlineGraph != null) {
InliningUtil.inline(methodCallTargetNode.invoke(), inlineGraph, true, methodCallTargetNode.targetMethod());
}
}
// Perform conditional elimination.
new ConditionalEliminationPhase(false).apply(graph, tierContext);
canonicalizer.apply(graph, tierContext);
// Do single partial escape and canonicalization pass.
try (DebugContext.Scope pe = debug.scope("TrufflePartialEscape", graph)) {
new PartialEscapePhase(TruffleCompilerOptions.getValue(TruffleIterativePartialEscape), canonicalizer, graph.getOptions()).apply(graph, tierContext);
} catch (Throwable t) {
debug.handle(t);
}
// recompute loop frequencies now that BranchProbabilities have had time to canonicalize
ComputeLoopFrequenciesClosure.compute(graph);
applyInstrumentationPhases(graph, tierContext);
graph.maybeCompress();
PerformanceInformationHandler.reportPerformanceWarnings(compilable, graph);
}
Aggregations