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

Simplify scratch local calculation #6583

Merged
merged 3 commits into from
May 14, 2024
Merged

Simplify scratch local calculation #6583

merged 3 commits into from
May 14, 2024

Conversation

tlively
Copy link
Member

@tlively tlively commented May 12, 2024

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.

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.
Copy link
Member Author

tlively commented May 12, 2024

@tlively tlively requested a review from aheejin May 12, 2024 07:55
scratchLocals[localType] = index - 1;
ScratchLocalFinder(BinaryInstWriter& parent) : parent(parent) {}

// We need two i32 scratch locals for reach string slice, but they can be
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// 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)
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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.


// We need two i32 scratch locals for reach string slice, but they can be
// reused.
bool hasStringSlice = false;
Copy link
Member

Choose a reason for hiding this comment

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

Is this used anywhere?

Copy link
Member Author

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.

@tlively tlively merged commit 020d08e into main May 14, 2024
26 checks passed
@tlively tlively deleted the simplify-scratch-locals branch May 14, 2024 00:10
@gkdn gkdn mentioned this pull request Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants