diff options
author | Alon Zakai <azakai@google.com> | 2021-11-01 15:36:41 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-01 15:36:41 -0700 |
commit | bbfee5cc3a463b1bc7f54414ccaf2e47bee3e216 (patch) | |
tree | fa167748b66cae6fdbd1e66c9648298c8f1c7644 /src/passes/LocalSubtyping.cpp | |
parent | 3666cbc74d690f5a062bd45e7ac0df0d58c24636 (diff) | |
download | binaryen-bbfee5cc3a463b1bc7f54414ccaf2e47bee3e216.tar.gz binaryen-bbfee5cc3a463b1bc7f54414ccaf2e47bee3e216.tar.bz2 binaryen-bbfee5cc3a463b1bc7f54414ccaf2e47bee3e216.zip |
[Wasm GC] LUBFinder helper. NFC (#4298)
This is a minor refactoring in DAE to have a helper class that does the
incremental LUB calculation. The class is also used in LocalSubtyping,
where it has the effect of making the work incremental which it was not
before (that would have no observable consequence, but it should make
us faster in the common case where we fail to find a new LUB).
This will allow further optimization in a central place later.
Diffstat (limited to 'src/passes/LocalSubtyping.cpp')
-rw-r--r-- | src/passes/LocalSubtyping.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/passes/LocalSubtyping.cpp b/src/passes/LocalSubtyping.cpp index 24a2e48e4..57119a253 100644 --- a/src/passes/LocalSubtyping.cpp +++ b/src/passes/LocalSubtyping.cpp @@ -25,6 +25,7 @@ #include <ir/find_all.h> #include <ir/linear-execution.h> #include <ir/local-graph.h> +#include <ir/lubs.h> #include <ir/utils.h> #include <pass.h> #include <wasm-builder.h> @@ -118,18 +119,21 @@ struct LocalSubtyping : public WalkerPass<PostWalker<LocalSubtyping>> { // type. for (Index i = varBase; i < numLocals; i++) { + auto oldType = func->getLocalType(i); + // Find all the types assigned to the var, and compute the optimal LUB. - std::unordered_set<Type> types; + LUBFinder lub; for (auto* set : setsForLocal[i]) { - types.insert(set->value->type); + if (lub.note(set->value) == oldType) { + break; + } } - if (types.empty()) { + if (!lub.noted()) { // Nothing is assigned to this local (other opts will remove it). continue; } - auto oldType = func->getLocalType(i); - auto newType = Type::getLeastUpperBound(types); + auto newType = lub.get(); assert(newType != Type::none); // in valid wasm there must be a LUB // Remove non-nullability if we disallow that in locals. |