OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of ssa; | 5 part of ssa; |
6 | 6 |
7 | 7 |
8 class ValueRangeInfo { | 8 class ValueRangeInfo { |
9 final ConstantSystem constantSystem; | 9 final ConstantSystem constantSystem; |
10 | 10 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 129 |
130 const IntValue(this.value, info) : super(info); | 130 const IntValue(this.value, info) : super(info); |
131 | 131 |
132 Value operator +(other) { | 132 Value operator +(other) { |
133 if (other.isZero) return this; | 133 if (other.isZero) return this; |
134 if (other is !IntValue) return other + this; | 134 if (other is !IntValue) return other + this; |
135 ConstantSystem constantSystem = info.constantSystem; | 135 ConstantSystem constantSystem = info.constantSystem; |
136 var constant = constantSystem.add.fold( | 136 var constant = constantSystem.add.fold( |
137 constantSystem.createInt(value), constantSystem.createInt(other.value)); | 137 constantSystem.createInt(value), constantSystem.createInt(other.value)); |
138 if (!constant.isInt) return const UnknownValue(); | 138 if (!constant.isInt) return const UnknownValue(); |
139 return info.newIntValue(constant.value); | 139 return info.newIntValue(constant.primitiveValue); |
140 } | 140 } |
141 | 141 |
142 Value operator -(other) { | 142 Value operator -(other) { |
143 if (other.isZero) return this; | 143 if (other.isZero) return this; |
144 if (other is !IntValue) return -other + this; | 144 if (other is !IntValue) return -other + this; |
145 ConstantSystem constantSystem = info.constantSystem; | 145 ConstantSystem constantSystem = info.constantSystem; |
146 var constant = constantSystem.subtract.fold( | 146 var constant = constantSystem.subtract.fold( |
147 constantSystem.createInt(value), constantSystem.createInt(other.value)); | 147 constantSystem.createInt(value), constantSystem.createInt(other.value)); |
148 if (!constant.isInt) return const UnknownValue(); | 148 if (!constant.isInt) return const UnknownValue(); |
149 return info.newIntValue(constant.value); | 149 return info.newIntValue(constant.primitiveValue); |
150 } | 150 } |
151 | 151 |
152 Value operator -() { | 152 Value operator -() { |
153 if (isZero) return this; | 153 if (isZero) return this; |
154 ConstantSystem constantSystem = info.constantSystem; | 154 ConstantSystem constantSystem = info.constantSystem; |
155 var constant = constantSystem.negate.fold( | 155 var constant = constantSystem.negate.fold( |
156 constantSystem.createInt(value)); | 156 constantSystem.createInt(value)); |
157 if (!constant.isInt) return const UnknownValue(); | 157 if (!constant.isInt) return const UnknownValue(); |
158 return info.newIntValue(constant.value); | 158 return info.newIntValue(constant.primitiveValue); |
159 } | 159 } |
160 | 160 |
161 Value operator &(other) { | 161 Value operator &(other) { |
162 if (other is !IntValue) return const UnknownValue(); | 162 if (other is !IntValue) return const UnknownValue(); |
163 ConstantSystem constantSystem = info.constantSystem; | 163 ConstantSystem constantSystem = info.constantSystem; |
164 var constant = constantSystem.bitAnd.fold( | 164 var constant = constantSystem.bitAnd.fold( |
165 constantSystem.createInt(value), constantSystem.createInt(other.value)); | 165 constantSystem.createInt(value), constantSystem.createInt(other.value)); |
166 return info.newIntValue(constant.value); | 166 return info.newIntValue(constant.primitiveValue); |
167 } | 167 } |
168 | 168 |
169 Value min(other) { | 169 Value min(other) { |
170 if (other is !IntValue) return other.min(this); | 170 if (other is !IntValue) return other.min(this); |
171 return this.value < other.value ? this : other; | 171 return this.value < other.value ? this : other; |
172 } | 172 } |
173 | 173 |
174 Value max(other) { | 174 Value max(other) { |
175 if (other is !IntValue) return other.max(this); | 175 if (other is !IntValue) return other.max(this); |
176 return this.value < other.value ? other : this; | 176 return this.value < other.value ? other : this; |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 | 665 |
666 Range range = ranges[phi.inputs[0]]; | 666 Range range = ranges[phi.inputs[0]]; |
667 for (int i = 1; i < phi.inputs.length; i++) { | 667 for (int i = 1; i < phi.inputs.length; i++) { |
668 range = range.union(ranges[phi.inputs[i]]); | 668 range = range.union(ranges[phi.inputs[i]]); |
669 } | 669 } |
670 return range; | 670 return range; |
671 } | 671 } |
672 | 672 |
673 Range visitConstant(HConstant hConstant) { | 673 Range visitConstant(HConstant hConstant) { |
674 if (!hConstant.isInteger(compiler)) return info.newUnboundRange(); | 674 if (!hConstant.isInteger(compiler)) return info.newUnboundRange(); |
675 Constant constant = hConstant.constant; | 675 ConstantValue constant = hConstant.constant; |
676 NumConstant constantNum; | 676 NumConstantValue constantNum; |
677 if (constant is DeferredConstant) { | 677 if (constant is DeferredConstantValue) { |
678 constantNum = constant.referenced; | 678 constantNum = constant.referenced; |
679 } else { | 679 } else { |
680 constantNum = constant; | 680 constantNum = constant; |
681 } | 681 } |
682 if (constantNum.isMinusZero) constantNum = new IntConstant(0); | 682 if (constantNum.isMinusZero) constantNum = new IntConstantValue(0); |
683 Value value = info.newIntValue(constantNum.value); | 683 Value value = info.newIntValue(constantNum.primitiveValue); |
684 return info.newNormalizedRange(value, value); | 684 return info.newNormalizedRange(value, value); |
685 } | 685 } |
686 | 686 |
687 Range visitFieldGet(HFieldGet fieldGet) { | 687 Range visitFieldGet(HFieldGet fieldGet) { |
688 if (!fieldGet.isInteger(compiler)) return info.newUnboundRange(); | 688 if (!fieldGet.isInteger(compiler)) return info.newUnboundRange(); |
689 if (!fieldGet.receiver.isIndexablePrimitive(compiler)) { | 689 if (!fieldGet.receiver.isIndexablePrimitive(compiler)) { |
690 return visitInstruction(fieldGet); | 690 return visitInstruction(fieldGet); |
691 } | 691 } |
692 JavaScriptBackend backend = compiler.backend; | 692 JavaScriptBackend backend = compiler.backend; |
693 assert(fieldGet.element == backend.jsIndexableLength); | 693 assert(fieldGet.element == backend.jsIndexableLength); |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1066 } | 1066 } |
1067 | 1067 |
1068 Range handleBinaryOperation(HBinaryArithmetic instruction) { | 1068 Range handleBinaryOperation(HBinaryArithmetic instruction) { |
1069 Range leftRange = visit(instruction.left); | 1069 Range leftRange = visit(instruction.left); |
1070 Range rightRange = visit(instruction.right); | 1070 Range rightRange = visit(instruction.right); |
1071 if (leftRange == null || rightRange == null) return null; | 1071 if (leftRange == null || rightRange == null) return null; |
1072 BinaryOperation operation = instruction.operation(info.constantSystem); | 1072 BinaryOperation operation = instruction.operation(info.constantSystem); |
1073 return operation.apply(leftRange, rightRange); | 1073 return operation.apply(leftRange, rightRange); |
1074 } | 1074 } |
1075 } | 1075 } |
OLD | NEW |