[clang] 6f71310 - [NewPM] Move analysis invalidation/clearing logging to instrumentation
Arthur Eubanks via cfe-commits
cfe-commits at lists.llvm.org
Fri May 7 15:42:30 PDT 2021
Author: Arthur Eubanks
Date: 2021-05-07T15:25:31-07:00
New Revision: 6f7131002b6a821fc9b245ec5179910f171e3358
URL: https://github.com/llvm/llvm-project/commit/6f7131002b6a821fc9b245ec5179910f171e3358
DIFF: https://github.com/llvm/llvm-project/commit/6f7131002b6a821fc9b245ec5179910f171e3358.diff
LOG: [NewPM] Move analysis invalidation/clearing logging to instrumentation
We're trying to move DebugLogging into instrumentation, rather than
being part of PassManagers/AnalysisManagers.
Reviewed By: ychen
Differential Revision: https://reviews.llvm.org/D102093
Added:
Modified:
clang/lib/CodeGen/BackendUtil.cpp
llvm/include/llvm/CodeGen/MachinePassManager.h
llvm/include/llvm/IR/PassInstrumentation.h
llvm/include/llvm/IR/PassManager.h
llvm/include/llvm/IR/PassManagerImpl.h
llvm/lib/LTO/LTOBackend.cpp
llvm/lib/Passes/StandardInstrumentations.cpp
llvm/test/Transforms/LoopUnroll/unroll-loop-invalidation.ll
llvm/tools/opt/NewPMDriver.cpp
llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
llvm/unittests/CodeGen/PassManagerTest.cpp
llvm/unittests/IR/PassBuilderCallbacksTest.cpp
llvm/unittests/IR/PassManagerTest.cpp
llvm/unittests/Transforms/Scalar/LoopPassManagerTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index fd3ce27bf20d8..31f2c36b2adfd 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1272,10 +1272,10 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
PTO.CallGraphProfile = !CodeGenOpts.DisableIntegratedAS;
PTO.Coroutines = LangOpts.Coroutines;
- LoopAnalysisManager LAM(CodeGenOpts.DebugPassManager);
- FunctionAnalysisManager FAM(CodeGenOpts.DebugPassManager);
- CGSCCAnalysisManager CGAM(CodeGenOpts.DebugPassManager);
- ModuleAnalysisManager MAM(CodeGenOpts.DebugPassManager);
+ LoopAnalysisManager LAM;
+ FunctionAnalysisManager FAM;
+ CGSCCAnalysisManager CGAM;
+ ModuleAnalysisManager MAM;
PassInstrumentationCallbacks PIC;
StandardInstrumentations SI(CodeGenOpts.DebugPassManager);
diff --git a/llvm/include/llvm/CodeGen/MachinePassManager.h b/llvm/include/llvm/CodeGen/MachinePassManager.h
index 1489177d9668d..a375c47118d1e 100644
--- a/llvm/include/llvm/CodeGen/MachinePassManager.h
+++ b/llvm/include/llvm/CodeGen/MachinePassManager.h
@@ -40,11 +40,10 @@ class MachineFunctionAnalysisManager : public AnalysisManager<MachineFunction> {
public:
using Base = AnalysisManager<MachineFunction>;
- MachineFunctionAnalysisManager() : Base(false), FAM(nullptr), MAM(nullptr) {}
+ MachineFunctionAnalysisManager() : Base(), FAM(nullptr), MAM(nullptr) {}
MachineFunctionAnalysisManager(FunctionAnalysisManager &FAM,
- ModuleAnalysisManager &MAM,
- bool DebugLogging = false)
- : Base(DebugLogging), FAM(&FAM), MAM(&MAM) {}
+ ModuleAnalysisManager &MAM)
+ : Base(), FAM(&FAM), MAM(&MAM) {}
MachineFunctionAnalysisManager(MachineFunctionAnalysisManager &&) = default;
MachineFunctionAnalysisManager &
operator=(MachineFunctionAnalysisManager &&) = default;
diff --git a/llvm/include/llvm/IR/PassInstrumentation.h b/llvm/include/llvm/IR/PassInstrumentation.h
index 291f324b159aa..b0ae1953361cb 100644
--- a/llvm/include/llvm/IR/PassInstrumentation.h
+++ b/llvm/include/llvm/IR/PassInstrumentation.h
@@ -81,6 +81,8 @@ class PassInstrumentationCallbacks {
using AfterPassInvalidatedFunc = void(StringRef, const PreservedAnalyses &);
using BeforeAnalysisFunc = void(StringRef, Any);
using AfterAnalysisFunc = void(StringRef, Any);
+ using AnalysisInvalidatedFunc = void(StringRef, Any);
+ using AnalysesClearedFunc = void(StringRef);
public:
PassInstrumentationCallbacks() {}
@@ -123,6 +125,16 @@ class PassInstrumentationCallbacks {
AfterAnalysisCallbacks.emplace_back(std::move(C));
}
+ template <typename CallableT>
+ void registerAnalysisInvalidatedCallback(CallableT C) {
+ AnalysisInvalidatedCallbacks.emplace_back(std::move(C));
+ }
+
+ template <typename CallableT>
+ void registerAnalysesClearedCallback(CallableT C) {
+ AnalysesClearedCallbacks.emplace_back(std::move(C));
+ }
+
/// Add a class name to pass name mapping for use by pass instrumentation.
void addClassToPassName(StringRef ClassName, StringRef PassName);
/// Get the pass name for a given pass class name.
@@ -152,6 +164,12 @@ class PassInstrumentationCallbacks {
/// These are run on analyses that have been run.
SmallVector<llvm::unique_function<AfterAnalysisFunc>, 4>
AfterAnalysisCallbacks;
+ /// These are run on analyses that have been invalidated.
+ SmallVector<llvm::unique_function<AnalysisInvalidatedFunc>, 4>
+ AnalysisInvalidatedCallbacks;
+ /// These are run on analyses that have been cleared.
+ SmallVector<llvm::unique_function<AnalysesClearedFunc>, 4>
+ AnalysesClearedCallbacks;
StringMap<std::string> ClassToPassName;
};
@@ -256,6 +274,24 @@ class PassInstrumentation {
C(Analysis.name(), llvm::Any(&IR));
}
+ /// AnalysisInvalidated instrumentation point - takes \p Analysis instance
+ /// that has just been invalidated and constant reference to IR it operated
+ /// on.
+ template <typename IRUnitT, typename PassT>
+ void runAnalysisInvalidated(const PassT &Analysis, const IRUnitT &IR) const {
+ if (Callbacks)
+ for (auto &C : Callbacks->AnalysisInvalidatedCallbacks)
+ C(Analysis.name(), llvm::Any(&IR));
+ }
+
+ /// AnalysesCleared instrumentation point - takes name of IR that analyses
+ /// operated on.
+ void runAnalysesCleared(StringRef Name) const {
+ if (Callbacks)
+ for (auto &C : Callbacks->AnalysesClearedCallbacks)
+ C(Name);
+ }
+
/// Handle invalidation from the pass manager when PassInstrumentation
/// is used as the result of PassInstrumentationAnalysis.
///
diff --git a/llvm/include/llvm/IR/PassManager.h b/llvm/include/llvm/IR/PassManager.h
index 79d5093720efb..c1817d8917cc5 100644
--- a/llvm/include/llvm/IR/PassManager.h
+++ b/llvm/include/llvm/IR/PassManager.h
@@ -746,9 +746,7 @@ template <typename IRUnitT, typename... ExtraArgTs> class AnalysisManager {
};
/// Construct an empty analysis manager.
- ///
- /// If \p DebugLogging is true, we'll log our progress to llvm::dbgs().
- AnalysisManager(bool DebugLogging = false);
+ AnalysisManager();
AnalysisManager(AnalysisManager &&);
AnalysisManager &operator=(AnalysisManager &&);
@@ -910,9 +908,6 @@ template <typename IRUnitT, typename... ExtraArgTs> class AnalysisManager {
/// Map from an analysis ID and IR unit to a particular cached
/// analysis result.
AnalysisResultMapT AnalysisResults;
-
- /// Indicates whether we log to \c llvm::dbgs().
- bool DebugLogging;
};
extern template class AnalysisManager<Module>;
diff --git a/llvm/include/llvm/IR/PassManagerImpl.h b/llvm/include/llvm/IR/PassManagerImpl.h
index 79dc8cf4f15c8..bb4fbe98b0822 100644
--- a/llvm/include/llvm/IR/PassManagerImpl.h
+++ b/llvm/include/llvm/IR/PassManagerImpl.h
@@ -20,9 +20,7 @@
namespace llvm {
template <typename IRUnitT, typename... ExtraArgTs>
-inline AnalysisManager<IRUnitT, ExtraArgTs...>::AnalysisManager(
- bool DebugLogging)
- : DebugLogging(DebugLogging) {}
+inline AnalysisManager<IRUnitT, ExtraArgTs...>::AnalysisManager() {}
template <typename IRUnitT, typename... ExtraArgTs>
inline AnalysisManager<IRUnitT, ExtraArgTs...>::AnalysisManager(
@@ -37,8 +35,8 @@ template <typename IRUnitT, typename... ExtraArgTs>
inline void
AnalysisManager<IRUnitT, ExtraArgTs...>::clear(IRUnitT &IR,
llvm::StringRef Name) {
- if (DebugLogging)
- dbgs() << "Clearing all analysis results for: " << Name << "\n";
+ if (auto *PI = getCachedResult<PassInstrumentationAnalysis>(IR))
+ PI->runAnalysesCleared(Name);
auto ResultsListI = AnalysisResultLists.find(&IR);
if (ResultsListI == AnalysisResultLists.end())
@@ -133,9 +131,8 @@ inline void AnalysisManager<IRUnitT, ExtraArgTs...>::invalidate(
continue;
}
- if (DebugLogging)
- dbgs() << "Invalidating analysis: " << this->lookUpPass(ID).name()
- << " on " << IR.getName() << "\n";
+ if (auto *PI = getCachedResult<PassInstrumentationAnalysis>(IR))
+ PI->runAnalysisInvalidated(this->lookUpPass(ID), IR);
I = ResultsList.erase(I);
AnalysisResults.erase({ID, &IR});
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index 8a03a4fa89a97..10f0c9e5773bd 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -221,10 +221,10 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
PGOOptions::IRUse, PGOOptions::CSIRUse);
}
- LoopAnalysisManager LAM(Conf.DebugPassManager);
- FunctionAnalysisManager FAM(Conf.DebugPassManager);
- CGSCCAnalysisManager CGAM(Conf.DebugPassManager);
- ModuleAnalysisManager MAM(Conf.DebugPassManager);
+ LoopAnalysisManager LAM;
+ FunctionAnalysisManager FAM;
+ CGSCCAnalysisManager CGAM;
+ ModuleAnalysisManager MAM;
PassInstrumentationCallbacks PIC;
StandardInstrumentations SI(Conf.DebugPassManager);
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index 321009c65228d..e95379d747722 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -900,6 +900,14 @@ void PrintPassInstrumentation::registerCallbacks(
PIC.registerBeforeAnalysisCallback([](StringRef PassID, Any IR) {
dbgs() << "Running analysis: " << PassID << " on " << getIRName(IR) << "\n";
});
+
+ PIC.registerAnalysisInvalidatedCallback([](StringRef PassID, Any IR) {
+ dbgs() << "Invalidating analysis: " << PassID << " on " << getIRName(IR)
+ << "\n";
+ });
+ PIC.registerAnalysesClearedCallback([](StringRef IRName) {
+ dbgs() << "Clearing all analysis results for: " << IRName << "\n";
+ });
}
void PassStructurePrinter::printWithIdent(bool Expand, const Twine &Msg) {
diff --git a/llvm/test/Transforms/LoopUnroll/unroll-loop-invalidation.ll b/llvm/test/Transforms/LoopUnroll/unroll-loop-invalidation.ll
index 3f30bbfc80220..c3ee5b136466d 100644
--- a/llvm/test/Transforms/LoopUnroll/unroll-loop-invalidation.ll
+++ b/llvm/test/Transforms/LoopUnroll/unroll-loop-invalidation.ll
@@ -23,8 +23,8 @@
; CHECK: Running pass: LoopUnrollPass
; CHECK: Clearing all analysis results for: inner2.header
; CHECK: Clearing all analysis results for: outer.header
-; CHECK: Invalidating analysis: LoopAccessAnalysis on inner1.header
-; CHECK-NOT: Invalidating analysis: LoopAccessAnalysis on inner1.header.1
+; CHECK: Invalidating analysis: LoopAccessAnalysis on {{.*}}inner1.header
+; CHECK-NOT: Invalidating analysis: LoopAccessAnalysis on {{.*}}inner1.header.1
; CHECK: Starting Loop pass manager run.
; CHECK: Running pass: LoopAccessInfoPrinterPass
; CHECK: Running analysis: LoopAccessAnalysis on Loop at depth 1 containing: %inner1.header
diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp
index 02a19d0fd500e..d974729c2b481 100644
--- a/llvm/tools/opt/NewPMDriver.cpp
+++ b/llvm/tools/opt/NewPMDriver.cpp
@@ -277,10 +277,10 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
P->CSAction = PGOOptions::CSIRUse;
}
}
- LoopAnalysisManager LAM(DebugPM);
- FunctionAnalysisManager FAM(DebugPM);
- CGSCCAnalysisManager CGAM(DebugPM);
- ModuleAnalysisManager MAM(DebugPM);
+ LoopAnalysisManager LAM;
+ FunctionAnalysisManager FAM;
+ CGSCCAnalysisManager CGAM;
+ ModuleAnalysisManager MAM;
PassInstrumentationCallbacks PIC;
StandardInstrumentations SI(DebugPM, VerifyEachPass);
diff --git a/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp b/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
index 4ad449f6fa7b4..e004296ac00cc 100644
--- a/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
+++ b/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
@@ -202,8 +202,7 @@ class CGSCCPassManagerTest : public ::testing::Test {
public:
CGSCCPassManagerTest()
- : FAM(/*DebugLogging*/ true), CGAM(/*DebugLogging*/ true),
- MAM(/*DebugLogging*/ true),
+ : FAM(), CGAM(), MAM(),
M(parseIR(
// Define a module with the following call graph, where calls go
// out the bottom of nodes and enter the top:
diff --git a/llvm/unittests/CodeGen/PassManagerTest.cpp b/llvm/unittests/CodeGen/PassManagerTest.cpp
index aac5ee6b3e53f..3bb11cf823037 100644
--- a/llvm/unittests/CodeGen/PassManagerTest.cpp
+++ b/llvm/unittests/CodeGen/PassManagerTest.cpp
@@ -208,10 +208,10 @@ TEST_F(PassManagerTest, Basic) {
LLVMTargetMachine *LLVMTM = static_cast<LLVMTargetMachine *>(TM.get());
M->setDataLayout(TM->createDataLayout());
- LoopAnalysisManager LAM(/*DebugLogging=*/true);
- FunctionAnalysisManager FAM(/*DebugLogging=*/true);
- CGSCCAnalysisManager CGAM(/*DebugLogging=*/true);
- ModuleAnalysisManager MAM(/*DebugLogging=*/true);
+ LoopAnalysisManager LAM;
+ FunctionAnalysisManager FAM;
+ CGSCCAnalysisManager CGAM;
+ ModuleAnalysisManager MAM;
PassBuilder PB(TM.get());
PB.registerModuleAnalyses(MAM);
PB.registerFunctionAnalyses(FAM);
@@ -225,8 +225,7 @@ TEST_F(PassManagerTest, Basic) {
MachineFunctionAnalysisManager MFAM;
{
// Test move assignment.
- MachineFunctionAnalysisManager NestedMFAM(FAM, MAM,
- /*DebugLogging*/ true);
+ MachineFunctionAnalysisManager NestedMFAM(FAM, MAM);
NestedMFAM.registerPass([&] { return PassInstrumentationAnalysis(); });
NestedMFAM.registerPass([&] { return TestMachineFunctionAnalysis(); });
MFAM = std::move(NestedMFAM);
@@ -241,7 +240,7 @@ TEST_F(PassManagerTest, Basic) {
MachineFunctionPassManager MFPM;
{
// Test move assignment.
- MachineFunctionPassManager NestedMFPM(/*DebugLogging*/ true);
+ MachineFunctionPassManager NestedMFPM;
NestedMFPM.addPass(TestMachineModulePass(Count, TestMachineModuleCount[0]));
NestedMFPM.addPass(TestMachineFunctionPass(Count, BeforeInitialization[0],
BeforeFinalization[0],
diff --git a/llvm/unittests/IR/PassBuilderCallbacksTest.cpp b/llvm/unittests/IR/PassBuilderCallbacksTest.cpp
index edd46b8521d6d..a8d397456c016 100644
--- a/llvm/unittests/IR/PassBuilderCallbacksTest.cpp
+++ b/llvm/unittests/IR/PassBuilderCallbacksTest.cpp
@@ -467,7 +467,7 @@ class PassBuilderCallbacksTest<PassManager<
"}\n")),
CallbacksHandle(), PB(false, nullptr, PipelineTuningOptions(), None,
&CallbacksHandle.Callbacks),
- PM(true), LAM(true), FAM(true), CGAM(true), AM(true) {
+ PM(true), LAM(), FAM(), CGAM(), AM() {
EXPECT_TRUE(&CallbacksHandle.Callbacks ==
PB.getPassInstrumentationCallbacks());
diff --git a/llvm/unittests/IR/PassManagerTest.cpp b/llvm/unittests/IR/PassManagerTest.cpp
index a53a81e27a262..006b9b260c2c9 100644
--- a/llvm/unittests/IR/PassManagerTest.cpp
+++ b/llvm/unittests/IR/PassManagerTest.cpp
@@ -419,11 +419,11 @@ TEST(PreservedAnalysisTest, Abandon) {
}
TEST_F(PassManagerTest, Basic) {
- FunctionAnalysisManager FAM(/*DebugLogging*/ true);
+ FunctionAnalysisManager FAM;
int FunctionAnalysisRuns = 0;
FAM.registerPass([&] { return TestFunctionAnalysis(FunctionAnalysisRuns); });
- ModuleAnalysisManager MAM(/*DebugLogging*/ true);
+ ModuleAnalysisManager MAM;
int ModuleAnalysisRuns = 0;
MAM.registerPass([&] { return TestModuleAnalysis(ModuleAnalysisRuns); });
MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); });
@@ -704,8 +704,8 @@ struct LambdaPass : public PassInfoMixin<LambdaPass> {
};
TEST_F(PassManagerTest, IndirectAnalysisInvalidation) {
- FunctionAnalysisManager FAM(/*DebugLogging*/ true);
- ModuleAnalysisManager MAM(/*DebugLogging*/ true);
+ FunctionAnalysisManager FAM;
+ ModuleAnalysisManager MAM;
int FunctionAnalysisRuns = 0, ModuleAnalysisRuns = 0,
IndirectAnalysisRuns = 0, DoublyIndirectAnalysisRuns = 0;
FAM.registerPass([&] { return TestFunctionAnalysis(FunctionAnalysisRuns); });
@@ -823,7 +823,7 @@ TEST_F(PassManagerTest, FunctionPassCFGChecker) {
"}\n");
auto *F = M->getFunction("foo");
- FunctionAnalysisManager FAM(/*DebugLogging*/ true);
+ FunctionAnalysisManager FAM;
FunctionPassManager FPM(/*DebugLogging*/ true);
PassInstrumentationCallbacks PIC;
StandardInstrumentations SI(/*DebugLogging*/ true);
@@ -869,7 +869,7 @@ TEST_F(PassManagerTest, FunctionPassCFGCheckerInvalidateAnalysis) {
"}\n");
auto *F = M->getFunction("foo");
- FunctionAnalysisManager FAM(/*DebugLogging*/ true);
+ FunctionAnalysisManager FAM;
FunctionPassManager FPM(/*DebugLogging*/ true);
PassInstrumentationCallbacks PIC;
StandardInstrumentations SI(/*DebugLogging*/ true);
@@ -934,7 +934,7 @@ TEST_F(PassManagerTest, FunctionPassCFGCheckerWrapped) {
"}\n");
auto *F = M->getFunction("foo");
- FunctionAnalysisManager FAM(/*DebugLogging*/ true);
+ FunctionAnalysisManager FAM;
FunctionPassManager FPM(/*DebugLogging*/ true);
PassInstrumentationCallbacks PIC;
StandardInstrumentations SI(/*DebugLogging*/ true);
diff --git a/llvm/unittests/Transforms/Scalar/LoopPassManagerTest.cpp b/llvm/unittests/Transforms/Scalar/LoopPassManagerTest.cpp
index a03d43b10ba41..74e92d546ca71 100644
--- a/llvm/unittests/Transforms/Scalar/LoopPassManagerTest.cpp
+++ b/llvm/unittests/Transforms/Scalar/LoopPassManagerTest.cpp
@@ -297,7 +297,7 @@ class LoopPassManagerTest : public ::testing::Test {
"end:\n"
" ret void\n"
"}\n")),
- LAM(true), FAM(true), MAM(true) {
+ LAM(), FAM(), MAM() {
// Register our mock analysis.
LAM.registerPass([&] { return MLAHandle.getAnalysis(); });
More information about the cfe-commits
mailing list