From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 2DF203857001 for ; Thu, 2 Sep 2021 21:53:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2DF203857001 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-451-4CHyiFhuM56tIAkRpHTzPA-1; Thu, 02 Sep 2021 17:52:59 -0400 X-MC-Unique: 4CHyiFhuM56tIAkRpHTzPA-1 Received: by mail-qk1-f199.google.com with SMTP id 21-20020a370815000000b003d5a81a4d12so3854580qki.3 for ; Thu, 02 Sep 2021 14:52:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Vfla5ZuM/X4bLexZWWMcY23715bO2dO0K1+mlmshYYw=; b=CYdl4trTBKNe/Ydk/Ljadgmk1JmvfUmWyLo8XtHrefRfe/IbhYszLoLPK/Rze20pgi wrbuljvOzslYp/gkuxufB4VrXOyxTZV+leyQlJ9u6cLOXdFK6pwDQA7UBU8je3uVc7Gb Du+2tG36cFQb5tPDcqy+vpHeP1ntpocpueXqA4CdaftwJBwpWsCsGO551xB4ivXP8wGd hZrhPD00I5irzA7Pd4Yb7i7LClHkCwcm9lFhyQW58LDia5y9GlaGnSWMZsP6KsN5MtvH CAb7bW5P0Sw6hBWFdSheey8NA3ZjwJ4RfWY68I9b6iGNm2rCnz6+e56DvObH93q5YdOd GWIw== X-Gm-Message-State: AOAM533DCm+rXIaMuYjKqDO7Yy/zwzOjUOkIaofWwM6mvjs1dJrrjlwk 69fsaRW1Atn6EFUykuD4EYYPPbSVdJ134SxMFX24BJ4b/Mbm3BOo5JwR/Eprj6rGJARhf2Wi4fz OZVLoJ7rToAMAdQQoxZsA94Tfulv0mZeebaXGXjdZn6hNh8s2GVzbq/GDppFFGWajVA== X-Received: by 2002:ae9:f814:: with SMTP id x20mr267237qkh.266.1630619578279; Thu, 02 Sep 2021 14:52:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyi+FFSKLVpNHdmBZ5d8Sb5r9aXaYR28nWb5BKCjbOVfF+3ADMp5v7b28D3Y7u3eMdJFaBfdw== X-Received: by 2002:ae9:f814:: with SMTP id x20mr267216qkh.266.1630619577946; Thu, 02 Sep 2021 14:52:57 -0700 (PDT) Received: from [192.168.1.149] (130-44-159-43.s11817.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id 12sm1812581qtt.16.2021.09.02.14.52.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 02 Sep 2021 14:52:57 -0700 (PDT) Subject: Re: [PATCH 2/8] coroutines: Add a helper for creating local vars. To: Iain Sandoe , GCC Patches References: <4C7B8763-1292-450A-96FE-A56B66926540@sandoe.co.uk> <3E415FEA-27D9-4C04-BFEE-002F67EED9F6@sandoe.co.uk> From: Jason Merrill Message-ID: <53b742bb-2d19-668c-03b4-0503f656fe2a@redhat.com> Date: Thu, 2 Sep 2021 17:52:56 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Sep 2021 21:53:08 -0000 On 9/1/21 6:53 AM, Iain Sandoe wrote: > > This is primarily code factoring, but we take this opportunity > to rename some of the implementation variables (which we intend > to expose to debugging) so that they are in the implementation > namespace. > > Signed-off-by: Iain Sandoe > > gcc/cp/ChangeLog: > > * coroutines.cc (coro_build_artificial_var): New. > (build_actor_fn): Use var builder, rename vars to use > implementation namespace. > (coro_rewrite_function_body): Likewise. > (morph_fn_to_coro): Likewise. > --- > gcc/cp/coroutines.cc | 69 +++++++++++++++++++++++++++----------------- > 1 file changed, 43 insertions(+), 26 deletions(-) > > diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc > index 2d68098f242..b8501032969 100644 > --- a/gcc/cp/coroutines.cc > +++ b/gcc/cp/coroutines.cc > @@ -1474,6 +1474,29 @@ coro_build_cvt_void_expr_stmt (tree expr, location_t loc) > return coro_build_expr_stmt (t, loc); > } > > +/* Helpers to build an artificial var, with location LOC, NAME and TYPE, in > + CTX, and with initializer INIT. */ > + > +static tree > +coro_build_artificial_var (location_t loc, tree name, tree type, tree ctx, > + tree init) > +{ > + tree res = build_lang_decl (VAR_DECL, name, type); > + DECL_SOURCE_LOCATION (res) = loc; > + DECL_CONTEXT (res) = ctx; > + DECL_ARTIFICIAL (res) = true; > + DECL_INITIAL (res) = init; > + return res; > +} > + > +static tree > +coro_build_artificial_var (location_t loc, const char *name, tree type, > + tree ctx, tree init) > +{ > + return coro_build_artificial_var (loc, get_identifier (name), > + type, ctx, init); > +} > + > /* Helpers for label creation: > 1. Create a named label in the specified context. */ > > @@ -2113,12 +2136,10 @@ build_actor_fn (location_t loc, tree coro_frame_type, tree actor, tree fnbody, > tree top_block = make_node (BLOCK); > BIND_EXPR_BLOCK (actor_bind) = top_block; > > - tree continuation = build_lang_decl (VAR_DECL, > - get_identifier ("actor.continue"), > - void_coro_handle_type); > - DECL_ARTIFICIAL (continuation) = 1; > - DECL_IGNORED_P (continuation) = 1; > - DECL_CONTEXT (continuation) = actor; > + tree continuation = coro_build_artificial_var (loc, "_Coro_actor_continue", > + void_coro_handle_type, actor, > + NULL_TREE); > + > BIND_EXPR_VARS (actor_bind) = continuation; > > /* Link in the block associated with the outer scope of the re-written > @@ -4069,12 +4090,11 @@ coro_rewrite_function_body (location_t fn_start, tree fnbody, tree orig, > fn_start, NULL, /*musthave=*/true); > /* Create and initialize the initial-await-resume-called variable per > [dcl.fct.def.coroutine] / 5.3. */ > - tree i_a_r_c = build_lang_decl (VAR_DECL, get_identifier ("i_a_r_c"), > - boolean_type_node); > - DECL_ARTIFICIAL (i_a_r_c) = true; > + tree i_a_r_c = coro_build_artificial_var (fn_start, "_Coro_i_a_r_c", I might use a bit longer name, since the user doesn't have the comment above to explain the acronym. :) OK either way. > + boolean_type_node, orig, > + boolean_false_node); > DECL_CHAIN (i_a_r_c) = var_list; > var_list = i_a_r_c; > - DECL_INITIAL (i_a_r_c) = boolean_false_node; > add_decl_expr (i_a_r_c); > /* Start the try-catch. */ > tree tcb = build_stmt (fn_start, TRY_BLOCK, NULL_TREE, NULL_TREE); > @@ -4459,8 +4479,10 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer) > add_stmt (ramp_bind); > tree ramp_body = push_stmt_list (); > > - tree coro_fp = build_lang_decl (VAR_DECL, get_identifier ("coro.frameptr"), > - coro_frame_ptr); > + tree zeroinit = build1_loc (fn_start, CONVERT_EXPR, > + coro_frame_ptr, integer_zero_node); > + tree coro_fp = coro_build_artificial_var (fn_start, "_Coro_frameptr", > + coro_frame_ptr, orig, zeroinit); > tree varlist = coro_fp; > > /* To signal that we need to cleanup copied function args. */ > @@ -4478,21 +4500,19 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer) > > /* Signal that we need to clean up the promise object on exception. */ > tree coro_promise_live > - = build_lang_decl (VAR_DECL, get_identifier ("coro.promise.live"), > - boolean_type_node); > - DECL_ARTIFICIAL (coro_promise_live) = true; > + = coro_build_artificial_var (fn_start, "_Coro_promise_live", > + boolean_type_node, orig, boolean_false_node); > DECL_CHAIN (coro_promise_live) = varlist; > varlist = coro_promise_live; > - DECL_INITIAL (coro_promise_live) = boolean_false_node; > + > /* When the get-return-object is in the RETURN slot, we need to arrange for > cleanup on exception. */ > tree coro_gro_live > - = build_lang_decl (VAR_DECL, get_identifier ("coro.gro.live"), > - boolean_type_node); > - DECL_ARTIFICIAL (coro_gro_live) = true; > + = coro_build_artificial_var (fn_start, "_Coro_gro_live", > + boolean_type_node, orig, boolean_false_node); > + > DECL_CHAIN (coro_gro_live) = varlist; > varlist = coro_gro_live; > - DECL_INITIAL (coro_gro_live) = boolean_false_node; > > /* Collected the scope vars we need ... only one for now. */ > BIND_EXPR_VARS (ramp_bind) = nreverse (varlist); > @@ -4508,8 +4528,7 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer) > /* The decl_expr for the coro frame pointer, initialize to zero so that we > can pass it to the IFN_CO_FRAME (since there's no way to pass a type, > directly apparently). This avoids a "used uninitialized" warning. */ > - tree zeroinit = build1 (CONVERT_EXPR, coro_frame_ptr, integer_zero_node); > - DECL_INITIAL (coro_fp) = zeroinit; > + > add_decl_expr (coro_fp); > if (flag_exceptions && DECL_ARGUMENTS (orig)) > for (tree arg = DECL_ARGUMENTS (orig); arg != NULL; > @@ -4969,10 +4988,8 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer) > { > /* ... or ... Construct an object that will be used as the single > param to the CTOR for the return object. */ > - gro = build_lang_decl (VAR_DECL, get_identifier ("coro.gro"), gro_type); > - DECL_CONTEXT (gro) = current_scope (); > - DECL_ARTIFICIAL (gro) = true; > - DECL_IGNORED_P (gro) = true; > + gro = coro_build_artificial_var (fn_start, "_Coro_gro", gro_type, orig, > + NULL_TREE); > add_decl_expr (gro); > gro_bind_vars = gro; > r = cp_build_modify_expr (input_location, gro, INIT_EXPR, get_ro, >