@@ -200,6 +200,9 @@ rtx current_insn_predicate;
/* True if printing into -fdump-final-insns= dump. */
bool final_insns_dump_p;
+/* True if profile_function should be called, but hasn't been called yet. */
+static bool need_profile_function;
+
static int asm_insn_count (rtx);
static void profile_function (FILE *);
static void profile_after_prologue (FILE *);
@@ -1668,13 +1671,15 @@ reemit_insn_block_notes (void)
test and compare insns. */
void
-final_start_function (rtx first ATTRIBUTE_UNUSED, FILE *file,
+final_start_function (rtx first, FILE *file,
int optimize_p ATTRIBUTE_UNUSED)
{
block_depth = 0;
this_is_asm_operands = 0;
+ need_profile_function = false;
+
last_filename = LOCATION_FILE (prologue_location);
last_linenum = LOCATION_LINE (prologue_location);
last_discriminator = discriminator = 0;
@@ -1695,7 +1700,41 @@ final_start_function (rtx first ATTRIBUT
/* The Sun386i and perhaps other machines don't work right
if the profiling code comes after the prologue. */
if (targetm.profile_before_prologue () && crtl->profile)
- profile_function (file);
+ {
+ if (targetm.asm_out.function_prologue
+ == default_function_pro_epilogue
+#ifdef HAVE_prologue
+ && HAVE_prologue
+#endif
+ )
+ {
+ rtx insn;
+ for (insn = first; insn; insn = NEXT_INSN (insn))
+ if (!NOTE_P (insn))
+ {
+ insn = NULL_RTX;
+ break;
+ }
+ else if (NOTE_KIND (insn) == NOTE_INSN_BASIC_BLOCK
+ || NOTE_KIND (insn) == NOTE_INSN_FUNCTION_BEG)
+ break;
+ else if (NOTE_KIND (insn) == NOTE_INSN_DELETED
+ || NOTE_KIND (insn) == NOTE_INSN_VAR_LOCATION)
+ continue;
+ else
+ {
+ insn = NULL_RTX;
+ break;
+ }
+
+ if (insn)
+ need_profile_function = true;
+ else
+ profile_function (file);
+ }
+ else
+ profile_function (file);
+ }
/* If debugging, assign block numbers to all of the blocks in this
function. */
@@ -2075,6 +2114,12 @@ final_scan_insn (rtx insn, FILE *file, i
break;
case NOTE_INSN_BASIC_BLOCK:
+ if (need_profile_function)
+ {
+ profile_function (asm_out_file);
+ need_profile_function = false;
+ }
+
if (targetm.asm_out.unwind_emit)
targetm.asm_out.unwind_emit (asm_out_file, insn);
@@ -2130,6 +2175,12 @@ final_scan_insn (rtx insn, FILE *file, i
break;
case NOTE_INSN_FUNCTION_BEG:
+ if (need_profile_function)
+ {
+ profile_function (asm_out_file);
+ need_profile_function = false;
+ }
+
app_disable ();
if (!DECL_IGNORED_P (current_function_decl))
debug_hooks->end_prologue (last_linenum, last_filename);