diff options
author | Zoltan Varga <vargaz@gmail.com> | 2020-06-30 11:13:18 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-30 11:13:18 +0300 |
commit | 174aeaa31c9d80a53c6c7981ba7206825cd1ea4d (patch) | |
tree | 582f49c352f2cae81cffad5694d98f371086886f /mcs | |
parent | 1d3e43ec3a5d2b9f672d86b12fce84a8da654cb6 (diff) |
[wasm] Optimize interp->native transitions. (#20034)
* [wasm] Optimize interp->native transitions.
* Generate tables of signatures/transition functions.
* Add mono_wasm_get_interp_to_native_trampoline () function to look up the transition function
for a signature.
* Cache the transition function in a imethod->method_data slot.
Previously, we were calling a mono_wasm_interp_to_native_trampoline () function and a generated
icall_trampoline_dispatch () function which added a lot of overhead.
* Avoid sharing cache entries.
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/tools/wasm-tuner/InterpToNativeGenerator.cs | 59 |
1 files changed, 9 insertions, 50 deletions
diff --git a/mcs/tools/wasm-tuner/InterpToNativeGenerator.cs b/mcs/tools/wasm-tuner/InterpToNativeGenerator.cs index 8c5adb6ff9c..e110dd9b27c 100644 --- a/mcs/tools/wasm-tuner/InterpToNativeGenerator.cs +++ b/mcs/tools/wasm-tuner/InterpToNativeGenerator.cs @@ -295,60 +295,19 @@ class InterpToNativeGenerator { w.WriteLine ("\n}\n"); } - w.WriteLine ("static void\nicall_trampoline_dispatch (const char *cookie, void *target_func, InterpMethodArguments *margs)"); - w.WriteLine ("{"); - - /* - if (args.Any(a => a == "--flat")) { - for (int i = 0; i < cookies.Length; ++i) { - var c = cookies [i]; - w.Write ("\t"); - if (i > 0) - w.Write ("else "); - w.WriteLine ($"if (!strcmp (\"{c}\", cookie))"); - w.WriteLine ($"\t\twasm_invoke_{c.ToLower ()} (target_func, margs);"); - } - w.WriteLine ("\telse {"); - w.WriteLine ("\t\tg_error (\"CANNOT HANDLE COOKIE %s\\n\", cookie);"); - w.WriteLine ("\t}"); - } else { - */ Array.Sort (signatures); - WritePartition (w, signatures, 0); - w.WriteLine ("\tg_error (\"CANNOT HANDLE COOKIE %s\\n\", cookie);"); - - w.WriteLine ("}"); - } - - static void WritePartition (StreamWriter w, IEnumerable<string> set, int pos = 0, int depth = 0) { - var prefix = "\t"; - for (var c = 0; c < pos; c++) - prefix += "\t"; - var checks = 0; - - var groups = set.OrderBy (s => -s.Length).Where (s => s.Length > pos).GroupBy (s => s.Skip(pos).First().ToString()); - foreach (var g in groups) { - w.WriteLine ($"{prefix}{Elif (checks)} (cookie[{pos}] == '{g.Key}') {{"); - WritePartition (w, g.ToList (), pos + 1, checks + depth); - w.WriteLine ($"{prefix}}}"); - checks++; - } - - var hits = set.Where (s => s.Length == pos); - if (hits.Any ()) { - w.WriteLine ($"{prefix}{Elif (checks++)} (cookie[{pos}] == '\\0') {{"); - - var h = hits.First (); - w.WriteLine ($"{prefix}\t// found: {h} depth {pos + checks + depth}"); - w.WriteLine ($"{prefix}\twasm_invoke_{h.ToLower ()} (target_func, margs);"); - w.WriteLine ($"{prefix}\treturn;"); - w.WriteLine ($"{prefix}}}"); - } + w.WriteLine ("static const char* interp_to_native_signatures [] = {"); + foreach (var sig in signatures) + w.WriteLine ($"\"{sig}\","); + w.WriteLine ("};"); - string Elif (int c) { - return c == 0 ? "if" : "else if"; + w.WriteLine ("static void* interp_to_native_invokes [] = {"); + foreach (var sig in signatures) { + var lsig = sig.ToLower (); + w.WriteLine ($"wasm_invoke_{lsig},"); } + w.WriteLine ("};"); } class EmitCtx |