asm: Stabilize loongarch32

This commit is contained in:
WANG Rui
2025-01-09 20:35:49 +08:00
parent 3c30dbbe31
commit a383fb0c73
8 changed files with 158 additions and 46 deletions

View File

@@ -48,6 +48,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
| asm::InlineAsmArch::Arm64EC
| asm::InlineAsmArch::RiscV32
| asm::InlineAsmArch::RiscV64
| asm::InlineAsmArch::LoongArch32
| asm::InlineAsmArch::LoongArch64
| asm::InlineAsmArch::S390x
);

View File

@@ -19,7 +19,6 @@ This feature tracks `asm!` and `global_asm!` support for the following architect
- M68k
- CSKY
- SPARC
- LoongArch32
## Register classes
@@ -54,8 +53,6 @@ This feature tracks `asm!` and `global_asm!` support for the following architect
| CSKY | `freg` | `f[0-31]` | `f` |
| SPARC | `reg` | `r[2-29]` | `r` |
| SPARC | `yreg` | `y` | Only clobbers |
| LoongArch32 | `reg` | `$r1`, `$r[4-20]`, `$r[23,30]` | `r` |
| LoongArch32 | `freg` | `$f[0-31]` | `f` |
> **Notes**:
> - NVPTX doesn't have a fixed register set, so named registers are not supported.
@@ -94,8 +91,6 @@ This feature tracks `asm!` and `global_asm!` support for the following architect
| CSKY | `freg` | None | `f32`, |
| SPARC | `reg` | None | `i8`, `i16`, `i32`, `i64` (SPARC64 only) |
| SPARC | `yreg` | N/A | Only clobbers |
| LoongArch32 | `reg` | None | `i8`, `i16`, `i32`, `f32` |
| LoongArch32 | `freg` | None | `f32`, `f64` |
## Register aliases

View File

