Skip to content

Commit 5f5afba

Browse files
committed
Feat: added s390x reg-definitions, constraint codes, and tests
1 parent f28793d commit 5f5afba

File tree

4 files changed

+118
-32
lines changed

4 files changed

+118
-32
lines changed

compiler/rustc_codegen_llvm/src/asm.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
314314
InlineAsmArch::PowerPC | InlineAsmArch::PowerPC64 => {}
315315
InlineAsmArch::Hexagon => {}
316316
InlineAsmArch::Mips | InlineAsmArch::Mips64 => {}
317-
InlineAsmArch::s390 => {}
317+
InlineAsmArch::S390x => {}
318318
InlineAsmArch::SpirV => {}
319319
InlineAsmArch::Wasm32 => {}
320320
InlineAsmArch::Bpf => {}
@@ -634,8 +634,8 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'tcx>>)
634634
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r",
635635
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r",
636636
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w",
637-
InlineAsmRegClass::s390x(s390xInlineAsmRegClass::reg) => "r",
638-
InlineAsmRegClass::s390x(s390xInlineAsmRegClass::freg) => "f",
637+
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => "r",
638+
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => "f",
639639
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
640640
bug!("LLVM backend does not support SPIR-V")
641641
}
@@ -714,7 +714,7 @@ fn modifier_to_llvm(
714714
}
715715
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => None,
716716
InlineAsmRegClass::Bpf(_) => None,
717-
InlineAsmRegClass::s390x(_) => None,
717+
InlineAsmRegClass::S390x(_) => None,
718718
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
719719
bug!("LLVM backend does not support SPIR-V")
720720
}
@@ -773,8 +773,8 @@ fn dummy_output_type(cx: &CodegenCx<'ll, 'tcx>, reg: InlineAsmRegClass) -> &'ll
773773
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(),
774774
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(),
775775
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => cx.type_i32(),
776-
InlineAsmRegClass::s390x(s390xInlineAsmRegClass::reg) => cx.type_i32(),
777-
InlineAsmRegClass::s390x(s390xInlineAsmRegClass::freg) => cx.type_f64(),
776+
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => cx.type_i32(),
777+
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => cx.type_f64(),
778778
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
779779
bug!("LLVM backend does not support SPIR-V")
780780
}

