diff options
Diffstat (limited to 'src/ast_utils.h')
-rw-r--r-- | src/ast_utils.h | 17 |
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; } |