From: Mikael Morin <[email protected]>

Regression tested on powerpc64le-unknown-linux-gnu.  OK for master?

-- >8 --

Add accessor functions to get or set the value of the elem_len field of
array descriptors, and remove from the public API the function giving direct
acces to the field.

gcc/fortran/ChangeLog:

        * trans-descriptor.cc (gfc_conv_descriptor_elem_len): Make static
        and rename ...
        (conv_descriptor_elem_len): ... to this.
        (gfc_conv_descriptor_elem_len_get,
        gfc_conv_descriptor_elem_len_set): New functions.
        * trans-descriptor.h (gfc_conv_descriptor_elem_len): Remove
        declaration.
        (gfc_conv_descriptor_elem_len_get,
        gfc_conv_descriptor_elem_len_set): New declarations.
        * trans-decl.cc (gfc_conv_cfi_to_gfc): Use
        gfc_conv_descriptor_elem_len_get to get the value of the elem_len
        field and gfc_conv_descriptor_elem_len_set to set it.
        * trans-array.cc (gfc_array_init_size,
        gfc_alloc_allocatable_for_assignment): Likewise.
        * trans-expr.cc (gfc_conv_scalar_to_descriptor,
        gfc_conv_gfc_desc_to_cfi_desc, gfc_trans_pointer_assignment):
        Likewise.
        * trans-intrinsic.cc (gfc_conv_is_contiguous_expr,
        gfc_conv_intrinsic_sizeof): Likewise.
        * trans-openmp.cc (gfc_omp_array_size, gfc_omp_deep_mapping_item):
        Likewise.
