This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[cft] remove a cast from array descriptors


The intent of this patch is to remove the cast added when initializing
array descriptors, which should allow the original data to be constant
propagated into the actual references.

I'd be interested in seeing (1) if this helps much and (2) if we don't
get in trouble with the array_range_ref thing.


r~



Index: trans-array.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-array.c,v
retrieving revision 1.11
diff -u -p -r1.11 trans-array.c
--- trans-array.c	15 Jul 2004 14:53:28 -0000	1.11
+++ trans-array.c	1 Aug 2004 19:13:25 -0000
@@ -321,6 +321,23 @@ gfc_build_null_descriptor (tree type)
 #undef LBOUND_SUBFIELD
 #undef UBOUND_SUBFIELD
 
+/* Convert the array EXPR, at offset ZERO_INDEX to the type expected for
+   the array descriptor DESC.  */
+
+static tree
+gfc_addr_for_descriptor_data (tree desc, tree expr, tree zero_index)
+{
+  tree type, ref;
+
+  type = gfc_array_dataptr_type (desc);
+
+  ref = build (ARRAY_RANGE_REF, TREE_TYPE (type),
+	       expr, zero_index, NULL_TREE, NULL_TREE);
+  ref = build_fold_addr_expr (ref);
+
+  return ref;
+}
+
 
 /* Mark a SS chain as used.  Flags specifies in which loops the SS is used.
    flags & 1 = Main loop body.
@@ -459,11 +476,10 @@ gfc_trans_allocate_array_storage (gfc_lo
       tmp = build_range_type (gfc_array_index_type, gfc_index_zero_node, tmp);
       tmp = build_array_type (gfc_get_element_type (TREE_TYPE (desc)), tmp);
       tmp = gfc_create_var (tmp, "A");
-      tmp = gfc_build_addr_expr (TREE_TYPE (data), tmp);
+      tmp = gfc_addr_for_descriptor_data (desc, tmp, gfc_index_zero_node);
       gfc_add_modify_expr (&loop->pre, data, tmp);
       info->data = data;
       info->offset = gfc_index_zero_node;
-
     }
   else
     {
@@ -3578,12 +3594,10 @@ gfc_conv_expr_descriptor (gfc_se * se, g
       /* Point the data pointer at the first element in the section.  */
       tmp = gfc_conv_array_data (desc);
       tmp = gfc_build_indirect_ref (tmp);
-      tmp = gfc_build_array_ref (tmp, offset);
-      offset = gfc_build_addr_expr (gfc_array_dataptr_type (desc), tmp);
+      offset = gfc_addr_for_descriptor_data (parm, tmp, offset);
 
       tmp = gfc_conv_descriptor_data (parm);
-      gfc_add_modify_expr (&loop.pre, tmp,
-			   fold_convert (TREE_TYPE (tmp), offset));
+      gfc_add_modify_expr (&loop.pre, tmp, offset);
 
       if (se->direct_byref)
 	{


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]