Skip to content

Proposing user-defined inlining #1889

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

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 16 additions & 0 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2685,6 +2685,22 @@ void BinaryenFunctionSetDebugLocation(BinaryenFunctionRef func, BinaryenExpressi

fn->debugLocations[ex] = loc;
}
int BinaryenFunctionGetUserFlags(BinaryenFunctionRef func) {
if (tracing) {
std::cout << " BinaryenFunctionGetUserFlags(functions[" << functions[func] << "]);\n";
}

auto* fn = (Function*)func;
return static_cast<int>(fn->userFlags);
}
void BinaryenFunctionSetUserFlags(BinaryenFunctionRef func, int flags) {
if (tracing) {
std::cout << " BinaryenFunctionSetUserFlags(functions[" << functions[func] << "], " << flags << ");\n";
}

auto* fn = (Function*)func;
fn->userFlags = (Function::UserFlags)flags;
}

//
// =========== Import operations ===========
Expand Down
5 changes: 5 additions & 0 deletions src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,11 @@ void BinaryenFunctionRunPasses(BinaryenFunctionRef func, BinaryenModuleRef modul
// Sets the debug location of the specified `Expression` within the specified `Function`.
void BinaryenFunctionSetDebugLocation(BinaryenFunctionRef func, BinaryenExpressionRef expr, BinaryenIndex fileIndex, BinaryenIndex lineNumber, BinaryenIndex columnNumber);

// Gets the user defined flags for this function
int BinaryenFunctionGetUserFlags(BinaryenFunctionRef func);
// Sets the user defined flags for this function
void BinaryenFunctionSetUserFlags(BinaryenFunctionRef func, int flags);

//
// ========== Import Operations ==========
//
Expand Down
2 changes: 1 addition & 1 deletion src/passes/Inlining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ struct Inlining : public Pass {
// decide which to inline
InliningState state;
ModuleUtils::iterDefinedFunctions(*module, [&](Function* func) {
if (infos[func->name].worthInlining(runner->options)) {
if (func->hasUserFlags(Function::UserFlags::Inline) || infos[func->name].worthInlining(runner->options)) {
state.worthInlining.insert(func->name);
}
});
Expand Down
11 changes: 11 additions & 0 deletions src/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,17 @@ class Function : public Importable {

void clearNames();
void clearDebugInfo();

// Special flags that can be set by a an API user
enum class UserFlags : unsigned int {
None = 0,
Inline = 1 << 0
};
UserFlags userFlags = UserFlags::None;

bool hasUserFlags(UserFlags flags) {
return static_cast<UserFlags>((static_cast<int>(userFlags) & static_cast<int>(flags))) == flags;
}
};

// The kind of an import or export.
Expand Down