summaryrefslogtreecommitdiff
path: root/src/ir/module-utils.h
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2020-03-16 13:51:31 -0700
committerGitHub <noreply@github.com>2020-03-16 13:51:31 -0700
commitaadec4526b339af4d2d2b92d3d64f07f935df7a5 (patch)
treeb1bb4d3154d6b0d922d8b5d82a83da2c23231bb9 /src/ir/module-utils.h
parent2b8e9248604b2419a69c268ab131366a7408ebaf (diff)
downloadbinaryen-aadec4526b339af4d2d2b92d3d64f07f935df7a5.tar.gz
binaryen-aadec4526b339af4d2d2b92d3d64f07f935df7a5.tar.bz2
binaryen-aadec4526b339af4d2d2b92d3d64f07f935df7a5.zip
Collect signatures from all block kinds (#2691)
Previously the signature collection mechanism responsible for populating the type section with signatures used by instructions only collected signatures from indirect call and block instructions. This works as long as all other control flow constructs like ifs, loops, and tries contain blocks with the same signature. But it is possible to have an if with non-block children, and we would need to collect its signature as well.
Diffstat (limited to 'src/ir/module-utils.h')
-rw-r--r--src/ir/module-utils.h18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/ir/module-utils.h b/src/ir/module-utils.h
index 0e18266e8..be924f742 100644
--- a/src/ir/module-utils.h
+++ b/src/ir/module-utils.h
@@ -19,6 +19,7 @@
#include "ir/find_all.h"
#include "ir/manipulation.h"
+#include "ir/properties.h"
#include "pass.h"
#include "support/unique_deferring_queue.h"
#include "wasm.h"
@@ -435,16 +436,19 @@ collectSignatures(Module& wasm,
if (func->imported()) {
return;
}
- struct TypeCounter : PostWalker<TypeCounter> {
+ struct TypeCounter
+ : PostWalker<TypeCounter, UnifiedExpressionVisitor<TypeCounter>> {
Counts& counts;
TypeCounter(Counts& counts) : counts(counts) {}
-
- void visitCallIndirect(CallIndirect* curr) { counts[curr->sig]++; }
- void visitBlock(Block* curr) {
- // TODO: Allow blocks to have input types as well
- if (curr->type.isMulti()) {
- counts[Signature(Type::none, curr->type)]++;
+ void visitExpression(Expression* curr) {
+ if (auto* call = curr->dynCast<CallIndirect>()) {
+ counts[call->sig]++;
+ } else if (Properties::isControlFlowStructure(curr)) {
+ // TODO: Allow control flow to have input types as well
+ if (curr->type.isMulti()) {
+ counts[Signature(Type::none, curr->type)]++;
+ }
}
}
};