| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/code-factory.h" | 5 #include "src/code-factory.h" |
| 6 #include "src/compiler/access-builder.h" | 6 #include "src/compiler/access-builder.h" |
| 7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
| 8 #include "src/compiler/js-typed-lowering.h" | 8 #include "src/compiler/js-typed-lowering.h" |
| 9 #include "src/compiler/linkage.h" | 9 #include "src/compiler/linkage.h" |
| 10 #include "src/compiler/node-matchers.h" | 10 #include "src/compiler/node-matchers.h" |
| (...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 if (IsExternalArrayElementsKind(array->map()->elements_kind()) && | 772 if (IsExternalArrayElementsKind(array->map()->elements_kind()) && |
| 773 key_type->Is(shifted_int32_ranges_[k]) && byte_length <= kMaxInt) { | 773 key_type->Is(shifted_int32_ranges_[k]) && byte_length <= kMaxInt) { |
| 774 // JSLoadProperty(typed-array, int32) | 774 // JSLoadProperty(typed-array, int32) |
| 775 Handle<ExternalArray> elements = | 775 Handle<ExternalArray> elements = |
| 776 Handle<ExternalArray>::cast(handle(array->elements())); | 776 Handle<ExternalArray>::cast(handle(array->elements())); |
| 777 Node* buffer = jsgraph()->PointerConstant(elements->external_pointer()); | 777 Node* buffer = jsgraph()->PointerConstant(elements->external_pointer()); |
| 778 Node* length = jsgraph()->Constant(byte_length); | 778 Node* length = jsgraph()->Constant(byte_length); |
| 779 Node* effect = NodeProperties::GetEffectInput(node); | 779 Node* effect = NodeProperties::GetEffectInput(node); |
| 780 Node* control = NodeProperties::GetControlInput(node); | 780 Node* control = NodeProperties::GetControlInput(node); |
| 781 // Check if we can avoid the bounds check. | 781 // Check if we can avoid the bounds check. |
| 782 if (key_type->Min() >= 0 && | 782 if (key_type->Min() >= 0 && key_type->Max() < array->length_value()) { |
| 783 key_type->Max() < array->length()->Number()) { | |
| 784 Node* load = graph()->NewNode( | 783 Node* load = graph()->NewNode( |
| 785 simplified()->LoadElement( | 784 simplified()->LoadElement( |
| 786 AccessBuilder::ForTypedArrayElement(array->type(), true)), | 785 AccessBuilder::ForTypedArrayElement(array->type(), true)), |
| 787 buffer, key, effect, control); | 786 buffer, key, effect, control); |
| 788 ReplaceWithValue(node, load, load); | 787 ReplaceWithValue(node, load, load); |
| 789 return Replace(load); | 788 return Replace(load); |
| 790 } | 789 } |
| 791 // Compute byte offset. | 790 // Compute byte offset. |
| 792 Node* offset = Word32Shl(key, static_cast<int>(k)); | 791 Node* offset = Word32Shl(key, static_cast<int>(k)); |
| 793 Node* load = graph()->NewNode(simplified()->LoadBuffer(access), buffer, | 792 Node* load = graph()->NewNode(simplified()->LoadBuffer(access), buffer, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 } | 842 } |
| 844 // For integer-typed arrays, convert to the integer type. | 843 // For integer-typed arrays, convert to the integer type. |
| 845 if (TypeOf(access.machine_type()) == kTypeInt32 && | 844 if (TypeOf(access.machine_type()) == kTypeInt32 && |
| 846 !value_type->Is(Type::Signed32())) { | 845 !value_type->Is(Type::Signed32())) { |
| 847 value = graph()->NewNode(simplified()->NumberToInt32(), value); | 846 value = graph()->NewNode(simplified()->NumberToInt32(), value); |
| 848 } else if (TypeOf(access.machine_type()) == kTypeUint32 && | 847 } else if (TypeOf(access.machine_type()) == kTypeUint32 && |
| 849 !value_type->Is(Type::Unsigned32())) { | 848 !value_type->Is(Type::Unsigned32())) { |
| 850 value = graph()->NewNode(simplified()->NumberToUint32(), value); | 849 value = graph()->NewNode(simplified()->NumberToUint32(), value); |
| 851 } | 850 } |
| 852 // Check if we can avoid the bounds check. | 851 // Check if we can avoid the bounds check. |
| 853 if (key_type->Min() >= 0 && | 852 if (key_type->Min() >= 0 && key_type->Max() < array->length_value()) { |
| 854 key_type->Max() < array->length()->Number()) { | |
| 855 node->set_op(simplified()->StoreElement( | 853 node->set_op(simplified()->StoreElement( |
| 856 AccessBuilder::ForTypedArrayElement(array->type(), true))); | 854 AccessBuilder::ForTypedArrayElement(array->type(), true))); |
| 857 node->ReplaceInput(0, buffer); | 855 node->ReplaceInput(0, buffer); |
| 858 DCHECK_EQ(key, node->InputAt(1)); | 856 DCHECK_EQ(key, node->InputAt(1)); |
| 859 node->ReplaceInput(2, value); | 857 node->ReplaceInput(2, value); |
| 860 node->ReplaceInput(3, effect); | 858 node->ReplaceInput(3, effect); |
| 861 node->ReplaceInput(4, control); | 859 node->ReplaceInput(4, control); |
| 862 node->TrimInputCount(5); | 860 node->TrimInputCount(5); |
| 863 RelaxControls(node); | 861 RelaxControls(node); |
| 864 return Changed(node); | 862 return Changed(node); |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1477 } | 1475 } |
| 1478 | 1476 |
| 1479 | 1477 |
| 1480 MachineOperatorBuilder* JSTypedLowering::machine() const { | 1478 MachineOperatorBuilder* JSTypedLowering::machine() const { |
| 1481 return jsgraph()->machine(); | 1479 return jsgraph()->machine(); |
| 1482 } | 1480 } |
| 1483 | 1481 |
| 1484 } // namespace compiler | 1482 } // namespace compiler |
| 1485 } // namespace internal | 1483 } // namespace internal |
| 1486 } // namespace v8 | 1484 } // namespace v8 |
| OLD | NEW |