From patchwork Mon Apr 15 19:33:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 236708 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id DE6DC2C00DB for ; Tue, 16 Apr 2013 05:33:54 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=QZsG2l9g5QrhjJzVB a/yMUqxUqvIfFAB9+RfB4Nu64sHxdDQl5hyf7PZmDpMQtyorHcpNPuaFurIw4wzy TkkFtbraszauMv+KX6g3xeu4cIsXdlEuCLU+YkjM5X9Za1xl1yeOZHjlSpG93Hrh zrORALNVC8yDuSnAv4FjXD7os0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=/scT0YfzbywCb6WJYtTcL6O Nu54=; b=Ktd6oJyxCB0Xx7tBTgICF/JeHhleqjzJtth8saCz3xfKxdp+sYcd+tf bfEsxy/kIiqKIyRIyy6m/m1hZkj4t1u62yBt4qRAms8CyOduEthEdq67vHf4ovj4 vqRMqHXT/b+szXTbU+9U75FaaSIfMQa40ktvLE5U/cYbK2VKTcJc= Received: (qmail 30699 invoked by alias); 15 Apr 2013 19:33:47 -0000 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 Received: (qmail 30681 invoked by uid 89); 15 Apr 2013 19:33:47 -0000 X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, KAM_STOCKGEN, KHOP_THREADED, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, TW_FC autolearn=no version=3.3.1 X-Spam-User: qpsmtpd, 2 recipients Received: from smtp23.services.sfr.fr (HELO smtp23.services.sfr.fr) (93.17.128.19) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 15 Apr 2013 19:33:45 +0000 Received: from filter.sfr.fr (localhost [127.0.0.1]) by msfrf2321.sfr.fr (SMTP Server) with ESMTP id 8BDB97000050; Mon, 15 Apr 2013 21:33:43 +0200 (CEST) Received: from [192.168.1.58] (53.183.72.86.rev.sfr.net [86.72.183.53]) by msfrf2321.sfr.fr (SMTP Server) with ESMTP id 4FB0D7000047; Mon, 15 Apr 2013 21:33:42 +0200 (CEST) X-SFR-UUID: 20130415193342326.4FB0D7000047@msfrf2321.sfr.fr Message-ID: <516C5615.8010007@sfr.fr> Date: Mon, 15 Apr 2013 21:33:41 +0200 From: Mikael Morin User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130412 Thunderbird/17.0.5 MIME-Version: 1.0 To: Thomas Koenig CC: "fortran@gcc.gnu.org" , gcc-patches Subject: Re: [patch, fortran] Really fix PR 56782 References: <516A7D6C.7000801@netcologne.de> <516AB9D0.3050308@sfr.fr> <516ABB54.4090309@netcologne.de> In-Reply-To: <516ABB54.4090309@netcologne.de> X-Virus-Found: No Le 14/04/2013 16:21, Thomas Koenig a écrit : > Hi Mikael, > >>> >>> - (void) gfc_expr_walker (&fcn, callback_reduction, NULL); >> >> why remove this? > > Because it is not needed, as the test case _46 shows. No need > to run this twice, it doesn't get better :-) > Indeed, that's right. > gfc_internal_error ("Illegal id in insert_iterator_function"); >> >> This duplicated code could probably be merged with >> copy_walk_reduction_arg. > > I thought about it. The reason why I didn't do it was > because the expr to be wrapped inside the call is different. Hum, how different? > I think callback_reduction's iterator handling >> should happen there as well. > > Like I said, it is done automatically by the expression > walker. > I don't really understand. Attached is what I had in mind. And a testcase (the '|| expr->expr_type == EXPR_FUNCTION' in copy_walk_reduction_arg appeared wrong to me, and it was seemingly). Mikael diff --git a/frontend-passes.c b/frontend-passes.c index 9749314..cf63318 100644 --- a/frontend-passes.c +++ b/frontend-passes.c @@ -192,37 +192,49 @@ optimize_expr (gfc_expr **e, int *walk_subtrees ATTRIBUTE_UNUSED, old one can be freed. */ static gfc_expr * -copy_walk_reduction_arg (gfc_expr *e, gfc_expr *fn) +copy_walk_reduction_arg (gfc_constructor *c, gfc_expr *fn) { - gfc_expr *fcn; - gfc_isym_id id; + gfc_expr *fcn, *e = c->expr; - if (e->rank == 0 || e->expr_type == EXPR_FUNCTION) - fcn = gfc_copy_expr (e); - else + fcn = gfc_copy_expr (e); + if (c->iterator) + { + gfc_constructor_base newbase; + gfc_expr *new_expr; + gfc_constructor *new_c; + + newbase = NULL; + new_expr = gfc_get_expr (); + new_expr->expr_type = EXPR_ARRAY; + new_expr->ts = e->ts; + new_expr->where = e->where; + new_expr->rank = 1; + new_c = gfc_constructor_append_expr (&newbase, fcn, &(e->where)); + new_c->iterator = c->iterator; + new_expr->value.constructor = newbase; + c->iterator = NULL; + + fcn = new_expr; + } + + if (fcn->rank != 0) { - id = fn->value.function.isym->id; + gfc_isym_id id = fn->value.function.isym->id; if (id == GFC_ISYM_SUM || id == GFC_ISYM_PRODUCT) - fcn = gfc_build_intrinsic_call (current_ns, - fn->value.function.isym->id, + fcn = gfc_build_intrinsic_call (current_ns, id, fn->value.function.isym->name, - fn->where, 3, gfc_copy_expr (e), - NULL, NULL); + fn->where, 3, fcn, NULL, NULL); else if (id == GFC_ISYM_ANY || id == GFC_ISYM_ALL) - fcn = gfc_build_intrinsic_call (current_ns, - fn->value.function.isym->id, + fcn = gfc_build_intrinsic_call (current_ns, id, fn->value.function.isym->name, - fn->where, 2, gfc_copy_expr (e), - NULL); + fn->where, 2, fcn, NULL); else gfc_internal_error ("Illegal id in copy_walk_reduction_arg"); fcn->symtree->n.sym->attr.access = ACCESS_PRIVATE; } - (void) gfc_expr_walker (&fcn, callback_reduction, NULL); - return fcn; } @@ -305,10 +317,10 @@ callback_reduction (gfc_expr **e, int *walk_subtrees ATTRIBUTE_UNUSED, - only have a single element in the array which contains an iterator. */ - if (c == NULL || (c->iterator != NULL && gfc_constructor_next (c) == NULL)) + if (c == NULL) return 0; - res = copy_walk_reduction_arg (c->expr, fn); + res = copy_walk_reduction_arg (c, fn); c = gfc_constructor_next (c); while (c) @@ -320,7 +332,7 @@ callback_reduction (gfc_expr **e, int *walk_subtrees ATTRIBUTE_UNUSED, new_expr->where = fn->where; new_expr->value.op.op = op; new_expr->value.op.op1 = res; - new_expr->value.op.op2 = copy_walk_reduction_arg (c->expr, fn); + new_expr->value.op.op2 = copy_walk_reduction_arg (c, fn); res = new_expr; c = gfc_constructor_next (c); }