diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp --- a/clang/lib/CodeGen/CGCleanup.cpp +++ b/clang/lib/CodeGen/CGCleanup.cpp @@ -942,7 +942,7 @@ // Append the prepared cleanup prologue from above. llvm::BasicBlock *NormalExit = Builder.GetInsertBlock(); for (unsigned I = 0, E = InstsToAppend.size(); I != E; ++I) - NormalExit->getInstList().push_back(InstsToAppend[I]); + InstsToAppend[I]->insertAt(NormalExit, NormalExit->end()); // Optimistically hope that any fixups will continue falling through. for (unsigned I = FixupDepth, E = EHStack.getNumBranchFixups(); diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h --- a/llvm/include/llvm/IR/IRBuilder.h +++ b/llvm/include/llvm/IR/IRBuilder.h @@ -65,7 +65,8 @@ virtual void InsertHelper(Instruction *I, const Twine &Name, BasicBlock *BB, BasicBlock::iterator InsertPt) const { - if (BB) BB->getInstList().insert(InsertPt, I); + if (BB) + I->insertAt(BB, InsertPt); I->setName(Name); } }; diff --git a/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h b/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h --- a/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h +++ b/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h @@ -397,7 +397,7 @@ assert(New && !New->getParent() && "New instruction already inserted into a basic block!"); BasicBlock *BB = Old.getParent(); - BB->getInstList().insert(Old.getIterator(), New); // Insert inst + New->insertAt(BB, Old.getIterator()); // Insert inst Worklist.push(New); return New; } diff --git a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h --- a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h +++ b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h @@ -121,8 +121,8 @@ /// Copies DebugLoc from BI to I, if I doesn't already have a DebugLoc. The /// original instruction is deleted and BI is updated to point to the new /// instruction. -void ReplaceInstWithInst(BasicBlock::InstListType &BIL, - BasicBlock::iterator &BI, Instruction *I); +void ReplaceInstWithInst(BasicBlock *BB, BasicBlock::iterator &BI, + Instruction *I); /// Replace the instruction specified by From with the instruction specified by /// To. Copies DebugLoc from BI to I, if I doesn't already have a DebugLoc. diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -6166,7 +6166,7 @@ llvm_unreachable("Unknown parseInstruction result!"); case InstError: return true; case InstNormal: - BB->getInstList().push_back(Inst); + Inst->insertAt(BB, BB->end()); // With a normal result, we check to see if the instruction is followed by // a comma and metadata. @@ -6175,7 +6175,7 @@ return true; break; case InstExtraComma: - BB->getInstList().push_back(Inst); + Inst->insertAt(BB, BB->end()); // If the instruction parser ate an extra comma at the end of it, it // *must* be followed by metadata. diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -4840,7 +4840,7 @@ if (Temp) { InstructionList.push_back(Temp); assert(CurBB && "No current BB?"); - CurBB->getInstList().push_back(Temp); + Temp->insertAt(CurBB, CurBB->end()); } } else { auto CastOp = (Instruction::CastOps)Opc; @@ -6088,7 +6088,7 @@ // Before weak cmpxchgs existed, the instruction simply returned the // value loaded from memory, so bitcode files from that era will be // expecting the first component of a modern cmpxchg. - CurBB->getInstList().push_back(I); + I->insertAt(CurBB, CurBB->end()); I = ExtractValueInst::Create(I, 0); ResTypeID = CmpTypeID; } else { @@ -6412,7 +6412,7 @@ I->deleteValue(); return error("Operand bundles found with no consumer"); } - CurBB->getInstList().push_back(I); + I->insertAt(CurBB, CurBB->end()); // If this was a terminator instruction, move to the next block. if (I->isTerminator()) { diff --git a/llvm/lib/CodeGen/WinEHPrepare.cpp b/llvm/lib/CodeGen/WinEHPrepare.cpp --- a/llvm/lib/CodeGen/WinEHPrepare.cpp +++ b/llvm/lib/CodeGen/WinEHPrepare.cpp @@ -1212,8 +1212,8 @@ BranchInst *Goto = cast(IncomingBlock->getTerminator()); Goto->removeFromParent(); CatchRet->removeFromParent(); - IncomingBlock->getInstList().push_back(CatchRet); - NewBlock->getInstList().push_back(Goto); + CatchRet->insertAt(IncomingBlock, IncomingBlock->end()); + Goto->insertAt(NewBlock, NewBlock->end()); Goto->setSuccessor(0, PHIBlock); CatchRet->setSuccessor(NewBlock); // Update the color mapping for the newly split edge. diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp --- a/llvm/lib/IR/Instruction.cpp +++ b/llvm/lib/IR/Instruction.cpp @@ -28,7 +28,7 @@ if (InsertBefore) { BasicBlock *BB = InsertBefore->getParent(); assert(BB && "Instruction to insert before is not in a basic block!"); - BB->getInstList().insert(InsertBefore->getIterator(), this); + insertAt(BB, InsertBefore->getIterator()); } } @@ -38,7 +38,7 @@ // append this instruction into the basic block assert(InsertAtEnd && "Basic block to append to may not be NULL!"); - InsertAtEnd->getInstList().push_back(this); + insertAt(InsertAtEnd, InsertAtEnd->end()); } Instruction::~Instruction() { @@ -85,14 +85,13 @@ /// Insert an unlinked instruction into a basic block immediately before the /// specified instruction. void Instruction::insertBefore(Instruction *InsertPos) { - InsertPos->getParent()->getInstList().insert(InsertPos->getIterator(), this); + insertAt(InsertPos->getParent(), InsertPos->getIterator()); } /// Insert an unlinked instruction into a basic block immediately after the /// specified instruction. void Instruction::insertAfter(Instruction *InsertPos) { - InsertPos->getParent()->getInstList().insertAfter(InsertPos->getIterator(), - this); + insertAt(InsertPos->getParent(), std::next(InsertPos->getIterator())); } BasicBlock::iterator Instruction::insertAt(BasicBlock *BB, diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -824,7 +824,7 @@ MCall = CallInst::Create(MallocFunc, AllocSize, OpB, "malloccall"); Result = MCall; if (Result->getType() != AllocPtrType) { - InsertAtEnd->getInstList().push_back(MCall); + MCall->insertAt(InsertAtEnd, InsertAtEnd->end()); // Create a cast instruction to convert to the right type... Result = new BitCastInst(MCall, AllocPtrType, Name); } @@ -2815,7 +2815,7 @@ const Twine &Name, BasicBlock *InsertAtEnd) { UnaryOperator *Res = Create(Op, S, Name); - InsertAtEnd->getInstList().push_back(Res); + Res->insertAt(InsertAtEnd, InsertAtEnd->end()); return Res; } @@ -2946,7 +2946,7 @@ const Twine &Name, BasicBlock *InsertAtEnd) { BinaryOperator *Res = Create(Op, S1, S2, Name); - InsertAtEnd->getInstList().push_back(Res); + Res->insertAt(InsertAtEnd, InsertAtEnd->end()); return Res; } diff --git a/llvm/lib/Transforms/IPO/IROutliner.cpp b/llvm/lib/Transforms/IPO/IROutliner.cpp --- a/llvm/lib/Transforms/IPO/IROutliner.cpp +++ b/llvm/lib/Transforms/IPO/IROutliner.cpp @@ -1872,7 +1872,7 @@ StoreInst *NewI = cast(I->clone()); NewI->setDebugLoc(DebugLoc()); BasicBlock *OutputBB = VBBIt->second; - OutputBB->getInstList().push_back(NewI); + NewI->insertAt(OutputBB, OutputBB->end()); LLVM_DEBUG(dbgs() << "Move store for instruction " << *I << " to " << *OutputBB << "\n"); diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -388,7 +388,7 @@ assert(New && !New->getParent() && "New instruction already inserted into a basic block!"); BasicBlock *BB = Old.getParent(); - BB->getInstList().insert(Old.getIterator(), New); // Insert inst + New->insertAt(BB, Old.getIterator()); // Insert inst Worklist.add(New); return New; } diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2213,7 +2213,7 @@ if (Instruction *I = visitBitCast(*BCI)) { if (I != BCI) { I->takeName(BCI); - BCI->getParent()->getInstList().insert(BCI->getIterator(), I); + I->insertAt(BCI->getParent(), BCI->getIterator()); replaceInstUsesWith(*BCI, I); } return &GEP; @@ -2419,8 +2419,7 @@ NewGEP->setOperand(DI, NewPN); } - GEP.getParent()->getInstList().insert( - GEP.getParent()->getFirstInsertionPt(), NewGEP); + NewGEP->insertAt(GEP.getParent(), GEP.getParent()->getFirstInsertionPt()); replaceOperand(GEP, 0, NewGEP); PtrOp = NewGEP; } @@ -4333,7 +4332,7 @@ InsertPos = InstParent->getFirstNonPHI()->getIterator(); } - InstParent->getInstList().insert(InsertPos, Result); + Result->insertAt(InstParent, InsertPos); // Push the new instruction and any users onto the worklist. Worklist.pushUsersToWorkList(*Result); diff --git a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp --- a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp +++ b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp @@ -1838,7 +1838,7 @@ BranchInst *NewBR = BranchInst::Create(NewEntryBlock, cast(VMap[NewEntryBlock]), ConstantInt::getTrue(F.getContext())); - PreEntryBlock->getInstList().push_back(NewBR); + NewBR->insertAt(PreEntryBlock, PreEntryBlock->end()); assert(NewEntryBlock->getSinglePredecessor() == EntryBlock && "NewEntryBlock's only pred must be EntryBlock"); return NewBR; diff --git a/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp b/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp --- a/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp @@ -422,7 +422,7 @@ assert(SizeType && "Expected integer type size argument."); ConstantInt *CaseSizeId = ConstantInt::get(SizeType, SizeId); NewMO.setLength(CaseSizeId); - CaseBB->getInstList().push_back(NewMO.I); + NewMO.I->insertAt(CaseBB, CaseBB->end()); IRBuilder<> IRBCase(CaseBB); IRBCase.CreateBr(MergeBB); SI->addCase(CaseSizeId, CaseBB); diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -2108,7 +2108,7 @@ for (; BI != BE; ++BI) { Instruction *New = BI->clone(); New->setName(BI->getName()); - NewBB->getInstList().push_back(New); + New->insertAt(NewBB, NewBB->end()); ValueMapping[&*BI] = New; adaptNoAliasScopes(New, ClonedScopes, Context); @@ -2701,7 +2701,7 @@ if (New) { // Otherwise, insert the new instruction into the block. New->setName(BI->getName()); - PredBB->getInstList().insert(OldPredBranch->getIterator(), New); + New->insertAt(PredBB, OldPredBranch->getIterator()); // Update Dominance from simplified New instruction operands. for (unsigned i = 0, e = New->getNumOperands(); i != e; ++i) if (BasicBlock *SuccBB = dyn_cast(New->getOperand(i))) @@ -2755,7 +2755,7 @@ BB->getParent(), BB); // Move the unconditional branch to NewBB. PredTerm->removeFromParent(); - NewBB->getInstList().insert(NewBB->end(), PredTerm); + PredTerm->insertAt(NewBB, NewBB->end()); // Create a conditional branch and update PHI nodes. auto *BI = BranchInst::Create(NewBB, BB, SI->getCondition(), Pred); BI->applyMergedLocation(PredTerm->getDebugLoc(), SI->getDebugLoc()); diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -1430,7 +1430,7 @@ New = I.clone(); } - ExitBlock.getInstList().insert(ExitBlock.getFirstInsertionPt(), New); + New->insertAt(&ExitBlock, ExitBlock.getFirstInsertionPt()); if (!I.getName().empty()) New->setName(I.getName() + ".le"); diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -2535,7 +2535,7 @@ ICmpInst *OldCond = Cond; Cond = cast(Cond->clone()); Cond->setName(L->getHeader()->getName() + ".termcond"); - ExitingBlock->getInstList().insert(TermBr->getIterator(), Cond); + Cond->insertAt(ExitingBlock, TermBr->getIterator()); // Clone the IVUse, as the old use still exists! CondUse = &IU.AddUser(Cond, CondUse->getOperandValToReplace()); diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp --- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp @@ -254,7 +254,7 @@ for (auto *Val : reverse(ToDuplicate)) { Instruction *Inst = cast(Val); Instruction *NewInst = Inst->clone(); - BB.getInstList().insert(BB.end(), NewInst); + NewInst->insertAt(&BB, BB.end()); RemapInstruction(NewInst, VMap, RF_NoModuleLevelChanges | RF_IgnoreMissingLocals); VMap[Val] = NewInst; @@ -584,7 +584,7 @@ if (MSSAU) { // Temporarily clone the terminator, to make MSSA update cheaper by // separating "insert edge" updates from "remove edge" ones. - ParentBB->getInstList().push_back(BI.clone()); + BI.clone()->insertAt(ParentBB, ParentBB->end()); } else { // Create a new unconditional branch that will continue the loop as a new // terminator. @@ -2254,7 +2254,7 @@ // Keep a clone of the terminator for MSSA updates. Instruction *NewTI = TI.clone(); - ParentBB->getInstList().push_back(NewTI); + NewTI->insertAt(ParentBB, ParentBB->end()); // First wire up the moved terminator to the preheaders. if (BI) { diff --git a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp --- a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp +++ b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp @@ -108,12 +108,12 @@ std::get<1>(I) = PHINode::Create(std::get<0>(I)->getType(), /*NumReservedValues=*/BBs.size(), CanonicalBB->getName() + ".op"); - CanonicalBB->getInstList().push_back(std::get<1>(I)); + std::get<1>(I)->insertAt(CanonicalBB, CanonicalBB->end()); } // Make it so that this canonical block actually has the right // terminator. CanonicalTerm = Term->clone(); - CanonicalBB->getInstList().push_back(CanonicalTerm); + CanonicalTerm->insertAt(CanonicalBB, CanonicalBB->end()); // If the canonical terminator has operands, rewrite it to take PHI's. for (auto I : zip(NewOps, CanonicalTerm->operands())) std::get<1>(I) = std::get<0>(I); diff --git a/llvm/lib/Transforms/Scalar/TLSVariableHoist.cpp b/llvm/lib/Transforms/Scalar/TLSVariableHoist.cpp --- a/llvm/lib/Transforms/Scalar/TLSVariableHoist.cpp +++ b/llvm/lib/Transforms/Scalar/TLSVariableHoist.cpp @@ -234,7 +234,7 @@ BasicBlock::iterator Iter = findInsertPos(Fn, GV, PosBB); Type *Ty = GV->getType(); auto *CastInst = new BitCastInst(GV, Ty, "tls_bitcast"); - PosBB->getInstList().insert(Iter, CastInst); + CastInst->insertAt(PosBB, Iter); return CastInst; } diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp --- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -555,8 +555,8 @@ BI = BIL.erase(BI); } -void llvm::ReplaceInstWithInst(BasicBlock::InstListType &BIL, - BasicBlock::iterator &BI, Instruction *I) { +void llvm::ReplaceInstWithInst(BasicBlock *BB, BasicBlock::iterator &BI, + Instruction *I) { assert(I->getParent() == nullptr && "ReplaceInstWithInst: Instruction already inserted into basic block!"); @@ -566,10 +566,10 @@ I->setDebugLoc(BI->getDebugLoc()); // Insert the new instruction into the basic block... - BasicBlock::iterator New = BIL.insert(BI, I); + BasicBlock::iterator New = I->insertAt(BB, BI); // Replace all uses of the old instruction, and delete it. - ReplaceInstWithValue(BIL, BI, I); + ReplaceInstWithValue(BB->getInstList(), BI, I); // Move BI back to point to the newly inserted instruction BI = New; @@ -591,7 +591,7 @@ void llvm::ReplaceInstWithInst(Instruction *From, Instruction *To) { BasicBlock::iterator BI(From); - ReplaceInstWithInst(From->getParent()->getInstList(), BI, To); + ReplaceInstWithInst(From->getParent(), BI, To); } BasicBlock *llvm::SplitEdge(BasicBlock *BB, BasicBlock *Succ, DominatorTree *DT, @@ -1344,12 +1344,12 @@ LandingPadInst *LPad = OrigBB->getLandingPadInst(); Instruction *Clone1 = LPad->clone(); Clone1->setName(Twine("lpad") + Suffix1); - NewBB1->getInstList().insert(NewBB1->getFirstInsertionPt(), Clone1); + Clone1->insertAt(NewBB1, NewBB1->getFirstInsertionPt()); if (NewBB2) { Instruction *Clone2 = LPad->clone(); Clone2->setName(Twine("lpad") + Suffix2); - NewBB2->getInstList().insert(NewBB2->getFirstInsertionPt(), Clone2); + Clone2->insertAt(NewBB2, NewBB2->getFirstInsertionPt()); // Create a PHI node for the two cloned landingpad instructions only // if the original landingpad instruction has some uses. @@ -1400,7 +1400,7 @@ Instruction *UncondBranch = Pred->getTerminator(); // Clone the return and add it to the end of the predecessor. Instruction *NewRet = RI->clone(); - Pred->getInstList().push_back(NewRet); + NewRet->insertAt(Pred, Pred->end()); // If the return instruction returns a value, and if the value was a // PHI node in "BB", propagate the right value into the return. @@ -1412,7 +1412,7 @@ // return instruction. V = BCI->getOperand(0); NewBC = BCI->clone(); - Pred->getInstList().insert(NewRet->getIterator(), NewBC); + NewBC->insertAt(Pred, NewRet->getIterator()); Op = NewBC; } @@ -1422,9 +1422,9 @@ NewEV = EVI->clone(); if (NewBC) { NewBC->setOperand(0, NewEV); - Pred->getInstList().insert(NewBC->getIterator(), NewEV); + NewEV->insertAt(Pred, NewBC->getIterator()); } else { - Pred->getInstList().insert(NewRet->getIterator(), NewEV); + NewEV->insertAt(Pred, NewRet->getIterator()); Op = NewEV; } } diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp --- a/llvm/lib/Transforms/Utils/CloneFunction.cpp +++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp @@ -58,7 +58,7 @@ Instruction *NewInst = I.clone(); if (I.hasName()) NewInst->setName(I.getName() + NameSuffix); - NewBB->getInstList().push_back(NewInst); + NewInst->insertAt(NewBB, NewBB->end()); VMap[&I] = NewInst; // Add instruction map to value. if (isa(I) && !I.isDebugOrPseudoInst()) { @@ -521,7 +521,7 @@ if (II->hasName()) NewInst->setName(II->getName() + NameSuffix); VMap[&*II] = NewInst; // Add instruction map to value. - NewBB->getInstList().push_back(NewInst); + NewInst->insertAt(NewBB, NewBB->end()); if (isa(II) && !II->isDebugOrPseudoInst()) { hasCalls = true; hasMemProfMetadata |= II->hasMetadata(LLVMContext::MD_memprof); @@ -583,7 +583,7 @@ Instruction *NewInst = OldTI->clone(); if (OldTI->hasName()) NewInst->setName(OldTI->getName() + NameSuffix); - NewBB->getInstList().push_back(NewInst); + NewInst->insertAt(NewBB, NewBB->end()); VMap[OldTI] = NewInst; // Add instruction map to value. if (CodeInfo) { diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp --- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -1208,7 +1208,7 @@ Idx[1] = ConstantInt::get(Type::getInt32Ty(Context), i); GetElementPtrInst *GEP = GetElementPtrInst::Create( StructArgTy, Struct, Idx, "gep_" + StructValues[i]->getName()); - codeReplacer->getInstList().push_back(GEP); + GEP->insertAt(codeReplacer, codeReplacer->end()); new StoreInst(StructValues[i], GEP, codeReplacer); NumAggregatedInputs++; } @@ -1226,7 +1226,7 @@ if (auto DL = newFunction->getEntryBlock().getTerminator()->getDebugLoc()) call->setDebugLoc(DL); } - codeReplacer->getInstList().push_back(call); + call->insertAt(codeReplacer, codeReplacer->end()); // Set swifterror parameter attributes. for (unsigned SwiftErrArgNo : SwiftErrorArgs) { @@ -1246,7 +1246,7 @@ Idx[1] = ConstantInt::get(Type::getInt32Ty(Context), aggIdx); GetElementPtrInst *GEP = GetElementPtrInst::Create( StructArgTy, Struct, Idx, "gep_reload_" + outputs[i]->getName()); - codeReplacer->getInstList().push_back(GEP); + GEP->insertAt(codeReplacer, codeReplacer->end()); Output = GEP; ++aggIdx; } else { @@ -1739,7 +1739,7 @@ }); }); } - newFuncRoot->getInstList().push_back(BranchI); + BranchI->insertAt(newFuncRoot, newFuncRoot->end()); ValueSet SinkingCands, HoistingCands; BasicBlock *CommonExit = nullptr; diff --git a/llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp b/llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp --- a/llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp +++ b/llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp @@ -496,7 +496,7 @@ assert(SuccBB && "The split block should have a single successor"); SuccBB->setName("cdce.end"); CI->removeFromParent(); - CallBB->getInstList().insert(CallBB->getFirstInsertionPt(), CI); + CI->insertAt(CallBB, CallBB->getFirstInsertionPt()); LLVM_DEBUG(dbgs() << "== Basic Block After =="); LLVM_DEBUG(dbgs() << *CallBB->getSinglePredecessor() << *CallBB << *CallBB->getSingleSuccessor() << "\n"); diff --git a/llvm/lib/Transforms/Utils/LowerSwitch.cpp b/llvm/lib/Transforms/Utils/LowerSwitch.cpp --- a/llvm/lib/Transforms/Utils/LowerSwitch.cpp +++ b/llvm/lib/Transforms/Utils/LowerSwitch.cpp @@ -301,7 +301,7 @@ NewNode, OrigBlock, Default, UnreachableRanges); F->getBasicBlockList().insert(++OrigBlock->getIterator(), NewNode); - NewNode->getInstList().push_back(Comp); + Comp->insertAt(NewNode, NewNode->end()); BranchInst::Create(LBranch, RBranch, Comp, NewNode); return NewNode; diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1129,7 +1129,7 @@ NewBonusInst->dropUndefImplyingAttrsAndUnknownMetadata( LLVMContext::MD_annotation); - PredBlock->getInstList().insert(PTI->getIterator(), NewBonusInst); + NewBonusInst->insertAt(PredBlock, PTI->getIterator()); NewBonusInst->takeName(&BonusInst); BonusInst.setName(NewBonusInst->getName() + ".old"); @@ -1694,7 +1694,7 @@ // Okay, it is safe to hoist the terminator. Instruction *NT = I1->clone(); - BIParent->getInstList().insert(BI->getIterator(), NT); + NT->insertAt(BIParent, BI->getIterator()); if (!NT->getType()->isVoidTy()) { I1->replaceAllUsesWith(NT); I2->replaceAllUsesWith(NT); @@ -2498,7 +2498,7 @@ auto *MergedInvoke = cast(II0->clone()); // NOTE: all invokes have the same attributes, so no handling needed. - MergedInvokeBB->getInstList().push_back(MergedInvoke); + MergedInvoke->insertAt(MergedInvokeBB, MergedInvokeBB->end()); if (!HasNormalDest) { // This set does not have a normal destination, @@ -3245,7 +3245,7 @@ } if (N) { // Insert the new instruction into its new home. - EdgeBB->getInstList().insert(InsertPt, N); + N->insertAt(EdgeBB, InsertPt); // Register the new instruction with the assumption cache if necessary. if (auto *Assume = dyn_cast(N)) diff --git a/llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp b/llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp --- a/llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp +++ b/llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp @@ -90,7 +90,7 @@ // If the function doesn't return void... add a PHI node to the block... PN = PHINode::Create(F.getReturnType(), ReturningBlocks.size(), "UnifiedRetVal"); - NewRetBlock->getInstList().push_back(PN); + PN->insertAt(NewRetBlock, NewRetBlock->end()); ReturnInst::Create(F.getContext(), PN, NewRetBlock); } diff --git a/llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp b/llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp --- a/llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp +++ b/llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp @@ -429,7 +429,7 @@ BasicBlock *BB = BasicBlock::Create(C); BB->insertInto(F); Instruction *Ret = ReturnInst::Create(C); - BB->getInstList().insert(BB->begin(), Ret); + Ret->insertAt(BB, BB->begin()); Function *FnAssume = Intrinsic::getDeclaration(Mod.get(), Intrinsic::assume); std::vector ShuffledArgs; diff --git a/llvm/unittests/Analysis/MemorySSATest.cpp b/llvm/unittests/Analysis/MemorySSATest.cpp --- a/llvm/unittests/Analysis/MemorySSATest.cpp +++ b/llvm/unittests/Analysis/MemorySSATest.cpp @@ -282,7 +282,7 @@ // - remove from original block LoadInst *LoadInstClone = cast(LoadInst1->clone()); - Merge->getInstList().insert(Merge->begin(), LoadInstClone); + LoadInstClone->insertAt(Merge, Merge->begin()); MemoryAccess * NewLoadAccess = Updater.createMemoryAccessInBB(LoadInstClone, nullptr, LoadInstClone->getParent(), diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp --- a/llvm/unittests/Analysis/ValueTrackingTest.cpp +++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp @@ -1624,7 +1624,7 @@ EXPECT_EQ(Known.Zero.getZExtValue(), 0u); BasicBlock *BB = BasicBlock::Create(Context); - BB->getInstList().push_back(CI); + CI->insertAt(BB, BB->end()); Known = computeKnownBits(CI, M.getDataLayout(), /* Depth */ 0); // There is no parent function so we cannot look up the vscale_range // attribute to determine the number of bits.