From patchwork Tue Sep 17 21:10:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: DJ Delorie X-Patchwork-Id: 275542 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 did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 33DD52C00D8 for ; Wed, 18 Sep 2013 07:10:52 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :message-id:from:to:subject; q=dns; s=default; b=I7Muwnz8srrgf20 03+qZJ2Xdizu94cNoul1UzIoPAnskdtNj5nOrDBQeFgpjIY/5x3LflKjPbYOVZQ8 0zHOrm7AA2m8Ehu2PGdlzLP1pyG3V7+K1ekfNCgVrO9bRQqNwHdugWscUqoPQQn0 tBfflQIetQwYEbh8XWkjgFHiKGWc= 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:date :message-id:from:to:subject; s=default; bh=BixtFT9X7jUcR0ABLZTjI LtgCK8=; b=u1pefOUCu8uJrJwv2cdYkFgDvIQxC3KTbCZpM+Kdx0hWjrO9Aai/K YurITO1rNlEP+5XL+ojuNjee+TyDoyW3w9inRfwVHnATaqpNbComc2tEWTtjfZFN /GHrDHDVIS2rRNHh3rNWzLTph8fFZ5Q9CgIKTLH/zdMJ9umih6LYSQ= Received: (qmail 17913 invoked by alias); 17 Sep 2013 21:10:45 -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 17900 invoked by uid 89); 17 Sep 2013 21:10:45 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 17 Sep 2013 21:10:45 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r8HLAh1D030883 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 17 Sep 2013 17:10:43 -0400 Received: from greed.delorie.com (ovpn-113-20.phx2.redhat.com [10.3.113.20]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r8HLAgmX002653 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 17 Sep 2013 17:10:42 -0400 Received: from greed.delorie.com (greed.delorie.com [127.0.0.1]) by greed.delorie.com (8.14.4/8.14.4) with ESMTP id r8HLAfdQ009443 for ; Tue, 17 Sep 2013 17:10:41 -0400 Received: (from dj@localhost) by greed.delorie.com (8.14.4/8.14.4/Submit) id r8HLAf8D009442; Tue, 17 Sep 2013 17:10:41 -0400 Date: Tue, 17 Sep 2013 17:10:41 -0400 Message-Id: <201309172110.r8HLAf8D009442@greed.delorie.com> From: DJ Delorie To: gcc-patches@gcc.gnu.org Subject: [rl78] optimize prologues X-IsSubscribed: yes Committed. 2013-09-17 Nick Clifton * config/rl78/rl78.c (need_to_save): Change return type to bool. For interrupt functions: save all call clobbered registers if the interrupt 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 psuhed. Index: config/rl78/rl78.c =================================================================== --- config/rl78/rl78.c (revision 202666) +++ config/rl78/rl78.c (working copy) @@ -537,40 +537,45 @@ rl78_force_nonfar_3 (rtx *operands, rtx static bool rl78_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to ATTRIBUTE_UNUSED) { 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. */ static rtx F (rtx x) { @@ -1023,20 +1028,26 @@ rl78_expand_prologue (void) rtx sp = gen_rtx_REG (HImode, STACK_POINTER_REGNUM); int rb = 0; if (rl78_is_naked_func ()) return; - 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) && !TARGET_G10) - 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]) { if (TARGET_G10) {