compiler/rustc_target/src/asm/mod.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub use mips::{MipsInlineAsmReg, MipsInlineAsmRegClass};
167167
pub use nvptx::{NvptxInlineAsmReg, NvptxInlineAsmRegClass};
168168
pub use powerpc::{PowerPCInlineAsmReg, PowerPCInlineAsmRegClass};
169169
pub use riscv::{RiscVInlineAsmReg, RiscVInlineAsmRegClass};
170-
pub use s390x::{s390xInlineAsmReg, s390xInlineAsmRegClass};
170+
pub use s390x::{S390xInlineAsmReg, S390xInlineAsmRegClass};
171171
pub use spirv::{SpirVInlineAsmReg, SpirVInlineAsmRegClass};
172172
pub use wasm::{WasmInlineAsmReg, WasmInlineAsmRegClass};
173173
pub use x86::{X86InlineAsmReg, X86InlineAsmRegClass};
@@ -186,7 +186,7 @@ pub enum InlineAsmArch {
186186
Mips64,
187187
PowerPC,
188188
PowerPC64,
189-
s390x,
189+
S390x,
190190
SpirV,
191191
Wasm32,
192192
Bpf,
@@ -209,7 +209,7 @@ impl FromStr for InlineAsmArch {
209209
"hexagon" => Ok(Self::Hexagon),
210210
"mips" => Ok(Self::Mips),
211211
"mips64" => Ok(Self::Mips64),
212-
"s390x" => Ok(Self::s390x),
212+
"s390x" => Ok(Self::S390x),
213213
"spirv" => Ok(Self::SpirV),
214214
"wasm32" => Ok(Self::Wasm32),
215215
"bpf" => Ok(Self::Bpf),
@@ -239,7 +239,7 @@ pub enum InlineAsmReg {
239239
PowerPC(PowerPCInlineAsmReg),
240240
Hexagon(HexagonInlineAsmReg),
241241
Mips(MipsInlineAsmReg),
242-
s390x(InlineAsmReg),
242+
S390x(S390xInlineAsmReg),
243243
SpirV(SpirVInlineAsmReg),
244244
Wasm(WasmInlineAsmReg),
245245
Bpf(BpfInlineAsmReg),
@@ -257,7 +257,7 @@ impl InlineAsmReg {
257257
Self::PowerPC(r) => r.name(),
258258
Self::Hexagon(r) => r.name(),
259259
Self::Mips(r) => r.name(),
260-
Self::s390x(r) => r.name(),
260+
Self::S390x(r) => r.name(),
261261
Self::Bpf(r) => r.name(),
262262
Self::Err => "<reg>",
263263
}
@@ -272,7 +272,7 @@ impl InlineAsmReg {
272272
Self::PowerPC(r) => InlineAsmRegClass::PowerPC(r.reg_class()),
273273
Self::Hexagon(r) => InlineAsmRegClass::Hexagon(r.reg_class()),
274274
Self::Mips(r) => InlineAsmRegClass::Mips(r.reg_class()),
275-
Self::s390x(r) => InlineAsmRegClass::s390x(r.reg_class()),
275+
Self::S390x(r) => InlineAsmRegClass::S390x(r.reg_class()),
276276
Self::Bpf(r) => InlineAsmRegClass::Bpf(r.reg_class()),
277277
Self::Err => InlineAsmRegClass::Err,
278278
}
@@ -312,8 +312,8 @@ impl InlineAsmReg {
312312
InlineAsmArch::Mips | InlineAsmArch::Mips64 => {
313313
Self::Mips(MipsInlineAsmReg::parse(arch, has_feature, target, &name)?)
314314
}
315-
InlineAsmArch::s390x => {
316-
Self::s390x(s390xInlineAsmReg::parse(arch, has_feature, target, &name)?)
315+
InlineAsmArch::S390x => {
316+
Self::S390x(S390xInlineAsmReg::parse(arch, has_feature, target, &name)?)
317317
}
318318
InlineAsmArch::SpirV => {
319319
Self::SpirV(SpirVInlineAsmReg::parse(arch, has_feature, target, &name)?)
@@ -343,7 +343,7 @@ impl InlineAsmReg {
343343
Self::PowerPC(r) => r.emit(out, arch, modifier),
344344
Self::Hexagon(r) => r.emit(out, arch, modifier),
345345
Self::Mips(r) => r.emit(out, arch, modifier),
346-
Self::s390x(r) => r.emit(out, arch, modifier),
346+
Self::S390x(r) => r.emit(out, arch, modifier),
347347
Self::Bpf(r) => r.emit(out, arch, modifier),
348348
Self::Err => unreachable!("Use of InlineAsmReg::Err"),
349349
}
@@ -358,7 +358,7 @@ impl InlineAsmReg {
358358
Self::PowerPC(_) => cb(self),
359359
Self::Hexagon(r) => r.overlapping_regs(|r| cb(Self::Hexagon(r))),
360360
Self::Mips(_) => cb(self),
361-
Self::s390x(_) => cb(self),
361+
Self::S390x(_) => cb(self),
362362
Self::Bpf(r) => r.overlapping_regs(|r| cb(Self::Bpf(r))),
363363
Self::Err => unreachable!("Use of InlineAsmReg::Err"),
364364
}
@@ -386,7 +386,7 @@ pub enum InlineAsmRegClass {
386386
PowerPC(PowerPCInlineAsmRegClass),
387387
Hexagon(HexagonInlineAsmRegClass),
388388
Mips(MipsInlineAsmRegClass),
389-
s390x(s390xInlineAsmRegClass),
389+
S390x(S390xInlineAsmRegClass),
390390
SpirV(SpirVInlineAsmRegClass),
391391
Wasm(WasmInlineAsmRegClass),
392392
Bpf(BpfInlineAsmRegClass),
@@ -405,7 +405,7 @@ impl InlineAsmRegClass {
405405
Self::PowerPC(r) => r.name(),
406406
Self::Hexagon(r) => r.name(),
407407
Self::Mips(r) => r.name(),
408-
Self::s390x(r) => r.name(),
408+
Self::S390x(r) => r.name(),
409409
Self::SpirV(r) => r.name(),
410410
Self::Wasm(r) => r.name(),
411411
Self::Bpf(r) => r.name(),
@@ -426,7 +426,7 @@ impl InlineAsmRegClass {
426426
Self::PowerPC(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::PowerPC),
427427
Self::Hexagon(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Hexagon),
428428
Self::Mips(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Mips),
429-
Self::s390x(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::s390x),
429+
Self::S390x(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::S390x),
430430
Self::SpirV(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::SpirV),
431431
Self::Wasm(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Wasm),
432432
Self::Bpf(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Bpf),
@@ -454,7 +454,7 @@ impl InlineAsmRegClass {
454454
Self::PowerPC(r) => r.suggest_modifier(arch, ty),
455455
Self::Hexagon(r) => r.suggest_modifier(arch, ty),
456456
Self::Mips(r) => r.suggest_modifier(arch, ty),
457-
Self::s390x(r) => r.suggest_modifier(arch, ty),
457+
Self::S390x(r) => r.suggest_modifier(arch, ty),
458458
Self::SpirV(r) => r.suggest_modifier(arch, ty),
459459
Self::Wasm(r) => r.suggest_modifier(arch, ty),
460460
Self::Bpf(r) => r.suggest_modifier(arch, ty),
@@ -478,7 +478,7 @@ impl InlineAsmRegClass {
478478
Self::PowerPC(r) => r.default_modifier(arch),
479479
Self::Hexagon(r) => r.default_modifier(arch),
480480
Self::Mips(r) => r.default_modifier(arch),
481-
Self::s390x(r) => r.default_modifier(arch),
481+
Self::S390x(r) => r.default_modifier(arch),
482482
Self::SpirV(r) => r.default_modifier(arch),
483483
Self::Wasm(r) => r.default_modifier(arch),
484484
Self::Bpf(r) => r.default_modifier(arch),
@@ -501,7 +501,7 @@ impl InlineAsmRegClass {
501501
Self::PowerPC(r) => r.supported_types(arch),
502502
Self::Hexagon(r) => r.supported_types(arch),
503503
Self::Mips(r) => r.supported_types(arch),
504-
Self::s390x(r) => r.supported_types(arch),
504+
Self::S390x(r) => r.supported_types(arch),
505505
Self::SpirV(r) => r.supported_types(arch),
506506
Self::Wasm(r) => r.supported_types(arch),
507507
Self::Bpf(r) => r.supported_types(arch),
@@ -527,7 +527,7 @@ impl InlineAsmRegClass {
527527
InlineAsmArch::Mips | InlineAsmArch::Mips64 => {
528528
Self::Mips(MipsInlineAsmRegClass::parse(arch, name)?)
529529
}
530-
InlineAsmArch::s390x => Self::s390x(s390xInlineAsmRegClass::parse(arch, name)?),
530+
InlineAsmArch::S390x => Self::S390x(S390xInlineAsmRegClass::parse(arch, name)?),
531531
InlineAsmArch::SpirV => Self::SpirV(SpirVInlineAsmRegClass::parse(arch, name)?),
532532
InlineAsmArch::Wasm32 => Self::Wasm(WasmInlineAsmRegClass::parse(arch, name)?),
533533
InlineAsmArch::Bpf => Self::Bpf(BpfInlineAsmRegClass::parse(arch, name)?),
@@ -546,7 +546,7 @@ impl InlineAsmRegClass {
546546
Self::PowerPC(r) => r.valid_modifiers(arch),
547547
Self::Hexagon(r) => r.valid_modifiers(arch),
548548
Self::Mips(r) => r.valid_modifiers(arch),
549-
Self::s390x(r) => r.valid_modifiers(arch),
549+
Self::S390x(r) => r.valid_modifiers(arch),
550550
Self::SpirV(r) => r.valid_modifiers(arch),
551551
Self::Wasm(r) => r.valid_modifiers(arch),
552552
Self::Bpf(r) => r.valid_modifiers(arch),
@@ -715,11 +715,11 @@ pub fn allocatable_registers(
715715
mips::fill_reg_map(arch, has_feature, target, &mut map);
716716
map
717717
}
718-
InlineAsmArch::s390x => {
719-
let mut map = s390x::regclass_map();
718+
InlineAsmArch::S390x => {
719+
let mut map = s390x::regclass_map();
720720
s390x::fill_reg_map(arch, has_feature, target, &mut map);
721721
map
722-
}
722+
}
723723
InlineAsmArch::SpirV => {
724724
let mut map = spirv::regclass_map();
725725
spirv::fill_reg_map(arch, has_feature, target, &mut map);

compiler/rustc_target/src/asm/s390x.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ use rustc_macros::HashStable_Generic;
33
use std::fmt;
44

55
def_reg_class! {
6-
s390x s390xInlineAsmRegClass {
6+
S390x S390xInlineAsmRegClass {
77
reg,
88
freg,
99
}
1010
}
1111

12-
impl s390xInlineAsmRegClass {
12+
impl S390xInlineAsmRegClass {
1313
pub fn valid_modifiers(self, _arch: super::InlineAsmArch) -> &'static [char] {
1414
&[]
1515
}
@@ -42,8 +42,8 @@ impl s390xInlineAsmRegClass {
4242
}
4343

4444
def_regs! {
45-
s390x s390xInlineAsmReg s390xInlineAsmRegClass {
46-
r0: req = ["r0"],
45+
S390x S390xInlineAsmReg S390xInlineAsmRegClass {
46+
r0: reg = ["r0"],
4747
r1: reg = ["r1"],
4848
r2: reg = ["r2"],
4949
r3: reg = ["r3"],
@@ -144,7 +144,7 @@ def_regs! {
144144
}
145145
}
146146

147-
impl s390xInlineAsmReg {
147+
impl S390xInlineAsmReg {
148148
pub fn emit(
149149
self,
150150
out: &mut dyn fmt::Write,

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

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// min-llvm-version: 10.0.1
2+
// revisions: s390x
3+
// assembly-output: emit-asm
4+
//[s390x] compile-flags: --target s390x-unknown-linux-gnu
5+
//[s390x] needs-llvm-components: systemz
6+
7+
#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
8+
#![crate_type = "rlib"]
9+
#![no_core]
10+
#![allow(asm_sub_register, non_camel_case_types)]
11+
12+
#[rustc_builtin_macro]
13+
macro_rules! asm {
14+
() => {};
15+
}
16+
#[rustc_builtin_macro]
17+
macro_rules! concat {
18+
() => {};
19+
}
20+
#[rustc_builtin_macro]
21+
macro_rules! stringify {
22+
() => {};
23+
}
24+
25+
#[lang = "sized"]
26+
trait Sized {}
27+
#[lang = "copy"]
28+
trait Copy {}
29+
30+
type ptr = *const i32;
31+
32+
impl Copy for i8 {}
33+
impl Copy for u8 {}
34+
impl Copy for i16 {}
35+
impl Copy for i32 {}
36+
impl Copy for i64 {}
37+
impl Copy for f32 {}
38+
impl Copy for f64 {}
39+
impl Copy for ptr {}
40+
41+
extern "C" {
42+
fn extern_func();
43+
static extern_static: u8;
44+
}
45+
46+
// Hack to avoid function merging
47+
extern "Rust" {
48+
fn dont_merge(s: &str);
49+
}
50+
51+
macro_rules! check { ($func:ident, $ty:ty, $class:ident, $mov:literal) => {
52+
53+
pub unsafe fn $func(x: $ty) -> $ty {
54+
dont_merge(stringify!(func));
55+
56+
let y;
57+
asm!(concat!($mov," {}, {}"), out($class) y, in($class) x);
58+
y
59+
}
60+
};}
61+
62+
macro_rules! check_reg { ($func:ident, $ty:ty, $reg:tt, $mov:literal) => {
63+
64+
pub unsafe fn $func(x: $ty) -> $ty {
65+
dont_merge(stringify!(func));
66+
67+
let y;
68+
asm!(concat!($mov, " ", $reg, ", ", $reg), lateout($reg) y, in($reg) x);
69+
y
70+
}
71+
};}
72+
73+
// systemz-LABEL: sym_fn_32:
74+
// systemz: #APP
75+
// systemz: brasl %r14, extern_func@PLT
76+
// systemz: #NO_APP
77+
#[cfg(s390x)]
78+
pub unsafe fn sym_fn_32() {
79+
asm!("brasl %r14, {}", sym extern_func);
80+
}
81+
82+
// CHECK-LABEL: reg_i32:
83+
// CHECK: #APP
84+
// CHECK: lgr r{{[0-15]+}}, r{{[0-15]+}}
85+
// CHECK: #NO_APP
86+
check!(reg_i32, i32, reg, "lgr");

0 commit comments

Comments
 (0)