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]

Fix PRINT_REG problem on x86-64


As I mentioned on the GCC list, dumping RTL on x86-64 will crash a lot of
the time when wide FP or complex modes are used because the RTL can have
registers (especially in notes) that are not valid for the assembler.

I looked into the history of PRINT_REG and saw that the only other place
it was ever used is in dwarfout.c, which has now been eliminated, and the
only port that defines it is i386.

So I think below is the best way to fix the problem and that's what I've
commited.  This was tested by taking RTL dumps and doing a bootstrap on
x86-64.  This also writes the register number as both an integer and name
in the dump files.  It used to do this and I think it's a good thing to
do, especially on machines like x86 where registers have names.  I briefly
considered adding a DEBUG_PRINT_REGNUM macro to allow ports to individually
specify if the register number is to be printed, but this didn't seem
worth the effort.

2003-12-31  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>

	* print-rtl.c (print_rtx): For hard register, write out register
	number and register name instead of calling PRINT_REG.
	* defaults.h (PRINT_REG): Deleted.
	* config/i386/i386.c (print_reg): Remove handling of CODE of -1.
	Move comments here from i386.h.
	(print_operand, print_operand_address): Call print_reg directly.
	* config/i386/i386.h (PRINT_REG): Deleted.

*** gcc/print-rtl.c	2 Nov 2003 19:47:56 -0000	1.103
--- gcc/print-rtl.c	31 Dec 2003 18:41:24 -0000
*************** print_rtx (rtx in_rtx)
*** 385,392 ****
  #ifndef GENERATOR_FILE
  	    if (GET_CODE (in_rtx) == REG && value < FIRST_PSEUDO_REGISTER)
! 	      {
! 		fputc (' ', outfile);
! 		PRINT_REG (in_rtx, -1, outfile);
! 	      }
  	    else if (GET_CODE (in_rtx) == REG
  		     && value <= LAST_VIRTUAL_REGISTER)
--- 385,390 ----
  #ifndef GENERATOR_FILE
  	    if (GET_CODE (in_rtx) == REG && value < FIRST_PSEUDO_REGISTER)
! 	      fprintf (outfile, " %d %s", REGNO (in_rtx),
! 		       reg_names[REGNO (in_rtx)]);
  	    else if (GET_CODE (in_rtx) == REG
  		     && value <= LAST_VIRTUAL_REGISTER)
*** gcc/defaults.h	24 Dec 2003 00:14:18 -0000	1.121
--- gcc/defaults.h	31 Dec 2003 18:41:25 -0000
*************** You Lose!  You must define PREFERRED_DEB
*** 680,689 ****
  #endif
  
- /* How to print out a register name.  */
- #ifndef PRINT_REG
- #define PRINT_REG(RTX, CODE, FILE) \
-   fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
- #endif
- 
  #ifndef LOCAL_REGNO
  #define LOCAL_REGNO(REGNO)  0
--- 680,683 ----
*** gcc/config/i386/i386.c	30 Dec 2003 23:05:10 -0000	1.627
--- gcc/config/i386/i386.c	31 Dec 2003 18:41:35 -0000
*************** put_condition_code (enum rtx_code code, 
*** 6969,6983 ****
  }
  
  void
  print_reg (rtx x, int code, FILE *file)
  {
!   /* Code -1 indicates we are called from print_rtx, and it is not
!      an error for a virtual register to appear here.  */
!   if (code == -1)
!     code = 0;
!   else if (REGNO (x) == ARG_POINTER_REGNUM
! 	   || REGNO (x) == FRAME_POINTER_REGNUM
! 	   || REGNO (x) == FLAGS_REG
! 	   || REGNO (x) == FPSR_REG)
      abort ();
  
--- 6969,6987 ----
  }
  
