Skip to content

Stabilize loongarch32 inline asm #144402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_ast_lowering/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ This feature tracks `asm!` and `global_asm!` support for the following architect
- M68k
- CSKY
- SPARC
- LoongArch32

## Register classes

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
51 changes: 31 additions & 20 deletions tests/assembly-llvm/asm/loongarch-type.rs
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
38 changes: 38 additions & 0 deletions tests/ui/asm/loongarch/bad-reg.loongarch32_ilp32d.stderr
Original file line number Diff line number Diff line change
@@ -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

62 changes: 62 additions & 0 deletions tests/ui/asm/loongarch/bad-reg.loongarch32_ilp32s.stderr
Original file line number Diff line number Diff line change
@@ -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

12 changes: 6 additions & 6 deletions tests/ui/asm/loongarch/bad-reg.loongarch64_lp64d.stderr
Original file line number Diff line number Diff line change
@@ -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") _);
| ^^^^^^^^^^^^^
Expand Down
20 changes: 10 additions & 10 deletions tests/ui/asm/loongarch/bad-reg.loongarch64_lp64s.stderr
Original file line number Diff line number Diff line change
@@ -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);
| ^^^^^^^^^^^
Expand Down
15 changes: 10 additions & 5 deletions tests/ui/asm/loongarch/bad-reg.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}
}
Loading