74 public final BinaryOp<OP> getArithmeticOp() { 75 return getOp(getX(), getY()); 76 } 77 78 public boolean isAssociative() { 79 return getArithmeticOp().isAssociative(); 80 } 81 82 @Override 83 public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) { 84 ValueNode result = tryConstantFold(getOp(forX, forY), forX, forY, stamp()); 85 if (result != null) { 86 return result; 87 } 88 return this; 89 } 90 91 public static <OP> ConstantNode tryConstantFold(BinaryOp<OP> op, ValueNode forX, ValueNode forY, Stamp stamp) { 92 if (forX.isConstant() && forY.isConstant()) { 93 Constant ret = op.foldConstant(forX.asConstant(), forY.asConstant()); 94 return ConstantNode.forPrimitive(stamp, ret); 95 } 96 return null; 97 } 98 99 @Override 100 public Stamp foldStamp(Stamp stampX, Stamp stampY) { 101 assert stampX.isCompatible(x.stamp()) && stampY.isCompatible(y.stamp()); 102 return getArithmeticOp().foldStamp(stampX, stampY); 103 } 104 105 public static ValueNode add(StructuredGraph graph, ValueNode v1, ValueNode v2) { 106 return graph.addOrUniqueWithInputs(AddNode.create(v1, v2)); 107 } 108 109 public static ValueNode add(ValueNode v1, ValueNode v2) { 110 return AddNode.create(v1, v2); 111 } 112 113 public static ValueNode mul(StructuredGraph graph, ValueNode v1, ValueNode v2) { 114 return graph.addOrUniqueWithInputs(MulNode.create(v1, v2)); | 74 public final BinaryOp<OP> getArithmeticOp() { 75 return getOp(getX(), getY()); 76 } 77 78 public boolean isAssociative() { 79 return getArithmeticOp().isAssociative(); 80 } 81 82 @Override 83 public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) { 84 ValueNode result = tryConstantFold(getOp(forX, forY), forX, forY, stamp()); 85 if (result != null) { 86 return result; 87 } 88 return this; 89 } 90 91 public static <OP> ConstantNode tryConstantFold(BinaryOp<OP> op, ValueNode forX, ValueNode forY, Stamp stamp) { 92 if (forX.isConstant() && forY.isConstant()) { 93 Constant ret = op.foldConstant(forX.asConstant(), forY.asConstant()); 94 if (ret != null) { 95 return ConstantNode.forPrimitive(stamp, ret); 96 } 97 } 98 return null; 99 } 100 101 @Override 102 public Stamp foldStamp(Stamp stampX, Stamp stampY) { 103 assert stampX.isCompatible(x.stamp()) && stampY.isCompatible(y.stamp()); 104 return getArithmeticOp().foldStamp(stampX, stampY); 105 } 106 107 public static ValueNode add(StructuredGraph graph, ValueNode v1, ValueNode v2) { 108 return graph.addOrUniqueWithInputs(AddNode.create(v1, v2)); 109 } 110 111 public static ValueNode add(ValueNode v1, ValueNode v2) { 112 return AddNode.create(v1, v2); 113 } 114 115 public static ValueNode mul(StructuredGraph graph, ValueNode v1, ValueNode v2) { 116 return graph.addOrUniqueWithInputs(MulNode.create(v1, v2)); |