Go to the documentation of this file.
31 #define DEBUG_TYPE "block-extractor"
33 STATISTIC(NumExtracted,
"Number of basic blocks extracted");
41 cl::desc(
"Erase the existing functions"),
44 class BlockExtractor {
46 BlockExtractor(
bool EraseFunctions) : EraseFunctions(EraseFunctions) {}
47 bool runOnModule(
Module &M);
49 &GroupsOfBlocksToExtract) {
51 GroupsOfBlocksToExtract) {
53 NewGroup.
append(GroupOfBlocks.begin(), GroupOfBlocks.end());
54 GroupsOfBlocks.emplace_back(NewGroup);
71 class BlockExtractorLegacyPass :
public ModulePass {
73 bool runOnModule(
Module &M)
override;
84 NewGroup.push_back(
BB);
85 MassagedGroupsOfBlocks.push_back(NewGroup);
87 BE.init(MassagedGroupsOfBlocks);
91 &GroupsOfBlocksToExtract,
94 BE.init(GroupsOfBlocksToExtract);
97 BlockExtractorLegacyPass()
105 "Extract basic blocks from module",
false,
false)
108 return new BlockExtractorLegacyPass();
112 return new BlockExtractorLegacyPass(BlocksToExtract, EraseFunctions);
116 &GroupsOfBlocksToExtract,
117 bool EraseFunctions) {
118 return new BlockExtractorLegacyPass(GroupsOfBlocksToExtract, EraseFunctions);
124 if (ErrOrBuf.getError())
127 auto &Buf = *ErrOrBuf;
129 Buf->getBuffer().split(Lines,
'\n', -1,
131 for (
const auto &Line : Lines) {
133 Line.split(LineSplit,
' ', -1,
135 if (LineSplit.empty())
137 if (LineSplit.size()!=2)
138 report_fatal_error(
"Invalid line format, expecting lines like: 'funcname bb1[;bb2..]'");
140 LineSplit[1].split(BBNames,
';', -1,
144 BlocksByName.push_back(
145 {std::string(LineSplit[0]), {BBNames.begin(), BBNames.end()}});
151 void BlockExtractor::splitLandingPadPreds(
Function &
F) {
154 if (!isa<InvokeInst>(&
I))
164 if (PredBB->isLandingPad() && PredBB != Parent &&
180 bool BlockExtractor::runOnModule(
Module &M) {
182 bool Changed =
false;
187 splitLandingPadPreds(
F);
188 Functions.push_back(&
F);
192 unsigned NextGroupIdx = GroupsOfBlocks.size();
193 GroupsOfBlocks.
resize(NextGroupIdx + BlocksByName.size());
194 for (
const auto &BInfo : BlocksByName) {
198 for (
const auto &BBInfo : BInfo.second) {
200 return BB.getName().equals(BBInfo);
204 GroupsOfBlocks[NextGroupIdx].push_back(&*Res);
210 for (
auto &BBs : GroupsOfBlocks) {
214 if (
BB->getParent()->getParent() != &M)
217 <<
BB->getParent()->getName() <<
":" <<
BB->getName()
219 BlocksToExtractVec.push_back(
BB);
220 if (
const InvokeInst *II = dyn_cast<InvokeInst>(
BB->getTerminator()))
228 LLVM_DEBUG(
dbgs() <<
"Extracted group '" << (*BBs.begin())->getName()
229 <<
"' in: " <<
F->getName() <<
'\n');
232 << (*BBs.begin())->getName() <<
"'\n");
238 LLVM_DEBUG(
dbgs() <<
"BlockExtractor: Trying to delete " <<
F->getName()
251 bool BlockExtractorLegacyPass::runOnModule(
Module &M) {
252 return BE.runOnModule(M);
257 BlockExtractor BE(
false);
A set of analyses that are preserved following a run of a transformation pass.
This is an optimization pass for GlobalISel generic memory operations.
void SplitLandingPadPredecessors(BasicBlock *OrigBB, ArrayRef< BasicBlock * > Preds, const char *Suffix, const char *Suffix2, SmallVectorImpl< BasicBlock * > &NewBBs, DominatorTree *DT, 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...
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
LLVM Basic Block Representation.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
static std::unique_ptr< Module > loadFile(const std::string &FileName, LLVMContext &Context)
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
ModulePass * createBlockExtractorPass()
createBlockExtractorPass - This pass extracts all the specified blocks from the functions in the modu...
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
STATISTIC(NumFunctions, "Total number of functions")
auto predecessors(MachineBasicBlock *BB)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
initializer< Ty > init(const Ty &Val)
A Module instance is used to store all the information related to an LLVM module.
static const Function * getParent(const Value *V)
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
@ ExternalLinkage
Externally visible function.
const BasicBlock * getParent() const
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
A container for analyses that lazily runs them and caches their results.
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
BasicBlock * getUnwindDest() const