Go to the first, previous, next, last section, table of contents.


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. The global compile flag profile_block_flag distinguishes two profile modes.
profile_block_flag != 2
Output code to 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_OR_LABEL contains a unique number which may be used to generate a label as a branch destination when __bb_init_func will not be called. Described in assembler language, the code to be output looks like:
  cmp (LPBX0),0
  bne local_label
  parameter1 <- LPBX0
  call __bb_init_func
local_label:
profile_block_flag == 2
Output code to call the subroutine __bb_init_trace_func and pass two parameters to it. The first parameter is the same as for __bb_init_func. The second parameter is the number of the first basic block of the function as given by BLOCK_OR_LABEL. Note that __bb_init_trace_func has to be called, even if the object module has been initialized already. Described in assembler language, the code to be output looks like:
parameter1 <- LPBX0
parameter2 <- BLOCK_OR_LABEL
call __bb_init_trace_func
BLOCK_PROFILER (file, blockno)
A C statement or compound statement to output to file some assembler code to increment the count associated with the basic block number blockno. The global compile flag profile_block_flag distinguishes two profile modes.
profile_block_flag != 2
Output code to increment the counter directly. 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. Described in assembler language, the code to be output looks like:
inc (LPBX2+4*BLOCKNO)
profile_block_flag == 2
Output code to initialize the global structure __bb and call the function __bb_trace_func, which will increment the counter. __bb consists of two words. In the first word, the current basic block number, as given by BLOCKNO, has to be stored. In the second word, the address of a block allocated in the object module has to be stored. The address is given by the label created with this statement:
ASM_GENERATE_INTERNAL_LABEL (buffer, "LPBX", 0);
Described in assembler language, the code to be output looks like:
move BLOCKNO -> (__bb)
move LPBX0 -> (__bb+4)
call __bb_trace_func
FUNCTION_BLOCK_PROFILER_EXIT (file)
A C statement or compound statement to output to file assembler code to call function __bb_trace_ret. The assembler code should only be output if the global compile flag profile_block_flag == 2. This macro has to be used at every place where code for returning from a function is generated (e.g. FUNCTION_EPILOGUE). Although you have to write the definition of FUNCTION_EPILOGUE as well, you have to define this macro to tell the compiler, that the proper call to __bb_trace_ret is produced.
MACHINE_STATE_SAVE (id)
A C statement or compound statement to save all registers, which may be clobbered by a function call, including condition codes. The asm statement will be mostly likely needed to handle this task. Local labels in the assembler code can be concatenated with the string id, to obtain a unique lable name. Registers or condition codes clobbered by FUNCTION_PROLOGUE or FUNCTION_EPILOGUE must be saved in the macros FUNCTION_BLOCK_PROFILER, FUNCTION_BLOCK_PROFILER_EXIT and BLOCK_PROFILER prior calling __bb_init_trace_func, __bb_trace_ret and __bb_trace_func respectively.
MACHINE_STATE_RESTORE (id)
A C statement or compound statement to restore all registers, including condition codes, saved by MACHINE_STATE_SAVE. Registers or condition codes clobbered by FUNCTION_PROLOGUE or FUNCTION_EPILOGUE must be restored in the macros FUNCTION_BLOCK_PROFILER, FUNCTION_BLOCK_PROFILER_EXIT and BLOCK_PROFILER after calling __bb_init_trace_func, __bb_trace_ret and __bb_trace_func respectively.
BLOCK_PROFILER_CODE
A C function or functions which are needed in the library to support block profiling.


Go to the first, previous, next, last section, table of contents.