summaryrefslogtreecommitdiff
path: root/src/passes/param-utils.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-03-25 16:33:53 -0700
committerGitHub <noreply@github.com>2022-03-25 16:33:53 -0700
commit11932cc31e88d3d368714fcca43df979f7694bd1 (patch)
tree889faa7d6c6e2e261970ea776e3183202e9d6cba /src/passes/param-utils.cpp
parent3a1953a1f417eb2f588eeb35bf26a3df6ea8f8e1 (diff)
downloadbinaryen-11932cc31e88d3d368714fcca43df979f7694bd1.tar.gz
binaryen-11932cc31e88d3d368714fcca43df979f7694bd1.tar.bz2
binaryen-11932cc31e88d3d368714fcca43df979f7694bd1.zip
[Wasm GC] Signature Pruning (#4545)
This adds a new signature-pruning pass that prunes parameters from signature types where those parameters are never used in any function that has that type. This is similar to DeadArgumentElimination but works on a set of functions, and it can handle indirect calls. Also move a little code from SignatureRefining into a shared place to avoid duplication of logic to update signature types. This pattern happens in j2wasm code, for example if all method functions for some virtual method just return a constant and do not use the this pointer.
Diffstat (limited to 'src/passes/param-utils.cpp')
-rw-r--r--src/passes/param-utils.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/passes/param-utils.cpp b/src/passes/param-utils.cpp
index ded96a826..ae641fd26 100644
--- a/src/passes/param-utils.cpp
+++ b/src/passes/param-utils.cpp
@@ -62,15 +62,24 @@ bool removeParameter(const std::vector<Function*>& funcs,
// Check if none of the calls has a param with side effects that we cannot
// remove (as if we can remove them, we will simply do that when we remove the
// parameter). Note: flattening the IR beforehand can help here.
+ auto hasBadEffects = [&](ExpressionList& operands) {
+ return EffectAnalyzer(runner->options, *module, operands[index])
+ .hasUnremovableSideEffects();
+ };
bool callParamsAreValid =
std::none_of(calls.begin(), calls.end(), [&](Call* call) {
- auto* operand = call->operands[index];
- return EffectAnalyzer(runner->options, *module, operand)
- .hasUnremovableSideEffects();
+ return hasBadEffects(call->operands);
});
if (!callParamsAreValid) {
return false;
}
+ bool callRefParamsAreValid =
+ std::none_of(callRefs.begin(), callRefs.end(), [&](CallRef* call) {
+ return hasBadEffects(call->operands);
+ });
+ if (!callRefParamsAreValid) {
+ return false;
+ }
// The type must be valid for us to handle as a local (since we
// replace the parameter with a local).