33 #define DEBUG_TYPE "loop-extract" 35 STATISTIC(NumExtracted,
"Number of loops extracted");
38 struct LoopExtractor :
public LoopPass {
42 explicit LoopExtractor(
unsigned numLoops = ~0)
60 "Extract loops into new functions",
false,
false)
77 "Extract at most one loop into a new function",
false,
false)
96 DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
97 LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
104 bool ShouldExtractLoop =
false;
109 if (!isa<BranchInst>(EntryTI) ||
110 !cast<BranchInst>(EntryTI)->isUnconditional() ||
112 ShouldExtractLoop =
true;
118 for (
unsigned i = 0, e = ExitBlocks.
size(); i != e; ++i)
119 if (!isa<ReturnInst>(ExitBlocks[i]->getTerminator())) {
120 ShouldExtractLoop =
true;
125 if (ShouldExtractLoop) {
132 for (
unsigned i = 0, e = ExitBlocks.
size(); i != e; ++i)
133 if (ExitBlocks[i]->isEHPad()) {
134 ShouldExtractLoop =
false;
139 if (ShouldExtractLoop) {
140 if (NumLoops == 0)
return Changed;
160 return new SingleLoopExtractor();
Pass interface - Implemented by all 'passes'.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
void initializeLoopExtractorPass(PassRegistry &)
This class represents lattice values for constants.
BasicBlock * getSuccessor(unsigned Idx) const
Return the specified successor. This instruction must be a terminator.
Pass * createSingleLoopExtractorPass()
createSingleLoopExtractorPass - This pass extracts one natural loop from the program into a function ...
STATISTIC(NumFunctions, "Total number of functions")
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...
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
void erase(Loop *L)
Update LoopInfo after removing the last backedge from a loop.
BlockT * getHeader() const
void getExitBlocks(SmallVectorImpl< BlockT *> &ExitBlocks) const
Return all of the successor blocks of this loop.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
const BasicBlock & getEntryBlock() const
char & BreakCriticalEdgesID
Represent the analysis usage information of a pass.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
AnalysisUsage & addRequiredID(const void *ID)
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.
void markLoopAsDeleted(Loop &L)
Pass * createLoopExtractorPass()
createLoopExtractorPass - This pass extracts all natural loops from the program into a function if it...
LoopT * getParentLoop() const
bool isLoopSimplifyForm() const
Return true if the Loop is in the form that the LoopSimplify form transforms loops to...
Represents a single loop in the control flow graph.
const Function * getParent() const
Return the enclosing method, or null if none.
The legacy pass manager's analysis pass to compute loop information.
Legacy analysis pass which computes a DominatorTree.