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

How to pass addition arguments to llvm pass registered by new pass manager #56137

Closed
LeoneChen opened this issue Jun 21, 2022 · 8 comments
Closed
Labels
llvm:core question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

Comments

@LeoneChen
Copy link

When I use clang-13 -fpass-plugin to load pass, and use mllvm to provide addition arguments

image

Then I get error

image

But when I use clang-13 -flegacy-pass-manager -Xclang -load -Xclang to load it, everything is OK

@EugeneZelenko EugeneZelenko added question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! llvm:core and removed new issue labels Jun 21, 2022
@Chordp
Copy link

Chordp commented Jul 7, 2022

Same question

@viroulep
Copy link

viroulep commented Aug 1, 2022

At the moment the only way to be able to register options and still use the new PM is to provide both the -Xclang -load -Xclang lib.so and -Xclang -fpass-plugin=lib.so.

The first load will make sure the options defined in the library will be registered before command line arguments are parsed.

@LeoneChen
Copy link
Author

OK, thanks~

@OfekShilon
Copy link
Contributor

@viroulep On clang 16 I'm getting "Bad options: -load" with this. Has the workaround changed since writing this?

@viroulep
Copy link

I don't think so, the load option seems to be still here, I just compiled the Bye example plugin and ran it over some very basic IR and the workaround seemed to still work:

foo@d366b74ba893:~/llvm/tmp/tests/Bye/build$ clang-16 -Xclang -load -Xclang ./Bye.so -fpass-plugin=./Bye.so -mllvm -wave-goodbye foo.ll -S
Bye: g
Bye: f
Bye: main

While looking at the code I also realized the frontend turns -fplugin into the appropriate load so this works too:

foo@d366b74ba893:~/llvm/dockers/tests/Bye/build$ clang-16 -fplugin=./Bye.so -fpass-plugin=./Bye.so -mllvm -wave-goodbye foo.ll -S
Bye: g
Bye: f
Bye: main

@OfekShilon
Copy link
Contributor

@viroulep Thank you! Perhaps invoking plugins this way works only on IR? If I change foo.ll into some toy foo.cpp I can no longer see "Bye: foo"

@viroulep
Copy link

I think it works on cpp as well:

foo@cf52f006f235:~/llvm/dockers/tests/Bye/build$ cat main.cpp 
int main() { return 0; }
foor@cf52f006f235:~/llvm/dockers/tests/Bye/build$ clang-16 -O1 -fplugin=./Bye.so -fpass-plugin=./Bye.so -mllvm -wave-goodbye main.cpp 
Bye: main

If the driver doesn't complain about an unknown option then the plugin is surely loaded and maybe it's just because you compile with -O0?
If you don't specify a -O then -O0 is assumed and clang will add an optnone attribute to the functions, and therefore Bye will not run over them (because the pass implemented in the Bye plugin doesn't implement the isRequired function).

@OfekShilon
Copy link
Contributor

@viroulep Thanks - you're right of course. I now think my problem is different: our plugin implements 2 passes (say "pass1" and "opass2") and according to the existing docs -mllvm -passes=pass1 should have made just pass1 apply. Is it possible this doesn't work in the new pass manager?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:core question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!
Projects
None yet
Development

No branches or pull requests

5 participants