From patchwork Thu Nov 14 20:29:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1195211 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-513498-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="V3A8MP+k"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="a94CBw0o"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="a94CBw0o"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47DY4S6Kqfz9s7T for ; Fri, 15 Nov 2019 07:29:42 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:content-type:mime-version; q=dns; s=default; b=e5nmfqplzANTWgaKzG+IoVaKtLBN6jPqzwJ2LV7fztObI6I6Sq f7+MIKRKY9IaUOMmJLhLJ0zWE98ETdlU8bSzpeps8FiYycUgFj2dVOOPwj0u+dDo 2zAgR+u7XmGYkRJ/EJGVYN2wbhbbhNWvk4As7ZM6xq7VlwRofMGO2qMak= 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:from :to:cc:subject:date:message-id:content-type:mime-version; s= default; bh=TSnKXHgRUFJszVQgCT37Y761GLU=; b=V3A8MP+kKWmq2QT+1R4W 8tb2l3Rk62Usl/K7ZIdbHQ38Mayvae0e1/r9VbcjgWhMF7H8yIyzb+ad2wZqOv2C NtuTv1e9dUq60mykZt+KdmDlQxdX/IxoQSW6H4dyROt8LMJDPcWoD618BFxaLiy/ jbEIfyHf75SHjKLBoIrCYpo= Received: (qmail 64375 invoked by alias); 14 Nov 2019 20:29:31 -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 64356 invoked by uid 89); 14 Nov 2019 20:29:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.4 required=5.0 tests=AWL, BAYES_00, FORGED_SPF_HELO, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=3200 X-HELO: EUR04-DB3-obe.outbound.protection.outlook.com Received: from mail-eopbgr60053.outbound.protection.outlook.com (HELO EUR04-DB3-obe.outbound.protection.outlook.com) (40.107.6.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 14 Nov 2019 20:29:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JcyC/j/PrvNiIFWnuOeRvj50v33r2l+Nym8PTGXAb+s=; b=a94CBw0oNcjziVx7iHp6PfdGhL4/rI+CujPeOM+SXeUL4I8USM5EyHZ+A+ffuWykUKSA6cgHDS540OQ3Ht3bYstShXTV3C/ls3UINMiHLX3cIctJHSKGUH2uVLrT/jj/eZSPBXyPbxnul7jDVLczPF65ZMbY6VQEm+76YkREmSQ= Received: from AM6PR08CA0043.eurprd08.prod.outlook.com (2603:10a6:20b:c0::31) by DB6PR0802MB2167.eurprd08.prod.outlook.com (2603:10a6:4:83::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2430.25; Thu, 14 Nov 2019 20:29:24 +0000 Received: from DB5EUR03FT035.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e0a::204) by AM6PR08CA0043.outlook.office365.com (2603:10a6:20b:c0::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2451.23 via Frontend Transport; Thu, 14 Nov 2019 20:29:24 +0000 Authentication-Results: spf=fail (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; gcc.gnu.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; gcc.gnu.org; dmarc=none action=none header.from=arm.com; Received-SPF: Fail (protection.outlook.com: domain of arm.com does not designate 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT035.mail.protection.outlook.com (10.152.20.65) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2451.23 via Frontend Transport; Thu, 14 Nov 2019 20:29:24 +0000 Received: ("Tessian outbound 0cf06bf5c60e:v33"); Thu, 14 Nov 2019 20:29:24 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 2b7e5544c782853b X-CR-MTA-TID: 64aa7808 Received: from 74b73bd7b029.1 (cr-mta-lb-1.cr-mta-net [104.47.10.50]) by 64aa7808-outbound-1.mta.getcheckrecipient.com id 4D50DA87-65D1-4CD4-BDD6-1012334CA809.1; Thu, 14 Nov 2019 20:29:19 +0000 Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-db5eur03lp2050.outbound.protection.outlook.com [104.47.10.50]) by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 74b73bd7b029.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 14 Nov 2019 20:29:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IAbLBxj/7UE/YevmwYxOmtjdexhy1vs7mupFIdyWJ0ABT5JkADW850lbb0iYg6IZ3OaABbj7jMCPsvOoEFIxHG+zI5k5wYLZ0YQ5Vb/Xi4hTXFgt1KTikcYBPirxSEZfkPmZ7n5vfRqlQxiqq3eOCaPnCsMIxbsmQb0Y0RsZqZn4jZjIhEF2tRd7mf4TMVzqr4PN2O7+MFnxD3wt+97quPOJ3azYHTgPOjE68Rse0ZHZTv5iJhLOFOXSHwH9r95RVIGlCwbC/D4S9F8do73VNhSr4amOkyxskP7umNjEvnB2RIMD66Ujj77m0Fk1CxtT/9dECKBlU0BemmCNFhgeAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JcyC/j/PrvNiIFWnuOeRvj50v33r2l+Nym8PTGXAb+s=; b=i1q2yB9PjlcWHEve+8UKmxdMHwq1GF9gpIHUaKDWBNEL80UE2RnJc9Cxy3l/Rt1ehaRbDcJj/+IwO5Ob+VfWoxfx1WOa5WzQE13EYJI9xv+2CV36Bca4wAFjJjDYgwZCK4Pj7Z/w8Ts2S75f4Pswuuo9r7b3HJi50mztjnS9UT7XI9ybK9rcK6juX1vw7Xm3LQ2QAz3te3mbspvt2BA9UZZBdpp7iVQEXuQvnj1gJg+XWGLykAmlkPf7MH1bxik/gq0tIIzlUJMdK2QPfo0g1E/GCo3cAScVOfKtsYEpPwEehDawcijui/b/QOPun4yAaiOrSq1VMjWBcoPBC/0jvA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JcyC/j/PrvNiIFWnuOeRvj50v33r2l+Nym8PTGXAb+s=; b=a94CBw0oNcjziVx7iHp6PfdGhL4/rI+CujPeOM+SXeUL4I8USM5EyHZ+A+ffuWykUKSA6cgHDS540OQ3Ht3bYstShXTV3C/ls3UINMiHLX3cIctJHSKGUH2uVLrT/jj/eZSPBXyPbxnul7jDVLczPF65ZMbY6VQEm+76YkREmSQ= Received: from DB7PR08MB3292.eurprd08.prod.outlook.com (52.134.111.30) by DB7PR08MB3833.eurprd08.prod.outlook.com (20.178.46.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2451.22; Thu, 14 Nov 2019 20:29:18 +0000 Received: from DB7PR08MB3292.eurprd08.prod.outlook.com ([fe80::21ec:f698:b78e:d4b8]) by DB7PR08MB3292.eurprd08.prod.outlook.com ([fe80::21ec:f698:b78e:d4b8%7]) with mapi id 15.20.2451.024; Thu, 14 Nov 2019 20:29:18 +0000 From: Szabolcs Nagy To: GCC Patches , Fortran List , Jakub Jelinek , Joseph Myers CC: nd Subject: [PATCH, fortran] Extend the builtin directive Date: Thu, 14 Nov 2019 20:29:17 +0000 Message-ID: user-agent: Mozilla/5.0 (X11; Linux aarch64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=Szabolcs.Nagy@arm.com; x-checkrecipientrouted: true x-ms-oob-tlc-oobclassifiers: OLM:8882;OLM:8882; X-Forefront-Antispam-Report-Untrusted: SFV:NSPM; SFS:(10009020)(4636009)(39860400002)(376002)(346002)(396003)(366004)(136003)(54534003)(199004)(189003)(52116002)(6306002)(36756003)(99286004)(478600001)(966005)(66066001)(26005)(25786009)(65806001)(65956001)(386003)(14454004)(6506007)(256004)(4001150100001)(14444005)(81156014)(5660300002)(81166006)(6116002)(3846002)(31696002)(186003)(102836004)(8676002)(44832011)(486006)(8936002)(71200400001)(71190400001)(2906002)(2616005)(476003)(66946007)(66476007)(66556008)(64756008)(66446008)(66616009)(86362001)(31686004)(110136005)(6436002)(58126008)(6486002)(7736002)(316002)(305945005)(6512007)(4326008); DIR:OUT; SFP:1101; SCL:1; SRVR:DB7PR08MB3833; H:DB7PR08MB3292.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: sPahOhtvqLTMWrM3sYpurmpY0XAkdnJUdiM8ce/hjuXtibv8QN5gi4xd+iqbHAkV3YU/0bb2PKVMHFjV7Mr6eZDz5oDvnFjj1hzufku89b4cwjP5A/vipRh7ekp8na6Uw+68Ft9pi9rgU7k6mSzd9h3bCk0ynk/VN3hKxFC7/6ZNjiMaoauHeqAIrc/t9o2DbyKk/uRcIyq5/Xu6yb4ho56XUzPmATz+wIhCHRGS/opbGBapYCn0kUwH3wScnvZssodwXd96VIRfeSaRG6u2TjoOYXaTE0iexRwh9hJppONpjm6XnWBMMXlKkwuY2ATOrJ/N/U1ATyJ9LW27lQFXJzc+sud3/vdcPNGMRlkRAZkOJpx3ig6sFo6AvZPpXDiZd/jBcuFq7Ku4RhGm2f9ii2xRH6TT3fXrvwrPWbgEpM9TX7eykhTmyB9CBWm4Qrc0 x-ms-exchange-transport-forked: True MIME-Version: 1.0 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Szabolcs.Nagy@arm.com; X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT035.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 032aaadd-0781-41fe-95b5-08d7694152c6 X-MS-Exchange-PUrlCount: 1 X-IsSubscribed: yes The builtin directive allows specifying the simd attribute for a builtin function. Similarly how the C language simd attribtue got extended to allow declaring a specific vector variant, update the fortran builtin directive too. Before the patch, only the masking (inbranch/notinbranch) could be specified, when declaring the availability of vector variants, e.g.: !GCC$ builtin (expf) attributes simd (notinbranch) if('x86_64') now the simdlen and simdabi (aka ISA) can be specified too, and a different name may be used instead of the vector ABI name, e.g.: !GCC$ builtin (expf) attributes simd (notinbranch, 4, 'b', 'vexpf') if('x86_64') Tested on aarch64-linux-gnu. The C language change is at https://gcc.gnu.org/ml/gcc-patches/2019-11/msg01288.html Note: I don't have much fortran experience, so i'm not sure if the syntax makes sense or if i modified the frontend reasonably. 2019-11-14 Szabolcs Nagy * gfortran.h (struct gfc_vect_builtin): Define. * decl.c (gfc_match_gcc_builtin): Parse new flags. * trans-intrinsic.c (add_simd_flag_for_built_in): Update. (gfc_adjust_builtins): Update. gcc/testsuite/ChangeLog: 2019-11-14 Szabolcs Nagy * gfortran.dg/simd-builtins-9.f90: New test. * gfortran.dg/simd-builtins-9.h: New test. * gfortran.dg/simd-builtins-10.f90: New test. * gfortran.dg/simd-builtins-10.h: New test. diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 7858973cc20..dab8a323148 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -105,7 +105,7 @@ bool directive_vector = false; bool directive_novector = false; /* Map of middle-end built-ins that should be vectorized. */ -hash_map *gfc_vectorized_builtins; +hash_map *gfc_vectorized_builtins; /* If a kind expression of a component of a parameterized derived type is parameterized, temporarily store the expression here. */ @@ -11600,9 +11600,13 @@ gfc_match_gcc_unroll (void) /* Match a !GCC$ builtin (b) attributes simd flags if('target') form: The parameter b is name of a middle-end built-in. - FLAGS is optional and must be one of: - - (inbranch) - - (notinbranch) + FLAGS is optional and must be of the form: + (mask) + (mask, simdlen) + (mask, simdlen, 'simdabi') + (mask, simdlen, 'simdabi', 'name') + where mask is inbranch or notinbranch, simdlen is an integer, simdabi + and name are strings. IF('target') is optional and TARGET is a name of a multilib ABI. @@ -11613,15 +11617,44 @@ gfc_match_gcc_builtin (void) { char builtin[GFC_MAX_SYMBOL_LEN + 1]; char target[GFC_MAX_SYMBOL_LEN + 1]; + char simdabi[GFC_MAX_SYMBOL_LEN + 1] = ""; + char name[GFC_MAX_SYMBOL_LEN + 1] = ""; + bool inbranch; + bool flags = false; + int simdlen = 0; if (gfc_match (" ( %n ) attributes simd", builtin) != MATCH_YES) return MATCH_ERROR; - gfc_simd_clause clause = SIMD_NONE; - if (gfc_match (" ( notinbranch ) ") == MATCH_YES) - clause = SIMD_NOTINBRANCH; - else if (gfc_match (" ( inbranch ) ") == MATCH_YES) - clause = SIMD_INBRANCH; + if (gfc_match (" ( ") == MATCH_YES) + { + flags = true; + if (gfc_match ("notinbranch") == MATCH_YES) + inbranch = false; + else if (gfc_match ("inbranch") == MATCH_YES) + inbranch = true; + else + { +syntax_error: + gfc_error ("Syntax error in !GCC$ BUILTIN directive at %C"); + return MATCH_ERROR; + } + + if (gfc_match (" , ") == MATCH_YES) + if (gfc_match_small_int (&simdlen) != MATCH_YES || simdlen < 0) + goto syntax_error; + + if (gfc_match (" , ") == MATCH_YES) + if (gfc_match (" '%n'", &simdabi) != MATCH_YES) + goto syntax_error; + + if (gfc_match (" , ") == MATCH_YES) + if (gfc_match (" '%n'", &name) != MATCH_YES) + goto syntax_error; + + if (gfc_match (" ) ") != MATCH_YES) + goto syntax_error; + } if (gfc_match (" if ( '%n' ) ", target) == MATCH_YES) { @@ -11631,16 +11664,27 @@ gfc_match_gcc_builtin (void) } if (gfc_vectorized_builtins == NULL) - gfc_vectorized_builtins = new hash_map (); + gfc_vectorized_builtins = + new hash_map (); char *r = XNEWVEC (char, strlen (builtin) + 32); sprintf (r, "__builtin_%s", builtin); bool existed; - int &value = gfc_vectorized_builtins->get_or_insert (r, &existed); - value |= clause; + gfc_vect_builtin *v = &gfc_vectorized_builtins->get_or_insert (r, &existed); if (existed) - free (r); + { + free (r); + gfc_vect_builtin *next = v->next; + v->next = new gfc_vect_builtin; + v = v->next; + v->next = next; + } + v->flags = flags; + v->inbranch = inbranch; + v->simdlen = simdlen; + v->simdabi = simdabi[0] ? xstrdup (simdabi) : 0; + v->name = name[0] ? xstrdup (name) : 0; return MATCH_YES; } diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 920acdafc6b..56becb207b2 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -2812,26 +2812,18 @@ extern bool directive_ivdep; extern bool directive_vector; extern bool directive_novector; -/* SIMD clause enum. */ -enum gfc_simd_clause -{ - SIMD_NONE = (1 << 0), - SIMD_INBRANCH = (1 << 1), - SIMD_NOTINBRANCH = (1 << 2) -}; - -/* Tuple for parsing of vectorized built-ins. */ -struct gfc_vect_builtin_tuple -{ - gfc_vect_builtin_tuple (const char *n, gfc_simd_clause t) - : name (n), simd_type (t) {} - - const char *name; - gfc_simd_clause simd_type; +struct gfc_vect_builtin +{ + gfc_vect_builtin *next; + char *name; + char *simdabi; + bool flags; + bool inbranch; + unsigned int simdlen; }; /* Map of middle-end built-ins that should be vectorized. */ -extern hash_map *gfc_vectorized_builtins; +extern hash_map *gfc_vectorized_builtins; /* Handling Parameterized Derived Types */ bool gfc_insert_kind_parameter_exprs (gfc_expr *); diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi index a34ac5aa1bf..05d3a93cb94 100644 --- a/gcc/fortran/gfortran.texi +++ b/gcc/fortran/gfortran.texi @@ -3671,12 +3671,25 @@ The syntax of the directive is You can use this directive to define which middle-end built-ins provide vector implementations. @code{B} is name of the middle-end built-in. @code{FLAGS} -are optional and must be either "(inbranch)" or "(notinbranch)". +are optional and must follow one of the forms +@itemize +@item @code{(mask)} +@item @code{(mask, simdlen)} +@item @code{(mask, simdlen, 'simdabi')} +@item @code{(mask, simdlen, 'simdabi', 'name')} +@end itemize +where @code{mask} is either inbranch or notinbranch, simdlen is a non-negative +integer, simdabi is a target specific ISA selector and name is the symbol +name of the vector function (when not specified the name is generated according +to the target Vector ABI document, the name is only valid to specify if the +directive specifies a single vector funtion variant). + @code{IF} statement is optional and is used to filter multilib ABIs for the built-in that should be vectorized. Example usage: @smallexample !GCC$ builtin (sinf) attributes simd (notinbranch) if('x86_64') +!GCC$ builtin (cosf) attributes simd (notinbranch, 4, 'b') if('x86_64') @end smallexample The purpose of the directive is to provide an API among the GCC compiler and diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c index c2e0533393a..d2ef3c43892 100644 --- a/gcc/fortran/trans-intrinsic.c +++ b/gcc/fortran/trans-intrinsic.c @@ -608,29 +608,45 @@ add_simd_flag_for_built_in (tree fndecl) return; const char *name = IDENTIFIER_POINTER (DECL_NAME (fndecl)); - int *clauses = gfc_vectorized_builtins->get (name); - if (clauses) + gfc_vect_builtin *v = gfc_vectorized_builtins->get (name); + for (; v != NULL; v = v->next) { - for (unsigned i = 0; i < 3; i++) - if (*clauses & (1 << i)) - { - gfc_simd_clause simd_type = (gfc_simd_clause)*clauses; - tree omp_clause = NULL_TREE; - if (simd_type == SIMD_NONE) - ; /* No SIMD clause. */ - else - { - omp_clause_code code - = (simd_type == SIMD_INBRANCH - ? OMP_CLAUSE_INBRANCH : OMP_CLAUSE_NOTINBRANCH); - omp_clause = build_omp_clause (UNKNOWN_LOCATION, code); - omp_clause = build_tree_list (NULL_TREE, omp_clause); - } - - DECL_ATTRIBUTES (fndecl) - = tree_cons (get_identifier ("omp declare simd"), omp_clause, - DECL_ATTRIBUTES (fndecl)); - } + tree t = NULL_TREE; + if (v->flags) + { + omp_clause_code code + = (v->inbranch ? OMP_CLAUSE_INBRANCH : OMP_CLAUSE_NOTINBRANCH); + tree c = build_omp_clause (UNKNOWN_LOCATION, code); + t = c; + if (v->simdlen != 0) + { + c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE_SIMDLEN); + OMP_CLAUSE_SIMDLEN_EXPR (c) + = build_int_cst (integer_type_node, v->simdlen); + OMP_CLAUSE_CHAIN (c) = t; + t = c; + } + if (v->simdabi != NULL) + { + c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__SIMDABI_); + OMP_CLAUSE__SIMDABI__EXPR (c) + = build_string (strlen (v->simdabi) + 1, v->simdabi); + OMP_CLAUSE_CHAIN (c) = t; + t = c; + } + if (v->name != NULL) + { + c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__SIMDNAME_); + OMP_CLAUSE__SIMDNAME__EXPR (c) + = build_string (strlen (v->name) + 1, v->name); + OMP_CLAUSE_CHAIN (c) = t; + t = c; + } + t = build_tree_list (NULL_TREE, t); + } + DECL_ATTRIBUTES (fndecl) + = tree_cons (get_identifier ("omp declare simd"), t, + DECL_ATTRIBUTES (fndecl)); } } @@ -659,10 +675,24 @@ gfc_adjust_builtins (void) /* Release all strings. */ if (gfc_vectorized_builtins != NULL) { - for (hash_map::iterator it + for (hash_map::iterator it = gfc_vectorized_builtins->begin (); it != gfc_vectorized_builtins->end (); ++it) - free (CONST_CAST (char *, (*it).first)); + { + free (CONST_CAST (char *, (*it).first)); + gfc_vect_builtin *v = &(*it).second; + free (v->name); + free (v->simdabi); + v = v->next; + while (v) + { + gfc_vect_builtin *next = v->next; + free (v->name); + free (v->simdabi); + delete v; + v = next; + } + } delete gfc_vectorized_builtins; gfc_vectorized_builtins = NULL; diff --git a/gcc/testsuite/gfortran.dg/simd-builtins-10.f90 b/gcc/testsuite/gfortran.dg/simd-builtins-10.f90 new file mode 100644 index 00000000000..59ae7bf0c18 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/simd-builtins-10.f90 @@ -0,0 +1,18 @@ +! { dg-do compile { target { aarch64*-*-linux* x86_64-*-* i?86-*-* } } } +! { dg-additional-options "-nostdinc -Ofast -fpre-include=simd-builtins-10.h -fdump-tree-optimized" } + +program test_overloaded_intrinsic + real(4) :: x4(3200), y4(3200) + real(8) :: x8(3200), y8(3200) + + y4 = sin(x4) + print *, y4 + + y8 = sin(x8) + print *, y8 +end + +! { dg-final { scan-tree-dump "sinf.simdclone" "optimized" } } */ +! { dg-final { scan-tree-dump-not "sin.simdclone" "optimized" } } */ + +! { dg-final { scan-assembler "vec_sinf" } } */ diff --git a/gcc/testsuite/gfortran.dg/simd-builtins-10.h b/gcc/testsuite/gfortran.dg/simd-builtins-10.h new file mode 100644 index 00000000000..0936b134cb0 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/simd-builtins-10.h @@ -0,0 +1,6 @@ +!GCC$ builtin (sinf) attributes simd (notinbranch, 4, 'n', 'vec_sinf') if('aarch64') +!GCC$ builtin (sinf) attributes simd (notinbranch, 4, 'n', 'vec_sinf') if('aarch64_be') +!GCC$ builtin (sinf) attributes simd (notinbranch, 4, 'n', 'vec_sinf') if('aarch64_ilp32') +!GCC$ builtin (sinf) attributes simd (notinbranch, 4, 'n', 'vec_sinf') if('aarch64_be_ilp32') +!GCC$ builtin (sinf) attributes simd (notinbranch, 4, 'b', 'vec_sinf') if('x64_64') +!GCC$ builtin (sinf) attributes simd (notinbranch, 4, 'b', 'vec_sinf') if('i386') diff --git a/gcc/testsuite/gfortran.dg/simd-builtins-9.f90 b/gcc/testsuite/gfortran.dg/simd-builtins-9.f90 new file mode 100644 index 00000000000..0ffae5b14d0 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/simd-builtins-9.f90 @@ -0,0 +1,19 @@ +! { dg-do compile { target { aarch64*-*-linux* } } } +! { dg-additional-options "-nostdinc -Ofast -fpre-include=simd-builtins-9.h -fdump-tree-optimized" } + +program test_overloaded_intrinsic + real(4) :: x4(3200), y4(3200) + real(8) :: x8(3200), y8(3200) + + y4 = sin(x4) + print *, y4 + + y8 = sin(x8) + print *, y8 +end + +! { dg-final { scan-tree-dump "sinf.simdclone" "optimized" { target ilp32 } } } */ +! { dg-final { scan-tree-dump-not "sin.simdclone" "optimized" { target ilp32 } } } */ + +! { dg-final { scan-tree-dump "sin.simdclone" "optimized" { target lp64 } } } */ +! { dg-final { scan-tree-dump-not "sinf.simdclone" "optimized" { target lp64 } } } */ diff --git a/gcc/testsuite/gfortran.dg/simd-builtins-9.h b/gcc/testsuite/gfortran.dg/simd-builtins-9.h new file mode 100644 index 00000000000..1f50834d869 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/simd-builtins-9.h @@ -0,0 +1,4 @@ +!GCC$ builtin (sin) attributes simd (notinbranch, 2, 'n') if('aarch64') +!GCC$ builtin (sin) attributes simd (notinbranch, 2, 'n') if('aarch64_be') +!GCC$ builtin (sinf) attributes simd (notinbranch, 4, 'n') if('aarch64_ilp32') +!GCC$ builtin (sinf) attributes simd (notinbranch, 4, 'n') if('aarch64_be_ilp32')