Conversation
When storing a globalized variable whose expression is a Wasm constant expression (only refs to immutable globals, inline constants, array/struct allocations), emit it as an immutable global with the expression as its initializer instead of a mutable global with a default value and GlobalSet. Skip this optimisation when always is true (multiple stores from different code paths).
After the distance-based globalization pass, propagate to fixpoint: a block whose fields are all global/constant becomes global, and a closure whose free variables are all global/constant becomes global (cascading to its free variables via globalize_closure).
Allow blocks with up to 2 non-available fields to be globalized in the propagation pass. In code generation, use partial constant initialization: the ArrayNewFixed is emitted as an immutable global initializer with placeholder values, and only the non-available fields are patched via ArraySet in the function body. This enables cascading for nested blocks (e.g. linked lists) where globalizing an inner block makes it available for outer blocks.
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.
Put constant expressions at toplevel into global variables, in order to reduce the size of the toplevel function.