[llvm] b8ce973 - [NewPM] Add PipelineTuningOption to eagerly invalidate analyses
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 18 13:20:43 PDT 2021
Author: Arthur Eubanks
Date: 2021-10-18T13:20:35-07:00
New Revision: b8ce97372d85ef0e6103ec8055fc5154f3bb5862
URL: https://github.com/llvm/llvm-project/commit/b8ce97372d85ef0e6103ec8055fc5154f3bb5862
DIFF: https://github.com/llvm/llvm-project/commit/b8ce97372d85ef0e6103ec8055fc5154f3bb5862.diff
LOG: [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
Added:
llvm/test/Other/new-pm-eager-invalidate.ll
Modified:
llvm/lib/Analysis/CGSCCPassManager.cpp
llvm/lib/IR/PassManager.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/CGSCCPassManager.cpp b/llvm/lib/Analysis/CGSCCPassManager.cpp
index 5573ad13d96dd..c2ba3d662bf37 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 bb8885a5e152d..4965a7d533437 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 0000000000000..188ac9bcaf039
--- /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
+}
More information about the llvm-commits
mailing list