changeset 2924:9d4e5b492521

Refactored LIR generation for If.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Thu, 09 Jun 2011 14:02:28 +0200
parents 287ddc8a9119
children b78b4ae0757c
files 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/target/amd64/AMD64LIRGenerator.java
diffstat 2 files changed, 58 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Thu Jun 09 13:41:49 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Thu Jun 09 14:02:28 2011 +0200
@@ -436,6 +436,60 @@
     }
 
     @Override
+    public void visitIf(If x) {
+        emitCompare(x.compare());
+        emitBranch(x.compare(), getLIRBlock(x.trueSuccessor()), getLIRBlock(x.falseSuccessor()));
+        assert x.defaultSuccessor() == x.falseSuccessor() : "wrong destination above";
+        lir.jump(getLIRBlock(x.defaultSuccessor()));
+    }
+
+    public void emitBranch(Compare compare, LIRBlock trueSuccessor, LIRBlock falseSucc) {
+        Condition cond = compare.condition();
+        if (compare.x().kind.isFloat() || compare.x().kind.isDouble()) {
+            LIRBlock unorderedSuccBlock = falseSucc;
+            if (compare.unorderedIsTrue()) {
+                unorderedSuccBlock = trueSuccessor;
+            }
+            lir.branch(cond, trueSuccessor, unorderedSuccBlock);
+        } else {
+            lir.branch(cond, trueSuccessor);
+        }
+    }
+
+    public void emitCompare(Compare compare) {
+        CiKind kind = compare.x().kind;
+
+        Condition cond = compare.condition();
+
+        LIRItem xitem = new LIRItem(compare.x(), this);
+        LIRItem yitem = new LIRItem(compare.y(), this);
+        LIRItem xin = xitem;
+        LIRItem yin = yitem;
+
+        if (kind.isLong()) {
+            // for longs, only conditions "eql", "neq", "lss", "geq" are valid;
+            // mirror for other conditions
+            if (cond == Condition.GT || cond == Condition.LE) {
+                cond = cond.mirror();
+                xin = yitem;
+                yin = xitem;
+            }
+            xin.setDestroysRegister();
+        }
+        xin.loadItem();
+        if (kind.isLong() && yin.result().isConstant() && yin.instruction.asConstant().asLong() == 0 && (cond == Condition.EQ || cond == Condition.NE)) {
+            // dont load item
+        } else if (kind.isLong() || kind.isFloat() || kind.isDouble()) {
+            // longs cannot handle constants at right side
+            yin.loadItem();
+        }
+
+        CiValue left = xin.result();
+        CiValue right = yin.result();
+        lir.cmp(cond, left, right);
+    }
+
+    @Override
     public void visitIfOp(Conditional i) {
         Value x = i.x();
         Value y = i.y();
@@ -474,11 +528,7 @@
     }
 
     private int getBeforeInvokeBci(Invoke invoke) {
-        /*int length = 3;
-        if (invoke.opcode() == Bytecodes.INVOKEINTERFACE) {
-            length += 2;
-        }
-        return invoke.stateAfter().bci - length;*/
+        // Cannot calculate BCI, because the invoke can have changed from e.g. invokeinterface to invokespecial because of optimizations.
         return invoke.bci;
     }
 
@@ -620,6 +670,9 @@
     }
 
     protected LIRBlock getLIRBlock(Instruction b) {
+        if (b == null) {
+            return null;
+        }
         LIRBlock result = ir.valueToBlock.get(b);
         if (result == null) {
             TTY.println("instruction without lir block: " + b);
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java	Thu Jun 09 13:41:49 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java	Thu Jun 09 14:02:28 2011 +0200
@@ -471,56 +471,6 @@
     }
 
     @Override
-    public void visitIf(If x) {
-        emitCompare(x.compare());
-        Condition cond = x.compare().condition();
-        if (x.compare().x().kind.isFloat() || x.compare().x().kind.isDouble()) {
-            Instruction unorderedSucc = x.falseSuccessor();
-            if (x.compare().unorderedIsTrue()) {
-                unorderedSucc = x.trueSuccessor();
-            }
-            lir.branch(cond, getLIRBlock(x.trueSuccessor()), getLIRBlock(unorderedSucc));
-        } else {
-            lir.branch(cond, getLIRBlock(x.trueSuccessor()));
-        }
-        assert x.defaultSuccessor() == x.falseSuccessor() : "wrong destination above";
-        lir.jump(getLIRBlock(x.defaultSuccessor()));
-    }
-
-    public void emitCompare(Compare compare) {
-        CiKind kind = compare.x().kind;
-
-        Condition cond = compare.condition();
-
-        LIRItem xitem = new LIRItem(compare.x(), this);
-        LIRItem yitem = new LIRItem(compare.y(), this);
-        LIRItem xin = xitem;
-        LIRItem yin = yitem;
-
-        if (kind.isLong()) {
-            // for longs, only conditions "eql", "neq", "lss", "geq" are valid;
-            // mirror for other conditions
-            if (cond == Condition.GT || cond == Condition.LE) {
-                cond = cond.mirror();
-                xin = yitem;
-                yin = xitem;
-            }
-            xin.setDestroysRegister();
-        }
-        xin.loadItem();
-        if (kind.isLong() && yin.result().isConstant() && yin.instruction.asConstant().asLong() == 0 && (cond == Condition.EQ || cond == Condition.NE)) {
-            // dont load item
-        } else if (kind.isLong() || kind.isFloat() || kind.isDouble()) {
-            // longs cannot handle constants at right side
-            yin.loadItem();
-        }
-
-        CiValue left = xin.result();
-        CiValue right = yin.result();
-        lir.cmp(cond, left, right);
-    }
-
-    @Override
     public void visitExceptionDispatch(ExceptionDispatch x) {
         // TODO ls: this needs some more work...