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]

CFG transparent inlining


Hi,
this patch makes the inlining happen on CFG. This is essential for profile
guided inlining and some other IPA patches waiting to be merged on
tree-profiling branch.  The patch is incremental patch to exception handling
change I sent eaelier this week and I pushed it out mainline to avoid slipping
schedule even further.

The basic idea is to make first few passes of tree-ssa path happen early
(tree_lowering_passes) and inlining happens on CFG.  This allows optimizations
to happen first (this is not included in this patch but on tree-profiling we
have pre-inline passes) and it allows easier analysis in IPA.
We plan to extend this in future to allow inlining on SSA form, but this requires
futher work and this seems like resonable stopping point.

The patch makes no slowdown on gcc module compilation test with -O3.  For some
testcases the memory requirements are increased because stmt and cfg
annotations are expensive.  I have some followup patches to at least release
memory needed by stmt operands but it would be nice to work in the direction of
decomposing the structures into part that needs to survive and part that needs
not.  On some testcases we actually save memory just because of early cleanups
(from GCC intermodule we are down from 1GB to 700MB after end of analysis
stage).

Bootstrapped/regtested i686-pc-gnu-linux,x86-64-linux,ppc-linux and ia64-linux
(last two only in earlier incarnation of patch before resolving some further
conflicts on moving mainline)

I am aware that the patch somes late in schedule, but still hope it will be applicable
for mainline because it is quite important for the other development on IPA to happen.

The work was originally done by Stuart, Dale, later merged into tree-profiling
by Steven and now cleaned up by me.

Honza

2005-04-28  Jan Hubicka  <jh@suse.cz>

	* tree-inline.c (execute_fixup_cfg): New function
	(pass_fixup_cfg): New variable.
	(init_tree_optimization_passes): Add new pass.

2005-04-26  Steven Bosscher  <stevenb@suse.de>

	* tree-inline.c: Fix various boring code style and white space issues.

2005-04-21  Jan Hubicka  <jh@suse.cz>

	* basic-block.h (FOR_ALL_BB_FN): New macro.
	* cfg.c (init_flow): Allocate the CFG.
	* cgraphunit.c (cgraph_finalize_function): Modify checking of presence
	of cfg.
	* except.c (duplicate_eh_regions): New argument outer_region; simplify.
	(get_eh_cur_region, set_eh_cur_region): Kill.
	* except.h (duplicate_eh_regions): Update prototype.
	(get_eh_cur_region, set_eh_cur_region): Kill.
	* function.c (allocate_struct_function): Kill creation of CFG object.
	* tree-cfg.c (init_empty_tree_cfg): Export.
	(label_to_block_fn): Do not crash on dead label never inserted to the
	stream.
	(dump_function_to_file): Modify checking of CFG presence.
	* tree-eh (duplicate_stmt_eh_region_mapping): Get it working after
	regions has been copied.
	* tree-flow.h (init_empty_tree_cfg): Declare.
	* tree-inline.c (inline_data): Kill ret_label, ret_count, original_tsi,
	bind_expr,
	copy_basic_block, return_block, oic_basic_block fields; add block field.
	(remap_decl): Work on block instead of bind_expr.
	(copy_body_r): Likewise; do not modify CFG, work after duplicating eh
	regions.
	(copy_bb): Simplify and use local variables.
	(copy_edges_for_bb): Rewrite handling of EH.
	(copy_cfg_body): Do not create shadow CFG, allow inserting directly
	into other's CFG, simplify.
	(copy_body): Update call of copy_cfg_body.
	(setup_one_parameter): Insert insns into basic block; simplify.
	(initialize_inlined_parameters): Likewise; work on block instead of
	bind_expr.
	(inline_forbidden_p): Kill abort call.
	(estimate_num_insns): Likewise.
	(expand_call_inline): Simplify; do not create hords of unnecesary
	datastructures.
	(gimple_expand_calls_inline): Simplify.
	(optimize_inline_calls): Push gimple context; simplify.
	(declare_inline_vars): Work on block instead of bind_expr.
	(tree_function_versioning): Kill abort; update for new interfaces.
	(create_block_annotation): Kill.
	* tree-optimize.c: Check presence of saved body by saved_cfg.

2005-04-19  Jan Hubicka  <jh@suse.cz>

	* tree-cfg.c (init_empty-tree_cfg): Do not clear basic_block_info size.
	(build_tree_cfg): Bring mostly into sync with mainline.
	(make_blocks): Likewise.
	(create_bb): Likewise.
	(tree_verify_flow_info): Likewise.
	(tree_forwarder_block_p): Likewise.
	* tree-inline.c (inline_data): Kill copy_tsi.
	(copy_body_r): Set stmt to NULL if it should not be added.
	(copy_bb): Revamp to use BSIs; simplify.
	(copy_edges_for_bb): Use BSIs.

2005-04-18  Jan Hubicka  <jh@suse.cz>

	* tree-inline.c (copy_bb): Break out from ....
	(copy_edges_for_bb): Break out from ....
	(copy_cfg): ... here; reorganize way old and new blocks are mapped
	together.

2005-04-16  Jan Hubicka  <jh@suse.cz>

	* tree-inline.c (remap_decl): Use inlining_p.
	(copy_bb): Break out of ....
	(copy_cfg_body): ... here.

	* tree-inline.c (expand_call_inline): Remove if 0 block in
	expand_call_inline.

2005-03-05  Jan Hubicka  <jh@suse.cz>

	* tree-flow.h (maybe_fold_stmt_indirect): Declare.
	* tree-inline.c (copy_body_r): Declare.
	(maybe_fold_stmt_indirect): Export.

2004-12-17  Jan Hubicka  <jh@suse.cz>

	* tree-inline.c (initialize_inlined_parameters): Do not throw away
	DECLs from BIND expr.

2004-12-08  Jan Hubicka  <jh@suse.cz>

	* tree-inline.c (optimize_inline_calls): Recount frequencies.

2004-12-07  Jan Hubicka  <jh@suse.cz>

	* tree-inline.c (copy_cfg_body, copy_body): New count argument;
	update profile.
	(copy_body_r, expand_call_inline): Update profiling.

2004-12-05  Dale Johannesen  <dalej@apple.com>

	* except.c (get_maybe_saved_eh_throw_stmt_table): Remove.
	* except.h (get_maybe_saved_eh_throw_stmt_table): Remove.
	* tree-eh.c (duplicate_stmt_eh_region_mapping): Call
	get_eh_throw_stmt_table instead of above.
	* tree-inline.c (struct inline_data): Add callee_cfun.
	(copy_body_r): Use it.
	(copy_cfg_body): Set and use it.
	(clone_body): Set it.
	(save_body): Set it.

2004-12-02  Steven Bosscher  <stevenb@suse.de>

	* tree-inline.c: Fix indenting and other style issues.

2004-12-01  Jan Hubicka  <jh@suse.cz>

	* tree-inline.c (copy_body_r): Do not alter source stmt when
	removing return of void.
2004-12-01  Jan Hubicka  <jh@suse.cz>

	* cgraph.h (cgraph_node): Kill unused fileds brought by cfg inliner
	patch.
	(cgraph_edge): Add undesirable field.
	* cgraphunit.c: Include coverage.h
	(cgraph_estimate_size_after_inlining): Rever hack brought by cfg
	inliner patch; add sanity check.
	(cgraph_decide_recursive_inlining): Don't work hard if function
	has no uninlined callees.
	(cgraph_maybe_hot_edge_p): New predicate.
	(cgraph_desirability): Compute something nonzero.
	(cgraph_pick_most_desirable_edge): Don't inline already inlined;
	don't bypass inline limits.
	(cgraph_analyze_function_inlinability): Compute nonzero function sizes.
	* tree-inline.c (estimate_num_insns): Kill bogus void cast.

2004-11-17  Stuart Hastings <stuarth@apple.com>
	    Dale Johannesen  <dalej@apple.com>

	* Makefile.in (tree-inline.o): Add dependency on $(TREE_FLOW_H) and
	on except.h.
	(tree-eh.o): Don't depend on gt-tree-eh.h.
	(tree-pretty-print.o): Don't depend on tree-iterator.h.
	(except.o): Add dependency on $(TREE_FLOW_H).
	(cgraph.o): Likewise.
	(cgraphunit.o): Add dependency on except.h and coverage.h.
	(GTFILES): Remove $(srcdir)/except.c.  Add $(srcdir)/tree-inline.c.
	* basic-block.h (FOR_EACH_BB_FN, FOR_EACH_BB_REVERSE_FN): New.
	(FOR_EACH_BB, FOR_EACH_BB_REVERSE): Define in terms of the above.
	* cfg.c (init_flow): Don't clear n_edges.
	* cfglayout.c (flow_obstack): Don't declare.
	* cgraph.c: Include basic-block.h.
	(cgraph_create_edge): Set edge_count.
	(cgraph_remove_node): Remove nodes for inlined nested functions.
	* cgraph.h: Include tree.h and basic-block.h.
	(struct cgraph_node): Add the fields current_basic_block,
	insn_size, and most_desirable.
	(cgraph_node, cgraph_edge, cgraph_varpool_node, cgraph_inline_p,
	cgraph_mark_inline_edge, cgraph_clone_inlined_nodes,
	cgraph_build_static_cdtor): Cleanup prototypes.
	* cgraphunit.c: Include basic-block.h, tree-iterator.h, tree-flow.h,
	value-prof.h, coverage.h, and except.h.
	(cgraph_build_cfg): New.  Build the CFG for a function.
	(record_call_1): Don't look at STATEMENT_LIST nodes.
	(cgraph_create_edges): Handle FUNCTION_DECLs as special cases when
	looking for things to add to the call graph.
	(verify_cgraph_node): Use walk_tree with a pointer set instead of
	walk_tree_without_duplicates.
	(cgraph_varpool_analyze_pending_decls): Only look at DECL_INITIAL
	for things to add to the call graph when it is non-NULL.
	(cgraph_analyze_function): Build the CFG from here.
	(cgraph_expand_function): Make sure there is a CFG at this point.
	(cgraph_estimate_growth): Avoid negative size estimates.
	(cgraph_clone_inlined_nodes): Avoid cleating duplicate, unnecessary
	clones.
	(cgraph_clone_inlined_nodes_1): New, callback for the above.
	(cgraph_mark_inline_edge): Handle simple recursion.
	(cgraph_desirability): New, determine how "desirable" it is for
	some given function to be inlined.
	(cgraph_pick_most_desirable_edge): New, find the inline candidate
	most desirable to be inlined.
	(cgraph_profile_driven_inlining): New.
	(cgraph_decide_inlining_of_small_function): Don't compute max_insns
	from here.
	(cgraph_decide_inlining): Do it here.
	(cgraph_build_static_cdtor): If all else fails, build a CFG from here,
	for irregular functions such as mudflap.
	* except.c: Include tree-iterator.h, tree-inline.h, and tree-flow.h.
	(struct eh_status): Add per-function throw_stmt_table hash table.
	(eh_region_must_not_throw_p): New.
	(expand_resx_expr): Add sanity check.
	(current_function_has_exception_handlers):
	(duplicate_eh_region_1): Rewrite for trees.
	(duplicate_eh_region_2): Likewise.
	(duplicate_eh_regions): Likewise.
	(remove_eh_handler): No longer static.  Make sure there is EH info
	for the current function cfun.
	(change_to_nothrow): New, fixup EH statements for which we've later
	figured out that they don't actually throw.
	(set_nothrow_function_flags): Call it.
	(set_eh_throw_stmt_table): New.
	(get_eh_throw_stmt_table): New.
	(get_maybe_saved_eh_throw_stmt_table): New.
	(get_eh_last_region_number): New.
	(get_eh_cur_region): New.
	(set_eh_cur_region): New.
	* except.h (duplicate_eh_regions): Adjust prototype after rewrite.
	(add_stmt_to_eh_region_fn, remove_stmt_from_eh_region_fn,
	lookup_stmt_eh_region_fn): New prototypes.
	(struct throw_stmt_node): Moved from tree-eh.c.
	(remove_eh_handler, set_eh_throw_stmt_table, get_eh_throw_stmt_table,
	get_maybe_saved_eh_throw_stmt_table, get_eh_last_region_number,
	get_eh_cur_region, set_eh_cur_region, eh_region_must_not_throw_p):
	More new prototypes.
	* expr.c (expand_expr_real): Beware of MODIFY_EXPRs and RETURN_EXPRs
	that might throw at the end of a function.
	* function.c (allocate_struct_function): Clear n_edges here.
	* function.h (struct function): Add saved_eh and saved_cfg fields.
	* gengtype.c (open_base_files): Remove except.h from headers to
	analyze.
	* gimple-low.c (lower_function_body): No longer static.
	* integrate.c (copy_decl_for_inlining): Clear LABEL_DECL_UID for
	copied labels.
	* langhooks-def.h (lhd_tree_inlining_add_pending_fn_decls,
	lhd_tree_inlining_start_inlining, lhd_tree_inlining_end_inlining):
	Remove prototypes.
	(lhd_tree_inlining_copy_res_decl_for_inlining): Add prototype.
	(LANG_HOOKS_TREE_INLINING_ADD_PENDING_FN_DECLS,
	LANG_HOOKS_TREE_INLINING_START_INLINING,
	LANG_HOOKS_TREE_INLINING_END_INLINING): Remove.
	(LANG_HOOKS_TREE_INLINING_COPY_RES_DECL_FOR_INLINING): New hook.
	(lhd_tree_inlining_disregard_inline_limit):
	(lhd_tree_inlining_add_pending_fn_decls):
	(lhd_tree_inlining_auto_var_in_fn_p):
	(lhd_tree_inlining_copy_res_decl_for_inlining):
	(lhd_tree_inlining_anon_aggr_type_p):
	(lhd_tree_inlining_start_inlining):
	(lhd_tree_inlining_end_inlining):
	* langhooks.c (lhd_tree_inlining_add_pending_fn_decls,
	lhd_tree_inlining_start_inlining, lhd_tree_inlining_end_inlining):
	Remove.
	(lhd_tree_inlining_copy_res_decl_for_inlining): New default hook.
	* langhooks.h (struct lang_hooks_for_tree_inlining): Adjust.
	* passes.c: Don't include alloc-pool.h.
	* print-tree.c: Include tree-iterator.h.
	(print_node): Print STATEMENT_LIST nodes.
	* tree-cfg.c (build_tree_cfg): No longer static.  Create
	ENTRY_BLOCK_PTR and EXIT_BLOCK_PTR here.
	(make_blocks): Purge basic_block_info.  Rechain split statements.
	Let statements in an EH region end a basic block.
	(make_edges): Make edges for blocks ending with an EH statement.
	(label_to_block): Rename to...
	(label_to_block_fn): ... this.  Work per function.
	(remove_useless_stmts_warn_notreached): Disable.
	(remove_useless_stmts_bind): Likewise.
	(remove_useless_stmts_1): Don't use them. Tighten up checks.
	(remove_useless_stmts): Rewrite to be basic block aware.
	(set_bb_for_stmt): Force the multiply to happen before the divide.
	(tree_forwarder_block_p): Don't forward forced labels.
	* tree-eh.c (struct throw_stmt_node): Removed here, moved to except.c.
	(add_stmt_to_eh_region_fn): New.
	(remove_stmt_from_eh_region_fn): New.
	(lookup_stmt_eh_region_fn): New.
	(record_stmt_eh_region): Get the table from cfun.
	(add_stmt_to_eh_region): Likewise.
	(remove_stmt_from_eh_region): Likewise.
	(lookup_stmt_eh_region): Likewise.
	(duplicate_stmt_eh_region_mapping): New function to preserve stmt EH
	mapping during inlining.
	(honor_protect_cleanup_actions): Use build_resx.
	(lower_try_finally_onedest): Likewise.
	(lower_try_finally_copy): Likewise.
	(lower_try_finally_switch): Likewise.
	(lower_eh_constructs): No longer static.
	(make_eh_edges): If a MUST_NOT_THROW region contains a call that
	throws, don't remove it.
	* tree-flow.h (build_tree_cfg): New prototype.
	(label_to_block): Make it a define.  Rename prototype to...
	(label_to_block_fn): ... this.
	(do_tree_profiling): New prototype.
	* tree-inline.c: Mostly rewritten for CFG inlining.
	* tree-inline.h (remap_decl_v): New prototype.
	(push_cfun, pop_cfun): Likewise.
	* tree-optimize.c (pass_gimple): Remove.
	(pass_lower_cf, pass_lower_eh, pass_build_cfg): Disable, we do
	this much earlier.  Needs to be cleaned up.
	(pass_tree_profile, pass_profile): Disable for now.
	(init_tree_optimization_passes): Hard-code initial properties.
	(tree_rest_of_compilation): Register the tree cfg hooks.  Preserve
	the CFG and EH data before optimizing.
	(pass_ipa_static): Disable for now, see the comments in that pass that
	need addressing.
	* tree-pass.h (pass_lower_cf): Remove.
	* tree-pretty-print.c: Don't include tree-iterator.h.
	* tree-profile.c (do_tree_profiling): No longer static.
	* tree.c (build_resx): New.
	* tree.h (lower_function_body, duplicate_stmt_eh_region_mapping,
	lower_eh_constructs): New prototypes.
diff -c3p /aux/hubicka/egcs2/gcc/gcc/basic-block.h gcc/basic-block.h
*** /aux/hubicka/egcs2/gcc/gcc/basic-block.h	Thu Apr 28 21:39:25 2005
--- gcc/basic-block.h	Wed Apr 27 20:21:38 2005
*************** extern bool rediscover_loops_after_threa
*** 444,449 ****
--- 444,452 ----
  #define FOR_ALL_BB(BB) \
    for (BB = ENTRY_BLOCK_PTR; BB; BB = BB->next_bb)
  
+ #define FOR_ALL_BB_FN(BB, FN) \
+   for (BB = ENTRY_BLOCK_PTR_FOR_FUNCTION (FN); BB; BB = BB->next_bb)
+ 
  /* Special labels found during CFG build.  */
  
  extern GTY(()) rtx label_value_list;
