diff options
author | Max Graey <maxgraey@gmail.com> | 2020-08-27 05:27:41 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-26 19:27:41 -0700 |
commit | 547e2be14d1f8f9b21905baee87b1946045b0fe7 (patch) | |
tree | 1f3381dd71eab93424571adaf33367deafbb4b46 /src | |
parent | a61b9dff9be3da4d4c56f92f494e5f2914f32e1e (diff) | |
download | binaryen-547e2be14d1f8f9b21905baee87b1946045b0fe7.tar.gz binaryen-547e2be14d1f8f9b21905baee87b1946045b0fe7.tar.bz2 binaryen-547e2be14d1f8f9b21905baee87b1946045b0fe7.zip |
Add allowHeavyweight inlining option (#3032)
As discussed in #2921, this allows inlining of functions not identified
as "lightweight" (that include a loop, for example).
Diffstat (limited to 'src')
-rw-r--r-- | src/binaryen-c.cpp | 8 | ||||
-rw-r--r-- | src/js/binaryen.js-post.js | 10 | ||||
-rw-r--r-- | src/pass.h | 3 | ||||
-rw-r--r-- | src/passes/Inlining.cpp | 2 | ||||
-rw-r--r-- | src/tools/optimization-options.h | 7 |
5 files changed, 29 insertions, 1 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index 3e85a417b..6776b785c 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -3528,6 +3528,14 @@ void BinaryenSetOneCallerInlineMaxSize(BinaryenIndex size) { globalPassOptions.inlining.oneCallerInlineMaxSize = size; } +bool BinaryenGetAllowHeavyweight(void) { + return globalPassOptions.inlining.allowHeavyweight; +} + +void BinaryenSetAllowHeavyweight(bool enabled) { + globalPassOptions.inlining.allowHeavyweight = enabled; +} + void BinaryenModuleRunPasses(BinaryenModuleRef module, const char** passes, BinaryenIndex numPasses) { diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index a9244c2d2..f8a0b8590 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -3030,6 +3030,16 @@ Module['setOneCallerInlineMaxSize'] = function(size) { Module['_BinaryenSetOneCallerInlineMaxSize'](size); }; +// Gets the value which allow inline functions that are not "lightweight". +Module['getAllowHeavyweight'] = function() { + return Module['_BinaryenGetAllowHeavyweight'](); +}; + +// Sets the value which allow inline functions that are not "lightweight". +Module['setAllowHeavyweight'] = function(value) { + Module['_BinaryenSetAllowHeavyweight'](value); +}; + // Expression wrappers // Makes a wrapper class with the specified static members while diff --git a/src/pass.h b/src/pass.h index 8b8e73fa0..f6dd52128 100644 --- a/src/pass.h +++ b/src/pass.h @@ -77,6 +77,9 @@ struct InliningOptions { // Function size which we inline when there is only one caller. // FIXME: this should logically be higher than flexibleInlineMaxSize. Index oneCallerInlineMaxSize = 15; + // Allow inlining of functions that are not "lightweight" in the sense the + // inlining pass estimates. + bool allowHeavyweight = false; }; struct PassOptions { diff --git a/src/passes/Inlining.cpp b/src/passes/Inlining.cpp index 5737359a3..c8c8a3f7b 100644 --- a/src/passes/Inlining.cpp +++ b/src/passes/Inlining.cpp @@ -84,7 +84,7 @@ struct FunctionInfo { // about size, and if it's lightweight so a good candidate for // speeding us up. return options.optimizeLevel >= 3 && options.shrinkLevel == 0 && - lightweight; + (lightweight || options.inlining.allowHeavyweight); } }; diff --git a/src/tools/optimization-options.h b/src/tools/optimization-options.h index ef5a7d67a..ff43b7213 100644 --- a/src/tools/optimization-options.h +++ b/src/tools/optimization-options.h @@ -165,6 +165,13 @@ struct OptimizationOptions : public ToolOptions { passOptions.inlining.oneCallerInlineMaxSize = static_cast<Index>(atoi(argument.c_str())); }) + .add("--inline-heavyweight-functions", + "-ihf", + "Allow inlining heavyweight functions", + Options::Arguments::Zero, + [this](Options* o, const std::string&) { + passOptions.inlining.allowHeavyweight = true; + }) .add("--ignore-implicit-traps", "-iit", "Optimize under the helpful assumption that no surprising traps " |