How to include a opt pass in clang driver


I have written a pass for the IR and I can run it with opt -load lib/ -mypass -myarguments -S -o output.ll < output.bc

I have registered my pass with the following code:

static RegisterPass
X(“mypass”, “MyPass Pass (with getAnalysisUsage implemented)”);

How do I include the same pass in the clang driver. I tried running the pass:

clang output.c -o output -Xclang -load -Xclang lib/ -mypass -myarguments

However, the pass is not being run as I cannot see output from my pass. What is the standard way to do it?

I have also tried approach described here: . It didn’t work.

See RegisterStandardPasses in llvm/Transforms/IPO/PassManagerBuilder.h .


Hi Eli,

I have tried that:

static void registerMyPass(const PassManagerBuilder &,
llvm::legacy::PassManagerBase &PM) {
PM.add(new MyPass());

static RegisterStandardPasses

It still couldn’t find my pass.

OptimizerLast doesn't run unless you turn on optimizations (-O2). Maybe that's the issue?


Yeah it worked. Thank you so much! Correct command

clang output.c -o output -Xclang -load -Xclang lib/ -mllvm -myarguments