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:
Reid Kleckner
2014-08-12 00:05:15 +00:00
parent f73ae4fbf6
commit e31acf239a
3 changed files with 45 additions and 30 deletions

View File

@@ -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,