PREV UP next Using and Porting GNU CC

16.7.10: Generating Code for Profiling

These macros will help you generate code for profiling.

FUNCTION_PROFILER (file, labelno)
A C statement or compound statement to output to file some assembler code to call the profiling subroutine mcount. Before calling, the assembler code must load the address of a counter variable into a register where mcount expects to find the address. The name of this variable is `LP' followed by the number labelno, so you would generate the name using `LP%d' in a fprintf.

The details of how the address should be passed to mcount are determined by your operating system environment, not by GNU CC. To figure them out, compile a small program for profiling using the system's installed C compiler and look at the assembler code that results.

PROFILE_BEFORE_PROLOGUE
Define this macro if the code for function profiling should come before the function prologue. Normally, the profiling code comes after.
FUNCTION_BLOCK_PROFILER (file, labelno)
A C statement or compound statement to output to file some assembler code to initialize basic-block profiling for the current object module. This code should call the subroutine __bb_init_func once per object module, passing it as its sole argument the address of a block allocated in the object module.

The name of the block is a local symbol made with this statement:

ASM_GENERATE_INTERNAL_LABEL (buffer, "LPBX", 0);

Of course, since you are writing the definition of ASM_GENERATE_INTERNAL_LABEL as well as that of this macro, you can take a short cut in the definition of this macro and use the name that you know will result.

The first word of this block is a flag which will be nonzero if the object module has already been initialized. So test this word first, and do not call __bb_init_func if the flag is nonzero.

BLOCK_PROFILER (file, blockno)
A C statement or compound statement to increment the count associated with the basic block number blockno. Basic blocks are numbered separately from zero within each compilation. The count associated with block number blockno is at index blockno in a vector of words; the name of this array is a local symbol made with this statement:
ASM_GENERATE_INTERNAL_LABEL (buffer, "LPBX", 2);

Of course, since you are writing the definition of ASM_GENERATE_INTERNAL_LABEL as well as that of this macro, you can take a short cut in the definition of this macro and use the name that you know will result.

BLOCK_PROFILER_CODE
A C function or functions which are needed in the library to support block profiling.