-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
New graph-coloring-based register allocator #816
New graph-coloring-based register allocator #816
Conversation
Some IR tests are failing because they check for exact the ASM output which is different now. I will update them. Converting to draft until I’m done. |
7e04ba0
to
8466803
Compare
8466803
to
634fc22
Compare
Ready for review. @otrho - regarding the IR tests that I had to update: how did you figure out/check the assembly for these tests? Did you do it by inspection? |
Yeah, when you're adding them progressively it's fairly easy to eyeball them and confirm they're correct. But making a pervasive change to codegen like this means there's a fair bit of work confirming the new ASM is right. At the same time you're trusting that the E2E regression tests are confirming that the changes haven't broken behaviour so I guess I'd be checking for stuff which looks obviously wrong in the IR tests, rather than making sure they're absolutely doing the right thing. To run E2E with IR you can use the |
I'll inspect the changes then - it would also be a good exercise to help understand the IR 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.
Looks good. Not sure why the new test would fail for IR though?
@@ -223,21 +223,575 @@ impl VirtualOp { | |||
.collect() | |||
} | |||
|
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.
For all these giant functions I feel like there must be a more data driven compile time computational way to build these, with macros or something. But I don't know specifically the best way.
move $r1 $r2 | ||
ji i8 | ||
move $r0 $r1 | ||
ji i7 | ||
ret $r0 |
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.
Nice!
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.
Ahh so cool, great job 😄
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.
Actually one nit, would you be able to include the name of the algorithm (and possibly a link to the wikipedia page) in the docstring associated with the function? That way we won't have to dig for this issue if/when we need to expand on this code in the future 😄
Done! |
It's due to #821 which is an issue on master. I see you're already looking at it though, thanks! :) |
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.
Great job!
Closes #155 and #800
This is basically Chaitin's original graph-coloring based algorithm for register allocation. The new file that I that added, called
register_allocator.rs
, has all the steps in details. I tried to make the steps and the different pieces of the algorithm as clear as possible. I couldn't really find one source where the full algorithm in details is described. However, my comments should contain the union of what I found in the literature and how it applies to the data structures we have in CodeGen.With this, the bytecode size typically goes down due to the coalescing phase. The table below shows the bytecode size saving percentages. I noticed that the larger the code, the bigger the savings.
Also, this patch fixes the functional issue described in #800. Loops introduce complexities to liveness analysis due to all the backward jumps, so I suspect something is going wrong with the existing allocator.
Now that I have all the building blocks, I can experiment with other algorithms such as the iterartive one described in https://c9x.me/compile/bib/irc.pdf. The steps are basically the same with minor tweeks and run in an iterative outer loop.
Update: E2E tests with the IR pipeline enabled seem to be okay except for three tests that are currently failing on
master
and the test that I'm adding here (due to #821).