Fix hot/startup partitioning with LTO

Message ID 20191210174953.cbwbsz6ur6oxtgya@kam.mff.cuni.cz
State New
Headers show
Series
  • Fix hot/startup partitioning with LTO
Related show

Commit Message

Jan Hubicka Dec. 10, 2019, 5:49 p.m.
Hi,
as noticed by Martin's new heatmaps default_function_sections disables
test.unlikely and text.startup sections during LTO.  This was meant to
be only with tp_first_run profiling. The hot section is still useful
since it does "poor man's clustering" so I kept only the test to disable
startup subsection with corrected fix.

Bootstrapped/regtested x86_64-linux and checked that it works well with
heatmap.

Honza

	* varasm.c (default_function_section): Fix confused tests for
	tp_first_run reordering.

Patch

Index: varasm.c
===================================================================
--- varasm.c	(revision 279167)
+++ varasm.c	(working copy)
@@ -589,9 +589,13 @@  default_function_section (tree decl, enu
      where we can split away unnecessary parts of static constructors.  */
   if (startup && freq != NODE_FREQUENCY_UNLIKELY_EXECUTED)
   {
-    /* If we do have a profile or(and) LTO phase is executed, we do not need
-       these ELF section.  */
-    if (!in_lto_p || !flag_profile_values)
+    /* During LTO the tp_first_run profiling will naturally place all
+       initialization code first.  Using separate section is counter-productive
+       because startup only code may call functions which are no longer
+       startup only.  */
+    if (!in_lto_p
+        || !cgraph_node::get (decl)->tp_first_run
+	|| !opt_for_fn (decl, flag_profile_reorder_functions))
       return get_named_text_section (decl, ".text.startup", NULL);
     else
       return NULL;
@@ -607,10 +611,7 @@  default_function_section (tree decl, enu
       case NODE_FREQUENCY_UNLIKELY_EXECUTED:
 	return get_named_text_section (decl, ".text.unlikely", NULL);
       case NODE_FREQUENCY_HOT:
-        /* If we do have a profile or(and) LTO phase is executed, we do not need
-           these ELF section.  */
-        if (!in_lto_p || !flag_profile_values)
-          return get_named_text_section (decl, ".text.hot", NULL);
+        return get_named_text_section (decl, ".text.hot", NULL);
 	/* FALLTHRU */
       default:
 	return NULL;