Commit 6603cbb3 authored by titzer@chromium.org's avatar titzer@chromium.org

Remove duplication in Scheduler and simplify interface. Make ComputeSchedule()...

Remove duplication in Scheduler and simplify interface. Make ComputeSchedule() and ComputeSpecialRPO() the only interface used by clients.

R=bmeurer@chromium.org
BUG=

Review URL: https://codereview.chromium.org/460633002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23039 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c08daece
...@@ -222,9 +222,8 @@ Handle<Code> Pipeline::GenerateCode() { ...@@ -222,9 +222,8 @@ Handle<Code> Pipeline::GenerateCode() {
Schedule* Pipeline::ComputeSchedule(Graph* graph) { Schedule* Pipeline::ComputeSchedule(Graph* graph) {
Scheduler scheduler(zone());
PhaseStats schedule_stats(info(), PhaseStats::CODEGEN, "scheduling"); PhaseStats schedule_stats(info(), PhaseStats::CODEGEN, "scheduling");
return scheduler.NewSchedule(graph); return Scheduler::ComputeSchedule(graph);
} }
......
...@@ -34,8 +34,7 @@ RawMachineAssembler::RawMachineAssembler( ...@@ -34,8 +34,7 @@ RawMachineAssembler::RawMachineAssembler(
Schedule* RawMachineAssembler::Export() { Schedule* RawMachineAssembler::Export() {
// Compute the correct codegen order. // Compute the correct codegen order.
DCHECK(schedule_->rpo_order()->empty()); DCHECK(schedule_->rpo_order()->empty());
Scheduler scheduler(zone(), graph(), schedule_); Scheduler::ComputeSpecialRPO(schedule_);
scheduler.ComputeSpecialRPO();
// Invalidate MachineAssembler. // Invalidate MachineAssembler.
Schedule* schedule = schedule_; Schedule* schedule = schedule_;
schedule_ = NULL; schedule_ = NULL;
......
...@@ -15,22 +15,6 @@ namespace v8 { ...@@ -15,22 +15,6 @@ namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
Scheduler::Scheduler(Zone* zone)
: zone_(zone),
graph_(NULL),
schedule_(NULL),
branches_(NodeVector::allocator_type(zone)),
calls_(NodeVector::allocator_type(zone)),
deopts_(NodeVector::allocator_type(zone)),
returns_(NodeVector::allocator_type(zone)),
loops_and_merges_(NodeVector::allocator_type(zone)),
node_block_placement_(BasicBlockVector::allocator_type(zone)),
unscheduled_uses_(IntVector::allocator_type(zone)),
scheduled_nodes_(NodeVectorVector::allocator_type(zone)),
schedule_root_nodes_(NodeVector::allocator_type(zone)),
schedule_early_rpo_index_(IntVector::allocator_type(zone)) {}
Scheduler::Scheduler(Zone* zone, Graph* graph, Schedule* schedule) Scheduler::Scheduler(Zone* zone, Graph* graph, Schedule* schedule)
: zone_(zone), : zone_(zone),
graph_(graph), graph_(graph),
...@@ -47,30 +31,26 @@ Scheduler::Scheduler(Zone* zone, Graph* graph, Schedule* schedule) ...@@ -47,30 +31,26 @@ Scheduler::Scheduler(Zone* zone, Graph* graph, Schedule* schedule)
schedule_early_rpo_index_(IntVector::allocator_type(zone)) {} schedule_early_rpo_index_(IntVector::allocator_type(zone)) {}
Schedule* Scheduler::NewSchedule(Graph* graph) { Schedule* Scheduler::ComputeSchedule(Graph* graph) {
graph_ = graph; Zone tmp_zone(graph->zone()->isolate());
schedule_ = new (zone_) Schedule(zone_); Schedule* schedule = new (graph->zone()) Schedule(graph->zone());
Scheduler scheduler(&tmp_zone, graph, schedule);
schedule_->AddNode(schedule_->end(), graph_->end());
PrepareAuxiliaryNodeData();
// Create basic blocks for each block and merge node in the graph.
CreateBlocks();
// Wire the basic blocks together. schedule->AddNode(schedule->end(), graph->end());
WireBlocks();
PrepareAuxiliaryBlockData(); scheduler.PrepareAuxiliaryNodeData();
scheduler.CreateBlocks();
scheduler.WireBlocks();
scheduler.PrepareAuxiliaryBlockData();
ComputeSpecialRPO(); Scheduler::ComputeSpecialRPO(schedule);
GenerateImmediateDominatorTree(); scheduler.GenerateImmediateDominatorTree();
PrepareUses(); scheduler.PrepareUses();
ScheduleEarly(); scheduler.ScheduleEarly();
ScheduleLate(); scheduler.ScheduleLate();
return schedule_; return schedule;
} }
...@@ -866,20 +846,22 @@ static void VerifySpecialRPO(int num_loops, LoopInfo* loops, ...@@ -866,20 +846,22 @@ static void VerifySpecialRPO(int num_loops, LoopInfo* loops,
// 2. All loops are contiguous in the order (i.e. no intervening blocks that // 2. All loops are contiguous in the order (i.e. no intervening blocks that
// do not belong to the loop.) // do not belong to the loop.)
// Note a simple RPO traversal satisfies (1) but not (3). // Note a simple RPO traversal satisfies (1) but not (3).
BasicBlockVector* Scheduler::ComputeSpecialRPO() { BasicBlockVector* Scheduler::ComputeSpecialRPO(Schedule* schedule) {
Zone tmp_zone(schedule->zone()->isolate());
Zone* zone = &tmp_zone;
if (FLAG_trace_turbo_scheduler) { if (FLAG_trace_turbo_scheduler) {
PrintF("------------- COMPUTING SPECIAL RPO ---------------\n"); PrintF("------------- COMPUTING SPECIAL RPO ---------------\n");
} }
// RPO should not have been computed for this schedule yet. // RPO should not have been computed for this schedule yet.
CHECK_EQ(kBlockUnvisited1, schedule_->entry()->rpo_number_); CHECK_EQ(kBlockUnvisited1, schedule->entry()->rpo_number_);
CHECK_EQ(0, static_cast<int>(schedule_->rpo_order_.size())); CHECK_EQ(0, static_cast<int>(schedule->rpo_order_.size()));
// Perform an iterative RPO traversal using an explicit stack, // Perform an iterative RPO traversal using an explicit stack,
// recording backedges that form cycles. O(|B|). // recording backedges that form cycles. O(|B|).
ZoneList<std::pair<BasicBlock*, int> > backedges(1, zone_); ZoneList<std::pair<BasicBlock*, int> > backedges(1, zone);
SpecialRPOStackFrame* stack = SpecialRPOStackFrame* stack =
zone_->NewArray<SpecialRPOStackFrame>(schedule_->BasicBlockCount()); zone->NewArray<SpecialRPOStackFrame>(schedule->BasicBlockCount());
BasicBlock* entry = schedule_->entry(); BasicBlock* entry = schedule->entry();
BlockList* order = NULL; BlockList* order = NULL;
int stack_depth = Push(stack, 0, entry, kBlockUnvisited1); int stack_depth = Push(stack, 0, entry, kBlockUnvisited1);
int num_loops = 0; int num_loops = 0;
...@@ -895,7 +877,7 @@ BasicBlockVector* Scheduler::ComputeSpecialRPO() { ...@@ -895,7 +877,7 @@ BasicBlockVector* Scheduler::ComputeSpecialRPO() {
if (succ->rpo_number_ == kBlockOnStack) { if (succ->rpo_number_ == kBlockOnStack) {
// The successor is on the stack, so this is a backedge (cycle). // The successor is on the stack, so this is a backedge (cycle).
backedges.Add( backedges.Add(
std::pair<BasicBlock*, int>(frame->block, frame->index - 1), zone_); std::pair<BasicBlock*, int>(frame->block, frame->index - 1), zone);
if (succ->loop_end_ < 0) { if (succ->loop_end_ < 0) {
// Assign a new loop number to the header if it doesn't have one. // Assign a new loop number to the header if it doesn't have one.
succ->loop_end_ = num_loops++; succ->loop_end_ = num_loops++;
...@@ -907,7 +889,7 @@ BasicBlockVector* Scheduler::ComputeSpecialRPO() { ...@@ -907,7 +889,7 @@ BasicBlockVector* Scheduler::ComputeSpecialRPO() {
} }
} else { } else {
// Finished with all successors; pop the stack and add the block. // Finished with all successors; pop the stack and add the block.
order = order->Add(zone_, frame->block); order = order->Add(zone, frame->block);
frame->block->rpo_number_ = kBlockVisited1; frame->block->rpo_number_ = kBlockVisited1;
stack_depth--; stack_depth--;
} }
...@@ -918,8 +900,8 @@ BasicBlockVector* Scheduler::ComputeSpecialRPO() { ...@@ -918,8 +900,8 @@ BasicBlockVector* Scheduler::ComputeSpecialRPO() {
if (num_loops != 0) { if (num_loops != 0) {
// Otherwise, compute the loop information from the backedges in order // Otherwise, compute the loop information from the backedges in order
// to perform a traversal that groups loop bodies together. // to perform a traversal that groups loop bodies together.
loops = ComputeLoopInfo(zone_, stack, num_loops, loops = ComputeLoopInfo(zone, stack, num_loops, schedule->BasicBlockCount(),
schedule_->BasicBlockCount(), &backedges); &backedges);
// Initialize the "loop stack". Note the entry could be a loop header. // Initialize the "loop stack". Note the entry could be a loop header.
LoopInfo* loop = entry->IsLoopHeader() ? &loops[entry->loop_end_] : NULL; LoopInfo* loop = entry->IsLoopHeader() ? &loops[entry->loop_end_] : NULL;
...@@ -944,7 +926,7 @@ BasicBlockVector* Scheduler::ComputeSpecialRPO() { ...@@ -944,7 +926,7 @@ BasicBlockVector* Scheduler::ComputeSpecialRPO() {
// Finish the loop body the first time the header is left on the // Finish the loop body the first time the header is left on the
// stack. // stack.
DCHECK(loop != NULL && loop->header == block); DCHECK(loop != NULL && loop->header == block);
loop->start = order->Add(zone_, block); loop->start = order->Add(zone, block);
order = loop->end; order = loop->end;
block->rpo_number_ = kBlockVisited2; block->rpo_number_ = kBlockVisited2;
// Pop the loop stack and continue visiting outgoing edges within the // Pop the loop stack and continue visiting outgoing edges within the
...@@ -973,7 +955,7 @@ BasicBlockVector* Scheduler::ComputeSpecialRPO() { ...@@ -973,7 +955,7 @@ BasicBlockVector* Scheduler::ComputeSpecialRPO() {
if (loop != NULL && !loop->members->Contains(succ->id())) { if (loop != NULL && !loop->members->Contains(succ->id())) {
// The successor is not in the current loop or any nested loop. // The successor is not in the current loop or any nested loop.
// Add it to the outgoing edges of this loop and visit it later. // Add it to the outgoing edges of this loop and visit it later.
loop->AddOutgoing(zone_, succ); loop->AddOutgoing(zone, succ);
} else { } else {
// Push the successor onto the stack. // Push the successor onto the stack.
stack_depth = Push(stack, stack_depth, succ, kBlockUnvisited2); stack_depth = Push(stack, stack_depth, succ, kBlockUnvisited2);
...@@ -1001,7 +983,7 @@ BasicBlockVector* Scheduler::ComputeSpecialRPO() { ...@@ -1001,7 +983,7 @@ BasicBlockVector* Scheduler::ComputeSpecialRPO() {
order = info->start; order = info->start;
} else { } else {
// Pop a single node off the stack and add it to the order. // Pop a single node off the stack and add it to the order.
order = order->Add(zone_, block); order = order->Add(zone, block);
block->rpo_number_ = kBlockVisited2; block->rpo_number_ = kBlockVisited2;
} }
stack_depth--; stack_depth--;
...@@ -1010,7 +992,7 @@ BasicBlockVector* Scheduler::ComputeSpecialRPO() { ...@@ -1010,7 +992,7 @@ BasicBlockVector* Scheduler::ComputeSpecialRPO() {
} }
// Construct the final order from the list. // Construct the final order from the list.
BasicBlockVector* final_order = &schedule_->rpo_order_; BasicBlockVector* final_order = &schedule->rpo_order_;
order->Serialize(final_order); order->Serialize(final_order);
// Compute the correct loop header for every block and set the correct loop // Compute the correct loop header for every block and set the correct loop
......
...@@ -18,14 +18,15 @@ namespace v8 { ...@@ -18,14 +18,15 @@ namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
// Computes a schedule from a graph, placing nodes into basic blocks and
// ordering the basic blocks in the special RPO order.
class Scheduler { class Scheduler {
public: public:
explicit Scheduler(Zone* zone); // Create a new schedule and place all computations from the graph in it.
Scheduler(Zone* zone, Graph* graph, Schedule* schedule); static Schedule* ComputeSchedule(Graph* graph);
Schedule* NewSchedule(Graph* graph);
BasicBlockVector* ComputeSpecialRPO(); // Compute the RPO of blocks in an existing schedule.
static BasicBlockVector* ComputeSpecialRPO(Schedule* schedule);
private: private:
Zone* zone_; Zone* zone_;
...@@ -42,6 +43,8 @@ class Scheduler { ...@@ -42,6 +43,8 @@ class Scheduler {
NodeVector schedule_root_nodes_; NodeVector schedule_root_nodes_;
IntVector schedule_early_rpo_index_; IntVector schedule_early_rpo_index_;
Scheduler(Zone* zone, Graph* graph, Schedule* schedule);
int GetRPONumber(BasicBlock* block) { int GetRPONumber(BasicBlock* block) {
DCHECK(block->rpo_number_ >= 0 && DCHECK(block->rpo_number_ >= 0 &&
block->rpo_number_ < static_cast<int>(schedule_->rpo_order_.size())); block->rpo_number_ < static_cast<int>(schedule_->rpo_order_.size()));
......
...@@ -41,8 +41,7 @@ StructuredMachineAssembler::StructuredMachineAssembler( ...@@ -41,8 +41,7 @@ StructuredMachineAssembler::StructuredMachineAssembler(
Schedule* StructuredMachineAssembler::Export() { Schedule* StructuredMachineAssembler::Export() {
// Compute the correct codegen order. // Compute the correct codegen order.
DCHECK(schedule_->rpo_order()->empty()); DCHECK(schedule_->rpo_order()->empty());
Scheduler scheduler(zone(), graph(), schedule_); Scheduler::ComputeSpecialRPO(schedule_);
scheduler.ComputeSpecialRPO();
// Invalidate MachineAssembler. // Invalidate MachineAssembler.
Schedule* schedule = schedule_; Schedule* schedule = schedule_;
schedule_ = NULL; schedule_ = NULL;
......
...@@ -51,8 +51,7 @@ class InstructionTester : public HandleAndZoneScope { ...@@ -51,8 +51,7 @@ class InstructionTester : public HandleAndZoneScope {
void allocCode() { void allocCode() {
if (schedule.rpo_order()->size() == 0) { if (schedule.rpo_order()->size() == 0) {
// Compute the RPO order. // Compute the RPO order.
Scheduler scheduler(zone(), &graph, &schedule); Scheduler::ComputeSpecialRPO(&schedule);
scheduler.ComputeSpecialRPO();
DCHECK(schedule.rpo_order()->size() > 0); DCHECK(schedule.rpo_order()->size() > 0);
} }
code = new TestInstrSeq(&linkage, &graph, &schedule); code = new TestInstrSeq(&linkage, &graph, &schedule);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment