From 06911ba6ea1e552d3bcaed2728c92a9aa6cbf4d2 Mon Sep 17 00:00:00 2001 From: Vasileios Porpodas Date: Mon, 28 Nov 2022 14:43:11 -0800 Subject: [PATCH] [NFC] Cleanup: Replaces BB->getInstList().insert() with I->insertAt(). This is part of a series of cleanup patches towards making BasicBlock::getInstList() private. Differential Revision: https://reviews.llvm.org/D138877 --- clang/lib/CodeGen/CGCleanup.cpp | 2 +- llvm/include/llvm/IR/IRBuilder.h | 3 ++- .../llvm/Transforms/InstCombine/InstCombiner.h | 2 +- .../llvm/Transforms/Utils/BasicBlockUtils.h | 4 ++-- llvm/lib/AsmParser/LLParser.cpp | 4 ++-- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 6 +++--- llvm/lib/CodeGen/WinEHPrepare.cpp | 4 ++-- llvm/lib/IR/Instruction.cpp | 9 ++++----- llvm/lib/IR/Instructions.cpp | 6 +++--- llvm/lib/Transforms/IPO/IROutliner.cpp | 2 +- .../Transforms/InstCombine/InstCombineInternal.h | 2 +- .../InstCombine/InstructionCombining.cpp | 7 +++---- .../Instrumentation/ControlHeightReduction.cpp | 2 +- .../Transforms/Instrumentation/PGOMemOPSizeOpt.cpp | 2 +- llvm/lib/Transforms/Scalar/JumpThreading.cpp | 6 +++--- llvm/lib/Transforms/Scalar/LICM.cpp | 2 +- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp | 2 +- llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp | 6 +++--- llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp | 4 ++-- llvm/lib/Transforms/Scalar/TLSVariableHoist.cpp | 2 +- llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | 22 +++++++++++----------- llvm/lib/Transforms/Utils/CloneFunction.cpp | 6 +++--- llvm/lib/Transforms/Utils/CodeExtractor.cpp | 8 ++++---- llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp | 2 +- llvm/lib/Transforms/Utils/LowerSwitch.cpp | 2 +- llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 8 ++++---- .../Transforms/Utils/UnifyFunctionExitNodes.cpp | 2 +- .../unittests/Analysis/AssumeBundleQueriesTest.cpp | 2 +- llvm/unittests/Analysis/MemorySSATest.cpp | 2 +- llvm/unittests/Analysis/ValueTrackingTest.cpp | 2 +- 30 files changed, 66 insertions(+), 67 deletions(-) diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp index a1ba1a9..94e25ae 100644 --- a/clang/lib/CodeGen/CGCleanup.cpp +++ b/clang/lib/CodeGen/CGCleanup.cpp @@ -942,7 +942,7 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) { // 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 index 592d608..6da83e9 100644 --- a/llvm/include/llvm/IR/IRBuilder.h +++ b/llvm/include/llvm/IR/IRBuilder.h @@ -65,7 +65,8 @@ public: 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 index 54d2210..81b982a 100644 --- a/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h +++ b/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h @@ -397,7 +397,7 @@ public: 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 index 3b2fe81..0464474 100644 --- a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h +++ b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h @@ -121,8 +121,8 @@ void ReplaceInstWithValue(BasicBlock::InstListType &BIL, /// 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 index a5f996b0..f8a858f 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -6166,7 +6166,7 @@ bool LLParser::parseBasicBlock(PerFunctionState &PFS) { 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 @@ bool LLParser::parseBasicBlock(PerFunctionState &PFS) { 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 index efc8b22..47b2972 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -4840,7 +4840,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) { 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 @@ Error BitcodeReader::parseFunctionBody(Function *F) { // 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 @@ Error BitcodeReader::parseFunctionBody(Function *F) { 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 index 8f5d9e9..15d97d3 100644 --- a/llvm/lib/CodeGen/WinEHPrepare.cpp +++ b/llvm/lib/CodeGen/WinEHPrepare.cpp @@ -1212,8 +1212,8 @@ void WinEHPrepare::replaceUseWithLoad(Value *V, Use &U, AllocaInst *&SpillSlot, 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 index bd89b3e..fa91c93 100644 --- a/llvm/lib/IR/Instruction.cpp +++ b/llvm/lib/IR/Instruction.cpp @@ -28,7 +28,7 @@ Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps, 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 @@ Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps, // 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 @@ iplist::iterator Instruction::eraseFromParent() { /// 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 index e266da5..4ca1323 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -824,7 +824,7 @@ static Instruction *createMalloc(Instruction *InsertBefore, 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 @@ UnaryOperator *UnaryOperator::Create(UnaryOps Op, Value *S, 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 @@ BinaryOperator *BinaryOperator::Create(BinaryOps Op, Value *S1, Value *S2, 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 index 16d0dc3..e79fe05 100644 --- a/llvm/lib/Transforms/IPO/IROutliner.cpp +++ b/llvm/lib/Transforms/IPO/IROutliner.cpp @@ -1872,7 +1872,7 @@ replaceArgumentUses(OutlinableRegion &Region, 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 index cc1dedf..c7efe27 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -388,7 +388,7 @@ public: 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 index 78c7453..8a8e6e6 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2213,7 +2213,7 @@ Instruction *InstCombinerImpl::visitGEPOfBitcast(BitCastInst *BCI, 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 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) { 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 @@ bool InstCombinerImpl::run() { 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 index 451a0f3..068565a 100644 --- a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp +++ b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp @@ -1838,7 +1838,7 @@ BranchInst *CHR::createMergedBranch(BasicBlock *PreEntryBlock, 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 index 267446b..5fa1d68 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp @@ -422,7 +422,7 @@ bool MemOPSizeOpt::perform(MemOp MO) { 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 index 75bc4bb..4ada263 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -2108,7 +2108,7 @@ JumpThreadingPass::cloneInstructions(BasicBlock::iterator BI, 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 @@ bool JumpThreadingPass::duplicateCondBranchOnPHIIntoPred( 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 @@ void JumpThreadingPass::unfoldSelectInstr(BasicBlock *Pred, BasicBlock *BB, 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 index 8a359f8..19b2de6 100644 --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -1430,7 +1430,7 @@ static Instruction *cloneInstructionInExitBlock( 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 index 3d80613..34dce23 100644 --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -2535,7 +2535,7 @@ LSRInstance::OptimizeLoopTermCond() { 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 index e3b3d5e..25c95d2 100644 --- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp @@ -254,7 +254,7 @@ static void buildPartialInvariantUnswitchConditionalBranch( 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 @@ static bool unswitchTrivialBranch(Loop &L, BranchInst &BI, DominatorTree &DT, 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 @@ static void unswitchNontrivialInvariants( // 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 index fb2d812..7622704 100644 --- a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp +++ b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp @@ -108,12 +108,12 @@ performBlockTailMerging(Function &F, ArrayRef BBs, 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 index 16b3483..3124714 100644 --- a/llvm/lib/Transforms/Scalar/TLSVariableHoist.cpp +++ b/llvm/lib/Transforms/Scalar/TLSVariableHoist.cpp @@ -234,7 +234,7 @@ Instruction *TLSVariableHoistPass::genBitCastInst(Function &Fn, 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 index 871d742..2ee3dbd 100644 --- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -555,8 +555,8 @@ void llvm::ReplaceInstWithValue(BasicBlock::InstListType &BIL, 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 @@ void llvm::ReplaceInstWithInst(BasicBlock::InstListType &BIL, 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 @@ bool llvm::IsBlockFollowedByDeoptOrUnreachable(const BasicBlock *BB) { 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 @@ static void SplitLandingPadPredecessorsImpl( 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 @@ ReturnInst *llvm::FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB, 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 @@ ReturnInst *llvm::FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB, // 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 @@ ReturnInst *llvm::FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB, 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 index f660eed..22807ec 100644 --- a/llvm/lib/Transforms/Utils/CloneFunction.cpp +++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp @@ -58,7 +58,7 @@ BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap, 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 @@ void PruningFunctionCloner::CloneBlock( 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 @@ void PruningFunctionCloner::CloneBlock( 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 index 3aa16eb..5c7b469 100644 --- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -1208,7 +1208,7 @@ CallInst *CodeExtractor::emitCallAndSwitchStatement(Function *newFunction, 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 @@ CallInst *CodeExtractor::emitCallAndSwitchStatement(Function *newFunction, 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 @@ CallInst *CodeExtractor::emitCallAndSwitchStatement(Function *newFunction, 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 @@ CodeExtractor::extractCodeRegion(const CodeExtractorAnalysisCache &CEAC, }); }); } - 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 index aab5206..f0f6f94 100644 --- a/llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp +++ b/llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp @@ -496,7 +496,7 @@ void LibCallsShrinkWrap::shrinkWrapCI(CallInst *CI, Value *Cond) { 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 index a0019d0..4a884af 100644 --- a/llvm/lib/Transforms/Utils/LowerSwitch.cpp +++ b/llvm/lib/Transforms/Utils/LowerSwitch.cpp @@ -301,7 +301,7 @@ BasicBlock *SwitchConvert(CaseItr Begin, CaseItr End, ConstantInt *LowerBound, 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 index 57954bc..7277c73 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1129,7 +1129,7 @@ static void CloneInstructionsIntoPredecessorBlockAndUpdateSSAUses( 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 @@ HoistTerminator: // 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 @@ static void MergeCompatibleInvokesImpl(ArrayRef Invokes, 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 @@ FoldCondBranchOnValueKnownInPredecessorImpl(BranchInst *BI, DomTreeUpdater *DTU, } 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 index 596056b..d73a511 100644 --- a/llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp +++ b/llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp @@ -90,7 +90,7 @@ bool unifyReturnBlocks(Function &F) { // 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 index 87cf0c7..7534418 100644 --- a/llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp +++ b/llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp @@ -429,7 +429,7 @@ static void RunRandTest(uint64_t Seed, int Size, int MinCount, int MaxCount, 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 index c500df5..f5d8b57 100644 --- a/llvm/unittests/Analysis/MemorySSATest.cpp +++ b/llvm/unittests/Analysis/MemorySSATest.cpp @@ -282,7 +282,7 @@ TEST_F(MemorySSATest, SinkLoad) { // - 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 index 9bf9259..2e5270e 100644 --- a/llvm/unittests/Analysis/ValueTrackingTest.cpp +++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp @@ -1624,7 +1624,7 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownBitsUnknownVScale) { 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. -- 2.7.4