Skip to content

Put more values into global variables#2211

Draft
vouillon wants to merge 3 commits intomasterfrom
globalize
Draft

Put more values into global variables#2211
vouillon wants to merge 3 commits intomasterfrom
globalize

Conversation

@vouillon
Copy link
Copy Markdown
Member

@vouillon vouillon commented Apr 8, 2026

Put constant expressions at toplevel into global variables, in order to reduce the size of the toplevel function.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant