[llvm] [MachinePass] Run instrumentation before/after module pass (PR #70919)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 1 03:34:20 PDT 2023
https://github.com/paperchalice created https://github.com/llvm/llvm-project/pull/70919
This commit adds `runBeforePass`/`runAfterPass` for machine module pass so `llc -debug-pass-manager` can e.g., print module pass names.
>From 00e6426533daf93da733455bc39a5de21a00900d Mon Sep 17 00:00:00 2001
From: liujunchang <lgamma at 163.com>
Date: Wed, 1 Nov 2023 10:47:44 +0800
Subject: [PATCH] [MachinePass] Run instrumentation before/after module pass
---
llvm/lib/CodeGen/MachinePassManager.cpp | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/CodeGen/MachinePassManager.cpp b/llvm/lib/CodeGen/MachinePassManager.cpp
index a13f820e457766f..914e6b19fde9ac8 100644
--- a/llvm/lib/CodeGen/MachinePassManager.cpp
+++ b/llvm/lib/CodeGen/MachinePassManager.cpp
@@ -33,10 +33,11 @@ Error MachineFunctionPassManager::run(Module &M,
(void)RequireCodeGenSCCOrder;
assert(!RequireCodeGenSCCOrder && "not implemented");
+ // M is unused here
+ PassInstrumentation PI = MFAM.getResult<PassInstrumentationAnalysis>(M);
+
// Add a PIC to verify machine functions.
if (VerifyMachineFunction) {
- PassInstrumentation PI = MFAM.getResult<PassInstrumentationAnalysis>(M);
-
// No need to pop this callback later since MIR pipeline is flat which means
// current pipeline is the top-level pipeline. Callbacks are not used after
// current pipeline.
@@ -59,8 +60,11 @@ Error MachineFunctionPassManager::run(Module &M,
do {
// Run machine module passes
for (; MachineModulePasses.count(Idx) && Idx != Size; ++Idx) {
+ if (!PI.runBeforePass<Module>(*Passes[Idx], M))
+ continue;
if (auto Err = MachineModulePasses.at(Idx)(M, MFAM))
return Err;
+ PI.runAfterPass(*Passes[Idx], M, PreservedAnalyses::all());
}
// Finish running all passes.
@@ -81,7 +85,6 @@ Error MachineFunctionPassManager::run(Module &M,
continue;
MachineFunction &MF = MMI.getOrCreateMachineFunction(F);
- PassInstrumentation PI = MFAM.getResult<PassInstrumentationAnalysis>(MF);
for (unsigned I = Begin, E = Idx; I != E; ++I) {
auto *P = Passes[I].get();
More information about the llvm-commits
mailing list