[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Introduction gfc_array_ref_info
Mikael Morin
mikael@gcc.gnu.org
Wed Sep 17 09:43:19 GMT 2025
https://gcc.gnu.org/g:28b6d180d243bd03d14ae401c1936ecd199e9e0d
commit 28b6d180d243bd03d14ae401c1936ecd199e9e0d
Author: Mikael Morin <mikael@gcc.gnu.org>
Date: Tue Sep 16 18:44:49 2025 +0200
Introduction gfc_array_ref_info
Diff:
---
gcc/fortran/trans-array.cc | 59 +++++++++++++++++++++++++++++++++-------------
gcc/fortran/trans-expr.cc | 5 ++--
gcc/fortran/trans-io.cc | 2 +-
gcc/fortran/trans.cc | 2 +-
gcc/fortran/trans.h | 19 +++++++++++++--
5 files changed, 63 insertions(+), 24 deletions(-)
diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 72fe62445983..f2a0d5ffe304 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -635,7 +635,7 @@ gfc_trans_allocate_array_storage (stmtblock_t * pre, stmtblock_t * post,
bool onstack;
desc = info->descriptor;
- info->offset = gfc_index_zero_node;
+ info->element_ref.index = gfc_index_zero_node;
if (size == NULL_TREE || (dynamic && integer_zerop (size)))
{
/* A callee allocated array. */
@@ -2231,7 +2231,7 @@ trans_constant_array_constructor (gfc_ss * ss, tree type)
info->descriptor = tmp;
info->data = gfc_build_addr_expr (NULL_TREE, tmp);
- info->offset = gfc_index_zero_node;
+ info->element_ref.index = gfc_index_zero_node;
for (i = 0; i < ss->dimen; i++)
{
@@ -2814,7 +2814,7 @@ gfc_add_loop_ss_code (gfc_loopinfo * loop, gfc_ss * ss, bool subscript,
tree tmp = gfc_class_data_get (se.expr);
info->descriptor = tmp;
info->data = gfc_conv_descriptor_data_get (tmp);
- info->offset = gfc_conv_descriptor_offset_get (tmp);
+ info->element_ref.index = gfc_conv_descriptor_offset_get (tmp);
for (gfc_ss *s = ss; s; s = s->parent)
for (int n = 0; n < s->dimen; n++)
{
@@ -3107,12 +3107,12 @@ gfc_conv_ss_descriptor (stmtblock_t * block, gfc_ss * ss, int base)
tmp = gfc_conv_array_offset (se.expr);
if (!ss->is_alloc_lhs)
tmp = gfc_evaluate_now (tmp, block);
- info->offset = tmp;
+ info->element_ref.index = tmp;
/* Make absolutely sure that the saved_offset is indeed saved
so that the variable is still accessible after the loops
are translated. */
- info->saved_offset = info->offset;
+ info->saved_offset = info->element_ref.index;
}
}
@@ -3710,11 +3710,11 @@ gfc_conv_scalarized_array_ref (gfc_se * se, gfc_array_ref * ar,
index = conv_array_index_offset (se, ss, ss->dim[n], n, ar, info->stride0);
/* Add the offset for this dimension to the stored offset for all other
dimensions. */
- if (info->offset && !integer_zerop (info->offset))
+ if (info->element_ref.index && !integer_zerop (info->element_ref.index))
index = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
- index, info->offset);
+ index, info->element_ref.index);
- base = build_fold_indirect_ref_loc (input_location, info->data);
+ base = build_fold_indirect_ref_loc (input_location, info->element_ref.base);
/* Use the vptr 'size' field to access the element of a class array. */
if (build_class_array_ref (se, base, index))
@@ -4029,10 +4029,10 @@ add_array_offset (stmtblock_t *pblock, gfc_loopinfo *loop, gfc_ss *ss,
index = conv_array_index_offset (&se, ss, array_dim, loop_dim, ar, stride);
gfc_add_block_to_block (pblock, &se.pre);
- info->offset = fold_build2_loc (input_location, PLUS_EXPR,
- gfc_array_index_type,
- info->offset, index);
- info->offset = gfc_evaluate_now (info->offset, pblock);
+ info->element_ref.index = fold_build2_loc (input_location, PLUS_EXPR,
+ gfc_array_index_type,
+ info->element_ref.index, index);
+ info->element_ref.index = gfc_evaluate_now (info->element_ref.index, pblock);
}
@@ -4140,7 +4140,7 @@ gfc_trans_preloop_setup (gfc_loopinfo * loop, int dim, int flag,
/* Remember this offset for the second loop. */
if (dim == loop->temp_dim - 1 && loop->parent == NULL)
- info->saved_offset = info->offset;
+ info->saved_offset = info->element_ref.index;
}
}
@@ -4157,6 +4157,28 @@ gfc_start_scalarized_body (gfc_loopinfo * loop, stmtblock_t * pbody)
gcc_assert (!loop->array_parameter);
+ for (gfc_ss *ss = loop->ss; ss != gfc_ss_terminator; ss = ss->loop_chain)
+ {
+ gfc_ss_type ss_type;
+ gfc_ss_info *ss_info;
+
+ ss_info = ss->info;
+
+ if ((ss_info->useflags & 1) == 0)
+ continue;
+
+ ss_type = ss_info->type;
+ if (ss_type != GFC_SS_SECTION
+ && ss_type != GFC_SS_FUNCTION
+ && ss_type != GFC_SS_CONSTRUCTOR
+ && ss_type != GFC_SS_COMPONENT)
+ continue;
+
+ gfc_array_info *info = &ss_info->data.array;
+
+ info->element_ref.base = info->data;
+ }
+
for (dim = loop->dimen - 1; dim >= 0; dim--)
{
n = loop->order[dim];
@@ -4369,7 +4391,10 @@ gfc_trans_scalarized_loop_boundary (gfc_loopinfo * loop, stmtblock_t * body)
&& ss_type != GFC_SS_COMPONENT)
continue;
- ss_info->data.array.offset = ss_info->data.array.saved_offset;
+ gfc_array_info *info = &ss_info->data.array;
+
+ info->element_ref.base = info->data;
+ info->element_ref.index = info->saved_offset;
}
/* Restart all the inner loops we just finished. */
@@ -4763,6 +4788,7 @@ done:
info->data = gfc_conv_array_data (info->descriptor);
info->data = gfc_evaluate_now (info->data, &outer_loop->pre);
+ info->element_ref.index = gfc_index_zero_node;
gfc_expr *array = expr->value.function.actual->expr;
tree rank = build_int_cst (gfc_array_index_type, array->rank);
@@ -4774,7 +4800,6 @@ done:
info->end[0] = gfc_evaluate_now (tmp, &outer_loop->pre);
info->start[0] = gfc_index_zero_node;
info->stride[0] = gfc_index_one_node;
- info->offset = gfc_index_zero_node;
continue;
}
@@ -10360,8 +10385,8 @@ gfc_update_reallocated_descriptor (stmtblock_t *block, gfc_loopinfo *loop)
if (save_descriptor_data (info->descriptor, info->data))
SAVE_VALUE (info->data);
- SAVE_VALUE (info->offset);
- info->saved_offset = info->offset;
+ SAVE_VALUE (info->element_ref.index);
+ info->saved_offset = info->element_ref.index;
for (int i = 0; i < s->dimen; i++)
{
int dim = s->dim[i];
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index dbe3a34f96d3..1ce45294b095 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -5505,8 +5505,7 @@ gfc_conv_subref_array_arg (gfc_se *se, gfc_expr * expr, int g77,
rse.loop->loopvar[0], offset);
/* Now use the offset for the reference. */
- tmp = build_fold_indirect_ref_loc (input_location,
- info->data);
+ tmp = build_fold_indirect_ref_loc (input_location, info->element_ref.base);
rse.expr = gfc_build_array_ref (tmp, tmp_index);
if (expr->ts.type == BT_CHARACTER)
@@ -9165,7 +9164,7 @@ gfc_trans_subarray_assign (tree dest, gfc_component * cm, gfc_expr * expr)
lss_array->shape = gfc_get_shape (cm->as->rank);
lss_array->descriptor = dest;
lss_array->data = gfc_conv_array_data (dest);
- lss_array->offset = gfc_conv_array_offset (dest);
+ lss_array->element_ref.index = gfc_conv_array_offset (dest);
for (n = 0; n < cm->as->rank; n++)
{
lss_array->start[n] = gfc_conv_array_lbound (dest, n);
diff --git a/gcc/fortran/trans-io.cc b/gcc/fortran/trans-io.cc
index 2ee60a7b1439..9277ad36b870 100644
--- a/gcc/fortran/trans-io.cc
+++ b/gcc/fortran/trans-io.cc
@@ -2188,7 +2188,7 @@ transfer_array_component (tree expr, gfc_component * cm, locus * where)
ss_array->descriptor = expr;
ss_array->data = gfc_conv_array_data (expr);
- ss_array->offset = gfc_conv_array_offset (expr);
+ ss_array->element_ref.index = gfc_conv_array_offset (expr);
for (n = 0; n < cm->as->rank; n++)
{
ss_array->start[n] = gfc_conv_array_lbound (expr, n);
diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc
index 76ddffc36dec..669a2ce6e654 100644
--- a/gcc/fortran/trans.cc
+++ b/gcc/fortran/trans.cc
@@ -557,7 +557,7 @@ gfc_build_array_ref (tree base, tree offset, bool non_negative_offset,
tree elt_size = fold_convert (gfc_array_index_type,
TYPE_SIZE_UNIT (type));
- return build_spanned_array_ref (base, zero_based_index, elt_size);
+ return gfc_build_spanned_array_ref (base, zero_based_index, elt_size);
}
}
diff --git a/gcc/fortran/trans.h b/gcc/fortran/trans.h
index 31e89825d89a..0972000e2c1c 100644
--- a/gcc/fortran/trans.h
+++ b/gcc/fortran/trans.h
@@ -182,6 +182,21 @@ enum gfc_structure_caf_mode_t {
};
+typedef struct gfc_array_ref_info
+{
+ tree base;
+ enum access_type
+ {
+ ARRAY_INDEX,
+ POINTER_OFFSET
+ };
+
+ access_type access;
+ tree index;
+}
+gfc_array_ref_info;
+
+
/* The array-specific scalarization information. The array members of
this struct are indexed by actual array index, and thus can be sparse. */
@@ -195,8 +210,6 @@ typedef struct gfc_array_info
tree descriptor;
/* holds the pointer to the data array. */
tree data;
- /* To move some of the array index calculation out of the innermost loop. */
- tree offset;
tree saved_offset;
tree stride0;
/* Holds the SS for a subscript. Indexed by actual dimension. */
@@ -209,6 +222,8 @@ typedef struct gfc_array_info
tree end[GFC_MAX_DIMENSIONS];
tree stride[GFC_MAX_DIMENSIONS];
tree delta[GFC_MAX_DIMENSIONS];
+
+ struct gfc_array_ref_info element_ref;
}
gfc_array_info;
More information about the Gcc-cvs
mailing list