[TI removal] Rework InstVisitor to support visiting instructions that

are terminators without relying on the specific `TerminatorInst` type.

This required cleaning up two users of `InstVisitor`s usage of
`TerminatorInst` as well.

llvm-svn: 344503
This commit is contained in:
Chandler Carruth 2018-10-15 10:10:54 +00:00
parent edb12a838a
commit 52eaaf3ff8
3 changed files with 56 additions and 35 deletions

View File

@ -166,15 +166,6 @@ public:
// Specific Instruction type classes... note that all of the casts are
// necessary because we use the instruction classes as opaque types...
//
RetTy visitReturnInst(ReturnInst &I) { DELEGATE(TerminatorInst);}
RetTy visitBranchInst(BranchInst &I) { DELEGATE(TerminatorInst);}
RetTy visitSwitchInst(SwitchInst &I) { DELEGATE(TerminatorInst);}
RetTy visitIndirectBrInst(IndirectBrInst &I) { DELEGATE(TerminatorInst);}
RetTy visitResumeInst(ResumeInst &I) { DELEGATE(TerminatorInst);}
RetTy visitUnreachableInst(UnreachableInst &I) { DELEGATE(TerminatorInst);}
RetTy visitCleanupReturnInst(CleanupReturnInst &I) { DELEGATE(TerminatorInst);}
RetTy visitCatchReturnInst(CatchReturnInst &I) { DELEGATE(TerminatorInst); }
RetTy visitCatchSwitchInst(CatchSwitchInst &I) { DELEGATE(TerminatorInst);}
RetTy visitICmpInst(ICmpInst &I) { DELEGATE(CmpInst);}
RetTy visitFCmpInst(FCmpInst &I) { DELEGATE(CmpInst);}
RetTy visitAllocaInst(AllocaInst &I) { DELEGATE(UnaryInstruction);}
@ -236,6 +227,37 @@ public:
return static_cast<SubClass*>(this)->visitCallSite(&I);
}
// While terminators don't have a distinct type modeling them, we support
// intercepting them with dedicated a visitor callback.
RetTy visitReturnInst(ReturnInst &I) {
return static_cast<SubClass *>(this)->visitTerminator(I);
}
RetTy visitBranchInst(BranchInst &I) {
return static_cast<SubClass *>(this)->visitTerminator(I);
}
RetTy visitSwitchInst(SwitchInst &I) {
return static_cast<SubClass *>(this)->visitTerminator(I);
}
RetTy visitIndirectBrInst(IndirectBrInst &I) {
return static_cast<SubClass *>(this)->visitTerminator(I);
}
RetTy visitResumeInst(ResumeInst &I) {
return static_cast<SubClass *>(this)->visitTerminator(I);
}
RetTy visitUnreachableInst(UnreachableInst &I) {
return static_cast<SubClass *>(this)->visitTerminator(I);
}
RetTy visitCleanupReturnInst(CleanupReturnInst &I) {
return static_cast<SubClass *>(this)->visitTerminator(I);
}
RetTy visitCatchReturnInst(CatchReturnInst &I) {
return static_cast<SubClass *>(this)->visitTerminator(I);
}
RetTy visitCatchSwitchInst(CatchSwitchInst &I) {
return static_cast<SubClass *>(this)->visitTerminator(I);
}
RetTy visitTerminator(Instruction &I) { DELEGATE(Instruction);}
// Next level propagators: If the user does not overload a specific
// instruction type, they can overload one of these to get the whole class
// of instructions...
@ -243,7 +265,6 @@ public:
RetTy visitCastInst(CastInst &I) { DELEGATE(UnaryInstruction);}
RetTy visitBinaryOperator(BinaryOperator &I) { DELEGATE(Instruction);}
RetTy visitCmpInst(CmpInst &I) { DELEGATE(Instruction);}
RetTy visitTerminatorInst(TerminatorInst &I) { DELEGATE(Instruction);}
RetTy visitUnaryInstruction(UnaryInstruction &I){ DELEGATE(Instruction);}
// Provide a special visitor for a 'callsite' that visits both calls and
@ -256,7 +277,7 @@ public:
DELEGATE(Instruction);
assert(CS.isInvoke());
DELEGATE(TerminatorInst);
return static_cast<SubClass *>(this)->visitTerminator(I);
}
// If the user wants a 'default' case, they can choose to override this

View File

