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
3 // found in the LICENSE file.
5 #ifndef V8_COMPILER_SCHEDULER_H_
6 #define V8_COMPILER_SCHEDULER_H_
10 #include "src/compiler/opcodes.h"
11 #include "src/compiler/schedule.h"
12 #include "src/zone-containers.h"
18 // Computes a schedule from a graph, placing nodes into basic blocks and
19 // ordering the basic blocks in the special RPO order.
22 // The complete scheduling algorithm.
23 // Create a new schedule and place all nodes from the graph into it.
24 static Schedule* ComputeSchedule(Graph* graph);
26 // Compute the RPO of blocks in an existing schedule.
27 static BasicBlockVector* ComputeSpecialRPO(Schedule* schedule);
29 // (Exposed for testing only)
30 // Build and connect the CFG for a node graph, but don't schedule nodes.
31 static void ComputeCFG(Graph* graph, Schedule* schedule);
34 enum Placement { kUnknown, kSchedulable, kFixed };
36 // Per-node data tracked during scheduling.
37 struct SchedulerData {
38 int unscheduled_count_; // Number of unscheduled uses of this node.
39 int minimum_rpo_; // Minimum legal RPO placement.
40 bool is_connected_control_; // {true} if control-connected to the end node.
41 bool is_floating_control_; // {true} if control, but not control-connected
43 Placement placement_ : 3; // Whether the node is fixed, schedulable,
50 NodeVectorVector scheduled_nodes_;
51 NodeVector schedule_root_nodes_;
52 ZoneVector<SchedulerData> node_data_;
53 bool has_floating_control_;
55 Scheduler(Zone* zone, Graph* graph, Schedule* schedule);
57 SchedulerData DefaultSchedulerData();
59 SchedulerData* GetData(Node* node) {
60 DCHECK(node->id() < static_cast<int>(node_data_.size()));
61 return &node_data_[node->id()];
66 Placement GetPlacement(Node* node);
68 int GetRPONumber(BasicBlock* block) {
69 DCHECK(block->rpo_number_ >= 0 &&
70 block->rpo_number_ < static_cast<int>(schedule_->rpo_order_.size()));
71 DCHECK(schedule_->rpo_order_[block->rpo_number_] == block);
72 return block->rpo_number_;
75 void GenerateImmediateDominatorTree();
76 BasicBlock* GetCommonDominator(BasicBlock* b1, BasicBlock* b2);
78 friend class CFGBuilder;
80 friend class ScheduleEarlyNodeVisitor;
83 friend class PrepareUsesVisitor;
86 friend class ScheduleLateNodeVisitor;
89 bool ConnectFloatingControl();
91 void ConnectFloatingControlSubgraph(BasicBlock* block, Node* node);
95 } // namespace v8::internal::compiler
97 #endif // V8_COMPILER_SCHEDULER_H_