[NFC] Rename Function::insertBasicBlockAt() to Function::insert().

I think this is a better name because it is what STL uses.

Differential Revision: https://reviews.llvm.org/D140068
This commit is contained in:
Vasileios Porpodas 2022-12-14 15:57:08 -08:00
parent 40cc041d4e
commit 80f2f1eabc
22 changed files with 46 additions and 46 deletions

View File

@ -574,9 +574,9 @@ void CodeGenFunction::EmitBlock(llvm::BasicBlock *BB, bool IsFinished) {
// 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 @@ void CodeGenFunction::EmitBlockAfterUses(llvm::BasicBlock *block) {
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);
}
@ -1469,7 +1468,7 @@ void CodeGenFunction::EmitCaseStmtRange(const CaseStmt &S,
llvm::BasicBlock *FalseDest = CaseRangeBlock;
CaseRangeBlock = createBasicBlock("sw.caserange");
CurFn->insertBasicBlockAt(CurFn->end(), CaseRangeBlock);
CurFn->insert(CurFn->end(), CaseRangeBlock);
Builder.SetInsertPoint(CaseRangeBlock);
// Emit range check.

View File

@ -320,7 +320,7 @@ llvm::DebugLoc CodeGenFunction::EmitReturnBlock() {
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;

View File

@ -863,7 +863,7 @@ Value *IfExprAST::codegen() {
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 @@ Value *IfExprAST::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");

View File

@ -863,7 +863,7 @@ Value *IfExprAST::codegen() {
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 @@ Value *IfExprAST::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");

View File

@ -863,7 +863,7 @@ Value *IfExprAST::codegen() {
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 @@ Value *IfExprAST::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");

View File

@ -846,7 +846,7 @@ Value *IfExprAST::codegen() {
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 @@ Value *IfExprAST::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");

View File

@ -650,7 +650,7 @@ Value *IfExprAST::codegen() {
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 @@ Value *IfExprAST::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");

View File

@ -762,7 +762,7 @@ Value *IfExprAST::codegen() {
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 @@ Value *IfExprAST::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");

View File

@ -869,7 +869,7 @@ Value *IfExprAST::codegen() {
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 @@ Value *IfExprAST::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");

View File

@ -867,7 +867,7 @@ Value *IfExprAST::codegen() {
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 @@ Value *IfExprAST::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");

View File

@ -1037,7 +1037,7 @@ Value *IfExprAST::codegen() {
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 @@ Value *IfExprAST::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");

View File

@ -689,7 +689,7 @@ public:
/// 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 @@ public:
/// 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; }

View File

@ -3617,7 +3617,7 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::emitCommonDirectiveEntry(
// 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)

View File

@ -62,9 +62,9 @@ void BasicBlock::insertInto(Function *NewParent, BasicBlock *InsertBefore) {
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() {

View File

@ -2655,14 +2655,12 @@ void LLVMInsertExistingBasicBlockAfterInsertBlock(LLVMBuilderRef Builder,
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,

View File

@ -179,7 +179,7 @@ llvm::SplitKnownCriticalEdge(Instruction *TI, unsigned SuccNum,
// 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);

View File

@ -670,7 +670,7 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
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.

View File

@ -999,7 +999,7 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs,
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 @@ void CodeExtractor::moveCodeToFunction(Function *newFunction) {
// 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);
}
}

View File

@ -539,7 +539,7 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
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");

View File

@ -374,7 +374,7 @@ llvm::UnrollAndJamLoop(Loop *L, unsigned Count, unsigned TripCount,
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);

View File

@ -160,7 +160,7 @@ BasicBlock *NewLeafBlock(CaseRange &Leaf, Value *Val, ConstantInt *LowerBound,
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 @@ BasicBlock *SwitchConvert(CaseItr Begin, CaseItr End, ConstantInt *LowerBound,
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);

View File

@ -206,34 +206,34 @@ bar_bb2:
// 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());