Move helper for getting a terminating musttail call to BasicBlock
No functional change. To be used in future commits that need to look for such instructions. Reviewed By: rafael Differential Revision: http://reviews.llvm.org/D4504 llvm-svn: 215413
This commit is contained in:
@@ -138,6 +138,37 @@ const TerminatorInst *BasicBlock::getTerminator() const {
|
||||
return dyn_cast<TerminatorInst>(&InstList.back());
|
||||
}
|
||||
|
||||
CallInst *BasicBlock::getTerminatingMustTailCall() {
|
||||
if (InstList.empty())
|
||||
return nullptr;
|
||||
ReturnInst *RI = dyn_cast<ReturnInst>(&InstList.back());
|
||||
if (!RI || RI == &InstList.front())
|
||||
return nullptr;
|
||||
|
||||
Instruction *Prev = RI->getPrevNode();
|
||||
if (!Prev)
|
||||
return nullptr;
|
||||
|
||||
if (Value *RV = RI->getReturnValue()) {
|
||||
if (RV != Prev)
|
||||
return nullptr;
|
||||
|
||||
// Look through the optional bitcast.
|
||||
if (auto *BI = dyn_cast<BitCastInst>(Prev)) {
|
||||
RV = BI->getOperand(0);
|
||||
Prev = BI->getPrevNode();
|
||||
if (!Prev || RV != Prev)
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (auto *CI = dyn_cast<CallInst>(Prev)) {
|
||||
if (CI->isMustTailCall())
|
||||
return CI;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Instruction* BasicBlock::getFirstNonPHI() {
|
||||
BasicBlock::iterator i = begin();
|
||||
// All valid basic blocks should have a terminator,
|
||||
|
||||
Reference in New Issue
Block a user