diff --git a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h index f55022fbff07c..e1e1cbfdbf7a4 100644 --- a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h +++ b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h @@ -102,32 +102,26 @@ class PassManager - LLVM_ATTRIBUTE_MINSIZE - std::enable_if_t::value> - addPass(PassT &&Pass) { - using LoopPassModelT = - detail::PassModel; - IsLoopNestPass.push_back(false); - // Do not use make_unique or emplace_back, they cause too many template - // instantiations, causing terrible compile times. - LoopPasses.push_back(std::unique_ptr( - new LoopPassModelT(std::forward(Pass)))); - } - - template - LLVM_ATTRIBUTE_MINSIZE - std::enable_if_t::value> - addPass(PassT &&Pass) { - using LoopNestPassModelT = - detail::PassModel; - IsLoopNestPass.push_back(true); - // Do not use make_unique or emplace_back, they cause too many template - // instantiations, causing terrible compile times. - LoopNestPasses.push_back(std::unique_ptr( - new LoopNestPassModelT(std::forward(Pass)))); + template LLVM_ATTRIBUTE_MINSIZE void addPass(PassT &&Pass) { + if constexpr (is_detected::value) { + using LoopPassModelT = + detail::PassModel; + IsLoopNestPass.push_back(false); + // Do not use make_unique or emplace_back, they cause too many template + // instantiations, causing terrible compile times. + LoopPasses.push_back(std::unique_ptr( + new LoopPassModelT(std::forward(Pass)))); + } else { + using LoopNestPassModelT = + detail::PassModel; + IsLoopNestPass.push_back(true); + // Do not use make_unique or emplace_back, they cause too many template + // instantiations, causing terrible compile times. + LoopNestPasses.push_back(std::unique_ptr( + new LoopNestPassModelT(std::forward(Pass)))); + } } bool isEmpty() const { return LoopPasses.empty() && LoopNestPasses.empty(); } @@ -442,42 +436,37 @@ class FunctionToLoopPassAdaptor /// adaptor. /// /// If \p Pass is a loop pass, the returned adaptor will be in loop mode. -template -inline std::enable_if_t::value, - FunctionToLoopPassAdaptor> -createFunctionToLoopPassAdaptor(LoopPassT &&Pass, bool UseMemorySSA = false, - bool UseBlockFrequencyInfo = false, - bool UseBranchProbabilityInfo = false) { - using PassModelT = - detail::PassModel; - // Do not use make_unique, it causes too many template instantiations, - // causing terrible compile times. - return FunctionToLoopPassAdaptor( - std::unique_ptr( - new PassModelT(std::forward(Pass))), - UseMemorySSA, UseBlockFrequencyInfo, UseBranchProbabilityInfo, false); -} - +/// /// If \p Pass is a loop-nest pass, \p Pass will first be wrapped into a /// \c LoopPassManager and the returned adaptor will be in loop-nest mode. -template -inline std::enable_if_t::value, - FunctionToLoopPassAdaptor> -createFunctionToLoopPassAdaptor(LoopNestPassT &&Pass, bool UseMemorySSA = false, +template +inline FunctionToLoopPassAdaptor +createFunctionToLoopPassAdaptor(LoopPassT &&Pass, bool UseMemorySSA = false, bool UseBlockFrequencyInfo = false, bool UseBranchProbabilityInfo = false) { - LoopPassManager LPM; - LPM.addPass(std::forward(Pass)); - using PassModelT = - detail::PassModel; - // Do not use make_unique, it causes too many template instantiations, - // causing terrible compile times. - return FunctionToLoopPassAdaptor( - std::unique_ptr( - new PassModelT(std::move(LPM))), - UseMemorySSA, UseBlockFrequencyInfo, UseBranchProbabilityInfo, true); + if constexpr (is_detected::value) { + using PassModelT = + detail::PassModel; + // Do not use make_unique, it causes too many template instantiations, + // causing terrible compile times. + return FunctionToLoopPassAdaptor( + std::unique_ptr( + new PassModelT(std::forward(Pass))), + UseMemorySSA, UseBlockFrequencyInfo, UseBranchProbabilityInfo, false); + } else { + LoopPassManager LPM; + LPM.addPass(std::forward(Pass)); + using PassModelT = + detail::PassModel; + // Do not use make_unique, it causes too many template instantiations, + // causing terrible compile times. + return FunctionToLoopPassAdaptor( + std::unique_ptr( + new PassModelT(std::move(LPM))), + UseMemorySSA, UseBlockFrequencyInfo, UseBranchProbabilityInfo, true); + } } /// If \p Pass is an instance of \c LoopPassManager, the returned adaptor will