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]

[tree-profiling] More cleanups


Hi,
this patch splits up lowering from early optimization.  This is usefull
so we can optimize functions already constructed in lowered form (for
instance by cprop clonning) and avoid the cgraph_build_cfg hack.  The
patch fixes bunch of failures in libmudflap and C++ and also some of
branch profiling ones, but not all.

Bootstrapped/regtested i686-pc-gnu-linux, will commit it shortly.

Honza

2004-11-29  Jan Hubicka  <jh@suse.cz>
	* cgraph.h (cgraph_node): Add "lowered" flag.
	(cgraph_build_cfg): Kill.
	(cgraph_lower_function): New.
	* cgraphunit.c: Kill bunch of includes introduced by cfg inliner patch.
	(cgraph_build_cfg): Kill.
	(cgraph_finalize_function): Set lowered flag.
	(cgraph_lower_function): New function.
	(cgraph_analyze_function): Lower the function; do early local passes iff
	unit-at-a-time
	(cgraph_expand_function): Do early passes iff !unit_at_a_time
	(cgraph_build_static_cdtor): Lower the function.
	* tree-optimize.c (all_lowering_passes): New static variable.
	(init_tree_optimization_passes): Split up lowering and optimization.
	(tree_early_local_passes): Do not lower function body.
	(tree_lowering_pass): New.
	* tree-pass.h (tree_lowering_passes): Declare.
	* cp/method.c: Include tree-pass.h
	(use_thunk): lower the body by hand.
