Chromium Code Reviews| 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 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 665 return Replace(value); | 665 return Replace(value); |
| 666 } | 666 } |
| 667 | 667 |
| 668 template <typename KeyedICNexus> | 668 template <typename KeyedICNexus> |
| 669 Reduction JSNativeContextSpecialization::ReduceKeyedAccess( | 669 Reduction JSNativeContextSpecialization::ReduceKeyedAccess( |
| 670 Node* node, Node* index, Node* value, KeyedICNexus const& nexus, | 670 Node* node, Node* index, Node* value, KeyedICNexus const& nexus, |
| 671 AccessMode access_mode, LanguageMode language_mode, | 671 AccessMode access_mode, LanguageMode language_mode, |
| 672 KeyedAccessStoreMode store_mode) { | 672 KeyedAccessStoreMode store_mode) { |
| 673 DCHECK(node->opcode() == IrOpcode::kJSLoadProperty || | 673 DCHECK(node->opcode() == IrOpcode::kJSLoadProperty || |
| 674 node->opcode() == IrOpcode::kJSStoreProperty); | 674 node->opcode() == IrOpcode::kJSStoreProperty); |
| 675 Node* const receiver = NodeProperties::GetValueInput(node, 0); | 675 Node* receiver = NodeProperties::GetValueInput(node, 0); |
| 676 Node* const effect = NodeProperties::GetEffectInput(node); | 676 Node* effect = NodeProperties::GetEffectInput(node); |
| 677 Node* control = NodeProperties::GetControlInput(node); | |
| 678 | |
| 679 // Optimize access for constant {receiver}. | |
| 680 HeapObjectMatcher mreceiver(receiver); | |
| 681 if (mreceiver.HasValue() && mreceiver.Value()->IsString()) { | |
| 682 Handle<String> string = Handle<String>::cast(mreceiver.Value()); | |
| 683 | |
| 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 | |
| 686 // check below. | |
| 687 if (nexus.GetKeyType() == ELEMENT) { | |
|
Yang
2016/10/24 06:48:32
So... if the index is also a constant... *wink*
Benedikt Meurer
2016/10/24 07:34:28
Follow-up CL.
| |
| 688 // Strings are immutable in JavaScript. | |
| 689 if (access_mode == AccessMode::kStore) return NoChange(); | |
| 690 | |
| 691 // Ensure that {index} is less than {receiver} length. | |
| 692 Node* length = jsgraph()->Constant(string->length()); | |
| 693 index = effect = graph()->NewNode(simplified()->CheckBounds(), index, | |
| 694 length, effect, control); | |
| 695 | |
| 696 // Load the character from the {receiver}. | |
| 697 value = graph()->NewNode(simplified()->StringCharCodeAt(), receiver, | |
| 698 index, control); | |
| 699 | |
| 700 // Return it as a single character string. | |
| 701 value = graph()->NewNode(simplified()->StringFromCharCode(), value); | |
| 702 ReplaceWithValue(node, value, effect, control); | |
| 703 return Replace(value); | |
| 704 } | |
| 705 } | |
| 677 | 706 |
| 678 // Check if the {nexus} reports type feedback for the IC. | 707 // Check if the {nexus} reports type feedback for the IC. |
| 679 if (nexus.IsUninitialized()) { | 708 if (nexus.IsUninitialized()) { |
| 680 if ((flags() & kDeoptimizationEnabled) && | 709 if ((flags() & kDeoptimizationEnabled) && |
| 681 (flags() & kBailoutOnUninitialized)) { | 710 (flags() & kBailoutOnUninitialized)) { |
| 682 return ReduceSoftDeoptimize( | 711 return ReduceSoftDeoptimize( |
| 683 node, | 712 node, |
| 684 DeoptimizeReason::kInsufficientTypeFeedbackForGenericKeyedAccess); | 713 DeoptimizeReason::kInsufficientTypeFeedbackForGenericKeyedAccess); |
| 685 } | 714 } |
| 686 return NoChange(); | 715 return NoChange(); |
| (...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1500 return jsgraph()->javascript(); | 1529 return jsgraph()->javascript(); |
| 1501 } | 1530 } |
| 1502 | 1531 |
| 1503 SimplifiedOperatorBuilder* JSNativeContextSpecialization::simplified() const { | 1532 SimplifiedOperatorBuilder* JSNativeContextSpecialization::simplified() const { |
| 1504 return jsgraph()->simplified(); | 1533 return jsgraph()->simplified(); |
| 1505 } | 1534 } |
| 1506 | 1535 |
| 1507 } // namespace compiler | 1536 } // namespace compiler |
| 1508 } // namespace internal | 1537 } // namespace internal |
| 1509 } // namespace v8 | 1538 } // namespace v8 |
| OLD | NEW |