public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix size & type for cold partition names (hot-cold function partitioning)
@ 2014-12-05 22:41 Caroline Tice
  2014-12-08 21:07 ` Jeff Law
  0 siblings, 1 reply; 27+ messages in thread
From: Caroline Tice @ 2014-12-05 22:41 UTC (permalink / raw)
  To: GCC Patches; +Cc: Caroline Tice

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

When hot/cold function splitting occurs, a symbol is generated for the
cold partition, and gets output in the assembly & debug info, but the
symbol currently gets a size of 0 and a type of NOTYPE, as in this
example (on x86_64-linux) from the cold_partition_label test in the
testsuite:

$ readelf -sW cold_partition_label.x02 | grep foo
    36: 0000000000400450     0 NOTYPE  LOCAL  DEFAULT   12 foo.cold.0
    58: 0000000000400490    43 FUNC    GLOBAL DEFAULT   12 foo
$

This patch fixes this by calculating the right size for the partition,
and outputing the size and type fo the cold partition symbol.  After
applying this patch and looking at the same test, I get:

$ readelf -sW cold_partition_label.x02 | grep foo
    36: 0000000000400450    29 FUNC    LOCAL  DEFAULT   12 foo.cold.0
    58: 0000000000400490    43 FUNC    GLOBAL DEFAULT   12 foo
$

This patch has been tested by bootstrapping the compiler, running the
dejagnu testsuite with no regressions, and checked as shown above that
it fixes the original problem.  Is this patch OK to commit to ToT?

-- Caroline Tice
cmtice@google.com

 2014-12-05  Caroline Tice  <cmtice@google.com>

        * final.c (final_scan_insn): Change 'cold_function_name' to
        'cold_partition_name' and make it a global variable; also output
        assembly to give it a 'FUNC' type, if appropriate.
        * varasm.c (cold_partition_name): Declare and initialize global
        variable.
        (assemble_start_function): Re-set value for cold_partition_name.
        (assemble_end_function): Output assembly to calculate size of cold
        partition, and associate size with name, if appropriate.
        * varash.h (cold_partition_name): Add extern declaration for global
        variable.

[-- Attachment #2: cold-partition-name.patch --]
[-- Type: text/x-patch, Size: 2830 bytes --]

Index: gcc/final.c
===================================================================
--- gcc/final.c	(revision 218434)
+++ gcc/final.c	(working copy)
@@ -2223,10 +2223,16 @@
 	     suffixing "cold" to the original function's name.  */
 	  if (in_cold_section_p)
 	    {
-	      tree cold_function_name
+	      cold_partition_name
 		= clone_function_name (current_function_decl, "cold");
+#ifdef ASM_DECLARE_FUNCTION_NAME
+	      ASM_DECLARE_FUNCTION_NAME (asm_out_file,
+					 IDENTIFIER_POINTER (cold_partition_name),
+					 current_function_decl);
+#else
 	      ASM_OUTPUT_LABEL (asm_out_file,
-				IDENTIFIER_POINTER (cold_function_name));
+				IDENTIFIER_POINTER (cold_partition_name));
+#endif
 	    }
 	  break;
 
Index: gcc/varasm.c
===================================================================
--- gcc/varasm.c	(revision 218434)
+++ gcc/varasm.c	(working copy)
@@ -171,6 +171,13 @@
    at the cold section.  */
 bool in_cold_section_p;
 
+/* The following global holds the partition name for the code in the
+   cold section of a function, if hot/cold function splitting is enabled
+   and there was actually code that went into the cold section.  A
+   pseudo function name is needed for the cold section of code for some
+   debugging tools that perform symbolization. */
+tree cold_partition_name = NULL_TREE;
+
 /* A linked list of all the unnamed sections.  */
 static GTY(()) section *unnamed_sections;
 
@@ -1708,6 +1715,7 @@
       ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno);
       crtl->subsections.cold_section_end_label = ggc_strdup (tmp_label);
       const_labelno++;
+      cold_partition_name = NULL_TREE;
     }
   else
     {
@@ -1843,6 +1851,10 @@
 
       save_text_section = in_section;
       switch_to_section (unlikely_text_section ());
+      if (cold_partition_name != NULL_TREE)
+	ASM_DECLARE_FUNCTION_SIZE (asm_out_file,
+				   IDENTIFIER_POINTER (cold_partition_name),
+				   decl);
       ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_end_label);
       if (first_function_block_is_cold)
 	switch_to_section (text_section);
Index: gcc/varasm.h
===================================================================
--- gcc/varasm.h	(revision 218434)
+++ gcc/varasm.h	(working copy)
@@ -20,6 +20,13 @@
 #ifndef GCC_VARASM_H
 #define GCC_VARASM_H
 
+/* The following global holds the partition name for the code in the
+   cold section of a function, if hot/cold function splitting is enabled
+   and there was actually code that went into the cold section.  A
+   pseudo function name is needed for the cold section of code for some
+   debugging tools that perform symbolization. */
+extern tree cold_partition_name;
+
 extern tree tree_output_constant_def (tree);
 extern void make_decl_rtl (tree);
 extern rtx make_decl_rtl_for_debug (tree);

^ permalink raw reply	[flat|nested] 27+ messages in thread
* Re: [PATCH] Fix size & type for cold partition names (hot-cold function partitioning)
@ 2015-04-28 17:14 David Edelsohn
  2015-04-28 17:15 ` Caroline Tice
  0 siblings, 1 reply; 27+ messages in thread
