use of org.graalvm.compiler.phases.common.FloatingReadPhase 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.FloatingReadPhase in project graal by oracle.
the class IfCanonicalizerTest method testCombinedIf.
private void testCombinedIf(String snippet, int count) {
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
PhaseContext context = new PhaseContext(getProviders());
new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
new FloatingReadPhase().apply(graph);
MidTierContext midContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo());
new GuardLoweringPhase().apply(graph, midContext);
new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, midContext);
new CanonicalizerPhase().apply(graph, context);
assertDeepEquals(count, graph.getNodes().filter(IfNode.class).count());
}
use of org.graalvm.compiler.phases.common.FloatingReadPhase in project graal by oracle.
the class ImplicitNullCheckTest method test.
@SuppressWarnings("try")
private void test(final String snippet) {
DebugContext debug = getDebugContext();
try (DebugContext.Scope s = debug.scope("FloatingReadTest", new DebugDumpScope(snippet))) {
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES, debug);
PhaseContext context = new PhaseContext(getProviders());
new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
new FloatingReadPhase().apply(graph);
MidTierContext midTierContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo());
new GuardLoweringPhase().apply(graph, midTierContext);
Assert.assertEquals(0, graph.getNodes(DeoptimizeNode.TYPE).count());
Assert.assertTrue(graph.getNodes().filter(ReadNode.class).first().canNullCheck());
} catch (Throwable e) {
throw debug.handle(e);
}
}
use of org.graalvm.compiler.phases.common.FloatingReadPhase in project graal by oracle.
the class ReadAfterCheckCastTest method test.
@SuppressWarnings("try")
private void test(final String snippet) {
DebugContext debug = getDebugContext();
try (DebugContext.Scope s = debug.scope("ReadAfterCheckCastTest", new DebugDumpScope(snippet))) {
// check shape of graph, with lots of assumptions. will probably fail if graph
// structure changes significantly
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
PhaseContext context = new PhaseContext(getProviders());
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
new FloatingReadPhase().apply(graph);
canonicalizer.apply(graph, context);
debug.dump(DebugContext.BASIC_LEVEL, graph, "After lowering");
for (FloatingReadNode node : graph.getNodes(ParameterNode.TYPE).first().usages().filter(FloatingReadNode.class)) {
// Checking that the parameter a is not directly used for the access to field
// x10 (because x10 must be guarded by the checkcast).
Assert.assertTrue(node.getLocationIdentity().isImmutable());
}
} catch (Throwable e) {
throw debug.handle(e);
}
}
use of org.graalvm.compiler.phases.common.FloatingReadPhase in project graal by oracle.
the class GuardPrioritiesTest method prepareGraph.
private StructuredGraph prepareGraph(String method) {
StructuredGraph graph = parseEager(method, StructuredGraph.AllowAssumptions.YES);
HighTierContext highTierContext = getDefaultHighTierContext();
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
new ConvertDeoptimizeToGuardPhase().apply(graph, highTierContext);
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, highTierContext);
new FloatingReadPhase().apply(graph);
return graph;
}
Aggregations