Skip to content
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

Deprecate llvm_asm! #87590

Merged
merged 3 commits into from
Aug 16, 2021
Merged

Deprecate llvm_asm! #87590

merged 3 commits into from
Aug 16, 2021

Conversation

Amanieu
Copy link
Member

@Amanieu Amanieu commented Jul 29, 2021

We would like to remove llvm_asm! from the compiler once asm! is stabilized. This PR deprecates llvm_asm! to encourage any remaining users to migrate to asm! (or if asm! is not supported for their target, to add this support to rustc).

The only remaining user of llvm_asm! in the standard library was black_box, which has been rewritten to use volatile operations when asm! is not available on the current target.

cc @rust-lang/wg-inline-asm

cc @RalfJung for the changes to black_box which might affect Miri.

r? @nagisa

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 29, 2021
@rust-log-analyzer

This comment has been minimized.

@joshtriplett
Copy link
Member

For simplicity's sake, is there any reason not to just use volatile operations on all platforms, and drop the complex and duplicated cfg condition?

@Amanieu Amanieu force-pushed the deprecate_llvm_asm branch from 55e8423 to 1c95f1c Compare July 29, 2021 16:16
@Amanieu
Copy link
Member Author

Amanieu commented Jul 29, 2021

Using asm! can be slightly faster if the value is already in memory. Also it can be further optimized in the future as suggested here: #64102 (comment)

@rust-log-analyzer

This comment has been minimized.

// 1. passing the value to some external process
// 2. allowing that process to access any memory that the value may point to
// 3. reading a potentially modified value back
#[cfg(any(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern with this implementation is that once support for assembly is added for any of these architectures, it is trivial to miss updating this location.

Any way we can avoid this? We could make up an intrinsic for this, perhaps?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using the fallback for all other architectures, could we have an explicit list of architectures that do use the fallback?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using the fallback for all other architectures, could we have an explicit list of architectures that do use the fallback?

This will likely cause problems when people try to use a new architecture with a custom json target.

Any way we can avoid this? We could make up an intrinsic for this, perhaps?

We could have a target_has_asm cfg flag like we do for atomics. But it seems a bit excessive to have this just for black_box.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having thought about this more, an intrinsic seems significantly more straightforward to me. But I guess I'm okay with this implementation too.

If we continue using cfgs here, consider cfg_if! maybe? It'll reduce the clutter here significantly I feel.

@nagisa
Copy link
Member

nagisa commented Jul 29, 2021

I think the direction is reasonable. See the concern above, once its resolved and the tests are fixed, r=me.

@joshtriplett
Copy link
Member

joshtriplett commented Jul 29, 2021 via email

@Amanieu
Copy link
Member Author

Amanieu commented Jul 30, 2021

The main use of black_box is in micro-benchmarking where you want it to have as little impact as possible on the benchmark. I would argue that performance is pretty important in this case.

There are more optimizations that can be done to black_box, such as passing the value directly in a register instead of just its address to avoid forcing a store to memory. However this is not the main point of this PR which is to deprecate llvm_asm! and remove its uses from the standard library.

@RalfJung
Copy link
Member

cc @RalfJung for the changes to black_box which might affect Miri.

Looks good -- though Miri doesn't optimize, so skipping the function entirely like before would also work. No strong opinion either way.

@joshtriplett
Copy link
Member

joshtriplett commented Jul 30, 2021 via email

@bors
Copy link
Contributor

bors commented Aug 8, 2021

