Go to the documentation of this file.
31 #define DEBUG_TYPE "loop-extract"
33 STATISTIC(NumExtracted,
"Number of loops extracted");
36 struct LoopExtractorLegacyPass :
public ModulePass {
41 explicit LoopExtractorLegacyPass(
unsigned NumLoops = ~0)
46 bool runOnModule(
Module &M)
override;
58 struct LoopExtractor {
59 explicit LoopExtractor(
64 : NumLoops(NumLoops), LookupDomTree(LookupDomTree),
65 LookupLoopInfo(LookupLoopInfo),
66 LookupAssumptionCache(LookupAssumptionCache) {}
67 bool runOnModule(
Module &M);
87 "Extract loops into new functions",
false,
false)
105 "Extract at most one loop into a new function",
false,
false)
112 bool LoopExtractorLegacyPass::runOnModule(
Module &M) {
116 bool Changed =
false;
118 return this->getAnalysis<DominatorTreeWrapperPass>(
F).getDomTree();
121 return this->getAnalysis<LoopInfoWrapperPass>(
F, &Changed).getLoopInfo();
124 if (
auto *ACT = this->getAnalysisIfAvailable<AssumptionCacheTracker>())
125 return ACT->lookupAssumptionCache(
F);
128 return LoopExtractor(NumLoops, LookupDomTree, LookupLoopInfo, LookupACT)
133 bool LoopExtractor::runOnModule(
Module &M) {
140 bool Changed =
false;
144 auto I =
M.begin(),
E = --
M.end();
169 bool Changed =
false;
180 if (std::next(LI.
begin()) != LI.
end())
181 return Changed | extractLoops(LI.
begin(), LI.
end(), LI, DT);
189 bool ShouldExtractLoop =
false;
192 Instruction *EntryTI =
F.getEntryBlock().getTerminator();
193 if (!isa<BranchInst>(EntryTI) ||
194 !cast<BranchInst>(EntryTI)->isUnconditional() ||
196 ShouldExtractLoop =
true;
202 for (
auto *ExitBlock : ExitBlocks)
203 if (!isa<ReturnInst>(ExitBlock->getTerminator())) {
204 ShouldExtractLoop =
true;
209 if (ShouldExtractLoop)
210 return Changed | extractLoop(TLL, LI, DT);
217 return Changed | extractLoops(TLL->
begin(), TLL->
end(), LI, DT);
222 bool Changed =
false;
229 if (!L->isLoopSimplifyForm())
232 Changed |= extractLoop(L, LI, DT);
244 CodeExtractor Extractor(DT, *L,
false,
nullptr,
nullptr, AC);
245 if (Extractor.extractCodeRegion(CEAC)) {
258 return new SingleLoopExtractor();
272 if (!LoopExtractor(NumLoops, LookupDomTree, LookupLoopInfo,
273 LookupAssumptionCache)
285 OS, MapClassName2PassName);
A set of analyses that are preserved following a run of a transformation pass.
This is an optimization pass for GlobalISel generic memory operations.
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
void getExitBlocks(SmallVectorImpl< BlockT * > &ExitBlocks) const
Return all of the successor blocks of this loop.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
const Function * getParent() const
Return the enclosing method, or null if none.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represents a single loop in the control flow graph.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
FunctionAnalysisManager FAM
The legacy pass manager's analysis pass to compute loop information.
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 ID Predecessors according to mbb< bb27, 0x8b0a7c0 > Note ADDri is not a two address instruction its result reg1037 is an operand of the PHI node in bb76 and its operand reg1039 is the result of the PHI node We should treat it as a two address code and make sure the ADDri is scheduled after any node that reads reg1039 Use info(i.e. register scavenger) to assign it a free register to allow reuse the collector could move the objects and invalidate the derived pointer This is bad enough in the first but safe points can crop up unpredictably **array_addr i32 n y store obj * new
Analysis the ScalarEvolution expression for r is< loop > Outside the loop
Pass * createLoopExtractorPass()
createLoopExtractorPass - This pass extracts all natural loops from the program into a function if it...
Pass * createSingleLoopExtractorPass()
createSingleLoopExtractorPass - This pass extracts one natural loop from the program into a function ...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Represent the analysis usage information of a pass.
Legacy analysis pass which computes a DominatorTree.
STATISTIC(NumFunctions, "Total number of functions")
This class implements an extremely fast bulk output stream that can only output to a stream.
BasicBlock * getSuccessor(unsigned Idx) const
Return the specified successor. This instruction must be a terminator.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
An efficient, type-erasing, non-owning reference to a callable.
bool isLoopSimplifyForm() const
Return true if the Loop is in the form that the LoopSimplify form transforms loops to,...
A function analysis which provides an AssumptionCache.
void preserve()
Mark an analysis as preserved.
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void erase(Loop *L)
Update LoopInfo after removing the last backedge from a loop.
A Module instance is used to store all the information related to an LLVM module.
An immutable pass that tracks lazily created AssumptionCache objects.
StringRef - Represent a constant reference to a string, i.e.
A cache of @llvm.assume calls within a function.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static bool runOnFunction(Function &F, bool PostInlining)
void initializeLoopExtractorLegacyPassPass(PassRegistry &)
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
BlockT * getHeader() const
char & BreakCriticalEdgesID
Analysis pass which computes a DominatorTree.
Pass interface - Implemented by all 'passes'.
std::vector< Loop * >::const_iterator iterator
A container for analyses that lazily runs them and caches their results.
AnalysisUsage & addUsedIfAvailable()
Add the specified Pass class to the set of analyses used by this pass.
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
AnalysisUsage & addRequiredID(const void *ID)
AnalysisUsage & addRequired()
BlockVerifier::State From
Analysis pass that exposes the LoopInfo for a function.