Skip to content

Commit 6c19a10

Browse files
committed
Auto merge of #68404 - Amanieu:llvm-asm, r=estebank
Rename asm! to llvm_asm! As per rust-lang/rfcs#2843, this PR renames `asm!` to `llvm_asm!`. It also renames the compiler's internal `InlineAsm` data structures to `LlvmInlineAsm` in preparation for the new `asm!` functionality specified in rust-lang/rfcs#2850. This PR doesn't actually deprecate `asm!` yet, it just makes it redirect to `llvm_asm!`. This is necessary because we first need to update the submodules (in particular stdarch) to use `llvm_asm!`.
2 parents 7b73d14 + 1cc521e commit 6c19a10

File tree

136 files changed

+634
-588
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+634
-588
lines changed

src/doc/unstable-book/src/library-features/asm.md src/doc/unstable-book/src/library-features/llvm-asm.md

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
# `asm`
1+
# `llvm_asm`
22

3-
The tracking issue for this feature is: [#29722]
3+
The tracking issue for this feature is: [#70173]
44

5-
[#29722]: https://github.com/rust-lang/rust/issues/29722
5+
[#70173]: https://github.com/rust-lang/rust/issues/70173
66

77
------------------------
88

99
For extremely low-level manipulations and performance reasons, one
1010
might wish to control the CPU directly. Rust supports using inline
11-
assembly to do this via the `asm!` macro.
11+
assembly to do this via the `llvm_asm!` macro.
1212

1313
```rust,ignore
14-
asm!(assembly template
14+
llvm_asm!(assembly template
1515
: output operands
1616
: input operands
1717
: clobbers
1818
: options
1919
);
2020
```
2121

22-
Any use of `asm` is feature gated (requires `#![feature(asm)]` on the
22+
Any use of `llvm_asm` is feature gated (requires `#![feature(llvm_asm)]` on the
2323
crate to allow) and of course requires an `unsafe` block.
2424

2525
> **Note**: the examples here are given in x86/x86-64 assembly, but
@@ -31,12 +31,12 @@ The `assembly template` is the only required parameter and must be a
3131
literal string (i.e. `""`)
3232

3333
```rust
34-
#![feature(asm)]
34+
#![feature(llvm_asm)]
3535

3636
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
3737
fn foo() {
3838
unsafe {
39-
asm!("NOP");
39+
llvm_asm!("NOP");
4040
}
4141
}
4242

@@ -51,16 +51,16 @@ fn main() {
5151
}
5252
```
5353

54-
(The `feature(asm)` and `#[cfg]`s are omitted from now on.)
54+
(The `feature(llvm_asm)` and `#[cfg]`s are omitted from now on.)
5555

5656
Output operands, input operands, clobbers and options are all optional
5757
but you must add the right number of `:` if you skip them:
5858

5959
```rust
60-
# #![feature(asm)]
60+
# #![feature(llvm_asm)]
6161
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
6262
# fn main() { unsafe {
63-
asm!("xor %eax, %eax"
63+
llvm_asm!("xor %eax, %eax"
6464
:
6565
:
6666
: "eax"
@@ -73,10 +73,10 @@ asm!("xor %eax, %eax"
7373
Whitespace also doesn't matter:
7474

7575
```rust
76-
# #![feature(asm)]
76+
# #![feature(llvm_asm)]
7777
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
7878
# fn main() { unsafe {
79-
asm!("xor %eax, %eax" ::: "eax");
79+
llvm_asm!("xor %eax, %eax" ::: "eax");
8080
# } }
8181
# #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
8282
# fn main() {}
@@ -89,12 +89,12 @@ Input and output operands follow the same format: `:
8989
expressions must be mutable lvalues, or not yet assigned:
9090

9191
```rust
92-
# #![feature(asm)]
92+
# #![feature(llvm_asm)]
9393
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
9494
fn add(a: i32, b: i32) -> i32 {
9595
let c: i32;
9696
unsafe {
97-
asm!("add $2, $0"
97+
llvm_asm!("add $2, $0"
9898
: "=r"(c)
9999
: "0"(a), "r"(b)
100100
);
@@ -116,11 +116,11 @@ operand. This is useful for very low level programming, where
116116
which register you use is important:
117117

118118
```rust
119-
# #![feature(asm)]
119+
# #![feature(llvm_asm)]
120120
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
121121
# unsafe fn read_byte_in(port: u16) -> u8 {
122122
let result: u8;
123-
asm!("in %dx, %al" : "={al}"(result) : "{dx}"(port));
123+
llvm_asm!("in %dx, %al" : "={al}"(result) : "{dx}"(port));
124124
result
125125
# }
126126
```
@@ -133,11 +133,11 @@ compiler not to assume any values loaded into those registers will
133133
stay valid.
134134

135135
```rust
136-
# #![feature(asm)]
136+
# #![feature(llvm_asm)]
137137
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
138138
# fn main() { unsafe {
139139
// Put the value 0x200 in eax:
140-
asm!("mov $$0x200, %eax" : /* no outputs */ : /* no inputs */ : "eax");
140+
llvm_asm!("mov $$0x200, %eax" : /* no outputs */ : /* no inputs */ : "eax");
141141
# } }
142142
# #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
143143
# fn main() {}
@@ -167,12 +167,12 @@ Current valid options are:
167167
3. *intel* - use intel syntax instead of the default AT&T.
168168

169169
```rust
170-
# #![feature(asm)]
170+
# #![feature(llvm_asm)]
171171
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
172172
# fn main() {
173173
let result: i32;
174174
unsafe {
175-
asm!("mov eax, 2" : "={eax}"(result) : : : "intel")
175+
llvm_asm!("mov eax, 2" : "={eax}"(result) : : : "intel")
176176
}
177177
println!("eax is currently {}", result);
178178
# }
@@ -182,12 +182,12 @@ println!("eax is currently {}", result);
182182

183183
## More Information
184184

185-
The current implementation of the `asm!` macro is a direct binding to [LLVM's
185+
The current implementation of the `llvm_asm!` macro is a direct binding to [LLVM's
186186
inline assembler expressions][llvm-docs], so be sure to check out [their
187187
documentation as well][llvm-docs] for more information about clobbers,
188188
constraints, etc.
189189

190190
[llvm-docs]: http://llvm.org/docs/LangRef.html#inline-assembler-expressions
191191

192192
If you need more power and don't mind losing some of the niceties of
193-
`asm!`, check out [global_asm](global-asm.md).
193+
`llvm_asm!`, check out [global_asm](global-asm.md).

src/libcore/hint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub fn black_box<T>(dummy: T) -> T {
113113
// box. This isn't the greatest implementation since it probably deoptimizes
114114
// more than we want, but it's so far good enough.
115115
unsafe {
116-
asm!("" : : "r"(&dummy));
116+
llvm_asm!("" : : "r"(&dummy));
117117
dummy
118118
}
119119
}

src/libcore/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
#![feature(is_sorted)]
9999
#![feature(lang_items)]
100100
#![feature(link_llvm_intrinsics)]
101+
#![feature(llvm_asm)]
101102
#![cfg_attr(not(bootstrap), feature(negative_impls))]
102103
#![feature(never_type)]
103104
#![feature(nll)]

src/libcore/macros/mod.rs

+42-1
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,7 @@ pub(crate) mod builtin {
13071307
/// [unstable book]: ../unstable-book/library-features/asm.html
13081308
#[unstable(
13091309
feature = "asm",
1310-
issue = "29722",
1310+
issue = "70173",
13111311
reason = "inline assembly is not stable enough for use and is subject to change"
13121312
)]
13131313
#[rustc_builtin_macro]
@@ -1322,6 +1322,47 @@ pub(crate) mod builtin {
13221322
};
13231323
}
13241324

1325+
/// Inline assembly.
1326+
///
1327+
/// Read the [unstable book] for the usage.
1328+
///
1329+
/// [unstable book]: ../unstable-book/library-features/asm.html
1330+
#[cfg(bootstrap)]
1331+
#[unstable(
1332+
feature = "llvm_asm",
1333+
issue = "70173",
1334+
reason = "inline assembly is not stable enough for use and is subject to change"
1335+
)]
1336+
#[macro_export]
1337+
#[allow_internal_unstable(asm)]
1338+
macro_rules! llvm_asm {
1339+
// Redirect to asm! for stage0
1340+
($($arg:tt)*) => { $crate::asm!($($arg)*) }
1341+
}
1342+
1343+
/// Inline assembly.
1344+
///
1345+
/// Read the [unstable book] for the usage.
1346+
///
1347+
/// [unstable book]: ../unstable-book/library-features/asm.html
1348+
#[cfg(not(bootstrap))]
1349+
#[unstable(
1350+
feature = "llvm_asm",
1351+
issue = "70173",
1352+
reason = "inline assembly is not stable enough for use and is subject to change"
1353+
)]
1354+
#[rustc_builtin_macro]
1355+
#[macro_export]
1356+
macro_rules! llvm_asm {
1357+
("assembly template"
1358+
: $("output"(operand),)*
1359+
: $("input"(operand),)*
1360+
: $("clobbers",)*
1361+
: $("options",)*) => {
1362+
/* compiler built-in */
1363+
};
1364+
}
1365+
13251366
/// Module-level inline assembly.
13261367
#[unstable(
13271368
feature = "global_asm",

src/libcore/num/dec2flt/algorithm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ mod fpu_precision {
6060
fn set_cw(cw: u16) {
6161
// SAFETY: the `fldcw` instruction has been audited to be able to work correctly with
6262
// any `u16`
63-
unsafe { asm!("fldcw $0" :: "m" (cw) :: "volatile") }
63+
unsafe { llvm_asm!("fldcw $0" :: "m" (cw) :: "volatile") }
6464
}
6565

6666
/// Sets the precision field of the FPU to `T` and returns a `FPUControlWord`.
@@ -78,7 +78,7 @@ mod fpu_precision {
7878
// `FPUControlWord` structure is dropped
7979
// SAFETY: the `fnstcw` instruction has been audited to be able to work correctly with
8080
// any `u16`
81-
unsafe { asm!("fnstcw $0" : "=*m" (&cw) ::: "volatile") }
81+
unsafe { llvm_asm!("fnstcw $0" : "=*m" (&cw) ::: "volatile") }
8282

8383
// Set the control word to the desired precision. This is achieved by masking away the old
8484
// precision (bits 8 and 9, 0x300) and replacing it with the precision flag computed above.

src/libcore/prelude/v1.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ pub use crate::hash::macros::Hash;
5757
#[doc(no_inline)]
5858
pub use crate::{
5959
asm, assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args,
60-
format_args_nl, global_asm, include, include_bytes, include_str, line, log_syntax, module_path,
61-
option_env, stringify, trace_macros,
60+
format_args_nl, global_asm, include, include_bytes, include_str, line, llvm_asm, log_syntax,
61+
module_path, option_env, stringify, trace_macros,
6262
};
6363

6464
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]

src/librustc/mir/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,7 @@ pub enum StatementKind<'tcx> {
15841584

15851585
/// Executes a piece of inline Assembly. Stored in a Box to keep the size
15861586
/// of `StatementKind` low.
1587-
InlineAsm(Box<InlineAsm<'tcx>>),
1587+
LlvmInlineAsm(Box<LlvmInlineAsm<'tcx>>),
15881588

15891589
/// Retag references in the given place, ensuring they got fresh tags. This is
15901590
/// part of the Stacked Borrows model. These statements are currently only interpreted
@@ -1668,8 +1668,8 @@ pub enum FakeReadCause {
16681668
}
16691669

16701670
#[derive(Clone, Debug, PartialEq, RustcEncodable, RustcDecodable, HashStable, TypeFoldable)]
1671-
pub struct InlineAsm<'tcx> {
1672-
pub asm: hir::InlineAsmInner,
1671+
pub struct LlvmInlineAsm<'tcx> {
1672+
pub asm: hir::LlvmInlineAsmInner,
16731673
pub outputs: Box<[Place<'tcx>]>,
16741674
pub inputs: Box<[(Span, Operand<'tcx>)]>,
16751675
}
@@ -1696,8 +1696,8 @@ impl Debug for Statement<'_> {
16961696
SetDiscriminant { ref place, variant_index } => {
16971697
write!(fmt, "discriminant({:?}) = {:?}", place, variant_index)
16981698
}
1699-
InlineAsm(ref asm) => {
1700-
write!(fmt, "asm!({:?} : {:?} : {:?})", asm.asm, asm.outputs, asm.inputs)
1699+
LlvmInlineAsm(ref asm) => {
1700+
write!(fmt, "llvm_asm!({:?} : {:?} : {:?})", asm.asm, asm.outputs, asm.inputs)
17011701
}
17021702
AscribeUserType(box (ref place, ref c_ty), ref variance) => {
17031703
write!(fmt, "AscribeUserType({:?}, {:?}, {:?})", place, variance, c_ty)

src/librustc/mir/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ macro_rules! make_mir_visitor {
385385
location
386386
);
387387
}
388-
StatementKind::InlineAsm(asm) => {
388+
StatementKind::LlvmInlineAsm(asm) => {
389389
for output in & $($mutability)? asm.outputs[..] {
390390
self.visit_place(
391391
output,

src/librustc/ty/structural_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ CloneTypeFoldableAndLiftImpls! {
263263
::rustc_span::symbol::Symbol,
264264
::rustc_hir::def::Res,
265265
::rustc_hir::def_id::DefId,
266-
::rustc_hir::InlineAsmInner,
266+
::rustc_hir::LlvmInlineAsmInner,
267267
::rustc_hir::MatchSource,
268268
::rustc_hir::Mutability,
269269
::rustc_hir::Unsafety,

src/librustc_ast/ast.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ impl Expr {
11141114
ExprKind::Break(..) => ExprPrecedence::Break,
11151115
ExprKind::Continue(..) => ExprPrecedence::Continue,
11161116
ExprKind::Ret(..) => ExprPrecedence::Ret,
1117-
ExprKind::InlineAsm(..) => ExprPrecedence::InlineAsm,
1117+
ExprKind::LlvmInlineAsm(..) => ExprPrecedence::InlineAsm,
11181118
ExprKind::MacCall(..) => ExprPrecedence::Mac,
11191119
ExprKind::Struct(..) => ExprPrecedence::Struct,
11201120
ExprKind::Repeat(..) => ExprPrecedence::Repeat,
@@ -1243,8 +1243,8 @@ pub enum ExprKind {
12431243
/// A `return`, with an optional value to be returned.
12441244
Ret(Option<P<Expr>>),
12451245

1246-
/// Output of the `asm!()` macro.
1247-
InlineAsm(P<InlineAsm>),
1246+
/// Output of the `llvm_asm!()` macro.
1247+
LlvmInlineAsm(P<LlvmInlineAsm>),
12481248

12491249
/// A macro invocation; pre-expansion.
12501250
MacCall(MacCall),
@@ -1860,37 +1860,37 @@ pub enum TraitObjectSyntax {
18601860

18611861
/// Inline assembly dialect.
18621862
///
1863-
/// E.g., `"intel"` as in `asm!("mov eax, 2" : "={eax}"(result) : : : "intel")`.
1863+
/// E.g., `"intel"` as in `llvm_asm!("mov eax, 2" : "={eax}"(result) : : : "intel")`.
18641864
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, HashStable_Generic)]
1865-
pub enum AsmDialect {
1865+
pub enum LlvmAsmDialect {
18661866
Att,
18671867
Intel,
18681868
}
18691869

1870-
/// Inline assembly.
1870+
/// LLVM-style inline assembly.
18711871
///
1872-
/// E.g., `"={eax}"(result)` as in `asm!("mov eax, 2" : "={eax}"(result) : : : "intel")`.
1872+
/// E.g., `"={eax}"(result)` as in `llvm_asm!("mov eax, 2" : "={eax}"(result) : : : "intel")`.
18731873
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
1874-
pub struct InlineAsmOutput {
1874+
pub struct LlvmInlineAsmOutput {
18751875
pub constraint: Symbol,
18761876
pub expr: P<Expr>,
18771877
pub is_rw: bool,
18781878
pub is_indirect: bool,
18791879
}
18801880

1881-
/// Inline assembly.
1881+
/// LLVM-style inline assembly.
18821882
///
1883-
/// E.g., `asm!("NOP");`.
1883+
/// E.g., `llvm_asm!("NOP");`.
18841884
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
1885-
pub struct InlineAsm {
1885+
pub struct LlvmInlineAsm {
18861886
pub asm: Symbol,
18871887
pub asm_str_style: StrStyle,
1888-
pub outputs: Vec<InlineAsmOutput>,
1888+
pub outputs: Vec<LlvmInlineAsmOutput>,
18891889
pub inputs: Vec<(Symbol, P<Expr>)>,
18901890
pub clobbers: Vec<Symbol>,
18911891
pub volatile: bool,
18921892
pub alignstack: bool,
1893-
pub dialect: AsmDialect,
1893+
pub dialect: LlvmAsmDialect,
18941894
}
18951895

18961896
/// A parameter in a function header.

src/librustc_ast/mut_visit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1202,8 +1202,8 @@ pub fn noop_visit_expr<T: MutVisitor>(Expr { kind, id, span, attrs }: &mut Expr,
12021202
ExprKind::Ret(expr) => {
12031203
visit_opt(expr, |expr| vis.visit_expr(expr));
12041204
}
1205-
ExprKind::InlineAsm(asm) => {
1206-
let InlineAsm {
1205+
ExprKind::LlvmInlineAsm(asm) => {
1206+
let LlvmInlineAsm {
12071207
asm: _,
12081208
asm_str_style: _,
12091209
outputs,
@@ -1214,7 +1214,7 @@ pub fn noop_visit_expr<T: MutVisitor>(Expr { kind, id, span, attrs }: &mut Expr,
12141214
dialect: _,
12151215
} = asm.deref_mut();
12161216
for out in outputs {
1217-
let InlineAsmOutput { constraint: _, expr, is_rw: _, is_indirect: _ } = out;
1217+
let LlvmInlineAsmOutput { constraint: _, expr, is_rw: _, is_indirect: _ } = out;
12181218
vis.visit_expr(expr);
12191219
}
12201220
visit_vec(inputs, |(_c, expr)| vis.visit_expr(expr));

0 commit comments

Comments
 (0)