changeset 20033:39c0ccfcd070

Allow InputTypes that are not Value in snippets.
author Roland Schatz <roland.schatz@oracle.com>
date Wed, 25 Mar 2015 16:55:24 +0100
parents 4d119424b4ce
children 975ffde6d791
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java graal/com.oracle.graal.nodeinfo/src/com/oracle/graal/nodeinfo/StructuralInput.java graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/DefaultGenericInvocationPlugin.java
diffstat 3 files changed, 127 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java	Wed Mar 25 11:48:13 2015 -0700
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java	Wed Mar 25 16:55:24 2015 +0100
@@ -70,7 +70,7 @@
         plugins.setLoadFieldPlugin(new HotSpotLoadFieldPlugin(metaAccess, constantReflection));
         plugins.setLoadIndexedPlugin(new HotSpotLoadIndexedPlugin(wordTypes));
         plugins.setInlineInvokePlugin(new DefaultInlineInvokePlugin(replacements));
-        plugins.setGenericInvocationPlugin(new DefaultGenericInvocationPlugin(nodeIntrinsification, wordOperationPlugin));
+        plugins.setGenericInvocationPlugin(new DefaultGenericInvocationPlugin(metaAccess, nodeIntrinsification, wordOperationPlugin));
 
         registerObjectPlugins(invocationPlugins);
         registerSystemPlugins(invocationPlugins, foreignCalls);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.nodeinfo/src/com/oracle/graal/nodeinfo/StructuralInput.java	Wed Mar 25 16:55:24 2015 +0100
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.nodeinfo;
+
+import java.lang.annotation.*;
+
+/**
+ * Marker type for describing node inputs in snippets that are not of type {@link InputType#Value}.
+ */
+public abstract class StructuralInput {
+
+    private StructuralInput() {
+        throw new Error("Illegal instance of StructuralInput. This class should be used in snippets only.");
+    }
+
+    @Retention(RetentionPolicy.RUNTIME)
+    @Target(ElementType.TYPE)
+    public @interface MarkerType {
+        InputType value();
+    }
+
+    /**
+     * Marker type for {@link InputType#Memory} edges in snippets.
+     */
+    @MarkerType(InputType.Memory)
+    public abstract static class Memory extends StructuralInput {
+    }
+
+    /**
+     * Marker type for {@link InputType#Condition} edges in snippets.
+     */
+    @MarkerType(InputType.Condition)
+    public abstract static class Condition extends StructuralInput {
+    }
+
+    /**
+     * Marker type for {@link InputType#State} edges in snippets.
+     */
+    @MarkerType(InputType.State)
+    public abstract static class State extends StructuralInput {
+    }
+
+    /**
+     * Marker type for {@link InputType#Guard} edges in snippets.
+     */
+    @MarkerType(InputType.Guard)
+    public abstract static class Guard extends StructuralInput {
+    }
+
+    /**
+     * Marker type for {@link InputType#Anchor} edges in snippets.
+     */
+    @MarkerType(InputType.Anchor)
+    public abstract static class Anchor extends StructuralInput {
+    }
+
+    /**
+     * Marker type for {@link InputType#Association} edges in snippets.
+     */
+    @MarkerType(InputType.Association)
+    public abstract static class Association extends StructuralInput {
+    }
+
+    /**
+     * Marker type for {@link InputType#Extension} edges in snippets.
+     */
+    @MarkerType(InputType.Extension)
+    public abstract static class Extension extends StructuralInput {
+    }
+}
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/DefaultGenericInvocationPlugin.java	Wed Mar 25 11:48:13 2015 -0700
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/DefaultGenericInvocationPlugin.java	Wed Mar 25 16:55:24 2015 +0100
@@ -29,9 +29,12 @@
 
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.api.replacements.*;
+import com.oracle.graal.compiler.common.*;
 import com.oracle.graal.compiler.common.type.*;
 import com.oracle.graal.graph.Node.NodeIntrinsic;
 import com.oracle.graal.graphbuilderconf.*;
+import com.oracle.graal.nodeinfo.*;
+import com.oracle.graal.nodeinfo.StructuralInput.MarkerType;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.extended.*;
 import com.oracle.graal.word.*;
@@ -44,9 +47,13 @@
     protected final NodeIntrinsificationPhase nodeIntrinsification;
     protected final WordOperationPlugin wordOperationPlugin;
 
-    public DefaultGenericInvocationPlugin(NodeIntrinsificationPhase nodeIntrinsification, WordOperationPlugin wordOperationPlugin) {
+    private final ResolvedJavaType structuralInputType;
+
+    public DefaultGenericInvocationPlugin(MetaAccessProvider metaAccess, NodeIntrinsificationPhase nodeIntrinsification, WordOperationPlugin wordOperationPlugin) {
         this.nodeIntrinsification = nodeIntrinsification;
         this.wordOperationPlugin = wordOperationPlugin;
+
+        this.structuralInputType = metaAccess.lookupJavaType(StructuralInput.class);
     }
 
     public boolean apply(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args) {
@@ -91,6 +98,24 @@
         return false;
     }
 
+    private InputType getInputType(ObjectStamp stamp) {
+        ResolvedJavaType type = stamp.type();
+        if (type != null && structuralInputType.isAssignableFrom(type)) {
+            while (type != null) {
+                MarkerType markerType = type.getAnnotation(MarkerType.class);
+                if (markerType != null) {
+                    return markerType.value();
+                }
+
+                type = type.getSuperclass();
+            }
+
+            throw GraalInternalError.shouldNotReachHere(String.format("%s extends StructuralInput, but is not annotated with @MarkerType", stamp.type()));
+        } else {
+            return InputType.Value;
+        }
+    }
+
     protected boolean processNodeIntrinsic(GraphBuilderContext b, ResolvedJavaMethod method, NodeIntrinsic intrinsic, List<ValueNode> args, Kind returnKind, Stamp stamp) {
         ValueNode res = createNodeIntrinsic(b, method, intrinsic, args, stamp);
         if (res == null) {
@@ -107,7 +132,16 @@
         }
 
         res = b.append(res);
-        if (returnKind != Kind.Void) {
+
+        InputType inputType = InputType.Value;
+        if (returnKind == Kind.Object && stamp instanceof ObjectStamp) {
+            inputType = getInputType((ObjectStamp) stamp);
+        }
+
+        if (inputType != InputType.Value) {
+            assert res.isAllowedUsageType(inputType);
+            b.push(Kind.Object, res);
+        } else if (returnKind != Kind.Void) {
             assert res.getKind().getStackKind() != Kind.Void;
             b.push(returnKind.getStackKind(), res);
         } else {