-
Notifications
You must be signed in to change notification settings - Fork 8
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
Introduce a new pseudo-IR we can lower Eir to that is easier to consume #28
Comments
Thoughts @bitwalker? |
Before getting in to specifics about the current IR, I want to clarify my take on what is important in a frontend/middle-tier IR:
For Lumen specifically, I'm very much invested in making maximal use of MLIR/LLVM, so it is actually less desirable for me to have anything resembling a low-level IR, and instead convert from a relatively high-level IR into an MLIR dialect, and then do a series of dialect transformations representing the stripping away of progressively higher-levels of abstraction all the way down to LLVM, rather than try to translate directly to LLVM IR. The main thing relevant to this discussion is around liveness and scheduling, but I just wanted to be clear about what I'm looking to EIR to provide. So putting all of that together, here's my take on what I'd do to improve EIR:
I think its a good idea to provide a variant dialect of EIR to downstream consumers with a more explicit form, but I would try to preserve the flexibility around scheduling in some form, since some compilers may want to do their own scheduling. With Lumen, I'd want to do some experimentation to see what works best in practice for codegen, but as long as some form of the current representation is still available, I don't see any reason why it wouldn't be worthwhile to develop another downstream IR that is lower-level, or at least commits to some scheduling decisions. |
Due to being based on Thorin, Eir is a pretty novel IR. This has many advantages in that it makes a lot of optimizations a lot easier to perform.
However, one downside to this is that since it is so different to traditional SSA IRs, lowering from it can be quite a complex and error prone task with loads of work duplicated between backends.
A much better approach here would be to keep and maintain these complex transformations as part of eir itself. This could be done with a relatively small amount of work, by introducing a different IR which represents the eir in a more traditional and approachable format.
This new IR would have:
Statically scheduled PrimOps
Any backend which does not have the concept of floating primops (pretty much all of them) would need to do some form of primop scheduling when lowering. Doing this the naive way, constructing the primop on every usage, is simple, but leaves much to be desired. A preferred method would be to do a more sophisticated primop scheduling pass on the eir graph. This scheduled form would be represented in the new IR, and which instance is used at which point would be fully explicit.
The original PrimOp information would also be exposed, so that any backends that wish to handle this themselves could easily do so.
Explicit liveness information
Liveness information would be part of the IR.
Explicit lambda captures
Separate functions would be represented separately, no need for the builder to juggle several functions within one eir container.
More explicit control flow
Returns, throws, calls and branches would each be represented separately and more clearly.
I think this could significantly simplify both lumen codegen and any other potential future backends we may have for eir. When I experimented with a BEAM backend, I really missed having something like this to lower from.
The text was updated successfully, but these errors were encountered: