Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling pass from Clang #36

Open
palmerc opened this issue Jul 7, 2021 · 5 comments
Open

Calling pass from Clang #36

palmerc opened this issue Jul 7, 2021 · 5 comments
Labels
enhancement New feature or request

Comments

@palmerc
Copy link

palmerc commented Jul 7, 2021

When you call opt directly you use --passes and the list of desired passes, but in some older code I've seen you could call from clang with -mllvm followed by some additional options added directly to PassManagerBuilder in the form of cl::opt items. This was also how you could then pass along additional options to the pass. This code was using the legacy pass manager. What is the current way to specify the passes and options when using clang?

@banach-space banach-space added the enhancement New feature or request label Jul 17, 2021
@banach-space
Copy link
Owner

Hello @palmerc ,

Thank you for stopping by! :) Unfortunately, the short answer is that I don't know.

Running plugins from clang
It's a very important use-case and I am curious myself. I've labeled this as an enhancement and will try to produce some examples and/or docs (or at least get a better understanding of the available options). I can't commit to any timelines and volunteers are always very welcome :)

Passing command line options to plugins with clang
All of llvm-tutor relies on opt to load and run the plugins. clang is a completely different driver, so the underlying logic around command-line options is also very different. I haven't really looked into it yet.

In opt, AFAIK, it is not possible to pass command line options to plugins when using the new PM. This was brought up in the past:

This might have changed since I looked into it originally (LLVM ~9).

-Andrzej

@palmerc
Copy link
Author

palmerc commented Jul 17, 2021 via email

@palmerc
Copy link
Author

palmerc commented Jul 19, 2021

Initial look. You can get options back to LLVM by calling clang with -mllvm followed by the option. You would then need to add your pass into PassManagerBuilder by specifying an option cl::opt and then in void PassManagerBuilder::populateModulePassManager(legacy::PassManagerBase &MPM) you would call MPM.add() there is a function pass analogue named populateFunctionPassManager

@banach-space
Copy link
Owner

Thanks for the update! Do you know where are options for LLVM defined? (e.g. -load). And who is responsible for calling populateModulePassManager? Is that supposed to happen in a plugin?

@banach-space
Copy link
Owner

FYI: https://lists.llvm.org/pipermail/cfe-dev/2020-November/067166.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants