summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/binaryen-c.cpp8
-rw-r--r--src/binaryen-c.h8
-rw-r--r--src/js/binaryen.js-post.js8
-rw-r--r--src/pass.h6
-rw-r--r--src/passes/Inlining.cpp26
-rw-r--r--src/tools/optimization-options.h8
6 files changed, 35 insertions, 29 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp
index db9258d59..101af5172 100644
--- a/src/binaryen-c.cpp
+++ b/src/binaryen-c.cpp
@@ -3528,12 +3528,12 @@ void BinaryenSetOneCallerInlineMaxSize(BinaryenIndex size) {
globalPassOptions.inlining.oneCallerInlineMaxSize = size;
}
-int BinaryenGetAllowHeavyweight(void) {
- return globalPassOptions.inlining.allowHeavyweight;
+int BinaryenGetAllowInliningFunctionsWithLoops(void) {
+ return globalPassOptions.inlining.allowFunctionsWithLoops;
}
-void BinaryenSetAllowHeavyweight(int enabled) {
- globalPassOptions.inlining.allowHeavyweight = enabled;
+void BinaryenSetAllowInliningFunctionsWithLoops(int enabled) {
+ globalPassOptions.inlining.allowFunctionsWithLoops = enabled;
}
void BinaryenModuleRunPasses(BinaryenModuleRef module,
diff --git a/src/binaryen-c.h b/src/binaryen-c.h
index 6239befd2..893d44e3c 100644
--- a/src/binaryen-c.h
+++ b/src/binaryen-c.h
@@ -2124,13 +2124,13 @@ BINARYEN_API BinaryenIndex BinaryenGetOneCallerInlineMaxSize(void);
// Applies to all modules, globally.
BINARYEN_API void BinaryenSetOneCallerInlineMaxSize(BinaryenIndex size);
-// Gets whether heavyweight functions are allowed to be inlined.
+// Gets whether functions with loops are allowed to be inlined.
// Applies to all modules, globally.
-BINARYEN_API int BinaryenGetAllowHeavyweight(void);
+BINARYEN_API int BinaryenGetAllowInliningFunctionsWithLoops(void);
-// Sets whether heavyweight functions are allowed to be inlined.
+// Sets whether functions with loops are allowed to be inlined.
// Applies to all modules, globally.
-BINARYEN_API void BinaryenSetAllowHeavyweight(int enabled);
+BINARYEN_API void BinaryenSetAllowInliningFunctionsWithLoops(int enabled);
// Runs the specified passes on the module. Uses the currently set global
// optimize and shrink level.
diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js
index 057252f78..4e673ab4b 100644
--- a/src/js/binaryen.js-post.js
+++ b/src/js/binaryen.js-post.js
@@ -3031,13 +3031,13 @@ Module['setOneCallerInlineMaxSize'] = function(size) {
};
// Gets the value which allow inline functions that are not "lightweight".
-Module['getAllowHeavyweight'] = function() {
- return Boolean(Module['_BinaryenGetAllowHeavyweight']());
+Module['getAllowInliningFunctionsWithLoops'] = function() {
+ return Boolean(Module['_BinaryenGetAllowInliningFunctionsWithLoops']());
};
// Sets the value which allow inline functions that are not "lightweight".
-Module['setAllowHeavyweight'] = function(value) {
- Module['_BinaryenSetAllowHeavyweight'](value);
+Module['setAllowInliningFunctionsWithLoops'] = function(value) {
+ Module['_BinaryenSetAllowInliningFunctionsWithLoops'](value);
};
// Expression wrappers
diff --git a/src/pass.h b/src/pass.h
index f6dd52128..a3ee41d61 100644
--- a/src/pass.h
+++ b/src/pass.h
@@ -77,9 +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;
+ // Loops usually mean the function does heavy work, so the call overhead
+ // is not significant and we do not inline such functions by default.
+ bool allowFunctionsWithLoops = false;
};
struct PassOptions {
diff --git a/src/passes/Inlining.cpp b/src/passes/Inlining.cpp
index c8c8a3f7b..d7f132879 100644
--- a/src/passes/Inlining.cpp
+++ b/src/passes/Inlining.cpp
@@ -48,13 +48,15 @@ namespace wasm {
struct FunctionInfo {
std::atomic<Index> refs;
Index size;
- std::atomic<bool> lightweight;
+ bool hasCalls;
+ bool hasLoops;
bool usedGlobally; // in a table or export
FunctionInfo() {
refs = 0;
size = 0;
- lightweight = true;
+ hasCalls = false;
+ hasLoops = false;
usedGlobally = false;
}
@@ -79,12 +81,16 @@ struct FunctionInfo {
size <= options.inlining.oneCallerInlineMaxSize) {
return true;
}
- // more than one use, so we can't eliminate it after inlining,
+ // More than one use, so we can't eliminate it after inlining,
// so only worth it if we really care about speed and don't care
- // about size, and if it's lightweight so a good candidate for
- // speeding us up.
+ // about size. First, check if it has calls. In that case it is not
+ // likely to speed us up, and also if we want to inline such
+ // functions we would need to be careful to avoid infinite recursion.
+ if (hasCalls) {
+ return false;
+ }
return options.optimizeLevel >= 3 && options.shrinkLevel == 0 &&
- (lightweight || options.inlining.allowHeavyweight);
+ (!hasLoops || options.inlining.allowFunctionsWithLoops);
}
};
@@ -101,16 +107,16 @@ struct FunctionInfoScanner
}
void visitLoop(Loop* curr) {
- // having a loop is not lightweight
- (*infos)[getFunction()->name].lightweight = false;
+ // having a loop
+ (*infos)[getFunction()->name].hasLoops = true;
}
void visitCall(Call* curr) {
// can't add a new element in parallel
assert(infos->count(curr->target) > 0);
(*infos)[curr->target].refs++;
- // having a call is not lightweight
- (*infos)[getFunction()->name].lightweight = false;
+ // having a call
+ (*infos)[getFunction()->name].hasCalls = true;
}
void visitRefFunc(RefFunc* curr) {
diff --git a/src/tools/optimization-options.h b/src/tools/optimization-options.h
index ff43b7213..72f478329 100644
--- a/src/tools/optimization-options.h
+++ b/src/tools/optimization-options.h
@@ -165,12 +165,12 @@ struct OptimizationOptions : public ToolOptions {
passOptions.inlining.oneCallerInlineMaxSize =
static_cast<Index>(atoi(argument.c_str()));
})
- .add("--inline-heavyweight-functions",
- "-ihf",
- "Allow inlining heavyweight functions",
+ .add("--inline-functions-with-loops",
+ "-ifwl",
+ "Allow inlining functions with loops",
Options::Arguments::Zero,
[this](Options* o, const std::string&) {
- passOptions.inlining.allowHeavyweight = true;
+ passOptions.inlining.allowFunctionsWithLoops = true;
})
.add("--ignore-implicit-traps",
"-iit",