From: Siddhesh Poyarekar <siddhesh@gotplt.org>
To: gcc-patches@gcc.gnu.org
Cc: jakub@redhat.com
Subject: [PATCH v3 1/8] tree-object-size: Replace magic numbers with enums
Date: Fri, 26 Nov 2021 10:58:44 +0530 [thread overview]
Message-ID: <20211126052851.2176408-2-siddhesh@gotplt.org> (raw)
In-Reply-To: <20211126052851.2176408-1-siddhesh@gotplt.org>
A simple cleanup to allow inserting dynamic size code more easily.
gcc/ChangeLog:
* tree-object-size.c: New enum.
(object_sizes, computed, addr_object_size,
compute_builtin_object_size, expr_object_size, call_object_size,
merge_object_sizes, plus_stmt_object_size,
collect_object_sizes_for, init_object_sizes, fini_object_sizes,
object_sizes_execute): Replace magic numbers with enums.
Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
---
Changes from v2:
- Incorporated review suggestions.
gcc/tree-object-size.c | 59 ++++++++++++++++++++++++------------------
1 file changed, 34 insertions(+), 25 deletions(-)
diff --git a/gcc/tree-object-size.c b/gcc/tree-object-size.c
index 4334e05ef70..5e93bb74f92 100644
--- a/gcc/tree-object-size.c
+++ b/gcc/tree-object-size.c
@@ -45,6 +45,13 @@ struct object_size_info
unsigned int *stack, *tos;
};
+enum
+{
+ OST_SUBOBJECT = 1,
+ OST_MINIMUM = 2,
+ OST_END = 4,
+};
+
static tree compute_object_offset (const_tree, const_tree);
static bool addr_object_size (struct object_size_info *,
const_tree, int, unsigned HOST_WIDE_INT *);
@@ -67,10 +74,10 @@ static void check_for_plus_in_loops_1 (struct object_size_info *, tree,
the subobject (innermost array or field with address taken).
object_sizes[2] is lower bound for number of bytes till the end of
the object and object_sizes[3] lower bound for subobject. */
-static vec<unsigned HOST_WIDE_INT> object_sizes[4];
+static vec<unsigned HOST_WIDE_INT> object_sizes[OST_END];
/* Bitmaps what object sizes have been computed already. */
-static bitmap computed[4];
+static bitmap computed[OST_END];
/* Maximum value of offset we consider to be addition. */
static unsigned HOST_WIDE_INT offset_limit;
@@ -227,11 +234,11 @@ addr_object_size (struct object_size_info *osi, const_tree ptr,
{
unsigned HOST_WIDE_INT sz;
- if (!osi || (object_size_type & 1) != 0
+ if (!osi || (object_size_type & OST_SUBOBJECT) != 0
|| TREE_CODE (TREE_OPERAND (pt_var, 0)) != SSA_NAME)
{
compute_builtin_object_size (TREE_OPERAND (pt_var, 0),
- object_size_type & ~1, &sz);
+ object_size_type & ~OST_SUBOBJECT, &sz);
}
else
{
@@ -266,7 +273,7 @@ addr_object_size (struct object_size_info *osi, const_tree ptr,
}
else if (DECL_P (pt_var))
{
- pt_var_size = decl_init_size (pt_var, object_size_type & 2);
+ pt_var_size = decl_init_size (pt_var, object_size_type & OST_MINIMUM);
if (!pt_var_size)
return false;
}
@@ -287,7 +294,7 @@ addr_object_size (struct object_size_info *osi, const_tree ptr,
{
tree var;
- if (object_size_type & 1)
+ if (object_size_type & OST_SUBOBJECT)
{
var = TREE_OPERAND (ptr, 0);
@@ -528,7 +535,7 @@ bool
compute_builtin_object_size (tree ptr, int object_size_type,
unsigned HOST_WIDE_INT *psize)
{
- gcc_assert (object_size_type >= 0 && object_size_type <= 3);
+ gcc_assert (object_size_type >= 0 && object_size_type < OST_END);
/* Set to unknown and overwrite just before returning if the size
could be determined. */
@@ -546,7 +553,7 @@ compute_builtin_object_size (tree ptr, int object_size_type,
if (computed[object_size_type] == NULL)
{
- if (optimize || object_size_type & 1)
+ if (optimize || object_size_type & OST_SUBOBJECT)
return false;
/* When not optimizing, rather than failing, make a small effort
@@ -586,8 +593,8 @@ compute_builtin_object_size (tree ptr, int object_size_type,
if (dump_file)
{
fprintf (dump_file, "Computing %s %sobject size for ",
- (object_size_type & 2) ? "minimum" : "maximum",
- (object_size_type & 1) ? "sub" : "");
+ (object_size_type & OST_MINIMUM) ? "minimum" : "maximum",
+ (object_size_type & OST_SUBOBJECT) ? "sub" : "");
print_generic_expr (dump_file, ptr, dump_flags);
fprintf (dump_file, ":\n");
}
@@ -620,7 +627,7 @@ compute_builtin_object_size (tree ptr, int object_size_type,
terminate, it could take a long time. If a pointer is
increasing this way, we need to assume 0 object size.
E.g. p = &buf[0]; while (cond) p = p + 4; */
- if (object_size_type & 2)
+ if (object_size_type & OST_MINIMUM)
{
osi.depths = XCNEWVEC (unsigned int, num_ssa_names);
osi.stack = XNEWVEC (unsigned int, num_ssa_names);
@@ -679,8 +686,9 @@ compute_builtin_object_size (tree ptr, int object_size_type,
fprintf (dump_file,
": %s %sobject size "
HOST_WIDE_INT_PRINT_UNSIGNED "\n",
- (object_size_type & 2) ? "minimum" : "maximum",
- (object_size_type & 1) ? "sub" : "",
+ ((object_size_type & OST_MINIMUM) ? "minimum"
+ : "maximum"),
+ (object_size_type & OST_SUBOBJECT) ? "sub" : "",
object_sizes[object_size_type][i]);
}
}
@@ -718,7 +726,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_size_type & OST_MINIMUM) == 0)
{
if (object_sizes[object_size_type][varno] < bytes)
object_sizes[object_size_type][varno] = bytes;
@@ -748,7 +756,7 @@ call_object_size (struct object_size_info *osi, tree ptr, gcall *call)
bytes = alloc_object_size (call, object_size_type);
- if ((object_size_type & 2) == 0)
+ if ((object_size_type & OST_MINIMUM) == 0)
{
if (object_sizes[object_size_type][varno] < bytes)
object_sizes[object_size_type][varno] = bytes;
@@ -804,7 +812,7 @@ merge_object_sizes (struct object_size_info *osi, tree dest, tree orig,
orig_bytes = (offset > orig_bytes)
? HOST_WIDE_INT_0U : orig_bytes - offset;
- if ((object_size_type & 2) == 0)
+ if ((object_size_type & OST_MINIMUM) == 0)
{
if (object_sizes[object_size_type][varno] < orig_bytes)
{
@@ -882,7 +890,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_size_type & OST_MINIMUM) == 0)
{
if (object_sizes[object_size_type][varno] < bytes)
object_sizes[object_size_type][varno] = bytes;
@@ -968,7 +976,7 @@ 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;
+ = (object_size_type & OST_MINIMUM) ? -1 : 0;
}
else
{
@@ -1238,7 +1246,7 @@ init_object_sizes (void)
if (computed[0])
return;
- for (object_size_type = 0; object_size_type <= 3; object_size_type++)
+ for (object_size_type = 0; object_size_type < OST_END; object_size_type++)
{
object_sizes[object_size_type].safe_grow (num_ssa_names, true);
computed[object_size_type] = BITMAP_ALLOC (NULL);
@@ -1255,7 +1263,7 @@ fini_object_sizes (void)
{
int object_size_type;
- for (object_size_type = 0; object_size_type <= 3; object_size_type++)
+ for (object_size_type = 0; object_size_type < OST_END; object_size_type++)
{
object_sizes[object_size_type].release ();
BITMAP_FREE (computed[object_size_type]);
@@ -1302,7 +1310,7 @@ object_sizes_execute (function *fun, bool insert_min_max_p)
{
unsigned HOST_WIDE_INT object_size_type = tree_to_uhwi (ost);
tree ptr = gimple_call_arg (call, 0);
- if ((object_size_type == 1 || object_size_type == 3)
+ if ((object_size_type & OST_SUBOBJECT)
&& (TREE_CODE (ptr) == ADDR_EXPR
|| TREE_CODE (ptr) == SSA_NAME))
{
@@ -1315,7 +1323,8 @@ object_sizes_execute (function *fun, bool insert_min_max_p)
tree tem = make_ssa_name (type);
gimple_call_set_lhs (call, tem);
enum tree_code code
- = object_size_type == 1 ? MIN_EXPR : MAX_EXPR;
+ = (object_size_type & OST_MINIMUM
+ ? MAX_EXPR : MIN_EXPR);
tree cst = build_int_cstu (type, bytes);
gimple *g
= gimple_build_assign (lhs, code, tem, cst);
@@ -1336,11 +1345,11 @@ object_sizes_execute (function *fun, bool insert_min_max_p)
{
unsigned HOST_WIDE_INT object_size_type = tree_to_uhwi (ost);
- if (object_size_type < 2)
+ if (object_size_type & OST_MINIMUM)
+ result = build_zero_cst (size_type_node);
+ else if (object_size_type < OST_END)
result = fold_convert (size_type_node,
integer_minus_one_node);
- else if (object_size_type < 4)
- result = build_zero_cst (size_type_node);
}
if (!result)
--
2.31.1
next prev parent reply other threads:[~2021-11-26 5:29 UTC|newest]
Thread overview: 97+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-09 19:01 [PATCH 00/10] __builtin_dynamic_object_size Siddhesh Poyarekar
2021-11-09 19:01 ` [PATCH 01/10] tree-object-size: Replace magic numbers with enums Siddhesh Poyarekar
2021-11-19 16:00 ` Jakub Jelinek
2021-11-09 19:01 ` [PATCH 02/10] tree-object-size: Abstract object_sizes array Siddhesh Poyarekar
2021-11-19 16:18 ` Jakub Jelinek
2021-11-19 16:53 ` Siddhesh Poyarekar
2021-11-09 19:01 ` [PATCH 03/10] tree-object-size: Use tree instead of HOST_WIDE_INT Siddhesh Poyarekar
2021-11-19 17:06 ` Jakub Jelinek
2021-11-19 19:01 ` Siddhesh Poyarekar
2021-11-19 19:16 ` Jakub Jelinek
2021-11-22 8:41 ` Richard Biener
2021-11-22 10:11 ` Siddhesh Poyarekar
2021-11-22 10:31 ` Jakub Jelinek
2021-11-22 12:00 ` Siddhesh Poyarekar
2021-11-22 12:31 ` Siddhesh Poyarekar
2021-11-22 12:32 ` Jakub Jelinek
2021-11-23 11:58 ` Jakub Jelinek
2021-11-23 13:33 ` Siddhesh Poyarekar
2021-11-09 19:01 ` [PATCH 04/10] tree-object-size: Single pass dependency loop resolution Siddhesh Poyarekar
2021-11-23 12:07 ` Jakub Jelinek
2021-11-23 13:44 ` Siddhesh Poyarekar
2021-11-23 14:22 ` Jakub Jelinek
2021-11-09 19:01 ` [PATCH 05/10] __builtin_dynamic_object_size: Recognize builtin Siddhesh Poyarekar
2021-11-23 12:41 ` Jakub Jelinek
2021-11-23 13:53 ` Siddhesh Poyarekar
2021-11-23 14:00 ` Jakub Jelinek
2021-11-09 19:01 ` [PATCH 06/10] tree-object-size: Support dynamic sizes in conditions Siddhesh Poyarekar
2021-11-23 15:12 ` Jakub Jelinek
2021-11-23 15:36 ` Siddhesh Poyarekar
2021-11-23 15:38 ` Siddhesh Poyarekar
2021-11-23 16:17 ` Jakub Jelinek
2021-11-23 15:52 ` Jakub Jelinek
2021-11-23 16:00 ` Siddhesh Poyarekar
2021-11-23 16:19 ` Jakub Jelinek
2021-11-09 19:01 ` [PATCH 07/10] tree-object-size: Handle function parameters Siddhesh Poyarekar
2021-11-09 19:01 ` [PATCH 08/10] tree-object-size: Handle GIMPLE_CALL Siddhesh Poyarekar
2021-11-09 19:01 ` [PATCH 09/10] tree-object-size: Dynamic sizes for ADDR_EXPR Siddhesh Poyarekar
2021-11-09 19:01 ` [PATCH 10/10] tree-object-size: Handle dynamic offsets Siddhesh Poyarekar
2021-11-19 15:56 ` [PATCH 00/10] __builtin_dynamic_object_size Jakub Jelinek
2021-11-26 5:28 ` [PATCH v3 0/8] __builtin_dynamic_object_size Siddhesh Poyarekar
2021-11-26 5:28 ` Siddhesh Poyarekar [this message]
2021-11-26 16:46 ` [PATCH v3 1/8] tree-object-size: Replace magic numbers with enums Jakub Jelinek
2021-11-26 17:53 ` Siddhesh Poyarekar
2021-11-26 18:01 ` Jakub Jelinek
2021-11-26 5:28 ` [PATCH v3 2/8] tree-object-size: Abstract object_sizes array Siddhesh Poyarekar
2021-11-26 16:47 ` Jakub Jelinek
2021-11-26 5:28 ` [PATCH v3 3/8] tree-object-size: Save sizes as trees and support negative offsets Siddhesh Poyarekar
2021-11-26 16:56 ` Jakub Jelinek
2021-11-26 17:59 ` Siddhesh Poyarekar
2021-11-26 18:04 ` Jakub Jelinek
2021-11-26 18:07 ` Siddhesh Poyarekar
2021-11-26 5:28 ` [PATCH v3 4/8] __builtin_dynamic_object_size: Recognize builtin Siddhesh Poyarekar
2021-11-26 5:28 ` [PATCH v3 5/8] tree-object-size: Support dynamic sizes in conditions Siddhesh Poyarekar
2021-11-26 5:28 ` [PATCH v3 6/8] tree-object-size: Handle function parameters Siddhesh Poyarekar
2021-11-26 5:28 ` [PATCH v3 7/8] tree-object-size: Handle GIMPLE_CALL Siddhesh Poyarekar
2021-11-26 5:28 ` [PATCH v3 8/8] tree-object-size: Dynamic sizes for ADDR_EXPR Siddhesh Poyarekar
2021-11-26 5:38 ` [PATCH v3 0/8] __builtin_dynamic_object_size Siddhesh Poyarekar
2021-12-01 14:27 ` [PATCH v4 0/6] __builtin_dynamic_object_size Siddhesh Poyarekar
2021-12-01 14:27 ` [PATCH v4 1/6] tree-object-size: Use trees and support negative offsets Siddhesh Poyarekar
2021-12-15 15:21 ` Jakub Jelinek
2021-12-15 17:12 ` Siddhesh Poyarekar
2021-12-15 18:43 ` Jakub Jelinek
2021-12-16 0:41 ` Siddhesh Poyarekar
2021-12-16 15:49 ` Jakub Jelinek
2021-12-16 18:56 ` Siddhesh Poyarekar
2021-12-16 21:16 ` Jakub Jelinek
2021-12-01 14:27 ` [PATCH v4 2/6] __builtin_dynamic_object_size: Recognize builtin Siddhesh Poyarekar
2021-12-15 15:24 ` Jakub Jelinek
2021-12-16 2:16 ` Siddhesh Poyarekar
2021-12-01 14:27 ` [PATCH v4 3/6] tree-object-size: Support dynamic sizes in conditions Siddhesh Poyarekar
2021-12-15 16:24 ` Jakub Jelinek
2021-12-15 17:56 ` Siddhesh Poyarekar
2021-12-15 18:52 ` Jakub Jelinek
2021-12-01 14:27 ` [PATCH v4 4/6] tree-object-size: Handle function parameters Siddhesh Poyarekar
2021-12-01 14:27 ` [PATCH v4 5/6] tree-object-size: Handle GIMPLE_CALL Siddhesh Poyarekar
2021-12-01 14:27 ` [PATCH v4 6/6] tree-object-size: Dynamic sizes for ADDR_EXPR Siddhesh Poyarekar
2021-12-18 12:35 ` [PATCH v5 0/4] __builtin_dynamic_object_size Siddhesh Poyarekar
2021-12-18 12:35 ` [PATCH v5 1/4] tree-object-size: Support dynamic sizes in conditions Siddhesh Poyarekar
2022-01-10 10:37 ` Jakub Jelinek
2022-01-10 23:55 ` Siddhesh Poyarekar
2021-12-18 12:35 ` [PATCH v5 2/4] tree-object-size: Handle function parameters Siddhesh Poyarekar
2022-01-10 10:50 ` Jakub Jelinek
2022-01-11 0:32 ` Siddhesh Poyarekar
2021-12-18 12:35 ` [PATCH v5 3/4] tree-object-size: Handle GIMPLE_CALL Siddhesh Poyarekar
2022-01-10 11:03 ` Jakub Jelinek
2021-12-18 12:35 ` [PATCH v5 4/4] tree-object-size: Dynamic sizes for ADDR_EXPR Siddhesh Poyarekar
2022-01-10 11:09 ` Jakub Jelinek
2022-01-04 3:24 ` [PING][PATCH v5 0/4] __builtin_dynamic_object_size Siddhesh Poyarekar
2022-01-11 8:57 ` [PATCH v6 " Siddhesh Poyarekar
2022-01-11 8:57 ` [PATCH v6 1/4] tree-object-size: Support dynamic sizes in conditions Siddhesh Poyarekar
2022-01-11 9:43 ` Jakub Jelinek
2022-01-11 9:44 ` Siddhesh Poyarekar
2022-01-11 8:57 ` [PATCH v6 2/4] tree-object-size: Handle function parameters Siddhesh Poyarekar
2022-01-11 9:44 ` Jakub Jelinek
2022-01-11 8:57 ` [PATCH v6 3/4] tree-object-size: Handle GIMPLE_CALL Siddhesh Poyarekar
2022-01-11 8:57 ` [PATCH v6 4/4] tree-object-size: Dynamic sizes for ADDR_EXPR Siddhesh Poyarekar
2022-01-11 9:47 ` Jakub Jelinek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211126052851.2176408-2-siddhesh@gotplt.org \
--to=siddhesh@gotplt.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).