| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 <deque> | 5 #include <deque> |
| 6 #include <queue> | 6 #include <queue> |
| 7 | 7 |
| 8 #include "src/compiler/scheduler.h" | 8 #include "src/compiler/scheduler.h" |
| 9 | 9 |
| 10 #include "src/bit-vector.h" | 10 #include "src/bit-vector.h" |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 // 2. All loops are contiguous in the order (i.e. no intervening blocks that | 520 // 2. All loops are contiguous in the order (i.e. no intervening blocks that |
| 521 // do not belong to the loop.) | 521 // do not belong to the loop.) |
| 522 // Note a simple RPO traversal satisfies (1) but not (2). | 522 // Note a simple RPO traversal satisfies (1) but not (2). |
| 523 class SpecialRPONumberer : public ZoneObject { | 523 class SpecialRPONumberer : public ZoneObject { |
| 524 public: | 524 public: |
| 525 SpecialRPONumberer(Zone* zone, Schedule* schedule) | 525 SpecialRPONumberer(Zone* zone, Schedule* schedule) |
| 526 : zone_(zone), | 526 : zone_(zone), |
| 527 schedule_(schedule), | 527 schedule_(schedule), |
| 528 order_(NULL), | 528 order_(NULL), |
| 529 loops_(zone), | 529 loops_(zone), |
| 530 beyond_end_(NULL), |
| 530 backedges_(1, zone), | 531 backedges_(1, zone), |
| 531 stack_(zone), | 532 stack_(zone), |
| 532 previous_block_count_(0) {} | 533 previous_block_count_(0) {} |
| 533 | 534 |
| 534 // Computes the special reverse-post-order for the main control flow graph, | 535 // Computes the special reverse-post-order for the main control flow graph, |
| 535 // that is for the graph spanned between the schedule's start and end blocks. | 536 // that is for the graph spanned between the schedule's start and end blocks. |
| 536 void ComputeSpecialRPO() { | 537 void ComputeSpecialRPO() { |
| 537 DCHECK(schedule_->end()->SuccessorCount() == 0); | |
| 538 DCHECK_EQ(NULL, order_); // Main order does not exist yet. | 538 DCHECK_EQ(NULL, order_); // Main order does not exist yet. |
| 539 ComputeAndInsertSpecialRPO(schedule_->start(), schedule_->end()); | 539 // TODO(mstarzinger): Should use Schedule::end() after tests are fixed. |
| 540 ComputeAndInsertSpecialRPO(schedule_->start(), NULL); |
| 540 } | 541 } |
| 541 | 542 |
| 542 // Computes the special reverse-post-order for a partial control flow graph, | 543 // Computes the special reverse-post-order for a partial control flow graph, |
| 543 // that is for the graph spanned between the given {entry} and {end} blocks, | 544 // that is for the graph spanned between the given {entry} and {end} blocks, |
| 544 // then updates the existing ordering with this new information. | 545 // then updates the existing ordering with this new information. |
| 545 void UpdateSpecialRPO(BasicBlock* entry, BasicBlock* end) { | 546 void UpdateSpecialRPO(BasicBlock* entry, BasicBlock* end) { |
| 546 DCHECK_NE(NULL, order_); // Main order to be updated is present. | 547 DCHECK_NE(NULL, order_); // Main order to be updated is present. |
| 547 ComputeAndInsertSpecialRPO(entry, end); | 548 ComputeAndInsertSpecialRPO(entry, end); |
| 548 } | 549 } |
| 549 | 550 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 562 } | 563 } |
| 563 | 564 |
| 564 // Serialize the previously computed order as a special reverse-post-order | 565 // Serialize the previously computed order as a special reverse-post-order |
| 565 // numbering for basic blocks into the final schedule. | 566 // numbering for basic blocks into the final schedule. |
| 566 void SerializeRPOIntoSchedule() { | 567 void SerializeRPOIntoSchedule() { |
| 567 int32_t number = 0; | 568 int32_t number = 0; |
| 568 for (BlockList* l = order_; l != NULL; l = l->next) { | 569 for (BlockList* l = order_; l != NULL; l = l->next) { |
| 569 l->block->set_rpo_number(number++); | 570 l->block->set_rpo_number(number++); |
| 570 schedule_->rpo_order()->push_back(l->block); | 571 schedule_->rpo_order()->push_back(l->block); |
| 571 } | 572 } |
| 572 if (schedule_->end()->rpo_number() < 0) { | 573 BeyondEndSentinel()->set_rpo_number(number); |
| 573 schedule_->end()->set_rpo_number(number); | |
| 574 } | |
| 575 } | 574 } |
| 576 | 575 |
| 577 // Print and verify the special reverse-post-order. | 576 // Print and verify the special reverse-post-order. |
| 578 void PrintAndVerifySpecialRPO() { | 577 void PrintAndVerifySpecialRPO() { |
| 579 #if DEBUG | 578 #if DEBUG |
| 580 if (FLAG_trace_turbo_scheduler) PrintRPO(); | 579 if (FLAG_trace_turbo_scheduler) PrintRPO(); |
| 581 VerifySpecialRPO(); | 580 VerifySpecialRPO(); |
| 582 #endif | 581 #endif |
| 583 } | 582 } |
| 584 | 583 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 // We are hijacking the {ao_number} to enumerate loops temporarily. Note that | 648 // We are hijacking the {ao_number} to enumerate loops temporarily. Note that |
| 650 // these numbers are only valid within this class. | 649 // these numbers are only valid within this class. |
| 651 static int GetLoopNumber(BasicBlock* block) { return block->ao_number(); } | 650 static int GetLoopNumber(BasicBlock* block) { return block->ao_number(); } |
| 652 static void SetLoopNumber(BasicBlock* block, int loop_number) { | 651 static void SetLoopNumber(BasicBlock* block, int loop_number) { |
| 653 return block->set_ao_number(loop_number); | 652 return block->set_ao_number(loop_number); |
| 654 } | 653 } |
| 655 static bool HasLoopNumber(BasicBlock* block) { | 654 static bool HasLoopNumber(BasicBlock* block) { |
| 656 return block->ao_number() >= 0; | 655 return block->ao_number() >= 0; |
| 657 } | 656 } |
| 658 | 657 |
| 658 // TODO(mstarzinger): We only need this special sentinel because some tests |
| 659 // use the schedule's end block in actual control flow (e.g. with end having |
| 660 // successors). Once this has been cleaned up we can use the end block here. |
| 661 BasicBlock* BeyondEndSentinel() { |
| 662 if (beyond_end_ == NULL) { |
| 663 BasicBlock::Id id = BasicBlock::Id::FromInt(-1); |
| 664 beyond_end_ = new (schedule_->zone()) BasicBlock(schedule_->zone(), id); |
| 665 } |
| 666 return beyond_end_; |
| 667 } |
| 668 |
| 659 // Compute special RPO for the control flow graph between {entry} and {end}, | 669 // Compute special RPO for the control flow graph between {entry} and {end}, |
| 660 // mutating any existing order so that the result is still valid. | 670 // mutating any existing order so that the result is still valid. |
| 661 void ComputeAndInsertSpecialRPO(BasicBlock* entry, BasicBlock* end) { | 671 void ComputeAndInsertSpecialRPO(BasicBlock* entry, BasicBlock* end) { |
| 662 // RPO should not have been serialized for this schedule yet. | 672 // RPO should not have been serialized for this schedule yet. |
| 663 CHECK_EQ(kBlockUnvisited1, schedule_->start()->ao_number()); | 673 CHECK_EQ(kBlockUnvisited1, schedule_->start()->ao_number()); |
| 664 CHECK_EQ(kBlockUnvisited1, schedule_->start()->rpo_number()); | 674 CHECK_EQ(kBlockUnvisited1, schedule_->start()->rpo_number()); |
| 665 CHECK_EQ(0, static_cast<int>(schedule_->rpo_order()->size())); | 675 CHECK_EQ(0, static_cast<int>(schedule_->rpo_order()->size())); |
| 666 | 676 |
| 667 // Find correct insertion point within existing order. | 677 // Find correct insertion point within existing order. |
| 668 BlockList* insert_before = order_->FindForBlock(entry); | 678 BlockList* insert_before = order_->FindForBlock(entry); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 current_header = current_loop == NULL ? NULL : current_loop->header; | 841 current_header = current_loop == NULL ? NULL : current_loop->header; |
| 832 --loop_depth; | 842 --loop_depth; |
| 833 } | 843 } |
| 834 current->set_loop_header(current_header); | 844 current->set_loop_header(current_header); |
| 835 | 845 |
| 836 // Push a new loop onto the stack if this loop is a loop header. | 846 // Push a new loop onto the stack if this loop is a loop header. |
| 837 if (HasLoopNumber(current)) { | 847 if (HasLoopNumber(current)) { |
| 838 ++loop_depth; | 848 ++loop_depth; |
| 839 current_loop = &loops_[GetLoopNumber(current)]; | 849 current_loop = &loops_[GetLoopNumber(current)]; |
| 840 BlockList* end = current_loop->end; | 850 BlockList* end = current_loop->end; |
| 841 current->set_loop_end(end == NULL ? schedule_->end() : end->block); | 851 current->set_loop_end(end == NULL ? BeyondEndSentinel() : end->block); |
| 842 current_header = current_loop->header; | 852 current_header = current_loop->header; |
| 843 Trace("B%d is a loop header, increment loop depth to %d\n", | 853 Trace("B%d is a loop header, increment loop depth to %d\n", |
| 844 current->id().ToInt(), loop_depth); | 854 current->id().ToInt(), loop_depth); |
| 845 } | 855 } |
| 846 | 856 |
| 847 current->set_loop_depth(loop_depth); | 857 current->set_loop_depth(loop_depth); |
| 848 | 858 |
| 849 if (current->loop_header() == NULL) { | 859 if (current->loop_header() == NULL) { |
| 850 Trace("B%d is not in a loop (depth == %d)\n", current->id().ToInt(), | 860 Trace("B%d is not in a loop (depth == %d)\n", current->id().ToInt(), |
| 851 current->loop_depth()); | 861 current->loop_depth()); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 } | 1011 } |
| 1002 DCHECK(links == count); | 1012 DCHECK(links == count); |
| 1003 } | 1013 } |
| 1004 } | 1014 } |
| 1005 #endif // DEBUG | 1015 #endif // DEBUG |
| 1006 | 1016 |
| 1007 Zone* zone_; | 1017 Zone* zone_; |
| 1008 Schedule* schedule_; | 1018 Schedule* schedule_; |
| 1009 BlockList* order_; | 1019 BlockList* order_; |
| 1010 ZoneVector<LoopInfo> loops_; | 1020 ZoneVector<LoopInfo> loops_; |
| 1021 BasicBlock* beyond_end_; |
| 1011 ZoneList<Backedge> backedges_; | 1022 ZoneList<Backedge> backedges_; |
| 1012 ZoneVector<SpecialRPOStackFrame> stack_; | 1023 ZoneVector<SpecialRPOStackFrame> stack_; |
| 1013 size_t previous_block_count_; | 1024 size_t previous_block_count_; |
| 1014 }; | 1025 }; |
| 1015 | 1026 |
| 1016 | 1027 |
| 1017 BasicBlockVector* Scheduler::ComputeSpecialRPO(ZonePool* zone_pool, | 1028 BasicBlockVector* Scheduler::ComputeSpecialRPO(ZonePool* zone_pool, |
| 1018 Schedule* schedule) { | 1029 Schedule* schedule) { |
| 1019 ZonePool::Scope zone_scope(zone_pool); | 1030 ZonePool::Scope zone_scope(zone_pool); |
| 1020 Zone* zone = zone_scope.zone(); | 1031 Zone* zone = zone_scope.zone(); |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1463 for (NodeVectorIter i = nodes->begin(); i != nodes->end(); ++i) { | 1474 for (NodeVectorIter i = nodes->begin(); i != nodes->end(); ++i) { |
| 1464 schedule_->SetBlockForNode(to, *i); | 1475 schedule_->SetBlockForNode(to, *i); |
| 1465 scheduled_nodes_[to->id().ToSize()].push_back(*i); | 1476 scheduled_nodes_[to->id().ToSize()].push_back(*i); |
| 1466 } | 1477 } |
| 1467 nodes->clear(); | 1478 nodes->clear(); |
| 1468 } | 1479 } |
| 1469 | 1480 |
| 1470 } // namespace compiler | 1481 } // namespace compiler |
| 1471 } // namespace internal | 1482 } // namespace internal |
| 1472 } // namespace v8 | 1483 } // namespace v8 |
| OLD | NEW |