1 //===- llvm/PassAnalysisSupport.h - Analysis Pass Support code ---*- C++ -*-==//
3 // This file defines stuff that is used to define and "use" Analysis Passes.
4 // This file is automatically #included by Pass.h, so:
6 // NO .CPP FILES SHOULD INCLUDE THIS FILE DIRECTLY
8 // Instead, #include Pass.h
10 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_PASS_ANALYSIS_SUPPORT_H
13 #define LLVM_PASS_ANALYSIS_SUPPORT_H
15 // No need to include Pass.h, we are being included by it!
19 //===----------------------------------------------------------------------===//
20 // AnalysisUsage - Represent the analysis usage information of a pass. This
21 // tracks analyses that the pass REQUIRES (must available when the pass runs),
22 // and analyses that the pass PRESERVES (the pass does not invalidate the
23 // results of these analyses). This information is provided by a pass to the
24 // Pass infrastructure through the getAnalysisUsage virtual function.
27 // Sets of analyses required and preserved by a pass
28 std::vector<AnalysisID> Required, Preserved;
31 AnalysisUsage() : PreservesAll(false) {}
33 // addRequires - Add the specified ID to the required set of the usage info
36 AnalysisUsage &addRequired(AnalysisID ID) {
37 Required.push_back(ID);
41 // addPreserves - Add the specified ID to the set of analyses preserved by
44 AnalysisUsage &addPreserved(AnalysisID ID) {
45 Preserved.push_back(ID);
49 // PreservesAll - Set by analyses that do not transform their input at all
50 void setPreservesAll() { PreservesAll = true; }
51 bool preservesAll() const { return PreservesAll; }
53 // preservesCFG - This function should be called to by the pass, iff they do
56 // 1. Add or remove basic blocks from the function
57 // 2. Modify terminator instructions in any way.
59 // This function annotates the AnalysisUsage info object to say that analyses
60 // that only depend on the CFG are preserved by this pass.
64 const std::vector<AnalysisID> &getRequiredSet() const { return Required; }
65 const std::vector<AnalysisID> &getPreservedSet() const { return Preserved; }
70 //===----------------------------------------------------------------------===//
71 // AnalysisResolver - Simple interface implemented by PassManager objects that
72 // is used to pull analysis information out of them.
74 struct AnalysisResolver {
75 virtual Pass *getAnalysisOrNullUp(AnalysisID ID) const = 0;
76 virtual Pass *getAnalysisOrNullDown(AnalysisID ID) const = 0;
77 Pass *getAnalysis(AnalysisID ID) {
78 Pass *Result = getAnalysisOrNullUp(ID);
79 assert(Result && "Pass has an incorrect analysis uses set!");
83 // getAnalysisToUpdate - Return an analysis result or null if it doesn't exist
84 Pass *getAnalysisToUpdate(AnalysisID ID) {
85 return getAnalysisOrNullUp(ID);
88 // Methods for introspecting into pass manager objects...
89 virtual unsigned getDepth() const = 0;
90 virtual unsigned getNumContainedPasses() const = 0;
91 virtual const Pass *getContainedPass(unsigned N) const = 0;
93 virtual void markPassUsed(AnalysisID P, Pass *User) = 0;
95 void startPass(Pass *P) {}
96 void endPass(Pass *P) {}
98 void setAnalysisResolver(Pass *P, AnalysisResolver *AR);