feat(asm): symbol operands ("s") — direct call/branch to a function
A `"s"` input operand feeds a function/global symbol; the template's %[name] emits the platform-mangled name, so `bl %[fn]` / `call %[fn]` branches DIRECTLY to it (PC-relative, no register load — one fewer indirection than register-indirect `blr`). Lowering: an `"s"` input lowers its RHS normally (a function name → `ptr @fn`); the rejection added last commit is removed. Emit: a symbol operand is passed with its OWN llvm type (LLVMTypeOf) and no coercion — the function value is a `ptr`, and the old coerce-to-register-int path mistyped it and failed the verifier. New asmIsSymbol helper. Verified on aarch64: examples/1656 (sx → asm → bl _cb → sx → 42); the emitted asm is a direct `bl <_cb>` (objdump-confirmed), IR constraint `...,s,...`(ptr @cb). Flipped 1656 from the rejection lock to a runnable aarch64 example. zig build test green (665 corpus, 446 unit).
This commit is contained in:
1
examples/expected/1656-platform-asm-symbol-operand.build
Normal file
1
examples/expected/1656-platform-asm-symbol-operand.build
Normal file
@@ -0,0 +1 @@
|
||||
{ "target": "macos" }
|
||||
@@ -1 +1 @@
|
||||
1
|
||||
42
|
||||
|
||||
28
examples/expected/1656-platform-asm-symbol-operand.ir
Normal file
28
examples/expected/1656-platform-asm-symbol-operand.ir
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define i64 @cb(i64 %0) #0 {
|
||||
entry:
|
||||
%alloca = alloca i64, align 8
|
||||
store i64 %0, ptr %alloca, align 8
|
||||
%load = load i64, ptr %alloca, align 8
|
||||
%add = add i64 %load, 1
|
||||
ret i64 %add
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define internal i64 @tramp(i64 %0) #0 {
|
||||
entry:
|
||||
%alloca = alloca i64, align 8
|
||||
store i64 %0, ptr %alloca, align 8
|
||||
%load = load i64, ptr %alloca, align 8
|
||||
%asm = call i64 asm sideeffect " stp x29, x30, [sp, #-16]!\0A mov x0, ${1}\0A bl ${2}\0A mov ${0}, x0\0A ldp x29, x30, [sp], #16\0A", "=r,r,s,~{x0},~{x30},~{memory}"(i64 %load, ptr @cb)
|
||||
ret i64 %asm
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define i32 @main() #0 {
|
||||
entry:
|
||||
%call = call i64 @tramp(i64 41)
|
||||
%ca.tr = trunc i64 %call to i32
|
||||
ret i32 %ca.tr
|
||||
}
|
||||
@@ -1,29 +1 @@
|
||||
error: symbol asm operands (`"s"`) are not yet implemented
|
||||
--> examples/1656-platform-asm-symbol-operand.sx:10:12
|
||||
|
|
||||
10 | return asm volatile {
|
||||
| ^^^^^^^^^^^^^^
|
||||
11 | #string ASM
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
12 | stp x29, x30, [sp, #-16]!
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
13 | mov x0, %[arg]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
14 | bl %[fn]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
15 | mov %[res], x0
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
16 | ldp x29, x30, [sp], #16
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
17 | ASM,
|
||||
| ^^^^
|
||||
18 | [res] "=r" -> i64,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
19 | [arg] "r" = n,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
20 | [fn] "s" = cb, // symbol operand → direct `bl _cb`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
21 | clobbers(.x0, .x30, .memory),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
22 | };
|
||||
| ^^^^^
|
||||
|
||||
|
||||
Reference in New Issue
Block a user