30#define DEBUG_TYPE "loop-pass-manager"
36class PrintLoopPassWrapper :
public LoopPass {
43 PrintLoopPassWrapper(
raw_ostream &
OS,
const std::string &Banner)
52 if (BBI != L->blocks().end() &&
62char PrintLoopPassWrapper::ID = 0;
73 CurrentLoop =
nullptr;
78 if (L.isOutermost()) {
85 for (
auto I = LQ.begin(), E = LQ.end();
I != E; ++
I) {
86 if (*
I == L.getParentLoop()) {
108 Info.setPreservesAll();
113 "Must not delete loop outside the current loop tree!");
117 assert(LQ.back() == CurrentLoop &&
"Loop queue back isn't the current loop!");
120 if (&L == CurrentLoop) {
121 CurrentLoopDeleted =
true;
130 auto &LIWP = getAnalysis<LoopInfoWrapperPass>();
131 LI = &LIWP.getLoopInfo();
134 DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
136 bool Changed =
false;
160 Changed |=
P->doInitialization(L, *
this);
167 bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
171 FunctionSize =
F.getInstructionCount();
173 while (!LQ.empty()) {
174 CurrentLoopDeleted =
false;
175 CurrentLoop = LQ.back();
189 bool LocalChanged =
false;
193#ifdef EXPENSIVE_CHECKS
196 LocalChanged =
P->runOnLoop(CurrentLoop, *
this);
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";
206 Changed |= LocalChanged;
208 unsigned NewSize =
F.getInstructionCount();
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;
224 CurrentLoopDeleted ?
"<deleted loop>"
228 if (!CurrentLoopDeleted) {
252 F.getContext().yield();
259 CurrentLoopDeleted ?
"<deleted>"
263 if (CurrentLoopDeleted)
271 if (CurrentLoopDeleted) {
285 Changed |=
P->doFinalization();
296 P->dumpPassStructure(
Offset + 1);
306 const std::string &Banner)
const {
307 return new PrintLoopPassWrapper(O, Banner);
319 while (!PMS.
empty() &&
335 while (!PMS.
empty() &&
344 assert (!PMS.
empty() &&
"Unable to create Loop Pass Manager");
372 const Function *
F = L->getHeader()->getParent();
381 if (
F->hasOptNone()) {
384 <<
F->getName() <<
"\n");
Analysis containing CSE Info
static std::string getDescription(const CallGraphSCC &SCC)
static unsigned InstrCount
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static void addLoopIntoQueue(Loop *L, std::deque< Loop * > &LQ)
Module.h This file contains the declarations for the Module class.
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...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
FunctionPass class - This class is used to implement most global optimizations.
bool runOnFunction(Function &F) override
run - Execute all of the passes scheduled for execution.
Pass * getAsPass() override
void dumpPassStructure(unsigned Offset) override
Print passes managed by this manager.
void markLoopAsDeleted(Loop &L)
LoopPass * getContainedPass(unsigned N)
void getAnalysisUsage(AnalysisUsage &Info) const override
Pass Manager itself does not invalidate any analysis info.
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
void verifyLoop() const
Verify loop structure.
BlockT * getHeader() const
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.
Pass * createPrinterPass(raw_ostream &O, const std::string &Banner) const override
getPrinterPass - Get a pass to print the function corresponding to a Loop.
virtual bool runOnLoop(Loop *L, LPPassManager &LPM)=0
void assignPassManager(PMStack &PMS, PassManagerType PMT) override
Assign pass manager to manage this pass.
bool skipLoop(const Loop *L) const
Optional passes call this function to check whether the pass should be skipped.
Represents a single loop in the control flow graph.
StringRef getName() const
bool isRecursivelyLCSSAForm(const DominatorTree &DT, const LoopInfo &LI, bool IgnoreTokens=true) const
Return true if this Loop and all inner subloops are in LCSSA form.
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(const StringRef PassName, StringRef IRDescription)
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! Here we fill in the AnalysisImpls m...
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
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...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Pass interface - Implemented by all 'passes'.
bool mustPreserveAnalysisID(char &AID) const
mustPreserveAnalysisID - This method serves the same function as getAnalysisIfAvailable,...
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
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.
StringRef getName() const
Return a constant reference to the value's name.
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.
void initializeLCSSAVerificationPassPass(PassRegistry &)
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:
Timer * getPassTimer(Pass *)
Request the timer for this legacy-pass-manager's pass instance.
auto reverse(ContainerTy &&C)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isFunctionInPrintList(StringRef FunctionName)
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
void printLoop(Loop &L, raw_ostream &OS, const std::string &Banner="")
Function to print a loop's contents as LLVM's text IR assembly.