Commit 114e4d10 by Roger Sayle Committed by Roger Sayle

trans-array.c (gfc_conv_expr_descriptor): We don't need to use a temporary array…

trans-array.c (gfc_conv_expr_descriptor): We don't need to use a temporary array to pass a constant non-character array...


	* trans-array.c (gfc_conv_expr_descriptor): We don't need to use
	a temporary array to pass a constant non-character array constructor.
	Generalize the descriptor generation code to handle scalarizer
	"info" without an array reference.

From-SVN: r121491
parent d4f8b567
2007-02-01 Roger Sayle <roger@eyesopen.com> 2007-02-01 Roger Sayle <roger@eyesopen.com>
* trans-array.c (gfc_conv_expr_descriptor): We don't need to use
a temporary array to pass a constant non-character array constructor.
Generalize the descriptor generation code to handle scalarizer
"info" without an array reference.
2007-02-01 Roger Sayle <roger@eyesopen.com>
* dependency.c (gfc_check_dependency) <EXPR_ARRAY>: Implement * dependency.c (gfc_check_dependency) <EXPR_ARRAY>: Implement
dependency checking for array constructors. dependency checking for array constructors.
......
/* Array translation routines /* Array translation routines
Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
Inc. Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org> Contributed by Paul Brook <paul@nowt.org>
and Steven Bosscher <s.bosscher@student.tudelft.nl> and Steven Bosscher <s.bosscher@student.tudelft.nl>
...@@ -4306,7 +4306,6 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss) ...@@ -4306,7 +4306,6 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss)
gcc_assert (ss != gfc_ss_terminator); gcc_assert (ss != gfc_ss_terminator);
/* TODO: Pass constant array constructors without a temporary. */
/* Special case things we know we can pass easily. */ /* Special case things we know we can pass easily. */
switch (expr->expr_type) switch (expr->expr_type)
{ {
...@@ -4402,6 +4401,24 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss) ...@@ -4402,6 +4401,24 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss)
} }
break; break;
case EXPR_ARRAY:
/* Constant array constructors don't need a temporary. */
if (ss->type == GFC_SS_CONSTRUCTOR
&& expr->ts.type != BT_CHARACTER
&& gfc_constant_array_constructor_p (expr->value.constructor))
{
need_tmp = 0;
info = &ss->data.info;
secss = ss;
}
else
{
need_tmp = 1;
secss = NULL;
info = NULL;
}
break;
default: default:
/* Something complicated. Copy it into a temporary. */ /* Something complicated. Copy it into a temporary. */
need_tmp = 1; need_tmp = 1;
...@@ -4553,7 +4570,7 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss) ...@@ -4553,7 +4570,7 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss)
limits will be the limits of the section. limits will be the limits of the section.
A function may decide to repack the array to speed up access, but A function may decide to repack the array to speed up access, but
we're not bothered about that here. */ we're not bothered about that here. */
int dim; int dim, ndim;
tree parm; tree parm;
tree parmtype; tree parmtype;
tree stride; tree stride;
...@@ -4603,12 +4620,14 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss) ...@@ -4603,12 +4620,14 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss)
else else
base = NULL_TREE; base = NULL_TREE;
for (n = 0; n < info->ref->u.ar.dimen; n++) ndim = info->ref ? info->ref->u.ar.dimen : info->dimen;
for (n = 0; n < ndim; n++)
{ {
stride = gfc_conv_array_stride (desc, n); stride = gfc_conv_array_stride (desc, n);
/* Work out the offset. */ /* Work out the offset. */
if (info->ref->u.ar.dimen_type[n] == DIMEN_ELEMENT) if (info->ref
&& info->ref->u.ar.dimen_type[n] == DIMEN_ELEMENT)
{ {
gcc_assert (info->subscript[n] gcc_assert (info->subscript[n]
&& info->subscript[n]->type == GFC_SS_SCALAR); && info->subscript[n]->type == GFC_SS_SCALAR);
...@@ -4630,13 +4649,15 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss) ...@@ -4630,13 +4649,15 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss)
tmp = fold_build2 (MULT_EXPR, TREE_TYPE (tmp), tmp, stride); tmp = fold_build2 (MULT_EXPR, TREE_TYPE (tmp), tmp, stride);
offset = fold_build2 (PLUS_EXPR, TREE_TYPE (tmp), offset, tmp); offset = fold_build2 (PLUS_EXPR, TREE_TYPE (tmp), offset, tmp);
if (info->ref->u.ar.dimen_type[n] == DIMEN_ELEMENT) if (info->ref
&& info->ref->u.ar.dimen_type[n] == DIMEN_ELEMENT)
{ {
/* For elemental dimensions, we only need the offset. */ /* For elemental dimensions, we only need the offset. */
continue; continue;
} }
/* Vector subscripts need copying and are handled elsewhere. */ /* Vector subscripts need copying and are handled elsewhere. */
if (info->ref)
gcc_assert (info->ref->u.ar.dimen_type[n] == DIMEN_RANGE); gcc_assert (info->ref->u.ar.dimen_type[n] == DIMEN_RANGE);
/* Set the new lower bound. */ /* Set the new lower bound. */
...@@ -4646,7 +4667,9 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss) ...@@ -4646,7 +4667,9 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss)
/* If we have an array section or are assigning to a pointer, /* If we have an array section or are assigning to a pointer,
make sure that the lower bound is 1. References to the full make sure that the lower bound is 1. References to the full
array should otherwise keep the original bounds. */ array should otherwise keep the original bounds. */
if ((info->ref->u.ar.type != AR_FULL || se->direct_byref) if ((!info->ref
|| info->ref->u.ar.type != AR_FULL
|| se->direct_byref)
&& !integer_onep (from)) && !integer_onep (from))
{ {
tmp = fold_build2 (MINUS_EXPR, gfc_array_index_type, tmp = fold_build2 (MINUS_EXPR, gfc_array_index_type,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment