public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Kai Tietz <ktietz70@googlemail.com>
To: Richard Henderson <rth@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>, GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [patch i386]: Add for win32 targets pre-prologue profiling 	feature
Date: Thu, 15 Jul 2010 18:08:00 -0000	[thread overview]
Message-ID: <AANLkTinDL6GV8W6EYkRu3jNqPRgjcpFoPHPWux0vFa-Q@mail.gmail.com> (raw)
In-Reply-To: <AANLkTimDPPvDpYHL2uX4QSPbJ9bxy4WMHCJ50WxMFRTH@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1849 bytes --]

Hello Andy,

I updated my patch in that way, that it should be trivial to add the
counter function for before prologue profiling to linux target by a
one-liner.
Just make sure that for the i386-target the macro
MCOUNT_NAME_BEFORE_PROLOGUE is defined.

I reworked the patch so that the option is now named -mfentry and it
is available for all i386 targets, if they have defined the counter
function's name via MCOUNT_NAME_BEFORE_PROLOGUE in target.
Additionally I added some option-checks for targets, which don't
support before prologue profiling.

ChangeLog

2010-07-15  Kai Tietz

	* config/i386/cygming.h (MCOUNT_NAME): New.
	(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_select_alt_pic_regnum): Likewise.
	(ix86_save_reg):
	(ix86_expand_prologue):
	(x86_function_profiler):
	(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.

Tested for i686-pc-mingw32, x86_64-pc-mingw32, and i686-pc-linux-gnu
to see if option check works. Ok for apply?

Regards,
Kai


-- 
|  (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination

[-- Attachment #2: profileb.diff --]
[-- Type: application/octet-stream, Size: 14056 bytes --]

Index: gcc/gcc/config/i386/cygming.h
===================================================================
--- gcc.orig/gcc/config/i386/cygming.h	2010-07-15 19:15:51.651349100 +0200
+++ gcc/gcc/config/i386/cygming.h	2010-07-15 19:49:18.100111400 +0200
@@ -39,6 +39,13 @@ along with GCC; see the file COPYING3.
 #undef DEFAULT_ABI
 #define DEFAULT_ABI (TARGET_64BIT ? MS_ABI : SYSV_ABI)
 
+/* Choose the correct profiler mcount name.  */
+#undef MCOUNT_NAME
+#define MCOUNT_NAME "_mcount"
+
+#undef MCOUNT_NAME_BEFORE_PROLOGUE
+#define MCOUNT_NAME_BEFORE_PROLOGUE "_mcount_top"
+
 #if ! defined (USE_MINGW64_LEADING_UNDERSCORES)
 #undef USER_LABEL_PREFIX
 #define USER_LABEL_PREFIX (TARGET_64BIT ? "" : "_")
Index: gcc/gcc/config/i386/i386.c
===================================================================
--- gcc.orig/gcc/config/i386/i386.c	2010-07-15 19:15:51.653349100 +0200
+++ gcc/gcc/config/i386/i386.c	2010-07-15 19:55:46.197309300 +0200
@@ -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,28 @@ override_options (bool main_args_p)
     target_flags |= MASK_CLD & ~target_flags_explicit;
 #endif
 
+  {
+    int default_profile_top_flag = 0;
+    int only_default = 1;
+
+#if defined(PROFILE_BEFORE_PROLOGUE)
+    default_profile_top_flag = 1;
+#endif
+#if defined(MCOUNT_NAME) && defined (MCOUNT_NAME_BEFORE_PROLOGUE)
+    only_default = 0;
+#endif
+
+    if (flag_fentry == -1)
+      flag_fentry = default_profile_top_flag;
+    else if (flag_fentry != default_profile_top_flag && only_default)
+      {
+        if (!default_profile_top_flag)
+          sorry ("-mfentry isn't supported for this target");
+        else
+          sorry ("-mno-fentry isn't supported for this target");
+	flag_fentry = default_profile_top_flag;
+      }
+  }
   /* Save the initial options in case the user does function specific options */
   if (main_args_p)
     target_option_default_node = target_option_current_node
@@ -4841,7 +4872,7 @@ ix86_function_regparm (const_tree type,
   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));
@@ -4913,7 +4944,8 @@ ix86_function_sseregparm (const_tree typ
 
   /* 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));
@@ -7875,7 +7907,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;
@@ -8143,7 +8175,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 && !flag_fentry)
       && !ix86_current_function_calls_tls_descriptor)
     {
       int i, drap;
@@ -8167,7 +8200,7 @@ ix86_save_reg (unsigned int regno, int m
   if (pic_offset_table_rtx
       && regno == REAL_PIC_OFFSET_TABLE_REGNUM
       && (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
-	  || crtl->profile
+	  || (crtl->profile && !flag_fentry)
 	  || crtl->calls_eh_return
 	  || crtl->uses_const_pool))
     {
@@ -9191,6 +9224,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
@@ -9443,7 +9481,7 @@ ix86_expand_prologue (void)
   pic_reg_used = false;
   if (pic_offset_table_rtx
       && (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
-	  || crtl->profile))
+	  || (crtl->profile && !flag_fentry)))
     {
       unsigned int alt_pic_reg_used = ix86_select_alt_pic_regnum ();
 
@@ -9480,7 +9518,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)
@@ -27282,11 +27320,26 @@ x86_field_alignment (tree field, int com
   return computed;
 }
 
+#if !defined(MCOUNT_NAME) && !defined(MCOUNT_NAME_BEFORE_PROLOGUE)
+#error MCOUNT_NAME ,and/or MCOUNT_NAME_BEFORE_PROLOGUE have to be define
+#endif
+
+/* Make sure both are getting defined.  */
+#ifndef MCOUNT_NAME
+#define MCOUNT_NAME MCOUNT_NAME_BEFORE_PROLOGUE
+#endif
+#ifndef MCOUNT_NAME_BEFORE_PROLOGUE
+#define MCOUNT_NAME_BEFORE_PROLOGUE MCOUNT_NAME
+#endif
+
 /* Output assembler code to FILE to increment profiler label # LABELNO
    for profiling a function entry.  */
 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 +27347,9 @@ x86_function_profiler (FILE *file, int l
 #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 +27357,7 @@ x86_function_profiler (FILE *file, int l
       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 +27365,7 @@ x86_function_profiler (FILE *file, int l
       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 +31413,9 @@ ix86_enum_va_list (int idx, const char *
 #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: gcc/gcc/config/i386/i386.opt
===================================================================
--- gcc.orig/gcc/config/i386/i386.opt	2010-07-15 19:15:51.665349100 +0200
+++ gcc/gcc/config/i386/i386.opt	2010-07-15 19:19:10.376715500 +0200
@@ -375,3 +375,7 @@ Support RDRND built-in functions and cod
 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: gcc/gcc/doc/invoke.texi
===================================================================
--- gcc.orig/gcc/doc/invoke.texi	2010-07-15 19:15:51.666349100 +0200
+++ gcc/gcc/doc/invoke.texi	2010-07-15 19:19:10.385716000 +0200
@@ -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
@@ -12466,6 +12466,14 @@ For systems that use GNU libc, the defau
 @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: gcc/gcc/doc/tm.texi
===================================================================
--- gcc.orig/gcc/doc/tm.texi	2010-07-15 19:15:51.668349100 +0200
+++ gcc/gcc/doc/tm.texi	2010-07-15 19:19:10.393716500 +0200
@@ -7101,6 +7101,14 @@ Contains the value true if the target pl
 ``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: gcc/gcc/doc/tm.texi.in
===================================================================
--- gcc.orig/gcc/doc/tm.texi.in	2010-07-15 19:15:51.673349100 +0200
+++ gcc/gcc/doc/tm.texi.in	2010-07-15 19:19:10.399716800 +0200
@@ -7101,6 +7101,14 @@ Contains the value true if the target pl
 ``small data'' into a separate section.  The default value is false.
 @end deftypevr
 
+@hook TARGET_PROFILE_BEFORE_PROLOGUE
+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
+
 @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: gcc/gcc/final.c
===================================================================
--- gcc.orig/gcc/final.c	2010-07-15 19:15:51.674349100 +0200
+++ gcc/gcc/final.c	2010-07-15 19:19:10.403717000 +0200
@@ -1546,10 +1546,8 @@ final_start_function (rtx first ATTRIBUT
 
   /* 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 ATTRIBUT
 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: gcc/gcc/function.c
===================================================================
--- gcc.orig/gcc/function.c	2010-07-15 19:15:51.675349100 +0200
+++ gcc/gcc/function.c	2010-07-15 19:19:10.408717300 +0200
@@ -5100,13 +5100,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: gcc/gcc/target.def
===================================================================
--- gcc.orig/gcc/target.def	2010-07-15 19:15:51.676349100 +0200
+++ gcc/gcc/target.def	2010-07-15 19:19:10.411717500 +0200
@@ -1218,6 +1218,13 @@ DEFHOOK
  bool, (const_tree exp),
  default_binds_local_p)
 
+/* Check if profiling code is before or after prologue.  */
+DEFHOOK
+(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: gcc/gcc/targhooks.c
===================================================================
--- gcc.orig/gcc/targhooks.c	2010-07-15 19:15:51.678349100 +0200
+++ gcc/gcc/targhooks.c	2010-07-15 19:19:10.413717600 +0200
@@ -1197,4 +1197,14 @@ default_register_move_cost (enum machine
 #endif
 }
 
+bool
+default_profile_before_prologue (void)
+{
+#ifndef PROFILE_BEFORE_PROLOGUE
+  return false;
+#else
+  return true;
+#endif
+}
+
 #include "gt-targhooks.h"
Index: gcc/gcc/targhooks.h
===================================================================
--- gcc.orig/gcc/targhooks.h	2010-07-15 19:15:51.687349100 +0200
+++ gcc/gcc/targhooks.h	2010-07-15 19:19:10.416717800 +0200
@@ -150,3 +150,4 @@ extern int default_memory_move_cost (enu
 extern int default_register_move_cost (enum machine_mode, reg_class_t,
 				       reg_class_t);
 
+extern bool default_profile_before_prologue (void);

  reply	other threads:[~2010-07-15 18:08 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-13 12:47 Kai Tietz
2010-07-13 16:28 ` Richard Henderson
2010-07-14 10:20   ` Kai Tietz
2010-07-14 11:49     ` Dave Korn
2010-07-14 12:11       ` Kai Tietz
2010-07-14 12:16     ` Andi Kleen
2010-07-14 12:38       ` Kai Tietz
2010-07-15 18:08         ` Kai Tietz [this message]
2010-07-16 17:06           ` Richard Henderson
2010-07-17  6:52             ` Kai Tietz
2010-07-20  2:27               ` Richard Henderson
2010-07-28  8:36                 ` Kai Tietz
2010-07-28 16:00                   ` Richard Henderson
2010-07-28 16:01                     ` Andi Kleen
2010-07-28 17:28                       ` Kai Tietz
2010-07-28 17:40                         ` Richard Henderson
2010-07-28 18:14                           ` Kai Tietz
2010-07-16 20:53           ` Gerald Pfeifer
2010-07-18 12:20             ` Kai Tietz
2010-07-18 20:52               ` Gerald Pfeifer
2010-07-18 20:54                 ` Kai Tietz
2010-07-28 18:06                 ` Kai Tietz
2010-07-16 23:57           ` Andi Kleen
2010-07-17  5:34             ` Kai Tietz
2010-07-17  9:45               ` Andi Kleen
2010-07-18 11:37                 ` Kai Tietz
2010-07-18 11:46                   ` Kai Tietz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AANLkTinDL6GV8W6EYkRu3jNqPRgjcpFoPHPWux0vFa-Q@mail.gmail.com \
    --to=ktietz70@googlemail.com \
    --cc=andi@firstfloor.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=rth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).