[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Extraction gfc_shift_descriptor
Mikael Morin
mikael@gcc.gnu.org
Fri Sep 19 19:17:40 GMT 2025
https://gcc.gnu.org/g:b1a4ac512990cf845a51cfa2e0a8cc3e825a15e1
commit b1a4ac512990cf845a51cfa2e0a8cc3e825a15e1
Author: Mikael Morin <mikael@gcc.gnu.org>
Date: Wed Jul 23 14:59:35 2025 +0200
Extraction gfc_shift_descriptor
Diff:
---
gcc/fortran/trans-descriptor.cc | 32 ++++++++++++++++++++++++++++++++
gcc/fortran/trans-descriptor.h | 2 ++
gcc/fortran/trans-expr.cc | 39 ++-------------------------------------
3 files changed, 36 insertions(+), 37 deletions(-)
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index db9dc8c326b7..4da8a1f24899 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -1231,3 +1231,35 @@ gfc_set_subarray_descriptor (stmtblock_t *block, tree descr, tree value,
gfc_conv_descriptor_offset_set (block, descr, tmp);
}
}
+
+
+void
+gfc_shift_descriptor (stmtblock_t *block, tree descr, int rank,
+ tree lbound[GFC_MAX_DIMENSIONS],
+ tree ubound[GFC_MAX_DIMENSIONS])
+{
+ tree size = gfc_index_one_node;
+ tree offset = gfc_index_zero_node;
+ for (int n = 0; n < rank; n++)
+ {
+ tree tmp = gfc_conv_descriptor_ubound_get (descr, gfc_rank_cst[n]);
+ tmp = fold_build2_loc (input_location, PLUS_EXPR,
+ gfc_array_index_type, tmp,
+ gfc_index_one_node);
+ gfc_conv_descriptor_ubound_set (block, descr, gfc_rank_cst[n], tmp);
+ gfc_conv_descriptor_lbound_set (block, descr, gfc_rank_cst[n],
+ gfc_index_one_node);
+ size = gfc_evaluate_now (size, block);
+ offset = fold_build2_loc (input_location, MINUS_EXPR,
+ gfc_array_index_type, offset, size);
+ offset = gfc_evaluate_now (offset, block);
+ tmp = fold_build2_loc (input_location, MINUS_EXPR,
+ gfc_array_index_type, ubound[n], lbound[n]);
+ tmp = fold_build2_loc (input_location, PLUS_EXPR,
+ gfc_array_index_type, tmp, gfc_index_one_node);
+ size = fold_build2_loc (input_location, MULT_EXPR,
+ gfc_array_index_type, size, tmp);
+ }
+
+ gfc_conv_descriptor_offset_set (block, descr, offset);
+}
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index 2a36a6c3623a..17ef086343aa 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -105,6 +105,8 @@ void gfc_conv_shift_descriptor (stmtblock_t *, tree, int);
void gfc_conv_shift_descriptor (stmtblock_t *, tree, const gfc_array_ref &);
void gfc_conv_shift_descriptor (stmtblock_t *, tree, tree, int, tree);
void gfc_set_subarray_descriptor (stmtblock_t *, tree, tree, gfc_expr *, gfc_expr *);
+void gfc_shift_descriptor (stmtblock_t *, tree, int, tree [GFC_MAX_DIMENSIONS],
+ tree [GFC_MAX_DIMENSIONS]);
void gfc_set_descriptor_from_scalar_class (stmtblock_t *, tree, tree, gfc_expr *);
void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree, symbol_attribute,
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 55f46be5b504..e6434f56cb22 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -5386,7 +5386,6 @@ gfc_conv_subref_array_arg (gfc_se *se, gfc_expr * expr, int g77,
tree tmp_index;
tree tmp;
tree base_type;
- tree size;
stmtblock_t body;
int n;
int dimen;
@@ -5627,42 +5626,8 @@ class_array_fcn:
/* Determine the offset for pointer formal arguments and set the
lbounds to one. */
if (formal_ptr)
- {
- size = gfc_index_one_node;
- offset = gfc_index_zero_node;
- for (n = 0; n < dimen; n++)
- {
- tmp = gfc_conv_descriptor_ubound_get (parmse->expr,
- gfc_rank_cst[n]);
- tmp = fold_build2_loc (input_location, PLUS_EXPR,
- gfc_array_index_type, tmp,
- gfc_index_one_node);
- gfc_conv_descriptor_ubound_set (&parmse->pre,
- parmse->expr,
- gfc_rank_cst[n],
- tmp);
- gfc_conv_descriptor_lbound_set (&parmse->pre,
- parmse->expr,
- gfc_rank_cst[n],
- gfc_index_one_node);
- size = gfc_evaluate_now (size, &parmse->pre);
- offset = fold_build2_loc (input_location, MINUS_EXPR,
- gfc_array_index_type,
- offset, size);
- offset = gfc_evaluate_now (offset, &parmse->pre);
- tmp = fold_build2_loc (input_location, MINUS_EXPR,
- gfc_array_index_type,
- rse.loop->to[n], rse.loop->from[n]);
- tmp = fold_build2_loc (input_location, PLUS_EXPR,
- gfc_array_index_type,
- tmp, gfc_index_one_node);
- size = fold_build2_loc (input_location, MULT_EXPR,
- gfc_array_index_type, size, tmp);
- }
-
- gfc_conv_descriptor_offset_set (&parmse->pre, parmse->expr,
- offset);
- }
+ gfc_shift_descriptor (&parmse->pre, parmse->expr, dimen,
+ rse.loop->from, rse.loop->to);
/* We want either the address for the data or the address of the descriptor,
depending on the mode of passing array arguments. */
More information about the Gcc-cvs
mailing list