31 #define DEBUG_TYPE "loop-pass-manager" 37 class PrintLoopPassWrapper :
public LoopPass {
44 PrintLoopPassWrapper(
raw_ostream &OS,
const std::string &Banner)
53 if (BBI != L->
blocks().end() &&
60 StringRef getPassName()
const override {
return "Print Loop IR"; }
75 CurrentLoop =
nullptr;
87 for (
auto I = LQ.begin(),
E = LQ.end();
I !=
E; ++
I) {
110 Info.setPreservesAll();
115 "Must not delete loop outside the current loop tree!");
119 assert(LQ.back() == CurrentLoop &&
"Loop queue back isn't the current loop!");
122 if (&L == CurrentLoop) {
123 CurrentLoopDeleted =
true;
132 auto &LIWP = getAnalysis<LoopInfoWrapperPass>();
133 LI = &LIWP.getLoopInfo();
136 DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
138 bool Changed =
false;
162 Changed |=
P->doInitialization(L, *
this);
169 bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
173 FunctionSize =
F.getInstructionCount();
175 while (!LQ.empty()) {
176 CurrentLoopDeleted =
false;
177 CurrentLoop = LQ.back();
191 bool LocalChanged =
false;
195 #ifdef EXPENSIVE_CHECKS 196 uint64_t RefHash = StructuralHash(
F);
198 LocalChanged =
P->runOnLoop(CurrentLoop, *
this);
200 #ifdef EXPENSIVE_CHECKS 201 if (!LocalChanged && (RefHash != StructuralHash(
F))) {
202 llvm::errs() <<
"Pass modifies its input and doesn't report it: " 203 <<
P->getPassName() <<
"\n";
208 Changed |= LocalChanged;
210 unsigned NewSize =
F.getInstructionCount();
213 if (NewSize != FunctionSize) {
214 int64_t Delta = static_cast<int64_t>(NewSize) -
215 static_cast<int64_t>(FunctionSize);
217 FunctionToInstrCount, &
F);
219 FunctionSize = NewSize;
226 CurrentLoopDeleted ?
"<deleted loop>" 230 if (!CurrentLoopDeleted) {
254 F.getContext().yield();
261 CurrentLoopDeleted ?
"<deleted>" 265 if (CurrentLoopDeleted)
273 if (CurrentLoopDeleted) {
287 Changed |=
P->doFinalization();
298 P->dumpPassStructure(
Offset + 1);
308 const std::string &Banner)
const {
309 return new PrintLoopPassWrapper(
O, Banner);
321 while (!PMS.
empty() &&
337 while (!PMS.
empty() &&
346 assert (!PMS.
empty() &&
"Unable to create Loop Pass Manager");
382 if (
F->hasOptNone()) {
385 <<
F->getName() <<
"\n");
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")
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
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...
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.
void assignPassManager(PMStack &PMS, PassManagerType PMT) override
Assign pass manager to manage this pass.
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,...
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.
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.
void freePass(Pass *P, StringRef Msg, enum PassDebuggingString)
Remove P.
bool isOutermost() const
Return true if the loop does not have a parent (natural) loop.
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
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
LLVM Basic Block Representation.
static std::string getDescription(const Loop &L)
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.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
#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.
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
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)
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.
LoopT * getParentLoop() const
Return the parent loop if it exists or nullptr for top level loops.
StringRef getName() const
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.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void erase_value(Container &C, ValueType V)
Wrapper function to remove a value from a container:
PMDataManager * top() const
bool runOnFunction(Function &F) override
run - Execute all of the passes scheduled for execution.
static void addLoopIntoQueue(Loop *L, std::deque< Loop * > &LQ)
unsigned getNumContainedPasses() const
bool isRecursivelyLCSSAForm(const DominatorTree &DT, const LoopInfo &LI) const
Return true if this Loop and all inner subloops are in LCSSA form.
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.
auto reverse(ContainerTy &&C, std::enable_if_t< has_rbegin< ContainerTy >::value > *=nullptr)
This header defines various interfaces for pass management in LLVM.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
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.