diff options
| author | Arthur Eubanks <aeubanks@google.com> | 2021-10-11 12:57:30 -0700 |
|---|---|---|
| committer | Arthur Eubanks <aeubanks@google.com> | 2021-10-18 13:20:35 -0700 |
| commit | b8ce97372d85ef0e6103ec8055fc5154f3bb5862 (patch) | |
| tree | c98027a87f0d760a835e4782af55e87689dd9b62 | |
| parent | b9cfa016daae725e4ed8173b431afb5e01cb80a6 (diff) | |
[NewPM] Add PipelineTuningOption to eagerly invalidate analyses
This trades off more compile time for less peak memory usage. Right now
it invalidates all function analyses after a module->function or
cgscc->function adaptor.
https://llvm-compile-time-tracker.com/compare.php?from=1fb24fe85a19ae71b00875ff6c96ef1831dcf7e3&to=cb28ddb063c87f0d5df89812ab2de9a69dd276db&stat=instructions
https://llvm-compile-time-tracker.com/compare.php?from=1fb24fe85a19ae71b00875ff6c96ef1831dcf7e3&to=cb28ddb063c87f0d5df89812ab2de9a69dd276db&stat=max-rss
For now this is just experimental.
See comments on why this may affect optimizations.
Reviewed By: asbirlea, nikic
Differential Revision: https://reviews.llvm.org/D111575
| -rw-r--r-- | llvm/lib/Analysis/CGSCCPassManager.cpp | 4 | ||||
| -rw-r--r-- | llvm/lib/IR/PassManager.cpp | 17 | ||||
| -rw-r--r-- | llvm/test/Other/new-pm-eager-invalidate.ll | 8 |
3 files changed, 26 insertions, 3 deletions
diff --git a/llvm/lib/Analysis/CGSCCPassManager.cpp b/llvm/lib/Analysis/CGSCCPassManager.cpp index 5573ad13d96d..c2ba3d662bf3 100644 --- a/llvm/lib/Analysis/CGSCCPassManager.cpp +++ b/llvm/lib/Analysis/CGSCCPassManager.cpp @@ -38,6 +38,7 @@ using namespace llvm; // Explicit template instantiations and specialization definitions for core // template typedefs. namespace llvm { +extern cl::opt<bool> EagerlyInvalidateAnalyses; static cl::opt<bool> AbortOnMaxDevirtIterationsReached( "abort-on-max-devirt-iterations-reached", @@ -556,7 +557,8 @@ PreservedAnalyses CGSCCToFunctionPassAdaptor::run(LazyCallGraph::SCC &C, // We know that the function pass couldn't have invalidated any other // function's analyses (that's the contract of a function pass), so // directly handle the function analysis manager's invalidation here. - FAM.invalidate(F, PassPA); + FAM.invalidate(F, EagerlyInvalidateAnalyses ? PreservedAnalyses::none() + : PassPA); // Then intersect the preserved set so that invalidation of module // analyses will eventually occur when the module pass completes. diff --git a/llvm/lib/IR/PassManager.cpp b/llvm/lib/IR/PassManager.cpp index bb8885a5e152..4965a7d53343 100644 --- a/llvm/lib/IR/PassManager.cpp +++ b/llvm/lib/IR/PassManager.cpp @@ -10,12 +10,24 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/PassManagerImpl.h" +#include "llvm/Support/CommandLine.h" using namespace llvm; +namespace llvm { +// Experimental option to eagerly invalidate more analyses. This has the +// potential to decrease max memory usage in exchange for more compile time. +// This may affect codegen due to either passes using analyses only when +// cached, or invalidating and recalculating an analysis that was +// stale/imprecise but still valid. Currently this invalidates all function +// analyses after a module->function or cgscc->function adaptor. +// TODO: make this a PipelineTuningOption. +cl::opt<bool> EagerlyInvalidateAnalyses( + "eagerly-invalidate-analyses", cl::init(false), cl::Hidden, + cl::desc("Eagerly invalidate more analyses in default pipelines")); + // Explicit template instantiations and specialization defininitions for core // template typedefs. -namespace llvm { template class AllAnalysesOn<Module>; template class AllAnalysesOn<Function>; template class PassManager<Module>; @@ -129,7 +141,8 @@ PreservedAnalyses ModuleToFunctionPassAdaptor::run(Module &M, // We know that the function pass couldn't have invalidated any other // function's analyses (that's the contract of a function pass), so // directly handle the function analysis manager's invalidation here. - FAM.invalidate(F, PassPA); + FAM.invalidate(F, EagerlyInvalidateAnalyses ? PreservedAnalyses::none() + : PassPA); // Then intersect the preserved set so that invalidation of module // analyses will eventually occur when the module pass completes. diff --git a/llvm/test/Other/new-pm-eager-invalidate.ll b/llvm/test/Other/new-pm-eager-invalidate.ll new file mode 100644 index 000000000000..188ac9bcaf03 --- /dev/null +++ b/llvm/test/Other/new-pm-eager-invalidate.ll @@ -0,0 +1,8 @@ +; RUN: opt -disable-verify -debug-pass-manager -passes='function(require<no-op-function>)' -disable-output -eagerly-invalidate-analyses %s 2>&1 | FileCheck %s +; RUN: opt -disable-verify -debug-pass-manager -passes='cgscc(function(require<no-op-function>))' -disable-output -eagerly-invalidate-analyses %s 2>&1 | FileCheck %s + +; CHECK: Invalidating analysis: NoOpFunctionAnalysis + +define void @foo() { + unreachable +} |
