• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/Pass.h"
20 #include "llvm/Support/CBindingWrapping.h"
21 
22 namespace llvm {
23 
24 class Pass;
25 class Module;
26 
27 namespace legacy {
28 
29 class PassManagerImpl;
30 class FunctionPassManagerImpl;
31 
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
34 /// it is.
35 class PassManagerBase {
36 public:
37   virtual ~PassManagerBase();
38 
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;
45 };
46 
47 /// PassManager manages ModulePassManagers
48 class PassManager : public PassManagerBase {
49 public:
50 
51   PassManager();
52   ~PassManager() override;
53 
54   void add(Pass *P) override;
55 
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.
58   bool run(Module &M);
59 
60 private:
61   /// PassManagerImpl_New is the actual class. PassManager is just the
62   /// wraper to publish simple pass manager interface
63   PassManagerImpl *PM;
64 };
65 
66 /// FunctionPassManager manages FunctionPasses.
67 class FunctionPassManager : public PassManagerBase {
68 public:
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;
73 
74   void add(Pass *P) override;
75 
76   /// run - Execute all of the passes scheduled for execution.  Keep
77   /// track of whether any of the passes modifies the function, and if
78   /// so, return true.
79   ///
80   bool run(Function &F);
81 
82   /// doInitialization - Run all of the initializers for the function passes.
83   ///
84   bool doInitialization();
85 
86   /// doFinalization - Run all of the finalizers for the function passes.
87   ///
88   bool doFinalization();
89 
90 private:
91   FunctionPassManagerImpl *FPM;
92   Module *M;
93 };
94 
95 } // End legacy namespace
96 
97 // Create wrappers for C Binding types (see CBindingWrapping.h).
98 DEFINE_STDCXX_CONVERSION_FUNCTIONS(legacy::PassManagerBase, LLVMPassManagerRef)
99 
100 } // End llvm namespace
101 
102 #endif
103