30 #define DEBUG_TYPE "loop-pass-manager" 36 class PrintLoopPassWrapper :
public LoopPass {
43 PrintLoopPassWrapper(
raw_ostream &OS,
const std::string &Banner)
44 :
LoopPass(ID), OS(OS), Banner(Banner) {}
52 if (BBI != L->
blocks().end() &&
59 StringRef getPassName()
const override {
return "Print Loop IR"; }
74 CurrentLoop =
nullptr;
86 for (
auto I = LQ.begin(),
E = LQ.end();
I !=
E; ++
I) {
108 if (
BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
146 "Must not delete loop outside the current loop tree!");
150 assert(LQ.back() == CurrentLoop &&
"Loop queue back isn't the current loop!");
151 LQ.erase(
std::remove(LQ.begin(), LQ.end(), &L), LQ.end());
153 if (&L == CurrentLoop) {
154 CurrentLoopDeleted =
true;
163 auto &LIWP = getAnalysis<LoopInfoWrapperPass>();
164 LI = &LIWP.getLoopInfo();
167 DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
169 bool Changed =
false;
206 while (!LQ.empty()) {
207 CurrentLoopDeleted =
false;
208 CurrentLoop = LQ.back();
222 bool LocalChanged =
false;
226 LocalChanged = P->
runOnLoop(CurrentLoop, *
this);
227 Changed |= LocalChanged;
232 if (NewSize != FunctionSize) {
233 int64_t Delta =
static_cast<int64_t
>(NewSize) -
234 static_cast<int64_t>(FunctionSize);
236 FunctionToInstrCount, &F);
237 InstrCount =
static_cast<int64_t
>(
InstrCount) + Delta;
238 FunctionSize = NewSize;
245 CurrentLoopDeleted ?
"<deleted loop>" 249 if (CurrentLoopDeleted) {
282 CurrentLoopDeleted ?
"<deleted>" 286 if (CurrentLoopDeleted)
294 if (CurrentLoopDeleted) {
316 errs().
indent(Offset*2) <<
"Loop Pass Manager\n";
329 const std::string &Banner)
const {
330 return new PrintLoopPassWrapper(O, Banner);
342 while (!PMS.
empty() &&
358 while (!PMS.
empty() &&
367 assert (!PMS.
empty() &&
"Unable to create Loop Pass Manager");
Pass interface - Implemented by all 'passes'.
bool preserveHigherLevelAnalysis(Pass *P)
PassManagerType
Different types of internal pass managers.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
bool hasOptNone() const
Do not optimize this function (-O0).
virtual void dumpPassStructure(unsigned Offset=0)
void dumpLastUses(Pass *P, unsigned Offset) const
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...
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
unsigned getInstructionCount() const
Returns the number of non-debug IR instructions in this function.
bool isRecursivelyLCSSAForm(DominatorTree &DT, const LoopInfo &LI) const
Return true if this Loop and all inner subloops are in LCSSA form.
virtual void deleteAnalysisLoop(Loop *L)
Delete analysis info associated with Loop L.
The TimeTraceScope is a helper class to call the begin and end functions of the time trace profiler...
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
void assignPassManager(PMStack &PMS, PassManagerType PMT) override
Assign pass manager to manage this pass.
void yield()
Calls the yield callback (if applicable).
static unsigned InstrCount
void dumpPassInfo(Pass *P, enum PassDebuggingString S1, enum PassDebuggingString S2, StringRef Msg)
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
bool mustPreserveAnalysisID(char &AID) const
mustPreserveAnalysisID - This method serves the same function as getAnalysisIfAvailable, but works if you just have an AnalysisID.
virtual bool shouldRunPass(const Pass *P, StringRef IRDescription)
IRDescription is a textual description of the IR unit the pass is running over.
PMTopLevelManager manages LastUser info and collects common APIs used by top level pass managers...
Timer * getPassTimer(Pass *)
Request the timer for this legacy-pass-manager's pass instance.
static void addLoopIntoQueue(Loop *L, std::deque< Loop *> &LQ)
The TimeRegion class is used as a helper class to call the startTimer() and stopTimer() methods of th...
void schedulePass(Pass *P)
Schedule pass P for execution.
AnalysisUsage & addRequired()
void freePass(Pass *P, StringRef Msg, enum PassDebuggingString)
Remove P.
void deleteSimpleAnalysisLoop(Loop *L)
Invoke deleteAnalysisLoop hook for all passes that implement simple analysis interface.
void verifyPreservedAnalysis(Pass *P)
verifyPreservedAnalysis – Verify analysis presreved by pass P.
void populateInheritedAnalysis(PMStack &PMS)
This header defines classes/functions to handle pass execution timing information with interfaces for...
PMStack - This class implements a stack data structure of PMDataManager pointers. ...
void initializeAnalysisImpl(Pass *P)
All Required analyses should be available to the pass as it runs! Here we fill in the AnalysisImpls m...
virtual bool isEnabled() const
isEnabled should return true before calling shouldRunPass
PassManagerPrettyStackEntry - This is used to print informative information about what pass is runnin...
BlockT * getHeader() const
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
OptPassGate & getOptPassGate() const
Access the object which can disable optional passes and individual optimizations at compile time...
Pass * createPrinterPass(raw_ostream &O, const std::string &Banner) const override
getPrinterPass - Get a pass to print the function corresponding to a Loop.
void add(Pass *P, bool ProcessAnalysis=true)
Add pass P into the PassVector.
This header provides classes for managing per-loop analyses.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Analysis containing CSE Info
virtual bool doInitialization(Loop *L, LPPassManager &LPM)
LLVM Basic Block Representation.
static std::string getDescription(const Loop &L)
virtual bool doFinalization()
bool shouldEmitInstrCountChangedRemark()
Return true if size-info optimization remark is enabled, false otherwise.
void addIndirectPassManager(PMDataManager *Manager)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
virtual PassManagerType getPassManagerType() const
void getAnalysisUsage(AnalysisUsage &Info) const override
Pass Manager itself does not invalidate any analysis info.
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
bool skipLoop(const Loop *L) const
Optional passes call this function to check whether the pass should be skipped.
void deleteSimpleAnalysisValue(Value *V, Loop *L)
deleteSimpleAnalysisValue - Invoke deleteAnalysisValue hook for all passes that implement simple anal...
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
BlockVerifier::State From
void recordAvailableAnalysis(Pass *P)
Augment AvailableAnalysis by adding analysis made available by pass P.
void dumpRequiredSet(const Pass *P) const
void removeNotPreservedAnalysis(Pass *P)
Remove Analysis that is not preserved by the pass.
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 removeDeadPasses(Pass *P, StringRef Msg, enum PassDebuggingString)
Remove dead passes used by P.
This file declares the interface for bisecting optimizations.
void markLoopAsDeleted(Loop &L)
bool isFunctionInPrintList(StringRef FunctionName)
isFunctionInPrintList - returns true if a function should be printed via
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
void setPreservesAll()
Set by analyses that do not transform their input at all.
void dumpPassStructure(unsigned Offset) override
Print passes managed by this manager.
void preparePassManager(PMStack &PMS) override
Check if available pass managers are suitable for this pass or not.
virtual bool runOnLoop(Loop *L, LPPassManager &LPM)=0
LoopT * getParentLoop() const
StringRef getName() const
void cloneBasicBlockSimpleAnalysis(BasicBlock *From, BasicBlock *To, Loop *L)
SimpleAnalysis - Provides simple interface to update analysis info maintained by various passes...
Represents a single loop in the control flow graph.
StringRef getName() const
Return a constant reference to the value's name.
const Function * getParent() const
Return the enclosing method, or null if none.
LoopPass * getContainedPass(unsigned N)
void push(PMDataManager *PM)
PMDataManager provides the common place to manage the analysis data used by pass managers.
This file defines passes to print out IR in various granularities.
virtual void cloneBasicBlockAnalysis(BasicBlock *F, BasicBlock *T, Loop *L)
SimpleAnalysis - Provides simple interface to update analysis info maintained by various passes...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
PMDataManager * top() const
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
virtual void deleteAnalysisValue(Value *V, Loop *L)
deleteAnalysisValue - Delete analysis info associated with value V.
bool runOnFunction(Function &F) override
run - Execute all of the passes scheduled for execution.
unsigned getNumContainedPasses() const
This class implements an extremely fast bulk output stream that can only output to a stream...
The legacy pass manager's analysis pass to compute loop information.
void verifyLoop() const
Verify loop structure.
StringRef - Represent a constant reference to a string, i.e.
Pass * getAsPass() override
Legacy analysis pass which computes a DominatorTree.
This header defines various interfaces for pass management in LLVM.
iterator_range< block_iterator > blocks() const
void printLoop(Loop &L, raw_ostream &OS, const std::string &Banner="")
Function to print a loop's contents as LLVM's text IR assembly.
void dumpPreservedSet(const Pass *P) const
void initializeLCSSAVerificationPassPass(PassRegistry &)
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.