| 803 | } |
| 804 | |
| 805 | void 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. |
| 849 | bool LoopUnrollerUtilsImpl::DuplicateLoop(Loop* old_loop, Loop* new_loop) { |
nothing calls this directly
no test coverage detected