-
Notifications
You must be signed in to change notification settings - Fork 745
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
Simplify scratch local calculation #6583
Conversation
Change `countScratchLocals` to return the count and type of necessary scratch locals. It used to encode them as keys in the global map from scratch local types to local indices, which could not handle having more than one scratch local of a given type and was generally harder to reason about due to its use of global state. Take the opportunity to avoid emitting unnecessary scratch locals for `TupleExtract` expressions that will be optimized to not use them. Also simplify and better document the calculation of the mapping from IR indices to binary indices for all locals, scratch and non-scratch.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
src/wasm/wasm-stack.cpp
Outdated
scratchLocals[localType] = index - 1; | ||
ScratchLocalFinder(BinaryInstWriter& parent) : parent(parent) {} | ||
|
||
// We need two i32 scratch locals for reach string slice, but they can be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// We need two i32 scratch locals for reach string slice, but they can be | |
// We need two i32 scratch locals for each string slice, but they can be |
;; ROUNDTRIP-NEXT: (local $15 (tuple i32 f32)) | ||
;; ROUNDTRIP-NEXT: (local $16 i32) | ||
;; ROUNDTRIP-NEXT: (local $14 (tuple i32 f32)) | ||
;; ROUNDTRIP-NEXT: (local $15 i32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment on line 80 looks like it needs to be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So is the scratch local created when first reading the binary, (local $14 f32)
now unnecessary? Is the reason because this was optimized by extractedGets
? (It looks before we were counting extractedGets
as scratch locals anyway)
In any case the comment needs to be updated from line 78.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good point, I think we no longer emit (local $14)
. I updated the comments.
src/wasm/wasm-stack.cpp
Outdated
|
||
// We need two i32 scratch locals for reach string slice, but they can be | ||
// reused. | ||
bool hasStringSlice = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, this is left over development cruft, will remove.
Change
countScratchLocals
to return the count and type of necessary scratchlocals. It used to encode them as keys in the global map from scratch local
types to local indices, which could not handle having more than one scratch
local of a given type and was generally harder to reason about due to its use of
global state. Take the opportunity to avoid emitting unnecessary scratch locals
for
TupleExtract
expressions that will be optimized to not use them.Also simplify and better document the calculation of the mapping from IR indices
to binary indices for all locals, scratch and non-scratch.