read-md.c: Move various state to within class rtx_reader
[official-gcc.git] / gcc / tree-nested.c
blob36b120ce570709327d26ae32b1fdeff9b89895bf
1 /* Nested function decomposition for GIMPLE.
2 Copyright (C) 2004-2016 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 3, 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 COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "backend.h"
24 #include "target.h"
25 #include "rtl.h"
26 #include "tree.h"
27 #include "gimple.h"
28 #include "memmodel.h"
29 #include "tm_p.h"
30 #include "stringpool.h"
31 #include "cgraph.h"
32 #include "fold-const.h"
33 #include "stor-layout.h"
34 #include "tree-dump.h"
35 #include "tree-inline.h"
36 #include "gimplify.h"
37 #include "gimple-iterator.h"
38 #include "gimple-walk.h"
39 #include "tree-cfg.h"
40 #include "explow.h"
41 #include "langhooks.h"
42 #include "gimple-low.h"
43 #include "gomp-constants.h"
46 /* The object of this pass is to lower the representation of a set of nested
47 functions in order to expose all of the gory details of the various
48 nonlocal references. We want to do this sooner rather than later, in
49 order to give us more freedom in emitting all of the functions in question.
51 Back in olden times, when gcc was young, we developed an insanely
52 complicated scheme whereby variables which were referenced nonlocally
53 were forced to live in the stack of the declaring function, and then
54 the nested functions magically discovered where these variables were
55 placed. In order for this scheme to function properly, it required
56 that the outer function be partially expanded, then we switch to
57 compiling the inner function, and once done with those we switch back
58 to compiling the outer function. Such delicate ordering requirements
59 makes it difficult to do whole translation unit optimizations
60 involving such functions.
62 The implementation here is much more direct. Everything that can be
63 referenced by an inner function is a member of an explicitly created
64 structure herein called the "nonlocal frame struct". The incoming
65 static chain for a nested function is a pointer to this struct in
66 the parent. In this way, we settle on known offsets from a known
67 base, and so are decoupled from the logic that places objects in the
68 function's stack frame. More importantly, we don't have to wait for
69 that to happen -- since the compilation of the inner function is no
70 longer tied to a real stack frame, the nonlocal frame struct can be
71 allocated anywhere. Which means that the outer function is now
72 inlinable.
74 Theory of operation here is very simple. Iterate over all the
75 statements in all the functions (depth first) several times,
76 allocating structures and fields on demand. In general we want to
77 examine inner functions first, so that we can avoid making changes
78 to outer functions which are unnecessary.
80 The order of the passes matters a bit, in that later passes will be
81 skipped if it is discovered that the functions don't actually interact
82 at all. That is, they're nested in the lexical sense but could have
83 been written as independent functions without change. */
86 struct nesting_info
88 struct nesting_info *outer;
89 struct nesting_info *inner;
90 struct nesting_info *next;
92 hash_map<tree, tree> *field_map;
93 hash_map<tree, tree> *var_map;
94 hash_set<tree *> *mem_refs;
95 bitmap suppress_expansion;
97 tree context;
98 tree new_local_var_chain;
99 tree debug_var_chain;
100 tree frame_type;
101 tree frame_decl;
102 tree chain_field;
103 tree chain_decl;
104 tree nl_goto_field;
106 bool any_parm_remapped;
107 bool any_tramp_created;
108 bool any_descr_created;
109 char static_chain_added;
113 /* Iterate over the nesting tree, starting with ROOT, depth first. */
115 static inline struct nesting_info *
116 iter_nestinfo_start (struct nesting_info *root)
118 while (root->inner)
119 root = root->inner;
120 return root;
123 static inline struct nesting_info *
124 iter_nestinfo_next (struct nesting_info *node)
126 if (node->next)
127 return iter_nestinfo_start (node->next);
128 return node->outer;
131 #define FOR_EACH_NEST_INFO(I, ROOT) \
132 for ((I) = iter_nestinfo_start (ROOT); (I); (I) = iter_nestinfo_next (I))
134 /* Obstack used for the bitmaps in the struct above. */
135 static struct bitmap_obstack nesting_info_bitmap_obstack;
138 /* We're working in so many different function contexts simultaneously,
139 that create_tmp_var is dangerous. Prevent mishap. */
140 #define create_tmp_var cant_use_create_tmp_var_here_dummy
142 /* Like create_tmp_var, except record the variable for registration at
143 the given nesting level. */
145 static tree
146 create_tmp_var_for (struct nesting_info *info, tree type, const char *prefix)
148 tree tmp_var;
150 /* If the type is of variable size or a type which must be created by the
151 frontend, something is wrong. Note that we explicitly allow
152 incomplete types here, since we create them ourselves here. */
153 gcc_assert (!TREE_ADDRESSABLE (type));
154 gcc_assert (!TYPE_SIZE_UNIT (type)
155 || TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST);
157 tmp_var = create_tmp_var_raw (type, prefix);
158 DECL_CONTEXT (tmp_var) = info->context;
159 DECL_CHAIN (tmp_var) = info->new_local_var_chain;
160 DECL_SEEN_IN_BIND_EXPR_P (tmp_var) = 1;
161 if (TREE_CODE (type) == COMPLEX_TYPE
162 || TREE_CODE (type) == VECTOR_TYPE)
163 DECL_GIMPLE_REG_P (tmp_var) = 1;
165 info->new_local_var_chain = tmp_var;
167 return tmp_var;
170 /* Take the address of EXP to be used within function CONTEXT.
171 Mark it for addressability as necessary. */
173 tree
174 build_addr (tree exp)
176 mark_addressable (exp);
177 return build_fold_addr_expr (exp);
180 /* Insert FIELD into TYPE, sorted by alignment requirements. */
182 void
183 insert_field_into_struct (tree type, tree field)
185 tree *p;
187 DECL_CONTEXT (field) = type;
189 for (p = &TYPE_FIELDS (type); *p ; p = &DECL_CHAIN (*p))
190 if (DECL_ALIGN (field) >= DECL_ALIGN (*p))
191 break;
193 DECL_CHAIN (field) = *p;
194 *p = field;
196 /* Set correct alignment for frame struct type. */
197 if (TYPE_ALIGN (type) < DECL_ALIGN (field))
198 SET_TYPE_ALIGN (type, DECL_ALIGN (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");
226 DECL_NONLOCAL_FRAME (info->frame_decl) = 1;
228 /* ??? Always make it addressable for now, since it is meant to
229 be pointed to by the static chain pointer. This pessimizes
230 when it turns out that no static chains are needed because
231 the nested functions referencing non-local variables are not
232 reachable, but the true pessimization is to create the non-
233 local frame structure in the first place. */
234 TREE_ADDRESSABLE (info->frame_decl) = 1;
236 return type;
239 /* Return true if DECL should be referenced by pointer in the non-local
240 frame structure. */
242 static bool
243 use_pointer_in_frame (tree decl)
245 if (TREE_CODE (decl) == PARM_DECL)
247 /* It's illegal to copy TREE_ADDRESSABLE, impossible to copy variable
248 sized decls, and inefficient to copy large aggregates. Don't bother
249 moving anything but scalar variables. */
250 return AGGREGATE_TYPE_P (TREE_TYPE (decl));
252 else
254 /* Variable sized types make things "interesting" in the frame. */
255 return DECL_SIZE (decl) == NULL || !TREE_CONSTANT (DECL_SIZE (decl));
259 /* Given DECL, a non-locally accessed variable, find or create a field
260 in the non-local frame structure for the given nesting context. */
262 static tree
263 lookup_field_for_decl (struct nesting_info *info, tree decl,
264 enum insert_option insert)
266 if (insert == NO_INSERT)
268 tree *slot = info->field_map->get (decl);
269 return slot ? *slot : NULL_TREE;
272 tree *slot = &info->field_map->get_or_insert (decl);
273 if (!*slot)
275 tree field = make_node (FIELD_DECL);
276 DECL_NAME (field) = DECL_NAME (decl);
278 if (use_pointer_in_frame (decl))
280 TREE_TYPE (field) = build_pointer_type (TREE_TYPE (decl));
281 SET_DECL_ALIGN (field, TYPE_ALIGN (TREE_TYPE (field)));
282 DECL_NONADDRESSABLE_P (field) = 1;
284 else
286 TREE_TYPE (field) = TREE_TYPE (decl);
287 DECL_SOURCE_LOCATION (field) = DECL_SOURCE_LOCATION (decl);
288 SET_DECL_ALIGN (field, DECL_ALIGN (decl));
289 DECL_USER_ALIGN (field) = DECL_USER_ALIGN (decl);
290 TREE_ADDRESSABLE (field) = TREE_ADDRESSABLE (decl);
291 DECL_NONADDRESSABLE_P (field) = !TREE_ADDRESSABLE (decl);
292 TREE_THIS_VOLATILE (field) = TREE_THIS_VOLATILE (decl);
295 insert_field_into_struct (get_frame_type (info), field);
296 *slot = field;
298 if (TREE_CODE (decl) == PARM_DECL)
299 info->any_parm_remapped = true;
302 return *slot;
305 /* Build or return the variable that holds the static chain within
306 INFO->CONTEXT. This variable may only be used within INFO->CONTEXT. */
308 static tree
309 get_chain_decl (struct nesting_info *info)
311 tree decl = info->chain_decl;
313 if (!decl)
315 tree type;
317 type = get_frame_type (info->outer);
318 type = build_pointer_type (type);
320 /* Note that this variable is *not* entered into any BIND_EXPR;
321 the construction of this variable is handled specially in
322 expand_function_start and initialize_inlined_parameters.
323 Note also that it's represented as a parameter. This is more
324 close to the truth, since the initial value does come from
325 the caller. */
326 decl = build_decl (DECL_SOURCE_LOCATION (info->context),
327 PARM_DECL, create_tmp_var_name ("CHAIN"), type);
328 DECL_ARTIFICIAL (decl) = 1;
329 DECL_IGNORED_P (decl) = 1;
330 TREE_USED (decl) = 1;
331 DECL_CONTEXT (decl) = info->context;
332 DECL_ARG_TYPE (decl) = type;
334 /* Tell tree-inline.c that we never write to this variable, so
335 it can copy-prop the replacement value immediately. */
336 TREE_READONLY (decl) = 1;
338 info->chain_decl = decl;
340 if (dump_file
341 && (dump_flags & TDF_DETAILS)
342 && !DECL_STATIC_CHAIN (info->context))
343 fprintf (dump_file, "Setting static-chain for %s\n",
344 lang_hooks.decl_printable_name (info->context, 2));
346 DECL_STATIC_CHAIN (info->context) = 1;
348 return decl;
351 /* Build or return the field within the non-local frame state that holds
352 the static chain for INFO->CONTEXT. This is the way to walk back up
353 multiple nesting levels. */
355 static tree
356 get_chain_field (struct nesting_info *info)
358 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 SET_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 if (dump_file
375 && (dump_flags & TDF_DETAILS)
376 && !DECL_STATIC_CHAIN (info->context))
377 fprintf (dump_file, "Setting static-chain for %s\n",
378 lang_hooks.decl_printable_name (info->context, 2));
380 DECL_STATIC_CHAIN (info->context) = 1;
382 return field;
385 /* Initialize a new temporary with the GIMPLE_CALL STMT. */
387 static tree
388 init_tmp_var_with_call (struct nesting_info *info, gimple_stmt_iterator *gsi,
389 gcall *call)
391 tree t;
393 t = create_tmp_var_for (info, gimple_call_return_type (call), NULL);
394 gimple_call_set_lhs (call, t);
395 if (! gsi_end_p (*gsi))
396 gimple_set_location (call, gimple_location (gsi_stmt (*gsi)));
397 gsi_insert_before (gsi, call, GSI_SAME_STMT);
399 return t;
403 /* Copy EXP into a temporary. Allocate the temporary in the context of
404 INFO and insert the initialization statement before GSI. */
406 static tree
407 init_tmp_var (struct nesting_info *info, tree exp, gimple_stmt_iterator *gsi)
409 tree t;
410 gimple *stmt;
412 t = create_tmp_var_for (info, TREE_TYPE (exp), NULL);
413 stmt = gimple_build_assign (t, exp);
414 if (! gsi_end_p (*gsi))
415 gimple_set_location (stmt, gimple_location (gsi_stmt (*gsi)));
416 gsi_insert_before_without_update (gsi, stmt, GSI_SAME_STMT);
418 return t;
422 /* Similarly, but only do so to force EXP to satisfy is_gimple_val. */
424 static tree
425 gsi_gimplify_val (struct nesting_info *info, tree exp,
426 gimple_stmt_iterator *gsi)
428 if (is_gimple_val (exp))
429 return exp;
430 else
431 return init_tmp_var (info, exp, gsi);
434 /* Similarly, but copy from the temporary and insert the statement
435 after the iterator. */
437 static tree
438 save_tmp_var (struct nesting_info *info, tree exp, gimple_stmt_iterator *gsi)
440 tree t;
441 gimple *stmt;
443 t = create_tmp_var_for (info, TREE_TYPE (exp), NULL);
444 stmt = gimple_build_assign (exp, t);
445 if (! gsi_end_p (*gsi))
446 gimple_set_location (stmt, gimple_location (gsi_stmt (*gsi)));
447 gsi_insert_after_without_update (gsi, stmt, GSI_SAME_STMT);
449 return t;
452 /* Build or return the type used to represent a nested function trampoline. */
454 static GTY(()) tree trampoline_type;
456 static tree
457 get_trampoline_type (struct nesting_info *info)
459 unsigned align, size;
460 tree t;
462 if (trampoline_type)
463 return trampoline_type;
465 align = TRAMPOLINE_ALIGNMENT;
466 size = TRAMPOLINE_SIZE;
468 /* If we won't be able to guarantee alignment simply via TYPE_ALIGN,
469 then allocate extra space so that we can do dynamic alignment. */
470 if (align > STACK_BOUNDARY)
472 size += ((align/BITS_PER_UNIT) - 1) & -(STACK_BOUNDARY/BITS_PER_UNIT);
473 align = STACK_BOUNDARY;
476 t = build_index_type (size_int (size - 1));
477 t = build_array_type (char_type_node, t);
478 t = build_decl (DECL_SOURCE_LOCATION (info->context),
479 FIELD_DECL, get_identifier ("__data"), t);
480 SET_DECL_ALIGN (t, align);
481 DECL_USER_ALIGN (t) = 1;
483 trampoline_type = make_node (RECORD_TYPE);
484 TYPE_NAME (trampoline_type) = get_identifier ("__builtin_trampoline");
485 TYPE_FIELDS (trampoline_type) = t;
486 layout_type (trampoline_type);
487 DECL_CONTEXT (t) = trampoline_type;
489 return trampoline_type;
492 /* Build or return the type used to represent a nested function descriptor. */
494 static GTY(()) tree descriptor_type;
496 static tree
497 get_descriptor_type (struct nesting_info *info)
499 tree t;
501 if (descriptor_type)
502 return descriptor_type;
504 t = build_index_type (integer_one_node);
505 t = build_array_type (ptr_type_node, t);
506 t = build_decl (DECL_SOURCE_LOCATION (info->context),
507 FIELD_DECL, get_identifier ("__data"), t);
509 descriptor_type = make_node (RECORD_TYPE);
510 TYPE_NAME (descriptor_type) = get_identifier ("__builtin_descriptor");
511 TYPE_FIELDS (descriptor_type) = t;
512 layout_type (descriptor_type);
513 DECL_CONTEXT (t) = descriptor_type;
515 return descriptor_type;
518 /* Given DECL, a nested function, find or create an element in the
519 var map for this function. */
521 static tree
522 lookup_element_for_decl (struct nesting_info *info, tree decl,
523 enum insert_option insert)
525 if (insert == NO_INSERT)
527 tree *slot = info->var_map->get (decl);
528 return slot ? *slot : NULL_TREE;
531 tree *slot = &info->var_map->get_or_insert (decl);
532 if (!*slot)
533 *slot = build_tree_list (NULL_TREE, NULL_TREE);
535 return (tree) *slot;
538 /* Given DECL, a nested function, create a field in the non-local
539 frame structure for this function. */
541 static tree
542 create_field_for_decl (struct nesting_info *info, tree decl, tree type)
544 tree field = make_node (FIELD_DECL);
545 DECL_NAME (field) = DECL_NAME (decl);
546 TREE_TYPE (field) = type;
547 TREE_ADDRESSABLE (field) = 1;
548 insert_field_into_struct (get_frame_type (info), field);
549 return field;
552 /* Given DECL, a nested function, find or create a field in the non-local
553 frame structure for a trampoline for this function. */
555 static tree
556 lookup_tramp_for_decl (struct nesting_info *info, tree decl,
557 enum insert_option insert)
559 tree elt, field;
561 elt = lookup_element_for_decl (info, decl, insert);
562 if (!elt)
563 return NULL_TREE;
565 field = TREE_PURPOSE (elt);
567 if (!field && insert == INSERT)
569 field = create_field_for_decl (info, decl, get_trampoline_type (info));
570 TREE_PURPOSE (elt) = field;
571 info->any_tramp_created = true;
574 return field;
577 /* Given DECL, a nested function, find or create a field in the non-local
578 frame structure for a descriptor for this function. */
580 static tree
581 lookup_descr_for_decl (struct nesting_info *info, tree decl,
582 enum insert_option insert)
584 tree elt, field;
586 elt = lookup_element_for_decl (info, decl, insert);
587 if (!elt)
588 return NULL_TREE;
590 field = TREE_VALUE (elt);
592 if (!field && insert == INSERT)
594 field = create_field_for_decl (info, decl, get_descriptor_type (info));
595 TREE_VALUE (elt) = field;
596 info->any_descr_created = true;
599 return field;
602 /* Build or return the field within the non-local frame state that holds
603 the non-local goto "jmp_buf". The buffer itself is maintained by the
604 rtl middle-end as dynamic stack space is allocated. */
606 static tree
607 get_nl_goto_field (struct nesting_info *info)
609 tree field = info->nl_goto_field;
610 if (!field)
612 unsigned size;
613 tree type;
615 /* For __builtin_nonlocal_goto, we need N words. The first is the
616 frame pointer, the rest is for the target's stack pointer save
617 area. The number of words is controlled by STACK_SAVEAREA_MODE;
618 not the best interface, but it'll do for now. */
619 if (Pmode == ptr_mode)
620 type = ptr_type_node;
621 else
622 type = lang_hooks.types.type_for_mode (Pmode, 1);
624 size = GET_MODE_SIZE (STACK_SAVEAREA_MODE (SAVE_NONLOCAL));
625 size = size / GET_MODE_SIZE (Pmode);
626 size = size + 1;
628 type = build_array_type
629 (type, build_index_type (size_int (size)));
631 field = make_node (FIELD_DECL);
632 DECL_NAME (field) = get_identifier ("__nl_goto_buf");
633 TREE_TYPE (field) = type;
634 SET_DECL_ALIGN (field, TYPE_ALIGN (type));
635 TREE_ADDRESSABLE (field) = 1;
637 insert_field_into_struct (get_frame_type (info), field);
639 info->nl_goto_field = field;
642 return field;
645 /* Invoke CALLBACK on all statements of GIMPLE sequence *PSEQ. */
647 static void
648 walk_body (walk_stmt_fn callback_stmt, walk_tree_fn callback_op,
649 struct nesting_info *info, gimple_seq *pseq)
651 struct walk_stmt_info wi;
653 memset (&wi, 0, sizeof (wi));
654 wi.info = info;
655 wi.val_only = true;
656 walk_gimple_seq_mod (pseq, callback_stmt, callback_op, &wi);
660 /* Invoke CALLBACK_STMT/CALLBACK_OP on all statements of INFO->CONTEXT. */
662 static inline void
663 walk_function (walk_stmt_fn callback_stmt, walk_tree_fn callback_op,
664 struct nesting_info *info)
666 gimple_seq body = gimple_body (info->context);
667 walk_body (callback_stmt, callback_op, info, &body);
668 gimple_set_body (info->context, body);
671 /* Invoke CALLBACK on a GIMPLE_OMP_FOR's init, cond, incr and pre-body. */
673 static void
674 walk_gimple_omp_for (gomp_for *for_stmt,
675 walk_stmt_fn callback_stmt, walk_tree_fn callback_op,
676 struct nesting_info *info)
678 struct walk_stmt_info wi;
679 gimple_seq seq;
680 tree t;
681 size_t i;
683 walk_body (callback_stmt, callback_op, info, gimple_omp_for_pre_body_ptr (for_stmt));
685 seq = NULL;
686 memset (&wi, 0, sizeof (wi));
687 wi.info = info;
688 wi.gsi = gsi_last (seq);
690 for (i = 0; i < gimple_omp_for_collapse (for_stmt); i++)
692 wi.val_only = false;
693 walk_tree (gimple_omp_for_index_ptr (for_stmt, i), callback_op,
694 &wi, NULL);
695 wi.val_only = true;
696 wi.is_lhs = false;
697 walk_tree (gimple_omp_for_initial_ptr (for_stmt, i), callback_op,
698 &wi, NULL);
700 wi.val_only = true;
701 wi.is_lhs = false;
702 walk_tree (gimple_omp_for_final_ptr (for_stmt, i), callback_op,
703 &wi, NULL);
705 t = gimple_omp_for_incr (for_stmt, i);
706 gcc_assert (BINARY_CLASS_P (t));
707 wi.val_only = false;
708 walk_tree (&TREE_OPERAND (t, 0), callback_op, &wi, NULL);
709 wi.val_only = true;
710 wi.is_lhs = false;
711 walk_tree (&TREE_OPERAND (t, 1), callback_op, &wi, NULL);
714 seq = gsi_seq (wi.gsi);
715 if (!gimple_seq_empty_p (seq))
717 gimple_seq pre_body = gimple_omp_for_pre_body (for_stmt);
718 annotate_all_with_location (seq, gimple_location (for_stmt));
719 gimple_seq_add_seq (&pre_body, seq);
720 gimple_omp_for_set_pre_body (for_stmt, pre_body);
724 /* Similarly for ROOT and all functions nested underneath, depth first. */
726 static void
727 walk_all_functions (walk_stmt_fn callback_stmt, walk_tree_fn callback_op,
728 struct nesting_info *root)
730 struct nesting_info *n;
731 FOR_EACH_NEST_INFO (n, root)
732 walk_function (callback_stmt, callback_op, n);
736 /* We have to check for a fairly pathological case. The operands of function
737 nested function are to be interpreted in the context of the enclosing
738 function. So if any are variably-sized, they will get remapped when the
739 enclosing function is inlined. But that remapping would also have to be
740 done in the types of the PARM_DECLs of the nested function, meaning the
741 argument types of that function will disagree with the arguments in the
742 calls to that function. So we'd either have to make a copy of the nested
743 function corresponding to each time the enclosing function was inlined or
744 add a VIEW_CONVERT_EXPR to each such operand for each call to the nested
745 function. The former is not practical. The latter would still require
746 detecting this case to know when to add the conversions. So, for now at
747 least, we don't inline such an enclosing function.
749 We have to do that check recursively, so here return indicating whether
750 FNDECL has such a nested function. ORIG_FN is the function we were
751 trying to inline to use for checking whether any argument is variably
752 modified by anything in it.
754 It would be better to do this in tree-inline.c so that we could give
755 the appropriate warning for why a function can't be inlined, but that's
756 too late since the nesting structure has already been flattened and
757 adding a flag just to record this fact seems a waste of a flag. */
759 static bool
760 check_for_nested_with_variably_modified (tree fndecl, tree orig_fndecl)
762 struct cgraph_node *cgn = cgraph_node::get (fndecl);
763 tree arg;
765 for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested)
767 for (arg = DECL_ARGUMENTS (cgn->decl); arg; arg = DECL_CHAIN (arg))
768 if (variably_modified_type_p (TREE_TYPE (arg), orig_fndecl))
769 return true;
771 if (check_for_nested_with_variably_modified (cgn->decl,
772 orig_fndecl))
773 return true;
776 return false;
779 /* Construct our local datastructure describing the function nesting
780 tree rooted by CGN. */
782 static struct nesting_info *
783 create_nesting_tree (struct cgraph_node *cgn)
785 struct nesting_info *info = XCNEW (struct nesting_info);
786 info->field_map = new hash_map<tree, tree>;
787 info->var_map = new hash_map<tree, tree>;
788 info->mem_refs = new hash_set<tree *>;
789 info->suppress_expansion = BITMAP_ALLOC (&nesting_info_bitmap_obstack);
790 info->context = cgn->decl;
792 for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested)
794 struct nesting_info *sub = create_nesting_tree (cgn);
795 sub->outer = info;
796 sub->next = info->inner;
797 info->inner = sub;
800 /* See discussion at check_for_nested_with_variably_modified for a
801 discussion of why this has to be here. */
802 if (check_for_nested_with_variably_modified (info->context, info->context))
803 DECL_UNINLINABLE (info->context) = true;
805 return info;
808 /* Return an expression computing the static chain for TARGET_CONTEXT
809 from INFO->CONTEXT. Insert any necessary computations before TSI. */
811 static tree
812 get_static_chain (struct nesting_info *info, tree target_context,
813 gimple_stmt_iterator *gsi)
815 struct nesting_info *i;
816 tree x;
818 if (info->context == target_context)
820 x = build_addr (info->frame_decl);
821 info->static_chain_added |= 1;
823 else
825 x = get_chain_decl (info);
826 info->static_chain_added |= 2;
828 for (i = info->outer; i->context != target_context; i = i->outer)
830 tree field = get_chain_field (i);
832 x = build_simple_mem_ref (x);
833 x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
834 x = init_tmp_var (info, x, gsi);
838 return x;
842 /* Return an expression referencing FIELD from TARGET_CONTEXT's non-local
843 frame as seen from INFO->CONTEXT. Insert any necessary computations
844 before GSI. */
846 static tree
847 get_frame_field (struct nesting_info *info, tree target_context,
848 tree field, gimple_stmt_iterator *gsi)
850 struct nesting_info *i;
851 tree x;
853 if (info->context == target_context)
855 /* Make sure frame_decl gets created. */
856 (void) get_frame_type (info);
857 x = info->frame_decl;
858 info->static_chain_added |= 1;
860 else
862 x = get_chain_decl (info);
863 info->static_chain_added |= 2;
865 for (i = info->outer; i->context != target_context; i = i->outer)
867 tree field = get_chain_field (i);
869 x = build_simple_mem_ref (x);
870 x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
871 x = init_tmp_var (info, x, gsi);
874 x = build_simple_mem_ref (x);
877 x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
878 return x;
881 static void note_nonlocal_vla_type (struct nesting_info *info, tree type);
883 /* A subroutine of convert_nonlocal_reference_op. Create a local variable
884 in the nested function with DECL_VALUE_EXPR set to reference the true
885 variable in the parent function. This is used both for debug info
886 and in OMP lowering. */
888 static tree
889 get_nonlocal_debug_decl (struct nesting_info *info, tree decl)
891 tree target_context;
892 struct nesting_info *i;
893 tree x, field, new_decl;
895 tree *slot = &info->var_map->get_or_insert (decl);
897 if (*slot)
898 return *slot;
900 target_context = decl_function_context (decl);
902 /* A copy of the code in get_frame_field, but without the temporaries. */
903 if (info->context == target_context)
905 /* Make sure frame_decl gets created. */
906 (void) get_frame_type (info);
907 x = info->frame_decl;
908 i = info;
909 info->static_chain_added |= 1;
911 else
913 x = get_chain_decl (info);
914 info->static_chain_added |= 2;
915 for (i = info->outer; i->context != target_context; i = i->outer)
917 field = get_chain_field (i);
918 x = build_simple_mem_ref (x);
919 x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
921 x = build_simple_mem_ref (x);
924 field = lookup_field_for_decl (i, decl, INSERT);
925 x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
926 if (use_pointer_in_frame (decl))
927 x = build_simple_mem_ref (x);
929 /* ??? We should be remapping types as well, surely. */
930 new_decl = build_decl (DECL_SOURCE_LOCATION (decl),
931 VAR_DECL, DECL_NAME (decl), TREE_TYPE (decl));
932 DECL_CONTEXT (new_decl) = info->context;
933 DECL_ARTIFICIAL (new_decl) = DECL_ARTIFICIAL (decl);
934 DECL_IGNORED_P (new_decl) = DECL_IGNORED_P (decl);
935 TREE_THIS_VOLATILE (new_decl) = TREE_THIS_VOLATILE (decl);
936 TREE_SIDE_EFFECTS (new_decl) = TREE_SIDE_EFFECTS (decl);
937 TREE_READONLY (new_decl) = TREE_READONLY (decl);
938 TREE_ADDRESSABLE (new_decl) = TREE_ADDRESSABLE (decl);
939 DECL_SEEN_IN_BIND_EXPR_P (new_decl) = 1;
940 if ((TREE_CODE (decl) == PARM_DECL
941 || TREE_CODE (decl) == RESULT_DECL
942 || VAR_P (decl))
943 && DECL_BY_REFERENCE (decl))
944 DECL_BY_REFERENCE (new_decl) = 1;
946 SET_DECL_VALUE_EXPR (new_decl, x);
947 DECL_HAS_VALUE_EXPR_P (new_decl) = 1;
949 *slot = new_decl;
950 DECL_CHAIN (new_decl) = info->debug_var_chain;
951 info->debug_var_chain = new_decl;
953 if (!optimize
954 && info->context != target_context
955 && variably_modified_type_p (TREE_TYPE (decl), NULL))
956 note_nonlocal_vla_type (info, TREE_TYPE (decl));
958 return new_decl;
962 /* Callback for walk_gimple_stmt, rewrite all references to VAR
963 and PARM_DECLs that belong to outer functions.
965 The rewrite will involve some number of structure accesses back up
966 the static chain. E.g. for a variable FOO up one nesting level it'll
967 be CHAIN->FOO. For two levels it'll be CHAIN->__chain->FOO. Further
968 indirections apply to decls for which use_pointer_in_frame is true. */
970 static tree
971 convert_nonlocal_reference_op (tree *tp, int *walk_subtrees, void *data)
973 struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
974 struct nesting_info *const info = (struct nesting_info *) wi->info;
975 tree t = *tp;
977 *walk_subtrees = 0;
978 switch (TREE_CODE (t))
980 case VAR_DECL:
981 /* Non-automatic variables are never processed. */
982 if (TREE_STATIC (t) || DECL_EXTERNAL (t))
983 break;
984 /* FALLTHRU */
986 case PARM_DECL:
987 if (decl_function_context (t) != info->context)
989 tree x;
990 wi->changed = true;
992 x = get_nonlocal_debug_decl (info, t);
993 if (!bitmap_bit_p (info->suppress_expansion, DECL_UID (t)))
995 tree target_context = decl_function_context (t);
996 struct nesting_info *i;
997 for (i = info->outer; i->context != target_context; i = i->outer)
998 continue;
999 x = lookup_field_for_decl (i, t, INSERT);
1000 x = get_frame_field (info, target_context, x, &wi->gsi);
1001 if (use_pointer_in_frame (t))
1003 x = init_tmp_var (info, x, &wi->gsi);
1004 x = build_simple_mem_ref (x);
1008 if (wi->val_only)
1010 if (wi->is_lhs)
1011 x = save_tmp_var (info, x, &wi->gsi);
1012 else
1013 x = init_tmp_var (info, x, &wi->gsi);
1016 *tp = x;
1018 break;
1020 case LABEL_DECL:
1021 /* We're taking the address of a label from a parent function, but
1022 this is not itself a non-local goto. Mark the label such that it
1023 will not be deleted, much as we would with a label address in
1024 static storage. */
1025 if (decl_function_context (t) != info->context)
1026 FORCED_LABEL (t) = 1;
1027 break;
1029 case ADDR_EXPR:
1031 bool save_val_only = wi->val_only;
1033 wi->val_only = false;
1034 wi->is_lhs = false;
1035 wi->changed = false;
1036 walk_tree (&TREE_OPERAND (t, 0), convert_nonlocal_reference_op, wi, 0);
1037 wi->val_only = true;
1039 if (wi->changed)
1041 tree save_context;
1043 /* If we changed anything, we might no longer be directly
1044 referencing a decl. */
1045 save_context = current_function_decl;
1046 current_function_decl = info->context;
1047 recompute_tree_invariant_for_addr_expr (t);
1048 current_function_decl = save_context;
1050 /* If the callback converted the address argument in a context
1051 where we only accept variables (and min_invariant, presumably),
1052 then compute the address into a temporary. */
1053 if (save_val_only)
1054 *tp = gsi_gimplify_val ((struct nesting_info *) wi->info,
1055 t, &wi->gsi);
1058 break;
1060 case REALPART_EXPR:
1061 case IMAGPART_EXPR:
1062 case COMPONENT_REF:
1063 case ARRAY_REF:
1064 case ARRAY_RANGE_REF:
1065 case BIT_FIELD_REF:
1066 /* Go down this entire nest and just look at the final prefix and
1067 anything that describes the references. Otherwise, we lose track
1068 of whether a NOP_EXPR or VIEW_CONVERT_EXPR needs a simple value. */
1069 wi->val_only = true;
1070 wi->is_lhs = false;
1071 for (; handled_component_p (t); tp = &TREE_OPERAND (t, 0), t = *tp)
1073 if (TREE_CODE (t) == COMPONENT_REF)
1074 walk_tree (&TREE_OPERAND (t, 2), convert_nonlocal_reference_op, wi,
1075 NULL);
1076 else if (TREE_CODE (t) == ARRAY_REF
1077 || TREE_CODE (t) == ARRAY_RANGE_REF)
1079 walk_tree (&TREE_OPERAND (t, 1), convert_nonlocal_reference_op,
1080 wi, NULL);
1081 walk_tree (&TREE_OPERAND (t, 2), convert_nonlocal_reference_op,
1082 wi, NULL);
1083 walk_tree (&TREE_OPERAND (t, 3), convert_nonlocal_reference_op,
1084 wi, NULL);
1087 wi->val_only = false;
1088 walk_tree (tp, convert_nonlocal_reference_op, wi, NULL);
1089 break;
1091 case VIEW_CONVERT_EXPR:
1092 /* Just request to look at the subtrees, leaving val_only and lhs
1093 untouched. This might actually be for !val_only + lhs, in which
1094 case we don't want to force a replacement by a temporary. */
1095 *walk_subtrees = 1;
1096 break;
1098 default:
1099 if (!IS_TYPE_OR_DECL_P (t))
1101 *walk_subtrees = 1;
1102 wi->val_only = true;
1103 wi->is_lhs = false;
1105 break;
1108 return NULL_TREE;
1111 static tree convert_nonlocal_reference_stmt (gimple_stmt_iterator *, bool *,
1112 struct walk_stmt_info *);
1114 /* Helper for convert_nonlocal_references, rewrite all references to VAR
1115 and PARM_DECLs that belong to outer functions. */
1117 static bool
1118 convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
1120 struct nesting_info *const info = (struct nesting_info *) wi->info;
1121 bool need_chain = false, need_stmts = false;
1122 tree clause, decl;
1123 int dummy;
1124 bitmap new_suppress;
1126 new_suppress = BITMAP_GGC_ALLOC ();
1127 bitmap_copy (new_suppress, info->suppress_expansion);
1129 for (clause = *pclauses; clause ; clause = OMP_CLAUSE_CHAIN (clause))
1131 switch (OMP_CLAUSE_CODE (clause))
1133 case OMP_CLAUSE_REDUCTION:
1134 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
1135 need_stmts = true;
1136 goto do_decl_clause;
1138 case OMP_CLAUSE_LASTPRIVATE:
1139 if (OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (clause))
1140 need_stmts = true;
1141 goto do_decl_clause;
1143 case OMP_CLAUSE_LINEAR:
1144 if (OMP_CLAUSE_LINEAR_GIMPLE_SEQ (clause))
1145 need_stmts = true;
1146 wi->val_only = true;
1147 wi->is_lhs = false;
1148 convert_nonlocal_reference_op (&OMP_CLAUSE_LINEAR_STEP (clause),
1149 &dummy, wi);
1150 goto do_decl_clause;
1152 case OMP_CLAUSE_PRIVATE:
1153 case OMP_CLAUSE_FIRSTPRIVATE:
1154 case OMP_CLAUSE_COPYPRIVATE:
1155 case OMP_CLAUSE_SHARED:
1156 case OMP_CLAUSE_TO_DECLARE:
1157 case OMP_CLAUSE_LINK:
1158 case OMP_CLAUSE_USE_DEVICE_PTR:
1159 case OMP_CLAUSE_IS_DEVICE_PTR:
1160 do_decl_clause:
1161 decl = OMP_CLAUSE_DECL (clause);
1162 if (VAR_P (decl)
1163 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
1164 break;
1165 if (decl_function_context (decl) != info->context)
1167 if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_SHARED)
1168 OMP_CLAUSE_SHARED_READONLY (clause) = 0;
1169 bitmap_set_bit (new_suppress, DECL_UID (decl));
1170 OMP_CLAUSE_DECL (clause) = get_nonlocal_debug_decl (info, decl);
1171 if (OMP_CLAUSE_CODE (clause) != OMP_CLAUSE_PRIVATE)
1172 need_chain = true;
1174 break;
1176 case OMP_CLAUSE_SCHEDULE:
1177 if (OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clause) == NULL)
1178 break;
1179 /* FALLTHRU */
1180 case OMP_CLAUSE_FINAL:
1181 case OMP_CLAUSE_IF:
1182 case OMP_CLAUSE_NUM_THREADS:
1183 case OMP_CLAUSE_DEPEND:
1184 case OMP_CLAUSE_DEVICE:
1185 case OMP_CLAUSE_NUM_TEAMS:
1186 case OMP_CLAUSE_THREAD_LIMIT:
1187 case OMP_CLAUSE_SAFELEN:
1188 case OMP_CLAUSE_SIMDLEN:
1189 case OMP_CLAUSE_PRIORITY:
1190 case OMP_CLAUSE_GRAINSIZE:
1191 case OMP_CLAUSE_NUM_TASKS:
1192 case OMP_CLAUSE_HINT:
1193 case OMP_CLAUSE__CILK_FOR_COUNT_:
1194 case OMP_CLAUSE_NUM_GANGS:
1195 case OMP_CLAUSE_NUM_WORKERS:
1196 case OMP_CLAUSE_VECTOR_LENGTH:
1197 case OMP_CLAUSE_GANG:
1198 case OMP_CLAUSE_WORKER:
1199 case OMP_CLAUSE_VECTOR:
1200 case OMP_CLAUSE_ASYNC:
1201 case OMP_CLAUSE_WAIT:
1202 /* Several OpenACC clauses have optional arguments. Check if they
1203 are present. */
1204 if (OMP_CLAUSE_OPERAND (clause, 0))
1206 wi->val_only = true;
1207 wi->is_lhs = false;
1208 convert_nonlocal_reference_op (&OMP_CLAUSE_OPERAND (clause, 0),
1209 &dummy, wi);
1212 /* The gang clause accepts two arguments. */
1213 if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_GANG
1214 && OMP_CLAUSE_GANG_STATIC_EXPR (clause))
1216 wi->val_only = true;
1217 wi->is_lhs = false;
1218 convert_nonlocal_reference_op
1219 (&OMP_CLAUSE_GANG_STATIC_EXPR (clause), &dummy, wi);
1221 break;
1223 case OMP_CLAUSE_DIST_SCHEDULE:
1224 if (OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (clause) != NULL)
1226 wi->val_only = true;
1227 wi->is_lhs = false;
1228 convert_nonlocal_reference_op (&OMP_CLAUSE_OPERAND (clause, 0),
1229 &dummy, wi);
1231 break;
1233 case OMP_CLAUSE_MAP:
1234 case OMP_CLAUSE_TO:
1235 case OMP_CLAUSE_FROM:
1236 if (OMP_CLAUSE_SIZE (clause))
1238 wi->val_only = true;
1239 wi->is_lhs = false;
1240 convert_nonlocal_reference_op (&OMP_CLAUSE_SIZE (clause),
1241 &dummy, wi);
1243 if (DECL_P (OMP_CLAUSE_DECL (clause)))
1244 goto do_decl_clause;
1245 wi->val_only = true;
1246 wi->is_lhs = false;
1247 walk_tree (&OMP_CLAUSE_DECL (clause), convert_nonlocal_reference_op,
1248 wi, NULL);
1249 break;
1251 case OMP_CLAUSE_ALIGNED:
1252 if (OMP_CLAUSE_ALIGNED_ALIGNMENT (clause))
1254 wi->val_only = true;
1255 wi->is_lhs = false;
1256 convert_nonlocal_reference_op
1257 (&OMP_CLAUSE_ALIGNED_ALIGNMENT (clause), &dummy, wi);
1259 /* Like do_decl_clause, but don't add any suppression. */
1260 decl = OMP_CLAUSE_DECL (clause);
1261 if (VAR_P (decl)
1262 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
1263 break;
1264 if (decl_function_context (decl) != info->context)
1266 OMP_CLAUSE_DECL (clause) = get_nonlocal_debug_decl (info, decl);
1267 if (OMP_CLAUSE_CODE (clause) != OMP_CLAUSE_PRIVATE)
1268 need_chain = true;
1270 break;
1272 case OMP_CLAUSE_NOWAIT:
1273 case OMP_CLAUSE_ORDERED:
1274 case OMP_CLAUSE_DEFAULT:
1275 case OMP_CLAUSE_COPYIN:
1276 case OMP_CLAUSE_COLLAPSE:
1277 case OMP_CLAUSE_UNTIED:
1278 case OMP_CLAUSE_MERGEABLE:
1279 case OMP_CLAUSE_PROC_BIND:
1280 case OMP_CLAUSE_NOGROUP:
1281 case OMP_CLAUSE_THREADS:
1282 case OMP_CLAUSE_SIMD:
1283 case OMP_CLAUSE_DEFAULTMAP:
1284 case OMP_CLAUSE_SEQ:
1285 case OMP_CLAUSE_INDEPENDENT:
1286 case OMP_CLAUSE_AUTO:
1287 break;
1289 /* OpenACC tile clauses are discarded during gimplification. */
1290 case OMP_CLAUSE_TILE:
1291 /* The following clause belongs to the OpenACC cache directive, which
1292 is discarded during gimplification. */
1293 case OMP_CLAUSE__CACHE_:
1294 /* The following clauses are only allowed in the OpenMP declare simd
1295 directive, so not seen here. */
1296 case OMP_CLAUSE_UNIFORM:
1297 case OMP_CLAUSE_INBRANCH:
1298 case OMP_CLAUSE_NOTINBRANCH:
1299 /* The following clauses are only allowed on OpenMP cancel and
1300 cancellation point directives, which at this point have already
1301 been lowered into a function call. */
1302 case OMP_CLAUSE_FOR:
1303 case OMP_CLAUSE_PARALLEL:
1304 case OMP_CLAUSE_SECTIONS:
1305 case OMP_CLAUSE_TASKGROUP:
1306 /* The following clauses are only added during OMP lowering; nested
1307 function decomposition happens before that. */
1308 case OMP_CLAUSE__LOOPTEMP_:
1309 case OMP_CLAUSE__SIMDUID_:
1310 case OMP_CLAUSE__GRIDDIM_:
1311 /* Anything else. */
1312 default:
1313 gcc_unreachable ();
1317 info->suppress_expansion = new_suppress;
1319 if (need_stmts)
1320 for (clause = *pclauses; clause ; clause = OMP_CLAUSE_CHAIN (clause))
1321 switch (OMP_CLAUSE_CODE (clause))
1323 case OMP_CLAUSE_REDUCTION:
1324 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
1326 tree old_context
1327 = DECL_CONTEXT (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause));
1328 DECL_CONTEXT (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
1329 = info->context;
1330 if (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
1331 DECL_CONTEXT (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
1332 = info->context;
1333 walk_body (convert_nonlocal_reference_stmt,
1334 convert_nonlocal_reference_op, info,
1335 &OMP_CLAUSE_REDUCTION_GIMPLE_INIT (clause));
1336 walk_body (convert_nonlocal_reference_stmt,
1337 convert_nonlocal_reference_op, info,
1338 &OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (clause));
1339 DECL_CONTEXT (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
1340 = old_context;
1341 if (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
1342 DECL_CONTEXT (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
1343 = old_context;
1345 break;
1347 case OMP_CLAUSE_LASTPRIVATE:
1348 walk_body (convert_nonlocal_reference_stmt,
1349 convert_nonlocal_reference_op, info,
1350 &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (clause));
1351 break;
1353 case OMP_CLAUSE_LINEAR:
1354 walk_body (convert_nonlocal_reference_stmt,
1355 convert_nonlocal_reference_op, info,
1356 &OMP_CLAUSE_LINEAR_GIMPLE_SEQ (clause));
1357 break;
1359 default:
1360 break;
1363 return need_chain;
1366 /* Create nonlocal debug decls for nonlocal VLA array bounds. */
1368 static void
1369 note_nonlocal_vla_type (struct nesting_info *info, tree type)
1371 while (POINTER_TYPE_P (type) && !TYPE_NAME (type))
1372 type = TREE_TYPE (type);
1374 if (TYPE_NAME (type)
1375 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1376 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1377 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
1379 while (POINTER_TYPE_P (type)
1380 || TREE_CODE (type) == VECTOR_TYPE
1381 || TREE_CODE (type) == FUNCTION_TYPE
1382 || TREE_CODE (type) == METHOD_TYPE)
1383 type = TREE_TYPE (type);
1385 if (TREE_CODE (type) == ARRAY_TYPE)
1387 tree domain, t;
1389 note_nonlocal_vla_type (info, TREE_TYPE (type));
1390 domain = TYPE_DOMAIN (type);
1391 if (domain)
1393 t = TYPE_MIN_VALUE (domain);
1394 if (t && (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
1395 && decl_function_context (t) != info->context)
1396 get_nonlocal_debug_decl (info, t);
1397 t = TYPE_MAX_VALUE (domain);
1398 if (t && (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
1399 && decl_function_context (t) != info->context)
1400 get_nonlocal_debug_decl (info, t);
1405 /* Create nonlocal debug decls for nonlocal VLA array bounds for VLAs
1406 in BLOCK. */
1408 static void
1409 note_nonlocal_block_vlas (struct nesting_info *info, tree block)
1411 tree var;
1413 for (var = BLOCK_VARS (block); var; var = DECL_CHAIN (var))
1414 if (VAR_P (var)
1415 && variably_modified_type_p (TREE_TYPE (var), NULL)
1416 && DECL_HAS_VALUE_EXPR_P (var)
1417 && decl_function_context (var) != info->context)
1418 note_nonlocal_vla_type (info, TREE_TYPE (var));
1421 /* Callback for walk_gimple_stmt. Rewrite all references to VAR and
1422 PARM_DECLs that belong to outer functions. This handles statements
1423 that are not handled via the standard recursion done in
1424 walk_gimple_stmt. STMT is the statement to examine, DATA is as in
1425 convert_nonlocal_reference_op. Set *HANDLED_OPS_P to true if all the
1426 operands of STMT have been handled by this function. */
1428 static tree
1429 convert_nonlocal_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
1430 struct walk_stmt_info *wi)
1432 struct nesting_info *info = (struct nesting_info *) wi->info;
1433 tree save_local_var_chain;
1434 bitmap save_suppress;
1435 gimple *stmt = gsi_stmt (*gsi);
1437 switch (gimple_code (stmt))
1439 case GIMPLE_GOTO:
1440 /* Don't walk non-local gotos for now. */
1441 if (TREE_CODE (gimple_goto_dest (stmt)) != LABEL_DECL)
1443 wi->val_only = true;
1444 wi->is_lhs = false;
1445 *handled_ops_p = false;
1446 return NULL_TREE;
1448 break;
1450 case GIMPLE_OMP_PARALLEL:
1451 case GIMPLE_OMP_TASK:
1452 save_suppress = info->suppress_expansion;
1453 if (convert_nonlocal_omp_clauses (gimple_omp_taskreg_clauses_ptr (stmt),
1454 wi))
1456 tree c, decl;
1457 decl = get_chain_decl (info);
1458 c = build_omp_clause (gimple_location (stmt),
1459 OMP_CLAUSE_FIRSTPRIVATE);
1460 OMP_CLAUSE_DECL (c) = decl;
1461 OMP_CLAUSE_CHAIN (c) = gimple_omp_taskreg_clauses (stmt);
1462 gimple_omp_taskreg_set_clauses (stmt, c);
1465 save_local_var_chain = info->new_local_var_chain;
1466 info->new_local_var_chain = NULL;
1468 walk_body (convert_nonlocal_reference_stmt, convert_nonlocal_reference_op,
1469 info, gimple_omp_body_ptr (stmt));
1471 if (info->new_local_var_chain)
1472 declare_vars (info->new_local_var_chain,
1473 gimple_seq_first_stmt (gimple_omp_body (stmt)),
1474 false);
1475 info->new_local_var_chain = save_local_var_chain;
1476 info->suppress_expansion = save_suppress;
1477 break;
1479 case GIMPLE_OMP_FOR:
1480 save_suppress = info->suppress_expansion;
1481 convert_nonlocal_omp_clauses (gimple_omp_for_clauses_ptr (stmt), wi);
1482 walk_gimple_omp_for (as_a <gomp_for *> (stmt),
1483 convert_nonlocal_reference_stmt,
1484 convert_nonlocal_reference_op, info);
1485 walk_body (convert_nonlocal_reference_stmt,
1486 convert_nonlocal_reference_op, info, gimple_omp_body_ptr (stmt));
1487 info->suppress_expansion = save_suppress;
1488 break;
1490 case GIMPLE_OMP_SECTIONS:
1491 save_suppress = info->suppress_expansion;
1492 convert_nonlocal_omp_clauses (gimple_omp_sections_clauses_ptr (stmt), wi);
1493 walk_body (convert_nonlocal_reference_stmt, convert_nonlocal_reference_op,
1494 info, gimple_omp_body_ptr (stmt));
1495 info->suppress_expansion = save_suppress;
1496 break;
1498 case GIMPLE_OMP_SINGLE:
1499 save_suppress = info->suppress_expansion;
1500 convert_nonlocal_omp_clauses (gimple_omp_single_clauses_ptr (stmt), wi);
1501 walk_body (convert_nonlocal_reference_stmt, convert_nonlocal_reference_op,
1502 info, gimple_omp_body_ptr (stmt));
1503 info->suppress_expansion = save_suppress;
1504 break;
1506 case GIMPLE_OMP_TARGET:
1507 if (!is_gimple_omp_offloaded (stmt))
1509 save_suppress = info->suppress_expansion;
1510 convert_nonlocal_omp_clauses (gimple_omp_target_clauses_ptr (stmt),
1511 wi);
1512 info->suppress_expansion = save_suppress;
1513 walk_body (convert_nonlocal_reference_stmt,
1514 convert_nonlocal_reference_op, info,
1515 gimple_omp_body_ptr (stmt));
1516 break;
1518 save_suppress = info->suppress_expansion;
1519 if (convert_nonlocal_omp_clauses (gimple_omp_target_clauses_ptr (stmt),
1520 wi))
1522 tree c, decl;
1523 decl = get_chain_decl (info);
1524 c = build_omp_clause (gimple_location (stmt), OMP_CLAUSE_MAP);
1525 OMP_CLAUSE_DECL (c) = decl;
1526 OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
1527 OMP_CLAUSE_SIZE (c) = DECL_SIZE_UNIT (decl);
1528 OMP_CLAUSE_CHAIN (c) = gimple_omp_target_clauses (stmt);
1529 gimple_omp_target_set_clauses (as_a <gomp_target *> (stmt), c);
1532 save_local_var_chain = info->new_local_var_chain;
1533 info->new_local_var_chain = NULL;
1535 walk_body (convert_nonlocal_reference_stmt, convert_nonlocal_reference_op,
1536 info, gimple_omp_body_ptr (stmt));
1538 if (info->new_local_var_chain)
1539 declare_vars (info->new_local_var_chain,
1540 gimple_seq_first_stmt (gimple_omp_body (stmt)),
1541 false);
1542 info->new_local_var_chain = save_local_var_chain;
1543 info->suppress_expansion = save_suppress;
1544 break;
1546 case GIMPLE_OMP_TEAMS:
1547 save_suppress = info->suppress_expansion;
1548 convert_nonlocal_omp_clauses (gimple_omp_teams_clauses_ptr (stmt), wi);
1549 walk_body (convert_nonlocal_reference_stmt, convert_nonlocal_reference_op,
1550 info, gimple_omp_body_ptr (stmt));
1551 info->suppress_expansion = save_suppress;
1552 break;
1554 case GIMPLE_OMP_SECTION:
1555 case GIMPLE_OMP_MASTER:
1556 case GIMPLE_OMP_TASKGROUP:
1557 case GIMPLE_OMP_ORDERED:
1558 walk_body (convert_nonlocal_reference_stmt, convert_nonlocal_reference_op,
1559 info, gimple_omp_body_ptr (stmt));
1560 break;
1562 case GIMPLE_BIND:
1564 gbind *bind_stmt = as_a <gbind *> (stmt);
1565 if (!optimize && gimple_bind_block (bind_stmt))
1566 note_nonlocal_block_vlas (info, gimple_bind_block (bind_stmt));
1568 for (tree var = gimple_bind_vars (bind_stmt); var; var = DECL_CHAIN (var))
1569 if (TREE_CODE (var) == NAMELIST_DECL)
1571 /* Adjust decls mentioned in NAMELIST_DECL. */
1572 tree decls = NAMELIST_DECL_ASSOCIATED_DECL (var);
1573 tree decl;
1574 unsigned int i;
1576 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (decls), i, decl)
1578 if (VAR_P (decl)
1579 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
1580 continue;
1581 if (decl_function_context (decl) != info->context)
1582 CONSTRUCTOR_ELT (decls, i)->value
1583 = get_nonlocal_debug_decl (info, decl);
1587 *handled_ops_p = false;
1588 return NULL_TREE;
1590 case GIMPLE_COND:
1591 wi->val_only = true;
1592 wi->is_lhs = false;
1593 *handled_ops_p = false;
1594 return NULL_TREE;
1596 default:
1597 /* For every other statement that we are not interested in
1598 handling here, let the walker traverse the operands. */
1599 *handled_ops_p = false;
1600 return NULL_TREE;
1603 /* We have handled all of STMT operands, no need to traverse the operands. */
1604 *handled_ops_p = true;
1605 return NULL_TREE;
1609 /* A subroutine of convert_local_reference. Create a local variable
1610 in the parent function with DECL_VALUE_EXPR set to reference the
1611 field in FRAME. This is used both for debug info and in OMP
1612 lowering. */
1614 static tree
1615 get_local_debug_decl (struct nesting_info *info, tree decl, tree field)
1617 tree x, new_decl;
1619 tree *slot = &info->var_map->get_or_insert (decl);
1620 if (*slot)
1621 return *slot;
1623 /* Make sure frame_decl gets created. */
1624 (void) get_frame_type (info);
1625 x = info->frame_decl;
1626 x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
1628 new_decl = build_decl (DECL_SOURCE_LOCATION (decl),
1629 VAR_DECL, DECL_NAME (decl), TREE_TYPE (decl));
1630 DECL_CONTEXT (new_decl) = info->context;
1631 DECL_ARTIFICIAL (new_decl) = DECL_ARTIFICIAL (decl);
1632 DECL_IGNORED_P (new_decl) = DECL_IGNORED_P (decl);
1633 TREE_THIS_VOLATILE (new_decl) = TREE_THIS_VOLATILE (decl);
1634 TREE_SIDE_EFFECTS (new_decl) = TREE_SIDE_EFFECTS (decl);
1635 TREE_READONLY (new_decl) = TREE_READONLY (decl);
1636 TREE_ADDRESSABLE (new_decl) = TREE_ADDRESSABLE (decl);
1637 DECL_SEEN_IN_BIND_EXPR_P (new_decl) = 1;
1638 if ((TREE_CODE (decl) == PARM_DECL
1639 || TREE_CODE (decl) == RESULT_DECL
1640 || VAR_P (decl))
1641 && DECL_BY_REFERENCE (decl))
1642 DECL_BY_REFERENCE (new_decl) = 1;
1644 SET_DECL_VALUE_EXPR (new_decl, x);
1645 DECL_HAS_VALUE_EXPR_P (new_decl) = 1;
1646 *slot = new_decl;
1648 DECL_CHAIN (new_decl) = info->debug_var_chain;
1649 info->debug_var_chain = new_decl;
1651 /* Do not emit debug info twice. */
1652 DECL_IGNORED_P (decl) = 1;
1654 return new_decl;
1658 /* Called via walk_function+walk_gimple_stmt, rewrite all references to VAR
1659 and PARM_DECLs that were referenced by inner nested functions.
1660 The rewrite will be a structure reference to the local frame variable. */
1662 static bool convert_local_omp_clauses (tree *, struct walk_stmt_info *);
1664 static tree
1665 convert_local_reference_op (tree *tp, int *walk_subtrees, void *data)
1667 struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
1668 struct nesting_info *const info = (struct nesting_info *) wi->info;
1669 tree t = *tp, field, x;
1670 bool save_val_only;
1672 *walk_subtrees = 0;
1673 switch (TREE_CODE (t))
1675 case VAR_DECL:
1676 /* Non-automatic variables are never processed. */
1677 if (TREE_STATIC (t) || DECL_EXTERNAL (t))
1678 break;
1679 /* FALLTHRU */
1681 case PARM_DECL:
1682 if (decl_function_context (t) == info->context)
1684 /* If we copied a pointer to the frame, then the original decl
1685 is used unchanged in the parent function. */
1686 if (use_pointer_in_frame (t))
1687 break;
1689 /* No need to transform anything if no child references the
1690 variable. */
1691 field = lookup_field_for_decl (info, t, NO_INSERT);
1692 if (!field)
1693 break;
1694 wi->changed = true;
1696 x = get_local_debug_decl (info, t, field);
1697 if (!bitmap_bit_p (info->suppress_expansion, DECL_UID (t)))
1698 x = get_frame_field (info, info->context, field, &wi->gsi);
1700 if (wi->val_only)
1702 if (wi->is_lhs)
1703 x = save_tmp_var (info, x, &wi->gsi);
1704 else
1705 x = init_tmp_var (info, x, &wi->gsi);
1708 *tp = x;
1710 break;
1712 case ADDR_EXPR:
1713 save_val_only = wi->val_only;
1714 wi->val_only = false;
1715 wi->is_lhs = false;
1716 wi->changed = false;
1717 walk_tree (&TREE_OPERAND (t, 0), convert_local_reference_op, wi, NULL);
1718 wi->val_only = save_val_only;
1720 /* If we converted anything ... */
1721 if (wi->changed)
1723 tree save_context;
1725 /* Then the frame decl is now addressable. */
1726 TREE_ADDRESSABLE (info->frame_decl) = 1;
1728 save_context = current_function_decl;
1729 current_function_decl = info->context;
1730 recompute_tree_invariant_for_addr_expr (t);
1731 current_function_decl = save_context;
1733 /* If we are in a context where we only accept values, then
1734 compute the address into a temporary. */
1735 if (save_val_only)
1736 *tp = gsi_gimplify_val ((struct nesting_info *) wi->info,
1737 t, &wi->gsi);
1739 break;
1741 case REALPART_EXPR:
1742 case IMAGPART_EXPR:
1743 case COMPONENT_REF:
1744 case ARRAY_REF:
1745 case ARRAY_RANGE_REF:
1746 case BIT_FIELD_REF:
1747 /* Go down this entire nest and just look at the final prefix and
1748 anything that describes the references. Otherwise, we lose track
1749 of whether a NOP_EXPR or VIEW_CONVERT_EXPR needs a simple value. */
1750 save_val_only = wi->val_only;
1751 wi->val_only = true;
1752 wi->is_lhs = false;
1753 for (; handled_component_p (t); tp = &TREE_OPERAND (t, 0), t = *tp)
1755 if (TREE_CODE (t) == COMPONENT_REF)
1756 walk_tree (&TREE_OPERAND (t, 2), convert_local_reference_op, wi,
1757 NULL);
1758 else if (TREE_CODE (t) == ARRAY_REF
1759 || TREE_CODE (t) == ARRAY_RANGE_REF)
1761 walk_tree (&TREE_OPERAND (t, 1), convert_local_reference_op, wi,
1762 NULL);
1763 walk_tree (&TREE_OPERAND (t, 2), convert_local_reference_op, wi,
1764 NULL);
1765 walk_tree (&TREE_OPERAND (t, 3), convert_local_reference_op, wi,
1766 NULL);
1769 wi->val_only = false;
1770 walk_tree (tp, convert_local_reference_op, wi, NULL);
1771 wi->val_only = save_val_only;
1772 break;
1774 case MEM_REF:
1775 save_val_only = wi->val_only;
1776 wi->val_only = true;
1777 wi->is_lhs = false;
1778 walk_tree (&TREE_OPERAND (t, 0), convert_local_reference_op,
1779 wi, NULL);
1780 /* We need to re-fold the MEM_REF as component references as
1781 part of a ADDR_EXPR address are not allowed. But we cannot
1782 fold here, as the chain record type is not yet finalized. */
1783 if (TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR
1784 && !DECL_P (TREE_OPERAND (TREE_OPERAND (t, 0), 0)))
1785 info->mem_refs->add (tp);
1786 wi->val_only = save_val_only;
1787 break;
1789 case VIEW_CONVERT_EXPR:
1790 /* Just request to look at the subtrees, leaving val_only and lhs
1791 untouched. This might actually be for !val_only + lhs, in which
1792 case we don't want to force a replacement by a temporary. */
1793 *walk_subtrees = 1;
1794 break;
1796 default:
1797 if (!IS_TYPE_OR_DECL_P (t))
1799 *walk_subtrees = 1;
1800 wi->val_only = true;
1801 wi->is_lhs = false;
1803 break;
1806 return NULL_TREE;
1809 static tree convert_local_reference_stmt (gimple_stmt_iterator *, bool *,
1810 struct walk_stmt_info *);
1812 /* Helper for convert_local_reference. Convert all the references in
1813 the chain of clauses at *PCLAUSES. WI is as in convert_local_reference. */
1815 static bool
1816 convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
1818 struct nesting_info *const info = (struct nesting_info *) wi->info;
1819 bool need_frame = false, need_stmts = false;
1820 tree clause, decl;
1821 int dummy;
1822 bitmap new_suppress;
1824 new_suppress = BITMAP_GGC_ALLOC ();
1825 bitmap_copy (new_suppress, info->suppress_expansion);
1827 for (clause = *pclauses; clause ; clause = OMP_CLAUSE_CHAIN (clause))
1829 switch (OMP_CLAUSE_CODE (clause))
1831 case OMP_CLAUSE_REDUCTION:
1832 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
1833 need_stmts = true;
1834 goto do_decl_clause;
1836 case OMP_CLAUSE_LASTPRIVATE:
1837 if (OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (clause))
1838 need_stmts = true;
1839 goto do_decl_clause;
1841 case OMP_CLAUSE_LINEAR:
1842 if (OMP_CLAUSE_LINEAR_GIMPLE_SEQ (clause))
1843 need_stmts = true;
1844 wi->val_only = true;
1845 wi->is_lhs = false;
1846 convert_local_reference_op (&OMP_CLAUSE_LINEAR_STEP (clause), &dummy,
1847 wi);
1848 goto do_decl_clause;
1850 case OMP_CLAUSE_PRIVATE:
1851 case OMP_CLAUSE_FIRSTPRIVATE:
1852 case OMP_CLAUSE_COPYPRIVATE:
1853 case OMP_CLAUSE_SHARED:
1854 case OMP_CLAUSE_TO_DECLARE:
1855 case OMP_CLAUSE_LINK:
1856 case OMP_CLAUSE_USE_DEVICE_PTR:
1857 case OMP_CLAUSE_IS_DEVICE_PTR:
1858 do_decl_clause:
1859 decl = OMP_CLAUSE_DECL (clause);
1860 if (VAR_P (decl)
1861 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
1862 break;
1863 if (decl_function_context (decl) == info->context
1864 && !use_pointer_in_frame (decl))
1866 tree field = lookup_field_for_decl (info, decl, NO_INSERT);
1867 if (field)
1869 if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_SHARED)
1870 OMP_CLAUSE_SHARED_READONLY (clause) = 0;
1871 bitmap_set_bit (new_suppress, DECL_UID (decl));
1872 OMP_CLAUSE_DECL (clause)
1873 = get_local_debug_decl (info, decl, field);
1874 need_frame = true;
1877 break;
1879 case OMP_CLAUSE_SCHEDULE:
1880 if (OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clause) == NULL)
1881 break;
1882 /* FALLTHRU */
1883 case OMP_CLAUSE_FINAL:
1884 case OMP_CLAUSE_IF:
1885 case OMP_CLAUSE_NUM_THREADS:
1886 case OMP_CLAUSE_DEPEND:
1887 case OMP_CLAUSE_DEVICE:
1888 case OMP_CLAUSE_NUM_TEAMS:
1889 case OMP_CLAUSE_THREAD_LIMIT:
1890 case OMP_CLAUSE_SAFELEN:
1891 case OMP_CLAUSE_SIMDLEN:
1892 case OMP_CLAUSE_PRIORITY:
1893 case OMP_CLAUSE_GRAINSIZE:
1894 case OMP_CLAUSE_NUM_TASKS:
1895 case OMP_CLAUSE_HINT:
1896 case OMP_CLAUSE__CILK_FOR_COUNT_:
1897 case OMP_CLAUSE_NUM_GANGS:
1898 case OMP_CLAUSE_NUM_WORKERS:
1899 case OMP_CLAUSE_VECTOR_LENGTH:
1900 case OMP_CLAUSE_GANG:
1901 case OMP_CLAUSE_WORKER:
1902 case OMP_CLAUSE_VECTOR:
1903 case OMP_CLAUSE_ASYNC:
1904 case OMP_CLAUSE_WAIT:
1905 /* Several OpenACC clauses have optional arguments. Check if they
1906 are present. */
1907 if (OMP_CLAUSE_OPERAND (clause, 0))
1909 wi->val_only = true;
1910 wi->is_lhs = false;
1911 convert_local_reference_op (&OMP_CLAUSE_OPERAND (clause, 0),
1912 &dummy, wi);
1915 /* The gang clause accepts two arguments. */
1916 if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_GANG
1917 && OMP_CLAUSE_GANG_STATIC_EXPR (clause))
1919 wi->val_only = true;
1920 wi->is_lhs = false;
1921 convert_nonlocal_reference_op
1922 (&OMP_CLAUSE_GANG_STATIC_EXPR (clause), &dummy, wi);
1924 break;
1926 case OMP_CLAUSE_DIST_SCHEDULE:
1927 if (OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (clause) != NULL)
1929 wi->val_only = true;
1930 wi->is_lhs = false;
1931 convert_local_reference_op (&OMP_CLAUSE_OPERAND (clause, 0),
1932 &dummy, wi);
1934 break;
1936 case OMP_CLAUSE_MAP:
1937 case OMP_CLAUSE_TO:
1938 case OMP_CLAUSE_FROM:
1939 if (OMP_CLAUSE_SIZE (clause))
1941 wi->val_only = true;
1942 wi->is_lhs = false;
1943 convert_local_reference_op (&OMP_CLAUSE_SIZE (clause),
1944 &dummy, wi);
1946 if (DECL_P (OMP_CLAUSE_DECL (clause)))
1947 goto do_decl_clause;
1948 wi->val_only = true;
1949 wi->is_lhs = false;
1950 walk_tree (&OMP_CLAUSE_DECL (clause), convert_local_reference_op,
1951 wi, NULL);
1952 break;
1954 case OMP_CLAUSE_ALIGNED:
1955 if (OMP_CLAUSE_ALIGNED_ALIGNMENT (clause))
1957 wi->val_only = true;
1958 wi->is_lhs = false;
1959 convert_local_reference_op
1960 (&OMP_CLAUSE_ALIGNED_ALIGNMENT (clause), &dummy, wi);
1962 /* Like do_decl_clause, but don't add any suppression. */
1963 decl = OMP_CLAUSE_DECL (clause);
1964 if (VAR_P (decl)
1965 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
1966 break;
1967 if (decl_function_context (decl) == info->context
1968 && !use_pointer_in_frame (decl))
1970 tree field = lookup_field_for_decl (info, decl, NO_INSERT);
1971 if (field)
1973 OMP_CLAUSE_DECL (clause)
1974 = get_local_debug_decl (info, decl, field);
1975 need_frame = true;
1978 break;
1980 case OMP_CLAUSE_NOWAIT:
1981 case OMP_CLAUSE_ORDERED:
1982 case OMP_CLAUSE_DEFAULT:
1983 case OMP_CLAUSE_COPYIN:
1984 case OMP_CLAUSE_COLLAPSE:
1985 case OMP_CLAUSE_UNTIED:
1986 case OMP_CLAUSE_MERGEABLE:
1987 case OMP_CLAUSE_PROC_BIND:
1988 case OMP_CLAUSE_NOGROUP:
1989 case OMP_CLAUSE_THREADS:
1990 case OMP_CLAUSE_SIMD:
1991 case OMP_CLAUSE_DEFAULTMAP:
1992 case OMP_CLAUSE_SEQ:
1993 case OMP_CLAUSE_INDEPENDENT:
1994 case OMP_CLAUSE_AUTO:
1995 break;
1997 /* OpenACC tile clauses are discarded during gimplification. */
1998 case OMP_CLAUSE_TILE:
1999 /* The following clause belongs to the OpenACC cache directive, which
2000 is discarded during gimplification. */
2001 case OMP_CLAUSE__CACHE_:
2002 /* The following clauses are only allowed in the OpenMP declare simd
2003 directive, so not seen here. */
2004 case OMP_CLAUSE_UNIFORM:
2005 case OMP_CLAUSE_INBRANCH:
2006 case OMP_CLAUSE_NOTINBRANCH:
2007 /* The following clauses are only allowed on OpenMP cancel and
2008 cancellation point directives, which at this point have already
2009 been lowered into a function call. */
2010 case OMP_CLAUSE_FOR:
2011 case OMP_CLAUSE_PARALLEL:
2012 case OMP_CLAUSE_SECTIONS:
2013 case OMP_CLAUSE_TASKGROUP:
2014 /* The following clauses are only added during OMP lowering; nested
2015 function decomposition happens before that. */
2016 case OMP_CLAUSE__LOOPTEMP_:
2017 case OMP_CLAUSE__SIMDUID_:
2018 case OMP_CLAUSE__GRIDDIM_:
2019 /* Anything else. */
2020 default:
2021 gcc_unreachable ();
2025 info->suppress_expansion = new_suppress;
2027 if (need_stmts)
2028 for (clause = *pclauses; clause ; clause = OMP_CLAUSE_CHAIN (clause))
2029 switch (OMP_CLAUSE_CODE (clause))
2031 case OMP_CLAUSE_REDUCTION:
2032 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
2034 tree old_context
2035 = DECL_CONTEXT (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause));
2036 DECL_CONTEXT (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
2037 = info->context;
2038 if (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
2039 DECL_CONTEXT (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
2040 = info->context;
2041 walk_body (convert_local_reference_stmt,
2042 convert_local_reference_op, info,
2043 &OMP_CLAUSE_REDUCTION_GIMPLE_INIT (clause));
2044 walk_body (convert_local_reference_stmt,
2045 convert_local_reference_op, info,
2046 &OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (clause));
2047 DECL_CONTEXT (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
2048 = old_context;
2049 if (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
2050 DECL_CONTEXT (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
2051 = old_context;
2053 break;
2055 case OMP_CLAUSE_LASTPRIVATE:
2056 walk_body (convert_local_reference_stmt,
2057 convert_local_reference_op, info,
2058 &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (clause));
2059 break;
2061 case OMP_CLAUSE_LINEAR:
2062 walk_body (convert_local_reference_stmt,
2063 convert_local_reference_op, info,
2064 &OMP_CLAUSE_LINEAR_GIMPLE_SEQ (clause));
2065 break;
2067 default:
2068 break;
2071 return need_frame;
2075 /* Called via walk_function+walk_gimple_stmt, rewrite all references to VAR
2076 and PARM_DECLs that were referenced by inner nested functions.
2077 The rewrite will be a structure reference to the local frame variable. */
2079 static tree
2080 convert_local_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
2081 struct walk_stmt_info *wi)
2083 struct nesting_info *info = (struct nesting_info *) wi->info;
2084 tree save_local_var_chain;
2085 bitmap save_suppress;
2086 gimple *stmt = gsi_stmt (*gsi);
2088 switch (gimple_code (stmt))
2090 case GIMPLE_OMP_PARALLEL:
2091 case GIMPLE_OMP_TASK:
2092 save_suppress = info->suppress_expansion;
2093 if (convert_local_omp_clauses (gimple_omp_taskreg_clauses_ptr (stmt),
2094 wi))
2096 tree c;
2097 (void) get_frame_type (info);
2098 c = build_omp_clause (gimple_location (stmt),
2099 OMP_CLAUSE_SHARED);
2100 OMP_CLAUSE_DECL (c) = info->frame_decl;
2101 OMP_CLAUSE_CHAIN (c) = gimple_omp_taskreg_clauses (stmt);
2102 gimple_omp_taskreg_set_clauses (stmt, c);
2105 save_local_var_chain = info->new_local_var_chain;
2106 info->new_local_var_chain = NULL;
2108 walk_body (convert_local_reference_stmt, convert_local_reference_op, info,
2109 gimple_omp_body_ptr (stmt));
2111 if (info->new_local_var_chain)
2112 declare_vars (info->new_local_var_chain,
2113 gimple_seq_first_stmt (gimple_omp_body (stmt)), false);
2114 info->new_local_var_chain = save_local_var_chain;
2115 info->suppress_expansion = save_suppress;
2116 break;
2118 case GIMPLE_OMP_FOR:
2119 save_suppress = info->suppress_expansion;
2120 convert_local_omp_clauses (gimple_omp_for_clauses_ptr (stmt), wi);
2121 walk_gimple_omp_for (as_a <gomp_for *> (stmt),
2122 convert_local_reference_stmt,
2123 convert_local_reference_op, info);
2124 walk_body (convert_local_reference_stmt, convert_local_reference_op,
2125 info, gimple_omp_body_ptr (stmt));
2126 info->suppress_expansion = save_suppress;
2127 break;
2129 case GIMPLE_OMP_SECTIONS:
2130 save_suppress = info->suppress_expansion;
2131 convert_local_omp_clauses (gimple_omp_sections_clauses_ptr (stmt), wi);
2132 walk_body (convert_local_reference_stmt, convert_local_reference_op,
2133 info, gimple_omp_body_ptr (stmt));
2134 info->suppress_expansion = save_suppress;
2135 break;
2137 case GIMPLE_OMP_SINGLE:
2138 save_suppress = info->suppress_expansion;
2139 convert_local_omp_clauses (gimple_omp_single_clauses_ptr (stmt), wi);
2140 walk_body (convert_local_reference_stmt, convert_local_reference_op,
2141 info, gimple_omp_body_ptr (stmt));
2142 info->suppress_expansion = save_suppress;
2143 break;
2145 case GIMPLE_OMP_TARGET:
2146 if (!is_gimple_omp_offloaded (stmt))
2148 save_suppress = info->suppress_expansion;
2149 convert_local_omp_clauses (gimple_omp_target_clauses_ptr (stmt), wi);
2150 info->suppress_expansion = save_suppress;
2151 walk_body (convert_local_reference_stmt, convert_local_reference_op,
2152 info, gimple_omp_body_ptr (stmt));
2153 break;
2155 save_suppress = info->suppress_expansion;
2156 if (convert_local_omp_clauses (gimple_omp_target_clauses_ptr (stmt), wi))
2158 tree c;
2159 (void) get_frame_type (info);
2160 c = build_omp_clause (gimple_location (stmt), OMP_CLAUSE_MAP);
2161 OMP_CLAUSE_DECL (c) = info->frame_decl;
2162 OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
2163 OMP_CLAUSE_SIZE (c) = DECL_SIZE_UNIT (info->frame_decl);
2164 OMP_CLAUSE_CHAIN (c) = gimple_omp_target_clauses (stmt);
2165 gimple_omp_target_set_clauses (as_a <gomp_target *> (stmt), c);
2168 save_local_var_chain = info->new_local_var_chain;
2169 info->new_local_var_chain = NULL;
2171 walk_body (convert_local_reference_stmt, convert_local_reference_op, info,
2172 gimple_omp_body_ptr (stmt));
2174 if (info->new_local_var_chain)
2175 declare_vars (info->new_local_var_chain,
2176 gimple_seq_first_stmt (gimple_omp_body (stmt)), false);
2177 info->new_local_var_chain = save_local_var_chain;
2178 info->suppress_expansion = save_suppress;
2179 break;
2181 case GIMPLE_OMP_TEAMS:
2182 save_suppress = info->suppress_expansion;
2183 convert_local_omp_clauses (gimple_omp_teams_clauses_ptr (stmt), wi);
2184 walk_body (convert_local_reference_stmt, convert_local_reference_op,
2185 info, gimple_omp_body_ptr (stmt));
2186 info->suppress_expansion = save_suppress;
2187 break;
2189 case GIMPLE_OMP_SECTION:
2190 case GIMPLE_OMP_MASTER:
2191 case GIMPLE_OMP_TASKGROUP:
2192 case GIMPLE_OMP_ORDERED:
2193 walk_body (convert_local_reference_stmt, convert_local_reference_op,
2194 info, gimple_omp_body_ptr (stmt));
2195 break;
2197 case GIMPLE_COND:
2198 wi->val_only = true;
2199 wi->is_lhs = false;
2200 *handled_ops_p = false;
2201 return NULL_TREE;
2203 case GIMPLE_ASSIGN:
2204 if (gimple_clobber_p (stmt))
2206 tree lhs = gimple_assign_lhs (stmt);
2207 if (!use_pointer_in_frame (lhs)
2208 && lookup_field_for_decl (info, lhs, NO_INSERT))
2210 gsi_replace (gsi, gimple_build_nop (), true);
2211 break;
2214 *handled_ops_p = false;
2215 return NULL_TREE;
2217 case GIMPLE_BIND:
2218 for (tree var = gimple_bind_vars (as_a <gbind *> (stmt));
2219 var;
2220 var = DECL_CHAIN (var))
2221 if (TREE_CODE (var) == NAMELIST_DECL)
2223 /* Adjust decls mentioned in NAMELIST_DECL. */
2224 tree decls = NAMELIST_DECL_ASSOCIATED_DECL (var);
2225 tree decl;
2226 unsigned int i;
2228 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (decls), i, decl)
2230 if (VAR_P (decl)
2231 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
2232 continue;
2233 if (decl_function_context (decl) == info->context
2234 && !use_pointer_in_frame (decl))
2236 tree field = lookup_field_for_decl (info, decl, NO_INSERT);
2237 if (field)
2239 CONSTRUCTOR_ELT (decls, i)->value
2240 = get_local_debug_decl (info, decl, field);
2246 *handled_ops_p = false;
2247 return NULL_TREE;
2249 default:
2250 /* For every other statement that we are not interested in
2251 handling here, let the walker traverse the operands. */
2252 *handled_ops_p = false;
2253 return NULL_TREE;
2256 /* Indicate that we have handled all the operands ourselves. */
2257 *handled_ops_p = true;
2258 return NULL_TREE;
2262 /* Called via walk_function+walk_gimple_stmt, rewrite all GIMPLE_GOTOs
2263 that reference labels from outer functions. The rewrite will be a
2264 call to __builtin_nonlocal_goto. */
2266 static tree
2267 convert_nl_goto_reference (gimple_stmt_iterator *gsi, bool *handled_ops_p,
2268 struct walk_stmt_info *wi)
2270 struct nesting_info *const info = (struct nesting_info *) wi->info, *i;
2271 tree label, new_label, target_context, x, field;
2272 gcall *call;
2273 gimple *stmt = gsi_stmt (*gsi);
2275 if (gimple_code (stmt) != GIMPLE_GOTO)
2277 *handled_ops_p = false;
2278 return NULL_TREE;
2281 label = gimple_goto_dest (stmt);
2282 if (TREE_CODE (label) != LABEL_DECL)
2284 *handled_ops_p = false;
2285 return NULL_TREE;
2288 target_context = decl_function_context (label);
2289 if (target_context == info->context)
2291 *handled_ops_p = false;
2292 return NULL_TREE;
2295 for (i = info->outer; target_context != i->context; i = i->outer)
2296 continue;
2298 /* The original user label may also be use for a normal goto, therefore
2299 we must create a new label that will actually receive the abnormal
2300 control transfer. This new label will be marked LABEL_NONLOCAL; this
2301 mark will trigger proper behavior in the cfg, as well as cause the
2302 (hairy target-specific) non-local goto receiver code to be generated
2303 when we expand rtl. Enter this association into var_map so that we
2304 can insert the new label into the IL during a second pass. */
2305 tree *slot = &i->var_map->get_or_insert (label);
2306 if (*slot == NULL)
2308 new_label = create_artificial_label (UNKNOWN_LOCATION);
2309 DECL_NONLOCAL (new_label) = 1;
2310 *slot = new_label;
2312 else
2313 new_label = *slot;
2315 /* Build: __builtin_nl_goto(new_label, &chain->nl_goto_field). */
2316 field = get_nl_goto_field (i);
2317 x = get_frame_field (info, target_context, field, gsi);
2318 x = build_addr (x);
2319 x = gsi_gimplify_val (info, x, gsi);
2320 call = gimple_build_call (builtin_decl_implicit (BUILT_IN_NONLOCAL_GOTO),
2321 2, build_addr (new_label), x);
2322 gsi_replace (gsi, call, false);
2324 /* We have handled all of STMT's operands, no need to keep going. */
2325 *handled_ops_p = true;
2326 return NULL_TREE;
2330 /* Called via walk_function+walk_tree, rewrite all GIMPLE_LABELs whose labels
2331 are referenced via nonlocal goto from a nested function. The rewrite
2332 will involve installing a newly generated DECL_NONLOCAL label, and
2333 (potentially) a branch around the rtl gunk that is assumed to be
2334 attached to such a label. */
2336 static tree
2337 convert_nl_goto_receiver (gimple_stmt_iterator *gsi, bool *handled_ops_p,
2338 struct walk_stmt_info *wi)
2340 struct nesting_info *const info = (struct nesting_info *) wi->info;
2341 tree label, new_label;
2342 gimple_stmt_iterator tmp_gsi;
2343 glabel *stmt = dyn_cast <glabel *> (gsi_stmt (*gsi));
2345 if (!stmt)
2347 *handled_ops_p = false;
2348 return NULL_TREE;
2351 label = gimple_label_label (stmt);
2353 tree *slot = info->var_map->get (label);
2354 if (!slot)
2356 *handled_ops_p = false;
2357 return NULL_TREE;
2360 /* If there's any possibility that the previous statement falls through,
2361 then we must branch around the new non-local label. */
2362 tmp_gsi = wi->gsi;
2363 gsi_prev (&tmp_gsi);
2364 if (gsi_end_p (tmp_gsi) || gimple_stmt_may_fallthru (gsi_stmt (tmp_gsi)))
2366 gimple *stmt = gimple_build_goto (label);
2367 gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
2370 new_label = (tree) *slot;
2371 stmt = gimple_build_label (new_label);
2372 gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
2374 *handled_ops_p = true;
2375 return NULL_TREE;
2379 /* Called via walk_function+walk_stmt, rewrite all references to addresses
2380 of nested functions that require the use of trampolines. The rewrite
2381 will involve a reference a trampoline generated for the occasion. */
2383 static tree
2384 convert_tramp_reference_op (tree *tp, int *walk_subtrees, void *data)
2386 struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
2387 struct nesting_info *const info = (struct nesting_info *) wi->info, *i;
2388 tree t = *tp, decl, target_context, x, builtin;
2389 bool descr;
2390 gcall *call;
2392 *walk_subtrees = 0;
2393 switch (TREE_CODE (t))
2395 case ADDR_EXPR:
2396 /* Build
2397 T.1 = &CHAIN->tramp;
2398 T.2 = __builtin_adjust_trampoline (T.1);
2399 T.3 = (func_type)T.2;
2402 decl = TREE_OPERAND (t, 0);
2403 if (TREE_CODE (decl) != FUNCTION_DECL)
2404 break;
2406 /* Only need to process nested functions. */
2407 target_context = decl_function_context (decl);
2408 if (!target_context)
2409 break;
2411 /* If the nested function doesn't use a static chain, then
2412 it doesn't need a trampoline. */
2413 if (!DECL_STATIC_CHAIN (decl))
2414 break;
2416 /* If we don't want a trampoline, then don't build one. */
2417 if (TREE_NO_TRAMPOLINE (t))
2418 break;
2420 /* Lookup the immediate parent of the callee, as that's where
2421 we need to insert the trampoline. */
2422 for (i = info; i->context != target_context; i = i->outer)
2423 continue;
2425 /* Decide whether to generate a descriptor or a trampoline. */
2426 descr = FUNC_ADDR_BY_DESCRIPTOR (t) && !flag_trampolines;
2428 if (descr)
2429 x = lookup_descr_for_decl (i, decl, INSERT);
2430 else
2431 x = lookup_tramp_for_decl (i, decl, INSERT);
2433 /* Compute the address of the field holding the trampoline. */
2434 x = get_frame_field (info, target_context, x, &wi->gsi);
2435 x = build_addr (x);
2436 x = gsi_gimplify_val (info, x, &wi->gsi);
2438 /* Do machine-specific ugliness. Normally this will involve
2439 computing extra alignment, but it can really be anything. */
2440 if (descr)
2441 builtin = builtin_decl_implicit (BUILT_IN_ADJUST_DESCRIPTOR);
2442 else
2443 builtin = builtin_decl_implicit (BUILT_IN_ADJUST_TRAMPOLINE);
2444 call = gimple_build_call (builtin, 1, x);
2445 x = init_tmp_var_with_call (info, &wi->gsi, call);
2447 /* Cast back to the proper function type. */
2448 x = build1 (NOP_EXPR, TREE_TYPE (t), x);
2449 x = init_tmp_var (info, x, &wi->gsi);
2451 *tp = x;
2452 break;
2454 default:
2455 if (!IS_TYPE_OR_DECL_P (t))
2456 *walk_subtrees = 1;
2457 break;
2460 return NULL_TREE;
2464 /* Called via walk_function+walk_gimple_stmt, rewrite all references
2465 to addresses of nested functions that require the use of
2466 trampolines. The rewrite will involve a reference a trampoline
2467 generated for the occasion. */
2469 static tree
2470 convert_tramp_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
2471 struct walk_stmt_info *wi)
2473 struct nesting_info *info = (struct nesting_info *) wi->info;
2474 gimple *stmt = gsi_stmt (*gsi);
2476 switch (gimple_code (stmt))
2478 case GIMPLE_CALL:
2480 /* Only walk call arguments, lest we generate trampolines for
2481 direct calls. */
2482 unsigned long i, nargs = gimple_call_num_args (stmt);
2483 for (i = 0; i < nargs; i++)
2484 walk_tree (gimple_call_arg_ptr (stmt, i), convert_tramp_reference_op,
2485 wi, NULL);
2486 break;
2489 case GIMPLE_OMP_TARGET:
2490 if (!is_gimple_omp_offloaded (stmt))
2492 *handled_ops_p = false;
2493 return NULL_TREE;
2495 /* FALLTHRU */
2496 case GIMPLE_OMP_PARALLEL:
2497 case GIMPLE_OMP_TASK:
2499 tree save_local_var_chain = info->new_local_var_chain;
2500 walk_gimple_op (stmt, convert_tramp_reference_op, wi);
2501 info->new_local_var_chain = NULL;
2502 char save_static_chain_added = info->static_chain_added;
2503 info->static_chain_added = 0;
2504 walk_body (convert_tramp_reference_stmt, convert_tramp_reference_op,
2505 info, gimple_omp_body_ptr (stmt));
2506 if (info->new_local_var_chain)
2507 declare_vars (info->new_local_var_chain,
2508 gimple_seq_first_stmt (gimple_omp_body (stmt)),
2509 false);
2510 for (int i = 0; i < 2; i++)
2512 tree c, decl;
2513 if ((info->static_chain_added & (1 << i)) == 0)
2514 continue;
2515 decl = i ? get_chain_decl (info) : info->frame_decl;
2516 /* Don't add CHAIN.* or FRAME.* twice. */
2517 for (c = gimple_omp_taskreg_clauses (stmt);
2519 c = OMP_CLAUSE_CHAIN (c))
2520 if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
2521 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED)
2522 && OMP_CLAUSE_DECL (c) == decl)
2523 break;
2524 if (c == NULL && gimple_code (stmt) != GIMPLE_OMP_TARGET)
2526 c = build_omp_clause (gimple_location (stmt),
2527 i ? OMP_CLAUSE_FIRSTPRIVATE
2528 : OMP_CLAUSE_SHARED);
2529 OMP_CLAUSE_DECL (c) = decl;
2530 OMP_CLAUSE_CHAIN (c) = gimple_omp_taskreg_clauses (stmt);
2531 gimple_omp_taskreg_set_clauses (stmt, c);
2533 else if (c == NULL)
2535 c = build_omp_clause (gimple_location (stmt),
2536 OMP_CLAUSE_MAP);
2537 OMP_CLAUSE_DECL (c) = decl;
2538 OMP_CLAUSE_SET_MAP_KIND (c,
2539 i ? GOMP_MAP_TO : GOMP_MAP_TOFROM);
2540 OMP_CLAUSE_SIZE (c) = DECL_SIZE_UNIT (decl);
2541 OMP_CLAUSE_CHAIN (c) = gimple_omp_target_clauses (stmt);
2542 gimple_omp_target_set_clauses (as_a <gomp_target *> (stmt),
2546 info->new_local_var_chain = save_local_var_chain;
2547 info->static_chain_added |= save_static_chain_added;
2549 break;
2551 default:
2552 *handled_ops_p = false;
2553 return NULL_TREE;
2556 *handled_ops_p = true;
2557 return NULL_TREE;
2562 /* Called via walk_function+walk_gimple_stmt, rewrite all GIMPLE_CALLs
2563 that reference nested functions to make sure that the static chain
2564 is set up properly for the call. */
2566 static tree
2567 convert_gimple_call (gimple_stmt_iterator *gsi, bool *handled_ops_p,
2568 struct walk_stmt_info *wi)
2570 struct nesting_info *const info = (struct nesting_info *) wi->info;
2571 tree decl, target_context;
2572 char save_static_chain_added;
2573 int i;
2574 gimple *stmt = gsi_stmt (*gsi);
2576 switch (gimple_code (stmt))
2578 case GIMPLE_CALL:
2579 if (gimple_call_chain (stmt))
2580 break;
2581 decl = gimple_call_fndecl (stmt);
2582 if (!decl)
2583 break;
2584 target_context = decl_function_context (decl);
2585 if (target_context && DECL_STATIC_CHAIN (decl))
2587 gimple_call_set_chain (as_a <gcall *> (stmt),
2588 get_static_chain (info, target_context,
2589 &wi->gsi));
2590 info->static_chain_added |= (1 << (info->context != target_context));
2592 break;
2594 case GIMPLE_OMP_PARALLEL:
2595 case GIMPLE_OMP_TASK:
2596 save_static_chain_added = info->static_chain_added;
2597 info->static_chain_added = 0;
2598 walk_body (convert_gimple_call, NULL, info, gimple_omp_body_ptr (stmt));
2599 for (i = 0; i < 2; i++)
2601 tree c, decl;
2602 if ((info->static_chain_added & (1 << i)) == 0)
2603 continue;
2604 decl = i ? get_chain_decl (info) : info->frame_decl;
2605 /* Don't add CHAIN.* or FRAME.* twice. */
2606 for (c = gimple_omp_taskreg_clauses (stmt);
2608 c = OMP_CLAUSE_CHAIN (c))
2609 if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
2610 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED)
2611 && OMP_CLAUSE_DECL (c) == decl)
2612 break;
2613 if (c == NULL)
2615 c = build_omp_clause (gimple_location (stmt),
2616 i ? OMP_CLAUSE_FIRSTPRIVATE
2617 : OMP_CLAUSE_SHARED);
2618 OMP_CLAUSE_DECL (c) = decl;
2619 OMP_CLAUSE_CHAIN (c) = gimple_omp_taskreg_clauses (stmt);
2620 gimple_omp_taskreg_set_clauses (stmt, c);
2623 info->static_chain_added |= save_static_chain_added;
2624 break;
2626 case GIMPLE_OMP_TARGET:
2627 if (!is_gimple_omp_offloaded (stmt))
2629 walk_body (convert_gimple_call, NULL, info, gimple_omp_body_ptr (stmt));
2630 break;
2632 save_static_chain_added = info->static_chain_added;
2633 info->static_chain_added = 0;
2634 walk_body (convert_gimple_call, NULL, info, gimple_omp_body_ptr (stmt));
2635 for (i = 0; i < 2; i++)
2637 tree c, decl;
2638 if ((info->static_chain_added & (1 << i)) == 0)
2639 continue;
2640 decl = i ? get_chain_decl (info) : info->frame_decl;
2641 /* Don't add CHAIN.* or FRAME.* twice. */
2642 for (c = gimple_omp_target_clauses (stmt);
2644 c = OMP_CLAUSE_CHAIN (c))
2645 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
2646 && OMP_CLAUSE_DECL (c) == decl)
2647 break;
2648 if (c == NULL)
2650 c = build_omp_clause (gimple_location (stmt), OMP_CLAUSE_MAP);
2651 OMP_CLAUSE_DECL (c) = decl;
2652 OMP_CLAUSE_SET_MAP_KIND (c, i ? GOMP_MAP_TO : GOMP_MAP_TOFROM);
2653 OMP_CLAUSE_SIZE (c) = DECL_SIZE_UNIT (decl);
2654 OMP_CLAUSE_CHAIN (c) = gimple_omp_target_clauses (stmt);
2655 gimple_omp_target_set_clauses (as_a <gomp_target *> (stmt),
2659 info->static_chain_added |= save_static_chain_added;
2660 break;
2662 case GIMPLE_OMP_FOR:
2663 walk_body (convert_gimple_call, NULL, info,
2664 gimple_omp_for_pre_body_ptr (stmt));
2665 /* FALLTHRU */
2666 case GIMPLE_OMP_SECTIONS:
2667 case GIMPLE_OMP_SECTION:
2668 case GIMPLE_OMP_SINGLE:
2669 case GIMPLE_OMP_TEAMS:
2670 case GIMPLE_OMP_MASTER:
2671 case GIMPLE_OMP_TASKGROUP:
2672 case GIMPLE_OMP_ORDERED:
2673 case GIMPLE_OMP_CRITICAL:
2674 walk_body (convert_gimple_call, NULL, info, gimple_omp_body_ptr (stmt));
2675 break;
2677 default:
2678 /* Keep looking for other operands. */
2679 *handled_ops_p = false;
2680 return NULL_TREE;
2683 *handled_ops_p = true;
2684 return NULL_TREE;
2687 /* Walk the nesting tree starting with ROOT. Convert all trampolines and
2688 call expressions. At the same time, determine if a nested function
2689 actually uses its static chain; if not, remember that. */
2691 static void
2692 convert_all_function_calls (struct nesting_info *root)
2694 unsigned int chain_count = 0, old_chain_count, iter_count;
2695 struct nesting_info *n;
2697 /* First, optimistically clear static_chain for all decls that haven't
2698 used the static chain already for variable access. But always create
2699 it if not optimizing. This makes it possible to reconstruct the static
2700 nesting tree at run time and thus to resolve up-level references from
2701 within the debugger. */
2702 FOR_EACH_NEST_INFO (n, root)
2704 tree decl = n->context;
2705 if (!optimize)
2707 if (n->inner)
2708 (void) get_frame_type (n);
2709 if (n->outer)
2710 (void) get_chain_decl (n);
2712 else if (!n->outer || (!n->chain_decl && !n->chain_field))
2714 DECL_STATIC_CHAIN (decl) = 0;
2715 if (dump_file && (dump_flags & TDF_DETAILS))
2716 fprintf (dump_file, "Guessing no static-chain for %s\n",
2717 lang_hooks.decl_printable_name (decl, 2));
2719 else
2720 DECL_STATIC_CHAIN (decl) = 1;
2721 chain_count += DECL_STATIC_CHAIN (decl);
2724 /* Walk the functions and perform transformations. Note that these
2725 transformations can induce new uses of the static chain, which in turn
2726 require re-examining all users of the decl. */
2727 /* ??? It would make sense to try to use the call graph to speed this up,
2728 but the call graph hasn't really been built yet. Even if it did, we
2729 would still need to iterate in this loop since address-of references
2730 wouldn't show up in the callgraph anyway. */
2731 iter_count = 0;
2734 old_chain_count = chain_count;
2735 chain_count = 0;
2736 iter_count++;
2738 if (dump_file && (dump_flags & TDF_DETAILS))
2739 fputc ('\n', dump_file);
2741 FOR_EACH_NEST_INFO (n, root)
2743 tree decl = n->context;
2744 walk_function (convert_tramp_reference_stmt,
2745 convert_tramp_reference_op, n);
2746 walk_function (convert_gimple_call, NULL, n);
2747 chain_count += DECL_STATIC_CHAIN (decl);
2750 while (chain_count != old_chain_count);
2752 if (dump_file && (dump_flags & TDF_DETAILS))
2753 fprintf (dump_file, "convert_all_function_calls iterations: %u\n\n",
2754 iter_count);
2757 struct nesting_copy_body_data
2759 copy_body_data cb;
2760 struct nesting_info *root;
2763 /* A helper subroutine for debug_var_chain type remapping. */
2765 static tree
2766 nesting_copy_decl (tree decl, copy_body_data *id)
2768 struct nesting_copy_body_data *nid = (struct nesting_copy_body_data *) id;
2769 tree *slot = nid->root->var_map->get (decl);
2771 if (slot)
2772 return (tree) *slot;
2774 if (TREE_CODE (decl) == TYPE_DECL && DECL_ORIGINAL_TYPE (decl))
2776 tree new_decl = copy_decl_no_change (decl, id);
2777 DECL_ORIGINAL_TYPE (new_decl)
2778 = remap_type (DECL_ORIGINAL_TYPE (decl), id);
2779 return new_decl;
2782 if (VAR_P (decl)
2783 || TREE_CODE (decl) == PARM_DECL
2784 || TREE_CODE (decl) == RESULT_DECL)
2785 return decl;
2787 return copy_decl_no_change (decl, id);
2790 /* A helper function for remap_vla_decls. See if *TP contains
2791 some remapped variables. */
2793 static tree
2794 contains_remapped_vars (tree *tp, int *walk_subtrees, void *data)
2796 struct nesting_info *root = (struct nesting_info *) data;
2797 tree t = *tp;
2799 if (DECL_P (t))
2801 *walk_subtrees = 0;
2802 tree *slot = root->var_map->get (t);
2804 if (slot)
2805 return *slot;
2807 return NULL;
2810 /* Remap VLA decls in BLOCK and subblocks if remapped variables are
2811 involved. */
2813 static void
2814 remap_vla_decls (tree block, struct nesting_info *root)
2816 tree var, subblock, val, type;
2817 struct nesting_copy_body_data id;
2819 for (subblock = BLOCK_SUBBLOCKS (block);
2820 subblock;
2821 subblock = BLOCK_CHAIN (subblock))
2822 remap_vla_decls (subblock, root);
2824 for (var = BLOCK_VARS (block); var; var = DECL_CHAIN (var))
2825 if (VAR_P (var) && DECL_HAS_VALUE_EXPR_P (var))
2827 val = DECL_VALUE_EXPR (var);
2828 type = TREE_TYPE (var);
2830 if (!(TREE_CODE (val) == INDIRECT_REF
2831 && TREE_CODE (TREE_OPERAND (val, 0)) == VAR_DECL
2832 && variably_modified_type_p (type, NULL)))
2833 continue;
2835 if (root->var_map->get (TREE_OPERAND (val, 0))
2836 || walk_tree (&type, contains_remapped_vars, root, NULL))
2837 break;
2840 if (var == NULL_TREE)
2841 return;
2843 memset (&id, 0, sizeof (id));
2844 id.cb.copy_decl = nesting_copy_decl;
2845 id.cb.decl_map = new hash_map<tree, tree>;
2846 id.root = root;
2848 for (; var; var = DECL_CHAIN (var))
2849 if (VAR_P (var) && DECL_HAS_VALUE_EXPR_P (var))
2851 struct nesting_info *i;
2852 tree newt, context;
2854 val = DECL_VALUE_EXPR (var);
2855 type = TREE_TYPE (var);
2857 if (!(TREE_CODE (val) == INDIRECT_REF
2858 && TREE_CODE (TREE_OPERAND (val, 0)) == VAR_DECL
2859 && variably_modified_type_p (type, NULL)))
2860 continue;
2862 tree *slot = root->var_map->get (TREE_OPERAND (val, 0));
2863 if (!slot && !walk_tree (&type, contains_remapped_vars, root, NULL))
2864 continue;
2866 context = decl_function_context (var);
2867 for (i = root; i; i = i->outer)
2868 if (i->context == context)
2869 break;
2871 if (i == NULL)
2872 continue;
2874 /* Fully expand value expressions. This avoids having debug variables
2875 only referenced from them and that can be swept during GC. */
2876 if (slot)
2878 tree t = (tree) *slot;
2879 gcc_assert (DECL_P (t) && DECL_HAS_VALUE_EXPR_P (t));
2880 val = build1 (INDIRECT_REF, TREE_TYPE (val), DECL_VALUE_EXPR (t));
2883 id.cb.src_fn = i->context;
2884 id.cb.dst_fn = i->context;
2885 id.cb.src_cfun = DECL_STRUCT_FUNCTION (root->context);
2887 TREE_TYPE (var) = newt = remap_type (type, &id.cb);
2888 while (POINTER_TYPE_P (newt) && !TYPE_NAME (newt))
2890 newt = TREE_TYPE (newt);
2891 type = TREE_TYPE (type);
2893 if (TYPE_NAME (newt)
2894 && TREE_CODE (TYPE_NAME (newt)) == TYPE_DECL
2895 && DECL_ORIGINAL_TYPE (TYPE_NAME (newt))
2896 && newt != type
2897 && TYPE_NAME (newt) == TYPE_NAME (type))
2898 TYPE_NAME (newt) = remap_decl (TYPE_NAME (newt), &id.cb);
2900 walk_tree (&val, copy_tree_body_r, &id.cb, NULL);
2901 if (val != DECL_VALUE_EXPR (var))
2902 SET_DECL_VALUE_EXPR (var, val);
2905 delete id.cb.decl_map;
2908 /* Fold the MEM_REF *E. */
2909 bool
2910 fold_mem_refs (tree *const &e, void *data ATTRIBUTE_UNUSED)
2912 tree *ref_p = CONST_CAST2 (tree *, const tree *, (const tree *)e);
2913 *ref_p = fold (*ref_p);
2914 return true;
2917 /* Given DECL, a nested function, build an initialization call for FIELD,
2918 the trampoline or descriptor for DECL, using FUNC as the function. */
2920 static gcall *
2921 build_init_call_stmt (struct nesting_info *info, tree decl, tree field,
2922 tree func)
2924 tree arg1, arg2, arg3, x;
2926 gcc_assert (DECL_STATIC_CHAIN (decl));
2927 arg3 = build_addr (info->frame_decl);
2929 arg2 = build_addr (decl);
2931 x = build3 (COMPONENT_REF, TREE_TYPE (field),
2932 info->frame_decl, field, NULL_TREE);
2933 arg1 = build_addr (x);
2935 return gimple_build_call (func, 3, arg1, arg2, arg3);
2938 /* Do "everything else" to clean up or complete state collected by the various
2939 walking passes -- create a field to hold the frame base address, lay out the
2940 types and decls, generate code to initialize the frame decl, store critical
2941 expressions in the struct function for rtl to find. */
2943 static void
2944 finalize_nesting_tree_1 (struct nesting_info *root)
2946 gimple_seq stmt_list;
2947 gimple *stmt;
2948 tree context = root->context;
2949 struct function *sf;
2951 stmt_list = NULL;
2953 /* If we created a non-local frame type or decl, we need to lay them
2954 out at this time. */
2955 if (root->frame_type)
2957 /* Debugging information needs to compute the frame base address of the
2958 parent frame out of the static chain from the nested frame.
2960 The static chain is the address of the FRAME record, so one could
2961 imagine it would be possible to compute the frame base address just
2962 adding a constant offset to this address. Unfortunately, this is not
2963 possible: if the FRAME object has alignment constraints that are
2964 stronger than the stack, then the offset between the frame base and
2965 the FRAME object will be dynamic.
2967 What we do instead is to append a field to the FRAME object that holds
2968 the frame base address: then debug info just has to fetch this
2969 field. */
2971 /* Debugging information will refer to the CFA as the frame base
2972 address: we will do the same here. */
2973 const tree frame_addr_fndecl
2974 = builtin_decl_explicit (BUILT_IN_DWARF_CFA);
2976 /* Create a field in the FRAME record to hold the frame base address for
2977 this stack frame. Since it will be used only by the debugger, put it
2978 at the end of the record in order not to shift all other offsets. */
2979 tree fb_decl = make_node (FIELD_DECL);
2981 DECL_NAME (fb_decl) = get_identifier ("FRAME_BASE.PARENT");
2982 TREE_TYPE (fb_decl) = ptr_type_node;
2983 TREE_ADDRESSABLE (fb_decl) = 1;
2984 DECL_CONTEXT (fb_decl) = root->frame_type;
2985 TYPE_FIELDS (root->frame_type) = chainon (TYPE_FIELDS (root->frame_type),
2986 fb_decl);
2988 /* In some cases the frame type will trigger the -Wpadded warning.
2989 This is not helpful; suppress it. */
2990 int save_warn_padded = warn_padded;
2991 warn_padded = 0;
2992 layout_type (root->frame_type);
2993 warn_padded = save_warn_padded;
2994 layout_decl (root->frame_decl, 0);
2996 /* Initialize the frame base address field. If the builtin we need is
2997 not available, set it to NULL so that debugging information does not
2998 reference junk. */
2999 tree fb_ref = build3 (COMPONENT_REF, TREE_TYPE (fb_decl),
3000 root->frame_decl, fb_decl, NULL_TREE);
3001 tree fb_tmp;
3003 if (frame_addr_fndecl != NULL_TREE)
3005 gcall *fb_gimple = gimple_build_call (frame_addr_fndecl, 1,
3006 integer_zero_node);
3007 gimple_stmt_iterator gsi = gsi_last (stmt_list);
3009 fb_tmp = init_tmp_var_with_call (root, &gsi, fb_gimple);
3011 else
3012 fb_tmp = build_int_cst (TREE_TYPE (fb_ref), 0);
3013 gimple_seq_add_stmt (&stmt_list,
3014 gimple_build_assign (fb_ref, fb_tmp));
3016 /* Remove root->frame_decl from root->new_local_var_chain, so
3017 that we can declare it also in the lexical blocks, which
3018 helps ensure virtual regs that end up appearing in its RTL
3019 expression get substituted in instantiate_virtual_regs(). */
3020 tree *adjust;
3021 for (adjust = &root->new_local_var_chain;
3022 *adjust != root->frame_decl;
3023 adjust = &DECL_CHAIN (*adjust))
3024 gcc_assert (DECL_CHAIN (*adjust));
3025 *adjust = DECL_CHAIN (*adjust);
3027 DECL_CHAIN (root->frame_decl) = NULL_TREE;
3028 declare_vars (root->frame_decl,
3029 gimple_seq_first_stmt (gimple_body (context)), true);
3032 /* If any parameters were referenced non-locally, then we need to
3033 insert a copy. Likewise, if any variables were referenced by
3034 pointer, we need to initialize the address. */
3035 if (root->any_parm_remapped)
3037 tree p;
3038 for (p = DECL_ARGUMENTS (context); p ; p = DECL_CHAIN (p))
3040 tree field, x, y;
3042 field = lookup_field_for_decl (root, p, NO_INSERT);
3043 if (!field)
3044 continue;
3046 if (use_pointer_in_frame (p))
3047 x = build_addr (p);
3048 else
3049 x = p;
3051 /* If the assignment is from a non-register the stmt is
3052 not valid gimple. Make it so by using a temporary instead. */
3053 if (!is_gimple_reg (x)
3054 && is_gimple_reg_type (TREE_TYPE (x)))
3056 gimple_stmt_iterator gsi = gsi_last (stmt_list);
3057 x = init_tmp_var (root, x, &gsi);
3060 y = build3 (COMPONENT_REF, TREE_TYPE (field),
3061 root->frame_decl, field, NULL_TREE);
3062 stmt = gimple_build_assign (y, x);
3063 gimple_seq_add_stmt (&stmt_list, stmt);
3067 /* If a chain_field was created, then it needs to be initialized
3068 from chain_decl. */
3069 if (root->chain_field)
3071 tree x = build3 (COMPONENT_REF, TREE_TYPE (root->chain_field),
3072 root->frame_decl, root->chain_field, NULL_TREE);
3073 stmt = gimple_build_assign (x, get_chain_decl (root));
3074 gimple_seq_add_stmt (&stmt_list, stmt);
3077 /* If trampolines were created, then we need to initialize them. */
3078 if (root->any_tramp_created)
3080 struct nesting_info *i;
3081 for (i = root->inner; i ; i = i->next)
3083 tree field, x;
3085 field = lookup_tramp_for_decl (root, i->context, NO_INSERT);
3086 if (!field)
3087 continue;
3089 x = builtin_decl_implicit (BUILT_IN_INIT_TRAMPOLINE);
3090 stmt = build_init_call_stmt (root, i->context, field, x);
3091 gimple_seq_add_stmt (&stmt_list, stmt);
3095 /* If descriptors were created, then we need to initialize them. */
3096 if (root->any_descr_created)
3098 struct nesting_info *i;
3099 for (i = root->inner; i ; i = i->next)
3101 tree field, x;
3103 field = lookup_descr_for_decl (root, i->context, NO_INSERT);
3104 if (!field)
3105 continue;
3107 x = builtin_decl_implicit (BUILT_IN_INIT_DESCRIPTOR);
3108 stmt = build_init_call_stmt (root, i->context, field, x);
3109 gimple_seq_add_stmt (&stmt_list, stmt);
3113 /* If we created initialization statements, insert them. */
3114 if (stmt_list)
3116 gbind *bind;
3117 annotate_all_with_location (stmt_list, DECL_SOURCE_LOCATION (context));
3118 bind = gimple_seq_first_stmt_as_a_bind (gimple_body (context));
3119 gimple_seq_add_seq (&stmt_list, gimple_bind_body (bind));
3120 gimple_bind_set_body (bind, stmt_list);
3123 /* If a chain_decl was created, then it needs to be registered with
3124 struct function so that it gets initialized from the static chain
3125 register at the beginning of the function. */
3126 sf = DECL_STRUCT_FUNCTION (root->context);
3127 sf->static_chain_decl = root->chain_decl;
3129 /* Similarly for the non-local goto save area. */
3130 if (root->nl_goto_field)
3132 sf->nonlocal_goto_save_area
3133 = get_frame_field (root, context, root->nl_goto_field, NULL);
3134 sf->has_nonlocal_label = 1;
3137 /* Make sure all new local variables get inserted into the
3138 proper BIND_EXPR. */
3139 if (root->new_local_var_chain)
3140 declare_vars (root->new_local_var_chain,
3141 gimple_seq_first_stmt (gimple_body (root->context)),
3142 false);
3144 if (root->debug_var_chain)
3146 tree debug_var;
3147 gbind *scope;
3149 remap_vla_decls (DECL_INITIAL (root->context), root);
3151 for (debug_var = root->debug_var_chain; debug_var;
3152 debug_var = DECL_CHAIN (debug_var))
3153 if (variably_modified_type_p (TREE_TYPE (debug_var), NULL))
3154 break;
3156 /* If there are any debug decls with variable length types,
3157 remap those types using other debug_var_chain variables. */
3158 if (debug_var)
3160 struct nesting_copy_body_data id;
3162 memset (&id, 0, sizeof (id));
3163 id.cb.copy_decl = nesting_copy_decl;
3164 id.cb.decl_map = new hash_map<tree, tree>;
3165 id.root = root;
3167 for (; debug_var; debug_var = DECL_CHAIN (debug_var))
3168 if (variably_modified_type_p (TREE_TYPE (debug_var), NULL))
3170 tree type = TREE_TYPE (debug_var);
3171 tree newt, t = type;
3172 struct nesting_info *i;
3174 for (i = root; i; i = i->outer)
3175 if (variably_modified_type_p (type, i->context))
3176 break;
3178 if (i == NULL)
3179 continue;
3181 id.cb.src_fn = i->context;
3182 id.cb.dst_fn = i->context;
3183 id.cb.src_cfun = DECL_STRUCT_FUNCTION (root->context);
3185 TREE_TYPE (debug_var) = newt = remap_type (type, &id.cb);
3186 while (POINTER_TYPE_P (newt) && !TYPE_NAME (newt))
3188 newt = TREE_TYPE (newt);
3189 t = TREE_TYPE (t);
3191 if (TYPE_NAME (newt)
3192 && TREE_CODE (TYPE_NAME (newt)) == TYPE_DECL
3193 && DECL_ORIGINAL_TYPE (TYPE_NAME (newt))
3194 && newt != t
3195 && TYPE_NAME (newt) == TYPE_NAME (t))
3196 TYPE_NAME (newt) = remap_decl (TYPE_NAME (newt), &id.cb);
3199 delete id.cb.decl_map;
3202 scope = gimple_seq_first_stmt_as_a_bind (gimple_body (root->context));
3203 if (gimple_bind_block (scope))
3204 declare_vars (root->debug_var_chain, scope, true);
3205 else
3206 BLOCK_VARS (DECL_INITIAL (root->context))
3207 = chainon (BLOCK_VARS (DECL_INITIAL (root->context)),
3208 root->debug_var_chain);
3211 /* Fold the rewritten MEM_REF trees. */
3212 root->mem_refs->traverse<void *, fold_mem_refs> (NULL);
3214 /* Dump the translated tree function. */
3215 if (dump_file)
3217 fputs ("\n\n", dump_file);
3218 dump_function_to_file (root->context, dump_file, dump_flags);
3222 static void
3223 finalize_nesting_tree (struct nesting_info *root)
3225 struct nesting_info *n;
3226 FOR_EACH_NEST_INFO (n, root)
3227 finalize_nesting_tree_1 (n);
3230 /* Unnest the nodes and pass them to cgraph. */
3232 static void
3233 unnest_nesting_tree_1 (struct nesting_info *root)
3235 struct cgraph_node *node = cgraph_node::get (root->context);
3237 /* For nested functions update the cgraph to reflect unnesting.
3238 We also delay finalizing of these functions up to this point. */
3239 if (node->origin)
3241 node->unnest ();
3242 cgraph_node::finalize_function (root->context, true);
3246 static void
3247 unnest_nesting_tree (struct nesting_info *root)
3249 struct nesting_info *n;
3250 FOR_EACH_NEST_INFO (n, root)
3251 unnest_nesting_tree_1 (n);
3254 /* Free the data structures allocated during this pass. */
3256 static void
3257 free_nesting_tree (struct nesting_info *root)
3259 struct nesting_info *node, *next;
3261 node = iter_nestinfo_start (root);
3264 next = iter_nestinfo_next (node);
3265 delete node->var_map;
3266 delete node->field_map;
3267 delete node->mem_refs;
3268 free (node);
3269 node = next;
3271 while (node);
3274 /* Gimplify a function and all its nested functions. */
3275 static void
3276 gimplify_all_functions (struct cgraph_node *root)
3278 struct cgraph_node *iter;
3279 if (!gimple_body (root->decl))
3280 gimplify_function_tree (root->decl);
3281 for (iter = root->nested; iter; iter = iter->next_nested)
3282 gimplify_all_functions (iter);
3285 /* Main entry point for this pass. Process FNDECL and all of its nested
3286 subroutines and turn them into something less tightly bound. */
3288 void
3289 lower_nested_functions (tree fndecl)
3291 struct cgraph_node *cgn;
3292 struct nesting_info *root;
3294 /* If there are no nested functions, there's nothing to do. */
3295 cgn = cgraph_node::get (fndecl);
3296 if (!cgn->nested)
3297 return;
3299 gimplify_all_functions (cgn);
3301 dump_file = dump_begin (TDI_nested, &dump_flags);
3302 if (dump_file)
3303 fprintf (dump_file, "\n;; Function %s\n\n",
3304 lang_hooks.decl_printable_name (fndecl, 2));
3306 bitmap_obstack_initialize (&nesting_info_bitmap_obstack);
3307 root = create_nesting_tree (cgn);
3309 walk_all_functions (convert_nonlocal_reference_stmt,
3310 convert_nonlocal_reference_op,
3311 root);
3312 walk_all_functions (convert_local_reference_stmt,
3313 convert_local_reference_op,
3314 root);
3315 walk_all_functions (convert_nl_goto_reference, NULL, root);
3316 walk_all_functions (convert_nl_goto_receiver, NULL, root);
3318 convert_all_function_calls (root);
3319 finalize_nesting_tree (root);
3320 unnest_nesting_tree (root);
3322 free_nesting_tree (root);
3323 bitmap_obstack_release (&nesting_info_bitmap_obstack);
3325 if (dump_file)
3327 dump_end (TDI_nested, dump_file);
3328 dump_file = NULL;
3332 #include "gt-tree-nested.h"