From patchwork Tue Nov 9 19:01:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 47323 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 841F1385781E for ; Tue, 9 Nov 2021 19:03:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from cyan.elm.relay.mailchannels.net (cyan.elm.relay.mailchannels.net [23.83.212.47]) by sourceware.org (Postfix) with ESMTPS id BB4463858027 for ; Tue, 9 Nov 2021 19:01:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BB4463858027 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 6915A361DDF; Tue, 9 Nov 2021 19:01:54 +0000 (UTC) Received: from pdx1-sub0-mail-a306.dreamhost.com (100-96-18-144.trex.outbound.svc.cluster.local [100.96.18.144]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id EC8A13619FC; Tue, 9 Nov 2021 19:01:53 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a306.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.96.18.144 (trex/6.4.3); Tue, 09 Nov 2021 19:01:54 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Skirt-Wiry: 393060a86563605d_1636484514232_3573939760 X-MC-Loop-Signature: 1636484514232:2955145764 X-MC-Ingress-Time: 1636484514232 Received: from rhbox.redhat.com (unknown [1.186.121.127]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a306.dreamhost.com (Postfix) with ESMTPSA id 4Hpcm01YJ2z2n; Tue, 9 Nov 2021 11:01:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gotplt.org; s=gotplt.org; t=1636484513; bh=A/OkS89QN1wbnF7MU/Oa9JmrJqI=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=AM+BZzlJ8ZJBayTkYAAIfxy/QE1j7+uJI5abJXgKzwyDVhB3S2ACUzp6amBNH+8rx F2Z/ubQ9EypV5cTtp6NxzeST8SyCCMZ5SgyHKXKmiKYdRzzKDO2CHlaTkbsqaUu1aw LOW3XRDJr2ZHYlVUMcyUkINVAMlayQ8o6Ncojmuo= From: Siddhesh Poyarekar To: gcc-patches@gcc.gnu.org Subject: [PATCH 02/10] tree-object-size: Abstract object_sizes array Date: Wed, 10 Nov 2021 00:31:28 +0530 Message-Id: <20211109190137.1107736-3-siddhesh@gotplt.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211109190137.1107736-1-siddhesh@gotplt.org> References: <20211109190137.1107736-1-siddhesh@gotplt.org> MIME-Version: 1.0 X-Spam-Status: No, score=-3038.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_SBL, SPF_HELO_NONE, SPF_PASS, 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: , Cc: jakub@redhat.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Put all accesses to object_sizes behind functions so that we can add dynamic capability more easily. gcc/ChangeLog: * tree-object-size.c (object_sizes_grow, object_sizes_release, object_sizes_unknown_p, object_sizes_get, object_size_set_force, object_sizes_set): New functions. (addr_object_size, compute_builtin_object_size, expr_object_size, call_object_size, unknown_object_size, merge_object_sizes, plus_stmt_object_size, cond_expr_object_size, collect_object_sizes_for, check_for_plus_in_loops_1, init_object_sizes, fini_object_sizes): Adjust. Signed-off-by: Siddhesh Poyarekar --- gcc/tree-object-size.c | 176 +++++++++++++++++++++++------------------ 1 file changed, 97 insertions(+), 79 deletions(-) diff --git a/gcc/tree-object-size.c b/gcc/tree-object-size.c index f70f95a7b29..7a22539cc43 100644 --- a/gcc/tree-object-size.c +++ b/gcc/tree-object-size.c @@ -88,6 +88,71 @@ unknown (int object_size_type) return ((unsigned HOST_WIDE_INT) -((object_size_type >> 1) ^ 1)); } +/* Grow object_sizes[OBJECT_SIZE_TYPE] to num_ssa_names. */ + +static inline void +object_sizes_grow (int object_size_type) +{ + if (num_ssa_names > object_sizes[object_size_type].length ()) + object_sizes[object_size_type].safe_grow (num_ssa_names, true); +} + +/* Release object_sizes[OBJECT_SIZE_TYPE]. */ + +static inline void +object_sizes_release (int object_size_type) +{ + object_sizes[object_size_type].release (); +} + +/* Return true if object_sizes[OBJECT_SIZE_TYPE][VARNO] is unknown. */ + +static inline bool +object_sizes_unknown_p (int object_size_type, unsigned varno) +{ + return (object_sizes[object_size_type][varno] + == unknown (object_size_type)); +} + +/* Return size for VARNO corresponding to OSI. */ + +static inline unsigned HOST_WIDE_INT +object_sizes_get (struct object_size_info *osi, unsigned varno) +{ + return object_sizes[osi->object_size_type][varno]; +} + +/* Set size for VARNO corresponding to OSI to VAL. */ + +static inline bool +object_sizes_set_force (struct object_size_info *osi, unsigned varno, + unsigned HOST_WIDE_INT val) +{ + object_sizes[osi->object_size_type][varno] = val; + return true; +} + +/* Set size for VARNO corresponding to OSI to VAL if it is the new minimum or + maximum. */ + +static inline bool +object_sizes_set (struct object_size_info *osi, unsigned varno, + unsigned HOST_WIDE_INT val) +{ + int object_size_type = osi->object_size_type; + if ((object_size_type & OST_MINIMUM) == 0) + { + if (object_sizes[object_size_type][varno] < val) + return object_sizes_set_force (osi, varno, val); + } + else + { + if (object_sizes[object_size_type][varno] > val) + return object_sizes_set_force (osi, varno, val); + } + return false; +} + /* Initialize OFFSET_LIMIT variable. */ static void init_offset_limit (void) @@ -247,7 +312,7 @@ addr_object_size (struct object_size_info *osi, const_tree ptr, collect_object_sizes_for (osi, var); if (bitmap_bit_p (computed[object_size_type], SSA_NAME_VERSION (var))) - sz = object_sizes[object_size_type][SSA_NAME_VERSION (var)]; + sz = object_sizes_get (osi, SSA_NAME_VERSION (var)); else sz = unknown (object_size_type); } @@ -582,14 +647,14 @@ compute_builtin_object_size (tree ptr, int object_size_type, return false; } + struct object_size_info osi; + osi.object_size_type = object_size_type; if (!bitmap_bit_p (computed[object_size_type], SSA_NAME_VERSION (ptr))) { - struct object_size_info osi; bitmap_iterator bi; unsigned int i; - if (num_ssa_names > object_sizes[object_size_type].length ()) - object_sizes[object_size_type].safe_grow (num_ssa_names, true); + object_sizes_grow (object_size_type); if (dump_file) { fprintf (dump_file, "Computing %s %sobject size for ", @@ -601,7 +666,6 @@ compute_builtin_object_size (tree ptr, int object_size_type, osi.visited = BITMAP_ALLOC (NULL); osi.reexamine = BITMAP_ALLOC (NULL); - osi.object_size_type = object_size_type; osi.depths = NULL; osi.stack = NULL; osi.tos = NULL; @@ -678,8 +742,7 @@ compute_builtin_object_size (tree ptr, int object_size_type, if (dump_file) { EXECUTE_IF_SET_IN_BITMAP (osi.visited, 0, i, bi) - if (object_sizes[object_size_type][i] - != unknown (object_size_type)) + if (!object_sizes_unknown_p (object_size_type, i)) { print_generic_expr (dump_file, ssa_name (i), dump_flags); @@ -689,7 +752,7 @@ compute_builtin_object_size (tree ptr, int object_size_type, ((object_size_type & OST_MINIMUM) ? "minimum" : "maximum"), (object_size_type & OST_SUBOBJECT) ? "sub" : "", - object_sizes[object_size_type][i]); + object_sizes_get (&osi, i)); } } @@ -697,7 +760,7 @@ compute_builtin_object_size (tree ptr, int object_size_type, BITMAP_FREE (osi.visited); } - *psize = object_sizes[object_size_type][SSA_NAME_VERSION (ptr)]; + *psize = object_sizes_get (&osi, SSA_NAME_VERSION (ptr)); return *psize != unknown (object_size_type); } @@ -710,8 +773,7 @@ expr_object_size (struct object_size_info *osi, tree ptr, tree value) unsigned int varno = SSA_NAME_VERSION (ptr); unsigned HOST_WIDE_INT bytes; - gcc_assert (object_sizes[object_size_type][varno] - != unknown (object_size_type)); + gcc_assert (!object_sizes_unknown_p (object_size_type, varno)); gcc_assert (osi->pass == 0); if (TREE_CODE (value) == WITH_SIZE_EXPR) @@ -726,16 +788,7 @@ expr_object_size (struct object_size_info *osi, tree ptr, tree value) else bytes = unknown (object_size_type); - if ((object_size_type & 2) == 0) - { - if (object_sizes[object_size_type][varno] < bytes) - object_sizes[object_size_type][varno] = bytes; - } - else - { - if (object_sizes[object_size_type][varno] > bytes) - object_sizes[object_size_type][varno] = bytes; - } + object_sizes_set (osi, varno, bytes); } @@ -750,22 +803,12 @@ call_object_size (struct object_size_info *osi, tree ptr, gcall *call) gcc_assert (is_gimple_call (call)); - gcc_assert (object_sizes[object_size_type][varno] - != unknown (object_size_type)); + gcc_assert (!object_sizes_unknown_p (object_size_type, varno)); gcc_assert (osi->pass == 0); bytes = alloc_object_size (call, object_size_type); - if ((object_size_type & 2) == 0) - { - if (object_sizes[object_size_type][varno] < bytes) - object_sizes[object_size_type][varno] = bytes; - } - else - { - if (object_sizes[object_size_type][varno] > bytes) - object_sizes[object_size_type][varno] = bytes; - } + object_sizes_set (osi, varno, bytes); } @@ -776,12 +819,11 @@ unknown_object_size (struct object_size_info *osi, tree ptr) { int object_size_type = osi->object_size_type; unsigned int varno = SSA_NAME_VERSION (ptr); - unsigned HOST_WIDE_INT bytes = unknown (object_size_type); - gcc_checking_assert (object_sizes[object_size_type][varno] != bytes); + gcc_checking_assert (!object_sizes_unknown_p (object_size_type, varno)); gcc_checking_assert (osi->pass == 0); - object_sizes[object_size_type][varno] = bytes; + object_sizes_set (osi, varno, unknown (object_size_type)); } @@ -796,38 +838,24 @@ merge_object_sizes (struct object_size_info *osi, tree dest, tree orig, unsigned int varno = SSA_NAME_VERSION (dest); unsigned HOST_WIDE_INT orig_bytes; - if (object_sizes[object_size_type][varno] == unknown (object_size_type)) + if (object_sizes_unknown_p (object_size_type, varno)) return false; if (offset >= offset_limit) { - object_sizes[object_size_type][varno] = unknown (object_size_type); + object_sizes_set (osi, varno, unknown (object_size_type)); return false; } if (osi->pass == 0) collect_object_sizes_for (osi, orig); - orig_bytes = object_sizes[object_size_type][SSA_NAME_VERSION (orig)]; + orig_bytes = object_sizes_get (osi, SSA_NAME_VERSION (orig)); if (orig_bytes != unknown (object_size_type)) orig_bytes = (offset > orig_bytes) ? HOST_WIDE_INT_0U : orig_bytes - offset; - if ((object_size_type & 2) == 0) - { - if (object_sizes[object_size_type][varno] < orig_bytes) - { - object_sizes[object_size_type][varno] = orig_bytes; - osi->changed = true; - } - } - else - { - if (object_sizes[object_size_type][varno] > orig_bytes) - { - object_sizes[object_size_type][varno] = orig_bytes; - osi->changed = true; - } - } + osi->changed = object_sizes_set (osi, varno, orig_bytes); + return bitmap_bit_p (osi->reexamine, SSA_NAME_VERSION (orig)); } @@ -859,7 +887,7 @@ plus_stmt_object_size (struct object_size_info *osi, tree var, gimple *stmt) else gcc_unreachable (); - if (object_sizes[object_size_type][varno] == unknown (object_size_type)) + if (object_sizes_unknown_p (object_size_type, varno)) return false; /* Handle PTR + OFFSET here. */ @@ -890,16 +918,7 @@ plus_stmt_object_size (struct object_size_info *osi, tree var, gimple *stmt) else bytes = unknown (object_size_type); - if ((object_size_type & 2) == 0) - { - if (object_sizes[object_size_type][varno] < bytes) - object_sizes[object_size_type][varno] = bytes; - } - else - { - if (object_sizes[object_size_type][varno] > bytes) - object_sizes[object_size_type][varno] = bytes; - } + object_sizes_set (osi, varno, bytes); return false; } @@ -918,7 +937,7 @@ cond_expr_object_size (struct object_size_info *osi, tree var, gimple *stmt) gcc_assert (gimple_assign_rhs_code (stmt) == COND_EXPR); - if (object_sizes[object_size_type][varno] == unknown (object_size_type)) + if (object_sizes_unknown_p (object_size_type, varno)) return false; then_ = gimple_assign_rhs2 (stmt); @@ -929,7 +948,7 @@ cond_expr_object_size (struct object_size_info *osi, tree var, gimple *stmt) else expr_object_size (osi, var, then_); - if (object_sizes[object_size_type][varno] == unknown (object_size_type)) + if (object_sizes_unknown_p (object_size_type, varno)) return reexamine; if (TREE_CODE (else_) == SSA_NAME) @@ -975,8 +994,9 @@ collect_object_sizes_for (struct object_size_info *osi, tree var) { if (bitmap_set_bit (osi->visited, varno)) { - object_sizes[object_size_type][varno] - = (object_size_type & 2) ? -1 : 0; + /* Initialize to 0 for maximum size and M1U for minimum size so that + it gets immediately overridden. */ + object_sizes_set_force (osi, varno, unknown (object_size_type ^ 2)); } else { @@ -1047,7 +1067,7 @@ collect_object_sizes_for (struct object_size_info *osi, tree var) case GIMPLE_ASM: /* Pointers defined by __asm__ statements can point anywhere. */ - object_sizes[object_size_type][varno] = unknown (object_size_type); + object_sizes_set (osi, varno, unknown (object_size_type)); break; case GIMPLE_NOP: @@ -1056,7 +1076,7 @@ collect_object_sizes_for (struct object_size_info *osi, tree var) expr_object_size (osi, var, SSA_NAME_VAR (var)); else /* Uninitialized SSA names point nowhere. */ - object_sizes[object_size_type][varno] = unknown (object_size_type); + object_sizes_set (osi, varno, unknown (object_size_type)); break; case GIMPLE_PHI: @@ -1067,8 +1087,7 @@ collect_object_sizes_for (struct object_size_info *osi, tree var) { tree rhs = gimple_phi_arg (stmt, i)->def; - if (object_sizes[object_size_type][varno] - == unknown (object_size_type)) + if (object_sizes_unknown_p (object_size_type, varno)) break; if (TREE_CODE (rhs) == SSA_NAME) @@ -1083,8 +1102,7 @@ collect_object_sizes_for (struct object_size_info *osi, tree var) gcc_unreachable (); } - if (! reexamine - || object_sizes[object_size_type][varno] == unknown (object_size_type)) + if (! reexamine || object_sizes_unknown_p (object_size_type, varno)) { bitmap_set_bit (computed[object_size_type], varno); bitmap_clear_bit (osi->reexamine, varno); @@ -1124,7 +1142,7 @@ check_for_plus_in_loops_1 (struct object_size_info *osi, tree var, --sp; bitmap_clear_bit (osi->reexamine, *sp); bitmap_set_bit (computed[osi->object_size_type], *sp); - object_sizes[osi->object_size_type][*sp] = 0; + object_sizes_set_force (osi, *sp, 0); if (*sp == varno) break; } @@ -1248,7 +1266,7 @@ init_object_sizes (void) for (object_size_type = 0; object_size_type < OST_END; object_size_type++) { - object_sizes[object_size_type].safe_grow (num_ssa_names, true); + object_sizes_grow (object_size_type); computed[object_size_type] = BITMAP_ALLOC (NULL); } @@ -1265,7 +1283,7 @@ fini_object_sizes (void) for (object_size_type = 0; object_size_type < OST_END; object_size_type++) { - object_sizes[object_size_type].release (); + object_sizes_release (object_size_type); BITMAP_FREE (computed[object_size_type]); } }