[dart2wasm] Pass on @pragma('wasm:prefer-inline') to wasm-opt

Now that we have a way to tell binaryen to inline functions (see [0],
which added support for `(@binaryen.inline <0...127>)` annotations) we
can tell it to inline functions that were annotated with
`@pragma('wasm:prefer-inline')`

Since binaryen sometimes can devirtualize call sites that TFA cannot, it
can then inline those devirtualized calls.

[0] https://github.com/WebAssembly/binaryen/issues/7972

Change-Id: I139bd43976a1ddb83afe756d4fbac09419f7199e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/510822
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
This commit is contained in:
Martin Kustermann
2026-06-10 15:59:53 -07:00
committed by dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent 8e751fbc02
commit 892e6a8b53
+6 -2
View File
@@ -112,6 +112,10 @@ class FunctionCollector {
(target == member.reference || target.isBodyReference);
}
final bool alwaysInline =
util.getWasmPreferInlinePragma(translator.coreTypes, member) ?? false;
final int? inlineHint = neverInline ? 0 : (alwaysInline ? 127 : null);
// If this function is a `@pragma('wasm:import', '<module>.<name>')` we
// import the function and return it.
if (member.reference == target && member.annotations.isNotEmpty) {
@@ -137,7 +141,7 @@ class FunctionCollector {
"$importName (import)",
)
..isPure = hasPureAnnotation
..inlineHint = neverInline ? 0 : null;
..inlineHint = inlineHint;
}
}
@@ -166,7 +170,7 @@ class FunctionCollector {
final function = module.functions.define(ftype, getFunctionName(target))
..isPure = hasPureAnnotation && !target.isCheckedEntryReference
..inlineHint = neverInline ? 0 : null;
..inlineHint = inlineHint;
if (exportName != null) {
// Add weak exports to the module as we now know they're used. Strong
// exports have already been added.