-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Pass through of target features to llvm-bitcode-linker and handling them #136608
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Noratrieb (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
This comment has been minimized.
This comment has been minimized.
f4e1ac4
to
935529b
Compare
r? @kjetilkjeka but I don't think it will work 🤔 |
Failed to set assignee to
|
Thanks for wanting to fix this bug in the llbm-bitcode-linker.
The features should be added in After this PR is merged it's already possible to use
By adding the features to |
Thanks for the feedback. I would prefer to add these features to The behavior of llc that I could observe during my tests is the highest ptx version specified wins. The logic in llvm is generated by tablegen and looks like this: if (Bits[NVPTX::PTX32] && PTXVersion < 32) PTXVersion = 32;
if (Bits[NVPTX::PTX40] && PTXVersion < 40) PTXVersion = 40;
// ...
if (Bits[NVPTX::PTX87] && PTXVersion < 87) PTXVersion = 87; So |
935529b
to
8f353ae
Compare
This comment has been minimized.
This comment has been minimized.
8f353ae
to
851724c
Compare
I changed the implementation so that the existing Other options would have been:
|
851724c
to
556281f
Compare
I slightly changed the implementation. |
It looks like you found the right place to hook onto the target_feature. It seems to me like I'm not an approved reviewer for rustc, but it looks great from my perspective. If I could I would have r+'ed. For the follow up, where you add the ptx features. Also add a couple of tests where we check that using features like Thanks a lot for contributing to the |
Thanks again for the review and the positive feedback! |
r? bjorn3 I think you're the best person to judge the approach from a compiler side |
Bitcode linkers like llvm-bitcode-linker or bpf linker hand over the target features to llvm during link stage. During link stage the `TyCtxt` is already gone so it is not possible to create a query for the global backend features any longer. The features preserved in `Session.target_features` only incorporate target features known to rustc. This would contradict with the behaviour during codegen stage which also passes target features to llvm which are unknown to rustc. This commit adds target features as a field to the `CrateInfo` struct and queries the target features in its new function. This way the target features are preserved beyond tcx and available at link stage. To make sure the `global_backend_features` query is always registered even if the CodegenBackend does not register it, this registration is added to the `provide`function of the `rustc_codegen_ssa` crate.
The .ptx version produced by llc can be specified by passing it with --mattr. Currently it is not possible to specify the .ptx version with -Ctarget-feature because these are not passed through to llvm-bitcode-linker and handled by it. This commit adds both. --target-feature and -mattr are passed with equals to mitigate issues when the value starts with a - (minus).
556281f
to
831d9f3
Compare
@bors r+ |
Pass through of target features to llvm-bitcode-linker and handling them When using the llvm-bitcode-linker (`linker-flavor=llbc`) target-features are not passed through and are not handled by it. The llvm-bitcode-linker is mainly used as a self contained linker to link llvm bitcode for the nvptx64 target. It uses `llvm-link`, `opt` and `llc` internally. To produce a `.ptx` file of a specific ptx-version it is necessary to pass the version to llc with the `--mattr` option. Without explicitly setting it, the emitted `.ptx`-version is the minimum supported version of the `--target-cpu`. I would like to be able to explicitly set the ptx version as [some llvm problems only occur in earlier `.ptx`-versions](llvm/llvm-project#112998). Therefore this pull request adds support for passing target features to llvm-bitcode-linker and handling them. I was not quite sure if adding these features to `rustc_target/src/target_features.rs` is necessary or not. If so I will gladly add these. r? `@kjetilkjeka`
…kingjubilee Rollup of 14 pull requests Successful merges: - rust-lang#131651 (Create a generic AVR target: avr-none) - rust-lang#136473 (infer linker flavor by linker name if it's sufficiently specific) - rust-lang#136608 (Pass through of target features to llvm-bitcode-linker and handling them) - rust-lang#136985 (Do not ignore uninhabited types for function-call ABI purposes. (Remove BackendRepr::Uninhabited)) - rust-lang#137192 (Remove obsolete Windows ThinLTO+TLS workaround) - rust-lang#137204 (Clarify MIR dialects and phases) - rust-lang#137270 (Fix `*-win7-windows-msvc` target since 26eeac1) - rust-lang#137298 (Check signature WF when lowering MIR body) - rust-lang#137299 (Simplify `Postorder` customization.) - rust-lang#137312 (Update references to cc_detect.rs) - rust-lang#137313 (Some codegen_llvm cleanups) - rust-lang#137318 (Workaround Cranelift not yet properly supporting vectors smaller than 128bit) - rust-lang#137322 (Update docs for default features of wasm targets) - rust-lang#137324 (Make x86 QNX target name consistent with other Rust targets) r? `@ghost` `@rustbot` modify labels: rollup
…kingjubilee Rollup of 12 pull requests Successful merges: - rust-lang#131651 (Create a generic AVR target: avr-none) - rust-lang#134340 (Stabilize `num_midpoint_signed` feature) - rust-lang#136473 (infer linker flavor by linker name if it's sufficiently specific) - rust-lang#136608 (Pass through of target features to llvm-bitcode-linker and handling them) - rust-lang#136985 (Do not ignore uninhabited types for function-call ABI purposes. (Remove BackendRepr::Uninhabited)) - rust-lang#137270 (Fix `*-win7-windows-msvc` target since 26eeac1) - rust-lang#137312 (Update references to cc_detect.rs) - rust-lang#137318 (Workaround Cranelift not yet properly supporting vectors smaller than 128bit) - rust-lang#137322 (Update docs for default features of wasm targets) - rust-lang#137324 (Make x86 QNX target name consistent with other Rust targets) - rust-lang#137338 (skip submodule updating logics on tarballs) - rust-lang#137340 (Add a notice about missing GCC sources into source tarballs) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#136608 - kulst:ptx_target_features, r=bjorn3 Pass through of target features to llvm-bitcode-linker and handling them When using the llvm-bitcode-linker (`linker-flavor=llbc`) target-features are not passed through and are not handled by it. The llvm-bitcode-linker is mainly used as a self contained linker to link llvm bitcode for the nvptx64 target. It uses `llvm-link`, `opt` and `llc` internally. To produce a `.ptx` file of a specific ptx-version it is necessary to pass the version to llc with the `--mattr` option. Without explicitly setting it, the emitted `.ptx`-version is the minimum supported version of the `--target-cpu`. I would like to be able to explicitly set the ptx version as [some llvm problems only occur in earlier `.ptx`-versions](llvm/llvm-project#112998). Therefore this pull request adds support for passing target features to llvm-bitcode-linker and handling them. I was not quite sure if adding these features to `rustc_target/src/target_features.rs` is necessary or not. If so I will gladly add these. r? ``@kjetilkjeka``
When using the llvm-bitcode-linker (
linker-flavor=llbc
) target-features are not passed through and are not handled by it.The llvm-bitcode-linker is mainly used as a self contained linker to link llvm bitcode for the nvptx64 target. It uses
llvm-link
,opt
andllc
internally. To produce a.ptx
file of a specific ptx-version it is necessary to pass the version to llc with the--mattr
option. Without explicitly setting it, the emitted.ptx
-version is the minimum supported version of the--target-cpu
.I would like to be able to explicitly set the ptx version as some llvm problems only occur in earlier
.ptx
-versions.Therefore this pull request adds support for passing target features to llvm-bitcode-linker and handling them.
I was not quite sure if adding these features to
rustc_target/src/target_features.rs
is necessary or not. If so I will gladly add these.