changeset 16162:b3945bb0016f

ConditionalNode is not a BinaryNode
author Lukas Stadler <lukas.stadler@oracle.com>
date Mon, 23 Jun 2014 14:13:03 +0200
parents 13b2e8c4c720
children d5e66f2adf8f
files graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/IfNode.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/ConditionalNode.java
diffstat 3 files changed, 20 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/IfNode.java	Mon Jun 23 14:13:03 2014 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/IfNode.java	Mon Jun 23 14:13:03 2014 +0200
@@ -560,11 +560,11 @@
             }
             boolean negateConditionalCondition;
             ValueNode otherValue;
-            if (constant == conditional.x()) {
-                otherValue = conditional.y();
+            if (constant == conditional.trueValue()) {
+                otherValue = conditional.falseValue();
                 negateConditionalCondition = false;
-            } else if (constant == conditional.y()) {
-                otherValue = conditional.x();
+            } else if (constant == conditional.falseValue()) {
+                otherValue = conditional.trueValue();
                 negateConditionalCondition = true;
             } else {
                 return null;
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/CompareNode.java	Mon Jun 23 14:13:03 2014 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/CompareNode.java	Mon Jun 23 14:13:03 2014 +0200
@@ -126,12 +126,10 @@
     protected abstract CompareNode duplicateModified(ValueNode newX, ValueNode newY);
 
     protected Node canonicalizeSymmetricConstant(CanonicalizerTool tool, Constant constant, ValueNode nonConstant, boolean mirrored) {
-        if (nonConstant instanceof BinaryNode) {
-            if (nonConstant instanceof ConditionalNode) {
-                return optimizeConditional(constant, (ConditionalNode) nonConstant, tool.getConstantReflection(), mirrored ? condition().mirror() : condition());
-            } else if (nonConstant instanceof NormalizeCompareNode) {
-                return optimizeNormalizeCmp(constant, (NormalizeCompareNode) nonConstant, mirrored);
-            }
+        if (nonConstant instanceof ConditionalNode) {
+            return optimizeConditional(constant, (ConditionalNode) nonConstant, tool.getConstantReflection(), mirrored ? condition().mirror() : condition());
+        } else if (nonConstant instanceof NormalizeCompareNode) {
+            return optimizeNormalizeCmp(constant, (NormalizeCompareNode) nonConstant, mirrored);
         } else if (nonConstant instanceof ConvertNode) {
             ConvertNode convert = (ConvertNode) nonConstant;
             ConstantNode newConstant = canonicalConvertConstant(tool, convert, constant);
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ConditionalNode.java	Mon Jun 23 14:13:03 2014 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ConditionalNode.java	Mon Jun 23 14:13:03 2014 +0200
@@ -37,9 +37,11 @@
  * The {@code ConditionalNode} class represents a comparison that yields one of two values. Note
  * that these nodes are not built directly from the bytecode but are introduced by canonicalization.
  */
-public final class ConditionalNode extends BinaryNode implements Canonicalizable, LIRLowerable {
+public final class ConditionalNode extends FloatingNode implements Canonicalizable, LIRLowerable {
 
     @Input(InputType.Condition) private LogicNode condition;
+    @Input private ValueNode trueValue;
+    @Input private ValueNode falseValue;
 
     public LogicNode condition() {
         return condition;
@@ -50,38 +52,40 @@
     }
 
     public ConditionalNode(LogicNode condition, ValueNode trueValue, ValueNode falseValue) {
-        super(trueValue.stamp().meet(falseValue.stamp()), trueValue, falseValue);
+        super(trueValue.stamp().meet(falseValue.stamp()));
         assert trueValue.stamp().isCompatible(falseValue.stamp());
         this.condition = condition;
+        this.trueValue = trueValue;
+        this.falseValue = falseValue;
     }
 
     @Override
     public boolean inferStamp() {
-        return updateStamp(x().stamp().meet(y().stamp()));
+        return updateStamp(trueValue.stamp().meet(falseValue.stamp()));
     }
 
     public ValueNode trueValue() {
-        return x();
+        return trueValue;
     }
 
     public ValueNode falseValue() {
-        return y();
+        return falseValue;
     }
 
     @Override
-    public Node canonical(CanonicalizerTool tool) {
+    public ValueNode canonical(CanonicalizerTool tool) {
         if (condition instanceof LogicNegationNode) {
             LogicNegationNode negated = (LogicNegationNode) condition;
             return graph().unique(new ConditionalNode(negated.getInput(), falseValue(), trueValue()));
         }
 
         // this optimizes the case where a value that can only be 0 or 1 is materialized to 0 or 1
-        if (x().isConstant() && y().isConstant() && condition instanceof IntegerEqualsNode) {
+        if (trueValue().isConstant() && falseValue().isConstant() && condition instanceof IntegerEqualsNode) {
             IntegerEqualsNode equals = (IntegerEqualsNode) condition;
             if (equals.y().isConstant() && equals.y().asConstant().equals(Constant.INT_0) && equals.x().stamp() instanceof IntegerStamp) {
                 IntegerStamp equalsXStamp = (IntegerStamp) equals.x().stamp();
                 if (equalsXStamp.upMask() == 1) {
-                    if (x().asConstant().equals(Constant.INT_0) && y().asConstant().equals(Constant.INT_1)) {
+                    if (trueValue().asConstant().equals(Constant.INT_0) && falseValue().asConstant().equals(Constant.INT_1)) {
                         return IntegerConvertNode.convertUnsigned(equals.x(), stamp());
                     }
                 }