LLVM API Documentation

LegacyPassManager.h
Go to the documentation of this file.
00001 //===- LegacyPassManager.h - Legacy 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 legacy 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_IR_LEGACYPASSMANAGER_H
00018 #define LLVM_IR_LEGACYPASSMANAGER_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 namespace legacy {
00029 
00030 class PassManagerImpl;
00031 class FunctionPassManagerImpl;
00032 
00033 /// PassManagerBase - An abstract interface to allow code to add passes to
00034 /// a pass manager without having to hard-code what kind of pass manager
00035 /// it is.
00036 class PassManagerBase {
00037 public:
00038   virtual ~PassManagerBase();
00039 
00040   /// add - Add a pass to the queue of passes to run.  This passes ownership of
00041   /// the Pass to the PassManager.  When the PassManager is destroyed, the pass
00042   /// will be destroyed as well, so there is no need to delete the pass.  This
00043   /// implies that all passes MUST be allocated with 'new'.
00044   virtual void add(Pass *P) = 0;
00045 };
00046 
00047 /// PassManager manages ModulePassManagers
00048 class PassManager : public PassManagerBase {
00049 public:
00050 
00051   PassManager();
00052   ~PassManager();
00053 
00054   /// add - Add a pass to the queue of passes to run.  This passes ownership of
00055   /// the Pass to the PassManager.  When the PassManager is destroyed, the pass
00056   /// will be destroyed as well, so there is no need to delete the pass.  This
00057   /// implies that all passes MUST be allocated with 'new'.
00058   void add(Pass *P) override;
00059 
00060   /// run - Execute all of the passes scheduled for execution.  Keep track of
00061   /// whether any of the passes modifies the module, and if so, return true.
00062   bool run(Module &M);
00063 
00064 private:
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.
00075   explicit FunctionPassManager(Module *M);
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.
00082   /// This implies that all passes MUST be allocated with 'new'.
00083   void add(Pass *P) override;
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 private:
00100   FunctionPassManagerImpl *FPM;
00101   Module *M;
00102 };
00103 
00104 } // End legacy namespace
00105 
00106 // Create wrappers for C Binding types (see CBindingWrapping.h).
00107 DEFINE_STDCXX_CONVERSION_FUNCTIONS(legacy::PassManagerBase, LLVMPassManagerRef)
00108 
00109 } // End llvm namespace
00110 
00111 #endif