Fix VM-to-EmitC [1/2]#24554
Open
severin-blip wants to merge 1 commit into
Open
Conversation
Contributor
|
Hi @severin-blip, thanks for you contribution :) Please check out the contribution guidelines: https://iree.dev/developers/general/contributing/ . You need to sign your commit. |
devtbi
requested changes
Jun 2, 2026
devtbi
left a comment
Contributor
There was a problem hiding this comment.
Please check out the contribution guidelines: https://iree.dev/developers/general/contributing/ . You need to sign your commit.
a922d9b to
9018d2c
Compare
9018d2c to
6812c2c
Compare
Use the target data layout when computing VM ABI buffer alignment in generated EmitC import shims instead of hard-coding refs to 8-byte alignment. On 32-bit targets, iree_vm_ref_t can have 4-byte alignment, so the old packing logic over-aligned ref fields and produced argument buffers whose offsets did not match the VM runtime ABI layout. This caused imports with variadic refs, such as iICrD, to read the ref object/type from the wrong offsets. Apply the target-aware alignment consistently when computing argument and result buffer sizes, packing arguments, releasing packed refs, and unpacking results. Signed-off-by: Severin Bochem <severin@Severins-MacBook-Pro.local> Signed-off-by: Severin Bochem <severin@mosaic-soc.com>
6812c2c to
3458e0a
Compare
Contributor
|
@severin-blip looks good in general, once the CI is passing I'll do a full review :) |
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
Fix VM-to-EmitC static import shim packing for
iree_vm_ref_t.Generated VM-C import shims were using a hard-coded 8-byte alignment for VM ref
arguments. That is incorrect on RV32, where
iree_vm_ref_tis two 32-bit wordsbut only has 4-byte alignment.
Fix
Use the target C ABI alignment for
iree_vm_ref_tinstead of assuming 8-bytealignment.
Conceptually, generated code changes from:
to:
for VM ref packing/unpacking.
Test
Added a regression test under
tests/riscv32_static_link.The test compiles a minimal tensor add program to VM-C for
riscv32-unknown-elfand FileChecks the generatediICrDimport shim. Itverifies that the shim uses 4-byte alignment for the
iree_vm_ref_tvariadic ref slot and for theactual
iree_vm_ref_retainpacking path.