☔ The latest upstream changes (presumably #87772) made this pull request unmergeable. Please resolve the merge conflicts.

@nagisa nagisa added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 8, 2021
@Amanieu Amanieu force-pushed the deprecate_llvm_asm branch 2 times, most recently from 6eae2e0 to 53ab846 Compare August 11, 2021 14:45
@rust-log-analyzer

This comment has been minimized.

JohnTitor added a commit to JohnTitor/rust that referenced this pull request Aug 11, 2021
Implement `black_box` using intrinsic

Introduce `black_box` intrinsic, as suggested in rust-lang#87590 (comment).

This is still codegenned as empty inline assembly for LLVM. For MIR interpretation and cranelift it's treated as identity.

cc `@Amanieu` as this is related to inline assembly
cc `@bjorn3` for rustc_codegen_cranelift changes
cc `@RalfJung` as this affects MIRI

r? `@nagisa` I suppose
@Amanieu Amanieu force-pushed the deprecate_llvm_asm branch from 53ab846 to 4280a5e Compare August 11, 2021 23:26
@Amanieu
Copy link
Member Author

Amanieu commented Aug 11, 2021

Should be good to go, however this will conflict with #87916 due to the need for an allow(deprecated) for black_box.

Manishearth added a commit to Manishearth/rust that referenced this pull request Aug 12, 2021
Implement `black_box` using intrinsic

Introduce `black_box` intrinsic, as suggested in rust-lang#87590 (comment).

This is still codegenned as empty inline assembly for LLVM. For MIR interpretation and cranelift it's treated as identity.

cc `@Amanieu` as this is related to inline assembly
cc `@bjorn3` for rustc_codegen_cranelift changes
cc `@RalfJung` as this affects MIRI

r? `@nagisa` I suppose
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 12, 2021
Implement `black_box` using intrinsic

Introduce `black_box` intrinsic, as suggested in rust-lang#87590 (comment).

This is still codegenned as empty inline assembly for LLVM. For MIR interpretation and cranelift it's treated as identity.

cc `@Amanieu` as this is related to inline assembly
cc `@bjorn3` for rustc_codegen_cranelift changes
cc `@RalfJung` as this affects MIRI

r? `@nagisa` I suppose
@bors
Copy link
Contributor

bors commented Aug 13, 2021

☔ The latest upstream changes (presumably #87916) made this pull request unmergeable. Please resolve the merge conflicts.

@Amanieu Amanieu force-pushed the deprecate_llvm_asm branch from 4280a5e to ee5adcd Compare August 13, 2021 01:15
@@ -7,6 +7,7 @@
// ignore-aarch64

#![feature(llvm_asm)]
#![allow(deprecated)] // llvm_asm!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this test be modified to use asm! instead? This test isn't testing llvm_asm! itself

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfectly fine to leave removal to a follow-up PR (potentially the same one that removes llvm_asm entirely.

@nagisa
Copy link
Member

nagisa commented Aug 14, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Aug 14, 2021

📌 Commit ee5adcdf9199d94aabecea7cdf8515f2877bd45e has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 14, 2021
@bors
Copy link
Contributor

bors commented Aug 15, 2021

☔ The latest upstream changes (presumably #87581) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 15, 2021
@Amanieu Amanieu force-pushed the deprecate_llvm_asm branch from ee5adcd to 632a400 Compare August 15, 2021 12:27
@Amanieu
Copy link
Member Author

Amanieu commented Aug 15, 2021

@bors r=nagisa

@bors
Copy link
Contributor

bors commented Aug 15, 2021

📌 Commit 632a400 has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 15, 2021
@bors
Copy link
Contributor

bors commented Aug 15, 2021

⌛ Testing commit 632a400 with merge 2bd17c1...

@bors
Copy link
Contributor

bors commented Aug 16, 2021

☀️ Test successful - checks-actions
Approved by: nagisa
Pushing 2bd17c1 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 16, 2021
@bors bors merged commit 2bd17c1 into rust-lang:master Aug 16, 2021
@rustbot rustbot added this to the 1.56.0 milestone Aug 16, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 17, 2022
Remove deprecated LLVM-style inline assembly

The `llvm_asm!` was deprecated back in rust-lang#87590 1.56.0, with intention to remove
it once `asm!` was stabilized, which already happened in rust-lang#91728 1.59.0. Now it
is time to remove `llvm_asm!` to avoid continued maintenance cost.

Closes rust-lang#70173.
Closes rust-lang#92794.
Closes rust-lang#87612.
Closes rust-lang#82065.

cc `@rust-lang/wg-inline-asm`

r? `@Amanieu`
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jan 27, 2022
Remove deprecated LLVM-style inline assembly

The `llvm_asm!` was deprecated back in rust-lang#87590 1.56.0, with intention to remove
it once `asm!` was stabilized, which already happened in rust-lang#91728 1.59.0. Now it
is time to remove `llvm_asm!` to avoid continued maintenance cost.

Closes rust-lang#70173.
Closes rust-lang#92794.
Closes rust-lang#87612.
Closes rust-lang#82065.

cc `@rust-lang/wg-inline-asm`

r? `@Amanieu`
bjorn3 pushed a commit to bjorn3/rust that referenced this pull request Feb 23, 2022
Remove deprecated LLVM-style inline assembly

The `llvm_asm!` was deprecated back in rust-lang#87590 1.56.0, with intention to remove
it once `asm!` was stabilized, which already happened in rust-lang#91728 1.59.0. Now it
is time to remove `llvm_asm!` to avoid continued maintenance cost.

Closes rust-lang#70173.
Closes rust-lang#92794.
Closes rust-lang#87612.
Closes rust-lang#82065.

cc `@rust-lang/wg-inline-asm`

r? `@Amanieu`
calebcartwright pushed a commit to calebcartwright/rust that referenced this pull request Mar 30, 2022
Remove deprecated LLVM-style inline assembly

The `llvm_asm!` was deprecated back in rust-lang#87590 1.56.0, with intention to remove
it once `asm!` was stabilized, which already happened in rust-lang#91728 1.59.0. Now it
is time to remove `llvm_asm!` to avoid continued maintenance cost.

Closes rust-lang#70173.
Closes rust-lang#92794.
Closes rust-lang#87612.
Closes rust-lang#82065.

cc `@rust-lang/wg-inline-asm`

r? `@Amanieu`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants