From patchwork Fri Jun 29 09:03:16 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Clifton X-Patchwork-Id: 168022 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]) by ozlabs.org (Postfix) with SMTP id 87B24B6FA1 for ; Fri, 29 Jun 2012 19:08:22 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1341565703; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=n3voQ+SCfhwKnmjKqHIJ LXxNF40=; b=ejnH3NI6/GLQvTT4OtlJgIsne35B7F9KVcPCMPYkMcSzdym/AySD BnlB2icT1rZlMGkB80Gup0Xg/wld58Xh8+mCFMiO7HgFGP3iWhAj9IlRkox/sjZ8 PzlLSE4mWVG0Xr7fJZC1tAjzN+erRqongUtPMwYHnJRNutpyrphohWI= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=kwRgK5ga+1dgm5XwW8coTpydMlyQ0/6726jJuTBCjAR3C1vbmgpoLSkwPBi8ZX ST+GSXHv/hLmlnta0LoY2oSmTb071FBnxoNJE+IfQW4gzXZZgG+3jyXmEmHxd0yk av7YmcMs2BnAVwhnaflQbTcmCIPnSaa9h1CcyPXf9MHNY=; Received: (qmail 12784 invoked by alias); 29 Jun 2012 09:08:15 -0000 Received: (qmail 12761 invoked by uid 22791); 29 Jun 2012 09:08:13 -0000 X-SWARE-Spam-Status: No, hits=-6.1 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 29 Jun 2012 09:07:57 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q5T97ucn022442 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 29 Jun 2012 05:07:56 -0400 Received: from Cadeux.redhat.com (vpn1-4-135.ams2.redhat.com [10.36.4.135]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q5T97mFC002118 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Fri, 29 Jun 2012 05:07:52 -0400 From: Nick Clifton To: law@redhat.com, aoliva@redhat.com Cc: gcc-patches@gcc.gnu.org Subject: RFA: MN10300: Replace REG_SAVE_BYTES macro with calls to mn10300_get_live_callee_saved_regs Date: Fri, 29 Jun 2012 10:03:16 +0100 Message-ID: <87a9zmsd63.fsf@redhat.com> MIME-Version: 1.0 X-IsSubscribed: yes 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 Hi Jeff, Hi Alex, I recently encountered a problem with the REG_SAVE_BYTES macro in the mn10300 backend. When compiling some code in -fPID mode it was producing a different result to the mask computed by mn10300_get_live_callee_saved_regs. The problem turned out to be that the macro was not checking the call_really_saved_regs array. Rather than update the macro, it seemed to me that it would be better to just make this computation in one place - the mn10300_get_live_callee_saved_regs function - and avoid problems like this in the future. So attached is a patch that does this. Tested with no regressions on an mn10300-elf and an am33_2.0-linux-gnu toolchain. OK to apply ? Cheers Nick gcc/ChangeLog 2012-06-29 Nick Clifton * config/mn10300/mn10300.c (REG_SAVE_BYTES): Delete. (mn10300_get_live_callee_saved_regs): If requested return a count of the number of bytes in the mask. (mn10300_expand_prologue): Add argument to invocation of mn10300_get_live_callee_regs. (mn10300_expand_epilogue): Compute reg_save_bytes by calling mn10300_get_live_callee_saved_regs. (mn10300_initial_offset): Likewise. * config/mn10300/mn10300-protos.h (mn10300_get_live_callee_saved_regs): Update prototype. * config/mn10300/mn10300.md (return_ret): Add argument to invocation of mn10300_get_live_callee_saved_regs. Index: gcc/config/mn10300/mn10300.md =================================================================== --- gcc/config/mn10300/mn10300.md (revision 189067) +++ gcc/config/mn10300/mn10300.md (working copy) @@ -2048,7 +2048,7 @@ { /* The RETF insn is up to 3 cycles faster than RET. */ fputs ((mn10300_can_use_retf_insn () ? "\tretf " : "\tret "), asm_out_file); - mn10300_print_reg_list (asm_out_file, mn10300_get_live_callee_saved_regs ()); + mn10300_print_reg_list (asm_out_file, mn10300_get_live_callee_saved_regs (NULL)); fprintf (asm_out_file, ",%d\n", (int) INTVAL (operands[0])); return ""; }) Index: gcc/config/mn10300/mn10300-protos.h =================================================================== --- gcc/config/mn10300/mn10300-protos.h (revision 189067) +++ gcc/config/mn10300/mn10300-protos.h (working copy) @@ -25,7 +25,7 @@ extern rtx mn10300_legitimize_reload_address (rtx, enum machine_mode, int, int, int); extern bool mn10300_function_value_regno_p (const unsigned int); -extern int mn10300_get_live_callee_saved_regs (void); +extern unsigned int mn10300_get_live_callee_saved_regs (unsigned int *); extern bool mn10300_hard_regno_mode_ok (unsigned int, enum machine_mode); extern bool mn10300_modes_tieable (enum machine_mode, enum machine_mode); extern const char *mn10300_output_add (rtx[3], bool); Index: gcc/config/mn10300/mn10300.c =================================================================== --- gcc/config/mn10300/mn10300.c (revision 189067) +++ gcc/config/mn10300/mn10300.c (working copy) @@ -56,18 +56,6 @@ /* Selected processor type for tuning. */ enum processor_type mn10300_tune_cpu = PROCESSOR_DEFAULT; -/* The size of the callee register save area. Right now we save everything - on entry since it costs us nothing in code size. It does cost us from a - speed standpoint, so we want to optimize this sooner or later. */ -#define REG_SAVE_BYTES (4 * df_regs_ever_live_p (2) \ - + 4 * df_regs_ever_live_p (3) \ - + 4 * df_regs_ever_live_p (6) \ - + 4 * df_regs_ever_live_p (7) \ - + 16 * (df_regs_ever_live_p (14) \ - || df_regs_ever_live_p (15) \ - || df_regs_ever_live_p (16) \ - || df_regs_ever_live_p (17))) - #define CC_FLAG_Z 1 #define CC_FLAG_N 2 #define CC_FLAG_C 4 @@ -634,21 +622,36 @@ /* Returns the set of live, callee-saved registers as a bitmask. The callee-saved extended registers cannot be stored individually, so - all of them will be included in the mask if any one of them is used. */ + Also returns the number of bytes in the registers in the mask if + BYTES_SAVED is not NULL. */ -int -mn10300_get_live_callee_saved_regs (void) +unsigned int +mn10300_get_live_callee_saved_regs (unsigned int * bytes_saved) { int mask; int i; + unsigned int count; - mask = 0; + count = mask = 0; for (i = 0; i <= LAST_EXTENDED_REGNUM; i++) if (df_regs_ever_live_p (i) && ! call_really_used_regs[i]) - mask |= (1 << i); + { + mask |= (1 << i); + ++ count; + } + if ((mask & 0x3c000) != 0) - mask |= 0x3c000; + { + for (i = 0x04000; i < 0x40000; i <<= 1) + if ((mask & i) == 0) + ++ count; + + mask |= 0x3c000; + } + if (bytes_saved) + * bytes_saved = count * UNITS_PER_WORD; + return mask; } @@ -741,7 +744,7 @@ HOST_WIDE_INT size = mn10300_frame_size (); /* If we use any of the callee-saved registers, save them now. */ - mn10300_gen_multiple_store (mn10300_get_live_callee_saved_regs ()); + mn10300_gen_multiple_store (mn10300_get_live_callee_saved_regs (NULL)); if (TARGET_AM33_2 && fp_regs_to_save ()) { @@ -998,8 +1001,10 @@ mn10300_expand_epilogue (void) { HOST_WIDE_INT size = mn10300_frame_size (); - int reg_save_bytes = REG_SAVE_BYTES; - + unsigned int reg_save_bytes; + + mn10300_get_live_callee_saved_regs (& reg_save_bytes); + if (TARGET_AM33_2 && fp_regs_to_save ()) { int num_regs_to_save = fp_regs_to_save (), i; @@ -1219,7 +1224,7 @@ if (mn10300_can_use_rets_insn ()) emit_jump_insn (ret_rtx); else - emit_jump_insn (gen_return_ret (GEN_INT (size + REG_SAVE_BYTES))); + emit_jump_insn (gen_return_ret (GEN_INT (size + reg_save_bytes))); } /* Recognize the PARALLEL rtx generated by mn10300_gen_multiple_store(). @@ -1434,7 +1439,10 @@ is the size of the callee register save area. */ if (from == ARG_POINTER_REGNUM) { - diff += REG_SAVE_BYTES; + unsigned int reg_save_bytes; + + mn10300_get_live_callee_saved_regs (& reg_save_bytes); + diff += reg_save_bytes; diff += 4 * fp_regs_to_save (); }