changeset 11896:280f97f13d54

Fixes to PTX control flow logic
author Morris Meyer <morris.meyer@oracle.com>
date Sat, 05 Oct 2013 16:51:42 -0400
parents 8e15a8b570e1
children 1ec42a9f6149
files graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/PTXAssembler.java graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ArrayPTXTest.java graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ControlPTXTest.java graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/FloatPTXTest.java graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/IntegerPTXTest.java graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/LogicPTXTest.java graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXTestBase.java graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXLIRGenerator.java graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXControlFlow.java
diffstat 9 files changed, 60 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/PTXAssembler.java	Sat Oct 05 10:37:38 2013 -0400
+++ b/graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/PTXAssembler.java	Sat Oct 05 16:51:42 2013 -0400
@@ -308,6 +308,27 @@
         }
     }
 
+    public static class BinarySingleOperandFormat extends SingleOperandFormat {
+
+        public BinarySingleOperandFormat(Variable dst, Value src) {
+            super(dst, src);
+        }
+
+        @Override
+        public String typeForKind(Kind k) {
+            switch (k.getTypeChar()) {
+                case 's':
+                    return "b16";
+                case 'i':
+                    return "b32";
+                case 'j':
+                    return "b64";
+                default:
+                    throw GraalInternalError.shouldNotReachHere();
+            }
+        }
+    }
+
     public static class ConversionFormat extends SingleOperandFormat {
 
         public ConversionFormat(Variable dst, Value src) {
@@ -490,7 +511,10 @@
 
     // Checkstyle: stop method name check
     public final void bra(String tgt, int pred) {
-        emitString((pred >= 0) ? "" : ("@%p" + pred + "  ") + "bra" + " " + tgt + ";" + "");
+        System.err.println("BRA: " + tgt + " pred: " + pred);
+        assert pred >= 0;
+
+        emitString("@%p" + pred + " " + "bra" + " " + tgt + ";");
     }
 
     public final void bra_uni(String tgt) {
@@ -536,7 +560,7 @@
         }
     }
     
-    public static class Not extends SingleOperandFormat {
+    public static class Not extends BinarySingleOperandFormat {
 
         public Not(Variable dst, Variable src) {
             super(dst, src);
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ArrayPTXTest.java	Sat Oct 05 10:37:38 2013 -0400
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ArrayPTXTest.java	Sat Oct 05 16:51:42 2013 -0400
@@ -71,12 +71,6 @@
     }
 
 
-    public static void printReport(String message) {
-        // CheckStyle: stop system..print check
-        System.out.println(message);
-        // CheckStyle: resume system..print check
-    }
-
     public static void main(String[] args) {
         ArrayPTXTest test = new ArrayPTXTest();
         for (Method m : ArrayPTXTest.class.getMethods()) {
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ControlPTXTest.java	Sat Oct 05 10:37:38 2013 -0400
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ControlPTXTest.java	Sat Oct 05 16:51:42 2013 -0400
@@ -28,13 +28,23 @@
 
 public class ControlPTXTest extends PTXTestBase {
 
-    @Ignore
     @Test
     public void testControl() {
-        compile("testLoop");
+        Integer ret = (Integer) invoke(compile("testLoop"), 42);
+        if (ret != null) {
+            printReport("testLoop: " + ret);
+        } else {
+            printReport("testLoop: no VALUE");
+        }
+        ret =  (Integer) invoke(compile("testSwitchDefault1I"), 3);
+        if (ret != null) {
+            printReport("testSwitchDefault1I: " + ret);
+        } else {
+            printReport("testSwitchDefault1I: no VALUE");
+        }
+        compile("testStatic");
+        compile("testCall");
         // compile("testSwitch1I");
-        // compile("testStatic");
-        // compile("testCall");
         // compile("testLookupSwitch1I");
     }
 
@@ -47,6 +57,13 @@
         return sum;
     }
 
+    public static int testSwitchDefault1I(int a) {
+        switch (a) {
+            default:
+                return 4;
+        }
+    }
+
     public static int testSwitch1I(int a) {
         switch (a) {
             case 1:
@@ -100,7 +117,7 @@
         return a + b;
     }
 
-    public static int testCall(@SuppressWarnings("unused") Object o, int a, int b) {
+    public static int testCall(int a, int b) {
         return method(a, b);
     }
 
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/FloatPTXTest.java	Sat Oct 05 10:37:38 2013 -0400
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/FloatPTXTest.java	Sat Oct 05 16:51:42 2013 -0400
@@ -358,13 +358,6 @@
         return (float) a;
     }
 
-    public static void printReport(String message) {
-        // CheckStyle: stop system..print check
-        System.out.println(message);
-        // CheckStyle: resume system..print check
-
-    }
-
     public static void main(String[] args) {
         FloatPTXTest test = new FloatPTXTest();
         for (Method m : FloatPTXTest.class.getMethods()) {
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/IntegerPTXTest.java	Sat Oct 05 10:37:38 2013 -0400
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/IntegerPTXTest.java	Sat Oct 05 16:51:42 2013 -0400
@@ -346,12 +346,6 @@
         return (int) a;
     }
 
-    public static void printReport(String message) {
-        // CheckStyle: stop system..print check
-        System.out.println(message);
-        // CheckStyle: resume system..print check
-
-    }
 
     public static void main(String[] args) {
         IntegerPTXTest test = new IntegerPTXTest();
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/LogicPTXTest.java	Sat Oct 05 10:37:38 2013 -0400
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/LogicPTXTest.java	Sat Oct 05 16:51:42 2013 -0400
@@ -24,11 +24,9 @@
 
 import java.lang.reflect.Method;
 
-import org.junit.Ignore;
 import org.junit.Test;
 
 /* PTX ISA 3.1 - 8.7.5 Logic and Shift Instructions */
-@Ignore
 public class LogicPTXTest extends PTXTestBase {
 
     @Test
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXTestBase.java	Sat Oct 05 10:37:38 2013 -0400
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXTestBase.java	Sat Oct 05 16:51:42 2013 -0400
@@ -55,6 +55,13 @@
 
     private StructuredGraph sg;
 
+    public void printReport(String message) {
+        // CheckStyle: stop system..print check
+        System.out.println(message);
+        // CheckStyle: resume system..print check
+
+    }
+
     protected CompilationResult compile(String test) {
         if (runtime instanceof PTXHotSpotRuntime) {
             StructuredGraph graph = parse(test);
--- a/graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXLIRGenerator.java	Sat Oct 05 10:37:38 2013 -0400
+++ b/graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXLIRGenerator.java	Sat Oct 05 16:51:42 2013 -0400
@@ -765,10 +765,10 @@
         // Making a copy of the switch value is necessary because jump table destroys the input
         // value
         if (key.getKind() == Kind.Int || key.getKind() == Kind.Long) {
-            append(new SequentialSwitchOp(keyConstants, keyTargets, defaultTarget, key, Value.ILLEGAL, nextPredRegNum));
+            append(new SequentialSwitchOp(keyConstants, keyTargets, defaultTarget, key, Value.ILLEGAL, nextPredRegNum++));
         } else {
             assert key.getKind() == Kind.Object : key.getKind();
-            append(new SequentialSwitchOp(keyConstants, keyTargets, defaultTarget, key, newVariable(Kind.Object), nextPredRegNum));
+            append(new SequentialSwitchOp(keyConstants, keyTargets, defaultTarget, key, newVariable(Kind.Object), nextPredRegNum++));
         }
     }
 
--- a/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXControlFlow.java	Sat Oct 05 10:37:38 2013 -0400
+++ b/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXControlFlow.java	Sat Oct 05 16:51:42 2013 -0400
@@ -230,7 +230,9 @@
     }
 
     @SuppressWarnings("unused")
-    private static void tableswitch(TargetMethodAssembler tasm, PTXAssembler masm, int lowKey, LabelRef defaultTarget, LabelRef[] targets, Value value, Value scratch, int predNum) {
+    private static void tableswitch(TargetMethodAssembler tasm, PTXAssembler masm, int lowKey,
+                                    LabelRef defaultTarget, LabelRef[] targets,
+                                    Value value, Value scratch, int predNum) {
         Buffer buf = masm.codeBuffer;
         // Compare index against jump table bounds
         int highKey = lowKey + targets.length - 1;