[PATCH] D137872: Implement lambdas with inalloca parameters by forwarding to function without inalloca calling convention.

Eli Friedman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 19 11:48:30 PDT 2023


efriedma added a comment.

In D137872#4348314 <https://reviews.llvm.org/D137872#4348314>, @akhuang wrote:

> In D137872#4327615 <https://reviews.llvm.org/D137872#4327615>, @efriedma wrote:
>
>> I'm having a bit of trouble following how exactly the thunk creation is working here... do we generate different code depending on whether the call operator and/or the static invoker are referenced?
>
> So I think it used to be that the static invoker calls the call operator which contains the body of the lambda? And now both the static invoker and the call operator are delegating to this new __impl function. In EmitLambdaStaticInvokeBody it first calls EmitLambdaInAllocaCallOpFn to make the new call operator (which is populated using EmitLambdaDelegatingInvokeBody). And then inside EmitLambdaDelegatingInvokeBody it generates the new impl function and calls it in the body. Not sure if that answers the question, I agree the code is a bit roundabout.
>
>> Why is the function in EmitLambdaInAllocaCallOpFn not getting defined using the normal CodeGenModule machinery?
>
> Do you mean why it's not using CodeGenModule machinery to generate the new call op body or why we're changing the original call op body?

I mean why it's not using the CodeGenModule machinery.  I understand there are three function bodies involved.  But I would expect that when you "emit" the lambda call operator, it emits the entry point for the call and for the call impl, and when you emit the static invoker, it just emits a call to the call impl.

Or... hmm.  Is this actually erasing the existing definition of the call operator, if it was already emitted?  That probably doesn't actually work in general; once a function is emitted, you can't re-emit it.  Emitting a function emits other related stuff like static variables; you can't EmitFunctionBody() more than once.  Either you need to decide when it's first emitted, or you need to rewrite the signature of the definition and splice the existing body in.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137872/new/

https://reviews.llvm.org/D137872



More information about the cfe-commits mailing list