From patchwork Sat Apr 23 15:22:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 92623 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 8373FB6F19 for ; Sun, 24 Apr 2011 01:23:20 +1000 (EST) Received: (qmail 14387 invoked by alias); 23 Apr 2011 15:23:17 -0000 Received: (qmail 14374 invoked by uid 22791); 23 Apr 2011 15:23:16 -0000 X-SWARE-Spam-Status: No, hits=-0.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cc-smtpout3.netcologne.de (HELO cc-smtpout3.netcologne.de) (89.1.8.213) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 23 Apr 2011 15:23:00 +0000 Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout3.netcologne.de (Postfix) with ESMTP id 49D531285F; Sat, 23 Apr 2011 17:22:58 +0200 (CEST) Received: from [192.168.0.197] (xdsl-78-35-160-65.netcologne.de [78.35.160.65]) by cc-smtpin2.netcologne.de (Postfix) with ESMTPSA id 2B26011E9B; Sat, 23 Apr 2011 17:22:56 +0200 (CEST) Message-ID: <4DB2EED0.8050708@netcologne.de> Date: Sat, 23 Apr 2011 17:22:56 +0200 From: Thomas Koenig User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.14) Gecko/20110221 SUSE/3.1.8 Thunderbird/3.1.8 MIME-Version: 1.0 To: "fortran@gcc.gnu.org" , gcc-patches Subject: [patch, fortran] Put front-end temporaries into BLOCKs Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 * 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. 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; }