summaryrefslogtreecommitdiff
path: root/src/ir/module-utils.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-07-11 10:31:31 -0700
committerGitHub <noreply@github.com>2024-07-11 10:31:31 -0700
commit5a1daf7727e768acebedd57464d2e0788afc85c5 (patch)
tree685da7a53cafb6d9a6b9afc3213b386425cf8489 /src/ir/module-utils.cpp
parente05f7629a27220c9951acc511d6f68a49e7b25d9 (diff)
downloadbinaryen-5a1daf7727e768acebedd57464d2e0788afc85c5.tar.gz
binaryen-5a1daf7727e768acebedd57464d2e0788afc85c5.tar.bz2
binaryen-5a1daf7727e768acebedd57464d2e0788afc85c5.zip
Monomorphization: Optimize constants (#6711)
Previously the pass would monomorphize a call when we were sending more refined types than the target expects. This generalizes the pass to also consider the case where we send a constant in a parameter. To achieve that, this refactors the pass to explicitly define the "call context", which is the code around the call (inputs and outputs) that may end up leading to optimization opportunities when combined with the target function. Also add comments about the overall design + roadmap. The existing test is mostly unmodified, and the diff there is smaller when ignoring whitespace. We do "regress" those tests by adding more local.set operations, as in the refactoring that makes things a lot simpler, that is, to handle the general case of an operand having either a refined type or be a constant, we copy it inside the function, which works either way. This "regression" is only in the testing version of the pass (the normal version runs optimizations, which would remove that extra code). This also enables the pass when GC is disabled. Previously we only handled refined types, so only GC could benefit. Add a test for MVP content specifically to show we operate there as well.
Diffstat (limited to 'src/ir/module-utils.cpp')
-rw-r--r--src/ir/module-utils.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/ir/module-utils.cpp b/src/ir/module-utils.cpp
index 5791ed77c..8ad127086 100644
--- a/src/ir/module-utils.cpp
+++ b/src/ir/module-utils.cpp
@@ -46,6 +46,15 @@ Function* copyFunction(Function* func,
Module& out,
Name newName,
std::optional<std::vector<Index>> fileIndexMap) {
+ auto ret = copyFunctionWithoutAdd(func, out, newName, fileIndexMap);
+ return out.addFunction(std::move(ret));
+}
+
+std::unique_ptr<Function>
+copyFunctionWithoutAdd(Function* func,
+ Module& out,
+ Name newName,
+ std::optional<std::vector<Index>> fileIndexMap) {
auto ret = std::make_unique<Function>();
ret->name = newName.is() ? newName : func->name;
ret->hasExplicitName = func->hasExplicitName;
@@ -71,7 +80,7 @@ Function* copyFunction(Function* func,
ret->base = func->base;
ret->noFullInline = func->noFullInline;
ret->noPartialInline = func->noPartialInline;
- return out.addFunction(std::move(ret));
+ return ret;
}
Global* copyGlobal(Global* global, Module& out) {