From aadec4526b339af4d2d2b92d3d64f07f935df7a5 Mon Sep 17 00:00:00 2001 From: Thomas Lively <7121787+tlively@users.noreply.github.com> Date: Mon, 16 Mar 2020 13:51:31 -0700 Subject: 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. --- src/ir/module-utils.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/ir/module-utils.h') 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 { + struct TypeCounter + : PostWalker> { 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()) { + 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)]++; + } } } }; -- cgit v1.2.3