From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp002.apm-internet.net (smtp002.apm-internet.net [85.119.248.221]) by sourceware.org (Postfix) with ESMTPS id D33313858023 for ; Wed, 1 Sep 2021 10:52:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D33313858023 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sandoe.co.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=sandoe.co.uk Received: (qmail 26760 invoked from network); 1 Sep 2021 10:52:31 -0000 X-APM-Out-ID: 16304935512675 X-APM-Authkey: 257869/1(257869/1) 4 Received: from unknown (HELO ?192.168.1.214?) (81.138.1.83) by smtp002.apm-internet.net with SMTP; 1 Sep 2021 10:52:31 -0000 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.21\)) Subject: [PATCH 1/8] coroutines : Use DECL_VALUE_EXPR instead of rewriting vars. From: Iain Sandoe In-Reply-To: <4C7B8763-1292-450A-96FE-A56B66926540@sandoe.co.uk> Date: Wed, 1 Sep 2021 11:52:30 +0100 Content-Transfer-Encoding: quoted-printable Message-Id: <3E415FEA-27D9-4C04-BFEE-002F67EED9F6@sandoe.co.uk> References: <4C7B8763-1292-450A-96FE-A56B66926540@sandoe.co.uk> To: GCC Patches X-Mailer: Apple Mail (2.3445.104.21) X-Spam-Status: No, score=-15.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_COUK, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, 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: Wed, 01 Sep 2021 10:52:43 -0000 Hi, Variables that need to persist over suspension expressions must be preserved by being copied into the coroutine frame. The initial implementations do this manually in the transform code. However, that has various disadvantages - including that the debug connections are lost between the original var and the frame copy. The revised implementation makes use of DECL_VALUE_EXPRs to contain the frame offset expressions, so that the original var names are preserved in the code. This process is also applied to the function parms which are always copied to the frame. In this case the decls need to be copied since they are used in two different contexts during the re-write (in the building of the ramp function, and in the actor function itself). This will assist in improvement of debugging (PR 99215). Signed-off-by: Iain Sandoe gcc/cp/ChangeLog: * coroutines.cc (transform_local_var_uses): Record frame offset expressions as DECL_VALUE_EXPRs instead of rewriting them. --- gcc/cp/coroutines.cc | 105 +++---------------------------------------- 1 file changed, 5 insertions(+), 100 deletions(-) diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index ceb3d3be75e..2d68098f242 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -1974,8 +1974,7 @@ transform_local_var_uses (tree *stmt, int = *do_subtree, void *d) local_vars_transform *lvd =3D (local_vars_transform *) d; =20 /* For each var in this bind expr (that has a frame id, which means = it was - accessed), build a frame reference for each and then walk the bind = expr - statements, substituting the frame ref for the original var. */ + accessed), build a frame reference and add it as the = DECL_VALUE_EXPR. */ =20 if (TREE_CODE (*stmt) =3D=3D BIND_EXPR) { @@ -1991,13 +1990,9 @@ transform_local_var_uses (tree *stmt, int = *do_subtree, void *d) /* Re-write the variable's context to be in the actor func. = */ DECL_CONTEXT (lvar) =3D lvd->context; =20 - /* For capture proxies, this could include the decl value expr. = */ - if (local_var.is_lambda_capture || local_var.has_value_expr_p) - { - tree ve =3D DECL_VALUE_EXPR (lvar); - cp_walk_tree (&ve, transform_local_var_uses, d, NULL); + /* For capture proxies, this could include the decl value = expr. */ + if (local_var.is_lambda_capture || local_var.has_value_expr_p) continue; /* No frame entry for this. */ - } =20 /* TODO: implement selective generation of fields when vars = are known not-used. */ @@ -2011,103 +2006,13 @@ transform_local_var_uses (tree *stmt, int = *do_subtree, void *d) tree fld_idx =3D build3_loc (lvd->loc, COMPONENT_REF, = TREE_TYPE (lvar), lvd->actor_frame, fld_ref, = NULL_TREE); local_var.field_idx =3D fld_idx; - } - /* FIXME: we should be able to do this in the loop above, but (at = least - for range for) there are cases where the DECL_INITIAL contains - forward references. - So, now we've built the revised var in the frame, substitute = uses of - it in initializers and the bind expr body. */ - for (lvar =3D BIND_EXPR_VARS (*stmt); lvar !=3D NULL; - lvar =3D DECL_CHAIN (lvar)) - { - /* we need to walk some of the decl trees, which might contain - references to vars replaced at a higher level. */ - cp_walk_tree (&DECL_INITIAL (lvar), transform_local_var_uses, = d, - NULL); - cp_walk_tree (&DECL_SIZE (lvar), transform_local_var_uses, d, = NULL); - cp_walk_tree (&DECL_SIZE_UNIT (lvar), = transform_local_var_uses, d, - NULL); + SET_DECL_VALUE_EXPR (lvar, fld_idx); + DECL_HAS_VALUE_EXPR_P (lvar) =3D true; } cp_walk_tree (&BIND_EXPR_BODY (*stmt), transform_local_var_uses, = d, NULL); - - /* Now we have processed and removed references to the original = vars, - we can drop those from the bind - leaving capture proxies = alone. */ - for (tree *pvar =3D &BIND_EXPR_VARS (*stmt); *pvar !=3D NULL;) - { - bool existed; - local_var_info &local_var - =3D lvd->local_var_uses->get_or_insert (*pvar, &existed); - gcc_checking_assert (existed); - - /* Leave lambda closure captures alone, we replace the *this - pointer with the frame version and let the normal process - deal with the rest. - Likewise, variables with their value found elsewhere. - Skip past unused ones too. */ - if (local_var.is_lambda_capture - || local_var.has_value_expr_p - || local_var.field_id =3D=3D NULL_TREE) - { - pvar =3D &DECL_CHAIN (*pvar); - continue; - } - - /* Discard this one, we replaced it. */ - *pvar =3D DECL_CHAIN (*pvar); - } - *do_subtree =3D 0; /* We've done the body already. */ return NULL_TREE; } - - tree var_decl =3D *stmt; - /* Look inside cleanups, we don't want to wrap a statement list in a - cleanup. */ - bool needs_cleanup =3D true; - if (TREE_CODE (var_decl) =3D=3D CLEANUP_POINT_EXPR) - var_decl =3D TREE_OPERAND (var_decl, 0); - else - needs_cleanup =3D false; - - /* Look inside the decl_expr for the actual var. */ - bool decl_expr_p =3D TREE_CODE (var_decl) =3D=3D DECL_EXPR; - if (decl_expr_p && TREE_CODE (DECL_EXPR_DECL (var_decl)) =3D=3D = VAR_DECL) - var_decl =3D DECL_EXPR_DECL (var_decl); - else if (TREE_CODE (var_decl) !=3D VAR_DECL) - return NULL_TREE; - - /* VAR_DECLs that are not recorded can belong to the proxies we've = placed - for the promise and coroutine handle(s), to global vars or to = compiler - temporaries. Skip past these, we will handle them later. */ - local_var_info *local_var_i =3D lvd->local_var_uses->get (var_decl); - - if (local_var_i =3D=3D NULL) - return NULL_TREE; - - if (local_var_i->is_lambda_capture - || local_var_i->is_static - || local_var_i->has_value_expr_p) - return NULL_TREE; - - /* This is our revised 'local' i.e. a frame slot. */ - tree revised =3D local_var_i->field_idx; - gcc_checking_assert (DECL_CONTEXT (var_decl) =3D=3D lvd->context); - - if (decl_expr_p && DECL_INITIAL (var_decl)) - { - location_t loc =3D DECL_SOURCE_LOCATION (var_decl); - tree r - =3D cp_build_modify_expr (loc, revised, INIT_EXPR, - DECL_INITIAL (var_decl), = tf_warning_or_error); - if (needs_cleanup) - r =3D coro_build_cvt_void_expr_stmt (r, EXPR_LOCATION (*stmt)); - *stmt =3D r; - } - else - *stmt =3D revised; - - if (decl_expr_p) - *do_subtree =3D 0; /* We've accounted for the nested use. */ return NULL_TREE; } =20 --=20