29 #define DEBUG_TYPE "loop-pass-manager" 35 class PrintLoopPassWrapper :
public LoopPass {
42 PrintLoopPassWrapper(
raw_ostream &OS,
const std::string &Banner)
43 :
LoopPass(ID), OS(OS), Banner(Banner) {}
51 if (BBI != L->
blocks().end() &&
58 StringRef getPassName()
const override {
return "Print Loop IR"; }
73 CurrentLoop =
nullptr;
85 for (
auto I = LQ.begin(),
E = LQ.end();
I !=
E; ++
I) {
107 if (
BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
145 "Must not delete loop outside the current loop tree!");
149 assert(LQ.back() == CurrentLoop &&
"Loop queue back isn't the current loop!");
150 LQ.erase(
std::remove(LQ.begin(), LQ.end(), &L), LQ.end());
152 if (&L == CurrentLoop) {
153 CurrentLoopDeleted =
true;
162 auto &LIWP = getAnalysis<LoopInfoWrapperPass>();
163 LI = &LIWP.getLoopInfo();
166 DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
168 bool Changed =
false;
205 while (!LQ.empty()) {
206 CurrentLoopDeleted =
false;
207 CurrentLoop = LQ.back();
219 bool LocalChanged =
false;
223 LocalChanged = P->
runOnLoop(CurrentLoop, *
this);
224 Changed |= LocalChanged;
229 if (NewSize != FunctionSize) {
230 int64_t Delta =
static_cast<int64_t
>(NewSize) -
231 static_cast<int64_t>(FunctionSize);
233 FunctionToInstrCount, &F);
234 InstrCount =
static_cast<int64_t
>(
InstrCount) + Delta;
235 FunctionSize = NewSize;
242 CurrentLoopDeleted ?
"<deleted loop>" 246 if (CurrentLoopDeleted) {
279 CurrentLoopDeleted ?
"<deleted>" 283 if (CurrentLoopDeleted)
291 if (CurrentLoopDeleted) {
313 errs().
indent(Offset*2) <<
"Loop Pass Manager\n";
326 const std::string &Banner)
const {
327 return new PrintLoopPassWrapper(O, Banner);
339 while (!PMS.
empty() &&
355 while (!PMS.
empty() &&
364 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.
This class represents lattice values for constants.
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. ...
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.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
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)
bool mustPreserveAnalysisID(char &AID) const
mustPreserveAnalysisID - This method serves the same function as getAnalysisIfAvailable, but works if you just have an AnalysisID.
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...
virtual bool shouldRunPass(const Pass *P, const Module &U)
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...
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.
This is an important class for using LLVM in a threaded context.
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 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.