Skip to content

Commit 5cb1d13

Browse files
committed
[MachinePass] Run instrumentation before/after module pass
1 parent f64a057 commit 5cb1d13

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

llvm/lib/CodeGen/MachinePassManager.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ Error MachineFunctionPassManager::run(Module &M,
3333
(void)RequireCodeGenSCCOrder;
3434
assert(!RequireCodeGenSCCOrder && "not implemented");
3535

36+
// M is unused here
37+
PassInstrumentation PI = MFAM.getResult<PassInstrumentationAnalysis>(M);
38+
3639
// Add a PIC to verify machine functions.
3740
if (VerifyMachineFunction) {
38-
PassInstrumentation PI = MFAM.getResult<PassInstrumentationAnalysis>(M);
39-
4041
// No need to pop this callback later since MIR pipeline is flat which means
4142
// current pipeline is the top-level pipeline. Callbacks are not used after
4243
// current pipeline.
@@ -59,8 +60,11 @@ Error MachineFunctionPassManager::run(Module &M,
5960
do {
6061
// Run machine module passes
6162
for (; MachineModulePasses.count(Idx) && Idx != Size; ++Idx) {
63+
if (!PI.runBeforePass<Module>(*Passes[Idx], M))
64+
continue;
6265
if (auto Err = MachineModulePasses.at(Idx)(M, MFAM))
6366
return Err;
67+
PI.runAfterPass(*Passes[Idx], M, PreservedAnalyses::all());
6468
}
6569

6670
// Finish running all passes.
@@ -81,7 +85,6 @@ Error MachineFunctionPassManager::run(Module &M,
8185
continue;
8286

8387
MachineFunction &MF = MMI.getOrCreateMachineFunction(F);
84-
PassInstrumentation PI = MFAM.getResult<PassInstrumentationAnalysis>(MF);
8588

8689
for (unsigned I = Begin, E = Idx; I != E; ++I) {
8790
auto *P = Passes[I].get();

0 commit comments

Comments
 (0)