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