Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/load-elimination.h" | 5 #include "src/compiler/load-elimination.h" |
| 6 | 6 |
| 7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
| 8 #include "src/compiler/node-properties.h" | 8 #include "src/compiler/node-properties.h" |
| 9 #include "src/compiler/simplified-operator.h" | 9 #include "src/compiler/simplified-operator.h" |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 bool MustAlias(Node* a, Node* b) { return QueryAlias(a, b) == kMustAlias; } | 49 bool MustAlias(Node* a, Node* b) { return QueryAlias(a, b) == kMustAlias; } |
| 50 | 50 |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 Reduction LoadElimination::Reduce(Node* node) { | 53 Reduction LoadElimination::Reduce(Node* node) { |
| 54 switch (node->opcode()) { | 54 switch (node->opcode()) { |
| 55 case IrOpcode::kCheckMaps: | 55 case IrOpcode::kCheckMaps: |
| 56 return ReduceCheckMaps(node); | 56 return ReduceCheckMaps(node); |
| 57 case IrOpcode::kEnsureWritableFastElements: | 57 case IrOpcode::kEnsureWritableFastElements: |
| 58 return ReduceEnsureWritableFastElements(node); | 58 return ReduceEnsureWritableFastElements(node); |
| 59 case IrOpcode::kMaybeGrowFastElements: | |
| 60 return ReduceMaybeGrowFastElements(node); | |
| 59 case IrOpcode::kTransitionElementsKind: | 61 case IrOpcode::kTransitionElementsKind: |
| 60 return ReduceTransitionElementsKind(node); | 62 return ReduceTransitionElementsKind(node); |
| 61 case IrOpcode::kLoadField: | 63 case IrOpcode::kLoadField: |
| 62 return ReduceLoadField(node); | 64 return ReduceLoadField(node); |
| 63 case IrOpcode::kStoreField: | 65 case IrOpcode::kStoreField: |
| 64 return ReduceStoreField(node); | 66 return ReduceStoreField(node); |
| 65 case IrOpcode::kLoadElement: | 67 case IrOpcode::kLoadElement: |
| 66 return ReduceLoadElement(node); | 68 return ReduceLoadElement(node); |
| 67 case IrOpcode::kStoreElement: | 69 case IrOpcode::kStoreElement: |
| 68 return ReduceStoreElement(node); | 70 return ReduceStoreElement(node); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 } | 347 } |
| 346 // We know that the resulting elements have the fixed array map. | 348 // We know that the resulting elements have the fixed array map. |
| 347 state = state->AddField(node, 0, fixed_array_map, zone()); | 349 state = state->AddField(node, 0, fixed_array_map, zone()); |
| 348 // Kill the previous elements on {object}. | 350 // Kill the previous elements on {object}. |
| 349 state = state->KillField(object, 2, zone()); | 351 state = state->KillField(object, 2, zone()); |
| 350 // Add the new elements on {object}. | 352 // Add the new elements on {object}. |
| 351 state = state->AddField(object, 2, node, zone()); | 353 state = state->AddField(object, 2, node, zone()); |
| 352 return UpdateState(node, state); | 354 return UpdateState(node, state); |
| 353 } | 355 } |
| 354 | 356 |
| 357 Reduction LoadElimination::ReduceMaybeGrowFastElements(Node* node) { | |
| 358 GrowFastElementsFlags flags = GrowFastElementsFlagsOf(node->op()); | |
| 359 Node* const object = NodeProperties::GetValueInput(node, 0); | |
| 360 Node* const effect = NodeProperties::GetEffectInput(node); | |
| 361 AbstractState const* state = node_states_.Get(effect); | |
| 362 if (state == nullptr) return NoChange(); | |
| 363 if (flags & GrowFastElementsFlag::kDoubleElements) { | |
| 364 // We know that the resulting elements have the fixed double array map. | |
| 365 Node* fixed_double_array_map = jsgraph()->FixedDoubleArrayMapConstant(); | |
| 366 state = state->AddField(node, 0, fixed_double_array_map, zone()); | |
| 367 } else { | |
| 368 // We know that the resulting elements have the fixed array map. | |
| 369 Node* fixed_array_map = jsgraph()->FixedArrayMapConstant(); | |
| 370 state = state->AddField(node, 0, fixed_array_map, zone()); | |
| 371 } | |
| 372 if (flags & GrowFastElementsFlag::kArrayObject) { | |
| 373 // Kill the previous Array::length on {object}. | |
| 374 state = state->KillField(object, 3, zone()); | |
| 375 } | |
| 376 // Kill the previous elements on {object}. | |
| 377 state = state->KillField(object, 2, zone()); | |
| 378 // Add the new elements on {object}. | |
| 379 state = state->AddField(object, 2, node, zone()); | |
| 380 return UpdateState(node, state); | |
| 381 } | |
| 382 | |
| 355 Reduction LoadElimination::ReduceTransitionElementsKind(Node* node) { | 383 Reduction LoadElimination::ReduceTransitionElementsKind(Node* node) { |
| 356 Node* const object = NodeProperties::GetValueInput(node, 0); | 384 Node* const object = NodeProperties::GetValueInput(node, 0); |
| 357 Node* const source_map = NodeProperties::GetValueInput(node, 1); | 385 Node* const source_map = NodeProperties::GetValueInput(node, 1); |
| 358 Node* const target_map = NodeProperties::GetValueInput(node, 2); | 386 Node* const target_map = NodeProperties::GetValueInput(node, 2); |
| 359 Node* const effect = NodeProperties::GetEffectInput(node); | 387 Node* const effect = NodeProperties::GetEffectInput(node); |
| 360 AbstractState const* state = node_states_.Get(effect); | 388 AbstractState const* state = node_states_.Get(effect); |
| 361 if (state == nullptr) return NoChange(); | 389 if (state == nullptr) return NoChange(); |
| 362 if (Node* const object_map = state->LookupField(object, 0)) { | 390 if (Node* const object_map = state->LookupField(object, 0)) { |
| 363 state = state->KillField(object, 0, zone()); | 391 state = state->KillField(object, 0, zone()); |
| 364 if (source_map == object_map) { | 392 if (source_map == object_map) { |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 573 } | 601 } |
| 574 while (!queue.empty()) { | 602 while (!queue.empty()) { |
| 575 Node* const current = queue.front(); | 603 Node* const current = queue.front(); |
| 576 queue.pop(); | 604 queue.pop(); |
| 577 if (visited.find(current) == visited.end()) { | 605 if (visited.find(current) == visited.end()) { |
| 578 visited.insert(current); | 606 visited.insert(current); |
| 579 if (!current->op()->HasProperty(Operator::kNoWrite)) { | 607 if (!current->op()->HasProperty(Operator::kNoWrite)) { |
| 580 switch (current->opcode()) { | 608 switch (current->opcode()) { |
| 581 case IrOpcode::kEnsureWritableFastElements: { | 609 case IrOpcode::kEnsureWritableFastElements: { |
| 582 Node* const object = NodeProperties::GetValueInput(current, 0); | 610 Node* const object = NodeProperties::GetValueInput(current, 0); |
| 583 Node* const elements = NodeProperties::GetValueInput(current, 1); | |
| 584 state = state->KillField(elements, 0, zone()); | |
| 585 state = state->KillField(object, 2, zone()); | 611 state = state->KillField(object, 2, zone()); |
| 586 break; | 612 break; |
| 587 } | 613 } |
| 614 case IrOpcode::kMaybeGrowFastElements: { | |
| 615 GrowFastElementsFlags flags = | |
| 616 GrowFastElementsFlagsOf(current->op()); | |
| 617 Node* const object = NodeProperties::GetValueInput(current, 0); | |
| 618 state = state->KillField(object, 2, zone()); | |
|
Jarin
2016/08/08 08:03:47
Should not the magic numbers (like 2 here and 3 be
Benedikt Meurer
2016/08/08 08:12:55
Acknowledged. On the TODO list.
| |
| 619 if (flags & GrowFastElementsFlag::kArrayObject) { | |
| 620 state = state->KillField(object, 3, zone()); | |
| 621 } | |
| 622 break; | |
| 623 } | |
| 588 case IrOpcode::kTransitionElementsKind: { | 624 case IrOpcode::kTransitionElementsKind: { |
| 589 Node* const object = NodeProperties::GetValueInput(current, 0); | 625 Node* const object = NodeProperties::GetValueInput(current, 0); |
| 590 state = state->KillField(object, 0, zone()); | 626 state = state->KillField(object, 0, zone()); |
| 591 state = state->KillField(object, 2, zone()); | 627 state = state->KillField(object, 2, zone()); |
| 592 break; | 628 break; |
| 593 } | 629 } |
| 594 case IrOpcode::kStoreField: { | 630 case IrOpcode::kStoreField: { |
| 595 FieldAccess const& access = FieldAccessOf(current->op()); | 631 FieldAccess const& access = FieldAccessOf(current->op()); |
| 596 Node* const object = NodeProperties::GetValueInput(current, 0); | 632 Node* const object = NodeProperties::GetValueInput(current, 0); |
| 597 int field_index = FieldIndexOf(access); | 633 int field_index = FieldIndexOf(access); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 650 DCHECK_EQ(kTaggedBase, access.base_is_tagged); | 686 DCHECK_EQ(kTaggedBase, access.base_is_tagged); |
| 651 DCHECK_EQ(0, access.offset % kPointerSize); | 687 DCHECK_EQ(0, access.offset % kPointerSize); |
| 652 int field_index = access.offset / kPointerSize; | 688 int field_index = access.offset / kPointerSize; |
| 653 if (field_index >= static_cast<int>(kMaxTrackedFields)) return -1; | 689 if (field_index >= static_cast<int>(kMaxTrackedFields)) return -1; |
| 654 return field_index; | 690 return field_index; |
| 655 } | 691 } |
| 656 | 692 |
| 657 } // namespace compiler | 693 } // namespace compiler |
| 658 } // namespace internal | 694 } // namespace internal |
| 659 } // namespace v8 | 695 } // namespace v8 |
| OLD | NEW |