[clang] [llvm] [RISCV] Add Codegen support for ACLIC (PR #238325)

Zeyi Xu via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 24 19:01:54 PST 2026


================
@@ -96,6 +96,61 @@ def CSR_XLEN_F32_V_Interrupt_RVE: CalleeSavedRegs<(sub CSR_XLEN_F32_V_Interrupt,
 def CSR_XLEN_F64_V_Interrupt_RVE: CalleeSavedRegs<(sub CSR_XLEN_F64_V_Interrupt,
                                                    (sequence "X%u", 16, 31))>;
 
+// For Smip/Ssip interrupt handlers, the compiler may assume that X10-X15
----------------
zeyi2 wrote:

> I don't think we want to do this, but I'm reviewing in sequence so I may be wrong. I definitely feel like this number of definitions is not maintainable.

Thanks, I noticed that `Zilsd` used an alternative approach and I will try whether it could work for ACLIC.

> I'd like us to follow that logic, especially as we need to emit .cfi_* directives for these registers so debuggers work correctly.

This might be a bit... hard.

ACLIC `Smip`/`Ssip` intentionally leaves the stack layout and register offsets implementation-defined:

- (`Smip`/`Ssip`)
> [NOTE: This extension does not require a normative stack layout. Interrupt handlers do not require access to the interrupted context.](https://github.com/riscv/riscv-fast-interrupt/blob/v0.20/src/aclic.adoc?plain=1#L1713-L1714)

- (`mipopret` / `sipopret`)
> [The order and access size of the loads, as well as the OFFSETS, are implementation-defined.](https://github.com/riscv/riscv-fast-interrupt/blob/v0.20/src/aclic.adoc?plain=1#L1808-L1823)

(and [similarly for `sipopret`](https://github.com/riscv/riscv-fast-interrupt/blob/v0.20/src/aclic.adoc?plain=1#L1861-L1876)).

There was an earlier `Smtp` draft that [recommended a stack layout with concrete offsets](https://github.com/riscv/riscv-fast-interrupt/blob/c94c3d8a0d1120036a5cb1a91c4368a298b71c36/src/aclic.adoc?plain=1#L1046-L1077), and that section was removed when `Smtp` was reworked into `Smip` in [riscv/riscv-fast-interrupt#653](https://github.com/riscv/riscv-fast-interrupt/pull/653).

---

So now in ACLIC different cores can place `a0`-`a5` at different offsets, IMO neither the compiler nor a generic debugger can infer the register offsets:

- We can't emit `.cfi_offset` for `a0`-`a5` without guessing an implementation-specific offset that would be wrong on other cores.
- Emitting `.cfi_same_value` would also be wrong, because once the handler modifies `a0`-`a5`, the interrupted values only live inside that opaque hardware frame.
- At best, we could emit `.cfi_undefined a0-a5` so debuggers know their previous values are not recoverable via DWARF rather than treating them as `same_value`.

```asm
.cfi_undefined a0
.cfi_undefined a1
.cfi_undefined a2
.cfi_undefined a3
.cfi_undefined a4
.cfi_undefined a5
```

WDYT?

https://github.com/llvm/llvm-project/pull/238325


More information about the cfe-commits mailing list