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]

[PATCH] S/390: Replace HARD_REGNO_MODE_OK and co by c-functions


Hi,

the S/390 back end macro HARD_REGNO_MODE_OK was defined using
several "? :" operators and over time has lost human readablity. The attached
patch moves the logic of this macro, the HARD_REGNO_NREGS and CLASS_MAX_NREGS
macros into c-functions in s390.c.

Bootstrapped on s390 and s390x.
No testsuite regressions.

OK for mainline?

Bye,

-Andreas-


2006-03-27  Andreas Krebbel  <krebbel1@de.ibm.com>

	* config/s390/s390-protos.h (s390_hard_regno_mode_ok, 
	s390_class_max_nregs): New function prototypes.
	* config/s390/s390.c (REGNO_PAIR_OK): New macro.
	(s390_hard_regno_mode_ok, s390_class_max_nregs): New functions.
	* config/s390/s390.h (HARD_REGNO_NREGS, HARD_REGNO_MODE_OK,
	CLASS_MAX_NREGS): Macro bodies replaced by function calls.


Index: gcc/config/s390/s390-protos.h
===================================================================
*** gcc/config/s390/s390-protos.h.orig	2006-03-23 14:38:35.000000000 +0100
--- gcc/config/s390/s390-protos.h	2006-03-23 14:44:27.000000000 +0100
*************** extern void s390_emit_epilogue (bool);
*** 30,36 ****
--- 30,38 ----
  extern void s390_function_profiler (FILE *, int);
  extern void s390_conditional_register_usage (void);
  extern void s390_set_has_landing_pad_p (bool);
+ extern bool s390_hard_regno_mode_ok (unsigned int, enum machine_mode);
  extern bool s390_hard_regno_rename_ok (unsigned int, unsigned int);
+ extern bool s390_class_max_nregs (enum reg_class, enum machine_mode);
  
  #ifdef RTX_CODE
  extern int s390_extra_constraint_str (rtx, int, const char *);
Index: gcc/config/s390/s390.c
===================================================================
*** gcc/config/s390/s390.c.orig	2006-03-23 14:38:35.000000000 +0100
--- gcc/config/s390/s390.c	2006-03-23 14:47:13.000000000 +0100
*************** struct machine_function GTY(())
*** 331,336 ****
--- 331,339 ----
  #define CONST_OK_FOR_On(x) \
          CONST_OK_FOR_CONSTRAINT_P((x), 'O', "On")
  
+ #define REGNO_PAIR_OK(REGNO, MODE)                               \
+   (HARD_REGNO_NREGS ((REGNO), (MODE)) == 1 || !((REGNO) & 1))
+ 
  /* Set the has_landing_pad_p flag in struct machine_function to VALUE.  */
  
  void
*************** s390_update_frame_layout (void)
*** 6744,6749 ****
--- 6747,6800 ----
      regs_ever_live[REGNO (cfun->machine->base_reg)] = 1;
  }
  
+ /* Return true if it is legal to put a value with MODE into REGNO.  */
+ 
+ bool
+ s390_hard_regno_mode_ok (unsigned int regno, enum machine_mode mode)
+ {
+   switch (REGNO_REG_CLASS (regno))
+     {
+     case FP_REGS:
+       if (REGNO_PAIR_OK (regno, mode))
+ 	{
+ 	  if (mode == SImode || mode == DImode)
+ 	    return true;
+ 
+ 	  if (FLOAT_MODE_P (mode) && GET_MODE_CLASS (mode) != MODE_VECTOR_FLOAT)
+ 	    return true;
+ 	}
+       break;
+     case ADDR_REGS:
+       if (FRAME_REGNO_P (regno) && mode == Pmode)
+ 	return true;
+ 
+       /* fallthrough */
+     case GENERAL_REGS:
+       if (REGNO_PAIR_OK (regno, mode))
+ 	{
+ 	  if (TARGET_64BIT 
+ 	      || (mode != TFmode && mode != TCmode))
+ 	    return true;
+ 	}	  
+       break;
+     case CC_REGS:
+       if (GET_MODE_CLASS (mode) == MODE_CC)
+ 	return true;
+       break;
+     case ACCESS_REGS:
+       if (REGNO_PAIR_OK (regno, mode))
+ 	{
+ 	  if (mode == SImode || mode == Pmode)
+ 	    return true;
+ 	}
+       break;
+     default:
+       return false;
+     }
+   
+   return false;
+ }
+ 
  /* Return nonzero if register OLD_REG can be renamed to register NEW_REG.  */
  
  bool
*************** s390_hard_regno_rename_ok (unsigned int 
*** 6759,6764 ****
--- 6810,6836 ----
    return true;
  }
  
+ /* Maximum number of registers to represent a value of mode MODE
+    in a register of class CLASS.  */
+ 
+ bool
+ s390_class_max_nregs (enum reg_class class, enum machine_mode mode)
+ {
+   switch (class)
+     {
+     case FP_REGS:
+       if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
+ 	return 2 * ((GET_MODE_SIZE (mode) / 2 + 8 - 1) / 8);
+       else
+ 	return (GET_MODE_SIZE (mode) + 8 - 1) / 8;
+     case ACCESS_REGS:
+       return (GET_MODE_SIZE (mode) + 4 - 1) / 4;
+     default:
+       break;
+     }
+   return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
+ }
+ 
  /* Return true if register FROM can be eliminated via register TO.  */
  
  bool
