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

Method FixExitCondition

source/opt/loop_peeling.cpp:327–365  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

325}
326
327bool LoopPeeling::FixExitCondition(
328 const std::function<uint32_t(Instruction*)>& condition_builder) {
329 CFG& cfg = *context_->cfg();
330
331 uint32_t condition_block_id = 0;
332 for (uint32_t id : cfg.preds(GetClonedLoop()->GetMergeBlock()->id())) {
333 if (GetClonedLoop()->IsInsideLoop(id)) {
334 condition_block_id = id;
335 break;
336 }
337 }
338 assert(condition_block_id != 0 && "2nd loop in improperly connected");
339
340 BasicBlock* condition_block = cfg.block(condition_block_id);
341 Instruction* exit_condition = condition_block->terminator();
342 assert(exit_condition->opcode() == spv::Op::OpBranchConditional);
343 BasicBlock::iterator insert_point = condition_block->tail();
344 if (condition_block->GetMergeInst()) {
345 --insert_point;
346 }
347
348 uint32_t new_cond_id = condition_builder(&*insert_point);
349 if (new_cond_id == 0) {
350 return false;
351 }
352 exit_condition->SetInOperand(0, {new_cond_id});
353
354 uint32_t to_continue_block_idx =
355 GetClonedLoop()->IsInsideLoop(exit_condition->GetSingleWordInOperand(1))
356 ? 1
357 : 2;
358 exit_condition->SetInOperand(
359 1, {exit_condition->GetSingleWordInOperand(to_continue_block_idx)});
360 exit_condition->SetInOperand(2, {GetClonedLoop()->GetMergeBlock()->id()});
361
362 // Update def/use manager.
363 context_->get_def_use_mgr()->AnalyzeInstUse(exit_condition);
364 return true;
365}
366
367BasicBlock* LoopPeeling::CreateBlockBefore(BasicBlock* bb) {
368 analysis::DefUseManager* def_use_mgr = context_->get_def_use_mgr();

Callers

nothing calls this directly

Calls 13

GetMergeBlockMethod · 0.80
GetMergeInstMethod · 0.80
SetInOperandMethod · 0.80
AnalyzeInstUseMethod · 0.80
cfgMethod · 0.45
idMethod · 0.45
IsInsideLoopMethod · 0.45
blockMethod · 0.45
terminatorMethod · 0.45
opcodeMethod · 0.45
tailMethod · 0.45

Tested by

no test coverage detected