Hello,
I am adding to an LLVM pass that requires a filename as input. I am able to input this filename as a command line argument when I invoke this pass using opt, but I ultimately need to pass this argument to my code when I compile code with clang.
How can I pass this argument to clang so that I can use it in my LLVM pass? Thanks for your help!
Best,
Shishir Jessu

Hello Shishir,
To pass arguments to LLVM from clang, use something like `clang source.c -mllvm -customarg -mllvm argvalue`. The -mllvm argument tells clang to forward the following argument to LLVM. Similarly, there is the -Xclang argument to pass the following argument to clang proper, as opposed to the clang driver.
Cheers,
Benno
Hi Benno,
Thanks for your response! Unfortunately, I don’t think the -mllvm flag is doing what I need.
Specifically, I am adding to the LowerTypeTests optimization pass in LLVM. When I invoke this pass with opt, there is a command line option called “lowertypetests-read-summary”, which allows me to specify a file name. I’ve added a similar option, that takes a filename as input and opens that file to obtain some information necessary to do the pass.
It looks like -lowertypetests is not a pass that -mllvm recognizes, so I’m not able to input arguments to this pass using -mllvm. In fact, it doesn’t seem like any of the passes that -mllvm recognizes can be invoked with opt. Do you know if there’s some code I can modify that will allow -mllvm to recognize this pass? Or is there a better way to get clang to send the filename input to my pass? Thanks so much for your help!
Best,
Shishir Jessu

Hi Shishir,
How are you adding/registering your pass? Perhaps you're loading your pass dynamically? Which pass manager are you using?
Certain things work differently depending on whether you're linking your pass statically, or loading it dynamically. Also, there are subtle differences between the new and legacy pass managers.
-Andrzej