changeset 3119:00ad6539b7dc

Changed genInstanceOf such that it does not longer automatically materialize the result.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Thu, 30 Jun 2011 16:49:13 +0200
parents ce12808b8ff2
children 6930b31c2fd5
files graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/ControlFlowOptimizer.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/LIRXirInstruction.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRAssembler.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64XirAssembler.java graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotXirGenerator.java
diffstat 7 files changed, 54 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/ControlFlowOptimizer.java	Thu Jun 30 16:07:18 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/ControlFlowOptimizer.java	Thu Jun 30 16:49:13 2011 +0200
@@ -130,6 +130,8 @@
                             ((LIRBranch) instr).substitute(block, newTarget);
                         } else if (instr instanceof LIRTableSwitch) {
                             ((LIRTableSwitch) instr).substitute(block, newTarget);
+                        } else if (instr instanceof LIRXirInstruction) {
+                            ((LIRXirInstruction) instr).substitute(block, newTarget);
                         }
                     }
                 }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Thu Jun 30 16:07:18 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Thu Jun 30 16:49:13 2011 +0200
@@ -355,9 +355,16 @@
 
     @Override
     public void visitInstanceOf(InstanceOf x) {
-        XirArgument obj = toXirArgument(x.object());
-        XirSnippet snippet = xir.genInstanceOf(site(x), obj, toXirArgument(x.targetClassInstruction()), x.targetClass());
-        emitXir(snippet, x, stateFor(x), null, true);
+        LIRBlock trueSuccessor = new LIRBlock(new Label(), null);
+        emitInstanceOf(x, trueSuccessor, null);
+
+        CiValue result = createResultVariable(x);
+        lir.move(CiConstant.FALSE, result);
+        Label label = new Label();
+        lir.branch(Condition.TRUE, label);
+        lir.branchDestination(trueSuccessor.label);
+        lir.move(CiConstant.TRUE, result);
+        lir.branchDestination(label);
     }
 
     @Override
@@ -480,14 +487,25 @@
         lir.branch(cond, trueSuccessor);
     }
 
-    public void emitBooleanBranch(BooleanNode node, LIRBlock trueSuccessor, LIRBlock falseSuccessor) {
+    public void emitBooleanBranch(Node node, LIRBlock trueSuccessor, LIRBlock falseSuccessor) {
         if (node instanceof Compare) {
             emitCompare((Compare) node, trueSuccessor, falseSuccessor);
+        } else if (node instanceof InstanceOf) {
+            emitInstanceOf((InstanceOf) node, trueSuccessor, falseSuccessor);
         } else {
             throw Util.unimplemented(node.toString());
         }
     }
 
+    private void emitInstanceOf(InstanceOf x, LIRBlock trueSuccessor, LIRBlock falseSuccessor) {
+        XirArgument obj = toXirArgument(x.object());
+        XirSnippet snippet = xir.genInstanceOf(site(x), obj, toXirArgument(x.targetClassInstruction()), x.targetClass());
+        emitXir(snippet, x, stateFor(x), null, false);
+        LIRXirInstruction instr = (LIRXirInstruction) lir.instructionsList().get(lir.instructionsList().size() - 1);
+        instr.setTrueSuccessor(trueSuccessor);
+        instr.setFalseSuccessor(falseSuccessor);
+    }
+
     public void emitCompare(Compare compare, LIRBlock trueSuccessorBlock, LIRBlock falseSuccessorBlock) {
         CiKind kind = compare.x().kind;
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/LIRXirInstruction.java	Thu Jun 30 16:07:18 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/LIRXirInstruction.java	Thu Jun 30 16:49:13 2011 +0200
@@ -183,4 +183,15 @@
 
         return sb.toString();
     }
+
+
+    public void substitute(LIRBlock block, LIRBlock newTarget) {
+        if (trueSuccessor == block) {
+            trueSuccessor = newTarget;
+        }
+
+        if (falseSuccessor == block) {
+            falseSuccessor = newTarget;
+        }
+    }
 }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRAssembler.java	Thu Jun 30 16:07:18 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRAssembler.java	Thu Jun 30 16:49:13 2011 +0200
