add pass to O2. use as "clang -O2 .."

Hello folks,

I wrote a transforming looppass for my project, opt --help can see it. I want clang to use my pass too, so that I don’t have to compile to IR, opt, and then llc to binary manually. Now I am trying to add my pass to O2 by mimicking LICM pass.

I add a line “MPM.add(createMyPass());” in PassManagerBuilder::populateModulePassManager, and got assertion fail “void llvm::PMTopLevelManager::schedulePass(llvm::Pass*): Assertion `PI && “Expected required passes to be initialized”’ failed.” I can’t figure out how to solve this? thanks for any inputs.

yuanfang

Hi Yuanfang,

I wrote a transforming looppass for my project, opt --help can see it. I want
clang to use my pass too, so that I don't have to compile to IR, opt, and then
llc to binary manually. Now I am trying to add my pass to O2 by mimicking LICM
pass.

I add a line "MPM.add(createMyPass());"
in PassManagerBuilder::populateModulePassManager, and got assertion fail "void
llvm::PMTopLevelManager::schedulePass(llvm::Pass*): Assertion `PI && "Expected
required passes to be initialized"' failed." I can't figure out how to solve
this? thanks for any inputs.

maybe you need to use INITIALIZE_PASS_DEPENDENCY. If you grep for this in
lib/Transforms/Scalar you will see several examples.

Ciao, Duncan.