This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[lto] Enable FDO with LTO


This patch fixes profile generation so it can be emitted in the
IL.  Essentially, all it does is move the call to coverage_finish
out of compile_file and into ipa_passes.

Most of the profile instrumentation is done before we write
gimple out, but the final creation of ctors and layout of global
counters was happening too late.

The remaining hunks are for minor bugs that FDO exposed:

- We were streaming out asm_written_flag for DECLs.  That's wrong
  since we need to do code generation again in LTO.
- cgraph_build_static_cdtor was not setting a context for
  RESULT_DECL.
- Since we don't need to run instrumentation in the lto1 FE, we don't
  re-compute profile_info.  This was expected by
  cgraph_decide_inlining.


I've tried this patch with 401.bzip2 from SPEC 2006.  I ran it
with

base=-O3 -ffast-math -fprofile-generate
peak=-O3 -ffast-math -fprofile-generate -fwhopr

By running profile generation in whole program mode, we get a 4%
improvement over basic profile generation.  This is good news as
it proves that cross-file inlining is working and that profile
instrumentation is generating better decisions when done in LTO.

I don't think we handle all of SPEC 2006 cleanly yet, but I will
try doing a run shortly and see what the numbers look like.

Bootstrapped and tested on x86_64.



	* lto-tree-flags.def (VAR_DECL, FUNCTION_DECL): Remove
	asm_written_flag.
	* toplev.c (compile_file): Move call to coverage_finish ...
	* cgraphunit.c (ipa_passes): ... here.
	Include coverage.h.
	(cgraph_build_static_cdtor): Set DECL_CONTEXT for RESDECL.
	* ipa-utils.c (ipa_utils_reduced_inorder): Handle
	CONSTRUCTOR nodes.
	* ipa-inline.c (cgraph_decide_inlining): Do not expect
	profile_info to be set in LTO.
	* Makefile.in (cgraphunit.o): Add dependency on COVERAGE_H.

Index: lto-tree-flags.def
===================================================================
--- lto-tree-flags.def	(revision 144118)
+++ lto-tree-flags.def	(working copy)
@@ -344,7 +344,6 @@
       ADD_EXPR_FLAG (addressable_flag)
       ADD_EXPR_FLAG (static_flag)
       ADD_EXPR_FLAG (public_flag)
-      ADD_EXPR_FLAG (asm_written_flag)
       ADD_EXPR_FLAG (nothrow_flag)
       ADD_EXPR_FLAG (readonly_flag)
       ADD_DECL_FLAG (nonlocal_flag)
@@ -805,7 +804,6 @@
       ADD_EXPR_FLAG (addressable_flag)
       ADD_EXPR_FLAG (static_flag)
       ADD_EXPR_FLAG (public_flag)
-      ADD_EXPR_FLAG (asm_written_flag)
       ADD_DECL_FLAG (nonlocal_flag)
       ADD_DECL_FLAG (virtual_flag)
       ADD_DECL_FLAG (abstract_flag)
Index: toplev.c
===================================================================
--- toplev.c	(revision 144118)
+++ toplev.c	(working copy)
@@ -996,11 +996,6 @@ compile_file (void)
   varpool_assemble_pending_decls ();
   finish_aliases_2 ();
 
-  /* This must occur after the loop to output deferred functions.
-     Else the coverage initializer would not be emitted if all the
-     functions in this compilation unit were deferred.  */
-  coverage_finish ();
-
   /* Likewise for mudflap static object registrations.  */
   if (flag_mudflap)
     mudflap_finish_file ();
Index: cgraphunit.c
===================================================================
--- cgraphunit.c	(revision 144118)
+++ cgraphunit.c	(working copy)
@@ -134,6 +134,7 @@ along with GCC; see the file COPYING3.  
 #include "tree-iterator.h"
 #include "tree-pass.h"
 #include "output.h"
+#include "coverage.h"
 
 static void cgraph_expand_all_functions (void);
 static void cgraph_mark_functions_to_output (void);
@@ -1262,6 +1263,14 @@ ipa_passes (void)
      inlined.  */
   cgraph_remove_unreachable_nodes (false, dump_file);
 
+  if (!in_lto_p)
+    {
+      coverage_finish ();
+      set_cfun (NULL);
+      current_function_decl = NULL;
+      cgraph_process_new_functions ();
+    }
+
   execute_ipa_summary_passes ((struct ipa_opt_pass *) all_regular_ipa_passes);
   execute_ipa_summary_passes ((struct ipa_opt_pass *) all_lto_gen_passes);
 
@@ -1433,6 +1442,7 @@ cgraph_build_static_cdtor (char which, t
   resdecl = build_decl (RESULT_DECL, NULL_TREE, void_type_node);
   DECL_ARTIFICIAL (resdecl) = 1;
   DECL_RESULT (decl) = resdecl;
+  DECL_CONTEXT (resdecl) = decl;
 
   allocate_struct_function (decl, false);
 
Index: ipa-utils.c
===================================================================
--- ipa-utils.c	(revision 144118)
+++ ipa-utils.c	(working copy)
@@ -210,14 +210,16 @@ ipa_utils_reduced_inorder (struct cgraph
 tree
 get_base_var (tree t)
 {
-  if ((TREE_CODE (t) == EXC_PTR_EXPR) || (TREE_CODE (t) == FILTER_EXPR))
+  if (TREE_CODE (t) == EXC_PTR_EXPR
+      || TREE_CODE (t) == FILTER_EXPR)
     return t;
 
   while (!SSA_VAR_P (t) 
 	 && (!CONSTANT_CLASS_P (t))
 	 && TREE_CODE (t) != LABEL_DECL
 	 && TREE_CODE (t) != FUNCTION_DECL
-	 && TREE_CODE (t) != CONST_DECL)
+	 && TREE_CODE (t) != CONST_DECL
+	 && TREE_CODE (t) != CONSTRUCTOR)
     {
       t = TREE_OPERAND (t, 0);
     }
Index: ipa-inline.c
===================================================================
--- ipa-inline.c	(revision 144118)
+++ ipa-inline.c	(working copy)
@@ -1106,7 +1106,9 @@ cgraph_decide_inlining (void)
 	    max_count = e->count;
       }
   overall_insns = initial_insns;
-  gcc_assert (!max_count || (profile_info && flag_branch_probabilities));
+  gcc_assert (!in_lto_p
+	      || !max_count
+	      || (profile_info && flag_branch_probabilities));
 
   nnodes = cgraph_postorder (order);
 
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 144118)
+++ Makefile.in	(working copy)
@@ -2675,7 +2675,7 @@ cgraphunit.o : cgraphunit.c $(CONFIG_H) 
    $(TARGET_H) $(CGRAPH_H) intl.h pointer-set.h $(FUNCTION_H) $(GIMPLE_H) \
    $(TREE_FLOW_H) tree-pass.h $(C_COMMON_H) debug.h $(DIAGNOSTIC_H) \
    $(FIBHEAP_H) output.h $(PARAMS_H) $(RTL_H) $(TIMEVAR_H) $(IPA_PROP_H) \
-   gt-cgraphunit.h tree-iterator.h
+   gt-cgraphunit.h tree-iterator.h $(COVERAGE_H)
 cgraphbuild.o : cgraphbuild.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
    $(TREE_H) langhooks.h $(CGRAPH_H) intl.h pointer-set.h $(GIMPLE_H) \
    $(TREE_FLOW_H) tree-pass.h


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]