Chromium Code Reviews| 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/schedule.h" | 5 #include "src/compiler/schedule.h" |
| 6 | 6 |
| 7 #include "src/compiler/node.h" | 7 #include "src/compiler/node.h" |
| 8 #include "src/compiler/node-properties.h" | 8 #include "src/compiler/node-properties.h" |
| 9 #include "src/ostreams.h" | 9 #include "src/ostreams.h" |
| 10 | 10 |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 MoveSuccessors(block, end); | 291 MoveSuccessors(block, end); |
| 292 for (size_t index = 0; index < succ_count; ++index) { | 292 for (size_t index = 0; index < succ_count; ++index) { |
| 293 AddSuccessor(block, succ_blocks[index]); | 293 AddSuccessor(block, succ_blocks[index]); |
| 294 } | 294 } |
| 295 if (block->control_input() != nullptr) { | 295 if (block->control_input() != nullptr) { |
| 296 SetControlInput(end, block->control_input()); | 296 SetControlInput(end, block->control_input()); |
| 297 } | 297 } |
| 298 SetControlInput(block, sw); | 298 SetControlInput(block, sw); |
| 299 } | 299 } |
| 300 | 300 |
| 301 void Schedule::EnsureSplitEdgeForm() { | |
| 302 // Make a copy of all the blocks for the iteration, since adding the split | |
| 303 // edges will allocate new blocks. | |
| 304 BasicBlockVector all_blocks_copy(all_blocks_); | |
| 305 | |
| 306 // Insert missing split edge blocks. | |
| 307 for (auto block : all_blocks_copy) { | |
| 308 if (block->PredecessorCount() > 1 && block != end_) { | |
| 309 for (auto current_pred = block->predecessors().begin(); | |
| 310 current_pred != block->predecessors().end(); ++current_pred) { | |
| 311 BasicBlock* pred = *current_pred; | |
| 312 if (pred->SuccessorCount() > 1) { | |
| 313 // Found a predecessor block with multiple successors. | |
| 314 BasicBlock* split_edge_block = NewBasicBlock(); | |
| 315 split_edge_block->set_control(BasicBlock::kGoto); | |
| 316 split_edge_block->successors().push_back(block); | |
| 317 split_edge_block->predecessors().push_back(pred); | |
| 318 split_edge_block->set_deferred(pred->deferred()); | |
| 319 *current_pred = split_edge_block; | |
| 320 // Find a corresponding successor in the previous block, replace it | |
| 321 // with the split edge block... but only do it once, since we only | |
| 322 // replace the previous blocks in the current block one at a time. | |
| 323 bool found = false; | |
| 324 replace_if(pred->successors().begin(), pred->successors().end(), | |
|
titzer
2016/03/21 08:06:03
A regular for loop would be more readable here.
danno
2016/03/22 07:53:44
Done.
| |
| 325 [block, found](BasicBlock* e) mutable -> bool { | |
| 326 if (!found && block == e) { | |
| 327 found = true; | |
| 328 return true; | |
| 329 } else { | |
| 330 return false; | |
| 331 } | |
| 332 }, | |
| 333 split_edge_block); | |
| 334 } | |
| 335 } | |
| 336 } | |
| 337 } | |
| 338 } | |
| 339 | |
| 340 void Schedule::PropagateDeferredMark() { | |
| 341 // Push forward the deferred block marks through newly inserted blocks | |
| 342 // and other improperly maked blocks until a fixed point is reached. | |
|
titzer
2016/03/21 08:06:03
s/maked/marked
danno
2016/03/22 07:53:44
Done.
| |
| 343 // TODO(danno): optimize the propagaion | |
|
titzer
2016/03/21 08:06:03
s/propagaion/propagation
danno
2016/03/22 07:53:44
Done.
| |
| 344 bool done = false; | |
| 345 while (!done) { | |
| 346 done = true; | |
| 347 for (auto block : all_blocks_) { | |
| 348 if (!block->deferred()) { | |
| 349 bool deferred = block->PredecessorCount() > 0; | |
| 350 for (auto pred : block->predecessors()) { | |
| 351 if (!pred->deferred()) { | |
| 352 deferred = false; | |
| 353 } | |
| 354 } | |
| 355 if (deferred) { | |
| 356 block->set_deferred(true); | |
| 357 done = false; | |
| 358 } | |
| 359 } | |
| 360 } | |
| 361 } | |
| 362 } | |
| 301 | 363 |
| 302 void Schedule::AddSuccessor(BasicBlock* block, BasicBlock* succ) { | 364 void Schedule::AddSuccessor(BasicBlock* block, BasicBlock* succ) { |
| 303 block->AddSuccessor(succ); | 365 block->AddSuccessor(succ); |
| 304 succ->AddPredecessor(block); | 366 succ->AddPredecessor(block); |
| 305 } | 367 } |
| 306 | 368 |
| 307 | 369 |
| 308 void Schedule::MoveSuccessors(BasicBlock* from, BasicBlock* to) { | 370 void Schedule::MoveSuccessors(BasicBlock* from, BasicBlock* to) { |
| 309 for (BasicBlock* const successor : from->successors()) { | 371 for (BasicBlock* const successor : from->successors()) { |
| 310 to->AddSuccessor(successor); | 372 to->AddSuccessor(successor); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 324 | 386 |
| 325 void Schedule::SetBlockForNode(BasicBlock* block, Node* node) { | 387 void Schedule::SetBlockForNode(BasicBlock* block, Node* node) { |
| 326 if (node->id() >= nodeid_to_block_.size()) { | 388 if (node->id() >= nodeid_to_block_.size()) { |
| 327 nodeid_to_block_.resize(node->id() + 1); | 389 nodeid_to_block_.resize(node->id() + 1); |
| 328 } | 390 } |
| 329 nodeid_to_block_[node->id()] = block; | 391 nodeid_to_block_[node->id()] = block; |
| 330 } | 392 } |
| 331 | 393 |
| 332 | 394 |
| 333 std::ostream& operator<<(std::ostream& os, const Schedule& s) { | 395 std::ostream& operator<<(std::ostream& os, const Schedule& s) { |
| 334 for (BasicBlock* block : *s.rpo_order()) { | 396 for (BasicBlock* block : |
| 335 os << "--- BLOCK B" << block->rpo_number(); | 397 ((s.RpoBlockCount() == 0) ? *s.all_blocks() : *s.rpo_order())) { |
| 398 if (block->rpo_number() == -1) { | |
| 399 os << "--- BLOCK B" << block->id().ToInt() << " (block id)"; | |
| 400 } else { | |
| 401 os << "--- BLOCK B" << block->rpo_number(); | |
| 402 } | |
| 336 if (block->deferred()) os << " (deferred)"; | 403 if (block->deferred()) os << " (deferred)"; |
| 337 if (block->PredecessorCount() != 0) os << " <- "; | 404 if (block->PredecessorCount() != 0) os << " <- "; |
| 338 bool comma = false; | 405 bool comma = false; |
| 339 for (BasicBlock const* predecessor : block->predecessors()) { | 406 for (BasicBlock const* predecessor : block->predecessors()) { |
| 340 if (comma) os << ", "; | 407 if (comma) os << ", "; |
| 341 comma = true; | 408 comma = true; |
| 342 os << "B" << predecessor->rpo_number(); | 409 if (predecessor->rpo_number() == -1) { |
| 410 os << "B" << predecessor->id().ToInt(); | |
| 411 } else { | |
| 412 os << "B" << predecessor->rpo_number(); | |
| 413 } | |
| 343 } | 414 } |
| 344 os << " ---\n"; | 415 os << " ---\n"; |
| 345 for (Node* node : *block) { | 416 for (Node* node : *block) { |
| 346 os << " " << *node; | 417 os << " " << *node; |
| 347 if (NodeProperties::IsTyped(node)) { | 418 if (NodeProperties::IsTyped(node)) { |
| 348 Type* type = NodeProperties::GetType(node); | 419 Type* type = NodeProperties::GetType(node); |
| 349 os << " : "; | 420 os << " : "; |
| 350 type->PrintTo(os); | 421 type->PrintTo(os); |
| 351 } | 422 } |
| 352 os << "\n"; | 423 os << "\n"; |
| 353 } | 424 } |
| 354 BasicBlock::Control control = block->control(); | 425 BasicBlock::Control control = block->control(); |
| 355 if (control != BasicBlock::kNone) { | 426 if (control != BasicBlock::kNone) { |
| 356 os << " "; | 427 os << " "; |
| 357 if (block->control_input() != nullptr) { | 428 if (block->control_input() != nullptr) { |
| 358 os << *block->control_input(); | 429 os << *block->control_input(); |
| 359 } else { | 430 } else { |
| 360 os << "Goto"; | 431 os << "Goto"; |
| 361 } | 432 } |
| 362 os << " -> "; | 433 os << " -> "; |
| 363 comma = false; | 434 comma = false; |
| 364 for (BasicBlock const* successor : block->successors()) { | 435 for (BasicBlock const* successor : block->successors()) { |
| 365 if (comma) os << ", "; | 436 if (comma) os << ", "; |
| 366 comma = true; | 437 comma = true; |
| 367 os << "B" << successor->rpo_number(); | 438 if (successor->rpo_number() == -1) { |
| 439 os << "B" << successor->id().ToInt(); | |
| 440 } else { | |
| 441 os << "B" << successor->rpo_number(); | |
| 442 } | |
| 368 } | 443 } |
| 369 os << "\n"; | 444 os << "\n"; |
| 370 } | 445 } |
| 371 } | 446 } |
| 372 return os; | 447 return os; |
| 373 } | 448 } |
| 374 | 449 |
| 375 } // namespace compiler | 450 } // namespace compiler |
| 376 } // namespace internal | 451 } // namespace internal |
| 377 } // namespace v8 | 452 } // namespace v8 |
| OLD | NEW |