diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -574,9 +574,9 @@ // Place the block after the current block, if possible, or else at // the end of the function. if (CurBB && CurBB->getParent()) - CurFn->insertBasicBlockAt(std::next(CurBB->getIterator()), BB); + CurFn->insert(std::next(CurBB->getIterator()), BB); else - CurFn->insertBasicBlockAt(CurFn->end(), BB); + CurFn->insert(CurFn->end(), BB); Builder.SetInsertPoint(BB); } @@ -601,15 +601,14 @@ bool inserted = false; for (llvm::User *u : block->users()) { if (llvm::Instruction *insn = dyn_cast(u)) { - CurFn->insertBasicBlockAt(std::next(insn->getParent()->getIterator()), - block); + CurFn->insert(std::next(insn->getParent()->getIterator()), block); inserted = true; break; } } if (!inserted) - CurFn->insertBasicBlockAt(CurFn->end(), block); + CurFn->insert(CurFn->end(), block); Builder.SetInsertPoint(block); } @@ -1469,7 +1468,7 @@ llvm::BasicBlock *FalseDest = CaseRangeBlock; CaseRangeBlock = createBasicBlock("sw.caserange"); - CurFn->insertBasicBlockAt(CurFn->end(), CaseRangeBlock); + CurFn->insert(CurFn->end(), CaseRangeBlock); Builder.SetInsertPoint(CaseRangeBlock); // Emit range check. diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -320,7 +320,7 @@ static void EmitIfUsed(CodeGenFunction &CGF, llvm::BasicBlock *BB) { if (!BB) return; if (!BB->use_empty()) { - CGF.CurFn->insertBasicBlockAt(CGF.CurFn->end(), BB); + CGF.CurFn->insert(CGF.CurFn->end(), BB); return; } delete BB; diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp --- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp +++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp @@ -863,7 +863,7 @@ ThenBB = Builder->GetInsertBlock(); // Emit else block. - TheFunction->insertBasicBlockAt(TheFunction->end(), ElseBB); + TheFunction->insert(TheFunction->end(), ElseBB); Builder->SetInsertPoint(ElseBB); Value *ElseV = Else->codegen(); @@ -875,7 +875,7 @@ ElseBB = Builder->GetInsertBlock(); // Emit merge block. - TheFunction->insertBasicBlockAt(TheFunction->end(), MergeBB); + TheFunction->insert(TheFunction->end(), MergeBB); Builder->SetInsertPoint(MergeBB); PHINode *PN = Builder->CreatePHI(Type::getDoubleTy(*TheContext), 2, "iftmp"); diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp --- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp +++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp @@ -863,7 +863,7 @@ ThenBB = Builder->GetInsertBlock(); // Emit else block. - TheFunction->insertBasicBlockAt(TheFunction->end(), ElseBB); + TheFunction->insert(TheFunction->end(), ElseBB); Builder->SetInsertPoint(ElseBB); Value *ElseV = Else->codegen(); @@ -875,7 +875,7 @@ ElseBB = Builder->GetInsertBlock(); // Emit merge block. - TheFunction->insertBasicBlockAt(TheFunction->end(), MergeBB); + TheFunction->insert(TheFunction->end(), MergeBB); Builder->SetInsertPoint(MergeBB); PHINode *PN = Builder->CreatePHI(Type::getDoubleTy(*TheContext), 2, "iftmp"); diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp --- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp +++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp @@ -863,7 +863,7 @@ ThenBB = Builder->GetInsertBlock(); // Emit else block. - TheFunction->insertBasicBlockAt(TheFunction->end(), ElseBB); + TheFunction->insert(TheFunction->end(), ElseBB); Builder->SetInsertPoint(ElseBB); Value *ElseV = Else->codegen(); @@ -875,7 +875,7 @@ ElseBB = Builder->GetInsertBlock(); // Emit merge block. - TheFunction->insertBasicBlockAt(TheFunction->end(), MergeBB); + TheFunction->insert(TheFunction->end(), MergeBB); Builder->SetInsertPoint(MergeBB); PHINode *PN = Builder->CreatePHI(Type::getDoubleTy(*TheContext), 2, "iftmp"); diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp --- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp +++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp @@ -846,7 +846,7 @@ ThenBB = Builder->GetInsertBlock(); // Emit else block. - TheFunction->insertBasicBlockAt(TheFunction->end(), ElseBB); + TheFunction->insert(TheFunction->end(), ElseBB); Builder->SetInsertPoint(ElseBB); Value *ElseV = Else->codegen(); @@ -858,7 +858,7 @@ ElseBB = Builder->GetInsertBlock(); // Emit merge block. - TheFunction->insertBasicBlockAt(TheFunction->end(), MergeBB); + TheFunction->insert(TheFunction->end(), MergeBB); Builder->SetInsertPoint(MergeBB); PHINode *PN = Builder->CreatePHI(Type::getDoubleTy(*TheContext), 2, "iftmp"); diff --git a/llvm/examples/Kaleidoscope/Chapter5/toy.cpp b/llvm/examples/Kaleidoscope/Chapter5/toy.cpp --- a/llvm/examples/Kaleidoscope/Chapter5/toy.cpp +++ b/llvm/examples/Kaleidoscope/Chapter5/toy.cpp @@ -650,7 +650,7 @@ ThenBB = Builder->GetInsertBlock(); // Emit else block. - TheFunction->insertBasicBlockAt(TheFunction->end(), ElseBB); + TheFunction->insert(TheFunction->end(), ElseBB); Builder->SetInsertPoint(ElseBB); Value *ElseV = Else->codegen(); @@ -662,7 +662,7 @@ ElseBB = Builder->GetInsertBlock(); // Emit merge block. - TheFunction->insertBasicBlockAt(TheFunction->end(), MergeBB); + TheFunction->insert(TheFunction->end(), MergeBB); Builder->SetInsertPoint(MergeBB); PHINode *PN = Builder->CreatePHI(Type::getDoubleTy(*TheContext), 2, "iftmp"); diff --git a/llvm/examples/Kaleidoscope/Chapter6/toy.cpp b/llvm/examples/Kaleidoscope/Chapter6/toy.cpp --- a/llvm/examples/Kaleidoscope/Chapter6/toy.cpp +++ b/llvm/examples/Kaleidoscope/Chapter6/toy.cpp @@ -762,7 +762,7 @@ ThenBB = Builder->GetInsertBlock(); // Emit else block. - TheFunction->insertBasicBlockAt(TheFunction->end(), ElseBB); + TheFunction->insert(TheFunction->end(), ElseBB); Builder->SetInsertPoint(ElseBB); Value *ElseV = Else->codegen(); @@ -774,7 +774,7 @@ ElseBB = Builder->GetInsertBlock(); // Emit merge block. - TheFunction->insertBasicBlockAt(TheFunction->end(), MergeBB); + TheFunction->insert(TheFunction->end(), MergeBB); Builder->SetInsertPoint(MergeBB); PHINode *PN = Builder->CreatePHI(Type::getDoubleTy(*TheContext), 2, "iftmp"); diff --git a/llvm/examples/Kaleidoscope/Chapter7/toy.cpp b/llvm/examples/Kaleidoscope/Chapter7/toy.cpp --- a/llvm/examples/Kaleidoscope/Chapter7/toy.cpp +++ b/llvm/examples/Kaleidoscope/Chapter7/toy.cpp @@ -869,7 +869,7 @@ ThenBB = Builder->GetInsertBlock(); // Emit else block. - TheFunction->insertBasicBlockAt(TheFunction->end(), ElseBB); + TheFunction->insert(TheFunction->end(), ElseBB); Builder->SetInsertPoint(ElseBB); Value *ElseV = Else->codegen(); @@ -881,7 +881,7 @@ ElseBB = Builder->GetInsertBlock(); // Emit merge block. - TheFunction->insertBasicBlockAt(TheFunction->end(), MergeBB); + TheFunction->insert(TheFunction->end(), MergeBB); Builder->SetInsertPoint(MergeBB); PHINode *PN = Builder->CreatePHI(Type::getDoubleTy(*TheContext), 2, "iftmp"); diff --git a/llvm/examples/Kaleidoscope/Chapter8/toy.cpp b/llvm/examples/Kaleidoscope/Chapter8/toy.cpp --- a/llvm/examples/Kaleidoscope/Chapter8/toy.cpp +++ b/llvm/examples/Kaleidoscope/Chapter8/toy.cpp @@ -867,7 +867,7 @@ ThenBB = Builder->GetInsertBlock(); // Emit else block. - TheFunction->insertBasicBlockAt(TheFunction->end(), ElseBB); + TheFunction->insert(TheFunction->end(), ElseBB); Builder->SetInsertPoint(ElseBB); Value *ElseV = Else->codegen(); @@ -879,7 +879,7 @@ ElseBB = Builder->GetInsertBlock(); // Emit merge block. - TheFunction->insertBasicBlockAt(TheFunction->end(), MergeBB); + TheFunction->insert(TheFunction->end(), MergeBB); Builder->SetInsertPoint(MergeBB); PHINode *PN = Builder->CreatePHI(Type::getDoubleTy(*TheContext), 2, "iftmp"); diff --git a/llvm/examples/Kaleidoscope/Chapter9/toy.cpp b/llvm/examples/Kaleidoscope/Chapter9/toy.cpp --- a/llvm/examples/Kaleidoscope/Chapter9/toy.cpp +++ b/llvm/examples/Kaleidoscope/Chapter9/toy.cpp @@ -1037,7 +1037,7 @@ ThenBB = Builder->GetInsertBlock(); // Emit else block. - TheFunction->insertBasicBlockAt(TheFunction->end(), ElseBB); + TheFunction->insert(TheFunction->end(), ElseBB); Builder->SetInsertPoint(ElseBB); Value *ElseV = Else->codegen(); @@ -1049,7 +1049,7 @@ ElseBB = Builder->GetInsertBlock(); // Emit merge block. - TheFunction->insertBasicBlockAt(TheFunction->end(), MergeBB); + TheFunction->insert(TheFunction->end(), MergeBB); Builder->SetInsertPoint(MergeBB); PHINode *PN = Builder->CreatePHI(Type::getDoubleTy(*TheContext), 2, "iftmp"); diff --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h --- a/llvm/include/llvm/IR/Function.h +++ b/llvm/include/llvm/IR/Function.h @@ -689,7 +689,7 @@ /// Insert \p BB in the basic block list at \p Position. \Returns an iterator /// to the newly inserted BB. - Function::iterator insertBasicBlockAt(Function::iterator Position, BasicBlock *BB) { + Function::iterator insert(Function::iterator Position, BasicBlock *BB) { return BasicBlocks.insert(Position, BB); } @@ -722,6 +722,9 @@ /// Get the underlying elements of the Function... the basic block list is /// empty for external functions. /// + /// This is deliberately private because we have implemented an adequate set + /// of functions to modify the list, including Function::splice(), + /// Function::erase(), Function::insert() etc. const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; } BasicBlockListType &getBasicBlockList() { return BasicBlocks; } diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp --- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp +++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp @@ -3617,7 +3617,7 @@ // Emit thenBB and set the Builder's insertion point there for // body generation next. Place the block after the current block. Function *CurFn = EntryBB->getParent(); - CurFn->insertBasicBlockAt(std::next(EntryBB->getIterator()), ThenBB); + CurFn->insert(std::next(EntryBB->getIterator()), ThenBB); // Move Entry branch to end of ThenBB, and replace with conditional // branch (If-stmt) diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp --- a/llvm/lib/IR/BasicBlock.cpp +++ b/llvm/lib/IR/BasicBlock.cpp @@ -62,9 +62,9 @@ assert(!Parent && "Already has a parent"); if (InsertBefore) - NewParent->insertBasicBlockAt(InsertBefore->getIterator(), this); + NewParent->insert(InsertBefore->getIterator(), this); else - NewParent->insertBasicBlockAt(NewParent->end(), this); + NewParent->insert(NewParent->end(), this); } BasicBlock::~BasicBlock() { diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -2655,14 +2655,12 @@ BasicBlock *ToInsert = unwrap(BB); BasicBlock *CurBB = unwrap(Builder)->GetInsertBlock(); assert(CurBB && "current insertion point is invalid!"); - CurBB->getParent()->insertBasicBlockAt(std::next(CurBB->getIterator()), - ToInsert); + CurBB->getParent()->insert(std::next(CurBB->getIterator()), ToInsert); } void LLVMAppendExistingBasicBlock(LLVMValueRef Fn, LLVMBasicBlockRef BB) { - unwrap(Fn)->insertBasicBlockAt(unwrap(Fn)->end(), - unwrap(BB)); + unwrap(Fn)->insert(unwrap(Fn)->end(), unwrap(BB)); } LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C, diff --git a/llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp b/llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp --- a/llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp +++ b/llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp @@ -179,7 +179,7 @@ // Insert the block into the function... right after the block TI lives in. Function &F = *TIBB->getParent(); Function::iterator FBBI = TIBB->getIterator(); - F.insertBasicBlockAt(++FBBI, NewBB); + F.insert(++FBBI, NewBB); // Branch to the new block, breaking the edge. TI->setSuccessor(SuccNum, NewBB); 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 @@ -670,7 +670,7 @@ continue; // Dead block. // Add the new block to the new function. - NewFunc->insertBasicBlockAt(NewFunc->end(), NewBB); + NewFunc->insert(NewFunc->end(), NewBB); // Handle PHI nodes specially, as we have to remove references to dead // blocks. 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 @@ -999,7 +999,7 @@ newFunction->addFnAttr(Attr); } - newFunction->insertBasicBlockAt(newFunction->end(), newRootNode); + newFunction->insert(newFunction->end(), newRootNode); // Create scalar and aggregate iterators to name all of the arguments we // inserted. @@ -1445,7 +1445,7 @@ // for the new function. The entry block may be followed // by a set of exit blocks at this point, but these exit // blocks better be placed at the end of the new function. - newFuncIt = newFunction->insertBasicBlockAt(std::next(newFuncIt), Block); + newFuncIt = newFunction->insert(std::next(newFuncIt), Block); } } diff --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp --- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp @@ -539,7 +539,7 @@ for (LoopBlocksDFS::RPOIterator BB = BlockBegin; BB != BlockEnd; ++BB) { ValueToValueMapTy VMap; BasicBlock *New = CloneBasicBlock(*BB, VMap, "." + Twine(It)); - Header->getParent()->insertBasicBlockAt(BlockInsertPt, New); + Header->getParent()->insert(BlockInsertPt, New); assert((*BB != Header || LI->getLoopFor(*BB) == L) && "Header should not be in a sub-loop"); diff --git a/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp b/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp --- a/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp @@ -374,7 +374,7 @@ for (LoopBlocksDFS::RPOIterator BB = BlockBegin; BB != BlockEnd; ++BB) { ValueToValueMapTy VMap; BasicBlock *New = CloneBasicBlock(*BB, VMap, "." + Twine(It)); - Header->getParent()->insertBasicBlockAt(Header->getParent()->end(), New); + Header->getParent()->insert(Header->getParent()->end(), New); // Tell LI about New. addClonedBlockToLoopInfo(*BB, New, LI, NewLoops); 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 @@ -160,7 +160,7 @@ BasicBlock *Default) { Function *F = OrigBlock->getParent(); BasicBlock *NewLeaf = BasicBlock::Create(Val->getContext(), "LeafBlock"); - F->insertBasicBlockAt(++OrigBlock->getIterator(), NewLeaf); + F->insert(++OrigBlock->getIterator(), NewLeaf); // Emit comparison ICmpInst *Comp = nullptr; @@ -300,7 +300,7 @@ SwitchConvert(RHS.begin(), RHS.end(), NewLowerBound, UpperBound, Val, NewNode, OrigBlock, Default, UnreachableRanges); - F->insertBasicBlockAt(++OrigBlock->getIterator(), NewNode); + F->insert(++OrigBlock->getIterator(), NewNode); Comp->insertAt(NewNode, NewNode->end()); BranchInst::Create(LBranch, RBranch, Comp, NewNode); diff --git a/llvm/unittests/IR/FunctionTest.cpp b/llvm/unittests/IR/FunctionTest.cpp --- a/llvm/unittests/IR/FunctionTest.cpp +++ b/llvm/unittests/IR/FunctionTest.cpp @@ -206,34 +206,34 @@ // Insert foo_bb0 into bar() at the very top. FooBB0->removeFromParent(); - auto It = BarF->insertBasicBlockAt(BarF->begin(), FooBB0); + auto It = BarF->insert(BarF->begin(), FooBB0); EXPECT_EQ(BarBB0->getPrevNode(), FooBB0); EXPECT_EQ(It, FooBB0->getIterator()); // Insert foo_bb0 into bar() at the very end. FooBB0->removeFromParent(); - It = BarF->insertBasicBlockAt(BarF->end(), FooBB0); + It = BarF->insert(BarF->end(), FooBB0); EXPECT_EQ(FooBB0->getPrevNode(), BarBB2); EXPECT_EQ(FooBB0->getNextNode(), nullptr); EXPECT_EQ(It, FooBB0->getIterator()); // Insert foo_bb0 into bar() just before bar_bb0. FooBB0->removeFromParent(); - It = BarF->insertBasicBlockAt(BarBB0->getIterator(), FooBB0); + It = BarF->insert(BarBB0->getIterator(), FooBB0); EXPECT_EQ(FooBB0->getPrevNode(), nullptr); EXPECT_EQ(FooBB0->getNextNode(), BarBB0); EXPECT_EQ(It, FooBB0->getIterator()); // Insert foo_bb0 into bar() just before bar_bb1. FooBB0->removeFromParent(); - It = BarF->insertBasicBlockAt(BarBB1->getIterator(), FooBB0); + It = BarF->insert(BarBB1->getIterator(), FooBB0); EXPECT_EQ(FooBB0->getPrevNode(), BarBB0); EXPECT_EQ(FooBB0->getNextNode(), BarBB1); EXPECT_EQ(It, FooBB0->getIterator()); // Insert foo_bb0 into bar() just before bar_bb2. FooBB0->removeFromParent(); - It = BarF->insertBasicBlockAt(BarBB2->getIterator(), FooBB0); + It = BarF->insert(BarBB2->getIterator(), FooBB0); EXPECT_EQ(FooBB0->getPrevNode(), BarBB1); EXPECT_EQ(FooBB0->getNextNode(), BarBB2); EXPECT_EQ(It, FooBB0->getIterator());