xref: /aosp_15_r20/external/llvm/include/llvm/IR/LegacyPassManager.h (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===- LegacyPassManager.h - Legacy Container for Passes --------*- C++ -*-===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This file defines the legacy PassManager class.  This class is used to hold,
11*9880d681SAndroid Build Coastguard Worker // maintain, and optimize execution of Passes.  The PassManager class ensures
12*9880d681SAndroid Build Coastguard Worker // that analysis results are available before a pass runs, and that Pass's are
13*9880d681SAndroid Build Coastguard Worker // destroyed when the PassManager is destroyed.
14*9880d681SAndroid Build Coastguard Worker //
15*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
16*9880d681SAndroid Build Coastguard Worker 
17*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_IR_LEGACYPASSMANAGER_H
18*9880d681SAndroid Build Coastguard Worker #define LLVM_IR_LEGACYPASSMANAGER_H
19*9880d681SAndroid Build Coastguard Worker 
20*9880d681SAndroid Build Coastguard Worker #include "llvm/Pass.h"
21*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/CBindingWrapping.h"
22*9880d681SAndroid Build Coastguard Worker 
23*9880d681SAndroid Build Coastguard Worker namespace llvm {
24*9880d681SAndroid Build Coastguard Worker 
25*9880d681SAndroid Build Coastguard Worker class Pass;
26*9880d681SAndroid Build Coastguard Worker class Module;
27*9880d681SAndroid Build Coastguard Worker 
28*9880d681SAndroid Build Coastguard Worker namespace legacy {
29*9880d681SAndroid Build Coastguard Worker 
30*9880d681SAndroid Build Coastguard Worker class PassManagerImpl;
31*9880d681SAndroid Build Coastguard Worker class FunctionPassManagerImpl;
32*9880d681SAndroid Build Coastguard Worker 
33*9880d681SAndroid Build Coastguard Worker /// PassManagerBase - An abstract interface to allow code to add passes to
34*9880d681SAndroid Build Coastguard Worker /// a pass manager without having to hard-code what kind of pass manager
35*9880d681SAndroid Build Coastguard Worker /// it is.
36*9880d681SAndroid Build Coastguard Worker class PassManagerBase {
37*9880d681SAndroid Build Coastguard Worker public:
38*9880d681SAndroid Build Coastguard Worker   virtual ~PassManagerBase();
39*9880d681SAndroid Build Coastguard Worker 
40*9880d681SAndroid Build Coastguard Worker   /// Add a pass to the queue of passes to run.  This passes ownership of
41*9880d681SAndroid Build Coastguard Worker   /// the Pass to the PassManager.  When the PassManager is destroyed, the pass
42*9880d681SAndroid Build Coastguard Worker   /// will be destroyed as well, so there is no need to delete the pass.  This
43*9880d681SAndroid Build Coastguard Worker   /// may even destroy the pass right away if it is found to be redundant. This
44*9880d681SAndroid Build Coastguard Worker   /// implies that all passes MUST be allocated with 'new'.
45*9880d681SAndroid Build Coastguard Worker   virtual void add(Pass *P) = 0;
46*9880d681SAndroid Build Coastguard Worker };
47*9880d681SAndroid Build Coastguard Worker 
48*9880d681SAndroid Build Coastguard Worker /// PassManager manages ModulePassManagers
49*9880d681SAndroid Build Coastguard Worker class PassManager : public PassManagerBase {
50*9880d681SAndroid Build Coastguard Worker public:
51*9880d681SAndroid Build Coastguard Worker 
52*9880d681SAndroid Build Coastguard Worker   PassManager();
53*9880d681SAndroid Build Coastguard Worker   ~PassManager() override;
54*9880d681SAndroid Build Coastguard Worker 
55*9880d681SAndroid Build Coastguard Worker   void add(Pass *P) override;
56*9880d681SAndroid Build Coastguard Worker 
57*9880d681SAndroid Build Coastguard Worker   /// run - Execute all of the passes scheduled for execution.  Keep track of
58*9880d681SAndroid Build Coastguard Worker   /// whether any of the passes modifies the module, and if so, return true.
59*9880d681SAndroid Build Coastguard Worker   bool run(Module &M);
60*9880d681SAndroid Build Coastguard Worker 
61*9880d681SAndroid Build Coastguard Worker private:
62*9880d681SAndroid Build Coastguard Worker   /// PassManagerImpl_New is the actual class. PassManager is just the
63*9880d681SAndroid Build Coastguard Worker   /// wraper to publish simple pass manager interface
64*9880d681SAndroid Build Coastguard Worker   PassManagerImpl *PM;
65*9880d681SAndroid Build Coastguard Worker };
66*9880d681SAndroid Build Coastguard Worker 
67*9880d681SAndroid Build Coastguard Worker /// FunctionPassManager manages FunctionPasses and BasicBlockPassManagers.
68*9880d681SAndroid Build Coastguard Worker class FunctionPassManager : public PassManagerBase {
69*9880d681SAndroid Build Coastguard Worker public:
70*9880d681SAndroid Build Coastguard Worker   /// FunctionPassManager ctor - This initializes the pass manager.  It needs,
71*9880d681SAndroid Build Coastguard Worker   /// but does not take ownership of, the specified Module.
72*9880d681SAndroid Build Coastguard Worker   explicit FunctionPassManager(Module *M);
73*9880d681SAndroid Build Coastguard Worker   ~FunctionPassManager() override;
74*9880d681SAndroid Build Coastguard Worker 
75*9880d681SAndroid Build Coastguard Worker   void add(Pass *P) override;
76*9880d681SAndroid Build Coastguard Worker 
77*9880d681SAndroid Build Coastguard Worker   /// run - Execute all of the passes scheduled for execution.  Keep
78*9880d681SAndroid Build Coastguard Worker   /// track of whether any of the passes modifies the function, and if
79*9880d681SAndroid Build Coastguard Worker   /// so, return true.
80*9880d681SAndroid Build Coastguard Worker   ///
81*9880d681SAndroid Build Coastguard Worker   bool run(Function &F);
82*9880d681SAndroid Build Coastguard Worker 
83*9880d681SAndroid Build Coastguard Worker   /// doInitialization - Run all of the initializers for the function passes.
84*9880d681SAndroid Build Coastguard Worker   ///
85*9880d681SAndroid Build Coastguard Worker   bool doInitialization();
86*9880d681SAndroid Build Coastguard Worker 
87*9880d681SAndroid Build Coastguard Worker   /// doFinalization - Run all of the finalizers for the function passes.
88*9880d681SAndroid Build Coastguard Worker   ///
89*9880d681SAndroid Build Coastguard Worker   bool doFinalization();
90*9880d681SAndroid Build Coastguard Worker 
91*9880d681SAndroid Build Coastguard Worker private:
92*9880d681SAndroid Build Coastguard Worker   FunctionPassManagerImpl *FPM;
93*9880d681SAndroid Build Coastguard Worker   Module *M;
94*9880d681SAndroid Build Coastguard Worker };
95*9880d681SAndroid Build Coastguard Worker 
96*9880d681SAndroid Build Coastguard Worker } // End legacy namespace
97*9880d681SAndroid Build Coastguard Worker 
98*9880d681SAndroid Build Coastguard Worker // Create wrappers for C Binding types (see CBindingWrapping.h).
99*9880d681SAndroid Build Coastguard Worker DEFINE_STDCXX_CONVERSION_FUNCTIONS(legacy::PassManagerBase, LLVMPassManagerRef)
100*9880d681SAndroid Build Coastguard Worker 
101*9880d681SAndroid Build Coastguard Worker } // End llvm namespace
102*9880d681SAndroid Build Coastguard Worker 
103*9880d681SAndroid Build Coastguard Worker #endif
104