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

Method FullyUnroll

source/opt/loop_unroller.cpp:592–626  ·  view source on GitHub ↗

Fully unroll the loop by partially unrolling it by the number of loop iterations minus one for the body already accounted for.

Source from the content-addressed store, hash-verified

590// Fully unroll the loop by partially unrolling it by the number of loop
591// iterations minus one for the body already accounted for.
592bool LoopUnrollerUtilsImpl::FullyUnroll(Loop* loop) {
593 // We unroll the loop by number of iterations in the loop.
594 if (!Unroll(loop, number_of_loop_iterations_)) {
595 return false;
596 }
597
598 // The first condition block is preserved until now so it can be copied.
599 if (!FoldConditionBlock(loop_condition_block_, 1)) {
600 return false;
601 }
602
603 // Delete the OpLoopMerge and remove the backedge to the header.
604 CloseUnrolledLoop(loop);
605
606 // Mark the loop for later deletion. This allows us to preserve the loop
607 // iterators but still disregard dead loops.
608 loop->MarkLoopForRemoval();
609
610 // If the loop has a parent add the new blocks to the parent.
611 if (loop->GetParent()) {
612 AddBlocksToLoop(loop->GetParent());
613 }
614
615 // Add the blocks to the function.
616 AddBlocksToFunction(loop->GetMergeBlock());
617
618 ReplaceInductionUseWithFinalValue(loop);
619
620 RemoveDeadInstructions();
621 // Invalidate all analyses.
622 context_->InvalidateAnalysesExceptFor(
623 IRContext::Analysis::kAnalysisLoopAnalysis |
624 IRContext::Analysis::kAnalysisDefUse);
625 return true;
626}
627
628void LoopUnrollerUtilsImpl::KillDebugDeclares(BasicBlock* bb) {
629 // We cannot kill an instruction inside BasicBlock::ForEachInst()

Callers 3

PartiallyUnrollMethod · 0.80
ProcessMethod · 0.80
TEST_FFunction · 0.80

Calls 7

MarkLoopForRemovalMethod · 0.80
GetMergeBlockMethod · 0.80
GetInductionVariablesMethod · 0.80
InitMethod · 0.80
GetParentMethod · 0.45
GetHeaderBlockMethod · 0.45

Tested by

no test coverage detected