| 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/compiler/access-builder.h" | 5 #include "src/compiler/access-builder.h" |
| 6 #include "src/compiler/graph-inl.h" | 6 #include "src/compiler/graph-inl.h" |
| 7 #include "src/compiler/js-builtin-reducer.h" | 7 #include "src/compiler/js-builtin-reducer.h" |
| 8 #include "src/compiler/js-typed-lowering.h" | 8 #include "src/compiler/js-typed-lowering.h" |
| 9 #include "src/compiler/node-aux-data-inl.h" | 9 #include "src/compiler/node-aux-data-inl.h" |
| 10 #include "src/compiler/node-properties-inl.h" | 10 #include "src/compiler/node-properties-inl.h" |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 Type* base_type = NodeProperties::GetBounds(base).upper; | 558 Type* base_type = NodeProperties::GetBounds(base).upper; |
| 559 // TODO(mstarzinger): This lowering is not correct if: | 559 // TODO(mstarzinger): This lowering is not correct if: |
| 560 // a) The typed array or it's buffer is neutered. | 560 // a) The typed array or it's buffer is neutered. |
| 561 if (base_type->IsConstant() && key_type->Is(Type::Integral32()) && | 561 if (base_type->IsConstant() && key_type->Is(Type::Integral32()) && |
| 562 base_type->AsConstant()->Value()->IsJSTypedArray()) { | 562 base_type->AsConstant()->Value()->IsJSTypedArray()) { |
| 563 // JSLoadProperty(typed-array, int32) | 563 // JSLoadProperty(typed-array, int32) |
| 564 Handle<JSTypedArray> array = | 564 Handle<JSTypedArray> array = |
| 565 Handle<JSTypedArray>::cast(base_type->AsConstant()->Value()); | 565 Handle<JSTypedArray>::cast(base_type->AsConstant()->Value()); |
| 566 if (IsExternalArrayElementsKind(array->map()->elements_kind())) { | 566 if (IsExternalArrayElementsKind(array->map()->elements_kind())) { |
| 567 ExternalArrayType type = array->type(); | 567 ExternalArrayType type = array->type(); |
| 568 uint32_t byte_length; | 568 double byte_length = array->byte_length()->Number(); |
| 569 if (array->byte_length()->ToUint32(&byte_length) && | 569 if (byte_length <= kMaxInt) { |
| 570 byte_length <= static_cast<uint32_t>(kMaxInt)) { | |
| 571 Handle<ExternalArray> elements = | 570 Handle<ExternalArray> elements = |
| 572 Handle<ExternalArray>::cast(handle(array->elements())); | 571 Handle<ExternalArray>::cast(handle(array->elements())); |
| 573 Node* pointer = jsgraph()->IntPtrConstant( | 572 Node* pointer = jsgraph()->IntPtrConstant( |
| 574 bit_cast<intptr_t>(elements->external_pointer())); | 573 bit_cast<intptr_t>(elements->external_pointer())); |
| 575 Node* length = jsgraph()->Uint32Constant( | 574 Node* length = jsgraph()->Constant(byte_length / array->element_size()); |
| 576 static_cast<uint32_t>(byte_length / array->element_size())); | |
| 577 Node* effect = NodeProperties::GetEffectInput(node); | 575 Node* effect = NodeProperties::GetEffectInput(node); |
| 578 Node* control = NodeProperties::GetControlInput(node); | 576 Node* control = NodeProperties::GetControlInput(node); |
| 579 Node* load = graph()->NewNode( | 577 Node* load = graph()->NewNode( |
| 580 simplified()->LoadElement( | 578 simplified()->LoadElement( |
| 581 AccessBuilder::ForTypedArrayElement(type, true)), | 579 AccessBuilder::ForTypedArrayElement(type, true)), |
| 582 pointer, key, length, effect, control); | 580 pointer, key, length, effect, control); |
| 583 return ReplaceEagerly(node, load); | 581 return ReplaceEagerly(node, load); |
| 584 } | 582 } |
| 585 } | 583 } |
| 586 } | 584 } |
| 587 return NoChange(); | 585 return NoChange(); |
| 588 } | 586 } |
| 589 | 587 |
| 590 | 588 |
| 591 Reduction JSTypedLowering::ReduceJSStoreProperty(Node* node) { | 589 Reduction JSTypedLowering::ReduceJSStoreProperty(Node* node) { |
| 592 Node* key = NodeProperties::GetValueInput(node, 1); | 590 Node* key = NodeProperties::GetValueInput(node, 1); |
| 593 Node* base = NodeProperties::GetValueInput(node, 0); | 591 Node* base = NodeProperties::GetValueInput(node, 0); |
| 594 Node* value = NodeProperties::GetValueInput(node, 2); | 592 Node* value = NodeProperties::GetValueInput(node, 2); |
| 595 Type* key_type = NodeProperties::GetBounds(key).upper; | 593 Type* key_type = NodeProperties::GetBounds(key).upper; |
| 596 Type* base_type = NodeProperties::GetBounds(base).upper; | 594 Type* base_type = NodeProperties::GetBounds(base).upper; |
| 597 // TODO(mstarzinger): This lowering is not correct if: | 595 // TODO(mstarzinger): This lowering is not correct if: |
| 598 // a) The typed array or its buffer is neutered. | 596 // a) The typed array or its buffer is neutered. |
| 599 if (key_type->Is(Type::Integral32()) && base_type->IsConstant() && | 597 if (key_type->Is(Type::Integral32()) && base_type->IsConstant() && |
| 600 base_type->AsConstant()->Value()->IsJSTypedArray()) { | 598 base_type->AsConstant()->Value()->IsJSTypedArray()) { |
| 601 // JSStoreProperty(typed-array, int32, value) | 599 // JSStoreProperty(typed-array, int32, value) |
| 602 Handle<JSTypedArray> array = | 600 Handle<JSTypedArray> array = |
| 603 Handle<JSTypedArray>::cast(base_type->AsConstant()->Value()); | 601 Handle<JSTypedArray>::cast(base_type->AsConstant()->Value()); |
| 604 if (IsExternalArrayElementsKind(array->map()->elements_kind())) { | 602 if (IsExternalArrayElementsKind(array->map()->elements_kind())) { |
| 605 ExternalArrayType type = array->type(); | 603 ExternalArrayType type = array->type(); |
| 606 uint32_t byte_length; | 604 double byte_length = array->byte_length()->Number(); |
| 607 if (array->byte_length()->ToUint32(&byte_length) && | 605 if (byte_length <= kMaxInt) { |
| 608 byte_length <= static_cast<uint32_t>(kMaxInt)) { | |
| 609 Handle<ExternalArray> elements = | 606 Handle<ExternalArray> elements = |
| 610 Handle<ExternalArray>::cast(handle(array->elements())); | 607 Handle<ExternalArray>::cast(handle(array->elements())); |
| 611 Node* pointer = jsgraph()->IntPtrConstant( | 608 Node* pointer = jsgraph()->IntPtrConstant( |
| 612 bit_cast<intptr_t>(elements->external_pointer())); | 609 bit_cast<intptr_t>(elements->external_pointer())); |
| 613 Node* length = jsgraph()->Uint32Constant( | 610 Node* length = jsgraph()->Constant(byte_length / array->element_size()); |
| 614 static_cast<uint32_t>(byte_length / array->element_size())); | |
| 615 Node* effect = NodeProperties::GetEffectInput(node); | 611 Node* effect = NodeProperties::GetEffectInput(node); |
| 616 Node* control = NodeProperties::GetControlInput(node); | 612 Node* control = NodeProperties::GetControlInput(node); |
| 617 Node* store = graph()->NewNode( | 613 Node* store = graph()->NewNode( |
| 618 simplified()->StoreElement( | 614 simplified()->StoreElement( |
| 619 AccessBuilder::ForTypedArrayElement(type, true)), | 615 AccessBuilder::ForTypedArrayElement(type, true)), |
| 620 pointer, key, length, value, effect, control); | 616 pointer, key, length, value, effect, control); |
| 621 return ReplaceEagerly(node, store); | 617 return ReplaceEagerly(node, store); |
| 622 } | 618 } |
| 623 } | 619 } |
| 624 } | 620 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 return JSBuiltinReducer(jsgraph()).Reduce(node); | 714 return JSBuiltinReducer(jsgraph()).Reduce(node); |
| 719 default: | 715 default: |
| 720 break; | 716 break; |
| 721 } | 717 } |
| 722 return NoChange(); | 718 return NoChange(); |
| 723 } | 719 } |
| 724 | 720 |
| 725 } // namespace compiler | 721 } // namespace compiler |
| 726 } // namespace internal | 722 } // namespace internal |
| 727 } // namespace v8 | 723 } // namespace v8 |
| OLD | NEW |