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_SCHEDULE_H_ | 5 #ifndef V8_COMPILER_SCHEDULE_H_ |
6 #define V8_COMPILER_SCHEDULE_H_ | 6 #define V8_COMPILER_SCHEDULE_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 | 9 |
10 #include "src/zone-containers.h" | 10 #include "src/zone-containers.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 int ToInt() const { return static_cast<int>(index_); } | 44 int ToInt() const { return static_cast<int>(index_); } |
45 size_t ToSize() const { return index_; } | 45 size_t ToSize() const { return index_; } |
46 static Id FromSize(size_t index) { return Id(index); } | 46 static Id FromSize(size_t index) { return Id(index); } |
47 static Id FromInt(int index) { return Id(static_cast<size_t>(index)); } | 47 static Id FromInt(int index) { return Id(static_cast<size_t>(index)); } |
48 | 48 |
49 private: | 49 private: |
50 explicit Id(size_t index) : index_(index) {} | 50 explicit Id(size_t index) : index_(index) {} |
51 size_t index_; | 51 size_t index_; |
52 }; | 52 }; |
53 | 53 |
54 static const int kInvalidRpoNumber = -1; | |
55 class RpoNumber FINAL { | |
56 public: | |
57 int ToInt() const { | |
58 DCHECK(IsValid()); | |
59 return index_; | |
60 } | |
61 size_t ToSize() const { | |
62 DCHECK(IsValid()); | |
63 return static_cast<size_t>(index_); | |
64 } | |
65 bool IsValid() const { return index_ >= 0; } | |
66 static RpoNumber FromInt(int index) { return RpoNumber(index); } | |
67 static RpoNumber Invalid() { return RpoNumber(kInvalidRpoNumber); } | |
68 | |
69 bool IsNext(const RpoNumber other) const { | |
70 DCHECK(IsValid()); | |
71 return other.index_ == this->index_ + 1; | |
72 } | |
73 | |
74 bool operator==(RpoNumber other) const { | |
75 return this->index_ == other.index_; | |
76 } | |
77 | |
78 private: | |
79 explicit RpoNumber(int32_t index) : index_(index) {} | |
80 int32_t index_; | |
81 }; | |
82 | |
83 BasicBlock(Zone* zone, Id id); | 54 BasicBlock(Zone* zone, Id id); |
84 | 55 |
85 Id id() const { return id_; } | 56 Id id() const { return id_; } |
86 | 57 |
87 // Predecessors. | 58 // Predecessors. |
88 BasicBlockVector& predecessors() { return predecessors_; } | 59 BasicBlockVector& predecessors() { return predecessors_; } |
89 const BasicBlockVector& predecessors() const { return predecessors_; } | 60 const BasicBlockVector& predecessors() const { return predecessors_; } |
90 size_t PredecessorCount() const { return predecessors_.size(); } | 61 size_t PredecessorCount() const { return predecessors_.size(); } |
91 BasicBlock* PredecessorAt(size_t index) { return predecessors_[index]; } | 62 BasicBlock* PredecessorAt(size_t index) { return predecessors_[index]; } |
92 void ClearPredecessors() { predecessors_.clear(); } | 63 void ClearPredecessors() { predecessors_.clear(); } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 | 124 |
154 BasicBlock* loop_end() const { return loop_end_; } | 125 BasicBlock* loop_end() const { return loop_end_; } |
155 void set_loop_end(BasicBlock* loop_end); | 126 void set_loop_end(BasicBlock* loop_end); |
156 | 127 |
157 int32_t loop_depth() const { return loop_depth_; } | 128 int32_t loop_depth() const { return loop_depth_; } |
158 void set_loop_depth(int32_t loop_depth); | 129 void set_loop_depth(int32_t loop_depth); |
159 | 130 |
160 int32_t loop_number() const { return loop_number_; } | 131 int32_t loop_number() const { return loop_number_; } |
161 void set_loop_number(int32_t loop_number) { loop_number_ = loop_number; } | 132 void set_loop_number(int32_t loop_number) { loop_number_ = loop_number; } |
162 | 133 |
163 RpoNumber GetRpoNumber() const { return RpoNumber::FromInt(rpo_number_); } | |
164 int32_t rpo_number() const { return rpo_number_; } | 134 int32_t rpo_number() const { return rpo_number_; } |
165 void set_rpo_number(int32_t rpo_number); | 135 void set_rpo_number(int32_t rpo_number); |
166 | 136 |
167 // Loop membership helpers. | 137 // Loop membership helpers. |
168 inline bool IsLoopHeader() const { return loop_end_ != NULL; } | 138 inline bool IsLoopHeader() const { return loop_end_ != NULL; } |
169 bool LoopContains(BasicBlock* block) const; | 139 bool LoopContains(BasicBlock* block) const; |
170 | 140 |
171 // Computes the immediate common dominator of {b1} and {b2}. The worst time | 141 // Computes the immediate common dominator of {b1} and {b2}. The worst time |
172 // complexity is O(N) where N is the height of the dominator tree. | 142 // complexity is O(N) where N is the height of the dominator tree. |
173 static BasicBlock* GetCommonDominator(BasicBlock* b1, BasicBlock* b2); | 143 static BasicBlock* GetCommonDominator(BasicBlock* b1, BasicBlock* b2); |
(...skipping 17 matching lines...) Expand all Loading... |
191 | 161 |
192 BasicBlockVector successors_; | 162 BasicBlockVector successors_; |
193 BasicBlockVector predecessors_; | 163 BasicBlockVector predecessors_; |
194 Id id_; | 164 Id id_; |
195 | 165 |
196 DISALLOW_COPY_AND_ASSIGN(BasicBlock); | 166 DISALLOW_COPY_AND_ASSIGN(BasicBlock); |
197 }; | 167 }; |
198 | 168 |
199 std::ostream& operator<<(std::ostream&, const BasicBlock::Control&); | 169 std::ostream& operator<<(std::ostream&, const BasicBlock::Control&); |
200 std::ostream& operator<<(std::ostream&, const BasicBlock::Id&); | 170 std::ostream& operator<<(std::ostream&, const BasicBlock::Id&); |
201 std::ostream& operator<<(std::ostream&, const BasicBlock::RpoNumber&); | |
202 | 171 |
203 | 172 |
204 // A schedule represents the result of assigning nodes to basic blocks | 173 // A schedule represents the result of assigning nodes to basic blocks |
205 // and ordering them within basic blocks. Prior to computing a schedule, | 174 // and ordering them within basic blocks. Prior to computing a schedule, |
206 // a graph has no notion of control flow ordering other than that induced | 175 // a graph has no notion of control flow ordering other than that induced |
207 // by the graph's dependencies. A schedule is required to generate code. | 176 // by the graph's dependencies. A schedule is required to generate code. |
208 class Schedule FINAL : public ZoneObject { | 177 class Schedule FINAL : public ZoneObject { |
209 public: | 178 public: |
210 explicit Schedule(Zone* zone, size_t node_count_hint = 0); | 179 explicit Schedule(Zone* zone, size_t node_count_hint = 0); |
211 | 180 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 DISALLOW_COPY_AND_ASSIGN(Schedule); | 262 DISALLOW_COPY_AND_ASSIGN(Schedule); |
294 }; | 263 }; |
295 | 264 |
296 std::ostream& operator<<(std::ostream&, const Schedule&); | 265 std::ostream& operator<<(std::ostream&, const Schedule&); |
297 | 266 |
298 } // namespace compiler | 267 } // namespace compiler |
299 } // namespace internal | 268 } // namespace internal |
300 } // namespace v8 | 269 } // namespace v8 |
301 | 270 |
302 #endif // V8_COMPILER_SCHEDULE_H_ | 271 #endif // V8_COMPILER_SCHEDULE_H_ |
OLD | NEW |