Integrating a pass as a clang option

Good afternoon

I've developed a pass that I want to run directly from a clang invocation by setting an option in the command line. The pass has been ran through opt and tested for correctness. I've defined the option and the driver can parse it but I haven't been able to trigger the execution of the pass by the pass manager. Is there any particular structure I need to follow to convert the flag I added in include/clang/Driver/ into an option parsed by the frontend?

Kindest regards

Jose Luis


I wrote a small tutorial about this very topic:
Details might differ from ToT codebase but I think the workflow hasn’t changed since then.
Hope this helps.


There is a pass plugin infrastructure for such cases [1]. There is an
example Bye pass[2] and Polly using it in-tree to see how to use it.



Good morning,

Thank you for the quick response. That tutorial helped with finding most of the parts that I needed to modify in order to run my pass but it seems that code changes in the past couple of years cause the option parsing to ignore the added code generator option in the “Real” CompilerInvocation, and as a consequence the passes are never ran. In particular it seems to be related to the new codegen options definition file, so I want to be perfectly sure of properly adding what is needed.

Kindest regards,

Jose Luis

Using the pass plugin infrastructure wasn't something that I had in mind, considering that the option to load them requires a file path and we also wanted it to be integrated within our compiler, but it's something I'll keep in mind now considering it seems to be the more accepted way to do it.

Kindest regards

Jose Luis