From patchwork Mon Nov 7 12:54:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georg-Johann Lay X-Patchwork-Id: 691896 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 3tCC8468Ppz9vFL for ; Mon, 7 Nov 2016 23:54:43 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="RE8NrCEa"; 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:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=klU0iltHaiwTwBx+AGp268zA1qP2/mUlrCwS2WeivHXzMdgBSJ Rs2hDcumMRmo5lBmHEX97kjMkKuK1/g1F6yWfOGBF516dab+xVb9Ad8aqS2sgOPg Dc/bnESVuXO/NnUEq/2IJPHTmZ8MpUEmZ4XJI+PzaDOn0yLO+N7IPUP7Y= 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:message-id:date:mime-version:content-type; s= default; bh=ElkUf9RDdGz7/hpQW3jQbCcCAt0=; b=RE8NrCEaZykJ7tqmyOjU YCfRgQSrtEavYEG8nnmdnSa1DyEHTMhNdt9nu6omjj8u/cWnQWM0/chgDYtXS8ep 7jQbvV22GCQ6ZoPIhujVrlgbIZdYDcnbHUlR1JABVXUGjBeqC1ct9RARhfR6zS62 zOF5tunvNlMZ96QGaLAb8U4= Received: (qmail 30223 invoked by alias); 7 Nov 2016 12:54: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 30211 invoked by uid 89); 7 Nov 2016 12:54:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, KAM_STOCKGEN, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=outgoing, johann, assembling, tree_value X-HELO: mo4-p00-ob.smtp.rzone.de Received: from mo4-p00-ob.smtp.rzone.de (HELO mo4-p00-ob.smtp.rzone.de) (81.169.146.221) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 07 Nov 2016 12:54:23 +0000 X-RZG-AUTH: :LXoWVUeid/7A29J/hMvvT3ol15ykJcYwTPLBCxG2PQt7BpWLF2I= X-RZG-CLASS-ID: mo00 Received: from [192.168.0.123] (ip5f5871bb.dynamic.kabel-deutschland.de [95.88.113.187]) by smtp.strato.de (RZmta 39.7 DYNA|AUTH) with ESMTPSA id k0ac61sA7CsJ6p2 (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Mon, 7 Nov 2016 13:54:19 +0100 (CET) To: gcc-patches Cc: Denis Chertykov , Senthil Kumar Selvaraj , Pitchumani Sivanupandi From: Georg-Johann Lay Subject: [patch,avr] Add new option -mabsdata. Message-ID: Date: Mon, 7 Nov 2016 13:54:19 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 X-IsSubscribed: yes This patch adds a new command line option -mabsdata which can be ised to set attribute absdata for all data in static storage so it can be accessed by LDS and STS instructions. This is only useful for some reduced Tiny devices like ATtiny40. For other reduced Tiny where all of SRAM fits LDS / STS, the new option is automatically set by the device specs file. For ordinary devices the option is accepted but has no effect. Ok for trunk? Johann gcc/ PR target/78093 * doc/invoke.texi (AVR Options) [-mabsdata]: Document new option. * config/avr/avr.opt (-mabsdata): New option. * config/avr/avr.c (avr_encode_section_info) [AVR_TINY]: If -mabsdata & symbol is not progmem, tag as AVR_SYMBOL_FLAG_TINY_ABSDATA. * config/avr/avr-mcus.def (attiny4/5/9/10/20): Use AVR_ISA_LDS. * config/avr/gen-avr-mmcu-specs.c (print_mcu): Print cc1_absdata spec depending on AVR_ISA_LDS. * config/avr/specs.h (CC1_SPEC): Enhanced by cc1_absdata spec. gcc/testsuite/ PR target/78093 * gcc.target/avr/torture/tiny-absdata-2.c: New test. Index: config/avr/avr-arch.h =================================================================== --- config/avr/avr-arch.h (revision 241841) +++ config/avr/avr-arch.h (working copy) @@ -157,7 +157,9 @@ enum avr_device_specific_features AVR_ISA_NONE, AVR_ISA_RMW = 0x1, /* device has RMW instructions. */ AVR_SHORT_SP = 0x2, /* Stack Pointer has 8 bits width. */ - AVR_ERRATA_SKIP = 0x4 /* device has a core erratum. */ + AVR_ERRATA_SKIP = 0x4, /* device has a core erratum. */ + AVR_ISA_LDS = 0x8 /* whether LDS / STS is valid for all data in static + storage. Only useful for reduced Tiny. */ }; /* Map architecture to its texinfo string. */ Index: config/avr/avr-mcus.def =================================================================== --- config/avr/avr-mcus.def (revision 241841) +++ config/avr/avr-mcus.def (working copy) @@ -341,11 +341,11 @@ AVR_MCU ("atxmega128a1u", ARCH_AVRXME AVR_MCU ("atxmega128a4u", ARCH_AVRXMEGA7, AVR_ISA_RMW, "__AVR_ATxmega128A4U__", 0x2000, 0x0, 3) /* Tiny family */ AVR_MCU ("avrtiny", ARCH_AVRTINY, AVR_ISA_NONE, NULL, 0x0040, 0x0, 1) -AVR_MCU ("attiny4", ARCH_AVRTINY, AVR_ISA_NONE, "__AVR_ATtiny4__", 0x0040, 0x0, 1) -AVR_MCU ("attiny5", ARCH_AVRTINY, AVR_ISA_NONE, "__AVR_ATtiny5__", 0x0040, 0x0, 1) -AVR_MCU ("attiny9", ARCH_AVRTINY, AVR_ISA_NONE, "__AVR_ATtiny9__", 0x0040, 0x0, 1) -AVR_MCU ("attiny10", ARCH_AVRTINY, AVR_ISA_NONE, "__AVR_ATtiny10__", 0x0040, 0x0, 1) -AVR_MCU ("attiny20", ARCH_AVRTINY, AVR_ISA_NONE, "__AVR_ATtiny20__", 0x0040, 0x0, 1) +AVR_MCU ("attiny4", ARCH_AVRTINY, AVR_ISA_LDS, "__AVR_ATtiny4__", 0x0040, 0x0, 1) +AVR_MCU ("attiny5", ARCH_AVRTINY, AVR_ISA_LDS, "__AVR_ATtiny5__", 0x0040, 0x0, 1) +AVR_MCU ("attiny9", ARCH_AVRTINY, AVR_ISA_LDS, "__AVR_ATtiny9__", 0x0040, 0x0, 1) +AVR_MCU ("attiny10", ARCH_AVRTINY, AVR_ISA_LDS, "__AVR_ATtiny10__", 0x0040, 0x0, 1) +AVR_MCU ("attiny20", ARCH_AVRTINY, AVR_ISA_LDS, "__AVR_ATtiny20__", 0x0040, 0x0, 1) AVR_MCU ("attiny40", ARCH_AVRTINY, AVR_ISA_NONE, "__AVR_ATtiny40__", 0x0040, 0x0, 1) /* Assembler only. */ AVR_MCU ("avr1", ARCH_AVR1, AVR_ISA_NONE, NULL, 0x0060, 0x0, 1) Index: config/avr/avr.c =================================================================== --- config/avr/avr.c (revision 241841) +++ config/avr/avr.c (working copy) @@ -10182,14 +10182,18 @@ avr_encode_section_info (tree decl, rtx && SYMBOL_REF_P (XEXP (rtl, 0))) { rtx sym = XEXP (rtl, 0); + bool progmem_p = -1 == avr_progmem_p (decl, DECL_ATTRIBUTES (decl)); - if (-1 == avr_progmem_p (decl, DECL_ATTRIBUTES (decl))) + if (progmem_p) { // Tag symbols for later addition of 0x4000 (AVR_TINY_PM_OFFSET). SYMBOL_REF_FLAGS (sym) |= AVR_SYMBOL_FLAG_TINY_PM; } if (avr_decl_absdata_p (decl, DECL_ATTRIBUTES (decl)) + || (TARGET_ABSDATA + && !progmem_p + && !addr_attr) || (addr_attr // If addr_attr is non-null, it has an argument. Peek into it. && TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (addr_attr))) < 0xc0)) @@ -10198,7 +10202,7 @@ avr_encode_section_info (tree decl, rtx SYMBOL_REF_FLAGS (sym) |= AVR_SYMBOL_FLAG_TINY_ABSDATA; } - if (-1 == avr_progmem_p (decl, DECL_ATTRIBUTES (decl)) + if (progmem_p && avr_decl_absdata_p (decl, DECL_ATTRIBUTES (decl))) { error ("%q+D has incompatible attributes %qs and %qs", Index: config/avr/avr.opt =================================================================== --- config/avr/avr.opt (revision 241841) +++ config/avr/avr.opt (working copy) @@ -99,6 +99,10 @@ mfract-convert-truncate Target Report Mask(FRACT_CONV_TRUNC) Allow to use truncation instead of rounding towards zero for fractional fixed-point types. +mabsdata +Target Report Mask(ABSDATA) +Assume that all data in static storage can be accessed by LDS / STS. This option is only useful for reduced Tiny devices. + nodevicelib Driver Target Report RejectNegative Do not link against the device-specific library lib.a. Index: config/avr/gen-avr-mmcu-specs.c =================================================================== --- config/avr/gen-avr-mmcu-specs.c (revision 241841) +++ config/avr/gen-avr-mmcu-specs.c (working copy) @@ -130,6 +130,7 @@ for (arch_mcu = mcu; arch_mcu->macro; ) FILE *f = fopen (name ,"w"); + bool absdata = 0 != (mcu->dev_attribute & AVR_ISA_LDS); bool errata_skip = 0 != (mcu->dev_attribute & AVR_ERRATA_SKIP); bool rmw = 0 != (mcu->dev_attribute & AVR_ISA_RMW); bool sp8 = 0 != (mcu->dev_attribute & AVR_SHORT_SP); @@ -189,6 +190,10 @@ bool is_arch = NULL == mcu->macro; ? "\t%{!mno-skip-bug: -mskip-bug}" : "\t%{!mskip-bug: -mno-skip-bug}"); + fprintf (f, "*cc1_absdata:\n%s\n\n", absdata + ? "\t%{!mno-absdata: -mabsdata}" + : "\t%{mabsdata}"); + // avr-gcc specific specs for assembling / the assembler. fprintf (f, "*asm_arch:\n\t-mmcu=%s\n\n", arch->name); Index: config/avr/specs.h =================================================================== --- config/avr/specs.h (revision 241841) +++ config/avr/specs.h (working copy) @@ -34,7 +34,8 @@ along with GCC; see the file COPYING3. #define CC1_SPEC \ "%(cc1_n_flash) " \ "%(cc1_errata_skip) " \ - "%(cc1_rmw) " + "%(cc1_rmw) " \ + "%(cc1_absdata) " #undef CC1PLUS_SPEC #define CC1PLUS_SPEC \ Index: doc/invoke.texi =================================================================== --- doc/invoke.texi (revision 241841) +++ doc/invoke.texi (working copy) @@ -650,7 +650,8 @@ -remap -trigraphs -undef -U@var{macro} -mpure-code} @emph{AVR Options} -@gccoptlist{-mmcu=@var{mcu} -maccumulate-args -mbranch-cost=@var{cost} @gol +@gccoptlist{-mmcu=@var{mcu} -mabsdata -maccumulate-args @gol +-mbranch-cost=@var{cost} @gol -mcall-prologues -mint8 -mn_flash=@var{size} -mno-interrupts @gol -mrelax -mrmw -mstrict-X -mtiny-stack -mfract-convert-truncate -nodevicelib @gol -Waddr-space-convert -Wmisspelled-isr} @@ -15261,6 +15262,13 @@ GCC supports the following AVR devices a @include avr-mmcu.texi +@item -mabsdata +@opindex mabsdata + +Assume that all data in static stocage can be accessed by LDS / STS +inctructions. This option has only an effect on reduced Tiny devices like +ATtiny40. + @item -maccumulate-args @opindex maccumulate-args Accumulate outgoing function arguments and acquire/release the needed Index: testsuite/gcc.target/avr/torture/tiny-absdata-2.c =================================================================== --- testsuite/gcc.target/avr/torture/tiny-absdata-2.c (nonexistent) +++ testsuite/gcc.target/avr/torture/tiny-absdata-2.c (working copy) @@ -0,0 +1,85 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target avr_tiny } */ +/* { dg-options "-mabsdata" } */ + +typedef struct +{ + char a, b, c; +} abc_t; + +extern char varA; +extern char varB; +extern const char varC __attribute__((progmem)); + +extern int arrayA[]; +extern int arrayB[]; +extern char arrayC[] __attribute__((address(0x80))); +extern char arrayD[] __attribute__((address(0xc0))); + +extern abc_t abc; + +char get_1 (void) +{ + return varA; +} + +int get_2 (void) +{ + return arrayA[3]; +} + +char get_3 (void) +{ + return abc.a + abc.b + abc.c; +} + +char get_4 (void) +{ + return varC; +} + +void put_1 (char b) +{ + varB = b; +} + +void put_2 (int b) +{ + arrayB[3] = b; +} + +void put_3 (void) +{ + abc.a = abc.b = abc.c = 0; +} + +void put_4 (void) +{ + arrayC[0] = arrayC[1] = arrayC[2] = 0; +} + +void put_5 (void) +{ + arrayD[0] = 0; +} + +/* { dg-final { scan-assembler "lds r\[0-9\]+,varA" } } */ +/* { dg-final { scan-assembler "lds r\[0-9\]+,arrayA\\+6" } } */ +/* { dg-final { scan-assembler "lds r\[0-9\]+,arrayA\\+6\\+1" } } */ +/* { dg-final { scan-assembler "lds r\[0-9\]+,abc" } } */ +/* { dg-final { scan-assembler "lds r\[0-9\]+,abc\\+1" } } */ +/* { dg-final { scan-assembler "lds r\[0-9\]+,abc\\+2" } } */ + +/* { dg-final { scan-assembler "sts varB," } } */ +/* { dg-final { scan-assembler "sts arrayB\\+6," } } */ +/* { dg-final { scan-assembler "sts arrayB\\+6\\+1," } } */ +/* { dg-final { scan-assembler "sts arrayC," } } */ +/* { dg-final { scan-assembler "sts arrayC\\+1," } } */ +/* { dg-final { scan-assembler "sts arrayC\\+2," } } */ + +/* { dg-final { scan-assembler "sts abc," } } */ +/* { dg-final { scan-assembler "sts abc\\+1," } } */ +/* { dg-final { scan-assembler "sts abc\\+2," } } */ + +/* { dg-final { scan-assembler-not "lds r\[0-9\]+,varC" } } */ +/* { dg-final { scan-assembler-not "sts arrayD," } } */