34 #define DEBUG_TYPE "loop-extract" 36 STATISTIC(NumExtracted,
"Number of loops extracted");
39 struct LoopExtractor :
public LoopPass {
43 explicit LoopExtractor(
unsigned numLoops = ~0)
62 "Extract loops into new functions",
false,
false)
79 "Extract at most one loop into a new function",
false,
false)
98 DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
99 LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
100 bool Changed =
false;
106 bool ShouldExtractLoop =
false;
111 if (!isa<BranchInst>(EntryTI) ||
112 !cast<BranchInst>(EntryTI)->isUnconditional() ||
114 ShouldExtractLoop =
true;
120 for (
unsigned i = 0,
e = ExitBlocks.
size(); i !=
e; ++i)
121 if (!isa<ReturnInst>(ExitBlocks[i]->getTerminator())) {
122 ShouldExtractLoop =
true;
127 if (ShouldExtractLoop) {
134 for (
unsigned i = 0,
e = ExitBlocks.
size(); i !=
e; ++i)
135 if (ExitBlocks[i]->isEHPad()) {
136 ShouldExtractLoop =
false;
141 if (ShouldExtractLoop) {
142 if (NumLoops == 0)
return Changed;
146 if (
auto *ACT = getAnalysisIfAvailable<AssumptionCacheTracker>())
147 AC = ACT->lookupAssumptionCache(Func);
149 CodeExtractor Extractor(DT, *L,
false,
nullptr,
nullptr, AC);
167 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.
An immutable pass that tracks lazily created AssumptionCache objects.
A cache of @llvm.assume calls within a function.
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.
AnalysisUsage & addUsedIfAvailable()
Add the specified Pass class to the set of analyses used by this pass.
The legacy pass manager's analysis pass to compute loop information.
Legacy analysis pass which computes a DominatorTree.