1 //===- LegacyPassManager.h - Legacy Container for Passes --------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_IR_LEGACYPASSMANAGER_H
17 #define LLVM_IR_LEGACYPASSMANAGER_H
19 #include "llvm/Pass.h"
20 #include "llvm/Support/CBindingWrapping.h"
29 class PassManagerImpl
;
30 class FunctionPassManagerImpl
;
32 /// PassManagerBase - An abstract interface to allow code to add passes to
33 /// a pass manager without having to hard-code what kind of pass manager
35 class PassManagerBase
{
37 virtual ~PassManagerBase();
39 /// Add a pass to the queue of passes to run. This passes ownership of
40 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
41 /// will be destroyed as well, so there is no need to delete the pass. This
42 /// may even destroy the pass right away if it is found to be redundant. This
43 /// implies that all passes MUST be allocated with 'new'.
44 virtual void add(Pass
*P
) = 0;
47 /// PassManager manages ModulePassManagers
48 class PassManager
: public PassManagerBase
{
52 ~PassManager() override
;
54 void add(Pass
*P
) override
;
56 /// run - Execute all of the passes scheduled for execution. Keep track of
57 /// whether any of the passes modifies the module, and if so, return true.
61 /// PassManagerImpl_New is the actual class. PassManager is just the
62 /// wraper to publish simple pass manager interface
66 /// FunctionPassManager manages FunctionPasses and BasicBlockPassManagers.
67 class FunctionPassManager
: public PassManagerBase
{
69 /// FunctionPassManager ctor - This initializes the pass manager. It needs,
70 /// but does not take ownership of, the specified Module.
71 explicit FunctionPassManager(Module
*M
);
72 ~FunctionPassManager() override
;
74 void add(Pass
*P
) override
;
76 /// run - Execute all of the passes scheduled for execution. Keep
77 /// track of whether any of the passes modifies the function, and if
80 bool run(Function
&F
);
82 /// doInitialization - Run all of the initializers for the function passes.
84 bool doInitialization();
86 /// doFinalization - Run all of the finalizers for the function passes.
88 bool doFinalization();
91 FunctionPassManagerImpl
*FPM
;
95 } // End legacy namespace
97 // Create wrappers for C Binding types (see CBindingWrapping.h).
98 DEFINE_STDCXX_CONVERSION_FUNCTIONS(legacy::PassManagerBase
, LLVMPassManagerRef
)
100 } // End llvm namespace