| 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 <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "src/v8.h" | 10 #include "src/v8.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 // by the graph's dependencies. A schedule is required to generate code. | 156 // by the graph's dependencies. A schedule is required to generate code. |
| 157 class Schedule : public GenericGraph<BasicBlock> { | 157 class Schedule : public GenericGraph<BasicBlock> { |
| 158 public: | 158 public: |
| 159 explicit Schedule(Zone* zone) | 159 explicit Schedule(Zone* zone) |
| 160 : GenericGraph<BasicBlock>(zone), | 160 : GenericGraph<BasicBlock>(zone), |
| 161 zone_(zone), | 161 zone_(zone), |
| 162 all_blocks_(BasicBlockVector::allocator_type(zone)), | 162 all_blocks_(BasicBlockVector::allocator_type(zone)), |
| 163 nodeid_to_block_(BasicBlockVector::allocator_type(zone)), | 163 nodeid_to_block_(BasicBlockVector::allocator_type(zone)), |
| 164 rpo_order_(BasicBlockVector::allocator_type(zone)), | 164 rpo_order_(BasicBlockVector::allocator_type(zone)), |
| 165 immediate_dominator_(BasicBlockVector::allocator_type(zone)) { | 165 immediate_dominator_(BasicBlockVector::allocator_type(zone)) { |
| 166 NewBasicBlock(); // entry. | 166 SetStart(NewBasicBlock()); // entry. |
| 167 NewBasicBlock(); // exit. | 167 SetEnd(NewBasicBlock()); // exit. |
| 168 SetStart(entry()); | |
| 169 SetEnd(exit()); | |
| 170 } | 168 } |
| 171 | 169 |
| 172 // TODO(titzer): rewrite users of these methods to use start() and end(). | |
| 173 BasicBlock* entry() const { return all_blocks_[0]; } // Return entry block. | |
| 174 BasicBlock* exit() const { return all_blocks_[1]; } // Return exit block. | |
| 175 | |
| 176 // Return the block which contains {node}, if any. | 170 // Return the block which contains {node}, if any. |
| 177 BasicBlock* block(Node* node) const { | 171 BasicBlock* block(Node* node) const { |
| 178 if (node->id() < static_cast<NodeId>(nodeid_to_block_.size())) { | 172 if (node->id() < static_cast<NodeId>(nodeid_to_block_.size())) { |
| 179 return nodeid_to_block_[node->id()]; | 173 return nodeid_to_block_[node->id()]; |
| 180 } | 174 } |
| 181 return NULL; | 175 return NULL; |
| 182 } | 176 } |
| 183 | 177 |
| 184 BasicBlock* dominator(BasicBlock* block) { | 178 BasicBlock* dominator(BasicBlock* block) { |
| 185 return immediate_dominator_[block->id()]; | 179 return immediate_dominator_[block->id()]; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 AddSuccessor(block, fblock); | 260 AddSuccessor(block, fblock); |
| 267 SetControlInput(block, branch); | 261 SetControlInput(block, branch); |
| 268 } | 262 } |
| 269 | 263 |
| 270 // BasicBlock building: add a return at the end of {block}. | 264 // BasicBlock building: add a return at the end of {block}. |
| 271 void AddReturn(BasicBlock* block, Node* input) { | 265 void AddReturn(BasicBlock* block, Node* input) { |
| 272 // TODO(titzer): require a Return node here. | 266 // TODO(titzer): require a Return node here. |
| 273 DCHECK(block->control_ == BasicBlock::kNone); | 267 DCHECK(block->control_ == BasicBlock::kNone); |
| 274 block->control_ = BasicBlock::kReturn; | 268 block->control_ = BasicBlock::kReturn; |
| 275 SetControlInput(block, input); | 269 SetControlInput(block, input); |
| 276 if (block != exit()) AddSuccessor(block, exit()); | 270 if (block != end()) AddSuccessor(block, end()); |
| 277 } | 271 } |
| 278 | 272 |
| 279 // BasicBlock building: add a throw at the end of {block}. | 273 // BasicBlock building: add a throw at the end of {block}. |
| 280 void AddThrow(BasicBlock* block, Node* input) { | 274 void AddThrow(BasicBlock* block, Node* input) { |
| 281 DCHECK(block->control_ == BasicBlock::kNone); | 275 DCHECK(block->control_ == BasicBlock::kNone); |
| 282 block->control_ = BasicBlock::kThrow; | 276 block->control_ = BasicBlock::kThrow; |
| 283 SetControlInput(block, input); | 277 SetControlInput(block, input); |
| 284 if (block != exit()) AddSuccessor(block, exit()); | 278 if (block != end()) AddSuccessor(block, end()); |
| 285 } | 279 } |
| 286 | 280 |
| 287 // BasicBlock building: add a deopt at the end of {block}. | 281 // BasicBlock building: add a deopt at the end of {block}. |
| 288 void AddDeoptimize(BasicBlock* block, Node* state) { | 282 void AddDeoptimize(BasicBlock* block, Node* state) { |
| 289 DCHECK(block->control_ == BasicBlock::kNone); | 283 DCHECK(block->control_ == BasicBlock::kNone); |
| 290 block->control_ = BasicBlock::kDeoptimize; | 284 block->control_ = BasicBlock::kDeoptimize; |
| 291 SetControlInput(block, state); | 285 SetControlInput(block, state); |
| 292 block->deferred_ = true; // By default, consider deopts the slow path. | 286 block->deferred_ = true; // By default, consider deopts the slow path. |
| 293 if (block != exit()) AddSuccessor(block, exit()); | 287 if (block != end()) AddSuccessor(block, end()); |
| 294 } | 288 } |
| 295 | 289 |
| 296 friend class Scheduler; | 290 friend class Scheduler; |
| 297 friend class CodeGenerator; | 291 friend class CodeGenerator; |
| 298 | 292 |
| 299 void AddSuccessor(BasicBlock* block, BasicBlock* succ) { | 293 void AddSuccessor(BasicBlock* block, BasicBlock* succ) { |
| 300 succ->AppendInput(zone_, block); | 294 succ->AppendInput(zone_, block); |
| 301 } | 295 } |
| 302 | 296 |
| 303 BasicBlockVector* rpo_order() { return &rpo_order_; } | 297 BasicBlockVector* rpo_order() { return &rpo_order_; } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 326 // dominator, indexed by block | 320 // dominator, indexed by block |
| 327 // id. | 321 // id. |
| 328 }; | 322 }; |
| 329 | 323 |
| 330 OStream& operator<<(OStream& os, const Schedule& s); | 324 OStream& operator<<(OStream& os, const Schedule& s); |
| 331 } | 325 } |
| 332 } | 326 } |
| 333 } // namespace v8::internal::compiler | 327 } // namespace v8::internal::compiler |
| 334 | 328 |
| 335 #endif // V8_COMPILER_SCHEDULE_H_ | 329 #endif // V8_COMPILER_SCHEDULE_H_ |
| OLD | NEW |