Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7dfa486

Browse files
committed
Add support for high byte registers on x86
1 parent 93e2946 commit 7dfa486

File tree

12 files changed

+198
-123
lines changed

12 files changed

+198
-123
lines changed

src/librustc_codegen_llvm/asm.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass) -> String {
409409
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => "f",
410410
InlineAsmRegClass::X86(X86InlineAsmRegClass::reg) => "r",
411411
InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_abcd) => "Q",
412+
InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_byte) => "r",
412413
InlineAsmRegClass::X86(X86InlineAsmRegClass::xmm_reg)
413414
| InlineAsmRegClass::X86(X86InlineAsmRegClass::ymm_reg) => "x",
414415
InlineAsmRegClass::X86(X86InlineAsmRegClass::zmm_reg) => "v",
@@ -459,6 +460,7 @@ fn modifier_to_llvm(
459460
Some('r') => Some('q'),
460461
_ => unreachable!(),
461462
},
463+
InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_byte) => None,
462464
InlineAsmRegClass::X86(reg @ X86InlineAsmRegClass::xmm_reg)
463465
| InlineAsmRegClass::X86(reg @ X86InlineAsmRegClass::ymm_reg)
464466
| InlineAsmRegClass::X86(reg @ X86InlineAsmRegClass::zmm_reg) => match (reg, modifier) {
@@ -499,6 +501,7 @@ fn dummy_output_type(cx: &CodegenCx<'ll, 'tcx>, reg: InlineAsmRegClass) -> &'ll
499501
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => cx.type_f32(),
500502
InlineAsmRegClass::X86(X86InlineAsmRegClass::reg)
501503
| InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_abcd) => cx.type_i32(),
504+
InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_byte) => cx.type_i8(),
502505
InlineAsmRegClass::X86(X86InlineAsmRegClass::xmm_reg)
503506
| InlineAsmRegClass::X86(X86InlineAsmRegClass::ymm_reg)
504507
| InlineAsmRegClass::X86(X86InlineAsmRegClass::zmm_reg) => cx.type_f32(),

src/librustc_passes/intrinsicck.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@ impl ExprVisitor<'tcx> {
268268
reg_class.name(),
269269
supported_tys.join(", "),
270270
));
271+
if let Some(suggest) = reg_class.suggest_class(asm_arch, asm_ty) {
272+
err.help(&format!(
273+
"consider using the `{}` register class instead",
274+
suggest.name()
275+
));
276+
}
271277
err.emit();
272278
return Some(asm_ty);
273279
}
@@ -298,7 +304,7 @@ impl ExprVisitor<'tcx> {
298304
}
299305

