From patchwork Thu Mar 24 17:45:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kai Tietz X-Patchwork-Id: 88261 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 C42B31007D1 for ; Fri, 25 Mar 2011 04:46:01 +1100 (EST) Received: (qmail 1124 invoked by alias); 24 Mar 2011 17:45:59 -0000 Received: (qmail 1110 invoked by uid 22791); 24 Mar 2011 17:45:57 -0000 X-SWARE-Spam-Status: No, hits=1.1 required=5.0 tests=AWL, BAYES_50, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RFC_ABUSE_POST, TW_FN, URIBL_RHS_DOB X-Spam-Check-By: sourceware.org Received: from mail-qy0-f182.google.com (HELO mail-qy0-f182.google.com) (209.85.216.182) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 24 Mar 2011 17:45:52 +0000 Received: by qyk27 with SMTP id 27so162019qyk.20 for ; Thu, 24 Mar 2011 10:45:51 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.0.75 with SMTP id 11mr7226713qca.94.1300988751750; Thu, 24 Mar 2011 10:45:51 -0700 (PDT) Received: by 10.229.97.206 with HTTP; Thu, 24 Mar 2011 10:45:51 -0700 (PDT) In-Reply-To: References: Date: Thu, 24 Mar 2011 18:45:51 +0100 Message-ID: Subject: Re: [patch i386 windows]: Introduce call-abi for 32-bit mingw and make callee_pop_aggregate_return attribute by default on for 32-bit mingw target From: Kai Tietz To: GCC Patches Cc: Richard Henderson 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 2011/3/24 Kai Tietz : > Hi, > > this patch introduces for windows 32-bit target also the call-abi > specifiers (ms_abi/sys_v) and set its default for this target to > "ms_abi".  This patch set the default of the > "callee_pop_aggregate_return" attribute to true for MS_ABI call-abi on > 32-bit.  Additionally it avoids the check of > "callee_pop_aggregate_return" for any x86_64 target. > I didn't changed here by intention the default settings of > cygwin-target. But of course, if wished this change could be done as > follow-up patch. > > ChangeLog gcc/ > > 2011-03-24  Kai Tietz > >        * config/i386/cygming.h (DWARF_FRAME_REGISTERS): Adjust comment. >        (STACK_BOUNDARY): Check for bit-ness in case of MS_ABI. >        * config/i386/i386.c (ix86_conditional_register_usage): Adjust >        comment and use macro TARGET_64BIT_MS_ABI instead. >        (ix86_keep_aggregate_return_pointer): Optimize for 64-bit case >        and change default behavior for 32-bit MS_ABI. >        (ix86_reg_parm_stack_space): Check additionally for bit-ness. >        (ix86_function_type_abi): Allow check for ms_abi/sysv_abi for >        32-bit, too. >        (ix86_cfun_abi): Likewise. >        (ix86_maybe_switch_abi): Adjust comment. >        (init_cumulative_args): Check for bit-ness in MS_ABI case. >        (ix86_gimplify_va_arg): Check just for not TARGET_64BIT_MS_ABI >        instead of checking for SYSV_ABI. >        (ix86_nsaved_sseregs): Likewise. >        (ix86_compute_frame_layout): Set only for 64-bit MS_ABI alignment >        to 16 bytes. >        (ix86_expand_call): Use TARGET_64BIT_MS_ABI macro. >        * config/i386.h (TARGET_32BIT_MS_ABI): New macro. >        (ACCUMULATE_OUTGOING_ARGS): Check explicit for 64-bit MS_ABI. >        (OUTGOING_REG_PARM_STACK_SPACE): Likewise. >        * config/mingw32.h (DEFAULT_ABI): Change default always to MS_ABI. > > Tested for x86_64-w64-mingw32, i686-pc-cygwin, and i686-w64-mingw32. > Ok for apply? > > Regards, > Kai > Duh, and here with patch. Kai Index: gcc/gcc/config/i386/cygming.h =================================================================== --- gcc.orig/gcc/config/i386/cygming.h 2011-03-24 17:56:00.289173500 +0100 +++ gcc/gcc/config/i386/cygming.h 2011-03-24 18:08:42.894925500 +0100 @@ -84,7 +84,7 @@ along with GCC; see the file COPYING3. (TARGET_64BIT ? dbx64_register_map[(n)] \ : svr4_dbx_register_map[(n)]) -/* The MS_ABI changes the set of call-used registers. */ +/* The 64-bit MS_ABI changes the set of call-used registers. */ #undef DWARF_FRAME_REGISTERS #define DWARF_FRAME_REGISTERS (TARGET_64BIT ? 33 : 17) @@ -262,7 +262,7 @@ do { \ #define CHECK_STACK_LIMIT 4000 #undef STACK_BOUNDARY -#define STACK_BOUNDARY (ix86_abi == MS_ABI ? 128 : BITS_PER_WORD) +#define STACK_BOUNDARY (TARGET_64BIT && ix86_abi == MS_ABI ? 128 : BITS_PER_WORD) /* By default, target has a 80387, uses IEEE compatible arithmetic, returns float values in the 387 and needs stack probes. Index: gcc/gcc/config/i386/i386.c =================================================================== --- gcc.orig/gcc/config/i386/i386.c 2011-03-24 17:56:00.312173500 +0100 +++ gcc/gcc/config/i386/i386.c 2011-03-24 18:08:42.916428200 +0100 @@ -4347,8 +4347,8 @@ ix86_conditional_register_usage (void) if (j != INVALID_REGNUM) fixed_regs[j] = call_used_regs[j] = 1; - /* The MS_ABI changes the set of call-used registers. */ - if (TARGET_64BIT && ix86_cfun_abi () == MS_ABI) + /* The 64-bit MS_ABI changes the set of call-used registers. */ + if (TARGET_64BIT_MS_ABI) { call_used_regs[SI_REG] = 0; call_used_regs[DI_REG] = 0; @@ -5607,11 +5607,18 @@ ix86_keep_aggregate_return_pointer (tree { tree attr; - attr = lookup_attribute ("callee_pop_aggregate_return", - TYPE_ATTRIBUTES (fntype)); - if (attr) - return (TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr))) == 0); + if (!TARGET_64BIT) + { + attr = lookup_attribute ("callee_pop_aggregate_return", + TYPE_ATTRIBUTES (fntype)); + if (attr) + return (TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr))) == 0); + /* For 32-bit MS-ABI the default is to keep aggregate + return pointer. */ + if (ix86_function_type_abi (fntype) == MS_ABI) + return true; + } return KEEP_AGGREGATE_RETURN_POINTER != 0; } @@ -5748,7 +5755,7 @@ ix86_reg_parm_stack_space (const_tree fn call_abi = ix86_function_abi (fndecl); else call_abi = ix86_function_type_abi (fndecl); - if (call_abi == MS_ABI) + if (TARGET_64BIT && call_abi == MS_ABI) return 32; return 0; } @@ -5758,7 +5765,7 @@ ix86_reg_parm_stack_space (const_tree fn enum calling_abi ix86_function_type_abi (const_tree fntype) { - if (TARGET_64BIT && fntype != NULL) + if (fntype != NULL) { enum calling_abi abi = ix86_abi; if (abi == SYSV_ABI) @@ -5800,7 +5807,7 @@ ix86_function_abi (const_tree fndecl) enum calling_abi ix86_cfun_abi (void) { - if (! cfun || ! TARGET_64BIT) + if (! cfun) return ix86_abi; return cfun->machine->call_abi; } @@ -5863,9 +5870,9 @@ ix86_call_abi_override (const_tree fndec cfun->machine->call_abi = ix86_function_type_abi (TREE_TYPE (fndecl)); } -/* MS and SYSV ABI have different set of call used registers. Avoid expensive - re-initialization of init_regs each time we switch function context since - this is needed only during RTL expansion. */ +/* 64-bit MS and SYSV ABI have different set of call used registers. Avoid + expensive re-initialization of init_regs each time we switch function context + since this is needed only during RTL expansion. */ static void ix86_maybe_switch_abi (void) { @@ -5931,7 +5938,7 @@ init_cumulative_args (CUMULATIVE_ARGS *c /* Set up the number of registers to use for passing arguments. */ - if (cum->call_abi == MS_ABI && !ACCUMULATE_OUTGOING_ARGS) + if (TARGET_64BIT && cum->call_abi == MS_ABI && !ACCUMULATE_OUTGOING_ARGS) sorry ("ms_abi attribute requires -maccumulate-outgoing-args " "or subtarget optimization implying it"); cum->nregs = ix86_regparm; @@ -8179,7 +8186,7 @@ ix86_gimplify_va_arg (tree valist, tree case V4DFmode: case V4DImode: /* Unnamed 256bit vector mode parameters are passed on stack. */ - if (ix86_cfun_abi () == SYSV_ABI) + if (!TARGET_64BIT_MS_ABI) { container = NULL; break; @@ -9095,7 +9102,7 @@ ix86_nsaved_sseregs (void) int nregs = 0; int regno; - if (ix86_cfun_abi () != MS_ABI) + if (!TARGET_64BIT_MS_ABI) return 0; for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true)) @@ -9207,9 +9214,9 @@ ix86_compute_frame_layout (struct ix86_f stack_alignment_needed = crtl->stack_alignment_needed / BITS_PER_UNIT; preferred_alignment = crtl->preferred_stack_boundary / BITS_PER_UNIT; - /* MS ABI seem to require stack alignment to be always 16 except for function - prologues and leaf. */ - if ((ix86_cfun_abi () == MS_ABI && preferred_alignment < 16) + /* 64-bit MS ABI seem to require stack alignment to be always 16 except for + function prologues and leaf. */ + if ((TARGET_64BIT_MS_ABI && preferred_alignment < 16) && (!current_function_is_leaf || cfun->calls_alloca != 0 || ix86_current_function_calls_tls_descriptor)) { @@ -21873,8 +21880,7 @@ ix86_expand_call (rtx retval, rtx fnaddr pop = gen_rtx_SET (VOIDmode, stack_pointer_rtx, pop); call = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, call, pop)); } - if (TARGET_64BIT - && ix86_cfun_abi () == MS_ABI + if (TARGET_64BIT_MS_ABI && (!callarg2 || INTVAL (callarg2) != -2)) { /* We need to represent that SI and DI registers are clobbered Index: gcc/gcc/config/i386/i386.h =================================================================== --- gcc.orig/gcc/config/i386/i386.h 2011-03-24 17:56:00.320173500 +0100 +++ gcc/gcc/config/i386/i386.h 2011-03-24 18:08:42.962934100 +0100 @@ -497,6 +497,9 @@ extern tree x86_mfence; /* For the Windows 64-bit ABI. */ #define TARGET_64BIT_MS_ABI (TARGET_64BIT && ix86_cfun_abi () == MS_ABI) +/* For the Windows 32-bit ABI. */ +#define TARGET_32BIT_MS_ABI (!TARGET_64BIT && ix86_cfun_abi () == MS_ABI) + /* This is re-defined by cygming.h. */ #define TARGET_SEH 0 @@ -1439,12 +1442,12 @@ enum reg_class No space will be pushed onto the stack for each call; instead, the function prologue should increase the stack frame size by this amount. - MS ABI seem to require 16 byte alignment everywhere except for function - prologue and apilogue. This is not possible without + 64-bit MS ABI seem to require 16 byte alignment everywhere except for + function prologue and apilogue. This is not possible without ACCUMULATE_OUTGOING_ARGS. */ #define ACCUMULATE_OUTGOING_ARGS \ - (TARGET_ACCUMULATE_OUTGOING_ARGS || ix86_cfun_abi () == MS_ABI) + (TARGET_ACCUMULATE_OUTGOING_ARGS || TARGET_64BIT_MS_ABI) /* If defined, a C expression whose value is nonzero when we want to use PUSH instructions to pass outgoing arguments. */ @@ -1470,7 +1473,7 @@ enum reg_class #define REG_PARM_STACK_SPACE(FNDECL) ix86_reg_parm_stack_space (FNDECL) #define OUTGOING_REG_PARM_STACK_SPACE(FNTYPE) \ - (ix86_function_type_abi (FNTYPE) == MS_ABI) + (TARGET_64BIT && ix86_function_type_abi (FNTYPE) == MS_ABI) /* Define how to find the value returned by a library function assuming the value has mode MODE. */ Index: gcc/gcc/config/i386/mingw32.h =================================================================== --- gcc.orig/gcc/config/i386/mingw32.h 2011-03-24 17:56:00.346173500 +0100 +++ gcc/gcc/config/i386/mingw32.h 2011-03-24 18:08:42.978436100 +0100 @@ -26,6 +26,9 @@ along with GCC; see the file COPYING3. #define TARGET_VERSION fprintf (stderr," (x86 MinGW)"); #endif +#undef DEFAULT_ABI +#define DEFAULT_ABI MS_ABI + /* See i386/crtdll.h for an alternative definition. _INTEGRAL_MAX_BITS is for compatibility with native compiler. */ #define EXTRA_OS_CPP_BUILTINS() \