-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[Scalar] Simplify addPass and createFunctionToLoopPassAdaptor (NFC) #137505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_constexpr_if_llvm_Scalar
Apr 27, 2025
Merged
[Scalar] Simplify addPass and createFunctionToLoopPassAdaptor (NFC) #137505
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_constexpr_if_llvm_Scalar
Apr 27, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We can use "constexpt if" to combine the two variants of functions.
Member
|
@llvm/pr-subscribers-llvm-transforms Author: Kazu Hirata (kazutakahirata) ChangesWe can use "constexpt if" to combine the two variants of functions. Full diff: https://github.com/llvm/llvm-project/pull/137505.diff 1 Files Affected:
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<Loop, LoopAnalysisManager, LoopStandardAnalysisResults &,
/// loop-nests instead. Also append whether \p Pass is loop-nest pass or not
/// to the end of \var IsLoopNestPass so we can easily identify the types of
/// passes in the pass manager later.
- template <typename PassT>
- LLVM_ATTRIBUTE_MINSIZE
- std::enable_if_t<is_detected<HasRunOnLoopT, PassT>::value>
- addPass(PassT &&Pass) {
- using LoopPassModelT =
- detail::PassModel<Loop, PassT, LoopAnalysisManager,
- LoopStandardAnalysisResults &, LPMUpdater &>;
- 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<LoopPassConceptT>(
- new LoopPassModelT(std::forward<PassT>(Pass))));
- }
-
- template <typename PassT>
- LLVM_ATTRIBUTE_MINSIZE
- std::enable_if_t<!is_detected<HasRunOnLoopT, PassT>::value>
- addPass(PassT &&Pass) {
- using LoopNestPassModelT =
- detail::PassModel<LoopNest, PassT, LoopAnalysisManager,
- LoopStandardAnalysisResults &, LPMUpdater &>;
- 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<LoopNestPassConceptT>(
- new LoopNestPassModelT(std::forward<PassT>(Pass))));
+ template <typename PassT> LLVM_ATTRIBUTE_MINSIZE void addPass(PassT &&Pass) {
+ if constexpr (is_detected<HasRunOnLoopT, PassT>::value) {
+ using LoopPassModelT =
+ detail::PassModel<Loop, PassT, LoopAnalysisManager,
+ LoopStandardAnalysisResults &, LPMUpdater &>;
+ 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<LoopPassConceptT>(
+ new LoopPassModelT(std::forward<PassT>(Pass))));
+ } else {
+ using LoopNestPassModelT =
+ detail::PassModel<LoopNest, PassT, LoopAnalysisManager,
+ LoopStandardAnalysisResults &, LPMUpdater &>;
+ 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<LoopNestPassConceptT>(
+ new LoopNestPassModelT(std::forward<PassT>(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 <typename LoopPassT>
-inline std::enable_if_t<is_detected<HasRunOnLoopT, LoopPassT>::value,
- FunctionToLoopPassAdaptor>
-createFunctionToLoopPassAdaptor(LoopPassT &&Pass, bool UseMemorySSA = false,
- bool UseBlockFrequencyInfo = false,
- bool UseBranchProbabilityInfo = false) {
- using PassModelT =
- detail::PassModel<Loop, LoopPassT, LoopAnalysisManager,
- LoopStandardAnalysisResults &, LPMUpdater &>;
- // Do not use make_unique, it causes too many template instantiations,
- // causing terrible compile times.
- return FunctionToLoopPassAdaptor(
- std::unique_ptr<FunctionToLoopPassAdaptor::PassConceptT>(
- new PassModelT(std::forward<LoopPassT>(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 <typename LoopNestPassT>
-inline std::enable_if_t<!is_detected<HasRunOnLoopT, LoopNestPassT>::value,
- FunctionToLoopPassAdaptor>
-createFunctionToLoopPassAdaptor(LoopNestPassT &&Pass, bool UseMemorySSA = false,
+template <typename LoopPassT>
+inline FunctionToLoopPassAdaptor
+createFunctionToLoopPassAdaptor(LoopPassT &&Pass, bool UseMemorySSA = false,
bool UseBlockFrequencyInfo = false,
bool UseBranchProbabilityInfo = false) {
- LoopPassManager LPM;
- LPM.addPass(std::forward<LoopNestPassT>(Pass));
- using PassModelT =
- detail::PassModel<Loop, LoopPassManager, LoopAnalysisManager,
- LoopStandardAnalysisResults &, LPMUpdater &>;
- // Do not use make_unique, it causes too many template instantiations,
- // causing terrible compile times.
- return FunctionToLoopPassAdaptor(
- std::unique_ptr<FunctionToLoopPassAdaptor::PassConceptT>(
- new PassModelT(std::move(LPM))),
- UseMemorySSA, UseBlockFrequencyInfo, UseBranchProbabilityInfo, true);
+ if constexpr (is_detected<HasRunOnLoopT, LoopPassT>::value) {
+ using PassModelT =
+ detail::PassModel<Loop, LoopPassT, LoopAnalysisManager,
+ LoopStandardAnalysisResults &, LPMUpdater &>;
+ // Do not use make_unique, it causes too many template instantiations,
+ // causing terrible compile times.
+ return FunctionToLoopPassAdaptor(
+ std::unique_ptr<FunctionToLoopPassAdaptor::PassConceptT>(
+ new PassModelT(std::forward<LoopPassT>(Pass))),
+ UseMemorySSA, UseBlockFrequencyInfo, UseBranchProbabilityInfo, false);
+ } else {
+ LoopPassManager LPM;
+ LPM.addPass(std::forward<LoopPassT>(Pass));
+ using PassModelT =
+ detail::PassModel<Loop, LoopPassManager, LoopAnalysisManager,
+ LoopStandardAnalysisResults &, LPMUpdater &>;
+ // Do not use make_unique, it causes too many template instantiations,
+ // causing terrible compile times.
+ return FunctionToLoopPassAdaptor(
+ std::unique_ptr<FunctionToLoopPassAdaptor::PassConceptT>(
+ new PassModelT(std::move(LPM))),
+ UseMemorySSA, UseBlockFrequencyInfo, UseBranchProbabilityInfo, true);
+ }
}
/// If \p Pass is an instance of \c LoopPassManager, the returned adaptor will
|
nikic
approved these changes
Apr 27, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
…lvm#137505) We can use "constexpt if" to combine the two variants of functions.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We can use "constexpt if" to combine the two variants of functions.