Identify pass in the compilation pipeline

Hello All;

My goal is to do a specific peephole to the IR using the InstrCombine pass. But I want to run the peephole at a particular point (at a late stage) of the compilation pipeline. The InstCombine is run multiple times in the compilation pipeline. Is there a way to identify where I am in the compilation pipeline from within the InstrCombine pass? I guess one option will be to look for specific code patterns that can only happen at a late compilation stage, but is there a simpler way?

Thanks a lot for your help.

This sounds fragile and unlikely to behave as we want in general. InstCombine only tries to do target-independent (universally good) transforms. That’s why it is included at all (some would say too many!) different points in the optimization pipeline.

If your transform only makes sense late in the pipeline, you might look at CodeGenPrepare or DAGCombiner instead of InstCombine. You would also have access to target features/costs in those passes, so the transform could be limited to the cases where it makes sense.