rust/tests/ui/asm
bors 96477c55bc Auto merge of #131341 - taiki-e:ppc-clobber-abi, r=bzEq,workingjubilee
Support clobber_abi and vector registers (clobber-only) in PowerPC inline assembly

This supports `clobber_abi` which is one of the requirements of stabilization mentioned in #93335.

This basically does a similar thing I did in https://github.com/rust-lang/rust/pull/130630 to implement `clobber_abi` for s390x, but for powerpc/powerpc64/powerpc64le.
- This also supports vector registers (as `vreg`) as clobber-only, which need to support clobbering of them to implement `clobber_abi`.
- `vreg` should be able to accept `#[repr(simd)]` types as input/output if the unstable `altivec` target feature is enabled, but `core::arch::{powerpc,powerpc64}` vector types, `#[repr(simd)]`, and `core::simd` are all unstable, so the fact that this is currently a clobber-only should not be considered a blocker of clobber_abi implementation or stabilization. So I have not implemented it in this PR.
  - See https://github.com/rust-lang/rust/pull/131551 (which is based on this PR) for a PR to implement this.
  - (I'm not sticking to whether that PR should be a separate PR or part of this PR, so I can merge that PR into this PR if needed.)

Refs:
- PPC32 SysV: Section "Function Calling Sequence" in [System V Application Binary Interface PowerPC Processor Supplement](https://refspecs.linuxfoundation.org/elf/elfspec_ppc.pdf)
- PPC64 ELFv1: Section 3.2 "Function Calling Sequence" in [64-bit PowerPC ELF Application Binary Interface Supplement](https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi.html#FUNC-CALL)
- PPC64 ELFv2: Section 2.2 "Function Calling Sequence" in [64-Bit ELF V2 ABI Specification](https://openpowerfoundation.org/specifications/64bitelfabi/)
- AIX: [Register usage and conventions](https://www.ibm.com/docs/en/aix/7.3?topic=overview-register-usage-conventions), [Special registers in the PowerPC®](https://www.ibm.com/docs/en/aix/7.3?topic=overview-special-registers-in-powerpc), [AIX vector programming](https://www.ibm.com/docs/en/aix/7.3?topic=concepts-aix-vector-programming)
- Register definition in LLVM: https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/PowerPC/PPCRegisterInfo.td#L189

If I understand the above four ABI documentations correctly, except for the PPC32 SysV's VR (Vector Registers) and 32-bit AIX (currently not supported by rustc)'s r13, there does not appear to be important differences in terms of implementing `clobber_abi`:
- The above four ABIs are consistent about FPR (0-13: volatile, 14-31: nonvolatile), CR (0-1,5-7: volatile, 2-4: nonvolatile), XER (volatile), and CTR (volatile).
- As for GPR, only the registers we are treating as reserved are slightly different
  - r0, r3-r12 are volatile
  - r1(sp, reserved), r14-31 are nonvolatile
  - r2(reserved) is TOC pointer in PPC64 ELF/AIX, system-reserved register in PPC32 SysV (AFAIK used as thread pointer in Linux/BSDs)
  - r13(reserved for non-32-bit-AIX) is thread pointer in PPC64 ELF, small data area pointer register in PPC32 SysV, "reserved under 64-bit environment; not restored across system calls[^r13]" in AIX)
- As for FPSCR, volatile in PPC64 ELFv1/AIX, some fields are volatile only in certain situations (rest are volatile) in PPC32 SysV/PPC64 ELFv2.
- As for VR (Vector Registers), it is not mentioned in PPC32 SysV, v0-v19 are volatile in both in PPC64 ELF/AIX, v20-v31 are nonvolatile in PPC64 ELF, reserved or nonvolatile depending on the ABI ([vec-extabi vs vec-default in LLVM](https://reviews.llvm.org/D89684), we are [using vec-extabi](https://github.com/rust-lang/rust/pull/131341#discussion_r1797693299)) in AIX:
  > When the default Vector enabled mode is used, these registers are reserved and must not be used.
  > In the extended ABI vector enabled mode, these registers are nonvolatile and their values are preserved across function calls

  I left [FIXME comment about PPC32 SysV](https://github.com/rust-lang/rust/pull/131341#discussion_r1790496095) and added ABI check for AIX.
- As for VRSAVE, it is not mentioned in PPC32 SysV, nonvolatile in PPC64 ELFv1, reserved in PPC64 ELFv2/AIX
- As for VSCR, it is not mentioned in PPC32 SysV/PPC64 ELFv1, some fields are volatile only in certain situations (rest are volatile) in PPC64 ELFv2, volatile in AIX

We are currently treating r1-r2, r13 (non-32-bit-AIX), r29-r31, LR, CTR, and VRSAVE as reserved.
We are currently not processing anything about FPSCR and VSCR, but I feel those are things that should be processed by `preserves_flags` rather than `clobber_abi` if we need to do something about them. (However, PPCRegisterInfo.td in LLVM does not seem to define anything about them.)

Replaces #111335 and #124279

cc `@ecnelises` `@bzEq` `@lu-zero`

r? `@Amanieu`

`@rustbot` label +O-PowerPC +A-inline-assembly

[^r13]: callee-saved, according to [LLVM](6a6af0246b/llvm/lib/Target/PowerPC/PPCCallingConv.td (L322)) and [GCC](a9173a50e7/gcc/config/rs6000/rs6000.h (L859)).
2024-11-05 03:13:47 +00:00
..
aarch64 Fix clobber_abi and disallow SVE-related registers in Arm64EC inline assembly 2024-10-14 05:30:45 +09:00
powerpc Support clobber_abi and vector registers (clobber-only) in PowerPC inline assembly 2024-11-02 20:26:08 +09:00
riscv Move tests/ui/abi/riscv32e-registers.rs to tests/ui/asm/riscv 2024-11-03 18:32:04 +09:00
s390x Adjust tests to use minicore and rebless 2024-11-02 21:59:27 +08:00
x86_64 make type-check-4 asm tests about non-const expressions 2024-09-30 13:47:36 +02:00
arm-low-dreg.rs
bad-arch.rs
bad-arch.stderr
bad-template.aarch64.stderr
bad-template.rs stabilize asm_const 2024-08-13 23:18:31 +02:00
bad-template.x86_64.stderr
binary_asm_labels_allowed.rs Change binary_asm_labels to only fire on x86 and x86_64 2024-07-18 15:00:56 -05:00
binary_asm_labels.rs
binary_asm_labels.stderr Update the binary_asm_label message 2024-07-18 17:00:43 -04:00
const-error.rs adjust test 2024-09-29 08:49:37 +02:00
const-refs-to-static.rs Stabilize const_refs_to_static 2024-09-26 13:21:15 +02:00
const-refs-to-static.stderr Stabilize const_refs_to_static 2024-09-26 13:21:15 +02:00
empty_global_asm.rs
fail-const-eval-issue-121099.rs stabilize asm_const 2024-08-13 23:18:31 +02:00
fail-const-eval-issue-121099.stderr stabilize asm_const 2024-08-13 23:18:31 +02:00
generic-const.rs stabilize asm_const 2024-08-13 23:18:31 +02:00
ice-bad-err-span-in-template-129503.rs Fix error span when arg to asm!() is a macro call 2024-09-27 09:49:15 +05:30
ice-bad-err-span-in-template-129503.stderr Fix error span when arg to asm!() is a macro call 2024-09-27 09:49:15 +05:30
inline-syntax.arm.stderr Update the minimum external LLVM to 18 2024-09-18 13:53:31 -07:00
inline-syntax.rs Update the minimum external LLVM to 18 2024-09-18 13:53:31 -07:00
inline-syntax.x86_64.stderr Update the minimum external LLVM to 18 2024-09-18 13:53:31 -07:00
invalid-const-operand.rs stabilize asm_const 2024-08-13 23:18:31 +02:00
invalid-const-operand.stderr stabilize asm_const 2024-08-13 23:18:31 +02:00
invalid-sym-operand.rs add needs-asm-support to invalid-sym-operand 2024-08-02 19:59:34 +01:00
invalid-sym-operand.stderr add needs-asm-support to invalid-sym-operand 2024-08-02 19:59:34 +01:00
issue-72570.rs
issue-72570.stderr
issue-85247.rs
issue-85247.rwpi.stderr
issue-87802.rs
issue-87802.stderr
issue-89305.rs
issue-89305.stderr
issue-92378.rs
issue-97490.rs
issue-99071.rs
issue-99071.stderr
issue-99122-2.rs
issue-99122.rs
issue-99122.stderr
issue-113788.rs
issue-113788.stderr
may_unwind.rs
naked-asm-outside-naked-fn.rs disallow naked_asm! outside of #[naked] functions 2024-09-10 15:19:14 +02:00
naked-asm-outside-naked-fn.stderr disallow naked_asm! outside of #[naked] functions 2024-09-10 15:19:14 +02:00
naked-functions-ffi.rs disallow asm! in #[naked] functions 2024-10-06 18:12:25 +02:00
naked-functions-ffi.stderr
naked-functions-inline.rs disallow asm! in #[naked] functions 2024-10-06 18:12:25 +02:00
naked-functions-inline.stderr switch to an allowlist approach 2024-07-27 12:55:39 +02:00
naked-functions-instruction-set.rs disallow asm! in #[naked] functions 2024-10-06 18:12:25 +02:00
naked-functions-testattrs.rs disallow asm! in #[naked] functions 2024-10-06 18:12:25 +02:00
naked-functions-testattrs.stderr switch to an allowlist approach 2024-07-27 12:55:39 +02:00
naked-functions-unused.aarch64.stderr use naked_asm! in naked-function tests 2024-10-06 18:12:25 +02:00
naked-functions-unused.rs disallow asm! in #[naked] functions 2024-10-06 18:12:25 +02:00
naked-functions-unused.x86_64.stderr use naked_asm! in naked-function tests 2024-10-06 18:12:25 +02:00
naked-functions.rs disallow asm! in #[naked] functions 2024-10-06 18:12:25 +02:00
naked-functions.stderr various fixes for naked_asm! implementation 2024-10-06 19:00:09 +02:00
naked-invalid-attr.rs disallow asm! in #[naked] functions 2024-10-06 18:12:25 +02:00
naked-invalid-attr.stderr disallow asm! in #[naked] functions 2024-10-06 18:12:25 +02:00
naked-with-invalid-repr-attr.rs disallow asm! in #[naked] functions 2024-10-06 18:12:25 +02:00
naked-with-invalid-repr-attr.stderr disallow asm! in #[naked] functions 2024-10-06 18:12:25 +02:00
named-asm-labels.rs disallow asm! in #[naked] functions 2024-10-06 18:12:25 +02:00
named-asm-labels.s
named-asm-labels.stderr disallow asm! in #[naked] functions 2024-10-06 18:12:25 +02:00
non-const.rs make type-check-4 asm tests about non-const expressions 2024-09-30 13:47:36 +02:00
non-const.stderr make type-check-4 asm tests about non-const expressions 2024-09-30 13:47:36 +02:00
noreturn.rs
parse-error.rs stabilize asm_const 2024-08-13 23:18:31 +02:00
parse-error.stderr stabilize asm_const 2024-08-13 23:18:31 +02:00
reg-conflict.rs
reg-conflict.stderr
simple_global_asm.rs
type-check-1.rs stabilize asm_const 2024-08-13 23:18:31 +02:00
type-check-1.stderr stabilize asm_const 2024-08-13 23:18:31 +02:00
type-check-4.rs
type-check-4.stderr
unpretty-expanded.rs
unpretty-expanded.stdout
unsupported-option.fixed add needs-asm-support to tests/ui/asm/unsupported-option.rs 2024-07-27 19:27:20 +02:00
unsupported-option.rs add needs-asm-support to tests/ui/asm/unsupported-option.rs 2024-07-27 19:27:20 +02:00
unsupported-option.stderr add needs-asm-support to tests/ui/asm/unsupported-option.rs 2024-07-27 19:27:20 +02:00