Bug 196387

Summary: Teach Call ICs how to call Wasm
Product: WebKit Reporter: Saam Barati <saam>
Component: JavaScriptCoreAssignee: Saam Barati <saam>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, commit-queue, ews-watchlist, fpizlo, ggaren, gskachkov, guijemont, keith_miller, mark.lam, msaboff, rmorisset, ticaiolima, tzagallo, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 196624    
Bug Blocks: 196385    
Attachments:
Description Flags
WIP
none
WIP
none
WIP
none
WIP
none
WIP
none
WIP
none
patch
fpizlo: review+
patch for landing
none
patch for landing none

Description Saam Barati 2019-03-28 19:30:06 PDT
...
Comment 1 Saam Barati 2019-04-01 16:27:15 PDT
Created attachment 366440 [details]
WIP

almost 2x faster on richards-wasm

I still need to make the code correct in the common case, e.g, teach the unwinder how to unwind past these frames and read callee saves, and restore wasm context
Comment 2 Saam Barati 2019-04-01 19:24:55 PDT
Created attachment 366455 [details]
WIP
Comment 3 Saam Barati 2019-04-01 19:29:40 PDT
Created attachment 366457 [details]
WIP
Comment 4 Saam Barati 2019-04-02 13:42:55 PDT
Created attachment 366532 [details]
WIP

Wasm tests appear to pass
Comment 5 Saam Barati 2019-04-02 13:43:22 PDT
I now need to make polymorphic calls work.
Comment 6 Saam Barati 2019-04-02 14:49:30 PDT
Created attachment 366541 [details]
WIP

now with polymorphic ICs
Comment 7 Saam Barati 2019-04-02 20:15:42 PDT
Created attachment 366571 [details]
WIP

Almost done. Just need to clean up a few things.
Comment 8 Saam Barati 2019-04-03 16:30:30 PDT
Created attachment 366667 [details]
patch
Comment 9 EWS Watchlist 2019-04-03 16:32:22 PDT
Attachment 366667 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/wasm/js/WebAssemblyFunctionHeapCellType.cpp:32:  Alphabetical sorting problem.  [build/include_order] [4]
Total errors found: 1 in 34 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 10 Filip Pizlo 2019-04-03 16:47:37 PDT
Comment on attachment 366667 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=366667&action=review

> Source/JavaScriptCore/jit/Repatch.cpp:1151
> -            codePtr = variant.executable()->generatedJITCodeForCall()->addressForCall(ArityCheckNotRequired);
> +
> +#if ENABLE(WEBASSEMBLY)
> +            if (callLinkInfo.specializationKind() == CodeForCall) {
> +                if (JSFunction* function = variant.function()) {
> +                    if (auto* wasmFunction = jsDynamicCast<WebAssemblyFunction*>(vm, function))
> +                        codePtr = wasmFunction->jsCallEntrypoint();
> +                }
> +            }
> +#endif
> +
> +            if (!codePtr)
> +                codePtr = variant.executable()->generatedJITCodeForCall()->addressForCall(ArityCheckNotRequired);

Seems like we write this code or some variant of it in multiple places.

Helper?
Comment 11 Saam Barati 2019-04-03 16:50:46 PDT
Comment on attachment 366667 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=366667&action=review

>> Source/JavaScriptCore/jit/Repatch.cpp:1151
>> +                codePtr = variant.executable()->generatedJITCodeForCall()->addressForCall(ArityCheckNotRequired);
> 
> Seems like we write this code or some variant of it in multiple places.
> 
> Helper?

Thanks for the review. Will fix.
Comment 12 Saam Barati 2019-04-03 17:07:48 PDT
Created attachment 366674 [details]
patch for landing
Comment 13 Saam Barati 2019-04-04 11:14:02 PDT
Created attachment 366730 [details]
patch for landing

With windows build fix.
Comment 14 Saam Barati 2019-04-04 11:18:46 PDT
This is also a 12% speedup on https://pspdfkit.com/webassembly-benchmark/
Comment 15 WebKit Commit Bot 2019-04-04 11:54:22 PDT
Comment on attachment 366730 [details]
patch for landing

Clearing flags on attachment: 366730

Committed r243886: <https://trac.webkit.org/changeset/243886>
Comment 16 WebKit Commit Bot 2019-04-04 11:54:23 PDT
All reviewed patches have been landed.  Closing bug.
Comment 17 Radar WebKit Bug Importer 2019-04-04 12:02:20 PDT
<rdar://problem/49616723>
Comment 18 Yusuke Suzuki 2019-04-04 13:42:19 PDT
Committed r243898: <https://trac.webkit.org/changeset/243898>
Comment 19 WebKit Commit Bot 2019-04-04 13:50:35 PDT
Re-opened since this is blocked by bug 196624
Comment 20 Saam Barati 2019-04-04 14:25:11 PDT
Will land cloop build fix momentarily
Comment 21 Saam Barati 2019-04-04 14:39:34 PDT
CLoop build fix:
http://trac.webkit.org/changeset/243907/webkit