+ /* Print the name of register X to FILE based on its machine mode and number.
+    If CODE is 'w', pretend the mode is HImode.
+    If CODE is 'b', pretend the mode is QImode.
+    If CODE is 'k', pretend the mode is SImode.
+    If CODE is 'q', pretend the mode is DImode.
+    If CODE is 'h', pretend the reg is the `high' byte register.
+    If CODE is 'y', print "st(0)" instead of "st", if the reg is stack op.  */
+ 
  void
  print_reg (rtx x, int code, FILE *file)
  {
!   if (REGNO (x) == ARG_POINTER_REGNUM
!       || REGNO (x) == FRAME_POINTER_REGNUM
!       || REGNO (x) == FLAGS_REG
!       || REGNO (x) == FPSR_REG)
      abort ();
  
*************** print_operand (FILE *file, rtx x, int co
*** 7390,7396 ****
  
    if (GET_CODE (x) == REG)
!     {
!       PRINT_REG (x, code, file);
!     }
  
    else if (GET_CODE (x) == MEM)
--- 7394,7398 ----
  
    if (GET_CODE (x) == REG)
!     print_reg (x, code, file);
  
    else if (GET_CODE (x) == MEM)
*************** print_operand_address (FILE *file, rtx a
*** 7571,7579 ****
  	  putc ('(', file);
  	  if (base)
! 	    PRINT_REG (base, 0, file);
  	  if (index)
  	    {
  	      putc (',', file);
! 	      PRINT_REG (index, 0, file);
  	      if (scale != 1)
  		fprintf (file, ",%d", scale);
--- 7573,7581 ----
  	  putc ('(', file);
  	  if (base)
! 	    print_reg (base, 0, file);
  	  if (index)
  	    {
  	      putc (',', file);
! 	      print_reg (index, 0, file);
  	      if (scale != 1)
  		fprintf (file, ",%d", scale);
*************** print_operand_address (FILE *file, rtx a
*** 7610,7614 ****
  	  if (base)
  	    {
! 	      PRINT_REG (base, 0, file);
  	      if (offset)
  		{
--- 7612,7616 ----
  	  if (base)
  	    {
! 	      print_reg (base, 0, file);
  	      if (offset)
  		{
*************** print_operand_address (FILE *file, rtx a
*** 7626,7630 ****
  	    {
  	      putc ('+', file);
! 	      PRINT_REG (index, 0, file);
  	      if (scale != 1)
  		fprintf (file, "*%d", scale);
--- 7628,7632 ----
  	    {
  	      putc ('+', file);
! 	      print_reg (index, 0, file);
  	      if (scale != 1)
  		fprintf (file, "*%d", scale);
*** gcc/config/i386/i386.h	31 Dec 2003 05:30:59 -0000	1.364
--- gcc/config/i386/i386.h	31 Dec 2003 18:41:38 -0000
*************** do {							\
*** 2721,2725 ****
  
     For float regs, the stack top is sometimes referred to as "%st(0)"
!    instead of just "%st".  PRINT_REG handles this with the "y" code.  */
  
  #define HI_REGISTER_NAMES						\
--- 2721,2725 ----
  
     For float regs, the stack top is sometimes referred to as "%st(0)"
!    instead of just "%st".  PRINT_OPERAND handles this with the "y" code.  */
  
  #define HI_REGISTER_NAMES						\
*************** do {									\
*** 2871,2886 ****
  #define PRINT_OPERAND_PUNCT_VALID_P(CODE) \
    ((CODE) == '*' || (CODE) == '+' || (CODE) == '&')
- 
- /* Print the name of a register based on its machine mode and number.
-    If CODE is 'w', pretend the mode is HImode.
-    If CODE is 'b', pretend the mode is QImode.
-    If CODE is 'k', pretend the mode is SImode.
-    If CODE is 'q', pretend the mode is DImode.
-    If CODE is 'h', pretend the reg is the `high' byte register.
-    If CODE is 'y', print "st(0)" instead of "st", if the reg is stack op.
-    If CODE is -1, it is not an error for X to be a virtual register.  */
- 
- #define PRINT_REG(X, CODE, FILE)  \
-   print_reg ((X), (CODE), (FILE))
  
  #define PRINT_OPERAND(FILE, X, CODE)  \
--- 2871,2874 ----


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