comparison graal/com.oracle.graal.loop/src/com/oracle/graal/loop/BasicInductionVariable.java @ 17197:ec35bb4eccb8

Add support for other data types to integer arithmetic nodes.
author Roland Schatz <roland.schatz@oracle.com>
date Wed, 24 Sep 2014 13:46:37 +0200
parents 06c15e88d383
children 83c3dd41ca64
comparison
equal deleted inserted replaced
17196:189479d72dc8 17197:ec35bb4eccb8
30 public class BasicInductionVariable extends InductionVariable { 30 public class BasicInductionVariable extends InductionVariable {
31 31
32 private ValuePhiNode phi; 32 private ValuePhiNode phi;
33 private ValueNode init; 33 private ValueNode init;
34 private ValueNode rawStride; 34 private ValueNode rawStride;
35 private IntegerArithmeticNode op; 35 private BinaryArithmeticNode op;
36 36
37 public BasicInductionVariable(LoopEx loop, ValuePhiNode phi, ValueNode init, ValueNode rawStride, IntegerArithmeticNode op) { 37 public BasicInductionVariable(LoopEx loop, ValuePhiNode phi, ValueNode init, ValueNode rawStride, BinaryArithmeticNode op) {
38 super(loop); 38 super(loop);
39 this.phi = phi; 39 this.phi = phi;
40 this.init = init; 40 this.init = init;
41 this.rawStride = rawStride; 41 this.rawStride = rawStride;
42 this.op = op; 42 this.op = op;
57 dir = Direction.Up; 57 dir = Direction.Up;
58 } else if (integerStamp.isStrictlyNegative()) { 58 } else if (integerStamp.isStrictlyNegative()) {
59 dir = Direction.Down; 59 dir = Direction.Down;
60 } 60 }
61 if (dir != null) { 61 if (dir != null) {
62 if (op instanceof IntegerAddNode) { 62 if (op instanceof AddNode) {
63 return dir; 63 return dir;
64 } else { 64 } else {
65 assert op instanceof IntegerSubNode; 65 assert op instanceof SubNode;
66 return dir.opposite(); 66 return dir.opposite();
67 } 67 }
68 } 68 }
69 } 69 }
70 return null; 70 return null;
80 return init; 80 return init;
81 } 81 }
82 82
83 @Override 83 @Override
84 public ValueNode strideNode() { 84 public ValueNode strideNode() {
85 if (op instanceof IntegerAddNode) { 85 if (op instanceof AddNode) {
86 return rawStride; 86 return rawStride;
87 } 87 }
88 if (op instanceof IntegerSubNode) { 88 if (op instanceof SubNode) {
89 return graph().unique(NegateNode.create(rawStride)); 89 return graph().unique(NegateNode.create(rawStride));
90 } 90 }
91 throw GraalInternalError.shouldNotReachHere(); 91 throw GraalInternalError.shouldNotReachHere();
92 } 92 }
93 93
106 return init.asConstant().asLong(); 106 return init.asConstant().asLong();
107 } 107 }
108 108
109 @Override 109 @Override
110 public long constantStride() { 110 public long constantStride() {
111 if (op instanceof IntegerAddNode) { 111 if (op instanceof AddNode) {
112 return rawStride.asConstant().asLong(); 112 return rawStride.asConstant().asLong();
113 } 113 }
114 if (op instanceof IntegerSubNode) { 114 if (op instanceof SubNode) {
115 return -rawStride.asConstant().asLong(); 115 return -rawStride.asConstant().asLong();
116 } 116 }
117 throw GraalInternalError.shouldNotReachHere(); 117 throw GraalInternalError.shouldNotReachHere();
118 } 118 }
119 119
129 } 129 }
130 ValueNode maxTripCount = loop.counted().maxTripCountNode(assumePositiveTripCount); 130 ValueNode maxTripCount = loop.counted().maxTripCountNode(assumePositiveTripCount);
131 if (!maxTripCount.stamp().isCompatible(stamp)) { 131 if (!maxTripCount.stamp().isCompatible(stamp)) {
132 maxTripCount = IntegerConvertNode.convert(maxTripCount, stamp, graph()); 132 maxTripCount = IntegerConvertNode.convert(maxTripCount, stamp, graph());
133 } 133 }
134 return IntegerArithmeticNode.add(graph, IntegerArithmeticNode.mul(graph, stride, IntegerArithmeticNode.sub(graph, maxTripCount, ConstantNode.forIntegerStamp(stamp, 1, graph))), initNode); 134 return BinaryArithmeticNode.add(graph, BinaryArithmeticNode.mul(graph, stride, BinaryArithmeticNode.sub(graph, maxTripCount, ConstantNode.forIntegerStamp(stamp, 1, graph))), initNode);
135 } 135 }
136 136
137 @Override 137 @Override
138 public ValueNode exitValueNode() { 138 public ValueNode exitValueNode() {
139 Stamp stamp = phi.stamp(); 139 Stamp stamp = phi.stamp();
140 ValueNode maxTripCount = loop.counted().maxTripCountNode(false); 140 ValueNode maxTripCount = loop.counted().maxTripCountNode(false);
141 if (!maxTripCount.stamp().isCompatible(stamp)) { 141 if (!maxTripCount.stamp().isCompatible(stamp)) {
142 maxTripCount = IntegerConvertNode.convert(maxTripCount, stamp, graph()); 142 maxTripCount = IntegerConvertNode.convert(maxTripCount, stamp, graph());
143 } 143 }
144 return IntegerArithmeticNode.add(graph(), IntegerArithmeticNode.mul(graph(), strideNode(), maxTripCount), initNode()); 144 return BinaryArithmeticNode.add(graph(), BinaryArithmeticNode.mul(graph(), strideNode(), maxTripCount), initNode());
145 } 145 }
146 146
147 @Override 147 @Override
148 public boolean isConstantExtremum() { 148 public boolean isConstantExtremum() {
149 return isConstantInit() && isConstantStride() && loop.counted().isConstantMaxTripCount(); 149 return isConstantInit() && isConstantStride() && loop.counted().isConstantMaxTripCount();