summaryrefslogtreecommitdiff
path: root/src/wasm-type.h
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2023-11-08 22:20:15 +0100
committerGitHub <noreply@github.com>2023-11-08 13:20:15 -0800
commitd6df91bcd0d9a67c63e336ae05f095cbcbf68df7 (patch)
tree02f8b9c3dc21595bde5f45a1cb330cc8bcfe0c30 /src/wasm-type.h
parent784960180eac208a34eb33415267d977034971df (diff)
downloadbinaryen-d6df91bcd0d9a67c63e336ae05f095cbcbf68df7.tar.gz
binaryen-d6df91bcd0d9a67c63e336ae05f095cbcbf68df7.tar.bz2
binaryen-d6df91bcd0d9a67c63e336ae05f095cbcbf68df7.zip
[analysis] Add an experimental TypeGeneralizing optimization (#6080)
This new optimization will eventually weaken casts by generalizing (i.e. un-refining) their output types. If a cast is weakened enough that its output type is a supertype of its input type, the cast will be able to be removed by OptimizeInstructions. Unlike refining cast inputs, generalizing cast outputs can break module validation. For example, if the result of a cast is stored to a local and the cast is weakened enough that its output type is no longer a subtype of that local's type, then the local.set after the cast will no longer validate. To avoid this validation failure, this optimization would have to generalize the type of the local as well. In general, the more we can generalize the types of program locations, the more we can weaken casts of values that flow into those locations. This initial implementation only generalizes the types of locals and does not actually weaken casts yet. It serves as a proof of concept for the analysis required to perform the full optimization, though. The analysis uses the new analysis framework to perform a reverse analysis tracking type requirements for each local and reference-typed stack value in a function. Planned and potential future work includes: - Implementing the transfer function for all kinds of expressions. - Tracking requirements on the dynamic types of each location to generalize allocations as well. - Making the analysis interprocedural and generalizing the types of more program locations. - Optimizing tuple-typed locations. - Generalizing only those locations necessary to eliminate at least one cast (although this would make the anlysis bidirectional, so it is probably better left to separate passes).
Diffstat (limited to 'src/wasm-type.h')
-rw-r--r--src/wasm-type.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/wasm-type.h b/src/wasm-type.h
index 0061b9626..573cd9102 100644
--- a/src/wasm-type.h
+++ b/src/wasm-type.h
@@ -390,6 +390,9 @@ public:
// Get the bottom heap type for this heap type's hierarchy.
BasicHeapType getBottom() const;
+ // Get the top heap type for this heap type's hierarchy.
+ BasicHeapType getTop() const;
+
// Get the recursion group for this non-basic type.
RecGroup getRecGroup() const;
size_t getRecGroupIndex() const;