diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp index 0a766d176200..3743d24f11fc 100644 --- a/clang/lib/CodeGen/CGCleanup.cpp +++ b/clang/lib/CodeGen/CGCleanup.cpp @@ -366,7 +366,7 @@ static llvm::SwitchInst *TransitionToCleanupSwitch(CodeGenFunction &CGF, llvm::BasicBlock *Block) { // If it's a branch, turn it into a switch whose default // destination is its original target. - llvm::TerminatorInst *Term = Block->getTerminator(); + llvm::Instruction *Term = Block->getTerminator(); assert(Term && "can't transition block without terminator"); if (llvm::BranchInst *Br = dyn_cast(Term)) { @@ -589,7 +589,7 @@ static void ForwardPrebranchedFallthrough(llvm::BasicBlock *Exit, llvm::BasicBlock *To) { // Exit is the exit block of a cleanup, so it always terminates in // an unconditional branch or a switch. - llvm::TerminatorInst *Term = Exit->getTerminator(); + llvm::Instruction *Term = Exit->getTerminator(); if (llvm::BranchInst *Br = dyn_cast(Term)) { assert(Br->isUnconditional() && Br->getSuccessor(0) == From); diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp index 4ee835259a54..3297bb319db5 100644 --- a/clang/lib/CodeGen/CGException.cpp +++ b/clang/lib/CodeGen/CGException.cpp @@ -1248,7 +1248,7 @@ void CodeGenFunction::ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock) { // we follow the false destination for each of the cond branches to reach // the rethrow block. llvm::BasicBlock *RethrowBlock = WasmCatchStartBlock; - while (llvm::TerminatorInst *TI = RethrowBlock->getTerminator()) { + while (llvm::Instruction *TI = RethrowBlock->getTerminator()) { auto *BI = cast(TI); assert(BI->isConditional()); RethrowBlock = BI->getSuccessor(1); diff --git a/llvm/include/llvm/IR/BasicBlock.h b/llvm/include/llvm/IR/BasicBlock.h index 1ee19975af75..7244bba1ca59 100644 --- a/llvm/include/llvm/IR/BasicBlock.h +++ b/llvm/include/llvm/IR/BasicBlock.h @@ -38,7 +38,6 @@ class LandingPadInst; class LLVMContext; class Module; class PHINode; -class TerminatorInst; class ValueSymbolTable; /// LLVM Basic Block Representation @@ -50,12 +49,12 @@ class ValueSymbolTable; /// represents a label to which a branch can jump. /// /// A well formed basic block is formed of a list of non-terminating -/// instructions followed by a single TerminatorInst instruction. -/// TerminatorInst's may not occur in the middle of basic blocks, and must -/// terminate the blocks. The BasicBlock class allows malformed basic blocks to -/// occur because it may be useful in the intermediate stage of constructing or -/// modifying a program. However, the verifier will ensure that basic blocks -/// are "well formed". +/// instructions followed by a single terminator instruction. Terminator +/// instructions may not occur in the middle of basic blocks, and must terminate +/// the blocks. The BasicBlock class allows malformed basic blocks to occur +/// because it may be useful in the intermediate stage of constructing or +/// modifying a program. However, the verifier will ensure that basic blocks are +/// "well formed". class BasicBlock final : public Value, // Basic blocks are data objects also public ilist_node_with_parent { public: @@ -120,10 +119,10 @@ public: /// Returns the terminator instruction if the block is well formed or null /// if the block is not well formed. - const TerminatorInst *getTerminator() const LLVM_READONLY; - TerminatorInst *getTerminator() { - return const_cast( - static_cast(this)->getTerminator()); + const Instruction *getTerminator() const LLVM_READONLY; + Instruction *getTerminator() { + return const_cast( + static_cast(this)->getTerminator()); } /// Returns the call instruction calling \@llvm.experimental.deoptimize diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp index 03fb5ccaffc3..12ab2e2ace4d 100644 --- a/llvm/lib/IR/BasicBlock.cpp +++ b/llvm/lib/IR/BasicBlock.cpp @@ -135,9 +135,10 @@ const Module *BasicBlock::getModule() const { return getParent()->getParent(); } -const TerminatorInst *BasicBlock::getTerminator() const { - if (InstList.empty()) return nullptr; - return dyn_cast(&InstList.back()); +const Instruction *BasicBlock::getTerminator() const { + if (InstList.empty() || !InstList.back().isTerminator()) + return nullptr; + return &InstList.back(); } const CallInst *BasicBlock::getTerminatingMustTailCall() const { diff --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp index 4357948d5ab2..4cb0a52961cc 100644 --- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp @@ -601,7 +601,7 @@ static Instruction *insertSpills(SpillInfo &Spills, coro::Shape &Shape) { } // Sets the unwind edge of an instruction to a particular successor. -static void setUnwindEdgeTo(TerminatorInst *TI, BasicBlock *Succ) { +static void setUnwindEdgeTo(Instruction *TI, BasicBlock *Succ) { if (auto *II = dyn_cast(TI)) II->setUnwindDest(Succ); else if (auto *CS = dyn_cast(TI)) diff --git a/llvm/lib/Transforms/Scalar/GVNHoist.cpp b/llvm/lib/Transforms/Scalar/GVNHoist.cpp index 3043df9cca75..0797ce9adeaf 100644 --- a/llvm/lib/Transforms/Scalar/GVNHoist.cpp +++ b/llvm/lib/Transforms/Scalar/GVNHoist.cpp @@ -577,7 +577,7 @@ private: // Returns the edge via which an instruction in BB will get the values from. // Returns true when the values are flowing out to each edge. - bool valueAnticipable(CHIArgs C, TerminatorInst *TI) const { + bool valueAnticipable(CHIArgs C, Instruction *TI) const { if (TI->getNumSuccessors() > (unsigned)size(C)) return false; // Not enough args in this CHI. diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 79b575b78cdd..5fdbf2190090 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -1536,12 +1536,12 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, // Check for terminator values (e.g. invoke). for (unsigned j = 0; j < VL.size(); ++j) for (unsigned i = 0, e = PH->getNumIncomingValues(); i < e; ++i) { - TerminatorInst *Term = dyn_cast( - cast(VL[j])->getIncomingValueForBlock(PH->getIncomingBlock(i))); - if (Term) { - LLVM_DEBUG( - dbgs() - << "SLP: Need to swizzle PHINodes (TerminatorInst use).\n"); + Instruction *Term = dyn_cast( + cast(VL[j])->getIncomingValueForBlock( + PH->getIncomingBlock(i))); + if (Term && Term->isTerminator()) { + LLVM_DEBUG(dbgs() + << "SLP: Need to swizzle PHINodes (terminator use).\n"); BS.cancelScheduling(VL, VL0); newTreeEntry(VL, false, UserTreeIdx, ReuseShuffleIndicies); return; @@ -3652,7 +3652,7 @@ BoUpSLP::vectorizeTree(ExtraValueToDebugLocsMap &ExternallyUsedValues) { if (PHINode *PH = dyn_cast(User)) { for (int i = 0, e = PH->getNumIncomingValues(); i != e; ++i) { if (PH->getIncomingValue(i) == Scalar) { - TerminatorInst *IncomingTerminator = + Instruction *IncomingTerminator = PH->getIncomingBlock(i)->getTerminator(); if (isa(IncomingTerminator)) { Builder.SetInsertPoint(VecI->getParent(), @@ -3960,7 +3960,7 @@ bool BoUpSLP::BlockScheduling::extendSchedulingRegion(Value *V, ScheduleEnd = I->getNextNode(); if (isOneOf(S, I) != I) CheckSheduleForI(I); - assert(ScheduleEnd && "tried to vectorize a TerminatorInst?"); + assert(ScheduleEnd && "tried to vectorize a terminator?"); LLVM_DEBUG(dbgs() << "SLP: initialize schedule region to " << *I << "\n"); return true; } @@ -3996,7 +3996,7 @@ bool BoUpSLP::BlockScheduling::extendSchedulingRegion(Value *V, ScheduleEnd = I->getNextNode(); if (isOneOf(S, I) != I) CheckSheduleForI(I); - assert(ScheduleEnd && "tried to vectorize a TerminatorInst?"); + assert(ScheduleEnd && "tried to vectorize a terminator?"); LLVM_DEBUG(dbgs() << "SLP: extend schedule region end to " << *I << "\n"); return true; diff --git a/llvm/tools/bugpoint/CrashDebugger.cpp b/llvm/tools/bugpoint/CrashDebugger.cpp index e973bfef4dc6..a50ff4c255bd 100644 --- a/llvm/tools/bugpoint/CrashDebugger.cpp +++ b/llvm/tools/bugpoint/CrashDebugger.cpp @@ -409,7 +409,7 @@ bool ReduceCrashingBlocks::TestBlocks(std::vector &BBs) { for (BasicBlock *Succ : successors(&BB)) Succ->removePredecessor(&BB); - TerminatorInst *BBTerm = BB.getTerminator(); + Instruction *BBTerm = BB.getTerminator(); if (BBTerm->isEHPad() || BBTerm->getType()->isTokenTy()) continue; if (!BBTerm->getType()->isVoidTy()) diff --git a/llvm/tools/llvm-diff/DifferenceEngine.cpp b/llvm/tools/llvm-diff/DifferenceEngine.cpp index b2673c1407f4..acff8bb3e89b 100644 --- a/llvm/tools/llvm-diff/DifferenceEngine.cpp +++ b/llvm/tools/llvm-diff/DifferenceEngine.cpp @@ -629,8 +629,8 @@ void FunctionDifferenceEngine::runBlockDiff(BasicBlock::iterator LStart, // If the terminators have different kinds, but one is an invoke and the // other is an unconditional branch immediately following a call, unify // the results and the destinations. - TerminatorInst *LTerm = LStart->getParent()->getTerminator(); - TerminatorInst *RTerm = RStart->getParent()->getTerminator(); + Instruction *LTerm = LStart->getParent()->getTerminator(); + Instruction *RTerm = RStart->getParent()->getTerminator(); if (isa(LTerm) && isa(RTerm)) { if (cast(LTerm)->isConditional()) return; BasicBlock::iterator I = LTerm->getIterator(); diff --git a/llvm/unittests/IR/DominatorTreeTest.cpp b/llvm/unittests/IR/DominatorTreeTest.cpp index cf81623d0d17..7539bbc860bd 100644 --- a/llvm/unittests/IR/DominatorTreeTest.cpp +++ b/llvm/unittests/IR/DominatorTreeTest.cpp @@ -301,7 +301,7 @@ TEST(DominatorTree, NonUniqueEdges) { BasicBlock *BB1 = &*FI++; BasicBlock *BB2 = &*FI++; - const TerminatorInst *TI = BB0->getTerminator(); + const Instruction *TI = BB0->getTerminator(); assert(TI->getNumSuccessors() == 3 && "Switch has three successors"); BasicBlockEdge Edge_BB0_BB2(BB0, TI->getSuccessor(0)); diff --git a/llvm/unittests/IR/IRBuilderTest.cpp b/llvm/unittests/IR/IRBuilderTest.cpp index 713c0a14f66a..be29b41309a4 100644 --- a/llvm/unittests/IR/IRBuilderTest.cpp +++ b/llvm/unittests/IR/IRBuilderTest.cpp @@ -160,7 +160,7 @@ TEST_F(IRBuilderTest, CreateCondBr) { BasicBlock *FBB = BasicBlock::Create(Ctx, "", F); BranchInst *BI = Builder.CreateCondBr(Builder.getTrue(), TBB, FBB); - TerminatorInst *TI = BB->getTerminator(); + Instruction *TI = BB->getTerminator(); EXPECT_EQ(BI, TI); EXPECT_EQ(2u, TI->getNumSuccessors()); EXPECT_EQ(TBB, TI->getSuccessor(0)); diff --git a/polly/include/polly/Support/ScopHelper.h b/polly/include/polly/Support/ScopHelper.h index b7455e786b39..4fec7710d01f 100644 --- a/polly/include/polly/Support/ScopHelper.h +++ b/polly/include/polly/Support/ScopHelper.h @@ -382,7 +382,7 @@ bool isErrorBlock(llvm::BasicBlock &BB, const llvm::Region &R, /// @param TI The terminator to get the condition from. /// /// @return The condition of @p TI and nullptr if none could be extracted. -llvm::Value *getConditionFromTerminator(llvm::TerminatorInst *TI); +llvm::Value *getConditionFromTerminator(llvm::Instruction *TI); /// Check if @p LInst can be hoisted in @p R. /// diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp index 480589e1f221..9502f324fc9d 100644 --- a/polly/lib/Analysis/ScopDetection.cpp +++ b/polly/lib/Analysis/ScopDetection.cpp @@ -657,7 +657,7 @@ bool ScopDetection::isValidCFG(BasicBlock &BB, bool IsLoopBranch, DetectionContext &Context) const { Region &CurRegion = Context.CurRegion; - TerminatorInst *TI = BB.getTerminator(); + Instruction *TI = BB.getTerminator(); if (AllowUnreachable && isa(TI)) return true; @@ -1756,7 +1756,7 @@ bool ScopDetection::isReducibleRegion(Region &R, DebugLoc &DbgLoc) const { DFSStack.pop(); // Loop to iterate over the successors of current BB. - const TerminatorInst *TInst = CurrBB->getTerminator(); + const Instruction *TInst = CurrBB->getTerminator(); unsigned NSucc = TInst->getNumSuccessors(); for (unsigned I = AdjacentBlockIndex; I < NSucc; ++I, ++AdjacentBlockIndex) { diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp index 9e8ee9116a93..896a1b6b4611 100644 --- a/polly/lib/Analysis/ScopInfo.cpp +++ b/polly/lib/Analysis/ScopInfo.cpp @@ -1502,7 +1502,7 @@ buildUnsignedConditionSets(Scop &S, BasicBlock *BB, Value *Condition, /// context under which @p Condition is true/false will be returned as the /// new elements of @p ConditionSets. bool buildConditionSets(Scop &S, BasicBlock *BB, Value *Condition, - TerminatorInst *TI, Loop *L, __isl_keep isl_set *Domain, + Instruction *TI, Loop *L, __isl_keep isl_set *Domain, DenseMap &InvalidDomainMap, SmallVectorImpl<__isl_give isl_set *> &ConditionSets) { ScalarEvolution &SE = *S.getSE(); @@ -1642,7 +1642,7 @@ bool buildConditionSets(Scop &S, BasicBlock *BB, Value *Condition, /// This will fill @p ConditionSets with the conditions under which control /// will be moved from @p TI to its successors. Hence, @p ConditionSets will /// have as many elements as @p TI has successors. -bool buildConditionSets(Scop &S, BasicBlock *BB, TerminatorInst *TI, Loop *L, +bool buildConditionSets(Scop &S, BasicBlock *BB, Instruction *TI, Loop *L, __isl_keep isl_set *Domain, DenseMap &InvalidDomainMap, SmallVectorImpl<__isl_give isl_set *> &ConditionSets) { @@ -2393,7 +2393,7 @@ static inline BasicBlock *getRegionNodeBasicBlock(RegionNode *RN) { /// Return the @p idx'th block that is executed after @p RN. static inline BasicBlock * -getRegionNodeSuccessor(RegionNode *RN, TerminatorInst *TI, unsigned idx) { +getRegionNodeSuccessor(RegionNode *RN, Instruction *TI, unsigned idx) { if (RN->isSubRegion()) { assert(idx == 0); return RN->getNodeAs()->getExit(); @@ -2743,7 +2743,7 @@ bool Scop::buildDomainsWithBranchConstraints( HasErrorBlock = true; BasicBlock *BB = getRegionNodeBasicBlock(RN); - TerminatorInst *TI = BB->getTerminator(); + Instruction *TI = BB->getTerminator(); if (isa(TI)) continue; @@ -2982,7 +2982,7 @@ bool Scop::addLoopBoundsToHeaderDomain( isl::set BackedgeCondition = nullptr; - TerminatorInst *TI = LatchBB->getTerminator(); + Instruction *TI = LatchBB->getTerminator(); BranchInst *BI = dyn_cast(TI); assert(BI && "Only branch instructions allowed in loop latches"); diff --git a/polly/lib/CodeGen/BlockGenerators.cpp b/polly/lib/CodeGen/BlockGenerators.cpp index 3a5867bb1c20..2248f158c79c 100644 --- a/polly/lib/CodeGen/BlockGenerators.cpp +++ b/polly/lib/CodeGen/BlockGenerators.cpp @@ -1566,7 +1566,7 @@ void RegionGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT <S, BasicBlock *BBCopyStart = StartBlockMap[BB]; BasicBlock *BBCopyEnd = EndBlockMap[BB]; - TerminatorInst *TI = BB->getTerminator(); + Instruction *TI = BB->getTerminator(); if (isa(TI)) { while (!BBCopyEnd->empty()) BBCopyEnd->begin()->eraseFromParent(); diff --git a/polly/lib/Support/ScopHelper.cpp b/polly/lib/Support/ScopHelper.cpp index 8d392300bb36..fedb7b06d847 100644 --- a/polly/lib/Support/ScopHelper.cpp +++ b/polly/lib/Support/ScopHelper.cpp @@ -440,7 +440,7 @@ bool polly::isErrorBlock(BasicBlock &BB, const Region &R, LoopInfo &LI, return false; } -Value *polly::getConditionFromTerminator(TerminatorInst *TI) { +Value *polly::getConditionFromTerminator(Instruction *TI) { if (BranchInst *BR = dyn_cast(TI)) { if (BR->isUnconditional()) return ConstantInt::getTrue(Type::getInt1Ty(TI->getContext()));