#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"
Pass *P;
Value *V;
Module *M;
+
public:
explicit PassManagerPrettyStackEntry(Pass *p)
: P(p), V(nullptr), M(nullptr) {} // When P is releaseMemory'd.
void print(raw_ostream &OS) const override;
};
-
//===----------------------------------------------------------------------===//
// PMStack
//
std::vector<PMDataManager *> S;
};
-
//===----------------------------------------------------------------------===//
// PMTopLevelManager
//
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<ImmutablePass *>& getImmutablePasses() {
return ImmutablePasses;
PMStack activeStack;
protected:
-
/// Collection of pass managers
SmallVector<PMDataManager *, 8> PassManagers;
private:
-
/// Collection of pass managers that are not directly maintained
/// by this pass manager
SmallVector<PMDataManager *, 8> IndirectPassManagers;
/// Immutable passes are managed by top level manager.
SmallVector<ImmutablePass *, 16> ImmutablePasses;
- DenseMap<Pass *, AnalysisUsage *> AnUsageMap;
+ /// Map from ID to immutable passes.
+ SmallDenseMap<AnalysisID, ImmutablePass *, 8> 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<AnalysisID>& 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<AUFoldingSetNode> UniqueAnalysisUsages;
+
+ // Allocator used for allocating UAFoldingSetNodes. This handles deletion of
+ // all allocated nodes in one fell swoop.
+ SpecificBumpPtrAllocator<AUFoldingSetNode> AUFoldingSetNodeAllocator;
+
+ // Maps from a pass to it's associated entry in UniqueAnalysisUsages. Does
+ // not own the storage associated with either key or value..
+ DenseMap<Pass *, AnalysisUsage*> 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.
mutable DenseMap<AnalysisID, const PassInfo *> AnalysisPassInfos;
};
-
-
//===----------------------------------------------------------------------===//
// PMDataManager
/// used by pass managers.
class PMDataManager {
public:
-
explicit PMDataManager() : TPM(nullptr), Depth(0) {
initializeAnalysisInfo();
}
// 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<Pass *> &RequiredPasses,
- SmallVectorImpl<AnalysisID> &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<Pass *> &UsedPasses,
+ SmallVectorImpl<AnalysisID> &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
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();
}
protected:
-
// Top level manager.
PMTopLevelManager *TPM;
/// 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;
};
Timer *getPassTimer(Pass *);
-
}
#endif