feat(riscv): WasmOp::Call lowering — leaf-call subset#116
Open
avrabe wants to merge 1 commit into
Open
Conversation
v0.3.1 minimum-viable cross-function call support in the RISC-V
selector. WasmOp::Call(idx) no longer errors with `Unsupported` for
leaf-call shapes — it now lowers to a label-based RiscVOp::Call that
the ELF builder resolves to a PC-relative `auipc + jalr` when the
callee is in the same compilation unit.
Behavior:
* Move top N vstack values (capped at 8) into a0..a(N-1).
* Emit `RiscVOp::Call { label: format!("synth_func_{idx}") }`.
* Push a fresh `a0` vreg as the return value.
What's deliberately deferred (documented in the lower_call doc + the
#[ignore]-marked `recursive_self_call_emits_two_call_ops` test):
* Function-signature plumbing from the decoder. Without it, the
selector can't know how many args to pop, so the v0.3.1 cut
over-consumes the vstack on back-to-back calls with surviving
results. v0.4 will pipe `FuncSig` through and lift this restriction.
* Args beyond 8 (RV psABI says spill to stack at fixed offsets — not
implemented).
* Caller-side a0..a7 invalidation across the BL — callers wanting to
survive a call should `drop` or `local.tee` their live values
explicitly until v0.4 models this properly.
* Multi-result returns (wasm 2.0).
* Cross-`.text` relocations for multi-unit linking.
Tests:
* `call_emits_label_and_argument_marshalling` — single-arg call, label
encodes `synth_func_{idx}`.
* `call_two_args_marshals_to_a0_a1` — two-arg call from i32.const seq.
* `recursive_self_call_emits_two_call_ops` — #[ignore]'d documentation
of the back-to-back-calls gap, to be flipped when v0.4 plumbing
lands.
Total: 100 passing tests in synth-backend-riscv (was 99); 1 ignored
that documents the next milestone.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Minimum-viable cross-function call support in the RISC-V instruction selector.
WasmOp::Call(idx)now lowers to a label-basedRiscVOp::Callinstead of returningSelectorError::Unsupported. The ELF builder already resolves call labels via PC-relativeauipc + jalr, so the only missing piece was the selector arm — this PR adds it.This is the third Track A item for v0.3.1 after PRs #113, #114, #115. RV32 i64 lowering is the next one.
What it does
lower_call(func_idx, op)method insynth-backend-riscv/src/selector.rs.What's deferred (deliberately, with tracking tests)
The v0.3.1 cut is the leaf-call subset. The following are known gaps, each carrying a comment and (where applicable) an `#[ignore]`'d test:
The ignored test `recursive_self_call_emits_two_call_ops` is the canary that v0.4's plumbing work will flip back on.
Tests
Local run before push:
Test plan
🤖 Generated with Claude Code