blob: 2b87143276b9a18db5d248998c9f80bc6ce1570f [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- LegacyPassManager.h - Legacy Container for Passes --------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
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
22namespace llvm {
23
24class Pass;
25class Module;
26
27namespace legacy {
28
29class PassManagerImpl;
30class 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.
35class PassManagerBase {
36public:
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
48class PassManager : public PassManagerBase {
49public:
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
60private:
61 /// PassManagerImpl_New is the actual class. PassManager is just the
62 /// wraper to publish simple pass manager interface
63 PassManagerImpl *PM;
64};
65
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020066/// FunctionPassManager manages FunctionPasses.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010067class FunctionPassManager : public PassManagerBase {
68public:
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
90private:
91 FunctionPassManagerImpl *FPM;
92 Module *M;
93};
94
95} // End legacy namespace
96
97// Create wrappers for C Binding types (see CBindingWrapping.h).
98DEFINE_STDCXX_CONVERSION_FUNCTIONS(legacy::PassManagerBase, LLVMPassManagerRef)
99
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100100} // End llvm namespace
101
102#endif