Skip to content

Commit 4a2d58e

Browse files
committed
[TI removal] Remove TerminatorInst from BasicBlockUtils.h
This requires updating a number of .cpp files to adapt to the new API. I've just systematically updated all uses of `TerminatorInst` within these files te `Instruction` so thta I won't have to touch them again in the future. llvm-svn: 344498
1 parent f21ce5d commit 4a2d58e

File tree

9 files changed

+43
-41
lines changed

9 files changed

+43
-41
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ inline bool SplitCriticalEdge(BasicBlock *Succ, pred_iterator PI,
148148
const CriticalEdgeSplittingOptions &Options =
149149
CriticalEdgeSplittingOptions()) {
150150
bool MadeChange = false;
151-
TerminatorInst *TI = (*PI)->getTerminator();
151+
Instruction *TI = (*PI)->getTerminator();
152152
for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
153153
if (TI->getSuccessor(i) == Succ)
154154
MadeChange |= !!SplitCriticalEdge(TI, i, Options);
@@ -162,7 +162,7 @@ inline BasicBlock *
162162
SplitCriticalEdge(BasicBlock *Src, BasicBlock *Dst,
163163
const CriticalEdgeSplittingOptions &Options =
164164
CriticalEdgeSplittingOptions()) {
165-
TerminatorInst *TI = Src->getTerminator();
165+
Instruction *TI = Src->getTerminator();
166166
unsigned i = 0;
167167
while (true) {
168168
assert(i != TI->getNumSuccessors() && "Edge doesn't exist!");
@@ -257,11 +257,11 @@ ReturnInst *FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB,
257257
/// Returns the NewBasicBlock's terminator.
258258
///
259259
/// Updates DT and LI if given.
260-
TerminatorInst *SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore,
261-
bool Unreachable,
262-
MDNode *BranchWeights = nullptr,
263-
DominatorTree *DT = nullptr,
264-
LoopInfo *LI = nullptr);
260+
Instruction *SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore,
261+
bool Unreachable,
262+
MDNode *BranchWeights = nullptr,
263+
DominatorTree *DT = nullptr,
264+
LoopInfo *LI = nullptr);
265265

266266
/// SplitBlockAndInsertIfThenElse is similar to SplitBlockAndInsertIfThen,
267267
/// but also creates the ElseBlock.
@@ -278,8 +278,8 @@ TerminatorInst *SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore,
278278
/// SplitBefore
279279
/// Tail
280280
void SplitBlockAndInsertIfThenElse(Value *Cond, Instruction *SplitBefore,
281-
TerminatorInst **ThenTerm,
282-
TerminatorInst **ElseTerm,
281+
Instruction **ThenTerm,
282+
Instruction **ElseTerm,
283283
MDNode *BranchWeights = nullptr);
284284

285285
/// Check whether BB is the merge point of a if-region.

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ static void instrumentMaskedLoadOrStore(AddressSanitizer *Pass,
14431443
} else {
14441444
IRBuilder<> IRB(I);
14451445
Value *MaskElem = IRB.CreateExtractElement(Mask, Idx);
1446-
TerminatorInst *ThenTerm = SplitBlockAndInsertIfThen(MaskElem, I, false);
1446+
Instruction *ThenTerm = SplitBlockAndInsertIfThen(MaskElem, I, false);
14471447
InsertBefore = ThenTerm;
14481448
}
14491449

@@ -1596,8 +1596,9 @@ void AddressSanitizer::instrumentAddress(Instruction *OrigIns,
15961596
Value *TagCheck =
15971597
IRB.CreateICmpEQ(Tag, ConstantInt::get(IntptrTy, kMyriadDDRTag));
15981598

1599-
TerminatorInst *TagCheckTerm = SplitBlockAndInsertIfThen(
1600-
TagCheck, InsertBefore, false, MDBuilder(*C).createBranchWeights(1, 100000));
1599+
Instruction *TagCheckTerm =
1600+
SplitBlockAndInsertIfThen(TagCheck, InsertBefore, false,
1601+
MDBuilder(*C).createBranchWeights(1, 100000));
16011602
assert(cast<BranchInst>(TagCheckTerm)->isUnconditional());
16021603
IRB.SetInsertPoint(TagCheckTerm);
16031604
InsertBefore = TagCheckTerm;
@@ -1613,12 +1614,12 @@ void AddressSanitizer::instrumentAddress(Instruction *OrigIns,
16131614

16141615
Value *Cmp = IRB.CreateICmpNE(ShadowValue, CmpVal);
16151616
size_t Granularity = 1ULL << Mapping.Scale;
1616-
TerminatorInst *CrashTerm = nullptr;
1617+
Instruction *CrashTerm = nullptr;
16171618

16181619
if (ClAlwaysSlowPath || (TypeSize < 8 * Granularity)) {
16191620
// We use branch weights for the slow path check, to indicate that the slow
16201621
// path is rarely taken. This seems to be the case for SPEC benchmarks.
1621-
TerminatorInst *CheckTerm = SplitBlockAndInsertIfThen(
1622+
Instruction *CheckTerm = SplitBlockAndInsertIfThen(
16221623
Cmp, InsertBefore, false, MDBuilder(*C).createBranchWeights(1, 100000));
16231624
assert(cast<BranchInst>(CheckTerm)->isUnconditional());
16241625
BasicBlock *NextBB = CheckTerm->getSuccessor(0);
@@ -3116,7 +3117,7 @@ void FunctionStackPoisoner::processStaticAllocas() {
31163117
// <This is not a fake stack; unpoison the redzones>
31173118
Value *Cmp =
31183119
IRBRet.CreateICmpNE(FakeStack, Constant::getNullValue(IntptrTy));
3119-
TerminatorInst *ThenTerm, *ElseTerm;
3120+
Instruction *ThenTerm, *ElseTerm;
31203121
SplitBlockAndInsertIfThenElse(Cmp, Ret, &ThenTerm, &ElseTerm);
31213122

31223123
IRBuilder<> IRBPoison(ThenTerm);

llvm/lib/Transforms/Instrumentation/EfficiencySanitizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ bool EfficiencySanitizer::instrumentFastpathWorkingSet(
887887
Value *OldValue = IRB.CreateLoad(IRB.CreateIntToPtr(ShadowPtr, ShadowPtrTy));
888888
// The AND and CMP will be turned into a TEST instruction by the compiler.
889889
Value *Cmp = IRB.CreateICmpNE(IRB.CreateAnd(OldValue, ValueMask), ValueMask);
890-
TerminatorInst *CmpTerm = SplitBlockAndInsertIfThen(Cmp, I, false);
890+
Instruction *CmpTerm = SplitBlockAndInsertIfThen(Cmp, I, false);
891891
// FIXME: do I need to call SetCurrentDebugLocation?
892892
IRB.SetInsertPoint(CmpTerm);
893893
// We use OR to set the shadow bits to avoid corrupting the middle 6 bits,

llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ void HWAddressSanitizer::instrumentMemAccessInline(Value *PtrLong, bool IsWrite,
467467
TagMismatch = IRB.CreateAnd(TagMismatch, TagNotIgnored);
468468
}
469469

470-
TerminatorInst *CheckTerm =
470+
Instruction *CheckTerm =
471471
SplitBlockAndInsertIfThen(TagMismatch, InsertBefore, !Recover,
472472
MDBuilder(*C).createBranchWeights(1, 100000));
473473

llvm/lib/Transforms/Scalar/JumpThreading.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ bool JumpThreadingPass::ComputeValueKnownInPredecessors(
947947
/// Since we can pick an arbitrary destination, we pick the successor with the
948948
/// fewest predecessors. This should reduce the in-degree of the others.
949949
static unsigned GetBestDestForJumpOnUndef(BasicBlock *BB) {
950-
TerminatorInst *BBTerm = BB->getTerminator();
950+
Instruction *BBTerm = BB->getTerminator();
951951
unsigned MinSucc = 0;
952952
BasicBlock *TestBB = BBTerm->getSuccessor(MinSucc);
953953
// Compute the successor with the minimum number of predecessors.
@@ -988,7 +988,7 @@ bool JumpThreadingPass::ProcessBlock(BasicBlock *BB) {
988988
// because now the condition in this block can be threaded through
989989
// predecessors of our predecessor block.
990990
if (BasicBlock *SinglePred = BB->getSinglePredecessor()) {
991-
const TerminatorInst *TI = SinglePred->getTerminator();
991+
const Instruction *TI = SinglePred->getTerminator();
992992
if (!TI->isExceptionalTerminator() && TI->getNumSuccessors() == 1 &&
993993
SinglePred != BB && !hasAddressTakenAndUsed(BB)) {
994994
// If SinglePred was a loop header, BB becomes one.
@@ -1080,7 +1080,7 @@ bool JumpThreadingPass::ProcessBlock(BasicBlock *BB) {
10801080
std::vector<DominatorTree::UpdateType> Updates;
10811081

10821082
// Fold the branch/switch.
1083-
TerminatorInst *BBTerm = BB->getTerminator();
1083+
Instruction *BBTerm = BB->getTerminator();
10841084
Updates.reserve(BBTerm->getNumSuccessors());
10851085
for (unsigned i = 0, e = BBTerm->getNumSuccessors(); i != e; ++i) {
10861086
if (i == BestSucc) continue;
@@ -1549,7 +1549,7 @@ FindMostPopularDest(BasicBlock *BB,
15491549
// successor list.
15501550
if (!SamePopularity.empty()) {
15511551
SamePopularity.push_back(MostPopularDest);
1552-
TerminatorInst *TI = BB->getTerminator();
1552+
Instruction *TI = BB->getTerminator();
15531553
for (unsigned i = 0; ; ++i) {
15541554
assert(i != TI->getNumSuccessors() && "Didn't find any successor!");
15551555

@@ -1669,7 +1669,7 @@ bool JumpThreadingPass::ProcessThreadableEdges(Value *Cond, BasicBlock *BB,
16691669
}
16701670

16711671
// Finally update the terminator.
1672-
TerminatorInst *Term = BB->getTerminator();
1672+
Instruction *Term = BB->getTerminator();
16731673
BranchInst::Create(OnlyDest, Term);
16741674
Term->eraseFromParent();
16751675
DTU->applyUpdates(Updates);
@@ -2006,7 +2006,7 @@ bool JumpThreadingPass::ThreadEdge(BasicBlock *BB,
20062006
// Update the terminator of PredBB to jump to NewBB instead of BB. This
20072007
// eliminates predecessors from BB, which requires us to simplify any PHI
20082008
// nodes in BB.
2009-
TerminatorInst *PredTerm = PredBB->getTerminator();
2009+
Instruction *PredTerm = PredBB->getTerminator();
20102010
for (unsigned i = 0, e = PredTerm->getNumSuccessors(); i != e; ++i)
20112011
if (PredTerm->getSuccessor(i) == BB) {
20122012
BB->removePredecessor(PredBB, true);
@@ -2115,7 +2115,7 @@ BasicBlock *JumpThreadingPass::SplitBlockPreds(BasicBlock *BB,
21152115
}
21162116

21172117
bool JumpThreadingPass::doesBlockHaveProfileData(BasicBlock *BB) {
2118-
const TerminatorInst *TI = BB->getTerminator();
2118+
const Instruction *TI = BB->getTerminator();
21192119
assert(TI->getNumSuccessors() > 1 && "not a split");
21202120

21212121
MDNode *WeightsNode = TI->getMetadata(LLVMContext::MD_prof);
@@ -2538,7 +2538,7 @@ bool JumpThreadingPass::TryToUnfoldSelectInCurrBB(BasicBlock *BB) {
25382538
if (!SI)
25392539
continue;
25402540
// Expand the select.
2541-
TerminatorInst *Term =
2541+
Instruction *Term =
25422542
SplitBlockAndInsertIfThen(SI->getCondition(), SI, false);
25432543
BasicBlock *SplitBB = SI->getParent();
25442544
BasicBlock *NewBB = Term->getParent();

llvm/lib/Transforms/Utils/BasicBlockUtils.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void llvm::DeleteDeadBlock(BasicBlock *BB, DomTreeUpdater *DTU) {
5252
assert((pred_begin(BB) == pred_end(BB) ||
5353
// Can delete self loop.
5454
BB->getSinglePredecessor() == BB) && "Block is not dead!");
55-
TerminatorInst *BBTerm = BB->getTerminator();
55+
Instruction *BBTerm = BB->getTerminator();
5656
std::vector<DominatorTree::UpdateType> Updates;
5757

5858
// Loop through all of our successors and make sure they know that one
@@ -270,7 +270,7 @@ BasicBlock *llvm::SplitEdge(BasicBlock *BB, BasicBlock *Succ, DominatorTree *DT,
270270
unsigned SuccNum = GetSuccessorNumber(BB, Succ);
271271

272272
// If this is a critical edge, let SplitCriticalEdge do it.
273-
TerminatorInst *LatchTerm = BB->getTerminator();
273+
Instruction *LatchTerm = BB->getTerminator();
274274
if (SplitCriticalEdge(
275275
LatchTerm, SuccNum,
276276
CriticalEdgeSplittingOptions(DT, LI, MSSAU).setPreserveLCSSA()))
@@ -298,7 +298,7 @@ llvm::SplitAllCriticalEdges(Function &F,
298298
const CriticalEdgeSplittingOptions &Options) {
299299
unsigned NumBroken = 0;
300300
for (BasicBlock &BB : F) {
301-
TerminatorInst *TI = BB.getTerminator();
301+
Instruction *TI = BB.getTerminator();
302302
if (TI->getNumSuccessors() > 1 && !isa<IndirectBrInst>(TI))
303303
for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
304304
if (SplitCriticalEdge(TI, i, Options))
@@ -705,16 +705,17 @@ ReturnInst *llvm::FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB,
705705
return cast<ReturnInst>(NewRet);
706706
}
707707

708-
TerminatorInst *
709-
llvm::SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore,
710-
bool Unreachable, MDNode *BranchWeights,
711-
DominatorTree *DT, LoopInfo *LI) {
708+
Instruction *llvm::SplitBlockAndInsertIfThen(Value *Cond,
709+
Instruction *SplitBefore,
710+
bool Unreachable,
711+
MDNode *BranchWeights,
712+
DominatorTree *DT, LoopInfo *LI) {
712713
BasicBlock *Head = SplitBefore->getParent();
713714
BasicBlock *Tail = Head->splitBasicBlock(SplitBefore->getIterator());
714-
TerminatorInst *HeadOldTerm = Head->getTerminator();
715+
Instruction *HeadOldTerm = Head->getTerminator();
715716
LLVMContext &C = Head->getContext();
716717
BasicBlock *ThenBlock = BasicBlock::Create(C, "", Head->getParent(), Tail);
717-
TerminatorInst *CheckTerm;
718+
Instruction *CheckTerm;
718719
if (Unreachable)
719720
CheckTerm = new UnreachableInst(C, ThenBlock);
720721
else
@@ -749,12 +750,12 @@ llvm::SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore,
749750
}
750751

751752
void llvm::SplitBlockAndInsertIfThenElse(Value *Cond, Instruction *SplitBefore,
752-
TerminatorInst **ThenTerm,
753-
TerminatorInst **ElseTerm,
753+
Instruction **ThenTerm,
754+
Instruction **ElseTerm,
754755
MDNode *BranchWeights) {
755756
BasicBlock *Head = SplitBefore->getParent();
756757
BasicBlock *Tail = Head->splitBasicBlock(SplitBefore->getIterator());
757-
TerminatorInst *HeadOldTerm = Head->getTerminator();
758+
Instruction *HeadOldTerm = Head->getTerminator();
758759
LLVMContext &C = Head->getContext();
759760
BasicBlock *ThenBlock = BasicBlock::Create(C, "", Head->getParent(), Tail);
760761
BasicBlock *ElseBlock = BasicBlock::Create(C, "", Head->getParent(), Tail);

llvm/lib/Transforms/Utils/CallPromotionUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ static Instruction *versionCallSite(CallSite CS, Value *Callee,
270270
// Create an if-then-else structure. The original instruction is moved into
271271
// the "else" block, and a clone of the original instruction is placed in the
272272
// "then" block.
273-
TerminatorInst *ThenTerm = nullptr;
274-
TerminatorInst *ElseTerm = nullptr;
273+
Instruction *ThenTerm = nullptr;
274+
Instruction *ElseTerm = nullptr;
275275
SplitBlockAndInsertIfThenElse(Cond, CS.getInstruction(), &ThenTerm, &ElseTerm,
276276
BranchWeights);
277277
BasicBlock *ThenBlock = ThenTerm->getParent();

llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ void LibCallsShrinkWrap::shrinkWrapCI(CallInst *CI, Value *Cond) {
487487
MDNode *BranchWeights =
488488
MDBuilder(CI->getContext()).createBranchWeights(1, 2000);
489489

490-
TerminatorInst *NewInst =
490+
Instruction *NewInst =
491491
SplitBlockAndInsertIfThen(Cond, CI, false, BranchWeights, DT);
492492
BasicBlock *CallBB = NewInst->getParent();
493493
CallBB->setName("cdce.call");

llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ static void createMemMoveLoop(Instruction *InsertBefore,
301301
// the appropriate conditional branches when the loop is built.
302302
ICmpInst *PtrCompare = new ICmpInst(InsertBefore, ICmpInst::ICMP_ULT,
303303
SrcAddr, DstAddr, "compare_src_dst");
304-
TerminatorInst *ThenTerm, *ElseTerm;
304+
Instruction *ThenTerm, *ElseTerm;
305305
SplitBlockAndInsertIfThenElse(PtrCompare, InsertBefore, &ThenTerm,
306306
&ElseTerm);
307307

0 commit comments

Comments
 (0)