summaryrefslogtreecommitdiff
path: root/src/wasm-stack.h
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2023-09-18 21:54:14 -0700
committerGitHub <noreply@github.com>2023-09-18 21:54:14 -0700
commita51bd6df919a5b79574f0996a760cc20cb05697e (patch)
tree32f67c9568aaee16b67ce0a4e6df1df2fb487036 /src/wasm-stack.h
parent6bab227860a6873204141e5ec9b14ed08d77fc62 (diff)
downloadbinaryen-a51bd6df919a5b79574f0996a760cc20cb05697e.tar.gz
binaryen-a51bd6df919a5b79574f0996a760cc20cb05697e.tar.bz2
binaryen-a51bd6df919a5b79574f0996a760cc20cb05697e.zip
Reland "Optimize tuple.extract of gets in BinaryInstWriter" (#5955)
In general, the binary lowering of tuple.extract expects that all the tuple values are on top of the stack, so it inserts drops and possibly uses a scratch local to ensure only the extracted value is left. However, when the extracted tuple expression is a local.get, local.tee, or global.get, it's much more efficient to change the lowering of the get or tee to ensure that only the extracted value is on the stack to begin with. Implement that optimization in the binary writer.
Diffstat (limited to 'src/wasm-stack.h')
-rw-r--r--src/wasm-stack.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/wasm-stack.h b/src/wasm-stack.h
index 03ec4eef5..1f66212ad 100644
--- a/src/wasm-stack.h
+++ b/src/wasm-stack.h
@@ -148,6 +148,11 @@ private:
InsertOrderedMap<Type, Index> scratchLocals;
void countScratchLocals();
void setScratchLocals();
+
+ // local.get, local.tee, and glboal.get expressions that will be followed by
+ // tuple.extracts. We can optimize these by getting only the local for the
+ // extracted index.
+ std::unordered_map<Expression*, Index> extractedGets;
};
// Takes binaryen IR and converts it to something else (binary or stack IR)