diff graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetTemplate.java @ 7141:c85aecfee9e4

made snippet template specialization support ConstantParameters of type Word added access to the specialized graph from outside a SnippetTemplate allowed an AbstractTemplate subclass to be a snippet holder (i.e., implements SnippetsInterface)
author Doug Simon <doug.simon@oracle.com>
date Fri, 07 Dec 2012 11:12:26 +0100
parents 3656236c7d27
children 9c06e8bd8769
line wrap: on
line diff
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetTemplate.java	Fri Dec 07 11:09:17 2012 +0100
+++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetTemplate.java	Fri Dec 07 11:12:26 2012 +0100
@@ -185,12 +185,17 @@
         protected final Cache cache;
         protected final MetaAccessProvider runtime;
         protected final Assumptions assumptions;
-        protected Class<T> snippetsClass;
+        protected Class<?> snippetsClass;
 
         public AbstractTemplates(MetaAccessProvider runtime, Assumptions assumptions, TargetDescription target, Class<T> snippetsClass) {
             this.runtime = runtime;
             this.assumptions = assumptions;
-            this.snippetsClass = snippetsClass;
+            if (snippetsClass == null) {
+                assert this instanceof SnippetsInterface;
+                this.snippetsClass = getClass();
+            } else {
+                this.snippetsClass = snippetsClass;
+            }
             this.cache = new Cache(runtime, target);
         }
 
@@ -243,7 +248,13 @@
                 String name = c.value();
                 Object arg = key.get(name);
                 Kind kind = signature.getParameterKind(i);
-                replacements.put(snippetGraph.getLocal(i), ConstantNode.forConstant(Constant.forBoxed(kind, arg), runtime, snippetCopy));
+                Constant constantArg;
+                if (arg instanceof Constant) {
+                    constantArg = (Constant) arg;
+                } else {
+                    constantArg = Constant.forBoxed(kind, arg);
+                }
+                replacements.put(snippetGraph.getLocal(i), ConstantNode.forConstant(constantArg, runtime, snippetCopy));
             } else {
                 VarargsParameter vp = MetaUtil.getParameterAnnotation(VarargsParameter.class, i, method);
                 if (vp != null) {
@@ -390,8 +401,12 @@
     }
 
     private static boolean checkConstantArgument(final ResolvedJavaMethod method, Signature signature, int i, String name, Object arg, Kind kind) {
+        ResolvedJavaType type = signature.getParameterType(i, method.getDeclaringClass()).resolve(method.getDeclaringClass());
+        if (WordTypeRewriterPhase.isWord(type)) {
+            assert arg instanceof Constant : method + ": word constant parameters must be passed boxed in a Constant value: " + arg;
+            return true;
+        }
         if (kind == Kind.Object) {
-            ResolvedJavaType type = signature.getParameterType(i, method.getDeclaringClass()).resolve(method.getDeclaringClass());
             assert arg == null || type.isInstance(Constant.forObject(arg)) :
                 method + ": wrong value type for " + name + ": expected " + type.getName() + ", got " + arg.getClass().getName();
         } else {
@@ -581,6 +596,13 @@
     }
 
     /**
+     * Gets a copy of the specialized graph.
+     */
+    public StructuredGraph copySpecializedGraph() {
+        return snippet.copy();
+    }
+
+    /**
      * Replaces a given floating node with this specialized snippet.
      *
      * @param runtime