RESOLVED FIXED Bug 191802
[WebAssembly] Change BBQ to generate Air IR
https://bugs.webkit.org/show_bug.cgi?id=191802
Summary [WebAssembly] Change BBQ to generate Air IR
Yusuke Suzuki
Reported 2018-11-16 23:39:51 PST
Template JIT like DFG.
Attachments
WIP (69.52 KB, patch)
2018-11-30 23:16 PST, Yusuke Suzuki
no flags
WIP (79.60 KB, patch)
2018-12-11 23:20 PST, Yusuke Suzuki
no flags
WIP (79.57 KB, patch)
2018-12-11 23:48 PST, Yusuke Suzuki
no flags
Patch (85.95 KB, patch)
2019-01-24 17:42 PST, Yusuke Suzuki
no flags
WIP (124.47 KB, patch)
2019-01-25 14:23 PST, Saam Barati
no flags
WIP (127.49 KB, patch)
2019-01-25 15:19 PST, Saam Barati
no flags
WIP (128.11 KB, patch)
2019-01-25 18:29 PST, Saam Barati
no flags
WIP (128.11 KB, patch)
2019-01-25 18:36 PST, Saam Barati
no flags
WIP (143.18 KB, patch)
2019-01-27 13:43 PST, Saam Barati
no flags
WIP (143.65 KB, patch)
2019-01-27 15:08 PST, Saam Barati
no flags
WIP (146.41 KB, patch)
2019-01-28 02:07 PST, Saam Barati
no flags
WIP (144.11 KB, patch)
2019-01-28 14:17 PST, Saam Barati
no flags
WIP (152.20 KB, patch)
2019-01-28 15:13 PST, Saam Barati
no flags
WIP (154.21 KB, patch)
2019-01-28 16:49 PST, Saam Barati
no flags
WIP (159.48 KB, patch)
2019-01-28 18:52 PST, Saam Barati
no flags
WIP (160.18 KB, patch)
2019-01-28 19:21 PST, Saam Barati
no flags
WIP (160.18 KB, patch)
2019-01-28 19:23 PST, Saam Barati
no flags
WIP (160.18 KB, patch)
2019-01-28 19:31 PST, Saam Barati
no flags
WIP (156.82 KB, patch)
2019-01-28 23:27 PST, Saam Barati
no flags
WIP (156.60 KB, patch)
2019-01-29 01:00 PST, Saam Barati
no flags
WIP (160.59 KB, patch)
2019-01-29 13:45 PST, Saam Barati
no flags
WIP (158.93 KB, patch)
2019-01-29 14:05 PST, Saam Barati
no flags
WIP (163.24 KB, patch)
2019-01-29 17:51 PST, Saam Barati
no flags
patch (175.04 KB, patch)
2019-01-30 17:02 PST, Saam Barati
no flags
patch (175.70 KB, patch)
2019-01-30 17:07 PST, Saam Barati
no flags
patch (175.19 KB, patch)
2019-01-30 17:11 PST, Saam Barati
keith_miller: review+
patch for landing (174.35 KB, patch)
2019-01-30 18:46 PST, Saam Barati
no flags
Saam Barati
Comment 1 2018-11-17 12:09:44 PST
(In reply to Yusuke Suzuki from comment #0) > Template JIT like DFG. I was thinking more like the baseline JIT. It might also be worth considering: - an interpreter - lazy compilation
Yusuke Suzuki
Comment 2 2018-11-19 00:15:48 PST
(In reply to Saam Barati from comment #1) > (In reply to Yusuke Suzuki from comment #0) > > Template JIT like DFG. > > I was thinking more like the baseline JIT. It might also be worth > considering: Right, the implementation should be like baseline JIT. > - an interpreter If we need an interpreter tier, anyway, I think bytecode for wasm is additionally required. After looking into the wasm format, wasm interpreter should target its own bytecode instead of running wasm code directly, because wasm interpreter needs to decode LEB everytime we execute wasm ops, which is super tricky and costly. > - lazy compilation
Yusuke Suzuki
Comment 3 2018-11-23 21:54:17 PST
I think the baseline JIT for wasm can be do some optimizations done in DFG. One of the good feature of stack VM is that the lifetimes of temporary values are roughly represented without any analysis. This information allows us to stay / spill values in the machine registers, which removes store/load operations :)
Yusuke Suzuki
Comment 4 2018-11-30 23:16:19 PST
Saam Barati
Comment 5 2018-12-01 00:15:12 PST
(In reply to Yusuke Suzuki from comment #4) > Created attachment 356297 [details] > WIP πŸ‘ŒπŸΌ
Saam Barati
Comment 6 2018-12-01 00:17:23 PST
(In reply to Yusuke Suzuki from comment #3) > I think the baseline JIT for wasm can be do some optimizations done in DFG. > One of the good feature of stack VM is that the lifetimes of temporary > values are roughly represented without any analysis. This information allows > us to stay / spill values in the machine registers, which removes store/load > operations :) This makes sense. It should be mostly free to have some basic register allocation. I wonder if it’s also worth having some kind of basic instruction selection.
Yusuke Suzuki
Comment 7 2018-12-11 23:20:13 PST
EWS Watchlist
Comment 8 2018-12-11 23:26:07 PST
Attachment 357108 [details] did not pass style-queue: ERROR: Source/JavaScriptCore/jit/RegisterBank.h:47: Should have only a single space after a punctuation in a comment. [whitespace/comments] [5] ERROR: Source/JavaScriptCore/jit/RegisterBank.h:49: Should have only a single space after a punctuation in a comment. [whitespace/comments] [5] ERROR: Source/JavaScriptCore/jit/RegisterBank.h:51: Should have only a single space after a punctuation in a comment. [whitespace/comments] [5] ERROR: Source/JavaScriptCore/jit/RegisterBank.h:71: NUM_REGS is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Source/JavaScriptCore/jit/RegisterBank.h:369: gpr_iterator is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Source/JavaScriptCore/jit/RegisterBank.h:370: fpr_iterator is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Source/JavaScriptCore/wasm/WasmRailgunJIT.cpp:312: One line control clauses should not use braces. [whitespace/braces] [4] Total errors found: 7 in 11 files If any of these errors are false positives, please file a bug against check-webkit-style.
Yusuke Suzuki
Comment 9 2018-12-11 23:48:42 PST
EWS Watchlist
Comment 10 2018-12-11 23:52:07 PST
Attachment 357110 [details] did not pass style-queue: ERROR: Source/JavaScriptCore/jit/RegisterBank.h:47: Should have only a single space after a punctuation in a comment. [whitespace/comments] [5] ERROR: Source/JavaScriptCore/jit/RegisterBank.h:49: Should have only a single space after a punctuation in a comment. [whitespace/comments] [5] ERROR: Source/JavaScriptCore/jit/RegisterBank.h:51: Should have only a single space after a punctuation in a comment. [whitespace/comments] [5] ERROR: Source/JavaScriptCore/jit/RegisterBank.h:71: NUM_REGS is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Source/JavaScriptCore/jit/RegisterBank.h:369: gpr_iterator is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Source/JavaScriptCore/jit/RegisterBank.h:370: fpr_iterator is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Source/JavaScriptCore/wasm/WasmRailgunJIT.cpp:321: One line control clauses should not use braces. [whitespace/braces] [4] ERROR: Source/JavaScriptCore/wasm/WasmRailgunJIT.cpp:344: One line control clauses should not use braces. [whitespace/braces] [4] Total errors found: 8 in 11 files If any of these errors are false positives, please file a bug against check-webkit-style.
Saam Barati
Comment 11 2019-01-24 13:00:06 PST
I'm going to take this over. I think if we do this right we can get between 4-8% faster on JetStream 2.
Yusuke Suzuki
Comment 12 2019-01-24 17:42:13 PST
Created attachment 360063 [details] Patch I've just cleaned up the uploaded patch before passing this to Saam.
EWS Watchlist
Comment 13 2019-01-24 17:45:03 PST
Attachment 360063 [details] did not pass style-queue: ERROR: Source/JavaScriptCore/wasm/WasmTemplateJIT.cpp:282: Use 'WTF::Optional<>' instead of 'std::optional<>'. [runtime/wtf_optional] [4] ERROR: Source/JavaScriptCore/wasm/WasmTemplateJIT.cpp:288: Use 'WTF::Optional<>' instead of 'std::optional<>'. [runtime/wtf_optional] [4] ERROR: Source/JavaScriptCore/wasm/WasmTemplateJIT.cpp:289: Use 'WTF::Optional<>' instead of 'std::optional<>'. [runtime/wtf_optional] [4] ERROR: Source/JavaScriptCore/wasm/WasmTemplateJIT.cpp:321: One line control clauses should not use braces. [whitespace/braces] [4] ERROR: Source/JavaScriptCore/wasm/WasmTemplateJIT.cpp:344: One line control clauses should not use braces. [whitespace/braces] [4] ERROR: Source/JavaScriptCore/wasm/WasmTemplateJIT.cpp:523: Use 'WTF::Optional<>' instead of 'std::optional<>'. [runtime/wtf_optional] [4] ERROR: Source/JavaScriptCore/wasm/WasmTemplateJIT.cpp:543: Use 'WTF::Optional<>' instead of 'std::optional<>'. [runtime/wtf_optional] [4] ERROR: Source/JavaScriptCore/wasm/WasmTemplateJIT.cpp:548: Use 'WTF::Optional<>' instead of 'std::optional<>'. [runtime/wtf_optional] [4] ERROR: Source/JavaScriptCore/jit/RegisterBank.h:47: Should have only a single space after a punctuation in a comment. [whitespace/comments] [5] ERROR: Source/JavaScriptCore/jit/RegisterBank.h:49: Should have only a single space after a punctuation in a comment. [whitespace/comments] [5] ERROR: Source/JavaScriptCore/jit/RegisterBank.h:51: Should have only a single space after a punctuation in a comment. [whitespace/comments] [5] ERROR: Source/JavaScriptCore/jit/RegisterBank.h:71: NUM_REGS is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Source/JavaScriptCore/jit/RegisterBank.h:369: gpr_iterator is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Source/JavaScriptCore/jit/RegisterBank.h:370: fpr_iterator is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp:216: Use 'WTF::Optional<>' instead of 'std::optional<>'. [runtime/wtf_optional] [4] ERROR: Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp:222: Use 'WTF::Optional<>' instead of 'std::optional<>'. [runtime/wtf_optional] [4] ERROR: Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp:223: Use 'WTF::Optional<>' instead of 'std::optional<>'. [runtime/wtf_optional] [4] ERROR: Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp:1018: Use 'WTF::Optional<>' instead of 'std::optional<>'. [runtime/wtf_optional] [4] ERROR: Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp:1086: Use 'WTF::Optional<>' instead of 'std::optional<>'. [runtime/wtf_optional] [4] ERROR: Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp:1185: Use 'WTF::Optional<>' instead of 'std::optional<>'. [runtime/wtf_optional] [4] ERROR: Source/JavaScriptCore/wasm/WasmValidate.cpp:130: Use 'WTF::Optional<>' instead of 'std::optional<>'. [runtime/wtf_optional] [4] ERROR: Source/JavaScriptCore/wasm/WasmValidate.cpp:140: Use 'WTF::Optional<>' instead of 'std::optional<>'. [runtime/wtf_optional] [4] ERROR: Source/JavaScriptCore/wasm/WasmValidate.cpp:141: Use 'WTF::Optional<>' instead of 'std::optional<>'. [runtime/wtf_optional] [4] ERROR: Source/JavaScriptCore/wasm/WasmValidate.cpp:282: Use 'WTF::Optional<>' instead of 'std::optional<>'. [runtime/wtf_optional] [4] ERROR: Source/JavaScriptCore/wasm/WasmValidate.cpp:328: Use 'WTF::Optional<>' instead of 'std::optional<>'. [runtime/wtf_optional] [4] ERROR: Source/JavaScriptCore/wasm/WasmValidate.cpp:340: Use 'WTF::Optional<>' instead of 'std::optional<>'. [runtime/wtf_optional] [4] ERROR: Source/JavaScriptCore/wasm/WasmFunctionParser.h:336: Use 'WTF::Optional<>' instead of 'std::optional<>'. [runtime/wtf_optional] [4] ERROR: Source/JavaScriptCore/wasm/WasmFunctionParser.h:365: Use 'WTF::Optional<>' instead of 'std::optional<>'. [runtime/wtf_optional] [4] ERROR: Source/JavaScriptCore/wasm/WasmFunctionParser.h:412: Use 'WTF::Optional<>' instead of 'std::optional<>'. [runtime/wtf_optional] [4] Total errors found: 29 in 11 files If any of these errors are false positives, please file a bug against check-webkit-style.
Saam Barati
Comment 14 2019-01-24 18:48:49 PST
I spoke with Yusuke and Keith. Our plan is to just generate Air directly, and write a trivial register allocator over Air.
Saam Barati
Comment 15 2019-01-25 14:23:09 PST
Saam Barati
Comment 16 2019-01-25 15:19:51 PST
Saam Barati
Comment 17 2019-01-25 18:29:30 PST
Created attachment 360204 [details] WIP I don't think I'm too far off from testing out some simple programs.
Saam Barati
Comment 18 2019-01-25 18:36:21 PST
Saam Barati
Comment 19 2019-01-25 19:05:18 PST
Comment on attachment 360205 [details] WIP View in context: https://bugs.webkit.org/attachment.cgi?id=360205&action=review > Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:2771 > + return addShift(Lshift32, arg0, arg1, result); Oops > Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:2815 > + append(NegateDouble, arg0, result); Oops
Saam Barati
Comment 20 2019-01-27 13:43:03 PST
Saam Barati
Comment 21 2019-01-27 15:08:47 PST
Saam Barati
Comment 22 2019-01-27 17:34:39 PST
Comment on attachment 360310 [details] WIP View in context: https://bugs.webkit.org/attachment.cgi?id=360310&action=review > Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:298 > + m_currentBlock->setSuccessors(continuation, failed); Oops
Saam Barati
Comment 23 2019-01-28 02:07:46 PST
Saam Barati
Comment 24 2019-01-28 14:17:30 PST
Saam Barati
Comment 25 2019-01-28 15:13:47 PST
Created attachment 360382 [details] WIP Seems close to compiling.
Saam Barati
Comment 26 2019-01-28 16:49:13 PST
Created attachment 360400 [details] WIP It compiles. Now to see how wrong it is...
Saam Barati
Comment 27 2019-01-28 18:52:08 PST
Created attachment 360415 [details] WIP Some tests run... Some don't
Saam Barati
Comment 28 2019-01-28 19:21:11 PST
Saam Barati
Comment 29 2019-01-28 19:23:59 PST
Created attachment 360421 [details] WIP Passing like 70% of tests.
Saam Barati
Comment 30 2019-01-28 19:31:01 PST
Saam Barati
Comment 31 2019-01-28 21:37:06 PST
Comment on attachment 360423 [details] WIP View in context: https://bugs.webkit.org/attachment.cgi?id=360423&action=review > Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:3031 > + append(FloorDouble, arg0, result); Oops. Add test > Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:3110 > + append(SubDouble, result, arg0); Oops
Saam Barati
Comment 32 2019-01-28 23:27:37 PST
Saam Barati
Comment 33 2019-01-29 01:00:02 PST
Created attachment 360452 [details] WIP Almost all tests pass. Just a few spec-tests left.
Saam Barati
Comment 34 2019-01-29 13:45:29 PST
Created attachment 360495 [details] WIP All wasm tests pass
Saam Barati
Comment 35 2019-01-29 14:05:24 PST
Radar WebKit Bug Importer
Comment 36 2019-01-29 16:56:59 PST
Saam Barati
Comment 37 2019-01-29 17:51:54 PST
Saam Barati
Comment 38 2019-01-30 17:02:25 PST
EWS Watchlist
Comment 39 2019-01-30 17:04:49 PST
Attachment 360648 [details] did not pass style-queue: ERROR: Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:1776: Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons. [readability/comparison_to_zero] [5] ERROR: Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:2061: One line control clauses should not use braces. [whitespace/braces] [4] ERROR: Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:2197: More than one command on the same line [whitespace/newline] [4] ERROR: Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:2219: More than one command on the same line [whitespace/newline] [4] ERROR: Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:3029: An else statement can be removed when the prior "if" concludes with a return, break, continue or goto statement. [readability/control_flow] [4] ERROR: Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:3383: An else statement can be removed when the prior "if" concludes with a return, break, continue or goto statement. [readability/control_flow] [4] Total errors found: 6 in 17 files If any of these errors are false positives, please file a bug against check-webkit-style.
Saam Barati
Comment 40 2019-01-30 17:07:06 PST
Saam Barati
Comment 41 2019-01-30 17:10:24 PST
Comment on attachment 360652 [details] patch View in context: https://bugs.webkit.org/attachment.cgi?id=360652&action=review > Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:593 > + Vector<Tmp, 8> m_freeFPTemps; > + Vector<Tmp, 8> m_freeGPTemps; These should be removed.
EWS Watchlist
Comment 42 2019-01-30 17:10:40 PST
Attachment 360652 [details] did not pass style-queue: ERROR: Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:1776: Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons. [readability/comparison_to_zero] [5] ERROR: Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:2061: One line control clauses should not use braces. [whitespace/braces] [4] ERROR: Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:2197: More than one command on the same line [whitespace/newline] [4] ERROR: Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:2219: More than one command on the same line [whitespace/newline] [4] ERROR: Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:3029: An else statement can be removed when the prior "if" concludes with a return, break, continue or goto statement. [readability/control_flow] [4] ERROR: Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:3383: An else statement can be removed when the prior "if" concludes with a return, break, continue or goto statement. [readability/control_flow] [4] Total errors found: 6 in 17 files If any of these errors are false positives, please file a bug against check-webkit-style.
Saam Barati
Comment 43 2019-01-30 17:11:41 PST
EWS Watchlist
Comment 44 2019-01-30 17:14:52 PST
Attachment 360655 [details] did not pass style-queue: ERROR: Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:1757: Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons. [readability/comparison_to_zero] [5] ERROR: Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:2042: One line control clauses should not use braces. [whitespace/braces] [4] ERROR: Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:2178: More than one command on the same line [whitespace/newline] [4] ERROR: Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:2200: More than one command on the same line [whitespace/newline] [4] ERROR: Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:3010: An else statement can be removed when the prior "if" concludes with a return, break, continue or goto statement. [readability/control_flow] [4] ERROR: Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:3364: An else statement can be removed when the prior "if" concludes with a return, break, continue or goto statement. [readability/control_flow] [4] Total errors found: 6 in 17 files If any of these errors are false positives, please file a bug against check-webkit-style.
Keith Miller
Comment 45 2019-01-30 18:23:52 PST
Comment on attachment 360655 [details] patch View in context: https://bugs.webkit.org/attachment.cgi?id=360655&action=review r=me. > Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:305 > + // FIXME: Fins a way to use origin here. typo: Fins => Find > Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:1290 > + auto storeArg = [&] () { > + if (Arg::isValidAddrForm(offset, B3::widthForBytes(sizeOfStoreOp(op)))) > + return Arg::addr(pointer, offset); > + immTmp = g64(); > + newPtr = g64(); > + append(Move, Arg::bigImm(offset), immTmp); > + append(Add64, immTmp, pointer, newPtr); > + return Arg::addr(newPtr); > + }; Why not just make an Arg::Addr and pass that in below rather than have a lambda that you call every time? > Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:2463 > + // the numbers are would be positive anyway as a signed integer. Since we cannot materialize constants into fprs we have b3 do it I think you mean air :P > Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:2541 > + // the numbers would be positive anyway as a signed integer. Since we cannot materialize constants into fprs we have b3 do it ditto.
Saam Barati
Comment 46 2019-01-30 18:40:58 PST
Comment on attachment 360655 [details] patch View in context: https://bugs.webkit.org/attachment.cgi?id=360655&action=review >> Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:305 >> + // FIXME: Fins a way to use origin here. > > typo: Fins => Find fixed >> Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:1290 >> + }; > > Why not just make an Arg::Addr and pass that in below rather than have a lambda that you call every time? sounds good. Will do the same for load. >> Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:2463 >> + // the numbers are would be positive anyway as a signed integer. Since we cannot materialize constants into fprs we have b3 do it > > I think you mean air :P Gonna remove these comments.
Saam Barati
Comment 47 2019-01-30 18:46:27 PST
Created attachment 360669 [details] patch for landing
Saam Barati
Comment 48 2019-01-30 18:49:54 PST
Note You need to log in before you can comment on or make changes to this bug.