From: David Edelsohn @ 2015-04-28 17:14 UTC (permalink / raw)
  To: Caroline Tice; +Cc: Jeffrey Law, GCC Patches

Caroline,

Your patch has broken bootstrap on AIX and probably other platforms.

/nasfarm/edelsohn/src/src/gcc/varasm.c: In function 'void
assemble_end_function(tree, const char*)':
/nasfarm/edelsohn/src/src/gcc/varasm.c:1870:12: error:
'ASM_DECLARE_FUNCTION_SIZE' was not declared in this scope
        decl);
            ^

You added a reference to ASM_DECLARE_FUNCTION_SIZE without guarding
it, as was done only 10 lines higher in the same function.  The macro
is not declared for all targets.

Also, the ChangeLog entry has numerous typos.

Please fix ASAP.

Thanks, David

^ permalink raw reply	[flat|nested] 27+ messages in thread
* Re: [PATCH] Fix size & type for cold partition names (hot-cold function partitioning)
@ 2015-04-29 16:48 Uros Bizjak
  2015-04-29 17:57 ` Caroline Tice
  0 siblings, 1 reply; 27+ messages in thread
From: Uros Bizjak @ 2015-04-29 16:48 UTC (permalink / raw)
  To: gcc-patches; +Cc: cmtice, Jeff Law, Richard Henderson

Hello!

> 2015-03-27  Caroline Tice  <cmtice@google.com>
>
>         * final.c (final_scan_insn): Change 'cold_function_name' to
>         'cold_partition_name' and make it a global variable; also output
>         assembly to give it a 'FUNC' type, if appropriate.
>         * varasm.c (cold_partition_name): Declare and initialize global
>         variable.
>         (assemble_start_function): Re-set value for cold_partition_name.
>         (assemble_end_function): Output assembly to calculate size of cold
>         partition, and associate size with name, if appropriate.
>         * varash.h (cold_partition_name): Add extern declaration for global
>         variable.
>         * testsuite/gcc.dg/tree-prof/cold_partition_label.c: Add dg-final-use
>         to scan assembly for cold partition name and size.

This patch caused PR 65929 [1].

Targets are (ab)using ASM_DECLARE_FUNCTION_NAME and
ASM_DECLARE_FUNCTION_SIZE for more things that their name suggests. As
shown in the PR, some directives that are generated through these
macros apply only to real functions, not to parts of function in the
middle of the function.

In the particular case in the PR, assembler doesn't tolerate nested
function declaration.

I suggest to revert the patch for now, until side effects of the patch
are resolved.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65929

Uros.

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2015-04-30 19:34 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-05 22:41 [PATCH] Fix size & type for cold partition names (hot-cold function partitioning) Caroline Tice
2014-12-08 21:07 ` Jeff Law
2015-03-27 16:45   ` Caroline Tice
2015-03-31  5:19     ` Jeff Law
2015-03-31 15:13       ` Caroline Tice
2015-03-31 15:17         ` Jeff Law
2015-04-28 17:14 David Edelsohn
2015-04-28 17:15 ` Caroline Tice
2015-04-28 17:16   ` Jeff Law
2015-04-28 17:17   ` Gerald Pfeifer
2015-04-28 17:33   ` David Edelsohn
2015-04-28 17:36     ` Caroline Tice
2015-04-29 16:48 Uros Bizjak
2015-04-29 17:57 ` Caroline Tice
2015-04-29 18:12   ` Uros Bizjak
2015-04-29 18:52     ` Uros Bizjak
2015-04-29 19:08       ` Caroline Tice
2015-04-29 21:30         ` Caroline Tice
2015-04-30  4:15           ` Jack Howarth
2015-04-30  6:40           ` Uros Bizjak
2015-04-30 16:36             ` Caroline Tice
2015-04-30 17:32               ` Uros Bizjak
2015-04-30 17:44               ` Richard Henderson
2015-04-30 19:34                 ` H.J. Lu
2015-04-30 19:34                   ` Caroline Tice
2015-04-30 19:38                     ` Uros Bizjak
2015-04-30 19:42                     ` H.J. Lu

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).