changeset 5402:80127e4a1742

remove Condition.OF and Condition.NOF
author Lukas Stadler <lukas.stadler@jku.at>
date Tue, 15 May 2012 14:22:01 +0200
parents 332a3c0d7b3b
children c574c4540791
files graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/target/amd64/AMD64LIRGenerator.java graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ControlFlow.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/CompareNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/Condition.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/LIRGeneratorTool.java graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/ConditionTest.java graal/com.oracle.max.asm/src/com/oracle/max/asm/target/amd64/AMD64Assembler.java
diffstat 7 files changed, 97 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/target/amd64/AMD64LIRGenerator.java	Tue May 15 11:07:34 2012 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/target/amd64/AMD64LIRGenerator.java	Tue May 15 14:22:01 2012 +0200
@@ -31,6 +31,7 @@
 
 import com.oracle.max.asm.*;
 import com.oracle.max.asm.target.amd64.*;
+import com.oracle.max.asm.target.amd64.AMD64Assembler.ConditionFlag;
 import com.oracle.max.cri.ci.*;
 import com.oracle.max.cri.ci.CiTargetMethod.Mark;
 import com.oracle.max.cri.ri.*;
@@ -499,11 +500,10 @@
 
 
     @Override
-    public void emitDeoptimizeOn(Condition cond, RiDeoptAction action, RiDeoptReason reason, Object deoptInfo) {
-        assert cond != null;
+    public void emitDeoptimizeOnOverflow(RiDeoptAction action, RiDeoptReason reason, Object deoptInfo) {
         LIRDebugInfo info = state();
         LabelRef stubEntry = createDeoptStub(action, reason, info, deoptInfo);
-        append(new BranchOp(cond, stubEntry, info));
+        append(new BranchOp(ConditionFlag.overflow, stubEntry, info));
     }
 
 
--- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ControlFlow.java	Tue May 15 11:07:34 2012 +0200
+++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ControlFlow.java	Tue May 15 14:22:01 2012 +0200
@@ -63,10 +63,14 @@
 
 
     public static class BranchOp extends AMD64LIRInstruction implements StandardOp.BranchOp {
-        protected Condition condition;
+        protected ConditionFlag condition;
         protected LabelRef destination;
 
         public BranchOp(Condition condition, LabelRef destination, LIRDebugInfo info) {
+            this(intCond(condition), destination, info);
+        }
+
+        public BranchOp(ConditionFlag condition, LabelRef destination, LIRDebugInfo info) {
             super("BRANCH", LIRInstruction.NO_OPERANDS, info, LIRInstruction.NO_OPERANDS, LIRInstruction.NO_OPERANDS, LIRInstruction.NO_OPERANDS);
             this.condition = condition;
             this.destination = destination;
@@ -74,7 +78,7 @@
 
         @Override
         public void emitCode(TargetMethodAssembler tasm, AMD64MacroAssembler masm) {
-            masm.jcc(intCond(condition), destination.label());
+            masm.jcc(condition, destination.label());
         }
 
         @Override
@@ -168,11 +172,11 @@
 
 
     public static class CondMoveOp extends AMD64LIRInstruction {
-        private final Condition condition;
+        private final ConditionFlag condition;
 
         public CondMoveOp(Variable result, Condition condition, Variable trueValue, CiValue falseValue) {
             super("CMOVE", new CiValue[] {result}, null, new CiValue[] {falseValue}, new CiValue[] {trueValue}, LIRInstruction.NO_OPERANDS);
-            this.condition = condition;
+            this.condition = intCond(condition);
         }
 
         @Override
@@ -200,12 +204,12 @@
 
 
     public static class FloatCondMoveOp extends AMD64LIRInstruction {
-        private final Condition condition;
+        private final ConditionFlag condition;
         private final boolean unorderedIsTrue;
 
         public FloatCondMoveOp(Variable result, Condition condition, boolean unorderedIsTrue, Variable trueValue, Variable falseValue) {
             super("FLOAT_CMOVE", new CiValue[] {result}, null, LIRInstruction.NO_OPERANDS, new CiValue[] {trueValue, falseValue}, LIRInstruction.NO_OPERANDS);
-            this.condition = condition;
+            this.condition = floatCond(condition);
             this.unorderedIsTrue = unorderedIsTrue;
         }
 
@@ -289,30 +293,28 @@
         tasm.targetMethod.addAnnotation(jt);
     }
 
-    private static void floatJcc(AMD64MacroAssembler masm, Condition condition, boolean unorderedIsTrue, Label label) {
-        ConditionFlag cond = floatCond(condition);
+    private static void floatJcc(AMD64MacroAssembler masm, ConditionFlag condition, boolean unorderedIsTrue, Label label) {
         Label endLabel = new Label();
-        if (unorderedIsTrue && !trueOnUnordered(cond)) {
+        if (unorderedIsTrue && !trueOnUnordered(condition)) {
             masm.jcc(ConditionFlag.parity, label);
-        } else if (!unorderedIsTrue && trueOnUnordered(cond)) {
+        } else if (!unorderedIsTrue && trueOnUnordered(condition)) {
             masm.jcc(ConditionFlag.parity, endLabel);
         }
-        masm.jcc(cond, label);
+        masm.jcc(condition, label);
         masm.bind(endLabel);
     }
 
-    private static void cmove(TargetMethodAssembler tasm, AMD64MacroAssembler masm, CiValue result, boolean isFloat, Condition condition, boolean unorderedIsTrue, CiValue trueValue, CiValue falseValue) {
-        ConditionFlag cond = isFloat ? floatCond(condition) : intCond(condition);
+    private static void cmove(TargetMethodAssembler tasm, AMD64MacroAssembler masm, CiValue result, boolean isFloat, ConditionFlag condition, boolean unorderedIsTrue, CiValue trueValue, CiValue falseValue) {
         // check that we don't overwrite an input operand before it is used.
         assert !result.equals(trueValue);
 
         AMD64Move.move(tasm, masm, result, falseValue);
-        cmove(tasm, masm, result, cond, trueValue);
+        cmove(tasm, masm, result, condition, trueValue);
 
         if (isFloat) {
-            if (unorderedIsTrue && !trueOnUnordered(cond)) {
+            if (unorderedIsTrue && !trueOnUnordered(condition)) {
                 cmove(tasm, masm, result, ConditionFlag.parity, trueValue);
-            } else if (!unorderedIsTrue && trueOnUnordered(cond)) {
+            } else if (!unorderedIsTrue && trueOnUnordered(condition)) {
                 cmove(tasm, masm, result, ConditionFlag.parity, falseValue);
             }
         }
@@ -347,8 +349,6 @@
             case AE: return ConditionFlag.aboveEqual;
             case AT: return ConditionFlag.above;
             case BT: return ConditionFlag.below;
-            case OF: return ConditionFlag.overflow;
-            case NOF: return ConditionFlag.noOverflow;
             default: throw GraalInternalError.shouldNotReachHere();
         }
     }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/CompareNode.java	Tue May 15 11:07:34 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/CompareNode.java	Tue May 15 14:22:01 2012 +0200
@@ -216,7 +216,6 @@
                 // both are constant, this should be canonicalized...
             }
         } else if (kind == CiKind.Int || kind == CiKind.Long) {
-            assert condition != Condition.NOF && condition != Condition.OF;
             if (y().isConstant() && !x().isConstant()) {
                 tool.addScalar(x()).constantBound(condition, y().asConstant());
             } else if (x().isConstant() && !y().isConstant()) {
@@ -236,7 +235,6 @@
     public Result canonical(TypeFeedbackTool tool) {
         CiKind kind = x().kind();
         if (kind == CiKind.Int || kind == CiKind.Long) {
-            assert condition != Condition.NOF && condition != Condition.OF;
             ScalarTypeQuery queryX = tool.queryScalar(x());
             if (y().isConstant() && !x().isConstant()) {
                 if (queryX.constantBound(condition, y().asConstant())) {
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/Condition.java	Tue May 15 11:07:34 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/Condition.java	Tue May 15 14:22:01 2012 +0200
@@ -78,17 +78,7 @@
     /**
      * Unsigned less than ("below than").
      */
-    BT("|<|"),
-
-    /**
-     * Operation produced an overflow.
-     */
-    OF("overflow"),
-
-    /**
-     * Operation did not produce an overflow.
-     */
-    NOF("noOverflow");
+    BT("|<|");
 
     public final String operator;
 
@@ -109,7 +99,28 @@
             case AT: return UnsignedMath.aboveThan(left, right);
             case BT: return UnsignedMath.belowThan(left, right);
         }
-        throw new IllegalArgumentException();
+        throw new IllegalArgumentException(this.toString());
+    }
+
+    /**
+     * Given a condition and its negation, this method returns true for one of the two and false for the other one.
+     * This can be used to keep comparisons in a canonical form.
+     * @return true if this condition is considered to be the canonical form, false otherwise.
+     */
+    public boolean isCanonical() {
+        switch (this) {
+            case EQ: return true;
+            case NE: return false;
+            case LT: return true;
+            case LE: return false;
+            case GT: return false;
+            case GE: return false;
+            case BT: return true;
+            case BE: return false;
+            case AT: return false;
+            case AE: return false;
+        }
+        throw new IllegalArgumentException(this.toString());
     }
 
     /**
@@ -128,8 +139,6 @@
             case BE: return AT;
             case AT: return BE;
             case AE: return BT;
-            case OF: return NOF;
-            case NOF: return OF;
         }
         throw new IllegalArgumentException(this.toString());
     }
@@ -149,8 +158,6 @@
             case BE: return false;
             case AT: return other == AE || other == NE;
             case AE: return false;
-            case OF: return false;
-            case NOF: return false;
         }
         throw new IllegalArgumentException(this.toString());
     }
@@ -278,9 +285,6 @@
         if (other == this) {
             return this;
         }
-        if (this == OF || this == NOF || other == OF || other == NOF) {
-            return null;
-        }
         switch (this) {
             case EQ:
                 if (other == LE || other == GE || other == BE || other == AE) {
@@ -366,9 +370,6 @@
         if (other == this) {
             return this;
         }
-        if (this == OF || this == NOF || other == OF || other == NOF) {
-            return null;
-        }
         switch (this) {
             case EQ:
                 if (other == LE || other == GE || other == BE || other == AE) {
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/LIRGeneratorTool.java	Tue May 15 11:07:34 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/LIRGeneratorTool.java	Tue May 15 14:22:01 2012 +0200
@@ -79,7 +79,7 @@
 
     public abstract CiValue emitConvert(ConvertNode.Op opcode, CiValue inputVal);
     public abstract void emitMembar(int barriers);
-    public abstract void emitDeoptimizeOn(Condition cond, RiDeoptAction action, RiDeoptReason reason, Object deoptInfo);
+    public abstract void emitDeoptimizeOnOverflow(RiDeoptAction action, RiDeoptReason reason, Object deoptInfo);
     public abstract void emitDeoptimize(RiDeoptAction action, RiDeoptReason reason, Object deoptInfo, long leafGraphId);
     public abstract CiValue emitCall(Object target, CiKind result, CiKind[] arguments, boolean canTrap, CiValue... args);
     public final CiValue emitCall(CiRuntimeCall runtimeCall, boolean canTrap, CiValue... args) {
--- a/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/ConditionTest.java	Tue May 15 11:07:34 2012 +0200
+++ b/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/ConditionTest.java	Tue May 15 14:22:01 2012 +0200
@@ -40,7 +40,7 @@
         for (Condition c1 : Condition.values()) {
             for (Condition c2 : Condition.values()) {
                 boolean implies = c1.implies(c2);
-                if (implies && c1 != Condition.OF && c2 != Condition.OF && c1 != Condition.NOF && c2 != Condition.NOF) {
+                if (implies) {
                     for (int i = 0; i < 10000; i++) {
                         CiConstant a = CiConstant.forInt(rand.nextInt());
                         CiConstant b = CiConstant.forInt(i < 100 ? a.asInt() : rand.nextInt());
@@ -62,7 +62,7 @@
             for (Condition c2 : Condition.values()) {
                 Condition join = c1.join(c2);
                 assertTrue(join == c2.join(c1));
-                if (join != null && c1 != Condition.OF && c2 != Condition.OF && c1 != Condition.NOF && c2 != Condition.NOF) {
+                if (join != null) {
                     for (int i = 0; i < 10000; i++) {
                         CiConstant a = CiConstant.forInt(rand.nextInt());
                         CiConstant b = CiConstant.forInt(i < 100 ? a.asInt() : rand.nextInt());
@@ -85,7 +85,7 @@
             for (Condition c2 : Condition.values()) {
                 Condition meet = c1.meet(c2);
                 assertTrue(meet == c2.meet(c1));
-                if (meet != null && c1 != Condition.OF && c2 != Condition.OF && c1 != Condition.NOF && c2 != Condition.NOF) {
+                if (meet != null) {
                     for (int i = 0; i < 10000; i++) {
                         CiConstant a = CiConstant.forInt(rand.nextInt());
                         CiConstant b = CiConstant.forInt(i < 100 ? a.asInt() : rand.nextInt());
--- a/graal/com.oracle.max.asm/src/com/oracle/max/asm/target/amd64/AMD64Assembler.java	Tue May 15 11:07:34 2012 +0200
+++ b/graal/com.oracle.max.asm/src/com/oracle/max/asm/target/amd64/AMD64Assembler.java	Tue May 15 14:22:01 2012 +0200
@@ -46,34 +46,60 @@
      * The x86 condition codes used for conditional jumps/moves.
      */
     public enum ConditionFlag {
-        zero(0x4),
-        notZero(0x5),
-        equal(0x4),
-        notEqual(0x5),
-        less(0xc),
-        lessEqual(0xe),
-        greater(0xf),
-        greaterEqual(0xd),
-        below(0x2),
-        belowEqual(0x6),
-        above(0x7),
-        aboveEqual(0x3),
-        overflow(0x0),
-        noOverflow(0x1),
-        carrySet(0x2),
-        carryClear(0x3),
-        negative(0x8),
-        positive(0x9),
-        parity(0xa),
-        noParity(0xb);
+        zero(0x4, "|zero|"),
+        notZero(0x5, "|nzero|"),
+        equal(0x4, "="),
+        notEqual(0x5, "!="),
+        less(0xc, "<"),
+        lessEqual(0xe, "<="),
+        greater(0xf, ">"),
+        greaterEqual(0xd, ">="),
+        below(0x2, "|<|"),
+        belowEqual(0x6, "|<=|"),
+        above(0x7, "|>|"),
+        aboveEqual(0x3, "|>=|"),
+        overflow(0x0, "|of|"),
+        noOverflow(0x1, "|nof|"),
+        carrySet(0x2, "|carry|"),
+        carryClear(0x3, "|ncarry|"),
+        negative(0x8, "|neg|"),
+        positive(0x9, "|pos|"),
+        parity(0xa, "|par|"),
+        noParity(0xb, "|npar|");
 
         public final int value;
-
-        private ConditionFlag(int value) {
+        public final String operator;
+
+        private ConditionFlag(int value, String operator) {
             this.value = value;
+            this.operator = operator;
         }
 
-        public static final ConditionFlag[] values = values();
+        public ConditionFlag negate() {
+            switch(this) {
+                case zero: return notZero;
+                case notZero: return zero;
+                case equal: return notEqual;
+                case notEqual: return equal;
+                case less: return greaterEqual;
+                case lessEqual: return greater;
+                case greater: return lessEqual;
+                case greaterEqual: return less;
+                case below: return aboveEqual;
+                case belowEqual: return above;
+                case above: return belowEqual;
+                case aboveEqual: return below;
+                case overflow: return noOverflow;
+                case noOverflow: return overflow;
+                case carrySet: return carryClear;
+                case carryClear: return carrySet;
+                case negative: return positive;
+                case positive: return negative;
+                case parity: return noParity;
+                case noParity: return parity;
+            }
+            throw new IllegalArgumentException();
+        }
     }
 
     /**