From patchwork Tue Mar 26 11:30:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Clifton X-Patchwork-Id: 231180 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 01B5F2C0095 for ; Tue, 26 Mar 2013 22:35:38 +1100 (EST) 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=upC8bSND4Fe40GqzWMjIiDslUCqGhh2juA/DFcvneadclwSszu 5ShASnkyfDJtTI+V0DPcBrFU6+rKpRmlWhzGnAgZijiULpyNCCGGgKWRIM27Glcb z+VP7labqHkdiByTxkTqwHbSDVL5LYMM/Y12phau91tG4/gY0mntxPN10= 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=jWN8ulFeK+3LA+38GtLroXHNwnk=; b=thhcuACxG8kgD+T/4zwK be72uvSSUIilH6qli4EDS8lKZ6UIijuT7klKDv5BxO0QnI/ucN80zjebyniQsGGy i0+B64soVMckzQNndVXH5zGjXgKqgHOJSkg0ZMZnMNNyeqftiqkWJX9pafgmYpQf 0yh64iDjOaMFTr+Tr+GiU2k= Received: (qmail 18070 invoked by alias); 26 Mar 2013 11:35: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 18046 invoked by uid 89); 26 Mar 2013 11:35:20 -0000 X-Spam-SWARE-Status: No, score=-7.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 26 Mar 2013 11:35:14 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2QBZCeG000758 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 26 Mar 2013 07:35:13 -0400 Received: from Cadeux.redhat.com (vpn1-6-38.ams2.redhat.com [10.36.6.38]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r2QBZ7n3009502 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Tue, 26 Mar 2013 07:35:11 -0400 From: Nick Clifton To: dj@redhat.com Cc: gcc-patches@gcc.gnu.org Subject: RFA: RL78: Improve prologues for interrupt handlers Date: Tue, 26 Mar 2013 11:30:03 +0000 Message-ID: <87ppympfes.fsf@redhat.com> MIME-Version: 1.0 Hi DJ, I am submitting a patch on behalf of Renesas and KPIT. They found a way to improve the prologues for interrupt handlers so that only the registers that actually need to be saved are pushed onto the stack. The patch has been tested with no regressions in the gcc testsuite for an rl78-elf toolchain, as well as various different interrupt handler configurations. OK to apply ? Cheers Nick gcc/ChangeLog 2013-03-26 Kaushik Phatak * config/rl78/rl78.c (need_to_save): Change return type to bool. For interrupt functions: save call clobbered registers if the register is used or the handler is not a leaf function. (rl78_expand_prologue): Always recompute the frame information. For interrupt functions: only select bank 0 if one of the bank 0 registers is going to be pushed. Index: gcc/config/rl78/rl78.c =================================================================== --- gcc/config/rl78/rl78.c (revision 197093) +++ gcc/config/rl78/rl78.c (working copy) @@ -373,34 +373,43 @@ return true; } -/* Returns nonzero if the given register needs to be saved by the +/* Returns true if the given register needs to be saved by the current function. */ -static int -need_to_save (int regno) +static bool +need_to_save (unsigned int regno) { if (is_interrupt_func (cfun->decl)) { - if (regno < 8) - return 1; /* don't know what devirt will need */ + /* We don't need to save registers that have + been reserved for interrupt handlers. */ if (regno > 23) - return 0; /* don't need to save interrupt registers */ - if (crtl->is_leaf) - { - return df_regs_ever_live_p (regno); - } - else - return 1; + return false; + + /* If the handler is a non-leaf function then it may call + non-interrupt aware routines which will happily clobber + any call_used registers, so we have to preserve them. */ + if (!crtl->is_leaf && call_used_regs[regno]) + return true; + + /* Otherwise we only have to save a register, call_used + or not, if it is used by this handler. */ + return df_regs_ever_live_p (regno); } + if (regno == FRAME_POINTER_REGNUM && frame_pointer_needed) - return 1; + return true; + if (fixed_regs[regno]) - return 0; + return false; + if (crtl->calls_eh_return) - return 1; + return true; + if (df_regs_ever_live_p (regno) && !call_used_regs[regno]) - return 1; - return 0; + return true; + + return false; } /* We use this to wrap all emitted insns in the prologue. */ @@ -833,14 +842,22 @@ rtx sp = gen_rtx_REG (HImode, STACK_POINTER_REGNUM); int rb = 0; - if (!cfun->machine->computed) - rl78_compute_frame_info (); + /* Always re-compute the frame info - the + register usage may have changed. */ + rl78_compute_frame_info (); + if (flag_stack_usage_info) current_function_static_stack_size = cfun->machine->framesize; if (is_interrupt_func (cfun->decl)) - emit_insn (gen_sel_rb (GEN_INT (0))); + for (i = 0; i < 4; i++) + if (cfun->machine->need_to_push [i]) + { + /* Select Bank 0 if we are using any registers from Bank 0. */ + emit_insn (gen_sel_rb (GEN_INT (0))); + break; + } for (i = 0; i < 16; i++) if (cfun->machine->need_to_push [i])