[GR-77075] Add instruction rewriting support for stack values. - #14333
Merged
Conversation
…uctions when returning from block Adds rewrite rules of the form: store.stackvalue(k), pop * k - 1, return -> return Essentially, when the result of a block is returned, we can skip the cleanup instructions since the frame will be thrown away.
This is a non-functional change necessary to properly remap childBci fields.
Adds rewrite rules of the form:
load.stackvalue(n - 1) * n, X, pop * n -> X (void X consumes n values)
load.stackvalue(n - 1) * n, X, store.stackvalue(n), pop * (n - 1) -> X (non-void X consumes n == k stack values)
load.stackvalue(n - 1) * n, X, store.stackvalue(k), pop * (k - 1) -> X, store.stackvalue(k - n), pop * (k - n - 1) (non-void X consumes n < k stack values)
This change requires limited support for REPLACE sections that replace 1 instruction with 1 instruction in order to replace the store.stackvalue instruction in the last pattern.
Since BCIs into instructions are disallowed, this limitation makes replacement safe without adding full support to check for ambiguous BCIs.
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.
Adds some new rewrite rules and the rewrite machinery to support them (immediate matching, REPLACE sections).
Also refactors the builder to keep operation stack entries on stack until after instruction emission, so that we can rewrite child bci's stored in the current operation stack entry.
New rewrite rules:
In text: if the result of a block is returned, we can skip the cleanup instructions since the frame will be thrown away.
In text: if X consumes some stack values from the top of stack, and then we pop those values, let X consume them directly.