@@ -1600,16 +1600,20 @@
         for (int i = 0; i < labels.length; i++) {
             labels[i] = new Label();
             if (snippet.template.labels[i].name == XirLabel.TrueSuccessor) {
-                labels[i] = instruction.trueSuccessor().label;
-                if (labels[i] == null) {
+                if (instruction.trueSuccessor() == null) {
                     assert endLabel == null;
                     endLabel = new Label();
+                    labels[i] = endLabel;
+                } else {
+                    labels[i] = instruction.trueSuccessor().label;
                 }
             } else if (snippet.template.labels[i].name == XirLabel.FalseSuccessor) {
-                labels[i] = instruction.falseSuccessor().label;
-                if (labels[i] == null) {
+                if (instruction.falseSuccessor() == null) {
                     assert endLabel == null;
                     endLabel = new Label();
+                    labels[i] = endLabel;
+                } else {
+                    labels[i] = instruction.falseSuccessor().label;
                 }
             }
         }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java	Thu Jun 30 16:07:18 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java	Thu Jun 30 16:49:13 2011 +0200
@@ -475,11 +475,10 @@
         XirArgument obj = toXirArgument(x.exception());
         XirArgument clazz = toXirArgument(riType.getEncoding(Representation.ObjectHub));
         XirSnippet snippet = xir.genInstanceOf(site(x), obj, clazz, riType);
-        CiValue result = emitXir(snippet, x, stateFor(x), null, true);
+        emitXir(snippet, x, stateFor(x), null, false);
 
-        lir.cmp(Condition.EQ, result, CiConstant.TRUE);
-        lir.branch(Condition.EQ, getLIRBlock(x.catchSuccessor()));
-
+        LIRXirInstruction instr = (LIRXirInstruction) lir.instructionsList().get(lir.instructionsList().size() - 1);
+        instr.setTrueSuccessor(getLIRBlock(x.catchSuccessor()));
         lir.jump(getLIRBlock(x.otherSuccessor()));
     }
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64XirAssembler.java	Thu Jun 30 16:07:18 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64XirAssembler.java	Thu Jun 30 16:49:13 2011 +0200
@@ -200,7 +200,7 @@
             }
         }
         for (XirLabel label : labels) {
-            assert boundLabels.contains(label) : "label " + label.name + " is not bound!";
+            assert label.name == XirLabel.TrueSuccessor || label.name == XirLabel.FalseSuccessor || boundLabels.contains(label) : "label " + label.name + " is not bound!";
         }
         XirInstruction[] fp = fastPath.toArray(new XirInstruction[fastPath.size()]);
         XirInstruction[] sp = slowPath.size() > 0 ? slowPath.toArray(new XirInstruction[slowPath.size()]) : null;
--- a/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotXirGenerator.java	Thu Jun 30 16:07:18 2011 +0200
+++ b/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotXirGenerator.java	Thu Jun 30 16:49:13 2011 +0200
@@ -643,25 +643,26 @@
 
             XirOperand objHub = asm.createTemp("objHub", CiKind.Object);
 
-            XirLabel end = asm.createInlineLabel("end");
             XirLabel slowPath = asm.createOutOfLineLabel("slow path");
+            XirLabel trueSucc = asm.createInlineLabel(XirLabel.TrueSuccessor);
+            XirLabel falseSucc = asm.createInlineLabel(XirLabel.FalseSuccessor);
 
             if (is(NULL_CHECK, flags)) {
                 // null isn't "instanceof" anything
-                asm.mov(result, asm.b(false));
-                asm.jeq(end, object, asm.o(null));
+                asm.jeq(falseSucc, object, asm.o(null));
             }
 
             asm.pload(CiKind.Object, objHub, object, asm.i(config.hubOffset), false);
             // if we get an exact match: succeed immediately
             asm.mov(result, asm.b(true));
-            asm.jneq(slowPath, objHub, hub);
-            asm.bindInline(end);
+            asm.jeq(trueSucc, objHub, hub);
+            asm.jmp(slowPath);
 
             // -- out of line -------------------------------------------------------
             asm.bindOutOfLine(slowPath);
             checkSubtype(asm, result, objHub, hub);
-            asm.jmp(end);
+            asm.jeq(falseSucc, result, asm.b(false));
+            asm.jmp(trueSucc);
 
             return asm.finishTemplate("instanceof");
         }