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

Method CanUnswitchLoop

source/opt/loop_unswitch_pass.cpp:60–82  ·  view source on GitHub ↗

Returns true if the loop can be unswitched. Can be unswitch if: - The loop has no instructions that prevents it (such as barrier); - The loop has one conditional branch or switch that do not depends on the loop; - The loop invariant condition is uniform;

Source from the content-addressed store, hash-verified

58 // loop;
59 // - The loop invariant condition is uniform;
60 bool CanUnswitchLoop() {
61 if (switch_block_) return true;
62 if (loop_->IsSafeToClone()) return false;
63
64 CFG& cfg = *context_->cfg();
65
66 for (uint32_t bb_id : loop_->GetBlocks()) {
67 BasicBlock* bb = cfg.block(bb_id);
68 if (loop_->GetLatchBlock() == bb) {
69 continue;
70 }
71
72 if (bb->terminator()->IsBranch() &&
73 bb->terminator()->opcode() != spv::Op::OpBranch) {
74 if (IsConditionNonConstantLoopInvariant(bb->terminator())) {
75 switch_block_ = bb;
76 break;
77 }
78 }
79 }
80
81 return switch_block_;
82 }
83
84 // Return the iterator to the basic block |bb|.
85 Function::iterator FindBasicBlockPosition(BasicBlock* bb_to_find) {

Callers 1

ProcessFunctionMethod · 0.80

Calls 7

IsSafeToCloneMethod · 0.80
GetLatchBlockMethod · 0.80
IsBranchMethod · 0.80
cfgMethod · 0.45
blockMethod · 0.45
terminatorMethod · 0.45
opcodeMethod · 0.45

Tested by

no test coverage detected