36 #define DEBUG_TYPE "loop-extract" 38 STATISTIC(NumExtracted,
"Number of loops extracted");
41 struct LoopExtractorLegacyPass :
public ModulePass {
46 explicit LoopExtractorLegacyPass(
unsigned NumLoops = ~0)
51 bool runOnModule(
Module &M)
override;
63 struct LoopExtractor {
64 explicit LoopExtractor(
69 : NumLoops(NumLoops), LookupDomTree(LookupDomTree),
70 LookupLoopInfo(LookupLoopInfo),
71 LookupAssumptionCache(LookupAssumptionCache) {}
72 bool runOnModule(
Module &M);
92 "Extract loops into new functions",
false,
false)
110 "Extract at most one loop into a new function",
false,
false)
117 bool LoopExtractorLegacyPass::runOnModule(
Module &M) {
121 bool Changed =
false;
123 return this->getAnalysis<DominatorTreeWrapperPass>(
F).getDomTree();
126 return this->getAnalysis<LoopInfoWrapperPass>(
F, &Changed).getLoopInfo();
129 if (
auto *ACT = this->getAnalysisIfAvailable<AssumptionCacheTracker>())
130 return ACT->lookupAssumptionCache(
F);
133 return LoopExtractor(NumLoops, LookupDomTree, LookupLoopInfo, LookupACT)
138 bool LoopExtractor::runOnModule(
Module &M) {
145 bool Changed =
false;
149 auto I =
M.begin(),
E = --
M.end();
174 bool Changed =
false;
185 if (std::next(LI.
begin()) != LI.
end())
186 return Changed | extractLoops(LI.
begin(), LI.
end(), LI, DT);
194 bool ShouldExtractLoop =
false;
197 Instruction *EntryTI =
F.getEntryBlock().getTerminator();
198 if (!isa<BranchInst>(EntryTI) ||
199 !cast<BranchInst>(EntryTI)->isUnconditional() ||
201 ShouldExtractLoop =
true;
207 for (
auto *ExitBlock : ExitBlocks)
208 if (!isa<ReturnInst>(ExitBlock->getTerminator())) {
209 ShouldExtractLoop =
true;
214 if (ShouldExtractLoop)
215 return Changed | extractLoop(TLL, LI, DT);
222 return Changed | extractLoops(TLL->
begin(), TLL->
end(), LI, DT);
227 bool Changed =
false;
234 if (!L->isLoopSimplifyForm())
237 Changed |= extractLoop(L, LI, DT);
249 CodeExtractor Extractor(DT, *L,
false,
nullptr,
nullptr, AC);
250 if (Extractor.extractCodeRegion(CEAC)) {
263 return new SingleLoopExtractor();
277 if (!LoopExtractor(NumLoops, LookupDomTree, LookupLoopInfo,
278 LookupAssumptionCache)
Pass interface - Implemented by all 'passes'.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module.
BasicBlock * getSuccessor(unsigned Idx) const
Return the specified successor. This instruction must be a terminator.
An immutable pass that tracks lazily created AssumptionCache objects.
An efficient, type-erasing, non-owning reference to a callable.
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")
Analysis pass which computes a DominatorTree.
AnalysisUsage & addRequired()
void erase(Loop *L)
Update LoopInfo after removing the last backedge from a loop.
Analysis pass that exposes the LoopInfo for a function.
BlockT * getHeader() const
std::vector< Loop * >::const_iterator iterator
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
static bool runOnFunction(Function &F, bool PostInlining)
A set of analyses that are preserved following a run of a transformation pass.
char & BreakCriticalEdgesID
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Represent the analysis usage information of a pass.
void getExitBlocks(SmallVectorImpl< BlockT * > &ExitBlocks) const
Return all of the successor blocks of this loop.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
A function analysis which provides an AssumptionCache.
BlockVerifier::State From
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.
Pass * createLoopExtractorPass()
createLoopExtractorPass - This pass extracts all natural loops from the program into a function if it...
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.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
void preserve()
Mark an analysis as preserved.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
A container for analyses that lazily runs them and caches their results.
Legacy analysis pass which computes a DominatorTree.
This header defines various interfaces for pass management in LLVM.
void initializeLoopExtractorLegacyPassPass(PassRegistry &)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...