1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

[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
This commit is contained in:
Arthur Eubanks 2021-05-07 14:32:40 -07:00
parent f2be584bf8
commit 86faf963ab
13 changed files with 79 additions and 46 deletions

View File

@ -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;

View File

@ -81,6 +81,8 @@ public:
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 @@ public:
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 @@ private:
/// 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 @@ public:
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.
///

View File

@ -746,9 +746,7 @@ public:
};
/// 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 @@ private:
/// 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>;

View File

@ -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});

View File

@ -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);

View File

@ -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) {

View File

@ -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

View File

@ -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);

View File

@ -202,8 +202,7 @@ protected:
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:

View File

@ -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],

View File

@ -467,7 +467,7 @@ protected:
"}\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());

View File

@ -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);

View File

@ -297,7 +297,7 @@ public:
"end:\n"
" ret void\n"
"}\n")),
LAM(true), FAM(true), MAM(true) {
LAM(), FAM(), MAM() {
// Register our mock analysis.
LAM.registerPass([&] { return MLAHandle.getAnalysis(); });