mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 10:42:39 +01:00
[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. llvm-svn: 344504
This commit is contained in:
parent
7e3e101b48
commit
cdfd07538f
@ -38,7 +38,6 @@ class LandingPadInst;
|
|||||||
class LLVMContext;
|
class LLVMContext;
|
||||||
class Module;
|
class Module;
|
||||||
class PHINode;
|
class PHINode;
|
||||||
class TerminatorInst;
|
|
||||||
class ValueSymbolTable;
|
class ValueSymbolTable;
|
||||||
|
|
||||||
/// LLVM Basic Block Representation
|
/// LLVM Basic Block Representation
|
||||||
@ -50,12 +49,12 @@ class ValueSymbolTable;
|
|||||||
/// represents a label to which a branch can jump.
|
/// represents a label to which a branch can jump.
|
||||||
///
|
///
|
||||||
/// A well formed basic block is formed of a list of non-terminating
|
/// A well formed basic block is formed of a list of non-terminating
|
||||||
/// instructions followed by a single TerminatorInst instruction.
|
/// instructions followed by a single terminator instruction. Terminator
|
||||||
/// TerminatorInst's may not occur in the middle of basic blocks, and must
|
/// instructions may not occur in the middle of basic blocks, and must terminate
|
||||||
/// terminate the blocks. The BasicBlock class allows malformed basic blocks to
|
/// the blocks. The BasicBlock class allows malformed basic blocks to occur
|
||||||
/// occur because it may be useful in the intermediate stage of constructing or
|
/// because it may be useful in the intermediate stage of constructing or
|
||||||
/// modifying a program. However, the verifier will ensure that basic blocks
|
/// modifying a program. However, the verifier will ensure that basic blocks are
|
||||||
/// are "well formed".
|
/// "well formed".
|
||||||
class BasicBlock final : public Value, // Basic blocks are data objects also
|
class BasicBlock final : public Value, // Basic blocks are data objects also
|
||||||
public ilist_node_with_parent<BasicBlock, Function> {
|
public ilist_node_with_parent<BasicBlock, Function> {
|
||||||
public:
|
public:
|
||||||
@ -120,10 +119,10 @@ public:
|
|||||||
|
|
||||||
/// Returns the terminator instruction if the block is well formed or null
|
/// Returns the terminator instruction if the block is well formed or null
|
||||||
/// if the block is not well formed.
|
/// if the block is not well formed.
|
||||||
const TerminatorInst *getTerminator() const LLVM_READONLY;
|
const Instruction *getTerminator() const LLVM_READONLY;
|
||||||
TerminatorInst *getTerminator() {
|
Instruction *getTerminator() {
|
||||||
return const_cast<TerminatorInst *>(
|
return const_cast<Instruction *>(
|
||||||
static_cast<const BasicBlock *>(this)->getTerminator());
|
static_cast<const BasicBlock *>(this)->getTerminator());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the call instruction calling \@llvm.experimental.deoptimize
|
/// Returns the call instruction calling \@llvm.experimental.deoptimize
|
||||||
|
@ -135,9 +135,10 @@ const Module *BasicBlock::getModule() const {
|
|||||||
return getParent()->getParent();
|
return getParent()->getParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
const TerminatorInst *BasicBlock::getTerminator() const {
|
const Instruction *BasicBlock::getTerminator() const {
|
||||||
if (InstList.empty()) return nullptr;
|
if (InstList.empty() || !InstList.back().isTerminator())
|
||||||
return dyn_cast<TerminatorInst>(&InstList.back());
|
return nullptr;
|
||||||
|
return &InstList.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
const CallInst *BasicBlock::getTerminatingMustTailCall() const {
|
const CallInst *BasicBlock::getTerminatingMustTailCall() const {
|
||||||
|
@ -601,7 +601,7 @@ static Instruction *insertSpills(SpillInfo &Spills, coro::Shape &Shape) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sets the unwind edge of an instruction to a particular successor.
|
// 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<InvokeInst>(TI))
|
if (auto *II = dyn_cast<InvokeInst>(TI))
|
||||||
II->setUnwindDest(Succ);
|
II->setUnwindDest(Succ);
|
||||||
else if (auto *CS = dyn_cast<CatchSwitchInst>(TI))
|
else if (auto *CS = dyn_cast<CatchSwitchInst>(TI))
|
||||||
|
@ -577,7 +577,7 @@ private:
|
|||||||
// Returns the edge via which an instruction in BB will get the values from.
|
// 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.
|
// 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))
|
if (TI->getNumSuccessors() > (unsigned)size(C))
|
||||||
return false; // Not enough args in this CHI.
|
return false; // Not enough args in this CHI.
|
||||||
|
|
||||||
|
@ -1536,12 +1536,12 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
|
|||||||
// Check for terminator values (e.g. invoke).
|
// Check for terminator values (e.g. invoke).
|
||||||
for (unsigned j = 0; j < VL.size(); ++j)
|
for (unsigned j = 0; j < VL.size(); ++j)
|
||||||
for (unsigned i = 0, e = PH->getNumIncomingValues(); i < e; ++i) {
|
for (unsigned i = 0, e = PH->getNumIncomingValues(); i < e; ++i) {
|
||||||
TerminatorInst *Term = dyn_cast<TerminatorInst>(
|
Instruction *Term = dyn_cast<Instruction>(
|
||||||
cast<PHINode>(VL[j])->getIncomingValueForBlock(PH->getIncomingBlock(i)));
|
cast<PHINode>(VL[j])->getIncomingValueForBlock(
|
||||||
if (Term) {
|
PH->getIncomingBlock(i)));
|
||||||
LLVM_DEBUG(
|
if (Term && Term->isTerminator()) {
|
||||||
dbgs()
|
LLVM_DEBUG(dbgs()
|
||||||
<< "SLP: Need to swizzle PHINodes (TerminatorInst use).\n");
|
<< "SLP: Need to swizzle PHINodes (terminator use).\n");
|
||||||
BS.cancelScheduling(VL, VL0);
|
BS.cancelScheduling(VL, VL0);
|
||||||
newTreeEntry(VL, false, UserTreeIdx, ReuseShuffleIndicies);
|
newTreeEntry(VL, false, UserTreeIdx, ReuseShuffleIndicies);
|
||||||
return;
|
return;
|
||||||
@ -3652,7 +3652,7 @@ BoUpSLP::vectorizeTree(ExtraValueToDebugLocsMap &ExternallyUsedValues) {
|
|||||||
if (PHINode *PH = dyn_cast<PHINode>(User)) {
|
if (PHINode *PH = dyn_cast<PHINode>(User)) {
|
||||||
for (int i = 0, e = PH->getNumIncomingValues(); i != e; ++i) {
|
for (int i = 0, e = PH->getNumIncomingValues(); i != e; ++i) {
|
||||||
if (PH->getIncomingValue(i) == Scalar) {
|
if (PH->getIncomingValue(i) == Scalar) {
|
||||||
TerminatorInst *IncomingTerminator =
|
Instruction *IncomingTerminator =
|
||||||
PH->getIncomingBlock(i)->getTerminator();
|
PH->getIncomingBlock(i)->getTerminator();
|
||||||
if (isa<CatchSwitchInst>(IncomingTerminator)) {
|
if (isa<CatchSwitchInst>(IncomingTerminator)) {
|
||||||
Builder.SetInsertPoint(VecI->getParent(),
|
Builder.SetInsertPoint(VecI->getParent(),
|
||||||
@ -3960,7 +3960,7 @@ bool BoUpSLP::BlockScheduling::extendSchedulingRegion(Value *V,
|
|||||||
ScheduleEnd = I->getNextNode();
|
ScheduleEnd = I->getNextNode();
|
||||||
if (isOneOf(S, I) != I)
|
if (isOneOf(S, I) != I)
|
||||||
CheckSheduleForI(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");
|
LLVM_DEBUG(dbgs() << "SLP: initialize schedule region to " << *I << "\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -3996,7 +3996,7 @@ bool BoUpSLP::BlockScheduling::extendSchedulingRegion(Value *V,
|
|||||||
ScheduleEnd = I->getNextNode();
|
ScheduleEnd = I->getNextNode();
|
||||||
if (isOneOf(S, I) != I)
|
if (isOneOf(S, I) != I)
|
||||||
CheckSheduleForI(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
|
LLVM_DEBUG(dbgs() << "SLP: extend schedule region end to " << *I
|
||||||
<< "\n");
|
<< "\n");
|
||||||
return true;
|
return true;
|
||||||
|
@ -409,7 +409,7 @@ bool ReduceCrashingBlocks::TestBlocks(std::vector<const BasicBlock *> &BBs) {
|
|||||||
for (BasicBlock *Succ : successors(&BB))
|
for (BasicBlock *Succ : successors(&BB))
|
||||||
Succ->removePredecessor(&BB);
|
Succ->removePredecessor(&BB);
|
||||||
|
|
||||||
TerminatorInst *BBTerm = BB.getTerminator();
|
Instruction *BBTerm = BB.getTerminator();
|
||||||
if (BBTerm->isEHPad() || BBTerm->getType()->isTokenTy())
|
if (BBTerm->isEHPad() || BBTerm->getType()->isTokenTy())
|
||||||
continue;
|
continue;
|
||||||
if (!BBTerm->getType()->isVoidTy())
|
if (!BBTerm->getType()->isVoidTy())
|
||||||
|
@ -629,8 +629,8 @@ void FunctionDifferenceEngine::runBlockDiff(BasicBlock::iterator LStart,
|
|||||||
// If the terminators have different kinds, but one is an invoke and the
|
// If the terminators have different kinds, but one is an invoke and the
|
||||||
// other is an unconditional branch immediately following a call, unify
|
// other is an unconditional branch immediately following a call, unify
|
||||||
// the results and the destinations.
|
// the results and the destinations.
|
||||||
TerminatorInst *LTerm = LStart->getParent()->getTerminator();
|
Instruction *LTerm = LStart->getParent()->getTerminator();
|
||||||
TerminatorInst *RTerm = RStart->getParent()->getTerminator();
|
Instruction *RTerm = RStart->getParent()->getTerminator();
|
||||||
if (isa<BranchInst>(LTerm) && isa<InvokeInst>(RTerm)) {
|
if (isa<BranchInst>(LTerm) && isa<InvokeInst>(RTerm)) {
|
||||||
if (cast<BranchInst>(LTerm)->isConditional()) return;
|
if (cast<BranchInst>(LTerm)->isConditional()) return;
|
||||||
BasicBlock::iterator I = LTerm->getIterator();
|
BasicBlock::iterator I = LTerm->getIterator();
|
||||||
|
@ -301,7 +301,7 @@ TEST(DominatorTree, NonUniqueEdges) {
|
|||||||
BasicBlock *BB1 = &*FI++;
|
BasicBlock *BB1 = &*FI++;
|
||||||
BasicBlock *BB2 = &*FI++;
|
BasicBlock *BB2 = &*FI++;
|
||||||
|
|
||||||
const TerminatorInst *TI = BB0->getTerminator();
|
const Instruction *TI = BB0->getTerminator();
|
||||||
assert(TI->getNumSuccessors() == 3 && "Switch has three successors");
|
assert(TI->getNumSuccessors() == 3 && "Switch has three successors");
|
||||||
|
|
||||||
BasicBlockEdge Edge_BB0_BB2(BB0, TI->getSuccessor(0));
|
BasicBlockEdge Edge_BB0_BB2(BB0, TI->getSuccessor(0));
|
||||||
|
@ -160,7 +160,7 @@ TEST_F(IRBuilderTest, CreateCondBr) {
|
|||||||
BasicBlock *FBB = BasicBlock::Create(Ctx, "", F);
|
BasicBlock *FBB = BasicBlock::Create(Ctx, "", F);
|
||||||
|
|
||||||
BranchInst *BI = Builder.CreateCondBr(Builder.getTrue(), TBB, FBB);
|
BranchInst *BI = Builder.CreateCondBr(Builder.getTrue(), TBB, FBB);
|
||||||
TerminatorInst *TI = BB->getTerminator();
|
Instruction *TI = BB->getTerminator();
|
||||||
EXPECT_EQ(BI, TI);
|
EXPECT_EQ(BI, TI);
|
||||||
EXPECT_EQ(2u, TI->getNumSuccessors());
|
EXPECT_EQ(2u, TI->getNumSuccessors());
|
||||||
EXPECT_EQ(TBB, TI->getSuccessor(0));
|
EXPECT_EQ(TBB, TI->getSuccessor(0));
|
||||||
|
Loading…
Reference in New Issue
Block a user