summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-03-29 11:33:52 -0700
committerGitHub <noreply@github.com>2021-03-29 11:33:52 -0700
commit1a6efdb4233a077bc6e5e8a340baf5672bb5bced (patch)
treef814f47930fe8a2312cd23848ea63ff7e13bb9dc /src
parent9c1d69f6596b76fe83bff17709b92f8cc2054a31 (diff)
downloadbinaryen-1a6efdb4233a077bc6e5e8a340baf5672bb5bced.tar.gz
binaryen-1a6efdb4233a077bc6e5e8a340baf5672bb5bced.tar.bz2
binaryen-1a6efdb4233a077bc6e5e8a340baf5672bb5bced.zip
Inlining: Always inline single-use functions (#3730)
This implements emscripten-core/emscripten#13744 Inlining functions with a single use allows us to remove the function afterward. That looks highly beneficial, shrinking every single benchmark in emscripten's benchmark suite, by an average of 2% on the macrobenchmarks and 3.5% on all of them. Speed also improves, although mostly on the microbenchmarks so that might be less realistic. There may be a slight downside to startup time due to emitting larger functions, but given the baseline compilers in VMs these days it seems worth it, as the delay would be just to get to the upper tier. On the benchmark suite the risk seems low. See more details in the PR above.
Diffstat (limited to 'src')
-rw-r--r--src/pass.h7
-rw-r--r--src/tools/optimization-options.h9
2 files changed, 8 insertions, 8 deletions
diff --git a/src/pass.h b/src/pass.h
index 643d9a25a..dd7c67bc1 100644
--- a/src/pass.h
+++ b/src/pass.h
@@ -69,9 +69,10 @@ struct InliningOptions {
// More generally, with 2 items we may have a local.get, but no way to
// require it to be saved instead of directly consumed.
Index alwaysInlineMaxSize = 2;
- // Function size which we inline when there is only one caller.
- // FIXME: this should logically be higher than flexibleInlineMaxSize.
- Index oneCallerInlineMaxSize = 15;
+ // Function size which we inline when there is only one caller. By default we
+ // inline all such functions (as after inlining we can remove the original
+ // function).
+ Index oneCallerInlineMaxSize = -1;
// Function size above which we never inline, ignoring the various flexible
// factors (like whether we are optimizing for size or speed) that could
// influence us.
diff --git a/src/tools/optimization-options.h b/src/tools/optimization-options.h
index 4f5c9e0d1..0e6157473 100644
--- a/src/tools/optimization-options.h
+++ b/src/tools/optimization-options.h
@@ -155,13 +155,12 @@ struct OptimizationOptions : public ToolOptions {
.add("--one-caller-inline-max-function-size",
"-ocimfs",
"Max size of functions that are inlined when there is only one "
- "caller (default " +
- std::to_string(InliningOptions().oneCallerInlineMaxSize) +
- "). Reason this is not unbounded is that some "
- "implementations may have a hard time optimizing really large "
- "functions",
+ "caller (default -1, which means all such functions are inlined)",
Options::Arguments::One,
[this](Options* o, const std::string& argument) {
+ static_assert(InliningOptions().oneCallerInlineMaxSize ==
+ Index(-1),
+ "the help text here is written to assume -1");
passOptions.inlining.oneCallerInlineMaxSize =
static_cast<Index>(atoi(argument.c_str()));
})