This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH][fortran] Use build_fold_indirec_ref instead of gfc_build_indirect_ref
- From: Richard Guenther <rguenther at suse dot de>
- To: fortran at gcc dot gnu dot org
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 16 Dec 2005 14:58:01 +0100 (CET)
- Subject: [PATCH][fortran] Use build_fold_indirec_ref instead of gfc_build_indirect_ref
Bootstrapped and tested on x86_64-unknown-linux-gnu.
Ok for mainline?
Thanks,
Richard.
2005-12-16 Richard Guenther <rguenther@suse.de>
* trans.h (gfc_build_indirect_ref): Remove declaration.
* trans.c (gfc_build_indirect_ref): Remove.
* trans-array.c (gfc_trans_array_ctor_element): Use
build_fold_indirect_ref instead of gfc_build_indirect_ref.
(gfc_trans_array_constructor_value): Likewise.
(gfc_conv_array_index_offset): Likewise.
(gfc_conv_scalarized_array_ref): Likewise.
(gfc_conv_array_ref): Likewise.
(gfc_trans_dummy_array_bias): Likewise.
(gfc_conv_expr_descriptor): Likewise.
(gfc_conv_array_parameter): Likewise.
* trans-decl.c (gfc_finish_cray_pointee): Likewise.
(gfc_get_symbol_decl): Likewise.
* trans-expr.c (gfc_conv_substring): Likewise.
(gfc_conv_component_ref): Likewise.
(gfc_conv_variable): Likewise.
(gfc_add_interface_mapping): Likewise.
(gfc_conv_function_call): Likewise.
* trans-intrinsic.c (gfc_conv_intrinsic_ichar): Likewise.
(gfc_conv_intrinsic_transfer): Likewise.
* trans-io.c (nml_get_addr_expr): Likewise.
(transfer_namelist_element): Likewise.
(transfer_expr): Likewise.
* trans-stmt.c (gfc_trans_nested_forall_loop): Likewise.
(allocate_temp_for_forall_nest_1): Likewise.
(gfc_trans_forall_1): Likewise.
*** trans-array.c (revision 72575)
--- trans-array.c (local)
*************** gfc_trans_array_ctor_element (stmtblock_
*** 932,938 ****
gfc_conv_expr (se, expr);
/* Store the value. */
! tmp = gfc_build_indirect_ref (gfc_conv_descriptor_data_get (desc));
tmp = gfc_build_array_ref (tmp, offset);
if (expr->ts.type == BT_CHARACTER)
{
--- 932,938 ----
gfc_conv_expr (se, expr);
/* Store the value. */
! tmp = build_fold_indirect_ref (gfc_conv_descriptor_data_get (desc));
tmp = gfc_build_array_ref (tmp, offset);
if (expr->ts.type == BT_CHARACTER)
{
*************** gfc_trans_array_constructor_value (stmtb
*** 1157,1163 ****
/* Use BUILTIN_MEMCPY to assign the values. */
tmp = gfc_conv_descriptor_data_get (desc);
! tmp = gfc_build_indirect_ref (tmp);
tmp = gfc_build_array_ref (tmp, *poffset);
tmp = build_fold_addr_expr (tmp);
init = build_fold_addr_expr (init);
--- 1157,1163 ----
/* Use BUILTIN_MEMCPY to assign the values. */
tmp = gfc_conv_descriptor_data_get (desc);
! tmp = build_fold_indirect_ref (tmp);
tmp = gfc_build_array_ref (tmp, *poffset);
tmp = build_fold_addr_expr (tmp);
init = build_fold_addr_expr (init);
*************** gfc_conv_array_index_offset (gfc_se * se
*** 1827,1833 ****
index, gfc_conv_array_stride (desc, 0));
/* Read the vector to get an index into info->descriptor. */
! data = gfc_build_indirect_ref (gfc_conv_array_data (desc));
index = gfc_build_array_ref (data, index);
index = gfc_evaluate_now (index, &se->pre);
--- 1827,1833 ----
index, gfc_conv_array_stride (desc, 0));
/* Read the vector to get an index into info->descriptor. */
! data = build_fold_indirect_ref (gfc_conv_array_data (desc));
index = gfc_build_array_ref (data, index);
index = gfc_evaluate_now (index, &se->pre);
*************** gfc_conv_scalarized_array_ref (gfc_se *
*** 1891,1897 ****
dimensions. */
index = fold_build2 (PLUS_EXPR, gfc_array_index_type, index, info->offset);
! tmp = gfc_build_indirect_ref (info->data);
se->expr = gfc_build_array_ref (tmp, index);
}
--- 1891,1897 ----
dimensions. */
index = fold_build2 (PLUS_EXPR, gfc_array_index_type, index, info->offset);
! tmp = build_fold_indirect_ref (info->data);
se->expr = gfc_build_array_ref (tmp, index);
}
*************** gfc_conv_array_ref (gfc_se * se, gfc_arr
*** 1980,1986 ****
/* Access the calculated element. */
tmp = gfc_conv_array_data (se->expr);
! tmp = gfc_build_indirect_ref (tmp);
se->expr = gfc_build_array_ref (tmp, index);
}
--- 1980,1986 ----
/* Access the calculated element. */
tmp = gfc_conv_array_data (se->expr);
! tmp = build_fold_indirect_ref (tmp);
se->expr = gfc_build_array_ref (tmp, index);
}
*************** gfc_trans_dummy_array_bias (gfc_symbol *
*** 3482,3488 ****
type = TREE_TYPE (tmpdesc);
gcc_assert (GFC_ARRAY_TYPE_P (type));
dumdesc = GFC_DECL_SAVED_DESCRIPTOR (tmpdesc);
! dumdesc = gfc_build_indirect_ref (dumdesc);
gfc_start_block (&block);
if (sym->ts.type == BT_CHARACTER
--- 3482,3488 ----
type = TREE_TYPE (tmpdesc);
gcc_assert (GFC_ARRAY_TYPE_P (type));
dumdesc = GFC_DECL_SAVED_DESCRIPTOR (tmpdesc);
! dumdesc = build_fold_indirect_ref (dumdesc);
gfc_start_block (&block);
if (sym->ts.type == BT_CHARACTER
*************** gfc_trans_dummy_array_bias (gfc_symbol *
*** 3707,3713 ****
stmt = gfc_finish_block (&cleanup);
/* Only do the cleanup if the array was repacked. */
! tmp = gfc_build_indirect_ref (dumdesc);
tmp = gfc_conv_descriptor_data_get (tmp);
tmp = build2 (NE_EXPR, boolean_type_node, tmp, tmpdesc);
stmt = build3_v (COND_EXPR, tmp, stmt, build_empty_stmt ());
--- 3707,3713 ----
stmt = gfc_finish_block (&cleanup);
/* Only do the cleanup if the array was repacked. */
! tmp = build_fold_indirect_ref (dumdesc);
tmp = gfc_conv_descriptor_data_get (tmp);
tmp = build2 (NE_EXPR, boolean_type_node, tmp, tmpdesc);
stmt = build3_v (COND_EXPR, tmp, stmt, build_empty_stmt ());
*************** gfc_conv_expr_descriptor (gfc_se * se, g
*** 3961,3967 ****
if (expr->ts.type == BT_CHARACTER)
{
gfc_conv_expr (&rse, expr);
! rse.expr = gfc_build_indirect_ref (rse.expr);
}
else
gfc_conv_expr_val (&rse, expr);
--- 3961,3967 ----
if (expr->ts.type == BT_CHARACTER)
{
gfc_conv_expr (&rse, expr);
! rse.expr = build_fold_indirect_ref (rse.expr);
}
else
gfc_conv_expr_val (&rse, expr);
*************** gfc_conv_expr_descriptor (gfc_se * se, g
*** 4119,4125 ****
/* 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);
gfc_conv_descriptor_data_set (&loop.pre, parm, offset);
--- 4119,4125 ----
/* Point the data pointer at the first element in the section. */
tmp = gfc_conv_array_data (desc);
! tmp = build_fold_indirect_ref (tmp);
tmp = gfc_build_array_ref (tmp, offset);
offset = gfc_build_addr_expr (gfc_array_dataptr_type (desc), tmp);
gfc_conv_descriptor_data_set (&loop.pre, parm, offset);
*************** gfc_conv_array_parameter (gfc_se * se, g
*** 4228,4234 ****
gfc_init_block (&block);
/* Only if it was repacked. This code needs to be executed before the
loop cleanup code. */
! tmp = gfc_build_indirect_ref (desc);
tmp = gfc_conv_array_data (tmp);
tmp = build2 (NE_EXPR, boolean_type_node, ptr, tmp);
tmp = build3_v (COND_EXPR, tmp, stmt, build_empty_stmt ());
--- 4228,4234 ----
gfc_init_block (&block);
/* Only if it was repacked. This code needs to be executed before the
loop cleanup code. */
! tmp = build_fold_indirect_ref (desc);
tmp = gfc_conv_array_data (tmp);
tmp = build2 (NE_EXPR, boolean_type_node, ptr, tmp);
tmp = build3_v (COND_EXPR, tmp, stmt, build_empty_stmt ());
*** trans-decl.c (revision 72575)
--- trans-decl.c (local)
*************** gfc_finish_cray_pointee (tree decl, gfc_
*** 368,374 ****
/* Parameters need to be dereferenced. */
if (sym->cp_pointer->attr.dummy)
! ptr_decl = gfc_build_indirect_ref (ptr_decl);
/* Check to see if we're dealing with a variable-sized array. */
if (sym->attr.dimension
--- 368,374 ----
/* Parameters need to be dereferenced. */
if (sym->cp_pointer->attr.dummy)
! ptr_decl = build_fold_indirect_ref (ptr_decl);
/* Check to see if we're dealing with a variable-sized array. */
if (sym->attr.dimension
*************** gfc_finish_cray_pointee (tree decl, gfc_
*** 382,388 ****
{
ptr_decl = convert (build_pointer_type (TREE_TYPE (decl)),
ptr_decl);
! value = gfc_build_indirect_ref (ptr_decl);
}
SET_DECL_VALUE_EXPR (decl, value);
--- 382,388 ----
{
ptr_decl = convert (build_pointer_type (TREE_TYPE (decl)),
ptr_decl);
! value = build_fold_indirect_ref (ptr_decl);
}
SET_DECL_VALUE_EXPR (decl, value);
*************** gfc_get_symbol_decl (gfc_symbol * sym)
*** 856,862 ****
if (sym->attr.pointer && sym->attr.dummy
&& sym->attr.dimension)
{
! tmp = gfc_build_indirect_ref (sym->backend_decl);
etype = gfc_get_element_type (TREE_TYPE (tmp));
if (TYPE_SIZE_UNIT (etype) == NULL_TREE)
{
--- 856,862 ----
if (sym->attr.pointer && sym->attr.dummy
&& sym->attr.dimension)
{
! tmp = build_fold_indirect_ref (sym->backend_decl);
etype = gfc_get_element_type (TREE_TYPE (tmp));
if (TYPE_SIZE_UNIT (etype) == NULL_TREE)
{
*** trans-expr.c (revision 72575)
--- trans-expr.c (local)
*************** gfc_conv_substring (gfc_se * se, gfc_ref
*** 232,238 ****
if (TYPE_STRING_FLAG (TREE_TYPE (se->expr)))
tmp = se->expr;
else
! tmp = gfc_build_indirect_ref (se->expr);
tmp = gfc_build_array_ref (tmp, start.expr);
se->expr = gfc_build_addr_expr (type, tmp);
}
--- 232,238 ----
if (TYPE_STRING_FLAG (TREE_TYPE (se->expr)))
tmp = se->expr;
else
! tmp = build_fold_indirect_ref (se->expr);
tmp = gfc_build_array_ref (tmp, start.expr);
se->expr = gfc_build_addr_expr (type, tmp);
}
*************** gfc_conv_component_ref (gfc_se * se, gfc
*** 284,290 ****
}
if (c->pointer && c->dimension == 0 && c->ts.type != BT_CHARACTER)
! se->expr = gfc_build_indirect_ref (se->expr);
}
--- 284,290 ----
}
if (c->pointer && c->dimension == 0 && c->ts.type != BT_CHARACTER)
! se->expr = build_fold_indirect_ref (se->expr);
}
*************** gfc_conv_variable (gfc_se * se, gfc_expr
*** 372,390 ****
&& (sym->attr.dummy
|| sym->attr.function
|| sym->attr.result))
! se->expr = gfc_build_indirect_ref (se->expr);
}
else
{
/* Dereference non-character scalar dummy arguments. */
if (sym->attr.dummy && !sym->attr.dimension)
! se->expr = gfc_build_indirect_ref (se->expr);
/* Dereference scalar hidden result. */
if (gfc_option.flag_f2c && sym->ts.type == BT_COMPLEX
&& (sym->attr.function || sym->attr.result)
&& !sym->attr.dimension && !sym->attr.pointer)
! se->expr = gfc_build_indirect_ref (se->expr);
/* Dereference non-character pointer variables.
These must be dummies, results, or scalars. */
--- 372,390 ----
&& (sym->attr.dummy
|| sym->attr.function
|| sym->attr.result))
! se->expr = build_fold_indirect_ref (se->expr);
}
else
{
/* Dereference non-character scalar dummy arguments. */
if (sym->attr.dummy && !sym->attr.dimension)
! se->expr = build_fold_indirect_ref (se->expr);
/* Dereference scalar hidden result. */
if (gfc_option.flag_f2c && sym->ts.type == BT_COMPLEX
&& (sym->attr.function || sym->attr.result)
&& !sym->attr.dimension && !sym->attr.pointer)
! se->expr = build_fold_indirect_ref (se->expr);
/* Dereference non-character pointer variables.
These must be dummies, results, or scalars. */
*************** gfc_conv_variable (gfc_se * se, gfc_expr
*** 393,399 ****
|| sym->attr.function
|| sym->attr.result
|| !sym->attr.dimension))
! se->expr = gfc_build_indirect_ref (se->expr);
}
ref = expr->ref;
--- 393,399 ----
|| sym->attr.function
|| sym->attr.result
|| !sym->attr.dimension))
! se->expr = build_fold_indirect_ref (se->expr);
}
ref = expr->ref;
*************** gfc_add_interface_mapping (gfc_interface
*** 1291,1302 ****
value = fold_convert (tmp, se->expr);
if (sym->attr.pointer)
! value = gfc_build_indirect_ref (value);
}
/* If the argument is a scalar or a pointer to an array, dereference it. */
else if (!sym->attr.dimension || sym->attr.pointer)
! value = gfc_build_indirect_ref (se->expr);
/* If the argument is an array descriptor, use it to determine
information about the actual argument's shape. */
--- 1291,1302 ----
value = fold_convert (tmp, se->expr);
if (sym->attr.pointer)
! value = build_fold_indirect_ref (value);
}
/* If the argument is a scalar or a pointer to an array, dereference it. */
else if (!sym->attr.dimension || sym->attr.pointer)
! value = build_fold_indirect_ref (se->expr);
/* If the argument is an array descriptor, use it to determine
information about the actual argument's shape. */
*************** gfc_add_interface_mapping (gfc_interface
*** 1304,1310 ****
&& GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (TREE_TYPE (se->expr))))
{
/* Get the actual argument's descriptor. */
! desc = gfc_build_indirect_ref (se->expr);
/* Create the replacement variable. */
tmp = gfc_conv_descriptor_data_get (desc);
--- 1304,1310 ----
&& GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (TREE_TYPE (se->expr))))
{
/* Get the actual argument's descriptor. */
! desc = build_fold_indirect_ref (se->expr);
/* Create the replacement variable. */
tmp = gfc_conv_descriptor_data_get (desc);
*************** gfc_conv_function_call (gfc_se * se, gfc
*** 1748,1754 ****
x = f()
where f is pointer valued, we have to dereference the result. */
if (!se->want_pointer && !byref && sym->attr.pointer)
! se->expr = gfc_build_indirect_ref (se->expr);
/* f2c calling conventions require a scalar default real function to
return a double precision result. Convert this back to default
--- 1748,1754 ----
x = f()
where f is pointer valued, we have to dereference the result. */
if (!se->want_pointer && !byref && sym->attr.pointer)
! se->expr = build_fold_indirect_ref (se->expr);
/* f2c calling conventions require a scalar default real function to
return a double precision result. Convert this back to default
*************** gfc_conv_function_call (gfc_se * se, gfc
*** 1793,1799 ****
{
/* Dereference for character pointer results. */
if (sym->attr.pointer || sym->attr.allocatable)
! se->expr = gfc_build_indirect_ref (var);
else
se->expr = var;
--- 1793,1799 ----
{
/* Dereference for character pointer results. */
if (sym->attr.pointer || sym->attr.allocatable)
! se->expr = build_fold_indirect_ref (var);
else
se->expr = var;
*************** gfc_conv_function_call (gfc_se * se, gfc
*** 1802,1808 ****
else
{
gcc_assert (sym->ts.type == BT_COMPLEX && gfc_option.flag_f2c);
! se->expr = gfc_build_indirect_ref (var);
}
}
}
--- 1802,1808 ----
else
{
gcc_assert (sym->ts.type == BT_COMPLEX && gfc_option.flag_f2c);
! se->expr = build_fold_indirect_ref (var);
}
}
}
*** trans-intrinsic.c (revision 72575)
--- trans-intrinsic.c (local)
*************** gfc_conv_intrinsic_ichar (gfc_se * se, g
*** 2177,2183 ****
arg = build1 (NOP_EXPR, pchar_type_node, arg);
type = gfc_typenode_for_spec (&expr->ts);
! se->expr = gfc_build_indirect_ref (arg);
se->expr = convert (type, se->expr);
}
--- 2177,2183 ----
arg = build1 (NOP_EXPR, pchar_type_node, arg);
type = gfc_typenode_for_spec (&expr->ts);
! se->expr = build_fold_indirect_ref (arg);
se->expr = convert (type, se->expr);
}
*************** gfc_conv_intrinsic_transfer (gfc_se * se
*** 2341,2347 ****
}
else
{
! se->expr = gfc_build_indirect_ref (ptr);
}
}
--- 2341,2347 ----
}
else
{
! se->expr = build_fold_indirect_ref (ptr);
}
}
*** trans-io.c (revision 72575)
--- trans-io.c (local)
*************** nml_get_addr_expr (gfc_symbol * sym, gfc
*** 1164,1170 ****
dummy_arg_flagged = POINTER_TYPE_P (TREE_TYPE(tmp));
! itmp = (dummy_arg_flagged) ? gfc_build_indirect_ref (tmp) : tmp;
/* If an array, set flag and use indirect ref. if built. */
--- 1164,1170 ----
dummy_arg_flagged = POINTER_TYPE_P (TREE_TYPE(tmp));
! itmp = (dummy_arg_flagged) ? build_fold_indirect_ref (tmp) : tmp;
/* If an array, set flag and use indirect ref. if built. */
*************** nml_get_addr_expr (gfc_symbol * sym, gfc
*** 1196,1202 ****
/* If scalar dummy, resolve indirect reference now. */
if (dummy_arg_flagged && !array_flagged)
! tmp = gfc_build_indirect_ref (tmp);
gcc_assert (tmp && POINTER_TYPE_P (TREE_TYPE (tmp)));
--- 1196,1202 ----
/* If scalar dummy, resolve indirect reference now. */
if (dummy_arg_flagged && !array_flagged)
! tmp = build_fold_indirect_ref (tmp);
gcc_assert (tmp && POINTER_TYPE_P (TREE_TYPE (tmp)));
*************** transfer_namelist_element (stmtblock_t *
*** 1322,1328 ****
/* Provide the RECORD_TYPE to build component references. */
! tree expr = gfc_build_indirect_ref (addr_expr);
for (cmp = ts->derived->components; cmp; cmp = cmp->next)
{
--- 1322,1328 ----
/* Provide the RECORD_TYPE to build component references. */
! tree expr = build_fold_indirect_ref (addr_expr);
for (cmp = ts->derived->components; cmp; cmp = cmp->next)
{
*************** transfer_expr (gfc_se * se, gfc_typespec
*** 1692,1698 ****
arg2 = se->string_length;
else
{
! tmp = gfc_build_indirect_ref (addr_expr);
gcc_assert (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE);
arg2 = TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (tmp)));
}
--- 1692,1698 ----
arg2 = se->string_length;
else
{
! tmp = build_fold_indirect_ref (addr_expr);
gcc_assert (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE);
arg2 = TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (tmp)));
}
*************** transfer_expr (gfc_se * se, gfc_typespec
*** 1702,1708 ****
case BT_DERIVED:
/* Recurse into the elements of the derived type. */
expr = gfc_evaluate_now (addr_expr, &se->pre);
! expr = gfc_build_indirect_ref (expr);
for (c = ts->derived->components; c; c = c->next)
{
--- 1702,1708 ----
case BT_DERIVED:
/* Recurse into the elements of the derived type. */
expr = gfc_evaluate_now (addr_expr, &se->pre);
! expr = build_fold_indirect_ref (expr);
for (c = ts->derived->components; c; c = c->next)
{
*** trans-stmt.c (revision 72575)
--- trans-stmt.c (local)
*************** gfc_trans_nested_forall_loop (forall_inf
*** 1471,1477 ****
{
/* If a mask was specified make the assignment conditional. */
if (pmask)
! tmp = gfc_build_indirect_ref (mask);
else
tmp = mask;
tmp = gfc_build_array_ref (tmp, maskindex);
--- 1471,1477 ----
{
/* If a mask was specified make the assignment conditional. */
if (pmask)
! tmp = build_fold_indirect_ref (mask);
else
tmp = mask;
tmp = gfc_build_array_ref (tmp, maskindex);
*************** allocate_temp_for_forall_nest_1 (tree ty
*** 1890,1896 ****
temp1 = gfc_do_allocate (bytesize, size, ptemp1, block, type);
if (*ptemp1)
! tmp = gfc_build_indirect_ref (temp1);
else
tmp = temp1;
--- 1890,1896 ----
temp1 = gfc_do_allocate (bytesize, size, ptemp1, block, type);
if (*ptemp1)
! tmp = build_fold_indirect_ref (temp1);
else
tmp = temp1;
*************** gfc_trans_forall_1 (gfc_code * code, for
*** 2404,2410 ****
se.expr = convert (smallest_boolean_type_node, se.expr);
if (pmask)
! tmp = gfc_build_indirect_ref (mask);
else
tmp = mask;
tmp = gfc_build_array_ref (tmp, maskindex);
--- 2404,2410 ----
se.expr = convert (smallest_boolean_type_node, se.expr);
if (pmask)
! tmp = build_fold_indirect_ref (mask);
else
tmp = mask;
tmp = gfc_build_array_ref (tmp, maskindex);
*** trans.c (revision 72575)
--- trans.c (local)
*************** gfc_build_addr_expr (tree type, tree t)
*** 282,303 ****
}
- /* Build an INDIRECT_REF with its natural type. */
-
- tree
- gfc_build_indirect_ref (tree t)
- {
- tree type = TREE_TYPE (t);
- gcc_assert (POINTER_TYPE_P (type));
- type = TREE_TYPE (type);
-
- if (TREE_CODE (t) == ADDR_EXPR)
- return TREE_OPERAND (t, 0);
- else
- return build1 (INDIRECT_REF, type, t);
- }
-
-
/* Build an ARRAY_REF with its natural type. */
tree
--- 282,287 ----
*** trans.h (revision 72575)
--- trans.h (local)
*************** tree gfc_get_function_decl (gfc_symbol *
*** 348,356 ****
/* Build an ADDR_EXPR. */
tree gfc_build_addr_expr (tree, tree);
- /* Build an INDIRECT_REF. */
- tree gfc_build_indirect_ref (tree);
-
/* Build an ARRAY_REF. */
tree gfc_build_array_ref (tree, tree);
--- 348,353 ----