Skip to content

Commit 3e844ba

Browse files
committed
asm: Stabilize loongarch32
1 parent 3c30dbb commit 3e844ba

File tree

7 files changed

+158
-41
lines changed

7 files changed

+158
-41
lines changed

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
4848
| asm::InlineAsmArch::Arm64EC
4949
| asm::InlineAsmArch::RiscV32
5050
| asm::InlineAsmArch::RiscV64
51+
| asm::InlineAsmArch::LoongArch32
5152
| asm::InlineAsmArch::LoongArch64
5253
| asm::InlineAsmArch::S390x
5354
);

tests/assembly-llvm/asm/loongarch-type.rs

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
//@ add-core-stubs
2+
//@ revisions: loongarch32 loongarch64
3+
24
//@ assembly-output: emit-asm
3-
//@ compile-flags: --target loongarch64-unknown-linux-gnu
5+
6+
//@[loongarch32] compile-flags: --target loongarch32-unknown-none
7+
//@[loongarch32] needs-llvm-components: loongarch
8+
9+
//@[loongarch64] compile-flags: --target loongarch64-unknown-none
10+
//@[loongarch64] needs-llvm-components: loongarch
11+
412
//@ compile-flags: -Zmerge-functions=disabled
5-
//@ needs-llvm-components: loongarch
613

