-
-
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
WIP: linear IR #24027
WIP: linear IR #24027
Conversation
What's the new way of getting the rhs type of
? |
|
Ah, I missed that. This level of SSAValue usage is going to hurt #23240 really badly... A lot of the optimizations there requires looking at the expression that is assigned to the slot and looking through multiple assignment is really hard with the current AST format. From my experiment at #23240 as well some additional thought recently, I feel like our final goal should be using an purly SSA based IR that's similar to what LLVM use. As incremental steps, it seems that the form in #23240 (though preferably in frontend...) is relatively easy to analyse while not having to put everything in SSA. Getting any further with SSA values without removing slots altogether seems to make optimization much harder so I would prefer to do this at the same time as introducing a phi node. It will still require looking though phi node but they carry information about control flow with much more easy to analyse input which is not the case for slots... |
Also note that phi node can be lowered back to slots without losing any information easily so that can be done after optimization so that other part of the system not ready for it doen't have to deal with it yet. My next target after #23240 was going to be a rewrite of it in a similar fashion but doing a transformation to BB's with phi node in order to explore control flow information. |
Why? You can look up the definition of an SSAValue in an array.
What rules would you like? If possible, it would be nice just to change the official IR format to that needed by #23240. I strongly suspect this PR can be made to implement that. |
The direct assignment gives two important information.
Of course these are all computable when it's put in
I'd like to get rid of both of these logic in the next version and I think using a linked list like LLVM should be able to handle 1 easily. Having 1 removed and be able to look at multiple values at the same time should also make 2 easier (so that I can scan deeper and see which value is affected). If the scan of use/def become much simpler than what I have right now, the whole rescan table might not even be needed anymore.
Allow the rhs of slot assignment to be any expression. (so hold off the second commit until a better optimization pass is ready). On a related note, I feel like a good representation for optimization/type inference would just have the ssavalue, the type and the rhs be stored together since the optimization frequently need to go from one to another (ssa->type, ssa->rhs, rhs(instruction)->ssa). One can argue if the type is going with ssavalue or the rhs at that point but it does seem like a representation that's a superset of what |
Ok, I think I can allow that. I believe that currently, an assignment LHS is never a TypedSlot, so we could use one of those to store the type of the RHS.
That would be fine with me --- the current representation of
is pretty inefficient anyway. It could be something like
|
Yes, exactly.
Yeah. That works too. |
bca2951
to
2bc4c38
Compare
update optimization passes to keep IR in linear form use typedslot LHS to store type of RHS
2bc4c38
to
50e0b87
Compare
Closing temporarily. I'll put up a more incremental change first, but please keep this branch. |
In short, after this a
call
expression can only appear as the right-hand side of an assignment to an SSAValue (or in statement position, but that might change too). Here's what I've done so far:slot = Expr(:call, ...)
.typ
field fromExpr
🎉 , instead using the type of a call's SSAValue.Still to do:
cglobal
is the only thing that causes validation failures, due to needing to see its argument symbol/tuple. Need to decide how to handle this. We can either make it a special form, or have it look inside a constant jl_cgval_t argument.The new IR is of course larger (sysimg +20%), but undeniably beautiful. Inlining is already much simpler and other passes will benefit in the future as well. I think we'll be able to make up the difference with new optimizations and clever encoding. For example, we could avoid inserting source location push/pop when inlining trivial functions. Here's a typical excerpt:
We could also add a special encoding for assignment to an SSAValue.