summaryrefslogtreecommitdiff
path: root/src/ast_utils.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-04-07 19:16:37 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-04-07 19:19:40 -0700
commite444aefddd6e491e193e5eb53beae0c3f9252422 (patch)
tree4b03449ed3bf0764c5ea5eca910d74414604063b /src/ast_utils.h
parent0a03aacd4ea32476714066eebe0cded77c87ca66 (diff)
downloadbinaryen-e444aefddd6e491e193e5eb53beae0c3f9252422.tar.gz
binaryen-e444aefddd6e491e193e5eb53beae0c3f9252422.tar.bz2
binaryen-e444aefddd6e491e193e5eb53beae0c3f9252422.zip
handle loops in effect analyzer
Diffstat (limited to 'src/ast_utils.h')
-rw-r--r--src/ast_utils.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/ast_utils.h b/src/ast_utils.h
index bf42d10e1..5ab427178 100644
--- a/src/ast_utils.h
+++ b/src/ast_utils.h
@@ -53,6 +53,7 @@ struct EffectAnalyzer : public WasmWalker<EffectAnalyzer> {
bool accessesLocal() { return readsLocal || writesLocal; }
bool accessesMemory() { return calls || readsMemory || writesMemory; }
bool hasSideEffects() { return calls || writesLocal || writesMemory; }
+ bool hasAnything() { return branches || calls || readsLocal || writesLocal || readsMemory || writesMemory; }
// checks if these effects would invalidate another set (e.g., if we write, we invalidate someone that reads, they can't be moved past us)
bool invalidates(EffectAnalyzer& other) {
@@ -61,7 +62,23 @@ struct EffectAnalyzer : public WasmWalker<EffectAnalyzer> {
|| (accessesMemory() && (other.writesMemory || other.calls)) || (accessesLocal() && other.writesLocal);
}
+ // the checks above happen after the node's children were processed, in the order of execution
+ // we must also check for control flow that happens before the children, i.e., loops
+ bool checkPre(Expression* curr) {
+ if (curr->is<Loop>()) {
+ branches = true;
+ return true;
+ }
+ return false;
+ }
+
+ bool checkPost(Expression* curr) {
+ visit(curr);
+ return hasAnything();
+ }
+
void visitBlock(Block *curr) { branches = true; }
+ void visitLoop(Loop *curr) { branches = true; }
void visitIf(If *curr) { branches = true; }
void visitBreak(Break *curr) { branches = true; }
void visitSwitch(Switch *curr) { branches = true; }