54
55 public static ValueNode create(ValueNode value, NodeView view) {
56 ValueNode synonym = findSynonym(value, view);
57 if (synonym != null) {
58 return synonym;
59 }
60 return new NegateNode(value);
61 }
62
63 @Override
64 public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) {
65 ValueNode synonym = findSynonym(forValue, getOp(forValue));
66 if (synonym != null) {
67 return synonym;
68 }
69 return this;
70 }
71
72 protected static ValueNode findSynonym(ValueNode forValue, NodeView view) {
73 ArithmeticOpTable.UnaryOp<Neg> negOp = ArithmeticOpTable.forStamp(forValue.stamp(view)).getNeg();
74 ValueNode synonym = UnaryArithmeticNode.findSynonym(forValue, negOp);
75 if (synonym != null) {
76 return synonym;
77 }
78 if (forValue instanceof NegateNode) {
79 return ((NegateNode) forValue).getValue();
80 }
81 if (forValue instanceof SubNode && !(forValue.stamp(view) instanceof FloatStamp)) {
82 SubNode sub = (SubNode) forValue;
83 return SubNode.create(sub.getY(), sub.getX(), view);
84 }
85 return null;
86 }
87
88 @Override
89 public void generate(NodeLIRBuilderTool nodeValueMap, ArithmeticLIRGeneratorTool gen) {
90 nodeValueMap.setResult(this, gen.emitNegate(nodeValueMap.operand(getValue())));
91 }
92
93 @Override
|
54
55 public static ValueNode create(ValueNode value, NodeView view) {
56 ValueNode synonym = findSynonym(value, view);
57 if (synonym != null) {
58 return synonym;
59 }
60 return new NegateNode(value);
61 }
62
63 @Override
64 public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) {
65 ValueNode synonym = findSynonym(forValue, getOp(forValue));
66 if (synonym != null) {
67 return synonym;
68 }
69 return this;
70 }
71
72 protected static ValueNode findSynonym(ValueNode forValue, NodeView view) {
73 ArithmeticOpTable.UnaryOp<Neg> negOp = ArithmeticOpTable.forStamp(forValue.stamp(view)).getNeg();
74
75 // Folds constants
76 ValueNode synonym = UnaryArithmeticNode.findSynonym(forValue, negOp);
77 if (synonym != null) {
78 return synonym;
79 }
80 if (forValue instanceof NegateNode) {
81 return ((NegateNode) forValue).getValue();
82 }
83 if (forValue instanceof SubNode && !(forValue.stamp(view) instanceof FloatStamp)) {
84 SubNode sub = (SubNode) forValue;
85 return SubNode.create(sub.getY(), sub.getX(), view);
86 }
87 return null;
88 }
89
90 @Override
91 public void generate(NodeLIRBuilderTool nodeValueMap, ArithmeticLIRGeneratorTool gen) {
92 nodeValueMap.setResult(this, gen.emitNegate(nodeValueMap.operand(getValue())));
93 }
94
95 @Override
|