Skip to content

Put more values into global variables#2211

Open
vouillon wants to merge 4 commits intomasterfrom
globalize
Open

Put more values into global variables#2211
vouillon wants to merge 4 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.

For the PRT benchmark, the size of the toplevel function is divided by 2.

@vouillon vouillon added the wasm label Apr 10, 2026
@vouillon vouillon force-pushed the globalize branch 2 times, most recently from faf9fd3 to f7dfb2f Compare April 14, 2026 15:04
@vouillon vouillon marked this pull request as ready for review April 14, 2026 15:04
Comment thread compiler/lib-wasm/globalize.ml Outdated
@vouillon vouillon force-pushed the globalize branch 2 times, most recently from adf2150 to c685f9a Compare May 5, 2026 15:46
vouillon added 2 commits May 6, 2026 20:14
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).
Comment thread compiler/lib-wasm/code_generation.ml Outdated
args
in
if List.is_empty patches
then None, st
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't this be an assert false ?

vouillon added 2 commits May 7, 2026 10:05
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.

2 participants