summaryrefslogtreecommitdiff
path: root/src/passes/CodePushing.cpp
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2020-02-03 10:44:49 -0800
committerGitHub <noreply@github.com>2020-02-03 10:44:49 -0800
commitc9f2e9b7b24182e830f39c176170d5ca64d3d05e (patch)
treeb9aeb5648997393c474d1e3ebf4513d640395c70 /src/passes/CodePushing.cpp
parentcd8d82910d229aa8357eb18882745397f6ed87eb (diff)
downloadbinaryen-c9f2e9b7b24182e830f39c176170d5ca64d3d05e.tar.gz
binaryen-c9f2e9b7b24182e830f39c176170d5ca64d3d05e.tar.bz2
binaryen-c9f2e9b7b24182e830f39c176170d5ca64d3d05e.zip
Add EH support for EffectAnalyzer (#2631)
This adds EH support to `EffectAnalyzer`. Before `throw` and `rethrow` conservatively set property. Now `EffectAnalyzer` has a new property `throws` to represent an expression that can throw, and expression that can throw sets `throws` correctly. When EH is enabled, any calls can throw too, so we cannot reorder them with another expression with any side effects, meaning all calls should be treated in the same way as branches when evaluating `invalidate`. This prevents many reorderings, so this patch sets `throws` for calls only when the exception handling features is enabled. This is also why I passed `--disable-exception-handling` to `wasm2js` tests. Most of code changes outside of `EffectAnalyzer` class was made in order to pass `FeatureSet` to it. `throws` isn't always set whenever an expression contains a throwable instruction. When an throwable instruction is within an inner try, it will be caught by the corresponding inner catch, so it does not set `throws`.
Diffstat (limited to 'src/passes/CodePushing.cpp')
-rw-r--r--src/passes/CodePushing.cpp24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/passes/CodePushing.cpp b/src/passes/CodePushing.cpp
index 4eb69b92e..6907f4fdc 100644
--- a/src/passes/CodePushing.cpp
+++ b/src/passes/CodePushing.cpp
@@ -82,14 +82,16 @@ class Pusher {
LocalAnalyzer& analyzer;
std::vector<Index>& numGetsSoFar;
PassOptions& passOptions;
+ FeatureSet features;
public:
Pusher(Block* block,
LocalAnalyzer& analyzer,
std::vector<Index>& numGetsSoFar,
- PassOptions& passOptions)
+ PassOptions& passOptions,
+ FeatureSet features)
: list(block->list), analyzer(analyzer), numGetsSoFar(numGetsSoFar),
- passOptions(passOptions) {
+ passOptions(passOptions), features(features) {
// Find an optimization segment: from the first pushable thing, to the first
// point past which we want to push. We then push in that range before
// continuing forward.
@@ -126,7 +128,7 @@ private:
// but also have no side effects, as it may not execute if pushed.
if (analyzer.isSFA(index) &&
numGetsSoFar[index] == analyzer.getNumGets(index) &&
- !EffectAnalyzer(passOptions, set->value).hasSideEffects()) {
+ !EffectAnalyzer(passOptions, features, set->value).hasSideEffects()) {
return set;
}
return nullptr;
@@ -157,7 +159,7 @@ private:
assert(firstPushable != Index(-1) && pushPoint != Index(-1) &&
firstPushable < pushPoint);
// everything that matters if you want to be pushed past the pushPoint
- EffectAnalyzer cumulativeEffects(passOptions);
+ EffectAnalyzer cumulativeEffects(passOptions, features);
cumulativeEffects.analyze(list[pushPoint]);
// it is ok to ignore the branching here, that is the crucial point of this
// opt
@@ -169,11 +171,12 @@ private:
if (pushable) {
auto iter = pushableEffects.find(pushable);
if (iter == pushableEffects.end()) {
- iter = pushableEffects
- .emplace(std::piecewise_construct,
- std::forward_as_tuple(pushable),
- std::forward_as_tuple(passOptions, pushable))
- .first;
+ iter =
+ pushableEffects
+ .emplace(std::piecewise_construct,
+ std::forward_as_tuple(pushable),
+ std::forward_as_tuple(passOptions, features, pushable))
+ .first;
}
auto& effects = iter->second;
if (cumulativeEffects.invalidates(effects)) {
@@ -263,7 +266,8 @@ struct CodePushing : public WalkerPass<PostWalker<CodePushing>> {
// don't hit a non-control-flow ordering invalidation issue, since if this
// isn't a loop, it's fine (we're not used outside), and if it is, we hit
// the assign before any use (as we can't push it past a use).
- Pusher pusher(curr, analyzer, numGetsSoFar, getPassOptions());
+ Pusher pusher(
+ curr, analyzer, numGetsSoFar, getPassOptions(), getModule()->features);
}
};