LLVM API Documentation

PassManager.h

Go to the documentation of this file.
00001 //===- llvm/PassManager.h - Container for Passes ----------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the PassManager class.  This class is used to hold,
00011 // maintain, and optimize execution of Passes.  The PassManager class ensures
00012 // that analysis results are available before a pass runs, and that Pass's are
00013 // destroyed when the PassManager is destroyed.
00014 //
00015 //===----------------------------------------------------------------------===//
00016 
00017 #ifndef LLVM_PASSMANAGER_H
00018 #define LLVM_PASSMANAGER_H
00019 
00020 #include "llvm/Pass.h"
00021 
00022 namespace llvm {
00023 
00024 class Pass;
00025 class ModulePass;
00026 class Module;
00027 class ModuleProvider;
00028 
00029 class PassManagerImpl;
00030 class FunctionPassManagerImpl;
00031 
00032 /// PassManagerBase - An abstract interface to allow code to add passes to
00033 /// a pass manager without having to hard-code what kind of pass manager
00034 /// it is.
00035 class PassManagerBase {
00036 public:
00037   virtual ~PassManagerBase();
00038 
00039   /// add - Add a pass to the queue of passes to run.  This passes ownership of
00040   /// the Pass to the PassManager.  When the PassManager is destroyed, the pass
00041   /// will be destroyed as well, so there is no need to delete the pass.  This
00042   /// implies that all passes MUST be allocated with 'new'.
00043   virtual void add(Pass *P) = 0;
00044 };
00045 
00046 /// PassManager manages ModulePassManagers
00047 class PassManager : public PassManagerBase {
00048 public:
00049 
00050   PassManager();
00051   ~PassManager();
00052 
00053   /// add - Add a pass to the queue of passes to run.  This passes ownership of
00054   /// the Pass to the PassManager.  When the PassManager is destroyed, the pass
00055   /// will be destroyed as well, so there is no need to delete the pass.  This
00056   /// implies that all passes MUST be allocated with 'new'.
00057   void add(Pass *P);
00058  
00059   /// run - Execute all of the passes scheduled for execution.  Keep track of
00060   /// whether any of the passes modifies the module, and if so, return true.
00061   bool run(Module &M);
00062 
00063 private:
00064 
00065   /// PassManagerImpl_New is the actual class. PassManager is just the 
00066   /// wraper to publish simple pass manager interface
00067   PassManagerImpl *PM;
00068 };
00069 
00070 /// FunctionPassManager manages FunctionPasses and BasicBlockPassManagers.
00071 class FunctionPassManager : public PassManagerBase {
00072 public:
00073   /// FunctionPassManager ctor - This initializes the pass manager.  It needs,
00074   /// but does not take ownership of, the specified module provider.
00075   explicit FunctionPassManager(ModuleProvider *P);
00076   ~FunctionPassManager();
00077  
00078   /// add - Add a pass to the queue of passes to run.  This passes
00079   /// ownership of the Pass to the PassManager.  When the
00080   /// PassManager_X is destroyed, the pass will be destroyed as well, so
00081   /// there is no need to delete the pass. (TODO delete passes.)
00082   /// This implies that all passes MUST be allocated with 'new'.
00083   void add(Pass *P);
00084 
00085   /// run - Execute all of the passes scheduled for execution.  Keep
00086   /// track of whether any of the passes modifies the function, and if
00087   /// so, return true.
00088   ///
00089   bool run(Function &F);
00090   
00091   /// doInitialization - Run all of the initializers for the function passes.
00092   ///
00093   bool doInitialization();
00094   
00095   /// doFinalization - Run all of the finalizers for the function passes.
00096   ///
00097   bool doFinalization();
00098   
00099   /// getModuleProvider - Return the module provider that this passmanager is
00100   /// currently using.  This is the module provider that it uses when a function
00101   /// is optimized that is non-resident in the module.
00102   ModuleProvider *getModuleProvider() const { return MP; }
00103   void setModuleProvider(ModuleProvider *NewMP) { MP = NewMP; }
00104 
00105 private:
00106   FunctionPassManagerImpl *FPM;
00107   ModuleProvider *MP;
00108 };
00109 
00110 } // End llvm namespace
00111 
00112 #endif