LLVM: lib/Analysis/LoopPass.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
28using namespace llvm;
29
30#define DEBUG_TYPE "loop-pass-manager"
31
32namespace {
33
34
35
36class PrintLoopPassWrapper : public LoopPass {
38 std::string Banner;
39
40public:
41 static char ID;
43 PrintLoopPassWrapper(raw_ostream &OS, const std::string &Banner)
44 : LoopPass(ID), OS(OS), Banner(Banner) {}
45
46 void getAnalysisUsage(AnalysisUsage &AU) const override {
48 }
49
52 if (BBI != L->blocks().end() &&
55 }
56 return false;
57 }
58
59 StringRef getPassName() const override { return "Print Loop IR"; }
60};
61
62char PrintLoopPassWrapper::ID = 0;
63}
64
65
66
67
68
70
72 LI = nullptr;
73 CurrentLoop = nullptr;
74}
75
76
78 if (L.isOutermost()) {
79
80 LQ.push_front(&L);
81 return;
82 }
83
84
85 for (auto I = LQ.begin(), E = LQ.end(); I != E; ++I) {
86 if (*I == L.getParentLoop()) {
87
88 ++I;
89 LQ.insert(I, 1, &L);
90 return;
91 }
92 }
93}
94
95
101
102
104
105
108 Info.setPreservesAll();
109}
110
112 assert((&L == CurrentLoop || CurrentLoop->contains(&L)) &&
113 "Must not delete loop outside the current loop tree!");
114
115
116
117 assert(LQ.back() == CurrentLoop && "Loop queue back isn't the current loop!");
119
120 if (&L == CurrentLoop) {
121 CurrentLoopDeleted = true;
122
123 LQ.push_back(&L);
124 }
125}
126
127
128
131 LI = &LIWP.getLoopInfo();
132 Module &M = *F.getParent();
133#if 0
135#endif
137
138
140
141
142
143
144
145
146
147
148
149
152
153 if (LQ.empty())
154 return false;
155
156
157 for (Loop *L : LQ) {
160 Changed |= P->doInitialization(L, *this);
161 }
162 }
163
164
165 unsigned InstrCount, FunctionSize = 0;
167 bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
168
169 if (EmitICRemark) {
171 FunctionSize = F.getInstructionCount();
172 }
173 while (!LQ.empty()) {
174 CurrentLoopDeleted = false;
175 CurrentLoop = LQ.back();
176
177
180
182
184 CurrentLoop->getHeader()->getName());
186
188
189 bool LocalChanged = false;
190 {
193#ifdef EXPENSIVE_CHECKS
194 uint64_t RefHash = P->structuralHash(F);
195#endif
196 LocalChanged = P->runOnLoop(CurrentLoop, *this);
197
198#ifdef EXPENSIVE_CHECKS
199 if (!LocalChanged && (RefHash != P->structuralHash(F))) {
200 llvm::errs() << "Pass modifies its input and doesn't report it: "
201 << P->getPassName() << "\n";
202 llvm_unreachable("Pass modifies its input and doesn't report it");
203 }
204#endif
205
207 if (EmitICRemark) {
208 unsigned NewSize = F.getInstructionCount();
209
210
211 if (NewSize != FunctionSize) {
212 int64_t Delta = static_cast<int64_t>(NewSize) -
213 static_cast<int64_t>(FunctionSize);
215 FunctionToInstrCount, &F);
217 FunctionSize = NewSize;
218 }
219 }
220 }
221
222 if (LocalChanged)
224 CurrentLoopDeleted ? ""
225 : CurrentLoop->getName());
227
228 if (!CurrentLoopDeleted) {
229
230
231
232
233
234 {
236 CurrentLoop->verifyLoop();
237 }
238
239
240
241
242
243
244#if 0
246 assert(CurrentLoop->isRecursivelyLCSSAForm(*DT, *LI));
247#endif
248
249
251
252 F.getContext().yield();
253 }
254
255 if (LocalChanged)
259 CurrentLoopDeleted ? ""
260 : CurrentLoop->getHeader()->getName(),
262
263 if (CurrentLoopDeleted)
264
265 break;
266 }
267
268
269
270
271 if (CurrentLoopDeleted) {
275 }
276 }
277
278
279 LQ.pop_back();
280 }
281
282
285 Changed |= P->doFinalization();
286 }
287
289}
290
291
296 P->dumpPassStructure(Offset + 1);
298 }
299}
300
301
302
303
304
306 const std::string &Banner) const {
307 return new PrintLoopPassWrapper(O, Banner);
308}
309
310
311
312
313
314
315
317
318
319 while (!PMS.empty() &&
321 PMS.pop();
322
323
324
325
328 PMS.pop();
329}
330
331
334
335 while (!PMS.empty() &&
337 PMS.pop();
338
342 else {
343
344 assert (!PMS.empty() && "Unable to create Loop Pass Manager");
346
347
350
351
354
355
356
359
360
361 PMS.push(LPPM);
362 }
363
364 LPPM->add(this);
365}
366
370
372 const Function *F = L->getHeader()->getParent();
373 if ()
374 return false;
375
376 const OptPassGate &Gate = F->getContext().getOptPassGate();
379 return true;
380
381 if (F->hasOptNone()) {
382
384 << F->getName() << "\n");
385
386 return true;
387 }
388 return false;
389}
390
392
395 false, false)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static unsigned InstrCount
Module.h This file contains the declarations for the Module class.
static std::string getDescription(const Loop &L)
Definition LoopPass.cpp:367
static void addLoopIntoQueue(Loop *L, std::deque< Loop * > &LQ)
Definition LoopPass.cpp:96
This file declares the interface for bisecting optimizations.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This header defines classes/functions to handle pass execution timing information with interfaces for...
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
LLVM Basic Block Representation.
Legacy analysis pass which computes a DominatorTree.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
bool runOnFunction(Function &F) override
run - Execute all of the passes scheduled for execution.
Definition LoopPass.cpp:129
Pass * getAsPass() override
void dumpPassStructure(unsigned Offset) override
Print passes managed by this manager.
Definition LoopPass.cpp:292
void markLoopAsDeleted(Loop &L)
Definition LoopPass.cpp:111
void addLoop(Loop &L)
Definition LoopPass.cpp:77
LoopPass * getContainedPass(unsigned N)
void getAnalysisUsage(AnalysisUsage &Info) const override
Pass Manager itself does not invalidate any analysis info.
Definition LoopPass.cpp:103
LPPassManager()
Definition LoopPass.cpp:71
The legacy pass manager's analysis pass to compute loop information.
void preparePassManager(PMStack &PMS) override
Check if available pass managers are suitable for this pass or not.
Definition LoopPass.cpp:316
Pass * createPrinterPass(raw_ostream &O, const std::string &Banner) const override
getPrinterPass - Get a pass to print the function corresponding to a Loop.
Definition LoopPass.cpp:305
void assignPassManager(PMStack &PMS, PassManagerType PMT) override
Assign pass manager to manage this pass.
Definition LoopPass.cpp:332
bool skipLoop(const Loop *L) const
Optional passes call this function to check whether the pass should be skipped.
Definition LoopPass.cpp:371
Represents a single loop in the control flow graph.
A Module instance is used to store all the information related to an LLVM module.
Extensions to this class implement mechanisms to disable passes and individual optimizations at compi...
virtual bool isEnabled() const
isEnabled() should return true before calling shouldRunPass().
virtual bool shouldRunPass(StringRef PassName, StringRef IRDescription) const
IRDescription is a textual description of the IR unit the pass is running over.
PMDataManager provides the common place to manage the analysis data used by pass managers.
void removeDeadPasses(Pass *P, StringRef Msg, enum PassDebuggingString)
Remove dead passes used by P.
void dumpLastUses(Pass *P, unsigned Offset) const
void recordAvailableAnalysis(Pass *P)
Augment AvailableAnalysis by adding analysis made available by pass P.
PMTopLevelManager * getTopLevelManager()
unsigned initSizeRemarkInfo(Module &M, StringMap< std::pair< unsigned, unsigned > > &FunctionToInstrCount)
Set the initial size of the module if the user has specified that they want remarks for size.
void dumpRequiredSet(const Pass *P) const
void initializeAnalysisImpl(Pass *P)
All Required analyses should be available to the pass as it runs!
void verifyPreservedAnalysis(Pass *P)
verifyPreservedAnalysis – Verify analysis presreved by pass P.
void freePass(Pass *P, StringRef Msg, enum PassDebuggingString)
Remove P.
bool preserveHigherLevelAnalysis(Pass *P)
unsigned getNumContainedPasses() const
virtual PassManagerType getPassManagerType() const
void emitInstrCountChangedRemark(Pass *P, Module &M, int64_t Delta, unsigned CountBefore, StringMap< std::pair< unsigned, unsigned > > &FunctionToInstrCount, Function *F=nullptr)
Emit a remark signifying that the number of IR instructions in the module changed.
void add(Pass *P, bool ProcessAnalysis=true)
Add pass P into the PassVector.
void populateInheritedAnalysis(PMStack &PMS)
void dumpPreservedSet(const Pass *P) const
void removeNotPreservedAnalysis(Pass *P)
Remove Analysis that is not preserved by the pass.
void dumpPassInfo(Pass *P, enum PassDebuggingString S1, enum PassDebuggingString S2, StringRef Msg)
PMStack - This class implements a stack data structure of PMDataManager pointers.
PMDataManager * top() const
LLVM_ABI void push(PMDataManager *PM)
PMTopLevelManager manages LastUser info and collects common APIs used by top level pass managers.
void addIndirectPassManager(PMDataManager *Manager)
void schedulePass(Pass *P)
Schedule pass P for execution.
PassManagerPrettyStackEntry - This is used to print informative information about what pass is runnin...
Pass interface - Implemented by all 'passes'.
bool mustPreserveAnalysisID(char &AID) const
mustPreserveAnalysisID - This method serves the same function as getAnalysisIfAvailable,...
Pass(PassKind K, char &pid)
AnalysisType & getAnalysis() const
getAnalysis() - This function is used by subclasses to get to the analysis information ...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
The TimeRegion class is used as a helper class to call the startTimer() and stopTimer() methods of th...
The TimeTraceScope is a helper class to call the begin and end functions of the time trace profiler.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
PassManagerType
Different types of internal pass managers.
@ PMT_LoopPassManager
LPPassManager.
void erase(Container &C, ValueType V)
Wrapper function to remove a value from a container:
LLVM_ABI Timer * getPassTimer(Pass *)
Request the timer for this legacy-pass-manager's pass instance.
auto reverse(ContainerTy &&C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isFunctionInPrintList(StringRef FunctionName)
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ABI void printLoop(const Loop &L, raw_ostream &OS, const std::string &Banner="")
Function to print a loop's contents as LLVM's text IR assembly.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI LCSSAVerificationPass()
Definition LoopPass.cpp:391