Skip to content

Commit 06911ba

Browse files
author
Vasileios Porpodas
committed
[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
1 parent 816b5e5 commit 06911ba

30 files changed

+66
-67
lines changed

clang/lib/CodeGen/CGCleanup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) {
942942
// Append the prepared cleanup prologue from above.
943943
llvm::BasicBlock *NormalExit = Builder.GetInsertBlock();
944944
for (unsigned I = 0, E = InstsToAppend.size(); I != E; ++I)
945-
NormalExit->getInstList().push_back(InstsToAppend[I]);
945+
InstsToAppend[I]->insertAt(NormalExit, NormalExit->end());
946946

947947
// Optimistically hope that any fixups will continue falling through.
948948
for (unsigned I = FixupDepth, E = EHStack.getNumBranchFixups();

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ class IRBuilderDefaultInserter {
6565
virtual void InsertHelper(Instruction *I, const Twine &Name,
6666
BasicBlock *BB,
6767
BasicBlock::iterator InsertPt) const {
68-
if (BB) BB->getInstList().insert(InsertPt, I);
68+
if (BB)
69+
I->insertAt(BB, InsertPt);
6970
I->setName(Name);
7071
}
7172
};

llvm/include/llvm/Transforms/InstCombine/InstCombiner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {
397397
assert(New && !New->getParent() &&
398398
"New instruction already inserted into a basic block!");
399399
BasicBlock *BB = Old.getParent();
400-
BB->getInstList().insert(Old.getIterator(), New); // Insert inst
400+
New->insertAt(BB, Old.getIterator()); // Insert inst
401401
Worklist.push(New);
402402
return New;
403403
}

llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ void ReplaceInstWithValue(BasicBlock::InstListType &BIL,
121121
/// Copies DebugLoc from BI to I, if I doesn't already have a DebugLoc. The
122122
/// original instruction is deleted and BI is updated to point to the new
123123
/// instruction.
124-
void ReplaceInstWithInst(BasicBlock::InstListType &BIL,
125-
BasicBlock::iterator &BI, Instruction *I);
124+
void ReplaceInstWithInst(BasicBlock *BB, BasicBlock::iterator &BI,
125+
Instruction *I);
126126

127127
/// Replace the instruction specified by From with the instruction specified by
128128
/// To. Copies DebugLoc from BI to I, if I doesn't already have a DebugLoc.

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6166,7 +6166,7 @@ bool LLParser::parseBasicBlock(PerFunctionState &PFS) {
61666166
llvm_unreachable("Unknown parseInstruction result!");
61676167
case InstError: return true;
61686168
case InstNormal:
6169-
BB->getInstList().push_back(Inst);
6169+
Inst->insertAt(BB, BB->end());
61706170

61716171
// With a normal result, we check to see if the instruction is followed by
61726172
// a comma and metadata.
@@ -6175,7 +6175,7 @@ bool LLParser::parseBasicBlock(PerFunctionState &PFS) {
61756175
return true;
61766176
break;
61776177
case InstExtraComma:
6178-
BB->getInstList().push_back(Inst);
6178+
Inst->insertAt(BB, BB->end());
61796179

61806180
// If the instruction parser ate an extra comma at the end of it, it
61816181
// *must* be followed by metadata.

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4840,7 +4840,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
48404840
if (Temp) {
48414841
InstructionList.push_back(Temp);
48424842
assert(CurBB && "No current BB?");
4843-
CurBB->getInstList().push_back(Temp);
4843+
Temp->insertAt(CurBB, CurBB->end());
48444844
}
48454845
} else {
48464846
auto CastOp = (Instruction::CastOps)Opc;
@@ -6088,7 +6088,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
60886088
// Before weak cmpxchgs existed, the instruction simply returned the
60896089
// value loaded from memory, so bitcode files from that era will be
60906090
// expecting the first component of a modern cmpxchg.
6091-
CurBB->getInstList().push_back(I);
6091+
I->insertAt(CurBB, CurBB->end());
60926092
I = ExtractValueInst::Create(I, 0);
60936093
ResTypeID = CmpTypeID;
60946094
} else {
@@ -6412,7 +6412,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
64126412
I->deleteValue();
64136413
return error("Operand bundles found with no consumer");
64146414
}
6415-
CurBB->getInstList().push_back(I);
6415+
I->insertAt(CurBB, CurBB->end());
64166416

64176417
// If this was a terminator instruction, move to the next block.
64186418
if (I->isTerminator()) {

llvm/lib/CodeGen/WinEHPrepare.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,8 +1212,8 @@ void WinEHPrepare::replaceUseWithLoad(Value *V, Use &U, AllocaInst *&SpillSlot,
12121212
BranchInst *Goto = cast<BranchInst>(IncomingBlock->getTerminator());
12131213
Goto->removeFromParent();
12141214
CatchRet->removeFromParent();
1215-
IncomingBlock->getInstList().push_back(CatchRet);
1216-
NewBlock->getInstList().push_back(Goto);
1215+
CatchRet->insertAt(IncomingBlock, IncomingBlock->end());
1216+
Goto->insertAt(NewBlock, NewBlock->end());
12171217
Goto->setSuccessor(0, PHIBlock);
12181218
CatchRet->setSuccessor(NewBlock);
12191219
// Update the color mapping for the newly split edge.

llvm/lib/IR/Instruction.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
2828
if (InsertBefore) {
2929
BasicBlock *BB = InsertBefore->getParent();
3030
assert(BB && "Instruction to insert before is not in a basic block!");
31-
BB->getInstList().insert(InsertBefore->getIterator(), this);
31+
insertAt(BB, InsertBefore->getIterator());
3232
}
3333
}
3434

@@ -38,7 +38,7 @@ Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
3838

3939
// append this instruction into the basic block
4040
assert(InsertAtEnd && "Basic block to append to may not be NULL!");
41-
InsertAtEnd->getInstList().push_back(this);
41+
insertAt(InsertAtEnd, InsertAtEnd->end());
4242
}
4343

4444
Instruction::~Instruction() {
@@ -85,14 +85,13 @@ iplist<Instruction>::iterator Instruction::eraseFromParent() {
8585
/// Insert an unlinked instruction into a basic block immediately before the
8686
/// specified instruction.
8787
void Instruction::insertBefore(Instruction *InsertPos) {
88-
InsertPos->getParent()->getInstList().insert(InsertPos->getIterator(), this);
88+
insertAt(InsertPos->getParent(), InsertPos->getIterator());
8989
}
9090

9191
/// Insert an unlinked instruction into a basic block immediately after the
9292
/// specified instruction.
9393
void Instruction::insertAfter(Instruction *InsertPos) {
94-
InsertPos->getParent()->getInstList().insertAfter(InsertPos->getIterator(),
95-
this);
94+
insertAt(InsertPos->getParent(), std::next(InsertPos->getIterator()));
9695
}
9796

9897
BasicBlock::iterator Instruction::insertAt(BasicBlock *BB,

llvm/lib/IR/Instructions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ static Instruction *createMalloc(Instruction *InsertBefore,
824824
MCall = CallInst::Create(MallocFunc, AllocSize, OpB, "malloccall");
825825
Result = MCall;
826826
if (Result->getType() != AllocPtrType) {
827-
InsertAtEnd->getInstList().push_back(MCall);
827+
MCall->insertAt(InsertAtEnd, InsertAtEnd->end());
828828
// Create a cast instruction to convert to the right type...
829829
Result = new BitCastInst(MCall, AllocPtrType, Name);
830830
}
@@ -2815,7 +2815,7 @@ UnaryOperator *UnaryOperator::Create(UnaryOps Op, Value *S,
28152815
const Twine &Name,
28162816
BasicBlock *InsertAtEnd) {
28172817
UnaryOperator *Res = Create(Op, S, Name);
2818-
InsertAtEnd->getInstList().push_back(Res);
2818+
Res->insertAt(InsertAtEnd, InsertAtEnd->end());
28192819
return Res;
28202820
}
28212821

@@ -2946,7 +2946,7 @@ BinaryOperator *BinaryOperator::Create(BinaryOps Op, Value *S1, Value *S2,
29462946
const Twine &Name,
29472947
BasicBlock *InsertAtEnd) {
29482948
BinaryOperator *Res = Create(Op, S1, S2, Name);
2949-
InsertAtEnd->getInstList().push_back(Res);
2949+
Res->insertAt(InsertAtEnd, InsertAtEnd->end());
29502950
return Res;
29512951
}
29522952

llvm/lib/Transforms/IPO/IROutliner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,7 @@ replaceArgumentUses(OutlinableRegion &Region,
18721872
StoreInst *NewI = cast<StoreInst>(I->clone());
18731873
NewI->setDebugLoc(DebugLoc());
18741874
BasicBlock *OutputBB = VBBIt->second;
1875-
OutputBB->getInstList().push_back(NewI);
1875+
NewI->insertAt(OutputBB, OutputBB->end());
18761876
LLVM_DEBUG(dbgs() << "Move store for instruction " << *I << " to "
18771877
<< *OutputBB << "\n");
18781878

0 commit comments

Comments
 (0)