use of org.graalvm.compiler.options.OptionValues in project graal by oracle.
the class UnsafeReadEliminationTest method testPartialEscapeReadElimination.
public void testPartialEscapeReadElimination(StructuredGraph graph, int reads, int writes) {
OptionValues options = graph.getOptions();
PhaseContext context = getDefaultHighTierContext();
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
canonicalizer.apply(graph, context);
new PartialEscapePhase(true, true, canonicalizer, null, options).apply(graph, context);
Assert.assertEquals(3, graph.getNodes().filter(UnsafeAccessNode.class).count());
// after lowering the same applies for reads and writes
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
canonicalizer.apply(graph, context);
new PartialEscapePhase(true, true, canonicalizer, null, options).apply(graph, context);
Assert.assertEquals(reads, graph.getNodes().filter(ReadNode.class).count());
Assert.assertEquals(writes, graph.getNodes().filter(WriteNode.class).count());
}
use of org.graalvm.compiler.options.OptionValues in project graal by oracle.
the class LongNodeChainTest method longAddChain.
private void longAddChain(boolean reverse) {
HighTierContext context = getDefaultHighTierContext();
OptionValues options = getInitialOptions();
StructuredGraph graph = new StructuredGraph.Builder(options, DebugContext.create(options, DebugHandlersFactory.LOADER)).build();
ValueNode constant = graph.unique(ConstantNode.forPrimitive(JavaConstant.INT_1));
ValueNode value = null;
if (reverse) {
// Make sure the constant's stamp is not used to infer the add node's stamp.
OpaqueNode opaque = graph.unique(new OpaqueNode(constant));
constant = opaque;
AddNode addNode = graph.unique(new AddNode(constant, constant));
value = addNode;
for (int i = 1; i < N; ++i) {
AddNode newAddNode = graph.addWithoutUnique(new AddNode(constant, constant));
addNode.setY(newAddNode);
addNode = newAddNode;
}
opaque.replaceAndDelete(opaque.getValue());
} else {
value = constant;
for (int i = 0; i < N; ++i) {
value = graph.unique(new AddNode(constant, value));
}
}
ReturnNode returnNode = graph.add(new ReturnNode(value));
graph.start().setNext(returnNode);
for (SchedulingStrategy s : Strategies) {
new SchedulePhase(s).apply(graph);
}
new CanonicalizerPhase().apply(graph, context);
JavaConstant asConstant = (JavaConstant) returnNode.result().asConstant();
Assert.assertEquals(N + 1, asConstant.asInt());
}
use of org.graalvm.compiler.options.OptionValues in project graal by oracle.
the class TraceBuilderPhase method getTraceBuilderResult.
private static TraceBuilderResult getTraceBuilderResult(LIR lir, AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] linearScanOrder) {
TraceBuilderResult.TrivialTracePredicate pred = getTrivialTracePredicate(lir);
OptionValues options = lir.getOptions();
TraceBuilder selectedTraceBuilder = Options.TraceBuilding.getValue(options);
DebugContext debug = lir.getDebug();
debug.log(DebugContext.BASIC_LEVEL, "Building Traces using %s", selectedTraceBuilder);
switch(Options.TraceBuilding.getValue(options)) {
case SingleBlock:
return SingleBlockTraceBuilder.computeTraces(debug, startBlock, linearScanOrder, pred);
case BiDirectional:
return BiDirectionalTraceBuilder.computeTraces(debug, startBlock, linearScanOrder, pred);
case UniDirectional:
return UniDirectionalTraceBuilder.computeTraces(debug, startBlock, linearScanOrder, pred);
}
throw GraalError.shouldNotReachHere("Unknown trace building algorithm: " + Options.TraceBuilding.getValue(options));
}
use of org.graalvm.compiler.options.OptionValues 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.options.OptionValues in project graal by oracle.
the class NativeImageGenerator method registerReplacements.
@SuppressWarnings("try")
public static void registerReplacements(DebugContext debug, FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, Providers providers, SnippetReflectionProvider snippetReflection, boolean hosted) {
OptionValues options = hosted ? HostedOptionValues.singleton() : RuntimeOptionValues.singleton();
Providers runtimeCallProviders = runtimeConfig != null ? runtimeConfig.getBackendForNormalMethod().getProviders() : providers;
SubstrateForeignCallsProvider foreignCallsProvider = (SubstrateForeignCallsProvider) providers.getForeignCalls();
for (SubstrateForeignCallDescriptor descriptor : SnippetRuntime.getRuntimeCalls()) {
foreignCallsProvider.getForeignCalls().put(descriptor, new SubstrateForeignCallLinkage(runtimeCallProviders, descriptor));
}
featureHandler.forEachGraalFeature(feature -> feature.registerForeignCalls(runtimeConfig, runtimeCallProviders, snippetReflection, foreignCallsProvider.getForeignCalls(), hosted));
try (DebugContext.Scope s = debug.scope("RegisterLowerings", new DebugDumpScope("RegisterLowerings"))) {
SubstrateLoweringProvider lowerer = (SubstrateLoweringProvider) providers.getLowerer();
Map<Class<? extends Node>, NodeLoweringProvider<?>> lowerings = lowerer.getLowerings();
Iterable<DebugHandlersFactory> factories = runtimeConfig != null ? runtimeConfig.getDebugHandlersFactories() : Collections.singletonList(new GraalDebugHandlersFactory(snippetReflection));
lowerer.setConfiguration(runtimeConfig, options, factories, providers, snippetReflection);
NonSnippetLowerings.registerLowerings(runtimeConfig, options, factories, providers, snippetReflection, lowerings);
ArithmeticSnippets.registerLowerings(options, factories, providers, snippetReflection, lowerings);
MonitorSnippets.registerLowerings(options, factories, providers, snippetReflection, lowerings);
TypeSnippets.registerLowerings(runtimeConfig, options, factories, providers, snippetReflection, lowerings);
ExceptionSnippets.registerLowerings(options, factories, providers, snippetReflection, lowerings);
if (hosted) {
AssertSnippets.registerLowerings(options, factories, providers, snippetReflection, lowerings);
DeoptHostedSnippets.registerLowerings(options, factories, providers, snippetReflection, lowerings);
} else {
DeoptRuntimeSnippets.registerLowerings(options, factories, providers, snippetReflection, lowerings);
}
if (NativeImageOptions.DeoptimizeAll.getValue()) {
DeoptTestSnippets.registerLowerings(options, factories, providers, snippetReflection, lowerings);
}
featureHandler.forEachGraalFeature(feature -> feature.registerLowerings(runtimeConfig, options, factories, providers, snippetReflection, lowerings, hosted));
} catch (Throwable e) {
throw debug.handle(e);
}
SubstrateReplacements replacements = (SubstrateReplacements) providers.getReplacements();
assert checkInvocationPluginMethods(replacements);
replacements.encodeSnippets();
}
Aggregations