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

Method DuplicateLoop

source/opt/loop_unroller.cpp:849–884  ·  view source on GitHub ↗

Uses the first loop to create a copy of the loop with new IDs.

Source from the content-addressed store, hash-verified

847
848// Uses the first loop to create a copy of the loop with new IDs.
849bool LoopUnrollerUtilsImpl::DuplicateLoop(Loop* old_loop, Loop* new_loop) {
850 std::vector<BasicBlock*> new_block_order;
851
852 // Copy every block in the old loop.
853 for (const BasicBlock* itr : loop_blocks_inorder_) {
854 if (!CopyBasicBlock(old_loop, itr, true)) {
855 return false;
856 }
857 new_block_order.push_back(blocks_to_add_.back().get());
858 }
859
860 // Clone the merge block, give it a new id and record it in the state.
861 BasicBlock* new_merge = old_loop->GetMergeBlock()->Clone(context_);
862 if (!new_merge) return false;
863 new_merge->SetParent(old_loop->GetMergeBlock()->GetParent());
864 if (!AssignNewResultIds(new_merge)) {
865 return false;
866 }
867 state_.new_blocks[old_loop->GetMergeBlock()->id()] = new_merge;
868
869 // Remap the operands of every instruction in the loop to point to the new
870 // copies.
871 for (auto& pair : state_.new_blocks) {
872 RemapOperands(pair.second);
873 }
874
875 loop_blocks_inorder_ = std::move(new_block_order);
876
877 AddBlocksToLoop(new_loop);
878
879 new_loop->SetHeaderBlock(state_.new_header_block);
880 new_loop->SetContinueBlock(state_.new_continue_block);
881 new_loop->SetLatchBlock(state_.new_latch_block);
882 new_loop->SetMergeBlock(new_merge);
883 return true;
884}
885
886// Whenever the utility copies a block it stores it in a temporary buffer, this
887// function adds the buffer into the Function. The blocks will be inserted

Callers

nothing calls this directly

Calls 12

getMethod · 0.80
backMethod · 0.80
GetMergeBlockMethod · 0.80
SetHeaderBlockMethod · 0.80
SetContinueBlockMethod · 0.80
SetLatchBlockMethod · 0.80
SetMergeBlockMethod · 0.80
push_backMethod · 0.45
CloneMethod · 0.45
SetParentMethod · 0.45
GetParentMethod · 0.45
idMethod · 0.45

Tested by

no test coverage detected