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 #include "src/compiler/node.h" | 5 #include "src/compiler/node.h" |
6 #include "src/compiler/node-properties.h" | 6 #include "src/compiler/node-properties.h" |
7 #include "src/compiler/node-properties-inl.h" | 7 #include "src/compiler/node-properties-inl.h" |
8 #include "src/compiler/schedule.h" | 8 #include "src/compiler/schedule.h" |
9 #include "src/ostreams.h" | 9 #include "src/ostreams.h" |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 void BasicBlock::AddPredecessor(BasicBlock* predecessor) { | 45 void BasicBlock::AddPredecessor(BasicBlock* predecessor) { |
46 predecessors_.push_back(predecessor); | 46 predecessors_.push_back(predecessor); |
47 } | 47 } |
48 | 48 |
49 | 49 |
50 void BasicBlock::AddNode(Node* node) { nodes_.push_back(node); } | 50 void BasicBlock::AddNode(Node* node) { nodes_.push_back(node); } |
51 | 51 |
52 | 52 |
53 void BasicBlock::set_control(Control control) { | 53 void BasicBlock::set_control(Control control) { |
54 DCHECK(control_ == BasicBlock::kNone); | |
55 control_ = control; | 54 control_ = control; |
56 } | 55 } |
57 | 56 |
58 | 57 |
59 void BasicBlock::set_control_input(Node* control_input) { | 58 void BasicBlock::set_control_input(Node* control_input) { |
60 control_input_ = control_input; | 59 control_input_ = control_input; |
61 } | 60 } |
62 | 61 |
63 | 62 |
64 void BasicBlock::set_dominator(BasicBlock* dominator) { | 63 void BasicBlock::set_dominator(BasicBlock* dominator) { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 207 |
209 | 208 |
210 void Schedule::AddThrow(BasicBlock* block, Node* input) { | 209 void Schedule::AddThrow(BasicBlock* block, Node* input) { |
211 DCHECK(block->control() == BasicBlock::kNone); | 210 DCHECK(block->control() == BasicBlock::kNone); |
212 block->set_control(BasicBlock::kThrow); | 211 block->set_control(BasicBlock::kThrow); |
213 SetControlInput(block, input); | 212 SetControlInput(block, input); |
214 if (block != end()) AddSuccessor(block, end()); | 213 if (block != end()) AddSuccessor(block, end()); |
215 } | 214 } |
216 | 215 |
217 | 216 |
| 217 void Schedule::InsertBranch(BasicBlock* block, BasicBlock* end, Node* branch, |
| 218 BasicBlock* tblock, BasicBlock* fblock) { |
| 219 DCHECK(block->control() != BasicBlock::kNone); |
| 220 DCHECK(end->control() == BasicBlock::kNone); |
| 221 end->set_control(block->control()); |
| 222 block->set_control(BasicBlock::kBranch); |
| 223 MoveSuccessors(block, end); |
| 224 AddSuccessor(block, tblock); |
| 225 AddSuccessor(block, fblock); |
| 226 if (block->control_input() != NULL) { |
| 227 SetControlInput(end, block->control_input()); |
| 228 } |
| 229 SetControlInput(block, branch); |
| 230 } |
| 231 |
| 232 |
218 void Schedule::AddSuccessor(BasicBlock* block, BasicBlock* succ) { | 233 void Schedule::AddSuccessor(BasicBlock* block, BasicBlock* succ) { |
219 block->AddSuccessor(succ); | 234 block->AddSuccessor(succ); |
220 succ->AddPredecessor(block); | 235 succ->AddPredecessor(block); |
221 } | 236 } |
222 | 237 |
223 | 238 |
| 239 void Schedule::MoveSuccessors(BasicBlock* from, BasicBlock* to) { |
| 240 for (BasicBlock::Predecessors::iterator i = from->successors_begin(); |
| 241 i != from->successors_end(); ++i) { |
| 242 BasicBlock* succ = *i; |
| 243 to->AddSuccessor(succ); |
| 244 for (BasicBlock::Predecessors::iterator j = succ->predecessors_begin(); |
| 245 j != succ->predecessors_end(); ++j) { |
| 246 if (*j == from) *j = to; |
| 247 } |
| 248 } |
| 249 from->ClearSuccessors(); |
| 250 } |
| 251 |
| 252 |
224 void Schedule::SetControlInput(BasicBlock* block, Node* node) { | 253 void Schedule::SetControlInput(BasicBlock* block, Node* node) { |
225 block->set_control_input(node); | 254 block->set_control_input(node); |
226 SetBlockForNode(block, node); | 255 SetBlockForNode(block, node); |
227 } | 256 } |
228 | 257 |
229 | 258 |
230 void Schedule::SetBlockForNode(BasicBlock* block, Node* node) { | 259 void Schedule::SetBlockForNode(BasicBlock* block, Node* node) { |
231 int length = static_cast<int>(nodeid_to_block_.size()); | 260 int length = static_cast<int>(nodeid_to_block_.size()); |
232 if (node->id() >= length) { | 261 if (node->id() >= length) { |
233 nodeid_to_block_.resize(node->id() + 1); | 262 nodeid_to_block_.resize(node->id() + 1); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 } | 314 } |
286 os << "\n"; | 315 os << "\n"; |
287 } | 316 } |
288 } | 317 } |
289 return os; | 318 return os; |
290 } | 319 } |
291 | 320 |
292 } // namespace compiler | 321 } // namespace compiler |
293 } // namespace internal | 322 } // namespace internal |
294 } // namespace v8 | 323 } // namespace v8 |
OLD | NEW |