Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Cranelift: Remove the stack_{load,store} instructions - #13580

#13580
Merged
fitzgen merged 1 commit into
bytecodealliance:mainbytecodealliance/wasmtime:mainfrom
fitzgen:wasmtime-remove-stack-load-storefitzgen/wasmtime:wasmtime-remove-stack-load-storeCopy head branch name to clipboard
Jun 8, 2026
Merged

Cranelift: Remove the stack_{load,store} instructions#13580
fitzgen merged 1 commit into
bytecodealliance:mainbytecodealliance/wasmtime:mainfrom
fitzgen:wasmtime-remove-stack-load-storefitzgen/wasmtime:wasmtime-remove-stack-load-storeCopy head branch name to clipboard

Conversation

@fitzgen

@fitzgen fitzgen commented Jun 5, 2026

Copy link
Copy Markdown
Member

These get immediately legalized to stack_addr and load or store, so frontends should just emit that pair directly. For convenience and backwards compat, we add InstBuilder::stack_load and InstBuilder::stack_store methods that emit the pair as a single operation. Unfortunately, these methods have to take an additional pointer-type parameter that the old version didn't have to take because the rewrite didn't happen until legalization time, so these new methods are not 100% backwards compatible. This also necessitated passing in a TargetFrontendConfig to FuncBuilder::finalize, which resulted in a bit of churn, but is fully mechanical.

@fitzgen
fitzgen requested review from a team as code owners June 5, 2026 23:00
@fitzgen
fitzgen requested review from alexcrichton and removed request for a team June 5, 2026 23:00

@alexcrichton alexcrichton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it be possible to avoid changing finalize by looking at the stack slot's size field and choosing an appropriate type based on that?

@github-actions github-actions Bot added cranelift Issues related to the Cranelift code generator cranelift:meta Everything related to the meta-language. labels Jun 6, 2026
@fitzgen

fitzgen commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

Would it be possible to avoid changing finalize by looking at the stack slot's size field and choosing an appropriate type based on that?

Unfortunately not, because it isn't the stack slot's type that we need to pass in (that was already passed in) it is the size of the target pointer.

@alexcrichton

Copy link
Copy Markdown
Member

So, here, which I belive is the only need for changing finalize currently, the slot variable's size doesn't match the platform's pointer width?

These get immediately legalized to `stack_addr` and `load` or `store`, so
frontends should just emit that pair directly. For convenience and backwards
compat, we add `InstBuilder::stack_load` and `InstBuilder::stack_store` methods
that emit the pair as a single operation. Unfortunately, these methods have to
take an additional pointer-type parameter that the old version didn't have to
take because the rewrite didn't happen until legalization time, so these new
methods are not 100% backwards compatible. This also necessitated passing in a
`TargetFrontendConfig` to `FuncBuilder::finalize`, which resulted in a bit of
churn, but is fully mechanical.
@fitzgen
fitzgen force-pushed the wasmtime-remove-stack-load-store branch from 03849f6 to 13b161a Compare June 8, 2026 18:24
@fitzgen

fitzgen commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

So, here, which I belive is the only need for changing finalize currently,

Correct, although I think it is very reasonable to require a target config when building CLIF in general (e.g. a small additional follow up refactor could make all the memcpy functions that want a target config as an argument stop taking that argument and using the same source of truth as finalize).

the slot variable's size doesn't match the platform's pointer width?

It does not match. For Wasmtime, for example, the slots are 4 bytes large (VMGcRef-sized) regardless of 64- or 32-bit target. In general, those slots are sized to the value that needs inclusion in stack maps, which can be of any arbitrary type.

@fitzgen
fitzgen enabled auto-merge June 8, 2026 18:28

@alexcrichton alexcrichton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah right, indeed. Would it make sense to take in an entire &dyn TargetIsa here instead of just the TargetFrontendConfig? Or alternatively just take the pointer_type instead of TargetFrontendConfig?

@fitzgen
fitzgen added this pull request to the merge queue Jun 8, 2026
@fitzgen

fitzgen commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

Ah right, indeed. Would it make sense to take in an entire &dyn TargetIsa here instead of just the TargetFrontendConfig? Or alternatively just take the pointer_type instead of TargetFrontendConfig?

Other frontend methods (such as the memcpy stuff mentioned earlier) take TargetFrontendConfig so I was just trying to match that.

All we absolutely need is the pointer type but it feels a bit like overspecializing on the exact use case today, vs what feels "right" / fits with the design of the crate. &dyn TargetIsa is a bit more of a mid-end/backend thing, for example.

Merged via the queue into bytecodealliance:main with commit ee61137 Jun 8, 2026
78 checks passed
@fitzgen
fitzgen deleted the wasmtime-remove-stack-load-store branch June 8, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift:meta Everything related to the meta-language. cranelift Issues related to the Cranelift code generator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.