use of org.graalvm.compiler.phases.tiers.HighTierContext in project graal by oracle.
the class InfopointReasonTest method lineInfopoints.
@Test
public void lineInfopoints() {
final ResolvedJavaMethod method = getResolvedJavaMethod("testMethod");
final StructuredGraph graph = parse(builder(method, AllowAssumptions.ifTrue(OptAssumptions.getValue(getInitialOptions()))), getDebugGraphBuilderSuite());
int graphLineSPs = 0;
for (FullInfopointNode ipn : graph.getNodes().filter(FullInfopointNode.class)) {
if (ipn.getReason() == InfopointReason.BYTECODE_POSITION) {
++graphLineSPs;
}
}
assertTrue(graphLineSPs > 0);
PhaseSuite<HighTierContext> graphBuilderSuite = getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withFullInfopoints(true));
final CompilationResult cr = compileGraph(graph, graph.method(), getProviders(), getBackend(), graphBuilderSuite, OptimisticOptimizations.ALL, graph.getProfilingInfo(), createSuites(graph.getOptions()), createLIRSuites(graph.getOptions()), new CompilationResult(graph.compilationId()), CompilationResultBuilderFactory.Default);
int lineSPs = 0;
for (Infopoint sp : cr.getInfopoints()) {
assertNotNull(sp.reason);
if (sp.reason == InfopointReason.BYTECODE_POSITION) {
++lineSPs;
}
}
assertTrue(lineSPs > 0);
}
use of org.graalvm.compiler.phases.tiers.HighTierContext in project graal by oracle.
the class NodePropertiesTest method testDifferentLoopsInnerOuter.
@Test
public void testDifferentLoopsInnerOuter() {
HighTierContext htc = getDefaultHighTierContext();
StructuredGraph g1 = parseForCompile(getResolvedJavaMethod("testLoop04"));
StructuredGraph g2 = parseForCompile(getResolvedJavaMethod("testLoop05"));
prepareGraphForLoopFrequencies(g1, htc);
prepareGraphForLoopFrequencies(g2, htc);
assertFrequency(g1, ITERATIONS_LOOP_1 * ITERATIONS_LOOP_2);
GraphCostPhase gc1 = new GraphCostPhase();
GraphCostPhase gc2 = new GraphCostPhase();
gc1.apply(g1, htc);
gc2.apply(g2, htc);
g1.getDebug().log("Test testDifferentLoopsInnerOuter --> 1.Graph cycles:%f size:%f vs. 2.Graph cycles:%f size:%f\n", gc1.finalCycles, gc1.finalSize, gc2.finalCycles, gc2.finalSize);
Assert.assertTrue(gc2.finalSize > gc1.finalSize);
}
use of org.graalvm.compiler.phases.tiers.HighTierContext in project graal by oracle.
the class NativeImageGenerator method createSuites.
public static Suites createSuites(FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, SnippetReflectionProvider snippetReflection, boolean hosted) {
Providers runtimeCallProviders = runtimeConfig.getBackendForNormalMethod().getProviders();
OptionValues options = hosted ? HostedOptionValues.singleton() : RuntimeOptionValues.singleton();
Suites suites = GraalConfiguration.instance().createSuites(options, hosted);
PhaseSuite<HighTierContext> highTier = suites.getHighTier();
PhaseSuite<MidTierContext> midTier = suites.getMidTier();
PhaseSuite<LowTierContext> lowTier = suites.getLowTier();
ListIterator<BasePhase<? super HighTierContext>> position;
if (hosted) {
position = GraalConfiguration.instance().createHostedInliners(highTier);
} else {
/* Find the runtime inliner. */
position = highTier.findPhase(InliningPhase.class);
}
if (position != null) {
/* These two phases must be after all method inlining. */
position.add(new DeadStoreRemovalPhase());
position.add(new RemoveUnwindPhase());
} else {
/* There is no inlining, so prepend them in reverse order. */
highTier.prependPhase(new RemoveUnwindPhase());
highTier.prependPhase(new DeadStoreRemovalPhase());
}
highTier.appendPhase(new StackValuePhase());
lowTier.addBeforeLast(new OptimizeExceptionCallsPhase());
CompressEncoding compressEncoding = ImageSingletons.lookup(CompressEncoding.class);
SubstrateAMD64RegisterConfig registerConfig = (SubstrateAMD64RegisterConfig) runtimeCallProviders.getCodeCache().getRegisterConfig();
SubstrateAMD64AddressLowering addressLowering = new SubstrateAMD64AddressLowering(compressEncoding, registerConfig);
lowTier.findPhase(FixReadsPhase.class).add(new AddressLoweringPhase(addressLowering));
if (SubstrateOptions.MultiThreaded.getValue()) {
/*
* Graal inserts only loop safepoints. We want a SafepointNode also before every return.
*/
midTier.findPhase(LoopSafepointInsertionPhase.class).add(new MethodSafepointInsertionPhase());
} else {
/* No need for safepoints when we have only one thread. */
VMError.guarantee(midTier.removePhase(LoopSafepointInsertionPhase.class));
}
if (hosted) {
lowTier.appendPhase(new VerifyNoGuardsPhase());
/* Disable the Graal method inlining, since we have our own inlining system. */
highTier.removePhase(InliningPhase.class);
/* Remove phases that are not suitable for AOT compilation. */
highTier.findPhase(ConvertDeoptimizeToGuardPhase.class, true).remove();
midTier.findPhase(DeoptimizationGroupingPhase.class).remove();
} else {
ListIterator<BasePhase<? super MidTierContext>> it = midTier.findPhase(DeoptimizationGroupingPhase.class);
it.previous();
it.add(new CollectDeoptimizationSourcePositionsPhase());
}
featureHandler.forEachGraalFeature(feature -> feature.registerGraalPhases(runtimeCallProviders, snippetReflection, suites, hosted));
return suites;
}
use of org.graalvm.compiler.phases.tiers.HighTierContext in project graal by oracle.
the class InvokeGraal method compileAndInstallMethod.
/**
* The simplest way to compile a method, using the default behavior for everything.
*/
@SuppressWarnings("try")
protected InstalledCode compileAndInstallMethod(ResolvedJavaMethod method) {
/* Create a unique compilation identifier, visible in IGV. */
CompilationIdentifier compilationId = backend.getCompilationIdentifier(method);
OptionValues options = getInitialOptions();
DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
try (DebugContext.Scope s = debug.scope("compileAndInstallMethod", new DebugDumpScope(String.valueOf(compilationId), true))) {
/*
* The graph that is compiled. We leave it empty (no nodes added yet). This means that
* it will be filled according to the graphBuilderSuite defined below. We also specify
* that we want the compilation to make optimistic assumptions about runtime state such
* as the loaded class hierarchy.
*/
StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).method(method).compilationId(compilationId).build();
/*
* The phases used to build the graph. Usually this is just the GraphBuilderPhase. If
* the graph already contains nodes, it is ignored.
*/
PhaseSuite<HighTierContext> graphBuilderSuite = backend.getSuites().getDefaultGraphBuilderSuite();
/*
* The optimization phases that are applied to the graph. This is the main configuration
* point for Graal. Add or remove phases to customize your compilation.
*/
Suites suites = backend.getSuites().getDefaultSuites(options);
/*
* The low-level phases that are applied to the low-level representation.
*/
LIRSuites lirSuites = backend.getSuites().getDefaultLIRSuites(options);
/*
* We want Graal to perform all speculative optimistic optimizations, using the
* profiling information that comes with the method (collected by the interpreter) for
* speculation.
*/
OptimisticOptimizations optimisticOpts = OptimisticOptimizations.ALL;
ProfilingInfo profilingInfo = graph.getProfilingInfo(method);
/* The default class and configuration for compilation results. */
CompilationResult compilationResult = new CompilationResult(graph.compilationId());
CompilationResultBuilderFactory factory = CompilationResultBuilderFactory.Default;
/* Invoke the whole Graal compilation pipeline. */
GraalCompiler.compileGraph(graph, method, providers, backend, graphBuilderSuite, optimisticOpts, profilingInfo, suites, lirSuites, compilationResult, factory);
/*
* Install the compilation result into the VM, i.e., copy the byte[] array that contains
* the machine code into an actual executable memory location.
*/
return backend.addInstalledCode(debug, method, asCompilationRequest(compilationId), compilationResult);
} catch (Throwable ex) {
throw debug.handle(ex);
}
}
use of org.graalvm.compiler.phases.tiers.HighTierContext in project graal by oracle.
the class IntegerExactFoldTest method prepareGraph.
protected StructuredGraph prepareGraph() {
String snippet = "snippetInt" + bits;
StructuredGraph graph = parseEager(getResolvedJavaMethod(operation.getClass(), snippet), AllowAssumptions.NO);
HighTierContext context = getDefaultHighTierContext();
new CanonicalizerPhase().apply(graph, context);
return graph;
}
Aggregations