28 #define DEBUG_TYPE "block-extractor" 30 STATISTIC(NumExtracted,
"Number of basic blocks extracted");
37 cl::desc(
"Erase the existing functions"),
51 EraseFunctions(EraseFunctions) {
56 bool runOnModule(
Module &M)
override;
66 "Extract basic blocks from module",
false,
false)
71 return new BlockExtractor(BlocksToExtract, EraseFunctions);
77 if (ErrOrBuf.getError())
80 auto &Buf = *ErrOrBuf;
82 Buf->getBuffer().split(Lines,
'\n', -1,
84 for (
const auto &Line : Lines) {
85 auto FBPair = Line.split(
' ');
86 BlocksByName.
push_back({FBPair.first, FBPair.second});
92 void BlockExtractor::splitLandingPadPreds(
Function &
F) {
95 if (!isa<InvokeInst>(&
I))
105 if (PredBB->isLandingPad() && PredBB != Parent &&
106 isa<InvokeInst>(Parent->getTerminator())) {
121 bool BlockExtractor::runOnModule(
Module &M) {
123 bool Changed =
false;
128 splitLandingPadPreds(F);
133 for (
const auto &BInfo : BlocksByName) {
148 if (BB->getParent()->getParent() != &M)
151 << BB->getParent()->getName() <<
":" << BB->getName()
155 if (
const InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator()))
156 BlocksToExtractVec.push_back(II->getUnwindDest());
const Function & getFunction() const
const_iterator end(StringRef path)
Get end iterator over path.
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
void push_back(const T &Elt)
Externally visible function.
STATISTIC(NumFunctions, "Total number of functions")
static std::unique_ptr< Module > loadFile(const std::string &FileName, LLVMContext &Context)
ModulePass * createBlockExtractorPass()
createBlockExtractorPass - This pass extracts all the specified blocks from the functions in the modu...
void SplitLandingPadPredecessors(BasicBlock *OrigBB, ArrayRef< BasicBlock *> Preds, const char *Suffix, const char *Suffix2, SmallVectorImpl< BasicBlock *> &NewBBs, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, bool PreserveLCSSA=false)
This method transforms the landing pad, OrigBB, by introducing two new basic blocks into the function...
LLVM Basic Block Representation.
void deleteBody()
deleteBody - This method deletes the body of the function, and converts the linkage to external...
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
pred_range predecessors(BasicBlock *BB)
void setLinkage(LinkageTypes LT)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
StringRef getName() const
Return a constant reference to the value's name.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
BasicBlock * getUnwindDest() const
static void Split(std::vector< std::string > &V, StringRef S)
Splits a string of comma separated items in to a vector of strings.
const BasicBlock * getParent() const