From patchwork Wed Jun 28 18:28:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Meissner X-Patchwork-Id: 781826 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wyWWz4rDdz9s65 for ; Thu, 29 Jun 2017 04:28:46 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="KMlJx5Sg"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:mime-version:content-type:message-id; q=dns; s= default; b=qjyUprslxPmdS6xSTqM1icSQQ2BT1UTjzQZcFY05Dg2zAqaIIvXQz crUx4Yn9XbzO+SWsP/r60HIF4X0xJ0Ge/ZC280ZSHkf0RIRLT7Cio3x/i8i0DHaF QAMOkBTnWUcRTySHq/+FpdBykjnPBHfCr1Pl9Z1BZvNoNkZd5nlues= 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:date :from:to:subject:mime-version:content-type:message-id; s= default; bh=eGd1l/Yy7sPDajV6hX0ScKLfLtY=; b=KMlJx5SgBrhhyBKd9Yrv pBF5VZmFgIFGOlIwgSL+cwyu1urwAl2xOqBHyFqKFiP/NLHuUWoq37KiKdzB5hwt ZlYZXBEC5XXNu4/6mYxcN5l3iieMzBBX2k8LEz8pyGTNUubUwkuCmknZ0ibuEVZ0 8ianoKNVpki+ZhPzHb7moHA= Received: (qmail 94616 invoked by alias); 28 Jun 2017 18:28:35 -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 94587 invoked by uid 89); 28 Jun 2017 18:28:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-9.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy= X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 28 Jun 2017 18:28:30 +0000 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v5SINsO2122573 for ; Wed, 28 Jun 2017 14:28:28 -0400 Received: from e14.ny.us.ibm.com (e14.ny.us.ibm.com [129.33.205.204]) by mx0a-001b2d01.pphosted.com with ESMTP id 2bcdc9dukg-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 28 Jun 2017 14:28:28 -0400 Received: from localhost by e14.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 28 Jun 2017 14:28:27 -0400 Received: from b01cxnp23034.gho.pok.ibm.com (9.57.198.29) by e14.ny.us.ibm.com (146.89.104.201) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 28 Jun 2017 14:28:24 -0400 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v5SISOTP26345552; Wed, 28 Jun 2017 18:28:24 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 52B68112047; Wed, 28 Jun 2017 14:28:26 -0400 (EDT) Received: from ibm-tiger.the-meissners.org (unknown [9.32.77.111]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP id 358F9112040; Wed, 28 Jun 2017 14:28:26 -0400 (EDT) Received: by ibm-tiger.the-meissners.org (Postfix, from userid 500) id 9D8CA47759; Wed, 28 Jun 2017 14:28:23 -0400 (EDT) Date: Wed, 28 Jun 2017 14:28:23 -0400 From: Michael Meissner To: GCC Patches , Segher Boessenkool , David Edelsohn , Bill Schmidt Subject: [PATCH], PowerPC target_clones minor support Mail-Followup-To: Michael Meissner , GCC Patches , Segher Boessenkool , David Edelsohn , Bill Schmidt MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-12-10) X-TM-AS-GCONF: 00 x-cbid: 17062818-0052-0000-0000-00000230FAC9 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007291; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000214; SDB=6.00880018; UDB=6.00438658; IPR=6.00660172; BA=6.00005445; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00015994; XFM=3.00000015; UTC=2017-06-28 18:28:25 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17062818-0053-0000-0000-00005122AC7A Message-Id: <20170628182822.GA21408@ibm-tiger.the-meissners.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-06-28_12:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1706280292 X-IsSubscribed: yes Some minor changes to the PowerPC target_clones support: 1) I added a warning if target_clones was used and the compiler whas configured with an older glibc where __builtin_cpu_supports always returns 0; 2) I reworked how the ifunc resolver function is generated, and always made it a static function; 3) I added an executable target_clones test, and I made both clone tests dependent on GCC being configured with a new glibc. I have done a full bootstrap and make check test on a little endian power8 system, and there were no regressions. I did the bootstrap using the Advance Toolchain 10.0-3 libraries, and verified that the 2 clone tests were run. Are these patches ok to apply to the trunk? [gcc] 2017-06-28 Michael Meissner * config/rs6000/rs6000.c (rs6000_get_function_versions_dispatcher): Add warning if the compiler is not configured to use at least GLIBC version 2.23. (make_resolver_func): Make resolver function private and not a COMDAT function. Create the name with clone_function_name instead of make_unique_name. [gcc/testsuite] 2017-06-28 Michael Meissner * gcc.target/powerpc/clone2.c: New runtime test for target_clones. * gcc.target/powerpc/clone1.c: Add check to make sure the __builtin_cpu_supports function is fully supported. Index: gcc/config/rs6000/rs6000.c =================================================================== --- gcc/config/rs6000/rs6000.c (.../svn+ssh://meissner@gcc.gnu.org/svn/gcc/trunk/gcc/config/rs6000) (revision 249737) +++ gcc/config/rs6000/rs6000.c (.../gcc/config/rs6000) (working copy) @@ -37266,6 +37266,11 @@ rs6000_get_function_versions_dispatcher default_node = default_version_info->this_node; +#ifndef TARGET_LIBC_PROVIDES_HWCAP_IN_TCB + warning_at (DECL_SOURCE_LOCATION (default_node->decl), 0, + "target_clone needs at least glibc 2.23"); +#endif + if (targetm.has_ifunc_p ()) { struct cgraph_function_version_info *it_v = NULL; @@ -37311,29 +37316,24 @@ make_resolver_func (const tree default_d const tree dispatch_decl, basic_block *empty_bb) { - /* IFUNC's have to be globally visible. So, if the default_decl is - not, then the name of the IFUNC should be made unique. */ - bool is_uniq = (TREE_PUBLIC (default_decl) == 0); - /* Append the filename to the resolver function if the versions are not externally visible. This is because the resolver function has to be externally visible for the loader to find it. So, appending the filename will prevent conflicts with a resolver function from another module which is based on the same version name. */ - char *resolver_name = make_unique_name (default_decl, "resolver", is_uniq); + tree decl_name = clone_function_name (default_decl, "resolver"); + const char *resolver_name = IDENTIFIER_POINTER (decl_name); /* The resolver function should return a (void *). */ tree type = build_function_type_list (ptr_type_node, NULL_TREE); tree decl = build_fn_decl (resolver_name, type); - tree decl_name = get_identifier (resolver_name); SET_DECL_ASSEMBLER_NAME (decl, decl_name); DECL_NAME (decl) = decl_name; TREE_USED (decl) = 1; DECL_ARTIFICIAL (decl) = 1; DECL_IGNORED_P (decl) = 0; - /* IFUNC resolvers have to be externally visible. */ - TREE_PUBLIC (decl) = 1; + TREE_PUBLIC (decl) = 0; DECL_UNINLINABLE (decl) = 1; /* Resolver is not external, body is generated. */ @@ -37344,15 +37344,6 @@ make_resolver_func (const tree default_d DECL_INITIAL (decl) = make_node (BLOCK); DECL_STATIC_CONSTRUCTOR (decl) = 0; - if (DECL_COMDAT_GROUP (default_decl) || TREE_PUBLIC (default_decl)) - { - /* In this case, each translation unit with a call to this - versioned function will put out a resolver. Ensure it - is comdat to keep just one copy. */ - DECL_COMDAT (decl) = 1; - make_decl_one_only (decl, DECL_ASSEMBLER_NAME (decl)); - } - /* Build result decl and add to function_decl. */ tree t = build_decl (UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, ptr_type_node); DECL_ARTIFICIAL (t) = 1; @@ -37374,7 +37365,7 @@ make_resolver_func (const tree default_d = make_attribute ("ifunc", resolver_name, DECL_ATTRIBUTES (dispatch_decl)); cgraph_node::create_same_body_alias (dispatch_decl, decl); - XDELETEVEC (resolver_name); + return decl; } Index: gcc/testsuite/gcc.target/powerpc/clone2.c =================================================================== --- gcc/testsuite/gcc.target/powerpc/clone2.c (.../svn+ssh://meissner@gcc.gnu.org/svn/gcc/trunk/gcc/testsuite/gcc.target/powerpc) (revision 0) +++ gcc/testsuite/gcc.target/powerpc/clone2.c (.../gcc/testsuite/gcc.target/powerpc) (revision 249738) @@ -0,0 +1,31 @@ +/* { dg-do run { target { powerpc*-*-linux* } } } */ +/* { dg-options "-mvsx -O2" } */ +/* { dg-require-effective-target powerpc_p9vector_ok } */ +/* { dg-require-effective-target ppc_cpu_supports_hw } */ + +#include +#include + +/* Power9 (aka, ISA 3.0) has a MODSD instruction to do modulus, while Power8 + (aka, ISA 2.07) has to do modulus with divide and multiply. Make sure that + the basic support for target_clones runs. + + Restrict ourselves to Linux, since IFUNC might not be supported in other + operating systems. */ + +__attribute__((__target_clones__("cpu=power9,default"))) +long mod_func (long a, long b) +{ + return a % b; +} + +#define X 53L +#define Y 7L +int +main (void) +{ + if (mod_func (X, Y) != (X % Y)) + abort (); + + return 0; +} Index: gcc/testsuite/gcc.target/powerpc/clone1.c =================================================================== --- gcc/testsuite/gcc.target/powerpc/clone1.c (.../svn+ssh://meissner@gcc.gnu.org/svn/gcc/trunk/gcc/testsuite/gcc.target/powerpc) (revision 249737) +++ gcc/testsuite/gcc.target/powerpc/clone1.c (.../gcc/testsuite/gcc.target/powerpc) (working copy) @@ -2,6 +2,7 @@ /* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { "-mcpu=power8" } } */ /* { dg-options "-mcpu=power8 -O2" } */ /* { dg-require-effective-target powerpc_p9vector_ok } */ +/* { dg-require-effective-target ppc_cpu_supports_hw } */ /* Power9 (aka, ISA 3.0) has a MODSD instruction to do modulus, while Power8 (aka, ISA 2.07) has to do modulus with divide and multiply. Make sure