* [patch, fortran] Put front-end temporaries into BLOCKs
@ 2011-04-23 20:12 Thomas Koenig
2011-04-26 1:23 ` Thomas Koenig
2011-04-26 4:58 ` Jerry DeLisle
0 siblings, 2 replies; 4+ messages in thread
From: Thomas Koenig @ 2011-04-23 20:12 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 880 bytes --]
Hello world,
the attached patch puts temporary variables, and the statement they are
being generated for, in their own BLOCK.
This may or may not be useful for data locality, and for telling the
middle end explicitly about the lifetime of the temporary variables. It
is intended as a step towards eliminating redundant calls to
array-valued functions whose bounds are unknown at compile time, such as
the original test case for PR 22572.
No test case, as this should not change anything.
Regression-tested. OK for trunk?
Thomas
2011-04-23 Thomas Koenig <tkoenig@gcc.gnu.org>
* frontend-passes.c (inserted_block): New variable.
(changed_statement): Likewise.
(create_var): Encase statement to be operated on in a BLOCK.
Adjust code insertion for BLOCK.
(cfe_code): Set inserted_block and changed_statement to NULL.
[-- Attachment #2: temp-block-1.diff --]
[-- Type: text/x-patch, Size: 2750 bytes --]
Index: frontend-passes.c
===================================================================
--- frontend-passes.c (Revision 172856)
+++ frontend-passes.c (Arbeitskopie)
@@ -48,10 +48,15 @@ static gfc_expr ***expr_array;
static int expr_size, expr_count;
/* Pointer to the gfc_code we currently work on - to be able to insert
- a statement before. */
+ a block before the statement. */
static gfc_code **current_code;
+/* Pointer to the block to be inserted, and the statement we are
+ changing within the block. */
+
+static gfc_code *inserted_block, **changed_statement;
+
/* The namespace we are currently dealing with. */
gfc_namespace *current_ns;
@@ -203,7 +208,9 @@ cfe_register_funcs (gfc_expr **e, int *walk_subtre
/* Returns a new expression (a variable) to be used in place of the old one,
with an an assignment statement before the current statement to set
- the value of the variable. */
+ the value of the variable. Creates a new BLOCK for the statement if
+ that hasn't already been done and puts the statement, plus the
+ newly created variables, in that block. */
static gfc_expr*
create_var (gfc_expr * e)
@@ -214,10 +221,31 @@ create_var (gfc_expr * e)
gfc_symbol *symbol;
gfc_expr *result;
gfc_code *n;
+ gfc_namespace *ns;
int i;
+ /* If the block hasn't already been created, do so. */
+ if (inserted_block == NULL)
+ {
+ inserted_block = XCNEW (gfc_code);
+ inserted_block->op = EXEC_BLOCK;
+ inserted_block->loc = (*current_code)->loc;
+ ns = gfc_build_block_ns (current_ns);
+ inserted_block->ext.block.ns = ns;
+ inserted_block->ext.block.assoc = NULL;
+
+ ns->code = *current_code;
+ inserted_block->next = (*current_code)->next;
+ changed_statement = &(inserted_block->ext.block.ns->code);
+ (*current_code)->next = NULL;
+ /* Insert the BLOCK at the right position. */
+ *current_code = inserted_block;
+ }
+ else
+ ns = inserted_block->ext.block.ns;
+
sprintf(name, "__var_%d",num++);
- if (gfc_get_sym_tree (name, current_ns, &symtree, false) != 0)
+ if (gfc_get_sym_tree (name, ns, &symtree, false) != 0)
gcc_unreachable ();
symbol = symtree->n.sym;
@@ -267,10 +295,10 @@ create_var (gfc_expr * e)
n = XCNEW (gfc_code);
n->op = EXEC_ASSIGN;
n->loc = (*current_code)->loc;
- n->next = *current_code;
+ n->next = *changed_statement;
n->expr1 = gfc_copy_expr (result);
n->expr2 = e;
- *current_code = n;
+ *changed_statement = n;
return result;
}
@@ -347,6 +375,8 @@ cfe_code (gfc_code **c, int *walk_subtrees ATTRIBU
void *data ATTRIBUTE_UNUSED)
{
current_code = c;
+ inserted_block = NULL;
+ changed_statement = NULL;
return 0;
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch, fortran] Put front-end temporaries into BLOCKs
2011-04-23 20:12 [patch, fortran] Put front-end temporaries into BLOCKs Thomas Koenig
@ 2011-04-26 1:23 ` Thomas Koenig
2011-04-26 4:58 ` Jerry DeLisle
1 sibling, 0 replies; 4+ messages in thread
From: Thomas Koenig @ 2011-04-26 1:23 UTC (permalink / raw)
To: fortran, gcc-patches
Am 23.04.2011 17:22, schrieb Thomas Koenig:
> Hello world,
>
> the attached patch puts temporary variables, and the statement they are
> being generated for, in their own BLOCK.
>
> This may or may not be useful for data locality, and for telling the
> middle end explicitly about the lifetime of the temporary variables. It
> is intended as a step towards eliminating redundant calls to
> array-valued functions whose bounds are unknown at compile time, such as
> the original test case for PR 22572.
>
> No test case, as this should not change anything.
>
> Regression-tested. OK for trunk?
>
Ping ** 0.25?
Thomas
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch, fortran] Put front-end temporaries into BLOCKs
2011-04-23 20:12 [patch, fortran] Put front-end temporaries into BLOCKs Thomas Koenig
2011-04-26 1:23 ` Thomas Koenig
@ 2011-04-26 4:58 ` Jerry DeLisle
2011-04-26 21:14 ` Thomas Koenig
1 sibling, 1 reply; 4+ messages in thread
From: Jerry DeLisle @ 2011-04-26 4:58 UTC (permalink / raw)
To: Thomas Koenig; +Cc: fortran, gcc-patches
On 04/23/2011 08:22 AM, Thomas Koenig wrote:
> Hello world,
>
> the attached patch puts temporary variables, and the statement they are being
> generated for, in their own BLOCK.
>
> This may or may not be useful for data locality, and for telling the middle end
> explicitly about the lifetime of the temporary variables. It is intended as a
> step towards eliminating redundant calls to array-valued functions whose bounds
> are unknown at compile time, such as the original test case for PR 22572.
>
> No test case, as this should not change anything.
>
> Regression-tested. OK for trunk?
OK and thanks for patch.
Jerry
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch, fortran] Put front-end temporaries into BLOCKs
2011-04-26 4:58 ` Jerry DeLisle
@ 2011-04-26 21:14 ` Thomas Koenig
0 siblings, 0 replies; 4+ messages in thread
From: Thomas Koenig @ 2011-04-26 21:14 UTC (permalink / raw)
To: Jerry DeLisle; +Cc: fortran, gcc-patches
Hi Jerry,
>
> OK and thanks for patch.
Waiting for Emacs...
Sende ChangeLog
Sende frontend-passes.c
Ãbertrage Daten ..
Revision 172983 ÃŒbertragen.
Thanks for the review!
Thomas
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-04-26 18:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-23 20:12 [patch, fortran] Put front-end temporaries into BLOCKs Thomas Koenig
2011-04-26 1:23 ` Thomas Koenig
2011-04-26 4:58 ` Jerry DeLisle
2011-04-26 21:14 ` Thomas Koenig
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).