-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Support LLVM new PassManager #8390
Conversation
Not sure if it was intentional to make this pr against the master branch, but zig also has a llvm12 branch that will be merged when llvm12 comes out. https://github.com/ziglang/zig/tree/llvm12 |
Yes, I'm aware of that (and shout out to zig community for keeping tightly with LLVM releases!) and I'll probably rebase this to LLVM 12 soon. But the problem is that migrating to new PM is not an easy task -- LLVM and Clang community takes years to do that. So I thought it's a good idea to make a separate PR to keep track of it |
Thank you @mshockwave for taking on this project. This is some valuable work you're doing here. I'd like to provide some guidance on a simplified approach to this problem: First of all please do rebase these changes against the Here's how I see this going: Let's switch over to the new pass manager immediately (in the llvm12 branch). No Also here is some miscellaneous replies to your bulleted points:
Note that we already have
The two levels are not separate on Zig's side of things either - this change actually is much closer to mapping to zig's actual optimization levels. It should be like this:
If you look one level up the callstack I believe you will see zig splitting its own optimization mode into separate levels; this code can be simplified to be a direct mapping instead.
I'm guessing you're talking about the "always inliner" pass? Right now this is required to emit semantically correct code, but I do want to note that this problem will go away with self-hosted, which does forced inlining in the semantic analysis phase, and so in this case we would not need to ever enable the "always inliner" pass. However, self-hosted is not done, so we do need the "always inliner" pass enabled with the new PM.
I didn't understand this point - can you elaborate? |
Make sense, I'll rebase to llvm12 branch and update this PR
Cool! I'm happy to do that
Oh, I am aware of that, the new flag I added,
Cool, this is also what I'm doing now
Make sense.
By saying code generation I'm talking about lowering LLVM IR to machine code, which is dictated by each target machine. For some reasons (for example, we don't have |
Now zig will use new PM for optimization by default.
68a1e9e
to
9ad832f
Compare
Just ported the changes from LLVM 11.x to 12.x (sorry I forgot to use RC3, hope that doesn't change anything. This is the HEAD I used: e89cdf8937bb6017cc99b05823428dd2fd673368) and compare against llvm12 branch. Everything looks fine (it can build stage2 without any problem) except that one of the tests, (NOTE: The build bots are failing because they are still configured with LLVM 11) |
Looks fine to me too - any reason this is still a draft? |
Oh okay, I'm happy to make it a normal PR |
- Enable MergeFunctionsPass in non-debug build. - Verify input and output IR when the assertion is turned on. - Add AlwaysInlinePass in debug build. - Add more comments.
// TODO: Maybe we should collect time trace rather than using timer | ||
// to get a more hierarchical timeline view |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you make this a github issue instead of a TODO comment?
edit: eh it's fine. will catch it with #363 eventually.
Nice work @mshockwave - this looks ready to merge to me. |
Please note this is reverted, see #8418 for more details. You pointed both of these issues out in this PR. Anyway now we have an issue to track it, and the next step towards landing the new PM code is to get the issues reported upstream. |
Make sense, thanks for putting them into a separate issue. I'll try to sort them out and report upstream if needed. |
Currently we are still using legacy LLVM PassManager for optimization and code generation. In this WIP draft, I'm adding an option to use the new PassManager for optimization.
There are primarily two reasons:
clang
,opt
, and LTO. Therefore I think it's good time to kick off the migration.Here is the summary and current status of the migration enclosed in this PR:
zig
:-fllvm-new-pm
to switch between legacy and new PM.build.zig
, we can't add custom compiler flag viabuild.Builder
, so I manually add two CLI flags as the advanced options forzig build
:--enable-time-report
and--llvm-use-newpm
for enabling time profiling and new PM, respectively. Please let me know if there is a more elegant solution.src/zig_llvm.cpp
, addemitUsingNewPM
function -- which will be enabled via the aforementioned CLI flag -- to optimize LLVM module with the new PassManager.PassBuilder
interface but I'm sure there is a knob for inlining hidden somewhere.Last but not the least, this PR is using LLVM release 11.x. I know some APIs and behaviors have changed on the new PM side since then, I'll see if new PM in newer version of LLVM can solve some of the problems here.