@@ -1,8 +1,15 @@
//@ add-core-stubs
//@ revisions: loongarch32 loongarch64
//@ assembly-output: emit-asm
//@ compile-flags: --target loongarch64-unknown-linux-gnu
//@[loongarch32] compile-flags: --target loongarch32-unknown-none
//@[loongarch32] needs-llvm-components: loongarch
//@[loongarch64] compile-flags: --target loongarch64-unknown-none
//@[loongarch64] needs-llvm-components: loongarch
//@ compile-flags: -Zmerge-functions=disabled
//@ needs-llvm-components: loongarch
#![feature(no_core, f16)]
#![crate_type = "rlib"]
@@ -22,7 +29,7 @@ extern "C" {
// CHECK-LABEL: sym_fn:
// CHECK: #APP
// CHECK: pcalau12i $t0, %got_pc_hi20(extern_func)
// CHECK: ld.d $t0, $t0, %got_pc_lo12(extern_func)
// CHECK: ld.{{[wd]}} $t0, $t0, %got_pc_lo12(extern_func)
// CHECK: #NO_APP
#[no_mangle]
pub unsafe fn sym_fn() {
@@ -32,7 +39,7 @@ pub unsafe fn sym_fn() {
// CHECK-LABEL: sym_static:
// CHECK: #APP
// CHECK: pcalau12i $t0, %got_pc_hi20(extern_static)
// CHECK: ld.d $t0, $t0, %got_pc_lo12(extern_static)
// CHECK: ld.{{[wd]}} $t0, $t0, %got_pc_lo12(extern_static)
// CHECK: #NO_APP
#[no_mangle]
pub unsafe fn sym_static() {
@@ -87,16 +94,18 @@ check!(reg_i32, i32, reg, "move");
// CHECK: #NO_APP
check!(reg_f32, f32, reg, "move");
// CHECK-LABEL: reg_i64:
// CHECK: #APP
// CHECK: move ${{[a-z0-9]+}}, ${{[a-z0-9]+}}
// CHECK: #NO_APP
// loongarch64-LABEL: reg_i64:
// loongarch64: #APP
// loongarch64: move ${{[a-z0-9]+}}, ${{[a-z0-9]+}}
// loongarch64: #NO_APP
#[cfg(loongarch64)]
check!(reg_i64, i64, reg, "move");
// CHECK-LABEL: reg_f64:
// CHECK: #APP
// CHECK: move ${{[a-z0-9]+}}, ${{[a-z0-9]+}}
// CHECK: #NO_APP
// loongarch64-LABEL: reg_f64:
// loongarch64: #APP
// loongarch64: move ${{[a-z0-9]+}}, ${{[a-z0-9]+}}
// loongarch64: #NO_APP
#[cfg(loongarch64)]
check!(reg_f64, f64, reg, "move");
// CHECK-LABEL: reg_ptr:
@@ -153,16 +162,18 @@ check_reg!(r4_i32, i32, "$r4", "move");
// CHECK: #NO_APP
check_reg!(r4_f32, f32, "$r4", "move");
// CHECK-LABEL: r4_i64:
// CHECK: #APP
// CHECK: move $a0, $a0
// CHECK: #NO_APP
// loongarch64-LABEL: r4_i64:
// loongarch64: #APP
// loongarch64: move $a0, $a0
// loongarch64: #NO_APP
#[cfg(loongarch64)]
check_reg!(r4_i64, i64, "$r4", "move");
// CHECK-LABEL: r4_f64:
// CHECK: #APP
// CHECK: move $a0, $a0
// CHECK: #NO_APP
// loongarch64-LABEL: r4_f64:
// loongarch64: #APP
// loongarch64: move $a0, $a0
// loongarch64: #NO_APP
#[cfg(loongarch64)]
check_reg!(r4_f64, f64, "$r4", "move");
// CHECK-LABEL: r4_ptr:

View File

@@ -0,0 +1,38 @@
error: invalid register `$r0`: constant zero cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:27:18
|
LL | asm!("", out("$r0") _);
| ^^^^^^^^^^^^
error: invalid register `$tp`: reserved for TLS
--> $DIR/bad-reg.rs:29:18
|
LL | asm!("", out("$tp") _);
| ^^^^^^^^^^^^
error: invalid register `$sp`: the stack pointer cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:31:18
|
LL | asm!("", out("$sp") _);
| ^^^^^^^^^^^^
error: invalid register `$r21`: reserved by the ABI
--> $DIR/bad-reg.rs:33:18
|
LL | asm!("", out("$r21") _);
| ^^^^^^^^^^^^^
error: invalid register `$fp`: the frame pointer cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:35:18
|
LL | asm!("", out("$fp") _);
| ^^^^^^^^^^^^
error: invalid register `$r31`: $r31 is used internally by LLVM and cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:37:18
|
LL | asm!("", out("$r31") _);
| ^^^^^^^^^^^^^
error: aborting due to 6 previous errors

View File

@@ -0,0 +1,62 @@
error: invalid register `$r0`: constant zero cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:27:18
|
LL | asm!("", out("$r0") _);
| ^^^^^^^^^^^^
error: invalid register `$tp`: reserved for TLS
--> $DIR/bad-reg.rs:29:18
|
LL | asm!("", out("$tp") _);
| ^^^^^^^^^^^^
error: invalid register `$sp`: the stack pointer cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:31:18
|
LL | asm!("", out("$sp") _);
| ^^^^^^^^^^^^
error: invalid register `$r21`: reserved by the ABI
--> $DIR/bad-reg.rs:33:18
|
LL | asm!("", out("$r21") _);
| ^^^^^^^^^^^^^
error: invalid register `$fp`: the frame pointer cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:35:18
|
LL | asm!("", out("$fp") _);
| ^^^^^^^^^^^^
error: invalid register `$r31`: $r31 is used internally by LLVM and cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:37:18
|
LL | asm!("", out("$r31") _);
| ^^^^^^^^^^^^^
error: register class `freg` requires at least one of the following target features: d, f
--> $DIR/bad-reg.rs:41:26
|
LL | asm!("/* {} */", in(freg) f);
| ^^^^^^^^^^
error: register class `freg` requires at least one of the following target features: d, f
--> $DIR/bad-reg.rs:43:26
|
LL | asm!("/* {} */", out(freg) _);
| ^^^^^^^^^^^
error: register class `freg` requires at least one of the following target features: d, f
--> $DIR/bad-reg.rs:45:26
|
LL | asm!("/* {} */", in(freg) d);
| ^^^^^^^^^^
error: register class `freg` requires at least one of the following target features: d, f
--> $DIR/bad-reg.rs:47:26
|
LL | asm!("/* {} */", out(freg) d);
| ^^^^^^^^^^^
error: aborting due to 10 previous errors

View File

@@ -1,35 +1,35 @@
error: invalid register `$r0`: constant zero cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:22:18
--> $DIR/bad-reg.rs:27:18
|
LL | asm!("", out("$r0") _);
| ^^^^^^^^^^^^
error: invalid register `$tp`: reserved for TLS
--> $DIR/bad-reg.rs:24:18
--> $DIR/bad-reg.rs:29:18
|
LL | asm!("", out("$tp") _);
| ^^^^^^^^^^^^
error: invalid register `$sp`: the stack pointer cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:26:18
--> $DIR/bad-reg.rs:31:18
|
LL | asm!("", out("$sp") _);
| ^^^^^^^^^^^^
error: invalid register `$r21`: reserved by the ABI
--> $DIR/bad-reg.rs:28:18
--> $DIR/bad-reg.rs:33:18
|
LL | asm!("", out("$r21") _);
| ^^^^^^^^^^^^^
error: invalid register `$fp`: the frame pointer cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:30:18
--> $DIR/bad-reg.rs:35:18
|
LL | asm!("", out("$fp") _);
| ^^^^^^^^^^^^
error: invalid register `$r31`: $r31 is used internally by LLVM and cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:32:18
--> $DIR/bad-reg.rs:37:18
|
LL | asm!("", out("$r31") _);
| ^^^^^^^^^^^^^

View File

@@ -1,59 +1,59 @@
error: invalid register `$r0`: constant zero cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:22:18
--> $DIR/bad-reg.rs:27:18
|
LL | asm!("", out("$r0") _);
| ^^^^^^^^^^^^
error: invalid register `$tp`: reserved for TLS
--> $DIR/bad-reg.rs:24:18
--> $DIR/bad-reg.rs:29:18
|
LL | asm!("", out("$tp") _);
| ^^^^^^^^^^^^
error: invalid register `$sp`: the stack pointer cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:26:18
--> $DIR/bad-reg.rs:31:18
|
LL | asm!("", out("$sp") _);
| ^^^^^^^^^^^^
error: invalid register `$r21`: reserved by the ABI
--> $DIR/bad-reg.rs:28:18
--> $DIR/bad-reg.rs:33:18
|
LL | asm!("", out("$r21") _);
| ^^^^^^^^^^^^^
error: invalid register `$fp`: the frame pointer cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:30:18
--> $DIR/bad-reg.rs:35:18
|
LL | asm!("", out("$fp") _);
| ^^^^^^^^^^^^
error: invalid register `$r31`: $r31 is used internally by LLVM and cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:32:18
--> $DIR/bad-reg.rs:37:18
|
LL | asm!("", out("$r31") _);
| ^^^^^^^^^^^^^
error: register class `freg` requires at least one of the following target features: d, f
--> $DIR/bad-reg.rs:36:26
--> $DIR/bad-reg.rs:41:26
|
LL | asm!("/* {} */", in(freg) f);
| ^^^^^^^^^^
error: register class `freg` requires at least one of the following target features: d, f
--> $DIR/bad-reg.rs:38:26
--> $DIR/bad-reg.rs:43:26
|
LL | asm!("/* {} */", out(freg) _);
| ^^^^^^^^^^^
error: register class `freg` requires at least one of the following target features: d, f
--> $DIR/bad-reg.rs:40:26
--> $DIR/bad-reg.rs:45:26
|
LL | asm!("/* {} */", in(freg) d);
| ^^^^^^^^^^
error: register class `freg` requires at least one of the following target features: d, f
--> $DIR/bad-reg.rs:42:26
--> $DIR/bad-reg.rs:47:26
|
LL | asm!("/* {} */", out(freg) d);
| ^^^^^^^^^^^

View File

@@ -1,6 +1,11 @@
//@ add-core-stubs
//@ needs-asm-support
//@ revisions: loongarch64_lp64d loongarch64_lp64s
//@ revisions: loongarch32_ilp32d loongarch32_ilp32s loongarch64_lp64d loongarch64_lp64s
//@ min-llvm-version: 20
//@[loongarch32_ilp32d] compile-flags: --target loongarch32-unknown-none
//@[loongarch32_ilp32d] needs-llvm-components: loongarch
//@[loongarch32_ilp32s] compile-flags: --target loongarch32-unknown-none-softfloat
//@[loongarch32_ilp32s] needs-llvm-components: loongarch
//@[loongarch64_lp64d] compile-flags: --target loongarch64-unknown-linux-gnu
//@[loongarch64_lp64d] needs-llvm-components: loongarch
//@[loongarch64_lp64s] compile-flags: --target loongarch64-unknown-none-softfloat
@@ -34,12 +39,12 @@ fn f() {
asm!("", out("$f0") _); // ok
asm!("/* {} */", in(freg) f);
//[loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f
//[loongarch32_ilp32s,loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f
asm!("/* {} */", out(freg) _);
//[loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f
//[loongarch32_ilp32s,loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f
asm!("/* {} */", in(freg) d);
//[loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f
//[loongarch32_ilp32s,loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f
asm!("/* {} */", out(freg) d);
//[loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f
//[loongarch32_ilp32s,loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f
}
}