| 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 #include "vm/intermediate_language.h" | 5 #include "vm/intermediate_language.h" |
| 6 | 6 |
| 7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/dart_entry.h" | 8 #include "vm/dart_entry.h" |
| 9 #include "vm/flow_graph_allocator.h" | 9 #include "vm/flow_graph_allocator.h" |
| 10 #include "vm/flow_graph_builder.h" | 10 #include "vm/flow_graph_builder.h" |
| (...skipping 2417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2428 | 2428 |
| 2429 void LoadFieldInstr::InferRange() { | 2429 void LoadFieldInstr::InferRange() { |
| 2430 if ((range_ == NULL) && | 2430 if ((range_ == NULL) && |
| 2431 ((recognized_kind() == MethodRecognizer::kObjectArrayLength) || | 2431 ((recognized_kind() == MethodRecognizer::kObjectArrayLength) || |
| 2432 (recognized_kind() == MethodRecognizer::kImmutableArrayLength))) { | 2432 (recognized_kind() == MethodRecognizer::kImmutableArrayLength))) { |
| 2433 range_ = new Range(RangeBoundary::FromConstant(0), | 2433 range_ = new Range(RangeBoundary::FromConstant(0), |
| 2434 RangeBoundary::FromConstant(Array::kMaxElements)); | 2434 RangeBoundary::FromConstant(Array::kMaxElements)); |
| 2435 return; | 2435 return; |
| 2436 } | 2436 } |
| 2437 if ((range_ == NULL) && | 2437 if ((range_ == NULL) && |
| 2438 (recognized_kind() == MethodRecognizer::kByteArrayBaseLength)) { |
| 2439 range_ = new Range(RangeBoundary::FromConstant(0), RangeBoundary::MaxSmi()); |
| 2440 return; |
| 2441 } |
| 2442 if ((range_ == NULL) && |
| 2438 (recognized_kind() == MethodRecognizer::kStringBaseLength)) { | 2443 (recognized_kind() == MethodRecognizer::kStringBaseLength)) { |
| 2439 range_ = new Range(RangeBoundary::FromConstant(0), | 2444 range_ = new Range(RangeBoundary::FromConstant(0), |
| 2440 RangeBoundary::FromConstant(String::kMaxElements)); | 2445 RangeBoundary::FromConstant(String::kMaxElements)); |
| 2441 return; | 2446 return; |
| 2442 } | 2447 } |
| 2443 Definition::InferRange(); | 2448 Definition::InferRange(); |
| 2444 } | 2449 } |
| 2445 | 2450 |
| 2446 | 2451 |
| 2447 | 2452 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2643 | 2648 |
| 2644 | 2649 |
| 2645 // Inclusive. | 2650 // Inclusive. |
| 2646 bool Range::IsWithin(intptr_t min_int, intptr_t max_int) const { | 2651 bool Range::IsWithin(intptr_t min_int, intptr_t max_int) const { |
| 2647 if (min().LowerBound().value() < min_int) return false; | 2652 if (min().LowerBound().value() < min_int) return false; |
| 2648 if (max().UpperBound().value() > max_int) return false; | 2653 if (max().UpperBound().value() > max_int) return false; |
| 2649 return true; | 2654 return true; |
| 2650 } | 2655 } |
| 2651 | 2656 |
| 2652 | 2657 |
| 2658 bool CheckArrayBoundInstr::IsFixedLengthArrayType(intptr_t cid) { |
| 2659 switch (cid) { |
| 2660 case kArrayCid: |
| 2661 case kImmutableArrayCid: |
| 2662 case kInt8ArrayCid: |
| 2663 case kUint8ArrayCid: |
| 2664 case kUint8ClampedArrayCid: |
| 2665 case kInt16ArrayCid: |
| 2666 case kUint16ArrayCid: |
| 2667 case kInt32ArrayCid: |
| 2668 case kUint32ArrayCid: |
| 2669 case kInt64ArrayCid: |
| 2670 case kUint64ArrayCid: |
| 2671 case kFloat32ArrayCid: |
| 2672 case kFloat64ArrayCid: |
| 2673 return true; |
| 2674 default: |
| 2675 return false; |
| 2676 } |
| 2677 } |
| 2678 |
| 2679 |
| 2653 bool CheckArrayBoundInstr::IsRedundant(RangeBoundary length) { | 2680 bool CheckArrayBoundInstr::IsRedundant(RangeBoundary length) { |
| 2654 // Check that array has an immutable length. | 2681 // Check that array has an immutable length. |
| 2655 if ((array_type() != kArrayCid) && (array_type() != kImmutableArrayCid)) { | 2682 if (!IsFixedLengthArrayType(array_type())) { |
| 2656 return false; | 2683 return false; |
| 2657 } | 2684 } |
| 2658 | 2685 |
| 2659 Range* index_range = index()->definition()->range(); | 2686 Range* index_range = index()->definition()->range(); |
| 2660 | 2687 |
| 2661 // Range of the index is unknown can't decide if the check is redundant. | 2688 // Range of the index is unknown can't decide if the check is redundant. |
| 2662 if (index_range == NULL) return false; | 2689 if (index_range == NULL) return false; |
| 2663 | 2690 |
| 2664 // Range of the index is not positive. Check can't be redundant. | 2691 // Range of the index is not positive. Check can't be redundant. |
| 2665 if (Range::ConstantMin(index_range).value() < 0) return false; | 2692 if (Range::ConstantMin(index_range).value() < 0) return false; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2684 | 2711 |
| 2685 // Failed to prove that maximum is bounded with array length. | 2712 // Failed to prove that maximum is bounded with array length. |
| 2686 return false; | 2713 return false; |
| 2687 } | 2714 } |
| 2688 | 2715 |
| 2689 | 2716 |
| 2690 intptr_t CheckArrayBoundInstr::LengthOffsetFor(intptr_t class_id) { | 2717 intptr_t CheckArrayBoundInstr::LengthOffsetFor(intptr_t class_id) { |
| 2691 switch (class_id) { | 2718 switch (class_id) { |
| 2692 case kGrowableObjectArrayCid: | 2719 case kGrowableObjectArrayCid: |
| 2693 return GrowableObjectArray::length_offset(); | 2720 return GrowableObjectArray::length_offset(); |
| 2694 case kFloat64ArrayCid: | |
| 2695 return Float64Array::length_offset(); | |
| 2696 case kFloat32ArrayCid: | |
| 2697 return Float32Array::length_offset(); | |
| 2698 case kOneByteStringCid: | 2721 case kOneByteStringCid: |
| 2699 case kTwoByteStringCid: | 2722 case kTwoByteStringCid: |
| 2700 return String::length_offset(); | 2723 return String::length_offset(); |
| 2701 case kArrayCid: | 2724 case kArrayCid: |
| 2702 case kImmutableArrayCid: | 2725 case kImmutableArrayCid: |
| 2703 return Array::length_offset(); | 2726 return Array::length_offset(); |
| 2727 case kInt8ArrayCid: |
| 2704 case kUint8ArrayCid: | 2728 case kUint8ArrayCid: |
| 2705 return Uint8Array::length_offset(); | |
| 2706 case kUint8ClampedArrayCid: | 2729 case kUint8ClampedArrayCid: |
| 2707 return Uint8ClampedArray::length_offset(); | 2730 case kInt16ArrayCid: |
| 2731 case kUint16ArrayCid: |
| 2732 case kInt32ArrayCid: |
| 2733 case kUint32ArrayCid: |
| 2734 case kInt64ArrayCid: |
| 2735 case kUint64ArrayCid: |
| 2736 case kFloat64ArrayCid: |
| 2737 case kFloat32ArrayCid: |
| 2708 case kExternalUint8ArrayCid: | 2738 case kExternalUint8ArrayCid: |
| 2709 return ByteArray::length_offset(); | 2739 return ByteArray::length_offset(); |
| 2710 default: | 2740 default: |
| 2711 UNREACHABLE(); | 2741 UNREACHABLE(); |
| 2712 return -1; | 2742 return -1; |
| 2713 } | 2743 } |
| 2714 } | 2744 } |
| 2715 | 2745 |
| 2716 | 2746 |
| 2717 #undef __ | 2747 #undef __ |
| 2718 | 2748 |
| 2719 } // namespace dart | 2749 } // namespace dart |
| OLD | NEW |