300306
// Check whether a modifier is suggested for using this type.
301-
if let Some((suggested_modifier, suggested_result, switch_reg_class)) =
307+
if let Some((suggested_modifier, suggested_result)) =
302308
reg_class.suggest_modifier(asm_arch, asm_ty)
303309
{
304310
// Search for any use of this operand without a modifier and emit
@@ -323,18 +329,10 @@ impl ExprVisitor<'tcx> {
323329
let msg = "formatting may not be suitable for sub-register argument";
324330
let mut err = lint.build(msg);
325331
err.span_label(expr.span, "for this argument");
326-
if let Some(switch_reg_class) = switch_reg_class {
327-
err.help(&format!(
328-
"use the `{}` modifier with the `{}` register class \
329-
to have the register formatted as `{}`",
330-
suggested_modifier, switch_reg_class, suggested_result,
331-
));
332-
} else {
333-
err.help(&format!(
334-
"use the `{}` modifier to have the register formatted as `{}`",
335-
suggested_modifier, suggested_result,
336-
));
337-
}
332+
err.help(&format!(
333+
"use the `{}` modifier to have the register formatted as `{}`",
334+
suggested_modifier, suggested_result,
335+
));
338336
err.help(&format!(
339337
"or use the `{}` modifier to keep the default formatting of `{}`",
340338
default_modifier, default_result,

src/librustc_target/asm/aarch64.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,26 @@ impl AArch64InlineAsmRegClass {
1818
}
1919
}
2020

21+
pub fn suggest_class(self, _arch: InlineAsmArch, _ty: InlineAsmType) -> Option<Self> {
22+
None
23+
}
24+
2125
pub fn suggest_modifier(
2226
self,
2327
_arch: InlineAsmArch,
2428
ty: InlineAsmType,
25-
) -> Option<(char, &'static str, Option<&'static str>)> {
29+
) -> Option<(char, &'static str)> {
2630
match self {
2731
Self::reg => match ty.size().bits() {
2832
64 => None,
29-
_ => Some(('w', "w0", None)),
33+
_ => Some(('w', "w0")),
3034
},
3135
Self::vreg | Self::vreg_low16 => match ty.size().bits() {
32-
8 => Some(('b', "b0", None)),
33-
16 => Some(('h', "h0", None)),
34-
32 => Some(('s', "s0", None)),
35-
64 => Some(('d', "d0", None)),
36-
128 => Some(('q', "q0", None)),
36+
8 => Some(('b', "b0")),
37+
16 => Some(('h', "h0")),
38+
32 => Some(('s', "s0")),
39+
64 => Some(('d', "d0")),
40+
128 => Some(('q', "q0")),
3741
_ => None,
3842
},
3943
}

src/librustc_target/asm/arm.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ impl ArmInlineAsmRegClass {
2525
}
2626
}
2727

28+
pub fn suggest_class(self, _arch: InlineAsmArch, _ty: InlineAsmType) -> Option<Self> {
29+
None
30+
}
31+
2832
pub fn suggest_modifier(
2933
self,
3034
_arch: InlineAsmArch,
3135
_ty: InlineAsmType,
32-
) -> Option<(char, &'static str, Option<&'static str>)> {
36+
) -> Option<(char, &'static str)> {
3337
None
3438
}
3539

src/librustc_target/asm/mod.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,20 @@ impl InlineAsmRegClass {
291291
}
292292
}
293293

294+
/// Returns a suggested register class to use for this type. This is called
295+
/// after type checking via `supported_types` fails to give a better error
296+
/// message to the user.
297+
pub fn suggest_class(self, arch: InlineAsmArch, ty: InlineAsmType) -> Option<Self> {
298+
match self {
299+
Self::X86(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::X86),
300+
Self::Arm(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Arm),
301+
Self::AArch64(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::AArch64),
302+
Self::RiscV(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::RiscV),
303+
}
304+
}
305+
294306
/// Returns a suggested template modifier to use for this type and an
295-
/// example of a register named formatted with it. Optionally also returns
296-
/// the name of a different register class to use instead.
307+
/// example of a register named formatted with it.
297308
///
298309
/// Such suggestions are useful if a type smaller than the full register
299310
/// size is used and a modifier can be used to point to the subregister of
@@ -302,7 +313,7 @@ impl InlineAsmRegClass {
302313
self,
303314
arch: InlineAsmArch,
304315
ty: InlineAsmType,
305-
) -> Option<(char, &'static str, Option<&'static str>)> {
316+
) -> Option<(char, &'static str)> {
306317
match self {
307318
Self::X86(r) => r.suggest_modifier(arch, ty),
308319
Self::Arm(r) => r.suggest_modifier(arch, ty),

src/librustc_target/asm/riscv.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ impl RiscVInlineAsmRegClass {
1414
&[]
1515
}
1616

17+
pub fn suggest_class(self, _arch: InlineAsmArch, _ty: InlineAsmType) -> Option<Self> {
18+
None
19+
}
20+
1721
pub fn suggest_modifier(
1822
self,
1923
_arch: InlineAsmArch,
2024
_ty: InlineAsmType,
21-
) -> Option<(char, &'static str, Option<&'static str>)> {
25+
) -> Option<(char, &'static str)> {
2226
None
2327
}
2428

0 commit comments

Comments
 (0)