]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fortran: array descriptor: Move bound shift utility function [PR122521]
authorMikael Morin <mikael@gcc.gnu.org>
Thu, 2 Jul 2026 08:44:47 +0000 (10:44 +0200)
committerMikael Morin <mikael@gcc.gnu.org>
Thu, 2 Jul 2026 08:44:47 +0000 (10:44 +0200)
Move gfc_conv_shift_descriptor_lbound to trans-descriptor.cc

PR fortran/122521

gcc/fortran/ChangeLog:

* trans-array.cc (gfc_conv_shift_descriptor_lbound): Move
function ...
* trans-descriptor.cc (gfc_conv_shift_descriptor_lbound): ... to
this file.
* trans-array.h (gfc_conv_shift_descriptor_lbound): Move
declaration ...
* trans-descriptor.h (gfc_conv_shift_descriptor_lbound): ... to this
file.

gcc/fortran/trans-array.cc
gcc/fortran/trans-array.h
gcc/fortran/trans-descriptor.cc
gcc/fortran/trans-descriptor.h

index 4bc242a41642ecdf43d5d785d26e4239913a8054..876d8d9f9bdb2fb3a03a007ed618cc36547fc063 100644 (file)
@@ -216,43 +216,6 @@ gfc_get_cfi_dim_sm (tree desc, tree idx)
 #undef CFI_DIM_FIELD_SM
 
 
-/* Modify a descriptor such that the lbound of a given dimension is the value
-   specified.  This also updates ubound and offset accordingly.  */
-
-void
-gfc_conv_shift_descriptor_lbound (stmtblock_t* block, tree desc,
-                                 int dim, tree new_lbound)
-{
-  tree offs, ubound, lbound, stride;
-  tree diff, offs_diff;
-
-  new_lbound = fold_convert (gfc_array_index_type, new_lbound);
-
-  offs = gfc_conv_descriptor_offset_get (desc);
-  lbound = gfc_conv_descriptor_lbound_get (desc, gfc_rank_cst[dim]);
-  ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[dim]);
-  stride = gfc_conv_descriptor_stride_get (desc, gfc_rank_cst[dim]);
-
-  /* Get difference (new - old) by which to shift stuff.  */
-  diff = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
-                         new_lbound, lbound);
-
-  /* Shift ubound and offset accordingly.  This has to be done before
-     updating the lbound, as they depend on the lbound expression!  */
-  ubound = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
-                           ubound, diff);
-  gfc_conv_descriptor_ubound_set (block, desc, gfc_rank_cst[dim], ubound);
-  offs_diff = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
-                              diff, stride);
-  offs = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
-                         offs, offs_diff);
-  gfc_conv_descriptor_offset_set (block, desc, offs);
-
-  /* Finally set lbound to value we want.  */
-  gfc_conv_descriptor_lbound_set (block, desc, gfc_rank_cst[dim], new_lbound);
-}
-
-
 /* Mark a SS chain as used.  Flags specifies in which loops the SS is used.
    flags & 1 = Main loop body.
    flags & 2 = temp copy loop.  */
index dbd97452d36dbeeff9e2ba9d285365a1fd787720..c0afccb28e2b97718054879eef5d754afe7b18ce 100644 (file)
@@ -179,9 +179,6 @@ tree gfc_get_cfi_dim_extent (tree, tree);
 tree gfc_get_cfi_dim_sm (tree, tree);
 
 
-/* Shift lower bound of descriptor, updating ubound and offset.  */
-void gfc_conv_shift_descriptor_lbound (stmtblock_t*, tree, int, tree);
-
 /* Add pre-loop scalarization code for intrinsic functions which require
    special handling.  */
 void gfc_add_intrinsic_ss_code (gfc_loopinfo *, gfc_ss *);
index f872bb8c12a3138b290140e474b1982f71a0330e..57297fcf75d7a90c763459c8e4349d1b333c2b0f 100644 (file)
@@ -462,3 +462,40 @@ gfc_conv_descriptor_cosize (tree desc, int rank, int corank)
 {
   return gfc_conv_descriptor_size_1 (desc, rank, rank + corank - 1);
 }
+
+
+/* Modify a descriptor such that the lbound of a given dimension is the value
+   specified.  This also updates ubound and offset accordingly.  */
+
+void
+gfc_conv_shift_descriptor_lbound (stmtblock_t* block, tree desc,
+                                 int dim, tree new_lbound)
+{
+  tree offs, ubound, lbound, stride;
+  tree diff, offs_diff;
+
+  new_lbound = fold_convert (gfc_array_index_type, new_lbound);
+
+  offs = gfc_conv_descriptor_offset_get (desc);
+  lbound = gfc_conv_descriptor_lbound_get (desc, gfc_rank_cst[dim]);
+  ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[dim]);
+  stride = gfc_conv_descriptor_stride_get (desc, gfc_rank_cst[dim]);
+
+  /* Get difference (new - old) by which to shift stuff.  */
+  diff = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
+                         new_lbound, lbound);
+
+  /* Shift ubound and offset accordingly.  This has to be done before
+     updating the lbound, as they depend on the lbound expression!  */
+  ubound = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
+                           ubound, diff);
+  gfc_conv_descriptor_ubound_set (block, desc, gfc_rank_cst[dim], ubound);
+  offs_diff = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
+                              diff, stride);
+  offs = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
+                         offs, offs_diff);
+  gfc_conv_descriptor_offset_set (block, desc, offs);
+
+  /* Finally set lbound to value we want.  */
+  gfc_conv_descriptor_lbound_set (block, desc, gfc_rank_cst[dim], new_lbound);
+}
index 826a6ce882978a4f630a7fcfbbdfcb54a6000418..fefa152e2d769167d237f9b66138f757f47c6937 100644 (file)
@@ -57,4 +57,7 @@ tree gfc_build_null_descriptor (tree type);
 tree gfc_conv_descriptor_size (tree, int);
 tree gfc_conv_descriptor_cosize (tree, int, int);
 
+/* Shift lower bound of descriptor, updating ubound and offset.  */
+void gfc_conv_shift_descriptor_lbound (stmtblock_t*, tree, int, tree);
+
 #endif /* GFC_TRANS_DESCRIPTOR_H */