From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 47119 invoked by alias); 20 Jan 2020 12:33:01 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 47108 invoked by uid 89); 20 Jan 2020 12:33:01 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.4 required=5.0 tests=AWL,BAYES_00,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham version=3.3.1 spammy=H*f:sk:8dd6586, H*i:sk:8FA4CE6, H*MI:sk:8FA4CE6, H*f:sk:8FA4CE6 X-HELO: out30-54.freemail.mail.aliyun.com Received: from out30-54.freemail.mail.aliyun.com (HELO out30-54.freemail.mail.aliyun.com) (115.124.30.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 20 Jan 2020 12:32:51 +0000 X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04396;MF=junma@linux.alibaba.com;NM=1;PH=DS;RN=2;SR=0;TI=SMTPD_---0ToET7ge_1579523566; Received: from MacBook-Pro-6.local(mailfrom:JunMa@linux.alibaba.com fp:SMTPD_---0ToET7ge_1579523566) by smtp.aliyun-inc.com(127.0.0.1); Mon, 20 Jan 2020 20:32:47 +0800 Subject: Re: [PATCH Coroutines] Fix issue with unused corutine function parameters To: Iain Sandoe Cc: gcc-patches References: <490e331a-e1f2-bee4-e150-4df87c752bfc@linux.alibaba.com> <322DA693-B320-4B9F-AAA6-1F4F781A15E8@sandoe.co.uk> <8dd65869-0325-5e48-d683-8fdbfc694bb8@linux.alibaba.com> <8FA4CE61-C1DD-4491-9FA6-8445BACB5D0D@sandoe.co.uk> From: JunMa Message-ID: Date: Mon, 20 Jan 2020 12:54:00 -0000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <8FA4CE61-C1DD-4491-9FA6-8445BACB5D0D@sandoe.co.uk> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2020-01/txt/msg01207.txt.bz2 在 2020/1/20 下午8:21, Iain Sandoe 写道: > JunMa wrote: > >> 在 2020/1/20 下午7:55, Iain Sandoe 写道: >>> Hi JunMa, >>> >>> JunMa wrote: >>> >>>> 在 2020/1/20 下午6:07, Iain Sandoe 写道: >>>>> Hi JunMa, >>>>> >>>>> JunMa wrote: >>>>> >>>>>> Hi >>>>>> Accroding to N4835: When a coroutine is invoked, a copy is created >>>>>> for each coroutine parameter. While in current implementation, we >>>>>> only collect used parameters. This may lost behavior inside >>>>>> constructor >>>>>> and destructor of unused parameters. >>>>>> >>>>>> This patch change the implementation to collect all parameter. >>>>> thanks for the patch. >>>>> >>>>> I am not convinced this is the right way to fix this, we do not >>>>> want to increase >>>>> the size of the coroutine frame unnecessarily.  I would like to >>>>> check the lifetime >>>>> requirements; such copies might only need to be made local to the >>>>> ramp function. >>>>> >>>>> Iain >>>> For type with trivial destructor, There is no need to copy >>>> parameter if it is >>>> never referenced after a reachable suspend >>>> point(return-to-caller/resume) in the >>>> coroutine. Since we are in front end, that should be inital_suspend >>>> point. so we >>>> can create field for type with non-trivial destructor first, and >>>> skip unused parameters >>>> in register_param_uses. I'll update the patch >>> I think that, even if the DTOR is non-trivial, the copy only needs >>> to be in the stack >>> frame of the ramp, not in the coroutine frame. >> I do think this.  It's just need more work on front end. > > I think we already did the work, and know the answer (about param uses > in the body), right? Yes, we may need extra work on copy parameters, I'll do this. > >>> This is also what clang does for -O>0 (although it makes a frame >>> copy at O0). >>> >>> Will clarify this (perhaps the wording could be slightly more specfic). >> No, clang build frame in middle end. In FE, it just generate local >> variable to do the copy, and let the middle end to >> do the optimization which can see more opportunity. > > Yes, i understand that clang does this in the ME not in the FE but, so > long as the principle is correct, it is equivalent for GCC to do this > in the FE. > Yes, just less situation we can handle, that's why we still need coroutine frame reduction pass. Regards JunMa > thanks > Iain > >> >> Regards >> JunMa >>> thanks >>> Iain >>> >>>> Regards >>>> JunMa >>>>>> Bootstrap and test on X86_64, is it OK? >>>>>> >>>>>> Regards >>>>>> JunMa >>>>>> >>>>>> gcc/cp >>>>>> 2020-01-20  Jun Ma >>>>>> >>>>>>         * coroutines.cc (build_actor_fn): Skip rewrite when there >>>>>> is no >>>>>>         param references. >>>>>>         (register_param_uses): Only collect param references here. >>>>>>         (morph_fn_to_coro): Create coroutine frame field for each >>>>>>         function params. >>>>>> >>>>>> gcc/testsuite >>>>>> 2020-01-20  Jun Ma >>>>>> >>>>>>         * g++.dg/coroutines/torture/func-params-07.C: New test. >>>>>> <0001-Fix-issue-when-copy-function-parameters-into-corouti.patch> >