| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/intermediate_language.h" | 5 #include "vm/intermediate_language.h" |
| 6 | 6 |
| 7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/dart_entry.h" | 8 #include "vm/dart_entry.h" |
| 9 #include "vm/flow_graph_allocator.h" | 9 #include "vm/flow_graph_allocator.h" |
| 10 #include "vm/flow_graph_builder.h" | 10 #include "vm/flow_graph_builder.h" |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 | 451 |
| 452 | 452 |
| 453 intptr_t JoinEntryInstr::IndexOfPredecessor(BlockEntryInstr* pred) const { | 453 intptr_t JoinEntryInstr::IndexOfPredecessor(BlockEntryInstr* pred) const { |
| 454 for (intptr_t i = 0; i < predecessors_.length(); ++i) { | 454 for (intptr_t i = 0; i < predecessors_.length(); ++i) { |
| 455 if (predecessors_[i] == pred) return i; | 455 if (predecessors_[i] == pred) return i; |
| 456 } | 456 } |
| 457 return -1; | 457 return -1; |
| 458 } | 458 } |
| 459 | 459 |
| 460 | 460 |
| 461 // ==== Recording assigned variables. | |
| 462 void Definition::RecordAssignedVars(BitVector* assigned_vars, | |
| 463 intptr_t fixed_parameter_count) { | |
| 464 // Nothing to do for the base class. | |
| 465 } | |
| 466 | |
| 467 | |
| 468 void StoreLocalInstr::RecordAssignedVars(BitVector* assigned_vars, | |
| 469 intptr_t fixed_parameter_count) { | |
| 470 if (!local().is_captured()) { | |
| 471 assigned_vars->Add(local().BitIndexIn(fixed_parameter_count)); | |
| 472 } | |
| 473 } | |
| 474 | |
| 475 | |
| 476 void Instruction::RecordAssignedVars(BitVector* assigned_vars, | |
| 477 intptr_t fixed_parameter_count) { | |
| 478 // Nothing to do for the base class. | |
| 479 } | |
| 480 | |
| 481 | |
| 482 void Value::AddToList(Value* value, Value** list) { | 461 void Value::AddToList(Value* value, Value** list) { |
| 483 Value* next = *list; | 462 Value* next = *list; |
| 484 *list = value; | 463 *list = value; |
| 485 value->set_next_use(next); | 464 value->set_next_use(next); |
| 486 value->set_previous_use(NULL); | 465 value->set_previous_use(NULL); |
| 487 if (next != NULL) next->set_previous_use(value); | 466 if (next != NULL) next->set_previous_use(value); |
| 488 } | 467 } |
| 489 | 468 |
| 490 | 469 |
| 491 void Value::RemoveFromUseList() { | 470 void Value::RemoveFromUseList() { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 return (i >= 0) && (i < preorder->length()) && ((*preorder)[i] == block); | 630 return (i >= 0) && (i < preorder->length()) && ((*preorder)[i] == block); |
| 652 } | 631 } |
| 653 | 632 |
| 654 | 633 |
| 655 // Base class implementation used for JoinEntry and TargetEntry. | 634 // Base class implementation used for JoinEntry and TargetEntry. |
| 656 void BlockEntryInstr::DiscoverBlocks( | 635 void BlockEntryInstr::DiscoverBlocks( |
| 657 BlockEntryInstr* predecessor, | 636 BlockEntryInstr* predecessor, |
| 658 GrowableArray<BlockEntryInstr*>* preorder, | 637 GrowableArray<BlockEntryInstr*>* preorder, |
| 659 GrowableArray<BlockEntryInstr*>* postorder, | 638 GrowableArray<BlockEntryInstr*>* postorder, |
| 660 GrowableArray<intptr_t>* parent, | 639 GrowableArray<intptr_t>* parent, |
| 661 GrowableArray<BitVector*>* assigned_vars, | |
| 662 intptr_t variable_count, | 640 intptr_t variable_count, |
| 663 intptr_t fixed_parameter_count) { | 641 intptr_t fixed_parameter_count) { |
| 664 // If this block has a predecessor (i.e., is not the graph entry) we can | 642 // If this block has a predecessor (i.e., is not the graph entry) we can |
| 665 // assume the preorder array is non-empty. | 643 // assume the preorder array is non-empty. |
| 666 ASSERT((predecessor == NULL) || !preorder->is_empty()); | 644 ASSERT((predecessor == NULL) || !preorder->is_empty()); |
| 667 // Blocks with a single predecessor cannot have been reached before. | 645 // Blocks with a single predecessor cannot have been reached before. |
| 668 ASSERT(IsJoinEntry() || !IsMarked(this, preorder)); | 646 ASSERT(IsJoinEntry() || !IsMarked(this, preorder)); |
| 669 | 647 |
| 670 // 1. If the block has already been reached, add current_block as a | 648 // 1. If the block has already been reached, add current_block as a |
| 671 // basic-block predecessor and we are done. | 649 // basic-block predecessor and we are done. |
| 672 if (IsMarked(this, preorder)) { | 650 if (IsMarked(this, preorder)) { |
| 673 ASSERT(predecessor != NULL); | 651 ASSERT(predecessor != NULL); |
| 674 AddPredecessor(predecessor); | 652 AddPredecessor(predecessor); |
| 675 return; | 653 return; |
| 676 } | 654 } |
| 677 | 655 |
| 678 // 2. Otherwise, clear the predecessors which might have been computed on | 656 // 2. Otherwise, clear the predecessors which might have been computed on |
| 679 // some earlier call to DiscoverBlocks and record this predecessor. | 657 // some earlier call to DiscoverBlocks and record this predecessor. |
| 680 ClearPredecessors(); | 658 ClearPredecessors(); |
| 681 if (predecessor != NULL) AddPredecessor(predecessor); | 659 if (predecessor != NULL) AddPredecessor(predecessor); |
| 682 | 660 |
| 683 // 3. The predecessor is the spanning-tree parent. The graph entry has no | 661 // 3. The predecessor is the spanning-tree parent. The graph entry has no |
| 684 // parent, indicated by -1. | 662 // parent, indicated by -1. |
| 685 intptr_t parent_number = | 663 intptr_t parent_number = |
| 686 (predecessor == NULL) ? -1 : predecessor->preorder_number(); | 664 (predecessor == NULL) ? -1 : predecessor->preorder_number(); |
| 687 parent->Add(parent_number); | 665 parent->Add(parent_number); |
| 688 | 666 |
| 689 // 4. Assign the preorder number and add the block entry to the list. | 667 // 4. Assign the preorder number and add the block entry to the list. |
| 690 // Allocate an empty set of assigned variables for the block. | |
| 691 set_preorder_number(preorder->length()); | 668 set_preorder_number(preorder->length()); |
| 692 preorder->Add(this); | 669 preorder->Add(this); |
| 693 BitVector* vars = | 670 |
| 694 (variable_count == 0) ? NULL : new BitVector(variable_count); | 671 // The preorder and parent arrays are indexed by |
| 695 assigned_vars->Add(vars); | |
| 696 // The preorder, parent, and assigned_vars arrays are all indexed by | |
| 697 // preorder block number, so they should stay in lockstep. | 672 // preorder block number, so they should stay in lockstep. |
| 698 ASSERT(preorder->length() == parent->length()); | 673 ASSERT(preorder->length() == parent->length()); |
| 699 ASSERT(preorder->length() == assigned_vars->length()); | |
| 700 | 674 |
| 701 // 5. Iterate straight-line successors to record assigned variables and | 675 // 5. Iterate straight-line successors to record assigned variables and |
| 702 // find the last instruction in the block. The graph entry block consists | 676 // find the last instruction in the block. The graph entry block consists |
| 703 // of only the entry instruction, so that is the last instruction in the | 677 // of only the entry instruction, so that is the last instruction in the |
| 704 // block. | 678 // block. |
| 705 Instruction* last = this; | 679 Instruction* last = this; |
| 706 for (ForwardInstructionIterator it(this); !it.Done(); it.Advance()) { | 680 for (ForwardInstructionIterator it(this); !it.Done(); it.Advance()) { |
| 707 last = it.Current(); | 681 last = it.Current(); |
| 708 if (vars != NULL) { | |
| 709 last->RecordAssignedVars(vars, fixed_parameter_count); | |
| 710 } | |
| 711 } | 682 } |
| 712 set_last_instruction(last); | 683 set_last_instruction(last); |
| 713 | 684 |
| 714 // Visit the block's successors in reverse so that they appear forwards | 685 // Visit the block's successors in reverse so that they appear forwards |
| 715 // the reverse postorder block ordering. | 686 // the reverse postorder block ordering. |
| 716 for (intptr_t i = last->SuccessorCount() - 1; i >= 0; --i) { | 687 for (intptr_t i = last->SuccessorCount() - 1; i >= 0; --i) { |
| 717 last->SuccessorAt(i)->DiscoverBlocks(this, preorder, postorder, | 688 last->SuccessorAt(i)->DiscoverBlocks(this, |
| 718 parent, assigned_vars, | 689 preorder, |
| 719 variable_count, fixed_parameter_count); | 690 postorder, |
| 691 parent, |
| 692 variable_count, |
| 693 fixed_parameter_count); |
| 720 } | 694 } |
| 721 | 695 |
| 722 // 6. Assign postorder number and add the block entry to the list. | 696 // 6. Assign postorder number and add the block entry to the list. |
| 723 set_postorder_number(postorder->length()); | 697 set_postorder_number(postorder->length()); |
| 724 postorder->Add(this); | 698 postorder->Add(this); |
| 725 } | 699 } |
| 726 | 700 |
| 727 | 701 |
| 728 bool BlockEntryInstr::Dominates(BlockEntryInstr* other) const { | 702 bool BlockEntryInstr::Dominates(BlockEntryInstr* other) const { |
| 729 // TODO(fschneider): Make this faster by e.g. storing dominators for each | 703 // TODO(fschneider): Make this faster by e.g. storing dominators for each |
| (...skipping 1608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2338 default: | 2312 default: |
| 2339 UNREACHABLE(); | 2313 UNREACHABLE(); |
| 2340 } | 2314 } |
| 2341 return kPowRuntimeEntry; | 2315 return kPowRuntimeEntry; |
| 2342 } | 2316 } |
| 2343 | 2317 |
| 2344 | 2318 |
| 2345 #undef __ | 2319 #undef __ |
| 2346 | 2320 |
| 2347 } // namespace dart | 2321 } // namespace dart |
| OLD | NEW |