-
Notifications
You must be signed in to change notification settings - Fork 80
irgen: starter instructions #153
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
Comments
I know phi instructions are a bit difficult to deal with, especially as they often have to reference LLVM IR values which have not yet been defined. I think these kind of checks belong to two places, namely as a validation step in an The intention is still to keep the core Note, in prior versions of What do you think? Cheers, |
I understand your consideration, but here is not actually about validating, the real problem is operating on instruction is hard for the user. Most user won't read source code and follow several internal conventions when modifying existed instruction, if we let them look into implementation is even more harmful since implementation might change, I would tend to avoid such situation. I also check again, I believe only
Hence, I still would like to implement this one to avoid leak of abstraction and have more free for future changes. |
I agree with you that for most users and use cases, creating phi instructions is difficult, and for this reason, the general recommendation for front-end compiler developers is to instead rely on the -mem2reg optimization pass of LLVM and model local variables using This was mentioned in the "LLVM IR and Go" post on Gopher Academy.
I still understand your preference to change the API. Sorry to be so resistant in this regard. The main reason is still that I believe a really good LLVM IR builder API is yet to be defined. And indeed, Similarly to the For background reference, these topics were discussed and brought up in #3 (comment)
Cheers, |
Ok, wrapping on llir was also a good choice, I would make some experiments irgen once I have time. |
That's great! :) |
In https://pkg.go.dev/github.com/dannypsnl/[email protected]#ExtBlock.NewPhi you can get exactly what I described above. initExpr := ...
step := ...
extBlock.NewPhi(
ir.NewIncoming(initExpr, nextBlock),
ir.NewIncoming(step, loopBlock),
) In above code, So I'm going to close this due to the solution existing. Feel free to reopen if you want anything more~~~ |
@mewmew sorry that I reopen the issue, so after some thought, I still want to port this behavior back to type Block struct {
Phis []*InstPhi
Insts []Instruction
} Now,
The benefit is that
|
@dannypsnl, would |
PHI instructions will only be in |
Thanks for clarifying. Given that we would no longer place PHI instructions in Any code like this would stop working: for _, inst := range block.Insts {
switch inst := inst.(type) {
case *ir.InstPhi:
// operate on PHI instruction.
}
} Therefore, we have to think hard before introducing such a change, due to API breakage. If the benefit is determined to outweigh the drawbacks of API breakage, then the change may still be introduced (we are still in I will try to give it some thought, but I am leaning towards having the Cheers, |
If we only do this on v0.4? |
I am having doubts since all existing code would stop working (if handling PHI nodes using This is very subtle and would be confusion for users of I agree that having PHI nodes distinct from However, making such a change now is risky, as it could cause a lot of code to break by our users, even if they don't realize it (since the code would still compile). So, for the time being, I'm in favour of letting other Note, this is a very good case to check for in the new Cheers, |
I think this is fine, their program would be fine with dependencies lock(this is why we versioning). Rather than check ideas for a long time and users still suffering from the current codebase, my preferred release solution is
Thus, we provide a promise: you only have one thing to change in the compiler for every update. For users that didn't use the package for a long time, there has no reason to believe they will go back without relearning. For users that actively using the package, this flow should be enough. And notice this proposal is not just since we could go wrong, but also for easier to write IR correct! I think form code to be correct at the beginning is better than check them later. |
I agree with your reasoning. The thing that scares me is that some users may simply do Otherwise, I agree that it is good practice to make the API easier to use correctly (and more difficult to use incorrectly), so if we would have thought about the So, I still have to give this some thought. It may be possible that we do update, and then write a tool to send PRs to all known open source projects that need to be updated, e.g. by writing our own Cheers, |
Just a hint: https://github.com/search?q=%27case+*ir.InstPhi%27+language%3AGo&type=code we actually can detect some effect range? |
According to language reference: phi:
and the following code can be compiled by
llc
:That means
phi
is kind of starter instruction, and we can have several starter instructions which always be put at the beginning of the basic block, then we can avoid this kind of code:We can do like this:
but won't break order we expected, and we would have new BasicBlock definition.
The text was updated successfully, but these errors were encountered: