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

Commit baa801a

Browse files
committed
Minor fixes, as requested in PR review
1 parent d77f73e commit baa801a

File tree

4 files changed

+80
-76
lines changed

4 files changed

+80
-76
lines changed

src/librustc_codegen_llvm/asm.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,6 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass) -> String {
414414
InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg16) => "h",
415415
InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg32) => "r",
416416
InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg64) => "l",
417-
InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::freg32) => "f",
418-
InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::freg64) => "d",
419417
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg) => "r",
420418
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => "f",
421419
InlineAsmRegClass::X86(X86InlineAsmRegClass::reg) => "r",
@@ -512,8 +510,6 @@ fn dummy_output_type(cx: &CodegenCx<'ll, 'tcx>, reg: InlineAsmRegClass) -> &'ll
512510
InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg16) => cx.type_i16(),
513511
InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg32) => cx.type_i32(),
514512
InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg64) => cx.type_i64(),
515-
InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::freg32) => cx.type_f32(),
516-
InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::freg64) => cx.type_f64(),
517513
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg) => cx.type_i32(),
518514
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => cx.type_f32(),
519515
InlineAsmRegClass::X86(X86InlineAsmRegClass::reg)

src/librustc_target/asm/mod.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,30 @@ macro_rules! def_reg_class {
5252

5353
#[macro_use]
5454
macro_rules! def_regs {
55+
($arch:ident $arch_reg:ident $arch_regclass:ident {}) => {
56+
#[allow(unreachable_code)]
57+
#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, Eq, PartialEq, Hash, HashStable_Generic)]
58+
pub enum $arch_reg {}
59+
60+
impl $arch_reg {
61+
pub fn parse(
62+
_arch: super::InlineAsmArch,
63+
mut _has_feature: impl FnMut(&str) -> bool,
64+
_name: &str,
65+
) -> Result<Self, &'static str> {
66+
Err("unknown register")
67+
}
68+
}
69+
70+
pub(super) fn fill_reg_map(
71+
_arch: super::InlineAsmArch,
72+
mut _has_feature: impl FnMut(&str) -> bool,
73+
_map: &mut rustc_data_structures::fx::FxHashMap<
74+
super::InlineAsmRegClass,
75+
rustc_data_structures::fx::FxHashSet<super::InlineAsmReg>,
76+
>,
77+
) {}
78+
};
5579
($arch:ident $arch_reg:ident $arch_regclass:ident {
5680
$(
5781
$reg:ident: $class:ident $(, $extra_class:ident)* = [$reg_name:literal $(, $alias:literal)*] $(% $filter:ident)?,
@@ -210,7 +234,6 @@ impl InlineAsmReg {
210234
Self::Arm(r) => r.name(),
211235
Self::AArch64(r) => r.name(),
212236
Self::RiscV(r) => r.name(),
213-
Self::Nvptx(r) => r.name(),
214237
}
215238
}
216239

@@ -220,7 +243,6 @@ impl InlineAsmReg {
220243
Self::Arm(r) => InlineAsmRegClass::Arm(r.reg_class()),
221244
Self::AArch64(r) => InlineAsmRegClass::AArch64(r.reg_class()),
222245
Self::RiscV(r) => InlineAsmRegClass::RiscV(r.reg_class()),
223-
Self::Nvptx(r) => InlineAsmRegClass::Nvptx(r.reg_class()),
224246
}
225247
}
226248

@@ -262,7 +284,6 @@ impl InlineAsmReg {
262284
Self::Arm(r) => r.emit(out, arch, modifier),
263285
Self::AArch64(r) => r.emit(out, arch, modifier),
264286
Self::RiscV(r) => r.emit(out, arch, modifier),
265-
Self::Nvptx(r) => r.emit(out, arch, modifier),
266287
}
267288
}
268289

@@ -272,7 +293,6 @@ impl InlineAsmReg {
272293
Self::Arm(r) => r.overlapping_regs(|r| cb(Self::Arm(r))),
273294
Self::AArch64(_) => cb(self),
274295
Self::RiscV(_) => cb(self),
275-
Self::Nvptx(_) => cb(self),
276296
}
277297
}
278298
}

src/librustc_target/asm/nvptx.rs

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
use super::{InlineAsmArch, InlineAsmType};
22
use rustc_macros::HashStable_Generic;
3-
use std::fmt;
43

54
def_reg_class! {
65
Nvptx NvptxInlineAsmRegClass {
76
reg16,
87
reg32,
98
reg64,
10-
freg32,
11-
freg64,
129
}
1310
}
1411

@@ -39,52 +36,12 @@ impl NvptxInlineAsmRegClass {
3936
) -> &'static [(InlineAsmType, Option<&'static str>)] {
4037
match self {
4138
Self::reg16 => types! { _: I8, I16; },
42-
Self::reg32 => types! { _: I8, I16, I32; },
43-
Self::reg64 => types! { _: I8, I16, I32, I64; },
44-
Self::freg32 => types! { _: F32; },
45-
Self::freg64 => types! { _: F32, F64; },
39+
Self::reg32 => types! { _: I8, I16, I32, F32; },
40+
Self::reg64 => types! { _: I8, I16, I32, F32, I64, F64; },
4641
}
4742
}
4843
}
4944

5045
def_regs! {
51-
Nvptx NvptxInlineAsmReg NvptxInlineAsmRegClass {
52-
// We have to define a register, otherwise we get warnings/errors about unused imports and
53-
// unreachable code. Do what clang does and define r0.
54-
r0: reg32 = ["r0"],
55-
#error = ["tid", "tid.x", "tid.y", "tid.z"] => "tid not supported for inline asm",
56-
#error = ["ntid", "ntid.x", "ntid.y", "ntid.z"] => "ntid not supported for inline asm",
57-
#error = ["laneid"] => "laneid not supported for inline asm",
58-
#error = ["warpid"] => "warpid not supported for inline asm",
59-
#error = ["nwarpid"] => "nwarpid not supported for inline asm",
60-
#error = ["ctaid", "ctaid.x", "ctaid.y", "ctaid.z"] => "ctaid not supported for inline asm",
61-
#error = ["nctaid", "nctaid.x", "nctaid.y", "nctaid.z"] => "nctaid not supported for inline asm",
62-
#error = ["smid"] => "smid not supported for inline asm",
63-
#error = ["nsmid"] => "nsmid not supported for inline asm",
64-
#error = ["gridid"] => "gridid not supported for inline asm",
65-
#error = ["lanemask_eq"] => "lanemask_eq not supported for inline asm",
66-
#error = ["lanemask_le"] => "lanemask_le not supported for inline asm",
67-
#error = ["lanemask_lt"] => "lanemask_lt not supported for inline asm",
68-
#error = ["lanemask_ge"] => "lanemask_ge not supported for inline asm",
69-
#error = ["lanemask_gt"] => "lanemask_gt not supported for inline asm",
70-
#error = ["clock", "clock_hi"] => "clock not supported for inline asm",
71-
#error = ["clock64"] => "clock64 not supported for inline asm",
72-
#error = ["pm0", "pm1", "pm2", "pm3", "pm4", "pm5", "pm6", "pm7"] => "pm not supported for inline asm",
73-
#error = ["pm0_64", "pm1_64", "pm2_64", "pm3_64", "pm4_64", "pm5_64", "pm6_64", "pm7_64"] => "pm_64 not supported for inline asm",
74-
#error = ["envreg0", "envreg1", "envreg2", "envreg3", "envreg4", "envreg5", "envreg6", "envreg7", "envreg8", "envreg9", "envreg10", "envreg11", "envreg12", "envreg13", "envreg14", "envreg15", "envreg16", "envreg17", "envreg18", "envreg19", "envreg20", "envreg21", "envreg22", "envreg23", "envreg24", "envreg25", "envreg26", "envreg27", "envreg28", "envreg29", "envreg30", "envreg31"] => "envreg not supported for inline asm",
75-
#error = ["globaltimer", "globaltimer_lo", "globaltimer_hi"] => "globaltimer not supported for inline asm",
76-
#error = ["total_mem_size"] => "total_mem_size not supported for inline asm",
77-
#error = ["dynamic_mem_size"] => "dynamic_mem_size not supported for inline asm",
78-
}
79-
}
80-
81-
impl NvptxInlineAsmReg {
82-
pub fn emit(
83-
self,
84-
out: &mut dyn fmt::Write,
85-
_arch: InlineAsmArch,
86-
_modifier: Option<char>,
87-
) -> fmt::Result {
88-
out.write_str(self.name())
89-
}
46+
Nvptx NvptxInlineAsmReg NvptxInlineAsmRegClass {}
9047
}

src/test/assembly/asm/nvptx-types.rs

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// no-system-llvm
22
// assembly-output: emit-asm
33
// compile-flags: --target --nvptx64-nvidia-cuda
4+
// compile-flags: -Z merge-functions=disabled
45
// only-nvptx64
56
// ignore-nvptx64
67

@@ -53,57 +54,87 @@ macro_rules! check {
5354
($func:ident $ty:ident, $class:ident $mov:literal) => {
5455
#[no_mangle]
5556
pub unsafe fn $func(x: $ty) -> $ty {
56-
// Hack to avoid function merging
57-
extern "Rust" {
58-
fn dont_merge(s: &str);
59-
}
60-
dont_merge(stringify!($func));
61-
6257
let y;
6358
asm!(concat!($mov, " {}, {};"), out($class) y, in($class) x);
6459
y
6560
}
6661
};
6762
}
6863

69-
// CHECK-LABEL: reg_i8
64+
// CHECK-LABEL: reg16_i8
7065
// CHECK: #APP
7166
// CHECK: mov.i16 {{[a-z0-9]+}}, {{[a-z0-9]+}};
7267
// CHECK: #NO_APP
73-
check!(reg_i8 i8 reg16 "mov.i16");
68+
check!(reg16_i8 i8 reg16 "mov.i16");
7469

75-
// CHECK-LABEL: reg_i16
70+
// CHECK-LABEL: reg16_i16
7671
// CHECK: #APP
7772
// CHECK: mov.i16 {{[a-z0-9]+}}, {{[a-z0-9]+}};
7873
// CHECK: #NO_APP
79-
check!(reg_i16 i16 reg16 "mov.i16");
74+
check!(reg16_i16 i16 reg16 "mov.i16");
75+
76+
// CHECK-LABEL: reg32_i8
77+
// CHECK: #APP
78+
// CHECK: mov.i32 {{[a-z0-9]+}}, {{[a-z0-9]+}};
79+
// CHECK: #NO_APP
80+
check!(reg32_i8 i8 reg32 "mov.i32");
81+
82+
// CHECK-LABEL: reg32_i16
83+
// CHECK: #APP
84+
// CHECK: mov.i32 {{[a-z0-9]+}}, {{[a-z0-9]+}};
85+
// CHECK: #NO_APP
86+
check!(reg32_i16 i16 reg32 "mov.i32");
8087

81-
// CHECK-LABEL: reg_i32
88+
// CHECK-LABEL: reg32_i32
8289
// CHECK: #APP
8390
// CHECK: mov.i32 {{[a-z0-9]+}}, {{[a-z0-9]+}};
8491
// CHECK: #NO_APP
85-
check!(reg_i32 i32 reg32 "mov.i32");
92+
check!(reg32_i32 i32 reg32 "mov.i32");
8693

87-
// CHECK-LABEL: reg_f32
94+
// CHECK-LABEL: reg32_f32
8895
// CHECK: #APP
89-
// CHECK: mov.f32 {{[a-z0-9]+}}, {{[a-z0-9]+}};
96+
// CHECK: mov.i32 {{[a-z0-9]+}}, {{[a-z0-9]+}};
97+
// CHECK: #NO_APP
98+
check!(reg32_f32 f32 reg32 "mov.i32");
99+
100+
// CHECK-LABEL: reg64_i8
101+
// CHECK: #APP
102+
// CHECK: mov.i64 {{[a-z0-9]+}}, {{[a-z0-9]+}};
90103
// CHECK: #NO_APP
91-
check!(reg_f32 f32 freg32 "mov.f32");
104+
check!(reg64_i8 i8 reg64 "mov.i64");
92105

93-
// CHECK-LABEL: reg_i54
106+
// CHECK-LABEL: reg64_i16
94107
// CHECK: #APP
95108
// CHECK: mov.i64 {{[a-z0-9]+}}, {{[a-z0-9]+}};
96109
// CHECK: #NO_APP
97-
check!(reg_i64 i64 reg64 "mov.i64");
110+
check!(reg64_i16 i16 reg64 "mov.i64");
98111

99-
// CHECK-LABEL: reg_f64
112+
// CHECK-LABEL: reg64_i32
100113
// CHECK: #APP
101-
// CHECK: mov.f64 {{[a-z0-9]+}}, {{[a-z0-9]+}};
114+
// CHECK: mov.i64 {{[a-z0-9]+}}, {{[a-z0-9]+}};
115+
// CHECK: #NO_APP
116+
check!(reg64_i32 i32 reg64 "mov.i64");
117+
118+
// CHECK-LABEL: reg64_f32
119+
// CHECK: #APP
120+
// CHECK: mov.i64 {{[a-z0-9]+}}, {{[a-z0-9]+}};
121+
// CHECK: #NO_APP
122+
check!(reg64_f32 f32 reg64 "mov.i64");
123+
124+
// CHECK-LABEL: reg64_i64
125+
// CHECK: #APP
126+
// CHECK: mov.i64 {{[a-z0-9]+}}, {{[a-z0-9]+}};
127+
// CHECK: #NO_APP
128+
check!(reg64_i64 i64 reg64 "mov.i64");
129+
130+
// CHECK-LABEL: reg64_f64
131+
// CHECK: #APP
132+
// CHECK: mov.i64 {{[a-z0-9]+}}, {{[a-z0-9]+}};
102133
// CHECK: #NO_APP
103-
check!(reg_f64 f64 freg64 "mov.f64");
134+
check!(reg64_f64 f64 reg64 "mov.i64");
104135

105-
// CHECK-LABEL: reg_ptr
136+
// CHECK-LABEL: reg64_ptr
106137
// CHECK: #APP
107138
// CHECK: mov.i64 {{[a-z0-9]+}}, {{[a-z0-9]+}};
108139
// CHECK: #NO_APP
109-
check!(reg_ptr ptr reg64 "mov.i64");
140+
check!(reg64_ptr ptr reg64 "mov.i64");

0 commit comments

Comments
 (0)