-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Add -Zllvm-target-feature to pass features directly to LLVM #159545
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
Draft
fo40225
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
fo40225:Zllvm-target-feature
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/doc/unstable-book/src/compiler-flags/llvm-target-feature.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # `llvm-target-feature` | ||
|
|
||
| --- | ||
|
|
||
| Forwards target feature strings directly to LLVM, bypassing Rust's known-feature table. | ||
|
|
||
| Registered as a target modifier. | ||
|
|
||
| Does not affect `cfg(target_feature)`. | ||
|
|
||
| Ignored by non-LLVM backends. | ||
|
|
||
| ```sh | ||
| rustc -Zllvm-target-feature=+prefer-256-bit main.rs | ||
| rustc -Zllvm-target-feature=+prefer-256-bit,+fast-gather main.rs | ||
| rustc -Zllvm-target-feature=+prefer-256-bit,-avx512f main.rs | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Verify `-Zllvm-target-feature` reaches LLVM IR (`prefer-256-bit` is LLVM-only). | ||
| //@ add-minicore | ||
| //@ needs-llvm-components: x86 | ||
| //@ compile-flags: --target x86_64-unknown-linux-gnu -Zllvm-target-feature=+prefer-256-bit | ||
| #![crate_type = "lib"] | ||
| #![feature(no_core)] | ||
| #![no_core] | ||
| extern crate minicore; | ||
|
|
||
| #[no_mangle] | ||
| pub fn foo() { | ||
| // CHECK: @foo() unnamed_addr #0 | ||
|
|
||
| // CHECK: attributes #0 = { {{.*}}"target-features"="{{[^"]*}}+prefer-256-bit{{.*}} } | ||
| } |
7 changes: 7 additions & 0 deletions
7
tests/ui/target_modifiers/auxiliary/wrong_llvm_target_feature.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| //@ no-prefer-dynamic | ||
| //@ compile-flags: --target x86_64-unknown-linux-gnu -Zllvm-target-feature=+fake-feature | ||
| //@ needs-llvm-components: x86 | ||
|
|
||
| #![feature(no_core)] | ||
| #![crate_type = "rlib"] | ||
| #![no_core] |
1 change: 1 addition & 0 deletions
1
...rget_modifiers/incompatible_llvm_target_feature.allow_llvm_target_feature_mismatch.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| '+another-feature' is not a recognized feature for this target (ignoring feature) |
14 changes: 14 additions & 0 deletions
14
tests/ui/target_modifiers/incompatible_llvm_target_feature.error_generated.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| '+another-feature' is not a recognized feature for this target (ignoring feature) | ||
| error: mixing `-Zllvm-target-feature` will cause an ABI mismatch in crate `incompatible_llvm_target_feature` | ||
| --> $DIR/incompatible_llvm_target_feature.rs:11:1 | ||
| | | ||
| LL | #![feature(no_core)] | ||
| | ^ | ||
| | | ||
| = help: the `-Zllvm-target-feature` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely | ||
| = note: `-Zllvm-target-feature=+another-feature` in this crate is incompatible with `-Zllvm-target-feature=+fake-feature` in dependency `wrong_llvm_target_feature` | ||
| = help: set `-Zllvm-target-feature=+fake-feature` in this crate or `-Zllvm-target-feature=+another-feature` in `wrong_llvm_target_feature` | ||
| = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=llvm-target-feature` to silence this error | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
16 changes: 16 additions & 0 deletions
16
tests/ui/target_modifiers/incompatible_llvm_target_feature.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| //@ aux-build:wrong_llvm_target_feature.rs | ||
| //@ compile-flags: --target x86_64-unknown-linux-gnu -Zllvm-target-feature=+another-feature | ||
| //@ needs-llvm-components: x86 | ||
|
|
||
| //@ revisions:allow_llvm_target_feature_mismatch error_generated | ||
| //@[allow_llvm_target_feature_mismatch] compile-flags: -Cunsafe-allow-abi-mismatch=llvm-target-feature | ||
| // [error_generated] no extra compile-flags | ||
| //@[allow_llvm_target_feature_mismatch] check-pass | ||
| //@ ignore-backends: gcc | ||
|
|
||
| #![feature(no_core)] | ||
| //[error_generated]~^ ERROR mixing `-Zllvm-target-feature` will cause an ABI mismatch in crate `incompatible_llvm_target_feature` | ||
| #![crate_type = "rlib"] | ||
| #![no_core] | ||
|
|
||
| extern crate wrong_llvm_target_feature; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Example should exemplify the multi-feature case (either in the same invocation or in another).