1//===- LegacyPassManager.h - Legacy Container for Passes --------*- C++ -*-===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8// 9// This file defines the legacy PassManager class. This class is used to hold, 10// maintain, and optimize execution of Passes. The PassManager class ensures 11// that analysis results are available before a pass runs, and that Pass's are 12// destroyed when the PassManager is destroyed. 13// 14//===----------------------------------------------------------------------===// 15 16#ifndef LLVM_IR_LEGACYPASSMANAGER_H 17#define LLVM_IR_LEGACYPASSMANAGER_H 18 19#include "llvm/Support/CBindingWrapping.h" 20 21namespace llvm { 22 23class Function; 24class Pass; 25class Module; 26 27namespace legacy { 28 29// Whether or not -debug-pass has been specified. For use to check if it's 30// specified alongside the new PM. 31bool debugPassSpecified(); 32 33class PassManagerImpl; 34class FunctionPassManagerImpl; 35 36/// PassManagerBase - An abstract interface to allow code to add passes to 37/// a pass manager without having to hard-code what kind of pass manager 38/// it is. 39class PassManagerBase { 40public: 41 virtual ~PassManagerBase(); 42 43 /// Add a pass to the queue of passes to run. This passes ownership of 44 /// the Pass to the PassManager. When the PassManager is destroyed, the pass 45 /// will be destroyed as well, so there is no need to delete the pass. This 46 /// may even destroy the pass right away if it is found to be redundant. This 47 /// implies that all passes MUST be allocated with 'new'. 48 virtual void add(Pass *P) = 0; 49}; 50 51/// PassManager manages ModulePassManagers 52class PassManager : public PassManagerBase { 53public: 54 55 PassManager(); 56 ~PassManager() override; 57 58 void add(Pass *P) override; 59 60 /// run - Execute all of the passes scheduled for execution. Keep track of 61 /// whether any of the passes modifies the module, and if so, return true. 62 bool run(Module &M); 63 64private: 65 /// PassManagerImpl_New is the actual class. PassManager is just the 66 /// wraper to publish simple pass manager interface 67 PassManagerImpl *PM; 68}; 69 70/// FunctionPassManager manages FunctionPasses. 71class FunctionPassManager : public PassManagerBase { 72public: 73 /// FunctionPassManager ctor - This initializes the pass manager. It needs, 74 /// but does not take ownership of, the specified Module. 75 explicit FunctionPassManager(Module *M); 76 ~FunctionPassManager() override; 77 78 void add(Pass *P) override; 79 80 /// run - Execute all of the passes scheduled for execution. Keep 81 /// track of whether any of the passes modifies the function, and if 82 /// so, return true. 83 /// 84 bool run(Function &F); 85 86 /// doInitialization - Run all of the initializers for the function passes. 87 /// 88 bool doInitialization(); 89 90 /// doFinalization - Run all of the finalizers for the function passes. 91 /// 92 bool doFinalization(); 93 94private: 95 FunctionPassManagerImpl *FPM; 96 Module *M; 97}; 98 99} // End legacy namespace 100 101// Create wrappers for C Binding types (see CBindingWrapping.h). 102DEFINE_STDCXX_CONVERSION_FUNCTIONS(legacy::PassManagerBase, LLVMPassManagerRef) 103 104} // End llvm namespace 105 106#endif 107