From patchwork Fri Nov 26 05:28:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 1559955 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gotplt.org header.i=@gotplt.org header.a=rsa-sha1 header.s=gotplt.org header.b=OaV3sUyk; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J0jyB44DGz9t54 for ; Fri, 26 Nov 2021 16:30:42 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4FBA53857C51 for ; Fri, 26 Nov 2021 05:30:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from fennec.ash.relay.mailchannels.net (fennec.ash.relay.mailchannels.net [23.83.222.58]) by sourceware.org (Postfix) with ESMTPS id 2EF583857C51 for ; Fri, 26 Nov 2021 05:29:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2EF583857C51 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 6F582200F92; Fri, 26 Nov 2021 05:29:11 +0000 (UTC) Received: from pdx1-sub0-mail-a305.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id D0A53200FAE; Fri, 26 Nov 2021 05:29:10 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a305.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.124.138.98 (trex/6.4.3); Fri, 26 Nov 2021 05:29:11 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Gusty-Abortive: 3bb2f4f654a2e8c6_1637904551230_364836392 X-MC-Loop-Signature: 1637904551230:3974795379 X-MC-Ingress-Time: 1637904551230 Received: from rhbox.intra.reserved-bit.com (unknown [1.186.223.60]) (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-a305.dreamhost.com (Postfix) with ESMTPSA id 4J0jwP23Dgz3C; Thu, 25 Nov 2021 21:29:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gotplt.org; s=gotplt.org; t=1637904550; bh=9xIM7aAUjGd65ipf3iXJcizp8Bk=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=OaV3sUykha3KRvdwYk2sPoihYri6zR8KkyvO1HmG8FcD30F1ABkhKWnYZiSf8dIdJ 2tXpPCXom2JH/JhcalIrz6ViYTI+mcocTj+VzXmaHTyMmmbT4dQObtGF8Ys00pmtls M6edGB5OkOEwy/htPt6RcGuN2OXUDuDyjR5dvZO4= From: Siddhesh Poyarekar To: gcc-patches@gcc.gnu.org Subject: [PATCH v3 2/8] tree-object-size: Abstract object_sizes array Date: Fri, 26 Nov 2021 10:58:45 +0530 Message-Id: <20211126052851.2176408-3-siddhesh@gotplt.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211126052851.2176408-1-siddhesh@gotplt.org> References: <20211109190137.1107736-1-siddhesh@gotplt.org> <20211126052851.2176408-1-siddhesh@gotplt.org> MIME-Version: 1.0 X-Spam-Status: No, score=-3038.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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+incoming=patchwork.ozlabs.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 --- Changes from v2: - Incorporated review suggestions. gcc/tree-object-size.c | 177 +++++++++++++++++++++++------------------ 1 file changed, 98 insertions(+), 79 deletions(-) diff --git a/gcc/tree-object-size.c b/gcc/tree-object-size.c index 5e93bb74f92..3780437ff91 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 & OST_MINIMUM) == 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 & OST_MINIMUM) == 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 & OST_MINIMUM) == 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 & OST_MINIMUM) == 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,10 @@ 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 & OST_MINIMUM) ? -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 ^ OST_MINIMUM)); } else { @@ -1047,7 +1068,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 +1077,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 +1088,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 +1103,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 +1143,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 +1267,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 +1284,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]); } }