| 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 #include <vector> | |
| 10 | 9 |
| 11 #include "src/v8.h" | 10 #include "src/zone-containers.h" |
| 12 | |
| 13 #include "src/compiler/node.h" | |
| 14 #include "src/compiler/opcodes.h" | |
| 15 #include "src/zone.h" | |
| 16 | 11 |
| 17 namespace v8 { | 12 namespace v8 { |
| 18 namespace internal { | 13 namespace internal { |
| 19 namespace compiler { | 14 namespace compiler { |
| 20 | 15 |
| 16 // Forward declarations. |
| 21 class BasicBlock; | 17 class BasicBlock; |
| 22 class BasicBlockInstrumentor; | 18 class BasicBlockInstrumentor; |
| 23 class Graph; | 19 class CodeGenerator; // Because of a namespace bug in clang. |
| 24 class ConstructScheduleData; | 20 class ConstructScheduleData; |
| 25 class CodeGenerator; // Because of a namespace bug in clang. | 21 class Node; |
| 22 |
| 23 |
| 24 typedef ZoneVector<BasicBlock*> BasicBlockVector; |
| 25 typedef ZoneVector<Node*> NodeVector; |
| 26 |
| 26 | 27 |
| 27 // A basic block contains an ordered list of nodes and ends with a control | 28 // A basic block contains an ordered list of nodes and ends with a control |
| 28 // node. Note that if a basic block has phis, then all phis must appear as the | 29 // node. Note that if a basic block has phis, then all phis must appear as the |
| 29 // first nodes in the block. | 30 // first nodes in the block. |
| 30 class BasicBlock FINAL : public ZoneObject { | 31 class BasicBlock FINAL : public ZoneObject { |
| 31 public: | 32 public: |
| 32 // Possible control nodes that can end a block. | 33 // Possible control nodes that can end a block. |
| 33 enum Control { | 34 enum Control { |
| 34 kNone, // Control not initialized yet. | 35 kNone, // Control not initialized yet. |
| 35 kGoto, // Goto a single successor block. | 36 kGoto, // Goto a single successor block. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 77 |
| 77 private: | 78 private: |
| 78 explicit RpoNumber(int32_t index) : index_(index) {} | 79 explicit RpoNumber(int32_t index) : index_(index) {} |
| 79 int32_t index_; | 80 int32_t index_; |
| 80 }; | 81 }; |
| 81 | 82 |
| 82 BasicBlock(Zone* zone, Id id); | 83 BasicBlock(Zone* zone, Id id); |
| 83 | 84 |
| 84 Id id() const { return id_; } | 85 Id id() const { return id_; } |
| 85 | 86 |
| 86 // Predecessors and successors. | 87 // Predecessors. |
| 87 typedef ZoneVector<BasicBlock*> Predecessors; | 88 BasicBlockVector& predecessors() { return predecessors_; } |
| 88 Predecessors::iterator predecessors_begin() { return predecessors_.begin(); } | 89 const BasicBlockVector& predecessors() const { return predecessors_; } |
| 89 Predecessors::iterator predecessors_end() { return predecessors_.end(); } | |
| 90 Predecessors::const_iterator predecessors_begin() const { | |
| 91 return predecessors_.begin(); | |
| 92 } | |
| 93 Predecessors::const_iterator predecessors_end() const { | |
| 94 return predecessors_.end(); | |
| 95 } | |
| 96 size_t PredecessorCount() const { return predecessors_.size(); } | 90 size_t PredecessorCount() const { return predecessors_.size(); } |
| 97 BasicBlock* PredecessorAt(size_t index) { return predecessors_[index]; } | 91 BasicBlock* PredecessorAt(size_t index) { return predecessors_[index]; } |
| 98 void ClearPredecessors() { predecessors_.clear(); } | 92 void ClearPredecessors() { predecessors_.clear(); } |
| 99 void AddPredecessor(BasicBlock* predecessor); | 93 void AddPredecessor(BasicBlock* predecessor); |
| 100 | 94 |
| 101 typedef ZoneVector<BasicBlock*> Successors; | 95 // Successors. |
| 102 Successors::iterator successors_begin() { return successors_.begin(); } | 96 BasicBlockVector& successors() { return successors_; } |
| 103 Successors::iterator successors_end() { return successors_.end(); } | 97 const BasicBlockVector& successors() const { return successors_; } |
| 104 Successors::const_iterator successors_begin() const { | |
| 105 return successors_.begin(); | |
| 106 } | |
| 107 Successors::const_iterator successors_end() const { | |
| 108 return successors_.end(); | |
| 109 } | |
| 110 size_t SuccessorCount() const { return successors_.size(); } | 98 size_t SuccessorCount() const { return successors_.size(); } |
| 111 BasicBlock* SuccessorAt(size_t index) { return successors_[index]; } | 99 BasicBlock* SuccessorAt(size_t index) { return successors_[index]; } |
| 112 void ClearSuccessors() { successors_.clear(); } | 100 void ClearSuccessors() { successors_.clear(); } |
| 113 void AddSuccessor(BasicBlock* successor); | 101 void AddSuccessor(BasicBlock* successor); |
| 114 | 102 |
| 115 // Nodes in the basic block. | 103 // Nodes in the basic block. |
| 104 typedef Node* value_type; |
| 105 bool empty() const { return nodes_.empty(); } |
| 106 size_t size() const { return nodes_.size(); } |
| 116 Node* NodeAt(size_t index) { return nodes_[index]; } | 107 Node* NodeAt(size_t index) { return nodes_[index]; } |
| 117 size_t NodeCount() const { return nodes_.size(); } | 108 size_t NodeCount() const { return nodes_.size(); } |
| 118 | 109 |
| 119 typedef NodeVector::iterator iterator; | 110 typedef NodeVector::iterator iterator; |
| 120 iterator begin() { return nodes_.begin(); } | 111 iterator begin() { return nodes_.begin(); } |
| 121 iterator end() { return nodes_.end(); } | 112 iterator end() { return nodes_.end(); } |
| 122 | 113 |
| 123 typedef NodeVector::const_iterator const_iterator; | 114 typedef NodeVector::const_iterator const_iterator; |
| 124 const_iterator begin() const { return nodes_.begin(); } | 115 const_iterator begin() const { return nodes_.begin(); } |
| 125 const_iterator end() const { return nodes_.end(); } | 116 const_iterator end() const { return nodes_.end(); } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 BasicBlock* loop_header_; // Pointer to dominating loop header basic block, | 175 BasicBlock* loop_header_; // Pointer to dominating loop header basic block, |
| 185 // NULL if none. For loop headers, this points to | 176 // NULL if none. For loop headers, this points to |
| 186 // enclosing loop header. | 177 // enclosing loop header. |
| 187 BasicBlock* loop_end_; // end of the loop, if this block is a loop header. | 178 BasicBlock* loop_end_; // end of the loop, if this block is a loop header. |
| 188 int32_t loop_depth_; // loop nesting, 0 is top-level | 179 int32_t loop_depth_; // loop nesting, 0 is top-level |
| 189 | 180 |
| 190 Control control_; // Control at the end of the block. | 181 Control control_; // Control at the end of the block. |
| 191 Node* control_input_; // Input value for control. | 182 Node* control_input_; // Input value for control. |
| 192 NodeVector nodes_; // nodes of this block in forward order. | 183 NodeVector nodes_; // nodes of this block in forward order. |
| 193 | 184 |
| 194 Successors successors_; | 185 BasicBlockVector successors_; |
| 195 Predecessors predecessors_; | 186 BasicBlockVector predecessors_; |
| 196 Id id_; | 187 Id id_; |
| 197 | 188 |
| 198 DISALLOW_COPY_AND_ASSIGN(BasicBlock); | 189 DISALLOW_COPY_AND_ASSIGN(BasicBlock); |
| 199 }; | 190 }; |
| 200 | 191 |
| 201 std::ostream& operator<<(std::ostream& os, const BasicBlock::Control& c); | 192 std::ostream& operator<<(std::ostream&, const BasicBlock::Control&); |
| 202 std::ostream& operator<<(std::ostream& os, const BasicBlock::Id& id); | 193 std::ostream& operator<<(std::ostream&, const BasicBlock::Id&); |
| 203 std::ostream& operator<<(std::ostream& os, const BasicBlock::RpoNumber& rpo); | 194 std::ostream& operator<<(std::ostream&, const BasicBlock::RpoNumber&); |
| 204 | 195 |
| 205 typedef ZoneVector<BasicBlock*> BasicBlockVector; | |
| 206 typedef BasicBlockVector::iterator BasicBlockVectorIter; | |
| 207 typedef BasicBlockVector::reverse_iterator BasicBlockVectorRIter; | |
| 208 | 196 |
| 209 // A schedule represents the result of assigning nodes to basic blocks | 197 // A schedule represents the result of assigning nodes to basic blocks |
| 210 // and ordering them within basic blocks. Prior to computing a schedule, | 198 // and ordering them within basic blocks. Prior to computing a schedule, |
| 211 // a graph has no notion of control flow ordering other than that induced | 199 // a graph has no notion of control flow ordering other than that induced |
| 212 // by the graph's dependencies. A schedule is required to generate code. | 200 // by the graph's dependencies. A schedule is required to generate code. |
| 213 class Schedule FINAL : public ZoneObject { | 201 class Schedule FINAL : public ZoneObject { |
| 214 public: | 202 public: |
| 215 explicit Schedule(Zone* zone, size_t node_count_hint = 0); | 203 explicit Schedule(Zone* zone, size_t node_count_hint = 0); |
| 216 | 204 |
| 217 // Return the block which contains {node}, if any. | 205 // Return the block which contains {node}, if any. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 Zone* zone_; | 267 Zone* zone_; |
| 280 BasicBlockVector all_blocks_; // All basic blocks in the schedule. | 268 BasicBlockVector all_blocks_; // All basic blocks in the schedule. |
| 281 BasicBlockVector nodeid_to_block_; // Map from node to containing block. | 269 BasicBlockVector nodeid_to_block_; // Map from node to containing block. |
| 282 BasicBlockVector rpo_order_; // Reverse-post-order block list. | 270 BasicBlockVector rpo_order_; // Reverse-post-order block list. |
| 283 BasicBlock* start_; | 271 BasicBlock* start_; |
| 284 BasicBlock* end_; | 272 BasicBlock* end_; |
| 285 | 273 |
| 286 DISALLOW_COPY_AND_ASSIGN(Schedule); | 274 DISALLOW_COPY_AND_ASSIGN(Schedule); |
| 287 }; | 275 }; |
| 288 | 276 |
| 289 std::ostream& operator<<(std::ostream& os, const Schedule& s); | 277 std::ostream& operator<<(std::ostream&, const Schedule&); |
| 290 | 278 |
| 291 } // namespace compiler | 279 } // namespace compiler |
| 292 } // namespace internal | 280 } // namespace internal |
| 293 } // namespace v8 | 281 } // namespace v8 |
| 294 | 282 |
| 295 #endif // V8_COMPILER_SCHEDULE_H_ | 283 #endif // V8_COMPILER_SCHEDULE_H_ |
| OLD | NEW |