changeset 5413:098c5eba749d

Merge
author Gilles Duboscq <duboscq@ssw.jku.at>
date Wed, 16 May 2012 13:24:39 +0200
parents bb47fd6a6290 (current diff) ae759e820ce7 (diff)
children d3dec1a05a80 79f12805362b
files
diffstat 3 files changed, 97 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/ComputeLinearScanOrder.java	Wed May 16 13:24:32 2012 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/ComputeLinearScanOrder.java	Wed May 16 13:24:39 2012 +0200
@@ -304,13 +304,21 @@
             Block cur = workList.remove(workList.size() - 1);
             appendBlock(cur);
 
-            int i;
-            int numSux = cur.numberOfSux();
-            // changed loop order to get "intuitive" order of if- and else-blocks
-            for (i = 0; i < numSux; i++) {
-                Block sux = cur.suxAt(i);
-                if (readyForProcessing(sux)) {
-                    sortIntoWorkList(sux);
+            // make the most successor with the highest probability the immediate successor
+            Node endNode = cur.getEndNode();
+            if (endNode instanceof IfNode && ((IfNode) endNode).probability() < 0.5) {
+                assert cur.numberOfSux() == 2;
+                if (readyForProcessing(cur.suxAt(1))) {
+                    sortIntoWorkList(cur.suxAt(1));
+                }
+                if (readyForProcessing(cur.suxAt(0))) {
+                    sortIntoWorkList(cur.suxAt(0));
+                }
+            } else {
+                for (Block sux : cur.getSuccessors()) {
+                    if (readyForProcessing(sux)) {
+                        sortIntoWorkList(sux);
+                    }
                 }
             }
         } while (workList.size() > 0);
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/target/amd64/AMD64LIRGenerator.java	Wed May 16 13:24:32 2012 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/target/amd64/AMD64LIRGenerator.java	Wed May 16 13:24:39 2012 +0200
@@ -44,6 +44,7 @@
 import com.oracle.graal.lir.*;
 import com.oracle.graal.lir.StandardOp.JumpOp;
 import com.oracle.graal.lir.StandardOp.LabelOp;
+import com.oracle.graal.lir.ValueUtil;
 import com.oracle.graal.lir.amd64.AMD64Arithmetic.DivOp;
 import com.oracle.graal.lir.amd64.AMD64Arithmetic.Op1Reg;
 import com.oracle.graal.lir.amd64.AMD64Arithmetic.Op1Stack;
@@ -218,39 +219,56 @@
 
     @Override
     public void emitBranch(CiValue left, CiValue right, Condition cond, boolean unorderedIsTrue, LabelRef label, LIRDebugInfo info) {
-        emitCompare(left, right);
-        switch (left.kind) {
-            case Boolean:
+        boolean mirrored = emitCompare(left, right);
+        Condition finalCondition = mirrored ? cond.mirror() : cond;
+        switch (left.kind.stackKind()) {
             case Int:
             case Long:
-            case Object: append(new BranchOp(cond, label, info)); break;
+            case Object: append(new BranchOp(finalCondition, label, info)); break;
             case Float:
-            case Double: append(new FloatBranchOp(cond, unorderedIsTrue, label, info)); break;
+            case Double: append(new FloatBranchOp(finalCondition, unorderedIsTrue, label, info)); break;
             default: throw GraalInternalError.shouldNotReachHere("" + left.kind);
         }
     }
 
     @Override
     public Variable emitCMove(CiValue left, CiValue right, Condition cond, boolean unorderedIsTrue, CiValue trueValue, CiValue falseValue) {
-        emitCompare(left, right);
+        boolean mirrored = emitCompare(left, right);
+        Condition finalCondition = mirrored ? cond.mirror() : cond;
 
         Variable result = newVariable(trueValue.kind);
-        switch (left.kind) {
-            case Boolean:
+        switch (left.kind.stackKind()) {
             case Int:
             case Long:
-            case Object: append(new CondMoveOp(result, cond, load(trueValue), loadNonConst(falseValue))); break;
+            case Object: append(new CondMoveOp(result, finalCondition, load(trueValue), loadNonConst(falseValue))); break;
             case Float:
-            case Double: append(new FloatCondMoveOp(result, cond, unorderedIsTrue, load(trueValue), load(falseValue))); break;
+            case Double: append(new FloatCondMoveOp(result, finalCondition, unorderedIsTrue, load(trueValue), load(falseValue))); break;
 
         }
         return result;
     }
 
-    private void emitCompare(CiValue a, CiValue b) {
-        Variable left = load(a);
-        CiValue right = loadNonConst(b);
-        switch (left.kind) {
+    /**
+     * This method emits the compare instruction, and may reorder the operands. It returns true if it did so.
+     *
+     * @param a the left operand of the comparison
+     * @param b the right operand of the comparison
+     * @return true if the left and right operands were switched, false otherwise
+     */
+    private boolean emitCompare(CiValue a, CiValue b) {
+        Variable left;
+        CiValue right;
+        boolean mirrored;
+        if (ValueUtil.isVariable(b)) {
+            left = load(b);
+            right = loadNonConst(a);
+            mirrored = true;
+        } else {
+            left = load(a);
+            right = loadNonConst(b);
+            mirrored = false;
+        }
+        switch (left.kind.stackKind()) {
             case Jsr:
             case Int: append(new CompareOp(ICMP, left, right)); break;
             case Long: append(new CompareOp(LCMP, left, right)); break;
@@ -259,6 +277,7 @@
             case Double: append(new CompareOp(DCMP, left, right)); break;
             default: throw GraalInternalError.shouldNotReachHere();
         }
+        return mirrored;
     }
 
     @Override
@@ -560,7 +579,6 @@
 
     @Override
     protected void emitNullCheckGuard(NullCheckNode node, long leafGraphId) {
-        assert !node.expectedNull;
         Variable value = load(operand(node.object()));
         LIRDebugInfo info = state(leafGraphId);
         append(new NullCheckOp(value, info));
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/Condition.java	Wed May 16 13:24:32 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/Condition.java	Wed May 16 13:24:39 2012 +0200
@@ -22,6 +22,7 @@
  */
 package com.oracle.graal.nodes.calc;
 
+import com.oracle.graal.graph.*;
 import com.oracle.max.cri.ci.*;
 import com.oracle.max.cri.ri.*;
 import com.oracle.max.cri.util.*;
@@ -124,6 +125,46 @@
     }
 
     /**
+     * Returns true if the condition needs to be mirrored to get to a canonical condition.
+     * The result of the mirroring operation might still need to be negated to achieve a canonical form.
+     */
+    public boolean canonicalMirror() {
+        switch (this) {
+            case EQ: return false;
+            case NE: return false;
+            case LT: return false;
+            case LE: return true;
+            case GT: return true;
+            case GE: return false;
+            case BT: return false;
+            case BE: return true;
+            case AT: return true;
+            case AE: return false;
+        }
+        throw new IllegalArgumentException(this.toString());
+    }
+
+    /**
+     * Returns true if the condition needs to be negated to get to a canonical condition.
+     * The result of the negation might still need to be mirrored to achieve a canonical form.
+     */
+    public boolean canonicalNegate() {
+        switch (this) {
+            case EQ: return false;
+            case NE: return true;
+            case LT: return false;
+            case LE: return true;
+            case GT: return false;
+            case GE: return true;
+            case BT: return false;
+            case BE: return true;
+            case AT: return false;
+            case AE: return true;
+        }
+        throw new IllegalArgumentException(this.toString());
+    }
+
+    /**
      * Negate this conditional.
      * @return the condition that represents the negation
      */
@@ -196,9 +237,9 @@
      * @param rt the constant on the right side of the comparison
      * @param runtime the RiRuntime (might be needed to compare runtime-specific types)
      * @return {@link Boolean#TRUE} if the comparison is known to be true,
-     * {@link Boolean#FALSE} if the comparison is known to be false, {@code null} otherwise.
+     * {@link Boolean#FALSE} if the comparison is known to be false
      */
-    public Boolean foldCondition(CiConstant lt, CiConstant rt, RiRuntime runtime, boolean unorderedIsTrue) {
+    public boolean foldCondition(CiConstant lt, CiConstant rt, RiRuntime runtime, boolean unorderedIsTrue) {
         switch (lt.kind) {
             case Boolean:
             case Byte:
@@ -219,8 +260,8 @@
                     case BE: return UnsignedMath.belowOrEqual(x, y);
                     case AT: return UnsignedMath.aboveThan(x, y);
                     case BT: return UnsignedMath.belowThan(x, y);
+                    default: throw new GraalInternalError("expected condition: %s", this);
                 }
-                break;
             }
             case Long: {
                 long x = lt.asLong();
@@ -236,15 +277,15 @@
                     case BE: return UnsignedMath.belowOrEqual(x, y);
                     case AT: return UnsignedMath.aboveThan(x, y);
                     case BT: return UnsignedMath.belowThan(x, y);
+                    default: throw new GraalInternalError("expected condition: %s", this);
                 }
-                break;
             }
             case Object: {
                 switch (this) {
                     case EQ: return runtime.areConstantObjectsEqual(lt, rt);
                     case NE: return !runtime.areConstantObjectsEqual(lt, rt);
+                    default: throw new GraalInternalError("expected condition: %s", this);
                 }
-                break;
             }
             case Float: {
                 float x = lt.asFloat();
@@ -259,6 +300,7 @@
                     case LE: return x <= y;
                     case GT: return x > y;
                     case GE: return x >= y;
+                    default: throw new GraalInternalError("expected condition: %s", this);
                 }
             }
             case Double: {
@@ -274,11 +316,11 @@
                     case LE: return x <= y;
                     case GT: return x > y;
                     case GE: return x >= y;
+                    default: throw new GraalInternalError("expected condition: %s", this);
                 }
             }
+            default: throw new GraalInternalError("expected value kind %s while folding condition: %s", lt.kind, this);
         }
-        assert false : "missed folding of constant operands: " + lt + " " + this + " " + rt;
-        return null;
     }
 
     public Condition join(Condition other) {