diff options
author | Alon Zakai <azakai@google.com> | 2023-03-21 14:45:02 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-21 14:45:02 -0700 |
commit | 39e3490793919261d11921b7490e252e35ca278a (patch) | |
tree | 4ff7fa77ef575ea3ccaf3aaf59c2f2a69a366dc3 | |
parent | 0f9c9b0a61c36a802319fd8c3bbcb8f2d8126c55 (diff) | |
download | binaryen-39e3490793919261d11921b7490e252e35ca278a.tar.gz binaryen-39e3490793919261d11921b7490e252e35ca278a.tar.bz2 binaryen-39e3490793919261d11921b7490e252e35ca278a.zip |
Use a SmallVector in MergeBlocks [NFC] (#5594)
This makes the pass 2-3% faster in some measurements I did locally.
Noticed when profiling for #5561 (comment)
Helps #4165
-rw-r--r-- | src/passes/MergeBlocks.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/passes/MergeBlocks.cpp b/src/passes/MergeBlocks.cpp index 45b9ebd9e..9a0b5d27b 100644 --- a/src/passes/MergeBlocks.cpp +++ b/src/passes/MergeBlocks.cpp @@ -77,6 +77,7 @@ #include <ir/iteration.h> #include <ir/utils.h> #include <pass.h> +#include <support/small_vector.h> #include <wasm-builder.h> #include <wasm.h> @@ -330,9 +331,13 @@ static void optimizeBlock(Block* curr, } // There is something to do! bool keepingPart = keepStart < keepEnd; - // Create a new merged list, and fill in the code before the - // child block we are merging in. TODO better efficiency - ExpressionList merged(module->allocator); + // Create a new merged list, and fill in the code before the child block + // we are merging in. It is efficient to use a small vector here because + // most blocks are fairly small, and this way we copy once into the arena + // we use for Block lists a single time at the end (arena allocations + // can't be freed, so any temporary allocations while we add to the list + // would end up wasted). + SmallVector<Expression*, 10> merged; for (size_t j = 0; j < i; j++) { merged.push_back(list[j]); } @@ -383,7 +388,7 @@ static void optimizeBlock(Block* curr, } } } - list.swap(merged); + list.set(merged); more = true; changed = true; break; |