-
Notifications
You must be signed in to change notification settings - Fork 0
/
PassManager.h
252 lines (203 loc) · 7.26 KB
/
PassManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#pragma once
#include <string>
#include "PassStructure.h"
namespace cchips {
class PassManagerImpl;
class FunctionPassManagerImpl;
class BBPassManagerImpl;
class InsnPassManagerImpl;
using AnalysisID = const void *;
class Pass
{
public:
enum pass_type {
pass_unknown = 0,
pass_region = 1,
pass_basicblock,
pass_loop,
pass_function,
pass_instruction,
pass_callgraphscc,
pass_module,
pass_passmanager
};
enum passmanager_type {
passmanager_unknown = 0,
passmanager_module = 1,
passmanager_callgraph,
passmanager_function,
passmanager_loop,
passmanager_region,
passmanager_basicblock,
passmanager_instruction,
passmanager_last
};
Pass() {}
explicit Pass(pass_type type, char &pass_id) : m_pass_id(&pass_id), m_pass_type(type) {}
Pass(const Pass &) = delete;
Pass &operator=(const Pass &) = delete;
virtual ~Pass() {}
pass_type getPassType() const { return m_pass_type; }
virtual std::string_view getPassName() const;
AnalysisID getPassID() const { return m_pass_id; }
virtual passmanager_type getPotentialPassManagerType() const { return passmanager_unknown; }
virtual bool DoInitialization(Module &) { return false; }
virtual bool DoFinalization(Module &) { return false; }
private:
const void* m_pass_id;
pass_type m_pass_type;
};
class ModulePass : public Pass
{
public:
explicit ModulePass(char &pid) : Pass(Pass::pass_module, pid) {}
~ModulePass() override {}
virtual bool runOnModule(std::shared_ptr<Module> M) = 0;
Pass::passmanager_type getPotentialPassManagerType() const override { return Pass::passmanager_module; }
private:
};
class FunctionPass : public Pass
{
public:
explicit FunctionPass(char &pid) : Pass(Pass::pass_function, pid) {}
~FunctionPass() override {}
virtual bool runOnFunction(std::shared_ptr<Function> Func) = 0;
Pass::passmanager_type getPotentialPassManagerType() const override { return Pass::passmanager_function; }
private:
};
class BasicBlockPass : public Pass
{
public:
explicit BasicBlockPass(char &pid) : Pass(Pass::pass_basicblock, pid) {}
~BasicBlockPass() override {}
virtual bool runOnBasicBlock(std::shared_ptr<BasicBlock> BB) = 0;
Pass::passmanager_type getPotentialPassManagerType() const override { return Pass::passmanager_basicblock; }
private:
};
class RegionPass : public Pass
{
public:
explicit RegionPass(char &pid) : Pass(Pass::pass_region, pid) {}
~RegionPass() override {}
virtual bool runOnRegion(/*Region *region*/) = 0;
Pass::passmanager_type getPotentialPassManagerType() const override { return Pass::passmanager_region; }
private:
};
class LoopPass : public Pass
{
public:
explicit LoopPass(char &pid) : Pass(Pass::pass_loop, pid) {}
~LoopPass() override {}
virtual bool runOnLoop(/*Loop *region*/) = 0;
Pass::passmanager_type getPotentialPassManagerType() const override { return Pass::passmanager_loop; }
private:
};
class InstructionPass : public Pass
{
public:
explicit InstructionPass(char &pid) : Pass(Pass::pass_instruction, pid) {}
~InstructionPass() override {}
virtual bool runOnInstruction(std::shared_ptr<CapInsn> insn) = 0;
Pass::passmanager_type getPotentialPassManagerType() const override { return Pass::passmanager_instruction; }
private:
};
class PMDataManager
{
};
class PassManagerBase
{
public:
virtual ~PassManagerBase() = default;
virtual bool Add(AnalysisID ID, std::unique_ptr<Pass> P) = 0;
virtual Pass::passmanager_type GetPassManagerType() const = 0;
virtual void sequence(const std::vector<AnalysisID>& seq_list) = 0;
};
class PassManager : public PassManagerBase
{
public:
PassManager();
~PassManager() = default;
bool Add(AnalysisID ID, std::unique_ptr<Pass> P) override;
Pass::passmanager_type GetPassManagerType() const {
return Pass::passmanager_module;
}
bool Run(std::shared_ptr<Module> M);
void sequence(const std::vector<AnalysisID>& seq_list);
private:
std::unique_ptr<PassManagerImpl> MPMI;
};
class FunctionPassManager : public PassManagerBase
{
public:
FunctionPassManager();
~FunctionPassManager() = default;
bool Add(AnalysisID ID, std::unique_ptr<Pass> P) override;
Pass::passmanager_type GetPassManagerType() const {
return Pass::passmanager_function;
}
bool Run(std::shared_ptr<Function> F);
void sequence(const std::vector<AnalysisID>& seq_list);
private:
std::unique_ptr<FunctionPassManagerImpl> FPMI;
};
class BBPassManager : public PassManagerBase
{
public:
BBPassManager();
~BBPassManager() = default;
bool Add(AnalysisID ID, std::unique_ptr<Pass> P) override;
Pass::passmanager_type GetPassManagerType() const {
return Pass::passmanager_basicblock;
}
bool Run(std::shared_ptr<BasicBlock> BB);
void sequence(const std::vector<AnalysisID>& seq_list);
private:
std::unique_ptr<BBPassManagerImpl> BPMI;
};
class RGPassManager : public PassManagerBase
{
public:
RGPassManager() {
//RPMI = std::make_unique<RGPassManagerImpl>();
}
~RGPassManager() = default;
bool Add(AnalysisID ID, std::unique_ptr<Pass> P) override { return false; }
Pass::passmanager_type GetPassManagerType() const {
return Pass::passmanager_region;
}
bool Run(std::shared_ptr<BasicBlock> BB) {}
void sequence(const std::vector<AnalysisID>& seq_list) { return; }
private:
//std::unique_ptr<RGPassManagerImpl> RPMI;
};
class LPPassManager : public PassManagerBase
{
public:
LPPassManager() {
//LPMI = std::make_unique<LPPassManagerImpl>();
}
~LPPassManager() = default;
bool Add(AnalysisID ID, std::unique_ptr<Pass> P) override { return false; }
Pass::passmanager_type GetPassManagerType() const {
return Pass::passmanager_loop;
}
bool Run(std::shared_ptr<BasicBlock> BB) {}
void sequence(const std::vector<AnalysisID>& seq_list) { return; }
private:
//std::unique_ptr<LPPassManagerImpl> LPMI;
};
class InsnPassManager : public PassManagerBase
{
public:
InsnPassManager();
~InsnPassManager() = default;
bool Add(AnalysisID ID, std::unique_ptr<Pass> P) override;
Pass::passmanager_type GetPassManagerType() const {
return Pass::passmanager_instruction;
}
bool Run(std::shared_ptr<CapInsn> insn);
void sequence(const std::vector<AnalysisID>& seq_list);
private:
std::unique_ptr<InsnPassManagerImpl> IPMI;
};
} // namespace cchips