[NFC] Cleanup: Replaces BB->getInstList().splice() with BB->splice().

This is part of a series of cleanup patches towards making BasicBlock::getInstList() private.

Differential Revision: https://reviews.llvm.org/D138979
This commit is contained in:
Vasileios Porpodas 2022-11-28 14:45:59 -08:00
parent 467432899b
commit bebca2b6d5
12 changed files with 30 additions and 42 deletions

View File

@ -556,7 +556,7 @@ static llvm::BasicBlock *SimplifyCleanupEntry(CodeGenFunction &CGF,
Entry->replaceAllUsesWith(Pred);
// Merge the blocks.
Pred->getInstList().splice(Pred->end(), Entry->getInstList());
Pred->splice(Pred->end(), Entry);
// Kill the entry block.
Entry->eraseFromParent();

View File

@ -261,8 +261,7 @@ void llvm::spliceBB(IRBuilderBase::InsertPoint IP, BasicBlock *New,
// Move instructions to new block.
BasicBlock *Old = IP.getBlock();
New->getInstList().splice(New->begin(), Old->getInstList(), IP.getPoint(),
Old->end());
New->splice(New->begin(), Old, IP.getPoint(), Old->end());
if (CreateBranch)
BranchInst::Create(New, Old);

View File

@ -115,7 +115,7 @@ void Instruction::moveAfter(Instruction *MovePos) {
void Instruction::moveBefore(BasicBlock &BB,
SymbolTableList<Instruction>::iterator I) {
assert(I == BB.end() || I->getParent() == &BB);
BB.getInstList().splice(I, getParent()->getInstList(), getIterator());
BB.splice(I, getParent(), getIterator());
}
bool Instruction::comesBefore(const Instruction *Other) const {

View File

@ -201,8 +201,8 @@ static bool replaceCoroEndAsync(AnyCoroEndInst *End) {
assert(MustTailCallFuncBlock && "Must have a single predecessor block");
auto It = MustTailCallFuncBlock->getTerminator()->getIterator();
auto *MustTailCall = cast<CallInst>(&*std::prev(It));
CoroEndBlock->getInstList().splice(
End->getIterator(), MustTailCallFuncBlock->getInstList(), MustTailCall);
CoroEndBlock->splice(End->getIterator(), MustTailCallFuncBlock,
MustTailCall->getIterator());
// Insert the return instruction.
Builder.SetInsertPoint(End);

View File

@ -1350,11 +1350,10 @@ bool LoopInterchangeTransform::transform() {
/// \brief Move all instructions except the terminator from FromBB right before
/// InsertBefore
static void moveBBContents(BasicBlock *FromBB, Instruction *InsertBefore) {
auto &ToList = InsertBefore->getParent()->getInstList();
auto &FromList = FromBB->getInstList();
BasicBlock *ToBB = InsertBefore->getParent();
ToList.splice(InsertBefore->getIterator(), FromList, FromList.begin(),
FromBB->getTerminator()->getIterator());
ToBB->splice(InsertBefore->getIterator(), FromBB, FromBB->begin(),
FromBB->getTerminator()->getIterator());
}
/// Swap instructions between \p BB1 and \p BB2 but keep terminators intact.

View File

@ -579,8 +579,7 @@ static bool unswitchTrivialBranch(Loop &L, BranchInst &BI, DominatorTree &DT,
// If fully unswitching, we can use the existing branch instruction.
// Splice it into the old PH to gate reaching the new preheader and re-point
// its successors.
OldPH->getInstList().splice(OldPH->end(), BI.getParent()->getInstList(),
BI);
OldPH->splice(OldPH->end(), BI.getParent(), BI.getIterator());
BI.setCondition(Cond);
if (MSSAU) {
// Temporarily clone the terminator, to make MSSA update cheaper by
@ -2251,7 +2250,7 @@ static void unswitchNontrivialInvariants(
if (FullUnswitch) {
// Splice the terminator from the original loop and rewrite its
// successors.
SplitBB->getInstList().splice(SplitBB->end(), ParentBB->getInstList(), TI);
SplitBB->splice(SplitBB->end(), ParentBB, TI.getIterator());
// Keep a clone of the terminator for MSSA updates.
Instruction *NewTI = TI.clone();

View File

@ -267,8 +267,7 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU,
Start = PTI;
// Move all definitions in the successor to the predecessor...
PredBB->getInstList().splice(PTI->getIterator(), BB->getInstList(),
BB->begin(), STI->getIterator());
PredBB->splice(PTI->getIterator(), BB, BB->begin(), STI->getIterator());
if (MSSAU)
MSSAU->moveAllAfterMergeBlocks(BB, PredBB, Start);
@ -288,7 +287,7 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU,
PredBB->back().eraseFromParent();
// Move terminator instruction.
PredBB->getInstList().splice(PredBB->end(), BB->getInstList());
PredBB->splice(PredBB->end(), BB);
// Terminator may be a memory accessing instruction too.
if (MSSAU)

View File

@ -889,7 +889,7 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
Dest->replaceAllUsesWith(&*I);
// Move all the instructions in the succ to the pred.
I->getInstList().splice(I->end(), Dest->getInstList());
I->splice(I->end(), Dest);
// Remove the dest block.
Dest->eraseFromParent();

View File

@ -285,8 +285,7 @@ bool FlattenCFGOpt::FlattenParallelAndOr(BasicBlock *BB, IRBuilder<> &Builder) {
CB = PBI->getSuccessor(1 - Idx);
// Delete the conditional branch.
FirstCondBlock->back().eraseFromParent();
FirstCondBlock->getInstList()
.splice(FirstCondBlock->end(), CB->getInstList());
FirstCondBlock->splice(FirstCondBlock->end(), CB);
PBI = cast<BranchInst>(FirstCondBlock->getTerminator());
Value *CC = PBI->getCondition();
// Merge conditions.
@ -481,8 +480,7 @@ bool FlattenCFGOpt::MergeIfRegion(BasicBlock *BB, IRBuilder<> &Builder) {
// Merge \param SecondEntryBlock into \param FirstEntryBlock.
FirstEntryBlock->back().eraseFromParent();
FirstEntryBlock->getInstList()
.splice(FirstEntryBlock->end(), SecondEntryBlock->getInstList());
FirstEntryBlock->splice(FirstEntryBlock->end(), SecondEntryBlock);
BranchInst *PBI = cast<BranchInst>(FirstEntryBlock->getTerminator());
assert(PBI->getCondition() == CInst2);
BasicBlock *SaveInsertBB = Builder.GetInsertBlock();

View File

@ -2411,8 +2411,8 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
// Transfer all of the allocas over in a block. Using splice means
// that the instructions aren't removed from the symbol table, then
// reinserted.
Caller->getEntryBlock().getInstList().splice(
InsertPoint, FirstNewBlock->getInstList(), AI->getIterator(), I);
Caller->getEntryBlock().splice(InsertPoint, &*FirstNewBlock,
AI->getIterator(), I);
}
}
@ -2755,8 +2755,8 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
// the calling basic block.
if (Returns.size() == 1 && std::distance(FirstNewBlock, Caller->end()) == 1) {
// Move all of the instructions right before the call.
OrigBB->getInstList().splice(CB.getIterator(), FirstNewBlock->getInstList(),
FirstNewBlock->begin(), FirstNewBlock->end());
OrigBB->splice(CB.getIterator(), &*FirstNewBlock, FirstNewBlock->begin(),
FirstNewBlock->end());
// Remove the cloned basic block.
Caller->getBasicBlockList().pop_back();
@ -2896,8 +2896,7 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
// Splice the code from the return block into the block that it will return
// to, which contains the code that was after the call.
AfterCallBB->getInstList().splice(AfterCallBB->begin(),
ReturnBB->getInstList());
AfterCallBB->splice(AfterCallBB->begin(), ReturnBB);
if (CreatedBranchToNormalDest)
CreatedBranchToNormalDest->setDebugLoc(Returns[0]->getDebugLoc());
@ -2927,7 +2926,7 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
// Splice the code entry block into calling block, right before the
// unconditional branch.
CalleeEntry->replaceAllUsesWith(OrigBB); // Update PHI nodes
OrigBB->getInstList().splice(Br->getIterator(), CalleeEntry->getInstList());
OrigBB->splice(Br->getIterator(), CalleeEntry);
// Remove the unconditional branch.
Br->eraseFromParent();

View File

@ -799,7 +799,7 @@ void llvm::MergeBasicBlockIntoOnlyPred(BasicBlock *DestBB,
// Splice all the instructions from PredBB to DestBB.
PredBB->getTerminator()->eraseFromParent();
DestBB->getInstList().splice(DestBB->begin(), PredBB->getInstList());
DestBB->splice(DestBB->begin(), PredBB);
new UnreachableInst(PredBB->getContext(), PredBB);
// If the PredBB is the entry block of the function, move DestBB up to
@ -1204,8 +1204,7 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB,
// Copy over any phi, debug or lifetime instruction.
BB->getTerminator()->eraseFromParent();
Succ->getInstList().splice(Succ->getFirstNonPHI()->getIterator(),
BB->getInstList());
Succ->splice(Succ->getFirstNonPHI()->getIterator(), BB);
} else {
while (PHINode *PN = dyn_cast<PHINode>(&BB->front())) {
// We explicitly check for such uses in CanPropagatePredecessorsForPHIs.
@ -2962,9 +2961,8 @@ void llvm::hoistAllInstructionsInto(BasicBlock *DomBlock, Instruction *InsertPt,
I->setDebugLoc(InsertPt->getDebugLoc());
++II;
}
DomBlock->getInstList().splice(InsertPt->getIterator(), BB->getInstList(),
BB->begin(),
BB->getTerminator()->getIterator());
DomBlock->splice(InsertPt->getIterator(), BB, BB->begin(),
BB->getTerminator()->getIterator());
}
namespace {

View File

@ -1603,16 +1603,13 @@ bool SimplifyCFGOpt::HoistThenElseCodeToIf(BranchInst *BI,
// The debug location is an integral part of a debug info intrinsic
// and can't be separated from it or replaced. Instead of attempting
// to merge locations, simply hoist both copies of the intrinsic.
BIParent->getInstList().splice(BI->getIterator(), BB1->getInstList(),
I1);
BIParent->getInstList().splice(BI->getIterator(), BB2->getInstList(),
I2);
BIParent->splice(BI->getIterator(), BB1, I1->getIterator());
BIParent->splice(BI->getIterator(), BB2, I2->getIterator());
} else {
// For a normal instruction, we just move one to right before the
// branch, then replace all uses of the other with the first. Finally,
// we remove the now redundant second instruction.
BIParent->getInstList().splice(BI->getIterator(), BB1->getInstList(),
I1);
BIParent->splice(BI->getIterator(), BB1, I1->getIterator());
if (!I2->use_empty())
I2->replaceAllUsesWith(I1);
I1->andIRFlags(I2);
@ -3040,8 +3037,8 @@ bool SimplifyCFGOpt::SpeculativelyExecuteBB(BranchInst *BI, BasicBlock *ThenBB,
}
// Hoist the instructions.
BB->getInstList().splice(BI->getIterator(), ThenBB->getInstList(),
ThenBB->begin(), std::prev(ThenBB->end()));
BB->splice(BI->getIterator(), ThenBB, ThenBB->begin(),
std::prev(ThenBB->end()));
// Insert selects and rewrite the PHI operands.
IRBuilder<NoFolder> Builder(BI);