Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cranelift: Choose memory trap code based on memflags #8134

Merged
merged 1 commit into from
Mar 14, 2024

Conversation

jameysharp
Copy link
Contributor

Ideally we'd allow the frontend to specify what trap code a memory access instruction can produce, but we don't have room to store that information.

Instead, I'm adding additional meaning to the table and heap memflags. Besides being used in alias analysis, these flags now also indicate whether the instruction should produce a trap code of TableOutOfBounds or HeapOutOfBounds, respectively.

In the Cranelift weekly meeting we discussed that it would be nice to assert that either table or heap is set when the trap-code is requested, but I don't know if all users of the instruction encodings (such as cg-clif or Winch) set those flags, so I've chosen to default to the old behavior if none of the alias-analysis flags are set.

Currently, memory accesses with the table flag set always have notrap set as well, so the TableOutOfBounds case is never hit, but I wanted to separate this change out from the cranelift-wasm changes which will use it.

@jameysharp jameysharp requested a review from a team as a code owner March 14, 2024 16:58
@jameysharp jameysharp requested review from abrown and removed request for a team March 14, 2024 16:58
@abrown
Copy link
Contributor

abrown commented Mar 14, 2024

@cfallin, @elliottt: do you want to review this instead? I am not as familiar with these trapping bits as I should be.

@cfallin cfallin requested review from cfallin and removed request for abrown March 14, 2024 17:40
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:area:x64 Issues related to x64 codegen labels Mar 14, 2024
Ideally we'd allow the frontend to specify what trap code a memory
access instruction can produce, but we don't have room to store that
information.

We do have a few bits to spare in `MemFlags`, though, so add a new
`tabletrap` bit to indicate that the trap code should be
TableOutOfBounds instead of the default HeapOutOfBounds.

Nothing yet sets the `tabletrap` flag, so the TableOutOfBounds case is
never hit, but I wanted to separate this change out from the
cranelift-wasm changes which will use it.

The original version of this patch reused the `table` flag instead of
introducing a new `tabletrap` flag. But this usage changes the semantics
of an instruction, while the `table` flag is meant to be a hint for
alias analysis in the egraph optimization pass.
Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@cfallin cfallin enabled auto-merge March 14, 2024 18:28
@cfallin cfallin added this pull request to the merge queue Mar 14, 2024
Merged via the queue into bytecodealliance:main with commit 779645f Mar 14, 2024
24 checks passed
@jameysharp jameysharp deleted the memflags-trapcode branch March 14, 2024 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:area:x64 Issues related to x64 codegen cranelift Issues related to the Cranelift code generator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants