diff options
author | Alon Zakai <azakai@google.com> | 2023-04-07 09:49:31 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-07 09:49:31 -0700 |
commit | 757d6a21a3c5626cfaa9dac28c28555748b93a6b (patch) | |
tree | a056cc39cd95168ced58c5b4357468b70d7fac17 /src/ir/possible-contents.h | |
parent | 9328b6c1906e2fb91253f65c6983547407c0a77c (diff) | |
download | binaryen-757d6a21a3c5626cfaa9dac28c28555748b93a6b.tar.gz binaryen-757d6a21a3c5626cfaa9dac28c28555748b93a6b.tar.bz2 binaryen-757d6a21a3c5626cfaa9dac28c28555748b93a6b.zip |
[GUFA] Refine global types during flow (#5639)
Previously (ref.as_non_null (global.get ..)) would return the global with no changes,
and if the global was nullable then the type didn't match the output, which hit an
assertion (where GUFA checks that the contents match the declared type in the wasm).
To fix this, refine global types, that is, the type we track on GlobalInfo may be more
refined than the global itself. In the above example, if the global is nullable then
the GlobalInfo would point to that global but have a non-nullable type.
In fact the code was already prepared for this, and few changes were needed.
Diffstat (limited to 'src/ir/possible-contents.h')
-rw-r--r-- | src/ir/possible-contents.h | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/ir/possible-contents.h b/src/ir/possible-contents.h index b7c9bfafd..b4326688e 100644 --- a/src/ir/possible-contents.h +++ b/src/ir/possible-contents.h @@ -66,10 +66,15 @@ class PossibleContents { struct GlobalInfo { Name name; - // The type of the global in the module. We stash this here so that we do - // not need to pass around a module all the time. - // TODO: could we save size in this variant if we did pass around the - // module? + // The type of contents. Note that this may not match the type of the + // global, if we were filtered. For example: + // + // (ref.as_non_null + // (global.get $nullable-global) + // ) + // + // The contents flowing out will be a Global, but of a non-nullable type, + // unlike the original global. Type type; bool operator==(const GlobalInfo& other) const { return name == other.name && type == other.type; @@ -287,6 +292,9 @@ public: return builder.makeConstantExpression(getLiteral()); } else { auto name = getGlobal(); + // Note that we load the type from the module, rather than use the type + // in the GlobalInfo, as that type may not match the global (see comment + // in the GlobalInfo declaration above). return builder.makeGlobalGet(name, wasm.getGlobal(name)->type); } } @@ -321,7 +329,7 @@ public: o << " HT: " << h; } } else if (isGlobal()) { - o << "GlobalInfo $" << getGlobal(); + o << "GlobalInfo $" << getGlobal() << " T: " << getType(); } else if (auto* coneType = std::get_if<ConeType>(&value)) { auto t = coneType->type; o << "ConeType " << t; |