OSDN Git Service

Compile speed improvement.
[pf3gnuchains/gcc-fork.git] / gcc / tree-nested.c
1 /* Nested function decomposition for trees.
2    Copyright (C) 2004 Free Software Foundation, Inc.
3
4    This file is part of GCC.
5
6    GCC is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2, or (at your option)
9    any later version.
10
11    GCC is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with GCC; see the file COPYING.  If not, write to
18    the Free Software Foundation, 59 Temple Place - Suite 330,
19    Boston, MA 02111-1307, USA.  */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "tree.h"
26 #include "rtl.h"
27 #include "tm_p.h"
28 #include "function.h"
29 #include "tree-dump.h"
30 #include "tree-inline.h"
31 #include "tree-gimple.h"
32 #include "tree-iterator.h"
33 #include "tree-flow.h"
34 #include "cgraph.h"
35 #include "expr.h"
36 #include "langhooks.h"
37 #include "ggc.h"
38
39
40 /* The object of this pass is to lower the representation of a set of nested
41    functions in order to expose all of the gory details of the various
42    nonlocal references.  We want to do this sooner rather than later, in
43    order to give us more freedom in emitting all of the functions in question.
44
45    Back in olden times, when gcc was young, we developed an insanely 
46    complicated scheme whereby variables which were referenced nonlocally
47    were forced to live in the stack of the declaring function, and then
48    the nested functions magically discovered where these variables were
49    placed.  In order for this scheme to function properly, it required
50    that the outer function be partially expanded, then we switch to 
51    compiling the inner function, and once done with those we switch back
52    to compiling the outer function.  Such delicate ordering requirements
53    makes it difficult to do whole translation unit optimizations 
54    involving such functions.
55
56    The implementation here is much more direct.  Everything that can be
57    referenced by an inner function is a member of an explicitly created
58    structure herein called the "nonlocal frame struct".  The incoming
59    static chain for a nested function is a pointer to this struct in 
60    the parent.  In this way, we settle on known offsets from a known
61    base, and so are decoupled from the logic that places objects in the
62    function's stack frame.  More importantly, we don't have to wait for
63    that to happen -- since the compilation of the inner function is no
64    longer tied to a real stack frame, the nonlocal frame struct can be
65    allocated anywhere.  Which means that the outer function is now
66    inlinable.
67
68    Theory of operation here is very simple.  Iterate over all the 
69    statements in all the functions (depth first) several times, 
70    allocating structures and fields on demand.  In general we want to
71    examine inner functions first, so that we can avoid making changes
72    to outer functions which are unnecessary.
73
74    The order of the passes matters a bit, in that later passes will be
75    skipped if it is discovered that the functions don't actually interact
76    at all.  That is, they're nested in the lexical sense but could have
77    been written as independent functions without change.  */
78
79
80 struct var_map_elt
81 {
82   tree old;
83   tree new;
84 };
85
86 struct nesting_info
87 {
88   struct nesting_info *outer;
89   struct nesting_info *inner;
90   struct nesting_info *next;
91   
92   htab_t var_map;
93   tree context;
94   tree new_local_var_chain;
95   tree frame_type;
96   tree frame_decl;
97   tree chain_field;
98   tree chain_decl;
99   tree nl_goto_field;
100
101   bool any_parm_remapped;
102   bool any_tramp_created;
103 };
104
105
106 /* Hashing and equality functions for nesting_info->var_map.  */
107
108 static hashval_t
109 var_map_hash (const void *x)
110 {
111   const struct var_map_elt *a = x;
112   return htab_hash_pointer (a->old);
113 }
114
115 static int
116 var_map_eq (const void *x, const void *y)
117 {
118   const struct var_map_elt *a = x;
119   const struct var_map_elt *b = y;
120   return a->old == b->old;
121 }
122
123 /* We're working in so many different function contexts simultaneously,
124    that create_tmp_var is dangerous.  Prevent mishap.  */
125 #define create_tmp_var cant_use_create_tmp_var_here_dummy
126
127 /* Like create_tmp_var, except record the variable for registration at
128    the given nesting level.  */
129
130 static tree
131 create_tmp_var_for (struct nesting_info *info, tree type, const char *prefix)
132 {
133   tree tmp_var;
134
135   /* If the type is of variable size or a type which must be created by the
136      frontend, something is wrong.  Note that we explicitly allow
137      incomplete types here, since we create them ourselves here.  */
138   gcc_assert (!TREE_ADDRESSABLE (type));
139   gcc_assert (!TYPE_SIZE_UNIT (type)
140               || TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST);
141
142   tmp_var = create_tmp_var_raw (type, prefix);
143   DECL_CONTEXT (tmp_var) = info->context;
144   TREE_CHAIN (tmp_var) = info->new_local_var_chain;
145   DECL_SEEN_IN_BIND_EXPR_P (tmp_var) = 1;
146   info->new_local_var_chain = tmp_var;
147
148   return tmp_var;
149 }
150
151 /* Take the address of EXP.  Mark it for addressability as necessary.  */
152
153 tree
154 build_addr (tree exp)
155 {
156   tree base = exp;
157
158   while (handled_component_p (base))
159     base = TREE_OPERAND (base, 0);
160
161   if (DECL_P (base))
162     TREE_ADDRESSABLE (base) = 1;
163
164   return build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (exp)), exp);
165 }
166
167 /* Insert FIELD into TYPE, sorted by alignment requirements.  */
168
169 static void
170 insert_field_into_struct (tree type, tree field)
171 {
172   tree *p;
173
174   DECL_CONTEXT (field) = type;
175
176   for (p = &TYPE_FIELDS (type); *p ; p = &TREE_CHAIN (*p))
177     if (DECL_ALIGN (field) >= DECL_ALIGN (*p))
178       break;
179
180   TREE_CHAIN (field) = *p;
181   *p = field;
182 }
183
184 /* Build or return the RECORD_TYPE that describes the frame state that is
185    shared between INFO->CONTEXT and its nested functions.  This record will
186    not be complete until finalize_nesting_tree; up until that point we'll
187    be adding fields as necessary.
188
189    We also build the DECL that represents this frame in the function.  */
190
191 static tree
192 get_frame_type (struct nesting_info *info)
193 {
194   tree type = info->frame_type;
195   if (!type)
196     {
197       char *name;
198
199       type = make_node (RECORD_TYPE);
200
201       name = concat ("FRAME.",
202                      IDENTIFIER_POINTER (DECL_NAME (info->context)),
203                      NULL);
204       TYPE_NAME (type) = get_identifier (name);
205       free (name);
206
207       info->frame_type = type;
208       info->frame_decl = create_tmp_var_for (info, type, "FRAME");
209     }
210   return type;
211 }
212
213 /* Return true if DECL should be referenced by pointer in the non-local
214    frame structure.  */
215
216 static bool
217 use_pointer_in_frame (tree decl)
218 {
219   if (TREE_CODE (decl) == PARM_DECL)
220     {
221       /* It's illegal to copy TREE_ADDRESSABLE, impossible to copy variable
222          sized decls, and inefficient to copy large aggregates.  Don't bother
223          moving anything but scalar variables.  */
224       return AGGREGATE_TYPE_P (TREE_TYPE (decl));
225     }
226   else
227     {
228       /* Variable sized types make things "interesting" in the frame.  */
229       return DECL_SIZE (decl) == NULL || !TREE_CONSTANT (DECL_SIZE (decl));
230     }
231 }
232
233 /* Given DECL, a non-locally accessed variable, find or create a field
234    in the non-local frame structure for the given nesting context.  */
235
236 static tree
237 lookup_field_for_decl (struct nesting_info *info, tree decl,
238                        enum insert_option insert)
239 {
240   struct var_map_elt *elt, dummy;
241   void **slot;
242   tree field;
243
244   dummy.old = decl;
245   slot = htab_find_slot (info->var_map, &dummy, insert);
246   if (!slot)
247     {
248       gcc_assert (insert != INSERT);
249       return NULL;
250     }
251   elt = *slot;
252
253   if (!elt && insert == INSERT)
254     {
255       field = make_node (FIELD_DECL);
256       DECL_NAME (field) = DECL_NAME (decl);
257
258       if (use_pointer_in_frame (decl))
259         {
260           TREE_TYPE (field) = build_pointer_type (TREE_TYPE (decl));
261           DECL_ALIGN (field) = TYPE_ALIGN (TREE_TYPE (field));
262           DECL_NONADDRESSABLE_P (field) = 1;
263         }
264       else
265         {
266           TREE_TYPE (field) = TREE_TYPE (decl);
267           DECL_SOURCE_LOCATION (field) = DECL_SOURCE_LOCATION (decl);
268           DECL_ALIGN (field) = DECL_ALIGN (decl);
269           DECL_USER_ALIGN (field) = DECL_USER_ALIGN (decl);
270           TREE_ADDRESSABLE (field) = TREE_ADDRESSABLE (decl);
271           DECL_NONADDRESSABLE_P (field) = !TREE_ADDRESSABLE (decl);
272           TREE_THIS_VOLATILE (field) = TREE_THIS_VOLATILE (decl);
273         }
274
275       insert_field_into_struct (get_frame_type (info), field);
276   
277       elt = xmalloc (sizeof (*elt));
278       elt->old = decl;
279       elt->new = field;
280       *slot = elt;
281
282       if (TREE_CODE (decl) == PARM_DECL)
283         info->any_parm_remapped = true;
284     }
285   else
286     field = elt ? elt->new : NULL;
287
288   return field;
289 }
290
291 /* Build or return the variable that holds the static chain within
292    INFO->CONTEXT.  This variable may only be used within INFO->CONTEXT.  */
293
294 static tree
295 get_chain_decl (struct nesting_info *info)
296 {
297   tree decl = info->chain_decl;
298   if (!decl)
299     {
300       tree type;
301
302       type = get_frame_type (info->outer);
303       type = build_pointer_type (type);
304
305       /* Note that this variable is *not* entered into any BIND_EXPR;
306          the construction of this variable is handled specially in
307          expand_function_start and initialize_inlined_parameters.
308          Note also that it's represented as a parameter.  This is more
309          close to the truth, since the initial value does come from 
310          the caller.  */
311       decl = build_decl (PARM_DECL, create_tmp_var_name ("CHAIN"), type);
312       DECL_ARTIFICIAL (decl) = 1;
313       DECL_IGNORED_P (decl) = 1;
314       TREE_USED (decl) = 1;
315       DECL_CONTEXT (decl) = info->context;
316       DECL_ARG_TYPE (decl) = type;
317
318       /* Tell tree-inline.c that we never write to this variable, so
319          it can copy-prop the replacement value immediately.  */
320       TREE_READONLY (decl) = 1;
321
322       info->chain_decl = decl;
323     }
324   return decl;
325 }
326
327 /* Build or return the field within the non-local frame state that holds
328    the static chain for INFO->CONTEXT.  This is the way to walk back up
329    multiple nesting levels.  */
330
331 static tree
332 get_chain_field (struct nesting_info *info)
333 {
334   tree field = info->chain_field;
335   if (!field)
336     {
337       tree type = build_pointer_type (get_frame_type (info->outer));
338
339       field = make_node (FIELD_DECL);
340       DECL_NAME (field) = get_identifier ("__chain");
341       TREE_TYPE (field) = type;
342       DECL_ALIGN (field) = TYPE_ALIGN (type);
343       DECL_NONADDRESSABLE_P (field) = 1;
344
345       insert_field_into_struct (get_frame_type (info), field);
346
347       info->chain_field = field;
348     }
349   return field;
350 }
351
352 /* Copy EXP into a temporary.  Allocate the temporary in the context of
353    INFO and insert the initialization statement before TSI.  */
354
355 static tree
356 init_tmp_var (struct nesting_info *info, tree exp, tree_stmt_iterator *tsi)
357 {
358   tree t, stmt;
359
360   t = create_tmp_var_for (info, TREE_TYPE (exp), NULL);
361   stmt = build (MODIFY_EXPR, TREE_TYPE (t), t, exp);
362   SET_EXPR_LOCUS (stmt, EXPR_LOCUS (tsi_stmt (*tsi)));
363   tsi_link_before (tsi, stmt, TSI_SAME_STMT);
364
365   return t;
366 }
367
368 /* Similarly, but only do so to force EXP to satisfy is_gimple_val.  */
369
370 static tree
371 tsi_gimplify_val (struct nesting_info *info, tree exp, tree_stmt_iterator *tsi)
372 {
373   if (is_gimple_val (exp))
374     return exp;
375   else
376     return init_tmp_var (info, exp, tsi);
377 }
378
379 /* Build or return the type used to represent a nested function trampoline.  */
380
381 static GTY(()) tree trampoline_type;
382
383 static tree
384 get_trampoline_type (void)
385 {
386   tree record, t;
387   unsigned align, size;
388
389   if (trampoline_type)
390     return trampoline_type;
391
392   align = TRAMPOLINE_ALIGNMENT;
393   size = TRAMPOLINE_SIZE;
394
395   /* If we won't be able to guarantee alignment simply via TYPE_ALIGN,
396      then allocate extra space so that we can do dynamic alignment.  */
397   if (align > STACK_BOUNDARY)
398     {
399       size += ((align/BITS_PER_UNIT) - 1) & -(STACK_BOUNDARY/BITS_PER_UNIT);
400       align = STACK_BOUNDARY;
401     }
402
403   t = build_index_type (build_int_cst (NULL_TREE, size - 1));
404   t = build_array_type (char_type_node, t);
405   t = build_decl (FIELD_DECL, get_identifier ("__data"), t);
406   DECL_ALIGN (t) = align;
407   DECL_USER_ALIGN (t) = 1;
408
409   record = make_node (RECORD_TYPE);
410   TYPE_NAME (record) = get_identifier ("__builtin_trampoline");
411   TYPE_FIELDS (record) = t;
412   layout_type (record);
413
414   return record;
415 }
416
417 /* Given DECL, a nested function, find or create a field in the non-local
418    frame structure for a trampoline for this function.  */
419
420 static tree
421 lookup_tramp_for_decl (struct nesting_info *info, tree decl,
422                        enum insert_option insert)
423 {
424   struct var_map_elt *elt, dummy;
425   void **slot;
426   tree field;
427
428   dummy.old = decl;
429   slot = htab_find_slot (info->var_map, &dummy, insert);
430   if (!slot)
431     {
432       gcc_assert (insert != INSERT);
433       return NULL;
434     }
435   elt = *slot;
436
437   if (!elt && insert == INSERT)
438     {
439       field = make_node (FIELD_DECL);
440       DECL_NAME (field) = DECL_NAME (decl);
441       TREE_TYPE (field) = get_trampoline_type ();
442       TREE_ADDRESSABLE (field) = 1;
443
444       insert_field_into_struct (get_frame_type (info), field);
445
446       elt = xmalloc (sizeof (*elt));
447       elt->old = decl;
448       elt->new = field;
449       *slot = elt;
450
451       info->any_tramp_created = true;
452     }
453   else
454     field = elt ? elt->new : NULL;
455
456   return field;
457
458
459 /* Build or return the field within the non-local frame state that holds
460    the non-local goto "jmp_buf".  The buffer itself is maintained by the
461    rtl middle-end as dynamic stack space is allocated.  */
462
463 static tree
464 get_nl_goto_field (struct nesting_info *info)
465 {
466   tree field = info->nl_goto_field;
467   if (!field)
468     {
469       unsigned size;
470       tree type;
471
472       /* For __builtin_nonlocal_goto, we need N words.  The first is the
473          frame pointer, the rest is for the target's stack pointer save
474          area.  The number of words is controlled by STACK_SAVEAREA_MODE;
475          not the best interface, but it'll do for now.  */
476       if (Pmode == ptr_mode)
477         type = ptr_type_node;
478       else
479         type = lang_hooks.types.type_for_mode (Pmode, 1);
480
481       size = GET_MODE_SIZE (STACK_SAVEAREA_MODE (SAVE_NONLOCAL));
482       size = size / GET_MODE_SIZE (Pmode);
483       size = size + 1;
484
485       type = build_array_type
486         (type, build_index_type (build_int_cst (NULL_TREE, size)));
487
488       field = make_node (FIELD_DECL);
489       DECL_NAME (field) = get_identifier ("__nl_goto_buf");
490       TREE_TYPE (field) = type;
491       DECL_ALIGN (field) = TYPE_ALIGN (type);
492       TREE_ADDRESSABLE (field) = 1;
493
494       insert_field_into_struct (get_frame_type (info), field);
495
496       info->nl_goto_field = field;
497     }
498
499   return field;
500 }
501 \f
502 /* Convenience routines to walk all statements of a gimple function.
503
504    For each statement, we invoke CALLBACK via walk_tree.  The passed
505    data is a walk_stmt_info structure.  Of note here is a TSI that
506    points to the current statement being walked.  The VAL_ONLY flag
507    that indicates whether the *TP being examined may be replaced 
508    with something that matches is_gimple_val (if true) or something
509    slightly more complicated (if false).  "Something" technically 
510    means the common subset of is_gimple_lvalue and is_gimple_rhs, 
511    but we never try to form anything more complicated than that, so
512    we don't bother checking.  */
513
514 struct walk_stmt_info
515 {
516   walk_tree_fn callback;
517   tree_stmt_iterator tsi;
518   struct nesting_info *info;
519   bool val_only;
520   bool changed;
521 };
522
523 /* A subroutine of walk_function.  Iterate over all sub-statements of *TP.  */
524
525 static void
526 walk_stmts (struct walk_stmt_info *wi, tree *tp)
527 {
528   tree t = *tp;
529   if (!t)
530     return;
531
532   switch (TREE_CODE (t))
533     {
534     case STATEMENT_LIST:
535       {
536         tree_stmt_iterator i;
537         for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
538           {
539             wi->tsi = i;
540             walk_stmts (wi, tsi_stmt_ptr (i));
541           }
542       }
543       break;
544
545     case COND_EXPR:
546       walk_tree (&COND_EXPR_COND (t), wi->callback, wi, NULL);
547       walk_stmts (wi, &COND_EXPR_THEN (t));
548       walk_stmts (wi, &COND_EXPR_ELSE (t));
549       break;
550     case CATCH_EXPR:
551       walk_stmts (wi, &CATCH_BODY (t));
552       break;
553     case EH_FILTER_EXPR:
554       walk_stmts (wi, &EH_FILTER_FAILURE (t));
555       break;
556     case TRY_CATCH_EXPR:
557     case TRY_FINALLY_EXPR:
558       walk_stmts (wi, &TREE_OPERAND (t, 0));
559       walk_stmts (wi, &TREE_OPERAND (t, 1));
560       break;
561     case BIND_EXPR:
562       walk_stmts (wi, &BIND_EXPR_BODY (t));
563       break;
564
565     case RETURN_EXPR:
566       walk_stmts (wi, &TREE_OPERAND (t, 0));
567       break;
568
569     case MODIFY_EXPR:
570       /* The immediate arguments of a MODIFY_EXPR may use COMPONENT_REF.  */
571       wi->val_only = false;
572       walk_tree (&TREE_OPERAND (t, 0), wi->callback, wi, NULL);
573       wi->val_only = false;
574       walk_tree (&TREE_OPERAND (t, 1), wi->callback, wi, NULL);
575       wi->val_only = true;
576       break;
577
578     default:
579       wi->val_only = true;
580       walk_tree (tp, wi->callback, wi, NULL);
581       break;
582     }
583 }
584
585 /* Invoke CALLBACK on all statements of INFO->CONTEXT.  */
586
587 static void
588 walk_function (walk_tree_fn callback, struct nesting_info *info)
589 {
590   struct walk_stmt_info wi;
591
592   memset (&wi, 0, sizeof (wi));
593   wi.callback = callback;
594   wi.info = info;
595   wi.val_only = true;
596
597   walk_stmts (&wi, &DECL_SAVED_TREE (info->context));
598 }
599
600 /* Similarly for ROOT and all functions nested underneath, depth first.  */
601     
602 static void
603 walk_all_functions (walk_tree_fn callback, struct nesting_info *root)
604 {
605   do
606     {
607       if (root->inner)
608         walk_all_functions (callback, root->inner);
609       walk_function (callback, root);
610       root = root->next;
611     }
612   while (root);
613 }
614 \f
615 /* We have to check for a fairly pathalogical case.  The operands of function
616    nested function are to be interpreted in the context of the enclosing
617    function.  So if any are variably-sized, they will get remapped when the
618    enclosing function is inlined.  But that remapping would also have to be
619    done in the types of the PARM_DECLs of the nested function, meaning the
620    argument types of that function will disagree with the arguments in the
621    calls to that function.  So we'd either have to make a copy of the nested
622    function corresponding to each time the enclosing function was inlined or
623    add a VIEW_CONVERT_EXPR to each such operand for each call to the nested
624    function.  The former is not practical.  The latter would still require
625    detecting this case to know when to add the conversions.  So, for now at
626    least, we don't inline such an enclosing function.
627
628    We have to do that check recursively, so here return indicating whether
629    FNDECL has such a nested function.  ORIG_FN is the function we were
630    trying to inline to use for checking whether any argument is variably
631    modified by anything in it.
632
633    It would be better to do this in tree-inline.c so that we could give
634    the appropriate warning for why a function can't be inlined, but that's
635    too late since the nesting structure has already been flattened and
636    adding a flag just to record this fact seems a waste of a flag.  */
637
638 static bool
639 check_for_nested_with_variably_modified (tree fndecl, tree orig_fndecl)
640 {
641   struct cgraph_node *cgn = cgraph_node (fndecl);
642   tree arg;
643
644   for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested)
645     {
646       for (arg = DECL_ARGUMENTS (cgn->decl); arg; arg = TREE_CHAIN (arg))
647         if (variably_modified_type_p (TREE_TYPE (arg), 0), orig_fndecl)
648           return true;
649
650       if (check_for_nested_with_variably_modified (cgn->decl, orig_fndecl))
651         return true;
652     }
653
654   return false;
655 }
656
657 /* Construct our local datastructure describing the function nesting
658    tree rooted by CGN.  */
659
660 static struct nesting_info *
661 create_nesting_tree (struct cgraph_node *cgn)
662 {
663   struct nesting_info *info = xcalloc (1, sizeof (*info));
664   info->var_map = htab_create (7, var_map_hash, var_map_eq, free);
665   info->context = cgn->decl;
666
667   for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested)
668     {
669       struct nesting_info *sub = create_nesting_tree (cgn);
670       sub->outer = info;
671       sub->next = info->inner;
672       info->inner = sub;
673     }
674
675   /* See discussion at check_for_nested_with_variably_modified for a
676      discussion of why this has to be here.  */
677   if (check_for_nested_with_variably_modified (info->context, info->context))
678     DECL_UNINLINABLE (info->context) = true;
679
680   return info;
681 }
682
683 /* Return an expression computing the static chain for TARGET_CONTEXT
684    from INFO->CONTEXT.  Insert any necessary computations before TSI.  */
685
686 static tree
687 get_static_chain (struct nesting_info *info, tree target_context,
688                   tree_stmt_iterator *tsi)
689 {
690   struct nesting_info *i;
691   tree x;
692
693   if (info->context == target_context)
694     {
695       x = build_addr (info->frame_decl);
696     }
697   else
698     {
699       x = get_chain_decl (info);
700
701       for (i = info->outer; i->context != target_context; i = i->outer)
702         {
703           tree field = get_chain_field (i);
704
705           x = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (x)), x);
706           x = build (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
707           x = init_tmp_var (info, x, tsi);
708         }
709     }
710
711   return x;
712 }
713
714 /* Return an expression referencing FIELD from TARGET_CONTEXT's non-local
715    frame as seen from INFO->CONTEXT.  Insert any necessary computations
716    before TSI.  */
717
718 static tree
719 get_frame_field (struct nesting_info *info, tree target_context,
720                  tree field, tree_stmt_iterator *tsi)
721 {
722   struct nesting_info *i;
723   tree x;
724
725   if (info->context == target_context)
726     {
727       /* Make sure frame_decl gets created.  */
728       (void) get_frame_type (info);
729       x = info->frame_decl;
730     }
731   else
732     {
733       x = get_chain_decl (info);
734
735       for (i = info->outer; i->context != target_context; i = i->outer)
736         {
737           tree field = get_chain_field (i);
738
739           x = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (x)), x);
740           x = build (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
741           x = init_tmp_var (info, x, tsi);
742         }
743
744       x = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (x)), x);
745     }
746
747   x = build (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
748   return x;
749 }
750
751 /* Called via walk_function+walk_tree, rewrite all references to VAR
752    and PARM_DECLs that belong to outer functions.
753
754    The rewrite will involve some number of structure accesses back up
755    the static chain.  E.g. for a variable FOO up one nesting level it'll
756    be CHAIN->FOO.  For two levels it'll be CHAIN->__chain->FOO.  Further
757    indirections apply to decls for which use_pointer_in_frame is true.  */
758
759 static tree
760 convert_nonlocal_reference (tree *tp, int *walk_subtrees, void *data)
761 {
762   struct walk_stmt_info *wi = data;
763   struct nesting_info *info = wi->info;
764   tree t = *tp;
765
766   *walk_subtrees = 0;
767   switch (TREE_CODE (t))
768     {
769     case VAR_DECL:
770       /* Non-automatic variables are never processed.  */
771       if (TREE_STATIC (t) || DECL_EXTERNAL (t))
772         break;
773       /* FALLTHRU */
774
775     case PARM_DECL:
776       if (decl_function_context (t) != info->context)
777         {
778           tree target_context = decl_function_context (t);
779           struct nesting_info *i;
780           tree x;
781           wi->changed = true;
782
783           for (i = info->outer; i->context != target_context; i = i->outer)
784             continue;
785           x = lookup_field_for_decl (i, t, INSERT);
786           x = get_frame_field (info, target_context, x, &wi->tsi);
787           if (use_pointer_in_frame (t))
788             {
789               x = init_tmp_var (info, x, &wi->tsi);
790               x = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (x)), x);
791             }
792           if (wi->val_only)
793             x = init_tmp_var (info, x, &wi->tsi);
794
795           *tp = x;
796         }
797       break;
798
799     case GOTO_EXPR:
800       /* Don't walk non-local gotos for now.  */
801       if (TREE_CODE (GOTO_DESTINATION (t)) != LABEL_DECL)
802         {
803           *walk_subtrees = 1;
804           wi->val_only = true;
805         }
806       break;
807
808     case LABEL_DECL:
809       /* We're taking the address of a label from a parent function, but
810          this is not itself a non-local goto.  Mark the label such that it
811          will not be deleted, much as we would with a label address in
812          static storage.  */
813       if (decl_function_context (t) != info->context)
814         FORCED_LABEL (t) = 1;
815       break;
816
817     case ADDR_EXPR:
818       {
819         bool save_val_only = wi->val_only;
820
821         wi->changed = false;
822         wi->val_only = false;
823         walk_tree (&TREE_OPERAND (t, 0), convert_nonlocal_reference, wi, NULL);
824         wi->val_only = true;
825
826         if (wi->changed)
827           {
828             /* If we changed anything, then TREE_INVARIANT is be wrong,
829                since we're no longer directly referencing a decl.  */
830             recompute_tree_invarant_for_addr_expr (t);
831
832             /* If the callback converted the address argument in a context
833                where we only accept variables (and min_invariant, presumably),
834                then compute the address into a temporary.  */
835             if (save_val_only)
836               *tp = tsi_gimplify_val (wi->info, t, &wi->tsi);
837           }
838       }
839       break;
840
841     case REALPART_EXPR:
842     case IMAGPART_EXPR:
843     case COMPONENT_REF:
844     case ARRAY_REF:
845     case ARRAY_RANGE_REF:
846     case BIT_FIELD_REF:
847       /* Go down this entire nest and just look at the final prefix and
848          anything that describes the references.  Otherwise, we lose track
849          of whether a NOP_EXPR or VIEW_CONVERT_EXPR needs a simple value.  */
850       wi->val_only = true;
851       for (; handled_component_p (t); tp = &TREE_OPERAND (t, 0), t = *tp)
852         {
853           if (TREE_CODE (t) == COMPONENT_REF)
854             walk_tree (&TREE_OPERAND (t, 2), convert_nonlocal_reference, wi,
855                        NULL);
856           else if (TREE_CODE (t) == ARRAY_REF
857                    || TREE_CODE (t) == ARRAY_RANGE_REF)
858             {
859               walk_tree (&TREE_OPERAND (t, 1), convert_nonlocal_reference, wi,
860                          NULL);
861               walk_tree (&TREE_OPERAND (t, 2), convert_nonlocal_reference, wi,
862                          NULL);
863               walk_tree (&TREE_OPERAND (t, 3), convert_nonlocal_reference, wi,
864                          NULL);
865             }
866           else if (TREE_CODE (t) == BIT_FIELD_REF)
867             {
868               walk_tree (&TREE_OPERAND (t, 1), convert_nonlocal_reference, wi,
869                          NULL);
870               walk_tree (&TREE_OPERAND (t, 2), convert_nonlocal_reference, wi,
871                          NULL);
872             }
873         }
874       wi->val_only = false;
875       walk_tree (tp, convert_nonlocal_reference, wi, NULL);
876       break;
877
878     default:
879       if (!IS_TYPE_OR_DECL_P (t))
880         {
881           *walk_subtrees = 1;
882           wi->val_only = true;
883         }
884       break;
885     }
886
887   return NULL_TREE;
888 }
889
890 /* Called via walk_function+walk_tree, rewrite all references to VAR
891    and PARM_DECLs that were referenced by inner nested functions.
892    The rewrite will be a structure reference to the local frame variable.  */
893
894 static tree
895 convert_local_reference (tree *tp, int *walk_subtrees, void *data)
896 {
897   struct walk_stmt_info *wi = data;
898   struct nesting_info *info = wi->info;
899   tree t = *tp, field, x;
900
901   switch (TREE_CODE (t))
902     {
903     case VAR_DECL:
904       /* Non-automatic variables are never processed.  */
905       if (TREE_STATIC (t) || DECL_EXTERNAL (t))
906         break;
907       /* FALLTHRU */
908
909     case PARM_DECL:
910       if (decl_function_context (t) == info->context)
911         {
912           /* If we copied a pointer to the frame, then the original decl
913              is used unchanged in the parent function.  */
914           if (use_pointer_in_frame (t))
915             break;
916
917           /* No need to transform anything if no child references the
918              variable.  */
919           field = lookup_field_for_decl (info, t, NO_INSERT);
920           if (!field)
921             break;
922           wi->changed = true;
923
924           x = get_frame_field (info, info->context, field, &wi->tsi);
925           if (wi->val_only)
926             x = init_tmp_var (info, x, &wi->tsi);
927           *tp = x;
928         }
929       break;
930
931     case ADDR_EXPR:
932       {
933         bool save_val_only = wi->val_only;
934
935         wi->changed = false;
936         wi->val_only = false;
937         walk_tree (&TREE_OPERAND (t, 0), convert_local_reference, wi, NULL);
938         wi->val_only = save_val_only;
939
940         /* If we converted anything ... */
941         if (wi->changed)
942           {
943             /* Then the frame decl is now addressable.  */
944             TREE_ADDRESSABLE (info->frame_decl) = 1;
945             
946             recompute_tree_invarant_for_addr_expr (t);
947
948             /* If we are in a context where we only accept values, then
949                compute the address into a temporary.  */
950             if (save_val_only)
951               *tp = tsi_gimplify_val (wi->info, t, &wi->tsi);
952           }
953       }
954       break;
955
956     case REALPART_EXPR:
957     case IMAGPART_EXPR:
958     case COMPONENT_REF:
959     case ARRAY_REF:
960     case ARRAY_RANGE_REF:
961     case BIT_FIELD_REF:
962       /* Go down this entire nest and just look at the final prefix and
963          anything that describes the references.  Otherwise, we lose track
964          of whether a NOP_EXPR or VIEW_CONVERT_EXPR needs a simple value.  */
965       wi->val_only = true;
966       for (; handled_component_p (t); tp = &TREE_OPERAND (t, 0), t = *tp)
967         {
968           if (TREE_CODE (t) == COMPONENT_REF)
969             walk_tree (&TREE_OPERAND (t, 2), convert_local_reference, wi,
970                        NULL);
971           else if (TREE_CODE (t) == ARRAY_REF
972                    || TREE_CODE (t) == ARRAY_RANGE_REF)
973             {
974               walk_tree (&TREE_OPERAND (t, 1), convert_local_reference, wi,
975                          NULL);
976               walk_tree (&TREE_OPERAND (t, 2), convert_local_reference, wi,
977                          NULL);
978               walk_tree (&TREE_OPERAND (t, 3), convert_local_reference, wi,
979                          NULL);
980             }
981           else if (TREE_CODE (t) == BIT_FIELD_REF)
982             {
983               walk_tree (&TREE_OPERAND (t, 1), convert_local_reference, wi,
984                          NULL);
985               walk_tree (&TREE_OPERAND (t, 2), convert_local_reference, wi,
986                          NULL);
987             }
988         }
989       wi->val_only = false;
990       walk_tree (tp, convert_local_reference, wi, NULL);
991       break;
992
993     default:
994       if (!IS_TYPE_OR_DECL_P (t))
995         {
996           *walk_subtrees = 1;
997           wi->val_only = true;
998         }
999       break;
1000     }
1001
1002   return NULL_TREE;
1003 }
1004
1005 /* Called via walk_function+walk_tree, rewrite all GOTO_EXPRs that 
1006    reference labels from outer functions.  The rewrite will be a 
1007    call to __builtin_nonlocal_goto.  */
1008
1009 static tree
1010 convert_nl_goto_reference (tree *tp, int *walk_subtrees, void *data)
1011 {
1012   struct walk_stmt_info *wi = data;
1013   struct nesting_info *info = wi->info, *i;
1014   tree t = *tp, label, new_label, target_context, x, arg, field;
1015   struct var_map_elt *elt;
1016   void **slot;
1017
1018   *walk_subtrees = 0;
1019   if (TREE_CODE (t) != GOTO_EXPR)
1020     return NULL_TREE;
1021   label = GOTO_DESTINATION (t);
1022   if (TREE_CODE (label) != LABEL_DECL)
1023     return NULL_TREE;
1024   target_context = decl_function_context (label);
1025   if (target_context == info->context)
1026     return NULL_TREE;
1027
1028   for (i = info->outer; target_context != i->context; i = i->outer)
1029     continue;
1030
1031   /* The original user label may also be use for a normal goto, therefore
1032      we must create a new label that will actually receive the abnormal
1033      control transfer.  This new label will be marked LABEL_NONLOCAL; this
1034      mark will trigger proper behavior in the cfg, as well as cause the
1035      (hairy target-specific) non-local goto receiver code to be generated
1036      when we expand rtl.  */
1037   new_label = create_artificial_label ();
1038   DECL_NONLOCAL (new_label) = 1;
1039
1040   /* Enter this association into var_map so that we can insert the new
1041      label into the IL during a second pass.  */
1042   elt = xmalloc (sizeof (*elt));
1043   elt->old = label;
1044   elt->new = new_label;
1045   slot = htab_find_slot (i->var_map, elt, INSERT);
1046   *slot = elt;
1047   
1048   /* Build: __builtin_nl_goto(new_label, &chain->nl_goto_field).  */
1049   field = get_nl_goto_field (i);
1050   x = get_frame_field (info, target_context, field, &wi->tsi);
1051   x = build_addr (x);
1052   x = tsi_gimplify_val (info, x, &wi->tsi);
1053   arg = tree_cons (NULL, x, NULL);
1054   x = build_addr (new_label);
1055   arg = tree_cons (NULL, x, arg);
1056   x = implicit_built_in_decls[BUILT_IN_NONLOCAL_GOTO];
1057   x = build_function_call_expr (x, arg);
1058
1059   SET_EXPR_LOCUS (x, EXPR_LOCUS (tsi_stmt (wi->tsi)));
1060   *tsi_stmt_ptr (wi->tsi) = x;
1061
1062   return NULL_TREE;
1063 }
1064
1065 /* Called via walk_function+walk_tree, rewrite all LABEL_EXPRs that 
1066    are referenced via nonlocal goto from a nested function.  The rewrite
1067    will involve installing a newly generated DECL_NONLOCAL label, and
1068    (potentially) a branch around the rtl gunk that is assumed to be 
1069    attached to such a label.  */
1070
1071 static tree
1072 convert_nl_goto_receiver (tree *tp, int *walk_subtrees, void *data)
1073 {
1074   struct walk_stmt_info *wi = data;
1075   struct nesting_info *info = wi->info;
1076   tree t = *tp, label, new_label, x;
1077   struct var_map_elt *elt, dummy;
1078   tree_stmt_iterator tmp_tsi;
1079
1080   *walk_subtrees = 0;
1081   if (TREE_CODE (t) != LABEL_EXPR)
1082     return NULL_TREE;
1083   label = LABEL_EXPR_LABEL (t);
1084
1085   dummy.old = label;
1086   elt = htab_find (info->var_map, &dummy);
1087   if (!elt)
1088     return NULL_TREE;
1089   new_label = elt->new;
1090
1091   /* If there's any possibility that the previous statement falls through,
1092      then we must branch around the new non-local label.  */
1093   tmp_tsi = wi->tsi;
1094   tsi_prev (&tmp_tsi);
1095   if (tsi_end_p (tmp_tsi) || block_may_fallthru (tsi_stmt (tmp_tsi)))
1096     {
1097       x = build1 (GOTO_EXPR, void_type_node, label);
1098       tsi_link_before (&wi->tsi, x, TSI_SAME_STMT);
1099     }
1100   x = build1 (LABEL_EXPR, void_type_node, new_label);
1101   tsi_link_before (&wi->tsi, x, TSI_SAME_STMT);
1102
1103   return NULL_TREE;
1104 }
1105
1106 /* Called via walk_function+walk_tree, rewrite all references to addresses
1107    of nested functions that require the use of trampolines.  The rewrite
1108    will involve a reference a trampoline generated for the occasion.  */
1109
1110 static tree
1111 convert_tramp_reference (tree *tp, int *walk_subtrees, void *data)
1112 {
1113   struct walk_stmt_info *wi = data;
1114   struct nesting_info *info = wi->info, *i;
1115   tree t = *tp, decl, target_context, x, arg;
1116
1117   *walk_subtrees = 0;
1118   switch (TREE_CODE (t))
1119     {
1120     case ADDR_EXPR:
1121       /* Build
1122            T.1 = &CHAIN->tramp;
1123            T.2 = __builtin_adjust_trampoline (T.1);
1124            T.3 = (func_type)T.2;
1125       */
1126
1127       decl = TREE_OPERAND (t, 0);
1128       if (TREE_CODE (decl) != FUNCTION_DECL)
1129         break;
1130
1131       /* Only need to process nested functions.  */
1132       target_context = decl_function_context (decl);
1133       if (!target_context)
1134         break;
1135
1136       /* If the nested function doesn't use a static chain, then
1137          it doesn't need a trampoline.  */
1138       if (DECL_NO_STATIC_CHAIN (decl))
1139         break;
1140
1141       /* Lookup the immediate parent of the callee, as that's where
1142          we need to insert the trampoline.  */
1143       for (i = info; i->context != target_context; i = i->outer)
1144         continue;
1145       x = lookup_tramp_for_decl (i, decl, INSERT);
1146
1147       /* Compute the address of the field holding the trampoline.  */
1148       x = get_frame_field (info, target_context, x, &wi->tsi);
1149       x = build_addr (x);
1150       x = tsi_gimplify_val (info, x, &wi->tsi);
1151       arg = tree_cons (NULL, x, NULL);
1152
1153       /* Do machine-specific ugliness.  Normally this will involve
1154          computing extra alignment, but it can really be anything.  */
1155       x = implicit_built_in_decls[BUILT_IN_ADJUST_TRAMPOLINE];
1156       x = build_function_call_expr (x, arg);
1157       x = init_tmp_var (info, x, &wi->tsi);
1158
1159       /* Cast back to the proper function type.  */
1160       x = build1 (NOP_EXPR, TREE_TYPE (t), x);
1161       x = init_tmp_var (info, x, &wi->tsi);
1162
1163       *tp = x;
1164       break;
1165
1166     case CALL_EXPR:
1167       /* Only walk call arguments, lest we generate trampolines for
1168          direct calls.  */
1169       walk_tree (&TREE_OPERAND (t, 1), convert_tramp_reference, wi, NULL);
1170       break;
1171
1172     default:
1173       if (!IS_TYPE_OR_DECL_P (t))
1174         *walk_subtrees = 1;
1175       break;
1176     }
1177
1178   return NULL_TREE;
1179 }
1180
1181 /* Called via walk_function+walk_tree, rewrite all CALL_EXPRs that 
1182    reference nested functions to make sure that the static chain is
1183    set up properly for the call.  */
1184
1185 static tree
1186 convert_call_expr (tree *tp, int *walk_subtrees, void *data)
1187 {
1188   struct walk_stmt_info *wi = data;
1189   struct nesting_info *info = wi->info;
1190   tree t = *tp, decl, target_context;
1191
1192   *walk_subtrees = 0;
1193   switch (TREE_CODE (t))
1194     {
1195     case CALL_EXPR:
1196       decl = get_callee_fndecl (t);
1197       if (!decl)
1198         break;
1199       target_context = decl_function_context (decl);
1200       if (target_context && !DECL_NO_STATIC_CHAIN (decl))
1201         TREE_OPERAND (t, 2)
1202           = get_static_chain (info, target_context, &wi->tsi);
1203       break;
1204
1205     case RETURN_EXPR:
1206     case MODIFY_EXPR:
1207     case WITH_SIZE_EXPR:
1208       /* Only return modify and with_size_expr may contain calls.  */
1209       *walk_subtrees = 1;
1210       break;
1211
1212     default:
1213       break;
1214     }
1215
1216   return NULL_TREE;
1217 }
1218
1219 /* Walk the nesting tree starting with ROOT, depth first.  Convert all
1220    trampolines and call expressions.  On the way back up, determine if
1221    a nested function actually uses its static chain; if not, remember that.  */
1222
1223 static void
1224 convert_all_function_calls (struct nesting_info *root)
1225 {
1226   do
1227     {
1228       if (root->inner)
1229         convert_all_function_calls (root->inner);
1230
1231       walk_function (convert_tramp_reference, root);
1232       walk_function (convert_call_expr, root);
1233
1234       /* If the function does not use a static chain, then remember that.  */
1235       if (root->outer && !root->chain_decl && !root->chain_field)
1236         DECL_NO_STATIC_CHAIN (root->context) = 1;
1237       else
1238         gcc_assert (!DECL_NO_STATIC_CHAIN (root->context));
1239
1240       root = root->next;
1241     }
1242   while (root);
1243 }
1244
1245 /* Do "everything else" to clean up or complete state collected by the
1246    various walking passes -- lay out the types and decls, generate code
1247    to initialize the frame decl, store critical expressions in the
1248    struct function for rtl to find.  */
1249
1250 static void
1251 finalize_nesting_tree_1 (struct nesting_info *root)
1252 {
1253   tree stmt_list = NULL;
1254   tree context = root->context;
1255   struct function *sf;
1256   struct cgraph_node *node;
1257
1258   /* If we created a non-local frame type or decl, we need to lay them
1259      out at this time.  */
1260   if (root->frame_type)
1261     {
1262       layout_type (root->frame_type);
1263       layout_decl (root->frame_decl, 0);
1264     }
1265
1266   /* If any parameters were referenced non-locally, then we need to 
1267      insert a copy.  Likewise, if any variables were referenced by
1268      pointer, we need to initialize the address.  */
1269   if (root->any_parm_remapped)
1270     {
1271       tree p;
1272       for (p = DECL_ARGUMENTS (context); p ; p = TREE_CHAIN (p))
1273         {
1274           tree field, x, y;
1275
1276           field = lookup_field_for_decl (root, p, NO_INSERT);
1277           if (!field)
1278             continue;
1279
1280           if (use_pointer_in_frame (p))
1281             x = build_addr (p);
1282           else
1283             x = p;
1284
1285           y = build (COMPONENT_REF, TREE_TYPE (field),
1286                      root->frame_decl, field, NULL_TREE);
1287           x = build (MODIFY_EXPR, TREE_TYPE (field), y, x);
1288           append_to_statement_list (x, &stmt_list);
1289         }
1290     }
1291
1292   /* If a chain_field was created, then it needs to be initialized
1293      from chain_decl.  */
1294   if (root->chain_field)
1295     {
1296       tree x = build (COMPONENT_REF, TREE_TYPE (root->chain_field),
1297                       root->frame_decl, root->chain_field, NULL_TREE);
1298       x = build (MODIFY_EXPR, TREE_TYPE (x), x, get_chain_decl (root));
1299       append_to_statement_list (x, &stmt_list);
1300     }
1301
1302   /* If trampolines were created, then we need to initialize them.  */
1303   if (root->any_tramp_created)
1304     {
1305       struct nesting_info *i;
1306       for (i = root->inner; i ; i = i->next)
1307         {
1308           tree arg, x, field;
1309
1310           field = lookup_tramp_for_decl (root, i->context, NO_INSERT);
1311           if (!field)
1312             continue;
1313
1314           if (DECL_NO_STATIC_CHAIN (i->context))
1315             x = null_pointer_node;
1316           else
1317             x = build_addr (root->frame_decl);
1318           arg = tree_cons (NULL, x, NULL);
1319
1320           x = build_addr (i->context);
1321           arg = tree_cons (NULL, x, arg);
1322
1323           x = build (COMPONENT_REF, TREE_TYPE (field),
1324                      root->frame_decl, field, NULL_TREE);
1325           x = build_addr (x);
1326           arg = tree_cons (NULL, x, arg);
1327
1328           x = implicit_built_in_decls[BUILT_IN_INIT_TRAMPOLINE];
1329           x = build_function_call_expr (x, arg);
1330
1331           append_to_statement_list (x, &stmt_list);
1332         }
1333     }
1334
1335   /* If we created initialization statements, insert them.  */
1336   if (stmt_list)
1337     {
1338       annotate_all_with_locus (&stmt_list,
1339                                DECL_SOURCE_LOCATION (context));
1340       append_to_statement_list (BIND_EXPR_BODY (DECL_SAVED_TREE (context)),
1341                                 &stmt_list);
1342       BIND_EXPR_BODY (DECL_SAVED_TREE (context)) = stmt_list;
1343     }
1344
1345   /* If a chain_decl was created, then it needs to be registered with
1346      struct function so that it gets initialized from the static chain
1347      register at the beginning of the function.  */
1348   sf = DECL_STRUCT_FUNCTION (root->context);
1349   sf->static_chain_decl = root->chain_decl;
1350
1351   /* Similarly for the non-local goto save area.  */
1352   if (root->nl_goto_field)
1353     {
1354       sf->nonlocal_goto_save_area
1355         = get_frame_field (root, context, root->nl_goto_field, NULL);
1356       sf->has_nonlocal_label = 1;
1357     }
1358
1359   /* Make sure all new local variables get inserted into the
1360      proper BIND_EXPR.  */
1361   if (root->new_local_var_chain)
1362     declare_tmp_vars (root->new_local_var_chain,
1363                       DECL_SAVED_TREE (root->context));
1364
1365   /* Dump the translated tree function.  */
1366   dump_function (TDI_nested, root->context);
1367   node = cgraph_node (root->context);
1368
1369   /* For nested functions update the cgraph to reflect unnesting.
1370      We also delay finalizing of these functions up to this point.  */
1371   if (node->origin)
1372     {
1373        cgraph_unnest_node (cgraph_node (root->context));
1374        cgraph_finalize_function (root->context, true);
1375     }
1376 }
1377
1378 static void
1379 finalize_nesting_tree (struct nesting_info *root)
1380 {
1381   do
1382     {
1383       if (root->inner)
1384         finalize_nesting_tree (root->inner);
1385       finalize_nesting_tree_1 (root);
1386       root = root->next;
1387     }
1388   while (root);
1389 }
1390
1391 /* Free the data structures allocated during this pass.  */
1392
1393 static void
1394 free_nesting_tree (struct nesting_info *root)
1395 {
1396   struct nesting_info *next;
1397   do
1398     {
1399       if (root->inner)
1400         free_nesting_tree (root->inner);
1401       htab_delete (root->var_map);
1402       next = root->next;
1403       free (root);
1404       root = next;
1405     }
1406   while (root);
1407 }
1408
1409 /* Main entry point for this pass.  Process FNDECL and all of its nested
1410    subroutines and turn them into something less tightly bound.  */
1411
1412 void
1413 lower_nested_functions (tree fndecl)
1414 {
1415   struct nesting_info *root;
1416   struct cgraph_node *cgn;
1417
1418   /* If there are no nested functions, there's nothing to do.  */
1419   cgn = cgraph_node (fndecl);
1420   if (!cgn->nested)
1421     return;
1422
1423   root = create_nesting_tree (cgn);
1424   walk_all_functions (convert_nonlocal_reference, root);
1425   walk_all_functions (convert_local_reference, root);
1426   walk_all_functions (convert_nl_goto_reference, root);
1427   walk_all_functions (convert_nl_goto_receiver, root);
1428   convert_all_function_calls (root);
1429   finalize_nesting_tree (root);
1430   free_nesting_tree (root);
1431 }
1432
1433 #include "gt-tree-nested.h"