-
Notifications
You must be signed in to change notification settings - Fork 103
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
[CIR][CIRGen] Fixes function calls with return values and cleanup stage #1214
Conversation
(cc @smeenai) |
Thanks for working on this, we are in the middle of redesigning exceptions and cleanups, so good timing. The fact that we try to use one I'd prefer a mix between (1) and (2): a call operation that has a high level invoke semantics (i.e. it has an attached catch):
We lose the "merging" capabilities I mentioned earlier, but perhaps we can look at it later in the pipeline. If we go this route, another problem would be how to integrate try/catches, perhaps those could be enforced not to have a catch blocks? Thoughts? |
(cc @ChuanqiXu9 which asked another question recently) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for fixing this!
In #1123, we've been discussing a potential alternative representation of cleanups, which might help here. For the current way cleanups are setup, is there any way to have the store to the b
alloca occur directly inside the cir.try_synthetic
, instead of going through tmp
?
At the first glance I don't see such way - at the moment |
What is the problem with try/catches? I'm not sure I understand.
So is it better to close the PR for now? There are several other C++ things I wanted to take a look at. But I can continue here as well - so up to you to decide, what is better. |
It's not a problem, it's more about the fact that automatic variables inside try/catch are already allocated within the cir.try scope, meaning we don't have the same problem as the synthetic version does.
This is more of a future opt, in order to lower multiple cleanups region to the same basic block, I was thinking about adding an operation to tag identical landing pads (CIRGen knows exactly which ones are the same, so we could leverage that). I haven't fleshed out all the details, but this is my brain dump.
This is definetely how we probably want to see it out of CIRGen, it was more about a future opt!
This PR is good (see below), but because I'm working on making cleanups closer to OG, I had to give it a break on all multiple inheritance stuff, so that route is also open if you want to look at those.
This is a good change and will fix real problems we are all facing. I'm focusing first on general cleanups (not necessarily exception related) so I think you should go ahead with this approach - when (if) we change the design of this later we can rely on the testcases you added and make sure we don't regress. If possible, it would probably be nice if this PR can get rid of the extra alloca/load/store during FlattenCFG, but more like bonus point. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I tried this in Spec2017 and it fixes a problem. Are you doing similar things?
✅ With the latest revision this PR passed the C/C++ code formatter. |
892b92e
to
c78799e
Compare
Not the same but similar!)
Well, I would glad to get the extra bonus point) but looks like there are around 10 tests that fail if I eliminate the temp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after some nits.
You just introduced this alloca, that's surprising.
Oh, I'm actually only worried about the ones you just introduced, not anything new. It can come in another PR though, since it's a small cleanup / improvement. Thank you! |
@bcardosolopes done! |
The Problem
Let's take a look at the following code:
The call to
foo
guarded by the synthetictryOp
looks approximately like the following:The result of the
foo
call is in thetry
region - and is not accessible from the outside, so the code generation fails withoperand #0 does not dominate its use
.Solution
So we have several options how to handle this properly.
TryCall
but probably more high level one, e.g. introduce theInvokeOp
.TryOp
.alloca
where we store the call result right in the try region. And the result of the wholeemitCall
is aload
from the tempalloca
.So this PR is both the request for changes and an open discussion as well - how to handle this properly. So far I choose the third approach. If it's ok - I will need to create one more PR with a similar fix for the aggregated results or update this one.