Fix x86-64 profiling

Jan Hubicka jh@suse.cz
Tue Jun 4 06:07:00 GMT 2002


Hi,
this patch makes the x86-64 function profiling code at least acceptable
for assemlber.  Hope it is valid too.
I am passing the argument in r11 that is caller saved and unused
otherwise.
I also had to fix PUSH/POP macros, even when I don't think they are
needed, as they are used to save/restore link pointer that may be done
by mcout as well... 

Tue Jun  4 15:03:35 CEST 2002  Jan Hubicka  <jh@suse.cz>
	* i386-protos.h (x86_function_profiler):  Declare
	* i386.h (ASM_OUTPUT_REG_PUSH, ASM_OUTPUT_REG_POP): Fix for 64bits.
	(FUNCTION_PROFILER): Move offline to ...
	* i386.c (x86_function_profiler): ... here; support 64bit profiling
Index: i386-protos.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/i386-protos.h,v
retrieving revision 1.74
diff -c -3 -p -r1.74 i386-protos.h
*** i386-protos.h	23 May 2002 21:55:25 -0000	1.74
--- i386-protos.h	2 Jun 2002 12:26:24 -0000
*************** extern void ix86_set_move_mem_attrs PARA
*** 177,182 ****
--- 177,183 ----
  extern void emit_i387_cw_initialization PARAMS ((rtx, rtx));
  extern bool ix86_fp_jump_nontrivial_p PARAMS ((enum rtx_code));
  extern void x86_order_regs_for_local_alloc PARAMS ((void));
+ extern void x86_function_profiler PARAMS ((FILE *, int));
  
  
  #ifdef TREE_CODE
Index: i386.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/i386.c,v
retrieving revision 1.418
diff -c -3 -p -r1.418 i386.c
*** i386.c	31 May 2002 11:54:11 -0000	1.418
--- i386.c	2 Jun 2002 12:26:30 -0000
*************** x86_output_mi_thunk (file, delta, functi
*** 13948,13950 ****
--- 13948,13982 ----
  	}
      }
  }
+ 
+ /* Output assembler code to FILE to increment profiler label # LABELNO
+    for profiling a function entry.  */
+ void
+ x86_function_profiler (file, labelno)
+      FILE *file;
+      int labelno;
+ {
+   if (TARGET_64BIT)
+     if (flag_pic)
+       {
+ 	fprintf (file, "\tleaq\t%sP%d@(%%rip),%%r11\n",
+ 		 LPREFIX, labelno);
+ 	fprintf (file, "\tcall\t*_mcount@GOTPCREL(%%rip)\n");
+       }
+     else
+       {
+ 	fprintf (file, "\tmovq\t$%sP%d,%%r11\n", LPREFIX, labelno);
+ 	fprintf (file, "\tcall\t_mcount\n");
+       }
+   else if (flag_pic)
+     {
+       fprintf (file, "\tleal\t%sP%d@GOTOFF(%%ebx),%%edx\n",
+ 	       LPREFIX, labelno);
+       fprintf (file, "\tcall\t*_mcount@GOT(%%ebx)\n");
+     }
+   else
+     {
+       fprintf (file, "\tmovl\t$%sP%d,%%edx\n", LPREFIX, labelno);
+       fprintf (file, "\tcall\t_mcount\n");
+     }
+ }
Index: i386.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/i386.h,v
retrieving revision 1.266
diff -c -3 -p -r1.266 i386.h
*** i386.h	30 May 2002 00:38:36 -0000	1.266
--- i386.h	2 Jun 2002 12:26:32 -0000
*************** typedef struct ix86_args {
*** 1718,1737 ****
  /* Output assembler code to FILE to increment profiler label # LABELNO
     for profiling a function entry.  */
  
! #define FUNCTION_PROFILER(FILE, LABELNO)				\
! do {									\
!   if (flag_pic)								\
!     {									\
!       fprintf ((FILE), "\tleal\t%sP%d@GOTOFF(%%ebx),%%edx\n",		\
! 	       LPREFIX, (LABELNO));					\
!       fprintf ((FILE), "\tcall\t*_mcount@GOT(%%ebx)\n");		\
!     }									\
!   else									\
!     {									\
!       fprintf ((FILE), "\tmovl\t$%sP%d,%%edx\n", LPREFIX, (LABELNO));	\
!       fprintf ((FILE), "\tcall\t_mcount\n");				\
!     }									\
! } while (0)
  
  /* EXIT_IGNORE_STACK should be nonzero if, when returning from a function,
     the stack pointer does not matter.  The value is tested only in
--- 1718,1724 ----
  /* Output assembler code to FILE to increment profiler label # LABELNO
     for profiling a function entry.  */
  
! #define FUNCTION_PROFILER(FILE, LABELNO) x86_function_profiler (FILE, LABELNO)
  
  /* EXIT_IGNORE_STACK should be nonzero if, when returning from a function,
     the stack pointer does not matter.  The value is tested only in
*************** extern int const svr4_dbx_register_map[F
*** 3009,3022 ****
  /* This is how to output an insn to push a register on the stack.
     It need not be very fast code.  */
  
! #define ASM_OUTPUT_REG_PUSH(FILE, REGNO)  \
!   asm_fprintf ((FILE), "\tpush{l}\t%%e%s\n", reg_names[(REGNO)])
  
  /* This is how to output an insn to pop a register from the stack.
     It need not be very fast code.  */
  
  #define ASM_OUTPUT_REG_POP(FILE, REGNO)  \
!   asm_fprintf ((FILE), "\tpop{l}\t%%e%s\n", reg_names[(REGNO)])
  
  /* This is how to output an element of a case-vector that is absolute.  */
  
--- 2996,3017 ----
  /* This is how to output an insn to push a register on the stack.
     It need not be very fast code.  */
  
! #define ASM_OUTPUT_REG_PUSH(FILE, REGNO)			   \
!   if (TARGET_64BIT)						   \
!     asm_fprintf ((FILE), "\tpush{q}\t%%%s%s\n",			   \
! 		 (REGNO) < 8 ? "r" :"", reg_names[(REGNO)]);	   \
!   else								   \
!     asm_fprintf ((FILE), "\tpush{l}\t%%e%s\n", reg_names[(REGNO)])
  
  /* This is how to output an insn to pop a register from the stack.
     It need not be very fast code.  */
  
  #define ASM_OUTPUT_REG_POP(FILE, REGNO)  \
!   if (TARGET_64BIT)						   \
!     asm_fprintf ((FILE), "\tpop{q}\t%%%s%s\n",			   \
! 		 (REGNO) < 8 ? "r" :"", reg_names[(REGNO)]);	   \
!   else								   \
!     asm_fprintf ((FILE), "\tpop{l}\t%%e%s\n", reg_names[(REGNO)])
  
  /* This is how to output an element of a case-vector that is absolute.  */
  



More information about the Gcc-patches mailing list