diff options
author | Thomas Lively <tlively@google.com> | 2024-04-29 13:17:14 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-29 13:17:14 -0700 |
commit | be001f7e214c31ee1d7864a7081634b8986d72bf (patch) | |
tree | 87a7d609cffbb86b72b05d9cca881cce697dfa2c /src | |
parent | dcc5b7ba0149a85d2784520c262b83df488705f5 (diff) | |
download | binaryen-be001f7e214c31ee1d7864a7081634b8986d72bf.tar.gz binaryen-be001f7e214c31ee1d7864a7081634b8986d72bf.tar.bz2 binaryen-be001f7e214c31ee1d7864a7081634b8986d72bf.zip |
[Parser] Re-use blocks instead of wrapping where possible (#6552)
When the input has branches to block scope, IR builder generally has to add a
wrapper block with a label name for the branch to target. To reduce the parsed
IR size, add a special case for when the wrapped expression is already an
unnamed block. In that case we can simply add the label to the existing block
instead of creating a new wrapper block.
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm/wasm-ir-builder.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp index 6322a5786..91e990180 100644 --- a/src/wasm/wasm-ir-builder.cpp +++ b/src/wasm/wasm-ir-builder.cpp @@ -929,13 +929,18 @@ Result<> IRBuilder::visitEnd() { auto maybeWrapForLabel = [&](Expression* curr) -> Expression* { bool isTry = scope.getTry() || scope.getCatch() || scope.getCatchAll(); auto& label = isTry ? scope.branchLabel : scope.label; - if (label) { - return builder.makeBlock(label, - {curr}, - scope.labelUsed ? originalScopeType - : scope.getResultType()); + if (!label) { + return curr; } - return curr; + auto blockType = + scope.labelUsed ? originalScopeType : scope.getResultType(); + // We can re-use unnamed blocks instead of wrapping them. + if (auto* block = curr->dynCast<Block>(); block && !block->name) { + block->name = label; + block->type = blockType; + return block; + } + return builder.makeBlock(label, {curr}, blockType); }; if (auto* func = scope.getFunction()) { |