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