From patchwork Mon Dec 31 12:17:04 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 208850 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 ACF502C00A6 for ; Mon, 31 Dec 2012 23:17:41 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1357561061; h=Comment: DomainKey-Signature:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=fYNW/CV 2xTUiw/fRzQyZR0qwh2Q=; b=dxOuic5yzcFe2lwTRGJYqrDYgiBZkoyFfIRR6/Y KFCvIj6kp/7hoOiL3X5xUd0k9c4M3igvHrIG3qOQqP7bWmTwxL95uXDk/twyTFeT a65aDGYACU4yUWLCy7WyAzX+Hm/bJ/tNRHr8ljDaOncQLF1u5non3pJhnQ8OCkcY q230= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=kZwT+aPvVc7InpYfBsK/a7TUIQXmTftO6R4MCWSxvoarjPCHTdGQWMyUnnfeX9 8H7y2orpETMYV+vBEKW0Y+VxhIAXF4NzuuH2wP1tvFwwznMdh9MSFTqg53CxN2us JFLTpH3fk7wfa3lmAdpy4UI8SD/RrLQfA+Og2JrEMMVlU=; Received: (qmail 30488 invoked by alias); 31 Dec 2012 12:17:16 -0000 Received: (qmail 30434 invoked by uid 22791); 31 Dec 2012 12:17:09 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mx01.qsc.de (HELO mx01.qsc.de) (213.148.129.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 31 Dec 2012 12:17:05 +0000 Received: from archimedes.net-b.de (port-92-195-100-21.dynamic.qsc.de [92.195.100.21]) by mx01.qsc.de (Postfix) with ESMTP id 5882D3CAE1; Mon, 31 Dec 2012 13:17:04 +0100 (CET) Message-ID: <50E18240.8040806@net-b.de> Date: Mon, 31 Dec 2012 13:17:04 +0100 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Patch, Fortran] FINAL (prep patches 2/5): Add internal STRIDE intrinsic 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 The attached patch adds a new - internal only - intrinsic, STRIDE, which returns the stride of an array with array descriptor; for an "integer :: array(5,5)", the stride of dim=2 is 5. This new intrinsic is only internally available and will be used by the finalization wrapper to handle noncontiguous arrays. Build on x86-64-gnu-linux. OK for the trunk? Tobias 2012-12-31 Tobias Burnus * intrinsic.c (add_functions): New internal intrinsic function GFC_PREFIX ("stride"). * gfortran.h (gfc_isym_id): Add GFC_ISYM_STRIDE. * intrinsic.h (gfc_resolve_stride): New prototypes. * iresolve.c (gfc_resolve_stride): New function. * trans-intrinsic.c (conv_intrinsic_stride): New static function. (gfc_conv_intrinsic_function): Use it. diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index a419af3..027cab6 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -521,6 +521,7 @@ enum gfc_isym_id GFC_ISYM_SR_KIND, GFC_ISYM_STAT, GFC_ISYM_STORAGE_SIZE, + GFC_ISYM_STRIDE, GFC_ISYM_SUM, GFC_ISYM_SYMLINK, GFC_ISYM_SYMLNK, diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c index 274c921..8328b9b 100644 --- a/gcc/fortran/intrinsic.c +++ b/gcc/fortran/intrinsic.c @@ -2640,6 +2640,14 @@ add_functions (void) make_generic ("size", GFC_ISYM_SIZE, GFC_STD_F95); + /* Obtain the stride for a given dimensions; to be used only internally. + "make_from_module" makes inaccessible for external users. */ + add_sym_2 (GFC_PREFIX ("stride"), GFC_ISYM_STRIDE, CLASS_INQUIRY, ACTUAL_NO, + BT_INTEGER, gfc_index_integer_kind, GFC_STD_GNU, + NULL, NULL, gfc_resolve_stride, + ar, BT_REAL, dr, REQUIRED, dm, BT_INTEGER, ii, OPTIONAL); + make_from_module(); + add_sym_1 ("sizeof", GFC_ISYM_SIZEOF, CLASS_IMPURE, ACTUAL_NO, BT_INTEGER, ii, GFC_STD_GNU, gfc_check_sizeof, NULL, NULL, x, BT_UNKNOWN, 0, REQUIRED); diff --git a/gcc/fortran/intrinsic.h b/gcc/fortran/intrinsic.h index 2635ba6..4540ad8 100644 --- a/gcc/fortran/intrinsic.h +++ b/gcc/fortran/intrinsic.h @@ -546,6 +546,7 @@ void gfc_resolve_signal (gfc_expr *, gfc_expr *, gfc_expr *); void gfc_resolve_sin (gfc_expr *, gfc_expr *); void gfc_resolve_sinh (gfc_expr *, gfc_expr *); void gfc_resolve_size (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *); +void gfc_resolve_stride (gfc_expr *, gfc_expr *, gfc_expr *); void gfc_resolve_spacing (gfc_expr *, gfc_expr *); void gfc_resolve_spread (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *); void gfc_resolve_sqrt (gfc_expr *, gfc_expr *); diff --git a/gcc/fortran/iresolve.c b/gcc/fortran/iresolve.c index 3f981d8..c884fc1 100644 --- a/gcc/fortran/iresolve.c +++ b/gcc/fortran/iresolve.c @@ -2314,6 +2314,15 @@ gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED, void +gfc_resolve_stride (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED, + gfc_expr *dim ATTRIBUTE_UNUSED) +{ + f->ts.type = BT_INTEGER; + f->ts.kind = gfc_index_integer_kind; +} + + +void gfc_resolve_spacing (gfc_expr *f, gfc_expr *x) { f->ts = x->ts; diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c index 5a89be1..e0b5f11 100644 --- a/gcc/fortran/trans-intrinsic.c +++ b/gcc/fortran/trans-intrinsic.c @@ -1657,6 +1657,35 @@ conv_intrinsic_cobound (gfc_se * se, gfc_expr * expr) static void +conv_intrinsic_stride (gfc_se * se, gfc_expr * expr) +{ + gfc_actual_arglist *array_arg; + gfc_actual_arglist *dim_arg; + gfc_se argse; + tree desc, tmp; + + array_arg = expr->value.function.actual; + dim_arg = array_arg->next; + + gcc_assert (array_arg->expr->expr_type == EXPR_VARIABLE); + + gfc_init_se (&argse, NULL); + gfc_conv_expr_descriptor (&argse, array_arg->expr); + gfc_add_block_to_block (&se->pre, &argse.pre); + gfc_add_block_to_block (&se->post, &argse.post); + desc = argse.expr; + + gcc_assert (dim_arg->expr); + gfc_init_se (&argse, NULL); + gfc_conv_expr_type (&argse, dim_arg->expr, gfc_array_index_type); + gfc_add_block_to_block (&se->pre, &argse.pre); + tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type, + argse.expr, gfc_index_one_node); + se->expr = gfc_conv_descriptor_stride_get (desc, tmp); +} + + +static void gfc_conv_intrinsic_abs (gfc_se * se, gfc_expr * expr) { tree arg, cabs; @@ -6806,6 +6835,10 @@ gfc_conv_intrinsic_function (gfc_se * se, gfc_expr * expr) gfc_conv_intrinsic_spacing (se, expr); break; + case GFC_ISYM_STRIDE: + conv_intrinsic_stride (se, expr); + break; + case GFC_ISYM_SUM: gfc_conv_intrinsic_arith (se, expr, PLUS_EXPR, false); break;