@@ -44,18 +44,62 @@ using MachineFunctionAnalysisManager = AnalysisManager<MachineFunction>;
44
44
// / automatically mixes in \c PassInfoMixin.
45
45
template <typename DerivedT>
46
46
struct MachinePassInfoMixin : public PassInfoMixin <DerivedT> {
47
- // TODO: Add MachineFunctionProperties support.
47
+ class PropertyChanger {
48
+ MachineFunction &MF;
49
+
50
+ template <typename T>
51
+ using has_get_required_properties_t =
52
+ decltype (std::declval<T &>().getRequiredProperties());
53
+
54
+ template <typename T>
55
+ using has_get_set_properties_t =
56
+ decltype (std::declval<T &>().getSetProperties());
57
+
58
+ template <typename T>
59
+ using has_get_cleared_properties_t =
60
+ decltype (std::declval<T &>().getClearedProperties());
61
+
62
+ public:
63
+ PropertyChanger (MachineFunction &MF) : MF(MF) {
64
+ #ifndef NDEBUG
65
+ if constexpr (is_detected<has_get_required_properties_t ,
66
+ DerivedT>::value) {
67
+ auto &MFProps = MF.getProperties ();
68
+ auto RequiredProperties = DerivedT::getRequiredProperties ();
69
+ if (!MFProps.verifyRequiredProperties (RequiredProperties)) {
70
+ errs () << " MachineFunctionProperties required by " << DerivedT::name ()
71
+ << " pass are not met by function " << MF.getName () << " .\n "
72
+ << " Required properties: " ;
73
+ RequiredProperties.print (errs ());
74
+ errs () << " \n Current properties: " ;
75
+ MFProps.print (errs ());
76
+ errs () << ' \n ' ;
77
+ report_fatal_error (" MachineFunctionProperties check failed" );
78
+ }
79
+ #endif
80
+ }
81
+ }
82
+
83
+ ~PropertyChanger () {
84
+ if constexpr (is_detected<has_get_set_properties_t , DerivedT>::value)
85
+ MF.getProperties ().set (DerivedT::getSetProperties ());
86
+ if constexpr (is_detected<has_get_cleared_properties_t , DerivedT>::value)
87
+ MF.getProperties ().reset (DerivedT::getClearedProperties ());
88
+ }
89
+ };
90
+
91
+ PreservedAnalyses run (MachineFunction &MF,
92
+ MachineFunctionAnalysisManager &MFAM) {
93
+ PropertyChanger PC (MF);
94
+ return static_cast <DerivedT *>(this )->run (MF, MFAM);
95
+ }
48
96
};
49
97
50
98
namespace detail {
51
- struct MachinePassConcept
52
- : PassConcept<MachineFunction, MachineFunctionAnalysisManager> {
53
- virtual MachineFunctionProperties getRequiredProperties () const = 0;
54
- virtual MachineFunctionProperties getSetProperties () const = 0;
55
- virtual MachineFunctionProperties getClearedProperties () const = 0;
56
- };
57
99
58
- template <typename PassT> struct MachinePassModel : MachinePassConcept {
100
+ template <typename PassT>
101
+ struct MachinePassModel
102
+ : PassConcept<MachineFunction, MachineFunctionAnalysisManager> {
59
103
explicit MachinePassModel (PassT &&Pass) : Pass(std::move(Pass)) {}
60
104
// We have to explicitly define all the special member functions because MSVC
61
105
// refuses to generate them.
@@ -75,7 +119,7 @@ template <typename PassT> struct MachinePassModel : MachinePassConcept {
75
119
MachinePassModel &operator =(const MachinePassModel &) = delete ;
76
120
PreservedAnalyses run (MachineFunction &IR,
77
121
MachineFunctionAnalysisManager &AM) override {
78
- return Pass.run (IR, AM);
122
+ return Pass.MachinePassInfoMixin <PassT>:: run (IR, AM);
79
123
}
80
124
81
125
void printPipeline (
@@ -100,82 +144,7 @@ template <typename PassT> struct MachinePassModel : MachinePassConcept {
100
144
}
101
145
bool isRequired () const override { return passIsRequiredImpl<PassT>(); }
102
146
103
- template <typename T>
104
- using has_get_required_properties_t =
105
- decltype (std::declval<T &>().getRequiredProperties());
106
- template <typename T>
107
- static std::enable_if_t <is_detected<has_get_required_properties_t , T>::value,
108
- MachineFunctionProperties>
109
- getRequiredPropertiesImpl () {
110
- return PassT::getRequiredProperties ();
111
- }
112
- template <typename T>
113
- static std::enable_if_t <!is_detected<has_get_required_properties_t , T>::value,
114
- MachineFunctionProperties>
115
- getRequiredPropertiesImpl () {
116
- return MachineFunctionProperties ();
117
- }
118
- MachineFunctionProperties getRequiredProperties () const override {
119
- return getRequiredPropertiesImpl<PassT>();
120
- }
121
-
122
- template <typename T>
123
- using has_get_set_properties_t =
124
- decltype (std::declval<T &>().getSetProperties());
125
- template <typename T>
126
- static std::enable_if_t <is_detected<has_get_set_properties_t , T>::value,
127
- MachineFunctionProperties>
128
- getSetPropertiesImpl () {
129
- return PassT::getSetProperties ();
130
- }
131
- template <typename T>
132
- static std::enable_if_t <!is_detected<has_get_set_properties_t , T>::value,
133
- MachineFunctionProperties>
134
- getSetPropertiesImpl () {
135
- return MachineFunctionProperties ();
136
- }
137
- MachineFunctionProperties getSetProperties () const override {
138
- return getSetPropertiesImpl<PassT>();
139
- }
140
-
141
- template <typename T>
142
- using has_get_cleared_properties_t =
143
- decltype (std::declval<T &>().getClearedProperties());
144
-
145
- public:
146
- PropertyChanger (MachineFunction &MF) : MF(MF) {
147
- #ifndef NDEBUG
148
- if constexpr (is_detected<has_get_required_properties_t ,
149
- DerivedT>::value) {
150
- auto &MFProps = MF.getProperties ();
151
- auto RequiredProperties = DerivedT::getRequiredProperties ();
152
- if (!MFProps.verifyRequiredProperties (RequiredProperties)) {
153
- errs () << " MachineFunctionProperties required by " << DerivedT::name ()
154
- << " pass are not met by function " << MF.getName () << " .\n "
155
- << " Required properties: " ;
156
- RequiredProperties.print (errs ());
157
- errs () << " \n Current properties: " ;
158
- MFProps.print (errs ());
159
- errs () << ' \n ' ;
160
- report_fatal_error (" MachineFunctionProperties check failed" );
161
- }
162
- #endif
163
- }
164
- }
165
-
166
- ~PropertyChanger () {
167
- if constexpr (is_detected<has_get_set_properties_t , DerivedT>::value)
168
- MF.getProperties ().set (DerivedT::getSetProperties ());
169
- if constexpr (is_detected<has_get_cleared_properties_t , DerivedT>::value)
170
- MF.getProperties ().reset (DerivedT::getClearedProperties ());
171
- }
172
- };
173
-
174
- PreservedAnalyses run (MachineFunction &MF,
175
- MachineFunctionAnalysisManager &MFAM) {
176
- PropertyChanger PC (MF);
177
- return static_cast <DerivedT *>(this )->run (MF, MFAM);
178
- }
147
+ PassT Pass;
179
148
};
180
149
} // namespace detail
181
150
@@ -269,11 +238,12 @@ class FunctionAnalysisManagerMachineFunctionProxy
269
238
270
239
class ModuleToMachineFunctionPassAdaptor
271
240
: public PassInfoMixin<ModuleToMachineFunctionPassAdaptor> {
272
- using MachinePassConcept = detail::MachinePassConcept;
273
-
274
241
public:
242
+ using PassConceptT =
243
+ detail::PassConcept<MachineFunction, MachineFunctionAnalysisManager>;
244
+
275
245
explicit ModuleToMachineFunctionPassAdaptor (
276
- std::unique_ptr<MachinePassConcept > Pass)
246
+ std::unique_ptr<PassConceptT > Pass)
277
247
: Pass(std::move(Pass)) {}
278
248
279
249
// / Runs the function pass across every function in the module.
@@ -284,41 +254,21 @@ class ModuleToMachineFunctionPassAdaptor
284
254
static bool isRequired () { return true ; }
285
255
286
256
private:
287
- std::unique_ptr<MachinePassConcept > Pass;
257
+ std::unique_ptr<PassConceptT > Pass;
288
258
};
289
259
290
260
template <typename MachineFunctionPassT>
291
261
ModuleToMachineFunctionPassAdaptor
292
262
createModuleToMachineFunctionPassAdaptor (MachineFunctionPassT &&Pass) {
293
- using PassModelT = detail::MachinePassModel<MachineFunctionPassT>;
263
+ using PassModelT = detail::PassModel<MachineFunction, MachineFunctionPassT,
264
+ MachineFunctionAnalysisManager>;
294
265
// Do not use make_unique, it causes too many template instantiations,
295
266
// causing terrible compile times.
296
267
return ModuleToMachineFunctionPassAdaptor (
297
- std::unique_ptr<detail::MachinePassConcept >(
268
+ std::unique_ptr<ModuleToMachineFunctionPassAdaptor::PassConceptT >(
298
269
new PassModelT (std::forward<MachineFunctionPassT>(Pass))));
299
270
}
300
271
301
- template <>
302
- template <typename PassT>
303
- std::enable_if_t <!std::is_same<PassT, PassManager<MachineFunction>>::value>
304
- PassManager<MachineFunction>::addPass (PassT &&Pass) {
305
- using PassModelT =
306
- detail::PassModel<MachineFunction, PassT, MachineFunctionAnalysisManager>;
307
- using MachineFunctionPassModelT =
308
- detail::PassModel<MachineFunction, MachinePassInfoMixin<PassT>,
309
- MachineFunctionAnalysisManager>;
310
- // Do not use make_unique or emplace_back, they cause too many template
311
- // instantiations, causing terrible compile times.
312
- if constexpr (std::is_base_of_v<MachinePassInfoMixin<PassT>, PassT>) {
313
- Passes.push_back (
314
- std::unique_ptr<PassConceptT>(new MachineFunctionPassModelT (
315
- std::forward<MachinePassInfoMixin<PassT>>(Pass))));
316
- } else {
317
- Passes.push_back (std::unique_ptr<PassConceptT>(
318
- new PassModelT (std::forward<PassT>(Pass))));
319
- }
320
- }
321
-
322
272
template <>
323
273
PreservedAnalyses
324
274
PassManager<MachineFunction>::run (MachineFunction &,
0 commit comments