This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

sysv/ms_abi attribute fix, part 4, proper initialization of call_used_regs


Hi,
this patch makes call_used_regs right when compiling foreign function.  Problem
in previous incarnation was that while ix86_call_abi_override properly set the
call_used_regs, the regclass again used CONDITIONAL_REGISTER_USAGE to fill in
the table before it computed other derrived things.  This was conflict in between
machine specific stuff and ABI attributes that was developed in parallel.

This patch solves it by making CONDITIONAL_REGISTER_USAGE do the right thing based
on cfun.  I do not trigger expensive target_reinit each time we switch ABIs since
we do this many times during IPA compilation and we don't need to do all the busy
recomputation.  Recomputation is triggered by TARGET_EXPAND_TO_RTL_HOOK at a
time we go to RTL.

Bootstrapped/regtested i686-linux, will commit it tomorrow if there are no complains.

	Jan Hubicka  <jh@suse.cz>
	Kai Tietz <kai.tietz@onevision.com>
	* i386.h (CONDITIONAL_REGISTER_USAGE): Initialize for current function ABI.
	* i386.c (ix86_call_abi_override): Do not trigger target re-init and do not
	try to modify call used regs.
	(ix86_maybe_switch_abi): New function.
	(TARGET_EXPAND_TO_RTL_HOOK): New macro.
Index: config/i386/i386.h
===================================================================
*** config/i386/i386.h	(revision 142597)
--- config/i386/i386.h	(working copy)
*************** do {									\
*** 964,970 ****
  	for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)		\
  	  reg_names[i] = "";						\
        }									\
!     if (TARGET_64BIT && DEFAULT_ABI == MS_ABI)				\
        {									\
          call_used_regs[4 /*RSI*/] = 0;                                  \
          call_used_regs[5 /*RDI*/] = 0;                                  \
--- 964,972 ----
  	for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)		\
  	  reg_names[i] = "";						\
        }									\
!     if (TARGET_64BIT							\
!         && ((cfun && cfun->machine->call_abi == MS_ABI)			\
!             || (!cfun && DEFAULT_ABI == MS_ABI)))			\
        {									\
          call_used_regs[4 /*RSI*/] = 0;                                  \
          call_used_regs[5 /*RDI*/] = 0;                                  \
Index: config/i386/i386.c
===================================================================
*** config/i386/i386.c	(revision 142597)
--- config/i386/i386.c	(working copy)
*************** extern void init_regs (void);
*** 4600,4608 ****
  
  /* Implementation of call abi switching target hook. Specific to FNDECL
     the specific call register sets are set. See also CONDITIONAL_REGISTER_USAGE
!    for more details.
!    To prevent redudant calls of costy function init_regs (), it checks not to
!    reset register usage for default abi.  */
  void
  ix86_call_abi_override (const_tree fndecl)
  {
--- 4605,4611 ----
  
  /* Implementation of call abi switching target hook. Specific to FNDECL
     the specific call register sets are set. See also CONDITIONAL_REGISTER_USAGE
!    for more details.  */
  void
  ix86_call_abi_override (const_tree fndecl)
  {
*************** ix86_call_abi_override (const_tree fndec
*** 4610,4633 ****
      cfun->machine->call_abi = DEFAULT_ABI;
    else
      cfun->machine->call_abi = ix86_function_type_abi (TREE_TYPE (fndecl));
!   if (TARGET_64BIT && cfun->machine->call_abi == MS_ABI)
!     {
!       if (call_used_regs[4 /*RSI*/] != 0 || call_used_regs[5 /*RDI*/] != 0)
!         {
!           call_used_regs[4 /*RSI*/] = 0;
!           call_used_regs[5 /*RDI*/] = 0;
!           init_regs ();
!         }
!     }
!   else if (TARGET_64BIT)
!     {
!       if (call_used_regs[4 /*RSI*/] != 1 || call_used_regs[5 /*RDI*/] != 1)
!         {
!           call_used_regs[4 /*RSI*/] = 1;
!           call_used_regs[5 /*RDI*/] = 1;
!           init_regs ();
!         }
!     }
  }
  
  /* Initialize a variable CUM of type CUMULATIVE_ARGS
--- 4613,4629 ----
      cfun->machine->call_abi = DEFAULT_ABI;
    else
      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.  */
! static void
! ix86_maybe_switch_abi (void)
! {
!   if (TARGET_64BIT &&
!       call_used_regs[4 /*RSI*/] ==  (cfun->machine->call_abi == MS_ABI))
!     init_regs ();
  }
  
  /* Initialize a variable CUM of type CUMULATIVE_ARGS
*************** ix86_enum_va_list (int idx, const char *
*** 29243,29248 ****
--- 29252,29260 ----
  #undef TARGET_OPTION_CAN_INLINE_P
  #define TARGET_OPTION_CAN_INLINE_P ix86_can_inline_p
  
+ #undef TARGET_EXPAND_TO_RTL_HOOK
+ #define TARGET_EXPAND_TO_RTL_HOOK ix86_maybe_switch_abi
+ 
  struct gcc_target targetm = TARGET_INITIALIZER;
  
  #include "gt-i386.h"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]