Skip to content

Save Linear IR before emit#8939

Merged
stedolan merged 5 commits intoocaml:trunkfrom
gretay-js:save-linear
Oct 7, 2020
Merged

Save Linear IR before emit#8939
stedolan merged 5 commits intoocaml:trunkfrom
gretay-js:save-linear

Conversation

@gretay-js
Copy link
Copy Markdown
Contributor

This PR adds command line option to marshal the compiler's intermediate representation of each compilation unit to a separate file. Currently, it is only implemented for saving the Linear IR.

This provides a convenient way for an external tool to get a hold of an intermediate representation and manipulate it using compiler-libs. It is analogous to the way ppx tools handle parse trees, but lets us access IRs down the compilation pipeline. There is no alternative way of doing it, as far as I can see, since the removal of compiler hooks in #2276

Adding this capability has previously been discussed, for example: #1945 (comment), #1945 (comment)

Following the conventions established for other compilation articfacts, the IR will be saved to a file named <output_prefix>.cmir-linear. The format is defined in linear_format.ml.

The option is named "-save-ir-after " and supports only "scheduling" pass in this PR.

I have another patch that supports "-save-ir-after parsing" and "-save-ir-after typing" by invoking existing functionality in the compiler. It seems redundant with other command line options and I don't have a way to test it, but happy to add it on for completeness if needed. The passes "parsing" and "typing" were already defined in Clflags.Compiler_passes for use with command line option "-stop-after ".

This PR is on top of PR #8938 in which I propose to add "scheduling" to the existing "-stop-after" option. The only new commit here to review is in 8ea2eb9

@gretay-js
Copy link
Copy Markdown
Contributor Author

ping

@gretay-js gretay-js force-pushed the save-linear branch 4 times, most recently from e7bd3d6 to e5a4b21 Compare November 6, 2019 14:17
Copy link
Copy Markdown
Contributor

@mshinwell mshinwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine to me modulo various minor comments. However since I've been working with @gretay-js on this project, another reviewer with commit access should please have a brief look through the code, and confirm that the approach is reasonable.

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Nov 26, 2019 via email

@gretay-js
Copy link
Copy Markdown
Contributor Author

gretay-js commented Nov 26, 2019

I don't think ocamlopt_byte_exit_status = "0" is required because that's what is expected by default.

fixed, thanks!

@gretay-js
Copy link
Copy Markdown
Contributor Author

@mshinwell @shindere Thank you for the reviews! I addressed all review comments so far in 1200de9.

@mshinwell
Copy link
Copy Markdown
Contributor

The changes are fine, and I'm happy with the whole thing now. It would be appreciated if someone else can sign off on this as described above, thanks.

stedolan added a commit to janestreet/ocaml that referenced this pull request Mar 17, 2020
@gretay-js
Copy link
Copy Markdown
Contributor Author

gretay-js commented Apr 6, 2020

I've rebased it today and the CI is happy. Can this be considered for merging please? It has been waiting for another reviewer to sign it off.

gretay-js pushed a commit to gretay-js/ocaml that referenced this pull request May 28, 2020
hhugo pushed a commit to janestreet/ocaml that referenced this pull request May 29, 2020
hhugo pushed a commit to janestreet/ocaml that referenced this pull request Jun 2, 2020
hhugo pushed a commit to janestreet/ocaml that referenced this pull request Jun 3, 2020
gretay-js added a commit to gretay-js/ocaml that referenced this pull request Jun 4, 2020
gretay-js pushed a commit to gretay-js/ocaml that referenced this pull request Jun 4, 2020
ocaml#8938 from upstream trunk (cherry-pick 4353c75)

ocaml#9090 from upstream trunk (cherry-pick fe7c8ed)

ocaml#9097 from upstream trunk (cherry-pick 6daaf62)

ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9)

ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26)
gretay-js pushed a commit to gretay-js/ocaml that referenced this pull request Jun 4, 2020
ocaml#8938 from upstream trunk (cherry-pick 4353c75)

ocaml#9090 from upstream trunk (cherry-pick fe7c8ed)

ocaml#9097 from upstream trunk (cherry-pick 6daaf62)

ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9)

ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26)

Add linear_format to dune file
gretay-js pushed a commit to gretay-js/ocaml that referenced this pull request Jun 4, 2020
ocaml#8938 from upstream trunk (cherry-pick 4353c75)

