Reg: Executing ModulePass before O2/O3 optimizations

Hello Everyone

I have created a custom ModulePass which works fine when no optimization flag is enabled i.e. on -O0 level. I am trying to order the passes such that I run my ModulePass first and then the O2/O3 optimizations. Currently I am doing it in multiple steps, where at each step I getting the transformed IR and providing as input. Is it possible to specify this order in when invoking via clang itself.
Kindly guide me in this.

Thanking you
Sai

If you’re using the new PassManager you can register your Pass with PassBuilder::registerPipelineStartEPCallback.

-Min

Thanks Min-Yih. But currently I am using the legacy PassManager. Is there any alternative way to achieve this?