Skip to content

Commit 1395e0a

Browse files
[Scalar] Simplify addPass and createFunctionToLoopPassAdaptor (NFC) (#137505)
We can use "constexpt if" to combine the two variants of functions.
1 parent 8c73fee commit 1395e0a

File tree

1 file changed

+47
-58
lines changed

1 file changed

+47
-58
lines changed

llvm/include/llvm/Transforms/Scalar/LoopPassManager.h

Lines changed: 47 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -102,32 +102,26 @@ class PassManager<Loop, LoopAnalysisManager, LoopStandardAnalysisResults &,
102102
/// loop-nests instead. Also append whether \p Pass is loop-nest pass or not
103103
/// to the end of \var IsLoopNestPass so we can easily identify the types of
104104
/// passes in the pass manager later.
105-
template <typename PassT>
106-
LLVM_ATTRIBUTE_MINSIZE
107-
std::enable_if_t<is_detected<HasRunOnLoopT, PassT>::value>
108-
addPass(PassT &&Pass) {
109-
using LoopPassModelT =
110-
detail::PassModel<Loop, PassT, LoopAnalysisManager,
111-
LoopStandardAnalysisResults &, LPMUpdater &>;
112-
IsLoopNestPass.push_back(false);
113-
// Do not use make_unique or emplace_back, they cause too many template
114-
// instantiations, causing terrible compile times.
115-
LoopPasses.push_back(std::unique_ptr<LoopPassConceptT>(
116-
new LoopPassModelT(std::forward<PassT>(Pass))));
117-
}
118-
119-
template <typename PassT>
120-
LLVM_ATTRIBUTE_MINSIZE
121-
std::enable_if_t<!is_detected<HasRunOnLoopT, PassT>::value>
122-
addPass(PassT &&Pass) {
123-
using LoopNestPassModelT =
124-
detail::PassModel<LoopNest, PassT, LoopAnalysisManager,
125-
LoopStandardAnalysisResults &, LPMUpdater &>;
126-
IsLoopNestPass.push_back(true);
127-
// Do not use make_unique or emplace_back, they cause too many template
128-
// instantiations, causing terrible compile times.
129-
LoopNestPasses.push_back(std::unique_ptr<LoopNestPassConceptT>(
130-
new LoopNestPassModelT(std::forward<PassT>(Pass))));
105+
template <typename PassT> LLVM_ATTRIBUTE_MINSIZE void addPass(PassT &&Pass) {
106+
if constexpr (is_detected<HasRunOnLoopT, PassT>::value) {
107+
using LoopPassModelT =
108+
detail::PassModel<Loop, PassT, LoopAnalysisManager,
109+
LoopStandardAnalysisResults &, LPMUpdater &>;
110+
IsLoopNestPass.push_back(false);
111+
// Do not use make_unique or emplace_back, they cause too many template
112+
// instantiations, causing terrible compile times.
113+
LoopPasses.push_back(std::unique_ptr<LoopPassConceptT>(
114+
new LoopPassModelT(std::forward<PassT>(Pass))));
115+
} else {
116+
using LoopNestPassModelT =
117+
detail::PassModel<LoopNest, PassT, LoopAnalysisManager,
118+
LoopStandardAnalysisResults &, LPMUpdater &>;
119+
IsLoopNestPass.push_back(true);
120+
// Do not use make_unique or emplace_back, they cause too many template
121+
// instantiations, causing terrible compile times.
122+
LoopNestPasses.push_back(std::unique_ptr<LoopNestPassConceptT>(
123+
new LoopNestPassModelT(std::forward<PassT>(Pass))));
124+
}
131125
}
132126

133127
bool isEmpty() const { return LoopPasses.empty() && LoopNestPasses.empty(); }
@@ -442,42 +436,37 @@ class FunctionToLoopPassAdaptor
442436
/// adaptor.
443437
///
444438
/// If \p Pass is a loop pass, the returned adaptor will be in loop mode.
445-
template <typename LoopPassT>
446-
inline std::enable_if_t<is_detected<HasRunOnLoopT, LoopPassT>::value,
447-
FunctionToLoopPassAdaptor>
448-
createFunctionToLoopPassAdaptor(LoopPassT &&Pass, bool UseMemorySSA = false,
449-
bool UseBlockFrequencyInfo = false,
450-
bool UseBranchProbabilityInfo = false) {
451-
using PassModelT =
452-
detail::PassModel<Loop, LoopPassT, LoopAnalysisManager,
453-
LoopStandardAnalysisResults &, LPMUpdater &>;
454-
// Do not use make_unique, it causes too many template instantiations,
455-
// causing terrible compile times.
456-
return FunctionToLoopPassAdaptor(
457-
std::unique_ptr<FunctionToLoopPassAdaptor::PassConceptT>(
458-
new PassModelT(std::forward<LoopPassT>(Pass))),
459-
UseMemorySSA, UseBlockFrequencyInfo, UseBranchProbabilityInfo, false);
460-
}
461-
439+
///
462440
/// If \p Pass is a loop-nest pass, \p Pass will first be wrapped into a
463441
/// \c LoopPassManager and the returned adaptor will be in loop-nest mode.
464-
template <typename LoopNestPassT>
465-
inline std::enable_if_t<!is_detected<HasRunOnLoopT, LoopNestPassT>::value,
466-
FunctionToLoopPassAdaptor>
467-
createFunctionToLoopPassAdaptor(LoopNestPassT &&Pass, bool UseMemorySSA = false,
442+
template <typename LoopPassT>
443+
inline FunctionToLoopPassAdaptor
444+
createFunctionToLoopPassAdaptor(LoopPassT &&Pass, bool UseMemorySSA = false,
468445
bool UseBlockFrequencyInfo = false,
469446
bool UseBranchProbabilityInfo = false) {
470-
LoopPassManager LPM;
471-
LPM.addPass(std::forward<LoopNestPassT>(Pass));
472-
using PassModelT =
473-
detail::PassModel<Loop, LoopPassManager, LoopAnalysisManager,
474-
LoopStandardAnalysisResults &, LPMUpdater &>;
475-
// Do not use make_unique, it causes too many template instantiations,
476-
// causing terrible compile times.
477-
return FunctionToLoopPassAdaptor(
478-
std::unique_ptr<FunctionToLoopPassAdaptor::PassConceptT>(
479-
new PassModelT(std::move(LPM))),
480-
UseMemorySSA, UseBlockFrequencyInfo, UseBranchProbabilityInfo, true);
447+
if constexpr (is_detected<HasRunOnLoopT, LoopPassT>::value) {
448+
using PassModelT =
449+
detail::PassModel<Loop, LoopPassT, LoopAnalysisManager,
450+
LoopStandardAnalysisResults &, LPMUpdater &>;
451+
// Do not use make_unique, it causes too many template instantiations,
452+
// causing terrible compile times.
453+
return FunctionToLoopPassAdaptor(
454+
std::unique_ptr<FunctionToLoopPassAdaptor::PassConceptT>(
455+
new PassModelT(std::forward<LoopPassT>(Pass))),
456+
UseMemorySSA, UseBlockFrequencyInfo, UseBranchProbabilityInfo, false);
457+
} else {
458+
LoopPassManager LPM;
459+
LPM.addPass(std::forward<LoopPassT>(Pass));
460+
using PassModelT =
461+
detail::PassModel<Loop, LoopPassManager, LoopAnalysisManager,
462+
LoopStandardAnalysisResults &, LPMUpdater &>;
463+
// Do not use make_unique, it causes too many template instantiations,
464+
// causing terrible compile times.
465+
return FunctionToLoopPassAdaptor(
466+
std::unique_ptr<FunctionToLoopPassAdaptor::PassConceptT>(
467+
new PassModelT(std::move(LPM))),
468+
UseMemorySSA, UseBlockFrequencyInfo, UseBranchProbabilityInfo, true);
469+
}
481470
}
482471

483472
/// If \p Pass is an instance of \c LoopPassManager, the returned adaptor will

0 commit comments

Comments
 (0)