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 #ifndef V8_COMPILER_SCHEDULER_H_ | 5 #ifndef V8_COMPILER_SCHEDULER_H_ |
6 #define V8_COMPILER_SCHEDULER_H_ | 6 #define V8_COMPILER_SCHEDULER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "src/v8.h" | 10 #include "src/v8.h" |
11 | 11 |
12 #include "src/compiler/opcodes.h" | 12 #include "src/compiler/opcodes.h" |
13 #include "src/compiler/schedule.h" | 13 #include "src/compiler/schedule.h" |
14 #include "src/zone-allocator.h" | 14 #include "src/zone-allocator.h" |
15 #include "src/zone-containers.h" | 15 #include "src/zone-containers.h" |
16 | 16 |
17 namespace v8 { | 17 namespace v8 { |
18 namespace internal { | 18 namespace internal { |
19 namespace compiler { | 19 namespace compiler { |
20 | 20 |
21 // Computes a schedule from a graph, placing nodes into basic blocks and | 21 // Computes a schedule from a graph, placing nodes into basic blocks and |
22 // ordering the basic blocks in the special RPO order. | 22 // ordering the basic blocks in the special RPO order. |
23 class Scheduler { | 23 class Scheduler { |
24 public: | 24 public: |
25 // Create a new schedule and place all computations from the graph in it. | 25 // The complete scheduling algorithm. |
| 26 // Create a new schedule and place all nodes from the graph into it. |
26 static Schedule* ComputeSchedule(Graph* graph); | 27 static Schedule* ComputeSchedule(Graph* graph); |
27 | 28 |
28 // Compute the RPO of blocks in an existing schedule. | 29 // Compute the RPO of blocks in an existing schedule. |
29 static BasicBlockVector* ComputeSpecialRPO(Schedule* schedule); | 30 static BasicBlockVector* ComputeSpecialRPO(Schedule* schedule); |
30 | 31 |
| 32 // (Exposed for testing only) |
| 33 // Build and connect the CFG for a node graph, but don't schedule nodes. |
| 34 static void ComputeCFG(Graph* graph, Schedule* schedule); |
| 35 |
31 private: | 36 private: |
32 Zone* zone_; | 37 Zone* zone_; |
33 Graph* graph_; | 38 Graph* graph_; |
34 Schedule* schedule_; | 39 Schedule* schedule_; |
35 NodeVector branches_; | |
36 NodeVector calls_; | |
37 NodeVector deopts_; | |
38 NodeVector returns_; | |
39 NodeVector loops_and_merges_; | |
40 IntVector unscheduled_uses_; | 40 IntVector unscheduled_uses_; |
41 NodeVectorVector scheduled_nodes_; | 41 NodeVectorVector scheduled_nodes_; |
42 NodeVector schedule_root_nodes_; | 42 NodeVector schedule_root_nodes_; |
43 IntVector schedule_early_rpo_index_; | 43 IntVector schedule_early_rpo_index_; |
44 | 44 |
45 Scheduler(Zone* zone, Graph* graph, Schedule* schedule); | 45 Scheduler(Zone* zone, Graph* graph, Schedule* schedule); |
46 | 46 |
47 bool IsBasicBlockBegin(Node* node); | 47 bool IsBasicBlockBegin(Node* node); |
48 bool CanBeScheduled(Node* node); | |
49 bool HasFixedSchedulePosition(Node* node); | 48 bool HasFixedSchedulePosition(Node* node); |
50 bool IsScheduleRoot(Node* node); | 49 bool IsScheduleRoot(Node* node); |
51 | 50 |
52 int GetRPONumber(BasicBlock* block) { | 51 int GetRPONumber(BasicBlock* block) { |
53 DCHECK(block->rpo_number_ >= 0 && | 52 DCHECK(block->rpo_number_ >= 0 && |
54 block->rpo_number_ < static_cast<int>(schedule_->rpo_order_.size())); | 53 block->rpo_number_ < static_cast<int>(schedule_->rpo_order_.size())); |
55 DCHECK(schedule_->rpo_order_[block->rpo_number_] == block); | 54 DCHECK(schedule_->rpo_order_[block->rpo_number_] == block); |
56 return block->rpo_number_; | 55 return block->rpo_number_; |
57 } | 56 } |
58 | 57 |
59 void PrepareAuxiliaryNodeData(); | 58 void PrepareAuxiliaryNodeData(); |
60 void PrepareAuxiliaryBlockData(); | 59 void PrepareAuxiliaryBlockData(); |
61 | 60 |
62 friend class CreateBlockVisitor; | |
63 void CreateBlocks(); | |
64 | |
65 void WireBlocks(); | |
66 | |
67 void AddPredecessorsForLoopsAndMerges(); | |
68 void AddSuccessorsForBranches(); | |
69 void AddSuccessorsForReturns(); | |
70 void AddSuccessorsForCalls(); | |
71 void AddSuccessorsForDeopts(); | |
72 | |
73 void GenerateImmediateDominatorTree(); | 61 void GenerateImmediateDominatorTree(); |
74 BasicBlock* GetCommonDominator(BasicBlock* b1, BasicBlock* b2); | 62 BasicBlock* GetCommonDominator(BasicBlock* b1, BasicBlock* b2); |
75 | 63 |
76 friend class ScheduleEarlyNodeVisitor; | 64 friend class ScheduleEarlyNodeVisitor; |
77 void ScheduleEarly(); | 65 void ScheduleEarly(); |
78 | 66 |
79 friend class PrepareUsesVisitor; | 67 friend class PrepareUsesVisitor; |
80 void PrepareUses(); | 68 void PrepareUses(); |
81 | 69 |
82 friend class ScheduleLateNodeVisitor; | 70 friend class ScheduleLateNodeVisitor; |
83 void ScheduleLate(); | 71 void ScheduleLate(); |
84 }; | 72 }; |
85 } | 73 } |
86 } | 74 } |
87 } // namespace v8::internal::compiler | 75 } // namespace v8::internal::compiler |
88 | 76 |
89 #endif // V8_COMPILER_SCHEDULER_H_ | 77 #endif // V8_COMPILER_SCHEDULER_H_ |
OLD | NEW |