From: Mikael Morin <mikael.morin@sfr.fr>
To: gfortran <fortran@gcc.gnu.org> , GCC patches <gcc-patches@gcc.gnu.org>
Subject: [Patch, fortran] [40..43/66] inline sum and product: Update the scalarizer: New gfc_ss::parent field.
Date: Thu, 27 Oct 2011 23:36:00 -0000 [thread overview]
Message-ID: <20111027233220.18581.6976@gimli.local> (raw)
In-Reply-To: <20111027233144.18581.30688@gimli.local>
[-- Attachment #1: Type: text/plain, Size: 322 bytes --]
We are going to loop over the parent array infos.
This introduces a new parent field to permit this loop (patch 40).
Then it will be used to loop over multiple parent ss:
- gfc_set_loop_bounds_from_array_spec (patch 41 with context diff)
- gfc_trans_array_constructor (patch 42)
- set_vector_loop_bounds (patch 43)
OK?
[-- Attachment #2: pr43829-40.CL --]
[-- Type: text/plain, Size: 264 bytes --]
2011-10-19 Mikael Morin <mikael@gcc.gnu.org>
* trans.h (struct gfc_ss): New field parent.
* trans-array.c (gfc_trans_scalarizing_loops): Skip clearing if a
parent exists.
* trans-expr.c (gfc_advance_se_ss_chain): Move to parent ss at the
end of the chain.
[-- Attachment #3: pr43829-40.patch --]
[-- Type: text/x-diff, Size: 1629 bytes --]
diff --git a/trans-array.c b/trans-array.c
index d386a22..abff8b5 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -3193,7 +3193,8 @@ gfc_trans_scalarizing_loops (gfc_loopinfo * loop, stmtblock_t * body)
/* Clear all the used flags. */
for (ss = loop->ss; ss != gfc_ss_terminator; ss = ss->loop_chain)
- ss->info->useflags = 0;
+ if (ss->parent == NULL)
+ ss->info->useflags = 0;
}
diff --git a/trans-expr.c b/trans-expr.c
index e091c89..72d35f8 100644
--- a/trans-expr.c
+++ b/trans-expr.c
@@ -83,6 +83,7 @@ void
gfc_advance_se_ss_chain (gfc_se * se)
{
gfc_se *p;
+ gfc_ss *ss;
gcc_assert (se != NULL && se->ss != NULL && se->ss != gfc_ss_terminator);
@@ -93,7 +94,15 @@ gfc_advance_se_ss_chain (gfc_se * se)
/* Simple consistency check. */
gcc_assert (p->parent == NULL || p->parent->ss == p->ss);
- p->ss = p->ss->next;
+ /* If we were in a nested loop, the next scalarized expression can be
+ on the parent ss' next pointer. Thus we should not take the next
+ pointer blindly, but rather go up one nest level as long as next
+ is the end of chain. */
+ ss = p->ss;
+ while (ss->next == gfc_ss_terminator && ss->parent != NULL)
+ ss = ss->parent;
+
+ p->ss = ss->next;
p = p->parent;
}
diff --git a/trans.h b/trans.h
index 62bcc64..53c5ce2 100644
--- a/trans.h
+++ b/trans.h
@@ -246,6 +246,9 @@ typedef struct gfc_ss
struct gfc_ss *loop_chain;
struct gfc_ss *next;
+ /* Non-null if the ss is part of a nested loop. */
+ struct gfc_ss *parent;
+
/* The loop this gfc_ss is in. */
struct gfc_loopinfo *loop;
[-- Attachment #4: pr43829-41.CL --]
[-- Type: text/plain, Size: 128 bytes --]
2011-10-19 Mikael Morin <mikael@gcc.gnu.org>
* trans-array.c (gfc_set_loop_bounds_from_array_spec): Loop over the
parents.
[-- Attachment #5: pr43829-41.patch --]
[-- Type: text/x-diff, Size: 2797 bytes --]
diff --git a/trans-array.c b/trans-array.c
index abff8b5..83542f6 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -688,41 +688,54 @@ void
gfc_set_loop_bounds_from_array_spec (gfc_interface_mapping * mapping,
gfc_se * se, gfc_array_spec * as)
{
- int n, dim;
+ int n, dim, total_dim;
gfc_se tmpse;
+ gfc_ss *ss;
tree lower;
tree upper;
tree tmp;
- if (as && as->type == AS_EXPLICIT)
- for (n = 0; n < se->loop->dimen; n++)
- {
- dim = se->ss->dim[n];
- gcc_assert (dim < as->rank);
- gcc_assert (se->loop->dimen == as->rank);
- if (se->loop->to[n] == NULL_TREE)
- {
- /* Evaluate the lower bound. */
- gfc_init_se (&tmpse, NULL);
- gfc_apply_interface_mapping (mapping, &tmpse, as->lower[dim]);
- gfc_add_block_to_block (&se->pre, &tmpse.pre);
- gfc_add_block_to_block (&se->post, &tmpse.post);
- lower = fold_convert (gfc_array_index_type, tmpse.expr);
-
- /* ...and the upper bound. */
- gfc_init_se (&tmpse, NULL);
- gfc_apply_interface_mapping (mapping, &tmpse, as->upper[dim]);
- gfc_add_block_to_block (&se->pre, &tmpse.pre);
- gfc_add_block_to_block (&se->post, &tmpse.post);
- upper = fold_convert (gfc_array_index_type, tmpse.expr);
-
- /* Set the upper bound of the loop to UPPER - LOWER. */
- tmp = fold_build2_loc (input_location, MINUS_EXPR,
- gfc_array_index_type, upper, lower);
- tmp = gfc_evaluate_now (tmp, &se->pre);
- se->loop->to[n] = tmp;
- }
- }
+ total_dim = 0;
+
+ if (!as || as->type != AS_EXPLICIT)
+ return;
+
+ for (ss = se->ss; ss; ss = ss->parent)
+ {
+ total_dim += ss->loop->dimen;
+ for (n = 0; n < ss->loop->dimen; n++)
+ {
+ /* The bound is known, nothing to do. */
+ if (ss->loop->to[n] != NULL_TREE)
+ continue;
+
+ dim = ss->dim[n];
+ gcc_assert (dim < as->rank);
+ gcc_assert (ss->loop->dimen <= as->rank);
+
+ /* Evaluate the lower bound. */
+ gfc_init_se (&tmpse, NULL);
+ gfc_apply_interface_mapping (mapping, &tmpse, as->lower[dim]);
+ gfc_add_block_to_block (&se->pre, &tmpse.pre);
+ gfc_add_block_to_block (&se->post, &tmpse.post);
+ lower = fold_convert (gfc_array_index_type, tmpse.expr);
+
+ /* ...and the upper bound. */
+ gfc_init_se (&tmpse, NULL);
+ gfc_apply_interface_mapping (mapping, &tmpse, as->upper[dim]);
+ gfc_add_block_to_block (&se->pre, &tmpse.pre);
+ gfc_add_block_to_block (&se->post, &tmpse.post);
+ upper = fold_convert (gfc_array_index_type, tmpse.expr);
+
+ /* Set the upper bound of the loop to UPPER - LOWER. */
+ tmp = fold_build2_loc (input_location, MINUS_EXPR,
+ gfc_array_index_type, upper, lower);
+ tmp = gfc_evaluate_now (tmp, &se->pre);
+ ss->loop->to[n] = tmp;
+ }
+ }
+
+ gcc_assert (total_dim == as->rank);
}
[-- Attachment #6: pr43829-41.diff --]
[-- Type: text/x-diff, Size: 2162 bytes --]
diff --git a/trans-array.c b/trans-array.c
index abff8b5dc732457e5f31957c3728c51340354688..83542f668111b5e43261782ef91bcb2377bfdd46 100644
*** a/trans-array.c
--- b/trans-array.c
*************** void
*** 688,707 ****
gfc_set_loop_bounds_from_array_spec (gfc_interface_mapping * mapping,
gfc_se * se, gfc_array_spec * as)
{
! int n, dim;
gfc_se tmpse;
tree lower;
tree upper;
tree tmp;
! if (as && as->type == AS_EXPLICIT)
! for (n = 0; n < se->loop->dimen; n++)
{
! dim = se->ss->dim[n];
! gcc_assert (dim < as->rank);
! gcc_assert (se->loop->dimen == as->rank);
! if (se->loop->to[n] == NULL_TREE)
{
/* Evaluate the lower bound. */
gfc_init_se (&tmpse, NULL);
gfc_apply_interface_mapping (mapping, &tmpse, as->lower[dim]);
--- 688,718 ----
gfc_set_loop_bounds_from_array_spec (gfc_interface_mapping * mapping,
gfc_se * se, gfc_array_spec * as)
{
! int n, dim, total_dim;
gfc_se tmpse;
+ gfc_ss *ss;
tree lower;
tree upper;
tree tmp;
! total_dim = 0;
!
! if (!as || as->type != AS_EXPLICIT)
! return;
!
! for (ss = se->ss; ss; ss = ss->parent)
{
! total_dim += ss->loop->dimen;
! for (n = 0; n < ss->loop->dimen; n++)
{
+ /* The bound is known, nothing to do. */
+ if (ss->loop->to[n] != NULL_TREE)
+ continue;
+
+ dim = ss->dim[n];
+ gcc_assert (dim < as->rank);
+ gcc_assert (ss->loop->dimen <= as->rank);
+
/* Evaluate the lower bound. */
gfc_init_se (&tmpse, NULL);
gfc_apply_interface_mapping (mapping, &tmpse, as->lower[dim]);
*************** gfc_set_loop_bounds_from_array_spec (gfc
*** 720,728 ****
tmp = fold_build2_loc (input_location, MINUS_EXPR,
gfc_array_index_type, upper, lower);
tmp = gfc_evaluate_now (tmp, &se->pre);
! se->loop->to[n] = tmp;
}
}
}
--- 731,741 ----
tmp = fold_build2_loc (input_location, MINUS_EXPR,
gfc_array_index_type, upper, lower);
tmp = gfc_evaluate_now (tmp, &se->pre);
! ss->loop->to[n] = tmp;
}
}
+
+ gcc_assert (total_dim == as->rank);
}
[-- Attachment #7: pr43829-42.CL --]
[-- Type: text/plain, Size: 119 bytes --]
2011-10-19 Mikael Morin <mikael@gcc.gnu.org>
* trans-array.c (gfc_trans_array_constructor): Loop over the parents.
[-- Attachment #8: pr43829-42.patch --]
[-- Type: text/x-diff, Size: 1660 bytes --]
diff --git a/trans-array.c b/trans-array.c
index 83542f6..463a0a2 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -1953,6 +1953,7 @@ trans_constant_array_constructor (gfc_ss * ss, tree type)
}
}
+
/* Helper routine of gfc_trans_array_constructor to determine if the
bounds of the loop specified by LOOP are constant and simple enough
to use with trans_constant_array_constructor. Returns the
@@ -2010,6 +2011,7 @@ trans_array_constructor (gfc_ss * ss, locus * where)
gfc_loopinfo *loop;
gfc_ss_info *ss_info;
gfc_expr *expr;
+ gfc_ss *s;
/* Save the old values for nested checking. */
old_first_len = first_len;
@@ -2078,16 +2080,20 @@ trans_array_constructor (gfc_ss * ss, locus * where)
if (expr->shape && loop->dimen > 1 && loop->to[0] == NULL_TREE)
{
/* We have a multidimensional parameter. */
- int n;
- for (n = 0; n < expr->rank; n++)
- {
- loop->from[n] = gfc_index_zero_node;
- loop->to[n] = gfc_conv_mpz_to_tree (expr->shape [n],
- gfc_index_integer_kind);
- loop->to[n] = fold_build2_loc (input_location, MINUS_EXPR,
- gfc_array_index_type,
- loop->to[n], gfc_index_one_node);
- }
+ for (s = ss; s; s = s->parent)
+ {
+ int n;
+ for (n = 0; n < s->loop->dimen; n++)
+ {
+ s->loop->from[n] = gfc_index_zero_node;
+ s->loop->to[n] = gfc_conv_mpz_to_tree (expr->shape[s->dim[n]],
+ gfc_index_integer_kind);
+ s->loop->to[n] = fold_build2_loc (input_location, MINUS_EXPR,
+ gfc_array_index_type,
+ s->loop->to[n],
+ gfc_index_one_node);
+ }
+ }
}
if (loop->to[0] == NULL_TREE)
[-- Attachment #9: pr43829-43.CL --]
[-- Type: text/plain, Size: 118 bytes --]
2011-10-19 Mikael Morin <mikael@gcc.gnu.org>
* trans-array.c (gfc_set_vector_loop_bounds): Loop over the parents.
[-- Attachment #10: pr43829-43.patch --]
[-- Type: text/x-diff, Size: 829 bytes --]
diff --git a/trans-array.c b/trans-array.c
index 463a0a2..25d9a37 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -2197,14 +2197,18 @@ set_vector_loop_bounds (gfc_ss * ss)
int dim;
info = &ss->info->data.array;
- loop = ss->loop;
- for (n = 0; n < loop->dimen; n++)
+ for (; ss; ss = ss->parent)
{
- dim = ss->dim[n];
- if (info->ref->u.ar.dimen_type[dim] == DIMEN_VECTOR
- && loop->to[n] == NULL)
+ loop = ss->loop;
+
+ for (n = 0; n < loop->dimen; n++)
{
+ dim = ss->dim[n];
+ if (info->ref->u.ar.dimen_type[dim] != DIMEN_VECTOR
+ || loop->to[n] != NULL)
+ continue;
+
/* Loop variable N indexes vector dimension DIM, and we don't
yet know the upper bound of loop variable N. Set it to the
difference between the vector's upper and lower bounds. */
next prev parent reply other threads:[~2011-10-27 23:34 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-27 23:43 [Patch, fortran] [00/66] PR fortran/43829 Inline sum and product (AKA scalarization of reductions) Mikael Morin
2011-10-27 23:32 ` [Patch, fortran] [20..30/66] inline sum and product: Update core structs Mikael Morin
2011-10-27 23:32 ` [Patch, fortran] [25/66] inline sum and product: Update core structs: Move string_length Mikael Morin
2011-10-27 23:32 ` [Patch, fortran] [29/66] inline sum and product: Update core structs: Move useflags flag Mikael Morin
2011-10-27 23:32 ` [Patch, fortran] [20/66] inline sum and product: Update core structs: Rename gfc_ss_info Mikael Morin
2011-10-27 23:33 ` [Patch, fortran] [23/66] inline sum and product: Update core structs: Move type Mikael Morin
2011-10-27 23:33 ` [Patch, fortran] [22/66] inline sum and product: Update core structs: Move shape Mikael Morin
2011-10-27 23:33 ` [Patch, fortran] [26/66] inline sum and product: Update core structs: Move scalar struct Mikael Morin
2011-10-27 23:34 ` [Patch, fortran] [27/66] inline sum and product: Update core structs: Move temp struct Mikael Morin
2011-10-27 23:35 ` [Patch, fortran] [21/66] inline sum and product: Update core structs: Move dim and dimen Mikael Morin
2011-10-27 23:35 ` [Patch, fortran] [30/66] inline sum and product: Update core structs: Move where flag Mikael Morin
2011-10-27 23:35 ` [Patch, fortran] [24/66] inline sum and product: Update core structs: Move expr Mikael Morin
2011-10-27 23:43 ` [Patch, fortran] [28/66] inline sum and product: Update core structs: Move info struct Mikael Morin
2011-10-27 23:35 ` [Patch, fortran] [31..53/66] inline sum and product: Update the scalarizer Mikael Morin
2011-10-27 23:34 ` [Patch, fortran] [32/66] inline sum and product: Update the scalarizer: clear specloop in gfc_trans_create_temp_arrays Mikael Morin
2011-10-27 23:34 ` [Patch, fortran] [31/66] inline sum and product: Update the scalarizer: Split gfc_conv_loop_setup Mikael Morin
2011-10-27 23:35 ` [Patch, fortran] [44/66] inline sum and product: Update the scalarizer: New gfc_ss::nested_ss field Mikael Morin
2011-10-27 23:35 ` [Patch, fortran] [47..48/66] inline sum and product: Update the scalarizer: New gfc_loopinfo::nested_loop field Mikael Morin
2011-10-27 23:35 ` [Patch, fortran] [33/66] inline sum and product: Update the scalarizer Mikael Morin
2011-10-27 23:35 ` [Patch, fortran] [45/66] inline sum and product: Update the scalarizer: Update dimension mapping inversion functions Mikael Morin
2011-10-27 23:36 ` [Patch, fortran] [49..51/66] inline sum and product: Update the scalarizer: New parent loop Mikael Morin
2011-10-27 23:36 ` [Patch, fortran] [53/66] inline sum and product: Update the scalarizer: Update gfc_trans_preloop_setup Mikael Morin
2011-10-27 23:36 ` [Patch, fortran] [52/66] inline sum and product: Update the scalarizer: New outermost_loop function Mikael Morin
2011-10-27 23:36 ` Mikael Morin [this message]
2011-10-27 23:36 ` [Patch, fortran] [46/66] inline sum and product: Update the scalarizer: Update gfc_trans_create_temp_array Mikael Morin
2011-10-27 23:36 ` [Patch, fortran] [34/66] inline sum and product: Update the scalarizer: gfc_ss_info refcounting Mikael Morin
2011-10-27 23:36 ` [Patch, fortran] [35..39/66] inline sum and product: Update the scalarizer: New gfc_ss::loop field Mikael Morin
2011-10-27 23:35 ` [Patch, fortran] [07..12/66] inline sum and product: Preliminary cleanups Mikael Morin
2011-10-27 23:31 ` [Patch, fortran] [10/66] inline sum and product: Preliminary cleanups: Use array's instead of loop's dimensions Mikael Morin
2011-10-27 23:31 ` [Patch, fortran] [07/66] inline sum and product: Preliminary cleanups: Useless coarray code removal Mikael Morin
2011-10-27 23:32 ` [Patch, fortran] [12/66] inline sum and product: Preliminary cleanups: Stop loop before end marker Mikael Morin
2011-10-27 23:32 ` [Patch, fortran] [08/66] inline sum and product: Preliminary cleanups: Remove redundant condition Mikael Morin
2011-10-27 23:36 ` [Patch, fortran] [11/66] inline sum and product: Preliminary cleanups: Skip temporary case Mikael Morin
2011-10-27 23:36 ` [Patch, fortran] [09/66] inline sum and product: Preliminary cleanups: Assertify condition Mikael Morin
2011-10-27 23:36 ` [Patch, fortran] [01..06/66] inline sum and product: Prepare gfc_trans_preloop_setup Mikael Morin
2011-10-27 23:30 ` [Patch, fortran] [06/66] " Mikael Morin
2011-10-30 9:52 ` Paul Richard Thomas
2011-10-30 21:57 ` Mikael Morin
2011-10-27 23:30 ` [Patch, fortran] [01/66] " Mikael Morin
2011-10-27 23:31 ` [Patch, fortran] [03/66] " Mikael Morin
2011-10-27 23:36 ` [Patch, fortran] [02/66] " Mikael Morin
2011-10-27 23:36 ` [Patch, fortran] [05/66] " Mikael Morin
2011-10-27 23:38 ` [Patch, fortran] [04/66] " Mikael Morin
2011-10-27 23:36 ` [Patch, fortran] [62..66/66] inline sum and product: Inline sum Mikael Morin
2011-10-27 23:36 ` [Patch, fortran] [64/66] inline sum and product: Inline sum: Change loop use Mikael Morin
2011-10-27 23:36 ` [Patch, fortran] [66/66] inline sum and product: Inline sum: The end Mikael Morin
2011-10-27 23:36 ` [Patch, fortran] [65/66] inline sum and product: Inline sum: Change se initialization Mikael Morin
2011-10-27 23:36 ` [Patch, fortran] [63/66] inline sum and product: Inline sum: Change argument handling Mikael Morin
2011-10-28 0:29 ` [Patch, fortran] [62/66] inline sum and product: Inline sum: Change conditions Mikael Morin
2011-10-28 0:02 ` [Patch, fortran] [13..19/66] inline sum and product: Interfaces changes Mikael Morin
2011-10-27 23:31 ` [Patch, fortran] [14/66] inline sum and product: Interfaces changes: gfc_trans_array_bound_check, gfc_conv_array_index_offset Mikael Morin
2011-10-27 23:32 ` [Patch, fortran] [15/66] inline sum and product: Interfaces changes: obtain name more simply Mikael Morin
2011-10-27 23:32 ` [Patch, fortran] [17/66] inline sum and product: Interfaces changes: gfc_set_vector_loop_bounds Mikael Morin
2011-10-27 23:36 ` [Patch, fortran] [13/66] inline sum and product: Interfaces changes: gfc_trans_array_constructor Mikael Morin
2011-10-27 23:36 ` [Patch, fortran] [16/66] inline sum and product: Interfaces changes: gfc_trans_create_temp_array Mikael Morin
2011-10-27 23:43 ` [Patch, fortran] [18/66] inline sum and product: Interfaces changes: get_array_ref_dim Mikael Morin
2011-10-27 23:44 ` [Patch, fortran] [19/66] inline sum and product: Interfaces changes: dim_ok Mikael Morin
2011-10-28 0:22 ` [Patch, fortran] [54..61/66] inline sum and product: Prevent regressions Mikael Morin
2011-10-27 23:36 ` [Patch, fortran] [60/66] inline sum and product: Update the scalarizer: Fix error markers Mikael Morin
2011-10-27 23:36 ` [Patch, fortran] [57..59/66] inline sum and product: Prevent regressions: Fix {min, max}{loc, val} Mikael Morin
2011-10-27 23:36 ` [Patch, fortran] [55..56/66] inline sum and product: Prevent regressions: Fix gfc_conv_elemental_dependencies Mikael Morin
2011-10-27 23:43 ` [Patch, fortran] [54/66] inline sum and product: Prevent regressions: Add dependency checking Mikael Morin
2011-10-28 0:01 ` [Patch, fortran] [61/66] inline sum and product: Prevent regressions: Disable frontend optimizations Mikael Morin
2011-10-28 14:35 ` [Patch, fortran] [00/66] PR fortran/43829 Inline sum and product (AKA scalarization of reductions) Jack Howarth
2011-10-28 17:25 ` Mikael Morin
2011-10-29 16:04 ` [Patch, fortran] [00/66] PR fortran/43829 Inline sum and?product " Jack Howarth
2011-11-01 21:33 ` [Patch, fortran] [00/66] PR fortran/43829 Inline sum and product " Paul Richard Thomas
2011-11-04 3:51 ` Mikael Morin
2011-11-04 9:39 ` Richard Guenther
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111027233220.18581.6976@gimli.local \
--to=mikael.morin@sfr.fr \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).