Sync usage with man page.
[netbsd-mini2440.git] / gnu / dist / gcc4 / gcc / tree-nested.c
blob0f8049ebf61a606eed9387cdd9fc4a19eed6a471
1 /* Nested function decomposition for trees.
2 Copyright (C) 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GCC.
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.
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.
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, 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA. */
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"
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.
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.
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.
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.
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. */
80 struct var_map_elt GTY(())
82 tree old;
83 tree new;
86 struct nesting_info GTY ((chain_next ("%h.next")))
88 struct nesting_info *outer;
89 struct nesting_info *inner;
90 struct nesting_info *next;
92 htab_t GTY ((param_is (struct var_map_elt))) 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;
101 bool any_parm_remapped;
102 bool any_tramp_created;
106 /* Hashing and equality functions for nesting_info->var_map. */
108 static hashval_t
109 var_map_hash (const void *x)
111 const struct var_map_elt *a = x;
112 return htab_hash_pointer (a->old);
115 static int
116 var_map_eq (const void *x, const void *y)
118 const struct var_map_elt *a = x;
119 const struct var_map_elt *b = y;
120 return a->old == b->old;
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
127 /* Like create_tmp_var, except record the variable for registration at
128 the given nesting level. */
130 static tree
131 create_tmp_var_for (struct nesting_info *info, tree type, const char *prefix)
133 tree tmp_var;
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);
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 if (TREE_CODE (type) == COMPLEX_TYPE)
147 DECL_COMPLEX_GIMPLE_REG_P (tmp_var) = 1;
149 info->new_local_var_chain = tmp_var;
151 return tmp_var;
154 /* Take the address of EXP to be used within function CONTEXT.
155 Mark it for addressability as necessary. */
157 tree
158 build_addr (tree exp, tree context)
160 tree base = exp;
161 tree save_context;
162 tree retval;
164 while (handled_component_p (base))
165 base = TREE_OPERAND (base, 0);
167 if (DECL_P (base))
168 TREE_ADDRESSABLE (base) = 1;
170 /* Building the ADDR_EXPR will compute a set of properties for
171 that ADDR_EXPR. Those properties are unfortunately context
172 specific. ie, they are dependent on CURRENT_FUNCTION_DECL.
174 Temporarily set CURRENT_FUNCTION_DECL to the desired context,
175 build the ADDR_EXPR, then restore CURRENT_FUNCTION_DECL. That
176 way the properties are for the ADDR_EXPR are computed properly. */
177 save_context = current_function_decl;
178 current_function_decl = context;
179 retval = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (exp)), exp);
180 current_function_decl = save_context;;
181 return retval;
184 /* Insert FIELD into TYPE, sorted by alignment requirements. */
186 static void
187 insert_field_into_struct (tree type, tree field)
189 tree *p;
191 DECL_CONTEXT (field) = type;
193 for (p = &TYPE_FIELDS (type); *p ; p = &TREE_CHAIN (*p))
194 if (DECL_ALIGN (field) >= DECL_ALIGN (*p))
195 break;
197 TREE_CHAIN (field) = *p;
198 *p = field;
201 /* Build or return the RECORD_TYPE that describes the frame state that is
202 shared between INFO->CONTEXT and its nested functions. This record will
203 not be complete until finalize_nesting_tree; up until that point we'll
204 be adding fields as necessary.
206 We also build the DECL that represents this frame in the function. */
208 static tree
209 get_frame_type (struct nesting_info *info)
211 tree type = info->frame_type;
212 if (!type)
214 char *name;
216 type = make_node (RECORD_TYPE);
218 name = concat ("FRAME.",
219 IDENTIFIER_POINTER (DECL_NAME (info->context)),
220 NULL);
221 TYPE_NAME (type) = get_identifier (name);
222 free (name);
224 info->frame_type = type;
225 info->frame_decl = create_tmp_var_for (info, type, "FRAME");
227 /* ??? Always make it addressable for now, since it is meant to
228 be pointed to by the static chain pointer. This pessimizes
229 when it turns out that no static chains are needed because
230 the nested functions referencing non-local variables are not
231 reachable, but the true pessimization is to create the non-
232 local frame structure in the first place. */
233 TREE_ADDRESSABLE (info->frame_decl) = 1;
235 return type;
238 /* Return true if DECL should be referenced by pointer in the non-local
239 frame structure. */
241 static bool
242 use_pointer_in_frame (tree decl)
244 if (TREE_CODE (decl) == PARM_DECL)
246 /* It's illegal to copy TREE_ADDRESSABLE, impossible to copy variable
247 sized decls, and inefficient to copy large aggregates. Don't bother
248 moving anything but scalar variables. */
249 return AGGREGATE_TYPE_P (TREE_TYPE (decl));
251 else
253 /* Variable sized types make things "interesting" in the frame. */
254 return DECL_SIZE (decl) == NULL || !TREE_CONSTANT (DECL_SIZE (decl));
258 /* Given DECL, a non-locally accessed variable, find or create a field
259 in the non-local frame structure for the given nesting context. */
261 static tree
262 lookup_field_for_decl (struct nesting_info *info, tree decl,
263 enum insert_option insert)
265 struct var_map_elt *elt, dummy;
266 void **slot;
267 tree field;
269 dummy.old = decl;
270 slot = htab_find_slot (info->var_map, &dummy, insert);
271 if (!slot)
273 gcc_assert (insert != INSERT);
274 return NULL;
276 elt = *slot;
278 if (!elt && insert == INSERT)
280 field = make_node (FIELD_DECL);
281 DECL_NAME (field) = DECL_NAME (decl);
283 if (use_pointer_in_frame (decl))
285 TREE_TYPE (field) = build_pointer_type (TREE_TYPE (decl));
286 DECL_ALIGN (field) = TYPE_ALIGN (TREE_TYPE (field));
287 DECL_NONADDRESSABLE_P (field) = 1;
289 else
291 TREE_TYPE (field) = TREE_TYPE (decl);
292 DECL_SOURCE_LOCATION (field) = DECL_SOURCE_LOCATION (decl);
293 DECL_ALIGN (field) = DECL_ALIGN (decl);
294 DECL_USER_ALIGN (field) = DECL_USER_ALIGN (decl);
295 TREE_ADDRESSABLE (field) = TREE_ADDRESSABLE (decl);
296 DECL_NONADDRESSABLE_P (field) = !TREE_ADDRESSABLE (decl);
297 TREE_THIS_VOLATILE (field) = TREE_THIS_VOLATILE (decl);
300 insert_field_into_struct (get_frame_type (info), field);
302 elt = ggc_alloc (sizeof (*elt));
303 elt->old = decl;
304 elt->new = field;
305 *slot = elt;
307 if (TREE_CODE (decl) == PARM_DECL)
308 info->any_parm_remapped = true;
310 else
311 field = elt ? elt->new : NULL;
313 return field;
316 /* Build or return the variable that holds the static chain within
317 INFO->CONTEXT. This variable may only be used within INFO->CONTEXT. */
319 static tree
320 get_chain_decl (struct nesting_info *info)
322 tree decl = info->chain_decl;
323 if (!decl)
325 tree type;
327 type = get_frame_type (info->outer);
328 type = build_pointer_type (type);
330 /* Note that this variable is *not* entered into any BIND_EXPR;
331 the construction of this variable is handled specially in
332 expand_function_start and initialize_inlined_parameters.
333 Note also that it's represented as a parameter. This is more
334 close to the truth, since the initial value does come from
335 the caller. */
336 decl = build_decl (PARM_DECL, create_tmp_var_name ("CHAIN"), type);
337 DECL_ARTIFICIAL (decl) = 1;
338 DECL_IGNORED_P (decl) = 1;
339 TREE_USED (decl) = 1;
340 DECL_CONTEXT (decl) = info->context;
341 DECL_ARG_TYPE (decl) = type;
343 /* Tell tree-inline.c that we never write to this variable, so
344 it can copy-prop the replacement value immediately. */
345 TREE_READONLY (decl) = 1;
347 info->chain_decl = decl;
349 return decl;
352 /* Build or return the field within the non-local frame state that holds
353 the static chain for INFO->CONTEXT. This is the way to walk back up
354 multiple nesting levels. */
356 static tree
357 get_chain_field (struct nesting_info *info)
359 tree field = info->chain_field;
360 if (!field)
362 tree type = build_pointer_type (get_frame_type (info->outer));
364 field = make_node (FIELD_DECL);
365 DECL_NAME (field) = get_identifier ("__chain");
366 TREE_TYPE (field) = type;
367 DECL_ALIGN (field) = TYPE_ALIGN (type);
368 DECL_NONADDRESSABLE_P (field) = 1;
370 insert_field_into_struct (get_frame_type (info), field);
372 info->chain_field = field;
374 return field;
377 /* Copy EXP into a temporary. Allocate the temporary in the context of
378 INFO and insert the initialization statement before TSI. */
380 static tree
381 init_tmp_var (struct nesting_info *info, tree exp, tree_stmt_iterator *tsi)
383 tree t, stmt;
385 t = create_tmp_var_for (info, TREE_TYPE (exp), NULL);
386 stmt = build (MODIFY_EXPR, TREE_TYPE (t), t, exp);
387 SET_EXPR_LOCUS (stmt, EXPR_LOCUS (tsi_stmt (*tsi)));
388 tsi_link_before (tsi, stmt, TSI_SAME_STMT);
390 return t;
393 /* Similarly, but only do so to force EXP to satisfy is_gimple_val. */
395 static tree
396 tsi_gimplify_val (struct nesting_info *info, tree exp, tree_stmt_iterator *tsi)
398 if (is_gimple_val (exp))
399 return exp;
400 else
401 return init_tmp_var (info, exp, tsi);
404 /* Similarly, but copy from the temporary and insert the statement
405 after the iterator. */
407 static tree
408 save_tmp_var (struct nesting_info *info, tree exp,
409 tree_stmt_iterator *tsi)
411 tree t, stmt;
413 t = create_tmp_var_for (info, TREE_TYPE (exp), NULL);
414 stmt = build (MODIFY_EXPR, TREE_TYPE (t), exp, t);
415 SET_EXPR_LOCUS (stmt, EXPR_LOCUS (tsi_stmt (*tsi)));
416 tsi_link_after (tsi, stmt, TSI_SAME_STMT);
418 return t;
421 /* Build or return the type used to represent a nested function trampoline. */
423 static GTY(()) tree trampoline_type;
425 static tree
426 get_trampoline_type (void)
428 tree record, t;
429 unsigned align, size;
431 if (trampoline_type)
432 return trampoline_type;
434 align = TRAMPOLINE_ALIGNMENT;
435 size = TRAMPOLINE_SIZE;
437 /* If we won't be able to guarantee alignment simply via TYPE_ALIGN,
438 then allocate extra space so that we can do dynamic alignment. */
439 if (align > STACK_BOUNDARY)
441 size += ((align/BITS_PER_UNIT) - 1) & -(STACK_BOUNDARY/BITS_PER_UNIT);
442 align = STACK_BOUNDARY;
445 t = build_index_type (build_int_cst (NULL_TREE, size - 1));
446 t = build_array_type (char_type_node, t);
447 t = build_decl (FIELD_DECL, get_identifier ("__data"), t);
448 DECL_ALIGN (t) = align;
449 DECL_USER_ALIGN (t) = 1;
451 record = make_node (RECORD_TYPE);
452 TYPE_NAME (record) = get_identifier ("__builtin_trampoline");
453 TYPE_FIELDS (record) = t;
454 layout_type (record);
456 return record;
459 /* Given DECL, a nested function, find or create a field in the non-local
460 frame structure for a trampoline for this function. */
462 static tree
463 lookup_tramp_for_decl (struct nesting_info *info, tree decl,
464 enum insert_option insert)
466 struct var_map_elt *elt, dummy;
467 void **slot;
468 tree field;
470 dummy.old = decl;
471 slot = htab_find_slot (info->var_map, &dummy, insert);
472 if (!slot)
474 gcc_assert (insert != INSERT);
475 return NULL;
477 elt = *slot;
479 if (!elt && insert == INSERT)
481 field = make_node (FIELD_DECL);
482 DECL_NAME (field) = DECL_NAME (decl);
483 TREE_TYPE (field) = get_trampoline_type ();
484 TREE_ADDRESSABLE (field) = 1;
486 insert_field_into_struct (get_frame_type (info), field);
488 elt = ggc_alloc (sizeof (*elt));
489 elt->old = decl;
490 elt->new = field;
491 *slot = elt;
493 info->any_tramp_created = true;
495 else
496 field = elt ? elt->new : NULL;
498 return field;
501 /* Build or return the field within the non-local frame state that holds
502 the non-local goto "jmp_buf". The buffer itself is maintained by the
503 rtl middle-end as dynamic stack space is allocated. */
505 static tree
506 get_nl_goto_field (struct nesting_info *info)
508 tree field = info->nl_goto_field;
509 if (!field)
511 unsigned size;
512 tree type;
514 /* For __builtin_nonlocal_goto, we need N words. The first is the
515 frame pointer, the rest is for the target's stack pointer save
516 area. The number of words is controlled by STACK_SAVEAREA_MODE;
517 not the best interface, but it'll do for now. */
518 if (Pmode == ptr_mode)
519 type = ptr_type_node;
520 else
521 type = lang_hooks.types.type_for_mode (Pmode, 1);
523 size = GET_MODE_SIZE (STACK_SAVEAREA_MODE (SAVE_NONLOCAL));
524 size = size / GET_MODE_SIZE (Pmode);
525 size = size + 1;
527 type = build_array_type
528 (type, build_index_type (build_int_cst (NULL_TREE, size)));
530 field = make_node (FIELD_DECL);
531 DECL_NAME (field) = get_identifier ("__nl_goto_buf");
532 TREE_TYPE (field) = type;
533 DECL_ALIGN (field) = TYPE_ALIGN (type);
534 TREE_ADDRESSABLE (field) = 1;
536 insert_field_into_struct (get_frame_type (info), field);
538 info->nl_goto_field = field;
541 return field;
544 /* Convenience routines to walk all statements of a gimple function.
546 For each statement, we invoke CALLBACK via walk_tree. The passed
547 data is a walk_stmt_info structure. Of note here is a TSI that
548 points to the current statement being walked. The VAL_ONLY flag
549 that indicates whether the *TP being examined may be replaced
550 with something that matches is_gimple_val (if true) or something
551 slightly more complicated (if false). "Something" technically
552 means the common subset of is_gimple_lvalue and is_gimple_rhs,
553 but we never try to form anything more complicated than that, so
554 we don't bother checking. */
556 struct walk_stmt_info
558 walk_tree_fn callback;
559 tree_stmt_iterator tsi;
560 struct nesting_info *info;
561 bool val_only;
562 bool is_lhs;
563 bool changed;
566 /* A subroutine of walk_function. Iterate over all sub-statements of *TP. */
568 static void
569 walk_stmts (struct walk_stmt_info *wi, tree *tp)
571 tree t = *tp;
572 if (!t)
573 return;
575 switch (TREE_CODE (t))
577 case STATEMENT_LIST:
579 tree_stmt_iterator i;
580 for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
582 wi->tsi = i;
583 walk_stmts (wi, tsi_stmt_ptr (i));
586 break;
588 case COND_EXPR:
589 walk_tree (&COND_EXPR_COND (t), wi->callback, wi, NULL);
590 walk_stmts (wi, &COND_EXPR_THEN (t));
591 walk_stmts (wi, &COND_EXPR_ELSE (t));
592 break;
593 case CATCH_EXPR:
594 walk_stmts (wi, &CATCH_BODY (t));
595 break;
596 case EH_FILTER_EXPR:
597 walk_stmts (wi, &EH_FILTER_FAILURE (t));
598 break;
599 case TRY_CATCH_EXPR:
600 case TRY_FINALLY_EXPR:
601 walk_stmts (wi, &TREE_OPERAND (t, 0));
602 walk_stmts (wi, &TREE_OPERAND (t, 1));
603 break;
604 case BIND_EXPR:
605 walk_stmts (wi, &BIND_EXPR_BODY (t));
606 break;
608 case RETURN_EXPR:
609 walk_stmts (wi, &TREE_OPERAND (t, 0));
610 break;
612 case MODIFY_EXPR:
613 /* A formal temporary lhs may use a COMPONENT_REF rhs. */
614 wi->val_only = !is_gimple_formal_tmp_var (TREE_OPERAND (t, 0));
615 walk_tree (&TREE_OPERAND (t, 1), wi->callback, wi, NULL);
617 /* If the rhs is appropriate for a memory, we may use a
618 COMPONENT_REF on the lhs. */
619 wi->val_only = !is_gimple_mem_rhs (TREE_OPERAND (t, 1));
620 wi->is_lhs = true;
621 walk_tree (&TREE_OPERAND (t, 0), wi->callback, wi, NULL);
623 wi->val_only = true;
624 wi->is_lhs = false;
625 break;
627 default:
628 wi->val_only = true;
629 walk_tree (tp, wi->callback, wi, NULL);
630 break;
634 /* Invoke CALLBACK on all statements of INFO->CONTEXT. */
636 static void
637 walk_function (walk_tree_fn callback, struct nesting_info *info)
639 struct walk_stmt_info wi;
641 memset (&wi, 0, sizeof (wi));
642 wi.callback = callback;
643 wi.info = info;
644 wi.val_only = true;
646 walk_stmts (&wi, &DECL_SAVED_TREE (info->context));
649 /* Similarly for ROOT and all functions nested underneath, depth first. */
651 static void
652 walk_all_functions (walk_tree_fn callback, struct nesting_info *root)
656 if (root->inner)
657 walk_all_functions (callback, root->inner);
658 walk_function (callback, root);
659 root = root->next;
661 while (root);
664 /* We have to check for a fairly pathological case. The operands of function
665 nested function are to be interpreted in the context of the enclosing
666 function. So if any are variably-sized, they will get remapped when the
667 enclosing function is inlined. But that remapping would also have to be
668 done in the types of the PARM_DECLs of the nested function, meaning the
669 argument types of that function will disagree with the arguments in the
670 calls to that function. So we'd either have to make a copy of the nested
671 function corresponding to each time the enclosing function was inlined or
672 add a VIEW_CONVERT_EXPR to each such operand for each call to the nested
673 function. The former is not practical. The latter would still require
674 detecting this case to know when to add the conversions. So, for now at
675 least, we don't inline such an enclosing function.
677 We have to do that check recursively, so here return indicating whether
678 FNDECL has such a nested function. ORIG_FN is the function we were
679 trying to inline to use for checking whether any argument is variably
680 modified by anything in it.
682 It would be better to do this in tree-inline.c so that we could give
683 the appropriate warning for why a function can't be inlined, but that's
684 too late since the nesting structure has already been flattened and
685 adding a flag just to record this fact seems a waste of a flag. */
687 static bool
688 check_for_nested_with_variably_modified (tree fndecl, tree orig_fndecl)
690 struct cgraph_node *cgn = cgraph_node (fndecl);
691 tree arg;
693 for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested)
695 for (arg = DECL_ARGUMENTS (cgn->decl); arg; arg = TREE_CHAIN (arg))
696 if (variably_modified_type_p (TREE_TYPE (arg), orig_fndecl))
697 return true;
699 if (check_for_nested_with_variably_modified (cgn->decl, orig_fndecl))
700 return true;
703 return false;
706 /* Construct our local datastructure describing the function nesting
707 tree rooted by CGN. */
709 static struct nesting_info *
710 create_nesting_tree (struct cgraph_node *cgn)
712 struct nesting_info *info = ggc_calloc (1, sizeof (*info));
713 info->var_map = htab_create_ggc (7, var_map_hash, var_map_eq, ggc_free);
714 info->context = cgn->decl;
716 for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested)
718 struct nesting_info *sub = create_nesting_tree (cgn);
719 sub->outer = info;
720 sub->next = info->inner;
721 info->inner = sub;
724 /* See discussion at check_for_nested_with_variably_modified for a
725 discussion of why this has to be here. */
726 if (check_for_nested_with_variably_modified (info->context, info->context))
727 DECL_UNINLINABLE (info->context) = true;
729 return info;
732 /* Return an expression computing the static chain for TARGET_CONTEXT
733 from INFO->CONTEXT. Insert any necessary computations before TSI. */
735 static tree
736 get_static_chain (struct nesting_info *info, tree target_context,
737 tree_stmt_iterator *tsi)
739 struct nesting_info *i;
740 tree x;
742 if (info->context == target_context)
744 x = build_addr (info->frame_decl, target_context);
746 else
748 x = get_chain_decl (info);
750 for (i = info->outer; i->context != target_context; i = i->outer)
752 tree field = get_chain_field (i);
754 x = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (x)), x);
755 x = build (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
756 x = init_tmp_var (info, x, tsi);
760 return x;
763 /* Return an expression referencing FIELD from TARGET_CONTEXT's non-local
764 frame as seen from INFO->CONTEXT. Insert any necessary computations
765 before TSI. */
767 static tree
768 get_frame_field (struct nesting_info *info, tree target_context,
769 tree field, tree_stmt_iterator *tsi)
771 struct nesting_info *i;
772 tree x;
774 if (info->context == target_context)
776 /* Make sure frame_decl gets created. */
777 (void) get_frame_type (info);
778 x = info->frame_decl;
780 else
782 x = get_chain_decl (info);
784 for (i = info->outer; i->context != target_context; i = i->outer)
786 tree field = get_chain_field (i);
788 x = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (x)), x);
789 x = build (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
790 x = init_tmp_var (info, x, tsi);
793 x = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (x)), x);
796 x = build (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
797 return x;
800 /* Called via walk_function+walk_tree, rewrite all references to VAR
801 and PARM_DECLs that belong to outer functions.
803 The rewrite will involve some number of structure accesses back up
804 the static chain. E.g. for a variable FOO up one nesting level it'll
805 be CHAIN->FOO. For two levels it'll be CHAIN->__chain->FOO. Further
806 indirections apply to decls for which use_pointer_in_frame is true. */
808 static tree
809 convert_nonlocal_reference (tree *tp, int *walk_subtrees, void *data)
811 struct walk_stmt_info *wi = data;
812 struct nesting_info *info = wi->info;
813 tree t = *tp;
815 *walk_subtrees = 0;
816 switch (TREE_CODE (t))
818 case VAR_DECL:
819 /* Non-automatic variables are never processed. */
820 if (TREE_STATIC (t) || DECL_EXTERNAL (t))
821 break;
822 /* FALLTHRU */
824 case PARM_DECL:
825 if (decl_function_context (t) != info->context)
827 tree target_context = decl_function_context (t);
828 struct nesting_info *i;
829 tree x;
830 wi->changed = true;
832 for (i = info->outer; i->context != target_context; i = i->outer)
833 continue;
834 x = lookup_field_for_decl (i, t, INSERT);
835 x = get_frame_field (info, target_context, x, &wi->tsi);
836 if (use_pointer_in_frame (t))
838 x = init_tmp_var (info, x, &wi->tsi);
839 x = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (x)), x);
842 if (wi->val_only)
844 if (wi->is_lhs)
845 x = save_tmp_var (info, x, &wi->tsi);
846 else
847 x = init_tmp_var (info, x, &wi->tsi);
850 *tp = x;
852 break;
854 case GOTO_EXPR:
855 /* Don't walk non-local gotos for now. */
856 if (TREE_CODE (GOTO_DESTINATION (t)) != LABEL_DECL)
858 *walk_subtrees = 1;
859 wi->val_only = true;
860 wi->is_lhs = false;
862 break;
864 case LABEL_DECL:
865 /* We're taking the address of a label from a parent function, but
866 this is not itself a non-local goto. Mark the label such that it
867 will not be deleted, much as we would with a label address in
868 static storage. */
869 if (decl_function_context (t) != info->context)
870 FORCED_LABEL (t) = 1;
871 break;
873 case ADDR_EXPR:
875 bool save_val_only = wi->val_only;
877 wi->val_only = false;
878 wi->is_lhs = false;
879 wi->changed = false;
880 walk_tree (&TREE_OPERAND (t, 0), convert_nonlocal_reference, wi, NULL);
881 wi->val_only = true;
883 if (wi->changed)
885 tree save_context;
887 /* If we changed anything, then TREE_INVARIANT is be wrong,
888 since we're no longer directly referencing a decl. */
889 save_context = current_function_decl;
890 current_function_decl = info->context;
891 recompute_tree_invarant_for_addr_expr (t);
892 current_function_decl = save_context;
894 /* If the callback converted the address argument in a context
895 where we only accept variables (and min_invariant, presumably),
896 then compute the address into a temporary. */
897 if (save_val_only)
898 *tp = tsi_gimplify_val (wi->info, t, &wi->tsi);
901 break;
903 case REALPART_EXPR:
904 case IMAGPART_EXPR:
905 case COMPONENT_REF:
906 case ARRAY_REF:
907 case ARRAY_RANGE_REF:
908 case BIT_FIELD_REF:
909 /* Go down this entire nest and just look at the final prefix and
910 anything that describes the references. Otherwise, we lose track
911 of whether a NOP_EXPR or VIEW_CONVERT_EXPR needs a simple value. */
912 wi->val_only = true;
913 wi->is_lhs = false;
914 for (; handled_component_p (t); tp = &TREE_OPERAND (t, 0), t = *tp)
916 if (TREE_CODE (t) == COMPONENT_REF)
917 walk_tree (&TREE_OPERAND (t, 2), convert_nonlocal_reference, wi,
918 NULL);
919 else if (TREE_CODE (t) == ARRAY_REF
920 || TREE_CODE (t) == ARRAY_RANGE_REF)
922 walk_tree (&TREE_OPERAND (t, 1), convert_nonlocal_reference, wi,
923 NULL);
924 walk_tree (&TREE_OPERAND (t, 2), convert_nonlocal_reference, wi,
925 NULL);
926 walk_tree (&TREE_OPERAND (t, 3), convert_nonlocal_reference, wi,
927 NULL);
929 else if (TREE_CODE (t) == BIT_FIELD_REF)
931 walk_tree (&TREE_OPERAND (t, 1), convert_nonlocal_reference, wi,
932 NULL);
933 walk_tree (&TREE_OPERAND (t, 2), convert_nonlocal_reference, wi,
934 NULL);
937 wi->val_only = false;
938 walk_tree (tp, convert_nonlocal_reference, wi, NULL);
939 break;
941 default:
942 if (!IS_TYPE_OR_DECL_P (t))
944 *walk_subtrees = 1;
945 wi->val_only = true;
946 wi->is_lhs = false;
948 break;
951 return NULL_TREE;
954 /* Called via walk_function+walk_tree, rewrite all references to VAR
955 and PARM_DECLs that were referenced by inner nested functions.
956 The rewrite will be a structure reference to the local frame variable. */
958 static tree
959 convert_local_reference (tree *tp, int *walk_subtrees, void *data)
961 struct walk_stmt_info *wi = data;
962 struct nesting_info *info = wi->info;
963 tree t = *tp, field, x;
964 bool save_val_only;
966 *walk_subtrees = 0;
967 switch (TREE_CODE (t))
969 case VAR_DECL:
970 /* Non-automatic variables are never processed. */
971 if (TREE_STATIC (t) || DECL_EXTERNAL (t))
972 break;
973 /* FALLTHRU */
975 case PARM_DECL:
976 if (decl_function_context (t) == info->context)
978 /* If we copied a pointer to the frame, then the original decl
979 is used unchanged in the parent function. */
980 if (use_pointer_in_frame (t))
981 break;
983 /* No need to transform anything if no child references the
984 variable. */
985 field = lookup_field_for_decl (info, t, NO_INSERT);
986 if (!field)
987 break;
988 wi->changed = true;
990 x = get_frame_field (info, info->context, field, &wi->tsi);
992 if (wi->val_only)
994 if (wi->is_lhs)
995 x = save_tmp_var (info, x, &wi->tsi);
996 else
997 x = init_tmp_var (info, x, &wi->tsi);
1000 *tp = x;
1002 break;
1004 case ADDR_EXPR:
1005 save_val_only = wi->val_only;
1006 wi->val_only = false;
1007 wi->is_lhs = false;
1008 wi->changed = false;
1009 walk_tree (&TREE_OPERAND (t, 0), convert_local_reference, wi, NULL);
1010 wi->val_only = save_val_only;
1012 /* If we converted anything ... */
1013 if (wi->changed)
1015 tree save_context;
1017 /* Then the frame decl is now addressable. */
1018 TREE_ADDRESSABLE (info->frame_decl) = 1;
1020 save_context = current_function_decl;
1021 current_function_decl = info->context;
1022 recompute_tree_invarant_for_addr_expr (t);
1023 current_function_decl = save_context;
1025 /* If we are in a context where we only accept values, then
1026 compute the address into a temporary. */
1027 if (save_val_only)
1028 *tp = tsi_gimplify_val (wi->info, t, &wi->tsi);
1030 break;
1032 case REALPART_EXPR:
1033 case IMAGPART_EXPR:
1034 case COMPONENT_REF:
1035 case ARRAY_REF:
1036 case ARRAY_RANGE_REF:
1037 case BIT_FIELD_REF:
1038 /* Go down this entire nest and just look at the final prefix and
1039 anything that describes the references. Otherwise, we lose track
1040 of whether a NOP_EXPR or VIEW_CONVERT_EXPR needs a simple value. */
1041 save_val_only = wi->val_only;
1042 wi->val_only = true;
1043 wi->is_lhs = false;
1044 for (; handled_component_p (t); tp = &TREE_OPERAND (t, 0), t = *tp)
1046 if (TREE_CODE (t) == COMPONENT_REF)
1047 walk_tree (&TREE_OPERAND (t, 2), convert_local_reference, wi,
1048 NULL);
1049 else if (TREE_CODE (t) == ARRAY_REF
1050 || TREE_CODE (t) == ARRAY_RANGE_REF)
1052 walk_tree (&TREE_OPERAND (t, 1), convert_local_reference, wi,
1053 NULL);
1054 walk_tree (&TREE_OPERAND (t, 2), convert_local_reference, wi,
1055 NULL);
1056 walk_tree (&TREE_OPERAND (t, 3), convert_local_reference, wi,
1057 NULL);
1059 else if (TREE_CODE (t) == BIT_FIELD_REF)
1061 walk_tree (&TREE_OPERAND (t, 1), convert_local_reference, wi,
1062 NULL);
1063 walk_tree (&TREE_OPERAND (t, 2), convert_local_reference, wi,
1064 NULL);
1067 wi->val_only = false;
1068 walk_tree (tp, convert_local_reference, wi, NULL);
1069 wi->val_only = save_val_only;
1070 break;
1072 default:
1073 if (!IS_TYPE_OR_DECL_P (t))
1075 *walk_subtrees = 1;
1076 wi->val_only = true;
1077 wi->is_lhs = false;
1079 break;
1082 return NULL_TREE;
1085 /* Called via walk_function+walk_tree, rewrite all GOTO_EXPRs that
1086 reference labels from outer functions. The rewrite will be a
1087 call to __builtin_nonlocal_goto. */
1089 static tree
1090 convert_nl_goto_reference (tree *tp, int *walk_subtrees, void *data)
1092 struct walk_stmt_info *wi = data;
1093 struct nesting_info *info = wi->info, *i;
1094 tree t = *tp, label, new_label, target_context, x, arg, field;
1095 struct var_map_elt *elt, dummy;
1096 void **slot;
1098 *walk_subtrees = 0;
1099 if (TREE_CODE (t) != GOTO_EXPR)
1100 return NULL_TREE;
1101 label = GOTO_DESTINATION (t);
1102 if (TREE_CODE (label) != LABEL_DECL)
1103 return NULL_TREE;
1104 target_context = decl_function_context (label);
1105 if (target_context == info->context)
1106 return NULL_TREE;
1108 for (i = info->outer; target_context != i->context; i = i->outer)
1109 continue;
1111 /* The original user label may also be use for a normal goto, therefore
1112 we must create a new label that will actually receive the abnormal
1113 control transfer. This new label will be marked LABEL_NONLOCAL; this
1114 mark will trigger proper behavior in the cfg, as well as cause the
1115 (hairy target-specific) non-local goto receiver code to be generated
1116 when we expand rtl. Enter this association into var_map so that we
1117 can insert the new label into the IL during a second pass. */
1118 dummy.old = label;
1119 slot = htab_find_slot (i->var_map, &dummy, INSERT);
1120 elt = *slot;
1121 if (elt == NULL)
1123 new_label = create_artificial_label ();
1124 DECL_NONLOCAL (new_label) = 1;
1126 elt = ggc_alloc (sizeof (*elt));
1127 elt->old = label;
1128 elt->new = new_label;
1129 *slot = elt;
1131 else
1132 new_label = elt->new;
1134 /* Build: __builtin_nl_goto(new_label, &chain->nl_goto_field). */
1135 field = get_nl_goto_field (i);
1136 x = get_frame_field (info, target_context, field, &wi->tsi);
1137 x = build_addr (x, target_context);
1138 x = tsi_gimplify_val (info, x, &wi->tsi);
1139 arg = tree_cons (NULL, x, NULL);
1140 x = build_addr (new_label, target_context);
1141 arg = tree_cons (NULL, x, arg);
1142 x = implicit_built_in_decls[BUILT_IN_NONLOCAL_GOTO];
1143 x = build_function_call_expr (x, arg);
1145 SET_EXPR_LOCUS (x, EXPR_LOCUS (tsi_stmt (wi->tsi)));
1146 *tsi_stmt_ptr (wi->tsi) = x;
1148 return NULL_TREE;
1151 /* Called via walk_function+walk_tree, rewrite all LABEL_EXPRs that
1152 are referenced via nonlocal goto from a nested function. The rewrite
1153 will involve installing a newly generated DECL_NONLOCAL label, and
1154 (potentially) a branch around the rtl gunk that is assumed to be
1155 attached to such a label. */
1157 static tree
1158 convert_nl_goto_receiver (tree *tp, int *walk_subtrees, void *data)
1160 struct walk_stmt_info *wi = data;
1161 struct nesting_info *info = wi->info;
1162 tree t = *tp, label, new_label, x;
1163 struct var_map_elt *elt, dummy;
1164 tree_stmt_iterator tmp_tsi;
1166 *walk_subtrees = 0;
1167 if (TREE_CODE (t) != LABEL_EXPR)
1168 return NULL_TREE;
1169 label = LABEL_EXPR_LABEL (t);
1171 dummy.old = label;
1172 elt = htab_find (info->var_map, &dummy);
1173 if (!elt)
1174 return NULL_TREE;
1175 new_label = elt->new;
1177 /* If there's any possibility that the previous statement falls through,
1178 then we must branch around the new non-local label. */
1179 tmp_tsi = wi->tsi;
1180 tsi_prev (&tmp_tsi);
1181 if (tsi_end_p (tmp_tsi) || block_may_fallthru (tsi_stmt (tmp_tsi)))
1183 x = build1 (GOTO_EXPR, void_type_node, label);
1184 tsi_link_before (&wi->tsi, x, TSI_SAME_STMT);
1186 x = build1 (LABEL_EXPR, void_type_node, new_label);
1187 tsi_link_before (&wi->tsi, x, TSI_SAME_STMT);
1189 return NULL_TREE;
1192 /* Called via walk_function+walk_tree, rewrite all references to addresses
1193 of nested functions that require the use of trampolines. The rewrite
1194 will involve a reference a trampoline generated for the occasion. */
1196 static tree
1197 convert_tramp_reference (tree *tp, int *walk_subtrees, void *data)
1199 struct walk_stmt_info *wi = data;
1200 struct nesting_info *info = wi->info, *i;
1201 tree t = *tp, decl, target_context, x, arg;
1203 *walk_subtrees = 0;
1204 switch (TREE_CODE (t))
1206 case ADDR_EXPR:
1207 /* Build
1208 T.1 = &CHAIN->tramp;
1209 T.2 = __builtin_adjust_trampoline (T.1);
1210 T.3 = (func_type)T.2;
1213 decl = TREE_OPERAND (t, 0);
1214 if (TREE_CODE (decl) != FUNCTION_DECL)
1215 break;
1217 /* Only need to process nested functions. */
1218 target_context = decl_function_context (decl);
1219 if (!target_context)
1220 break;
1222 /* If the nested function doesn't use a static chain, then
1223 it doesn't need a trampoline. */
1224 if (DECL_NO_STATIC_CHAIN (decl))
1225 break;
1227 /* Lookup the immediate parent of the callee, as that's where
1228 we need to insert the trampoline. */
1229 for (i = info; i->context != target_context; i = i->outer)
1230 continue;
1231 x = lookup_tramp_for_decl (i, decl, INSERT);
1233 /* Compute the address of the field holding the trampoline. */
1234 x = get_frame_field (info, target_context, x, &wi->tsi);
1235 x = build_addr (x, target_context);
1236 x = tsi_gimplify_val (info, x, &wi->tsi);
1237 arg = tree_cons (NULL, x, NULL);
1239 /* Do machine-specific ugliness. Normally this will involve
1240 computing extra alignment, but it can really be anything. */
1241 x = implicit_built_in_decls[BUILT_IN_ADJUST_TRAMPOLINE];
1242 x = build_function_call_expr (x, arg);
1243 x = init_tmp_var (info, x, &wi->tsi);
1245 /* Cast back to the proper function type. */
1246 x = build1 (NOP_EXPR, TREE_TYPE (t), x);
1247 x = init_tmp_var (info, x, &wi->tsi);
1249 *tp = x;
1250 break;
1252 case CALL_EXPR:
1253 /* Only walk call arguments, lest we generate trampolines for
1254 direct calls. */
1255 walk_tree (&TREE_OPERAND (t, 1), convert_tramp_reference, wi, NULL);
1256 break;
1258 default:
1259 if (!IS_TYPE_OR_DECL_P (t))
1260 *walk_subtrees = 1;
1261 break;
1264 return NULL_TREE;
1267 /* Called via walk_function+walk_tree, rewrite all CALL_EXPRs that
1268 reference nested functions to make sure that the static chain is
1269 set up properly for the call. */
1271 static tree
1272 convert_call_expr (tree *tp, int *walk_subtrees, void *data)
1274 struct walk_stmt_info *wi = data;
1275 struct nesting_info *info = wi->info;
1276 tree t = *tp, decl, target_context;
1278 *walk_subtrees = 0;
1279 switch (TREE_CODE (t))
1281 case CALL_EXPR:
1282 decl = get_callee_fndecl (t);
1283 if (!decl)
1284 break;
1285 target_context = decl_function_context (decl);
1286 if (target_context && !DECL_NO_STATIC_CHAIN (decl))
1287 TREE_OPERAND (t, 2)
1288 = get_static_chain (info, target_context, &wi->tsi);
1289 break;
1291 case RETURN_EXPR:
1292 case MODIFY_EXPR:
1293 case WITH_SIZE_EXPR:
1294 /* Only return modify and with_size_expr may contain calls. */
1295 *walk_subtrees = 1;
1296 break;
1298 default:
1299 break;
1302 return NULL_TREE;
1305 /* Walk the nesting tree starting with ROOT, depth first. Convert all
1306 trampolines and call expressions. On the way back up, determine if
1307 a nested function actually uses its static chain; if not, remember that. */
1309 static void
1310 convert_all_function_calls (struct nesting_info *root)
1314 if (root->inner)
1315 convert_all_function_calls (root->inner);
1317 walk_function (convert_tramp_reference, root);
1318 walk_function (convert_call_expr, root);
1320 /* If the function does not use a static chain, then remember that. */
1321 if (root->outer && !root->chain_decl && !root->chain_field)
1322 DECL_NO_STATIC_CHAIN (root->context) = 1;
1323 else
1324 gcc_assert (!DECL_NO_STATIC_CHAIN (root->context));
1326 root = root->next;
1328 while (root);
1331 /* Do "everything else" to clean up or complete state collected by the
1332 various walking passes -- lay out the types and decls, generate code
1333 to initialize the frame decl, store critical expressions in the
1334 struct function for rtl to find. */
1336 static void
1337 finalize_nesting_tree_1 (struct nesting_info *root)
1339 tree stmt_list = NULL;
1340 tree context = root->context;
1341 struct function *sf;
1342 struct cgraph_node *node;
1344 /* If we created a non-local frame type or decl, we need to lay them
1345 out at this time. */
1346 if (root->frame_type)
1348 /* In some cases the frame type will trigger the -Wpadded warning.
1349 This is not helpful; suppress it. */
1350 int save_warn_padded = warn_padded;
1351 warn_padded = 0;
1352 layout_type (root->frame_type);
1353 warn_padded = save_warn_padded;
1354 layout_decl (root->frame_decl, 0);
1357 /* If any parameters were referenced non-locally, then we need to
1358 insert a copy. Likewise, if any variables were referenced by
1359 pointer, we need to initialize the address. */
1360 if (root->any_parm_remapped)
1362 tree p;
1363 for (p = DECL_ARGUMENTS (context); p ; p = TREE_CHAIN (p))
1365 tree field, x, y;
1367 field = lookup_field_for_decl (root, p, NO_INSERT);
1368 if (!field)
1369 continue;
1371 if (use_pointer_in_frame (p))
1372 x = build_addr (p, context);
1373 else
1374 x = p;
1376 y = build (COMPONENT_REF, TREE_TYPE (field),
1377 root->frame_decl, field, NULL_TREE);
1378 x = build (MODIFY_EXPR, TREE_TYPE (field), y, x);
1379 append_to_statement_list (x, &stmt_list);
1383 /* If a chain_field was created, then it needs to be initialized
1384 from chain_decl. */
1385 if (root->chain_field)
1387 tree x = build (COMPONENT_REF, TREE_TYPE (root->chain_field),
1388 root->frame_decl, root->chain_field, NULL_TREE);
1389 x = build (MODIFY_EXPR, TREE_TYPE (x), x, get_chain_decl (root));
1390 append_to_statement_list (x, &stmt_list);
1393 /* If trampolines were created, then we need to initialize them. */
1394 if (root->any_tramp_created)
1396 struct nesting_info *i;
1397 for (i = root->inner; i ; i = i->next)
1399 tree arg, x, field;
1401 field = lookup_tramp_for_decl (root, i->context, NO_INSERT);
1402 if (!field)
1403 continue;
1405 if (DECL_NO_STATIC_CHAIN (i->context))
1406 x = null_pointer_node;
1407 else
1408 x = build_addr (root->frame_decl, context);
1409 arg = tree_cons (NULL, x, NULL);
1411 x = build_addr (i->context, context);
1412 arg = tree_cons (NULL, x, arg);
1414 x = build (COMPONENT_REF, TREE_TYPE (field),
1415 root->frame_decl, field, NULL_TREE);
1416 x = build_addr (x, context);
1417 arg = tree_cons (NULL, x, arg);
1419 x = implicit_built_in_decls[BUILT_IN_INIT_TRAMPOLINE];
1420 x = build_function_call_expr (x, arg);
1422 append_to_statement_list (x, &stmt_list);
1426 /* If we created initialization statements, insert them. */
1427 if (stmt_list)
1429 annotate_all_with_locus (&stmt_list,
1430 DECL_SOURCE_LOCATION (context));
1431 append_to_statement_list (BIND_EXPR_BODY (DECL_SAVED_TREE (context)),
1432 &stmt_list);
1433 BIND_EXPR_BODY (DECL_SAVED_TREE (context)) = stmt_list;
1436 /* If a chain_decl was created, then it needs to be registered with
1437 struct function so that it gets initialized from the static chain
1438 register at the beginning of the function. */
1439 sf = DECL_STRUCT_FUNCTION (root->context);
1440 sf->static_chain_decl = root->chain_decl;
1442 /* Similarly for the non-local goto save area. */
1443 if (root->nl_goto_field)
1445 sf->nonlocal_goto_save_area
1446 = get_frame_field (root, context, root->nl_goto_field, NULL);
1447 sf->has_nonlocal_label = 1;
1450 /* Make sure all new local variables get inserted into the
1451 proper BIND_EXPR. */
1452 if (root->new_local_var_chain)
1453 declare_tmp_vars (root->new_local_var_chain,
1454 DECL_SAVED_TREE (root->context));
1456 /* Dump the translated tree function. */
1457 dump_function (TDI_nested, root->context);
1458 node = cgraph_node (root->context);
1460 /* For nested functions update the cgraph to reflect unnesting.
1461 We also delay finalizing of these functions up to this point. */
1462 if (node->origin)
1464 cgraph_unnest_node (cgraph_node (root->context));
1465 cgraph_finalize_function (root->context, true);
1469 static void
1470 finalize_nesting_tree (struct nesting_info *root)
1474 if (root->inner)
1475 finalize_nesting_tree (root->inner);
1476 finalize_nesting_tree_1 (root);
1477 root = root->next;
1479 while (root);
1482 /* Free the data structures allocated during this pass. */
1484 static void
1485 free_nesting_tree (struct nesting_info *root)
1487 struct nesting_info *next;
1490 if (root->inner)
1491 free_nesting_tree (root->inner);
1492 htab_delete (root->var_map);
1493 next = root->next;
1494 ggc_free (root);
1495 root = next;
1497 while (root);
1500 static GTY(()) struct nesting_info *root;
1502 /* Main entry point for this pass. Process FNDECL and all of its nested
1503 subroutines and turn them into something less tightly bound. */
1505 void
1506 lower_nested_functions (tree fndecl)
1508 struct cgraph_node *cgn;
1510 /* If there are no nested functions, there's nothing to do. */
1511 cgn = cgraph_node (fndecl);
1512 if (!cgn->nested)
1513 return;
1515 root = create_nesting_tree (cgn);
1516 walk_all_functions (convert_nonlocal_reference, root);
1517 walk_all_functions (convert_local_reference, root);
1518 walk_all_functions (convert_nl_goto_reference, root);
1519 walk_all_functions (convert_nl_goto_receiver, root);
1520 convert_all_function_calls (root);
1521 finalize_nesting_tree (root);
1522 free_nesting_tree (root);
1523 root = NULL;
1526 #include "gt-tree-nested.h"