changeset 13146:ffbfc3e78746

extend replacements API to support svm specific snippet handling
author Erik Eckstein <erik.eckstein@oracle.com>
date Mon, 25 Nov 2013 13:54:02 +0100
parents 3e5555577ebc
children 371db31081be
files graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/Replacements.java graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java
diffstat 3 files changed, 36 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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}
--- 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<ResolvedJavaMethod, StructuredGraph> graphs;
+    protected final ConcurrentMap<ResolvedJavaMethod, StructuredGraph> graphs;
 
     // These data structures are all fully initialized during single-threaded
     // compiler startup and so do not need to be concurrent.
-    private final Map<ResolvedJavaMethod, ResolvedJavaMethod> registeredMethodSubstitutions;
+    protected final Map<ResolvedJavaMethod, ResolvedJavaMethod> registeredMethodSubstitutions;
     private final Map<ResolvedJavaMethod, Class<? extends FixedWithNextNode>> registeredMacroSubstitutions;
     private final Set<ResolvedJavaMethod> forcedSubstitutions;
     private final Map<Class<? extends SnippetTemplateCache>, 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) {
--- 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];