@@ -36,35 +36,20 @@ class MachineFunction;
3636extern template class AnalysisManager <MachineFunction>;
3737using MachineFunctionAnalysisManager = AnalysisManager<MachineFunction>;
3838
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 ();
6146#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 ();
6550 if (!MFProps.verifyRequiredProperties (RequiredProperties)) {
6651 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 "
6853 << " Required properties: " ;
6954 RequiredProperties.print (errs ());
7055 errs () << " \n Current properties: " ;
@@ -73,18 +58,22 @@ struct MachinePassModel
7358 report_fatal_error (" MachineFunctionProperties check failed" );
7459 }
7560 }
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+ }
7965
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+ }
8571 }
8672
8773private:
74+ PassT &P;
75+ MachineFunction &MF;
76+
8877 template <typename T>
8978 using has_get_required_properties_t =
9079 decltype (std::declval<T &>().getRequiredProperties());
@@ -96,8 +85,19 @@ struct MachinePassModel
9685 template <typename T>
9786 using has_get_cleared_properties_t =
9887 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;
99100};
100- } // namespace detail
101101
102102using MachineFunctionAnalysisManagerModuleProxy =
103103 InnerAnalysisManagerProxy<MachineFunctionAnalysisManager, Module>;
@@ -219,21 +219,6 @@ createFunctionToMachineFunctionPassAdaptor(MachineFunctionPassT &&Pass) {
219219 new PassModelT (std::forward<MachineFunctionPassT>(Pass))));
220220}
221221
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-
237222template <>
238223PreservedAnalyses
239224PassManager<MachineFunction>::run(MachineFunction &,
0 commit comments