rnk added a comment. The general approach seems reasonable to me, but IIRC a ModulePass creates a scheduling barrier in the PassManager pipeline. You probably want to schedule it first at the top of addPassesToGenerateCode in LLVMTargetMachine.cpp. http://reviews.llvm.org/D15300