summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2024-11-18 15:43:11 -0800
committerGitHub <noreply@github.com>2024-11-18 15:43:11 -0800
commit25b8e6a714d2217e8735a925bc751900bce09d53 (patch)
tree752e3a6f51b07bd1b02de73523c2f663257f7b40 /src/wasm
parent08b7496306915dbe11030a7a4cf79207f9460d2f (diff)
downloadbinaryen-25b8e6a714d2217e8735a925bc751900bce09d53.tar.gz
binaryen-25b8e6a714d2217e8735a925bc751900bce09d53.tar.bz2
binaryen-25b8e6a714d2217e8735a925bc751900bce09d53.zip
Use hints when generating fresh labels in IRBuilder (#7086)
IRBuilder often has to generate new label names for blocks and other scopes. Previously it would generate each new name by starting with "block" or "label" and incrementing a suffix until finding a fresh name, but this made name generation quadratic in the number of names to generate. To spend less time generating names, track a hint index at which to start looking for a fresh name and increment it every time a name is generated. This speeds up a version of the binary parser that uses IRBuilder by about 15%.
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/wasm-ir-builder.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp
index 5253c91ee..a73c7f2ac 100644
--- a/src/wasm/wasm-ir-builder.cpp
+++ b/src/wasm/wasm-ir-builder.cpp
@@ -987,6 +987,8 @@ Result<> IRBuilder::visitEnd() {
EHUtils::handleBlockNestedPops(func, wasm);
}
this->func = nullptr;
+ blockHint = 0;
+ labelHint = 0;
} else if (auto* block = scope.getBlock()) {
assert(*expr == block);
block->name = scope.label;
@@ -1073,9 +1075,9 @@ Result<Name> IRBuilder::getLabelName(Index label, bool forDelegate) {
if (!scopeLabel) {
// The scope does not already have a name, so we need to create one.
if ((*scope)->getBlock()) {
- scopeLabel = makeFresh("block");
+ scopeLabel = makeFresh("block", blockHint++);
} else {
- scopeLabel = makeFresh("label");
+ scopeLabel = makeFresh("label", labelHint++);
}
}
if (!forDelegate) {