From c9f2e9b7b24182e830f39c176170d5ca64d3d05e Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Mon, 3 Feb 2020 10:44:49 -0800 Subject: 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`. --- src/passes/LocalCSE.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/passes/LocalCSE.cpp') diff --git a/src/passes/LocalCSE.cpp b/src/passes/LocalCSE.cpp index b49c92310..f7c1cda26 100644 --- a/src/passes/LocalCSE.cpp +++ b/src/passes/LocalCSE.cpp @@ -60,8 +60,11 @@ struct LocalCSE : public WalkerPass> { Index index; // the local we are assigned to, local.get that to reuse us EffectAnalyzer effects; - UsableInfo(Expression* value, Index index, PassOptions& passOptions) - : value(value), index(index), effects(passOptions, value) {} + UsableInfo(Expression* value, + Index index, + PassOptions& passOptions, + FeatureSet features) + : value(value), index(index), effects(passOptions, features, value) {} }; // a list of usables in a linear execution trace @@ -136,7 +139,7 @@ struct LocalCSE : public WalkerPass> { // pre operations Expression* curr = *currp; - EffectAnalyzer effects(self->getPassOptions()); + EffectAnalyzer effects(self->getPassOptions(), self->getModule()->features); if (effects.checkPre(curr)) { self->checkInvalidations(effects); } @@ -152,7 +155,7 @@ struct LocalCSE : public WalkerPass> { // post operations - EffectAnalyzer effects(self->getPassOptions()); + EffectAnalyzer effects(self->getPassOptions(), self->getModule()->features); if (effects.checkPost(curr)) { self->checkInvalidations(effects, curr); } @@ -194,7 +197,9 @@ struct LocalCSE : public WalkerPass> { } else { // not in table, add this, maybe we can help others later usables.emplace(std::make_pair( - hashed, UsableInfo(value, set->index, getPassOptions()))); + hashed, + UsableInfo( + value, set->index, getPassOptions(), getModule()->features))); } } } else if (auto* get = curr->dynCast()) { @@ -215,7 +220,8 @@ struct LocalCSE : public WalkerPass> { if (!value->type.isConcrete()) { return false; // don't bother with unreachable etc. } - if (EffectAnalyzer(getPassOptions(), value).hasSideEffects()) { + if (EffectAnalyzer(getPassOptions(), getModule()->features, value) + .hasSideEffects()) { return false; // we can't combine things with side effects } auto& options = getPassRunner()->options; -- cgit v1.2.3