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 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 Type* base_type = NodeProperties::GetBounds(base).upper; | 534 Type* base_type = NodeProperties::GetBounds(base).upper; |
535 // TODO(mstarzinger): This lowering is not correct if: | 535 // TODO(mstarzinger): This lowering is not correct if: |
536 // a) The typed array or it's buffer is neutered. | 536 // a) The typed array or it's buffer is neutered. |
537 if (base_type->IsConstant() && key_type->Is(Type::Integral32()) && | 537 if (base_type->IsConstant() && key_type->Is(Type::Integral32()) && |
538 base_type->AsConstant()->Value()->IsJSTypedArray()) { | 538 base_type->AsConstant()->Value()->IsJSTypedArray()) { |
539 // JSLoadProperty(typed-array, int32) | 539 // JSLoadProperty(typed-array, int32) |
540 Handle<JSTypedArray> array = | 540 Handle<JSTypedArray> array = |
541 Handle<JSTypedArray>::cast(base_type->AsConstant()->Value()); | 541 Handle<JSTypedArray>::cast(base_type->AsConstant()->Value()); |
542 if (IsExternalArrayElementsKind(array->map()->elements_kind())) { | 542 if (IsExternalArrayElementsKind(array->map()->elements_kind())) { |
543 ExternalArrayType type = array->type(); | 543 ExternalArrayType type = array->type(); |
544 uint32_t length; | 544 uint32_t byte_length; |
545 CHECK(array->length()->ToUint32(&length)); | 545 if (array->byte_length()->ToUint32(&byte_length)) { |
546 Node* elements = graph()->NewNode( | 546 Node* elements = graph()->NewNode( |
547 simplified()->LoadField(AccessBuilder::ForJSObjectElements()), base, | 547 simplified()->LoadField(AccessBuilder::ForJSObjectElements()), base, |
548 graph()->start()); | 548 graph()->start()); |
549 Node* pointer = graph()->NewNode( | 549 Node* pointer = graph()->NewNode( |
550 simplified()->LoadField(AccessBuilder::ForExternalArrayPointer()), | 550 simplified()->LoadField(AccessBuilder::ForExternalArrayPointer()), |
551 elements, elements); | 551 elements, elements); |
552 Node* effect = NodeProperties::GetEffectInput(node); | 552 Node* length = jsgraph()->Uint32Constant( |
553 Node* control = NodeProperties::GetControlInput(node); | 553 static_cast<uint32_t>(byte_length / array->element_size())); |
554 Node* load = graph()->NewNode( | 554 Node* effect = NodeProperties::GetEffectInput(node); |
555 simplified()->LoadElement( | 555 Node* control = NodeProperties::GetControlInput(node); |
556 AccessBuilder::ForTypedArrayElement(type, true)), | 556 Node* load = graph()->NewNode( |
557 pointer, key, jsgraph()->Uint32Constant(length), effect, control); | 557 simplified()->LoadElement( |
558 return ReplaceEagerly(node, load); | 558 AccessBuilder::ForTypedArrayElement(type, true)), |
| 559 pointer, key, length, effect, control); |
| 560 return ReplaceEagerly(node, load); |
| 561 } |
559 } | 562 } |
560 } | 563 } |
561 return NoChange(); | 564 return NoChange(); |
562 } | 565 } |
563 | 566 |
564 | 567 |
565 Reduction JSTypedLowering::ReduceJSStoreProperty(Node* node) { | 568 Reduction JSTypedLowering::ReduceJSStoreProperty(Node* node) { |
566 Node* key = NodeProperties::GetValueInput(node, 1); | 569 Node* key = NodeProperties::GetValueInput(node, 1); |
567 Node* base = NodeProperties::GetValueInput(node, 0); | 570 Node* base = NodeProperties::GetValueInput(node, 0); |
568 Node* value = NodeProperties::GetValueInput(node, 2); | 571 Node* value = NodeProperties::GetValueInput(node, 2); |
569 Type* key_type = NodeProperties::GetBounds(key).upper; | 572 Type* key_type = NodeProperties::GetBounds(key).upper; |
570 Type* base_type = NodeProperties::GetBounds(base).upper; | 573 Type* base_type = NodeProperties::GetBounds(base).upper; |
571 // TODO(mstarzinger): This lowering is not correct if: | 574 // TODO(mstarzinger): This lowering is not correct if: |
572 // a) The typed array or its buffer is neutered. | 575 // a) The typed array or its buffer is neutered. |
573 if (key_type->Is(Type::Integral32()) && base_type->IsConstant() && | 576 if (key_type->Is(Type::Integral32()) && base_type->IsConstant() && |
574 base_type->AsConstant()->Value()->IsJSTypedArray()) { | 577 base_type->AsConstant()->Value()->IsJSTypedArray()) { |
575 // JSStoreProperty(typed-array, int32, value) | 578 // JSStoreProperty(typed-array, int32, value) |
576 Handle<JSTypedArray> array = | 579 Handle<JSTypedArray> array = |
577 Handle<JSTypedArray>::cast(base_type->AsConstant()->Value()); | 580 Handle<JSTypedArray>::cast(base_type->AsConstant()->Value()); |
578 if (IsExternalArrayElementsKind(array->map()->elements_kind())) { | 581 if (IsExternalArrayElementsKind(array->map()->elements_kind())) { |
579 ExternalArrayType type = array->type(); | 582 ExternalArrayType type = array->type(); |
580 uint32_t length; | 583 uint32_t byte_length; |
581 CHECK(array->length()->ToUint32(&length)); | 584 if (array->byte_length()->ToUint32(&byte_length)) { |
582 Node* elements = graph()->NewNode( | 585 Node* elements = graph()->NewNode( |
583 simplified()->LoadField(AccessBuilder::ForJSObjectElements()), base, | 586 simplified()->LoadField(AccessBuilder::ForJSObjectElements()), base, |
584 graph()->start()); | 587 graph()->start()); |
585 Node* pointer = graph()->NewNode( | 588 Node* pointer = graph()->NewNode( |
586 simplified()->LoadField(AccessBuilder::ForExternalArrayPointer()), | 589 simplified()->LoadField(AccessBuilder::ForExternalArrayPointer()), |
587 elements, elements); | 590 elements, elements); |
588 Node* effect = NodeProperties::GetEffectInput(node); | 591 Node* length = jsgraph()->Uint32Constant( |
589 Node* control = NodeProperties::GetControlInput(node); | 592 static_cast<uint32_t>(byte_length / array->element_size())); |
590 Node* store = | 593 Node* effect = NodeProperties::GetEffectInput(node); |
591 graph()->NewNode(simplified()->StoreElement( | 594 Node* control = NodeProperties::GetControlInput(node); |
592 AccessBuilder::ForTypedArrayElement(type, true)), | 595 Node* store = graph()->NewNode( |
593 pointer, key, jsgraph()->Uint32Constant(length), | 596 simplified()->StoreElement( |
594 value, effect, control); | 597 AccessBuilder::ForTypedArrayElement(type, true)), |
595 return ReplaceEagerly(node, store); | 598 pointer, key, length, value, effect, control); |
| 599 return ReplaceEagerly(node, store); |
| 600 } |
596 } | 601 } |
597 } | 602 } |
598 return NoChange(); | 603 return NoChange(); |
599 } | 604 } |
600 | 605 |
601 | 606 |
602 static Reduction ReplaceWithReduction(Node* node, Reduction reduction) { | 607 static Reduction ReplaceWithReduction(Node* node, Reduction reduction) { |
603 if (reduction.Changed()) { | 608 if (reduction.Changed()) { |
604 NodeProperties::ReplaceWithValue(node, reduction.replacement()); | 609 NodeProperties::ReplaceWithValue(node, reduction.replacement()); |
605 return reduction; | 610 return reduction; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 return JSBuiltinReducer(jsgraph()).Reduce(node); | 695 return JSBuiltinReducer(jsgraph()).Reduce(node); |
691 default: | 696 default: |
692 break; | 697 break; |
693 } | 698 } |
694 return NoChange(); | 699 return NoChange(); |
695 } | 700 } |
696 | 701 |
697 } // namespace compiler | 702 } // namespace compiler |
698 } // namespace internal | 703 } // namespace internal |
699 } // namespace v8 | 704 } // namespace v8 |
OLD | NEW |