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

Method CloseUnrolledLoop

source/opt/loop_unroller.cpp:805–846  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

803}
804
805void LoopUnrollerUtilsImpl::CloseUnrolledLoop(Loop* loop) {
806 // Remove the OpLoopMerge instruction from the function.
807 Instruction* merge_inst = loop->GetHeaderBlock()->GetLoopMergeInst();
808 invalidated_instructions_.push_back(merge_inst);
809
810 // Remove the final backedge to the header and make it point instead to the
811 // merge block.
812 Instruction* latch_instruction = state_.previous_latch_block_->terminator();
813 latch_instruction->SetInOperand(0, {loop->GetMergeBlock()->id()});
814 context_->UpdateDefUse(latch_instruction);
815
816 // Remove all induction variables as the phis will now be invalid. Replace all
817 // uses with the constant initializer value (all uses of phis will be in
818 // the first iteration with the subsequent phis already having been removed).
819 std::vector<Instruction*> inductions;
820 loop->GetInductionVariables(inductions);
821
822 // We can use the state instruction mechanism to replace all internal loop
823 // values within the first loop trip (as the subsequent ones will be updated
824 // by the copy function) with the value coming in from the preheader and then
825 // use context ReplaceAllUsesWith for the uses outside the loop with the final
826 // trip phi value.
827 state_.new_inst.clear();
828 for (Instruction* induction : inductions) {
829 uint32_t initalizer_id =
830 GetPhiDefID(induction, loop->GetPreHeaderBlock()->id());
831
832 state_.new_inst[induction->result_id()] = initalizer_id;
833 }
834
835 for (BasicBlock* block : loop_blocks_inorder_) {
836 RemapOperands(block);
837 }
838 for (auto& block_itr : blocks_to_add_) {
839 RemapOperands(block_itr.get());
840 }
841
842 // Rewrite the last phis, since they may still reference the original phi.
843 for (Instruction* last_phi : state_.previous_phis_) {
844 RemapOperands(last_phi);
845 }
846}
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) {

Callers

nothing calls this directly

Calls 13

GetLoopMergeInstMethod · 0.80
SetInOperandMethod · 0.80
GetMergeBlockMethod · 0.80
GetInductionVariablesMethod · 0.80
GetPreHeaderBlockMethod · 0.80
getMethod · 0.80
GetHeaderBlockMethod · 0.45
push_backMethod · 0.45
terminatorMethod · 0.45
idMethod · 0.45
UpdateDefUseMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected