x86-64 profiling fix
Jan Hubicka
jh@suse.cz
Fri Oct 18 05:00:00 GMT 2002
> On Thu, Oct 17, 2002 at 07:21:52PM +0200, Jan Hubicka wrote:
> > * i386-protos.h (x86_function_profiler): New function
> > * i386.h (OUTPUT_FUNCTION_PROFILER): Move offline to ...
> > * i386.c (x86_function_profiler) ... here; fix 64bit support
>
> Not ok. There are 11 copies of FUNCTION_PROFILER. They
> need to be unified in some manner.
Hi,
here is my working version of the OUTPUT_FUNCTION_PROFILER.
I've stopped on netbsd implementation, that unlike the rest uses @PLT
for call instead of GOTOFF. Why?
Is there some reason why @PLT method does not work elsewhere and works on netbsd?
Honza
Thu Oct 17 19:19:49 CEST 2002 Jan Hubicka <jh@suse.cz>
* i386-protos.h (x86_function_profiler): New function
* i386.h (OUTPUT_FUNCTION_PROFILER): Move offline to ...
(MCOUNT_NAME): New.
(PROFILE_COUNT_REGISTER): New.
* i386.c (x86_function_profiler) ... here; fix 64bit support
* beos-elf.h (OUTPUT_FUNCTION_PROFILER): Kill.
(MCOUNT_NAME): New.
* freebsd-aout.h (OUTPUT_FUNCTION_PROFILER): Kill.
(MCOUNT_NAME): New.
(PROFILE_COUNT_REGISTER): New.
* linux.h (OUTPUT_FUNCTION_PROFILER): Kill.
(MCOUNT_NAME): New.
* x86-64.h (OUTPUT_FUNCTION_PROFILER): Kill.
(MCOUNT_NAME): New.
* freebsd.h (OUTPUT_FUNCTION_PROFILER): Kill.
(MCOUNT_NAME): New.
Index: beos-elf.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/beos-elf.h,v
retrieving revision 1.17
diff -c -3 -p -r1.17 beos-elf.h
*** beos-elf.h 5 Jun 2002 17:01:30 -0000 1.17
--- beos-elf.h 18 Oct 2002 11:10:45 -0000
*************** Boston, MA 02111-1307, USA. */
*** 40,60 ****
/* Output assembler code to FILE to increment profiler label # LABELNO
for profiling a function entry. */
! #undef FUNCTION_PROFILER
! #define FUNCTION_PROFILER(FILE, LABELNO) \
! { \
! if (flag_pic) \
! { \
! fprintf (FILE, "\tleal %sP%d@GOTOFF(%%ebx),%%edx\n", \
! LPREFIX, (LABELNO)); \
! fprintf (FILE, "\tcall *mcount@GOT(%%ebx)\n"); \
! } \
! else \
! { \
! fprintf (FILE, "\tmovl $%sP%d,%%edx\n", LPREFIX, (LABELNO)); \
! fprintf (FILE, "\tcall mcount\n"); \
! } \
! }
#undef SIZE_TYPE
#define SIZE_TYPE "long unsigned int"
--- 40,47 ----
/* Output assembler code to FILE to increment profiler label # LABELNO
for profiling a function entry. */
! #undef MCOUNT_NAME
! #define MCOUNT_NAME "mcount"
#undef SIZE_TYPE
#define SIZE_TYPE "long unsigned int"
Index: freebsd-aout.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/freebsd-aout.h,v
retrieving revision 1.13
diff -c -3 -p -r1.13 freebsd-aout.h
*** freebsd-aout.h 28 Jul 2002 18:44:34 -0000 1.13
--- freebsd-aout.h 18 Oct 2002 11:10:45 -0000
*************** Boston, MA 02111-1307, USA. */
*** 94,115 ****
/* Profiling routines, partially copied from i386/osfrose.h. */
! /* Redefine this to use %eax instead of %edx. */
! #undef FUNCTION_PROFILER
! #define FUNCTION_PROFILER(FILE, LABELNO) \
! { \
! if (flag_pic) \
! { \
! fprintf (FILE, "\tleal %sP%d@GOTOFF(%%ebx),%%eax\n", \
! LPREFIX, (LABELNO)); \
! fprintf (FILE, "\tcall *mcount@GOT(%%ebx)\n"); \
! } \
! else \
! { \
! fprintf (FILE, "\tmovl $%sP%d,%%eax\n", LPREFIX, (LABELNO)); \
! fprintf (FILE, "\tcall mcount\n"); \
! } \
! }
/*
* Some imports from svr4.h in support of shared libraries.
--- 94,103 ----
/* Profiling routines, partially copied from i386/osfrose.h. */
! #undef MCOUNT_NAME
! #define MCOUNT_NAME "mcount"
! #undef PROFILE_COUNT_REGISTER
! #define PROFILE_COUNT_REGISTER "eax"
/*
* Some imports from svr4.h in support of shared libraries.
Index: freebsd.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/freebsd.h,v
retrieving revision 1.32
diff -c -3 -p -r1.32 freebsd.h
*** freebsd.h 12 Apr 2002 01:18:37 -0000 1.32
--- freebsd.h 18 Oct 2002 11:10:45 -0000
*************** Boston, MA 02111-1307, USA. */
*** 47,60 ****
/* Tell final.c that we don't need a label passed to mcount. */
! #undef FUNCTION_PROFILER
! #define FUNCTION_PROFILER(FILE, LABELNO) \
! { \
! if (flag_pic) \
! fprintf ((FILE), "\tcall *.mcount@GOT(%%ebx)\n"); \
! else \
! fprintf ((FILE), "\tcall .mcount\n"); \
! }
/* Make gcc agree with <machine/ansi.h>. */
--- 47,54 ----
/* Tell final.c that we don't need a label passed to mcount. */
! #undef MCOUNT_NAME
! #define MCOUNT_NAME ".mcount"
/* Make gcc agree with <machine/ansi.h>. */
Index: i386-protos.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/i386-protos.h,v
retrieving revision 1.80
diff -c -3 -p -r1.80 i386-protos.h
*** i386-protos.h 15 Sep 2002 21:47:42 -0000 1.80
--- i386-protos.h 18 Oct 2002 11:10:45 -0000
*************** extern void ix86_set_move_mem_attrs PARA
*** 184,189 ****
--- 184,190 ----
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.472
diff -c -3 -p -r1.472 i386.c
*** i386.c 17 Oct 2002 17:09:16 -0000 1.472
--- i386.c 18 Oct 2002 11:10:51 -0000
*************** x86_field_alignment (field, computed)
*** 13949,13954 ****
--- 13949,13994 ----
return computed;
}
+ /* 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)
+ {
+ #ifndef NO_PROFILE_COUNTERS
+ fprintf (file, "\tleaq\t%sP%d@(%%rip),%%r11\n", LPREFIX, labelno);
+ #endif
+ fprintf (file, "\tcall\t*%s@GOTPCREL(%%rip)\n", MCOUNT_NAME);
+ }
+ else
+ {
+ #ifndef NO_PROFILE_COUNTERS
+ fprintf (file, "\tmovq\t$%sP%d,%%r11\n", LPREFIX, labelno);
+ #endif
+ fprintf (file, "\tcall\t%s\n", MCOUNT_NAME);
+ }
+ else if (flag_pic)
+ {
+ #ifndef NO_PROFILE_COUNTERS
+ fprintf (file, "\tleal\t%sP%d@GOTOFF(%%ebx),%%%s\n",
+ LPREFIX, labelno, PROFILE_COUNT_REGISTER);
+ #endif
+ fprintf (file, "\tcall\t*%s@GOT(%%ebx)\n", MCOUNT_NAME);
+ }
+ else
+ {
+ #ifndef NO_PROFILE_COUNTERS
+ fprintf (file, "\tmovl\t$%sP%d,%%$s\n", LPREFIX, labelno,
+ PROFILE_COUNT_REGISTER);
+ #endif
+ fprintf (file, "\tcall\t%s\n", MCOUNT_NAME);
+ }
+ }
+
/* Implement machine specific optimizations.
At the moment we implement single transformation: AMD Athlon works faster
when RET is not destination of conditional jump or directly preceeded
Index: i386.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/i386.h,v
retrieving revision 1.295
diff -c -3 -p -r1.295 i386.h
*** i386.h 16 Oct 2002 13:14:23 -0000 1.295
--- i386.h 18 Oct 2002 11:10:52 -0000
*************** typedef struct ix86_args {
*** 1730,1749 ****
/* 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
--- 1730,1740 ----
/* 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)
!
! #define MCOUNT_NAME "_mcount"
!
! #define PROFILE_COUNT_REGISTER "edx"
/* EXIT_IGNORE_STACK should be nonzero if, when returning from a function,
the stack pointer does not matter. The value is tested only in
Index: linux.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/linux.h,v
retrieving revision 1.40
diff -c -3 -p -r1.40 linux.h
*** linux.h 5 Jun 2002 17:01:30 -0000 1.40
--- linux.h 18 Oct 2002 11:10:52 -0000
*************** Boston, MA 02111-1307, USA. */
*** 53,66 ****
#define NO_PROFILE_COUNTERS
! #undef FUNCTION_PROFILER
! #define FUNCTION_PROFILER(FILE, LABELNO) \
! { \
! if (flag_pic) \
! fprintf (FILE, "\tcall\t*mcount@GOT(%%ebx)\n"); \
! else \
! fprintf (FILE, "\tcall\tmcount\n"); \
! }
/* The GLIBC version of mcount for the x86 assumes that there is a
frame, so we cannot allow profiling without a frame pointer. */
--- 53,60 ----
#define NO_PROFILE_COUNTERS
! #undef MCOUNT_NAME
! #define MCOUNT_NAME "mcount"
/* The GLIBC version of mcount for the x86 assumes that there is a
frame, so we cannot allow profiling without a frame pointer. */
Index: x86-64.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/x86-64.h,v
retrieving revision 1.5
diff -c -3 -p -r1.5 x86-64.h
*** x86-64.h 29 Aug 2002 21:40:11 -0000 1.5
--- x86-64.h 18 Oct 2002 11:10:52 -0000
*************** Boston, MA 02111-1307, USA. */
*** 29,44 ****
/* Output assembler code to FILE to call the profiler. */
#define NO_PROFILE_COUNTERS
! #undef FUNCTION_PROFILER
! #define FUNCTION_PROFILER(FILE, LABELNO) \
! { \
! if (TARGET_64BIT && flag_pic) \
! fprintf (FILE, "\tcall\t*mcount@PLT\n"); \
! else if (flag_pic) \
! fprintf (FILE, "\tcall\t*mcount@GOT(%%ebx)\n"); \
! else \
! fprintf (FILE, "\tcall\tmcount\n"); \
! }
#undef SIZE_TYPE
#define SIZE_TYPE (TARGET_64BIT ? "long unsigned int" : "unsigned int")
--- 29,36 ----
/* Output assembler code to FILE to call the profiler. */
#define NO_PROFILE_COUNTERS
! #undef MCOUNT_NAME
! #define MCOUNT_NAME mcount
#undef SIZE_TYPE
#define SIZE_TYPE (TARGET_64BIT ? "long unsigned int" : "unsigned int")
More information about the Gcc-patches
mailing list