From def9d684c29e3f3213b0a90970c578f86012844f Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 29 Mar 2024 15:16:43 -0700 Subject: [PATCH 1/3] one --- src/ir/possible-contents.cpp | 10 +++++----- src/ir/possible-contents.h | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/ir/possible-contents.cpp b/src/ir/possible-contents.cpp index c80ada95c61..0dde1df74d8 100644 --- a/src/ir/possible-contents.cpp +++ b/src/ir/possible-contents.cpp @@ -226,9 +226,9 @@ void PossibleContents::intersect(const PossibleContents& other) { // Note the global's information, if we started as a global. In that case, the // code below will refine our type but we can remain a global, which we will // accomplish by restoring our global status at the end. - std::optional globalName; + std::optional global; if (isGlobal()) { - globalName = getGlobal(); + global = getGlobal(); } auto newType = Type(newHeapType, nullability); @@ -267,9 +267,9 @@ void PossibleContents::intersect(const PossibleContents& other) { value = ConeType{newType, newDepth}; } - if (globalName) { + if (global) { // Restore the global but keep the new and refined type. - value = GlobalInfo{*globalName, getType()}; + value = GlobalInfo{*global, getType()}; } } @@ -2578,7 +2578,7 @@ void Flower::filterGlobalContents(PossibleContents& contents, // a cone/exact type *and* that something is equal to a global, in some // cases. See https://github.com/WebAssembly/binaryen/pull/5083 if (contents.isMany() || contents.isConeType()) { - contents = PossibleContents::global(global->name, global->type); + contents = PossibleContents::global(global, global->type); // TODO: We could do better here, to set global->init->type instead of // global->type, or even the contents.getType() - either of those diff --git a/src/ir/possible-contents.h b/src/ir/possible-contents.h index 2773c1d3125..ada9eca0365 100644 --- a/src/ir/possible-contents.h +++ b/src/ir/possible-contents.h @@ -65,7 +65,7 @@ class PossibleContents { struct None : public std::monostate {}; struct GlobalInfo { - Name name; + Global* global; // The type of contents. Note that this may not match the type of the // global, if we were filtered. For example: // @@ -77,7 +77,7 @@ class PossibleContents { // unlike the original global. Type type; bool operator==(const GlobalInfo& other) const { - return name == other.name && type == other.type; + return global == other.global && type == other.type; } }; @@ -119,8 +119,8 @@ class PossibleContents { static PossibleContents none() { return PossibleContents{None()}; } static PossibleContents literal(Literal c) { return PossibleContents{c}; } - static PossibleContents global(Name name, Type type) { - return PossibleContents{GlobalInfo{name, type}}; + static PossibleContents global(Global* global, Type type) { + return PossibleContents{GlobalInfo{global, type}}; } // Helper for a cone type with depth 0, i.e., an exact type. static PossibleContents exactType(Type type) { @@ -190,9 +190,9 @@ class PossibleContents { return std::get(value); } - Name getGlobal() const { + Global* getGlobal() const { assert(isGlobal()); - return std::get(value).name; + return std::get(value).global; } bool isNull() const { return isLiteral() && getLiteral().isNull(); } @@ -290,11 +290,11 @@ class PossibleContents { if (isLiteral()) { return builder.makeConstantExpression(getLiteral()); } else { - auto name = getGlobal(); + auto* global = 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); + return builder.makeGlobalGet(global->name, global->type); } } @@ -306,7 +306,7 @@ class PossibleContents { } else if (isLiteral()) { rehash(ret, getLiteral()); } else if (isGlobal()) { - rehash(ret, getGlobal()); + rehash(ret, getGlobal()->name); } else if (auto* coneType = std::get_if(&value)) { rehash(ret, coneType->type); rehash(ret, coneType->depth); @@ -328,7 +328,7 @@ class PossibleContents { o << " HT: " << h; } } else if (isGlobal()) { - o << "GlobalInfo $" << getGlobal() << " T: " << getType(); + o << "GlobalInfo $" << getGlobal()->name << " T: " << getType(); } else if (auto* coneType = std::get_if(&value)) { auto t = coneType->type; o << "ConeType " << t; From 03403b7df6c487407c32205f2b922441b6cc0d62 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 29 Mar 2024 15:27:36 -0700 Subject: [PATCH 2/3] Revert "one" This reverts commit def9d684c29e3f3213b0a90970c578f86012844f. --- src/ir/possible-contents.cpp | 10 +++++----- src/ir/possible-contents.h | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/ir/possible-contents.cpp b/src/ir/possible-contents.cpp index 0dde1df74d8..c80ada95c61 100644 --- a/src/ir/possible-contents.cpp +++ b/src/ir/possible-contents.cpp @@ -226,9 +226,9 @@ void PossibleContents::intersect(const PossibleContents& other) { // Note the global's information, if we started as a global. In that case, the // code below will refine our type but we can remain a global, which we will // accomplish by restoring our global status at the end. - std::optional global; + std::optional globalName; if (isGlobal()) { - global = getGlobal(); + globalName = getGlobal(); } auto newType = Type(newHeapType, nullability); @@ -267,9 +267,9 @@ void PossibleContents::intersect(const PossibleContents& other) { value = ConeType{newType, newDepth}; } - if (global) { + if (globalName) { // Restore the global but keep the new and refined type. - value = GlobalInfo{*global, getType()}; + value = GlobalInfo{*globalName, getType()}; } } @@ -2578,7 +2578,7 @@ void Flower::filterGlobalContents(PossibleContents& contents, // a cone/exact type *and* that something is equal to a global, in some // cases. See https://github.com/WebAssembly/binaryen/pull/5083 if (contents.isMany() || contents.isConeType()) { - contents = PossibleContents::global(global, global->type); + contents = PossibleContents::global(global->name, global->type); // TODO: We could do better here, to set global->init->type instead of // global->type, or even the contents.getType() - either of those diff --git a/src/ir/possible-contents.h b/src/ir/possible-contents.h index ada9eca0365..2773c1d3125 100644 --- a/src/ir/possible-contents.h +++ b/src/ir/possible-contents.h @@ -65,7 +65,7 @@ class PossibleContents { struct None : public std::monostate {}; struct GlobalInfo { - Global* global; + Name name; // The type of contents. Note that this may not match the type of the // global, if we were filtered. For example: // @@ -77,7 +77,7 @@ class PossibleContents { // unlike the original global. Type type; bool operator==(const GlobalInfo& other) const { - return global == other.global && type == other.type; + return name == other.name && type == other.type; } }; @@ -119,8 +119,8 @@ class PossibleContents { static PossibleContents none() { return PossibleContents{None()}; } static PossibleContents literal(Literal c) { return PossibleContents{c}; } - static PossibleContents global(Global* global, Type type) { - return PossibleContents{GlobalInfo{global, type}}; + static PossibleContents global(Name name, Type type) { + return PossibleContents{GlobalInfo{name, type}}; } // Helper for a cone type with depth 0, i.e., an exact type. static PossibleContents exactType(Type type) { @@ -190,9 +190,9 @@ class PossibleContents { return std::get(value); } - Global* getGlobal() const { + Name getGlobal() const { assert(isGlobal()); - return std::get(value).global; + return std::get(value).name; } bool isNull() const { return isLiteral() && getLiteral().isNull(); } @@ -290,11 +290,11 @@ class PossibleContents { if (isLiteral()) { return builder.makeConstantExpression(getLiteral()); } else { - auto* global = getGlobal(); + 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(global->name, global->type); + return builder.makeGlobalGet(name, wasm.getGlobal(name)->type); } } @@ -306,7 +306,7 @@ class PossibleContents { } else if (isLiteral()) { rehash(ret, getLiteral()); } else if (isGlobal()) { - rehash(ret, getGlobal()->name); + rehash(ret, getGlobal()); } else if (auto* coneType = std::get_if(&value)) { rehash(ret, coneType->type); rehash(ret, coneType->depth); @@ -328,7 +328,7 @@ class PossibleContents { o << " HT: " << h; } } else if (isGlobal()) { - o << "GlobalInfo $" << getGlobal()->name << " T: " << getType(); + o << "GlobalInfo $" << getGlobal() << " T: " << getType(); } else if (auto* coneType = std::get_if(&value)) { auto t = coneType->type; o << "ConeType " << t; From 1b6944935a0876fe828c4ef02275732992c65258 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 29 Mar 2024 15:29:50 -0700 Subject: [PATCH 3/3] fix --- src/ir/possible-contents.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ir/possible-contents.h b/src/ir/possible-contents.h index 2773c1d3125..7ff0f1a0761 100644 --- a/src/ir/possible-contents.h +++ b/src/ir/possible-contents.h @@ -76,6 +76,9 @@ class PossibleContents { // The contents flowing out will be a Global, but of a non-nullable type, // unlike the original global. Type type; + // TODO: Consider adding a depth here, or merging this with ConeType in some + // way. In principle, not having depth info can lead to loss of + // precision. bool operator==(const GlobalInfo& other) const { return name == other.name && type == other.type; } @@ -305,8 +308,9 @@ class PossibleContents { // Nothing to add. } else if (isLiteral()) { rehash(ret, getLiteral()); - } else if (isGlobal()) { - rehash(ret, getGlobal()); + } else if (auto* global = std::get_if(&value)) { + rehash(ret, global->name); + rehash(ret, global->type); } else if (auto* coneType = std::get_if(&value)) { rehash(ret, coneType->type); rehash(ret, coneType->depth);