[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Factorisation set_descriptor_dimension
Mikael Morin
mikael@gcc.gnu.org
Fri Jun 13 14:43:13 GMT 2025
https://gcc.gnu.org/g:5d14c52753b1a40c72c1907dfff10951c0883621
commit 5d14c52753b1a40c72c1907dfff10951c0883621
Author: Mikael Morin <mikael@gcc.gnu.org>
Date: Fri Feb 7 12:07:36 2025 +0100
Factorisation set_descriptor_dimension
Correction compil'
Diff:
---
gcc/fortran/trans-array.cc | 82 +++++++++++++++++++++++++---------------------
1 file changed, 44 insertions(+), 38 deletions(-)
diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index ee5b95df9ccb..87114f13424b 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -1474,6 +1474,41 @@ gfc_build_null_descriptor (tree type)
}
+static tree
+set_descriptor_dimension (stmtblock_t *block, tree desc, int dim,
+ tree lbound, tree ubound, tree stride, tree *offset)
+{
+ /* Set bounds in descriptor. */
+ lbound = fold_convert (gfc_array_index_type, lbound);
+ lbound = gfc_evaluate_now (lbound, block);
+ gfc_conv_descriptor_lbound_set (block, desc,
+ gfc_rank_cst[dim], lbound);
+
+ ubound = fold_convert (gfc_array_index_type, ubound);
+ ubound = gfc_evaluate_now (ubound, block);
+ gfc_conv_descriptor_ubound_set (block, desc,
+ gfc_rank_cst[dim], ubound);
+
+ /* Set stride. */
+ stride = fold_convert (gfc_array_index_type, stride);
+ stride = gfc_evaluate_now (stride, block);
+ gfc_conv_descriptor_stride_set (block, desc,
+ gfc_rank_cst[dim], stride);
+
+ /* Update offset. */
+ tree tmp = fold_build2_loc (input_location, MULT_EXPR,
+ gfc_array_index_type, lbound, stride);
+ *offset = fold_build2_loc (input_location, MINUS_EXPR,
+ gfc_array_index_type, *offset, tmp);
+
+ /* Return stride for next dimension. */
+ tmp = gfc_conv_array_extent_dim (lbound, ubound, NULL);
+ stride = fold_build2_loc (input_location, MULT_EXPR,
+ gfc_array_index_type, stride, tmp);
+ return stride;
+}
+
+
/* Modify a descriptor such that the lbound of a given dimension is the value
specified. This also updates ubound and offset accordingly. */
@@ -1824,9 +1859,9 @@ gfc_conv_remap_descriptor (stmtblock_t *block, tree dest, tree src,
/* Copy offset but adjust it such that it would correspond
to a lbound of zero. */
+ tree offset;
if (src_rank == -1)
- gfc_conv_descriptor_offset_set (block, dest,
- gfc_index_zero_node);
+ offset = gfc_index_zero_node;
else
{
tree offs = gfc_conv_descriptor_offset_get (src);
@@ -1842,7 +1877,7 @@ gfc_conv_remap_descriptor (stmtblock_t *block, tree dest, tree src,
offs = fold_build2_loc (input_location, PLUS_EXPR,
gfc_array_index_type, offs, tmp);
}
- gfc_conv_descriptor_offset_set (block, dest, offs);
+ offset = offs;
}
/* Set the bounds as declared for the LHS and calculate strides as
well as another offset update accordingly. */
@@ -1858,46 +1893,17 @@ gfc_conv_remap_descriptor (stmtblock_t *block, tree dest, tree src,
/* Convert declared bounds. */
gfc_init_se (&lower_se, NULL);
gfc_init_se (&upper_se, NULL);
- gfc_conv_expr (&lower_se, as.lower[dim]);
- gfc_conv_expr (&upper_se, as.upper[dim]);
+ gfc_conv_expr_val (&lower_se, as.lower[dim]);
+ gfc_conv_expr_val (&upper_se, as.upper[dim]);
gfc_add_block_to_block (block, &lower_se.pre);
gfc_add_block_to_block (block, &upper_se.pre);
- tree lbound = fold_convert (gfc_array_index_type, lower_se.expr);
- tree ubound = fold_convert (gfc_array_index_type, upper_se.expr);
-
- lbound = gfc_evaluate_now (lbound, block);
- ubound = gfc_evaluate_now (ubound, block);
-
- gfc_add_block_to_block (block, &lower_se.post);
- gfc_add_block_to_block (block, &upper_se.post);
-
- /* Set bounds in descriptor. */
- gfc_conv_descriptor_lbound_set (block, dest,
- gfc_rank_cst[dim], lbound);
- gfc_conv_descriptor_ubound_set (block, dest,
- gfc_rank_cst[dim], ubound);
-
- /* Set stride. */
- stride = gfc_evaluate_now (stride, block);
- gfc_conv_descriptor_stride_set (block, dest,
- gfc_rank_cst[dim], stride);
-
- /* Update offset. */
- tree offs = gfc_conv_descriptor_offset_get (dest);
- tmp = fold_build2_loc (input_location, MULT_EXPR,
- gfc_array_index_type, lbound, stride);
- offs = fold_build2_loc (input_location, MINUS_EXPR,
- gfc_array_index_type, offs, tmp);
- offs = gfc_evaluate_now (offs, block);
- gfc_conv_descriptor_offset_set (block, dest, offs);
-
- /* Update stride. */
- tmp = gfc_conv_array_extent_dim (lbound, ubound, NULL);
- stride = fold_build2_loc (input_location, MULT_EXPR,
- gfc_array_index_type, stride, tmp);
+ stride = set_descriptor_dimension (block, dest, dim,
+ lower_se.expr, upper_se.expr, stride,
+ &offset);
}
+ gfc_conv_descriptor_offset_set (block, dest, offset);
}
More information about the Gcc-cvs
mailing list