diff -c3p /aux/hubicka/egcs2/gcc/gcc/cfg.c gcc/cfg.c
*** /aux/hubicka/egcs2/gcc/gcc/cfg.c	Thu Apr 28 21:39:29 2005
--- gcc/cfg.c	Wed Apr 27 20:52:33 2005
*************** static void free_edge (edge);
*** 78,84 ****
  void
  init_flow (void)
  {
! 
    ENTRY_BLOCK_PTR = ggc_alloc_cleared (sizeof (struct basic_block_def));
    ENTRY_BLOCK_PTR->index = ENTRY_BLOCK;
    EXIT_BLOCK_PTR = ggc_alloc_cleared (sizeof (struct basic_block_def));
--- 78,86 ----
  void
  init_flow (void)
  {
!   if (!cfun->cfg)
!     cfun->cfg = ggc_alloc_cleared (sizeof (struct control_flow_graph));
!   n_edges = 0;
    ENTRY_BLOCK_PTR = ggc_alloc_cleared (sizeof (struct basic_block_def));
    ENTRY_BLOCK_PTR->index = ENTRY_BLOCK;
    EXIT_BLOCK_PTR = ggc_alloc_cleared (sizeof (struct basic_block_def));
diff -c3p /aux/hubicka/egcs2/gcc/gcc/cfgbuild.c gcc/cfgbuild.c
*** /aux/hubicka/egcs2/gcc/gcc/cfgbuild.c	Thu Mar 17 14:25:56 2005
--- gcc/cfgbuild.c	Thu Apr 28 13:00:57 2005
*************** rtl_make_eh_edge (sbitmap edge_cache, ba
*** 205,212 ****
    handlers = reachable_handlers (insn);
  
    for (i = handlers; i; i = XEXP (i, 1))
!     make_label_edge (edge_cache, src, XEXP (i, 0),
! 		     EDGE_ABNORMAL | EDGE_EH | is_call);
  
    free_INSN_LIST_list (&handlers);
  }
--- 205,220 ----
    handlers = reachable_handlers (insn);
  
    for (i = handlers; i; i = XEXP (i, 1))
!     {
!       /* After inlining function marked NOTHROW into MUST_NOT_THROW region
! 	 with throwing instructions we may end up with missing EH landing
! 	 pad for the exceptions.  It seems safe to ignore them (by setting
! 	 NOTHOROW flag on the function user promised this scenario to not
! 	 happen).  See filter2.C testcase.  */
!       if (XEXP (i, 0))
! 	make_label_edge (edge_cache, src, XEXP (i, 0),
! 			 EDGE_ABNORMAL | EDGE_EH | is_call);
!     }
  
    free_INSN_LIST_list (&handlers);
  }
diff -c3p /aux/hubicka/egcs2/gcc/gcc/cgraph.h gcc/cgraph.h
*** /aux/hubicka/egcs2/gcc/gcc/cgraph.h	Thu Apr 28 21:39:30 2005
--- gcc/cgraph.h	Wed Apr 27 20:45:43 2005
*************** struct cgraph_node GTY((chain_next ("%h.
*** 117,122 ****
--- 117,124 ----
    /* 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;
*************** bool decide_is_variable_needed (struct c
*** 215,220 ****
--- 217,223 ----
  bool cgraph_assemble_pending_functions (void);
  bool cgraph_varpool_assemble_pending_decls (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);
diff -c3p /aux/hubicka/egcs2/gcc/gcc/except.c gcc/except.c
*** /aux/hubicka/egcs2/gcc/gcc/except.c	Fri Apr 29 15:26:03 2005
--- gcc/except.c	Thu Apr 28 18:42:55 2005
*************** current_function_has_exception_handlers 
*** 853,858 ****
--- 853,1011 ----
    return false;
  }
  
+ static struct eh_region *
+ duplicate_eh_region_1 (struct eh_region *o)
+ {
+   struct eh_region *n = ggc_alloc_cleared (sizeof (struct eh_region));
+   
+   n->region_number = o->region_number + cfun->eh->last_region_number;
+   n->type = o->type;
+   gcc_assert (!o->aka);
+   
+   switch (n->type)
+     {
+     case ERT_CLEANUP:
+     case ERT_MUST_NOT_THROW:
+       break;
+       
+     case ERT_TRY:
+       break;
+       
+     case ERT_CATCH:
+       n->u.catch.type_list = o->u.catch.type_list;
+       break;
+       
+     case ERT_ALLOWED_EXCEPTIONS:
+       n->u.allowed.type_list = o->u.allowed.type_list;
+       break;
+       
+     case ERT_THROW:
+       n->u.throw.type = o->u.throw.type;
+       
+     default:
+       abort ();
+     }
+   
+   return n;
+ }
+ 
+ static void
+ duplicate_eh_region_2 (struct eh_region *o, struct eh_region **n_array)
+ {
+   struct eh_region *n = n_array[o->region_number];
+   
+   switch (n->type)
+     {
+     case ERT_TRY:
+       if (o->u.try.catch)
+         n->u.try.catch = n_array[o->u.try.catch->region_number];
+       if (o->u.try.last_catch)
+         n->u.try.last_catch = n_array[o->u.try.last_catch->region_number];
+       break;
+       
+     case ERT_CATCH:
+       if (o->u.catch.next_catch)
+ 	n->u.catch.next_catch = n_array[o->u.catch.next_catch->region_number];
+       if (o->u.catch.prev_catch)
+ 	n->u.catch.prev_catch = n_array[o->u.catch.prev_catch->region_number];
+       break;
+ 
+     case ERT_CLEANUP:
+       if (o->u.cleanup.prev_try)
+ 	n->u.cleanup.prev_try = n_array[o->u.cleanup.prev_try->region_number];
+       break;
+       
+     default:
+       break;
+     }
+   
+   if (o->outer)
+     n->outer = n_array[o->outer->region_number];
+   if (o->inner)
+     n->inner = n_array[o->inner->region_number];
+   if (o->next_peer)
+     n->next_peer = n_array[o->next_peer->region_number];
+ }
+ 
+ /* Duplicate the EH regions of IFUN into current function, root the tree in
+    OUTER_REGION and remap labels using MAP callback.  */
+ int
+ duplicate_eh_regions (struct function *ifun, duplicate_eh_regions_map map,
+ 		      void *data, int outer_region)
+ {
+   int ifun_last_region_number = ifun->eh->last_region_number;
+   struct eh_region **n_array, *root, *cur;
+   int i;
+   
+   if (ifun_last_region_number == 0 || !ifun->eh->region_tree)
+     return 0;
+   
+   n_array = xcalloc (ifun_last_region_number + 1, sizeof (*n_array));
+   
+   for (i = 1; i <= ifun_last_region_number; ++i)
+     {
+       cur = ifun->eh->region_array[i];
+       if (!cur || cur->region_number != i)
+ 	continue;
+       n_array[i] = duplicate_eh_region_1 (cur);
+       if (cur->tree_label)
+ 	{
+ 	  tree newlabel = map (cur->tree_label, data);
+ 	  n_array[i]->tree_label = newlabel;
+ 	}
+       else
+ 	n_array[i]->tree_label = NULL;
+     }
+   for (i = 1; i <= ifun_last_region_number; ++i)
+     {
+       cur = ifun->eh->region_array[i];
+       if (!cur || cur->region_number != i)
+ 	continue;
+       duplicate_eh_region_2 (cur, n_array);
+     }
+   
+   root = n_array[ifun->eh->region_tree->region_number];
+   gcc_assert (root->outer == NULL);
+   if (outer_region > 0)
+     {
+       struct eh_region *cur = cfun->eh->region_array[outer_region];
+       struct eh_region *p = cur->inner;
+ 
+       if (p)
+ 	{
+ 	  while (p->next_peer)
+ 	    p = p->next_peer;
+ 	  p->next_peer = root;
+ 	}
+       else
+         cur->inner = root;
+       for (i = 1; i <= ifun_last_region_number; ++i)
+ 	if (n_array[i] && n_array[i]->outer == NULL)
+ 	  n_array[i]->outer = cur;
+     }
+   else
+     {
+       struct eh_region *p = cfun->eh->region_tree;
+       if (p)
+ 	{
+ 	  while (p->next_peer)
+ 	    p = p->next_peer;
+ 	  p->next_peer = root;
+ 	}
+       else
+         cfun->eh->region_tree = root;
+     }
+   
+   free (n_array);
+   
+   i = cfun->eh->last_region_number;
+   cfun->eh->last_region_number = i + ifun_last_region_number;
+   
+   collect_eh_region_array ();
+   
+   return i;
+ }
+ 
  static int
  t2r_eq (const void *pentry, const void *pdata)
  {
*************** reachable_next_level (struct eh_region *
*** 2273,2280 ****
        /* Here we end our search, since no exceptions may propagate.
  	 If we've touched down at some landing pad previous, then the
  	 explicit function call we generated may be used.  Otherwise
! 	 the call is made by the runtime.  */
!       if (info && info->saw_any_handlers)
  	{
  	  add_reachable_handler (info, region, region);
  	  return RNL_CAUGHT;
--- 2426,2437 ----
        /* Here we end our search, since no exceptions may propagate.
  	 If we've touched down at some landing pad previous, then the
  	 explicit function call we generated may be used.  Otherwise
! 	 the call is made by the runtime. 
! 
! 	 Be conservative before inlining since new subregions may be
! 	 introduced.  fixup_cfg pass takes care of removing unnecesary
! 	 EH edges later on.  */
!       if ((info && info->saw_any_handlers) || !cfun->after_inlining)
  	{
  	  add_reachable_handler (info, region, region);
  	  return RNL_CAUGHT;
*************** htab_t
*** 3448,3453 ****
--- 3605,3618 ----
  get_eh_throw_stmt_table (struct function *fun)
  {
    return fun->eh->throw_stmt_table;
+ }
+ 
+ int
+ get_eh_last_region_number (struct function *ifun)
+ {
+   if (!ifun || !ifun->eh)
+     return -1;
+   return ifun->eh->last_region_number;
  }
  
  /* Dump EH information to OUT.  */
diff -c3p /aux/hubicka/egcs2/gcc/gcc/except.h gcc/except.h
*** /aux/hubicka/egcs2/gcc/gcc/except.h	Fri Apr 29 15:26:03 2005
--- gcc/except.h	Thu Apr 28 13:02:32 2005
*************** extern void expand_eh_return (void);
*** 81,86 ****
--- 81,90 ----
  extern rtx expand_builtin_extend_pointer (tree);
  extern rtx get_exception_pointer (struct function *);
  extern rtx get_exception_filter (struct function *);
+ typedef tree (*duplicate_eh_regions_map) (tree, void *);
+ extern int duplicate_eh_regions (struct function *, duplicate_eh_regions_map, void *, int);
+ void duplicate_stmt_eh_region_mapping (struct function *, 
+ 				       struct function *, tree, tree, bool);
  
  extern void sjlj_emit_function_exit_after (rtx);
  
*************** struct throw_stmt_node GTY(())
*** 170,172 ****
--- 174,177 ----
  
  extern void set_eh_throw_stmt_table (struct function *, void *);
  extern struct htab *get_eh_throw_stmt_table (struct function *);
+ extern int get_eh_last_region_number (struct function *);
diff -c3p /aux/hubicka/egcs2/gcc/gcc/function.c gcc/function.c
*** /aux/hubicka/egcs2/gcc/gcc/function.c	Thu Apr 28 21:39:35 2005
--- gcc/function.c	Fri Apr 29 00:05:30 2005
*************** allocate_struct_function (tree fndecl)
*** 3908,3916 ****
    tree fntype = fndecl ? TREE_TYPE (fndecl) : NULL_TREE;
  
    cfun = ggc_alloc_cleared (sizeof (struct function));
-   cfun->cfg = ggc_alloc_cleared (sizeof (struct control_flow_graph));
- 
-   n_edges = 0;
  
    cfun->stack_alignment_needed = STACK_BOUNDARY;
    cfun->preferred_stack_boundary = STACK_BOUNDARY;
--- 3908,3913 ----
diff -c3p /aux/hubicka/egcs2/gcc/gcc/function.h gcc/function.h
*** /aux/hubicka/egcs2/gcc/gcc/function.h	Thu Apr 28 21:39:35 2005
--- gcc/function.h	Fri Apr 29 00:05:30 2005
*************** struct expr_status GTY(())
*** 162,173 ****
--- 162,176 ----
  struct function GTY(())
  {
    struct eh_status *eh;
+   struct eh_status *saved_eh;
    struct expr_status *expr;
    struct emit_status *emit;
    struct varasm_status *varasm;
  
    /* The control flow graph for this function.  */
    struct control_flow_graph *cfg;
+   struct control_flow_graph *saved_cfg;
+   bool after_inlining;
  
    /* For tree-optimize.c.  */
  
diff -c3p /aux/hubicka/egcs2/gcc/gcc/integrate.c gcc/integrate.c
*** /aux/hubicka/egcs2/gcc/gcc/integrate.c	Thu Apr 28 21:39:38 2005
--- gcc/integrate.c	Fri Apr 29 00:05:31 2005
*************** copy_decl_for_inlining (tree decl, tree 
*** 121,126 ****
--- 121,127 ----
        if (TREE_CODE (copy) == LABEL_DECL)
  	{
  	  TREE_ADDRESSABLE (copy) = 0;
+           LABEL_DECL_UID (copy) = -1;
  	}
      }
  
diff -c3p /aux/hubicka/egcs2/gcc/gcc/tree-cfg.c gcc/tree-cfg.c
*** /aux/hubicka/egcs2/gcc/gcc/tree-cfg.c	Thu Apr 28 21:39:44 2005
--- gcc/tree-cfg.c	Thu Apr 28 22:30:12 2005
*************** static tree find_case_label_for_value (t
*** 132,137 ****
--- 132,157 ----
  static bool phi_alternatives_equal (basic_block, edge, edge);
  static bool cleanup_forwarder_blocks (void);
  
+ void
+ init_empty_tree_cfg (void)
+ {
+   /* Initialize the basic block array.  */
+   init_flow ();
+   profile_status = PROFILE_ABSENT;
+   n_basic_blocks = 0;
+   last_basic_block = 0;
+   VARRAY_BB_INIT (basic_block_info, initial_cfg_capacity, "basic_block_info");
+ 
+   /* Build a mapping of labels to their associated blocks.  */
+   VARRAY_BB_INIT (label_to_block_map, initial_cfg_capacity,
+ 		  "label to block map");
+ 
+   ENTRY_BLOCK_PTR->next_bb = EXIT_BLOCK_PTR;
+   EXIT_BLOCK_PTR->prev_bb = ENTRY_BLOCK_PTR;
+ 
+   create_block_annotation (ENTRY_BLOCK_PTR);
+   create_block_annotation (EXIT_BLOCK_PTR);
+ }
  
  /*---------------------------------------------------------------------------
  			      Create basic blocks
*************** build_tree_cfg (tree *tp)
*** 146,165 ****
    /* Register specific tree functions.  */
    tree_register_cfg_hooks ();
  
-   /* Initialize the basic block array.  */
-   init_flow ();
-   profile_status = PROFILE_ABSENT;
-   n_basic_blocks = 0;
-   last_basic_block = 0;
-   VARRAY_BB_INIT (basic_block_info, initial_cfg_capacity, "basic_block_info");
    memset ((void *) &cfg_stats, 0, sizeof (cfg_stats));
  
!   /* Build a mapping of labels to their associated blocks.  */
!   VARRAY_BB_INIT (label_to_block_map, initial_cfg_capacity,
! 		  "label to block map");
! 
!   ENTRY_BLOCK_PTR->next_bb = EXIT_BLOCK_PTR;
!   EXIT_BLOCK_PTR->prev_bb = ENTRY_BLOCK_PTR;
  
    found_computed_goto = 0;
    make_blocks (*tp);
--- 166,174 ----
    /* Register specific tree functions.  */
    tree_register_cfg_hooks ();
  
    memset ((void *) &cfg_stats, 0, sizeof (cfg_stats));
  
!   init_empty_tree_cfg ();
  
    found_computed_goto = 0;
    make_blocks (*tp);
*************** build_tree_cfg (tree *tp)
*** 176,184 ****
    if (n_basic_blocks == 0)
      create_empty_bb (ENTRY_BLOCK_PTR);
  
-   create_block_annotation (ENTRY_BLOCK_PTR);
-   create_block_annotation (EXIT_BLOCK_PTR);
-   
    /* Adjust the size of the array.  */
    VARRAY_GROW (basic_block_info, n_basic_blocks);
  
--- 185,190 ----
*************** create_bb (void *h, void *e, basic_block
*** 436,442 ****
  
  /* Fold COND_EXPR_COND of each COND_EXPR.  */
  
! static void
  fold_cond_expr_cond (void)
  {
    basic_block bb;
--- 442,448 ----
  
  /* Fold COND_EXPR_COND of each COND_EXPR.  */
  
! void
  fold_cond_expr_cond (void)
  {
    basic_block bb;
*************** label_to_block_fn (struct function *ifun
*** 823,828 ****
--- 829,836 ----
        bsi_insert_before (&bsi, stmt, BSI_NEW_STMT);
        uid = LABEL_DECL_UID (dest);
      }
+   if (VARRAY_SIZE (ifun->cfg->x_label_to_block_map) <= (unsigned int)uid)
+     return NULL;
    return VARRAY_BB (ifun->cfg->x_label_to_block_map, uid);
  }
  
diff -c3p /aux/hubicka/egcs2/gcc/gcc/tree-eh.c gcc/tree-eh.c
*** /aux/hubicka/egcs2/gcc/gcc/tree-eh.c	Fri Apr 29 15:26:03 2005
--- gcc/tree-eh.c	Thu Apr 28 20:13:21 2005
*************** lookup_stmt_eh_region (tree t)
*** 174,179 ****
--- 174,227 ----
    return lookup_stmt_eh_region_fn (cfun, t);
  }
  
+ /* While duplicating the tree for ifun, check if old_tree was mapped
+    to an EH region in ifun.  If yes, create a mapping from new_tree to
+    the corresponding duplicate EH region in cfun.  The duplicate
+    region doesn't exist yet; it will be created later, once this
+    duplicate function tree is complete.  */
+ 
+ void
+ duplicate_stmt_eh_region_mapping (struct function *ifun, 
+ 				  struct function *cfun,
+ 				  tree old_tree, 
+ 				  tree new_tree,
+ 				  bool adjust_number)
+ {
+   struct throw_stmt_node *p, old, *new;
+   htab_t cfun_hash, ifun_hash;
+   void **slot;
+   
+   ifun_hash = (htab_t)get_eh_throw_stmt_table (ifun);
+   if (!ifun_hash)
+     return;
+   
+   old.stmt = old_tree;
+   p = (struct throw_stmt_node *)htab_find (ifun_hash, &old);
+   
+   if (p)
+     {
+       cfun_hash = (htab_t)get_eh_throw_stmt_table (cfun);
+       
+       if (!cfun_hash)
+ 	{
+ 	  cfun_hash = htab_create_ggc (31, struct_ptr_hash, struct_ptr_eq, ggc_free);
+ 	  set_eh_throw_stmt_table (cfun, (void *)cfun_hash);
+ 	}
+       
+       /* old_tree was mapped to some EH region; create a similar
+ 	 mapping for new_tree.  */
+       new = (struct throw_stmt_node *)ggc_alloc (sizeof (*new));
+       new->stmt = new_tree;
+       new->region_nr = p->region_nr;
+       if (adjust_number)
+ 	new->region_nr += get_eh_last_region_number (cfun) - get_eh_last_region_number (ifun);
+       slot = htab_find_slot (cfun_hash, (void *)new, INSERT);
+       if (*slot)
+ 	abort ();
+       *slot = (void *)new;
+     }
+ }
+ 
  
  /* First pass of EH node decomposition.  Build up a tree of TRY_FINALLY_EXPR
     nodes and LABEL_DECL nodes.  We will use this during the second phase to
*************** tree_could_throw_p (tree t)
*** 2020,2026 ****
  bool
  tree_can_throw_internal (tree stmt)
  {
!   int region_nr = lookup_stmt_eh_region (stmt);
    if (region_nr < 0)
      return false;
    return can_throw_internal_1 (region_nr);
--- 2068,2079 ----
  bool
  tree_can_throw_internal (tree stmt)
  {
!   int region_nr;
! 
!   if (TREE_CODE (stmt) == RESX_EXPR)
!     region_nr = TREE_INT_CST_LOW (TREE_OPERAND (stmt, 0));
!   else
!     region_nr = lookup_stmt_eh_region (stmt);
    if (region_nr < 0)
      return false;
    return can_throw_internal_1 (region_nr);
*************** tree_can_throw_external (tree stmt)
*** 2031,2038 ****
  {
    int region_nr = lookup_stmt_eh_region (stmt);
    if (region_nr < 0)
!     return false;
!   return can_throw_external_1 (region_nr);
  }
  
  bool
--- 2084,2092 ----
  {
    int region_nr = lookup_stmt_eh_region (stmt);
    if (region_nr < 0)
!     return tree_could_throw_p (stmt);
!   else
!     return can_throw_external_1 (region_nr);
  }
  
  bool
diff -c3p /aux/hubicka/egcs2/gcc/gcc/tree-flow.h gcc/tree-flow.h
*** /aux/hubicka/egcs2/gcc/gcc/tree-flow.h	Thu Apr 28 21:39:44 2005
--- gcc/tree-flow.h	Thu Apr 28 22:30:51 2005
*************** extern tree gimplify_build2 (block_stmt_
*** 545,550 ****
--- 545,552 ----
  			     tree, tree, tree);
  extern tree gimplify_build3 (block_stmt_iterator *, enum tree_code,
  			     tree, tree, tree, tree);
+ extern void init_empty_tree_cfg (void);
+ extern void fold_cond_expr_cond (void);
  
  /* In tree-pretty-print.c.  */
  extern void dump_generic_bb (FILE *, basic_block, int, int);
*************** void set_current_def (tree, tree);
*** 632,637 ****
--- 634,640 ----
  
  /* In tree-ssa-ccp.c  */
  bool fold_stmt (tree *);
+ tree maybe_fold_stmt_indirect (tree, tree, tree);
  tree widen_bitfield (tree, tree, tree);
  
  /* In tree-vrp.c  */
diff -c3p /aux/hubicka/egcs2/gcc/gcc/tree-inline.c gcc/tree-inline.c
*** /aux/hubicka/egcs2/gcc/gcc/tree-inline.c	Thu Apr 28 21:39:45 2005
--- gcc/tree-inline.c	Thu Apr 28 22:30:08 2005
*************** Boston, MA 02111-1307, USA.  */
*** 32,55 ****
  #include "params.h"
  #include "input.h"
  #include "insn-config.h"
- #include "integrate.h"
  #include "varray.h"
  #include "hashtab.h"
  #include "splay-tree.h"
  #include "langhooks.h"
  #include "cgraph.h"
  #include "intl.h"
  #include "tree-mudflap.h"
  #include "tree-flow.h"
  #include "function.h"
  #include "diagnostic.h"
  #include "debug.h"
  
  /* I'm not real happy about this, but we need to handle gimple and
     non-gimple trees.  */
- #include "tree-iterator.h"
  #include "tree-gimple.h"
  
  /* 0 if we should not perform inlining.
     1 if we should expand functions calls inline at the tree level.
     2 if we should consider *all* functions to be inline
--- 32,89 ----
  #include "params.h"
  #include "input.h"
  #include "insn-config.h"
  #include "varray.h"
  #include "hashtab.h"
  #include "splay-tree.h"
  #include "langhooks.h"
+ #include "basic-block.h"
+ #include "tree-iterator.h"
  #include "cgraph.h"
  #include "intl.h"
  #include "tree-mudflap.h"
  #include "tree-flow.h"
  #include "function.h"
+ #include "ggc.h"
+ #include "tree-flow.h"
  #include "diagnostic.h"
+ #include "except.h"
  #include "debug.h"
+ #include "pointer-set.h"
+ #include "integrate.h"
  
  /* I'm not real happy about this, but we need to handle gimple and
     non-gimple trees.  */
  #include "tree-gimple.h"
  
+ /* Inlining, Saving, Cloning
+ 
+    Inlining: a function body is duplicated, but the PARM_DECLs are
+    remapped into VAR_DECLs, and non-void RETURN_EXPRs become
+    MODIFY_EXPRs that store to a dedicated returned-value variable.
+    The duplicated eh_region info of the copy will later be appended
+    to the info for the caller; the eh_region info in copied throwing
+    statements and RESX_EXPRs is adjusted accordingly.
+ 
+    Saving: make a semantically-identical copy of the function body.
+    Necessary when we want to generate code for the body (a destructive
+    operation), but we expect to need this body in the future (e.g. for
+    inlining into another function).
+ 
+    Cloning: (only in C++) We have one body for a con/de/structor, and
+    multiple function decls, each with a unique parameter list.
+    Duplicate the body, using the given splay tree; some parameters
+    will become constants (like 0 or 1).
+ 
+    All of these will simultaneously lookup any callgraph edges.  If
+    we're going to inline the duplicated function body, and the given
+    function has some cloned callgraph nodes (one for each place this
+    function will be inlined) those callgraph edges will be duplicated.
+    If we're saving or cloning the body, those callgraph edges will be
+    updated to point into the new body.  (Note that the original
+    callgraph node and edge list will not be altered.)
+ 
+    See the CALL_EXPR handling case in copy_body_r ().  */
+ 
  /* 0 if we should not perform inlining.
     1 if we should expand functions calls inline at the tree level.
     2 if we should consider *all* functions to be inline
*************** int flag_inline_trees = 0;
*** 73,100 ****
  
  typedef struct inline_data
  {
!   /* A stack of the functions we are inlining.  For example, if we are
!      compiling `f', which calls `g', which calls `h', and we are
!      inlining the body of `h', the stack will contain, `h', followed
!      by `g', followed by `f'.  The first few elements of the stack may
!      contain other functions that we know we should not recurse into,
!      even though they are not directly being inlined.  */
!   varray_type fns;
!   /* The index of the first element of FNS that really represents an
!      inlined function.  */
!   unsigned first_inlined_fn;
!   /* The label to jump to when a return statement is encountered.  If
!      this value is NULL, then return statements will simply be
!      remapped as return statements, rather than as jumps.  */
!   tree ret_label;
    /* The VAR_DECL for the return value.  */
    tree retvar;
    /* The map from local declarations in the inlined function to
       equivalents in the function into which it is being inlined.  */
    splay_tree decl_map;
-   /* Nonzero if we are currently within the cleanup for a
-      TARGET_EXPR.  */
-   int in_target_cleanup_p;
    /* We use the same mechanism to build clones that we do to perform
       inlining.  However, there are a few places where we need to
       distinguish between those two situations.  This flag is true if
--- 107,125 ----
  
  typedef struct inline_data
  {
!   /* FUNCTION_DECL for function being inlined.  */
!   tree callee;
!   /* FUNCTION_DECL for function being inlined into.  */
!   tree caller;
!   /* struct function for function being inlined.  Usually this is the same
!      as DECL_STRUCT_FUNCTION (callee), but can be different if saved_cfg
!      and saved_eh are in use.  */
!   struct function *callee_cfun;
    /* The VAR_DECL for the return value.  */
    tree retvar;
    /* The map from local declarations in the inlined function to
       equivalents in the function into which it is being inlined.  */
    splay_tree decl_map;
    /* We use the same mechanism to build clones that we do to perform
       inlining.  However, there are a few places where we need to
       distinguish between those two situations.  This flag is true if
*************** typedef struct inline_data
*** 102,140 ****
    bool cloning_p;
    /* Similarly for saving function body.  */
    bool saving_p;
-   /* Hash table used to prevent walk_tree from visiting the same node
-      umpteen million times.  */
-   htab_t tree_pruner;
    /* Callgraph node of function we are inlining into.  */
    struct cgraph_node *node;
    /* Callgraph node of currently inlined function.  */
    struct cgraph_node *current_node;
!   /* Statement iterator.  We need this so we can keep the tree in
!      gimple form when we insert the inlined function.   It is not
!      used when we are not dealing with gimple trees.  */
!   tree_stmt_iterator tsi;
  } inline_data;
  
  /* Prototypes.  */
  
  static tree copy_body_r (tree *, int *, void *);
! static tree copy_body (inline_data *);
! static tree expand_call_inline (tree *, int *, void *);
! static void expand_calls_inline (tree *, inline_data *);
  static bool inlinable_function_p (tree);
  static tree remap_decl (tree, inline_data *);
  static tree remap_type (tree, inline_data *);
- static tree initialize_inlined_parameters (inline_data *, tree,
- 					   tree, tree, tree);
  static void remap_block (tree *, inline_data *);
  static tree remap_decls (tree, inline_data *);
  static void copy_bind_expr (tree *, int *, inline_data *);
  static tree mark_local_for_remap_r (tree *, int *, void *);
  static void unsave_expr_1 (tree);
  static tree unsave_r (tree *, int *, void *);
! static void declare_inline_vars (tree bind_expr, tree vars);
  static void remap_save_expr (tree *, void *, int *);
  
  /* Insert a tree->tree mapping for ID.  Despite the name suggests
     that the trees should be variables, it is used for more than that.  */
  
--- 127,163 ----
    bool cloning_p;
    /* Similarly for saving function body.  */
    bool saving_p;
    /* Callgraph node of function we are inlining into.  */
    struct cgraph_node *node;
    /* Callgraph node of currently inlined function.  */
    struct cgraph_node *current_node;
!   /* Current BLOCK.  */
!   tree block;
!   /* Exception region the inlined call like in.  */
!   int eh_region;
  } inline_data;
  
  /* Prototypes.  */
  
+ static tree declare_return_variable (inline_data *, tree, tree, tree *);
  static tree copy_body_r (tree *, int *, void *);
! static tree copy_generic_body (inline_data *);
  static bool inlinable_function_p (tree);
  static tree remap_decl (tree, inline_data *);
  static tree remap_type (tree, inline_data *);
  static void remap_block (tree *, inline_data *);
+ static tree remap_decl (tree, inline_data *);
  static tree remap_decls (tree, inline_data *);
  static void copy_bind_expr (tree *, int *, inline_data *);
  static tree mark_local_for_remap_r (tree *, int *, void *);
  static void unsave_expr_1 (tree);
  static tree unsave_r (tree *, int *, void *);
! static void declare_inline_vars (tree, tree);
! static void add_lexical_block (tree, tree);
  static void remap_save_expr (tree *, void *, int *);
  
+ static inline bool inlining_p (inline_data *id);
+ 
  /* Insert a tree->tree mapping for ID.  Despite the name suggests
     that the trees should be variables, it is used for more than that.  */
  
*************** insert_decl_map (inline_data *id, tree k
*** 151,171 ****
  		       (splay_tree_value) value);
  }
  
! /* Remap DECL during the copying of the BLOCK tree for the function.
!    We are only called to remap local variables in the current function.  */
  
  static tree
  remap_decl (tree decl, inline_data *id)
  {
!   splay_tree_node n = splay_tree_lookup (id->decl_map, (splay_tree_key) decl);
!   tree fn = VARRAY_TOP_TREE (id->fns);
  
!   /* See if we have remapped this declaration.  If we didn't already have an
!      equivalent for this declaration, create one now.  */
    if (!n)
      {
        /* Make a copy of the variable or label.  */
!       tree t = copy_decl_for_inlining (decl, fn, VARRAY_TREE (id->fns, 0));
  
        /* Remember it, so that if we encounter this local entity again
  	 we can reuse this copy.  Do this early because remap_type may
--- 174,201 ----
  		       (splay_tree_value) value);
  }
  
! /* Remap DECL during the copying of the BLOCK tree for the function.  */
  
  static tree
  remap_decl (tree decl, inline_data *id)
  {
!   splay_tree_node n;
!   tree fn;
  
!   /* We only remap local variables in the current function.  */
!   fn = id->callee;
! 
!   /* See if we have remapped this declaration.  */
! 
!   n = splay_tree_lookup (id->decl_map, (splay_tree_key) decl);
! 
!   /* If we didn't already have an equivalent for this declaration,
!      create one now.  */
    if (!n)
      {
        /* Make a copy of the variable or label.  */
!       tree t;
!       t = copy_decl_for_inlining (decl, fn, id->caller);
  
        /* Remember it, so that if we encounter this local entity again
  	 we can reuse this copy.  Do this early because remap_type may
*************** remap_decl (tree decl, inline_data *id)
*** 184,197 ****
        walk_tree (&DECL_SIZE (t), copy_body_r, id, NULL);
        walk_tree (&DECL_SIZE_UNIT (t), copy_body_r, id, NULL);
  
-       /* If fields, do likewise for offset and qualifier.  */
-       if (TREE_CODE (t) == FIELD_DECL)
- 	{
- 	  walk_tree (&DECL_FIELD_OFFSET (t), copy_body_r, id, NULL);
- 	  if (TREE_CODE (DECL_CONTEXT (t)) == QUAL_UNION_TYPE)
- 	    walk_tree (&DECL_QUALIFIER (t), copy_body_r, id, NULL);
- 	}
- 
  #if 0
        /* FIXME handle anon aggrs.  */
        if (! DECL_NAME (t) && TREE_TYPE (t)
--- 214,219 ----
*************** remap_decl (tree decl, inline_data *id)
*** 214,219 ****
--- 236,251 ----
  	}
  #endif
  
+       /* If we are inlining and this is a variable (not a label), declare the
+ 	 remapped variable in the callers' body.  */
+       if (inlining_p (id)
+ 	  && (TREE_CODE (t) == VAR_DECL
+ 	      || TREE_CODE (t) == PARM_DECL))
+ 	declare_inline_vars (id->block, t);
+ 
+       /* Remember it, so that if we encounter this local entity
+ 	 again we can reuse this copy.  */
+       insert_decl_map (id, decl, t);
        return t;
      }
  
*************** remap_type (tree type, inline_data *id)
*** 234,242 ****
    if (node)
      return (tree) node->value;
  
!   /* The type only needs remapping if it's variably modified by a variable
!      in the function we are inlining.  */
!   if (! variably_modified_type_p (type, VARRAY_TOP_TREE (id->fns)))
      {
        insert_decl_map (id, type, type);
        return type;
--- 266,273 ----
    if (node)
      return (tree) node->value;
  
!   /* The type only needs remapping if it's variably modified.  */
!   if (! variably_modified_type_p (type, id->callee))
      {
        insert_decl_map (id, type, type);
        return type;
*************** remap_type (tree type, inline_data *id)
*** 305,310 ****
--- 336,354 ----
          walk_tree (&TYPE_MAX_VALUE (new), copy_body_r, id, NULL);
        return new;
  
+     case POINTER_TYPE:
+       TREE_TYPE (new) = t = remap_type (TREE_TYPE (new), id);
+       TYPE_NEXT_PTR_TO (new) = TYPE_POINTER_TO (t);
+       TYPE_POINTER_TO (t) = new;
+       return new;
+ 
+     case REFERENCE_TYPE:
+       TREE_TYPE (new) = t = remap_type (TREE_TYPE (new), id);
+       TYPE_NEXT_REF_TO (new) = TYPE_REFERENCE_TO (t);
+       TYPE_REFERENCE_TO (t) = new;
+       return new;
+ 
+     case METHOD_TYPE:
      case FUNCTION_TYPE:
        TREE_TYPE (new) = remap_type (TREE_TYPE (new), id);
        walk_tree (&TYPE_ARG_TYPES (new), copy_body_r, id, NULL);
*************** remap_block (tree *block, inline_data *i
*** 383,389 ****
    /* Remap its variables.  */
    BLOCK_VARS (new_block) = remap_decls (BLOCK_VARS (old_block), id);
  
!   fn = VARRAY_TREE (id->fns, 0);
  #if 1
    /* FIXME!  It shouldn't be so hard to manage blocks.  Rebuilding them in
       rest_of_compilation is a good start.  */
--- 427,433 ----
    /* Remap its variables.  */
    BLOCK_VARS (new_block) = remap_decls (BLOCK_VARS (old_block), id);
  
!   fn = id->caller;
  #if 1
    /* FIXME!  It shouldn't be so hard to manage blocks.  Rebuilding them in
       rest_of_compilation is a good start.  */
*************** static void
*** 414,428 ****
  copy_statement_list (tree *tp)
  {
    tree_stmt_iterator oi, ni;
!   tree new;
  
!   new = alloc_stmt_list ();
!   ni = tsi_start (new);
!   oi = tsi_start (*tp);
!   *tp = new;
! 
!   for (; !tsi_end_p (oi); tsi_next (&oi))
      tsi_link_after (&ni, tsi_stmt (oi), TSI_NEW_STMT);
  }
  
  static void
--- 458,471 ----
  copy_statement_list (tree *tp)
  {
    tree_stmt_iterator oi, ni;
!   tree newlist;
  
!   newlist = alloc_stmt_list ();
!   ni = tsi_start (newlist);
!   for (oi = tsi_start (*tp); !tsi_end_p (oi); tsi_next (&oi))
      tsi_link_after (&ni, tsi_stmt (oi), TSI_NEW_STMT);
+ 
+   *tp = newlist;
  }
  
  static void
*************** copy_bind_expr (tree *tp, int *walk_subt
*** 443,493 ****
      BIND_EXPR_VARS (*tp) = remap_decls (BIND_EXPR_VARS (*tp), id);
  }
  
! /* Called from copy_body via walk_tree.  DATA is really an `inline_data *'.  */
  
  static tree
  copy_body_r (tree *tp, int *walk_subtrees, void *data)
  {
    inline_data *id = (inline_data *) data;
!   tree fn = VARRAY_TOP_TREE (id->fns);
! 
! #if 0
!   /* All automatic variables should have a DECL_CONTEXT indicating
!      what function they come from.  */
!   if ((TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == LABEL_DECL)
!       && DECL_NAMESPACE_SCOPE_P (*tp))
!     gcc_assert (DECL_EXTERNAL (*tp) || TREE_STATIC (*tp));
! #endif
  
!   /* If this is a RETURN_EXPR, change it into a MODIFY_EXPR and a
!      GOTO_EXPR with the RET_LABEL as its target.  */
!   if (TREE_CODE (*tp) == RETURN_EXPR && id->ret_label)
!     {
!       tree return_stmt = *tp;
!       tree goto_stmt;
! 
!       /* Build the GOTO_EXPR.  */
!       tree assignment = TREE_OPERAND (return_stmt, 0);
!       goto_stmt = build1 (GOTO_EXPR, void_type_node, id->ret_label);
!       TREE_USED (id->ret_label) = 1;
  
        /* If we're returning something, just turn that into an
! 	 assignment into the equivalent of the original
! 	 RESULT_DECL.  */
!       if (assignment)
!         {
! 	  /* Do not create a statement containing a naked RESULT_DECL.  */
! 	  if (TREE_CODE (assignment) == RESULT_DECL)
! 	    gimplify_stmt (&assignment);
! 
! 	  *tp = build (BIND_EXPR, void_type_node, NULL, NULL, NULL);
! 	  append_to_statement_list (assignment, &BIND_EXPR_BODY (*tp));
! 	  append_to_statement_list (goto_stmt, &BIND_EXPR_BODY (*tp));
!         }
!       /* If we're not returning anything just do the jump.  */
!       else
! 	*tp = goto_stmt;
      }
    /* Local variables and labels need to be replaced by equivalent
       variables.  We don't want to copy static variables; there's only
       one of those, no matter how many times we inline the containing
--- 486,530 ----
      BIND_EXPR_VARS (*tp) = remap_decls (BIND_EXPR_VARS (*tp), id);
  }
  
! /* Called from copy_body_id via walk_tree.  DATA is really an
!    `inline_data *'.  */
  
  static tree
  copy_body_r (tree *tp, int *walk_subtrees, void *data)
  {
    inline_data *id = (inline_data *) data;
!   tree fn = id->callee;
  
!   /* Begin by recognizing trees that we'll completely rewrite for the
!      inlining context.  Our output for these trees is completely
!      different from out input (e.g. RETURN_EXPR is deleted, and morphs
!      into an edge).  Further down, we'll handle trees that get
!      duplicated and/or tweaked.  */
! 
!   /* If this is a RETURN_STMT, change it into an EXPR_STMT and a
!      GOTO_STMT with the RET_LABEL as its target.  */
!   if (TREE_CODE (*tp) == RETURN_EXPR && inlining_p (id))
!     {
!       tree assignment = TREE_OPERAND (*tp, 0);
  
        /* If we're returning something, just turn that into an
! 	 assignment into the equivalent of the original RESULT_DECL.
! 	 If the "assignment" is just the result decl, the result
! 	 decl has already been set (e.g. a recent "foo (&result_decl,
! 	 ...)"); just toss the entire RETURN_EXPR.  */
!       if (assignment && TREE_CODE (assignment) == MODIFY_EXPR)
! 	{
! 	  /* Replace the RETURN_EXPR with (a copy of) the
! 	     MODIFY_EXPR hangning underneath.  */
! 	  *tp = copy_node (assignment);
! 	}
!       else /* Else the RETURN_EXPR returns no value.  */
! 	{
! 	  *tp = NULL;
! 	  return (void *)1;
! 	}
      }
+ 
    /* Local variables and labels need to be replaced by equivalent
       variables.  We don't want to copy static variables; there's only
       one of those, no matter how many times we inline the containing
*************** copy_body_r (tree *tp, int *walk_subtree
*** 505,513 ****
        *walk_subtrees = 0;
      }
    else if (TREE_CODE (*tp) == STATEMENT_LIST)
!     copy_statement_list (tp);
    else if (TREE_CODE (*tp) == SAVE_EXPR)
      remap_save_expr (tp, id->decl_map, walk_subtrees);
    else if (TREE_CODE (*tp) == BIND_EXPR)
      copy_bind_expr (tp, walk_subtrees, id);
    /* Types may need remapping as well.  */
--- 542,557 ----
        *walk_subtrees = 0;
      }
    else if (TREE_CODE (*tp) == STATEMENT_LIST)
!     {
!       tree *step_p = tp;
!       for (step_p = tp; step_p && *step_p; step_p = &TREE_CHAIN (*step_p))
! 	copy_statement_list (step_p);
!     }
    else if (TREE_CODE (*tp) == SAVE_EXPR)
      remap_save_expr (tp, id->decl_map, walk_subtrees);
+   else if (TREE_CODE (*tp) == LABEL_DECL)
+     /* These may need to be remapped for EH handling.  */
+     remap_decl (*tp, id);
    else if (TREE_CODE (*tp) == BIND_EXPR)
      copy_bind_expr (tp, walk_subtrees, id);
    /* Types may need remapping as well.  */
*************** copy_body_r (tree *tp, int *walk_subtree
*** 539,544 ****
--- 583,591 ----
      {
        tree old_node = *tp;
  
+       /* Here we handle trees that are not completely rewritten.
+ 	 First we detect some inlining-induced bogosities for
+ 	 discarding.  */
        if (TREE_CODE (*tp) == MODIFY_EXPR
  	  && TREE_OPERAND (*tp, 0) == TREE_OPERAND (*tp, 1)
  	  && (lang_hooks.tree_inlining.auto_var_in_fn_p
*************** copy_body_r (tree *tp, int *walk_subtree
*** 572,599 ****
  	  n = splay_tree_lookup (id->decl_map, (splay_tree_key) decl);
  	  if (n)
  	    {
  	      value = (tree) n->value;
  	      STRIP_NOPS (value);
! 	      if (TREE_CODE (value) == ADDR_EXPR
! 		  && (lang_hooks.types_compatible_p
! 		      (TREE_TYPE (*tp), TREE_TYPE (TREE_OPERAND (value, 0)))))
! 		{
! 		  *tp = TREE_OPERAND (value, 0);
! 		  return copy_body_r (tp, walk_subtrees, data);
! 		}
  	    }
  	}
  
        copy_tree_r (tp, walk_subtrees, NULL);
! 
!       if (TREE_CODE (*tp) == CALL_EXPR && id->node && get_callee_fndecl (*tp))
  	{
  	  if (id->saving_p)
  	    {
  	      struct cgraph_node *node;
                struct cgraph_edge *edge;
  
! 	      for (node = id->node->next_clone; node; node = node->next_clone)
  		{
  		  edge = cgraph_edge (node, old_node);
  		  gcc_assert (edge);
--- 619,663 ----
  	  n = splay_tree_lookup (id->decl_map, (splay_tree_key) decl);
  	  if (n)
  	    {
+ 	      tree copy, folded;
  	      value = (tree) n->value;
  	      STRIP_NOPS (value);
! 	      copy = build1 (INDIRECT_REF, TREE_TYPE (*tp), (tree) n->value);
! 	      if ((folded = maybe_fold_stmt_indirect (copy, value,
! 						      integer_zero_node)))
! 		*tp = folded;
! 	      else
! 		*tp = copy;
! 	      *walk_subtrees = 0;
! 	      return NULL;
  	    }
  	}
  
+       /* Here is the "usual case".  Copy this tree node, and then
+ 	 tweak some special cases.  */
        copy_tree_r (tp, walk_subtrees, NULL);
!       if (id->block
! 	  && IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (*tp))))
! 	TREE_BLOCK (*tp) = id->block;
! 
!       /* We're duplicationg a CALL_EXPR.  Find any corresponding
! 	 callgraph edges and update or duplicate them.  */
!       if (TREE_CODE (*tp) == CALL_EXPR
! 	  && id->node
! 	  && get_callee_fndecl (*tp))
  	{
  	  if (id->saving_p)
  	    {
  	      struct cgraph_node *node;
                struct cgraph_edge *edge;
  
! 	      /* We're saving a copy of the body, so we'll update the
! 		 callgraph nodes in place.  Note that we avoid
! 		 altering the original callgraph node; we begin with
! 		 the first clone.  */
! 	      for (node = id->node->next_clone;
! 		   node;
! 		   node = node->next_clone)
  		{
  		  edge = cgraph_edge (node, old_node);
  		  gcc_assert (edge);
*************** copy_body_r (tree *tp, int *walk_subtree
*** 602,614 ****
  	    }
  	  else
  	    {
!               struct cgraph_edge *edge
! 		= cgraph_edge (id->current_node, old_node);
  
  	      if (edge)
! 	        cgraph_clone_edge (edge, id->node, *tp);
  	    }
  	}
  
        TREE_TYPE (*tp) = remap_type (TREE_TYPE (*tp), id);
  
--- 666,693 ----
  	    }
  	  else
  	    {
!               struct cgraph_edge *edge;
  
+ 	      /* We're cloning or inlining this body; duplicate the
+ 		 associate callgraph nodes.  */
+ 	      edge = cgraph_edge (id->current_node, old_node);
  	      if (edge)
! 		 cgraph_clone_edge (edge, id->node, *tp);
  	    }
  	}
+       else if (TREE_CODE (*tp) == RESX_EXPR)
+ 	{
+ 	  /* If we're inlining (e.g. not saving, not cloning and not
+ 	     versioning, adjust the region number of this resume
+ 	     expression.  */
+ 	  if (inlining_p (id))
+ 	    TREE_OPERAND (*tp, 0) =
+ 	      build_int_cst
+ 		(NULL_TREE,
+ 		 get_eh_last_region_number (DECL_STRUCT_FUNCTION (id->caller))
+ 		 - get_eh_last_region_number (id->callee_cfun)
+ 		 + TREE_INT_CST_LOW (TREE_OPERAND (*tp, 0)));
+ 	}
  
        TREE_TYPE (*tp) = remap_type (TREE_TYPE (*tp), id);
  
*************** copy_body_r (tree *tp, int *walk_subtree
*** 635,648 ****
    return NULL_TREE;
  }
  
  /* Make a copy of the body of FN so that it can be inserted inline in
     another function.  */
  
  static tree
! copy_body (inline_data *id)
  {
    tree body;
!   tree fndecl = VARRAY_TOP_TREE (id->fns);
  
    if (fndecl == current_function_decl
        && cfun->saved_tree)
--- 714,981 ----
    return NULL_TREE;
  }
  
+ /* Copy basic block, scale profile accordingly.  Edges will be taken care of
+    later  */
+ 
+ static basic_block
+ copy_bb (inline_data *id, basic_block bb, int frequency_scale, int count_scale)
+ {
+   block_stmt_iterator bsi, copy_bsi;
+   basic_block copy_basic_block;
+ 
+   /* create_basic_block() will append every new block to
+      basic_block_info automatically.  */
+   copy_basic_block = create_basic_block (NULL, (void *) 0, bb->prev_bb->aux);
+   copy_basic_block->count = bb->count * count_scale / REG_BR_PROB_BASE;
+   copy_basic_block->frequency = (bb->frequency
+ 				     * frequency_scale / REG_BR_PROB_BASE);
+   copy_bsi = bsi_start (copy_basic_block);
+ 
+   for (bsi = bsi_start (bb);
+        !bsi_end_p (bsi); bsi_next (&bsi))
+     {
+       tree stmt = bsi_stmt (bsi);
+       tree orig_stmt = stmt;
+ 
+       walk_tree (&stmt, copy_body_r, id, NULL);
+ 
+       /* RETURN_EXPR might be removed,
+          this is signalled by making stmt pointer NULL.  */
+       if (stmt)
+ 	{
+           bsi_insert_after (&copy_bsi, stmt, BSI_NEW_STMT);
+ 	  /* If you think we can abort here, you are wrong.
+ 	     There is no region 0 in tree land.  */
+ 	  gcc_assert (lookup_stmt_eh_region_fn (id->callee_cfun, orig_stmt)
+ 		      != 0);
+ 
+ 	  if (tree_could_throw_p (stmt))
+ 	    {
+ 	      /* Add an entry for the copied tree in the EH hashtable.
+ 		 When saving or cloning or versioning, use the hashtable in
+ 		 cfun, and just copy the EH number.  When inlining, use the
+ 		 hashtable in the caller, and adjust the region number.  */
+ 	      if (!inlining_p (id))
+ 		duplicate_stmt_eh_region_mapping (
+ 			    id->callee_cfun, cfun,
+ 			    orig_stmt, stmt, 0);
+ 	      else
+ 		duplicate_stmt_eh_region_mapping (
+ 			    id->callee_cfun,
+ 			    DECL_STRUCT_FUNCTION (id->caller),
+ 			    orig_stmt, stmt, 1);
+ 
+ 	      /* If this tree doesn't have a region associated with it,
+ 		 and there is a "current region,"
+ 		 then associate this tree with the current region
+ 		 and add edges associated with this region.  */
+ 	      if ((lookup_stmt_eh_region_fn (id->callee_cfun,
+ 					     orig_stmt) <= 0
+ 		   && id->eh_region > 0)
+ 		  && tree_could_throw_p (stmt))
+ 		add_stmt_to_eh_region (stmt, id->eh_region);
+ 	    }
+ 	}
+     }
+   return copy_basic_block;
+ }
+ 
+ /* Copy edges from BB into it's copy constructed ealier, scale profile
+    accordingly.  Edges will be taken care of
+    later.  Assume aux pointers to point to the copies of each BB  */
+ static void
+ copy_edges_for_bb (basic_block bb, int count_scale)
+ {
+   basic_block new_bb = bb->aux;
+   edge_iterator ei;
+   edge old_edge;
+   block_stmt_iterator bsi;
+   int flags;
+ 
+   /* Use the indices from the original blocks to create edges for the
+      new ones.  */
+   FOR_EACH_EDGE (old_edge, ei, bb->succs)
+     {
+       edge new;
+ 
+       flags = old_edge->flags;
+ 
+       /* Return edges do get a FALLTHU flag when the get inlined.  */
+       if (old_edge->dest->index == EXIT_BLOCK && !old_edge->flags
+ 	  && old_edge->dest->aux != EXIT_BLOCK_PTR)
+ 	flags |= EDGE_FALLTHRU;
+       new = make_edge (new_bb, old_edge->dest->aux, flags);
+       new->count = old_edge->count * count_scale / REG_BR_PROB_BASE;
+       new->probability = old_edge->probability;
+     }
+ 
+   if (bb->index == ENTRY_BLOCK || bb->index == EXIT_BLOCK)
+     return;
+ 
+   tree_purge_dead_eh_edges (new_bb);
+   for (bsi = bsi_start (new_bb); !bsi_end_p (bsi);)
+     {
+       tree copy_stmt;
+ 
+       copy_stmt = bsi_stmt (bsi);
+       update_stmt (copy_stmt);
+       /* Do this before the possible split_block.  */
+       bsi_next (&bsi);
+ 
+       /* If this tree could throw an exception, there are two
+          cases where we need to add abnormal edge(s): the
+          tree wasn't in a region and there is a "current
+          region" in the caller; or the original tree had
+          EH edges.  In both cases split the block after the tree,
+          and add abnormal edge(s) as needed; we need both
+          those from the callee and the caller.
+          We check whether the copy can throw, because the const
+          propagation can change an INDIRECT_REF which throws
+          into a COMPONENT_REF which doesn't.  If the copy
+          can throw, the original could also throw.  */
+ 
+       if (TREE_CODE (copy_stmt) == RESX_EXPR
+ 	  || (tree_could_throw_p (copy_stmt)
+ 	      && lookup_stmt_eh_region (copy_stmt) > 0))
+ 	{
+ 	  if (!bsi_end_p (bsi))
+ 	    /* Note that bb's predecessor edges aren't necessarily
+ 	       right at this point; split_block doesn't care.  */
+ 	    {
+ 	      edge e = split_block (new_bb, copy_stmt);
+ 	      new_bb = e->dest;
+ 	      bsi = bsi_start (new_bb);
+ 	    }
+ 
+            make_eh_edges (copy_stmt);
+ 	}
+     }
+ }
+ 
+ /* Make a copy of the body of FN so that it can be inserted inline in
+    another function.  Walks FN via CFG, returns new fndecl.  */
+ 
+ static tree
+ copy_cfg_body (inline_data * id, gcov_type count, int frequency,
+ 	       basic_block entry_block_map, basic_block exit_block_map)
+ {
+   tree callee_fndecl = id->callee;
+   /* Original cfun for the callee, doesn't change.  */
+   struct function *callee_cfun = DECL_STRUCT_FUNCTION (callee_fndecl);
+   /* Copy, built by this function.  */
+   struct function *new_cfun;
+   /* Place to copy from; when a copy of the function was saved off earlier,
+      use that instead of the main copy.  */
+   struct function *cfun_to_copy =
+     (struct function *) ggc_alloc_cleared (sizeof (struct function));
+   basic_block bb;
+   tree new_fndecl = NULL;
+   bool saving_or_cloning;
+   int count_scale, frequency_scale;
+ 
+   if (ENTRY_BLOCK_PTR_FOR_FUNCTION (callee_cfun)->count)
+     count_scale = (REG_BR_PROB_BASE * count
+ 		   / ENTRY_BLOCK_PTR_FOR_FUNCTION (callee_cfun)->count);
+   else
+     count_scale = 1;
+ 
+   if (ENTRY_BLOCK_PTR_FOR_FUNCTION (callee_cfun)->frequency)
+     frequency_scale = (REG_BR_PROB_BASE * frequency
+ 		       /
+ 		       ENTRY_BLOCK_PTR_FOR_FUNCTION (callee_cfun)->frequency);
+   else
+     frequency_scale = count_scale;
+ 
+   /* Register specific tree functions.  */
+   tree_register_cfg_hooks ();
+ 
+   /* Must have a CFG here at this point.  */
+   gcc_assert (ENTRY_BLOCK_PTR_FOR_FUNCTION
+ 	      (DECL_STRUCT_FUNCTION (callee_fndecl)));
+ 
+   *cfun_to_copy = *DECL_STRUCT_FUNCTION (callee_fndecl);
+ 
+   /* If there is a saved_cfg+saved_tree+saved_args lurking in the
+      struct function, a copy of the callee body was saved there, and
+      the 'struct cgraph edge' nodes have been fudged to point into the
+      saved body.  Accordingly, we want to copy that saved body so the
+      callgraph edges will be recognized and cloned properly.  */
+   if (cfun_to_copy->saved_cfg)
+     {
+       cfun_to_copy->cfg = cfun_to_copy->saved_cfg;
+       cfun_to_copy->eh = cfun_to_copy->saved_eh;
+     }
+   id->callee_cfun = cfun_to_copy;
+ 
+   /* If saving or cloning a function body, create new basic_block_info
+      and label_to_block_maps.  Otherwise, we're duplicaing a function
+      body for inlining; insert our new blocks and labels into the
+      existing varrays.  */
+   saving_or_cloning = (id->saving_p || id->cloning_p);
+   if (saving_or_cloning)
+     {
+       new_cfun =
+ 	(struct function *) ggc_alloc_cleared (sizeof (struct function));
+       *new_cfun = *DECL_STRUCT_FUNCTION (callee_fndecl);
+       new_cfun->cfg = NULL;
+       new_cfun->decl = new_fndecl = copy_node (callee_fndecl);
+       new_cfun->ib_boundaries_block = (varray_type) 0;
+       DECL_STRUCT_FUNCTION (new_fndecl) = new_cfun;
+       push_cfun (new_cfun);
+       init_empty_tree_cfg ();
+ 
+       ENTRY_BLOCK_PTR->count =
+ 	(ENTRY_BLOCK_PTR_FOR_FUNCTION (callee_cfun)->count * count_scale /
+ 	 REG_BR_PROB_BASE);
+       ENTRY_BLOCK_PTR->frequency =
+ 	(ENTRY_BLOCK_PTR_FOR_FUNCTION (callee_cfun)->frequency *
+ 	 frequency_scale / REG_BR_PROB_BASE);
+       EXIT_BLOCK_PTR->count =
+ 	(EXIT_BLOCK_PTR_FOR_FUNCTION (callee_cfun)->count * count_scale /
+ 	 REG_BR_PROB_BASE);
+       EXIT_BLOCK_PTR->frequency =
+ 	(EXIT_BLOCK_PTR_FOR_FUNCTION (callee_cfun)->frequency *
+ 	 frequency_scale / REG_BR_PROB_BASE);
+ 
+       entry_block_map = ENTRY_BLOCK_PTR;
+       exit_block_map = EXIT_BLOCK_PTR;
+     }
+ 
+   ENTRY_BLOCK_PTR_FOR_FUNCTION (cfun_to_copy)->aux = entry_block_map;
+   EXIT_BLOCK_PTR_FOR_FUNCTION (cfun_to_copy)->aux = exit_block_map;
+ 
+ 
+   /* Duplicate any exception-handling regions.  */
+   if (cfun->eh)
+     {
+       if (saving_or_cloning)
+         init_eh_for_function ();
+       duplicate_eh_regions (cfun_to_copy, (duplicate_eh_regions_map)remap_decl,
+ 		      	    id, id->eh_region);
+     }
+   /* Use aux pointers to map the original blocks to copy.  */
+   FOR_EACH_BB_FN (bb, cfun_to_copy)
+     bb->aux = copy_bb (id, bb, frequency_scale, count_scale);
+   /* Now that we've duplicated the blocks, duplicate their edges.  */
+   FOR_ALL_BB_FN (bb, cfun_to_copy)
+     copy_edges_for_bb (bb, count_scale);
+   FOR_ALL_BB_FN (bb, cfun_to_copy)
+     bb->aux = NULL;
+ 
+   if (saving_or_cloning)
+     pop_cfun ();
+ 
+   return new_fndecl;
+ }
+ 
  /* Make a copy of the body of FN so that it can be inserted inline in
     another function.  */
  
  static tree
! copy_generic_body (inline_data *id)
  {
    tree body;
!   tree fndecl = id->callee;
  
    if (fndecl == current_function_decl
        && cfun->saved_tree)
*************** copy_body (inline_data *id)
*** 654,659 ****
--- 987,1006 ----
    return body;
  }
  
+ static tree
+ copy_body (inline_data *id, gcov_type count, int frequency,
+ 	   basic_block entry_block_map, basic_block exit_block_map)
+ {
+   tree fndecl = id->callee;
+   tree body;
+ 
+   /* If this body has a CFG, walk CFG and copy.  */
+   gcc_assert (ENTRY_BLOCK_PTR_FOR_FUNCTION (DECL_STRUCT_FUNCTION (fndecl)));
+   body = copy_cfg_body (id, count, frequency, entry_block_map, exit_block_map);
+ 
+   return body;
+ }
+ 
  /* Return true if VALUE is an ADDR_EXPR of an automatic variable
     defined in function FN, or of a data member thereof.  */
  
*************** self_inlining_addr_expr (tree value, tre
*** 666,694 ****
      return false;
  
    var = get_base_address (TREE_OPERAND (value, 0));
! 	      
    return var && lang_hooks.tree_inlining.auto_var_in_fn_p (var, fn);
  }
  
  static void
  setup_one_parameter (inline_data *id, tree p, tree value, tree fn,
! 		     tree *init_stmts, tree *vars, bool *gimplify_init_stmts_p)
  {
    tree init_stmt;
    tree var;
  
    /* If the parameter is never assigned to, we may not need to
       create a new variable here at all.  Instead, we may be able
       to just use the argument value.  */
    if (TREE_READONLY (p)
        && !TREE_ADDRESSABLE (p)
        && value && !TREE_SIDE_EFFECTS (value))
      {
-       /* We can't risk substituting complex expressions.  They
- 	 might contain variables that will be assigned to later.
- 	 Theoretically, we could check the expression to see if
- 	 all of the variables that determine its value are
- 	 read-only, but we don't bother.  */
        /* We may produce non-gimple trees by adding NOPs or introduce
  	 invalid sharing when operand is not really constant.
  	 It is not big deal to prohibit constant propagation here as
--- 1013,1040 ----
      return false;
  
    var = get_base_address (TREE_OPERAND (value, 0));
! 
    return var && lang_hooks.tree_inlining.auto_var_in_fn_p (var, fn);
  }
  
  static void
  setup_one_parameter (inline_data *id, tree p, tree value, tree fn,
! 		     basic_block bb, tree *vars)
  {
    tree init_stmt;
    tree var;
+   tree var_sub;
  
    /* If the parameter is never assigned to, we may not need to
       create a new variable here at all.  Instead, we may be able
       to just use the argument value.  */
+   /* In theory this should not be necessary for correctness, but
+      in practice there are a lot of dejagnu failures (especially
+      in C++ library) if it is removed...  */
    if (TREE_READONLY (p)
        && !TREE_ADDRESSABLE (p)
        && value && !TREE_SIDE_EFFECTS (value))
      {
        /* We may produce non-gimple trees by adding NOPs or introduce
  	 invalid sharing when operand is not really constant.
  	 It is not big deal to prohibit constant propagation here as
*************** setup_one_parameter (inline_data *id, tr
*** 710,721 ****
    /* Make an equivalent VAR_DECL.  Note that we must NOT remap the type
       here since the type of this decl must be visible to the calling
       function.  */
!   var = copy_decl_for_inlining (p, fn, VARRAY_TREE (id->fns, 0));
  
    /* Register the VAR_DECL as the equivalent for the PARM_DECL;
       that way, when the PARM_DECL is encountered, it will be
       automatically replaced by the VAR_DECL.  */
!   insert_decl_map (id, p, var);
  
    /* Declare this new variable.  */
    TREE_CHAIN (var) = *vars;
--- 1056,1080 ----
    /* Make an equivalent VAR_DECL.  Note that we must NOT remap the type
       here since the type of this decl must be visible to the calling
       function.  */
!   var = copy_decl_for_inlining (p, fn, id->caller);
! 
!   /* See if the frontend wants to pass this by invisible reference.  If
!      so, our new VAR_DECL will have REFERENCE_TYPE, and we need to
!      replace uses of the PARM_DECL with dereferences.  */
!   if (TREE_TYPE (var) != TREE_TYPE (p)
!       && POINTER_TYPE_P (TREE_TYPE (var))
!       && TREE_TYPE (TREE_TYPE (var)) == TREE_TYPE (p))
!     {
!       insert_decl_map (id, var, var);
!       var_sub = build1 (INDIRECT_REF, TREE_TYPE (p), var);
!     }
!   else
!     var_sub = var;
  
    /* Register the VAR_DECL as the equivalent for the PARM_DECL;
       that way, when the PARM_DECL is encountered, it will be
       automatically replaced by the VAR_DECL.  */
!   insert_decl_map (id, p, var_sub);
  
    /* Declare this new variable.  */
    TREE_CHAIN (var) = *vars;
*************** setup_one_parameter (inline_data *id, tr
*** 741,746 ****
--- 1100,1106 ----
    if (value)
      {
        tree rhs = fold_convert (TREE_TYPE (var), value);
+       block_stmt_iterator bsi = bsi_last (bb);
  
        if (rhs == error_mark_node)
  	return;
*************** setup_one_parameter (inline_data *id, tr
*** 748,754 ****
        /* We want to use MODIFY_EXPR, not INIT_EXPR here so that we
  	 keep our trees in gimple form.  */
        init_stmt = build (MODIFY_EXPR, TREE_TYPE (var), var, rhs);
-       append_to_statement_list (init_stmt, init_stmts);
  
        /* If we did not create a gimple value and we did not create a gimple
  	 cast of a gimple value, then we will need to gimplify INIT_STMTS
--- 1108,1113 ----
*************** setup_one_parameter (inline_data *id, tr
*** 758,780 ****
        if (!is_gimple_val (rhs)
  	  && (!is_gimple_cast (rhs)
  	      || !is_gimple_val (TREE_OPERAND (rhs, 0))))
! 	*gimplify_init_stmts_p = true;
      }
  }
  
  /* Generate code to initialize the parameters of the function at the
     top of the stack in ID from the ARGS (presented as a TREE_LIST).  */
  
! static tree
  initialize_inlined_parameters (inline_data *id, tree args, tree static_chain,
! 			       tree fn, tree bind_expr)
  {
-   tree init_stmts = NULL_TREE;
    tree parms;
    tree a;
    tree p;
    tree vars = NULL_TREE;
-   bool gimplify_init_stmts_p = false;
    int argnum = 0;
  
    /* Figure out what the parameters are.  */
--- 1117,1138 ----
        if (!is_gimple_val (rhs)
  	  && (!is_gimple_cast (rhs)
  	      || !is_gimple_val (TREE_OPERAND (rhs, 0))))
! 	gimplify_stmt (&init_stmt);
!       bsi_insert_after (&bsi, init_stmt, BSI_NEW_STMT);
      }
  }
  
  /* Generate code to initialize the parameters of the function at the
     top of the stack in ID from the ARGS (presented as a TREE_LIST).  */
  
! static void
  initialize_inlined_parameters (inline_data *id, tree args, tree static_chain,
! 			       tree fn, basic_block bb)
  {
    tree parms;
    tree a;
    tree p;
    tree vars = NULL_TREE;
    int argnum = 0;
  
    /* Figure out what the parameters are.  */
*************** initialize_inlined_parameters (inline_da
*** 795,809 ****
        value = lang_hooks.tree_inlining.convert_parm_for_inlining
  	      (p, a ? TREE_VALUE (a) : NULL_TREE, fn, argnum);
  
!       setup_one_parameter (id, p, value, fn, &init_stmts, &vars,
! 			   &gimplify_init_stmts_p);
!     }
! 
!   /* Evaluate trailing arguments.  */
!   for (; a; a = TREE_CHAIN (a))
!     {
!       tree value = TREE_VALUE (a);
!       append_to_statement_list (value, &init_stmts);
      }
  
    /* Initialize the static chain.  */
--- 1153,1159 ----
        value = lang_hooks.tree_inlining.convert_parm_for_inlining
  	      (p, a ? TREE_VALUE (a) : NULL_TREE, fn, argnum);
  
!       setup_one_parameter (id, p, value, fn, bb, &vars);
      }
  
    /* Initialize the static chain.  */
*************** initialize_inlined_parameters (inline_da
*** 815,833 ****
        /* No static chain?  Seems like a bug in tree-nested.c.  */
        gcc_assert (static_chain);
  
!       setup_one_parameter (id, p, static_chain, fn, &init_stmts, &vars,
! 			   &gimplify_init_stmts_p);
      }
  
!   if (gimplify_init_stmts_p)
!     gimplify_body (&init_stmts, current_function_decl, false);
  
!   declare_inline_vars (bind_expr, vars);
!   return init_stmts;
  }
  
! /* Declare a return variable to replace the RESULT_DECL for the function we
!    are calling.  RETURN_SLOT_ADDR, if non-null, was a fake parameter that
     took the address of the result.  MODIFY_DEST, if non-null, was the LHS of
     the MODIFY_EXPR to which this call is the RHS.
  
--- 1165,1204 ----
        /* No static chain?  Seems like a bug in tree-nested.c.  */
        gcc_assert (static_chain);
  
!       setup_one_parameter (id, p, static_chain, fn, bb, &vars);
      }
  
!   declare_inline_vars (id->block, vars);
! }
! 
! /* should return a
!    declaration for the result RES of function FN to be inlined into
!    CALLER.  NDP points to an integer that should be set in case a new
!    declaration wasn't created (presumably because RES was of aggregate
!    type, such that a TARGET_EXPR is used for the result).  TEXPS is a
!    pointer to a varray with the stack of TARGET_EXPRs seen while
!    inlining functions into caller; the top of TEXPS is supposed to
!    match RES.  */
  
! static tree
! copy_res_decl_for_inlining (tree res, tree fn, tree caller,
!                             void *dm ATTRIBUTE_UNUSED,
!                             int *ndp ATTRIBUTE_UNUSED,
!                             tree return_slot_addr ATTRIBUTE_UNUSED)
! {
!   if (return_slot_addr)
!     return build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (return_slot_addr)),
!                    return_slot_addr);
!   else
!     return copy_decl_for_inlining (res, fn, caller);
  }
  
! /* Declare a return variable to replace the RESULT_DECL for the
!    function we are calling.  An appropriate DECL_STMT is returned.
!    The USE_STMT is filled to contain a use of the declaration to
!    indicate the return value of the function.
! 
!    RETURN_SLOT_ADDR, if non-null, was a fake parameter that
     took the address of the result.  MODIFY_DEST, if non-null, was the LHS of
     the MODIFY_EXPR to which this call is the RHS.
  
*************** static tree
*** 839,850 ****
  declare_return_variable (inline_data *id, tree return_slot_addr,
  			 tree modify_dest, tree *use_p)
  {
!   tree callee = VARRAY_TOP_TREE (id->fns);
!   tree caller = VARRAY_TREE (id->fns, 0);
    tree result = DECL_RESULT (callee);
    tree callee_type = TREE_TYPE (result);
    tree caller_type = TREE_TYPE (TREE_TYPE (callee));
    tree var, use;
  
    /* We don't need to do anything for functions that don't return
       anything.  */
--- 1210,1222 ----
  declare_return_variable (inline_data *id, tree return_slot_addr,
  			 tree modify_dest, tree *use_p)
  {
!   tree callee = id->callee;
!   tree caller = id->caller;
    tree result = DECL_RESULT (callee);
    tree callee_type = TREE_TYPE (result);
    tree caller_type = TREE_TYPE (TREE_TYPE (callee));
    tree var, use;
+   int need_return_decl = 1;
  
    /* We don't need to do anything for functions that don't return
       anything.  */
*************** declare_return_variable (inline_data *id
*** 905,911 ****
  
    gcc_assert (TREE_CODE (TYPE_SIZE_UNIT (callee_type)) == INTEGER_CST);
  
!   var = copy_decl_for_inlining (result, callee, caller);
    DECL_SEEN_IN_BIND_EXPR_P (var) = 1;
    DECL_STRUCT_FUNCTION (caller)->unexpanded_var_list
      = tree_cons (NULL_TREE, var,
--- 1277,1284 ----
  
    gcc_assert (TREE_CODE (TYPE_SIZE_UNIT (callee_type)) == INTEGER_CST);
  
!   var = copy_res_decl_for_inlining (result, callee, id->caller, id->decl_map,
! 				    &need_return_decl, return_slot_addr);
    DECL_SEEN_IN_BIND_EXPR_P (var) = 1;
    DECL_STRUCT_FUNCTION (caller)->unexpanded_var_list
      = tree_cons (NULL_TREE, var,
*************** static tree
*** 1094,1102 ****
  inline_forbidden_p (tree fndecl)
  {
    location_t saved_loc = input_location;
!   tree ret = walk_tree_without_duplicates (&DECL_SAVED_TREE (fndecl),
! 					   inline_forbidden_p_1, fndecl);
  
    input_location = saved_loc;
    return ret;
  }
--- 1467,1486 ----
  inline_forbidden_p (tree fndecl)
  {
    location_t saved_loc = input_location;
!   block_stmt_iterator bsi;
!   basic_block bb;
!   tree ret = NULL_TREE;
  
+   FOR_EACH_BB_FN (bb, DECL_STRUCT_FUNCTION (fndecl))
+     for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
+       {
+ 	ret = walk_tree_without_duplicates (bsi_stmt_ptr (bsi),
+ 				    inline_forbidden_p_1, fndecl);
+ 	if (ret)
+ 	  goto egress;
+       }
+ 
+ egress:
    input_location = saved_loc;
    return ret;
  }
*************** estimate_num_insns_1 (tree *tp, int *wal
*** 1306,1312 ****
        if (is_gimple_reg (x))
  	break;
        /* Otherwise it's a store, so fall through to compute the move cost.  */
!       
      case CONSTRUCTOR:
        *count += estimate_move_cost (TREE_TYPE (x));
        break;
--- 1696,1702 ----
        if (is_gimple_reg (x))
  	break;
        /* Otherwise it's a store, so fall through to compute the move cost.  */
! 
      case CONSTRUCTOR:
        *count += estimate_move_cost (TREE_TYPE (x));
        break;
*************** int
*** 1441,1470 ****
  estimate_num_insns (tree expr)
  {
    int num = 0;
!   walk_tree_without_duplicates (&expr, estimate_num_insns_1, &num);
    return num;
  }
  
  /* If *TP is a CALL_EXPR, replace it with its inline expansion.  */
  
! static tree
! expand_call_inline (tree *tp, int *walk_subtrees, void *data)
  {
    inline_data *id;
    tree t;
-   tree expr;
-   tree stmt;
    tree use_retvar;
    tree fn;
-   tree arg_inits;
-   tree *inlined_body;
    splay_tree st;
    tree args;
    tree return_slot_addr;
    tree modify_dest;
    location_t saved_location;
!   struct cgraph_edge *edge;
    const char *reason;
  
    /* See what we've got.  */
    id = (inline_data *) data;
--- 1831,1929 ----
  estimate_num_insns (tree expr)
  {
    int num = 0;
!   struct pointer_set_t *visited_nodes;
!   basic_block bb;
!   block_stmt_iterator bsi;
!   struct function *my_function;
! 
!   /* If we're given an entire function, walk the CFG.  */
!   if (TREE_CODE (expr) == FUNCTION_DECL)
!     {
!       my_function = DECL_STRUCT_FUNCTION (expr);
!       gcc_assert (my_function && my_function->cfg);
!       visited_nodes = pointer_set_create ();
!       FOR_EACH_BB_FN (bb, my_function)
! 	{
! 	  for (bsi = bsi_start (bb);
! 	       !bsi_end_p (bsi);
! 	       bsi_next (&bsi))
! 	    {
! 	      walk_tree (bsi_stmt_ptr (bsi), estimate_num_insns_1,
! 			 &num, visited_nodes);
! 	    }
! 	}
!       pointer_set_destroy (visited_nodes);
!     }
!   else
!     walk_tree_without_duplicates (&expr, estimate_num_insns_1, &num);
! 
    return num;
  }
  
+ /* Initialized with NOGC, making this poisonous to the garbage collector.  */
+ static varray_type cfun_stack;
+ 
+ void
+ push_cfun (struct function *new_cfun)
+ {
+   static bool initialized = false;
+ 
+   if (!initialized)
+     {
+       VARRAY_GENERIC_PTR_NOGC_INIT (cfun_stack, 20, "cfun_stack");
+       initialized = true;
+     }
+   VARRAY_PUSH_GENERIC_PTR (cfun_stack, cfun);
+   cfun = new_cfun;
+ }
+ 
+ void
+ pop_cfun (void)
+ {
+   cfun = (struct function *)VARRAY_TOP_GENERIC_PTR (cfun_stack);
+   VARRAY_POP (cfun_stack);
+ }
+ 
+ /* Install new lexical TREE_BLOCK underneath 'current_block'.  */
+ static void
+ add_lexical_block (tree current_block, tree new_block)
+ {
+   tree *blk_p;
+ 
+   /* Walk to the last sub-block.  */
+   for (blk_p = &BLOCK_SUBBLOCKS (current_block);
+        *blk_p;
+        blk_p = &TREE_CHAIN (*blk_p))
+     ;
+   *blk_p = new_block;
+   BLOCK_SUPERCONTEXT (new_block) = current_block;
+   BLOCK_SUBBLOCKS (new_block) = NULL_TREE;
+ }
+ 
  /* If *TP is a CALL_EXPR, replace it with its inline expansion.  */
  
! static bool
! expand_call_inline (basic_block bb, tree stmt, tree *tp, void *data)
  {
    inline_data *id;
    tree t;
    tree use_retvar;
    tree fn;
    splay_tree st;
    tree args;
    tree return_slot_addr;
    tree modify_dest;
    location_t saved_location;
!   struct cgraph_edge *cg_edge;
    const char *reason;
+   basic_block return_block;
+   edge e;
+   block_stmt_iterator bsi, stmt_bsi;
+   bool successfully_inlined = FALSE;
+   tree t_step;
+   tree var;
+   struct cgraph_node *old_node;
+   tree decl;
  
    /* See what we've got.  */
    id = (inline_data *) data;
*************** expand_call_inline (tree *tp, int *walk_
*** 1476,1514 ****
    if (EXPR_HAS_LOCATION (t))
      input_location = EXPR_LOCATION (t);
  
-   /* Recurse, but letting recursive invocations know that we are
-      inside the body of a TARGET_EXPR.  */
-   if (TREE_CODE (*tp) == TARGET_EXPR)
-     {
- #if 0
-       int i, len = TREE_CODE_LENGTH (TARGET_EXPR);
- 
-       /* We're walking our own subtrees.  */
-       *walk_subtrees = 0;
- 
-       /* Actually walk over them.  This loop is the body of
- 	 walk_trees, omitting the case where the TARGET_EXPR
- 	 itself is handled.  */
-       for (i = 0; i < len; ++i)
- 	{
- 	  if (i == 2)
- 	    ++id->in_target_cleanup_p;
- 	  walk_tree (&TREE_OPERAND (*tp, i), expand_call_inline, data,
- 		     id->tree_pruner);
- 	  if (i == 2)
- 	    --id->in_target_cleanup_p;
- 	}
- 
-       goto egress;
- #endif
-     }
- 
-   if (TYPE_P (t))
-     /* Because types were not copied in copy_body, CALL_EXPRs beneath
-        them should not be expanded.  This can happen if the type is a
-        dynamic array type, for example.  */
-     *walk_subtrees = 0;
- 
    /* From here on, we're only interested in CALL_EXPRs.  */
    if (TREE_CODE (t) != CALL_EXPR)
      goto egress;
--- 1935,1940 ----
*************** expand_call_inline (tree *tp, int *walk_
*** 1539,1549 ****
    if (!id->current_node->analyzed)
      goto egress;
  
!   edge = cgraph_edge (id->current_node, t);
  
    /* Constant propagation on argument done during previous inlining
       may create new direct call.  Produce an edge for it.  */
!   if (!edge)
      {
        struct cgraph_node *dest = cgraph_node (fn);
  
--- 1965,1975 ----
    if (!id->current_node->analyzed)
      goto egress;
  
!   cg_edge = cgraph_edge (id->current_node, t);
  
    /* Constant propagation on argument done during previous inlining
       may create new direct call.  Produce an edge for it.  */
!   if (!cg_edge)
      {
        struct cgraph_node *dest = cgraph_node (fn);
  
*************** expand_call_inline (tree *tp, int *walk_
*** 1559,1565 ****
  
    /* Don't try to inline functions that are not well-suited to
       inlining.  */
!   if (!cgraph_inline_p (edge, &reason))
      {
        if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)))
  	{
--- 1985,1991 ----
  
    /* Don't try to inline functions that are not well-suited to
       inlining.  */
!   if (!cgraph_inline_p (cg_edge, &reason))
      {
        if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)))
  	{
*************** expand_call_inline (tree *tp, int *walk_
*** 1578,1598 ****
      }
  
  #ifdef ENABLE_CHECKING
!   if (edge->callee->decl != id->node->decl)
!     verify_cgraph_node (edge->callee);
  #endif
  
!   if (! lang_hooks.tree_inlining.start_inlining (fn))
!     goto egress;
  
    /* Build a block containing code to initialize the arguments, the
       actual inline expansion of the body, and a label for the return
       statements within the function to jump to.  The type of the
       statement expression is the return type of the function call.  */
!   stmt = NULL;
!   expr = build (BIND_EXPR, void_type_node, NULL_TREE,
! 		stmt, make_node (BLOCK));
!   BLOCK_ABSTRACT_ORIGIN (BIND_EXPR_BLOCK (expr)) = fn;
  
    /* Local declarations will be replaced by their equivalents in this
       map.  */
--- 2004,2048 ----
      }
  
  #ifdef ENABLE_CHECKING
!   if (cg_edge->callee->decl != id->node->decl)
!     verify_cgraph_node (cg_edge->callee);
  #endif
  
!   /* We will be inlining this callee.  */
! 
!   id->eh_region = lookup_stmt_eh_region (stmt);
! 
!   /* Split the block holding the CALL_EXPR.  */
! 
!   e = split_block (bb, stmt);
!   bb = e->src;
!   return_block = e->dest;
!   remove_edge (e);
! 
!   /* split_block splits before the statement, work around this by moving
!      the call into the first half_bb.  Not pretty, but seems easier than
!      doing the CFG manipulation by hand when the CALL_EXPR is in the last
!      statement in BB.  */
!   stmt_bsi = bsi_last (bb);
!   bsi = bsi_start (return_block);
!   if (!bsi_end_p (bsi))
!     bsi_move_before (&stmt_bsi, &bsi);
!   else
!     {
!       tree stmt = bsi_stmt (stmt_bsi);
!       bsi_remove (&stmt_bsi);
!       bsi_insert_after (&bsi, stmt, BSI_NEW_STMT);
!     }
!   stmt_bsi = bsi_start (return_block);
  
    /* Build a block containing code to initialize the arguments, the
       actual inline expansion of the body, and a label for the return
       statements within the function to jump to.  The type of the
       statement expression is the return type of the function call.  */
!   id->block = make_node (BLOCK);
!   BLOCK_ABSTRACT_ORIGIN (id->block) = fn;
!   add_lexical_block (TREE_BLOCK (stmt), id->block);
! 
  
    /* Local declarations will be replaced by their equivalents in this
       map.  */
*************** expand_call_inline (tree *tp, int *walk_
*** 1602,1653 ****
  
    /* Initialize the parameters.  */
    args = TREE_OPERAND (t, 1);
-   return_slot_addr = NULL_TREE;
    if (CALL_EXPR_HAS_RETURN_SLOT_ADDR (t))
      {
        return_slot_addr = TREE_VALUE (args);
        args = TREE_CHAIN (args);
-       TREE_TYPE (expr) = void_type_node;
      }
  
!   arg_inits = initialize_inlined_parameters (id, args, TREE_OPERAND (t, 2),
! 					     fn, expr);
!   if (arg_inits)
!     {
!       /* Expand any inlined calls in the initializers.  Do this before we
! 	 push FN on the stack of functions we are inlining; we want to
! 	 inline calls to FN that appear in the initializers for the
! 	 parameters.
! 
! 	 Note we need to save and restore the saved tree statement iterator
! 	 to avoid having it clobbered by expand_calls_inline.  */
!       tree_stmt_iterator save_tsi;
! 
!       save_tsi = id->tsi;
!       expand_calls_inline (&arg_inits, id);
!       id->tsi = save_tsi;
! 
!       /* And add them to the tree.  */
!       append_to_statement_list (arg_inits, &BIND_EXPR_BODY (expr));
!     }
  
!   /* Record the function we are about to inline so that we can avoid
!      recursing into it.  */
!   VARRAY_PUSH_TREE (id->fns, fn);
  
    /* Return statements in the function body will be replaced by jumps
       to the RET_LABEL.  */
-   id->ret_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
-   DECL_ARTIFICIAL (id->ret_label) = 1;
-   DECL_IGNORED_P (id->ret_label) = 1;
-   DECL_CONTEXT (id->ret_label) = VARRAY_TREE (id->fns, 0);
-   insert_decl_map (id, id->ret_label, id->ret_label);
  
    gcc_assert (DECL_INITIAL (fn));
    gcc_assert (TREE_CODE (DECL_INITIAL (fn)) == BLOCK);
  
    /* Find the lhs to which the result of this call is assigned.  */
!   modify_dest = tsi_stmt (id->tsi);
    if (TREE_CODE (modify_dest) == MODIFY_EXPR)
      {
        modify_dest = TREE_OPERAND (modify_dest, 0);
--- 2052,2078 ----
  
    /* Initialize the parameters.  */
    args = TREE_OPERAND (t, 1);
    if (CALL_EXPR_HAS_RETURN_SLOT_ADDR (t))
      {
        return_slot_addr = TREE_VALUE (args);
        args = TREE_CHAIN (args);
      }
+   else
+     return_slot_addr = NULL_TREE;
  
!   initialize_inlined_parameters (id, args, TREE_OPERAND (t, 2), fn, bb);
  
!   /* Record the function we are about to inline.  */
!   id->callee = fn;
  
    /* Return statements in the function body will be replaced by jumps
       to the RET_LABEL.  */
  
    gcc_assert (DECL_INITIAL (fn));
    gcc_assert (TREE_CODE (DECL_INITIAL (fn)) == BLOCK);
  
    /* Find the lhs to which the result of this call is assigned.  */
!   modify_dest = stmt;
    if (TREE_CODE (modify_dest) == MODIFY_EXPR)
      {
        modify_dest = TREE_OPERAND (modify_dest, 0);
*************** expand_call_inline (tree *tp, int *walk_
*** 1665,1854 ****
      modify_dest = NULL;
  
    /* Declare the return variable for the function.  */
!   declare_return_variable (id, return_slot_addr,
! 			   modify_dest, &use_retvar);
  
    /* After we've initialized the parameters, we insert the body of the
       function itself.  */
!   {
!     struct cgraph_node *old_node = id->current_node;
!     tree copy;
! 
!     id->current_node = edge->callee;
!     copy = copy_body (id);
! 
!     /* If the function uses a return slot, then it may legitimately
!        fall through while still returning a value, so we have to skip
!        the warning here.  */
!     if (warn_return_type
! 	&& !TREE_NO_WARNING (fn)
! 	&& !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (fn)))
! 	&& return_slot_addr == NULL_TREE
! 	&& block_may_fallthru (copy))
!       {
! 	warning (0, "control may reach end of non-void function %qD being inlined",
! 		 fn);
! 	TREE_NO_WARNING (fn) = 1;
!       }
  
!     append_to_statement_list (copy, &BIND_EXPR_BODY (expr));
!     id->current_node = old_node;
!   }
!   inlined_body = &BIND_EXPR_BODY (expr);
! 
!   /* After the body of the function comes the RET_LABEL.  This must come
!      before we evaluate the returned value below, because that evaluation
!      may cause RTL to be generated.  */
!   if (TREE_USED (id->ret_label))
!     {
!       tree label = build1 (LABEL_EXPR, void_type_node, id->ret_label);
!       append_to_statement_list (label, &BIND_EXPR_BODY (expr));
!     }
  
    /* Clean up.  */
    splay_tree_delete (id->decl_map);
    id->decl_map = st;
  
-   /* Although, from the semantic viewpoint, the new expression has
-      side-effects only if the old one did, it is not possible, from
-      the technical viewpoint, to evaluate the body of a function
-      multiple times without serious havoc.  */
-   TREE_SIDE_EFFECTS (expr) = 1;
- 
-   tsi_link_before (&id->tsi, expr, TSI_SAME_STMT);
- 
    /* If the inlined function returns a result that we care about,
!      then we're going to need to splice in a MODIFY_EXPR.  Otherwise
!      the call was a standalone statement and we can just replace it
!      with the BIND_EXPR inline representation of the called function.  */
!   if (!use_retvar || !modify_dest)
!     *tsi_stmt_ptr (id->tsi) = build_empty_stmt ();
    else
!     *tp = use_retvar;
  
-   /* When we gimplify a function call, we may clear TREE_SIDE_EFFECTS on
-      the call if it is to a "const" function.  Thus the copy of
-      TREE_SIDE_EFFECTS from the CALL_EXPR to the BIND_EXPR above with
-      result in TREE_SIDE_EFFECTS not being set for the inlined copy of a
-      "const" function.
- 
-      Unfortunately, that is wrong as inlining the function can create/expose
-      interesting side effects (such as setting of a return value).
- 
-      The easiest solution is to simply recalculate TREE_SIDE_EFFECTS for
-      the toplevel expression.  */
-   recalculate_side_effects (expr);
-   
    /* Output the inlining info for this abstract function, since it has been
       inlined.  If we don't do this now, we can lose the information about the
       variables in the function when the blocks get blown away as soon as we
       remove the cgraph node.  */
!   (*debug_hooks->outlining_inline_function) (edge->callee->decl);
  
    /* Update callgraph if needed.  */
!   cgraph_remove_node (edge->callee);
! 
!   /* Recurse into the body of the just inlined function.  */
!   expand_calls_inline (inlined_body, id);
!   VARRAY_POP (id->fns);
  
!   /* Don't walk into subtrees.  We've already handled them above.  */
!   *walk_subtrees = 0;
! 
!   lang_hooks.tree_inlining.end_inlining (fn);
  
-   /* Keep iterating.  */
   egress:
    input_location = saved_location;
!   return NULL_TREE;
  }
  
! static void
! expand_calls_inline (tree *stmt_p, inline_data *id)
! {
!   tree stmt = *stmt_p;
!   enum tree_code code = TREE_CODE (stmt);
!   int dummy;
! 
!   switch (code)
!     {
!     case STATEMENT_LIST:
!       {
! 	tree_stmt_iterator i;
! 	tree new;
! 
! 	for (i = tsi_start (stmt); !tsi_end_p (i); )
! 	  {
! 	    id->tsi = i;
! 	    expand_calls_inline (tsi_stmt_ptr (i), id);
! 
! 	    new = tsi_stmt (i);
! 	    if (TREE_CODE (new) == STATEMENT_LIST)
! 	      {
! 		tsi_link_before (&i, new, TSI_SAME_STMT);
! 		tsi_delink (&i);
! 	      }
! 	    else
! 	      tsi_next (&i);
! 	  }
!       }
!       break;
! 
!     case COND_EXPR:
!       expand_calls_inline (&COND_EXPR_THEN (stmt), id);
!       expand_calls_inline (&COND_EXPR_ELSE (stmt), id);
!       break;
! 
!     case CATCH_EXPR:
!       expand_calls_inline (&CATCH_BODY (stmt), id);
!       break;
! 
!     case EH_FILTER_EXPR:
!       expand_calls_inline (&EH_FILTER_FAILURE (stmt), id);
!       break;
! 
!     case TRY_CATCH_EXPR:
!     case TRY_FINALLY_EXPR:
!       expand_calls_inline (&TREE_OPERAND (stmt, 0), id);
!       expand_calls_inline (&TREE_OPERAND (stmt, 1), id);
!       break;
! 
!     case BIND_EXPR:
!       expand_calls_inline (&BIND_EXPR_BODY (stmt), id);
!       break;
! 
!     case COMPOUND_EXPR:
!       /* We're gimple.  We should have gotten rid of all these.  */
!       gcc_unreachable ();
! 
!     case RETURN_EXPR:
!       stmt_p = &TREE_OPERAND (stmt, 0);
!       stmt = *stmt_p;
!       if (!stmt || TREE_CODE (stmt) != MODIFY_EXPR)
! 	break;
! 
!       /* FALLTHRU */
! 
!     case MODIFY_EXPR:
!       stmt_p = &TREE_OPERAND (stmt, 1);
!       stmt = *stmt_p;
!       if (TREE_CODE (stmt) == WITH_SIZE_EXPR)
! 	{
! 	  stmt_p = &TREE_OPERAND (stmt, 0);
! 	  stmt = *stmt_p;
! 	}
!       if (TREE_CODE (stmt) != CALL_EXPR)
! 	break;
! 
!       /* FALLTHRU */
  
!     case CALL_EXPR:
!       expand_call_inline (stmt_p, &dummy, id);
!       break;
  
!     default:
!       break;
      }
  }
  
  /* Expand calls to inline functions in the body of FN.  */
--- 2090,2199 ----
      modify_dest = NULL;
  
    /* Declare the return variable for the function.  */
!   decl = declare_return_variable (id, return_slot_addr,
! 			          modify_dest, &use_retvar);
!   /* Do this only if declare_return_variable created a new one.  */
!   if (decl && !return_slot_addr && decl != modify_dest)
!     declare_inline_vars (id->block, decl);
  
    /* After we've initialized the parameters, we insert the body of the
       function itself.  */
!   old_node = id->current_node;
  
!   /* Anoint the callee-to-be-duplicated as the "current_node."  When
!      CALL_EXPRs within callee are duplicated, the edges from callee to
!      callee's callees (caller's grandchildren) will be cloned.  */
!   id->current_node = cg_edge->callee;
! 
!   /* This is it.  Duplicate the callee body.  Assume callee is
!      pre-gimplified.  Note that we must not alter the caller
!      function in any way before this point, as this CALL_EXPR may be
!      a self-referential call; if we're calling ourselves, we need to
!      duplicate our body before altering anything.  */
!   copy_body (id, bb->count, bb->frequency, bb, return_block);
!   id->current_node = old_node;
  
    /* Clean up.  */
    splay_tree_delete (id->decl_map);
    id->decl_map = st;
  
    /* If the inlined function returns a result that we care about,
!      clobber the CALL_EXPR with a reference to the return variable.  */
!   if (use_retvar && (TREE_CODE (bsi_stmt (stmt_bsi)) != CALL_EXPR))
!     {
!       *tp = use_retvar;
!       maybe_clean_eh_stmt (stmt);
!     }
    else
!     /* We're modifying a TSI owned by gimple_expand_calls_inline();
!        tsi_delink() will leave the iterator in a sane state.  */
!     bsi_remove (&stmt_bsi);
! 
!   bsi_next (&bsi);
!   if (bsi_end_p (bsi))
!     tree_purge_dead_eh_edges (return_block);
! 
!   /* If the value of the new expression is ignored, that's OK.  We
!      don't warn about this for CALL_EXPRs, so we shouldn't warn about
!      the equivalent inlined version either.  */
!   TREE_USED (*tp) = 1;
  
    /* Output the inlining info for this abstract function, since it has been
       inlined.  If we don't do this now, we can lose the information about the
       variables in the function when the blocks get blown away as soon as we
       remove the cgraph node.  */
!   (*debug_hooks->outlining_inline_function) (cg_edge->callee->decl);
  
    /* Update callgraph if needed.  */
!   cgraph_remove_node (cg_edge->callee);
  
!   /* Declare the 'auto' variables added with this inlined body.  */
!   record_vars (BLOCK_VARS (id->block));
!   id->block = NULL_TREE;
! 
!   /* Add local static vars in this inlined callee to caller.  */
!   for (t_step = id->callee_cfun->unexpanded_var_list;
!        t_step;
!        t_step = TREE_CHAIN (t_step))
!     {
!       var = TREE_VALUE (t_step);
!       if (TREE_STATIC (var) && !TREE_ASM_WRITTEN (var))
! 	record_vars (var);
!     }
!   successfully_inlined = TRUE;
  
   egress:
    input_location = saved_location;
!   return successfully_inlined;
  }
  
! /* Expand call statements reachable from STMT_P.
!    We can only have CALL_EXPRs as the "toplevel" tree code or nested
!    in a MODIFY_EXPR.  See tree-gimple.c:get_call_expr_in().  We can
!    unfortunately not use that function here because we need a pointer
!    to the CALL_EXPR, not the tree itself.  */
  
! static bool
! gimple_expand_calls_inline (basic_block bb, inline_data *id)
! {
!   block_stmt_iterator bsi;
  
!   /* Register specific tree functions.  */
!   tree_register_cfg_hooks ();
!   for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
!     {
!       tree *expr_p = bsi_stmt_ptr (bsi);
!       tree stmt = *expr_p;
! 
!       if (TREE_CODE (*expr_p) == MODIFY_EXPR)
! 	expr_p = &TREE_OPERAND (*expr_p, 1);
!       if (TREE_CODE (*expr_p) == WITH_SIZE_EXPR)
! 	expr_p = &TREE_OPERAND (*expr_p, 0);
!       if (TREE_CODE (*expr_p) == CALL_EXPR)
! 	if (expand_call_inline (bb, stmt, expr_p, id))
! 	  return true;
      }
+   return false;
  }
  
  /* Expand calls to inline functions in the body of FN.  */
*************** optimize_inline_calls (tree fn)
*** 1858,1864 ****
  {
    inline_data id;
    tree prev_fn;
! 
    /* There is no point in performing inlining if errors have already
       occurred -- and we might crash if we try to inline invalid
       code.  */
--- 2203,2209 ----
  {
    inline_data id;
    tree prev_fn;
!   basic_block bb;
    /* There is no point in performing inlining if errors have already
       occurred -- and we might crash if we try to inline invalid
       code.  */
*************** optimize_inline_calls (tree fn)
*** 1869,1898 ****
    memset (&id, 0, sizeof (id));
  
    id.current_node = id.node = cgraph_node (fn);
!   /* Don't allow recursion into FN.  */
!   VARRAY_TREE_INIT (id.fns, 32, "fns");
!   VARRAY_PUSH_TREE (id.fns, fn);
    /* Or any functions that aren't finished yet.  */
    prev_fn = NULL_TREE;
    if (current_function_decl)
      {
!       VARRAY_PUSH_TREE (id.fns, current_function_decl);
        prev_fn = current_function_decl;
      }
  
!   prev_fn = lang_hooks.tree_inlining.add_pending_fn_decls (&id.fns, prev_fn);
! 
!   /* Keep track of the low-water mark, i.e., the point where the first
!      real inlining is represented in ID.FNS.  */
!   id.first_inlined_fn = VARRAY_ACTIVE_SIZE (id.fns);
! 
!   /* Replace all calls to inline functions with the bodies of those
!      functions.  */
!   id.tree_pruner = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
!   expand_calls_inline (&DECL_SAVED_TREE (fn), &id);
! 
!   /* Clean up.  */
!   htab_delete (id.tree_pruner);
  
  #ifdef ENABLE_CHECKING
      {
--- 2214,2244 ----
    memset (&id, 0, sizeof (id));
  
    id.current_node = id.node = cgraph_node (fn);
!   id.caller = fn;
    /* Or any functions that aren't finished yet.  */
    prev_fn = NULL_TREE;
    if (current_function_decl)
      {
!       id.caller = current_function_decl;
        prev_fn = current_function_decl;
      }
+   push_gimplify_context ();
  
!   /* Reach the trees by walking over the CFG, and note the
!      enclosing basic-blocks in the call edges.  */
!   /* We walk the blocks going forward, because inlined function bodies
!      will split id->current_basic_block, and the new blocks will
!      follow it; we'll trudge through them, processing their CALL_EXPRs
!      along the way.  */
!   FOR_EACH_BB (bb)
!     gimple_expand_calls_inline (bb, &id);
! 
! 
!   pop_gimplify_context (NULL);
!   /* Renumber the (code) basic_blocks consecutively.  */
!   compact_blocks ();
!   /* Renumber the lexical scoping (non-code) blocks consecutively.  */
!   number_blocks (fn);
  
  #ifdef ENABLE_CHECKING
      {
*************** optimize_inline_calls (tree fn)
*** 1905,1910 ****
--- 2251,2261 ----
  	gcc_assert (e->inline_failed);
      }
  #endif
+   /* We need to rescale frequencies again to peak at REG_BR_PROB_BASE
+      as inlining loops might increase the maximum.  */
+   if (ENTRY_BLOCK_PTR->count)
+     counts_to_freqs ();
+   fold_cond_expr_cond ();
  }
  
  /* FN is a function that has a complete body, and CLONE is a function whose
*************** clone_body (tree clone, tree fn, void *a
*** 1917,1938 ****
    inline_data id;
  
    /* Clone the body, as if we were making an inline call.  But, remap the
!      parameters in the callee to the parameters of caller.  If there's an
!      in-charge parameter, map it to an appropriate constant.  */
    memset (&id, 0, sizeof (id));
!   VARRAY_TREE_INIT (id.fns, 2, "fns");
!   VARRAY_PUSH_TREE (id.fns, clone);
!   VARRAY_PUSH_TREE (id.fns, fn);
    id.decl_map = (splay_tree)arg_map;
  
    /* Cloning is treated slightly differently from inlining.  Set
       CLONING_P so that it's clear which operation we're performing.  */
    id.cloning_p = true;
  
    /* Actually copy the body.  */
!   append_to_statement_list_force (copy_body (&id), &DECL_SAVED_TREE (clone));
  }
  
  /* Make and return duplicate of body in FN.  Put copies of DECL_ARGUMENTS
     in *arg_copy and of the static chain, if any, in *sc_copy.  */
  
--- 2268,2294 ----
    inline_data id;
  
    /* Clone the body, as if we were making an inline call.  But, remap the
!      parameters in the callee to the parameters of caller.  */
    memset (&id, 0, sizeof (id));
!   id.caller = clone;
!   id.callee = fn;
!   id.callee_cfun = DECL_STRUCT_FUNCTION (fn);
    id.decl_map = (splay_tree)arg_map;
  
    /* Cloning is treated slightly differently from inlining.  Set
       CLONING_P so that it's clear which operation we're performing.  */
    id.cloning_p = true;
  
+   /* We're not inside any EH region.  */
+   id.eh_region = -1;
+ 
    /* Actually copy the body.  */
!   append_to_statement_list_force (copy_generic_body (&id), &DECL_SAVED_TREE (clone));
  }
  
+ /* Save duplicate body in FN.  MAP is used to pass around splay tree
+    used to update argments in restore_body.  */
+ 
  /* Make and return duplicate of body in FN.  Put copies of DECL_ARGUMENTS
     in *arg_copy and of the static chain, if any, in *sc_copy.  */
  
*************** save_body (tree fn, tree *arg_copy, tree
*** 1941,1950 ****
  {
    inline_data id;
    tree body, *parg;
  
    memset (&id, 0, sizeof (id));
!   VARRAY_TREE_INIT (id.fns, 1, "fns");
!   VARRAY_PUSH_TREE (id.fns, fn);
    id.node = cgraph_node (fn);
    id.saving_p = true;
    id.decl_map = splay_tree_new (splay_tree_compare_pointers, NULL, NULL);
--- 2297,2308 ----
  {
    inline_data id;
    tree body, *parg;
+   basic_block fn_entry_block;
  
    memset (&id, 0, sizeof (id));
!   id.callee = fn;
!   id.callee_cfun = DECL_STRUCT_FUNCTION (fn);
!   id.caller = fn;
    id.node = cgraph_node (fn);
    id.saving_p = true;
    id.decl_map = splay_tree_new (splay_tree_compare_pointers, NULL, NULL);
*************** save_body (tree fn, tree *arg_copy, tree
*** 1973,1982 ****
        *sc_copy = new;
      }
  
    insert_decl_map (&id, DECL_RESULT (fn), DECL_RESULT (fn));
  
!   /* Actually copy the body.  */
!   body = copy_body (&id);
  
    /* Clean up.  */
    splay_tree_delete (id.decl_map);
--- 2331,2351 ----
        *sc_copy = new;
      }
  
+   /* We're not inside any EH region.  */
+   id.eh_region = -1;
+ 
    insert_decl_map (&id, DECL_RESULT (fn), DECL_RESULT (fn));
  
!   /* Actually copy the body, including a new (struct function *) and CFG.
!      EH info is also duplicated so its labels point into the copied
!      CFG, not the original.  */
!   fn_entry_block = ENTRY_BLOCK_PTR_FOR_FUNCTION (DECL_STRUCT_FUNCTION (fn));
!   body = copy_body (&id,
! 		    fn_entry_block->count,
! 		    fn_entry_block->frequency,
! 		    NULL, NULL);
!   DECL_STRUCT_FUNCTION (fn)->saved_cfg = DECL_STRUCT_FUNCTION (body)->cfg;
!   DECL_STRUCT_FUNCTION (fn)->saved_eh = DECL_STRUCT_FUNCTION (body)->eh;
  
    /* Clean up.  */
    splay_tree_delete (id.decl_map);
*************** copy_tree_r (tree *tp, int *walk_subtree
*** 2034,2040 ****
  
  /* The SAVE_EXPR pointed to by TP is being copied.  If ST contains
     information indicating to what new SAVE_EXPR this one should be mapped,
!    use that one.  Otherwise, create a new node and enter it in ST.  */
  
  static void
  remap_save_expr (tree *tp, void *st_, int *walk_subtrees)
--- 2403,2410 ----
  
  /* The SAVE_EXPR pointed to by TP is being copied.  If ST contains
     information indicating to what new SAVE_EXPR this one should be mapped,
!    use that one.  Otherwise, create a new node and enter it in ST.  FN is
!    the function into which the copy will be placed.  */
  
  static void
  remap_save_expr (tree *tp, void *st_, int *walk_subtrees)
*************** static tree
*** 2075,2089 ****
  mark_local_for_remap_r (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
  			void *data)
  {
    inline_data *id = (inline_data *) data;
  
    /* Don't walk into types.  */
!   if (TYPE_P (*tp))
!     *walk_subtrees = 0;
  
!   else if (TREE_CODE (*tp) == LABEL_EXPR)
      {
!       tree decl = TREE_OPERAND (*tp, 0);
  
        /* Copy the decl and remember the copy.  */
        insert_decl_map (id, decl,
--- 2445,2464 ----
  mark_local_for_remap_r (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
  			void *data)
  {
+   tree t = *tp;
    inline_data *id = (inline_data *) data;
+   tree decl;
  
    /* Don't walk into types.  */
!   if (TYPE_P (t))
!     {
!       *walk_subtrees = 0;
!       return NULL_TREE;
!     }
  
!   else if (TREE_CODE (t) == LABEL_EXPR)
      {
!       decl = TREE_OPERAND (*tp, 0);
  
        /* Copy the decl and remember the copy.  */
        insert_decl_map (id, decl,
*************** unsave_expr_now (tree expr)
*** 2174,2181 ****
  
    /* Set up ID.  */
    memset (&id, 0, sizeof (id));
!   VARRAY_TREE_INIT (id.fns, 1, "fns");
!   VARRAY_PUSH_TREE (id.fns, current_function_decl);
    id.decl_map = splay_tree_new (splay_tree_compare_pointers, NULL, NULL);
  
    /* Walk the tree once to find local labels.  */
--- 2549,2556 ----
  
    /* Set up ID.  */
    memset (&id, 0, sizeof (id));
!   id.callee = current_function_decl;
!   id.caller = current_function_decl;
    id.decl_map = splay_tree_new (splay_tree_compare_pointers, NULL, NULL);
  
    /* Walk the tree once to find local labels.  */
*************** debug_find_tree_1 (tree *tp, int *walk_s
*** 2201,2206 ****
--- 2576,2583 ----
      return NULL;
  }
  
+ extern bool debug_find_tree (tree top, tree search);
+ 
  bool
  debug_find_tree (tree top, tree search)
  {
*************** debug_find_tree (tree top, tree search)
*** 2211,2221 ****
     VARS to BIND_EXPR.  */
  
  static void
! declare_inline_vars (tree bind_expr, tree vars)
  {
    tree t;
    for (t = vars; t; t = TREE_CHAIN (t))
      DECL_SEEN_IN_BIND_EXPR_P (t) = 1;
  
!   add_var_to_bind_expr (bind_expr, vars);
  }
--- 2588,2606 ----
     VARS to BIND_EXPR.  */
  
  static void
! declare_inline_vars (tree block, tree vars)
  {
    tree t;
    for (t = vars; t; t = TREE_CHAIN (t))
      DECL_SEEN_IN_BIND_EXPR_P (t) = 1;
  
!   if (block)
!     BLOCK_VARS (block) = chainon (BLOCK_VARS (block), vars);
! }
! 
! /* Returns true if we're inlining.  */
! static inline bool
! inlining_p (inline_data *id)
! {
!   return (!id->saving_p && !id->cloning_p);
  }
diff -c3p /aux/hubicka/egcs2/gcc/gcc/tree-inline.h gcc/tree-inline.h
*** /aux/hubicka/egcs2/gcc/gcc/tree-inline.h	Sat Apr  9 16:12:16 2005
--- gcc/tree-inline.h	Wed Apr 27 20:37:32 2005
*************** tree copy_tree_r (tree *, int *, void *)
*** 30,35 ****
--- 30,37 ----
  void clone_body (tree, tree, void *);
  tree save_body (tree, tree *, tree *);
  int estimate_move_cost (tree type);
+ void push_cfun (struct function *new_cfun);
+ void pop_cfun (void);
  int estimate_num_insns (tree expr);
  
  /* 0 if we should not perform inlining.
diff -c3p /aux/hubicka/egcs2/gcc/gcc/tree-optimize.c gcc/tree-optimize.c
*** /aux/hubicka/egcs2/gcc/gcc/tree-optimize.c	Thu Apr 28 21:39:45 2005
--- gcc/tree-optimize.c	Thu Apr 28 18:44:04 2005
*************** Boston, MA 02111-1307, USA.  */
*** 48,53 ****
--- 48,54 ----
  #include "cgraph.h"
  #include "graph.h"
  #include "cfgloop.h"
+ #include "except.h"
  
  
  /* Global variables used to communicate with passes.  */
*************** int dump_flags;
*** 55,61 ****
  bool in_gimple_form;
  
  /* The root of the compilation pass tree, once constructed.  */
! static struct tree_opt_pass *all_passes, *all_ipa_passes;
  
  /* Pass: dump the gimplified, inlined, functions.  */
  
--- 56,62 ----
  bool in_gimple_form;
  
  /* The root of the compilation pass tree, once constructed.  */
! static struct tree_opt_pass *all_passes, *all_ipa_passes, * all_lowering_passes;
  
  /* Pass: dump the gimplified, inlined, functions.  */
  
*************** static struct tree_opt_pass pass_free_da
*** 177,182 ****
--- 178,224 ----
    0					/* letter */
  };
  
+ /* Pass: fixup_cfg - IPA passes or compilation of earlier functions might've
+    changed some properties - such as marged functions nothrow.  Remove now
+    redundant edges and basic blocks.  */
+ 
+ static void
+ execute_fixup_cfg (void)
+ {
+   basic_block bb;
+   block_stmt_iterator bsi;
+ 
+   if (cfun->eh)
+     FOR_EACH_BB (bb)
+       {
+ 	for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
+ 	  {
+ 	    tree stmt = bsi_stmt (bsi);
+ 	    if (!tree_could_throw_p (stmt) && lookup_stmt_eh_region (stmt))
+ 	      remove_stmt_from_eh_region (stmt);
+ 	  }
+ 	tree_purge_dead_eh_edges (bb);
+       }
+     
+   cleanup_tree_cfg ();
+ }
+ 
+ static struct tree_opt_pass pass_fixup_cfg =
+ {
+   NULL,					/* name */
+   NULL,					/* gate */
+   execute_fixup_cfg,			/* execute */
+   NULL,					/* sub */
+   NULL,					/* next */
+   0,					/* static_pass_number */
+   0,					/* tv_id */
+   PROP_cfg,				/* properties_required */
+   0,					/* properties_provided */
+   0,					/* properties_destroyed */
+   0,					/* todo_flags_start */
+   0,					/* todo_flags_finish */
+   0					/* letter */
+ };
  
  /* Do the actions required to initialize internal data structures used
     in tree-ssa optimization passes.  */
*************** init_tree_optimization_passes (void)
*** 339,352 ****
    NEXT_PASS (pass_ipa_inline);
    *p = NULL;
  
!   p = &all_passes;
!   NEXT_PASS (pass_gimple);
    NEXT_PASS (pass_remove_useless_stmts);
    NEXT_PASS (pass_mudflap_1);
!   NEXT_PASS (pass_lower_cf);
!   NEXT_PASS (pass_lower_eh);
!   NEXT_PASS (pass_build_cfg);
    NEXT_PASS (pass_pre_expand);
    NEXT_PASS (pass_tree_profile);
    NEXT_PASS (pass_init_datastructures);
    NEXT_PASS (pass_all_optimizations);
--- 381,401 ----
    NEXT_PASS (pass_ipa_inline);
    *p = NULL;
  
!   /* 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);
!   NEXT_PASS (pass_lower_cf); 
!   NEXT_PASS (pass_lower_eh); 
!   NEXT_PASS (pass_build_cfg); 
    NEXT_PASS (pass_pre_expand);
+   *p = NULL;
+ 
+   p = &all_passes;
+   NEXT_PASS (pass_fixup_cfg);
    NEXT_PASS (pass_tree_profile);
    NEXT_PASS (pass_init_datastructures);
    NEXT_PASS (pass_all_optimizations);
*************** init_tree_optimization_passes (void)
*** 445,450 ****
--- 494,500 ----
  
  #undef NEXT_PASS
  
+   register_dump_files (all_lowering_passes, false, 0);
    register_dump_files (all_passes, false, PROP_gimple_any
  					  | PROP_gimple_lcf
  					  | PROP_gimple_leh
*************** execute_pass_list (struct tree_opt_pass 
*** 619,624 ****
--- 669,691 ----
    while (pass);
  }
  
+ 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 ();
+   bitmap_obstack_initialize (NULL);
+   execute_pass_list (all_lowering_passes);
+   free_dominance_info (CDI_POST_DOMINATORS);
+   compact_blocks ();
+   current_function_decl = saved_current_function_decl;
+   bitmap_obstack_release (NULL);
+   pop_cfun ();
+ }
+ 
  /* Execute all IPA passes.  */
  void
  ipa_passes (void)
*************** tree_rest_of_compilation (tree fndecl)
*** 669,674 ****
--- 736,742 ----
       We haven't necessarily assigned RTL to all variables yet, so it's
       not safe to try to expand expressions involving them.  */
    cfun->x_dont_save_pending_sizes_p = 1;
+   cfun->after_inlining = true;
  
    node = cgraph_node (fndecl);
  
*************** tree_rest_of_compilation (tree fndecl)
*** 724,729 ****
--- 792,798 ----
    bitmap_obstack_initialize (NULL);
    bitmap_obstack_initialize (&reg_obstack); /* FIXME, only at RTL generation*/
    
+   tree_register_cfg_hooks ();
    /* Perform all tree transforms and optimizations.  */
    execute_pass_list (all_passes);
    
*************** tree_rest_of_compilation (tree fndecl)
*** 733,744 ****
    bitmap_obstack_release (NULL);
    
    /* Restore original body if still needed.  */
!   if (cfun->saved_tree)
      {
        DECL_SAVED_TREE (fndecl) = cfun->saved_tree;
        DECL_ARGUMENTS (fndecl) = cfun->saved_args;
        cfun->static_chain_decl = cfun->saved_static_chain_decl;
- 
        /* When not in unit-at-a-time mode, we must preserve out of line copy
  	 representing node before inlining.  Restore original outgoing edges
  	 using clone we created earlier.  */
--- 802,817 ----
    bitmap_obstack_release (NULL);
    
    /* Restore original body if still needed.  */
!   if (cfun->saved_cfg)
      {
        DECL_SAVED_TREE (fndecl) = cfun->saved_tree;
        DECL_ARGUMENTS (fndecl) = cfun->saved_args;
+       cfun->cfg = DECL_STRUCT_FUNCTION (cfun->saved_tree)->cfg;
+       cfun->eh = DECL_STRUCT_FUNCTION (cfun->saved_tree)->eh;
+       cfun->saved_cfg = (struct control_flow_graph *) 0;
+       cfun->saved_tree = NULL_TREE;
+       cfun->saved_args = NULL_TREE;
        cfun->static_chain_decl = cfun->saved_static_chain_decl;
        /* When not in unit-at-a-time mode, we must preserve out of line copy
  	 representing node before inlining.  Restore original outgoing edges
  	 using clone we created earlier.  */
*************** tree_rest_of_compilation (tree fndecl)
*** 746,751 ****
--- 819,825 ----
  	{
  	  struct cgraph_edge *e;
  
+ 	  node = cgraph_node (current_function_decl);
  	  cgraph_node_remove_callees (node);
  	  node->callees = saved_node->callees;
  	  saved_node->callees = NULL;
diff -c3p /aux/hubicka/egcs2/gcc/gcc/tree-pass.h gcc/tree-pass.h
*** /aux/hubicka/egcs2/gcc/gcc/tree-pass.h	Thu Apr 28 21:39:45 2005
--- gcc/tree-pass.h	Wed Apr 27 20:46:45 2005
*************** struct dump_file_info
*** 155,160 ****
--- 155,161 ----
    (TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts)
  
  extern void ipa_passes (void);
+ extern void tree_lowering_passes (tree decl);
  
  extern struct tree_opt_pass pass_mudflap_1;
  extern struct tree_opt_pass pass_mudflap_2;
diff -c3p /aux/hubicka/egcs2/gcc/gcc/tree-ssa-ccp.c gcc/tree-ssa-ccp.c
*** /aux/hubicka/egcs2/gcc/gcc/tree-ssa-ccp.c	Thu Apr 28 21:39:46 2005
--- gcc/tree-ssa-ccp.c	Wed Apr 27 20:50:12 2005
*************** maybe_fold_offset_to_component_ref (tree
*** 1583,1589 ****
  /* A subroutine of fold_stmt_r.  Attempt to simplify *(BASE+OFFSET).
     Return the simplified expression, or NULL if nothing could be done.  */
  
! static tree
  maybe_fold_stmt_indirect (tree expr, tree base, tree offset)
  {
    tree t;
--- 1583,1589 ----
  /* A subroutine of fold_stmt_r.  Attempt to simplify *(BASE+OFFSET).
     Return the simplified expression, or NULL if nothing could be done.  */
  
! tree
  maybe_fold_stmt_indirect (tree expr, tree base, tree offset)
  {
    tree t;
diff -c3p /aux/hubicka/egcs2/gcc/gcc/cgraphunit.c gcc/cgraphunit.c
*** /aux/hubicka/egcs2/gcc/gcc/cgraphunit.c	Thu Apr 28 21:39:30 2005
--- gcc/cgraphunit.c	Thu Apr 28 11:31:28 2005
*************** cgraph_finalize_function (tree decl, boo
*** 427,432 ****
--- 427,433 ----
    notice_global_symbol (decl);
    node->decl = decl;
    node->local.finalized = true;
+   node->lowered = DECL_STRUCT_FUNCTION (decl)->cfg != NULL;
    if (node->nested)
      lower_nested_functions (decl);
    gcc_assert (!node->nested);
*************** cgraph_finalize_function (tree decl, boo
*** 459,464 ****
--- 460,475 ----
      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)
*************** record_call_1 (tree *tp, int *walk_subtr
*** 513,518 ****
--- 524,542 ----
  	break;
        }
  
+     case STATEMENT_LIST:
+       {
+ 	tree_stmt_iterator tsi;
+ 	/* Track current statement while finding CALL_EXPRs.  */
+ 	for (tsi = tsi_start (*tp); !tsi_end_p (tsi); tsi_next (&tsi))
+ 	  {
+ 	    walk_tree (tsi_stmt_ptr (tsi), record_call_1, data,
+ 		       visited_nodes);
+ 	  }
+       }
+       break;
+ 
+ 
      default:
        /* Save some cycles by not walking types and declaration as we
  	 won't find anything useful there anyway.  */
*************** cgraph_create_edges (struct cgraph_node 
*** 538,543 ****
--- 562,602 ----
    /* The nodes we're interested in are never shared, so walk
       the tree ignoring duplicates.  */
    visited_nodes = pointer_set_create ();
+   if (TREE_CODE (body) == FUNCTION_DECL)
+     {
+       struct function *this_cfun = DECL_STRUCT_FUNCTION (body);
+       basic_block this_block;
+       tree step;
+ 
+       /* Reach the trees by walking over the CFG, and note the 
+ 	 enclosing basic-blocks in the call edges.  */
+       FOR_EACH_BB_FN (this_block, this_cfun)
+ 	walk_tree (&this_block->stmt_list, record_call_1, node, visited_nodes);
+ 
+       /* Walk over any private statics that may take addresses of functions.  */
+       if (TREE_CODE (DECL_INITIAL (body)) == BLOCK)
+ 	{
+ 	  for (step = BLOCK_VARS (DECL_INITIAL (body));
+ 	       step;
+ 	       step = TREE_CHAIN (step))
+ 	    if (DECL_INITIAL (step))
+ 	      walk_tree (&DECL_INITIAL (step), record_call_1, node, visited_nodes);
+ 	}
+ 
+       /* Also look here for private statics.  */
+       if (DECL_STRUCT_FUNCTION (body))
+ 	for (step = DECL_STRUCT_FUNCTION (body)->unexpanded_var_list;
+ 	     step;
+ 	     step = TREE_CHAIN (step))
+ 	  {
+ 	    tree decl = TREE_VALUE (step);
+ 	    if (DECL_INITIAL (decl) && TREE_STATIC (decl))
+ 	      walk_tree (&DECL_INITIAL (decl), record_call_1, node, visited_nodes);
+ 	  }
+     }
+   else
+     walk_tree (&body, record_call_1, node, visited_nodes);
+     
    walk_tree (&body, record_call_1, node, visited_nodes);
    pointer_set_destroy (visited_nodes);
    visited_nodes = NULL;
*************** verify_cgraph_node (struct cgraph_node *
*** 596,601 ****
--- 655,662 ----
  {
    struct cgraph_edge *e;
    struct cgraph_node *main_clone;
+   struct function *this_cfun = DECL_STRUCT_FUNCTION (node->decl);
+   basic_block this_block;
  
    timevar_push (TV_CGRAPH_VERIFY);
    error_found = false;
*************** verify_cgraph_node (struct cgraph_node *
*** 655,662 ****
        && DECL_SAVED_TREE (node->decl) && !TREE_ASM_WRITTEN (node->decl)
        && (!DECL_EXTERNAL (node->decl) || node->global.inlined_to))
      {
!       walk_tree_without_duplicates (&DECL_SAVED_TREE (node->decl),
! 				    verify_cgraph_node_1, node);
        for (e = node->callees; e; e = e->next_callee)
  	{
  	  if (!e->aux)
--- 716,737 ----
        && DECL_SAVED_TREE (node->decl) && !TREE_ASM_WRITTEN (node->decl)
        && (!DECL_EXTERNAL (node->decl) || node->global.inlined_to))
      {
!       if (this_cfun->cfg->x_entry_block_ptr)
! 	{
! 	  /* The nodes we're interested in are never shared, so walk
! 	     the tree ignoring duplicates.  */
! 	  visited_nodes = pointer_set_create ();
! 	  /* Reach the trees by walking over the CFG, and note the
! 	     enclosing basic-blocks in the call edges.  */
! 	  FOR_EACH_BB_FN (this_block, this_cfun)
! 	    walk_tree (&this_block->stmt_list, verify_cgraph_node_1, node, visited_nodes);
! 	  pointer_set_destroy (visited_nodes);
! 	  visited_nodes = NULL;
! 	}
!       else
! 	/* No CFG available?!  */
! 	gcc_unreachable ();
! 
        for (e = node->callees; e; e = e->next_callee)
  	{
  	  if (!e->aux)
*************** cgraph_analyze_function (struct cgraph_n
*** 729,740 ****
    struct cgraph_edge *e;
  
    current_function_decl = decl;
  
    /* First kill forward declaration so reverse inlining works properly.  */
!   cgraph_create_edges (node, DECL_SAVED_TREE (decl));
  
    node->local.inlinable = tree_inlinable_function_p (decl);
!   node->local.self_insns = estimate_num_insns (DECL_SAVED_TREE (decl));
    if (node->local.inlinable)
      node->local.disregard_inline_limits
        = lang_hooks.tree_inlining.disregard_inline_limits (decl);
--- 804,817 ----
    struct cgraph_edge *e;
  
    current_function_decl = decl;
+   push_cfun (DECL_STRUCT_FUNCTION (decl));
+   cgraph_lower_function (node);
  
    /* First kill forward declaration so reverse inlining works properly.  */
!   cgraph_create_edges (node, decl);
  
    node->local.inlinable = tree_inlinable_function_p (decl);
!   node->local.self_insns = estimate_num_insns (decl);
    if (node->local.inlinable)
      node->local.disregard_inline_limits
        = lang_hooks.tree_inlining.disregard_inline_limits (decl);
*************** cgraph_analyze_function (struct cgraph_n
*** 754,759 ****
--- 831,837 ----
    node->global.insns = node->local.self_insns;
  
    node->analyzed = true;
+   pop_cfun ();
    current_function_decl = NULL;
  }
  
*************** cgraph_build_static_cdtor (char which, t
*** 1178,1184 ****
  
    /* ??? We will get called LATE in the compilation process.  */
    if (cgraph_global_info_ready)
!     tree_rest_of_compilation (decl);
    else
      cgraph_finalize_function (decl, 0);
    
--- 1256,1265 ----
  
    /* ??? We will get called LATE in the compilation process.  */
    if (cgraph_global_info_ready)
!     {
!       tree_lowering_passes (decl);
!       tree_rest_of_compilation (decl);
!     }
    else
      cgraph_finalize_function (decl, 0);
    
Index: cp/method.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/method.c,v
retrieving revision 1.327
diff -c -3 -p -r1.327 method.c
*** cp/method.c	23 Apr 2005 21:28:54 -0000	1.327
--- cp/method.c	28 Apr 2005 20:37:52 -0000
*************** Boston, MA 02111-1307, USA.  */
*** 36,41 ****
--- 36,42 ----
  #include "toplev.h"
  #include "tm_p.h"
  #include "target.h"
+ #include "tree-pass.h"
  
  /* Various flags to control the mangling process.  */
  
*************** use_thunk (tree thunk_fndecl, bool emit_
*** 504,510 ****
        /* Re-enable access control.  */
        pop_deferring_access_checks ();
  
!       expand_body (finish_function (0));
      }
  
    pop_from_top_level ();
--- 505,513 ----
        /* Re-enable access control.  */
        pop_deferring_access_checks ();
  
!       thunk_fndecl = finish_function (0);
!       tree_lowering_passes (thunk_fndecl);
!       expand_body (thunk_fndecl);
      }
  
    pop_from_top_level ();


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