From patchwork Fri Aug 2 10:43:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 1968295 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=bF9VCQ3d; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wb2Vy2t1Wz1yYq for ; Fri, 2 Aug 2024 20:43:34 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6626E385C6C6 for ; Fri, 2 Aug 2024 10:43:32 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 81E963858D35 for ; Fri, 2 Aug 2024 10:43:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 81E963858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 81E963858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::432 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722595388; cv=none; b=WwKIbtW49/8EXo+qCKdo0mG0OYeEWkSwdDZp7bFXO5p1FjsCJrqzSNPpJrT2Ymh1PEfb2gNGn4/I2FG7l8LqGDmEI8raejV2154vV36/flx7A4ShzSwfKRxzjgKwlVq3dTYFmoH6OjVamvgv2hwyT40U04ZWIrsD9JbNgNyXBQQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722595388; c=relaxed/simple; bh=r1t1Dljo2fJPMUJPiLQCT4pTSazqdvC++2it/RwRHzg=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=XaRJ0zThO8E8xAL0V7FP2CgUG0G46GCS3hNEoMh2yidn3h27Zf1f5WBMhgi0MdAvc2rf/XqYoDekpAJQz9BvmU99DzChGkZ5A/3g4VIyDZPcBPIz+1GR2lSgcTPNOUsJwcC9mrVFOUVyfSBM7IHGtS1XT3zONrs7OPgNg891Zxs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-368f92df172so4008839f8f.2 for ; Fri, 02 Aug 2024 03:43:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722595384; x=1723200184; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:to:from:from:to:cc:subject:date:message-id:reply-to; bh=H/YuAZOtOveYFlo5xTudFqeKDlqpZAXxIjvN82O2suk=; b=bF9VCQ3dUftO1WgM2OYIN28IhgHBPZaLFRKJDdFkLImoIR7V6/pHAdwTVxxDGSIAx+ u+ahGmlncIvYW5rfUl2n2e6coo9bgTMS4Zk5Nka1u2r2IaDQANYaIVwgvBTUYYFAdg7t guvdHAwzukiOU56UcPgK3sX2EdtYFMMz7ABRAwzoZqNC0QUazKsSZgDQDtZaN495GLe8 vE9AeOKyPGLLbQtLPkCdhGIy+9Zbjdl2RKQaDJGHdDxYzoiox2251sMitcgjs1TQLm/N svA6NjNTVQKkIyB6b5ReHEFhIid3HJ+drIpWf4EGolHq/xTqOax3LVmBMI0JvNVUR5YV 0pgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722595384; x=1723200184; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=H/YuAZOtOveYFlo5xTudFqeKDlqpZAXxIjvN82O2suk=; b=RlDr35JTU3WRwV8uvmOscmVEWPf1aTO2q2Se9Zz0DN2xWtfBPk70Plg0PsMo9hkYXb y5/flkuYrK2PtaxE8CWTzp4E5dOfV0WLFEXSdV0k0N+EECEKddGNw+y6yl/nhRjJa20E w5pDeSWAKfPrUnjr6cbuo+amFPVQ/cF+me3Z5U/2HOBcKyJ27uT5PUjeNATVIB1zYwNI L9Yy5ELKSl5hTYp5cgT2io3vGyqQThQ3jZZL5W+8o+AFvqUIzneHuwuE7ubkxnnYwzHM fZJQ6SP+M6MVGtiJ5t685uhftP8R7Yap0OIMdt85E8EEWSyzn3NjcpnfANG7fcG4fsvs uM+A== X-Gm-Message-State: AOJu0YxG6RBK/qpyTn9sjdQ8dWnGV0erF8AqUCkCKCGqpLCDhmh6NaYY boUsCFHxoK3Msg/O17X31I9NXywZtc7+AZ5Cnr2bohNTYsag5mPzyt5ZJkPa X-Google-Smtp-Source: AGHT+IHIHvzuUFFmBPIe/5y9EQvEi2OZuG0WVWFmh98wexOjSeagNxDLRc+R2rrXcEdQGhTM+Px+Lg== X-Received: by 2002:a5d:5f43:0:b0:367:4dce:1ff5 with SMTP id ffacd0b85a97d-36bbc0e7593mr2288769f8f.32.1722595383266; Fri, 02 Aug 2024 03:43:03 -0700 (PDT) Received: from localhost.localdomain (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36bbd01ee30sm1649835f8f.50.2024.08.02.03.43.02 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 02 Aug 2024 03:43:02 -0700 (PDT) From: Iain Sandoe X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [pushed] c++, coroutines: Remove unused suspend point state [NFC]. Date: Fri, 2 Aug 2024 11:43:02 +0100 Message-Id: <20240802104302.40990-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.39.2 (Apple Git-143) MIME-Version: 1.0 X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: iain@sandoe.co.uk Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Tested on x86_64-darwin, pushed to trunk as obvious, thanks Iain --- 8< --- We maintain state on the progress of await analysis in an object that is passed to the various tree walks used. Some of the state had become stale (i.e. unused members). Remove those and provide a CTOR so that updates are localised. Remove the file scope hash_map used to collect the final state for the actor function and make that part of the suspend point state. gcc/cp/ChangeLog: * coroutines.cc (struct susp_frame_data): Remove unused members, provide a CTOR. (morph_fn_to_coro): Use susp_frame_data CTOR, and make the suspend state hash map local to the morph function. Signed-off-by: Iain Sandoe --- gcc/cp/coroutines.cc | 56 +++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index 9c1e5f0c5d7..78a72047846 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -1988,12 +1988,11 @@ struct suspend_point_info tree await_field_id; }; -static hash_map *suspend_points; - struct await_xform_data { tree actor_fn; /* Decl for context. */ tree actor_frame; + hash_map *suspend_points; }; /* When we built the await expressions, we didn't know the coro frame @@ -2003,7 +2002,7 @@ struct await_xform_data static tree transform_await_expr (tree await_expr, await_xform_data *xform) { - suspend_point_info *si = suspend_points->get (await_expr); + suspend_point_info *si = xform->suspend_points->get (await_expr); location_t loc = EXPR_LOCATION (await_expr); if (!si) { @@ -2227,6 +2226,7 @@ coro_get_frame_dtor (tree coro_fp, tree orig, tree frame_size, static void build_actor_fn (location_t loc, tree coro_frame_type, tree actor, tree fnbody, tree orig, hash_map *local_var_uses, + hash_map *suspend_points, vec *param_dtor_list, tree resume_idx_var, unsigned body_count, tree frame_size) { @@ -2407,7 +2407,7 @@ build_actor_fn (location_t loc, tree coro_frame_type, tree actor, tree fnbody, /* Now we know the real promise, and enough about the frame layout to decide where to put things. */ - await_xform_data xform = {actor, actor_frame}; + await_xform_data xform = {actor, actor_frame, suspend_points}; /* Transform the await expressions in the function body. Only do each await tree once! */ @@ -2642,7 +2642,8 @@ build_init_or_final_await (location_t loc, bool is_final) function. */ static bool -register_await_info (tree await_expr, tree aw_type, tree aw_nam) +register_await_info (tree await_expr, tree aw_type, tree aw_nam, + hash_map *suspend_points) { bool seen; suspend_point_info &s @@ -2663,21 +2664,26 @@ register_await_info (tree await_expr, tree aw_type, tree aw_nam) struct susp_frame_data { /* Function-wide. */ - tree *field_list; /* The current coroutine frame field list. */ - tree handle_type; /* The self-handle type for this coroutine. */ - tree fs_label; /* The destination for co_returns. */ + tree fs_label; /* The destination for co_returns. */ + hash_map *suspend_points; /* Not owned. */ vec *block_stack; /* Track block scopes. */ vec *bind_stack; /* Track current bind expr. */ - unsigned await_number; /* Which await in the function. */ - unsigned cond_number; /* Which replaced condition in the fn. */ + unsigned await_number = 0; /* Which await in the function. */ + unsigned cond_number = 0; /* Which replaced condition in the fn. */ + /* Temporary values for one statement or expression being analyzed. */ - hash_set captured_temps; /* The suspend captured these temps. */ - vec *to_replace; /* The VAR decls to replace. */ - hash_set *truth_aoif_to_expand; /* The set of TRUTH exprs to expand. */ - unsigned saw_awaits; /* Count of awaits in this statement */ - bool captures_temporary; /* This expr captures temps by ref. */ - bool needs_truth_if_exp; /* We must expand a truth_if expression. */ - bool has_awaiter_init; /* We must handle initializing an awaiter. */ + hash_set *truth_aoif_to_expand = nullptr; /* The set of TRUTH exprs to expand. */ + unsigned saw_awaits = 0; /* Count of awaits in this statement */ + bool captures_temporary = false; /* This expr captures temps by ref. */ + bool needs_truth_if_exp = false; /* We must expand a truth_if expression. */ + bool has_awaiter_init = false; /* We must handle initializing an awaiter. */ + + susp_frame_data (tree _final_susp, hash_map *_spt) + : fs_label (_final_susp), suspend_points (_spt) + { + block_stack = make_tree_vector (); + bind_stack = make_tree_vector (); + } }; /* If this is an await expression, then count it (both uniquely within the @@ -2708,7 +2714,7 @@ register_awaits (tree *stmt, int *, void *d) tree aw_field_type = TREE_TYPE (aw); tree aw_field_nam = NULL_TREE; - register_await_info (aw_expr, aw_field_type, aw_field_nam); + register_await_info (aw_expr, aw_field_type, aw_field_nam, data->suspend_points); /* Rewrite target expressions on the await_suspend () to remove extraneous cleanups for the awaitables, which are now promoted to frame vars and @@ -4540,7 +4546,6 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer) 1. Types we already know. */ tree fn_return_type = TREE_TYPE (TREE_TYPE (orig)); - tree handle_type = get_coroutine_handle_type (orig); tree promise_type = get_coroutine_promise_type (orig); /* 2. Types we need to define or look up. */ @@ -4578,17 +4583,12 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer) /* We need to know, and inspect, each suspend point in the function in several places. It's convenient to place this map out of line since it's used from tree walk callbacks. */ - suspend_points = new hash_map; + hash_map suspend_points; /* Now insert the data for any body await points, at this time we also need to promote any temporaries that are captured by reference (to regular vars) they will get added to the coro frame along with other locals. */ - susp_frame_data body_aw_points - = {&field_list, handle_type, fs_label, NULL, NULL, 0, 0, - hash_set (), NULL, NULL, 0, false, false, false}; - body_aw_points.block_stack = make_tree_vector (); - body_aw_points.bind_stack = make_tree_vector (); - body_aw_points.to_replace = make_tree_vector (); + susp_frame_data body_aw_points (fs_label, &suspend_points); cp_walk_tree (&fnbody, await_statement_walker, &body_aw_points, NULL); /* 4. Now make space for local vars, this is conservative again, and we @@ -5273,7 +5273,7 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer) /* Build the actor... */ build_actor_fn (fn_start, coro_frame_type, actor, fnbody, orig, - &local_var_uses, param_dtor_list, + &local_var_uses, &suspend_points, param_dtor_list, resume_idx_var, body_aw_points.await_number, frame_size); /* Destroyer ... */ @@ -5290,8 +5290,6 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer) *resumer = actor; *destroyer = destroy; - delete suspend_points; - suspend_points = NULL; return true; }