ocaml#9090 from upstream trunk (cherry-pick fe7c8ed)

ocaml#9097 from upstream trunk (cherry-pick 6daaf62)

ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9)

ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26)

Add linear_format to dune file

Update .depend
hhugo pushed a commit to janestreet/ocaml that referenced this pull request Jun 5, 2020
hhugo pushed a commit to janestreet/ocaml that referenced this pull request Jun 5, 2020
hhugo pushed a commit to janestreet/ocaml that referenced this pull request Jun 10, 2020
hhugo pushed a commit to janestreet/ocaml that referenced this pull request Jun 24, 2020
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Aug 20, 2020
ocaml#8938 from upstream trunk (cherry-pick 4353c75)

ocaml#9090 from upstream trunk (cherry-pick fe7c8ed)

ocaml#9097 from upstream trunk (cherry-pick 6daaf62)

ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9)

ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26)

Add linear_format to dune file

Update .depend
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Aug 28, 2020
ocaml#8938 from upstream trunk (cherry-pick 4353c75)

ocaml#9090 from upstream trunk (cherry-pick fe7c8ed)

ocaml#9097 from upstream trunk (cherry-pick 6daaf62)

ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9)

ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26)

Add linear_format to dune file

Update .depend
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Sep 2, 2020
ocaml#8938 from upstream trunk (cherry-pick 4353c75)

ocaml#9090 from upstream trunk (cherry-pick fe7c8ed)

ocaml#9097 from upstream trunk (cherry-pick 6daaf62)

ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9)

ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26)

Add linear_format to dune file

Update .depend
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Sep 2, 2020
ocaml#8938 from upstream trunk (cherry-pick 4353c75)

ocaml#9090 from upstream trunk (cherry-pick fe7c8ed)

ocaml#9097 from upstream trunk (cherry-pick 6daaf62)

ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9)

ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26)

Add linear_format to dune file

Update .depend
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Sep 2, 2020
ocaml#8938 from upstream trunk (cherry-pick 4353c75)

ocaml#9090 from upstream trunk (cherry-pick fe7c8ed)

ocaml#9097 from upstream trunk (cherry-pick 6daaf62)

ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9)

ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26)

Add linear_format to dune file

Update .depend
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Sep 7, 2020
ocaml#8938 from upstream trunk (cherry-pick 4353c75)

ocaml#9090 from upstream trunk (cherry-pick fe7c8ed)

ocaml#9097 from upstream trunk (cherry-pick 6daaf62)

ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9)

ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26)

Add linear_format to dune file

Update .depend
hhugo pushed a commit to janestreet/ocaml that referenced this pull request Sep 8, 2020
@gretay-js gretay-js force-pushed the save-linear branch 2 times, most recently from c84ec94 to fc3326e Compare September 8, 2020 16:31
mshinwell pushed a commit to janestreet/ocaml that referenced this pull request Sep 29, 2020
mshinwell pushed a commit to janestreet/ocaml that referenced this pull request Sep 30, 2020
mshinwell pushed a commit to janestreet/ocaml that referenced this pull request Sep 30, 2020
mshinwell pushed a commit to janestreet/ocaml that referenced this pull request Oct 1, 2020
mshinwell pushed a commit to janestreet/ocaml that referenced this pull request Oct 1, 2020
hhugo pushed a commit to janestreet/ocaml that referenced this pull request Oct 5, 2020
Copy link
Copy Markdown
Contributor

@let-def let-def left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look fine to me too.

@gretay-js
Copy link
Copy Markdown
Contributor Author

@let-def thank you for the review! I've just rebased the PR. @gasche can this be merged please, once the CI is finished?

@gasche gasche added the merge-me label Oct 7, 2020
@gasche
Copy link
Copy Markdown
Member

gasche commented Oct 7, 2020

I'm happy to merge if I happen to remember to do it in a few hours after the CI has finished. Feel free to ping me if I don't. I added the "merge-me" label, meaning that anyone else will feel encouraged to merge once the CI comes back green.

@gretay-js
Copy link
Copy Markdown
Contributor Author

Thank you!

@hhugo
Copy link
Copy Markdown
Contributor

hhugo commented Oct 7, 2020

@gasche , it's all green ready for you :)

@stedolan stedolan merged commit 04bceec into ocaml:trunk Oct 7, 2020
gretay-js pushed a commit to gretay-js/ocaml that referenced this pull request May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants