Subject: Profiling prologue questions
To: None <port-mips@netbsd.org>
From: Rafal Boni <rafal@mediaone.net>
List: port-mips
Date: 11/24/2001 15:46:50
Folks:
	In the process of getting the new toolchain working on BE MIPS
	platforms, I've found that profiling is totally broken due to
	the way the GCC profiler prologue is coded (it emits assembly
	code that was hand-scheduled and breaks in the face of PIC).

	I'm including the fixed up profiler prologue macro below (the
	problem was that previous to this fix, the stack pre-adjustment
	had been hand-scheduled into the delay slot of the `jal', which
	broke in the .abicalls/PIC case as the assembler re-wrote the
	`jal' into a `load $t9; jalr $t9; restore $gp' sequence, pushing
	the stack pre-adjustment until a point *after* the jump).

	It had been suggested on the GCC list that while fixing this 
	it might be even better to get rid of the `.set noreoder'/`.set
	reorder', as after all the assembler should know better than the
	compiler how to schedule the instructions.

	I'm sort of up in the air as to whether removing the `noreorder'
	makes things any safer, even if it allows the assembler to do a
	potentially better job of instruction scheduling.  Unless any of
	you have good arguments as to why it *would* be better without the
	`noreorder', I'll check in this version soon... 

	However, I thought I'd solicit input from the MIPS experts out on
	the list before I change in in case getting rid of the `noreorder'
	really *is* a win.  So, if you have an opinion on this, please let
	me know soon so the fix makes everyone happy...

Thanks!
--rafal

| /* Output assembler code to FILE to increment profiler label # LABELNO
|    for profiling a function entry.  */
| 
| #define FUNCTION_PROFILER(FILE, LABELNO)				\
| {									\
|   if (TARGET_MIPS16)							\
|     sorry ("mips16 function profiling");				\
|   fprintf (FILE, "\t.set\tnoreorder\n");				\
|   fprintf (FILE, "\t.set\tnoat\n");					\
|   fprintf (FILE, "\tmove\t%s,%s\t\t# save current return address\n",	\
| 	   reg_names[GP_REG_FIRST + 1], reg_names[GP_REG_FIRST + 31]);	\
|   fprintf (FILE,							\
| 	   "\t%s\t%s,%s,%d\t\t# _mcount pops 2 words from  stack\n",	\
| 	   TARGET_64BIT ? "dsubu" : "subu",				\
| 	   reg_names[STACK_POINTER_REGNUM],				\
| 	   reg_names[STACK_POINTER_REGNUM],				\
| 	   Pmode == DImode ? 16 : 8);					\
|   fprintf (FILE, "\tjal\t_mcount\n");					\
|   fprintf (FILE, "\tnop\n");						\
|   fprintf (FILE, "\t.set\treorder\n");				\
|   fprintf (FILE, "\t.set\tat\n");					\
| }

----
Rafal Boni                                                   rafal@mediaone.net