Index: cgraph.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cgraph.h,v
retrieving revision 1.1.4.16.2.14
diff -c -3 -p -r1.1.4.16.2.14 cgraph.h
*** cgraph.h	17 Nov 2004 22:07:30 -0000	1.1.4.16.2.14
--- cgraph.h	28 Nov 2004 22:20:40 -0000
*************** struct cgraph_node GTY((chain_next ("%h.
*** 158,163 ****
--- 158,165 ----
    /* Set when function is reachable by call from other function
       that is either reachable or needed.  */
    bool reachable;
+   /* Set once the function is lowered (ie it's CFG is built).  */
+   bool lowered;
    /* Set once the function has been instantiated and its callee
       lists created.  */
    bool analyzed;
*************** struct cgraph_node *cgraph_master_clone 
*** 260,268 ****
  struct cgraph_node *cgraph_immortal_master_clone (struct cgraph_node *);
  
  /* In cgraphunit.c  */
- void cgraph_build_cfg (tree);
  bool cgraph_assemble_pending_functions (void);
  void cgraph_finalize_function (tree, bool);
  void cgraph_finalize_compilation_unit (void);
  void cgraph_create_edges (struct cgraph_node *, tree);
  void cgraph_optimize (void);
--- 262,270 ----
  struct cgraph_node *cgraph_immortal_master_clone (struct cgraph_node *);
  
  /* In cgraphunit.c  */
  bool cgraph_assemble_pending_functions (void);
  void cgraph_finalize_function (tree, bool);
+ void cgraph_lower_function (struct cgraph_node *);
  void cgraph_finalize_compilation_unit (void);
  void cgraph_create_edges (struct cgraph_node *, tree);
  void cgraph_optimize (void);
Index: cgraphunit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cgraphunit.c,v
retrieving revision 1.1.4.35.2.27
diff -c -3 -p -r1.1.4.35.2.27 cgraphunit.c
*** cgraphunit.c	28 Nov 2004 17:59:35 -0000	1.1.4.35.2.27
--- cgraphunit.c	28 Nov 2004 22:20:40 -0000
*************** Software Foundation, 59 Temple Place - S
*** 190,199 ****
  #include "c-common.h"
  #include "intl.h"
  #include "function.h"
- #include "tree-flow.h"
- #include "value-prof.h"
- #include "coverage.h"
- #include "except.h"
  #include "ipa_prop.h"
  #include "tree-gimple.h"
  #include "output.h"
--- 190,195 ----
*************** decide_is_function_needed (struct cgraph
*** 305,333 ****
    return false;
  }
  
- /* If the compilation has progressed this far for function FN,
-    it's time to build the CFG for it.
-    FIXME: this function causes a lot of includes to be needed.
-    Is there a better place for it?  */
- 
- void 
- cgraph_build_cfg (tree fn)
- {
-   if (!DECL_STRUCT_FUNCTION (fn)->cfg->x_entry_block_ptr)
-     {
-       tree saved_current_function_decl = current_function_decl;
-       current_function_decl = fn;
-       push_cfun (DECL_STRUCT_FUNCTION (fn));
-       lower_function_body ();
-       lower_eh_constructs ();
-       build_tree_cfg (&DECL_SAVED_TREE (fn));
-       current_function_decl = saved_current_function_decl;
-       pop_cfun ();
-     }
-   else
-     gcc_unreachable ();
- }
- 
  /* When not doing unit-at-a-time, output all functions enqueued.
     Return true when such a functions were found.  */
  
--- 301,306 ----
*************** cgraph_finalize_function (tree decl, boo
*** 443,448 ****
--- 416,422 ----
    notice_global_symbol (decl);
    node->decl = decl;
    node->local.finalized = true;
+   node->lowered = DECL_STRUCT_FUNCTION (decl)->cfg->x_entry_block_ptr != NULL;
    if (node->nested)
      lower_nested_functions (decl);
    gcc_assert (!node->nested);
*************** cgraph_finalize_function (tree decl, boo
*** 482,487 ****
--- 456,470 ----
      do_warn_unused_parameter (decl);
  }
  
+ void
+ cgraph_lower_function (struct cgraph_node *node)
+ {
+   if (node->lowered)
+     return;
+   tree_lowering_passes (node->decl);
+   node->lowered = true;
+ }
+ 
  /* Walk tree and record all calls.  Called via walk_tree.  */
  static tree
  record_call_1 (tree *tp, int *walk_subtrees, void *data)
*************** cgraph_analyze_function (struct cgraph_n
*** 849,855 ****
    push_cfun (DECL_STRUCT_FUNCTION (decl));
    current_function_decl = decl;
  
!   tree_early_local_passes (decl);
  
    /* First kill forward declaration so reverse inlining works properly.  */
    cgraph_create_edges (node, decl);
--- 832,840 ----
    push_cfun (DECL_STRUCT_FUNCTION (decl));
    current_function_decl = decl;
  
!   cgraph_lower_function (node);
!   if (flag_unit_at_a_time)
!     tree_early_local_passes (decl);
  
    /* First kill forward declaration so reverse inlining works properly.  */
    cgraph_create_edges (node, decl);
*************** cgraph_expand_function (struct cgraph_no
*** 1038,1043 ****
--- 1023,1030 ----
    /* Must have a CFG here at this point.  */
    gcc_assert (ENTRY_BLOCK_PTR_FOR_FUNCTION (DECL_STRUCT_FUNCTION (node->decl)));
  
+   if (!flag_unit_at_a_time)
+     tree_early_local_passes (decl);
    /* Generate RTL for the body of DECL.  */
    lang_hooks.callgraph.expand_function (decl);
  
*************** cgraph_build_static_cdtor (char which, t
*** 2370,2375 ****
--- 2357,2363 ----
    /* ??? We will get called LATE in the compilation process.  */
    if (cgraph_global_info_ready)
      {
+       tree_lowering_passes (decl);
        tree_early_local_passes (decl);
        tree_rest_of_compilation (decl);
      }
Index: tree-optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-optimize.c,v
retrieving revision 1.1.4.122.2.26
diff -c -3 -p -r1.1.4.122.2.26 tree-optimize.c
*** tree-optimize.c	28 Nov 2004 17:59:36 -0000	1.1.4.122.2.26
--- tree-optimize.c	28 Nov 2004 22:20:40 -0000
*************** bitmap vars_to_rename;
*** 55,61 ****
  bool in_gimple_form;
  
  /* The root of the compilation pass tree, once constructed.  */
! static struct tree_opt_pass *all_passes, *all_early_local_passes, *all_ipa_passes;
  
  /* Pass: dump the gimplified, inlined, functions.  */
  
--- 55,61 ----
  bool in_gimple_form;
  
  /* The root of the compilation pass tree, once constructed.  */
! static struct tree_opt_pass *all_passes, *all_lowering_passes, *all_early_local_passes, *all_ipa_passes;
  
  /* Pass: dump the gimplified, inlined, functions.  */
  
*************** init_tree_optimization_passes (void)
*** 370,376 ****
    struct tree_opt_pass **p;
  
  #define NEXT_PASS(PASS)  (p = next_pass_1 (p, &PASS))
!   p = &all_early_local_passes;
    NEXT_PASS (pass_gimple); 
    NEXT_PASS (pass_remove_useless_stmts);
    NEXT_PASS (pass_mudflap_1);
--- 370,380 ----
    struct tree_opt_pass **p;
  
  #define NEXT_PASS(PASS)  (p = next_pass_1 (p, &PASS))
! 
!   /* All passes needed to lower the function into shape optimizers can operate
!      on.  We need these to be separate from local optimization because C++ needs
!      to go into lowered form earlier to perfrom template instantiation.  */
!   p = &all_lowering_passes;
    NEXT_PASS (pass_gimple); 
    NEXT_PASS (pass_remove_useless_stmts);
    NEXT_PASS (pass_mudflap_1);
*************** init_tree_optimization_passes (void)
*** 378,386 ****
--- 382,402 ----
    NEXT_PASS (pass_lower_eh); 
    NEXT_PASS (pass_build_cfg); 
    NEXT_PASS (pass_pre_expand);
+   *p = NULL;
+ 
+   /* Optimizations passes run before the intraprocedural passes are done.  */
+   p = &all_early_local_passes;
    NEXT_PASS (pass_tree_profile); 
    NEXT_PASS (pass_cleanup_cfg);
+   *p = NULL;
+ 
+   /* Intraprocedural optimization passes.  */
+   p = &all_ipa_passes;
+   NEXT_PASS (pass_ipa_inline);
+   NEXT_PASS (pass_ipa_static);
+   *p = NULL;
  
+   /* Passes done after the intraprocedural passes.  */
    p = &all_passes;
    NEXT_PASS (pass_cleanup_cfg);
    NEXT_PASS (pass_init_datastructures);
*************** init_tree_optimization_passes (void)
*** 451,466 ****
    NEXT_PASS (pass_loop_done);
    *p = NULL;
  
-   p = &all_ipa_passes;
-   NEXT_PASS (pass_ipa_inline);
-   NEXT_PASS (pass_ipa_static);
-   *p = NULL;
- 
  #undef NEXT_PASS
  
!   /* Register the passes with the tree dump code.  */
!   /* HACK, PROP_* should go away.  */
!   register_dump_files (all_early_local_passes, false, 0);
    register_dump_files (all_passes, false, PROP_gimple_any
  					  | PROP_gimple_lcf
  					  | PROP_gimple_leh
--- 467,479 ----
    NEXT_PASS (pass_loop_done);
    *p = NULL;
  
  #undef NEXT_PASS
  
!   register_dump_files (all_lowering_passes, false, 0);
!   register_dump_files (all_early_local_passes, false, PROP_gimple_any
! 					  | PROP_gimple_lcf
! 					  | PROP_gimple_leh
! 					  | PROP_cfg);
    register_dump_files (all_passes, false, PROP_gimple_any
  					  | PROP_gimple_lcf
  					  | PROP_gimple_leh
*************** execute_pass_list (struct tree_opt_pass 
*** 651,663 ****
  }
  
  void
  tree_early_local_passes (tree fn)
  {
    tree saved_current_function_decl = current_function_decl;
  
    current_function_decl = fn;
    push_cfun (DECL_STRUCT_FUNCTION (fn));
!   lower_function_body ();
    execute_pass_list (all_early_local_passes, EXECUTE_HOOK, NULL, NULL);
    current_function_decl = saved_current_function_decl;
    compact_blocks ();
--- 664,690 ----
  }
  
  void
+ tree_lowering_passes (tree fn)
+ {
+   tree saved_current_function_decl = current_function_decl;
+ 
+   current_function_decl = fn;
+   push_cfun (DECL_STRUCT_FUNCTION (fn));
+   tree_register_cfg_hooks ();
+   execute_pass_list (all_lowering_passes, EXECUTE_HOOK, NULL, NULL);
+   current_function_decl = saved_current_function_decl;
+   compact_blocks ();
+   pop_cfun ();
+ }
+ 
+ void
  tree_early_local_passes (tree fn)
  {
    tree saved_current_function_decl = current_function_decl;
  
    current_function_decl = fn;
    push_cfun (DECL_STRUCT_FUNCTION (fn));
!   tree_register_cfg_hooks ();
    execute_pass_list (all_early_local_passes, EXECUTE_HOOK, NULL, NULL);
    current_function_decl = saved_current_function_decl;
    compact_blocks ();
Index: tree-pass.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-pass.h,v
retrieving revision 1.1.2.12.2.12
diff -c -3 -p -r1.1.2.12.2.12 tree-pass.h
*** tree-pass.h	28 Nov 2004 17:59:36 -0000	1.1.2.12.2.12
--- tree-pass.h	28 Nov 2004 22:20:40 -0000
*************** extern void ipa_modify_function (struct 
*** 138,143 ****
--- 138,144 ----
  extern void ipa_modify_variable (struct cgraph_varpool_node *vnode);
  extern void ipa_passes (void);
  extern void tree_early_local_passes (tree decl);
+ extern void tree_lowering_passes (tree decl);
  
  extern struct tree_opt_pass pass_mudflap_1;
  extern struct tree_opt_pass pass_mudflap_2;
Index: cp/method.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/method.c,v
retrieving revision 1.224.2.26.2.9
diff -c -3 -p -r1.224.2.26.2.9 method.c
*** cp/method.c	17 Nov 2004 22:07:59 -0000	1.224.2.26.2.9
--- cp/method.c	28 Nov 2004 22:20:41 -0000
*************** Boston, MA 02111-1307, USA.  */
*** 37,42 ****
--- 37,43 ----
  #include "tm_p.h"
  #include "target.h"
  #include "cgraph.h"
+ #include "tree-pass.h"
  
  /* Various flags to control the mangling process.  */
  
*************** use_thunk (tree thunk_fndecl, bool emit_
*** 488,495 ****
  
        thunk_fndecl = finish_function (0);
  
!       cgraph_build_cfg (thunk_fndecl);
! 
        expand_body (thunk_fndecl);
      }
  
--- 489,497 ----
  
        thunk_fndecl = finish_function (0);
  
!       /* ??? We really ought to find way not hooking into backend directly.  */
!       tree_lowering_passes (thunk_fndecl);
!       tree_early_local_passes (thunk_fndecl);
        expand_body (thunk_fndecl);
      }
  


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