changeset 22001:4b4ef02158bd

LIRTest: add LIRValueNode.
author Josef Eisl <josef.eisl@jku.at>
date Thu, 18 Jun 2015 10:00:11 +0200
parents 5ab48fcf8fcd
children 6a9e2f3bc32b
files graal/com.oracle.graal.lir.jtt/src/com/oracle/graal/lir/jtt/LIRTest.java graal/com.oracle.graal.lir.jtt/src/com/oracle/graal/lir/jtt/LIRTestSpecification.java
diffstat 2 files changed, 96 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.lir.jtt/src/com/oracle/graal/lir/jtt/LIRTest.java	Wed Jun 17 16:37:27 2015 +0200
+++ b/graal/com.oracle.graal.lir.jtt/src/com/oracle/graal/lir/jtt/LIRTest.java	Thu Jun 18 10:00:11 2015 +0200
@@ -22,6 +22,8 @@
  */
 package com.oracle.graal.lir.jtt;
 
+import static com.oracle.graal.lir.LIRValueUtil.*;
+
 import java.lang.annotation.*;
 import java.lang.reflect.*;
 import java.util.stream.*;
@@ -83,7 +85,45 @@
         }
     }
 
-    private final InvocationPlugin lirTestPlugin = new InvocationPlugin() {
+    @NodeInfo
+    private static final class LIRValueNode extends FixedWithNextNode implements LIRLowerable {
+
+        public static final NodeClass<LIRValueNode> TYPE = NodeClass.create(LIRValueNode.class);
+        @Input protected ValueNode opsNode;
+        @Input protected ValueNode name;
+        public final SnippetReflectionProvider snippetReflection;
+
+        public LIRValueNode(SnippetReflectionProvider snippetReflection, Kind kind, ValueNode opsNode, ValueNode name) {
+            super(TYPE, StampFactory.forKind(kind));
+            this.opsNode = opsNode;
+            this.name = name;
+            this.snippetReflection = snippetReflection;
+        }
+
+        public ValueNode getLIROpsNode() {
+            return opsNode;
+        }
+
+        @Override
+        public void generate(NodeLIRBuilderTool gen) {
+            LIRTestSpecification spec = getLIROperations();
+            Value output = spec.getOutput(getName());
+            gen.setResult(this, isVariable(output) ? output : gen.getLIRGeneratorTool().emitMove(output));
+        }
+
+        private String getName() {
+            assert name.isConstant();
+            return snippetReflection.asObject(String.class, name.asJavaConstant());
+        }
+
+        private LIRTestSpecification getLIROperations() {
+            assert getLIROpsNode().isConstant();
+            return snippetReflection.asObject(LIRTestSpecification.class, getLIROpsNode().asJavaConstant());
+        }
+
+    }
+
+    private InvocationPlugin lirTestPlugin = new InvocationPlugin() {
         public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode spec) {
             Kind returnKind = targetMethod.getSignature().getReturnKind();
             b.addPush(returnKind, new LIRTestNode(getSnippetReflection(), returnKind, spec, new ValueNode[]{}));
@@ -131,9 +171,53 @@
                 invocationPlugins.register(lirTestPlugin, c, m.getName(), p);
             }
         }
+        InvocationPlugin outputPlugin = new InvocationPlugin() {
+            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode spec, ValueNode name, ValueNode expected) {
+                Kind returnKind = targetMethod.getSignature().getReturnKind();
+                b.addPush(returnKind, new LIRValueNode(getSnippetReflection(), returnKind, spec, name));
+                return true;
+            }
+        };
+        invocationPlugins.register(outputPlugin, LIRTest.class, "getOutput", new Class<?>[]{LIRTestSpecification.class, String.class, Object.class});
+        invocationPlugins.register(outputPlugin, LIRTest.class, "getOutput", new Class<?>[]{LIRTestSpecification.class, String.class, int.class});
         return super.editGraphBuilderConfiguration(conf);
     }
 
+    @SuppressWarnings("unused")
+    public static byte getOutput(LIRTestSpecification spec, String name, byte expected) {
+        return expected;
+    }
+
+    @SuppressWarnings("unused")
+    public static short getOutput(LIRTestSpecification spec, String name, short expected) {
+        return expected;
+    }
+
+    @SuppressWarnings("unused")
+    public static int getOutput(LIRTestSpecification spec, String name, int expected) {
+        return expected;
+    }
+
+    @SuppressWarnings("unused")
+    public static long getOutput(LIRTestSpecification spec, String name, long expected) {
+        return expected;
+    }
+
+    @SuppressWarnings("unused")
+    public static float getOutput(LIRTestSpecification spec, String name, float expected) {
+        return expected;
+    }
+
+    @SuppressWarnings("unused")
+    public static double getOutput(LIRTestSpecification spec, String name, double expected) {
+        return expected;
+    }
+
+    @SuppressWarnings("unused")
+    public static Object getOutput(LIRTestSpecification spec, String name, Object expected) {
+        return expected;
+    }
+
     @java.lang.annotation.Retention(RetentionPolicy.RUNTIME)
     @java.lang.annotation.Target(ElementType.METHOD)
     public static @interface LIRIntrinsic {
--- a/graal/com.oracle.graal.lir.jtt/src/com/oracle/graal/lir/jtt/LIRTestSpecification.java	Wed Jun 17 16:37:27 2015 +0200
+++ b/graal/com.oracle.graal.lir.jtt/src/com/oracle/graal/lir/jtt/LIRTestSpecification.java	Thu Jun 18 10:00:11 2015 +0200
@@ -22,12 +22,15 @@
  */
 package com.oracle.graal.lir.jtt;
 
+import java.util.*;
+
 import com.oracle.graal.lir.gen.*;
 import com.oracle.jvmci.common.*;
 import com.oracle.jvmci.meta.*;
 
 public abstract class LIRTestSpecification {
     private Value result;
+    private final HashMap<String, Value> output = new HashMap<>();
 
     public void generate(LIRGeneratorTool gen) {
         defaultHandler(gen);
@@ -76,6 +79,14 @@
 
     }
 
+    public void setOutput(String name, Value value) {
+        output.put(name, value);
+    }
+
+    public Value getOutput(String name) {
+        return output.get(name);
+    }
+
     public void setResult(Value value) {
         result = value;
     }