From: Julian Brown <julian@codesourcery.com>
To: <gcc-patches@gcc.gnu.org>
Cc: Jakub Jelinek <jakub@redhat.com>,
Chung-Lin Tang <cltang@codesourcery.com>,
Thomas Schwinge <thomas@codesourcery.com>
Subject: [PATCH 02/11] Remove base_ind/base_ref handling from extract_base_bit_offset
Date: Fri, 1 Oct 2021 10:07:49 -0700 [thread overview]
Message-ID: <dd3f3de114db0ed9124cc1e4e800be3826aac71a.1633106212.git.julian@codesourcery.com> (raw)
In-Reply-To: <cover.1633106212.git.julian@codesourcery.com>
In preparation for follow-up patches extending struct dereference
handling for OpenMP, this patch removes base_ind/base_ref handling from
gimplify.c:extract_base_bit_offset. This arguably simplifies some of the
code around the callers of the function also, though subsequent patches
modify those parts further.
OK for mainline?
Thanks,
Julian
2021-09-29 Julian Brown <julian@codesourcery.com>
gcc/
* gimplify.c (extract_base_bit_offset): Remove BASE_IND, BASE_REF and
OPENMP parameters.
(strip_indirections): New function.
(build_struct_group): Update calls to extract_base_bit_offset.
Rearrange indirect/reference handling accordingly. Use extracted base
instead of passed-in decl when grouping component accesses together.
---
gcc/gimplify.c | 109 ++++++++++++++++++++++++++-----------------------
1 file changed, 57 insertions(+), 52 deletions(-)
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 92f8a7b4073..ece22b7a4ae 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -8641,9 +8641,8 @@ build_struct_comp_nodes (enum tree_code code, tree grp_start, tree grp_end,
has array type, else return NULL. */
static tree
-extract_base_bit_offset (tree base, tree *base_ind, tree *base_ref,
- poly_int64 *bitposp, poly_offset_int *poffsetp,
- tree *offsetp, bool openmp)
+extract_base_bit_offset (tree base, poly_int64 *bitposp,
+ poly_offset_int *poffsetp, tree *offsetp)
{
tree offset;
poly_int64 bitsize, bitpos;
@@ -8651,38 +8650,12 @@ extract_base_bit_offset (tree base, tree *base_ind, tree *base_ref,
int unsignedp, reversep, volatilep = 0;
poly_offset_int poffset;
- if (base_ind)
- *base_ind = NULL_TREE;
-
- if (base_ref)
- *base_ref = NULL_TREE;
+ STRIP_NOPS (base);
base = get_inner_reference (base, &bitsize, &bitpos, &offset, &mode,
&unsignedp, &reversep, &volatilep);
- if (!openmp
- && (TREE_CODE (base) == INDIRECT_REF
- || (TREE_CODE (base) == MEM_REF
- && integer_zerop (TREE_OPERAND (base, 1))))
- && TREE_CODE (TREE_TYPE (TREE_OPERAND (base, 0))) == POINTER_TYPE)
- {
- if (base_ind)
- *base_ind = base;
- base = TREE_OPERAND (base, 0);
- }
- if ((TREE_CODE (base) == INDIRECT_REF
- || (TREE_CODE (base) == MEM_REF
- && integer_zerop (TREE_OPERAND (base, 1))))
- && DECL_P (TREE_OPERAND (base, 0))
- && TREE_CODE (TREE_TYPE (TREE_OPERAND (base, 0))) == REFERENCE_TYPE)
- {
- if (base_ref)
- *base_ref = base;
- base = TREE_OPERAND (base, 0);
- }
-
- if (!openmp)
- STRIP_NOPS (base);
+ STRIP_NOPS (base);
if (offset && poly_int_tree_p (offset))
{
@@ -8739,6 +8712,17 @@ strip_components_and_deref (tree expr)
return expr;
}
+static tree
+strip_indirections (tree expr)
+{
+ while (TREE_CODE (expr) == INDIRECT_REF
+ || (TREE_CODE (expr) == MEM_REF
+ && integer_zerop (TREE_OPERAND (expr, 1))))
+ expr = TREE_OPERAND (expr, 0);
+
+ return expr;
+}
+
/* Return TRUE if EXPR is something we will use as the base of an aggregate
access, either:
@@ -9232,7 +9216,7 @@ build_struct_group (struct gimplify_omp_ctx *ctx,
{
poly_offset_int coffset;
poly_int64 cbitpos;
- tree base_ind, base_ref, tree_coffset;
+ tree tree_coffset;
tree ocd = OMP_CLAUSE_DECL (c);
bool openmp = !(region_type & ORT_ACC);
@@ -9242,10 +9226,25 @@ build_struct_group (struct gimplify_omp_ctx *ctx,
if (TREE_CODE (ocd) == INDIRECT_REF)
ocd = TREE_OPERAND (ocd, 0);
- tree base = extract_base_bit_offset (ocd, &base_ind, &base_ref, &cbitpos,
- &coffset, &tree_coffset, openmp);
+ tree base = extract_base_bit_offset (ocd, &cbitpos, &coffset, &tree_coffset);
+ tree sbase;
- bool do_map_struct = (base == decl && !tree_coffset);
+ if (openmp)
+ {
+ if (TREE_CODE (base) == INDIRECT_REF
+ && TREE_CODE (TREE_TYPE (TREE_OPERAND (base, 0))) == REFERENCE_TYPE)
+ sbase = strip_indirections (base);
+ else
+ sbase = base;
+ }
+ else
+ {
+ sbase = strip_indirections (base);
+
+ STRIP_NOPS (sbase);
+ }
+
+ bool do_map_struct = (sbase == decl && !tree_coffset);
/* Here, DECL is usually a DECL_P, unless we have chained indirect member
accesses, e.g. mystruct->a->b. In that case it'll be the "mystruct->a"
@@ -9305,19 +9304,12 @@ build_struct_group (struct gimplify_omp_ctx *ctx,
OMP_CLAUSE_SET_MAP_KIND (l, k);
- if (!openmp && base_ind)
- OMP_CLAUSE_DECL (l) = unshare_expr (base_ind);
- else if (base_ref)
- OMP_CLAUSE_DECL (l) = unshare_expr (base_ref);
- else
- {
- OMP_CLAUSE_DECL (l) = unshare_expr (decl);
- if (openmp
- && !DECL_P (OMP_CLAUSE_DECL (l))
- && (gimplify_expr (&OMP_CLAUSE_DECL (l), pre_p, NULL,
- is_gimple_lvalue, fb_lvalue) == GS_ERROR))
- return error_mark_node;
- }
+ OMP_CLAUSE_DECL (l) = unshare_expr (base);
+ if (openmp
+ && !DECL_P (OMP_CLAUSE_DECL (l))
+ && (gimplify_expr (&OMP_CLAUSE_DECL (l), pre_p, NULL,
+ is_gimple_lvalue, fb_lvalue) == GS_ERROR))
+ return error_mark_node;
OMP_CLAUSE_SIZE (l)
= (!attach ? size_int (1)
: (DECL_P (OMP_CLAUSE_DECL (l))
@@ -9353,6 +9345,20 @@ build_struct_group (struct gimplify_omp_ctx *ctx,
else
list_p = insert_node_after (l, list_p);
+ bool base_ref
+ = (TREE_CODE (base) == INDIRECT_REF
+ && ((TREE_CODE (TREE_TYPE (TREE_OPERAND (base, 0)))
+ == REFERENCE_TYPE)
+ || ((TREE_CODE (TREE_OPERAND (base, 0)) == INDIRECT_REF)
+ && (TREE_CODE (TREE_TYPE (TREE_OPERAND
+ (TREE_OPERAND (base, 0), 0)))
+ == REFERENCE_TYPE))));
+ bool base_ind = ((TREE_CODE (base) == INDIRECT_REF
+ || (TREE_CODE (base) == MEM_REF
+ && integer_zerop (TREE_OPERAND (base, 1))))
+ && (TREE_CODE (TREE_TYPE (TREE_OPERAND (base, 0)))
+ == POINTER_TYPE));
+
/* Handle pointers to structs and references to structs: these cases
have an additional GOMP_MAP_FIRSTPRIVATE_{REFERENCE,POINTER} node
inserted after the GOMP_MAP_STRUCT node. References to pointers
@@ -9485,10 +9491,9 @@ build_struct_group (struct gimplify_omp_ctx *ctx,
== REFERENCE_TYPE))
sc_decl = TREE_OPERAND (sc_decl, 0);
- tree base = extract_base_bit_offset (sc_decl, NULL, NULL,
- &bitpos, &offset,
- &tree_offset, openmp);
- if (!base || !operand_equal_p (base, decl, 0))
+ tree base2 = extract_base_bit_offset (sc_decl, &bitpos, &offset,
+ &tree_offset);
+ if (!base2 || !operand_equal_p (base2, base, 0))
break;
if (scp)
continue;
--
2.29.2
next prev parent reply other threads:[~2021-10-01 17:08 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-01 17:07 [PATCH 00/11] OpenMP: Deep struct dereferences Julian Brown
2021-10-01 17:07 ` [PATCH 01/11] libgomp: Release device lock on cbuf error path Julian Brown
2021-10-12 9:23 ` Jakub Jelinek
2021-10-01 17:07 ` Julian Brown [this message]
2021-10-12 9:27 ` [PATCH 02/11] Remove base_ind/base_ref handling from extract_base_bit_offset Jakub Jelinek
2021-10-01 17:07 ` [PATCH 03/11] OpenMP 5.0: Clause ordering for OpenMP 5.0 (topological sorting by base pointer) Julian Brown
2021-10-01 17:07 ` [PATCH 04/11] Remove omp_target_reorder_clauses Julian Brown
2021-10-01 17:09 ` [PATCH 05/11] OpenMP/OpenACC: Hoist struct sibling list handling in gimplification Julian Brown
2021-10-01 17:16 ` Julian Brown
2021-10-01 17:09 ` [PATCH 06/11] OpenMP: Allow array ref components for C & C++ Julian Brown
2021-10-01 17:09 ` [PATCH 07/11] OpenMP: Fix non-zero attach/detach bias for struct dereferences Julian Brown
2021-10-11 14:49 ` Julian Brown
2021-10-01 17:09 ` [PATCH 08/11] Not for committing: noisy topological sorting output Julian Brown
2021-10-01 17:09 ` [PATCH 09/11] Not for committing: noisy sibling-list handling output Julian Brown
2021-10-01 17:10 ` [PATCH 10/11] Not for committing: noisy mapping-group taxonomy Julian Brown
2021-10-01 17:10 ` [PATCH 11/11] OpenMP/OpenACC: [WIP] Add gcc_unreachable to apparently-dead path in build_struct_comp_nodes Julian Brown
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=dd3f3de114db0ed9124cc1e4e800be3826aac71a.1633106212.git.julian@codesourcery.com \
--to=julian@codesourcery.com \
--cc=cltang@codesourcery.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=thomas@codesourcery.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).