Closed Bug 1699271 Opened 3 years ago Closed 10 months ago

[meta] Auto generate MIR, LIR, and WarpCacheIRTranspiler boilerplate

Categories

(Core :: JavaScript Engine: JIT, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED

People

(Reporter: caroline, Unassigned)

References

(Blocks 1 open bug)

Details

(Keywords: meta)

Attachments

(23 files, 10 obsolete files)

48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review

Much of MIR class definition, LIR code, and WarpCacheIRTranspiler is very mechanical and can be generated similarly to what was done for auto generating CacheIR code.

The obvious question for me is, "does this reduce essential complexity?", and the answer is imo not obviously "yes". Looking at a few of the patches here, I see that generally the YAML is about as long (lines of code) as the C++ it replaces. Add to that that the YAML has ad-hoc semantics, is untyped and indentation-structured, and is processed by a dynamically typed program, and I have a hard time seeing the upside compared to, say, further macroization of the MIR. I agree that the MIR boilerplate is annoying, but does this patch set address anything deep or open up for other important work in the future?

Is there a backgrounder for this work somewhere, a design doc or notes from a discussion?

Re the implementation of the idea, why barely-structured YAML and not well-structured JSON? Why untyped Python and not TypeScript or Go?

(Sorry to come across as negative; I'm only looking for enlightenment.)

Flags: needinfo?(ccullen)

The main background for this work is that we are currently using a very similar system for supporting CacheIR (see CacheIROps.yaml and GenerateCacheIRFiles.py), and it has been an overwhelming success. Adding a new CacheIR op in baseline is very smooth: you define it in the yaml file, you use it in CacheIR.cpp, and you implement it in CacheIRCompiler.cpp. We previously had a macro-based system for handling CacheIR boilerplate, but it was already creaking under its own weight, and we had several new features to add. Switching to a code generator was an unambiguous improvement.

Transpiling a new CacheIR op in Warp is less nice: if you add a new MIR op, you need to write somewhat finicky code in at least five places, most of which is boilerplate. The purpose of this project is to explore whether we can get similar benefits when auto-generating MIR that we saw from CacheIR. In a perfect world, we could add new functionality -- say, supporting a new inlineable native function -- while only touching the yaml files (to define boilerplate), CacheIR.cpp (to decide when to use the new op), CacheIRCompiler.cpp (to generate IC code), and CodeGenerator.cpp (to generate Warp/Ion code). We might not be able to get there, but it seems valuable to at least try writing a prototype and see how it feels. (Note that the current patches are just Caroline's first draft being put up for feedback. There will likely be significant changes. If it turns out that, even after polishing, some of the boilerplate we're hoping to remove was better without the code generator, we won't land those parts.)

One other benefit of auto-generation is that it makes it easier to experiment with different MIR implementations: for example, devirtualizing MIR in favour of auto-generated switch statements.

In terms of implementation choices: Python is nice because it's already well-supported in our build system. YAML over JSON was pretty arbitrary: YAML is a little nicer to write by hand, and JSON doesn't support comments. Neither choice has had any issues in the CacheIR implementation, It's certainly possible that we could run into problems in the future, but this code runs as part of the build process and produces the same output every time, so there's not a lot of room for bugs to slip in.

Thanks for the backgrounder / perspective. I'll be interested in following this work and see where it goes. Clearly the amount of boilerplate in Ion is smaller these days than it used to be but is still annoyingly large, and I have no arguments against generating code where we can.

(I admit to strong negative biases re untyped languages, untyped data, and indentation-based structuring; that said, I don't really think justifying them with "it's what we've done in the past" is all that great either. A discussion for another day. "JSON doesn't support comments" seems highly relevant, though.)

Flags: needinfo?(ccullen)
Attachment #9213996 - Attachment description: Bug 1699271 - Part 8: Auto generate MIR ops and WarpCacheIRTranspiler code for certain ops. r?iain → Bug 1699271 - Part 8: Auto generate more MIR ops. r?iain
Attachment #9213989 - Attachment description: Bug 1699271 - Part 1: Generate MIR Opcodes. r?jandem → Bug 1699271 - Part 1: Generate MIR Opcodes. r?jandem!
Attachment #9213990 - Attachment description: Bug 1699271 - Part 2: Auto generate simple nullary MIR Ops. r?jandem → Bug 1699271 - Part 2: Auto generate simple nullary MIR Ops. r?jandem!
Attachment #9213991 - Attachment description: Bug 1699271 - Part 3: Auto generate simple MIR Ops with constructor args. r?iain → Bug 1699271 - Part 3: Auto generate simple MIR Ops with constructor args. r?iain!
Attachment #9213992 - Attachment description: Bug 1699271 - Part 4: Auto generate MIR ops with congruentTo methods. r?jandem → Bug 1699271 - Part 4: Auto generate MIR ops with congruentTo methods. r?jandem!
Attachment #9213993 - Attachment description: Bug 1699271 - Part 5: Auto generate MIR ops that contain foldsTo methods. r?iain → Bug 1699271 - Part 5: Auto generate MIR ops that contain foldsTo methods. r?iain!
Attachment #9213994 - Attachment description: Bug 1699271 - Part 6: Auto generate ops that possibly call. r?jandem → Bug 1699271 - Part 6: Auto generate ops that possibly call. r?jandem!
Attachment #9213995 - Attachment description: Bug 1699271 - Part 7: Auto generate MIR ops that compute range. r?iain → Bug 1699271 - Part 7: Auto generate MIR ops that compute range. r?iain!
Attachment #9213996 - Attachment description: Bug 1699271 - Part 8: Auto generate more MIR ops. r?iain → Bug 1699271 - Part 8: Auto generate more MIR ops. r?iain!
Attachment #9213997 - Attachment description: Bug 1699271 - Part 9: Auto generate MIR ops that can recover from bailouts. r?jandem → Bug 1699271 - Part 9: Auto generate MIR ops that can recover from bailouts. r?jandem!
Attachment #9216966 - Attachment description: Bug 1699271 - Part 10: Auto generate more MIR instructions. r?iain → Bug 1699271 - Part 10: Auto generate more MIR instructions. r?iain!
Pushed by ccullen@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/bbce3487d14f
Part 1: Generate MIR Opcodes. r=jandem,iain
https://hg.mozilla.org/integration/autoland/rev/bf6f19cc2331
Part 2: Auto generate simple nullary MIR Ops. r=iain
https://hg.mozilla.org/integration/autoland/rev/2cb147cc9ae2
Part 3: Auto generate simple MIR Ops with constructor args. r=iain
https://hg.mozilla.org/integration/autoland/rev/9ce262e1f44b
Part 4: Auto generate MIR ops with congruentTo methods. r=iain
https://hg.mozilla.org/integration/autoland/rev/ed0d74615437
Part 5: Auto generate MIR ops that contain foldsTo methods. r=iain
https://hg.mozilla.org/integration/autoland/rev/5f6a27d7e131
Part 6: Auto generate ops that possibly call. r=iain
https://hg.mozilla.org/integration/autoland/rev/566c2b19754e
Part 7: Auto generate MIR ops that compute range. r=iain
https://hg.mozilla.org/integration/autoland/rev/822533d1632f
Part 8: Auto generate more MIR ops. r=iain
https://hg.mozilla.org/integration/autoland/rev/b13552f6d81e
Part 9: Auto generate MIR ops that can recover from bailouts. r=iain
https://hg.mozilla.org/integration/autoland/rev/cbebfcacd934
Part 10: Auto generate more MIR instructions. r=iain
Regressions: 1713581

Depends on D116775

Attachment #9225798 - Attachment description: Bug 1699271 - Part 12: Remove unnecessary temporary allocator MIR ops. r?iain! → Bug 1699271 - Part 12: Remove unnecessary temporary allocator arguments to MIR ops. r?iain!
Attachment #9225080 - Attachment is obsolete: true
Attachment #9225798 - Attachment description: Bug 1699271 - Part 12: Remove unnecessary temporary allocator arguments to MIR ops. r?iain! → Bug 1699271 - Part 12: Remove unnecessary temporary allocator MIR ops. r?iain!
Pushed by ccullen@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/599f833f08c1
Part 11: Add autogeneration for MIR ops that take arguments. r=iain
https://hg.mozilla.org/integration/autoland/rev/f7abfb7d50d2
Part 12: Remove unnecessary temporary allocator MIR ops. r=iain
https://hg.mozilla.org/integration/autoland/rev/26a855a6149e
Part 13: Add auto generated static assertions for non gc pointer arguments to MIR ops. r=iain
Pushed by ccullen@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/00819b6018f9
Part 14: Fix up mir auto gen assertion patch and add assertion message. r=iain
Regressions: 1716134

Depends on D119720

Depends on D120277

Depends on D120278

Depends on D120280

Depends on D120283

Attachment #9230884 - Attachment description: Bug 1699271 - Part 15: Generate LIR opcodes from YAML. r?iain → Bug 1699271 - Part 15: Generate LIR opcodes from YAML. r?iain!
Attachment #9230885 - Attachment description: Bug 1699271 - Part 16: Generate LIR nodes. r?iain → Bug 1699271 - Part 16: Generate LIR nodes. r?iain!
Attachment #9230886 - Attachment description: Bug 1699271 - Part 17: Generate LIR call instructions. r?iain → Bug 1699271 - Part 17: Generate LIR call instructions. r?iain!
Attachment #9230887 - Attachment description: Bug 1699271 - Part 18: Generate LIR instructions that produce LDefintions. r?iain → Bug 1699271 - Part 18: Generate LIR instructions that produce LDefintions. r?iain!
Attachment #9230888 - Attachment description: Bug 1699271 - Part 19: Generate LIR ops that take operands. r?iain → Bug 1699271 - Part 19: Generate LIR ops that take operands. r?iain!
Attachment #9230889 - Attachment description: Bug 1699271 - Part 20: Generate LIR ops that use temporary registers. r?iain → Bug 1699271 - Part 20: Generate LIR ops that use temporary registers. r?iain!
Attachment #9230890 - Attachment description: Bug 1699271 - Part 21: Generate more LIR nodes. r?iain → Bug 1699271 - Part 21: Generate more LIR nodes. r?iain!
Attachment #9230891 - Attachment description: Bug 1699271 - Part 22: Generate LIR ops that produce value or int64 definitions. r?iain → Bug 1699271 - Part 22: Generate LIR ops that produce value or int64 definitions. r?iain!
Attachment #9230892 - Attachment description: Bug 1699271 - Part 23: Generate LIR nodes that take arguments. r?iain → Bug 1699271 - Part 23: Generate LIR nodes that take arguments. r?iain!
Attachment #9232027 - Attachment is obsolete: true
Attachment #9232028 - Attachment is obsolete: true
Attachment #9232029 - Attachment is obsolete: true
Attachment #9232030 - Attachment is obsolete: true
Attachment #9232032 - Attachment is obsolete: true
Attachment #9232033 - Attachment is obsolete: true
Attachment #9232034 - Attachment is obsolete: true
Attachment #9232035 - Attachment is obsolete: true
Attachment #9232036 - Attachment is obsolete: true
Attachment #9230891 - Attachment description: Bug 1699271 - Part 22: Generate LIR ops that produce value or int64 definitions. r?iain! → Bug 1699271 - Part 22: Generate more LIR ops. r?iain!
Pushed by ccullen@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/98e70cb9f81a
Part 15: Generate LIR opcodes from YAML. r=iain
https://hg.mozilla.org/integration/autoland/rev/59114f24f348
Part 16: Generate LIR nodes. r=iain
https://hg.mozilla.org/integration/autoland/rev/9c17091087a8
Part 17: Generate LIR call instructions. r=iain
https://hg.mozilla.org/integration/autoland/rev/778ead7a44ba
Part 18: Generate LIR instructions that produce LDefintions. r=iain
https://hg.mozilla.org/integration/autoland/rev/e25df64152c2
Part 19: Generate LIR ops that take operands. r=iain
https://hg.mozilla.org/integration/autoland/rev/66491995508e
Part 20: Generate LIR ops that use temporary registers. r=iain
https://hg.mozilla.org/integration/autoland/rev/898028ee73ec
Part 21: Generate more LIR nodes. r=iain
https://hg.mozilla.org/integration/autoland/rev/54c739cc8d2f
Part 22: Generate more LIR ops. r=iain
https://hg.mozilla.org/integration/autoland/rev/1053a0c611ba
Part 23: Generate LIR nodes that take arguments. r=iain
Regressions: 1726094

The bug assignee is inactive on Bugzilla, so the assignee is being reset.

Assignee: ccullen → nobody

The meta keyword is there, the bug doesn't depend on other bugs and there is no activity for 12 months.
:willyelm, maybe it's time to close this bug?

Flags: needinfo?(wmedina)

Hi Jan, do you have additional information about this bug?

Flags: needinfo?(wmedina) → needinfo?(jdemooij)

Patches landed in this bug so let's close it. We can file a new bug for other work in this area.

Status: NEW → RESOLVED
Closed: 10 months ago
Flags: needinfo?(jdemooij)
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: