X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FIR%2FLegacyPassManagers.h;h=b8e33478d6a9d3666db8076ffcbb270c75bbd31d;hb=ef112d46b98642b59c657f1560f7e1c21b13a0da;hp=f6065a4e21a66d86c0d4b82a9f0cf071a839b5ac;hpb=68b0d1d2b47f1be8eec2ce57c8119906c354ccd8;p=oota-llvm.git diff --git a/include/llvm/IR/LegacyPassManagers.h b/include/llvm/IR/LegacyPassManagers.h index f6065a4e21a..b8e33478d6a 100644 --- a/include/llvm/IR/LegacyPassManagers.h +++ b/include/llvm/IR/LegacyPassManagers.h @@ -11,11 +11,12 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_PASSMANAGERS_H -#define LLVM_PASSMANAGERS_H +#ifndef LLVM_IR_LEGACYPASSMANAGERS_H +#define LLVM_IR_LEGACYPASSMANAGERS_H #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Pass.h" @@ -61,7 +62,7 @@ // // [o] class FunctionPassManager; // -// This is a external interface used by JIT to manage FunctionPasses. This +// This is a external interface used to manage FunctionPasses. This // interface relies on FunctionPassManagerImpl to do all the tasks. // // [o] class FunctionPassManagerImpl : public ModulePass, PMDataManager, @@ -118,6 +119,7 @@ class PassManagerPrettyStackEntry : public PrettyStackTraceEntry { Pass *P; Value *V; Module *M; + public: explicit PassManagerPrettyStackEntry(Pass *p) : P(p), V(nullptr), M(nullptr) {} // When P is releaseMemory'd. @@ -130,7 +132,6 @@ public: void print(raw_ostream &OS) const override; }; - //===----------------------------------------------------------------------===// // PMStack // @@ -158,7 +159,6 @@ private: std::vector S; }; - //===----------------------------------------------------------------------===// // PMTopLevelManager // @@ -195,16 +195,16 @@ public: /// then return NULL. Pass *findAnalysisPass(AnalysisID AID); + /// Retrieve the PassInfo for an analysis. + const PassInfo *findAnalysisPassInfo(AnalysisID AID) const; + /// Find analysis usage information for the pass P. AnalysisUsage *findAnalysisUsage(Pass *P); virtual ~PMTopLevelManager(); /// Add immutable pass and initialize it. - inline void addImmutablePass(ImmutablePass *P) { - P->initializePass(); - ImmutablePasses.push_back(P); - } + void addImmutablePass(ImmutablePass *P); inline SmallVectorImpl& getImmutablePasses() { return ImmutablePasses; @@ -228,12 +228,10 @@ public: PMStack activeStack; protected: - /// Collection of pass managers SmallVector PassManagers; private: - /// Collection of pass managers that are not directly maintained /// by this pass manager SmallVector IndirectPassManagers; @@ -248,13 +246,56 @@ private: DenseMap > InversedLastUser; /// Immutable passes are managed by top level manager. - SmallVector ImmutablePasses; - - DenseMap AnUsageMap; + SmallVector ImmutablePasses; + + /// Map from ID to immutable passes. + SmallDenseMap ImmutablePassMap; + + + /// A wrapper around AnalysisUsage for the purpose of uniqueing. The wrapper + /// is used to avoid needing to make AnalysisUsage itself a folding set node. + struct AUFoldingSetNode : public FoldingSetNode { + AnalysisUsage AU; + AUFoldingSetNode(const AnalysisUsage &AU) : AU(AU) {} + void Profile(FoldingSetNodeID &ID) const { + Profile(ID, AU); + } + static void Profile(FoldingSetNodeID &ID, const AnalysisUsage &AU) { + // TODO: We could consider sorting the dependency arrays within the + // AnalysisUsage (since they are conceptually unordered). + ID.AddBoolean(AU.getPreservesAll()); + auto ProfileVec = [&](const SmallVectorImpl& Vec) { + ID.AddInteger(Vec.size()); + for(AnalysisID AID : Vec) + ID.AddPointer(AID); + }; + ProfileVec(AU.getRequiredSet()); + ProfileVec(AU.getRequiredTransitiveSet()); + ProfileVec(AU.getPreservedSet()); + ProfileVec(AU.getUsedSet()); + } + }; + + // Contains all of the unique combinations of AnalysisUsage. This is helpful + // when we have multiple instances of the same pass since they'll usually + // have the same analysis usage and can share storage. + FoldingSet UniqueAnalysisUsages; + + // Allocator used for allocating UAFoldingSetNodes. This handles deletion of + // all allocated nodes in one fell swoop. + SpecificBumpPtrAllocator AUFoldingSetNodeAllocator; + + // Maps from a pass to it's associated entry in UniqueAnalysisUsages. Does + // not own the storage associated with either key or value.. + DenseMap AnUsageMap; + + /// Collection of PassInfo objects found via analysis IDs and in this top + /// level manager. This is used to memoize queries to the pass registry. + /// FIXME: This is an egregious hack because querying the pass registry is + /// either slow or racy. + mutable DenseMap AnalysisPassInfos; }; - - //===----------------------------------------------------------------------===// // PMDataManager @@ -262,7 +303,6 @@ private: /// used by pass managers. class PMDataManager { public: - explicit PMDataManager() : TPM(nullptr), Depth(0) { initializeAnalysisInfo(); } @@ -310,13 +350,12 @@ public: // passes that are managed by this manager. bool preserveHigherLevelAnalysis(Pass *P); - - /// Populate RequiredPasses with analysis pass that are required by - /// pass P and are available. Populate ReqPassNotAvailable with analysis - /// pass that are required by pass P but are not available. - void collectRequiredAnalysis(SmallVectorImpl &RequiredPasses, - SmallVectorImpl &ReqPassNotAvailable, - Pass *P); + /// Populate UsedPasses with analysis pass that are used or required by pass + /// P and are available. Populate ReqPassNotAvailable with analysis pass that + /// are required by pass P but are not available. + void collectRequiredAndUsedAnalyses( + SmallVectorImpl &UsedPasses, + SmallVectorImpl &ReqPassNotAvailable, Pass *P); /// All Required analyses should be available to the pass as it runs! Here /// we fill in the AnalysisImpls member of the pass so that it can @@ -342,6 +381,7 @@ public: enum PassDebuggingString S2, StringRef Msg); void dumpRequiredSet(const Pass *P) const; void dumpPreservedSet(const Pass *P) const; + void dumpUsedSet(const Pass *P) const; unsigned getNumContainedPasses() const { return (unsigned)PassVector.size(); @@ -365,7 +405,6 @@ public: } protected: - // Top level manager. PMTopLevelManager *TPM; @@ -393,7 +432,7 @@ private: // Collection of higher level analysis used by the pass managed by // this manager. - SmallVector HigherLevelAnalysis; + SmallVector HigherLevelAnalysis; unsigned Depth; }; @@ -430,9 +469,9 @@ public: /// doFinalization - Overrides ModulePass doFinalization for global /// finalization tasks - /// + /// using ModulePass::doFinalization; - + /// doFinalization - Run all of the finalizers for the function passes. /// bool doFinalization(Module &M) override; @@ -464,7 +503,6 @@ public: }; Timer *getPassTimer(Pass *); - } #endif