Patchwork [google,4.7] Generate a label for the split cold function while using -freorder-blocks-and-partition

login
register
mail settings
Submitter Sriraman Tallam
Date April 21, 2013, 12:09 a.m.
Message ID <CAAs8HmyyMx4e-H8EZ1w5KrqFQrLQDTfNsY2mBOZyL2Cc9S8Ktw@mail.gmail.com>
Download mbox | patch
Permalink /patch/238194/
State New
Headers show

Comments

Sriraman Tallam - April 21, 2013, 12:09 a.m.
Fixed a bug in the previous patch sent, where  I did not check if the
switch section was actually to the cold function part.  Updated patch
attached.

Thanks
Sri



On Fri, Apr 19, 2013 at 1:58 PM, Sriraman Tallam <tmsriram@google.com> wrote:
> Updated patch attached.
>
> Thanks
> Sri
>
> On Fri, Apr 19, 2013 at 1:43 PM, Sriraman Tallam <tmsriram@google.com> wrote:
>> Hi,
>>
>>   This patch generates labels for cold function parts that are split when
>> using the option -freorder-blocks-and-partition.  The cold label name
>> is generated by suffixing ".cold" to the assembler name of the hot
>> function.
>>
>>   This is useful when getting back traces from gdb when the cold function
>> part does get executed.
>>
>> I will port this patch to trunk, please let me know what you think.
>>
>> Thanks
>> Sri
Patch to generate labels for cold function parts that are split when
using the option -freorder-blocks-and-partition.  The cold label name
is generated by suffixing ".cold" to the assembler name of the hot
function.

This is useful when getting back traces from gdb when the cold function
part does get executed.
Xinliang David Li - April 23, 2013, 8:55 p.m.
It might be better to submit this to trunk first.

thanks,

David

On Sat, Apr 20, 2013 at 5:09 PM, Sriraman Tallam <tmsriram@google.com> wrote:
> Fixed a bug in the previous patch sent, where  I did not check if the
> switch section was actually to the cold function part.  Updated patch
> attached.
>
> Thanks
> Sri
>
>
>
> On Fri, Apr 19, 2013 at 1:58 PM, Sriraman Tallam <tmsriram@google.com> wrote:
>> Updated patch attached.
>>
>> Thanks
>> Sri
>>
>> On Fri, Apr 19, 2013 at 1:43 PM, Sriraman Tallam <tmsriram@google.com> wrote:
>>> Hi,
>>>
>>>   This patch generates labels for cold function parts that are split when
>>> using the option -freorder-blocks-and-partition.  The cold label name
>>> is generated by suffixing ".cold" to the assembler name of the hot
>>> function.
>>>
>>>   This is useful when getting back traces from gdb when the cold function
>>> part does get executed.
>>>
>>> I will port this patch to trunk, please let me know what you think.
>>>
>>> Thanks
>>> Sri

Patch

Index: final.c
===================================================================
--- final.c	(revision 198081)
+++ final.c	(working copy)
@@ -1934,6 +1934,21 @@  final_scan_insn (rtx insn, FILE *file, int optimiz
 	  targetm.asm_out.function_switched_text_sections (asm_out_file,
 							   current_function_decl,
 							   in_cold_section_p);
+	  /* Emit a label for the split cold section.  Form label name by
+	     suffixing ".cold" to the function's assembler name.  */
+	  if (in_cold_section_p)
+	    {
+	      char *cold_function_name;
+	      const char *mangled_function_name;
+	      tree asm_name = DECL_ASSEMBLER_NAME (current_function_decl);
+
+	      mangled_function_name = IDENTIFIER_POINTER (asm_name);
+	      cold_function_name = XNEWVEC (char,
+	          strlen (mangled_function_name) + strlen (".cold") + 1);
+	      sprintf (cold_function_name, "%s.cold", mangled_function_name);
+	      ASM_OUTPUT_LABEL (asm_out_file, cold_function_name);
+	      XDELETEVEC (cold_function_name);
+	    }
 	  break;
 
 	case NOTE_INSN_BASIC_BLOCK:
Index: testsuite/gcc.dg/tree-prof/cold_partition_label.c
===================================================================
--- testsuite/gcc.dg/tree-prof/cold_partition_label.c	(revision 0)
+++ testsuite/gcc.dg/tree-prof/cold_partition_label.c	(revision 0)
@@ -0,0 +1,39 @@ 
+/* Test case to check if function foo gets split and the cold function
+   gets a label.  */
+/* { dg-require-effective-target freorder } */
+/* { dg-options "-O2 -freorder-blocks-and-partition --save-temps" } */
+
+#define SIZE 10000
+
+const char *sarr[SIZE];
+const char *buf_hot;
+const char *buf_cold;
+
+__attribute__((noinline))
+void 
+foo (int path)
+{
+  int i;
+  if (path)
+    {
+      for (i = 0; i < SIZE; i++)
+	sarr[i] = buf_hot;
+    }
+  else
+    {
+      for (i = 0; i < SIZE; i++)
+	sarr[i] = buf_cold;
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+  buf_hot =  "hello";
+  buf_cold = "world";
+  foo (argc);
+  return 0;
+}
+
+/* { dg-final-use { scan-assembler "foo.cold" } } */
+/* { dg-final-use { cleanup-saved-temps } } */