---
 gcc/fortran/trans-array.cc      |  8 ++------
 gcc/fortran/trans-decl.cc       | 10 +++++-----
 gcc/fortran/trans-descriptor.cc | 24 ++++++++++++++++++++++--
 gcc/fortran/trans-descriptor.h  |  3 ++-
 gcc/fortran/trans-expr.cc       | 10 ++++------
 gcc/fortran/trans-intrinsic.cc  |  9 ++-------
 gcc/fortran/trans-openmp.cc     |  6 +++---
 7 files changed, 40 insertions(+), 30 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index e164b982e06..5f47bd8ce3b 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -5914,11 +5914,7 @@ gfc_array_init_size (tree descriptor, int rank, int 
corank, tree * poffset,
   else if (expr->ts.type == BT_CLASS && !explicit_ts
           && expr3 && expr3->ts.type != BT_CLASS
           && expr3_elem_size != NULL_TREE && expr3_desc == NULL_TREE)
-    {
-      tmp = gfc_conv_descriptor_elem_len (descriptor);
-      gfc_add_modify (pblock, tmp,
-                     fold_convert (TREE_TYPE (tmp), expr3_elem_size));
-    }
+    gfc_conv_descriptor_elem_len_set (pblock, descriptor, expr3_elem_size);
   else
     {
       tmp = gfc_conv_descriptor_dtype (descriptor);
@@ -11345,7 +11341,7 @@ gfc_alloc_allocatable_for_assignment (gfc_loopinfo 
*loop,
     {
       /* Unfortunately, the lhs vptr is set too early in many cases.
         Play it safe by using the descriptor element length.  */
-      tmp = gfc_conv_descriptor_elem_len (desc);
+      tmp = gfc_conv_descriptor_elem_len_get (desc);
       elemsize1 = fold_convert (gfc_array_index_type, tmp);
     }
   else
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 5efed17e86b..5ef2603d6bf 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -7334,8 +7334,8 @@ gfc_conv_cfi_to_gfc (stmtblock_t *init, stmtblock_t 
*finally,
   if (sym->ts.type == BT_ASSUMED)
     {
       /* For type(*), take elem_len + dtype.type from the actual argument.  */
-      gfc_add_modify (&block, gfc_conv_descriptor_elem_len (gfc_desc),
-                     gfc_get_cfi_desc_elem_len (cfi));
+      gfc_conv_descriptor_elem_len_set (&block, gfc_desc,
+                                       gfc_get_cfi_desc_elem_len (cfi));
       tree cond;
       tree ctype = gfc_get_cfi_desc_type (cfi);
       ctype = fold_build2_loc (input_location, BIT_AND_EXPR, TREE_TYPE (ctype),
@@ -7565,7 +7565,7 @@ gfc_conv_cfi_to_gfc (stmtblock_t *init, stmtblock_t 
*finally,
       /* memcpy (lhs + idx*elem_len, rhs + shift, elem_len)  */
       tree elem_len;
       if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (gfc_desc)))
-       elem_len = gfc_conv_descriptor_elem_len (gfc_desc);
+       elem_len = gfc_conv_descriptor_elem_len_get (gfc_desc);
       else
        elem_len = gfc_get_cfi_desc_elem_len (cfi);
       lhs = fold_build2_loc (input_location, MULT_EXPR, size_type_node,
@@ -7603,7 +7603,7 @@ gfc_conv_cfi_to_gfc (stmtblock_t *init, stmtblock_t 
*finally,
   /* if do_copy_inout:  gfc->dspan = gfc->dtype.elem_len
      We use gfc instead of cfi on the RHS as this might be a constant.  */
   tmp = fold_convert (gfc_array_index_type,
-                     gfc_conv_descriptor_elem_len (gfc_desc));
+                     gfc_conv_descriptor_elem_len_get (gfc_desc));
   if (!do_copy_inout)
     {
       /* gfc->dspan = ((cfi->dim[0].sm % gfc->elem_len)
@@ -7807,7 +7807,7 @@ done:
          /* memcpy (lhs + shift, rhs + idx*elem_len, elem_len) */
          tree elem_len;
          if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (gfc_desc)))
-           elem_len = gfc_conv_descriptor_elem_len (gfc_desc);
+           elem_len = gfc_conv_descriptor_elem_len_get (gfc_desc);
          else
            elem_len = gfc_get_cfi_desc_elem_len (cfi);
          rhs = fold_build2_loc (input_location, MULT_EXPR, size_type_node,
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 5286d3d54ec..0a1355e3e5f 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -182,8 +182,8 @@ gfc_conv_descriptor_version (tree desc)
 
 /* Return the element length from the descriptor dtype field.  */
 
-tree
-gfc_conv_descriptor_elem_len (tree desc)
+static tree
+conv_descriptor_elem_len (tree desc)
 {
   tree tmp;
   tree dtype;
@@ -197,6 +197,26 @@ gfc_conv_descriptor_elem_len (tree desc)
                          dtype, tmp, NULL_TREE);
 }
 
+/* Return the descriptor DESC's array element size in bytes.  */
+
+tree
+gfc_conv_descriptor_elem_len_get (tree desc)
+{
+  return conv_descriptor_elem_len (desc);
+}
+
+/* Add code to BLOCK setting to VALUE the descriptor DESC's size (in bytes) of
+   array elements.  */
+
+void
+gfc_conv_descriptor_elem_len_set (stmtblock_t *block, tree desc, tree value)
+{
+  location_t loc = input_location;
+  tree t = conv_descriptor_elem_len (desc);
+  gfc_add_modify_loc (loc, block, t,
+                     fold_convert_loc (loc, TREE_TYPE (t), value));
+}
+
 
 tree
 gfc_conv_descriptor_attribute (tree desc)
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index b68a28bddff..afc8f5d442e 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -23,7 +23,6 @@ along with GCC; see the file COPYING3.  If not see
 tree gfc_conv_descriptor_dtype (tree);
 tree gfc_conv_descriptor_rank (tree);
 tree gfc_conv_descriptor_version (tree);
-tree gfc_conv_descriptor_elem_len (tree);
 tree gfc_conv_descriptor_attribute (tree);
 tree gfc_conv_descriptor_type (tree);
 tree gfc_get_descriptor_dimension (tree);
@@ -32,6 +31,7 @@ tree gfc_conv_descriptor_token (tree);
 
 tree gfc_conv_descriptor_data_get (tree);
 tree gfc_conv_descriptor_offset_get (tree);
+tree gfc_conv_descriptor_elem_len_get (tree);
 tree gfc_conv_descriptor_span_get (tree);
 
 tree gfc_conv_descriptor_stride_get (tree, tree);
@@ -40,6 +40,7 @@ tree gfc_conv_descriptor_ubound_get (tree, tree);
 
 void gfc_conv_descriptor_data_set (stmtblock_t *, tree, tree);
 void gfc_conv_descriptor_offset_set (stmtblock_t *, tree, tree);
+void gfc_conv_descriptor_elem_len_set (stmtblock_t *, tree, tree);
 void gfc_conv_descriptor_span_set (stmtblock_t *, tree, tree);
 void gfc_conv_descriptor_stride_set (stmtblock_t *, tree, tree, tree);
 void gfc_conv_descriptor_lbound_set (stmtblock_t *, tree, tree, tree);
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 29a4d758d8a..230665ef9c5 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -130,7 +130,7 @@ gfc_conv_scalar_to_descriptor (gfc_se *se, tree scalar, 
symbol_attribute attr)
                  gfc_get_dtype_rank_type (0, etype));
   gfc_conv_descriptor_data_set (&se->pre, desc, scalar);
   gfc_conv_descriptor_span_set (&se->pre, desc,
-                               gfc_conv_descriptor_elem_len (desc));
+                               gfc_conv_descriptor_elem_len_get (desc));
 
   /* Copy pointer address back - but only if it could have changed and
      if the actual argument is a pointer and not, e.g., NULL().  */
@@ -6289,7 +6289,7 @@ gfc_conv_gfc_desc_to_cfi_desc (gfc_se *parmse, gfc_expr 
*e, gfc_symbol *fsym)
     }
   else if (e->ts.type == BT_ASSUMED)
     {
-      tmp = gfc_conv_descriptor_elem_len (gfc);
+      tmp = gfc_conv_descriptor_elem_len_get (gfc);
       tmp2 = gfc_get_cfi_desc_elem_len (cfi);
       gfc_add_modify (&block2, tmp2, fold_convert (TREE_TYPE (tmp2), tmp));
     }
@@ -6304,7 +6304,7 @@ gfc_conv_gfc_desc_to_cfi_desc (gfc_se *parmse, gfc_expr 
*e, gfc_symbol *fsym)
       tree type = fold_convert (TREE_TYPE (ctype),
                                gfc_conv_descriptor_type (gfc));
       tree kind = fold_convert (TREE_TYPE (ctype),
-                               gfc_conv_descriptor_elem_len (gfc));
+                               gfc_conv_descriptor_elem_len_get (gfc));
       kind = fold_build2_loc (input_location, LSHIFT_EXPR, TREE_TYPE (type),
                              kind, build_int_cst (TREE_TYPE (type),
                                                   CFI_type_kind_shift));
@@ -11354,9 +11354,7 @@ gfc_trans_pointer_assignment (gfc_expr * expr1, 
gfc_expr * expr2)
              tmp = TYPE_SIZE_UNIT (gfc_typenode_for_spec (&expr2->ts));
              elem_len = fold_convert (gfc_array_index_type, tmp);
              elem_len = gfc_evaluate_now (elem_len, &block);
-             tmp = gfc_conv_descriptor_elem_len (desc);
-             gfc_add_modify (&block, tmp,
-                             fold_convert (TREE_TYPE (tmp), elem_len));
+             gfc_conv_descriptor_elem_len_set (&block, desc, elem_len);
            }
 
          if (rank_remap)
diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index 930dae6b40b..a74ad261722 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -2386,7 +2386,7 @@ gfc_conv_is_contiguous_expr (gfc_se *se, gfc_expr *arg)
     {
       tree span = gfc_conv_descriptor_span_get (desc);
       tmp = fold_convert (TREE_TYPE (span),
-                         gfc_conv_descriptor_elem_len (desc));
+                         gfc_conv_descriptor_elem_len_get (desc));
       cond = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node,
                              span, tmp);
       se->expr = fold_build2_loc (input_location, TRUTH_ANDIF_EXPR,
@@ -8352,7 +8352,6 @@ gfc_conv_intrinsic_sizeof (gfc_se *se, gfc_expr *expr)
   tree lower;
   tree upper;
   tree byte_size;
-  tree field;
   int n;
 
   gfc_init_se (&argse, NULL);
@@ -8376,11 +8375,7 @@ gfc_conv_intrinsic_sizeof (gfc_se *se, gfc_expr *expr)
       if (POINTER_TYPE_P (TREE_TYPE (tmp)))
        tmp = build_fold_indirect_ref_loc (input_location, tmp);
 
-      tmp = gfc_conv_descriptor_dtype (tmp);
-      field = gfc_advance_chain (TYPE_FIELDS (get_dtype_type_node ()),
-                                GFC_DTYPE_ELEM_LEN);
-      tmp = fold_build3_loc (input_location, COMPONENT_REF, TREE_TYPE (field),
-                            tmp, field, NULL_TREE);
+      tmp = gfc_conv_descriptor_elem_len_get (tmp);
 
       byte_size = fold_convert (gfc_array_index_type, tmp);
     }
diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index 2b2cef7e8ab..5e419180983 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -196,7 +196,7 @@ gfc_omp_array_size (tree decl, gimple_seq *pre_p)
   size = fold_convert (size_type_node, size);
   tree elemsz = gfc_get_element_type (TREE_TYPE (decl));
   if (TREE_CODE (elemsz) == ARRAY_TYPE && TYPE_STRING_FLAG (elemsz))
-    elemsz = gfc_conv_descriptor_elem_len (decl);
+    elemsz = gfc_conv_descriptor_elem_len_get (decl);
   else
     elemsz = TYPE_SIZE_UNIT (elemsz);
   size = fold_build2 (MULT_EXPR, size_type_node, size, elemsz);
@@ -2206,7 +2206,7 @@ gfc_omp_deep_mapping_item (bool is_cnt, bool do_copy, 
bool do_alloc_check,
          /* TODO: Optimization: Shouldn't this be an expr. const, except for
             deferred-length strings. (Cf. also below).  */
          elem_len = (poly ? gfc_class_vtab_size_get (class_decl)
-                          : gfc_conv_descriptor_elem_len (decl));
+                          : gfc_conv_descriptor_elem_len_get (decl));
          tmp = (POINTER_TYPE_P (TREE_TYPE (decl))
                 ? build_fold_indirect_ref (decl) : decl);
          size = gfc_omp_get_array_size (loc, tmp, seq);
@@ -2251,7 +2251,7 @@ gfc_omp_deep_mapping_item (bool is_cnt, bool do_copy, 
bool do_alloc_check,
        {
          if (elem_len == NULL_TREE)
            {
-             elem_len = gfc_conv_descriptor_elem_len (decl);
+             elem_len = gfc_conv_descriptor_elem_len_get (decl);
              size = fold_convert (size_type_node,
                                   gfc_omp_get_array_size (loc, decl, seq));
            }
-- 
2.51.0

Reply via email to