在 2020/2/6 下午5:12, Iain Sandoe 写道:
Hi JunMa,

JunMa <ju...@linux.alibaba.com> wrote:

在 2020/2/4 下午8:17, JunMa 写道:
Hi
When testing coroutines with lambda function, I find we copy each captured variable to frame. However, according to gimplify pass, for each declaration
that is an alias for another expression(DECL_VALUE_EXPR), we can
substitute them directly.

Since lambda captured variables is one of this kind. It is better to replace them rather than copy them, This can reduce frame size (all of the captured variables
are field of closure class) and avoid extra copy behavior as well.

This patch remove all of the code related to copy captured variable.
Instead, we first rewrite DECL_VALUE_EXPR with frame field, then we check every variable whether it has DECL_VALUE_EXPR, and then substitute it, this
patch does not create frame field for such variables.

Bootstrap and test on X86_64, is it OK?

minor update: only handle var_decl when iterate BIND_EXPR_VARS
in register_local_var_uses.

Do you have any other local patches applied along with this?

Testing locally (on Darwin), I see regressions with optimisation O2/O3/Os e.g:

class-05-lambda-capture-copy-local.C   -O2  (internal compiler error)
class-06-lambda-capture-ref.C   -O2  (internal compiler error)
lambda-05-capture-copy-local.C   -O2  (internal compiler error)
lambda-06-multi-capture.C   -O2  (internal compiler error)
lambda-07-multi-capture.C   -O2  (internal compiler error)
lambda-08-co-ret-parm-ref.C   -O3 -g  (internal compiler error)

I have applied this to master, and on top of the patches posted by you and
Bin, but the results are the same.

+Bin
This is known issue which has been fixed by Bin, he will send the patch.

Regards
JunMa
thanks
Iain

gcc/cp
2020-02-04  Jun Ma <ju...@linux.alibaba.com>

        * coroutines.cc (morph_fn_to_coro): Remove code related to
        copy captured variable.
        (register_local_var_uses):  Ditto.
        (register_param_uses):  Collect use of parameters inside
        DECL_VALUE_EXPR.
        (transform_local_var_uses): Substitute the alias variable
        with DECL_VALUE_EXPR if it has one.


gcc/testsuite
2020-02-04  Jun Ma <ju...@linux.alibaba.com>

        * g++.dg/coroutines/lambda-07-multi-capture.C: New test.


<0001-fix-alias-variable.patch>


Reply via email to