| 471 | } |
| 472 | |
| 473 | void Loop::ComputeLoopStructuredOrder( |
| 474 | std::vector<BasicBlock*>* ordered_loop_blocks, bool include_pre_header, |
| 475 | bool include_merge) const { |
| 476 | CFG& cfg = *context_->cfg(); |
| 477 | |
| 478 | // Reserve the memory: all blocks in the loop + extra if needed. |
| 479 | ordered_loop_blocks->reserve(GetBlocks().size() + include_pre_header + |
| 480 | include_merge); |
| 481 | |
| 482 | if (include_pre_header && GetPreHeaderBlock()) |
| 483 | ordered_loop_blocks->push_back(loop_preheader_); |
| 484 | |
| 485 | bool is_shader = |
| 486 | context_->get_feature_mgr()->HasCapability(spv::Capability::Shader); |
| 487 | if (!is_shader) { |
| 488 | cfg.ForEachBlockInReversePostOrder( |
| 489 | loop_header_, [ordered_loop_blocks, this](BasicBlock* bb) { |
| 490 | if (IsInsideLoop(bb)) ordered_loop_blocks->push_back(bb); |
| 491 | }); |
| 492 | } else { |
| 493 | // If this is a shader, it is possible that there are unreachable merge and |
| 494 | // continue blocks that must be copied to retain the structured order. |
| 495 | // The structured order will include these. |
| 496 | std::list<BasicBlock*> order; |
| 497 | cfg.ComputeStructuredOrder(loop_header_->GetParent(), loop_header_, |
| 498 | loop_merge_, &order); |
| 499 | for (BasicBlock* bb : order) { |
| 500 | if (bb == GetMergeBlock()) { |
| 501 | break; |
| 502 | } |
| 503 | ordered_loop_blocks->push_back(bb); |
| 504 | } |
| 505 | } |
| 506 | if (include_merge && GetMergeBlock()) |
| 507 | ordered_loop_blocks->push_back(loop_merge_); |
| 508 | } |
| 509 | |
| 510 | LoopDescriptor::LoopDescriptor(IRContext* context, const Function* f) |
| 511 | : loops_(), placeholder_top_loop_(nullptr) { |
no test coverage detected