summaryrefslogtreecommitdiff
path: root/src/ir/iteration.h
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2020-02-26 18:20:24 -0800
committerGitHub <noreply@github.com>2020-02-26 18:20:24 -0800
commitf79faeb14e4da75f131c00c26796ae25ee96a7b7 (patch)
tree5b954daf160f83ae8227520055fb5b32fc1272f3 /src/ir/iteration.h
parentb17e84b491a309c9f15e7a502f115ece19404b11 (diff)
downloadbinaryen-f79faeb14e4da75f131c00c26796ae25ee96a7b7.tar.gz
binaryen-f79faeb14e4da75f131c00c26796ae25ee96a7b7.tar.bz2
binaryen-f79faeb14e4da75f131c00c26796ae25ee96a7b7.zip
Add EH support for CodeFolding (#2665)
This does two things: - Treats the target branch of `br_on_exn` as unoptimizables, because it is a conditional branch. - Makes sure we don't move expressions that contain `exnref.pop`, which should follow right after `catch`. - Adds `containsChild` utility function, which can search all children, optionally with limited depth. This was actually added to be used in CodeFolding but ended up not being used, but wasn't removed in case there will be uses later.
Diffstat (limited to 'src/ir/iteration.h')
-rw-r--r--src/ir/iteration.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/ir/iteration.h b/src/ir/iteration.h
index 289e5fa01..fd275f749 100644
--- a/src/ir/iteration.h
+++ b/src/ir/iteration.h
@@ -82,6 +82,30 @@ public:
Iterator end() const { return Iterator(*this, children.size()); }
};
+// Returns true if the current expression contains a certain kind of expression,
+// within the given depth of BFS. If depth is -1, this searches all children.
+template<typename T> bool containsChild(Expression* parent, int depth = -1) {
+ std::vector<Expression*> exprs;
+ std::vector<Expression*> nextExprs;
+ exprs.push_back(parent);
+ while (!exprs.empty() && depth > 0) {
+ for (auto* expr : exprs) {
+ for (auto* child : ChildIterator(expr)) {
+ if (child->is<T>()) {
+ return true;
+ }
+ nextExprs.push_back(child);
+ }
+ }
+ exprs.swap(nextExprs);
+ nextExprs.clear();
+ if (depth > 0) {
+ depth--;
+ }
+ }
+ return false;
+}
+
} // namespace wasm
#endif // wasm_ir_iteration_h