| 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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 /** | 421 /** |
| 422 * A [Range] represents the possible integer values an instruction | 422 * A [Range] represents the possible integer values an instruction |
| 423 * can have, from its [lower] bound to its [upper] bound, both | 423 * can have, from its [lower] bound to its [upper] bound, both |
| 424 * included. | 424 * included. |
| 425 */ | 425 */ |
| 426 class Range { | 426 class Range { |
| 427 final Value lower; | 427 final Value lower; |
| 428 final Value upper; | 428 final Value upper; |
| 429 final ValueRangeInfo info; | 429 final ValueRangeInfo info; |
| 430 Range(this.lower, this.upper, this.info); | 430 Range(this.lower, this.upper, this.info); |
| 431 Range.unbound(this.info) | 431 |
| 432 : lower = const MinIntValue(), | 432 Range.unbound(info) : this(const MinIntValue(), const MaxIntValue(), info); |
| 433 upper = const MaxIntValue(); | 433 |
| 434 /** | 434 /** |
| 435 * Checks if the given values are unknown, and creates a | 435 * Checks if the given values are unknown, and creates a |
| 436 * range that does not have any unknown values. | 436 * range that does not have any unknown values. |
| 437 */ | 437 */ |
| 438 Range.normalize(Value low, Value up, this.info) | 438 Range.normalize(Value low, Value up, info) : this( |
| 439 : lower = low == const UnknownValue() ? const MinIntValue() : low, | 439 low == const UnknownValue() ? const MinIntValue() : low, |
| 440 upper = up == const UnknownValue() ? const MaxIntValue() : up; | 440 up == const UnknownValue() ? const MaxIntValue() : up, |
| 441 info); |
| 441 | 442 |
| 442 Range union(Range other) { | 443 Range union(Range other) { |
| 443 return info.newNormalizedRange( | 444 return info.newNormalizedRange( |
| 444 lower.min(other.lower), upper.max(other.upper)); | 445 lower.min(other.lower), upper.max(other.upper)); |
| 445 } | 446 } |
| 446 | 447 |
| 447 intersection(Range other) { | 448 intersection(Range other) { |
| 448 Value low = lower.max(other.lower); | 449 Value low = lower.max(other.lower); |
| 449 Value up = upper.min(other.upper); | 450 Value up = upper.min(other.upper); |
| 450 // If we could not compute max or min, pick a value in the two | 451 // If we could not compute max or min, pick a value in the two |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 // greater or equal than the lower bound of the index. | 678 // greater or equal than the lower bound of the index. |
| 678 Value low = lengthRange.lower.max(indexRange.lower); | 679 Value low = lengthRange.lower.max(indexRange.lower); |
| 679 if (low != const UnknownValue()) { | 680 if (low != const UnknownValue()) { |
| 680 HInstruction instruction = | 681 HInstruction instruction = |
| 681 createRangeConversion(next, check.length); | 682 createRangeConversion(next, check.length); |
| 682 ranges[instruction] = info.newRange(low, lengthRange.upper); | 683 ranges[instruction] = info.newRange(low, lengthRange.upper); |
| 683 } | 684 } |
| 684 } | 685 } |
| 685 | 686 |
| 686 if (!belowLength) { | 687 if (!belowLength) { |
| 687 // Update the range of the index if using the length bounds | 688 // Update the range of the index if using the maximum index |
| 688 // narrows it. | 689 // narrows it. |
| 689 Range newIndexRange = indexRange.intersection( | 690 Range newIndexRange = indexRange.intersection( |
| 690 info.newRange(lengthRange.lower, maxIndex)); | 691 info.newRange(info.intZero, maxIndex)); |
| 691 if (indexRange == newIndexRange) return indexRange; | 692 if (indexRange == newIndexRange) return indexRange; |
| 692 HInstruction instruction = createRangeConversion(next, check.index); | 693 HInstruction instruction = createRangeConversion(next, check.index); |
| 693 ranges[instruction] = newIndexRange; | 694 ranges[instruction] = newIndexRange; |
| 694 return newIndexRange; | 695 return newIndexRange; |
| 695 } | 696 } |
| 696 | 697 |
| 697 return indexRange; | 698 return indexRange; |
| 698 } | 699 } |
| 699 | 700 |
| 700 Range visitRelational(HRelational relational) { | 701 Range visitRelational(HRelational relational) { |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 if (instruction is HPhi && !instruction.block.isLoopHeader()) { | 988 if (instruction is HPhi && !instruction.block.isLoopHeader()) { |
| 988 HInstruction result = unwrap(instruction.inputs[0]); | 989 HInstruction result = unwrap(instruction.inputs[0]); |
| 989 for (int i = 1; i < instruction.inputs.length; i++) { | 990 for (int i = 1; i < instruction.inputs.length; i++) { |
| 990 if (result != unwrap(instruction.inputs[i])) return instruction; | 991 if (result != unwrap(instruction.inputs[i])) return instruction; |
| 991 } | 992 } |
| 992 return result; | 993 return result; |
| 993 } | 994 } |
| 994 return instruction; | 995 return instruction; |
| 995 } | 996 } |
| 996 } | 997 } |
| OLD | NEW |