diff options
author | Thomas Lively <tlively@google.com> | 2024-05-13 17:10:23 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-13 17:10:23 -0700 |
commit | 020d08e01ff506099c8293e69cd03f5f75f562d9 (patch) | |
tree | c61320e25d5945e9cd56a69d1fb013f867898951 /src/wasm-stack.h | |
parent | 924533fbcd0181f4460a13adc5762ee52f97de58 (diff) | |
download | binaryen-020d08e01ff506099c8293e69cd03f5f75f562d9.tar.gz binaryen-020d08e01ff506099c8293e69cd03f5f75f562d9.tar.bz2 binaryen-020d08e01ff506099c8293e69cd03f5f75f562d9.zip |
Simplify scratch local calculation (#6583)
Change `countScratchLocals` to return the count and type of necessary scratch
locals. It used to encode them as keys in the global map from scratch local
types to local indices, which could not handle having more than one scratch
local of a given type and was generally harder to reason about due to its use of
global state. Take the opportunity to avoid emitting unnecessary scratch locals
for `TupleExtract` expressions that will be optimized to not use them.
Also simplify and better document the calculation of the mapping from IR indices
to binary indices for all locals, scratch and non-scratch.
Diffstat (limited to 'src/wasm-stack.h')
-rw-r--r-- | src/wasm-stack.h | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/wasm-stack.h b/src/wasm-stack.h index ae453f9de..fc38d07a4 100644 --- a/src/wasm-stack.h +++ b/src/wasm-stack.h @@ -146,13 +146,14 @@ private: // type => number of locals of that type in the compact form std::unordered_map<Type, size_t> numLocalsByType; - void noteLocalType(Type type); + void noteLocalType(Type type, Index count = 1); // Keeps track of the binary index of the scratch locals used to lower - // tuple.extract. + // tuple.extract. If there are multiple scratch locals of the same type, they + // are contiguous and this map holds the index of the first. InsertOrderedMap<Type, Index> scratchLocals; - void countScratchLocals(); - void setScratchLocals(); + // Return the type and number of required scratch locals. + InsertOrderedMap<Type, Index> countScratchLocals(); // 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 |