[llvm] d372e92 - Manually create unique_ptr in various pass adaptors
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 30 09:55:32 PDT 2021
Author: Arthur Eubanks
Date: 2021-09-30T09:55:06-07:00
New Revision: d372e92baf96cb0913aa361ecbc53a38a5f29ae1
URL: https://github.com/llvm/llvm-project/commit/d372e92baf96cb0913aa361ecbc53a38a5f29ae1
DIFF: https://github.com/llvm/llvm-project/commit/d372e92baf96cb0913aa361ecbc53a38a5f29ae1.diff
LOG: Manually create unique_ptr in various pass adaptors
This avoids creating tons of make_unique template instantiations. And we
only create a unique_ptr of the actual pass concept type, rather than
creating a unique_ptr of the pass model subclass then casting it to the
pass concept type.
This reduces the work spent compiling PassBuilder.cpp from 83M -> 73M
instructions according to perf stat.
Reviewed By: rnk
Differential Revision: https://reviews.llvm.org/D110784
Added:
Modified:
llvm/include/llvm/Analysis/CGSCCPassManager.h
llvm/include/llvm/IR/PassManager.h
llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/CGSCCPassManager.h b/llvm/include/llvm/Analysis/CGSCCPassManager.h
index 5603e68f2386..9acb7c0328ba 100644
--- a/llvm/include/llvm/Analysis/CGSCCPassManager.h
+++ b/llvm/include/llvm/Analysis/CGSCCPassManager.h
@@ -390,8 +390,11 @@ createModuleToPostOrderCGSCCPassAdaptor(CGSCCPassT &&Pass) {
using PassModelT = detail::PassModel<LazyCallGraph::SCC, CGSCCPassT,
PreservedAnalyses, CGSCCAnalysisManager,
LazyCallGraph &, CGSCCUpdateResult &>;
+ // Do not use make_unique, it causes too many template instantiations,
+ // causing terrible compile times.
return ModuleToPostOrderCGSCCPassAdaptor(
- std::make_unique<PassModelT>(std::forward<CGSCCPassT>(Pass)));
+ std::unique_ptr<ModuleToPostOrderCGSCCPassAdaptor::PassConceptT>(
+ new PassModelT(std::forward<CGSCCPassT>(Pass))));
}
/// A proxy from a \c FunctionAnalysisManager to an \c SCC.
@@ -515,8 +518,11 @@ createCGSCCToFunctionPassAdaptor(FunctionPassT &&Pass) {
using PassModelT =
detail::PassModel<Function, FunctionPassT, PreservedAnalyses,
FunctionAnalysisManager>;
+ // Do not use make_unique, it causes too many template instantiations,
+ // causing terrible compile times.
return CGSCCToFunctionPassAdaptor(
- std::make_unique<PassModelT>(std::forward<FunctionPassT>(Pass)));
+ std::unique_ptr<CGSCCToFunctionPassAdaptor::PassConceptT>(
+ new PassModelT(std::forward<FunctionPassT>(Pass))));
}
/// A helper that repeats an SCC pass each time an indirect call is refined to
@@ -568,8 +574,11 @@ DevirtSCCRepeatedPass createDevirtSCCRepeatedPass(CGSCCPassT &&Pass,
using PassModelT = detail::PassModel<LazyCallGraph::SCC, CGSCCPassT,
PreservedAnalyses, CGSCCAnalysisManager,
LazyCallGraph &, CGSCCUpdateResult &>;
+ // Do not use make_unique, it causes too many template instantiations,
+ // causing terrible compile times.
return DevirtSCCRepeatedPass(
- std::make_unique<PassModelT>(std::forward<CGSCCPassT>(Pass)),
+ std::unique_ptr<DevirtSCCRepeatedPass::PassConceptT>(
+ new PassModelT(std::forward<CGSCCPassT>(Pass))),
MaxIterations);
}
diff --git a/llvm/include/llvm/IR/PassManager.h b/llvm/include/llvm/IR/PassManager.h
index 29f2494bb554..a409402a459a 100644
--- a/llvm/include/llvm/IR/PassManager.h
+++ b/llvm/include/llvm/IR/PassManager.h
@@ -1226,8 +1226,11 @@ createModuleToFunctionPassAdaptor(FunctionPassT &&Pass) {
detail::PassModel<Function, FunctionPassT, PreservedAnalyses,
FunctionAnalysisManager>;
+ // Do not use make_unique, it causes too many template instantiations,
+ // causing terrible compile times.
return ModuleToFunctionPassAdaptor(
- std::make_unique<PassModelT>(std::forward<FunctionPassT>(Pass)));
+ std::unique_ptr<ModuleToFunctionPassAdaptor::PassConceptT>(
+ new PassModelT(std::forward<FunctionPassT>(Pass))));
}
/// A utility pass template to force an analysis result to be available.
diff --git a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
index ad72d28d4871..b9703d7143e5 100644
--- a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
+++ b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
@@ -469,9 +469,13 @@ createFunctionToLoopPassAdaptor(LoopPassT &&Pass, bool UseMemorySSA = false,
using PassModelT =
detail::PassModel<Loop, LoopPassT, PreservedAnalyses, LoopAnalysisManager,
LoopStandardAnalysisResults &, LPMUpdater &>;
+ // Do not use make_unique, it causes too many template instantiations,
+ // causing terrible compile times.
+
return FunctionToLoopPassAdaptor(
- std::make_unique<PassModelT>(std::forward<LoopPassT>(Pass)), UseMemorySSA,
- UseBlockFrequencyInfo, UseBranchProbabilityInfo, false);
+ 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
@@ -488,9 +492,10 @@ createFunctionToLoopPassAdaptor(LoopNestPassT &&Pass, bool UseMemorySSA = false,
detail::PassModel<Loop, LoopPassManager, PreservedAnalyses,
LoopAnalysisManager, LoopStandardAnalysisResults &,
LPMUpdater &>;
- return FunctionToLoopPassAdaptor(std::make_unique<PassModelT>(std::move(LPM)),
- UseMemorySSA, UseBlockFrequencyInfo,
- UseBranchProbabilityInfo, true);
+ 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
@@ -507,9 +512,11 @@ createFunctionToLoopPassAdaptor<LoopPassManager>(
LoopAnalysisManager, LoopStandardAnalysisResults &,
LPMUpdater &>;
bool LoopNestMode = (LPM.getNumLoopPasses() == 0);
- return FunctionToLoopPassAdaptor(std::make_unique<PassModelT>(std::move(LPM)),
- UseMemorySSA, UseBlockFrequencyInfo,
- UseBranchProbabilityInfo, LoopNestMode);
+ return FunctionToLoopPassAdaptor(
+ std::unique_ptr<FunctionToLoopPassAdaptor::PassConceptT>(
+ new PassModelT(std::move(LPM))),
+ UseMemorySSA, UseBlockFrequencyInfo, UseBranchProbabilityInfo,
+ LoopNestMode);
}
/// Pass for printing a loop's contents as textual IR.
More information about the llvm-commits
mailing list