Avoid CFG check for a module pass

I’m working on a module pass that modifies CFG (add a if statement to guard an instruction). However, the pass triggers the CFG check defined in StandardInstrumentations.cpp (PreservedCFGCheckerInstrumentation::registerCallbacks).

So my question is what is the recommended way to avoid the CFG check for my pass? My module pass is added in PassBuilder::buildPerModuleDefaultPipeline and the check was triggered when running my pass (i.e. modifying the CFG by adding basic block).

I’m not familiar with the CFG check but I think you can avoid StandardInstrumentations, by simply not passing anything to the PassInstrumentationCallbacks ctor argument, when you created a PassBuilder instance, right? (assuming you have control on PassBuilder creation)

The CFG checker should only complain if you modified the CFG and reported that CFG-analyses are preserved. Modifying the CFG in a module pass is fine, but the change needs to be reported.

What do you return for PreservedAnalyses from the run() method of the pass?

I returned PreservedAnalyses::none() if the change is made in my pass.

I didn’t add anything related to PassInstrumentationCallbacks while adding my pass in PassBuilderPipeline but I guess I might need to blacklist my pass in PassInstrumentationCallbacks?

As nikic said, it’s checking that a pass returns the proper PreservedAnalyses if you’ve made a change to the IR. Unless there’s an issue with PreservedCFGCheckerInstrumentation itself, which I doubt, you shouldn’t turn it off.

It’s probably more likely that you’re accidentally making some change but returning PreservedAnalyses::all(). Check the IR before and after the checker complains with --print-changed or --print-before-all. --print-changed=diff is quite nice.