-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add some CFG manipulation tools for IRCode #45305
base: master
Are you sure you want to change the base?
Conversation
It looks like the tester_win32 failure is OOM #44948 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM in terms of code quality, though I don't quite understand the use case. Could you explain a bit more when we would want to use allocate_new_blocks!
and allocate_gotoifnot_sequence!
?
So I think in the LICM PR I wanted to split an edge. Can you add a test for this?
Goal:
Also if you add comments to the test explaining what transformation is happening it would be easier to think through if we cover all test cases. |
I like the general direction of this. In the past I had suggested we make a stdlib for this, but I'm fine with putting it in Base for now and making code movement decisions later. In general, it would be good to have a relatively clean and stable API for IRCode. Various utilities exist in various packages, so consolidating them is a good idea. |
Co-authored-by: Ian Atol <ian.atol@juliacomputing.com>
IMO, this PR would make more sense if there was a second commit in it that makes more of the compiler to use these tools. |
base/compiler/ssair/ir.jl
Outdated
Create new "singleton" basic blocks (i.e., it contains a single instruction) | ||
before `statement_positions`. This function adds `2 * length(statement_positions)` | ||
blocks; i.e., `length(statement_positions)` blocks for the new singleton basic | ||
blocks and the remaining `length(statement_positions)` blocks for the basic | ||
block containing the instructions starting at each `statement_positions`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create new "singleton" basic blocks (i.e., it contains a single instruction) | |
before `statement_positions`. This function adds `2 * length(statement_positions)` | |
blocks; i.e., `length(statement_positions)` blocks for the new singleton basic | |
blocks and the remaining `length(statement_positions)` blocks for the basic | |
block containing the instructions starting at each `statement_positions`. | |
Create new "singleton" basic blocks (i.e., it contains a single dummy instruction) | |
before `statement_positions`. This function adds `2 * length(statement_positions)` | |
instructions; i.e., `length(statement_positions)` instructions for the new singleton basic | |
blocks and the remaining `length(statement_positions)` instructions for the basic | |
block containing the dummy instructions starting at each `statement_positions`. |
explains better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to pull some ideas from this. I also cleaned up the API which simplified the explanation.
Thanks, these tools look very useful and the code quality is great.
I'm not sure that there are such places where we manipulate CFG of |
Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>
Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>
@vchuravy I created a sketch for how to do LICM https://nbviewer.org/gist/tkf/d4734be24d2694a3afd669f8f50e6b0f/00_notebook.ipynb (see the last example). It's tedious to create the input IR "by hand" so I want to do this after #45306 if we are to add it to the test. @ianatol Does this also answer your question about when we would want to use these APIs? Another example was for doing the lowering of
There are single-sentence explanations in the testset labels. I also added some pseudocode for explaining the input and output IRs. |
Okay rebased onto ToT, and I am in the process of rewriting #36832 on top of this. |
This PR adds CFG manipulation function
allocate_new_blocks!
and a derived functionallocate_gotoifnot_sequence!
to help CFG manipulation ofIRCode
s.julia/base/compiler/ssair/ir.jl
Lines 1630 to 1680 in 90133d4
julia/base/compiler/ssair/ir.jl
Lines 1937 to 1959 in 90133d4
This PR also adds a bit more somewhat automated way to wrap
Core.Compiler
interface functions asBase
interface functions; e.g.,julia/base/compilerwrappers.jl
Lines 17 to 18 in 90133d4
Some of the manually-handled definitions in
IRShow
are now handled this way. These definitions are very handy for writing tests and also playing with them in REPL. But I think this PR can be done without them if it's better to do this elsewhere.