Replies: 10 comments 4 replies
-
This is definitely a good choice!. Thank you.
I had LLVM in mind (only because I'm more familiar with it), but cranelift is a good choice too. I think at some point we'll have them both. No reason to restrict.
💯
Yes, very much. I've been pondering over a rewrite infrastructure for some time, but that should begin with a walker API first, so yes.
Can you elaborate a little more? I'd like to hear this. |
Beta Was this translation helpful? Give feedback.
-
I opened a PR for the function arguments: #26 The change kinda makes me wonder if we want to have a more type-safe API. I think it is not the first time I bring this up. One common pattern we find in MLIR is the separation of the 'storage' from the 'interpretation'. We have it in the In contrast to pliron we find a similar pattern in MLIR for types and attributes. Let's look at an example for
The
The split into
Now the constructor of FuncOp would become become:
Other Ops like ConstantOp might still allow any kind of Type or Attribute. For this to work we have the One can also accept a type family via |
Beta Was this translation helpful? Give feedback.
-
I agree with your concern. Let me think about this a bit and get back to you. |
Beta Was this translation helpful? Give feedback.
-
Did some experiments and for now settled on the following approach: The core traits are On top of some core traits I have implemented some more implementations and other helpers to make some common patterns more convenient to use. Kind of like a Lego-set of walking patterns 😅 . IR walking - coreThe The
The The
We have 2 implementations: Forward and Reverse (sometimes you might want to walk backwards). The default implementation of You may have noticed that we return a
As The Pre-/Post Order traversalHaving to implement
The
Enter/Exit? Stack based analyzers/processingSometimes one wants to be notified when entering and exiting a particular node type. An acceptor supporting said pattern might look like this:
Walking with callback functions?On top of that functionality one can provide callback based walker functions:
The
The Example usage of
&mut ContextWithout For this reason I have basically copied all interfaces and provide Unfortunately the borrow checker doesn't like that the
Having many small allocations and free does not sound that nice either. In order to get rid of the allocations one would need Follow upsThese are still rather low-level building blocks. Users get to operate on You can find the complete code (still untested) here. The
Alternative strategy:In |
Beta Was this translation helpful? Give feedback.
-
Actually it would. But before that, let me take some time to ponder over this. |
Beta Was this translation helpful? Give feedback.
-
I'm looking at the latest, why do we need a separation b/w |
Beta Was this translation helpful? Give feedback.
-
After spending some more time on I still find this code quite hard to follow through, mostly the various instantiations. For example, why does walk_blocks, a function that should walk over blocks (of a region?) take a
|
Beta Was this translation helpful? Give feedback.
-
The names are more or less and artifact because I initially started with references to concrete types like I renamed the walk_x methods in the Strategy trait to match the IR entity. Maybe it is more clear now, as it is more similar More important to me right now is the potential direction/approach to the API like traits/types/utility functions we want to expose.
Right. The code consists of 2 functionalities. The actual visitor core ( One does not really need the second one, but I like it for convenience. The Order trait is only part of the later one. I could also have chosen an Enum for Order and instead of exposing
I actually added this implementation to Now we do not need to export the Callback visitor. When implementing an actual visitor you would normally also set the Strategy when implementing the trait. The
Because the other visit method use the configured strategy we do not have to implement them if we want to choose another strategy. If we change Visitor to this
then the implementation of
vs. the type directed approach (which maybe could be optimized better):
|
Beta Was this translation helpful? Give feedback.
-
Thank you @urso . |
Beta Was this translation helpful? Give feedback.
-
Closing this as the main topic of discussion, which is a walker is implemented with #32 . The smaller topic of stronger typing for the type system is implemented with #28. |
Beta Was this translation helpful? Give feedback.
-
In order to give pliron a test run I'm thinking to start with a very simple language. I chose the kaleidoscope language from the LLVM tutorials. One starts very simple with expressions and functions calls. And later eventually adds some control constructs. This makes it a great way to test things out while having a very small set Ops to deal with.
The idea is parse it into a "high level" dialect modeling the language, then lower it to a cranelift based dialect, convert the IR to cranelift and finally execute the generated code.
This also gives us a means to discuss enhancements to pliron on live (but hopefully simple) code.
For the beginning:
Issue: how to use function arguments with the basic blocks?
Do we have an API or plans for extending the API of
FuncOp
to register arguments that can be used as Operands in the function body? See #24Visitor?
We do not have any functionality to walk or rewrite operations, regions, and blocks. There is an draft PR #4, but maybe we should start with a walker API first? Is this something that would fit this project, or shall
pliron
rather focus on the storage + print/parse part for now while we start pushing more complex functionality like walking/rewriting/lowering/pass-manager into external repos and eventually incorporate some functionality that works well back into pliron?#4 has a visitor that seems to resemble the MLIR walker functions.
Support to visit operations recursively is an important building block for more complex operations/transformations. Especially with the potentially arbitrary nesting of IR Ops and regions. Maybe we should start with that pattern and see how it goes.
In contrast to MLIR and #4, I have a more typical visitor pattern based on traits in mind. Maybe even separating the 'Walk' from the 'Visit' part.
Beta Was this translation helpful? Give feedback.
All reactions