-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Extract some shared code from codegen backend target feature handling #140920
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
base: master
Are you sure you want to change the base?
Conversation
rustbot has assigned @compiler-errors. Use |
Some changes occurred in compiler/rustc_codegen_ssa Some changes occurred in compiler/rustc_codegen_ssa/src/codegen_attrs.rs Some changes occurred in compiler/rustc_codegen_gcc |
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.
There's a lot more logic in this file that seems like it should be shared across backends (almost all of fn codegen_fn_attrs
), but I shied away from the huge refactor that would have been.
This comment has been minimized.
This comment has been minimized.
8175ae7
to
b0607f4
Compare
This comment has been minimized.
This comment has been minimized.
There is no reason for that. I probably missed some stuff when I implemented this. |
b0607f4
to
e3f260f
Compare
This comment has been minimized.
This comment has been minimized.
e3f260f
to
e973da1
Compare
This comment has been minimized.
This comment has been minimized.
c46d167
to
891f35e
Compare
Anything in particular you're concerned about? But generally, no, it shouldn't be a problem. |
I can imagine two concerns:
|
☔ The latest upstream changes (presumably #141238) made this pull request unmergeable. Please resolve the merge conflicts. |
891f35e
to
9fc38d1
Compare
r? compiler |
☔ The latest upstream changes (presumably #135160) made this pull request unmergeable. Please resolve the merge conflicts. |
9fc38d1
to
1a58c68
Compare
This is somewhat bitrotty... and to my knowledge rather outside your typical review areas, @nnethercote. @workingjubilee @bjorn3 @nikic maybe one of you could take this? |
1a58c68
to
8915a90
Compare
That sounds reasonable.
I think you've gotten off-track here.
Also, Here's part of the crate graph. You can see how Crate graph generated with:
Based on this, I think significant parts of this PR are unnecessary:
This will significantly reduce the size of the PR, e.g. the entire first commit would disappear, along with part of the third commit. |
Thank you for doing this cleanup, and thank you @nnethercote and @WaffleLapkin for covering the review! |
Rollup of 9 pull requests Successful merges: - #128425 (Make `missing_fragment_specifier` an unconditional error) - #135927 (retpoline and retpoline-external-thunk flags (target modifiers) to enable retpoline-related target features) - #140770 (add `extern "custom"` functions) - #142176 (tests: Split dont-shuffle-bswaps along opt-levels and arches) - #142248 (Add supported asm types for LoongArch32) - #142267 (assert more in release in `rustc_ast_lowering`) - #142274 (Update the stdarch submodule) - #142276 (Update dependencies in `library/Cargo.lock`) - #142308 (Upgrade `object`, `addr2line`, and `unwinding` in the standard library) Failed merges: - #140920 (Extract some shared code from codegen backend target feature handling) r? `@ghost` `@rustbot` modify labels: rollup try-job: aarch64-apple try-job: x86_64-msvc-1 try-job: x86_64-gnu try-job: dist-i586-gnu-i586-i686-musl try-job: test-various
Rollup of 9 pull requests Successful merges: - #128425 (Make `missing_fragment_specifier` an unconditional error) - #135927 (retpoline and retpoline-external-thunk flags (target modifiers) to enable retpoline-related target features) - #140770 (add `extern "custom"` functions) - #142176 (tests: Split dont-shuffle-bswaps along opt-levels and arches) - #142248 (Add supported asm types for LoongArch32) - #142267 (assert more in release in `rustc_ast_lowering`) - #142274 (Update the stdarch submodule) - #142276 (Update dependencies in `library/Cargo.lock`) - #142308 (Upgrade `object`, `addr2line`, and `unwinding` in the standard library) Failed merges: - #140920 (Extract some shared code from codegen backend target feature handling) r? `@ghost` `@rustbot` modify labels: rollup try-job: aarch64-apple try-job: x86_64-msvc-1 try-job: x86_64-gnu try-job: dist-i586-gnu-i586-i686-musl try-job: test-various
☔ The latest upstream changes (presumably #142443) made this pull request unmergeable. Please resolve the merge conflicts. |
e790e54
to
0bc5e7e
Compare
I'm afraid this will need another review... the conflicts with #135927 were enormous. Also, that PR added some spaghetti to target_features that I found easier to remove during conflict resolution, than to incorporate into this PR. So this PR is now also a cleanup of retpoline flag handling, removing a bunch of unneeded complexity. Only the 2nd commit ("move -Ctarget-feature handling into shared code") saw major changes. |
This comment has been minimized.
This comment has been minimized.
f6affd7
to
83872bf
Compare
This comment has been minimized.
This comment has been minimized.
147d25a
to
9c1898b
Compare
This comment has been minimized.
This comment has been minimized.
This does change the logic a bit: previously, we didn't forward reverse implications of negated features to the backend, instead relying on the backend to handle the implication itself.
9c1898b
to
b471447
Compare
There's a bunch of code duplication between the GCC and LLVM backends in target feature handling. This moves that into new shared helper functions in
rustc_codegen_ssa
.The first two commits should be purely refactoring. I am fairly sure the LLVM-side behavior stays the same; if the GCC side deliberately diverges from this then I may have missed that. I did account for one divergence, which I do not know is deliberate or not: GCC does not seem to use the
-Ctarget-feature
flag to populatecfg(target_feature)
. That seems odd, since the-Ctarget-feature
flag is used to populate the return value ofglobal_gcc_features
which controls the target features actually used by GCC. @GuillaumeGomez @antoyo is there a reasontarget_config
ignores-Ctarget-feature
butglobal_gcc_features
does not?The third commit extracts some shared logic out of the functions that populate
cfg(target_feature)
and the backend target feature set, respectively. This one actually has some slight functional changes:-Ctarget-feature=-feat
, if there is some other featurex
that impliesfeat
we would not add-x
to the backend target feature set. Now, we do. This fixes Target feature implications for negative features are handled inconsistently between codegen andcfg(target_feature)
#134792.x
fromcfg(target_feature)
in this case also changed a bit, avoiding a large number of calls to the (uncached)sess.target.implied_target_features
(if there were a large number of positive features listed before a negative feature) but instead constructing a full inverse implication map when encountering the first negative feature. Ideally this would be done with queries but the backend target feature logic runs beforetcx
so we can't use that...-Ctarget-feature=+a
would also emit a warning aboutb
. I had to remove this since when accounting for negative implications, this emits a ton of warnings in a bunch of existing tests... I assume this was unintentional anyway.The fourth commit increases consistency of the GCC backend with the LLVM backend.
@bjorn3 I did not touch the cranelift backend here, since AFAIK it doesn't really support target features. But if you ever do, please use the new helpers. :)
Cc @workingjubilee