[func-sig-opts] Add SILFunction::findReturnBB to easily find the unique basic block containing a ReturnInst in a SILFunction.

Swift SVN r22923
This commit is contained in:
Michael Gottesman
2014-10-24 22:21:48 +00:00
parent cbcfa97814
commit c42bdcf418
2 changed files with 21 additions and 5 deletions

View File

@@ -378,6 +378,26 @@ public:
getBlocks().splice(begin(), F->getBlocks());
}
/// Return the unique basic block containing a return inst if it
/// exists. Otherwise, returns end.
iterator findReturnBB() {
return std::find_if(F->begin(), F->end(),
[](const SILBasicBlock &BB) -> bool {
const TermInst *TI = BB.getTerminator();
return isa<ReturnInst>(TI);
});
}
/// Return the unique basic block containing a return inst if it
/// exists. Otherwise, returns end.
const_iterator findReturnBB() const {
return std::find_if(F->begin(), F->end(),
[](const SILBasicBlock &BB) -> bool {
const TermInst *TI = BB.getTerminator();
return isa<ReturnInst>(TI);
});
}
//===--------------------------------------------------------------------===//
// Miscellaneous
//===--------------------------------------------------------------------===//