llvm.org GIT mirror llvm / d8d8371
[TI removal] Make `getTerminator()` return a generic `Instruction`. This removes the primary remaining API producing `TerminatorInst` which will reduce the rate at which code is introduced trying to use it and generally make it much easier to remove the remaining APIs across the codebase. Also clean up some of the stragglers that the previous mechanical update of variables missed. Users of LLVM and out-of-tree code generally will need to update any explicit variable types to handle this. Replacing `TerminatorInst` with `Instruction` (or `auto`) almost always works. Most of these edits were made in prior commits using the perl one-liner: ``` perl -i -ple 's/TerminatorInst(\b.* = .*getTerminator\(\))/Instruction\1/g' ``` This also my break some rare use cases where people overload for both `Instruction` and `TerminatorInst`, but these should be easily fixed by removing the `TerminatorInst` overload. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@344504 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 2 years ago
9 changed file(s) with 30 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
3737 class LLVMContext;
3838 class Module;
3939 class PHINode;
40 class TerminatorInst;
4140 class ValueSymbolTable;
4241
4342 /// LLVM Basic Block Representation
4948 /// represents a label to which a branch can jump.
5049 ///
5150 /// A well formed basic block is formed of a list of non-terminating
52 /// instructions followed by a single TerminatorInst instruction.
53 /// TerminatorInst's may not occur in the middle of basic blocks, and must
54 /// terminate the blocks. The BasicBlock class allows malformed basic blocks to
55 /// occur because it may be useful in the intermediate stage of constructing or
56 /// modifying a program. However, the verifier will ensure that basic blocks
57 /// are "well formed".
51 /// instructions followed by a single terminator instruction. Terminator
52 /// instructions may not occur in the middle of basic blocks, and must terminate
53 /// the blocks. The BasicBlock class allows malformed basic blocks to occur
54 /// because it may be useful in the intermediate stage of constructing or
55 /// modifying a program. However, the verifier will ensure that basic blocks are
56 /// "well formed".
5857 class BasicBlock final : public Value, // Basic blocks are data objects also
5958 public ilist_node_with_parent {
6059 public:
119118
120119 /// Returns the terminator instruction if the block is well formed or null
121120 /// if the block is not well formed.
122 const TerminatorInst *getTerminator() const LLVM_READONLY;
123 TerminatorInst *getTerminator() {
124 return const_cast(
125 static_cast(this)->getTerminator());
121 const Instruction *getTerminator() const LLVM_READONLY;
122 Instruction *getTerminator() {
123 return const_cast(
124 static_cast(this)->getTerminator());
126125 }
127126
128127 /// Returns the call instruction calling \@llvm.experimental.deoptimize
134134 return getParent()->getParent();
135135 }
136136
137 const TerminatorInst *BasicBlock::getTerminator() const {
138 if (InstList.empty()) return nullptr;
139 return dyn_cast(&InstList.back());
137 const Instruction *BasicBlock::getTerminator() const {
138 if (InstList.empty() || !InstList.back().isTerminator())
139 return nullptr;
140 return &InstList.back();
140141 }
141142
142143 const CallInst *BasicBlock::getTerminatingMustTailCall() const {
600600 }
601601
602602 // Sets the unwind edge of an instruction to a particular successor.
603 static void setUnwindEdgeTo(TerminatorInst *TI, BasicBlock *Succ) {
603 static void setUnwindEdgeTo(Instruction *TI, BasicBlock *Succ) {
604604 if (auto *II = dyn_cast(TI))
605605 II->setUnwindDest(Succ);
606606 else if (auto *CS = dyn_cast(TI))
576576 // Returns the edge via which an instruction in BB will get the values from.
577577
578578 // Returns true when the values are flowing out to each edge.
579 bool valueAnticipable(CHIArgs C, TerminatorInst *TI) const {
579 bool valueAnticipable(CHIArgs C, Instruction *TI) const {
580580 if (TI->getNumSuccessors() > (unsigned)size(C))
581581 return false; // Not enough args in this CHI.
582582
15351535 // Check for terminator values (e.g. invoke).
15361536 for (unsigned j = 0; j < VL.size(); ++j)
15371537 for (unsigned i = 0, e = PH->getNumIncomingValues(); i < e; ++i) {
1538 TerminatorInst *Term = dyn_cast(
1539 cast(VL[j])->getIncomingValueForBlock(PH->getIncomingBlock(i)));
1540 if (Term) {
1541 LLVM_DEBUG(
1542 dbgs()
1543 << "SLP: Need to swizzle PHINodes (TerminatorInst use).\n");
1538 Instruction *Term = dyn_cast(
1539 cast(VL[j])->getIncomingValueForBlock(
1540 PH->getIncomingBlock(i)));
1541 if (Term && Term->isTerminator()) {
1542 LLVM_DEBUG(dbgs()
1543 << "SLP: Need to swizzle PHINodes (terminator use).\n");
15441544 BS.cancelScheduling(VL, VL0);
15451545 newTreeEntry(VL, false, UserTreeIdx, ReuseShuffleIndicies);
15461546 return;
36513651 if (PHINode *PH = dyn_cast(User)) {
36523652 for (int i = 0, e = PH->getNumIncomingValues(); i != e; ++i) {
36533653 if (PH->getIncomingValue(i) == Scalar) {
3654 TerminatorInst *IncomingTerminator =
3654 Instruction *IncomingTerminator =
36553655 PH->getIncomingBlock(i)->getTerminator();
36563656 if (isa(IncomingTerminator)) {
36573657 Builder.SetInsertPoint(VecI->getParent(),
39593959 ScheduleEnd = I->getNextNode();
39603960 if (isOneOf(S, I) != I)
39613961 CheckSheduleForI(I);
3962 assert(ScheduleEnd && "tried to vectorize a TerminatorInst?");
3962 assert(ScheduleEnd && "tried to vectorize a terminator?");
39633963 LLVM_DEBUG(dbgs() << "SLP: initialize schedule region to " << *I << "\n");
39643964 return true;
39653965 }
39953995 ScheduleEnd = I->getNextNode();
39963996 if (isOneOf(S, I) != I)
39973997 CheckSheduleForI(I);
3998 assert(ScheduleEnd && "tried to vectorize a TerminatorInst?");
3998 assert(ScheduleEnd && "tried to vectorize a terminator?");
39993999 LLVM_DEBUG(dbgs() << "SLP: extend schedule region end to " << *I
40004000 << "\n");
40014001 return true;
408408 for (BasicBlock *Succ : successors(&BB))
409409 Succ->removePredecessor(&BB);
410410
411 TerminatorInst *BBTerm = BB.getTerminator();
411 Instruction *BBTerm = BB.getTerminator();
412412 if (BBTerm->isEHPad() || BBTerm->getType()->isTokenTy())
413413 continue;
414414 if (!BBTerm->getType()->isVoidTy())
628628 // If the terminators have different kinds, but one is an invoke and the
629629 // other is an unconditional branch immediately following a call, unify
630630 // the results and the destinations.
631 TerminatorInst *LTerm = LStart->getParent()->getTerminator();
632 TerminatorInst *RTerm = RStart->getParent()->getTerminator();
631 Instruction *LTerm = LStart->getParent()->getTerminator();
632 Instruction *RTerm = RStart->getParent()->getTerminator();
633633 if (isa(LTerm) && isa(RTerm)) {
634634 if (cast(LTerm)->isConditional()) return;
635635 BasicBlock::iterator I = LTerm->getIterator();
300300 BasicBlock *BB1 = &*FI++;
301301 BasicBlock *BB2 = &*FI++;
302302
303 const TerminatorInst *TI = BB0->getTerminator();
303 const Instruction *TI = BB0->getTerminator();
304304 assert(TI->getNumSuccessors() == 3 && "Switch has three successors");
305305
306306 BasicBlockEdge Edge_BB0_BB2(BB0, TI->getSuccessor(0));
159159 BasicBlock *FBB = BasicBlock::Create(Ctx, "", F);
160160
161161 BranchInst *BI = Builder.CreateCondBr(Builder.getTrue(), TBB, FBB);
162 TerminatorInst *TI = BB->getTerminator();
162 Instruction *TI = BB->getTerminator();
163163 EXPECT_EQ(BI, TI);
164164 EXPECT_EQ(2u, TI->getNumSuccessors());
165165 EXPECT_EQ(TBB, TI->getSuccessor(0));