changeset 14077:3ea5f337cc0d

Truffle-DSL: generate better implementations for getKind()
author Christian Humer <christian.humer@gmail.com>
date Wed, 05 Mar 2014 23:33:25 +0100
parents 61bc19c3dcdc
children f157fabf6b38
files graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeCodeGenerator.java
diffstat 1 files changed, 27 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeCodeGenerator.java	Wed Mar 05 23:33:25 2014 +0100
+++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeCodeGenerator.java	Wed Mar 05 23:33:25 2014 +0100
@@ -953,12 +953,32 @@
             if (node.getGenericSpecialization() != null && node.getGenericSpecialization().isReachable()) {
                 clazz.add(createGenericExecute(node, rootGroup));
             }
+
+            clazz.add(createGetKind(node, null, Kind.SPECIALIZED));
         }
 
         protected boolean needsInvokeCopyConstructorMethod() {
             return getModel().getNode().isPolymorphic();
         }
 
+        protected CodeExecutableElement createGetKind(NodeData node, SpecializationData specialization, Kind kind) {
+            CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), context.getTruffleTypes().getNodeInfoKind(), "getKind");
+
+            TypeMirror nodeInfoKind = context.getTruffleTypes().getNodeInfoKind();
+
+            CodeTreeBuilder builder = method.createBuilder();
+            if (node.isPolymorphic() && specialization == null) {
+                // assume next0 exists
+                builder.startIf().string("next0 != null && next0.getKind() == ").staticReference(nodeInfoKind, "SPECIALIZED").end();
+                builder.startBlock();
+                builder.startReturn().staticReference(nodeInfoKind, "POLYMORPHIC").end();
+                builder.end();
+            }
+
+            builder.startReturn().staticReference(nodeInfoKind, kind.name()).end();
+            return method;
+        }
+
         protected CodeExecutableElement createInvokeCopyConstructor(TypeMirror baseType, SpecializationData specialization) {
             CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED), baseType, "invokeCopyConstructor");
             if (specialization == null) {
@@ -2503,7 +2523,7 @@
             }
 
             createCachedExecuteMethods(specialization);
-
+            clazz.add(createGetKind(specialization.getNode(), specialization, Kind.SPECIALIZED));
         }
 
         private ExecutableElement createUpdateType(ActualParameter parameter) {
@@ -2587,6 +2607,12 @@
             if (needsInvokeCopyConstructorMethod()) {
                 clazz.add(createInvokeCopyConstructor(nodeGen.asType(), specialization));
             }
+
+            if (specialization.isGeneric()) {
+                clazz.add(createGetKind(specialization.getNode(), specialization, Kind.GENERIC));
+            } else if (specialization.isUninitialized()) {
+                clazz.add(createGetKind(specialization.getNode(), specialization, Kind.UNINITIALIZED));
+            }
         }
 
         protected void createConstructors(CodeTypeElement clazz) {