714
#![feature(no_core, f16)]
815
#![crate_type = "rlib"]
@@ -22,7 +29,7 @@ extern "C" {
2229
// CHECK-LABEL: sym_fn:
2330
// CHECK: #APP
2431
// CHECK: pcalau12i $t0, %got_pc_hi20(extern_func)
25-
// CHECK: ld.d $t0, $t0, %got_pc_lo12(extern_func)
32+
// CHECK: ld.{{[wd]}} $t0, $t0, %got_pc_lo12(extern_func)
2633
// CHECK: #NO_APP
2734
#[no_mangle]
2835
pub unsafe fn sym_fn() {
@@ -32,7 +39,7 @@ pub unsafe fn sym_fn() {
3239
// CHECK-LABEL: sym_static:
3340
// CHECK: #APP
3441
// CHECK: pcalau12i $t0, %got_pc_hi20(extern_static)
35-
// CHECK: ld.d $t0, $t0, %got_pc_lo12(extern_static)
42+
// CHECK: ld.{{[wd]}} $t0, $t0, %got_pc_lo12(extern_static)
3643
// CHECK: #NO_APP
3744
#[no_mangle]
3845
pub unsafe fn sym_static() {
@@ -87,16 +94,18 @@ check!(reg_i32, i32, reg, "move");
8794
// CHECK: #NO_APP
8895
check!(reg_f32, f32, reg, "move");
8996

90-
// CHECK-LABEL: reg_i64:
91-
// CHECK: #APP
92-
// CHECK: move ${{[a-z0-9]+}}, ${{[a-z0-9]+}}
93-
// CHECK: #NO_APP
97+
// loongarch64-LABEL: reg_i64:
98+
// loongarch64: #APP
99+
// loongarch64: move ${{[a-z0-9]+}}, ${{[a-z0-9]+}}
100+
// loongarch64: #NO_APP
101+
#[cfg(loongarch64)]
94102
check!(reg_i64, i64, reg, "move");
95103

96-
// CHECK-LABEL: reg_f64:
97-
// CHECK: #APP
98-
// CHECK: move ${{[a-z0-9]+}}, ${{[a-z0-9]+}}
99-
// CHECK: #NO_APP
104+
// loongarch64-LABEL: reg_f64:
105+
// loongarch64: #APP
106+
// loongarch64: move ${{[a-z0-9]+}}, ${{[a-z0-9]+}}
107+
// loongarch64: #NO_APP
108+
#[cfg(loongarch64)]
100109
check!(reg_f64, f64, reg, "move");
101110

102111
// CHECK-LABEL: reg_ptr:
@@ -153,16 +162,18 @@ check_reg!(r4_i32, i32, "$r4", "move");
153162
// CHECK: #NO_APP
154163
check_reg!(r4_f32, f32, "$r4", "move");
155164

156-
// CHECK-LABEL: r4_i64:
157-
// CHECK: #APP
158-
// CHECK: move $a0, $a0
159-
// CHECK: #NO_APP
165+
// loongarch64-LABEL: r4_i64:
166+
// loongarch64: #APP
167+
// loongarch64: move $a0, $a0
168+
// loongarch64: #NO_APP
169+
#[cfg(loongarch64)]
160170
check_reg!(r4_i64, i64, "$r4", "move");
161171

162-
// CHECK-LABEL: r4_f64:
163-
// CHECK: #APP
164-
// CHECK: move $a0, $a0
165-
// CHECK: #NO_APP
172+
// loongarch64-LABEL: r4_f64:
173+
// loongarch64: #APP
174+
// loongarch64: move $a0, $a0
175+
// loongarch64: #NO_APP
176+
#[cfg(loongarch64)]
166177
check_reg!(r4_f64, f64, "$r4", "move");
167178

168179
// CHECK-LABEL: r4_ptr:
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error: invalid register `$r0`: constant zero cannot be used as an operand for inline asm
2+
--> $DIR/bad-reg.rs:27:18
3+
|
4+
LL | asm!("", out("$r0") _);
5+
| ^^^^^^^^^^^^
6+
7+
error: invalid register `$tp`: reserved for TLS
8+
--> $DIR/bad-reg.rs:29:18
9+
|
10+
LL | asm!("", out("$tp") _);
11+
| ^^^^^^^^^^^^
12+
13+
error: invalid register `$sp`: the stack pointer cannot be used as an operand for inline asm
14+
--> $DIR/bad-reg.rs:31:18
15+
|
16+
LL | asm!("", out("$sp") _);
17+
| ^^^^^^^^^^^^
18+
19+
error: invalid register `$r21`: reserved by the ABI
20+
--> $DIR/bad-reg.rs:33:18
21+
|
22+
LL | asm!("", out("$r21") _);
23+
| ^^^^^^^^^^^^^
24+
25+
error: invalid register `$fp`: the frame pointer cannot be used as an operand for inline asm
26+
--> $DIR/bad-reg.rs:35:18
27+
|
28+
LL | asm!("", out("$fp") _);
29+
| ^^^^^^^^^^^^
30+
31+
error: invalid register `$r31`: $r31 is used internally by LLVM and cannot be used as an operand for inline asm
32+
--> $DIR/bad-reg.rs:37:18
33+
|
34+
LL | asm!("", out("$r31") _);
35+
| ^^^^^^^^^^^^^
36+
37+
error: aborting due to 6 previous errors
38+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
error: invalid register `$r0`: constant zero cannot be used as an operand for inline asm
2+
--> $DIR/bad-reg.rs:27:18
3+
|
4+
LL | asm!("", out("$r0") _);
5+
| ^^^^^^^^^^^^
6+
7+
error: invalid register `$tp`: reserved for TLS
8+
--> $DIR/bad-reg.rs:29:18
9+
|
10+
LL | asm!("", out("$tp") _);
11+
| ^^^^^^^^^^^^
12+
13+
error: invalid register `$sp`: the stack pointer cannot be used as an operand for inline asm
14+
--> $DIR/bad-reg.rs:31:18
15+
|
16+
LL | asm!("", out("$sp") _);
17+
| ^^^^^^^^^^^^
18+
19+
error: invalid register `$r21`: reserved by the ABI
20+
--> $DIR/bad-reg.rs:33:18
21+
|
22+
LL | asm!("", out("$r21") _);
23+
| ^^^^^^^^^^^^^
24+
25+
error: invalid register `$fp`: the frame pointer cannot be used as an operand for inline asm
26+
--> $DIR/bad-reg.rs:35:18
27+
|
28+
LL | asm!("", out("$fp") _);
29+
| ^^^^^^^^^^^^
30+
31+
error: invalid register `$r31`: $r31 is used internally by LLVM and cannot be used as an operand for inline asm
32+
--> $DIR/bad-reg.rs:37:18
33+
|
34+
LL | asm!("", out("$r31") _);
35+
| ^^^^^^^^^^^^^
36+
37+
error: register class `freg` requires at least one of the following target features: d, f
38+
--> $DIR/bad-reg.rs:41:26
39+
|
40+
LL | asm!("/* {} */", in(freg) f);
41+
| ^^^^^^^^^^
42+
43+
error: register class `freg` requires at least one of the following target features: d, f
44+
--> $DIR/bad-reg.rs:43:26
45+
|
46+
LL | asm!("/* {} */", out(freg) _);
47+
| ^^^^^^^^^^^
48+
49+
error: register class `freg` requires at least one of the following target features: d, f
50+
--> $DIR/bad-reg.rs:45:26
51+
|
52+
LL | asm!("/* {} */", in(freg) d);
53+
| ^^^^^^^^^^
54+
55+
error: register class `freg` requires at least one of the following target features: d, f
56+
--> $DIR/bad-reg.rs:47:26
57+
|
58+
LL | asm!("/* {} */", out(freg) d);
59+
| ^^^^^^^^^^^
60+
61+
error: aborting due to 10 previous errors
62+

tests/ui/asm/loongarch/bad-reg.loongarch64_lp64d.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
error: invalid register `$r0`: constant zero cannot be used as an operand for inline asm
2-
--> $DIR/bad-reg.rs:22:18
2+
--> $DIR/bad-reg.rs:27:18
33
|
44
LL | asm!("", out("$r0") _);
55
| ^^^^^^^^^^^^
66

77
error: invalid register `$tp`: reserved for TLS
8-
--> $DIR/bad-reg.rs:24:18
8+
--> $DIR/bad-reg.rs:29:18
99
|
1010
LL | asm!("", out("$tp") _);
1111
| ^^^^^^^^^^^^
1212

1313
error: invalid register `$sp`: the stack pointer cannot be used as an operand for inline asm
14-
--> $DIR/bad-reg.rs:26:18
14+
--> $DIR/bad-reg.rs:31:18
1515
|
1616
LL | asm!("", out("$sp") _);
1717
| ^^^^^^^^^^^^
1818

1919
error: invalid register `$r21`: reserved by the ABI
20-
--> $DIR/bad-reg.rs:28:18
20+
--> $DIR/bad-reg.rs:33:18
2121
|
2222
LL | asm!("", out("$r21") _);
2323
| ^^^^^^^^^^^^^
2424

2525
error: invalid register `$fp`: the frame pointer cannot be used as an operand for inline asm
26-
--> $DIR/bad-reg.rs:30:18
26+
--> $DIR/bad-reg.rs:35:18
2727
|
2828
LL | asm!("", out("$fp") _);
2929
| ^^^^^^^^^^^^
3030

3131
error: invalid register `$r31`: $r31 is used internally by LLVM and cannot be used as an operand for inline asm
32-
--> $DIR/bad-reg.rs:32:18
32+
--> $DIR/bad-reg.rs:37:18
3333
|
3434
LL | asm!("", out("$r31") _);
3535
| ^^^^^^^^^^^^^

tests/ui/asm/loongarch/bad-reg.loongarch64_lp64s.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
11
error: invalid register `$r0`: constant zero cannot be used as an operand for inline asm
2-
--> $DIR/bad-reg.rs:22:18
2+
--> $DIR/bad-reg.rs:27:18
33
|
44
LL | asm!("", out("$r0") _);
55
| ^^^^^^^^^^^^
66

77
error: invalid register `$tp`: reserved for TLS
8-
--> $DIR/bad-reg.rs:24:18
8+
--> $DIR/bad-reg.rs:29:18
99
|
1010
LL | asm!("", out("$tp") _);
1111
| ^^^^^^^^^^^^
1212

1313
error: invalid register `$sp`: the stack pointer cannot be used as an operand for inline asm
14-
--> $DIR/bad-reg.rs:26:18
14+
--> $DIR/bad-reg.rs:31:18
1515
|
1616
LL | asm!("", out("$sp") _);
1717
| ^^^^^^^^^^^^
1818

1919
error: invalid register `$r21`: reserved by the ABI
20-
--> $DIR/bad-reg.rs:28:18
20+
--> $DIR/bad-reg.rs:33:18
2121
|
2222
LL | asm!("", out("$r21") _);
2323
| ^^^^^^^^^^^^^
2424

2525
error: invalid register `$fp`: the frame pointer cannot be used as an operand for inline asm
26-
--> $DIR/bad-reg.rs:30:18
26+
--> $DIR/bad-reg.rs:35:18
2727
|
2828
LL | asm!("", out("$fp") _);
2929
| ^^^^^^^^^^^^
3030

3131
error: invalid register `$r31`: $r31 is used internally by LLVM and cannot be used as an operand for inline asm
32-
--> $DIR/bad-reg.rs:32:18
32+
--> $DIR/bad-reg.rs:37:18
3333
|
3434
LL | asm!("", out("$r31") _);
3535
| ^^^^^^^^^^^^^
3636

3737
error: register class `freg` requires at least one of the following target features: d, f
38-
--> $DIR/bad-reg.rs:36:26
38+
--> $DIR/bad-reg.rs:41:26
3939
|
4040
LL | asm!("/* {} */", in(freg) f);
4141
| ^^^^^^^^^^
4242

4343
error: register class `freg` requires at least one of the following target features: d, f
44-
--> $DIR/bad-reg.rs:38:26
44+
--> $DIR/bad-reg.rs:43:26
4545
|
4646
LL | asm!("/* {} */", out(freg) _);
4747
| ^^^^^^^^^^^
4848

4949
error: register class `freg` requires at least one of the following target features: d, f
50-
--> $DIR/bad-reg.rs:40:26
50+
--> $DIR/bad-reg.rs:45:26
5151
|
5252
LL | asm!("/* {} */", in(freg) d);
5353
| ^^^^^^^^^^
5454

5555
error: register class `freg` requires at least one of the following target features: d, f
56-
--> $DIR/bad-reg.rs:42:26
56+
--> $DIR/bad-reg.rs:47:26
5757
|
5858
LL | asm!("/* {} */", out(freg) d);
5959
| ^^^^^^^^^^^

tests/ui/asm/loongarch/bad-reg.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
//@ add-core-stubs
22
//@ needs-asm-support
3-
//@ revisions: loongarch64_lp64d loongarch64_lp64s
3+
//@ revisions: loongarch32_ilp32d loongarch32_ilp32s loongarch64_lp64d loongarch64_lp64s
4+
//@ min-llvm-version: 20
5+
//@[loongarch32_ilp32d] compile-flags: --target loongarch32-unknown-none
6+
//@[loongarch32_ilp32d] needs-llvm-components: loongarch
7+
//@[loongarch32_ilp32s] compile-flags: --target loongarch32-unknown-none-softfloat
8+
//@[loongarch32_ilp32s] needs-llvm-components: loongarch
49
//@[loongarch64_lp64d] compile-flags: --target loongarch64-unknown-linux-gnu
510
//@[loongarch64_lp64d] needs-llvm-components: loongarch
611
//@[loongarch64_lp64s] compile-flags: --target loongarch64-unknown-none-softfloat
@@ -34,12 +39,12 @@ fn f() {
3439

3540
asm!("", out("$f0") _); // ok
3641
asm!("/* {} */", in(freg) f);
37-
//[loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f
42+
//[loongarch32_ilp32s,loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f
3843
asm!("/* {} */", out(freg) _);
39-
//[loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f
44+
//[loongarch32_ilp32s,loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f
4045
asm!("/* {} */", in(freg) d);
41-
//[loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f
46+
//[loongarch32_ilp32s,loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f
4247
asm!("/* {} */", out(freg) d);
43-
//[loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f
48+
//[loongarch32_ilp32s,loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f
4449
}
4550
}

0 commit comments

Comments
 (0)