use of com.oracle.svm.core.graal.phases.DeadStoreRemovalPhase 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 com.oracle.svm.core.graal.phases.DeadStoreRemovalPhase in project graal by oracle.
the class CompileQueue method defaultParseFunction.
@SuppressWarnings("try")
private void defaultParseFunction(DebugContext debug, HostedMethod method, CompileReason reason, RuntimeConfiguration config) {
if (method.getAnnotation(Fold.class) != null || method.getAnnotation(NodeIntrinsic.class) != null) {
throw VMError.shouldNotReachHere("Parsing method annotated with @Fold or @NodeIntrinsic: " + method.format("%H.%n(%p)"));
}
HostedProviders providers = (HostedProviders) config.lookupBackend(method).getProviders();
boolean needParsing = false;
OptionValues options = HostedOptionValues.singleton();
StructuredGraph graph = method.buildGraph(debug, method, providers, Purpose.AOT_COMPILATION);
if (graph == null) {
InvocationPlugin plugin = providers.getGraphBuilderPlugins().getInvocationPlugins().lookupInvocation(method);
if (plugin != null && !plugin.inlineOnly()) {
Bytecode code = new ResolvedJavaMethodBytecode(method);
// DebugContext debug = new DebugContext(options, providers.getSnippetReflection());
graph = new SubstrateIntrinsicGraphBuilder(debug.getOptions(), debug, providers.getMetaAccess(), providers.getConstantReflection(), providers.getConstantFieldProvider(), providers.getStampProvider(), code).buildGraph(plugin);
}
}
if (graph == null && method.isNative() && NativeImageOptions.ReportUnsupportedElementsAtRuntime.getValue()) {
graph = DeletedMethod.buildGraph(debug, method, providers, DeletedMethod.NATIVE_MESSAGE);
}
if (graph == null) {
needParsing = true;
if (!method.compilationInfo.isDeoptTarget()) {
/*
* Disabling liveness analysis preserves the values of local variables beyond the
* bytecode-liveness. This greatly helps debugging. When local variable numbers are
* reused by javac, local variables can still get illegal values. Since we cannot
* "restore" such illegal values during deoptimization, we must do liveness analysis
* for deoptimization target methods.
*/
options = new OptionValues(options, GraalOptions.OptClearNonLiveLocals, false);
}
graph = new StructuredGraph.Builder(options, debug).method(method).build();
}
try (DebugContext.Scope s = debug.scope("Parsing", graph, method, this)) {
try {
if (needParsing) {
GraphBuilderConfiguration gbConf = createHostedGraphBuilderConfiguration(providers, method);
new HostedGraphBuilderPhase(providers.getMetaAccess(), providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), gbConf, optimisticOpts, null, providers.getWordTypes()).apply(graph);
} else {
graph.setGuardsStage(GuardsStage.FIXED_DEOPTS);
}
new DeadStoreRemovalPhase().apply(graph);
new DevirtualizeCallsPhase().apply(graph);
new CanonicalizerPhase().apply(graph, new PhaseContext(providers));
/*
* The StrengthenStampsPhase may not insert type check nodes for specialized
* methods, because we would get type state mismatches regarding Const<Type> !=
* <Type>
*/
/*
* cwimmer: the old, commented out, condition always disabled checking of static
* analysis results. Therefore, the checks are broken right now.
*/
// new StrengthenStampsPhase(BootImageOptions.CheckStaticAnalysisResults.getValue()
// && method.compilationInfo.deoptTarget != null &&
// !method.compilationInfo.isDeoptTarget).apply(graph);
new StrengthenStampsPhase(false).apply(graph);
new CanonicalizerPhase().apply(graph, new PhaseContext(providers));
/* Check that graph is in good shape after parsing. */
assert GraphOrder.assertSchedulableGraph(graph);
method.compilationInfo.graph = graph;
for (Invoke invoke : graph.getInvokes()) {
if (!canBeUsedForInlining(invoke)) {
invoke.setUseForInlining(false);
}
if (invoke.callTarget() instanceof MethodCallTargetNode) {
MethodCallTargetNode targetNode = (MethodCallTargetNode) invoke.callTarget();
HostedMethod invokeTarget = (HostedMethod) targetNode.targetMethod();
if (targetNode.invokeKind().isDirect()) {
if (invokeTarget.wrapped.isImplementationInvoked()) {
handleSpecialization(method, targetNode, invokeTarget, invokeTarget);
ensureParsed(invokeTarget, new DirectCallReason(method, reason));
}
} else {
for (HostedMethod invokeImplementation : invokeTarget.getImplementations()) {
handleSpecialization(method, targetNode, invokeTarget, invokeImplementation);
ensureParsed(invokeImplementation, new VirtualCallReason(method, invokeImplementation, reason));
}
}
}
}
} catch (Throwable ex) {
GraalError error = ex instanceof GraalError ? (GraalError) ex : new GraalError(ex);
error.addContext("method: " + method.format("%r %H.%n(%p)"));
throw error;
}
} catch (Throwable e) {
throw debug.handle(e);
}
}
use of com.oracle.svm.core.graal.phases.DeadStoreRemovalPhase in project graal by oracle.
the class SubstratePartialEvaluator method doGraphPE.
@Override
protected void doGraphPE(CompilableTruffleAST callTarget, StructuredGraph graph, HighTierContext tierContext, TruffleInliningPlan inliningDecision) {
super.doGraphPE(callTarget, graph, tierContext, inliningDecision);
new DeadStoreRemovalPhase().apply(graph);
new TruffleBoundaryPhase().apply(graph);
}
Aggregations