[llvm] fb12863 - [CodeGen][NewPM] Add `MachineOptimizationRemarkEmitterAnalysis` (#98601)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 13 23:29:12 PDT 2024
Author: paperchalice
Date: 2024-07-14T14:29:08+08:00
New Revision: fb128630a7ba0ebe21cddf6647903a18ab246188
URL: https://github.com/llvm/llvm-project/commit/fb128630a7ba0ebe21cddf6647903a18ab246188
DIFF: https://github.com/llvm/llvm-project/commit/fb128630a7ba0ebe21cddf6647903a18ab246188.diff
LOG: [CodeGen][NewPM] Add `MachineOptimizationRemarkEmitterAnalysis` (#98601)
Add `MachineOptimizationRemarkEmitterAnalysis` the legacy version
`MachineOptimizationRemarkEmitterPass` is already a wrapper.
Added:
Modified:
llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h
llvm/include/llvm/Passes/MachinePassRegistry.def
llvm/lib/CodeGen/MachineOptimizationRemarkEmitter.cpp
llvm/lib/Passes/PassBuilder.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h b/llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h
index 2b177e6763d39..d4edacedb88e6 100644
--- a/llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h
+++ b/llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h
@@ -16,6 +16,7 @@
#define LLVM_CODEGEN_MACHINEOPTIMIZATIONREMARKEMITTER_H
#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/CodeGen/MachinePassManager.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Function.h"
#include <optional>
@@ -155,6 +156,13 @@ class MachineOptimizationRemarkEmitter {
MachineBlockFrequencyInfo *MBFI)
: MF(MF), MBFI(MBFI) {}
+ MachineOptimizationRemarkEmitter(MachineOptimizationRemarkEmitter &&) =
+ default;
+
+ /// Handle invalidation events in the new pass manager.
+ bool invalidate(MachineFunction &MF, const PreservedAnalyses &PA,
+ MachineFunctionAnalysisManager::Invalidator &Inv);
+
/// Emit an optimization remark.
void emit(DiagnosticInfoOptimizationBase &OptDiag);
@@ -212,6 +220,17 @@ class MachineOptimizationRemarkEmitter {
bool shouldEmitVerbose() { return MBFI != nullptr; }
};
+/// The analysis pass
+class MachineOptimizationRemarkEmitterAnalysis
+ : public AnalysisInfoMixin<MachineOptimizationRemarkEmitterAnalysis> {
+ friend AnalysisInfoMixin<MachineOptimizationRemarkEmitterAnalysis>;
+ static AnalysisKey Key;
+
+public:
+ using Result = MachineOptimizationRemarkEmitter;
+ Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM);
+};
+
/// The analysis pass
///
/// Note that this pass shouldn't generally be marked as preserved by other
diff --git a/llvm/include/llvm/Passes/MachinePassRegistry.def b/llvm/include/llvm/Passes/MachinePassRegistry.def
index d5cd8d4a132fc..70c4f3484af1a 100644
--- a/llvm/include/llvm/Passes/MachinePassRegistry.def
+++ b/llvm/include/llvm/Passes/MachinePassRegistry.def
@@ -101,6 +101,8 @@ MACHINE_FUNCTION_ANALYSIS("machine-branch-prob",
MachineBranchProbabilityAnalysis())
MACHINE_FUNCTION_ANALYSIS("machine-dom-tree", MachineDominatorTreeAnalysis())
MACHINE_FUNCTION_ANALYSIS("machine-loops", MachineLoopAnalysis())
+MACHINE_FUNCTION_ANALYSIS("machine-opt-remark-emitter",
+ MachineOptimizationRemarkEmitterAnalysis())
MACHINE_FUNCTION_ANALYSIS("machine-post-dom-tree",
MachinePostDominatorTreeAnalysis())
MACHINE_FUNCTION_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis(PIC))
@@ -112,8 +114,6 @@ MACHINE_FUNCTION_ANALYSIS("slot-indexes", SlotIndexesAnalysis())
// MACHINE_FUNCTION_ANALYSIS("machine-loops", MachineLoopInfoAnalysis())
// MACHINE_FUNCTION_ANALYSIS("machine-dom-frontier",
// MachineDominanceFrontierAnalysis())
-// MACHINE_FUNCTION_ANALYSIS("machine-ore",
-// MachineOptimizationRemarkEmitterPassAnalysis())
// MACHINE_FUNCTION_ANALYSIS("machine-post-dom-tree",
// MachinePostDominatorTreeAnalysis())
// MACHINE_FUNCTION_ANALYSIS("machine-region-info",
diff --git a/llvm/lib/CodeGen/MachineOptimizationRemarkEmitter.cpp b/llvm/lib/CodeGen/MachineOptimizationRemarkEmitter.cpp
index 1c31eba909e78..039f07f2e5e3f 100644
--- a/llvm/lib/CodeGen/MachineOptimizationRemarkEmitter.cpp
+++ b/llvm/lib/CodeGen/MachineOptimizationRemarkEmitter.cpp
@@ -31,6 +31,14 @@ DiagnosticInfoMIROptimization::MachineArgument::MachineArgument(
/*SkipDebugLoc=*/true);
}
+bool MachineOptimizationRemarkEmitter::invalidate(
+ MachineFunction &MF, const PreservedAnalyses &PA,
+ MachineFunctionAnalysisManager::Invalidator &Inv) {
+ // This analysis has no state and so can be trivially preserved but it needs
+ // a fresh view of BFI if it was constructed with one.
+ return MBFI && Inv.invalidate<MachineBlockFrequencyAnalysis>(MF, PA);
+}
+
std::optional<uint64_t>
MachineOptimizationRemarkEmitter::computeHotness(const MachineBasicBlock &MBB) {
if (!MBFI)
@@ -86,6 +94,18 @@ void MachineOptimizationRemarkEmitterPass::getAnalysisUsage(
MachineFunctionPass::getAnalysisUsage(AU);
}
+AnalysisKey MachineOptimizationRemarkEmitterAnalysis::Key;
+
+MachineOptimizationRemarkEmitterAnalysis::Result
+MachineOptimizationRemarkEmitterAnalysis::run(
+ MachineFunction &MF, MachineFunctionAnalysisManager &MFAM) {
+ MachineBlockFrequencyInfo *MBFI =
+ MF.getFunction().getContext().getDiagnosticsHotnessRequested()
+ ? &MFAM.getResult<MachineBlockFrequencyAnalysis>(MF)
+ : nullptr;
+ return Result(MF, MBFI);
+}
+
char MachineOptimizationRemarkEmitterPass::ID = 0;
static const char ore_name[] = "Machine Optimization Remark Emitter";
#define ORE_NAME "machine-opt-remark-emitter"
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index d4eca4a48e55d..96fd446551975 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -100,6 +100,7 @@
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineFunctionAnalysis.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
+#include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
#include "llvm/CodeGen/MachinePassManager.h"
#include "llvm/CodeGen/MachinePostDominators.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
More information about the llvm-commits
mailing list