OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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. | |
4 | |
5 #ifndef V8_COMPILER_INSTRUCTION_SCHEDULER_H_ | |
6 #define V8_COMPILER_INSTRUCTION_SCHEDULER_H_ | |
7 | |
8 #include "src/compiler/instruction.h" | |
9 #include "src/zone-containers.h" | |
10 | |
11 namespace v8 { | |
12 namespace internal { | |
13 namespace compiler { | |
14 | |
15 class InstructionScheduler final : public ZoneObject { | |
16 public: | |
17 InstructionScheduler(Zone* zone, InstructionSequence* sequence); | |
18 | |
19 void StartBlock(RpoNumber rpo); | |
20 void EndBlock(RpoNumber rpo); | |
21 | |
22 void AddInstruction(Instruction* instr); | |
23 | |
24 private: | |
25 // A scheduling graph node. | |
26 // Represent an instruction and their dependencies. | |
27 class ScheduleGraphNode: public ZoneObject { | |
28 public: | |
29 ScheduleGraphNode(Zone* zone, Instruction* instr); | |
30 | |
31 // Add an edge between two nodes in the scheduling graph. | |
32 // Edges are directed and an edge from A -> B means that instruction A must | |
33 // be scheduled before B. | |
Jarin
2015/10/26 15:12:35
You might want to say that it means A is a depende
baptiste.afsa1
2015/10/27 16:00:24
Done.
Good idea. Using the term UnscheduledPredec
| |
34 void AddSuccessor(ScheduleGraphNode* node); | |
35 | |
36 bool HasDependency() { return dependency_count_ != 0; } | |
37 | |
38 // Record that we have scheduled one of the dependencies of the current | |
39 // node. | |
40 void DropDependency() { | |
41 DCHECK(dependency_count_ > 0); | |
42 dependency_count_--; | |
43 } | |
44 | |
45 Instruction* instruction() { return instr_; } | |
46 ZoneVector<ScheduleGraphNode*> &successors() { return successors_; } | |
47 int latency() const { return latency_; } | |
48 | |
49 int total_latency() const { return total_latency_; } | |
50 void set_total_latency(int latency) { total_latency_ = latency; } | |
51 | |
52 int start_cycle() const { return start_cycle_; } | |
53 void set_start_cycle(int start_cycle) { start_cycle_ = start_cycle; } | |
54 | |
55 private: | |
56 Instruction* instr_; | |
57 ZoneVector<ScheduleGraphNode*> successors_; | |
Jarin
2015/10/26 15:12:35
I think it is better to use ZoneDeque here.
baptiste.afsa1
2015/10/27 16:00:24
Done.
| |
58 int dependency_count_; // Number of dependencies for a given node. | |
59 | |
60 // Estimate of the instruction latency (the number of cycles it takes for | |
61 // instruction to complete). | |
62 int latency_; | |
63 | |
64 // The sum of all the latencies from a node to the root of the graph. | |
Jarin
2015/10/26 15:12:35
What is the "root of the graph" here? From the cod
baptiste.afsa1
2015/10/27 16:00:24
Done.
| |
65 int total_latency_; | |
66 | |
67 // The scheduler keeps a nominal cycle count to keep track of when the | |
68 // result of an instruction is available. This field is updated by the | |
69 // scheduler to indicate when the value of all the operands of this | |
70 // instruction will be available. | |
71 int start_cycle_; | |
72 }; | |
73 | |
74 // Compare the two nodes and return true if node1 is a better candidate than | |
75 // node2 (i.e. node1 should be scheduled before node2). | |
76 bool CompareNodes(ScheduleGraphNode *node1, ScheduleGraphNode *node2) const; | |
77 | |
78 // Perform scheduling for the current block. | |
79 void ScheduleBlock(); | |
80 | |
81 // Return true if instr2 uses any value defined by instr1. | |
82 bool HasOperandDependency(const Instruction* instr1, | |
83 const Instruction* instr2) const; | |
84 | |
85 // Return true if the instruction is a basic block terminator. | |
86 bool IsBlockTerminator(const Instruction* instr) const; | |
87 | |
88 // Check whether the given instruction has side effects (e.g. function call, | |
89 // memory store). | |
90 bool HasSideEffect(const Instruction* instr) const { | |
91 return instruction_flags_[instr->arch_opcode()] & kHasSideEffect; | |
92 } | |
93 | |
94 // Return true if the instruction is a memory load. | |
95 bool IsLoadOperation(const Instruction* instr) const { | |
96 return instruction_flags_[instr->arch_opcode()] & kIsLoadOperation; | |
97 } | |
98 | |
99 void ComputeTotalLatency(ScheduleGraphNode* node); | |
100 | |
101 static int GetInstructionLatency(const Instruction* instr); | |
102 | |
103 Zone* zone() { return zone_; } | |
104 InstructionSequence* sequence() { return sequence_; } | |
105 | |
106 static const int instruction_flags_[]; | |
107 | |
108 Zone* zone_; | |
109 InstructionSequence* sequence_; | |
110 ZoneVector<ScheduleGraphNode*> graph_; | |
111 }; | |
112 | |
113 } // namespace compiler | |
114 } // namespace internal | |
115 } // namespace v8 | |
116 | |
117 #endif // V8_COMPILER_INSTRUCTION_SCHEDULER_H_ | |
OLD | NEW |