| 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 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 | 452 |
| 453 | 453 |
| 454 intptr_t JoinEntryInstr::IndexOfPredecessor(BlockEntryInstr* pred) const { | 454 intptr_t JoinEntryInstr::IndexOfPredecessor(BlockEntryInstr* pred) const { |
| 455 for (intptr_t i = 0; i < predecessors_.length(); ++i) { | 455 for (intptr_t i = 0; i < predecessors_.length(); ++i) { |
| 456 if (predecessors_[i] == pred) return i; | 456 if (predecessors_[i] == pred) return i; |
| 457 } | 457 } |
| 458 return -1; | 458 return -1; |
| 459 } | 459 } |
| 460 | 460 |
| 461 | 461 |
| 462 // ==== Recording assigned variables. | |
| 463 void Definition::RecordAssignedVars(BitVector* assigned_vars, | |
| 464 intptr_t fixed_parameter_count) { | |
| 465 // Nothing to do for the base class. | |
| 466 } | |
| 467 | |
| 468 | |
| 469 void StoreLocalInstr::RecordAssignedVars(BitVector* assigned_vars, | |
| 470 intptr_t fixed_parameter_count) { | |
| 471 if (!local().is_captured()) { | |
| 472 assigned_vars->Add(local().BitIndexIn(fixed_parameter_count)); | |
| 473 } | |
| 474 } | |
| 475 | |
| 476 | |
| 477 void Instruction::RecordAssignedVars(BitVector* assigned_vars, | |
| 478 intptr_t fixed_parameter_count) { | |
| 479 // Nothing to do for the base class. | |
| 480 } | |
| 481 | |
| 482 | |
| 483 void Value::AddToList(Value* value, Value** list) { | 462 void Value::AddToList(Value* value, Value** list) { |
| 484 Value* next = *list; | 463 Value* next = *list; |
| 485 *list = value; | 464 *list = value; |
| 486 value->set_next_use(next); | 465 value->set_next_use(next); |
| 487 value->set_previous_use(NULL); | 466 value->set_previous_use(NULL); |
| 488 if (next != NULL) next->set_previous_use(value); | 467 if (next != NULL) next->set_previous_use(value); |
| 489 } | 468 } |
| 490 | 469 |
| 491 | 470 |
| 492 void Value::RemoveFromUseList() { | 471 void Value::RemoveFromUseList() { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 return (i >= 0) && (i < preorder->length()) && ((*preorder)[i] == block); | 654 return (i >= 0) && (i < preorder->length()) && ((*preorder)[i] == block); |
| 676 } | 655 } |
| 677 | 656 |
| 678 | 657 |
| 679 // Base class implementation used for JoinEntry and TargetEntry. | 658 // Base class implementation used for JoinEntry and TargetEntry. |
| 680 void BlockEntryInstr::DiscoverBlocks( | 659 void BlockEntryInstr::DiscoverBlocks( |
| 681 BlockEntryInstr* predecessor, | 660 BlockEntryInstr* predecessor, |
| 682 GrowableArray<BlockEntryInstr*>* preorder, | 661 GrowableArray<BlockEntryInstr*>* preorder, |
| 683 GrowableArray<BlockEntryInstr*>* postorder, | 662 GrowableArray<BlockEntryInstr*>* postorder, |
| 684 GrowableArray<intptr_t>* parent, | 663 GrowableArray<intptr_t>* parent, |
| 685 GrowableArray<BitVector*>* assigned_vars, | |
| 686 intptr_t variable_count, | 664 intptr_t variable_count, |
| 687 intptr_t fixed_parameter_count) { | 665 intptr_t fixed_parameter_count) { |
| 688 // If this block has a predecessor (i.e., is not the graph entry) we can | 666 // If this block has a predecessor (i.e., is not the graph entry) we can |
| 689 // assume the preorder array is non-empty. | 667 // assume the preorder array is non-empty. |
| 690 ASSERT((predecessor == NULL) || !preorder->is_empty()); | 668 ASSERT((predecessor == NULL) || !preorder->is_empty()); |
| 691 // Blocks with a single predecessor cannot have been reached before. | 669 // Blocks with a single predecessor cannot have been reached before. |
| 692 ASSERT(IsJoinEntry() || !IsMarked(this, preorder)); | 670 ASSERT(IsJoinEntry() || !IsMarked(this, preorder)); |
| 693 | 671 |
| 694 // 1. If the block has already been reached, add current_block as a | 672 // 1. If the block has already been reached, add current_block as a |
| 695 // basic-block predecessor and we are done. | 673 // basic-block predecessor and we are done. |
| 696 if (IsMarked(this, preorder)) { | 674 if (IsMarked(this, preorder)) { |
| 697 ASSERT(predecessor != NULL); | 675 ASSERT(predecessor != NULL); |
| 698 AddPredecessor(predecessor); | 676 AddPredecessor(predecessor); |
| 699 return; | 677 return; |
| 700 } | 678 } |
| 701 | 679 |
| 702 // 2. Otherwise, clear the predecessors which might have been computed on | 680 // 2. Otherwise, clear the predecessors which might have been computed on |
| 703 // some earlier call to DiscoverBlocks and record this predecessor. | 681 // some earlier call to DiscoverBlocks and record this predecessor. |
| 704 ClearPredecessors(); | 682 ClearPredecessors(); |
| 705 if (predecessor != NULL) AddPredecessor(predecessor); | 683 if (predecessor != NULL) AddPredecessor(predecessor); |
| 706 | 684 |
| 707 // 3. The predecessor is the spanning-tree parent. The graph entry has no | 685 // 3. The predecessor is the spanning-tree parent. The graph entry has no |
| 708 // parent, indicated by -1. | 686 // parent, indicated by -1. |
| 709 intptr_t parent_number = | 687 intptr_t parent_number = |
| 710 (predecessor == NULL) ? -1 : predecessor->preorder_number(); | 688 (predecessor == NULL) ? -1 : predecessor->preorder_number(); |
| 711 parent->Add(parent_number); | 689 parent->Add(parent_number); |
| 712 | 690 |
| 713 // 4. Assign the preorder number and add the block entry to the list. | 691 // 4. Assign the preorder number and add the block entry to the list. |
| 714 // Allocate an empty set of assigned variables for the block. | |
| 715 set_preorder_number(preorder->length()); | 692 set_preorder_number(preorder->length()); |
| 716 preorder->Add(this); | 693 preorder->Add(this); |
| 717 BitVector* vars = | 694 |
| 718 (variable_count == 0) ? NULL : new BitVector(variable_count); | 695 // The preorder and parent arrays are indexed by |
| 719 assigned_vars->Add(vars); | |
| 720 // The preorder, parent, and assigned_vars arrays are all indexed by | |
| 721 // preorder block number, so they should stay in lockstep. | 696 // preorder block number, so they should stay in lockstep. |
| 722 ASSERT(preorder->length() == parent->length()); | 697 ASSERT(preorder->length() == parent->length()); |
| 723 ASSERT(preorder->length() == assigned_vars->length()); | |
| 724 | 698 |
| 725 // 5. Iterate straight-line successors to record assigned variables and | 699 // 5. Iterate straight-line successors to record assigned variables and |
| 726 // find the last instruction in the block. The graph entry block consists | 700 // find the last instruction in the block. The graph entry block consists |
| 727 // of only the entry instruction, so that is the last instruction in the | 701 // of only the entry instruction, so that is the last instruction in the |
| 728 // block. | 702 // block. |
| 729 Instruction* last = this; | 703 Instruction* last = this; |
| 730 for (ForwardInstructionIterator it(this); !it.Done(); it.Advance()) { | 704 for (ForwardInstructionIterator it(this); !it.Done(); it.Advance()) { |
| 731 last = it.Current(); | 705 last = it.Current(); |
| 732 if (vars != NULL) { | |
| 733 last->RecordAssignedVars(vars, fixed_parameter_count); | |
| 734 } | |
| 735 } | 706 } |
| 736 set_last_instruction(last); | 707 set_last_instruction(last); |
| 737 | 708 |
| 738 // Visit the block's successors in reverse so that they appear forwards | 709 // Visit the block's successors in reverse so that they appear forwards |
| 739 // the reverse postorder block ordering. | 710 // the reverse postorder block ordering. |
| 740 for (intptr_t i = last->SuccessorCount() - 1; i >= 0; --i) { | 711 for (intptr_t i = last->SuccessorCount() - 1; i >= 0; --i) { |
| 741 last->SuccessorAt(i)->DiscoverBlocks(this, preorder, postorder, | 712 last->SuccessorAt(i)->DiscoverBlocks(this, |
| 742 parent, assigned_vars, | 713 preorder, |
| 743 variable_count, fixed_parameter_count); | 714 postorder, |
| 715 parent, |
| 716 variable_count, |
| 717 fixed_parameter_count); |
| 744 } | 718 } |
| 745 | 719 |
| 746 // 6. Assign postorder number and add the block entry to the list. | 720 // 6. Assign postorder number and add the block entry to the list. |
| 747 set_postorder_number(postorder->length()); | 721 set_postorder_number(postorder->length()); |
| 748 postorder->Add(this); | 722 postorder->Add(this); |
| 749 } | 723 } |
| 750 | 724 |
| 751 | 725 |
| 752 bool BlockEntryInstr::Dominates(BlockEntryInstr* other) const { | 726 bool BlockEntryInstr::Dominates(BlockEntryInstr* other) const { |
| 753 // TODO(fschneider): Make this faster by e.g. storing dominators for each | 727 // TODO(fschneider): Make this faster by e.g. storing dominators for each |
| (...skipping 1660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2414 default: | 2388 default: |
| 2415 UNREACHABLE(); | 2389 UNREACHABLE(); |
| 2416 } | 2390 } |
| 2417 return kPowRuntimeEntry; | 2391 return kPowRuntimeEntry; |
| 2418 } | 2392 } |
| 2419 | 2393 |
| 2420 | 2394 |
| 2421 #undef __ | 2395 #undef __ |
| 2422 | 2396 |
| 2423 } // namespace dart | 2397 } // namespace dart |
| OLD | NEW |