summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/BasicBlock.cpp
diff options
context:
space:
mode:
authorReid Kleckner <reid@kleckner.net>2014-08-12 00:05:15 +0000
committerReid Kleckner <reid@kleckner.net>2014-08-12 00:05:15 +0000
commite31acf239a94ac402ce568867cf93cd2ac6fa1e9 (patch)
tree3e2ca540216817f3a069761d1347af9adace8339 /llvm/lib/IR/BasicBlock.cpp
parentf73ae4fbf6d378ea4f806ffcfcbd85c949c37708 (diff)
downloadbcm5719-llvm-e31acf239a94ac402ce568867cf93cd2ac6fa1e9.tar.gz
bcm5719-llvm-e31acf239a94ac402ce568867cf93cd2ac6fa1e9.zip
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
Diffstat (limited to 'llvm/lib/IR/BasicBlock.cpp')
-rw-r--r--llvm/lib/IR/BasicBlock.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index 1ec977811ce..5ed9bed1baf 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -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,
OpenPOWER on IntegriCloud