Mercurial > hg > truffle
comparison graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NormalizeCompareNode.java @ 19379:b720a1e02fa0
Add graph building time canonicalization for NormalizeCompareNode.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sun, 15 Feb 2015 14:33:16 +0100 |
parents | 7227f5671c87 |
children | 7e2c87dae93e |
comparison
equal
deleted
inserted
replaced
19378:1a9d5e9ab0f4 | 19379:b720a1e02fa0 |
---|---|
21 * questions. | 21 * questions. |
22 */ | 22 */ |
23 package com.oracle.graal.nodes.calc; | 23 package com.oracle.graal.nodes.calc; |
24 | 24 |
25 import com.oracle.graal.api.meta.*; | 25 import com.oracle.graal.api.meta.*; |
26 import com.oracle.graal.compiler.common.calc.*; | |
26 import com.oracle.graal.compiler.common.type.*; | 27 import com.oracle.graal.compiler.common.type.*; |
27 import com.oracle.graal.graph.spi.*; | 28 import com.oracle.graal.graph.spi.*; |
28 import com.oracle.graal.nodeinfo.*; | 29 import com.oracle.graal.nodeinfo.*; |
29 import com.oracle.graal.nodes.*; | 30 import com.oracle.graal.nodes.*; |
30 import com.oracle.graal.nodes.spi.*; | 31 import com.oracle.graal.nodes.spi.*; |
42 public NormalizeCompareNode(ValueNode x, ValueNode y, boolean isUnorderedLess) { | 43 public NormalizeCompareNode(ValueNode x, ValueNode y, boolean isUnorderedLess) { |
43 super(StampFactory.forKind(Kind.Int), x, y); | 44 super(StampFactory.forKind(Kind.Int), x, y); |
44 this.isUnorderedLess = isUnorderedLess; | 45 this.isUnorderedLess = isUnorderedLess; |
45 } | 46 } |
46 | 47 |
48 public static ValueNode create(ValueNode x, ValueNode y, boolean isUnorderedLess, ConstantReflectionProvider constantReflection) { | |
49 LogicNode result = CompareNode.tryConstantFold(Condition.EQ, x, y, constantReflection, false); | |
50 if (result instanceof LogicConstantNode) { | |
51 LogicConstantNode logicConstantNode = (LogicConstantNode) result; | |
52 LogicNode resultLT = CompareNode.tryConstantFold(Condition.LT, x, y, constantReflection, isUnorderedLess); | |
53 if (resultLT instanceof LogicConstantNode) { | |
54 LogicConstantNode logicConstantNodeLT = (LogicConstantNode) resultLT; | |
55 if (logicConstantNodeLT.getValue()) { | |
56 return ConstantNode.forInt(-1); | |
57 } else if (logicConstantNode.getValue()) { | |
58 return ConstantNode.forInt(0); | |
59 } else { | |
60 return ConstantNode.forInt(1); | |
61 } | |
62 } | |
63 } | |
64 | |
65 return new NormalizeCompareNode(x, y, isUnorderedLess); | |
66 } | |
67 | |
47 @Override | 68 @Override |
48 public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) { | 69 public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) { |
49 // nothing to do | 70 // nothing to do |
50 return this; | 71 return this; |
51 } | 72 } |
54 public void lower(LoweringTool tool) { | 75 public void lower(LoweringTool tool) { |
55 LogicNode equalComp; | 76 LogicNode equalComp; |
56 LogicNode lessComp; | 77 LogicNode lessComp; |
57 if (getX().stamp() instanceof FloatStamp) { | 78 if (getX().stamp() instanceof FloatStamp) { |
58 equalComp = graph().unique(FloatEqualsNode.create(getX(), getY(), tool.getConstantReflection())); | 79 equalComp = graph().unique(FloatEqualsNode.create(getX(), getY(), tool.getConstantReflection())); |
59 lessComp = graph().unique(new FloatLessThanNode(getX(), getY(), isUnorderedLess)); | 80 lessComp = graph().unique(FloatLessThanNode.create(getX(), getY(), isUnorderedLess, tool.getConstantReflection())); |
60 } else { | 81 } else { |
61 equalComp = graph().unique(new IntegerEqualsNode(getX(), getY())); | 82 equalComp = graph().unique(IntegerEqualsNode.create(getX(), getY(), tool.getConstantReflection())); |
62 lessComp = graph().unique(new IntegerLessThanNode(getX(), getY())); | 83 lessComp = graph().unique(IntegerLessThanNode.create(getX(), getY(), tool.getConstantReflection())); |
63 } | 84 } |
64 | 85 |
65 ConditionalNode equalValue = graph().unique(new ConditionalNode(equalComp, ConstantNode.forInt(0, graph()), ConstantNode.forInt(1, graph()))); | 86 ConditionalNode equalValue = graph().unique(new ConditionalNode(equalComp, ConstantNode.forInt(0, graph()), ConstantNode.forInt(1, graph()))); |
66 ConditionalNode value = graph().unique(new ConditionalNode(lessComp, ConstantNode.forInt(-1, graph()), equalValue)); | 87 ConditionalNode value = graph().unique(new ConditionalNode(lessComp, ConstantNode.forInt(-1, graph()), equalValue)); |
67 | 88 |