From patchwork Wed May 22 20:29:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Schmidt X-Patchwork-Id: 1103657 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-501469-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Zc5Jr0+p"; 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 458PPY5TNNz9s55 for ; Thu, 23 May 2019 06:29:37 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:date:mime-version:message-id:content-type :content-transfer-encoding; q=dns; s=default; b=uBh7mZR3CarcbLH9 AzwE6CtH1ZYZGui+cIYSrlJmYMbCvBznorBS/h20HpVMz3Q0Qh5tLHI3UD9oKhNl crUwMkCvpdwaaShYNy5tr1n9xOmi7KGNn3rSuJhNjY5awEEqsQHYDaNlHEoyjqUP YZonOJ+x8CG53j1X+3CUNF/8kzI= 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:to:cc :from:subject:date:mime-version:message-id:content-type :content-transfer-encoding; s=default; bh=0EsQnfJ/DhBuRru3vSiyvw frTGA=; b=Zc5Jr0+p8oX+CiVhy8kfizkHHGRj7/6d9R2z1gLgxVL12R6jt32tFi dhre0ItJT02C/4hOjtAwn5bpicQ7rk7l7G2BVO6D1O0CBudVM2QrmCf90cCNUu9r ZpW+vIdaQXt7669UNMBy2rg/QIEQjAKavl6XLxT77hSnl/I2rNqXw= Received: (qmail 41943 invoked by alias); 22 May 2019 20:29:30 -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 40289 invoked by uid 89); 22 May 2019 20:29:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, HTML_MESSAGE, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 22 May 2019 20:29:25 +0000 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x4MKR1tY110204 for ; Wed, 22 May 2019 16:29:22 -0400 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0a-001b2d01.pphosted.com with ESMTP id 2snbgycy0y-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 22 May 2019 16:29:22 -0400 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 22 May 2019 21:29:21 +0100 Received: from b03cxnp08026.gho.boulder.ibm.com (9.17.130.18) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 22 May 2019 21:29:20 +0100 Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x4MKTJA612452214 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 22 May 2019 20:29:19 GMT Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6B5DB136051; Wed, 22 May 2019 20:29:19 +0000 (GMT) Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C0B0B136053; Wed, 22 May 2019 20:29:18 +0000 (GMT) Received: from BigMac.local (unknown [9.85.143.85]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 22 May 2019 20:29:18 +0000 (GMT) To: GCC Patches Cc: Segher Boessenkool From: Bill Schmidt Subject: [PATCH] rs6000: Add basic infrastructure for PC-relative addressing Date: Wed, 22 May 2019 15:29:17 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 x-cbid: 19052220-0036-0000-0000-00000AC17DC7 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00011144; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000286; SDB=6.01207124; UDB=6.00633923; IPR=6.00988099; MB=3.00027007; MTD=3.00000008; XFM=3.00000015; UTC=2019-05-22 20:29:21 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19052220-0037-0000-0000-00004BE73D61 Message-Id: Hi, This patch adds basic infrastructure support to enable PC-relative addressing. It adds the -mpcrel / -mno-pcrel option (defaulted on for -mcpu=future, otherwise off), and provides a couple of interfaces to determine whether PC-relative addressing should be used when generating a single function. Bootstrapped and tested on powerpc64le-unknown-linux-gnu with no regressions. Is this okay for trunk? Thanks, Bill 2019-05-22 Bill Schmidt Michael Meissner Segher Boessenkool * config/rs6000/rs6000-cpus.def (ISA_FUTURE_MASKS_SERVER): Add OPTION_MASK_PCREL. (OTHER_FUTURE_MASKS): New #define. (OTHER_P9_VECTOR_MASKS): Add OTHER_FUTURE_MASKS. (POWERPC_MASKS): Add OPTION_MASK_PCREL. * config/rs6000/rs6000-protos.h (rs6000_pcrel_p): New prototype. (rs6000_fndecl_pcrel_p): Likewise. * config/rs6000/rs6000.c (rs6000_option_override_internal): Report error if -mpcrel is requested without -mcpu=future. (rs6000_fndecl_pcrel_p): New function. (rs6000_pcrel_p): Likewise. * config/rs6000/rs6000.opt (mpcrel): New option. * doc/invoke.texi: Document -mpcrel and -mno-pcrel. diff --git a/gcc/config/rs6000/rs6000-cpus.def b/gcc/config/rs6000/rs6000-cpus.def index f32da25930d..a4e1d1a01d8 100644 --- a/gcc/config/rs6000/rs6000-cpus.def +++ b/gcc/config/rs6000/rs6000-cpus.def @@ -74,10 +74,15 @@ /* Support for a future processor's features. */ #define ISA_FUTURE_MASKS_SERVER (ISA_3_0_MASKS_SERVER \ - | OPTION_MASK_FUTURE) + | OPTION_MASK_FUTURE \ + | OPTION_MASK_PCREL) + +/* Flags that need to be turned off if -mno-future. */ +#define OTHER_FUTURE_MASKS (OPTION_MASK_PCREL) /* Flags that need to be turned off if -mno-power9-vector. */ -#define OTHER_P9_VECTOR_MASKS (OPTION_MASK_FLOAT128_HW \ +#define OTHER_P9_VECTOR_MASKS (OTHER_FUTURE_MASKS \ + | OPTION_MASK_FLOAT128_HW \ | OPTION_MASK_FUTURE \ | OPTION_MASK_P9_MINMAX) @@ -129,6 +134,7 @@ | OPTION_MASK_P9_MINMAX \ | OPTION_MASK_P9_MISC \ | OPTION_MASK_P9_VECTOR \ + | OPTION_MASK_PCREL \ | OPTION_MASK_POPCNTB \ | OPTION_MASK_POPCNTD \ | OPTION_MASK_POWERPC64 \ diff --git a/gcc/config/rs6000/rs6000-protos.h b/gcc/config/rs6000/rs6000-protos.h index 9718adaa2b9..18ece005a96 100644 --- a/gcc/config/rs6000/rs6000-protos.h +++ b/gcc/config/rs6000/rs6000-protos.h @@ -152,6 +152,8 @@ extern rtx rs6000_machopic_legitimize_pic_address (rtx, machine_mode, extern rtx rs6000_allocate_stack_temp (machine_mode, bool, bool); extern align_flags rs6000_loop_align (rtx); extern void rs6000_split_logical (rtx [], enum rtx_code, bool, bool, bool); +extern bool rs6000_pcrel_p (struct function *); +extern bool rs6000_fndecl_pcrel_p (const_tree); #endif /* RTX_CODE */ #ifdef TREE_CODE diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 57c9eae8208..68abc81c354 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -4296,6 +4296,15 @@ rs6000_option_override_internal (bool global_init_p) rs6000_isa_flags &= ~OPTION_MASK_FLOAT128_HW; } + /* -mpcrel requires the prefixed load/store support on FUTURE systems. */ + if (!TARGET_FUTURE && TARGET_PCREL) + { + if ((rs6000_isa_flags_explicit & OPTION_MASK_PCREL) != 0) + error ("%qs requires %qs", "-mpcrel", "-mcpu=future"); + + rs6000_isa_flags &= ~OPTION_MASK_PCREL; + } + /* Print the options after updating the defaults. */ if (TARGET_DEBUG_REG || TARGET_DEBUG_TARGET) rs6000_print_isa_options (stderr, 0, "after defaults", rs6000_isa_flags); @@ -38112,6 +38121,34 @@ rs6000_save_toc_in_prologue_p (void) return (cfun && cfun->machine && cfun->machine->save_toc_in_prologue); } +/* Return whether we should generate PC-relative code for FNDECL. */ +bool +rs6000_fndecl_pcrel_p (const_tree fndecl) +{ + if (DEFAULT_ABI != ABI_ELFv2) + return false; + + struct cl_target_option *opts = target_opts_for_fn (fndecl); + + return ((opts->x_rs6000_isa_flags & OPTION_MASK_PCREL) != 0 + && TARGET_CMODEL == CMODEL_MEDIUM); +} + +/* Return whether we should generate PC-relative code for *FN. */ +bool +rs6000_pcrel_p (struct function *fn) +{ + if (DEFAULT_ABI != ABI_ELFv2) + return false; + + /* Optimize usual case. */ + if (fn == cfun) + return ((rs6000_isa_flags & OPTION_MASK_PCREL) != 0 + && TARGET_CMODEL == CMODEL_MEDIUM); + + return rs6000_fndecl_pcrel_p (fn->decl); +} + #ifdef HAVE_GAS_HIDDEN # define USE_HIDDEN_LINKONCE 1 #else diff --git a/gcc/config/rs6000/rs6000.opt b/gcc/config/rs6000/rs6000.opt index 196e75d7009..43b04834746 100644 --- a/gcc/config/rs6000/rs6000.opt +++ b/gcc/config/rs6000/rs6000.opt @@ -573,3 +573,7 @@ Target Undocumented Var(rs6000_speculate_indirect_jumps) Init(1) Save mfuture Target Report Mask(FUTURE) Var(rs6000_isa_flags) Use instructions for a future architecture. + +mpcrel +Target Report Mask(PCREL) Var(rs6000_isa_flags) +Generate (do not generate) pc-relative memory addressing. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index fbbc4f829b7..c6ca0c7216a 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -1121,7 +1121,7 @@ See RS/6000 and PowerPC Options. -mfloat128 -mno-float128 -mfloat128-hardware -mno-float128-hardware @gol -mgnu-attribute -mno-gnu-attribute @gol -mstack-protector-guard=@var{guard} -mstack-protector-guard-reg=@var{reg} @gol --mstack-protector-guard-offset=@var{offset}} +-mstack-protector-guard-offset=@var{offset} -mpcrel -mno-pcrel} @emph{RX Options} @gccoptlist{-m64bit-doubles -m32bit-doubles -fpu -nofpu@gol @@ -25084,6 +25084,13 @@ which register to use as base register for reading the canary, and from what offset from that base register. The default for those is as specified in the relevant ABI. @option{-mstack-protector-guard-symbol=@var{symbol}} overrides the offset with a symbol reference to a canary in the TLS block. + +@item -mpcrel +@itemx -mno-pcrel +@opindex mpcrel +@opindex mno-pcrel +Generate (do not generate) pc-relative addressing when the option +@option{-mcpu=future} is used. @end table @node RX Options