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 23namespace llvm { 24 25class Pass; 26class Module; 27 28class PassManagerImpl; 29class FunctionPassManagerImpl; 30 31/// PassManagerBase - An abstract interface to allow code to add passes to 32/// a pass manager without having to hard-code what kind of pass manager 33/// it is. 34class PassManagerBase { 35public: 36 virtual ~PassManagerBase(); 37 38 /// add - Add a pass to the queue of passes to run. This passes ownership of 39 /// the Pass to the PassManager. When the PassManager is destroyed, the pass 40 /// will be destroyed as well, so there is no need to delete the pass. This 41 /// implies that all passes MUST be allocated with 'new'. 42 virtual void add(Pass *P) = 0; 43}; 44 45/// PassManager manages ModulePassManagers 46class PassManager : public PassManagerBase { 47public: 48 49 PassManager(); 50 ~PassManager(); 51 52 /// add - Add a pass to the queue of passes to run. This passes ownership of 53 /// the Pass to the PassManager. When the PassManager is destroyed, the pass 54 /// will be destroyed as well, so there is no need to delete the pass. This 55 /// implies that all passes MUST be allocated with 'new'. 56 void add(Pass *P); 57 58 /// run - Execute all of the passes scheduled for execution. Keep track of 59 /// whether any of the passes modifies the module, and if so, return true. 60 bool run(Module &M); 61 62private: 63 /// PassManagerImpl_New is the actual class. PassManager is just the 64 /// wraper to publish simple pass manager interface 65 PassManagerImpl *PM; 66}; 67 68/// FunctionPassManager manages FunctionPasses and BasicBlockPassManagers. 69class FunctionPassManager : public PassManagerBase { 70public: 71 /// FunctionPassManager ctor - This initializes the pass manager. It needs, 72 /// but does not take ownership of, the specified Module. 73 explicit FunctionPassManager(Module *M); 74 ~FunctionPassManager(); 75 76 /// add - Add a pass to the queue of passes to run. This passes 77 /// ownership of the Pass to the PassManager. When the 78 /// PassManager_X is destroyed, the pass will be destroyed as well, so 79 /// there is no need to delete the pass. 80 /// This implies that all passes MUST be allocated with 'new'. 81 void add(Pass *P); 82 83 /// run - Execute all of the passes scheduled for execution. Keep 84 /// track of whether any of the passes modifies the function, and if 85 /// so, return true. 86 /// 87 bool run(Function &F); 88 89 /// doInitialization - Run all of the initializers for the function passes. 90 /// 91 bool doInitialization(); 92 93 /// doFinalization - Run all of the finalizers for the function passes. 94 /// 95 bool doFinalization(); 96 97private: 98 FunctionPassManagerImpl *FPM; 99 Module *M; 100}; 101 102// Create wrappers for C Binding types (see CBindingWrapping.h). 103DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef) 104 105} // End llvm namespace 106 107#endif 108