2010-07-28 Kai Tietz <kai.tietz@onevision.com>
authorktietz <ktietz@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 28 Jul 2010 18:00:09 +0000 (18:00 +0000)
committerktietz <ktietz@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 28 Jul 2010 18:00:09 +0000 (18:00 +0000)
        * 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

12 files changed:
gcc/ChangeLog
gcc/config/i386/i386.c
gcc/config/i386/i386.h
gcc/config/i386/i386.opt
gcc/doc/invoke.texi
gcc/doc/tm.texi
gcc/doc/tm.texi.in
gcc/final.c
gcc/function.c
gcc/target.def
gcc/targhooks.c
gcc/targhooks.h

index a4491cb..d5f931d 100644 (file)
@@ -1,3 +1,25 @@
+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
index bd0de27..ff6f4b8 100644 (file)
@@ -2768,6 +2768,15 @@ software_prefetching_beneficial_p (void)
     }
 }
 
+/* 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
@@ -3671,6 +3680,21 @@ override_options (bool main_args_p)
     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
@@ -4832,7 +4856,7 @@ ix86_function_regparm (const_tree type, const_tree decl)
   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));
@@ -4904,7 +4928,8 @@ ix86_function_sseregparm (const_tree type, const_tree decl, bool warn)
 
   /* 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));
@@ -7874,7 +7899,7 @@ ix86_frame_pointer_required (void)
          || ix86_current_function_calls_tls_descriptor))
     return true;
 
-  if (crtl->profile)
+  if (crtl->profile && !flag_fentry)
     return true;
 
   return false;
@@ -8142,7 +8167,8 @@ gen_push (rtx arg)
 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;
@@ -9190,6 +9216,11 @@ ix86_expand_prologue (void)
     {
       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
@@ -9479,7 +9510,7 @@ ix86_expand_prologue (void)
      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)
@@ -27287,6 +27318,9 @@ x86_field_alignment (tree field, int computed)
 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
@@ -27294,9 +27328,9 @@ x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
 #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)
     {
@@ -27304,7 +27338,7 @@ x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
       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
     {
@@ -27312,7 +27346,7 @@ x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
       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);
     }
 }
 
@@ -31360,6 +31394,9 @@ ix86_enum_va_list (int idx, const char **pname, tree *ptree)
 #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
index e153920..fe093cf 100644 (file)
@@ -1607,6 +1607,8 @@ typedef struct ix86_args {
 
 #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,
index f264c42..236082d 100644 (file)
@@ -375,3 +375,7 @@ Support RDRND built-in functions and code generation
 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.
index 78f81e2..c9f7664 100644 (file)
@@ -601,7 +601,7 @@ Objective-C and Objective-C++ Dialects}.
 -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
@@ -12492,6 +12492,14 @@ For systems that use GNU libc, the default is on.
 @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
index e94fdf6..d59c55f 100644 (file)
@@ -7076,6 +7076,13 @@ Contains the value true if the target places read-only
 ``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
index caa0115..1b00ebc 100644 (file)
@@ -7076,6 +7076,8 @@ Contains the value true if the target places read-only
 ``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
index fd597ac..c35ed7b 100644 (file)
@@ -1546,10 +1546,8 @@ final_start_function (rtx first ATTRIBUTE_UNUSED, FILE *file,
 
   /* 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 ())
@@ -1591,10 +1589,8 @@ final_start_function (rtx first ATTRIBUTE_UNUSED, FILE *file,
 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
index 5a308f4..e89a5c9 100644 (file)
@@ -5183,13 +5183,11 @@ thread_prologue_and_epilogue_insns (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 ();
index 01ab478..10013e6 100644 (file)
@@ -1229,6 +1229,15 @@ DEFHOOK
  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).
index 22077f8..553d0bc 100644 (file)
@@ -1197,4 +1197,14 @@ default_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED,
 #endif
 }
 
+bool
+default_profile_before_prologue (void)
+{
+#ifdef PROFILE_BEFORE_PROLOGUE
+  return true;
+#else
+  return false;
+#endif
+}
+
 #include "gt-targhooks.h"
index 23393b4..198bcc7 100644 (file)
@@ -150,3 +150,4 @@ extern int default_memory_move_cost (enum machine_mode, reg_class_t, bool);
 extern int default_register_move_cost (enum machine_mode, reg_class_t,
                                       reg_class_t);
 
+extern bool default_profile_before_prologue (void);