I think this is a better name because it is what STL uses.
Differential Revision: https://reviews.llvm.org/D140068
// 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);
}
bool inserted = false;
for (llvm::User *u : block->users()) {
if (llvm::Instruction *insn = dyn_cast<llvm::Instruction>(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);
}
llvm::BasicBlock *FalseDest = CaseRangeBlock;
CaseRangeBlock = createBasicBlock("sw.caserange");
- CurFn->insertBasicBlockAt(CurFn->end(), CaseRangeBlock);
+ CurFn->insert(CurFn->end(), CaseRangeBlock);
Builder.SetInsertPoint(CaseRangeBlock);
// Emit range check.
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;
ThenBB = Builder->GetInsertBlock();
// Emit else block.
- TheFunction->insertBasicBlockAt(TheFunction->end(), ElseBB);
+ TheFunction->insert(TheFunction->end(), ElseBB);
Builder->SetInsertPoint(ElseBB);
Value *ElseV = Else->codegen();
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");
ThenBB = Builder->GetInsertBlock();
// Emit else block.
- TheFunction->insertBasicBlockAt(TheFunction->end(), ElseBB);
+ TheFunction->insert(TheFunction->end(), ElseBB);
Builder->SetInsertPoint(ElseBB);
Value *ElseV = Else->codegen();
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");
ThenBB = Builder->GetInsertBlock();
// Emit else block.
- TheFunction->insertBasicBlockAt(TheFunction->end(), ElseBB);
+ TheFunction->insert(TheFunction->end(), ElseBB);
Builder->SetInsertPoint(ElseBB);
Value *ElseV = Else->codegen();
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");
ThenBB = Builder->GetInsertBlock();
// Emit else block.
- TheFunction->insertBasicBlockAt(TheFunction->end(), ElseBB);
+ TheFunction->insert(TheFunction->end(), ElseBB);
Builder->SetInsertPoint(ElseBB);
Value *ElseV = Else->codegen();
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");
ThenBB = Builder->GetInsertBlock();
// Emit else block.
- TheFunction->insertBasicBlockAt(TheFunction->end(), ElseBB);
+ TheFunction->insert(TheFunction->end(), ElseBB);
Builder->SetInsertPoint(ElseBB);
Value *ElseV = Else->codegen();
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");
ThenBB = Builder->GetInsertBlock();
// Emit else block.
- TheFunction->insertBasicBlockAt(TheFunction->end(), ElseBB);
+ TheFunction->insert(TheFunction->end(), ElseBB);
Builder->SetInsertPoint(ElseBB);
Value *ElseV = Else->codegen();
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");
ThenBB = Builder->GetInsertBlock();
// Emit else block.
- TheFunction->insertBasicBlockAt(TheFunction->end(), ElseBB);
+ TheFunction->insert(TheFunction->end(), ElseBB);
Builder->SetInsertPoint(ElseBB);
Value *ElseV = Else->codegen();
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");
ThenBB = Builder->GetInsertBlock();
// Emit else block.
- TheFunction->insertBasicBlockAt(TheFunction->end(), ElseBB);
+ TheFunction->insert(TheFunction->end(), ElseBB);
Builder->SetInsertPoint(ElseBB);
Value *ElseV = Else->codegen();
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");
ThenBB = Builder->GetInsertBlock();
// Emit else block.
- TheFunction->insertBasicBlockAt(TheFunction->end(), ElseBB);
+ TheFunction->insert(TheFunction->end(), ElseBB);
Builder->SetInsertPoint(ElseBB);
Value *ElseV = Else->codegen();
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");
/// 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);
}
/// 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; }
// 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)
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() {
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<Function>(Fn)->insertBasicBlockAt(unwrap<Function>(Fn)->end(),
- unwrap(BB));
+ unwrap<Function>(Fn)->insert(unwrap<Function>(Fn)->end(), unwrap(BB));
}
LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
// 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);
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.
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.
// 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);
}
}
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");
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);
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;
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);
// 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());