From patchwork Tue Aug 7 05:18:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 954362 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-483282-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="OZ2yU/Ki"; 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 41l2rK0MQXz9s0R for ; Tue, 7 Aug 2018 15:19:27 +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:from :to:cc:subject:date:message-id:mime-version:content-type; q=dns; s=default; b=Eq1nEmkeINwNTDvhAkyVE9Lj3Q4qedrKfO9qojilGOhOuM1mN1 DMO3tIZkHNSInUEjwe+M5uRnjNsIjOneevwCS5+ZUFB2AX09DlSDTzgemFQzQWHB l3Brj4s9ZtoIufUdWk84CveYlJemlWMCVzT0+VwtCo10563jh4jO3hUgM= 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:mime-version:content-type; s= default; bh=JAJTfNvsRX4uYONLgQya2YtAlTY=; b=OZ2yU/KiPrrwg8/bHxxa iquXZRlw3KGbtXuytpiLeWql35/onX/15WsmwYMcYTHaHZse5axuk45o39/sLX44 o4XAyHixvT4F0xHkkGCom0jotzOfp1MLJZzACRE+A34Y1r0dyKtYStTiLvlqwbmg rBA0Y0G9KW2jybVhyfu+OeQ= Received: (qmail 101982 invoked by alias); 7 Aug 2018 05:19:18 -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 101964 invoked by uid 89); 7 Aug 2018 05:19:17 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Engineer, free!, shot, modes X-HELO: linux-libre.fsfla.org Received: from linux-libre.fsfla.org (HELO linux-libre.fsfla.org) (208.118.235.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 07 Aug 2018 05:19:15 +0000 Received: from free.home (home.lxoliva.fsfla.org [172.31.160.164]) by linux-libre.fsfla.org (8.15.2/8.15.2/Debian-3) with ESMTP id w775J8Ys002388; Tue, 7 Aug 2018 05:19:10 GMT Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTP id w775IxJY348871; Tue, 7 Aug 2018 02:18:59 -0300 From: Alexandre Oliva To: David Edelsohn , Segher Boessenkool Cc: gcc-patches@gcc.gnu.org Subject: [RFC,PATCH] Introduce -msdata=explicit for powerpc Date: Tue, 07 Aug 2018 02:18:59 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes This option allows users to manually select what goes in the limited small data range, and still get smaller and faster small data access sequences for the selected data. We've considered adding a new attribute, say "sdata", to let the compiler pick the sdata/sbss section name itself, but that's not strictly necessary since attribute section already does what we need. I'm not sure how the semantics of conflicting attributes should be implemented, but if others think it's a good idea, I could give it a shot. Like, if attribute((sdata, section("data"))) is given, should the variable be placed in .data but be accessed using sdata addressing modes? Should we reject that with an error? Should we warn and ignore one of the attributes? Something else? I saw comments, docs and init code that suggested the possibility of using r2/.sdata2 for small data, but I couldn't get code to be generated for such access, even with very old toolchains. I'm not sure I'm just missing how this magic comes about, or whether it hasn't been available for a very long time but nobody removed the comments/docs. Assuming I'm missing something, I put in the possibility of using r2 in the test in the patch, but I'm sure I have not exercised it to make sure I got it right. Help? I have not YET given this much testing. I'm posting it so as to give ppc maintainers an opportunity to comment on the proposed approach, in hopes of getting buy-in for the idea, if not necessarily for the patch, but I welcome alternate suggestions to enable users to choose what goes in faster sdata when there's too much data for size-based assignment to place interesting variables in sdata without overflowing its range. for gcc/ChangeLog * config/rs6000/rs6000-opts.h (SDATA_EXPLICIT): New enumerator. * config/rs6000/rs6000.c (rs6000_debug_reg_global): Handle it. (rs6000_file_start): Likewise. (rs6000_elf_in_small_data_p): Likewise. (SMALL_DATA_EABI_P): New, likewise. (SMALL_DATA_RELOC, SMALL_DATA_REG): Use it. * config/rs6000/sysv4.h (SUBTARGET_OVERRIDE_OPTIONS): Check for and set up SDATA_EXPLICIT. * config/rs6000/sysv4.opt: Add explicit to -msdata. * doc/invoke.texi (-msdata=explicit): Document it. for gcc/testsuite/ChangeLog * gcc.target/powerpc/ppc-sdata-3.c: New. diff --git a/gcc/config/rs6000/rs6000-opts.h b/gcc/config/rs6000/rs6000-opts.h index a8194783e018..cc780f569308 100644 --- a/gcc/config/rs6000/rs6000-opts.h +++ b/gcc/config/rs6000/rs6000-opts.h @@ -120,7 +120,8 @@ enum rs6000_sdata_type { SDATA_NONE, /* No small data support. */ SDATA_DATA, /* Just put data in .sbss/.sdata, don't use relocs. */ SDATA_SYSV, /* Use r13 to point to .sdata/.sbss. */ - SDATA_EABI /* Use r13 like above, r2 points to .sdata2/.sbss2. */ + SDATA_EABI, /* Use r13 like above, r2 points to .sdata2/.sbss2. */ + SDATA_EXPLICIT /* Use r13 (or r2?) for explicit sdata. */ }; /* Type of traceback to use. */ diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index ddc61bdaffe7..a679709a055f 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -2819,6 +2819,10 @@ rs6000_debug_reg_global (void) fprintf (stderr, DEBUG_FMT_S, "sdata", "eabi"); break; + case SDATA_EXPLICIT: + fprintf (stderr, DEBUG_FMT_S, "sdata", "explicit"); + break; + } switch (rs6000_traceback) @@ -6098,6 +6102,8 @@ rs6000_file_start (void) case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break; case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break; case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break; + case SDATA_EXPLICIT: + fprintf (file, "%s -msdata=explicit", start); start = ""; break; } if (rs6000_sdata && g_switch_value) @@ -21240,8 +21246,10 @@ rs6000_output_function_entry (FILE *file, const char *fname) /* Print an operand. Recognize special options, documented below. */ #if TARGET_ELF -#define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel") -#define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13) +#define SMALL_DATA_EABI_P (rs6000_sdata == SDATA_EABI \ + || (rs6000_sdata == SDATA_EXPLICIT && TARGET_EABI)) +#define SMALL_DATA_RELOC (SMALL_DATA_EABI_P ? "sda21" : "sdarel") +#define SMALL_DATA_REG (SMALL_DATA_EABI_P ? 0 : 13) #else #define SMALL_DATA_RELOC "sda21" #define SMALL_DATA_REG 0 @@ -33221,6 +33229,11 @@ rs6000_elf_in_small_data_p (const_tree decl) } else { + /* Explicit mode means no implicit assignment to small data + sections. */ + if (rs6000_sdata == SDATA_EXPLICIT) + return false; + /* If we are told not to put readonly data in sdata, then don't. */ if (TREE_READONLY (decl) && rs6000_sdata != SDATA_EABI && !rs6000_readonly_in_sdata) diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h index bb19d0dcd411..83f527c57af1 100644 --- a/gcc/config/rs6000/sysv4.h +++ b/gcc/config/rs6000/sysv4.h @@ -119,6 +119,8 @@ do { \ rs6000_sdata = SDATA_DATA; \ else if (!strcmp (rs6000_sdata_name, "default")) \ rs6000_sdata = (TARGET_EABI) ? SDATA_EABI : SDATA_SYSV; \ + else if (!strcmp (rs6000_sdata_name, "explicit")) \ + rs6000_sdata = SDATA_EXPLICIT; \ else if (!strcmp (rs6000_sdata_name, "sysv")) \ rs6000_sdata = SDATA_SYSV; \ else if (!strcmp (rs6000_sdata_name, "eabi")) \ diff --git a/gcc/config/rs6000/sysv4.opt b/gcc/config/rs6000/sysv4.opt index 34fea0ddd08a..d11053e4bdaf 100644 --- a/gcc/config/rs6000/sysv4.opt +++ b/gcc/config/rs6000/sysv4.opt @@ -25,7 +25,7 @@ Target RejectNegative Joined Var(rs6000_abi_name) msdata= Target RejectNegative Joined Var(rs6000_sdata_name) --msdata=[none,data,sysv,eabi] Select method for sdata handling. +-msdata=[none,data,sysv,eabi,explicit] Select method for sdata handling. mreadonly-in-sdata Target Report Var(rs6000_readonly_in_sdata) Init(1) Save diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 444159178a76..86dbb1d8700d 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -22824,6 +22824,16 @@ On embedded PowerPC systems, put all initialized global and static data in the @code{.data} section, and all uninitialized data in the @code{.bss} section. +@item -msdata=explicit +@itemx -msdata +@opindex msdata=explicit +@opindex msdata +Put all initialized global and static data that is not assigned to an +explicit section in the @code{.data} section, and all uninitialized data +that is not assigned to an explicit section in the @code{.bss} section. +Use small data access patterns to access variables explicitly assigned +to small data sections. + @item -mblock-move-inline-limit=@var{num} @opindex mblock-move-inline-limit Inline all block moves (such as calls to @code{memcpy} or structure diff --git a/gcc/testsuite/gcc.target/powerpc/ppc-sdata-3.c b/gcc/testsuite/gcc.target/powerpc/ppc-sdata-3.c new file mode 100644 index 000000000000..750e5ad234af --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/ppc-sdata-3.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-msdata=explicit" } */ +/* { dg-require-effective-target powerpc_eabi_ok } */ +/* { dg-require-effective-target nonpic } */ +/* { dg-final { scan-assembler "\\.section\[ \t\]\\.sdata," } } */ +/* { dg-final { scan-assembler "\\.section\[ \t\]\\.sbss," } } */ +/* { dg-final { scan-assembler "\\.section\[ \t\]\\.sdata2," } } */ +/* { dg-final { scan-assembler "\\.section\[ \t\]\\.sbss2," } } */ +/* { dg-final { scan-assembler "i@ha" } } */ +/* { dg-final { scan-assembler "j@sda(rel|21)\\((13|0)\\)" } } */ +/* { dg-final { scan-assembler "k@sda(rel|21)\\((13|0)\\)" } } */ +/* { dg-final { scan-assembler "l@sda(rel|21)\\((2|13|0)\\)" } } */ +/* { dg-final { scan-assembler "m@sda(rel|21)\\((2|13|0)\\)" } } */ + +static int i; +static int j __attribute__((section(".sbss"))); +static int k __attribute__((section(".sdata"))) = 2; +static int l __attribute__((section(".sbss2"))); +static int m __attribute__((section(".sdata2"))) = 4; +int f(void) { + return i + j + k + l + m; +}