30#define DEBUG_TYPE "loop-pass-manager"
34bool shouldPrintLoop(
const Loop &L) {
40 if (SourceLocFilterEmpty)
52class PrintLoopPassWrapper :
public LoopPass {
59 PrintLoopPassWrapper(
raw_ostream &OS,
const std::string &Banner)
60 :
LoopPass(ID), OS(OS), Banner(Banner) {}
67 if (shouldPrintLoop(*L))
72 StringRef getPassName()
const override {
return "Print Loop IR"; }
75char PrintLoopPassWrapper::ID = 0;
86 CurrentLoop =
nullptr;
91 if (L.isOutermost()) {
98 for (
auto I = LQ.begin(), E = LQ.end();
I != E; ++
I) {
99 if (*
I == L.getParentLoop()) {
121 Info.setPreservesAll();
125 assert((&L == CurrentLoop || CurrentLoop->contains(&L)) &&
126 "Must not delete loop outside the current loop tree!");
130 assert(LQ.back() == CurrentLoop &&
"Loop queue back isn't the current loop!");
133 if (&L == CurrentLoop) {
134 CurrentLoopDeleted =
true;
144 LI = &LIWP.getLoopInfo();
173 Changed |=
P->doInitialization(L, *
this);
180 bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
184 FunctionSize =
F.getInstructionCount();
186 while (!LQ.empty()) {
187 CurrentLoopDeleted =
false;
188 CurrentLoop = LQ.back();
197 CurrentLoop->getHeader()->getName());
202 bool LocalChanged =
false;
206#ifdef EXPENSIVE_CHECKS
207 uint64_t RefHash =
P->structuralHash(
F);
209 LocalChanged =
P->runOnLoop(CurrentLoop, *
this);
211#ifdef EXPENSIVE_CHECKS
212 if (!LocalChanged && (RefHash !=
P->structuralHash(
F))) {
213 llvm::errs() <<
"Pass modifies its input and doesn't report it: "
214 <<
P->getPassName() <<
"\n";
221 unsigned NewSize =
F.getInstructionCount();
224 if (NewSize != FunctionSize) {
225 int64_t Delta =
static_cast<int64_t
>(NewSize) -
226 static_cast<int64_t
>(FunctionSize);
228 FunctionToInstrCount, &
F);
230 FunctionSize = NewSize;
237 CurrentLoopDeleted ?
"<deleted loop>"
238 : CurrentLoop->getName());
241 if (!CurrentLoopDeleted) {
249 CurrentLoop->verifyLoop();
257 assert(CurrentLoop->isRecursivelyLCSSAForm(*DT, *LI));
263 F.getContext().yield();
270 CurrentLoopDeleted ?
"<deleted>"
271 : CurrentLoop->getHeader()->getName(),
274 if (CurrentLoopDeleted)
282 if (CurrentLoopDeleted) {
307 P->dumpPassStructure(
Offset + 1);
317 const std::string &Banner)
const {
318 return new PrintLoopPassWrapper(O, Banner);
330 while (!PMS.
empty() &&
346 while (!PMS.
empty() &&
355 assert (!PMS.
empty() &&
"Unable to create Loop Pass Manager");
383 const Function *
F = L->getHeader()->getParent();
387 const OptPassGate &Gate =
F->getContext().getOptPassGate();
392 if (
F->hasOptNone()) {
395 <<
F->getName() <<
"\n");
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)
static void addLoopIntoQueue(Loop *L, std::deque< Loop * > &LQ)
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...
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.
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.
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.
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.
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<AnalysisType>() - 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",...
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.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI bool isSourceLocInPrintList(const DebugLoc &Loc)
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.
LLVM_ABI bool isFunctionInPrintList(StringRef FunctionName)
LLVM_ABI bool isSourceLocFilterEmpty()
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.
LLVM_ABI LCSSAVerificationPass()