feat(asm): indirect-memory =*m place outputs

Implements indirect-memory (`=*m`) `-> @place` outputs — the last
substantive asm feature. Unlike a write-through `=` output (which
returns a value that is then stored), an indirect output passes the
place ADDRESS to the asm and the asm writes through it; there is no
return slot.

emitInlineAsm:
  - indirect outputs are excluded from the LLVM return type;
  - their pointer is passed as an opaque `ptr` call arg, placed FIRST
    (the arg-consuming constraint order is: output-section indirect
    pointers, then inputs, then read-write tied seeds);
  - each indirect arg gets an `elementtype(T)` call-site attribute
    (required in the opaque-pointer era), T = the pointee type;
  - the store-back loop skips indirect outputs (already written).
New asmIsIndirect helper. Lowering stops rejecting `*` (constraint kept
verbatim; `=*m` reaches the constraint string as-is). asmOperandIndex
is unchanged — indirect outputs still count as operands, so `%[name]`
${N} numbering holds.

Verified by running on aarch64: store-through-pointer (str x9, %[out]
→ 42, IR `=*m,~{x9}` with `ptr elementtype(i64)`) and a mixed case
(indirect + value output + input → `=*m,=r,r`, indirect ptr arg first,
${0}/${1}/${2} correct). 1652 flipped from the rejection lock to a
runnable aarch64 example (ir-only elsewhere). zig build test green
(661 corpus, 446 unit).
This commit is contained in:
agra
2026-06-16 07:09:17 +03:00
parent 2a43713d7f
commit cb6c032c58
6 changed files with 74 additions and 36 deletions

View File

@@ -0,0 +1 @@
{ "target": "macos" }

View File

@@ -0,0 +1,18 @@
; Function Attrs: nounwind
define internal i64 @poke() #0 {
entry:
%alloca = alloca i64, align 8
store i64 0, ptr %alloca, align 8
call void asm sideeffect " mov x9, #42\0A str x9, ${0}\0A", "=*m,~{x9}"(ptr elementtype(i64) %alloca)
%load = load i64, ptr %alloca, align 8
ret i64 %load
}
; Function Attrs: nounwind
define i32 @main() #0 {
entry:
%call = call i64 @poke()
%ca.tr = trunc i64 %call to i32
ret i32 %ca.tr
}

View File

@@ -1,19 +1 @@
error: indirect-memory (`*`) asm outputs are not yet implemented
--> examples/1652-platform-asm-indirect-mem.sx:9:5
|
9 | asm volatile {
| ^^^^^^^^^^^^^^
10 | #string ASM
| ^^^^^^^^^^^^^^^^^^^
11 | mov x9, #42
| ^^^^^^^^^^^^^^^^^^^
12 | str x9, %[out]
| ^^^^^^^^^^^^^^^^^^^^^^
13 | ASM,
| ^^^^
14 | [out] "=*m" -> @x,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
15 | clobbers(.x9),
| ^^^^^^^^^^^^^^^^^^^^^^
16 | };
| ^^^^^