diff --git a/llvm/lib/Analysis/CGSCCPassManager.cpp b/llvm/lib/Analysis/CGSCCPassManager.cpp --- a/llvm/lib/Analysis/CGSCCPassManager.cpp +++ b/llvm/lib/Analysis/CGSCCPassManager.cpp @@ -38,6 +38,7 @@ // Explicit template instantiations and specialization definitions for core // template typedefs. namespace llvm { +extern cl::opt EagerlyInvalidateAnalyses; static cl::opt AbortOnMaxDevirtIterationsReached( "abort-on-max-devirt-iterations-reached", @@ -556,7 +557,8 @@ // 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 --- 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 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; template class AllAnalysesOn; template class PassManager; @@ -129,7 +141,8 @@ // 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 --- /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)' -disable-output -eagerly-invalidate-analyses %s 2>&1 | FileCheck %s +; RUN: opt -disable-verify -debug-pass-manager -passes='cgscc(function(require))' -disable-output -eagerly-invalidate-analyses %s 2>&1 | FileCheck %s + +; CHECK: Invalidating analysis: NoOpFunctionAnalysis + +define void @foo() { + unreachable +}