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/graph-inl.h" | 6 #include "src/compiler/graph-inl.h" |
6 #include "src/compiler/js-typed-lowering.h" | 7 #include "src/compiler/js-typed-lowering.h" |
7 #include "src/compiler/node-aux-data-inl.h" | 8 #include "src/compiler/node-aux-data-inl.h" |
8 #include "src/compiler/node-properties-inl.h" | 9 #include "src/compiler/node-properties-inl.h" |
9 #include "src/types.h" | 10 #include "src/types.h" |
10 | 11 |
11 namespace v8 { | 12 namespace v8 { |
12 namespace internal { | 13 namespace internal { |
13 namespace compiler { | 14 namespace compiler { |
14 | 15 |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 ReplaceEagerly(input, inv); | 493 ReplaceEagerly(input, inv); |
493 // TODO(titzer): Ugly. ReplaceEagerly smashes all uses. Smash it back here. | 494 // TODO(titzer): Ugly. ReplaceEagerly smashes all uses. Smash it back here. |
494 cmp->ReplaceInput(0, input); | 495 cmp->ReplaceInput(0, input); |
495 return Changed(inv); | 496 return Changed(inv); |
496 } | 497 } |
497 // TODO(turbofan): js-typed-lowering of ToBoolean(string) | 498 // TODO(turbofan): js-typed-lowering of ToBoolean(string) |
498 return NoChange(); | 499 return NoChange(); |
499 } | 500 } |
500 | 501 |
501 | 502 |
| 503 Reduction JSTypedLowering::ReduceJSPropertyLoad(Node* node) { |
| 504 Node* key = NodeProperties::GetValueInput(node, 1); |
| 505 Node* base = NodeProperties::GetValueInput(node, 0); |
| 506 Type* key_type = NodeProperties::GetBounds(key).upper; |
| 507 Type* base_type = NodeProperties::GetBounds(base).upper; |
| 508 // TODO(mstarzinger): This lowering is not correct if: |
| 509 // a) The typed array turns external (i.e. MaterializeArrayBuffer) |
| 510 // b) The typed array or it's buffer is neutered. |
| 511 // c) The index is out of bounds. |
| 512 if (base_type->IsConstant() && key_type->Is(Type::Integral32()) && |
| 513 base_type->AsConstant()->Value()->IsJSTypedArray()) { |
| 514 // JSLoadProperty(typed-array, int32) |
| 515 JSTypedArray* array = JSTypedArray::cast(*base_type->AsConstant()->Value()); |
| 516 ElementsKind elements_kind = array->map()->elements_kind(); |
| 517 ExternalArrayType type = array->type(); |
| 518 ElementAccess element_access; |
| 519 Node* elements = graph()->NewNode( |
| 520 simplified()->LoadField(AccessBuilder::ForJSObjectElements()), base, |
| 521 NodeProperties::GetEffectInput(node)); |
| 522 if (IsExternalArrayElementsKind(elements_kind)) { |
| 523 elements = graph()->NewNode( |
| 524 simplified()->LoadField(AccessBuilder::ForExternalArrayPointer()), |
| 525 elements, NodeProperties::GetEffectInput(node)); |
| 526 element_access = AccessBuilder::ForTypedArrayElement(type, true); |
| 527 } else { |
| 528 DCHECK(IsFixedTypedArrayElementsKind(elements_kind)); |
| 529 element_access = AccessBuilder::ForTypedArrayElement(type, false); |
| 530 } |
| 531 Node* value = |
| 532 graph()->NewNode(simplified()->LoadElement(element_access), elements, |
| 533 key, NodeProperties::GetEffectInput(node)); |
| 534 return ReplaceEagerly(node, value); |
| 535 } |
| 536 return NoChange(); |
| 537 } |
| 538 |
| 539 |
502 static Reduction ReplaceWithReduction(Node* node, Reduction reduction) { | 540 static Reduction ReplaceWithReduction(Node* node, Reduction reduction) { |
503 if (reduction.Changed()) { | 541 if (reduction.Changed()) { |
504 NodeProperties::ReplaceWithValue(node, reduction.replacement()); | 542 NodeProperties::ReplaceWithValue(node, reduction.replacement()); |
505 return reduction; | 543 return reduction; |
506 } | 544 } |
507 return Reducer::NoChange(); | 545 return Reducer::NoChange(); |
508 } | 546 } |
509 | 547 |
510 | 548 |
511 Reduction JSTypedLowering::Reduce(Node* node) { | 549 Reduction JSTypedLowering::Reduce(Node* node) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 } | 604 } |
567 case IrOpcode::kJSToBoolean: | 605 case IrOpcode::kJSToBoolean: |
568 return ReplaceWithReduction(node, | 606 return ReplaceWithReduction(node, |
569 ReduceJSToBooleanInput(node->InputAt(0))); | 607 ReduceJSToBooleanInput(node->InputAt(0))); |
570 case IrOpcode::kJSToNumber: | 608 case IrOpcode::kJSToNumber: |
571 return ReplaceWithReduction(node, | 609 return ReplaceWithReduction(node, |
572 ReduceJSToNumberInput(node->InputAt(0))); | 610 ReduceJSToNumberInput(node->InputAt(0))); |
573 case IrOpcode::kJSToString: | 611 case IrOpcode::kJSToString: |
574 return ReplaceWithReduction(node, | 612 return ReplaceWithReduction(node, |
575 ReduceJSToStringInput(node->InputAt(0))); | 613 ReduceJSToStringInput(node->InputAt(0))); |
| 614 case IrOpcode::kJSLoadProperty: |
| 615 return ReduceJSPropertyLoad(node); |
576 default: | 616 default: |
577 break; | 617 break; |
578 } | 618 } |
579 return NoChange(); | 619 return NoChange(); |
580 } | 620 } |
581 } | 621 } |
582 } | 622 } |
583 } // namespace v8::internal::compiler | 623 } // namespace v8::internal::compiler |
OLD | NEW |