From patchwork Mon Jan 8 16:19:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georg-Johann Lay X-Patchwork-Id: 856907 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-470431-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="XVMrcfKr"; 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 3zFgTL5kdpz9s7M for ; Tue, 9 Jan 2018 03:19:34 +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:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=dfMrJ+aCs7LDfoAkX7znzCaRBT65WLktyyCXP6naMpOXfASi7d x2zotf9atzMIg8s19oCDy0Wc4QFMpQFrQmjMuRQnF17okQG4OYKPa7QinLhf3TXH IyQnQHbt2XbmIdjdKQqy54FtfRM6CzS3X35DR9ThNOXNqDv/vRheMmigM= 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=Bk6p0DdGsHMQB67Cxt82mNTzVvI=; b=XVMrcfKr4m8EZjomx76c Brn4i6qpRCSHS54Z0VRpfnhFxFJ3tSRmgkuthWZD7Up0y0Raorq5KVD06gOXmwKH SbY8WTh5jpIBnx+rKLZizcsj0L7asQoFg5XOsO90c/sMpG5cwMeBgZyCupiE/L5m oXwzXEXCZfOn1t40Zm5v2zg= Received: (qmail 38970 invoked by alias); 8 Jan 2018 16:19:27 -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 38959 invoked by uid 89); 8 Jan 2018 16:19:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-14.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Treat, H*r:AUTH, H*r:ip*192.168.0.123, 22529 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.162) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 08 Jan 2018 16:19:24 +0000 X-RZG-AUTH: :LXoWVUeid/7A29J/hMvvT3koxZnKXKoq0dKoR0veqDn+abI2nramdeIcmg== X-RZG-CLASS-ID: mo00 Received: from [192.168.0.123] (mail.hightec-rt.com [213.135.1.215]) by smtp.strato.de (RZmta 42.15 DYNA|AUTH) with ESMTPSA id 60692du08GJLPFI (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Mon, 8 Jan 2018 17:19:21 +0100 (CET) To: gcc-patches Cc: Denis Chertykov From: Georg-Johann Lay Subject: [patch,avr] Implement PR83737 Message-ID: Date: Mon, 8 Jan 2018 17:19:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 X-IsSubscribed: yes This PR skips saving of any registers in main. Attribute OS_main can do this as well, however we can just drop any saves / restores in all optimized compilation -- not even the test suite needs these saves. The feature can still be switched off by new -mno-OS_main Ok for trunk? gcc/ Don't save registers in main(). PR target/83737 * doc/invoke.texi (AVR Options) [-mOS_main]: Document it. * config/avr/avr.opt (-mOS_main): New target option. * config/avr/avr.c (avr_in_main_p): New static function. (avr_regs_to_save) [avr_in_main_p]: Return 0. (avr_prologue_setup_frame): Don't save any regs if avr_in_main_p. (avr_expand_epilogue): Same. * common/config/avr/avr-common.c (avr_option_optimization_table): Switch on -mOS_main for optimizing compilations. Index: common/config/avr/avr-common.c =================================================================== --- common/config/avr/avr-common.c (revision 256338) +++ common/config/avr/avr-common.c (working copy) @@ -31,6 +31,7 @@ static const struct default_options avr_ // a frame without need when it tries to be smart around calls. { OPT_LEVELS_ALL, OPT_fcaller_saves, NULL, 0 }, { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_mgas_isr_prologues, NULL, 1 }, + { OPT_LEVELS_1_PLUS, OPT_mOS_main, NULL, 1 }, { OPT_LEVELS_NONE, 0, NULL, 0 } }; Index: config/avr/avr.c =================================================================== --- config/avr/avr.c (revision 256338) +++ config/avr/avr.c (working copy) @@ -1167,6 +1167,23 @@ avr_starting_frame_offset (void) } +/* Return true if we are supposed to be in main(). This is only used + to determine if the callee-saved registers don't need to be saved + because the caller of main (crt*.o) doesn't use any of them. */ + +static bool +avr_in_main_p () +{ + return (TARGET_OS_MAIN + && MAIN_NAME_P (DECL_NAME (current_function_decl)) + // FIXME: We'd like to also test `flag_hosted' which is only + // available in the C-ish fronts, so no such test for now. + // Instead, we test the return type of "main" which is not exactly + // the same but good enough. + && INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl)))); +} + + /* Return the number of hard registers to push/pop in the prologue/epilogue of the current function, and optionally store these registers in SET. */ @@ -1180,10 +1197,11 @@ avr_regs_to_save (HARD_REG_SET *set) CLEAR_HARD_REG_SET (*set); count = 0; - /* No need to save any registers if the function never returns or - has the "OS_task" or "OS_main" attribute. */ + /* No need to save any registers if the function never returns or has the + "OS_task" or "OS_main" attribute. Dito if we are in "main". */ if (TREE_THIS_VOLATILE (current_function_decl) + || avr_in_main_p() || cfun->machine->is_OS_task || cfun->machine->is_OS_main) return 0; @@ -1651,6 +1669,7 @@ avr_prologue_setup_frame (HOST_WIDE_INT && size < size_max && live_seq && !isr_p + && !avr_in_main_p() && !cfun->machine->is_OS_task && !cfun->machine->is_OS_main && !AVR_TINY); @@ -1713,7 +1732,9 @@ avr_prologue_setup_frame (HOST_WIDE_INT emit_push_byte (reg, true); if (frame_pointer_needed - && (!(cfun->machine->is_OS_task || cfun->machine->is_OS_main))) + && (!(avr_in_main_p() + || cfun->machine->is_OS_task + || cfun->machine->is_OS_main))) { /* Push frame pointer. Always be consistent about the ordering of pushes -- epilogue_restores expects the @@ -1834,6 +1855,9 @@ avr_prologue_setup_frame (HOST_WIDE_INT if (cfun->machine->is_interrupt) irq_state = 1; + /* IRQs might be on when entering "main", hence avr_in_main_p + is *not* included in the following test. */ + if (TARGET_NO_INTERRUPTS || cfun->machine->is_signal || cfun->machine->is_OS_main) @@ -2122,6 +2146,7 @@ avr_expand_epilogue (bool sibcall_p) && !isr_p && !cfun->machine->is_OS_task && !cfun->machine->is_OS_main + && !avr_in_main_p() && !AVR_TINY); if (minimize @@ -2227,7 +2252,9 @@ avr_expand_epilogue (bool sibcall_p) } /* size != 0 */ if (frame_pointer_needed - && !(cfun->machine->is_OS_task || cfun->machine->is_OS_main)) + && !(avr_in_main_p() + || cfun->machine->is_OS_task + || cfun->machine->is_OS_main)) { /* Restore previous frame_pointer. See avr_expand_prologue for rationale for not using pophi. */ Index: config/avr/avr.opt =================================================================== --- config/avr/avr.opt (revision 256338) +++ config/avr/avr.opt (working copy) @@ -70,6 +70,10 @@ Target Report Undocumented Mask(ORDER_1) morder2 Target Report Undocumented Mask(ORDER_2) +mOS_main +Target Report Mask(OS_MAIN) +Treat main as if it had attribute OS_main. + mtiny-stack Target Report Mask(TINY_STACK) Change only the low 8 bits of the stack pointer. Index: doc/invoke.texi =================================================================== --- doc/invoke.texi (revision 256338) +++ doc/invoke.texi (working copy) @@ -669,7 +669,8 @@ -imacros @var{file} -imultilib @var{dir -mbranch-cost=@var{cost} @gol -mcall-prologues -mgas-isr-prologues -mint8 @gol -mn_flash=@var{size} -mno-interrupts @gol --mrelax -mrmw -mstrict-X -mtiny-stack -mfract-convert-truncate @gol +-mOS_main -mrelax -mrmw -mstrict-X -mtiny-stack @gol +-mfract-convert-truncate @gol -mshort-calls -nodevicelib @gol -Waddr-space-convert -Wmisspelled-isr} @@ -16472,6 +16473,12 @@ Assume that the flash memory has a size Generated code is not compatible with hardware interrupts. Code size is smaller. +@item -mOS_main +@opindex mOS_main +Do not save registers in @code{main}. The effect is similar to +attaching attribute @ref{AVR Function Attributes,,@code{OS_main}} +to @code{main}. It is activated per default if optimization is on. + @item -mrelax @opindex mrelax Try to replace @code{CALL} resp.@: @code{JMP} instruction by the shorter