changeset 7751:ef1b41ea0a90

Implemented an option to turn off generated generic generation using specializations in @Generic.
author Christian Humer <christian.humer@gmail.com>
date Fri, 08 Feb 2013 16:07:33 +0100
parents bdcb3cc47e16
children 388848bbe03d
files graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/Generic.java graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/GenericParser.java graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeCodeGenerator.java graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/SpecializationData.java
diffstat 4 files changed, 38 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/Generic.java	Fri Feb 08 15:59:43 2013 +0100
+++ b/graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/Generic.java	Fri Feb 08 16:07:33 2013 +0100
@@ -30,4 +30,7 @@
 @Retention(RetentionPolicy.CLASS)
 @Target({ElementType.METHOD})
 public @interface Generic {
+
+    boolean useSpecializations() default true;
+
 }
--- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/GenericParser.java	Fri Feb 08 15:59:43 2013 +0100
+++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/GenericParser.java	Fri Feb 08 16:07:33 2013 +0100
@@ -53,7 +53,9 @@
 
     @Override
     public SpecializationData create(TemplateMethod method) {
-        return new SpecializationData(method, true, false);
+        SpecializationData data = new SpecializationData(method, true, false);
+        data.setUseSpecializationsForGeneric(Utils.getAnnotationValueBoolean(data.getMarkerAnnotation(), "useSpecializations"));
+        return data;
     }
 
     @Override
--- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeCodeGenerator.java	Fri Feb 08 15:59:43 2013 +0100
+++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeCodeGenerator.java	Fri Feb 08 16:07:33 2013 +0100
@@ -427,27 +427,32 @@
             addValueParameters(method, node.getGenericSpecialization(), true);
 
             CodeTreeBuilder builder = method.createBuilder();
-            boolean ifStarted = false;
-            for (int i = 0; i < node.getSpecializations().length; i++) {
-                SpecializationData specialization = node.getSpecializations()[i];
-                if (specialization.isUninitialized()) {
-                    continue;
-                }
-                if (!specialization.isGeneric()) {
-                    if (!ifStarted) {
-                        builder.startIf();
-                        ifStarted = true;
+
+            if (node.getGenericSpecialization().isUseSpecializationsForGeneric()) {
+                boolean ifStarted = false;
+                for (int i = 0; i < node.getSpecializations().length; i++) {
+                    SpecializationData specialization = node.getSpecializations()[i];
+                    if (specialization.isUninitialized()) {
+                        continue;
+                    }
+                    if (!specialization.isGeneric()) {
+                        if (!ifStarted) {
+                            builder.startIf();
+                            ifStarted = true;
+                        } else {
+                            builder.startElseIf();
+                        }
+                        emitGuards(getContext(), builder, "", specialization, false, true);
+                        builder.end().startBlock();
                     } else {
-                        builder.startElseIf();
+                        builder.startElseBlock();
                     }
-                    emitGuards(getContext(), builder, "", specialization, false, true);
-                    builder.end().startBlock();
-                } else {
-                    builder.startElseBlock();
+
+                    emitInvokeDoMethod(builder, specialization, 0);
+                    builder.end();
                 }
-
-                emitInvokeDoMethod(builder, specialization, 0);
-                builder.end();
+            } else {
+                emitInvokeDoMethod(builder, node.getGenericSpecialization(), 0);
             }
             return method;
         }
--- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/SpecializationData.java	Fri Feb 08 15:59:43 2013 +0100
+++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/SpecializationData.java	Fri Feb 08 16:07:33 2013 +0100
@@ -33,7 +33,7 @@
     private final SpecializationThrowsData[] exceptions;
     private SpecializationGuardData[] guards;
     private ShortCircuitData[] shortCircuits;
-
+    private boolean useSpecializationsForGeneric = true;
     private NodeData node;
 
     public SpecializationData(TemplateMethod template, int order, SpecializationThrowsData[] exceptions) {
@@ -97,6 +97,14 @@
         return shortCircuits;
     }
 
+    void setUseSpecializationsForGeneric(boolean useSpecializationsForGeneric) {
+        this.useSpecializationsForGeneric = useSpecializationsForGeneric;
+    }
+
+    public boolean isUseSpecializationsForGeneric() {
+        return useSpecializationsForGeneric;
+    }
+
     public SpecializationData findNextSpecialization() {
         SpecializationData[] specializations = node.getSpecializations();
         for (int i = 0; i < specializations.length - 1; i++) {