@ -287,7 +287,7 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
// Maps catchswitches and cleanuppads that unwind to siblings to the
// terminators that indicate the unwind, used to detect cycles therein.
MapVector<Instruction *, TerminatorInst *> SiblingFuncletInfo;
MapVector<Instruction *, Instruction *> SiblingFuncletInfo;
/// Cache of constants visited in search of ConstantExprs.
SmallPtrSet<const Constant *, 32> ConstantExprVisited;
@ -457,7 +457,7 @@ private:
void visitStoreInst(StoreInst &SI);
void verifyDominatesUse(Instruction &I, unsigned i);
void visitInstruction(Instruction &I);
void visitTerminatorInst(TerminatorInst &I);
void visitTerminator(Instruction &I);
void visitBranchInst(BranchInst &BI);
void visitReturnInst(ReturnInst &RI);
void visitSwitchInst(SwitchInst &SI);
@ -2009,7 +2009,7 @@ void Verifier::verifyFrameRecoverIndices() {
}
}
static Instruction *getSuccPad(TerminatorInst *Terminator) {
static Instruction *getSuccPad(Instruction *Terminator) {
BasicBlock *UnwindDest;
if (auto *II = dyn_cast<InvokeInst>(Terminator))
UnwindDest = II->getUnwindDest();
@ -2028,7 +2028,7 @@ void Verifier::verifySiblingFuncletUnwinds() {
if (Visited.count(PredPad))
continue;
Active.insert(PredPad);
TerminatorInst *Terminator = Pair.second;
Instruction *Terminator = Pair.second;
do {
Instruction *SuccPad = getSuccPad(Terminator);
if (Active.count(SuccPad)) {
@ -2037,7 +2037,7 @@ void Verifier::verifySiblingFuncletUnwinds() {
SmallVector<Instruction *, 8> CycleNodes;
do {
CycleNodes.push_back(CyclePad);
TerminatorInst *CycleTerminator = SiblingFuncletInfo[CyclePad];
Instruction *CycleTerminator = SiblingFuncletInfo[CyclePad];
if (CycleTerminator != CyclePad)
CycleNodes.push_back(CycleTerminator);
CyclePad = getSuccPad(CycleTerminator);
@ -2352,7 +2352,7 @@ void Verifier::visitBasicBlock(BasicBlock &BB) {
}
}
void Verifier::visitTerminatorInst(TerminatorInst &I) {
void Verifier::visitTerminator(Instruction &I) {
// Ensure that terminators only exist at the end of the basic block.
Assert(&I == I.getParent()->getTerminator(),
"Terminator found in the middle of a basic block!", I.getParent());
@ -2364,7 +2364,7 @@ void Verifier::visitBranchInst(BranchInst &BI) {
Assert(BI.getCondition()->getType()->isIntegerTy(1),
"Branch condition is not 'i1' type!", &BI, BI.getCondition());
}
visitTerminatorInst(BI);
visitTerminator(BI);
}
void Verifier::visitReturnInst(ReturnInst &RI) {
@ -2383,7 +2383,7 @@ void Verifier::visitReturnInst(ReturnInst &RI) {
// Check to make sure that the return value has necessary properties for
// terminators...
visitTerminatorInst(RI);
visitTerminator(RI);
}
void Verifier::visitSwitchInst(SwitchInst &SI) {
@ -2398,7 +2398,7 @@ void Verifier::visitSwitchInst(SwitchInst &SI) {
"Duplicate integer as switch case", &SI, Case.getCaseValue());
}
visitTerminatorInst(SI);
visitTerminator(SI);
}
void Verifier::visitIndirectBrInst(IndirectBrInst &BI) {
@ -2408,7 +2408,7 @@ void Verifier::visitIndirectBrInst(IndirectBrInst &BI) {
Assert(BI.getDestination(i)->getType()->isLabelTy(),
"Indirectbr destinations must all have pointer type!", &BI);
visitTerminatorInst(BI);
visitTerminator(BI);
}
void Verifier::visitSelectInst(SelectInst &SI) {
@ -2987,7 +2987,7 @@ void Verifier::visitInvokeInst(InvokeInst &II) {
"The unwind destination does not have an exception handling instruction!",
&II);
visitTerminatorInst(II);
visitTerminator(II);
}
/// visitBinaryOperator - Check that both arguments to the binary operator are
@ -3538,7 +3538,7 @@ void Verifier::visitResumeInst(ResumeInst &RI) {
"inside a function.",
&RI);
visitTerminatorInst(RI);
visitTerminator(RI);
}
void Verifier::visitCatchPadInst(CatchPadInst &CPI) {
@ -3566,7 +3566,7 @@ void Verifier::visitCatchReturnInst(CatchReturnInst &CatchReturn) {
"CatchReturnInst needs to be provided a CatchPad", &CatchReturn,
CatchReturn.getOperand(0));
visitTerminatorInst(CatchReturn);
visitTerminator(CatchReturn);
}
void Verifier::visitCleanupPadInst(CleanupPadInst &CPI) {
@ -3687,7 +3687,7 @@ void Verifier::visitFuncletPadInst(FuncletPadInst &FPI) {
// Record cleanup sibling unwinds for verifySiblingFuncletUnwinds
if (isa<CleanupPadInst>(&FPI) && !isa<ConstantTokenNone>(UnwindPad) &&
getParentPad(UnwindPad) == getParentPad(&FPI))
SiblingFuncletInfo[&FPI] = cast<TerminatorInst>(U);
SiblingFuncletInfo[&FPI] = cast<Instruction>(U);
}
}
// Make sure we visit all uses of FPI, but for nested pads stop as
@ -3788,7 +3788,7 @@ void Verifier::visitCatchSwitchInst(CatchSwitchInst &CatchSwitch) {
}
visitEHPadPredecessors(CatchSwitch);
visitTerminatorInst(CatchSwitch);
visitTerminator(CatchSwitch);
}
void Verifier::visitCleanupReturnInst(CleanupReturnInst &CRI) {
@ -3804,7 +3804,7 @@ void Verifier::visitCleanupReturnInst(CleanupReturnInst &CRI) {
&CRI);
}
visitTerminatorInst(CRI);
visitTerminator(CRI);
}
void Verifier::verifyDominatesUse(Instruction &I, unsigned i) {

View File

@ -563,7 +563,7 @@ private:
// getFeasibleSuccessors - Return a vector of booleans to indicate which
// successors are reachable from a given terminator instruction.
void getFeasibleSuccessors(TerminatorInst &TI, SmallVectorImpl<bool> &Succs);
void getFeasibleSuccessors(Instruction &TI, SmallVectorImpl<bool> &Succs);
// OperandChangedState - This method is invoked on all of the users of an
// instruction that was just changed state somehow. Based on this
@ -604,7 +604,7 @@ private:
// Terminators
void visitReturnInst(ReturnInst &I);
void visitTerminatorInst(TerminatorInst &TI);
void visitTerminator(Instruction &TI);
void visitCastInst(CastInst &I);
void visitSelectInst(SelectInst &I);
@ -615,7 +615,7 @@ private:
void visitCatchSwitchInst(CatchSwitchInst &CPI) {
markOverdefined(&CPI);
visitTerminatorInst(CPI);
visitTerminator(CPI);
}
// Instructions that cannot be folded away.
@ -630,12 +630,12 @@ private:
void visitInvokeInst (InvokeInst &II) {
visitCallSite(&II);
visitTerminatorInst(II);
visitTerminator(II);
}
void visitCallSite (CallSite CS);
void visitResumeInst (TerminatorInst &I) { /*returns void*/ }
void visitUnreachableInst(TerminatorInst &I) { /*returns void*/ }
void visitResumeInst (ResumeInst &I) { /*returns void*/ }
void visitUnreachableInst(UnreachableInst &I) { /*returns void*/ }
void visitFenceInst (FenceInst &I) { /*returns void*/ }
void visitInstruction(Instruction &I) {
@ -650,7 +650,7 @@ private:
// getFeasibleSuccessors - Return a vector of booleans to indicate which
// successors are reachable from a given terminator instruction.
void SCCPSolver::getFeasibleSuccessors(TerminatorInst &TI,
void SCCPSolver::getFeasibleSuccessors(Instruction &TI,
SmallVectorImpl<bool> &Succs) {
Succs.resize(TI.getNumSuccessors());
if (auto *BI = dyn_cast<BranchInst>(&TI)) {
@ -837,7 +837,7 @@ void SCCPSolver::visitReturnInst(ReturnInst &I) {
}
}
void SCCPSolver::visitTerminatorInst(TerminatorInst &TI) {
void SCCPSolver::visitTerminator(Instruction &TI) {
SmallVector<bool, 16> SuccFeasible;
getFeasibleSuccessors(TI, SuccFeasible);