* config/i386/i386.h (MCOUNT_NAME_BEFORE_PROLOGUE): New.
* config/i386/i386.c (ix86_profile_before_prologue): New.
(override_options): Add special handling for -mfentry.
(ix86_function_regparm): Likewise.
(ix86_function_sseregparm): Likewise.
(ix86_frame_pointer_required): Likewise.
(ix86_expand_prologue): Check for ms_hook_prologue.
(x86_function_profiler): Adjust mcount output.
(TARGET_PROFILE_BEFORE_PROLOGUE): Define hook.
* config/i386/i386.opt (mfentry): New.
* doc/invoke.texi (mfentry): Add documentation.
* doc/tm.texi: Regenerated..
* doc/tm.texi.in (TARGET_PROFILE_BEFORE_PROLOGUE): New.
* final.c (final_start_function): Replace macro
PROFILE_BEFORE_PROLOGUE by target hook.
* function.c (thread_prologue_and_epilogue_insns): Likewise.
* target.def (profile_before_prologue): New hook.
* targhooks.c (default_profile_before_prologue): New.
* targhooks.h (default_profile_before_prologue): New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@162651
138bc75d-0d04-0410-961f-
82ee72b054a4
+2010-07-28 Kai Tietz <kai.tietz@onevision.com>
+
+ * config/i386/i386.h (MCOUNT_NAME_BEFORE_PROLOGUE): New.
+ * config/i386/i386.c (ix86_profile_before_prologue): New.
+ (override_options): Add special handling for -mfentry.
+ (ix86_function_regparm): Likewise.
+ (ix86_function_sseregparm): Likewise.
+ (ix86_frame_pointer_required): Likewise.
+ (ix86_expand_prologue): Check for ms_hook_prologue.
+ (x86_function_profiler): Adjust mcount output.
+ (TARGET_PROFILE_BEFORE_PROLOGUE): Define hook.
+ * config/i386/i386.opt (mfentry): New.
+ * doc/invoke.texi (mfentry): Add documentation.
+ * doc/tm.texi: Regenerated..
+ * doc/tm.texi.in (TARGET_PROFILE_BEFORE_PROLOGUE): New.
+ * final.c (final_start_function): Replace macro
+ PROFILE_BEFORE_PROLOGUE by target hook.
+ * function.c (thread_prologue_and_epilogue_insns): Likewise.
+ * target.def (profile_before_prologue): New hook.
+ * targhooks.c (default_profile_before_prologue): New.
+ * targhooks.h (default_profile_before_prologue): New.
+
2010-07-28 Jakub Jelinek <jakub@redhat.com>
PR debug/45105
}
}
+/* Return true, if profiling code should be emitted before
+ prologue. Otherwise it returns false.
+ Note: For x86 with "hotfix" it is sorried. */
+static bool
+ix86_profile_before_prologue (void)
+{
+ return flag_fentry != 0;
+}
+
/* Function that is callable from the debugger to print the current
options. */
void
target_flags |= MASK_CLD & ~target_flags_explicit;
#endif
+ if (!TARGET_64BIT && flag_pic)
+ {
+ if (flag_fentry > 0)
+ sorry ("-mfentry isn't supported for 32-bit in combination with -fpic");
+ flag_fentry = 0;
+ }
+ if (flag_fentry < 0)
+ {
+#if defined(PROFILE_BEFORE_PROLOGUE)
+ flag_fentry = 1;
+#else
+ flag_fentry = 0;
+#endif
+ }
+
/* Save the initial options in case the user does function specific options */
if (main_args_p)
target_option_default_node = target_option_current_node
if (decl
&& TREE_CODE (decl) == FUNCTION_DECL
&& optimize
- && !profile_flag)
+ && !(profile_flag && !flag_fentry))
{
/* FIXME: remove this CONST_CAST when cgraph.[ch] is constified. */
struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE (decl));
/* For local functions, pass up to SSE_REGPARM_MAX SFmode
(and DFmode for SSE2) arguments in SSE registers. */
- if (decl && TARGET_SSE_MATH && optimize && !profile_flag)
+ if (decl && TARGET_SSE_MATH && optimize
+ && !(profile_flag && !flag_fentry))
{
/* FIXME: remove this CONST_CAST when cgraph.[ch] is constified. */
struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
|| ix86_current_function_calls_tls_descriptor))
return true;
- if (crtl->profile)
+ if (crtl->profile && !flag_fentry)
return true;
return false;
static unsigned int
ix86_select_alt_pic_regnum (void)
{
- if (current_function_is_leaf && !crtl->profile
+ if (current_function_is_leaf
+ && !crtl->profile
&& !ix86_current_function_calls_tls_descriptor)
{
int i, drap;
{
rtx push, mov;
+ /* Check if profiling is active and we shall use profiling before
+ prologue variant. If so sorry. */
+ if (crtl->profile && flag_fentry != 0)
+ sorry ("ms_hook_prologue attribute isn't compatible with -mfentry for 32-bit");
+
/* Make sure the function starts with
8b ff movl.s %edi,%edi (emited by ix86_asm_output_function_label)
55 push %ebp
when mcount needs it. Blockage to avoid call movement across mcount
call is emitted in generic code after the NOTE_INSN_PROLOGUE_END
note. */
- if (crtl->profile && pic_reg_used)
+ if (crtl->profile && !flag_fentry && pic_reg_used)
emit_insn (gen_prologue_use (pic_offset_table_rtx));
if (crtl->drap_reg && !crtl->stack_realign_needed)
void
x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
{
+ const char *mcount_name = (flag_fentry ? MCOUNT_NAME_BEFORE_PROLOGUE
+ : MCOUNT_NAME);
+
if (TARGET_64BIT)
{
#ifndef NO_PROFILE_COUNTERS
#endif
if (DEFAULT_ABI == SYSV_ABI && flag_pic)
- fputs ("\tcall\t*" MCOUNT_NAME "@GOTPCREL(%rip)\n", file);
+ fprintf (file, "\tcall\t*%s@GOTPCREL(%%rip)\n", mcount_name);
else
- fputs ("\tcall\t" MCOUNT_NAME "\n", file);
+ fprintf (file, "\tcall\t%s\n", mcount_name);
}
else if (flag_pic)
{
fprintf (file, "\tleal\t%sP%d@GOTOFF(%%ebx),%%" PROFILE_COUNT_REGISTER "\n",
LPREFIX, labelno);
#endif
- fputs ("\tcall\t*" MCOUNT_NAME "@GOT(%ebx)\n", file);
+ fprintf (file, "\tcall\t*%s@GOT(%%ebx)\n", mcount_name);
}
else
{
fprintf (file, "\tmovl\t$%sP%d,%%" PROFILE_COUNT_REGISTER "\n",
LPREFIX, labelno);
#endif
- fputs ("\tcall\t" MCOUNT_NAME "\n", file);
+ fprintf (file, "\tcall\t%s\n", mcount_name);
}
}
#define TARGET_ASM_ALIGNED_DI_OP ASM_QUAD
#endif
+#undef TARGET_PROFILE_BEFORE_PROLOGUE
+#define TARGET_PROFILE_BEFORE_PROLOGUE ix86_profile_before_prologue
+
#undef TARGET_ASM_UNALIGNED_HI_OP
#define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
#undef TARGET_ASM_UNALIGNED_SI_OP
#define MCOUNT_NAME "_mcount"
+#define MCOUNT_NAME_BEFORE_PROLOGUE "__fentry__"
+
#define PROFILE_COUNT_REGISTER "edx"
/* EXIT_IGNORE_STACK should be nonzero if, when returning from a function,
mf16c
Target Report Mask(ISA_F16C) Var(ix86_isa_flags) VarExists Save
Support F16C built-in functions and code generation
+
+mfentry
+Target Report Var(flag_fentry) Init(-1)
+Emit profiling counter call at function entry before prologue.
-momit-leaf-frame-pointer -mno-red-zone -mno-tls-direct-seg-refs @gol
-mcmodel=@var{code-model} -mabi=@var{name} @gol
-m32 -m64 -mlarge-data-threshold=@var{num} @gol
--msse2avx}
+-msse2avx -mfentry}
@emph{IA-64 Options}
@gccoptlist{-mbig-endian -mlittle-endian -mgnu-as -mgnu-ld -mno-pic @gol
@opindex msse2avx
Specify that the assembler should encode SSE instructions with VEX
prefix. The option @option{-mavx} turns this on by default.
+
+@item -mfentry
+@itemx -mno-fentry
+@opindex mfentry
+If profiling is active @option{-pg} put the profiling
+counter call before prologue.
+Note: On x86 architectures the attribute @code{ms_hook_prologue}
+isn't possible at the moment for @option{-mfentry} and @option{-pg}.
@end table
These @samp{-m} switches are supported in addition to the above
``small data'' into a separate section. The default value is false.
@end deftypevr
+@deftypefn {Target Hook} bool TARGET_PROFILE_BEFORE_PROLOGUE (void)
+It returns true if target wants profile code emitted before prologue.
+
+The default version of this hook use the target macro
+@code{PROFILE_BEFORE_PROLOGUE}.
+@end deftypefn
+
@deftypefn {Target Hook} bool TARGET_BINDS_LOCAL_P (const_tree @var{exp})
Returns true if @var{exp} names an object for which name resolution
rules must resolve to the current ``module'' (dynamic shared library
``small data'' into a separate section. The default value is false.
@end deftypevr
+@hook TARGET_PROFILE_BEFORE_PROLOGUE
+
@hook TARGET_BINDS_LOCAL_P
Returns true if @var{exp} names an object for which name resolution
rules must resolve to the current ``module'' (dynamic shared library
/* The Sun386i and perhaps other machines don't work right
if the profiling code comes after the prologue. */
-#ifdef PROFILE_BEFORE_PROLOGUE
- if (crtl->profile)
+ if (targetm.profile_before_prologue () && crtl->profile)
profile_function (file);
-#endif /* PROFILE_BEFORE_PROLOGUE */
#if defined (DWARF2_UNWIND_INFO) && defined (HAVE_prologue)
if (dwarf2out_do_frame ())
static void
profile_after_prologue (FILE *file ATTRIBUTE_UNUSED)
{
-#ifndef PROFILE_BEFORE_PROLOGUE
- if (crtl->profile)
+ if (!targetm.profile_before_prologue () && crtl->profile)
profile_function (file);
-#endif /* not PROFILE_BEFORE_PROLOGUE */
}
static void
record_insns (seq, NULL, &prologue_insn_hash);
emit_note (NOTE_INSN_PROLOGUE_END);
-#ifndef PROFILE_BEFORE_PROLOGUE
/* Ensure that instructions are not moved into the prologue when
profiling is on. The call to the profiling routine can be
emitted within the live range of a call-clobbered register. */
- if (crtl->profile)
+ if (!targetm.profile_before_prologue () && crtl->profile)
emit_insn (gen_blockage ());
-#endif
seq = get_insns ();
end_sequence ();
bool, (const_tree exp),
default_binds_local_p)
+/* Check if profiling code is before or after prologue. */
+DEFHOOK
+(profile_before_prologue,
+ "It returns true if target wants profile code emitted before prologue.\n\n\
+The default version of this hook use the target macro\n\
+@code{PROFILE_BEFORE_PROLOGUE}.",
+ bool, (void),
+ default_profile_before_prologue)
+
/* Modify and return the identifier of a DECL's external name,
originally identified by ID, as required by the target,
(eg, append @nn to windows32 stdcall function names).
#endif
}
+bool
+default_profile_before_prologue (void)
+{
+#ifdef PROFILE_BEFORE_PROLOGUE
+ return true;
+#else
+ return false;
+#endif
+}
+
#include "gt-targhooks.h"
extern int default_register_move_cost (enum machine_mode, reg_class_t,
reg_class_t);
+extern bool default_profile_before_prologue (void);