use of org.graalvm.compiler.phases.tiers.PhaseContext 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.tiers.PhaseContext in project graal by oracle.
the class PartialEvaluator method createGraph.
@SuppressWarnings("try")
public StructuredGraph createGraph(DebugContext debug, final CompilableTruffleAST compilable, TruffleInliningPlan inliningPlan, AllowAssumptions allowAssumptions, CompilationIdentifier compilationId, SpeculationLog log, Cancellable cancellable) {
String name = compilable.toString();
OptionValues options = TruffleCompilerOptions.getOptions();
ResolvedJavaMethod rootMethod = rootForCallTarget(compilable);
// @formatter:off
final StructuredGraph graph = new StructuredGraph.Builder(options, debug, allowAssumptions).name(name).method(rootMethod).speculationLog(log).compilationId(compilationId).cancellable(cancellable).build();
try (DebugContext.Scope s = debug.scope("CreateGraph", graph);
Indent indent = debug.logAndIndent("createGraph %s", graph)) {
PhaseContext baseContext = new PhaseContext(providers);
HighTierContext tierContext = new HighTierContext(providers, new PhaseSuite<HighTierContext>(), OptimisticOptimizations.NONE);
fastPartialEvaluation(compilable, inliningPlan, graph, baseContext, tierContext);
if (cancellable != null && cancellable.isCancelled()) {
return null;
}
new VerifyFrameDoesNotEscapePhase().apply(graph, false);
postPartialEvaluation(graph);
} catch (Throwable e) {
throw debug.handle(e);
}
return graph;
}
use of org.graalvm.compiler.phases.tiers.PhaseContext in project graal by oracle.
the class RuntimeStrengthenStampsPhase method beforeCompilation.
@Override
@SuppressWarnings("try")
public void beforeCompilation(BeforeCompilationAccess c) {
CompilationAccessImpl config = (CompilationAccessImpl) c;
if (Options.PrintRuntimeCompileMethods.getValue()) {
printCallTree();
}
System.out.println(methods.size() + " method(s) included for runtime compilation");
if (Options.PrintStaticTruffleBoundaries.getValue()) {
printStaticTruffleBoundaries();
}
Integer maxMethods = Options.MaxRuntimeCompileMethods.getValue();
if (maxMethods != 0 && methods.size() > maxMethods) {
printDeepestLevelPath();
throw VMError.shouldNotReachHere("Number of methods for runtime compilation exceeds the allowed limit: " + methods.size() + " > " + maxMethods);
}
HostedMetaAccess hMetaAccess = config.getMetaAccess();
runtimeConfigBuilder.updateLazyState(hMetaAccess);
/*
* Start fresh with a new GraphEncoder, since we are going to optimize all graphs now that
* the static analysis results are available.
*/
graphEncoder = new GraphEncoder(ConfigurationValues.getTarget().arch);
StrengthenStampsPhase strengthenStamps = new RuntimeStrengthenStampsPhase(config.getUniverse(), objectReplacer);
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
PhaseContext phaseContext = new PhaseContext(hostedProviders);
for (CallTreeNode node : methods.values()) {
StructuredGraph graph = node.graph;
if (graph != null) {
DebugContext debug = graph.getDebug();
try (DebugContext.Scope scope = debug.scope("RuntimeOptimize", graph)) {
removeUnreachableInvokes(node);
strengthenStamps.apply(graph);
canonicalizer.apply(graph, phaseContext);
GraalConfiguration.instance().runAdditionalCompilerPhases(graph, this);
canonicalizer.apply(graph, phaseContext);
graphEncoder.prepare(graph);
} catch (Throwable ex) {
debug.handle(ex);
}
}
}
graphEncoder.finishPrepare();
for (CallTreeNode node : methods.values()) {
if (node.graph != null) {
registerDeoptEntries(node);
long startOffset = graphEncoder.encode(node.graph);
objectReplacer.createMethod(node.implementationMethod).setEncodedGraphStartOffset(startOffset);
/* We do not need the graph anymore, let the GC do it's work. */
node.graph = null;
}
}
GraalSupport.setGraphEncoding(graphEncoder.getEncoding(), graphEncoder.getObjects(), graphEncoder.getNodeClasses());
objectReplacer.updateDataDuringAnalysis((AnalysisMetaAccess) hMetaAccess.getWrapped());
}
use of org.graalvm.compiler.phases.tiers.PhaseContext in project graal by oracle.
the class ScalarTypeSystemTest method test.
private void test(final String snippet, final String referenceSnippet) {
// No debug scope to reduce console noise for @Test(expected = ...) tests
StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
graph.getDebug().dump(DebugContext.BASIC_LEVEL, graph, "Graph");
PhaseContext context = new PhaseContext(getProviders());
new CanonicalizerPhase().apply(graph, context);
StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.NO);
assertEquals(referenceGraph, graph);
}
use of org.graalvm.compiler.phases.tiers.PhaseContext in project graal by oracle.
the class StampCanonicalizerTest method testZeroReturn.
private void testZeroReturn(String methodName) {
StructuredGraph graph = parseEager(methodName, AllowAssumptions.YES);
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
new DeadCodeEliminationPhase().apply(graph);
assertConstantReturn(graph, 0);
}
Aggregations