diff options
author | Alon Zakai <azakai@google.com> | 2021-08-31 16:49:34 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-31 16:49:34 -0700 |
commit | 82cdabf20e496508cd241ef31a5f630c2de844ad (patch) | |
tree | d125e86b1bd50e85c20b540be1074ed655591b8f /src/passes/OptimizeInstructions.cpp | |
parent | 7d966528f603e65dacbf25f585a5accc46470bbd (diff) | |
download | binaryen-82cdabf20e496508cd241ef31a5f630c2de844ad.tar.gz binaryen-82cdabf20e496508cd241ef31a5f630c2de844ad.tar.bz2 binaryen-82cdabf20e496508cd241ef31a5f630c2de844ad.zip |
Use the new module version of EffectAnalyzer (#4116)
This finishes the refactoring started in #4115 by doing the
same change to pass a Module into EffectAnalyzer instead of
features. To do so this refactors the fallthrough API and a few
other small things. After those changes, this PR removes the
old feature constructor of EffectAnalyzer entirely.
This requires a small breaking change in the C API, changing
BinaryenExpressionGetSideEffects's feature param to a
module. That makes this change not NFC, but otherwise it is.
Diffstat (limited to 'src/passes/OptimizeInstructions.cpp')
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 22d53b151..8752c76cb 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -101,8 +101,8 @@ struct LocalScanner : PostWalker<LocalScanner> { return; } // an integer var, worth processing - auto* value = Properties::getFallthrough( - curr->value, passOptions, getModule()->features); + auto* value = + Properties::getFallthrough(curr->value, passOptions, *getModule()); auto& info = localInfo[curr->index]; info.maxBits = std::max(info.maxBits, Bits::getMaxBits(value, this)); auto signExtBits = LocalInfo::kUnknown; @@ -469,9 +469,9 @@ struct OptimizeInstructions Index extraLeftShifts; auto bits = Properties::getAlmostSignExtBits(curr, extraLeftShifts); if (extraLeftShifts == 0) { - if (auto* load = Properties::getFallthrough( - ext, getPassOptions(), getModule()->features) - ->dynCast<Load>()) { + if (auto* load = + Properties::getFallthrough(ext, getPassOptions(), *getModule()) + ->dynCast<Load>()) { // pattern match a load of 8 bits and a sign extend using a shl of // 24 then shr_s of 24 as well, etc. if (LoadUtils::canBeSigned(load) && @@ -1152,9 +1152,9 @@ struct OptimizeInstructions // the fallthrough value there. It takes more work to optimize this case, // but it is pretty important to allow a call_ref to become a fast direct // call, so make the effort. - if (auto* ref = - Properties::getFallthrough(curr->target, getPassOptions(), features) - ->dynCast<RefFunc>()) { + if (auto* ref = Properties::getFallthrough( + curr->target, getPassOptions(), *getModule()) + ->dynCast<RefFunc>()) { // Check if the fallthrough make sense. We may have cast it to a different // type, which would be a problem - we'd be replacing a call_ref to one // type with a direct call to a function of another type. That would trap @@ -1290,8 +1290,8 @@ struct OptimizeInstructions Builder builder(*getModule()); auto passOptions = getPassOptions(); - auto fallthrough = Properties::getFallthrough( - curr->ref, getPassOptions(), getModule()->features); + auto fallthrough = + Properties::getFallthrough(curr->ref, getPassOptions(), *getModule()); // If the value is a null, it will just flow through, and we do not need the // cast. However, if that would change the type, then things are less @@ -1358,8 +1358,6 @@ struct OptimizeInstructions } } - auto features = getModule()->features; - // Repeated identical ref.cast operations are unnecessary, if using the // exact same rtt - the result will be the same. Find the immediate child // cast, if there is one, and see if it is identical. @@ -1370,7 +1368,7 @@ struct OptimizeInstructions // RefCast falls through the value, so instead of calling getFallthrough() // to look through all fallthroughs, we must iterate manually. Keep going // until we reach either the end of things falling-through, or a cast. - ref = Properties::getImmediateFallthrough(ref, passOptions, features); + ref = Properties::getImmediateFallthrough(ref, passOptions, *getModule()); if (ref == last) { break; } @@ -1544,7 +1542,6 @@ private: // also ok to have side effects here, if we can remove them, as we are also // checking if we can remove the two inputs anyhow.) auto passOptions = getPassOptions(); - auto features = getModule()->features; if (EffectAnalyzer(passOptions, *getModule(), left) .hasUnremovableSideEffects() || EffectAnalyzer(passOptions, *getModule(), right) @@ -1553,14 +1550,15 @@ private: } // Ignore extraneous things and compare them structurally. - left = Properties::getFallthrough(left, passOptions, features); - right = Properties::getFallthrough(right, passOptions, features); + left = Properties::getFallthrough(left, passOptions, *getModule()); + right = Properties::getFallthrough(right, passOptions, *getModule()); if (!ExpressionAnalyzer::equal(left, right)) { return false; } // To be equal, they must also be known to return the same result // deterministically. - if (Properties::isIntrinsicallyNondeterministic(left, features)) { + if (Properties::isIntrinsicallyNondeterministic(left, + getModule()->features)) { return false; } return true; |