MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / ComputeLoopStructuredOrder

Method ComputeLoopStructuredOrder

source/opt/loop_descriptor.cpp:473–508  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

471}
472
473void 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
510LoopDescriptor::LoopDescriptor(IRContext* context, const Function* f)
511 : loops_(), placeholder_top_loop_(nullptr) {

Callers 4

CloneLoopMethod · 0.80
PerformUnswitchMethod · 0.80

Calls 8

cfgMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
HasCapabilityMethod · 0.45
get_feature_mgrMethod · 0.45
GetParentMethod · 0.45

Tested by

no test coverage detected