Index: gcc/config/s390/s390.h
===================================================================
*** gcc/config/s390/s390.h.orig	2006-03-23 14:38:35.000000000 +0100
--- gcc/config/s390/s390.h	2006-03-23 14:44:27.000000000 +0100
*************** if (INTEGRAL_MODE_P (MODE) &&	        	 
*** 355,390 ****
  
     Condition code modes fit only into the CC register.  */
  
  #define HARD_REGNO_NREGS(REGNO, MODE)                           \
!   (FP_REGNO_P(REGNO)?                                           \
!    (GET_MODE_CLASS(MODE) == MODE_COMPLEX_FLOAT ?                \
!     2 * ((GET_MODE_SIZE(MODE) / 2 + 8 - 1) / 8) : 		\
!     ((GET_MODE_SIZE(MODE) + 8 - 1) / 8)) :			\
!    GENERAL_REGNO_P(REGNO)?                                      \
!     ((GET_MODE_SIZE(MODE)+UNITS_PER_WORD-1) / UNITS_PER_WORD) : \
!    ACCESS_REGNO_P(REGNO)?					\
!     ((GET_MODE_SIZE(MODE) + 4 - 1) / 4) : 			\
!    1)
! 
! #define HARD_REGNO_MODE_OK(REGNO, MODE)                             \
!   (FP_REGNO_P(REGNO)?                                               \
!    (((MODE) == SImode || (MODE) == DImode                           \
!      || GET_MODE_CLASS(MODE) == MODE_FLOAT                          \
!      || GET_MODE_CLASS(MODE) == MODE_COMPLEX_FLOAT)                 \
!     && (HARD_REGNO_NREGS(REGNO, MODE) == 1 || !((REGNO) & 1))) :    \
!    GENERAL_REGNO_P(REGNO)?                                          \
!    ((HARD_REGNO_NREGS(REGNO, MODE) == 1 || !((REGNO) & 1))	    \
!     && (((MODE) != TFmode && (MODE) != TCmode) || TARGET_64BIT)) :  \
!    CC_REGNO_P(REGNO)?                                               \
!      GET_MODE_CLASS (MODE) == MODE_CC :                             \
!    FRAME_REGNO_P(REGNO)?                                            \
!      (enum machine_mode) (MODE) == Pmode :                          \
!    ACCESS_REGNO_P(REGNO)?					    \
!      (((MODE) == SImode || ((enum machine_mode) (MODE) == Pmode))   \
!       && (HARD_REGNO_NREGS(REGNO, MODE) == 1 || !((REGNO) & 1))) :  \
!    0)
  
! #define HARD_REGNO_RENAME_OK(FROM, TO) \
    s390_hard_regno_rename_ok (FROM, TO)
  
  #define MODES_TIEABLE_P(MODE1, MODE2)		\
--- 355,369 ----
  
     Condition code modes fit only into the CC register.  */
  
+ /* Because all registers in a class have the same size HARD_REGNO_NREGS
+    is equivalent to CLASS_MAX_NREGS.  */
  #define HARD_REGNO_NREGS(REGNO, MODE)                           \
!   s390_class_max_nregs (REGNO_REG_CLASS (REGNO), (MODE))
  
! #define HARD_REGNO_MODE_OK(REGNO, MODE)         \
!   s390_hard_regno_mode_ok ((REGNO), (MODE))
! 
! #define HARD_REGNO_RENAME_OK(FROM, TO)          \
    s390_hard_regno_rename_ok (FROM, TO)
  
  #define MODES_TIEABLE_P(MODE1, MODE2)		\
*************** if (INTEGRAL_MODE_P (MODE) &&	        	 
*** 394,406 ****
  /* Maximum number of registers to represent a value of mode MODE
     in a register of class CLASS.  */
  #define CLASS_MAX_NREGS(CLASS, MODE)   					\
!      ((CLASS) == FP_REGS ? 						\
!       (GET_MODE_CLASS(MODE) == MODE_COMPLEX_FLOAT ?                     \
!        2 * (GET_MODE_SIZE (MODE) / 2 + 8 - 1) / 8 :		        \
!        (GET_MODE_SIZE (MODE) + 8 - 1) / 8) :				\
!       (CLASS) == ACCESS_REGS ?						\
!       (GET_MODE_SIZE (MODE) + 4 - 1) / 4 :				\
!       (GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
  
  /* If a 4-byte value is loaded into a FPR, it is placed into the
     *upper* half of the register, not the lower.  Therefore, we
--- 373,379 ----
  /* Maximum number of registers to represent a value of mode MODE
     in a register of class CLASS.  */
  #define CLASS_MAX_NREGS(CLASS, MODE)   					\
!   s390_class_max_nregs ((CLASS), (MODE))
  
  /* If a 4-byte value is loaded into a FPR, it is placed into the
     *upper* half of the register, not the lower.  Therefore, we


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