summaryrefslogtreecommitdiff
path: root/src/ir/effects.h
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-08-31 10:58:03 -0700
committerGitHub <noreply@github.com>2021-08-31 10:58:03 -0700
commit7d966528f603e65dacbf25f585a5accc46470bbd (patch)
treea07634a95dee38a611bc7fc29bc0828a7e8d1dfe /src/ir/effects.h
parent41fff9e2284e9be6e8a99da05beda54f398b0305 (diff)
downloadbinaryen-7d966528f603e65dacbf25f585a5accc46470bbd.tar.gz
binaryen-7d966528f603e65dacbf25f585a5accc46470bbd.tar.bz2
binaryen-7d966528f603e65dacbf25f585a5accc46470bbd.zip
Add a Module parameter to EffectAnalyzer. NFC (#4115)
Knowing the module will allow us to do more analysis in the effect analyzer. For now, this just refactors the code to allow providing a module instead of features, and to infer the features from the module. This actually shortens the code in most places which is nice (just pass module instead of module->features). This modifies basically all callers to use the new module form, except for the fallthrough logic. That would require some more refactoring, so to keep this PR reasonably small that is not yet done.
Diffstat (limited to 'src/ir/effects.h')
-rw-r--r--src/ir/effects.h28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/ir/effects.h b/src/ir/effects.h
index e8fba8e3a..d34f8e5b2 100644
--- a/src/ir/effects.h
+++ b/src/ir/effects.h
@@ -31,7 +31,19 @@ public:
Expression* ast = nullptr)
: ignoreImplicitTraps(passOptions.ignoreImplicitTraps),
trapsNeverHappen(passOptions.trapsNeverHappen),
- debugInfo(passOptions.debugInfo), features(features) {
+ debugInfo(passOptions.debugInfo), module(nullptr), features(features) {
+ if (ast) {
+ walk(ast);
+ }
+ }
+
+ EffectAnalyzer(const PassOptions& passOptions,
+ Module& module,
+ Expression* ast = nullptr)
+ : ignoreImplicitTraps(passOptions.ignoreImplicitTraps),
+ trapsNeverHappen(passOptions.trapsNeverHappen),
+ debugInfo(passOptions.debugInfo), module(&module),
+ features(module.features) {
if (ast) {
walk(ast);
}
@@ -40,6 +52,7 @@ public:
bool ignoreImplicitTraps;
bool trapsNeverHappen;
bool debugInfo;
+ Module* module;
FeatureSet features;
// Walk an expression and all its children.
@@ -680,6 +693,15 @@ public:
return !aEffects.invalidates(bEffects);
}
+ static bool canReorder(const PassOptions& passOptions,
+ Module& module,
+ Expression* a,
+ Expression* b) {
+ EffectAnalyzer aEffects(passOptions, module, a);
+ EffectAnalyzer bEffects(passOptions, module, b);
+ return !aEffects.invalidates(bEffects);
+ }
+
// C-API
enum SideEffects : uint32_t {
@@ -767,9 +789,9 @@ private:
class ShallowEffectAnalyzer : public EffectAnalyzer {
public:
ShallowEffectAnalyzer(const PassOptions& passOptions,
- FeatureSet features,
+ Module& module,
Expression* ast = nullptr)
- : EffectAnalyzer(passOptions, features) {
+ : EffectAnalyzer(passOptions, module) {
if (ast) {
visit(ast);
}