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 #include "llvm/Support/CBindingWrapping.h"
00022 
00023 namespace llvm {
00024 
00025 class Pass;
00026 class Module;
00027 
00028 class PassManagerImpl;
00029 class FunctionPassManagerImpl;
00030 
00031 /// PassManagerBase - An abstract interface to allow code to add passes to
00032 /// a pass manager without having to hard-code what kind of pass manager
00033 /// it is.
00034 class PassManagerBase {
00035 public:
00036   virtual ~PassManagerBase();
00037 
00038   /// add - Add a pass to the queue of passes to run.  This passes ownership of
00039   /// the Pass to the PassManager.  When the PassManager is destroyed, the pass
00040   /// will be destroyed as well, so there is no need to delete the pass.  This
00041   /// implies that all passes MUST be allocated with 'new'.
00042   virtual void add(Pass *P) = 0;
00043 };
00044 
00045 /// PassManager manages ModulePassManagers
00046 class PassManager : public PassManagerBase {
00047 public:
00048 
00049   PassManager();
00050   ~PassManager();
00051 
00052   /// add - Add a pass to the queue of passes to run.  This passes ownership of
00053   /// the Pass to the PassManager.  When the PassManager is destroyed, the pass
00054   /// will be destroyed as well, so there is no need to delete the pass.  This
00055   /// implies that all passes MUST be allocated with 'new'.
00056   void add(Pass *P);
00057 
00058   /// run - Execute all of the passes scheduled for execution.  Keep track of
00059   /// whether any of the passes modifies the module, and if so, return true.
00060   bool run(Module &M);
00061 
00062 private:
00063   /// PassManagerImpl_New is the actual class. PassManager is just the
00064   /// wraper to publish simple pass manager interface
00065   PassManagerImpl *PM;
00066 };
00067 
00068 /// FunctionPassManager manages FunctionPasses and BasicBlockPassManagers.
00069 class FunctionPassManager : public PassManagerBase {
00070 public:
00071   /// FunctionPassManager ctor - This initializes the pass manager.  It needs,
00072   /// but does not take ownership of, the specified Module.
00073   explicit FunctionPassManager(Module *M);
00074   ~FunctionPassManager();
00075 
00076   /// add - Add a pass to the queue of passes to run.  This passes
00077   /// ownership of the Pass to the PassManager.  When the
00078   /// PassManager_X is destroyed, the pass will be destroyed as well, so
00079   /// there is no need to delete the pass.
00080   /// This implies that all passes MUST be allocated with 'new'.
00081   void add(Pass *P);
00082 
00083   /// run - Execute all of the passes scheduled for execution.  Keep
00084   /// track of whether any of the passes modifies the function, and if
00085   /// so, return true.
00086   ///
00087   bool run(Function &F);
00088 
00089   /// doInitialization - Run all of the initializers for the function passes.
00090   ///
00091   bool doInitialization();
00092 
00093   /// doFinalization - Run all of the finalizers for the function passes.
00094   ///
00095   bool doFinalization();
00096 
00097 private:
00098   FunctionPassManagerImpl *FPM;
00099   Module *M;
00100 };
00101 
00102 // Create wrappers for C Binding types (see CBindingWrapping.h).
00103 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef)
00104 
00105 } // End llvm namespace
00106 
00107 #endif