| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/js-native-context-specialization.h" | 5 #include "src/compiler/js-native-context-specialization.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
| 9 #include "src/compilation-dependencies.h" | 9 #include "src/compilation-dependencies.h" |
| 10 #include "src/compiler/access-builder.h" | 10 #include "src/compiler/access-builder.h" |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 Node* receiver = NodeProperties::GetValueInput(node, 0); | 675 Node* receiver = NodeProperties::GetValueInput(node, 0); |
| 676 Node* effect = NodeProperties::GetEffectInput(node); | 676 Node* effect = NodeProperties::GetEffectInput(node); |
| 677 Node* control = NodeProperties::GetControlInput(node); | 677 Node* control = NodeProperties::GetControlInput(node); |
| 678 | 678 |
| 679 // Optimize access for constant {receiver}. | 679 // Optimize access for constant {receiver}. |
| 680 HeapObjectMatcher mreceiver(receiver); | 680 HeapObjectMatcher mreceiver(receiver); |
| 681 if (mreceiver.HasValue() && mreceiver.Value()->IsString()) { | 681 if (mreceiver.HasValue() && mreceiver.Value()->IsString()) { |
| 682 Handle<String> string = Handle<String>::cast(mreceiver.Value()); | 682 Handle<String> string = Handle<String>::cast(mreceiver.Value()); |
| 683 | 683 |
| 684 // We can only assume that the {index} is a valid array index if the IC | 684 // We can only assume that the {index} is a valid array index if the IC |
| 685 // is in element access mode, otherwise there's no guard for the bounds | 685 // is in element access mode and not MEGAMORPHIC, otherwise there's no |
| 686 // check below. | 686 // guard for the bounds check below. |
| 687 if (nexus.GetKeyType() == ELEMENT) { | 687 if (nexus.ic_state() != MEGAMORPHIC && nexus.GetKeyType() == ELEMENT) { |
| 688 // Strings are immutable in JavaScript. | 688 // Strings are immutable in JavaScript. |
| 689 if (access_mode == AccessMode::kStore) return NoChange(); | 689 if (access_mode == AccessMode::kStore) return NoChange(); |
| 690 | 690 |
| 691 // Ensure that {index} is less than {receiver} length. | 691 // Ensure that {index} is less than {receiver} length. |
| 692 Node* length = jsgraph()->Constant(string->length()); | 692 Node* length = jsgraph()->Constant(string->length()); |
| 693 index = effect = graph()->NewNode(simplified()->CheckBounds(), index, | 693 index = effect = graph()->NewNode(simplified()->CheckBounds(), index, |
| 694 length, effect, control); | 694 length, effect, control); |
| 695 | 695 |
| 696 // Load the character from the {receiver}. | 696 // Load the character from the {receiver}. |
| 697 value = graph()->NewNode(simplified()->StringCharCodeAt(), receiver, | 697 value = graph()->NewNode(simplified()->StringCharCodeAt(), receiver, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 // Check if we have feedback for a named access. | 753 // Check if we have feedback for a named access. |
| 754 if (Name* name = nexus.FindFirstName()) { | 754 if (Name* name = nexus.FindFirstName()) { |
| 755 return ReduceNamedAccess(node, value, receiver_maps, | 755 return ReduceNamedAccess(node, value, receiver_maps, |
| 756 handle(name, isolate()), access_mode, | 756 handle(name, isolate()), access_mode, |
| 757 language_mode, index); | 757 language_mode, index); |
| 758 } else if (nexus.GetKeyType() != ELEMENT) { | 758 } else if (nexus.GetKeyType() != ELEMENT) { |
| 759 // The KeyedLoad/StoreIC has seen non-element accesses, so we cannot assume | 759 // The KeyedLoad/StoreIC has seen non-element accesses, so we cannot assume |
| 760 // that the {index} is a valid array index, thus we just let the IC continue | 760 // that the {index} is a valid array index, thus we just let the IC continue |
| 761 // to deal with this load/store. | 761 // to deal with this load/store. |
| 762 return NoChange(); | 762 return NoChange(); |
| 763 } else if (nexus.ic_state() == MEGAMORPHIC) { |
| 764 // The KeyedLoad/StoreIC uses the MEGAMORPHIC state to guard the assumption |
| 765 // that a numeric {index} is within the valid bounds for {receiver}, i.e. |
| 766 // it transitions to MEGAMORPHIC once it sees an out-of-bounds access. Thus |
| 767 // we cannot continue here if the IC state is MEGAMORPHIC. |
| 768 return NoChange(); |
| 763 } | 769 } |
| 764 | 770 |
| 765 // Try to lower the element access based on the {receiver_maps}. | 771 // Try to lower the element access based on the {receiver_maps}. |
| 766 return ReduceElementAccess(node, index, value, receiver_maps, access_mode, | 772 return ReduceElementAccess(node, index, value, receiver_maps, access_mode, |
| 767 language_mode, store_mode); | 773 language_mode, store_mode); |
| 768 } | 774 } |
| 769 | 775 |
| 770 Reduction JSNativeContextSpecialization::ReduceSoftDeoptimize( | 776 Reduction JSNativeContextSpecialization::ReduceSoftDeoptimize( |
| 771 Node* node, DeoptimizeReason reason) { | 777 Node* node, DeoptimizeReason reason) { |
| 772 Node* effect = NodeProperties::GetEffectInput(node); | 778 Node* effect = NodeProperties::GetEffectInput(node); |
| (...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1529 return jsgraph()->javascript(); | 1535 return jsgraph()->javascript(); |
| 1530 } | 1536 } |
| 1531 | 1537 |
| 1532 SimplifiedOperatorBuilder* JSNativeContextSpecialization::simplified() const { | 1538 SimplifiedOperatorBuilder* JSNativeContextSpecialization::simplified() const { |
| 1533 return jsgraph()->simplified(); | 1539 return jsgraph()->simplified(); |
| 1534 } | 1540 } |
| 1535 | 1541 |
| 1536 } // namespace compiler | 1542 } // namespace compiler |
| 1537 } // namespace internal | 1543 } // namespace internal |
| 1538 } // namespace v8 | 1544 } // namespace v8 |
| OLD | NEW |