@@ -36,35 +36,20 @@ class MachineFunction;
36
36
extern template class AnalysisManager <MachineFunction>;
37
37
using MachineFunctionAnalysisManager = AnalysisManager<MachineFunction>;
38
38
39
- namespace detail {
40
-
41
- template <typename PassT>
42
- struct MachinePassModel
43
- : PassModel<MachineFunction, PassT, MachineFunctionAnalysisManager> {
44
- explicit MachinePassModel (PassT &&Pass)
45
- : PassModel<MachineFunction, PassT, MachineFunctionAnalysisManager>(
46
- std::move (Pass)) {}
47
-
48
- friend void swap (MachinePassModel &LHS, MachinePassModel &RHS) {
49
- using std::swap;
50
- swap (LHS.Pass , RHS.Pass );
51
- }
52
-
53
- MachinePassModel &operator =(MachinePassModel RHS) {
54
- swap (*this , RHS);
55
- return *this ;
56
- }
57
-
58
- MachinePassModel &operator =(const MachinePassModel &) = delete ;
59
- PreservedAnalyses run (MachineFunction &IR,
60
- MachineFunctionAnalysisManager &AM) override {
39
+ // / An RAII based helper class to modify MachineFunctionProperties when running
40
+ // / pass. Define a MFPropsModifier in PassT::run to set
41
+ // / MachineFunctionProperties properly.
42
+ template <typename PassT> class MFPropsModifier {
43
+ public:
44
+ MFPropsModifier (PassT &P_, MachineFunction &MF_) : P(P_), MF(MF_) {
45
+ auto &MFProps = MF.getProperties ();
61
46
#ifndef NDEBUG
62
- if constexpr (is_detected< has_get_required_properties_t , PassT>::value ) {
63
- auto &MFProps = IR .getProperties ();
64
- auto RequiredProperties = this -> Pass .getRequiredProperties ();
47
+ if constexpr (has_get_required_properties_v< PassT>) {
48
+ auto &MFProps = MF .getProperties ();
49
+ auto RequiredProperties = P .getRequiredProperties ();
65
50
if (!MFProps.verifyRequiredProperties (RequiredProperties)) {
66
51
errs () << " MachineFunctionProperties required by " << PassT::name ()
67
- << " pass are not met by function " << IR .getName () << " .\n "
52
+ << " pass are not met by function " << MF .getName () << " .\n "
68
53
<< " Required properties: " ;
69
54
RequiredProperties.print (errs ());
70
55
errs () << " \n Current properties: " ;
@@ -73,18 +58,22 @@ struct MachinePassModel
73
58
report_fatal_error (" MachineFunctionProperties check failed" );
74
59
}
75
60
}
76
- #endif
77
-
78
- auto PA = this ->Pass .run (IR, AM);
61
+ #endif // NDEBUG
62
+ if constexpr (has_get_cleared_properties_v<PassT>)
63
+ MFProps.reset (P.getClearedProperties ());
64
+ }
79
65
80
- if constexpr (is_detected< has_get_set_properties_t , PassT>::value)
81
- IR. getProperties (). set ( this -> Pass . getSetProperties ());
82
- if constexpr (is_detected< has_get_cleared_properties_t , PassT>::value)
83
- IR. getProperties (). reset ( this -> Pass . getClearedProperties ());
84
- return PA;
66
+ ~MFPropsModifier () {
67
+ if constexpr (has_get_set_properties_v<PassT>) {
68
+ auto &MFProps = MF. getProperties ();
69
+ MFProps. set (P. getSetProperties ());
70
+ }
85
71
}
86
72
87
73
private:
74
+ PassT &P;
75
+ MachineFunction &MF;
76
+
88
77
template <typename T>
89
78
using has_get_required_properties_t =
90
79
decltype (std::declval<T &>().getRequiredProperties());
@@ -96,8 +85,19 @@ struct MachinePassModel
96
85
template <typename T>
97
86
using has_get_cleared_properties_t =
98
87
decltype (std::declval<T &>().getClearedProperties());
88
+
89
+ template <typename T>
90
+ static constexpr bool has_get_required_properties_v =
91
+ is_detected<has_get_required_properties_t , T>::value;
92
+
93
+ template <typename T>
94
+ static constexpr bool has_get_set_properties_v =
95
+ is_detected<has_get_set_properties_t , T>::value;
96
+
97
+ template <typename T>
98
+ static constexpr bool has_get_cleared_properties_v =
99
+ is_detected<has_get_cleared_properties_t , T>::value;
99
100
};
100
- } // namespace detail
101
101
102
102
using MachineFunctionAnalysisManagerModuleProxy =
103
103
InnerAnalysisManagerProxy<MachineFunctionAnalysisManager, Module>;
@@ -219,21 +219,6 @@ createFunctionToMachineFunctionPassAdaptor(MachineFunctionPassT &&Pass) {
219
219
new PassModelT (std::forward<MachineFunctionPassT>(Pass))));
220
220
}
221
221
222
- template <>
223
- template <typename PassT>
224
- void PassManager<MachineFunction>::addPass(PassT &&Pass) {
225
- using MachinePassModelT = detail::MachinePassModel<PassT>;
226
- // Do not use make_unique or emplace_back, they cause too many template
227
- // instantiations, causing terrible compile times.
228
- if constexpr (std::is_same_v<PassT, PassManager<MachineFunction>>) {
229
- for (auto &P : Pass.Passes )
230
- Passes.push_back (std::move (P));
231
- } else {
232
- Passes.push_back (std::unique_ptr<MachinePassModelT>(
233
- new MachinePassModelT (std::forward<PassT>(Pass))));
234
- }
235
- }
236
-
237
222
template <>
238
223
PreservedAnalyses
239
224
PassManager<MachineFunction>::run(MachineFunction &,
0 commit comments