diff options
author | Alon Zakai <azakai@google.com> | 2021-10-29 14:38:17 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-29 14:38:17 -0700 |
commit | 3666cbc74d690f5a062bd45e7ac0df0d58c24636 (patch) | |
tree | 8779610bb91f717226f6750a3d7755f46e97723b /src/passes/SimplifyGlobals.cpp | |
parent | 5b3cc376af95daba7da944842babe47b2b2197d2 (diff) | |
download | binaryen-3666cbc74d690f5a062bd45e7ac0df0d58c24636.tar.gz binaryen-3666cbc74d690f5a062bd45e7ac0df0d58c24636.tar.bz2 binaryen-3666cbc74d690f5a062bd45e7ac0df0d58c24636.zip |
Effects: Differentiate mutable from immutable globals (#4286)
Similar to what we do with structs, if a global is immutable then we know it
cannot interact with calls.
This changes the JS API for getSideEffects(). That was actually broken,
as passing in the optional module param would just pass it along to the
compiled C code, so it was coerced to 0 or 1, and not a pointer to a module.
To fix that, this now does module.ptr to actually get the pointer, and this is
now actually tested as without a module we cannot compute the effects of a
global. This PR also makes the module param mandatory in the JS API,
as again, without a module we can't compute global effects. (The module
param has already been mandatory in the C++ API for some time.)
Diffstat (limited to 'src/passes/SimplifyGlobals.cpp')
-rw-r--r-- | src/passes/SimplifyGlobals.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/passes/SimplifyGlobals.cpp b/src/passes/SimplifyGlobals.cpp index 0943c04fe..be7cc6ca1 100644 --- a/src/passes/SimplifyGlobals.cpp +++ b/src/passes/SimplifyGlobals.cpp @@ -123,11 +123,19 @@ struct GlobalUseScanner : public WalkerPass<PostWalker<GlobalUseScanner>> { // See if reading a specific global is the only effect the first has. EffectAnalyzer firstEffects(getPassOptions(), *getModule(), first); - if (firstEffects.globalsRead.size() != 1) { + if (firstEffects.immutableGlobalsRead.size() + + firstEffects.mutableGlobalsRead.size() != + 1) { return Name(); } - auto global = *firstEffects.globalsRead.begin(); - firstEffects.globalsRead.clear(); + Name global; + if (firstEffects.immutableGlobalsRead.size() == 1) { + global = *firstEffects.immutableGlobalsRead.begin(); + firstEffects.immutableGlobalsRead.clear(); + } else { + global = *firstEffects.mutableGlobalsRead.begin(); + firstEffects.mutableGlobalsRead.clear(); + } if (firstEffects.hasAnything()) { return Name(); } |