[PATCH 02/16] OpenMP/OpenACC: Move array_ref/indirect_ref handling code out of extract_base_bit_offset

Julian Brown julian@codesourcery.com
Thu Nov 25 14:07:18 GMT 2021


This patch slightly cleans up the semantics of extract_base_bit_offset,
in that the stripping of ARRAY_REFS/INDIRECT_REFS out of
extract_base_bit_offset is moved back into the (two) call sites of the
function. This is done in preparation for follow-on patches that extend
the function.

Previously posted for the og11 branch here (patch & reversion/rework):

  https://gcc.gnu.org/pipermail/gcc-patches/2021-June/571712.html
  https://gcc.gnu.org/pipermail/gcc-patches/2021-June/571884.html

OK?

Thanks,

Julian

2021-06-03  Julian Brown  <julian@codesourcery.com>

gcc/
	* gimplify.c (extract_base_bit_offset): Don't look through ARRAY_REFs or
	INDIRECT_REFs here.
	(build_struct_group): Reinstate previous behaviour for handling
	ARRAY_REFs/INDIRECT_REFs.
---
 gcc/gimplify.c | 59 +++++++++++++++++++++++++-------------------------
 1 file changed, 29 insertions(+), 30 deletions(-)

diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 8d8735ae4c1..1baea68920b 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -8675,31 +8675,7 @@ extract_base_bit_offset (tree base, tree *base_ref, poly_int64 *bitposp,
   poly_offset_int poffset;
 
   if (base_ref)
-    {
-      *base_ref = NULL_TREE;
-
-      while (TREE_CODE (base) == ARRAY_REF)
-	base = TREE_OPERAND (base, 0);
-
-      if (TREE_CODE (base) == INDIRECT_REF)
-	base = TREE_OPERAND (base, 0);
-    }
-  else
-    {
-      if (TREE_CODE (base) == ARRAY_REF)
-	{
-	  while (TREE_CODE (base) == ARRAY_REF)
-	    base = TREE_OPERAND (base, 0);
-	  if (TREE_CODE (base) != COMPONENT_REF
-	      || TREE_CODE (TREE_TYPE (base)) != ARRAY_TYPE)
-	    return NULL_TREE;
-	}
-      else if (TREE_CODE (base) == INDIRECT_REF
-	       && TREE_CODE (TREE_OPERAND (base, 0)) == COMPONENT_REF
-	       && (TREE_CODE (TREE_TYPE (TREE_OPERAND (base, 0)))
-		   == REFERENCE_TYPE))
-	base = TREE_OPERAND (base, 0);
-    }
+    *base_ref = NULL_TREE;
 
   base = get_inner_reference (base, &bitsize, &bitpos, &offset, &mode,
 			      &unsignedp, &reversep, &volatilep);
@@ -9673,12 +9649,17 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p,
 		  poly_offset_int offset1;
 		  poly_int64 bitpos1;
 		  tree tree_offset1;
-		  tree base_ref;
+		  tree base_ref, ocd = OMP_CLAUSE_DECL (c);
 
-		  tree base
-		    = extract_base_bit_offset (OMP_CLAUSE_DECL (c), &base_ref,
-					       &bitpos1, &offset1,
-					       &tree_offset1);
+		  while (TREE_CODE (ocd) == ARRAY_REF)
+		    ocd = TREE_OPERAND (ocd, 0);
+
+		  if (TREE_CODE (ocd) == INDIRECT_REF)
+		    ocd = TREE_OPERAND (ocd, 0);
+
+		  tree base = extract_base_bit_offset (ocd, &base_ref,
+						       &bitpos1, &offset1,
+						       &tree_offset1);
 
 		  bool do_map_struct = (base == decl && !tree_offset1);
 
@@ -9871,6 +9852,24 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p,
 			    poly_offset_int offsetn;
 			    poly_int64 bitposn;
 			    tree tree_offsetn;
+
+			    if (TREE_CODE (sc_decl) == ARRAY_REF)
+			      {
+				while (TREE_CODE (sc_decl) == ARRAY_REF)
+				  sc_decl = TREE_OPERAND (sc_decl, 0);
+				if (TREE_CODE (sc_decl) != COMPONENT_REF
+				    || (TREE_CODE (TREE_TYPE (sc_decl))
+					!= ARRAY_TYPE))
+				  break;
+			      }
+			    else if (TREE_CODE (sc_decl) == INDIRECT_REF
+				     && (TREE_CODE (TREE_OPERAND (sc_decl, 0))
+					 == COMPONENT_REF)
+				     && (TREE_CODE (TREE_TYPE
+					  (TREE_OPERAND (sc_decl, 0)))
+					 == REFERENCE_TYPE))
+			      sc_decl = TREE_OPERAND (sc_decl, 0);
+
 			    tree base
 			      = extract_base_bit_offset (sc_decl, NULL,
 							 &bitposn, &offsetn,
-- 
2.29.2



More information about the Gcc-patches mailing list