Skip to content

Add C-/JS-APIs for inlining limits #2655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3958,6 +3958,54 @@ void BinaryenClearPassArguments(void) {
globalPassOptions.arguments.clear();
}

BinaryenIndex BinaryenGetAlwaysInlineMaxSize(void) {
if (tracing) {
std::cout << " BinaryenGetAlwaysInlineMaxSize();\n";
}

return globalPassOptions.inlining.alwaysInlineMaxSize;
}

void BinaryenSetAlwaysInlineMaxSize(BinaryenIndex size) {
if (tracing) {
std::cout << " BinaryenSetAlwaysInlineMaxSize(" << size << ");\n";
}

globalPassOptions.inlining.alwaysInlineMaxSize = size;
}

BinaryenIndex BinaryenGetFlexibleInlineMaxSize(void) {
if (tracing) {
std::cout << " BinaryenGetFlexibleInlineMaxSize();\n";
}

return globalPassOptions.inlining.flexibleInlineMaxSize;
}

void BinaryenSetFlexibleInlineMaxSize(BinaryenIndex size) {
if (tracing) {
std::cout << " BinaryenSetFlexibleInlineMaxSize(" << size << ");\n";
}

globalPassOptions.inlining.flexibleInlineMaxSize = size;
}

BinaryenIndex BinaryenGetOneCallerInlineMaxSize(void) {
if (tracing) {
std::cout << " BinaryenGetOneCallerInlineMaxSize();\n";
}

return globalPassOptions.inlining.oneCallerInlineMaxSize;
}

void BinaryenSetOneCallerInlineMaxSize(BinaryenIndex size) {
if (tracing) {
std::cout << " BinaryenSetOneCallerInlineMaxSize(" << size << ");\n";
}

globalPassOptions.inlining.oneCallerInlineMaxSize = size;
}

void BinaryenModuleRunPasses(BinaryenModuleRef module,
const char** passes,
BinaryenIndex numPasses) {
Expand Down
24 changes: 24 additions & 0 deletions src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,30 @@ BINARYEN_API void BinaryenSetPassArgument(const char* name, const char* value);
// Applies to all modules, globally.
BINARYEN_API void BinaryenClearPassArguments();

// Gets the function size at which we always inline.
// Applies to all modules, globally.
BINARYEN_API BinaryenIndex BinaryenGetAlwaysInlineMaxSize(void);

// Sets the function size at which we always inline.
// Applies to all modules, globally.
BINARYEN_API void BinaryenSetAlwaysInlineMaxSize(BinaryenIndex size);

// Gets the function size which we inline when functions are lightweight.
// Applies to all modules, globally.
BINARYEN_API BinaryenIndex BinaryenGetFlexibleInlineMaxSize(void);

// Sets the function size which we inline when functions are lightweight.
// Applies to all modules, globally.
BINARYEN_API void BinaryenSetFlexibleInlineMaxSize(BinaryenIndex size);

// Gets the function size which we inline when there is only one caller.
// Applies to all modules, globally.
BINARYEN_API BinaryenIndex BinaryenGetOneCallerInlineMaxSize(void);

// Sets the function size which we inline when there is only one caller.
// Applies to all modules, globally.
BINARYEN_API void BinaryenSetOneCallerInlineMaxSize(BinaryenIndex size);

// Runs the specified passes on the module. Uses the currently set global
// optimize and shrink level.
BINARYEN_API void BinaryenModuleRunPasses(BinaryenModuleRef module,
Expand Down
30 changes: 30 additions & 0 deletions src/js/binaryen.js-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -2928,6 +2928,36 @@ Module['clearPassArguments'] = function() {
Module['_BinaryenClearPassArguments']();
};

// Gets the function size at which we always inline.
Module['getAlwaysInlineMaxSize'] = function() {
return Module['_BinaryenGetAlwaysInlineMaxSize']();
};

// Sets the function size at which we always inline.
Module['setAlwaysInlineMaxSize'] = function(size) {
Module['_BinaryenSetAlwaysInlineMaxSize'](size);
};

// Gets the function size which we inline when functions are lightweight.
Module['getFlexibleInlineMaxSize'] = function() {
return Module['_BinaryenGetFlexibleInlineMaxSize']();
};

// Sets the function size which we inline when functions are lightweight.
Module['setFlexibleInlineMaxSize'] = function(size) {
Module['_BinaryenSetFlexibleInlineMaxSize'](size);
};

// Gets the function size which we inline when there is only one caller.
Module['getOneCallerInlineMaxSize'] = function() {
return Module['_BinaryenGetOneCallerInlineMaxSize']();
};

// Sets the function size which we inline when there is only one caller.
Module['setOneCallerInlineMaxSize'] = function(size) {
Module['_BinaryenSetOneCallerInlineMaxSize'](size);
};

// Enables or disables C-API tracing
Module['setAPITracing'] = function(on) {
return Module['_BinaryenSetAPITracing'](on);
Expand Down
15 changes: 15 additions & 0 deletions test/binaryen.js/inlining-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
binaryen.setAPITracing(true);

console.log("// alwaysInlineMaxSize=" + binaryen.getAlwaysInlineMaxSize());
binaryen.setAlwaysInlineMaxSize(11);
assert(binaryen.getAlwaysInlineMaxSize() == 11);

console.log("// flexibleInlineMaxSize=" + binaryen.getFlexibleInlineMaxSize());
binaryen.setFlexibleInlineMaxSize(22);
assert(binaryen.getFlexibleInlineMaxSize() == 22);

console.log("// oneCallerInlineMaxSize=" + binaryen.getOneCallerInlineMaxSize());
binaryen.setOneCallerInlineMaxSize(33);
assert(binaryen.getOneCallerInlineMaxSize() == 33);

binaryen.setAPITracing(false);
28 changes: 28 additions & 0 deletions test/binaryen.js/inlining-options.js.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// beginning a Binaryen API trace
#include <math.h>
#include <map>
#include "binaryen-c.h"
int main() {
std::map<size_t, BinaryenExpressionRef> expressions;
std::map<size_t, BinaryenFunctionRef> functions;
std::map<size_t, BinaryenGlobalRef> globals;
std::map<size_t, BinaryenEventRef> events;
std::map<size_t, BinaryenExportRef> exports;
std::map<size_t, RelooperBlockRef> relooperBlocks;
BinaryenModuleRef the_module = NULL;
RelooperRef the_relooper = NULL;
BinaryenGetAlwaysInlineMaxSize();
// alwaysInlineMaxSize=2
BinaryenSetAlwaysInlineMaxSize(11);
BinaryenGetAlwaysInlineMaxSize();
BinaryenGetFlexibleInlineMaxSize();
// flexibleInlineMaxSize=20
BinaryenSetFlexibleInlineMaxSize(22);
BinaryenGetFlexibleInlineMaxSize();
BinaryenGetOneCallerInlineMaxSize();
// oneCallerInlineMaxSize=15
BinaryenSetOneCallerInlineMaxSize(33);
BinaryenGetOneCallerInlineMaxSize();
return 0;
}
// ending a Binaryen API trace