-
Notifications
You must be signed in to change notification settings - Fork 3
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
feature: PHI Node creation binding #3
base: master
Are you sure you want to change the base?
Conversation
Wow! You beat me to the punch! This was the next instruction I was planning on adding (as I will need it for conditional return blocks when emitting LLVM for Lean). Will merge it soon. |
I went through the list of not implemented instructions and considered which might be the most useful :). So this seemed like a good place to contribute. |
fa8dee8
to
f85bc73
Compare
Some notes on style:
|
Thanks for your comments, this codebase is teaching me a lot :). |
@cpehle one thing to keep in mind about using Lean's I also just don't see the use for index-specific getters/setters for something like |
f85bc73
to
8b95454
Compare
I just meant the convention in Haskell to prefix functions that are unsafe with that word, like
I've added this setter aswell now, when writing FFI I prefer to go for completeness if easily possible, but I will defer to your judgement. |
8b95454
to
455ec56
Compare
One other option for the unsafe operations would be to postfix them with an exclamation mark "!", that is what is used in the FloatArray package for unsafe operations. |
455ec56
to
a76a867
Compare
a76a867
to
5e0265a
Compare
984fd02
to
a92950d
Compare
@cpehle The Also, if any of the cleanup is to tedious for you, don't worry, I will do some cleanup myself after I merge the PR. |
Ok fair enough, as I understand the use case of the Phi Node in the project now, they would not be needed. On the script side I think the way things are currently setup make it hard to use the phi node. The following does not work llvm module phiTest do
define double @baz(i1 %test, double %a, double %b) do
br1:
%c1 = fadd double %a %b
br %ifcont
br2:
%c2 = fsub double %a %b
br %ifcont
ifcont:
%iftmp = phi double [ %c1, %br1 ], [ %c2, %br2 ]
ret double %iftmp
br %test, %br1, %br2 I think this might be a limitation of the script API at the moment. It should be possible to use the monadic API to first allocate basic blocks manually and then wire things up, but I did not see a way to use (<- read) and still make use of the labels. |
@cpehle see, now this what I was talking about when I said there were still refactors in the works that I still needed to do! 😆 I am planning on supporting an alternate brace-based function body syntax that will wire up the basic blocks first before building them just like you suggested. I also considering having values using the In other words, migrating the script implementation from it's current ad-hoc current state to something better designed and written is the core of the refactoring I need to do. Once it's cleaned adding more complete support for LLVM's IR is a much more reasonable proposition. |
a92950d
to
b977e05
Compare
😀. I think the solution of SIL (swift intermediate language) and MLIR is quite elegant: Instead of PHI nodes basic blocks take arguments. That doesn't obviate doing something different from what is done now, but might make sense. |
@cpehle That's a wonderful solution! I am still aiming to have the Script DSL be a superset of LLVM IR (hence the need for the brace-based approach), but I think that be a great way to handle phi nodes in the more Lean-style It would actually resolve the conundrum I was having for implementation a catch-all PHI node return block. Many functions would use such a block, but I didn't want it to be generated in functions that did not. With this solution, it would just be another parameterized basic block. |
Yes exactly, it also emphasises the fact that basic blocks are secretly let bound local functions (https://www.cs.princeton.edu/~appel/papers/ssafun.pdf). The LLVM dialect in MLIR also supports this style of blocks (https://mlir.llvm.org/docs/Dialects/LLVM/). |
I believe there is still some cleanup to do and some / a lot more tests to write. I might have some time on the weekend, otherwise I'm really occupied the next week, so I can't spend much time on this. |
@cpehle That's fine (I am similarly busy). I'll merge what's here when I have the time and clean it up as necessary. |
Still needs test + more bindings.