Skip to content

Commit

Permalink
Avoid checking nsp in generated graphs.
Browse files Browse the repository at this point in the history
Move some phases after parsing.
  • Loading branch information
majavu committed Mar 28, 2019
1 parent 982c418 commit 55b7956
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public void removeDeoptTargetOptimizations(@SuppressWarnings("unused") Suites su
* Returns a {@link ListIterator} at the position of the last inlining phase or null if no
* inlining phases were created.
*/
public ListIterator<BasePhase<? super HighTierContext>> createHostedInliners(@SuppressWarnings("unused") PhaseSuite<HighTierContext> highTier) {
public ListIterator<BasePhase<? super HighTierContext>> createHostedInliners(@SuppressWarnings("unused") PhaseSuite<HighTierContext> highTier,
@SuppressWarnings("unused") boolean requiresPostParseCanonicalization) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ public void beforeAnalysis(BeforeAnalysisAccess c) {
DebugContext debug = DebugContext.forCurrentThread();
NativeImageGenerator.registerReplacements(debug, featureHandler, runtimeConfig, runtimeConfig.getProviders(), runtimeConfig.getSnippetReflection(), false, true);
featureHandler.forEachGraalFeature(feature -> feature.registerCodeObserver(runtimeConfig));
Suites suites = NativeImageGenerator.createSuites(featureHandler, runtimeConfig, runtimeConfig.getSnippetReflection(), false);
Suites suites = NativeImageGenerator.createSuites(featureHandler, runtimeConfig, runtimeConfig.getSnippetReflection(), false, false);
LIRSuites lirSuites = NativeImageGenerator.createLIRSuites(featureHandler, runtimeConfig.getProviders(), false);
Suites firstTierSuites = NativeImageGenerator.createFirstTierSuites(featureHandler, runtimeConfig, runtimeConfig.getSnippetReflection(), false);
Suites firstTierSuites = NativeImageGenerator.createFirstTierSuites(featureHandler, runtimeConfig, runtimeConfig.getSnippetReflection(), false, false);
LIRSuites firstTierLirSuites = NativeImageGenerator.createFirstTierLIRSuites(featureHandler, runtimeConfig.getProviders(), false);
GraalSupport.setRuntimeConfig(runtimeConfig, suites, lirSuites, firstTierSuites, firstTierLirSuites);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.function.Function;
import java.util.function.Predicate;

import com.oracle.svm.hosted.code.SharedRuntimeConfigurationBuilder;
import org.graalvm.compiler.debug.DebugContext;
import org.graalvm.nativeimage.Feature;
import org.graalvm.nativeimage.Feature.DuringAnalysisAccess;
Expand Down Expand Up @@ -452,9 +453,16 @@ public Collection<? extends SharedMethod> getMethods() {
}

public static class BeforeCompilationAccessImpl extends CompilationAccessImpl implements Feature.BeforeCompilationAccess {
SharedRuntimeConfigurationBuilder runtimeBuilder;

BeforeCompilationAccessImpl(FeatureHandler featureHandler, ImageClassLoader imageClassLoader, AnalysisUniverse aUniverse, HostedUniverse hUniverse, HostedMetaAccess hMetaAccess,
NativeImageHeap heap, DebugContext debugContext) {
NativeImageHeap heap, DebugContext debugContext, SharedRuntimeConfigurationBuilder runtime) {
super(featureHandler, imageClassLoader, aUniverse, hUniverse, hMetaAccess, heap, debugContext);
runtimeBuilder = runtime;
}

public SharedRuntimeConfigurationBuilder getRuntimeBuilder() {
return runtimeBuilder;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package com.oracle.svm.hosted;

import static com.oracle.svm.hosted.code.CompileQueue.afterParseCanonicalization;
import static org.graalvm.compiler.replacements.StandardGraphBuilderPlugins.registerInvocationPlugins;
import static org.graalvm.compiler.serviceprovider.JavaVersionUtil.JAVA_SPECIFICATION_VERSION;

Expand Down Expand Up @@ -563,7 +564,7 @@ private void doRun(Map<Method, CEntryPointData> entryPoints, Method mainEntryPoi

heap = new NativeImageHeap(aUniverse, hUniverse, hMetaAccess);

BeforeCompilationAccessImpl config = new BeforeCompilationAccessImpl(featureHandler, loader, aUniverse, hUniverse, hMetaAccess, heap, debug);
BeforeCompilationAccessImpl config = new BeforeCompilationAccessImpl(featureHandler, loader, aUniverse, hUniverse, hMetaAccess, heap, debug, runtime);
featureHandler.forEachFeature(feature -> feature.beforeCompilation(config));

bigbang.getUnsupportedFeatures().report(bigbang);
Expand Down Expand Up @@ -1243,24 +1244,26 @@ private static boolean checkInvocationPluginMethods(SubstrateReplacements replac
return true;
}

public static Suites createSuites(FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, SnippetReflectionProvider snippetReflection, boolean hosted) {
public static Suites createSuites(FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, SnippetReflectionProvider snippetReflection, boolean hosted,
boolean requiresPostParseCanonicalization) {
SubstrateBackend backend = runtimeConfig.getBackendForNormalMethod();

OptionValues options = hosted ? HostedOptionValues.singleton() : RuntimeOptionValues.singleton();
Suites suites = GraalConfiguration.instance().createSuites(options, hosted);
return modifySuites(backend, suites, featureHandler, runtimeConfig, snippetReflection, hosted, false);
return modifySuites(backend, suites, featureHandler, runtimeConfig, snippetReflection, hosted, false, requiresPostParseCanonicalization);
}

public static Suites createFirstTierSuites(FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, SnippetReflectionProvider snippetReflection, boolean hosted) {
public static Suites createFirstTierSuites(FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, SnippetReflectionProvider snippetReflection, boolean hosted,
boolean requiresPostParseCanonicalization) {
SubstrateBackend backend = runtimeConfig.getBackendForNormalMethod();
OptionValues options = hosted ? HostedOptionValues.singleton() : RuntimeOptionValues.singleton();
Suites suites = GraalConfiguration.instance().createFirstTierSuites(options, hosted);
return modifySuites(backend, suites, featureHandler, runtimeConfig, snippetReflection, hosted, true);
return modifySuites(backend, suites, featureHandler, runtimeConfig, snippetReflection, hosted, true, requiresPostParseCanonicalization);
}

@SuppressWarnings("unused")
private static Suites modifySuites(SubstrateBackend backend, Suites suites, FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig,
SnippetReflectionProvider snippetReflection, boolean hosted, boolean firstTier) {
SnippetReflectionProvider snippetReflection, boolean hosted, boolean firstTier, boolean requiresPostParseCanonicalization) {
Providers runtimeCallProviders = backend.getProviders();

PhaseSuite<HighTierContext> highTier = suites.getHighTier();
Expand All @@ -1269,7 +1272,7 @@ private static Suites modifySuites(SubstrateBackend backend, Suites suites, Feat

ListIterator<BasePhase<? super HighTierContext>> position;
if (hosted) {
position = GraalConfiguration.instance().createHostedInliners(highTier);
position = GraalConfiguration.instance().createHostedInliners(highTier, requiresPostParseCanonicalization);
} else {
/* Find the runtime inliner. */
position = highTier.findPhase(InliningPhase.class);
Expand Down Expand Up @@ -1333,6 +1336,14 @@ private static Suites modifySuites(SubstrateBackend backend, Suites suites, Feat

featureHandler.forEachGraalFeature(feature -> feature.registerGraalPhases(runtimeCallProviders, snippetReflection, suites, hosted));

if (hosted && requiresPostParseCanonicalization) {
List<BasePhase<? super HighTierContext>> reverseAfterParsePhases = new ArrayList<>(afterParseCanonicalization().getPhases());
Collections.reverse(reverseAfterParsePhases);
for (BasePhase<? super HighTierContext> phase : reverseAfterParsePhases) {
highTier.prependPhase(phase);
}
}

return suites;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ public interface CompileFunction {
protected CompletionExecutor executor;
private final ConcurrentMap<HostedMethod, CompileTask> compilations;
protected final RuntimeConfiguration runtimeConfig;
private final OptimisticOptimizations optimisticOpts;
private final Suites regularSuites;
private final Suites deoptTargetSuites;
private final LIRSuites regularLIRSuites;
Expand Down Expand Up @@ -314,13 +313,12 @@ public CompileQueue(DebugContext debug, FeatureHandler featureHandler, HostedUni
this.universe = universe;
this.compilations = new ConcurrentHashMap<>();
this.runtimeConfig = runtimeConfigBuilder.getRuntimeConfig();
this.optimisticOpts = OptimisticOptimizations.ALL.remove(OptimisticOptimizations.Optimization.UseLoopLimitChecks);
this.deoptimizeAll = deoptimizeAll;
this.dataCache = new ConcurrentHashMap<>();
this.executor = new CompletionExecutor(universe.getBigBang(), executorService);

regularSuites = NativeImageGenerator.createSuites(featureHandler, runtimeConfig, snippetReflection, true);
deoptTargetSuites = NativeImageGenerator.createSuites(featureHandler, runtimeConfig, snippetReflection, true);
regularSuites = NativeImageGenerator.createSuites(featureHandler, runtimeConfig, snippetReflection, true, !universe.isPostParseCanonicalized());
deoptTargetSuites = NativeImageGenerator.createSuites(featureHandler, runtimeConfig, snippetReflection, true, !universe.isPostParseCanonicalized());
removeDeoptTargetOptimizations(deoptTargetSuites);
regularLIRSuites = NativeImageGenerator.createLIRSuites(featureHandler, runtimeConfig.getProviders(), true);
deoptTargetLIRSuites = NativeImageGenerator.createLIRSuites(featureHandler, runtimeConfig.getProviders(), true);
Expand All @@ -330,6 +328,10 @@ public CompileQueue(DebugContext debug, FeatureHandler featureHandler, HostedUni
callForReplacements(debug, featureHandler, runtimeConfig, snippetReflection);
}

public static OptimisticOptimizations getOptimisticOpts() {
return OptimisticOptimizations.ALL.remove(OptimisticOptimizations.Optimization.UseLoopLimitChecks);
}

protected void callForReplacements(DebugContext debug, FeatureHandler featureHandler, @SuppressWarnings("hiding") RuntimeConfiguration runtimeConfig, SnippetReflectionProvider snippetReflection) {
NativeImageGenerator.registerReplacements(debug, featureHandler, runtimeConfig, runtimeConfig.getProviders(), snippetReflection, true, true);
}
Expand Down Expand Up @@ -367,6 +369,16 @@ public void finish(DebugContext debug) {
}
}

public static PhaseSuite<HighTierContext> afterParseCanonicalization() {
PhaseSuite<HighTierContext> phaseSuite = new PhaseSuite<>();
phaseSuite.appendPhase(new DeadStoreRemovalPhase());
phaseSuite.appendPhase(new DevirtualizeCallsPhase());
phaseSuite.appendPhase(new CanonicalizerPhase());
phaseSuite.appendPhase(new StrengthenStampsPhase(false));
phaseSuite.appendPhase(new CanonicalizerPhase());
return phaseSuite;
}

private void printMethodHistogram() {
long sizeAllMethods = 0;
long sizeDeoptMethods = 0;
Expand Down Expand Up @@ -501,16 +513,27 @@ private void checkTrivial(HostedMethod method) {

@SuppressWarnings("try")
private void inlineTrivialMethods(DebugContext debug) throws InterruptedException {
PhaseSuite<HighTierContext> afterParseSuite = afterParseCanonicalization();
for (HostedMethod method : universe.getMethods()) {
try (DebugContext.Scope s = debug.scope("InlineTrivial", method.compilationInfo.getGraph(), method, this)) {
if (method.compilationInfo.getGraph() != null) {
HostedProviders providers = (HostedProviders) runtimeConfig.lookupBackend(method).getProviders();
if (!universe.isPostParseCanonicalized()) {
afterParseSuite.apply(method.compilationInfo.getGraph(), new HighTierContext(providers, afterParseSuite, getOptimisticOpts()));

/* Check that graph is in good shape after parsing. */
assert GraphOrder.assertSchedulableGraph(method.compilationInfo.getGraph());
}

checkTrivial(method);
}
} catch (Throwable e) {
throw debug.handle(e);
}
}

universe.setPostParseCanonicalized();

int round = 0;
do {
inliningProgress = false;
Expand Down Expand Up @@ -687,34 +710,12 @@ private void defaultParseFunction(DebugContext debug, HostedMethod method, Compi
try {
if (needParsing) {
GraphBuilderConfiguration gbConf = createHostedGraphBuilderConfiguration(providers, method);
new HostedGraphBuilderPhase(providers, gbConf, optimisticOpts, null, providers.getWordTypes()).apply(graph);
new HostedGraphBuilderPhase(providers, gbConf, getOptimisticOpts(), 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()) {
Expand Down Expand Up @@ -847,6 +848,10 @@ protected void ensureCompiled(HostedMethod method, CompileReason reason) {
if (method.compilationInfo.specializedArguments != null) {
// Do the specialization: replace the argument locals with the constant arguments.
StructuredGraph graph = method.compilationInfo.graph;

/* Check that graph is in good shape before compilation. */
assert GraphOrder.assertSchedulableGraph(graph);

int idx = 0;
for (ConstantNode argument : method.compilationInfo.specializedArguments) {
ParameterNode local = graph.getParameter(idx++);
Expand Down Expand Up @@ -909,7 +914,7 @@ private CompilationResult defaultCompileFunction(DebugContext debug, HostedMetho
CompilationResult result = backend.newCompilationResult(compilationIdentifier, method.format("%H.%n(%p)"));

try (Indent indent = debug.logAndIndent("compile %s", method)) {
GraalCompiler.compileGraph(graph, method, backend.getProviders(), backend, null, optimisticOpts, method.getProfilingInfo(), suites, lirSuites, result,
GraalCompiler.compileGraph(graph, method, backend.getProviders(), backend, null, getOptimisticOpts(), method.getProfilingInfo(), suites, lirSuites, result,
new HostedCompilationResultBuilderFactory(), false);
}
method.getProfilingInfo().setCompilerIRSize(StructuredGraph.class, method.compilationInfo.graph.getNodeCount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public class HostedUniverse implements Universe {
* Number of allocated bits for instanceof checks.
*/
protected int numInterfaceBits;
private boolean postParseCanonicalized;

public HostedUniverse(Inflation bb) {
this.bb = bb;
Expand Down Expand Up @@ -277,4 +278,12 @@ public OptionValues adjustCompilerOptions(OptionValues optionValues, ResolvedJav
public HostedType objectType() {
return types.get(bb.getUniverse().objectType());
}

public boolean isPostParseCanonicalized() {
return postParseCanonicalized;
}

public void setPostParseCanonicalized() {
postParseCanonicalized = true;
}
}

0 comments on commit 55b7956

Please sign in to comment.