LLVM  4.0.0
LoopPassManager.cpp
Go to the documentation of this file.
1 //===- LoopPassManager.cpp - Loop pass management -------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 #include "llvm/Analysis/LoopInfo.h"
12 
13 using namespace llvm;
14 
15 // Explicit template instantiations and specialization defininitions for core
16 // template typedefs.
17 namespace llvm {
18 template class PassManager<Loop, LoopAnalysisManager,
20 
21 /// Explicitly specialize the pass manager's run method to handle loop nest
22 /// structure updates.
23 template <>
29 
30  if (DebugLogging)
31  dbgs() << "Starting Loop pass manager run.\n";
32 
33  for (auto &Pass : Passes) {
34  if (DebugLogging)
35  dbgs() << "Running pass: " << Pass->name() << " on " << L;
36 
37  PreservedAnalyses PassPA = Pass->run(L, AM, AR, U);
38 
39  // If the loop was deleted, abort the run and return to the outer walk.
40  if (U.skipCurrentLoop()) {
41  PA.intersect(std::move(PassPA));
42  break;
43  }
44 
45  // Update the analysis manager as each pass runs and potentially
46  // invalidates analyses.
47  AM.invalidate(L, PassPA);
48 
49  // Finally, we intersect the final preserved analyses to compute the
50  // aggregate preserved set for this pass manager.
51  PA.intersect(std::move(PassPA));
52 
53  // FIXME: Historically, the pass managers all called the LLVM context's
54  // yield function here. We don't have a generic way to acquire the
55  // context and it isn't yet clear what the right pattern is for yielding
56  // in the new pass manager so it is currently omitted.
57  // ...getContext().yield();
58  }
59 
60  // Invalidation for the current loop should be handled above, and other loop
61  // analysis results shouldn't be impacted by runs over this loop. Therefore,
62  // the remaining analysis results in the AnalysisManager are preserved. We
63  // mark this with a set so that we don't need to inspect each one
64  // individually.
65  // FIXME: This isn't correct! This loop and all nested loops' analyses should
66  // be preserved, but unrolling should invalidate the parent loop's analyses.
68 
69  if (DebugLogging)
70  dbgs() << "Finished Loop pass manager run.\n";
71 
72  return PA;
73 }
74 }
75 
77 PrintLoopPass::PrintLoopPass(raw_ostream &OS, const std::string &Banner)
78  : OS(OS), Banner(Banner) {}
79 
82  LPMUpdater &) {
83  printLoop(L, OS, Banner);
84  return PreservedAnalyses::all();
85 }
MachineLoop * L
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:81
This header provides classes for managing a pipeline of passes over loops in LLVM IR...
void intersect(const PreservedAnalyses &Arg)
Intersect this set with another in place.
Definition: PassManager.h:171
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:107
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:113
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
void invalidate(IRUnitT &IR)
Invalidate a specific analysis pass for an IR module.
Definition: PassManager.h:722
PreservedAnalyses run(Loop &L, LoopAnalysisManager &, LoopStandardAnalysisResults &, LPMUpdater &)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
Manages a sequence of passes over a particular unit of IR.
Definition: PassManager.h:389
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:368
void preserveSet()
Mark an analysis set as preserved.
Definition: PassManager.h:135
bool skipCurrentLoop() const
This can be queried by loop passes which run other loop passes (like pass managers) to know whether t...
This templated class represents "all analyses that operate over \<a particular IR unit\>" (e...
Definition: PassManager.h:361
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
A container for analyses that lazily runs them and caches their results.
void printLoop(Loop &L, raw_ostream &OS, const std::string &Banner="")
Function to print a loop's contents as LLVM's text IR assembly.
Definition: LoopInfo.cpp:692