playX18 opened PR #13917 from playX18:ap-ghc-callconv to bytecodealliance:main:
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->This PR adds LLVM’s GHC (
ghccc) calling convention to Cranelift asCallConv::Ghc/ CLIFghc, for x86_64, aarch64, and riscv64.Why?
People writing compilers for functional languages often want "register
pinning": keep runtime / VM state in fixed hardware registers, and jump
between functions instead of doing normal C calls. Haskell does this with
the STG machine and LLVM'sghccc. SML/NJ (and similar CPS systems) do
heap-allocated continuations and need something like jump-with-arguments.
Scheme compilers in CPS style want the same kind of thing.In Cranelift today,
enable_pinned_regonly gives you one reserved
register.tailhelps withreturn_call, but it is still basically a
SysV-like ABI: it still builds native frames, and it does not pin a big
set of STG-style registers for you.So this PR adds LLVM's GHC calling convention. Then you can map many
virtual machine registers to real regs through the callconv, with no
callee-saves, and usereturn_callbetweenghcfunctions.Summary
- Mirror LLVM STG register pinning: args only in fixed regs, no callee-saves, no return values, no stack spill of overflow args (
Unsupported).return_callallowed betweenghcfunctions (supports_tail_calls); does not use Tail’s callee-pops-stack-args behavior.- x86_64: Sp is
%rbp, soghcframes are FP-less (RSP-relative spills only). Entry from SysV/Rust that needs Sp must use a naked asm trampoline (documented incranelift/docs/ir.md); Craneliftsystem_vcannot place Sp in%rbpwhile using it as FP.- aarch64 / riscv64: Sp is not the hardware FP, so full STG arg lists work from
system_vwithout asm.- Unsupported on s390x/pulley.
- Exceptions not supported for
ghc.Test plan
- [x] Verifier:
filetests/filetests/verifier/ghc-abi.clif- [x] Precise-output:
isa/{x64,aarch64,riscv64}/ghc.clif- [x]
cargo run -p cranelift-tools -- test ./filetests/filetests/isa/*/ghc.clif ./filetests/filetests/verifier/ghc-abi.clif
playX18 has marked PR #13917 as ready for review.
playX18 requested wasmtime-compiler-s390x-reviewers for a review on PR #13917.
playX18 requested cfallin for a review on PR #13917.
playX18 requested wasmtime-compiler-reviewers for a review on PR #13917.
:cross_mark: playX18 closed without merge PR #13917.
Last updated: Jul 29 2026 at 05:03 UTC