# HG changeset patch # User Erik Eckstein # Date 1385384042 -3600 # Node ID ffbfc3e78746868b56e1ca41820b171ed8ffe94c # Parent 3e5555577ebc29f3ca62799e38e99bc505def43f extend replacements API to support svm specific snippet handling diff -r 3e5555577ebc -r ffbfc3e78746 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/Replacements.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/Replacements.java Mon Nov 25 13:53:06 2013 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/Replacements.java Mon Nov 25 13:54:02 2013 +0100 @@ -42,6 +42,19 @@ StructuredGraph getSnippet(ResolvedJavaMethod method); /** + * Registers a method as snippet. + */ + void registerSnippet(ResolvedJavaMethod method); + + /** + * Prepares the copy of a snippet graph immediately after instantiation. This can be used to do + * node intrinsification for example. + * + * @param snippetCopy The copy of the snippet graph. + */ + void prepareSnippetCopyAfterInstantiation(StructuredGraph snippetCopy); + + /** * Gets the graph that is a substitution for a given method. * * @return the graph, if any, that is a substitution for {@code method} diff -r 3e5555577ebc -r ffbfc3e78746 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java Mon Nov 25 13:53:06 2013 +0100 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java Mon Nov 25 13:54:02 2013 +0100 @@ -60,11 +60,11 @@ /** * The preprocessed replacement graphs. */ - private final ConcurrentMap graphs; + protected final ConcurrentMap graphs; // These data structures are all fully initialized during single-threaded // compiler startup and so do not need to be concurrent. - private final Map registeredMethodSubstitutions; + protected final Map registeredMethodSubstitutions; private final Map> registeredMacroSubstitutions; private final Set forcedSubstitutions; private final Map, SnippetTemplateCache> snippetTemplateCache; @@ -83,6 +83,7 @@ private static final boolean UseSnippetGraphCache = Boolean.parseBoolean(System.getProperty("graal.useSnippetGraphCache", "true")); private static final DebugTimer SnippetPreparationTime = Debug.timer("SnippetPreparationTime"); + @Override public StructuredGraph getSnippet(ResolvedJavaMethod method) { assert method.getAnnotation(Snippet.class) != null : "Snippet must be annotated with @" + Snippet.class.getSimpleName(); assert !Modifier.isAbstract(method.getModifiers()) && !Modifier.isNative(method.getModifiers()) : "Snippet must not be abstract or native"; @@ -102,6 +103,22 @@ return graph; } + @Override + public void registerSnippet(ResolvedJavaMethod method) { + // No initialization needed as snippet graphs are created on demand in getSnippet + } + + @Override + public void prepareSnippetCopyAfterInstantiation(StructuredGraph snippetCopy) { + + // Do deferred intrinsification of node intrinsics + + new NodeIntrinsificationPhase(providers).apply(snippetCopy); + new CanonicalizerPhase(true).apply(snippetCopy, new PhaseContext(providers, assumptions)); + NodeIntrinsificationVerificationPhase.verify(snippetCopy); + } + + @Override public StructuredGraph getMethodSubstitution(ResolvedJavaMethod original) { ResolvedJavaMethod substitute = registeredMethodSubstitutions.get(original); if (substitute == null) { diff -r 3e5555577ebc -r ffbfc3e78746 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java Mon Nov 25 13:53:06 2013 +0100 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java Mon Nov 25 13:54:02 2013 +0100 @@ -398,7 +398,9 @@ } } assert found != null : "did not find @" + Snippet.class.getSimpleName() + " method in " + declaringClass + (methodName == null ? "" : " named " + methodName); - return new SnippetInfo(providers.getMetaAccess().lookupJavaMethod(found)); + ResolvedJavaMethod javaMethod = providers.getMetaAccess().lookupJavaMethod(found); + providers.getReplacements().registerSnippet(javaMethod); + return new SnippetInfo(javaMethod); } /** @@ -512,12 +514,8 @@ Debug.dump(snippetCopy, "Before specialization"); if (!nodeReplacements.isEmpty()) { - // Do deferred intrinsification of node intrinsics - new CanonicalizerPhase(true).apply(snippetCopy, phaseContext); - new NodeIntrinsificationPhase(providers).apply(snippetCopy); - new CanonicalizerPhase(true).apply(snippetCopy, phaseContext); + providers.getReplacements().prepareSnippetCopyAfterInstantiation(snippetCopy); } - NodeIntrinsificationVerificationPhase.verify(snippetCopy); // Gather the template parameters parameters = new Object[parameterCount];