Skip to content

[MachinePass] Run instrumentation before/after module pass #70919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions llvm/lib/CodeGen/MachinePassManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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();
Expand Down