This is an archive of the discontinued LLVM Phabricator instance.

[NPM] Move more O0 pass building into PassBuilder
ClosedPublic

Authored by aeubanks on Nov 16 2020, 8:35 PM.

Details

Summary

This moves handling of alwaysinline, coroutines, matrix lowering, PGO,
and LTO-required passes into PassBuilder. Much of this is replicated
between Clang and opt. Other out-of-tree users also replicate some of
this, such as Rust [1] replicating the alwaysinline, LTO, and PGO
passes.

The LTO passes are also now run in
build(Thin)LTOPreLinkDefaultPipeline() since they are semantically
required for (Thin)LTO.

[1]: https://github.com/rust-lang/rust/blob/f5230fbf76bafd86ee4376a0e26e551df8d17fec/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp#L896

Diff Detail

Event Timeline

aeubanks created this revision.Nov 16 2020, 8:35 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptNov 16 2020, 8:35 PM
aeubanks requested review of this revision.Nov 16 2020, 8:35 PM

Thanks, generally this seems to be good cleanup. Question on one of the changes below though.

llvm/lib/Passes/PassBuilder.cpp
2363

This seems to change behavior. For one, previously we were only suppressing adding the PGO Instr passes for ThinLTO. Now this will suppress adding the coroutines passes and whatever else runRegisteredEPCallbacks was doing. Also, it's now doing the same for regular LTO but it didn't seem to do any special handling in that case before. Are these changes intended?

aeubanks added inline comments.Nov 17 2020, 1:12 PM
llvm/lib/Passes/PassBuilder.cpp
2363

The callbacks are generally for two purposes. One is to lower certain constructs, which only needs to be done once. It should already have been done in the pre-link step. The other is for optimization purposes at specific points in the pipeline. Since this is -O0, that doesn't matter.

So I think this makes sense.

aeubanks planned changes to this revision.Nov 17 2020, 1:16 PM
aeubanks added inline comments.
llvm/lib/Passes/PassBuilder.cpp
2363

Actually, I just noticed that build(Thin)LTODefaultPipeline does handle O0. The default and LTO pre-link ones assert when passed O0 so I assumed that was the case for the LTO pipelines, but that's not the case. I'll change that.

aeubanks updated this revision to Diff 305900.Nov 17 2020, 1:54 PM

make build(Thin)LTODefaultPipeline handle O0

tejohnson added inline comments.Nov 19 2020, 9:18 AM
llvm/lib/Passes/PassBuilder.cpp
2363

Ok, just to confirm, it seems like this code was incorrectly adding additional passes before for thinlto<O0> (coroutines, runRegisteredEPCallbacks) and for lto<O0> (pgo, coroutines, runRegisteredEPCallbacks) - is that correct?

I would have expected some changes in the new PM pipeline tests, but it looks like there is a lack of testing of these two. I don't see any pipeline tests for lto<O0>, and only one for thinlto<O0> - and that only checks the PGO passes (llvm/test/Other/new-pm-pgo-O0.ll). Can you add lto<O0> to that test? Can you also beef it up to add some of the other passes that (I think) we were previously adding below here for thinlto and lto that we won't anymore?

2365

I think it would be clearer to check against "thinlto-pre-link" and "lto-pre-link" here (and more robust in case any other types added in the future).

aeubanks updated this revision to Diff 306448.Nov 19 2020, 10:05 AM

check 'thinlto-pre-link'/'lto-pre-link' explicitly
add test

aeubanks marked an inline comment as done.Nov 19 2020, 10:07 AM
aeubanks added inline comments.
llvm/lib/Passes/PassBuilder.cpp
2363

added a new test in the vein of new-pm-defaults.ll, could you see if the printed passes make sense?

tejohnson added inline comments.Nov 19 2020, 10:13 AM
llvm/lib/Passes/PassBuilder.cpp
2365

Sorry, to be more explicit, I was talking about the below line, where it sets up the LTOPreLink parameter to buildO0DefaultPipeline. I think the above line is actually better the way it was (checking != "thinlto" and != "lto").

aeubanks updated this revision to Diff 306473.Nov 19 2020, 10:35 AM

change strings to check for

This revision is now accepted and ready to land.Nov 19 2020, 10:37 AM
Harbormaster completed remote builds in B79493: Diff 306473.
This revision was landed with ongoing or failed builds.Nov 19 2020, 11:22 AM
This revision was automatically updated to reflect the committed changes.