Don't build insn-extract.o with rtl checking
[gcc.git] / gcc / tree-nested.c
1 /* Nested function decomposition for GIMPLE.
2 Copyright (C) 2004-2020 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
10
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
19
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 "dumpfile.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"
44 #include "diagnostic.h"
45 #include "alloc-pool.h"
46 #include "tree-nested.h"
47 #include "symbol-summary.h"
48 #include "symtab-thunks.h"
49
50 /* Summary of nested functions. */
51 static function_summary <nested_function_info *>
52 *nested_function_sum = NULL;
53
54 /* Return nested_function_info, if available. */
55 nested_function_info *
56 nested_function_info::get (cgraph_node *node)
57 {
58 if (!nested_function_sum)
59 return NULL;
60 return nested_function_sum->get (node);
61 }
62
63 /* Return nested_function_info possibly creating new one. */
64 nested_function_info *
65 nested_function_info::get_create (cgraph_node *node)
66 {
67 if (!nested_function_sum)
68 {
69 nested_function_sum = new function_summary <nested_function_info *>
70 (symtab);
71 nested_function_sum->disable_insertion_hook ();
72 }
73 return nested_function_sum->get_create (node);
74 }
75
76 /* cgraph_node is no longer nested function; update cgraph accordingly. */
77 void
78 unnest_function (cgraph_node *node)
79 {
80 nested_function_info *info = nested_function_info::get (node);
81 cgraph_node **node2 = &nested_function_info::get
82 (nested_function_origin (node))->nested;
83
84 gcc_checking_assert (info->origin);
85 while (*node2 != node)
86 node2 = &nested_function_info::get (*node2)->next_nested;
87 *node2 = info->next_nested;
88 info->next_nested = NULL;
89 info->origin = NULL;
90 nested_function_sum->remove (node);
91 }
92
93 /* Destructor: unlink function from nested function lists. */
94 nested_function_info::~nested_function_info ()
95 {
96 cgraph_node *next;
97 for (cgraph_node *n = nested; n; n = next)
98 {
99 nested_function_info *info = nested_function_info::get (n);
100 next = info->next_nested;
101 info->origin = NULL;
102 info->next_nested = NULL;
103 }
104 nested = NULL;
105 if (origin)
106 {
107 cgraph_node **node2
108 = &nested_function_info::get (origin)->nested;
109
110 nested_function_info *info;
111 while ((info = nested_function_info::get (*node2)) != this && info)
112 node2 = &info->next_nested;
113 *node2 = next_nested;
114 }
115 }
116
117 /* Free nested function info summaries. */
118 void
119 nested_function_info::release ()
120 {
121 if (nested_function_sum)
122 delete (nested_function_sum);
123 nested_function_sum = NULL;
124 }
125
126 /* If NODE is nested function, record it. */
127 void
128 maybe_record_nested_function (cgraph_node *node)
129 {
130 /* All nested functions gets lowered during the construction of symtab. */
131 if (symtab->state > CONSTRUCTION)
132 return;
133 if (DECL_CONTEXT (node->decl)
134 && TREE_CODE (DECL_CONTEXT (node->decl)) == FUNCTION_DECL)
135 {
136 cgraph_node *origin = cgraph_node::get_create (DECL_CONTEXT (node->decl));
137 nested_function_info *info = nested_function_info::get_create (node);
138 nested_function_info *origin_info
139 = nested_function_info::get_create (origin);
140
141 info->origin = origin;
142 info->next_nested = origin_info->nested;
143 origin_info->nested = node;
144 }
145 }
146
147 /* The object of this pass is to lower the representation of a set of nested
148 functions in order to expose all of the gory details of the various
149 nonlocal references. We want to do this sooner rather than later, in
150 order to give us more freedom in emitting all of the functions in question.
151
152 Back in olden times, when gcc was young, we developed an insanely
153 complicated scheme whereby variables which were referenced nonlocally
154 were forced to live in the stack of the declaring function, and then
155 the nested functions magically discovered where these variables were
156 placed. In order for this scheme to function properly, it required
157 that the outer function be partially expanded, then we switch to
158 compiling the inner function, and once done with those we switch back
159 to compiling the outer function. Such delicate ordering requirements
160 makes it difficult to do whole translation unit optimizations
161 involving such functions.
162
163 The implementation here is much more direct. Everything that can be
164 referenced by an inner function is a member of an explicitly created
165 structure herein called the "nonlocal frame struct". The incoming
166 static chain for a nested function is a pointer to this struct in
167 the parent. In this way, we settle on known offsets from a known
168 base, and so are decoupled from the logic that places objects in the
169 function's stack frame. More importantly, we don't have to wait for
170 that to happen -- since the compilation of the inner function is no
171 longer tied to a real stack frame, the nonlocal frame struct can be
172 allocated anywhere. Which means that the outer function is now
173 inlinable.
174
175 Theory of operation here is very simple. Iterate over all the
176 statements in all the functions (depth first) several times,
177 allocating structures and fields on demand. In general we want to
178 examine inner functions first, so that we can avoid making changes
179 to outer functions which are unnecessary.
180
181 The order of the passes matters a bit, in that later passes will be
182 skipped if it is discovered that the functions don't actually interact
183 at all. That is, they're nested in the lexical sense but could have
184 been written as independent functions without change. */
185
186
187 struct nesting_info
188 {
189 struct nesting_info *outer;
190 struct nesting_info *inner;
191 struct nesting_info *next;
192
193 hash_map<tree, tree> *field_map;
194 hash_map<tree, tree> *var_map;
195 hash_set<tree *> *mem_refs;
196 bitmap suppress_expansion;
197
198 tree context;
199 tree new_local_var_chain;
200 tree debug_var_chain;
201 tree frame_type;
202 tree frame_decl;
203 tree chain_field;
204 tree chain_decl;
205 tree nl_goto_field;
206
207 bool thunk_p;
208 bool any_parm_remapped;
209 bool any_tramp_created;
210 bool any_descr_created;
211 char static_chain_added;
212 };
213
214
215 /* Iterate over the nesting tree, starting with ROOT, depth first. */
216
217 static inline struct nesting_info *
218 iter_nestinfo_start (struct nesting_info *root)
219 {
220 while (root->inner)
221 root = root->inner;
222 return root;
223 }
224
225 static inline struct nesting_info *
226 iter_nestinfo_next (struct nesting_info *node)
227 {
228 if (node->next)
229 return iter_nestinfo_start (node->next);
230 return node->outer;
231 }
232
233 #define FOR_EACH_NEST_INFO(I, ROOT) \
234 for ((I) = iter_nestinfo_start (ROOT); (I); (I) = iter_nestinfo_next (I))
235
236 /* Obstack used for the bitmaps in the struct above. */
237 static struct bitmap_obstack nesting_info_bitmap_obstack;
238
239
240 /* We're working in so many different function contexts simultaneously,
241 that create_tmp_var is dangerous. Prevent mishap. */
242 #define create_tmp_var cant_use_create_tmp_var_here_dummy
243
244 /* Like create_tmp_var, except record the variable for registration at
245 the given nesting level. */
246
247 static tree
248 create_tmp_var_for (struct nesting_info *info, tree type, const char *prefix)
249 {
250 tree tmp_var;
251
252 /* If the type is of variable size or a type which must be created by the
253 frontend, something is wrong. Note that we explicitly allow
254 incomplete types here, since we create them ourselves here. */
255 gcc_assert (!TREE_ADDRESSABLE (type));
256 gcc_assert (!TYPE_SIZE_UNIT (type)
257 || TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST);
258
259 tmp_var = create_tmp_var_raw (type, prefix);
260 DECL_CONTEXT (tmp_var) = info->context;
261 DECL_CHAIN (tmp_var) = info->new_local_var_chain;
262 DECL_SEEN_IN_BIND_EXPR_P (tmp_var) = 1;
263
264 info->new_local_var_chain = tmp_var;
265
266 return tmp_var;
267 }
268
269 /* Like build_simple_mem_ref, but set TREE_THIS_NOTRAP on the result. */
270
271 static tree
272 build_simple_mem_ref_notrap (tree ptr)
273 {
274 tree t = build_simple_mem_ref (ptr);
275 TREE_THIS_NOTRAP (t) = 1;
276 return t;
277 }
278
279 /* Take the address of EXP to be used within function CONTEXT.
280 Mark it for addressability as necessary. */
281
282 tree
283 build_addr (tree exp)
284 {
285 mark_addressable (exp);
286 return build_fold_addr_expr (exp);
287 }
288
289 /* Insert FIELD into TYPE, sorted by alignment requirements. */
290
291 void
292 insert_field_into_struct (tree type, tree field)
293 {
294 tree *p;
295
296 DECL_CONTEXT (field) = type;
297
298 for (p = &TYPE_FIELDS (type); *p ; p = &DECL_CHAIN (*p))
299 if (DECL_ALIGN (field) >= DECL_ALIGN (*p))
300 break;
301
302 DECL_CHAIN (field) = *p;
303 *p = field;
304
305 /* Set correct alignment for frame struct type. */
306 if (TYPE_ALIGN (type) < DECL_ALIGN (field))
307 SET_TYPE_ALIGN (type, DECL_ALIGN (field));
308 }
309
310 /* Build or return the RECORD_TYPE that describes the frame state that is
311 shared between INFO->CONTEXT and its nested functions. This record will
312 not be complete until finalize_nesting_tree; up until that point we'll
313 be adding fields as necessary.
314
315 We also build the DECL that represents this frame in the function. */
316
317 static tree
318 get_frame_type (struct nesting_info *info)
319 {
320 tree type = info->frame_type;
321 if (!type)
322 {
323 char *name;
324
325 type = make_node (RECORD_TYPE);
326
327 name = concat ("FRAME.",
328 IDENTIFIER_POINTER (DECL_NAME (info->context)),
329 NULL);
330 TYPE_NAME (type) = get_identifier (name);
331 free (name);
332
333 info->frame_type = type;
334
335 /* Do not put info->frame_decl on info->new_local_var_chain,
336 so that we can declare it in the lexical blocks, which
337 makes sure virtual regs that end up appearing in its RTL
338 expression get substituted in instantiate_virtual_regs. */
339 info->frame_decl = create_tmp_var_raw (type, "FRAME");
340 DECL_CONTEXT (info->frame_decl) = info->context;
341 DECL_NONLOCAL_FRAME (info->frame_decl) = 1;
342 DECL_SEEN_IN_BIND_EXPR_P (info->frame_decl) = 1;
343
344 /* ??? Always make it addressable for now, since it is meant to
345 be pointed to by the static chain pointer. This pessimizes
346 when it turns out that no static chains are needed because
347 the nested functions referencing non-local variables are not
348 reachable, but the true pessimization is to create the non-
349 local frame structure in the first place. */
350 TREE_ADDRESSABLE (info->frame_decl) = 1;
351 }
352
353 return type;
354 }
355
356 /* Return true if DECL should be referenced by pointer in the non-local frame
357 structure. */
358
359 static bool
360 use_pointer_in_frame (tree decl)
361 {
362 if (TREE_CODE (decl) == PARM_DECL)
363 {
364 /* It's illegal to copy TREE_ADDRESSABLE, impossible to copy variable-
365 sized DECLs, and inefficient to copy large aggregates. Don't bother
366 moving anything but scalar parameters. */
367 return AGGREGATE_TYPE_P (TREE_TYPE (decl));
368 }
369 else
370 {
371 /* Variable-sized DECLs can only come from OMP clauses at this point
372 since the gimplifier has already turned the regular variables into
373 pointers. Do the same as the gimplifier. */
374 return !DECL_SIZE (decl) || TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST;
375 }
376 }
377
378 /* Given DECL, a non-locally accessed variable, find or create a field
379 in the non-local frame structure for the given nesting context. */
380
381 static tree
382 lookup_field_for_decl (struct nesting_info *info, tree decl,
383 enum insert_option insert)
384 {
385 gcc_checking_assert (decl_function_context (decl) == info->context);
386
387 if (insert == NO_INSERT)
388 {
389 tree *slot = info->field_map->get (decl);
390 return slot ? *slot : NULL_TREE;
391 }
392
393 tree *slot = &info->field_map->get_or_insert (decl);
394 if (!*slot)
395 {
396 tree type = get_frame_type (info);
397 tree field = make_node (FIELD_DECL);
398 DECL_NAME (field) = DECL_NAME (decl);
399
400 if (use_pointer_in_frame (decl))
401 {
402 TREE_TYPE (field) = build_pointer_type (TREE_TYPE (decl));
403 SET_DECL_ALIGN (field, TYPE_ALIGN (TREE_TYPE (field)));
404 DECL_NONADDRESSABLE_P (field) = 1;
405 }
406 else
407 {
408 TREE_TYPE (field) = TREE_TYPE (decl);
409 DECL_SOURCE_LOCATION (field) = DECL_SOURCE_LOCATION (decl);
410 SET_DECL_ALIGN (field, DECL_ALIGN (decl));
411 DECL_USER_ALIGN (field) = DECL_USER_ALIGN (decl);
412 DECL_IGNORED_P (field) = DECL_IGNORED_P (decl);
413 DECL_NONADDRESSABLE_P (field) = !TREE_ADDRESSABLE (decl);
414 TREE_NO_WARNING (field) = TREE_NO_WARNING (decl);
415 TREE_THIS_VOLATILE (field) = TREE_THIS_VOLATILE (decl);
416
417 /* Declare the transformation and adjust the original DECL. For a
418 variable or for a parameter when not optimizing, we make it point
419 to the field in the frame directly. For a parameter, we don't do
420 it when optimizing because the variable tracking pass will already
421 do the job, */
422 if (VAR_P (decl) || !optimize)
423 {
424 tree x
425 = build3 (COMPONENT_REF, TREE_TYPE (field), info->frame_decl,
426 field, NULL_TREE);
427
428 /* If the next declaration is a PARM_DECL pointing to the DECL,
429 we need to adjust its VALUE_EXPR directly, since chains of
430 VALUE_EXPRs run afoul of garbage collection. This occurs
431 in Ada for Out parameters that aren't copied in. */
432 tree next = DECL_CHAIN (decl);
433 if (next
434 && TREE_CODE (next) == PARM_DECL
435 && DECL_HAS_VALUE_EXPR_P (next)
436 && DECL_VALUE_EXPR (next) == decl)
437 SET_DECL_VALUE_EXPR (next, x);
438
439 SET_DECL_VALUE_EXPR (decl, x);
440 DECL_HAS_VALUE_EXPR_P (decl) = 1;
441 }
442 }
443
444 insert_field_into_struct (type, field);
445 *slot = field;
446
447 if (TREE_CODE (decl) == PARM_DECL)
448 info->any_parm_remapped = true;
449 }
450
451 return *slot;
452 }
453
454 /* Build or return the variable that holds the static chain within
455 INFO->CONTEXT. This variable may only be used within INFO->CONTEXT. */
456
457 static tree
458 get_chain_decl (struct nesting_info *info)
459 {
460 tree decl = info->chain_decl;
461
462 if (!decl)
463 {
464 tree type;
465
466 type = get_frame_type (info->outer);
467 type = build_pointer_type (type);
468
469 /* Note that this variable is *not* entered into any BIND_EXPR;
470 the construction of this variable is handled specially in
471 expand_function_start and initialize_inlined_parameters.
472 Note also that it's represented as a parameter. This is more
473 close to the truth, since the initial value does come from
474 the caller. */
475 decl = build_decl (DECL_SOURCE_LOCATION (info->context),
476 PARM_DECL, create_tmp_var_name ("CHAIN"), type);
477 DECL_ARTIFICIAL (decl) = 1;
478 DECL_IGNORED_P (decl) = 1;
479 TREE_USED (decl) = 1;
480 DECL_CONTEXT (decl) = info->context;
481 DECL_ARG_TYPE (decl) = type;
482
483 /* Tell tree-inline.c that we never write to this variable, so
484 it can copy-prop the replacement value immediately. */
485 TREE_READONLY (decl) = 1;
486
487 info->chain_decl = decl;
488
489 if (dump_file
490 && (dump_flags & TDF_DETAILS)
491 && !DECL_STATIC_CHAIN (info->context))
492 fprintf (dump_file, "Setting static-chain for %s\n",
493 lang_hooks.decl_printable_name (info->context, 2));
494
495 DECL_STATIC_CHAIN (info->context) = 1;
496 }
497 return decl;
498 }
499
500 /* Build or return the field within the non-local frame state that holds
501 the static chain for INFO->CONTEXT. This is the way to walk back up
502 multiple nesting levels. */
503
504 static tree
505 get_chain_field (struct nesting_info *info)
506 {
507 tree field = info->chain_field;
508
509 if (!field)
510 {
511 tree type = build_pointer_type (get_frame_type (info->outer));
512
513 field = make_node (FIELD_DECL);
514 DECL_NAME (field) = get_identifier ("__chain");
515 TREE_TYPE (field) = type;
516 SET_DECL_ALIGN (field, TYPE_ALIGN (type));
517 DECL_NONADDRESSABLE_P (field) = 1;
518
519 insert_field_into_struct (get_frame_type (info), field);
520
521 info->chain_field = field;
522
523 if (dump_file
524 && (dump_flags & TDF_DETAILS)
525 && !DECL_STATIC_CHAIN (info->context))
526 fprintf (dump_file, "Setting static-chain for %s\n",
527 lang_hooks.decl_printable_name (info->context, 2));
528
529 DECL_STATIC_CHAIN (info->context) = 1;
530 }
531 return field;
532 }
533
534 /* Initialize a new temporary with the GIMPLE_CALL STMT. */
535
536 static tree
537 init_tmp_var_with_call (struct nesting_info *info, gimple_stmt_iterator *gsi,
538 gcall *call)
539 {
540 tree t;
541
542 t = create_tmp_var_for (info, gimple_call_return_type (call), NULL);
543 gimple_call_set_lhs (call, t);
544 if (! gsi_end_p (*gsi))
545 gimple_set_location (call, gimple_location (gsi_stmt (*gsi)));
546 gsi_insert_before (gsi, call, GSI_SAME_STMT);
547
548 return t;
549 }
550
551
552 /* Copy EXP into a temporary. Allocate the temporary in the context of
553 INFO and insert the initialization statement before GSI. */
554
555 static tree
556 init_tmp_var (struct nesting_info *info, tree exp, gimple_stmt_iterator *gsi)
557 {
558 tree t;
559 gimple *stmt;
560
561 t = create_tmp_var_for (info, TREE_TYPE (exp), NULL);
562 stmt = gimple_build_assign (t, exp);
563 if (! gsi_end_p (*gsi))
564 gimple_set_location (stmt, gimple_location (gsi_stmt (*gsi)));
565 gsi_insert_before_without_update (gsi, stmt, GSI_SAME_STMT);
566
567 return t;
568 }
569
570
571 /* Similarly, but only do so to force EXP to satisfy is_gimple_val. */
572
573 static tree
574 gsi_gimplify_val (struct nesting_info *info, tree exp,
575 gimple_stmt_iterator *gsi)
576 {
577 if (is_gimple_val (exp))
578 return exp;
579 else
580 return init_tmp_var (info, exp, gsi);
581 }
582
583 /* Similarly, but copy from the temporary and insert the statement
584 after the iterator. */
585
586 static tree
587 save_tmp_var (struct nesting_info *info, tree exp, gimple_stmt_iterator *gsi)
588 {
589 tree t;
590 gimple *stmt;
591
592 t = create_tmp_var_for (info, TREE_TYPE (exp), NULL);
593 stmt = gimple_build_assign (exp, t);
594 if (! gsi_end_p (*gsi))
595 gimple_set_location (stmt, gimple_location (gsi_stmt (*gsi)));
596 gsi_insert_after_without_update (gsi, stmt, GSI_SAME_STMT);
597
598 return t;
599 }
600
601 /* Build or return the type used to represent a nested function trampoline. */
602
603 static GTY(()) tree trampoline_type;
604
605 static tree
606 get_trampoline_type (struct nesting_info *info)
607 {
608 unsigned align, size;
609 tree t;
610
611 if (trampoline_type)
612 return trampoline_type;
613
614 align = TRAMPOLINE_ALIGNMENT;
615 size = TRAMPOLINE_SIZE;
616
617 /* If we won't be able to guarantee alignment simply via TYPE_ALIGN,
618 then allocate extra space so that we can do dynamic alignment. */
619 if (align > STACK_BOUNDARY)
620 {
621 size += ((align/BITS_PER_UNIT) - 1) & -(STACK_BOUNDARY/BITS_PER_UNIT);
622 align = STACK_BOUNDARY;
623 }
624
625 t = build_index_type (size_int (size - 1));
626 t = build_array_type (char_type_node, t);
627 t = build_decl (DECL_SOURCE_LOCATION (info->context),
628 FIELD_DECL, get_identifier ("__data"), t);
629 SET_DECL_ALIGN (t, align);
630 DECL_USER_ALIGN (t) = 1;
631
632 trampoline_type = make_node (RECORD_TYPE);
633 TYPE_NAME (trampoline_type) = get_identifier ("__builtin_trampoline");
634 TYPE_FIELDS (trampoline_type) = t;
635 layout_type (trampoline_type);
636 DECL_CONTEXT (t) = trampoline_type;
637
638 return trampoline_type;
639 }
640
641 /* Build or return the type used to represent a nested function descriptor. */
642
643 static GTY(()) tree descriptor_type;
644
645 static tree
646 get_descriptor_type (struct nesting_info *info)
647 {
648 /* The base alignment is that of a function. */
649 const unsigned align = FUNCTION_ALIGNMENT (FUNCTION_BOUNDARY);
650 tree t;
651
652 if (descriptor_type)
653 return descriptor_type;
654
655 t = build_index_type (integer_one_node);
656 t = build_array_type (ptr_type_node, t);
657 t = build_decl (DECL_SOURCE_LOCATION (info->context),
658 FIELD_DECL, get_identifier ("__data"), t);
659 SET_DECL_ALIGN (t, MAX (TYPE_ALIGN (ptr_type_node), align));
660 DECL_USER_ALIGN (t) = 1;
661
662 descriptor_type = make_node (RECORD_TYPE);
663 TYPE_NAME (descriptor_type) = get_identifier ("__builtin_descriptor");
664 TYPE_FIELDS (descriptor_type) = t;
665 layout_type (descriptor_type);
666 DECL_CONTEXT (t) = descriptor_type;
667
668 return descriptor_type;
669 }
670
671 /* Given DECL, a nested function, find or create an element in the
672 var map for this function. */
673
674 static tree
675 lookup_element_for_decl (struct nesting_info *info, tree decl,
676 enum insert_option insert)
677 {
678 if (insert == NO_INSERT)
679 {
680 tree *slot = info->var_map->get (decl);
681 return slot ? *slot : NULL_TREE;
682 }
683
684 tree *slot = &info->var_map->get_or_insert (decl);
685 if (!*slot)
686 *slot = build_tree_list (NULL_TREE, NULL_TREE);
687
688 return (tree) *slot;
689 }
690
691 /* Given DECL, a nested function, create a field in the non-local
692 frame structure for this function. */
693
694 static tree
695 create_field_for_decl (struct nesting_info *info, tree decl, tree type)
696 {
697 tree field = make_node (FIELD_DECL);
698 DECL_NAME (field) = DECL_NAME (decl);
699 TREE_TYPE (field) = type;
700 TREE_ADDRESSABLE (field) = 1;
701 insert_field_into_struct (get_frame_type (info), field);
702 return field;
703 }
704
705 /* Given DECL, a nested function, find or create a field in the non-local
706 frame structure for a trampoline for this function. */
707
708 static tree
709 lookup_tramp_for_decl (struct nesting_info *info, tree decl,
710 enum insert_option insert)
711 {
712 tree elt, field;
713
714 elt = lookup_element_for_decl (info, decl, insert);
715 if (!elt)
716 return NULL_TREE;
717
718 field = TREE_PURPOSE (elt);
719
720 if (!field && insert == INSERT)
721 {
722 field = create_field_for_decl (info, decl, get_trampoline_type (info));
723 TREE_PURPOSE (elt) = field;
724 info->any_tramp_created = true;
725 }
726
727 return field;
728 }
729
730 /* Given DECL, a nested function, find or create a field in the non-local
731 frame structure for a descriptor for this function. */
732
733 static tree
734 lookup_descr_for_decl (struct nesting_info *info, tree decl,
735 enum insert_option insert)
736 {
737 tree elt, field;
738
739 elt = lookup_element_for_decl (info, decl, insert);
740 if (!elt)
741 return NULL_TREE;
742
743 field = TREE_VALUE (elt);
744
745 if (!field && insert == INSERT)
746 {
747 field = create_field_for_decl (info, decl, get_descriptor_type (info));
748 TREE_VALUE (elt) = field;
749 info->any_descr_created = true;
750 }
751
752 return field;
753 }
754
755 /* Build or return the field within the non-local frame state that holds
756 the non-local goto "jmp_buf". The buffer itself is maintained by the
757 rtl middle-end as dynamic stack space is allocated. */
758
759 static tree
760 get_nl_goto_field (struct nesting_info *info)
761 {
762 tree field = info->nl_goto_field;
763 if (!field)
764 {
765 unsigned size;
766 tree type;
767
768 /* For __builtin_nonlocal_goto, we need N words. The first is the
769 frame pointer, the rest is for the target's stack pointer save
770 area. The number of words is controlled by STACK_SAVEAREA_MODE;
771 not the best interface, but it'll do for now. */
772 if (Pmode == ptr_mode)
773 type = ptr_type_node;
774 else
775 type = lang_hooks.types.type_for_mode (Pmode, 1);
776
777 scalar_int_mode mode
778 = as_a <scalar_int_mode> (STACK_SAVEAREA_MODE (SAVE_NONLOCAL));
779 size = GET_MODE_SIZE (mode);
780 size = size / GET_MODE_SIZE (Pmode);
781 size = size + 1;
782
783 type = build_array_type
784 (type, build_index_type (size_int (size)));
785
786 field = make_node (FIELD_DECL);
787 DECL_NAME (field) = get_identifier ("__nl_goto_buf");
788 TREE_TYPE (field) = type;
789 SET_DECL_ALIGN (field, TYPE_ALIGN (type));
790 TREE_ADDRESSABLE (field) = 1;
791
792 insert_field_into_struct (get_frame_type (info), field);
793
794 info->nl_goto_field = field;
795 }
796
797 return field;
798 }
799
800 /* Invoke CALLBACK on all statements of GIMPLE sequence *PSEQ. */
801
802 static void
803 walk_body (walk_stmt_fn callback_stmt, walk_tree_fn callback_op,
804 struct nesting_info *info, gimple_seq *pseq)
805 {
806 struct walk_stmt_info wi;
807
808 memset (&wi, 0, sizeof (wi));
809 wi.info = info;
810 wi.val_only = true;
811 walk_gimple_seq_mod (pseq, callback_stmt, callback_op, &wi);
812 }
813
814
815 /* Invoke CALLBACK_STMT/CALLBACK_OP on all statements of INFO->CONTEXT. */
816
817 static inline void
818 walk_function (walk_stmt_fn callback_stmt, walk_tree_fn callback_op,
819 struct nesting_info *info)
820 {
821 gimple_seq body = gimple_body (info->context);
822 walk_body (callback_stmt, callback_op, info, &body);
823 gimple_set_body (info->context, body);
824 }
825
826 /* Invoke CALLBACK on a GIMPLE_OMP_FOR's init, cond, incr and pre-body. */
827
828 static void
829 walk_gimple_omp_for (gomp_for *for_stmt,
830 walk_stmt_fn callback_stmt, walk_tree_fn callback_op,
831 struct nesting_info *info)
832 {
833 struct walk_stmt_info wi;
834 gimple_seq seq;
835 tree t;
836 size_t i;
837
838 walk_body (callback_stmt, callback_op, info, gimple_omp_for_pre_body_ptr (for_stmt));
839
840 seq = NULL;
841 memset (&wi, 0, sizeof (wi));
842 wi.info = info;
843 wi.gsi = gsi_last (seq);
844
845 for (i = 0; i < gimple_omp_for_collapse (for_stmt); i++)
846 {
847 wi.val_only = false;
848 walk_tree (gimple_omp_for_index_ptr (for_stmt, i), callback_op,
849 &wi, NULL);
850 wi.val_only = true;
851 wi.is_lhs = false;
852 walk_tree (gimple_omp_for_initial_ptr (for_stmt, i), callback_op,
853 &wi, NULL);
854
855 wi.val_only = true;
856 wi.is_lhs = false;
857 walk_tree (gimple_omp_for_final_ptr (for_stmt, i), callback_op,
858 &wi, NULL);
859
860 t = gimple_omp_for_incr (for_stmt, i);
861 gcc_assert (BINARY_CLASS_P (t));
862 wi.val_only = false;
863 walk_tree (&TREE_OPERAND (t, 0), callback_op, &wi, NULL);
864 wi.val_only = true;
865 wi.is_lhs = false;
866 walk_tree (&TREE_OPERAND (t, 1), callback_op, &wi, NULL);
867 }
868
869 seq = gsi_seq (wi.gsi);
870 if (!gimple_seq_empty_p (seq))
871 {
872 gimple_seq pre_body = gimple_omp_for_pre_body (for_stmt);
873 annotate_all_with_location (seq, gimple_location (for_stmt));
874 gimple_seq_add_seq (&pre_body, seq);
875 gimple_omp_for_set_pre_body (for_stmt, pre_body);
876 }
877 }
878
879 /* Similarly for ROOT and all functions nested underneath, depth first. */
880
881 static void
882 walk_all_functions (walk_stmt_fn callback_stmt, walk_tree_fn callback_op,
883 struct nesting_info *root)
884 {
885 struct nesting_info *n;
886 FOR_EACH_NEST_INFO (n, root)
887 walk_function (callback_stmt, callback_op, n);
888 }
889
890
891 /* We have to check for a fairly pathological case. The operands of function
892 nested function are to be interpreted in the context of the enclosing
893 function. So if any are variably-sized, they will get remapped when the
894 enclosing function is inlined. But that remapping would also have to be
895 done in the types of the PARM_DECLs of the nested function, meaning the
896 argument types of that function will disagree with the arguments in the
897 calls to that function. So we'd either have to make a copy of the nested
898 function corresponding to each time the enclosing function was inlined or
899 add a VIEW_CONVERT_EXPR to each such operand for each call to the nested
900 function. The former is not practical. The latter would still require
901 detecting this case to know when to add the conversions. So, for now at
902 least, we don't inline such an enclosing function.
903
904 We have to do that check recursively, so here return indicating whether
905 FNDECL has such a nested function. ORIG_FN is the function we were
906 trying to inline to use for checking whether any argument is variably
907 modified by anything in it.
908
909 It would be better to do this in tree-inline.c so that we could give
910 the appropriate warning for why a function can't be inlined, but that's
911 too late since the nesting structure has already been flattened and
912 adding a flag just to record this fact seems a waste of a flag. */
913
914 static bool
915 check_for_nested_with_variably_modified (tree fndecl, tree orig_fndecl)
916 {
917 struct cgraph_node *cgn = cgraph_node::get (fndecl);
918 tree arg;
919
920 for (cgn = first_nested_function (cgn); cgn;
921 cgn = next_nested_function (cgn))
922 {
923 for (arg = DECL_ARGUMENTS (cgn->decl); arg; arg = DECL_CHAIN (arg))
924 if (variably_modified_type_p (TREE_TYPE (arg), orig_fndecl))
925 return true;
926
927 if (check_for_nested_with_variably_modified (cgn->decl,
928 orig_fndecl))
929 return true;
930 }
931
932 return false;
933 }
934
935 /* Construct our local datastructure describing the function nesting
936 tree rooted by CGN. */
937
938 static struct nesting_info *
939 create_nesting_tree (struct cgraph_node *cgn)
940 {
941 struct nesting_info *info = XCNEW (struct nesting_info);
942 info->field_map = new hash_map<tree, tree>;
943 info->var_map = new hash_map<tree, tree>;
944 info->mem_refs = new hash_set<tree *>;
945 info->suppress_expansion = BITMAP_ALLOC (&nesting_info_bitmap_obstack);
946 info->context = cgn->decl;
947 info->thunk_p = cgn->thunk;
948
949 for (cgn = first_nested_function (cgn); cgn;
950 cgn = next_nested_function (cgn))
951 {
952 struct nesting_info *sub = create_nesting_tree (cgn);
953 sub->outer = info;
954 sub->next = info->inner;
955 info->inner = sub;
956 }
957
958 /* See discussion at check_for_nested_with_variably_modified for a
959 discussion of why this has to be here. */
960 if (check_for_nested_with_variably_modified (info->context, info->context))
961 DECL_UNINLINABLE (info->context) = true;
962
963 return info;
964 }
965
966 /* Return an expression computing the static chain for TARGET_CONTEXT
967 from INFO->CONTEXT. Insert any necessary computations before TSI. */
968
969 static tree
970 get_static_chain (struct nesting_info *info, tree target_context,
971 gimple_stmt_iterator *gsi)
972 {
973 struct nesting_info *i;
974 tree x;
975
976 if (info->context == target_context)
977 {
978 x = build_addr (info->frame_decl);
979 info->static_chain_added |= 1;
980 }
981 else
982 {
983 x = get_chain_decl (info);
984 info->static_chain_added |= 2;
985
986 for (i = info->outer; i->context != target_context; i = i->outer)
987 {
988 tree field = get_chain_field (i);
989
990 x = build_simple_mem_ref_notrap (x);
991 x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
992 x = init_tmp_var (info, x, gsi);
993 }
994 }
995
996 return x;
997 }
998
999
1000 /* Return an expression referencing FIELD from TARGET_CONTEXT's non-local
1001 frame as seen from INFO->CONTEXT. Insert any necessary computations
1002 before GSI. */
1003
1004 static tree
1005 get_frame_field (struct nesting_info *info, tree target_context,
1006 tree field, gimple_stmt_iterator *gsi)
1007 {
1008 struct nesting_info *i;
1009 tree x;
1010
1011 if (info->context == target_context)
1012 {
1013 /* Make sure frame_decl gets created. */
1014 (void) get_frame_type (info);
1015 x = info->frame_decl;
1016 info->static_chain_added |= 1;
1017 }
1018 else
1019 {
1020 x = get_chain_decl (info);
1021 info->static_chain_added |= 2;
1022
1023 for (i = info->outer; i->context != target_context; i = i->outer)
1024 {
1025 tree field = get_chain_field (i);
1026
1027 x = build_simple_mem_ref_notrap (x);
1028 x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
1029 x = init_tmp_var (info, x, gsi);
1030 }
1031
1032 x = build_simple_mem_ref_notrap (x);
1033 }
1034
1035 x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
1036 return x;
1037 }
1038
1039 static void note_nonlocal_vla_type (struct nesting_info *info, tree type);
1040
1041 /* A subroutine of convert_nonlocal_reference_op. Create a local variable
1042 in the nested function with DECL_VALUE_EXPR set to reference the true
1043 variable in the parent function. This is used both for debug info
1044 and in OMP lowering. */
1045
1046 static tree
1047 get_nonlocal_debug_decl (struct nesting_info *info, tree decl)
1048 {
1049 tree target_context;
1050 struct nesting_info *i;
1051 tree x, field, new_decl;
1052
1053 tree *slot = &info->var_map->get_or_insert (decl);
1054
1055 if (*slot)
1056 return *slot;
1057
1058 target_context = decl_function_context (decl);
1059
1060 /* A copy of the code in get_frame_field, but without the temporaries. */
1061 if (info->context == target_context)
1062 {
1063 /* Make sure frame_decl gets created. */
1064 (void) get_frame_type (info);
1065 x = info->frame_decl;
1066 i = info;
1067 info->static_chain_added |= 1;
1068 }
1069 else
1070 {
1071 x = get_chain_decl (info);
1072 info->static_chain_added |= 2;
1073 for (i = info->outer; i->context != target_context; i = i->outer)
1074 {
1075 field = get_chain_field (i);
1076 x = build_simple_mem_ref_notrap (x);
1077 x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
1078 }
1079 x = build_simple_mem_ref_notrap (x);
1080 }
1081
1082 field = lookup_field_for_decl (i, decl, INSERT);
1083 x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
1084 if (use_pointer_in_frame (decl))
1085 x = build_simple_mem_ref_notrap (x);
1086
1087 /* ??? We should be remapping types as well, surely. */
1088 new_decl = build_decl (DECL_SOURCE_LOCATION (decl),
1089 VAR_DECL, DECL_NAME (decl), TREE_TYPE (decl));
1090 DECL_CONTEXT (new_decl) = info->context;
1091 DECL_ARTIFICIAL (new_decl) = DECL_ARTIFICIAL (decl);
1092 DECL_IGNORED_P (new_decl) = DECL_IGNORED_P (decl);
1093 TREE_THIS_VOLATILE (new_decl) = TREE_THIS_VOLATILE (decl);
1094 TREE_SIDE_EFFECTS (new_decl) = TREE_SIDE_EFFECTS (decl);
1095 TREE_READONLY (new_decl) = TREE_READONLY (decl);
1096 TREE_ADDRESSABLE (new_decl) = TREE_ADDRESSABLE (decl);
1097 DECL_SEEN_IN_BIND_EXPR_P (new_decl) = 1;
1098 if ((TREE_CODE (decl) == PARM_DECL
1099 || TREE_CODE (decl) == RESULT_DECL
1100 || VAR_P (decl))
1101 && DECL_BY_REFERENCE (decl))
1102 DECL_BY_REFERENCE (new_decl) = 1;
1103
1104 SET_DECL_VALUE_EXPR (new_decl, x);
1105 DECL_HAS_VALUE_EXPR_P (new_decl) = 1;
1106
1107 *slot = new_decl;
1108 DECL_CHAIN (new_decl) = info->debug_var_chain;
1109 info->debug_var_chain = new_decl;
1110
1111 if (!optimize
1112 && info->context != target_context
1113 && variably_modified_type_p (TREE_TYPE (decl), NULL))
1114 note_nonlocal_vla_type (info, TREE_TYPE (decl));
1115
1116 return new_decl;
1117 }
1118
1119
1120 /* Callback for walk_gimple_stmt, rewrite all references to VAR
1121 and PARM_DECLs that belong to outer functions.
1122
1123 The rewrite will involve some number of structure accesses back up
1124 the static chain. E.g. for a variable FOO up one nesting level it'll
1125 be CHAIN->FOO. For two levels it'll be CHAIN->__chain->FOO. Further
1126 indirections apply to decls for which use_pointer_in_frame is true. */
1127
1128 static tree
1129 convert_nonlocal_reference_op (tree *tp, int *walk_subtrees, void *data)
1130 {
1131 struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
1132 struct nesting_info *const info = (struct nesting_info *) wi->info;
1133 tree t = *tp;
1134
1135 *walk_subtrees = 0;
1136 switch (TREE_CODE (t))
1137 {
1138 case VAR_DECL:
1139 /* Non-automatic variables are never processed. */
1140 if (TREE_STATIC (t) || DECL_EXTERNAL (t))
1141 break;
1142 /* FALLTHRU */
1143
1144 case PARM_DECL:
1145 {
1146 tree x, target_context = decl_function_context (t);
1147
1148 if (info->context == target_context)
1149 break;
1150
1151 wi->changed = true;
1152
1153 if (bitmap_bit_p (info->suppress_expansion, DECL_UID (t)))
1154 x = get_nonlocal_debug_decl (info, t);
1155 else
1156 {
1157 struct nesting_info *i = info;
1158 while (i && i->context != target_context)
1159 i = i->outer;
1160 /* If none of the outer contexts is the target context, this means
1161 that the VAR or PARM_DECL is referenced in a wrong context. */
1162 if (!i)
1163 internal_error ("%s from %s referenced in %s",
1164 IDENTIFIER_POINTER (DECL_NAME (t)),
1165 IDENTIFIER_POINTER (DECL_NAME (target_context)),
1166 IDENTIFIER_POINTER (DECL_NAME (info->context)));
1167
1168 x = lookup_field_for_decl (i, t, INSERT);
1169 x = get_frame_field (info, target_context, x, &wi->gsi);
1170 if (use_pointer_in_frame (t))
1171 {
1172 x = init_tmp_var (info, x, &wi->gsi);
1173 x = build_simple_mem_ref_notrap (x);
1174 }
1175 }
1176
1177 if (wi->val_only)
1178 {
1179 if (wi->is_lhs)
1180 x = save_tmp_var (info, x, &wi->gsi);
1181 else
1182 x = init_tmp_var (info, x, &wi->gsi);
1183 }
1184
1185 *tp = x;
1186 }
1187 break;
1188
1189 case LABEL_DECL:
1190 /* We're taking the address of a label from a parent function, but
1191 this is not itself a non-local goto. Mark the label such that it
1192 will not be deleted, much as we would with a label address in
1193 static storage. */
1194 if (decl_function_context (t) != info->context)
1195 FORCED_LABEL (t) = 1;
1196 break;
1197
1198 case ADDR_EXPR:
1199 {
1200 bool save_val_only = wi->val_only;
1201
1202 wi->val_only = false;
1203 wi->is_lhs = false;
1204 wi->changed = false;
1205 walk_tree (&TREE_OPERAND (t, 0), convert_nonlocal_reference_op, wi, 0);
1206 wi->val_only = true;
1207
1208 if (wi->changed)
1209 {
1210 tree save_context;
1211
1212 /* If we changed anything, we might no longer be directly
1213 referencing a decl. */
1214 save_context = current_function_decl;
1215 current_function_decl = info->context;
1216 recompute_tree_invariant_for_addr_expr (t);
1217 current_function_decl = save_context;
1218
1219 /* If the callback converted the address argument in a context
1220 where we only accept variables (and min_invariant, presumably),
1221 then compute the address into a temporary. */
1222 if (save_val_only)
1223 *tp = gsi_gimplify_val ((struct nesting_info *) wi->info,
1224 t, &wi->gsi);
1225 }
1226 }
1227 break;
1228
1229 case REALPART_EXPR:
1230 case IMAGPART_EXPR:
1231 case COMPONENT_REF:
1232 case ARRAY_REF:
1233 case ARRAY_RANGE_REF:
1234 case BIT_FIELD_REF:
1235 /* Go down this entire nest and just look at the final prefix and
1236 anything that describes the references. Otherwise, we lose track
1237 of whether a NOP_EXPR or VIEW_CONVERT_EXPR needs a simple value. */
1238 wi->val_only = true;
1239 wi->is_lhs = false;
1240 for (; handled_component_p (t); tp = &TREE_OPERAND (t, 0), t = *tp)
1241 {
1242 if (TREE_CODE (t) == COMPONENT_REF)
1243 walk_tree (&TREE_OPERAND (t, 2), convert_nonlocal_reference_op, wi,
1244 NULL);
1245 else if (TREE_CODE (t) == ARRAY_REF
1246 || TREE_CODE (t) == ARRAY_RANGE_REF)
1247 {
1248 walk_tree (&TREE_OPERAND (t, 1), convert_nonlocal_reference_op,
1249 wi, NULL);
1250 walk_tree (&TREE_OPERAND (t, 2), convert_nonlocal_reference_op,
1251 wi, NULL);
1252 walk_tree (&TREE_OPERAND (t, 3), convert_nonlocal_reference_op,
1253 wi, NULL);
1254 }
1255 }
1256 wi->val_only = false;
1257 walk_tree (tp, convert_nonlocal_reference_op, wi, NULL);
1258 break;
1259
1260 case VIEW_CONVERT_EXPR:
1261 /* Just request to look at the subtrees, leaving val_only and lhs
1262 untouched. This might actually be for !val_only + lhs, in which
1263 case we don't want to force a replacement by a temporary. */
1264 *walk_subtrees = 1;
1265 break;
1266
1267 default:
1268 if (!IS_TYPE_OR_DECL_P (t))
1269 {
1270 *walk_subtrees = 1;
1271 wi->val_only = true;
1272 wi->is_lhs = false;
1273 }
1274 break;
1275 }
1276
1277 return NULL_TREE;
1278 }
1279
1280 static tree convert_nonlocal_reference_stmt (gimple_stmt_iterator *, bool *,
1281 struct walk_stmt_info *);
1282
1283 /* Helper for convert_nonlocal_references, rewrite all references to VAR
1284 and PARM_DECLs that belong to outer functions. */
1285
1286 static bool
1287 convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
1288 {
1289 struct nesting_info *const info = (struct nesting_info *) wi->info;
1290 bool need_chain = false, need_stmts = false;
1291 tree clause, decl, *pdecl;
1292 int dummy;
1293 bitmap new_suppress;
1294
1295 new_suppress = BITMAP_GGC_ALLOC ();
1296 bitmap_copy (new_suppress, info->suppress_expansion);
1297
1298 for (clause = *pclauses; clause ; clause = OMP_CLAUSE_CHAIN (clause))
1299 {
1300 pdecl = NULL;
1301 switch (OMP_CLAUSE_CODE (clause))
1302 {
1303 case OMP_CLAUSE_REDUCTION:
1304 case OMP_CLAUSE_IN_REDUCTION:
1305 case OMP_CLAUSE_TASK_REDUCTION:
1306 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
1307 need_stmts = true;
1308 if (TREE_CODE (OMP_CLAUSE_DECL (clause)) == MEM_REF)
1309 {
1310 pdecl = &TREE_OPERAND (OMP_CLAUSE_DECL (clause), 0);
1311 if (TREE_CODE (*pdecl) == POINTER_PLUS_EXPR)
1312 pdecl = &TREE_OPERAND (*pdecl, 0);
1313 if (TREE_CODE (*pdecl) == INDIRECT_REF
1314 || TREE_CODE (*pdecl) == ADDR_EXPR)
1315 pdecl = &TREE_OPERAND (*pdecl, 0);
1316 }
1317 goto do_decl_clause;
1318
1319 case OMP_CLAUSE_LASTPRIVATE:
1320 if (OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (clause))
1321 need_stmts = true;
1322 goto do_decl_clause;
1323
1324 case OMP_CLAUSE_LINEAR:
1325 if (OMP_CLAUSE_LINEAR_GIMPLE_SEQ (clause))
1326 need_stmts = true;
1327 wi->val_only = true;
1328 wi->is_lhs = false;
1329 convert_nonlocal_reference_op (&OMP_CLAUSE_LINEAR_STEP (clause),
1330 &dummy, wi);
1331 goto do_decl_clause;
1332
1333 case OMP_CLAUSE_PRIVATE:
1334 case OMP_CLAUSE_FIRSTPRIVATE:
1335 case OMP_CLAUSE_COPYPRIVATE:
1336 case OMP_CLAUSE_SHARED:
1337 case OMP_CLAUSE_TO_DECLARE:
1338 case OMP_CLAUSE_LINK:
1339 case OMP_CLAUSE_USE_DEVICE_PTR:
1340 case OMP_CLAUSE_USE_DEVICE_ADDR:
1341 case OMP_CLAUSE_IS_DEVICE_PTR:
1342 do_decl_clause:
1343 if (pdecl == NULL)
1344 pdecl = &OMP_CLAUSE_DECL (clause);
1345 decl = *pdecl;
1346 if (VAR_P (decl)
1347 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
1348 break;
1349 if (decl_function_context (decl) != info->context)
1350 {
1351 if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_SHARED)
1352 OMP_CLAUSE_SHARED_READONLY (clause) = 0;
1353 bitmap_set_bit (new_suppress, DECL_UID (decl));
1354 *pdecl = get_nonlocal_debug_decl (info, decl);
1355 if (OMP_CLAUSE_CODE (clause) != OMP_CLAUSE_PRIVATE)
1356 need_chain = true;
1357 }
1358 break;
1359
1360 case OMP_CLAUSE_SCHEDULE:
1361 if (OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clause) == NULL)
1362 break;
1363 /* FALLTHRU */
1364 case OMP_CLAUSE_FINAL:
1365 case OMP_CLAUSE_IF:
1366 case OMP_CLAUSE_NUM_THREADS:
1367 case OMP_CLAUSE_DEPEND:
1368 case OMP_CLAUSE_DEVICE:
1369 case OMP_CLAUSE_NUM_TEAMS:
1370 case OMP_CLAUSE_THREAD_LIMIT:
1371 case OMP_CLAUSE_SAFELEN:
1372 case OMP_CLAUSE_SIMDLEN:
1373 case OMP_CLAUSE_PRIORITY:
1374 case OMP_CLAUSE_GRAINSIZE:
1375 case OMP_CLAUSE_NUM_TASKS:
1376 case OMP_CLAUSE_HINT:
1377 case OMP_CLAUSE_NUM_GANGS:
1378 case OMP_CLAUSE_NUM_WORKERS:
1379 case OMP_CLAUSE_VECTOR_LENGTH:
1380 case OMP_CLAUSE_GANG:
1381 case OMP_CLAUSE_WORKER:
1382 case OMP_CLAUSE_VECTOR:
1383 case OMP_CLAUSE_ASYNC:
1384 case OMP_CLAUSE_WAIT:
1385 /* Several OpenACC clauses have optional arguments. Check if they
1386 are present. */
1387 if (OMP_CLAUSE_OPERAND (clause, 0))
1388 {
1389 wi->val_only = true;
1390 wi->is_lhs = false;
1391 convert_nonlocal_reference_op (&OMP_CLAUSE_OPERAND (clause, 0),
1392 &dummy, wi);
1393 }
1394
1395 /* The gang clause accepts two arguments. */
1396 if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_GANG
1397 && OMP_CLAUSE_GANG_STATIC_EXPR (clause))
1398 {
1399 wi->val_only = true;
1400 wi->is_lhs = false;
1401 convert_nonlocal_reference_op
1402 (&OMP_CLAUSE_GANG_STATIC_EXPR (clause), &dummy, wi);
1403 }
1404 break;
1405
1406 case OMP_CLAUSE_DIST_SCHEDULE:
1407 if (OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (clause) != NULL)
1408 {
1409 wi->val_only = true;
1410 wi->is_lhs = false;
1411 convert_nonlocal_reference_op (&OMP_CLAUSE_OPERAND (clause, 0),
1412 &dummy, wi);
1413 }
1414 break;
1415
1416 case OMP_CLAUSE_MAP:
1417 case OMP_CLAUSE_TO:
1418 case OMP_CLAUSE_FROM:
1419 if (OMP_CLAUSE_SIZE (clause))
1420 {
1421 wi->val_only = true;
1422 wi->is_lhs = false;
1423 convert_nonlocal_reference_op (&OMP_CLAUSE_SIZE (clause),
1424 &dummy, wi);
1425 }
1426 if (DECL_P (OMP_CLAUSE_DECL (clause)))
1427 goto do_decl_clause;
1428 wi->val_only = true;
1429 wi->is_lhs = false;
1430 walk_tree (&OMP_CLAUSE_DECL (clause), convert_nonlocal_reference_op,
1431 wi, NULL);
1432 break;
1433
1434 case OMP_CLAUSE_ALIGNED:
1435 if (OMP_CLAUSE_ALIGNED_ALIGNMENT (clause))
1436 {
1437 wi->val_only = true;
1438 wi->is_lhs = false;
1439 convert_nonlocal_reference_op
1440 (&OMP_CLAUSE_ALIGNED_ALIGNMENT (clause), &dummy, wi);
1441 }
1442 /* FALLTHRU */
1443 case OMP_CLAUSE_NONTEMPORAL:
1444 do_decl_clause_no_supp:
1445 /* Like do_decl_clause, but don't add any suppression. */
1446 decl = OMP_CLAUSE_DECL (clause);
1447 if (VAR_P (decl)
1448 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
1449 break;
1450 if (decl_function_context (decl) != info->context)
1451 {
1452 OMP_CLAUSE_DECL (clause) = get_nonlocal_debug_decl (info, decl);
1453 need_chain = true;
1454 }
1455 break;
1456
1457 case OMP_CLAUSE_ALLOCATE:
1458 if (OMP_CLAUSE_ALLOCATE_ALLOCATOR (clause))
1459 {
1460 wi->val_only = true;
1461 wi->is_lhs = false;
1462 convert_nonlocal_reference_op
1463 (&OMP_CLAUSE_ALLOCATE_ALLOCATOR (clause), &dummy, wi);
1464 }
1465 goto do_decl_clause_no_supp;
1466
1467 case OMP_CLAUSE_NOWAIT:
1468 case OMP_CLAUSE_ORDERED:
1469 case OMP_CLAUSE_DEFAULT:
1470 case OMP_CLAUSE_COPYIN:
1471 case OMP_CLAUSE_COLLAPSE:
1472 case OMP_CLAUSE_TILE:
1473 case OMP_CLAUSE_UNTIED:
1474 case OMP_CLAUSE_MERGEABLE:
1475 case OMP_CLAUSE_PROC_BIND:
1476 case OMP_CLAUSE_NOGROUP:
1477 case OMP_CLAUSE_THREADS:
1478 case OMP_CLAUSE_SIMD:
1479 case OMP_CLAUSE_DEFAULTMAP:
1480 case OMP_CLAUSE_ORDER:
1481 case OMP_CLAUSE_SEQ:
1482 case OMP_CLAUSE_INDEPENDENT:
1483 case OMP_CLAUSE_AUTO:
1484 case OMP_CLAUSE_IF_PRESENT:
1485 case OMP_CLAUSE_FINALIZE:
1486 case OMP_CLAUSE__CONDTEMP_:
1487 case OMP_CLAUSE__SCANTEMP_:
1488 break;
1489
1490 /* The following clause belongs to the OpenACC cache directive, which
1491 is discarded during gimplification. */
1492 case OMP_CLAUSE__CACHE_:
1493 /* The following clauses are only allowed in the OpenMP declare simd
1494 directive, so not seen here. */
1495 case OMP_CLAUSE_UNIFORM:
1496 case OMP_CLAUSE_INBRANCH:
1497 case OMP_CLAUSE_NOTINBRANCH:
1498 /* The following clauses are only allowed on OpenMP cancel and
1499 cancellation point directives, which at this point have already
1500 been lowered into a function call. */
1501 case OMP_CLAUSE_FOR:
1502 case OMP_CLAUSE_PARALLEL:
1503 case OMP_CLAUSE_SECTIONS:
1504 case OMP_CLAUSE_TASKGROUP:
1505 /* The following clauses are only added during OMP lowering; nested
1506 function decomposition happens before that. */
1507 case OMP_CLAUSE__LOOPTEMP_:
1508 case OMP_CLAUSE__REDUCTEMP_:
1509 case OMP_CLAUSE__SIMDUID_:
1510 case OMP_CLAUSE__SIMT_:
1511 /* Anything else. */
1512 default:
1513 gcc_unreachable ();
1514 }
1515 }
1516
1517 info->suppress_expansion = new_suppress;
1518
1519 if (need_stmts)
1520 for (clause = *pclauses; clause ; clause = OMP_CLAUSE_CHAIN (clause))
1521 switch (OMP_CLAUSE_CODE (clause))
1522 {
1523 case OMP_CLAUSE_REDUCTION:
1524 case OMP_CLAUSE_IN_REDUCTION:
1525 case OMP_CLAUSE_TASK_REDUCTION:
1526 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
1527 {
1528 tree old_context
1529 = DECL_CONTEXT (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause));
1530 DECL_CONTEXT (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
1531 = info->context;
1532 if (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
1533 DECL_CONTEXT (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
1534 = info->context;
1535 tree save_local_var_chain = info->new_local_var_chain;
1536 info->new_local_var_chain = NULL;
1537 gimple_seq *seq = &OMP_CLAUSE_REDUCTION_GIMPLE_INIT (clause);
1538 walk_body (convert_nonlocal_reference_stmt,
1539 convert_nonlocal_reference_op, info, seq);
1540 if (info->new_local_var_chain)
1541 declare_vars (info->new_local_var_chain,
1542 gimple_seq_first_stmt (*seq), false);
1543 info->new_local_var_chain = NULL;
1544 seq = &OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (clause);
1545 walk_body (convert_nonlocal_reference_stmt,
1546 convert_nonlocal_reference_op, info, seq);
1547 if (info->new_local_var_chain)
1548 declare_vars (info->new_local_var_chain,
1549 gimple_seq_first_stmt (*seq), false);
1550 info->new_local_var_chain = save_local_var_chain;
1551 DECL_CONTEXT (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
1552 = old_context;
1553 if (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
1554 DECL_CONTEXT (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
1555 = old_context;
1556 }
1557 break;
1558
1559 case OMP_CLAUSE_LASTPRIVATE:
1560 {
1561 tree save_local_var_chain = info->new_local_var_chain;
1562 info->new_local_var_chain = NULL;
1563 gimple_seq *seq = &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (clause);
1564 walk_body (convert_nonlocal_reference_stmt,
1565 convert_nonlocal_reference_op, info, seq);
1566 if (info->new_local_var_chain)
1567 declare_vars (info->new_local_var_chain,
1568 gimple_seq_first_stmt (*seq), false);
1569 info->new_local_var_chain = save_local_var_chain;
1570 }
1571 break;
1572
1573 case OMP_CLAUSE_LINEAR:
1574 {
1575 tree save_local_var_chain = info->new_local_var_chain;
1576 info->new_local_var_chain = NULL;
1577 gimple_seq *seq = &OMP_CLAUSE_LINEAR_GIMPLE_SEQ (clause);
1578 walk_body (convert_nonlocal_reference_stmt,
1579 convert_nonlocal_reference_op, info, seq);
1580 if (info->new_local_var_chain)
1581 declare_vars (info->new_local_var_chain,
1582 gimple_seq_first_stmt (*seq), false);
1583 info->new_local_var_chain = save_local_var_chain;
1584 }
1585 break;
1586
1587 default:
1588 break;
1589 }
1590
1591 return need_chain;
1592 }
1593
1594 /* Create nonlocal debug decls for nonlocal VLA array bounds. */
1595
1596 static void
1597 note_nonlocal_vla_type (struct nesting_info *info, tree type)
1598 {
1599 while (POINTER_TYPE_P (type) && !TYPE_NAME (type))
1600 type = TREE_TYPE (type);
1601
1602 if (TYPE_NAME (type)
1603 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1604 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1605 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
1606
1607 while (POINTER_TYPE_P (type)
1608 || TREE_CODE (type) == VECTOR_TYPE
1609 || TREE_CODE (type) == FUNCTION_TYPE
1610 || TREE_CODE (type) == METHOD_TYPE)
1611 type = TREE_TYPE (type);
1612
1613 if (TREE_CODE (type) == ARRAY_TYPE)
1614 {
1615 tree domain, t;
1616
1617 note_nonlocal_vla_type (info, TREE_TYPE (type));
1618 domain = TYPE_DOMAIN (type);
1619 if (domain)
1620 {
1621 t = TYPE_MIN_VALUE (domain);
1622 if (t && (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
1623 && decl_function_context (t) != info->context)
1624 get_nonlocal_debug_decl (info, t);
1625 t = TYPE_MAX_VALUE (domain);
1626 if (t && (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
1627 && decl_function_context (t) != info->context)
1628 get_nonlocal_debug_decl (info, t);
1629 }
1630 }
1631 }
1632
1633 /* Callback for walk_gimple_stmt. Rewrite all references to VAR and
1634 PARM_DECLs that belong to outer functions. This handles statements
1635 that are not handled via the standard recursion done in
1636 walk_gimple_stmt. STMT is the statement to examine, DATA is as in
1637 convert_nonlocal_reference_op. Set *HANDLED_OPS_P to true if all the
1638 operands of STMT have been handled by this function. */
1639
1640 static tree
1641 convert_nonlocal_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
1642 struct walk_stmt_info *wi)
1643 {
1644 struct nesting_info *info = (struct nesting_info *) wi->info;
1645 tree save_local_var_chain;
1646 bitmap save_suppress;
1647 gimple *stmt = gsi_stmt (*gsi);
1648
1649 switch (gimple_code (stmt))
1650 {
1651 case GIMPLE_GOTO:
1652 /* Don't walk non-local gotos for now. */
1653 if (TREE_CODE (gimple_goto_dest (stmt)) != LABEL_DECL)
1654 {
1655 wi->val_only = true;
1656 wi->is_lhs = false;
1657 *handled_ops_p = false;
1658 return NULL_TREE;
1659 }
1660 break;
1661
1662 case GIMPLE_OMP_TEAMS:
1663 if (!gimple_omp_teams_host (as_a <gomp_teams *> (stmt)))
1664 {
1665 save_suppress = info->suppress_expansion;
1666 convert_nonlocal_omp_clauses (gimple_omp_teams_clauses_ptr (stmt),
1667 wi);
1668 walk_body (convert_nonlocal_reference_stmt,
1669 convert_nonlocal_reference_op, info,
1670 gimple_omp_body_ptr (stmt));
1671 info->suppress_expansion = save_suppress;
1672 break;
1673 }
1674 /* FALLTHRU */
1675
1676 case GIMPLE_OMP_PARALLEL:
1677 case GIMPLE_OMP_TASK:
1678 save_suppress = info->suppress_expansion;
1679 if (convert_nonlocal_omp_clauses (gimple_omp_taskreg_clauses_ptr (stmt),
1680 wi))
1681 {
1682 tree c, decl;
1683 decl = get_chain_decl (info);
1684 c = build_omp_clause (gimple_location (stmt),
1685 OMP_CLAUSE_FIRSTPRIVATE);
1686 OMP_CLAUSE_DECL (c) = decl;
1687 OMP_CLAUSE_CHAIN (c) = gimple_omp_taskreg_clauses (stmt);
1688 gimple_omp_taskreg_set_clauses (stmt, c);
1689 }
1690
1691 save_local_var_chain = info->new_local_var_chain;
1692 info->new_local_var_chain = NULL;
1693
1694 walk_body (convert_nonlocal_reference_stmt, convert_nonlocal_reference_op,
1695 info, gimple_omp_body_ptr (stmt));
1696
1697 if (info->new_local_var_chain)
1698 declare_vars (info->new_local_var_chain,
1699 gimple_seq_first_stmt (gimple_omp_body (stmt)),
1700 false);
1701 info->new_local_var_chain = save_local_var_chain;
1702 info->suppress_expansion = save_suppress;
1703 break;
1704
1705 case GIMPLE_OMP_FOR:
1706 save_suppress = info->suppress_expansion;
1707 convert_nonlocal_omp_clauses (gimple_omp_for_clauses_ptr (stmt), wi);
1708 walk_gimple_omp_for (as_a <gomp_for *> (stmt),
1709 convert_nonlocal_reference_stmt,
1710 convert_nonlocal_reference_op, info);
1711 walk_body (convert_nonlocal_reference_stmt,
1712 convert_nonlocal_reference_op, info, gimple_omp_body_ptr (stmt));
1713 info->suppress_expansion = save_suppress;
1714 break;
1715
1716 case GIMPLE_OMP_SECTIONS:
1717 save_suppress = info->suppress_expansion;
1718 convert_nonlocal_omp_clauses (gimple_omp_sections_clauses_ptr (stmt), wi);
1719 walk_body (convert_nonlocal_reference_stmt, convert_nonlocal_reference_op,
1720 info, gimple_omp_body_ptr (stmt));
1721 info->suppress_expansion = save_suppress;
1722 break;
1723
1724 case GIMPLE_OMP_SINGLE:
1725 save_suppress = info->suppress_expansion;
1726 convert_nonlocal_omp_clauses (gimple_omp_single_clauses_ptr (stmt), wi);
1727 walk_body (convert_nonlocal_reference_stmt, convert_nonlocal_reference_op,
1728 info, gimple_omp_body_ptr (stmt));
1729 info->suppress_expansion = save_suppress;
1730 break;
1731
1732 case GIMPLE_OMP_TASKGROUP:
1733 save_suppress = info->suppress_expansion;
1734 convert_nonlocal_omp_clauses (gimple_omp_taskgroup_clauses_ptr (stmt), wi);
1735 walk_body (convert_nonlocal_reference_stmt, convert_nonlocal_reference_op,
1736 info, gimple_omp_body_ptr (stmt));
1737 info->suppress_expansion = save_suppress;
1738 break;
1739
1740 case GIMPLE_OMP_TARGET:
1741 if (!is_gimple_omp_offloaded (stmt))
1742 {
1743 save_suppress = info->suppress_expansion;
1744 convert_nonlocal_omp_clauses (gimple_omp_target_clauses_ptr (stmt),
1745 wi);
1746 info->suppress_expansion = save_suppress;
1747 walk_body (convert_nonlocal_reference_stmt,
1748 convert_nonlocal_reference_op, info,
1749 gimple_omp_body_ptr (stmt));
1750 break;
1751 }
1752 save_suppress = info->suppress_expansion;
1753 if (convert_nonlocal_omp_clauses (gimple_omp_target_clauses_ptr (stmt),
1754 wi))
1755 {
1756 tree c, decl;
1757 decl = get_chain_decl (info);
1758 c = build_omp_clause (gimple_location (stmt), OMP_CLAUSE_MAP);
1759 OMP_CLAUSE_DECL (c) = decl;
1760 OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
1761 OMP_CLAUSE_SIZE (c) = DECL_SIZE_UNIT (decl);
1762 OMP_CLAUSE_CHAIN (c) = gimple_omp_target_clauses (stmt);
1763 gimple_omp_target_set_clauses (as_a <gomp_target *> (stmt), c);
1764 }
1765
1766 save_local_var_chain = info->new_local_var_chain;
1767 info->new_local_var_chain = NULL;
1768
1769 walk_body (convert_nonlocal_reference_stmt, convert_nonlocal_reference_op,
1770 info, gimple_omp_body_ptr (stmt));
1771
1772 if (info->new_local_var_chain)
1773 declare_vars (info->new_local_var_chain,
1774 gimple_seq_first_stmt (gimple_omp_body (stmt)),
1775 false);
1776 info->new_local_var_chain = save_local_var_chain;
1777 info->suppress_expansion = save_suppress;
1778 break;
1779
1780 case GIMPLE_OMP_SECTION:
1781 case GIMPLE_OMP_MASTER:
1782 case GIMPLE_OMP_ORDERED:
1783 case GIMPLE_OMP_SCAN:
1784 walk_body (convert_nonlocal_reference_stmt, convert_nonlocal_reference_op,
1785 info, gimple_omp_body_ptr (stmt));
1786 break;
1787
1788 case GIMPLE_BIND:
1789 {
1790 gbind *bind_stmt = as_a <gbind *> (stmt);
1791
1792 for (tree var = gimple_bind_vars (bind_stmt); var; var = DECL_CHAIN (var))
1793 if (TREE_CODE (var) == NAMELIST_DECL)
1794 {
1795 /* Adjust decls mentioned in NAMELIST_DECL. */
1796 tree decls = NAMELIST_DECL_ASSOCIATED_DECL (var);
1797 tree decl;
1798 unsigned int i;
1799
1800 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (decls), i, decl)
1801 {
1802 if (VAR_P (decl)
1803 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
1804 continue;
1805 if (decl_function_context (decl) != info->context)
1806 CONSTRUCTOR_ELT (decls, i)->value
1807 = get_nonlocal_debug_decl (info, decl);
1808 }
1809 }
1810
1811 *handled_ops_p = false;
1812 return NULL_TREE;
1813 }
1814 case GIMPLE_COND:
1815 wi->val_only = true;
1816 wi->is_lhs = false;
1817 *handled_ops_p = false;
1818 return NULL_TREE;
1819
1820 case GIMPLE_ASSIGN:
1821 if (gimple_clobber_p (stmt))
1822 {
1823 tree lhs = gimple_assign_lhs (stmt);
1824 if (DECL_P (lhs)
1825 && !(TREE_STATIC (lhs) || DECL_EXTERNAL (lhs))
1826 && decl_function_context (lhs) != info->context)
1827 {
1828 gsi_replace (gsi, gimple_build_nop (), true);
1829 break;
1830 }
1831 }
1832 *handled_ops_p = false;
1833 return NULL_TREE;
1834
1835 default:
1836 /* For every other statement that we are not interested in
1837 handling here, let the walker traverse the operands. */
1838 *handled_ops_p = false;
1839 return NULL_TREE;
1840 }
1841
1842 /* We have handled all of STMT operands, no need to traverse the operands. */
1843 *handled_ops_p = true;
1844 return NULL_TREE;
1845 }
1846
1847
1848 /* A subroutine of convert_local_reference. Create a local variable
1849 in the parent function with DECL_VALUE_EXPR set to reference the
1850 field in FRAME. This is used both for debug info and in OMP
1851 lowering. */
1852
1853 static tree
1854 get_local_debug_decl (struct nesting_info *info, tree decl, tree field)
1855 {
1856 tree x, new_decl;
1857
1858 tree *slot = &info->var_map->get_or_insert (decl);
1859 if (*slot)
1860 return *slot;
1861
1862 /* Make sure frame_decl gets created. */
1863 (void) get_frame_type (info);
1864 x = info->frame_decl;
1865 x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE);
1866
1867 new_decl = build_decl (DECL_SOURCE_LOCATION (decl),
1868 VAR_DECL, DECL_NAME (decl), TREE_TYPE (decl));
1869 DECL_CONTEXT (new_decl) = info->context;
1870 DECL_ARTIFICIAL (new_decl) = DECL_ARTIFICIAL (decl);
1871 DECL_IGNORED_P (new_decl) = DECL_IGNORED_P (decl);
1872 TREE_THIS_VOLATILE (new_decl) = TREE_THIS_VOLATILE (decl);
1873 TREE_SIDE_EFFECTS (new_decl) = TREE_SIDE_EFFECTS (decl);
1874 TREE_READONLY (new_decl) = TREE_READONLY (decl);
1875 TREE_ADDRESSABLE (new_decl) = TREE_ADDRESSABLE (decl);
1876 DECL_SEEN_IN_BIND_EXPR_P (new_decl) = 1;
1877 if ((TREE_CODE (decl) == PARM_DECL
1878 || TREE_CODE (decl) == RESULT_DECL
1879 || VAR_P (decl))
1880 && DECL_BY_REFERENCE (decl))
1881 DECL_BY_REFERENCE (new_decl) = 1;
1882
1883 SET_DECL_VALUE_EXPR (new_decl, x);
1884 DECL_HAS_VALUE_EXPR_P (new_decl) = 1;
1885 *slot = new_decl;
1886
1887 DECL_CHAIN (new_decl) = info->debug_var_chain;
1888 info->debug_var_chain = new_decl;
1889
1890 /* Do not emit debug info twice. */
1891 DECL_IGNORED_P (decl) = 1;
1892
1893 return new_decl;
1894 }
1895
1896
1897 /* Called via walk_function+walk_gimple_stmt, rewrite all references to VAR
1898 and PARM_DECLs that were referenced by inner nested functions.
1899 The rewrite will be a structure reference to the local frame variable. */
1900
1901 static bool convert_local_omp_clauses (tree *, struct walk_stmt_info *);
1902
1903 static tree
1904 convert_local_reference_op (tree *tp, int *walk_subtrees, void *data)
1905 {
1906 struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
1907 struct nesting_info *const info = (struct nesting_info *) wi->info;
1908 tree t = *tp, field, x;
1909 bool save_val_only;
1910
1911 *walk_subtrees = 0;
1912 switch (TREE_CODE (t))
1913 {
1914 case VAR_DECL:
1915 /* Non-automatic variables are never processed. */
1916 if (TREE_STATIC (t) || DECL_EXTERNAL (t))
1917 break;
1918 /* FALLTHRU */
1919
1920 case PARM_DECL:
1921 if (t != info->frame_decl && decl_function_context (t) == info->context)
1922 {
1923 /* If we copied a pointer to the frame, then the original decl
1924 is used unchanged in the parent function. */
1925 if (use_pointer_in_frame (t))
1926 break;
1927
1928 /* No need to transform anything if no child references the
1929 variable. */
1930 field = lookup_field_for_decl (info, t, NO_INSERT);
1931 if (!field)
1932 break;
1933 wi->changed = true;
1934
1935 if (bitmap_bit_p (info->suppress_expansion, DECL_UID (t)))
1936 x = get_local_debug_decl (info, t, field);
1937 else
1938 x = get_frame_field (info, info->context, field, &wi->gsi);
1939
1940 if (wi->val_only)
1941 {
1942 if (wi->is_lhs)
1943 x = save_tmp_var (info, x, &wi->gsi);
1944 else
1945 x = init_tmp_var (info, x, &wi->gsi);
1946 }
1947
1948 *tp = x;
1949 }
1950 break;
1951
1952 case ADDR_EXPR:
1953 save_val_only = wi->val_only;
1954 wi->val_only = false;
1955 wi->is_lhs = false;
1956 wi->changed = false;
1957 walk_tree (&TREE_OPERAND (t, 0), convert_local_reference_op, wi, NULL);
1958 wi->val_only = save_val_only;
1959
1960 /* If we converted anything ... */
1961 if (wi->changed)
1962 {
1963 tree save_context;
1964
1965 /* Then the frame decl is now addressable. */
1966 TREE_ADDRESSABLE (info->frame_decl) = 1;
1967
1968 save_context = current_function_decl;
1969 current_function_decl = info->context;
1970 recompute_tree_invariant_for_addr_expr (t);
1971 current_function_decl = save_context;
1972
1973 /* If we are in a context where we only accept values, then
1974 compute the address into a temporary. */
1975 if (save_val_only)
1976 *tp = gsi_gimplify_val ((struct nesting_info *) wi->info,
1977 t, &wi->gsi);
1978 }
1979 break;
1980
1981 case REALPART_EXPR:
1982 case IMAGPART_EXPR:
1983 case COMPONENT_REF:
1984 case ARRAY_REF:
1985 case ARRAY_RANGE_REF:
1986 case BIT_FIELD_REF:
1987 /* Go down this entire nest and just look at the final prefix and
1988 anything that describes the references. Otherwise, we lose track
1989 of whether a NOP_EXPR or VIEW_CONVERT_EXPR needs a simple value. */
1990 save_val_only = wi->val_only;
1991 wi->val_only = true;
1992 wi->is_lhs = false;
1993 for (; handled_component_p (t); tp = &TREE_OPERAND (t, 0), t = *tp)
1994 {
1995 if (TREE_CODE (t) == COMPONENT_REF)
1996 walk_tree (&TREE_OPERAND (t, 2), convert_local_reference_op, wi,
1997 NULL);
1998 else if (TREE_CODE (t) == ARRAY_REF
1999 || TREE_CODE (t) == ARRAY_RANGE_REF)
2000 {
2001 walk_tree (&TREE_OPERAND (t, 1), convert_local_reference_op, wi,
2002 NULL);
2003 walk_tree (&TREE_OPERAND (t, 2), convert_local_reference_op, wi,
2004 NULL);
2005 walk_tree (&TREE_OPERAND (t, 3), convert_local_reference_op, wi,
2006 NULL);
2007 }
2008 }
2009 wi->val_only = false;
2010 walk_tree (tp, convert_local_reference_op, wi, NULL);
2011 wi->val_only = save_val_only;
2012 break;
2013
2014 case MEM_REF:
2015 save_val_only = wi->val_only;
2016 wi->val_only = true;
2017 wi->is_lhs = false;
2018 walk_tree (&TREE_OPERAND (t, 0), convert_local_reference_op,
2019 wi, NULL);
2020 /* We need to re-fold the MEM_REF as component references as
2021 part of a ADDR_EXPR address are not allowed. But we cannot
2022 fold here, as the chain record type is not yet finalized. */
2023 if (TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR
2024 && !DECL_P (TREE_OPERAND (TREE_OPERAND (t, 0), 0)))
2025 info->mem_refs->add (tp);
2026 wi->val_only = save_val_only;
2027 break;
2028
2029 case VIEW_CONVERT_EXPR:
2030 /* Just request to look at the subtrees, leaving val_only and lhs
2031 untouched. This might actually be for !val_only + lhs, in which
2032 case we don't want to force a replacement by a temporary. */
2033 *walk_subtrees = 1;
2034 break;
2035
2036 default:
2037 if (!IS_TYPE_OR_DECL_P (t))
2038 {
2039 *walk_subtrees = 1;
2040 wi->val_only = true;
2041 wi->is_lhs = false;
2042 }
2043 break;
2044 }
2045
2046 return NULL_TREE;
2047 }
2048
2049 static tree convert_local_reference_stmt (gimple_stmt_iterator *, bool *,
2050 struct walk_stmt_info *);
2051
2052 /* Helper for convert_local_reference. Convert all the references in
2053 the chain of clauses at *PCLAUSES. WI is as in convert_local_reference. */
2054
2055 static bool
2056 convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
2057 {
2058 struct nesting_info *const info = (struct nesting_info *) wi->info;
2059 bool need_frame = false, need_stmts = false;
2060 tree clause, decl, *pdecl;
2061 int dummy;
2062 bitmap new_suppress;
2063
2064 new_suppress = BITMAP_GGC_ALLOC ();
2065 bitmap_copy (new_suppress, info->suppress_expansion);
2066
2067 for (clause = *pclauses; clause ; clause = OMP_CLAUSE_CHAIN (clause))
2068 {
2069 pdecl = NULL;
2070 switch (OMP_CLAUSE_CODE (clause))
2071 {
2072 case OMP_CLAUSE_REDUCTION:
2073 case OMP_CLAUSE_IN_REDUCTION:
2074 case OMP_CLAUSE_TASK_REDUCTION:
2075 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
2076 need_stmts = true;
2077 if (TREE_CODE (OMP_CLAUSE_DECL (clause)) == MEM_REF)
2078 {
2079 pdecl = &TREE_OPERAND (OMP_CLAUSE_DECL (clause), 0);
2080 if (TREE_CODE (*pdecl) == POINTER_PLUS_EXPR)
2081 pdecl = &TREE_OPERAND (*pdecl, 0);
2082 if (TREE_CODE (*pdecl) == INDIRECT_REF
2083 || TREE_CODE (*pdecl) == ADDR_EXPR)
2084 pdecl = &TREE_OPERAND (*pdecl, 0);
2085 }
2086 goto do_decl_clause;
2087
2088 case OMP_CLAUSE_LASTPRIVATE:
2089 if (OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (clause))
2090 need_stmts = true;
2091 goto do_decl_clause;
2092
2093 case OMP_CLAUSE_LINEAR:
2094 if (OMP_CLAUSE_LINEAR_GIMPLE_SEQ (clause))
2095 need_stmts = true;
2096 wi->val_only = true;
2097 wi->is_lhs = false;
2098 convert_local_reference_op (&OMP_CLAUSE_LINEAR_STEP (clause), &dummy,
2099 wi);
2100 goto do_decl_clause;
2101
2102 case OMP_CLAUSE_PRIVATE:
2103 case OMP_CLAUSE_FIRSTPRIVATE:
2104 case OMP_CLAUSE_COPYPRIVATE:
2105 case OMP_CLAUSE_SHARED:
2106 case OMP_CLAUSE_TO_DECLARE:
2107 case OMP_CLAUSE_LINK:
2108 case OMP_CLAUSE_USE_DEVICE_PTR:
2109 case OMP_CLAUSE_USE_DEVICE_ADDR:
2110 case OMP_CLAUSE_IS_DEVICE_PTR:
2111 do_decl_clause:
2112 if (pdecl == NULL)
2113 pdecl = &OMP_CLAUSE_DECL (clause);
2114 decl = *pdecl;
2115 if (VAR_P (decl)
2116 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
2117 break;
2118 if (decl_function_context (decl) == info->context
2119 && !use_pointer_in_frame (decl))
2120 {
2121 tree field = lookup_field_for_decl (info, decl, NO_INSERT);
2122 if (field)
2123 {
2124 if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_SHARED)
2125 OMP_CLAUSE_SHARED_READONLY (clause) = 0;
2126 bitmap_set_bit (new_suppress, DECL_UID (decl));
2127 *pdecl = get_local_debug_decl (info, decl, field);
2128 need_frame = true;
2129 }
2130 }
2131 break;
2132
2133 case OMP_CLAUSE_SCHEDULE:
2134 if (OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clause) == NULL)
2135 break;
2136 /* FALLTHRU */
2137 case OMP_CLAUSE_FINAL:
2138 case OMP_CLAUSE_IF:
2139 case OMP_CLAUSE_NUM_THREADS:
2140 case OMP_CLAUSE_DEPEND:
2141 case OMP_CLAUSE_DEVICE:
2142 case OMP_CLAUSE_NUM_TEAMS:
2143 case OMP_CLAUSE_THREAD_LIMIT:
2144 case OMP_CLAUSE_SAFELEN:
2145 case OMP_CLAUSE_SIMDLEN:
2146 case OMP_CLAUSE_PRIORITY:
2147 case OMP_CLAUSE_GRAINSIZE:
2148 case OMP_CLAUSE_NUM_TASKS:
2149 case OMP_CLAUSE_HINT:
2150 case OMP_CLAUSE_NUM_GANGS:
2151 case OMP_CLAUSE_NUM_WORKERS:
2152 case OMP_CLAUSE_VECTOR_LENGTH:
2153 case OMP_CLAUSE_GANG:
2154 case OMP_CLAUSE_WORKER:
2155 case OMP_CLAUSE_VECTOR:
2156 case OMP_CLAUSE_ASYNC:
2157 case OMP_CLAUSE_WAIT:
2158 /* Several OpenACC clauses have optional arguments. Check if they
2159 are present. */
2160 if (OMP_CLAUSE_OPERAND (clause, 0))
2161 {
2162 wi->val_only = true;
2163 wi->is_lhs = false;
2164 convert_local_reference_op (&OMP_CLAUSE_OPERAND (clause, 0),
2165 &dummy, wi);
2166 }
2167
2168 /* The gang clause accepts two arguments. */
2169 if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_GANG
2170 && OMP_CLAUSE_GANG_STATIC_EXPR (clause))
2171 {
2172 wi->val_only = true;
2173 wi->is_lhs = false;
2174 convert_nonlocal_reference_op
2175 (&OMP_CLAUSE_GANG_STATIC_EXPR (clause), &dummy, wi);
2176 }
2177 break;
2178
2179 case OMP_CLAUSE_DIST_SCHEDULE:
2180 if (OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (clause) != NULL)
2181 {
2182 wi->val_only = true;
2183 wi->is_lhs = false;
2184 convert_local_reference_op (&OMP_CLAUSE_OPERAND (clause, 0),
2185 &dummy, wi);
2186 }
2187 break;
2188
2189 case OMP_CLAUSE_MAP:
2190 case OMP_CLAUSE_TO:
2191 case OMP_CLAUSE_FROM:
2192 if (OMP_CLAUSE_SIZE (clause))
2193 {
2194 wi->val_only = true;
2195 wi->is_lhs = false;
2196 convert_local_reference_op (&OMP_CLAUSE_SIZE (clause),
2197 &dummy, wi);
2198 }
2199 if (DECL_P (OMP_CLAUSE_DECL (clause)))
2200 goto do_decl_clause;
2201 wi->val_only = true;
2202 wi->is_lhs = false;
2203 walk_tree (&OMP_CLAUSE_DECL (clause), convert_local_reference_op,
2204 wi, NULL);
2205 break;
2206
2207 case OMP_CLAUSE_ALIGNED:
2208 if (OMP_CLAUSE_ALIGNED_ALIGNMENT (clause))
2209 {
2210 wi->val_only = true;
2211 wi->is_lhs = false;
2212 convert_local_reference_op
2213 (&OMP_CLAUSE_ALIGNED_ALIGNMENT (clause), &dummy, wi);
2214 }
2215 /* FALLTHRU */
2216 case OMP_CLAUSE_NONTEMPORAL:
2217 do_decl_clause_no_supp:
2218 /* Like do_decl_clause, but don't add any suppression. */
2219 decl = OMP_CLAUSE_DECL (clause);
2220 if (VAR_P (decl)
2221 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
2222 break;
2223 if (decl_function_context (decl) == info->context
2224 && !use_pointer_in_frame (decl))
2225 {
2226 tree field = lookup_field_for_decl (info, decl, NO_INSERT);
2227 if (field)
2228 {
2229 OMP_CLAUSE_DECL (clause)
2230 = get_local_debug_decl (info, decl, field);
2231 need_frame = true;
2232 }
2233 }
2234 break;
2235
2236 case OMP_CLAUSE_ALLOCATE:
2237 if (OMP_CLAUSE_ALLOCATE_ALLOCATOR (clause))
2238 {
2239 wi->val_only = true;
2240 wi->is_lhs = false;
2241 convert_local_reference_op
2242 (&OMP_CLAUSE_ALLOCATE_ALLOCATOR (clause), &dummy, wi);
2243 }
2244 goto do_decl_clause_no_supp;
2245
2246 case OMP_CLAUSE_NOWAIT:
2247 case OMP_CLAUSE_ORDERED:
2248 case OMP_CLAUSE_DEFAULT:
2249 case OMP_CLAUSE_COPYIN:
2250 case OMP_CLAUSE_COLLAPSE:
2251 case OMP_CLAUSE_TILE:
2252 case OMP_CLAUSE_UNTIED:
2253 case OMP_CLAUSE_MERGEABLE:
2254 case OMP_CLAUSE_PROC_BIND:
2255 case OMP_CLAUSE_NOGROUP:
2256 case OMP_CLAUSE_THREADS:
2257 case OMP_CLAUSE_SIMD:
2258 case OMP_CLAUSE_DEFAULTMAP:
2259 case OMP_CLAUSE_ORDER:
2260 case OMP_CLAUSE_SEQ:
2261 case OMP_CLAUSE_INDEPENDENT:
2262 case OMP_CLAUSE_AUTO:
2263 case OMP_CLAUSE_IF_PRESENT:
2264 case OMP_CLAUSE_FINALIZE:
2265 case OMP_CLAUSE__CONDTEMP_:
2266 case OMP_CLAUSE__SCANTEMP_:
2267 break;
2268
2269 /* The following clause belongs to the OpenACC cache directive, which
2270 is discarded during gimplification. */
2271 case OMP_CLAUSE__CACHE_:
2272 /* The following clauses are only allowed in the OpenMP declare simd
2273 directive, so not seen here. */
2274 case OMP_CLAUSE_UNIFORM:
2275 case OMP_CLAUSE_INBRANCH:
2276 case OMP_CLAUSE_NOTINBRANCH:
2277 /* The following clauses are only allowed on OpenMP cancel and
2278 cancellation point directives, which at this point have already
2279 been lowered into a function call. */
2280 case OMP_CLAUSE_FOR:
2281 case OMP_CLAUSE_PARALLEL:
2282 case OMP_CLAUSE_SECTIONS:
2283 case OMP_CLAUSE_TASKGROUP:
2284 /* The following clauses are only added during OMP lowering; nested
2285 function decomposition happens before that. */
2286 case OMP_CLAUSE__LOOPTEMP_:
2287 case OMP_CLAUSE__REDUCTEMP_:
2288 case OMP_CLAUSE__SIMDUID_:
2289 case OMP_CLAUSE__SIMT_:
2290 /* Anything else. */
2291 default:
2292 gcc_unreachable ();
2293 }
2294 }
2295
2296 info->suppress_expansion = new_suppress;
2297
2298 if (need_stmts)
2299 for (clause = *pclauses; clause ; clause = OMP_CLAUSE_CHAIN (clause))
2300 switch (OMP_CLAUSE_CODE (clause))
2301 {
2302 case OMP_CLAUSE_REDUCTION:
2303 case OMP_CLAUSE_IN_REDUCTION:
2304 case OMP_CLAUSE_TASK_REDUCTION:
2305 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
2306 {
2307 tree old_context
2308 = DECL_CONTEXT (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause));
2309 DECL_CONTEXT (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
2310 = info->context;
2311 if (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
2312 DECL_CONTEXT (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
2313 = info->context;
2314 walk_body (convert_local_reference_stmt,
2315 convert_local_reference_op, info,
2316 &OMP_CLAUSE_REDUCTION_GIMPLE_INIT (clause));
2317 walk_body (convert_local_reference_stmt,
2318 convert_local_reference_op, info,
2319 &OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (clause));
2320 DECL_CONTEXT (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause))
2321 = old_context;
2322 if (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
2323 DECL_CONTEXT (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clause))
2324 = old_context;
2325 }
2326 break;
2327
2328 case OMP_CLAUSE_LASTPRIVATE:
2329 walk_body (convert_local_reference_stmt,
2330 convert_local_reference_op, info,
2331 &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (clause));
2332 break;
2333
2334 case OMP_CLAUSE_LINEAR:
2335 walk_body (convert_local_reference_stmt,
2336 convert_local_reference_op, info,
2337 &OMP_CLAUSE_LINEAR_GIMPLE_SEQ (clause));
2338 break;
2339
2340 default:
2341 break;
2342 }
2343
2344 return need_frame;
2345 }
2346
2347
2348 /* Called via walk_function+walk_gimple_stmt, rewrite all references to VAR
2349 and PARM_DECLs that were referenced by inner nested functions.
2350 The rewrite will be a structure reference to the local frame variable. */
2351
2352 static tree
2353 convert_local_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
2354 struct walk_stmt_info *wi)
2355 {
2356 struct nesting_info *info = (struct nesting_info *) wi->info;
2357 tree save_local_var_chain;
2358 bitmap save_suppress;
2359 char save_static_chain_added;
2360 bool frame_decl_added;
2361 gimple *stmt = gsi_stmt (*gsi);
2362
2363 switch (gimple_code (stmt))
2364 {
2365 case GIMPLE_OMP_TEAMS:
2366 if (!gimple_omp_teams_host (as_a <gomp_teams *> (stmt)))
2367 {
2368 save_suppress = info->suppress_expansion;
2369 convert_local_omp_clauses (gimple_omp_teams_clauses_ptr (stmt), wi);
2370 walk_body (convert_local_reference_stmt, convert_local_reference_op,
2371 info, gimple_omp_body_ptr (stmt));
2372 info->suppress_expansion = save_suppress;
2373 break;
2374 }
2375 /* FALLTHRU */
2376
2377 case GIMPLE_OMP_PARALLEL:
2378 case GIMPLE_OMP_TASK:
2379 save_suppress = info->suppress_expansion;
2380 frame_decl_added = false;
2381 if (convert_local_omp_clauses (gimple_omp_taskreg_clauses_ptr (stmt),
2382 wi))
2383 {
2384 tree c = build_omp_clause (gimple_location (stmt),
2385 OMP_CLAUSE_SHARED);
2386 (void) get_frame_type (info);
2387 OMP_CLAUSE_DECL (c) = info->frame_decl;
2388 OMP_CLAUSE_CHAIN (c) = gimple_omp_taskreg_clauses (stmt);
2389 gimple_omp_taskreg_set_clauses (stmt, c);
2390 info->static_chain_added |= 4;
2391 frame_decl_added = true;
2392 }
2393
2394 save_local_var_chain = info->new_local_var_chain;
2395 save_static_chain_added = info->static_chain_added;
2396 info->new_local_var_chain = NULL;
2397 info->static_chain_added = 0;
2398
2399 walk_body (convert_local_reference_stmt, convert_local_reference_op, info,
2400 gimple_omp_body_ptr (stmt));
2401
2402 if ((info->static_chain_added & 4) != 0 && !frame_decl_added)
2403 {
2404 tree c = build_omp_clause (gimple_location (stmt),
2405 OMP_CLAUSE_SHARED);
2406 (void) get_frame_type (info);
2407 OMP_CLAUSE_DECL (c) = info->frame_decl;
2408 OMP_CLAUSE_CHAIN (c) = gimple_omp_taskreg_clauses (stmt);
2409 info->static_chain_added |= 4;
2410 gimple_omp_taskreg_set_clauses (stmt, c);
2411 }
2412 if (info->new_local_var_chain)
2413 declare_vars (info->new_local_var_chain,
2414 gimple_seq_first_stmt (gimple_omp_body (stmt)), false);
2415 info->new_local_var_chain = save_local_var_chain;
2416 info->suppress_expansion = save_suppress;
2417 info->static_chain_added |= save_static_chain_added;
2418 break;
2419
2420 case GIMPLE_OMP_FOR:
2421 save_suppress = info->suppress_expansion;
2422 convert_local_omp_clauses (gimple_omp_for_clauses_ptr (stmt), wi);
2423 walk_gimple_omp_for (as_a <gomp_for *> (stmt),
2424 convert_local_reference_stmt,
2425 convert_local_reference_op, info);
2426 walk_body (convert_local_reference_stmt, convert_local_reference_op,
2427 info, gimple_omp_body_ptr (stmt));
2428 info->suppress_expansion = save_suppress;
2429 break;
2430
2431 case GIMPLE_OMP_SECTIONS:
2432 save_suppress = info->suppress_expansion;
2433 convert_local_omp_clauses (gimple_omp_sections_clauses_ptr (stmt), wi);
2434 walk_body (convert_local_reference_stmt, convert_local_reference_op,
2435 info, gimple_omp_body_ptr (stmt));
2436 info->suppress_expansion = save_suppress;
2437 break;
2438
2439 case GIMPLE_OMP_SINGLE:
2440 save_suppress = info->suppress_expansion;
2441 convert_local_omp_clauses (gimple_omp_single_clauses_ptr (stmt), wi);
2442 walk_body (convert_local_reference_stmt, convert_local_reference_op,
2443 info, gimple_omp_body_ptr (stmt));
2444 info->suppress_expansion = save_suppress;
2445 break;
2446
2447 case GIMPLE_OMP_TASKGROUP:
2448 save_suppress = info->suppress_expansion;
2449 convert_local_omp_clauses (gimple_omp_taskgroup_clauses_ptr (stmt), wi);
2450 walk_body (convert_local_reference_stmt, convert_local_reference_op,
2451 info, gimple_omp_body_ptr (stmt));
2452 info->suppress_expansion = save_suppress;
2453 break;
2454
2455 case GIMPLE_OMP_TARGET:
2456 if (!is_gimple_omp_offloaded (stmt))
2457 {
2458 save_suppress = info->suppress_expansion;
2459 convert_local_omp_clauses (gimple_omp_target_clauses_ptr (stmt), wi);
2460 info->suppress_expansion = save_suppress;
2461 walk_body (convert_local_reference_stmt, convert_local_reference_op,
2462 info, gimple_omp_body_ptr (stmt));
2463 break;
2464 }
2465 save_suppress = info->suppress_expansion;
2466 frame_decl_added = false;
2467 if (convert_local_omp_clauses (gimple_omp_target_clauses_ptr (stmt), wi))
2468 {
2469 tree c = build_omp_clause (gimple_location (stmt), OMP_CLAUSE_MAP);
2470 (void) get_frame_type (info);
2471 OMP_CLAUSE_DECL (c) = info->frame_decl;
2472 OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
2473 OMP_CLAUSE_SIZE (c) = DECL_SIZE_UNIT (info->frame_decl);
2474 OMP_CLAUSE_CHAIN (c) = gimple_omp_target_clauses (stmt);
2475 gimple_omp_target_set_clauses (as_a <gomp_target *> (stmt), c);
2476 info->static_chain_added |= 4;
2477 frame_decl_added = true;
2478 }
2479
2480 save_local_var_chain = info->new_local_var_chain;
2481 save_static_chain_added = info->static_chain_added;
2482 info->new_local_var_chain = NULL;
2483 info->static_chain_added = 0;
2484
2485 walk_body (convert_local_reference_stmt, convert_local_reference_op, info,
2486 gimple_omp_body_ptr (stmt));
2487
2488 if ((info->static_chain_added & 4) != 0 && !frame_decl_added)
2489 {
2490 tree c = build_omp_clause (gimple_location (stmt), OMP_CLAUSE_MAP);
2491 (void) get_frame_type (info);
2492 OMP_CLAUSE_DECL (c) = info->frame_decl;
2493 OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
2494 OMP_CLAUSE_SIZE (c) = DECL_SIZE_UNIT (info->frame_decl);
2495 OMP_CLAUSE_CHAIN (c) = gimple_omp_target_clauses (stmt);
2496 gimple_omp_target_set_clauses (as_a <gomp_target *> (stmt), c);
2497 info->static_chain_added |= 4;
2498 }
2499
2500 if (info->new_local_var_chain)
2501 declare_vars (info->new_local_var_chain,
2502 gimple_seq_first_stmt (gimple_omp_body (stmt)), false);
2503 info->new_local_var_chain = save_local_var_chain;
2504 info->suppress_expansion = save_suppress;
2505 info->static_chain_added |= save_static_chain_added;
2506 break;
2507
2508 case GIMPLE_OMP_SECTION:
2509 case GIMPLE_OMP_MASTER:
2510 case GIMPLE_OMP_ORDERED:
2511 case GIMPLE_OMP_SCAN:
2512 walk_body (convert_local_reference_stmt, convert_local_reference_op,
2513 info, gimple_omp_body_ptr (stmt));
2514 break;
2515
2516 case GIMPLE_COND:
2517 wi->val_only = true;
2518 wi->is_lhs = false;
2519 *handled_ops_p = false;
2520 return NULL_TREE;
2521
2522 case GIMPLE_ASSIGN:
2523 if (gimple_clobber_p (stmt))
2524 {
2525 tree lhs = gimple_assign_lhs (stmt);
2526 if (DECL_P (lhs)
2527 && !use_pointer_in_frame (lhs)
2528 && lookup_field_for_decl (info, lhs, NO_INSERT))
2529 {
2530 gsi_replace (gsi, gimple_build_nop (), true);
2531 break;
2532 }
2533 }
2534 *handled_ops_p = false;
2535 return NULL_TREE;
2536
2537 case GIMPLE_BIND:
2538 for (tree var = gimple_bind_vars (as_a <gbind *> (stmt));
2539 var;
2540 var = DECL_CHAIN (var))
2541 if (TREE_CODE (var) == NAMELIST_DECL)
2542 {
2543 /* Adjust decls mentioned in NAMELIST_DECL. */
2544 tree decls = NAMELIST_DECL_ASSOCIATED_DECL (var);
2545 tree decl;
2546 unsigned int i;
2547
2548 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (decls), i, decl)
2549 {
2550 if (VAR_P (decl)
2551 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
2552 continue;
2553 if (decl_function_context (decl) == info->context
2554 && !use_pointer_in_frame (decl))
2555 {
2556 tree field = lookup_field_for_decl (info, decl, NO_INSERT);
2557 if (field)
2558 {
2559 CONSTRUCTOR_ELT (decls, i)->value
2560 = get_local_debug_decl (info, decl, field);
2561 }
2562 }
2563 }
2564 }
2565
2566 *handled_ops_p = false;
2567 return NULL_TREE;
2568
2569 default:
2570 /* For every other statement that we are not interested in
2571 handling here, let the walker traverse the operands. */
2572 *handled_ops_p = false;
2573 return NULL_TREE;
2574 }
2575
2576 /* Indicate that we have handled all the operands ourselves. */
2577 *handled_ops_p = true;
2578 return NULL_TREE;
2579 }
2580
2581
2582 /* Called via walk_function+walk_gimple_stmt, rewrite all GIMPLE_GOTOs
2583 that reference labels from outer functions. The rewrite will be a
2584 call to __builtin_nonlocal_goto. */
2585
2586 static tree
2587 convert_nl_goto_reference (gimple_stmt_iterator *gsi, bool *handled_ops_p,
2588 struct walk_stmt_info *wi)
2589 {
2590 struct nesting_info *const info = (struct nesting_info *) wi->info, *i;
2591 tree label, new_label, target_context, x, field;
2592 gcall *call;
2593 gimple *stmt = gsi_stmt (*gsi);
2594
2595 if (gimple_code (stmt) != GIMPLE_GOTO)
2596 {
2597 *handled_ops_p = false;
2598 return NULL_TREE;
2599 }
2600
2601 label = gimple_goto_dest (stmt);
2602 if (TREE_CODE (label) != LABEL_DECL)
2603 {
2604 *handled_ops_p = false;
2605 return NULL_TREE;
2606 }
2607
2608 target_context = decl_function_context (label);
2609 if (target_context == info->context)
2610 {
2611 *handled_ops_p = false;
2612 return NULL_TREE;
2613 }
2614
2615 for (i = info->outer; target_context != i->context; i = i->outer)
2616 continue;
2617
2618 /* The original user label may also be use for a normal goto, therefore
2619 we must create a new label that will actually receive the abnormal
2620 control transfer. This new label will be marked LABEL_NONLOCAL; this
2621 mark will trigger proper behavior in the cfg, as well as cause the
2622 (hairy target-specific) non-local goto receiver code to be generated
2623 when we expand rtl. Enter this association into var_map so that we
2624 can insert the new label into the IL during a second pass. */
2625 tree *slot = &i->var_map->get_or_insert (label);
2626 if (*slot == NULL)
2627 {
2628 new_label = create_artificial_label (UNKNOWN_LOCATION);
2629 DECL_NONLOCAL (new_label) = 1;
2630 *slot = new_label;
2631 }
2632 else
2633 new_label = *slot;
2634
2635 /* Build: __builtin_nl_goto(new_label, &chain->nl_goto_field). */
2636 field = get_nl_goto_field (i);
2637 x = get_frame_field (info, target_context, field, gsi);
2638 x = build_addr (x);
2639 x = gsi_gimplify_val (info, x, gsi);
2640 call = gimple_build_call (builtin_decl_implicit (BUILT_IN_NONLOCAL_GOTO),
2641 2, build_addr (new_label), x);
2642 gsi_replace (gsi, call, false);
2643
2644 /* We have handled all of STMT's operands, no need to keep going. */
2645 *handled_ops_p = true;
2646 return NULL_TREE;
2647 }
2648
2649
2650 /* Called via walk_function+walk_tree, rewrite all GIMPLE_LABELs whose labels
2651 are referenced via nonlocal goto from a nested function. The rewrite
2652 will involve installing a newly generated DECL_NONLOCAL label, and
2653 (potentially) a branch around the rtl gunk that is assumed to be
2654 attached to such a label. */
2655
2656 static tree
2657 convert_nl_goto_receiver (gimple_stmt_iterator *gsi, bool *handled_ops_p,
2658 struct walk_stmt_info *wi)
2659 {
2660 struct nesting_info *const info = (struct nesting_info *) wi->info;
2661 tree label, new_label;
2662 gimple_stmt_iterator tmp_gsi;
2663 glabel *stmt = dyn_cast <glabel *> (gsi_stmt (*gsi));
2664
2665 if (!stmt)
2666 {
2667 *handled_ops_p = false;
2668 return NULL_TREE;
2669 }
2670
2671 label = gimple_label_label (stmt);
2672
2673 tree *slot = info->var_map->get (label);
2674 if (!slot)
2675 {
2676 *handled_ops_p = false;
2677 return NULL_TREE;
2678 }
2679
2680 /* If there's any possibility that the previous statement falls through,
2681 then we must branch around the new non-local label. */
2682 tmp_gsi = wi->gsi;
2683 gsi_prev (&tmp_gsi);
2684 if (gsi_end_p (tmp_gsi) || gimple_stmt_may_fallthru (gsi_stmt (tmp_gsi)))
2685 {
2686 gimple *stmt = gimple_build_goto (label);
2687 gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
2688 }
2689
2690 new_label = (tree) *slot;
2691 stmt = gimple_build_label (new_label);
2692 gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
2693
2694 *handled_ops_p = true;
2695 return NULL_TREE;
2696 }
2697
2698
2699 /* Called via walk_function+walk_stmt, rewrite all references to addresses
2700 of nested functions that require the use of trampolines. The rewrite
2701 will involve a reference a trampoline generated for the occasion. */
2702
2703 static tree
2704 convert_tramp_reference_op (tree *tp, int *walk_subtrees, void *data)
2705 {
2706 struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
2707 struct nesting_info *const info = (struct nesting_info *) wi->info, *i;
2708 tree t = *tp, decl, target_context, x, builtin;
2709 bool descr;
2710 gcall *call;
2711
2712 *walk_subtrees = 0;
2713 switch (TREE_CODE (t))
2714 {
2715 case ADDR_EXPR:
2716 /* Build
2717 T.1 = &CHAIN->tramp;
2718 T.2 = __builtin_adjust_trampoline (T.1);
2719 T.3 = (func_type)T.2;
2720 */
2721
2722 decl = TREE_OPERAND (t, 0);
2723 if (TREE_CODE (decl) != FUNCTION_DECL)
2724 break;
2725
2726 /* Only need to process nested functions. */
2727 target_context = decl_function_context (decl);
2728 if (!target_context)
2729 break;
2730
2731 /* If the nested function doesn't use a static chain, then
2732 it doesn't need a trampoline. */
2733 if (!DECL_STATIC_CHAIN (decl))
2734 break;
2735
2736 /* If we don't want a trampoline, then don't build one. */
2737 if (TREE_NO_TRAMPOLINE (t))
2738 break;
2739
2740 /* Lookup the immediate parent of the callee, as that's where
2741 we need to insert the trampoline. */
2742 for (i = info; i->context != target_context; i = i->outer)
2743 continue;
2744
2745 /* Decide whether to generate a descriptor or a trampoline. */
2746 descr = FUNC_ADDR_BY_DESCRIPTOR (t) && !flag_trampolines;
2747
2748 if (descr)
2749 x = lookup_descr_for_decl (i, decl, INSERT);
2750 else
2751 x = lookup_tramp_for_decl (i, decl, INSERT);
2752
2753 /* Compute the address of the field holding the trampoline. */
2754 x = get_frame_field (info, target_context, x, &wi->gsi);
2755 x = build_addr (x);
2756 x = gsi_gimplify_val (info, x, &wi->gsi);
2757
2758 /* Do machine-specific ugliness. Normally this will involve
2759 computing extra alignment, but it can really be anything. */
2760 if (descr)
2761 builtin = builtin_decl_implicit (BUILT_IN_ADJUST_DESCRIPTOR);
2762 else
2763 builtin = builtin_decl_implicit (BUILT_IN_ADJUST_TRAMPOLINE);
2764 call = gimple_build_call (builtin, 1, x);
2765 x = init_tmp_var_with_call (info, &wi->gsi, call);
2766
2767 /* Cast back to the proper function type. */
2768 x = build1 (NOP_EXPR, TREE_TYPE (t), x);
2769 x = init_tmp_var (info, x, &wi->gsi);
2770
2771 *tp = x;
2772 break;
2773
2774 default:
2775 if (!IS_TYPE_OR_DECL_P (t))
2776 *walk_subtrees = 1;
2777 break;
2778 }
2779
2780 return NULL_TREE;
2781 }
2782
2783
2784 /* Called via walk_function+walk_gimple_stmt, rewrite all references
2785 to addresses of nested functions that require the use of
2786 trampolines. The rewrite will involve a reference a trampoline
2787 generated for the occasion. */
2788
2789 static tree
2790 convert_tramp_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
2791 struct walk_stmt_info *wi)
2792 {
2793 struct nesting_info *info = (struct nesting_info *) wi->info;
2794 gimple *stmt = gsi_stmt (*gsi);
2795
2796 switch (gimple_code (stmt))
2797 {
2798 case GIMPLE_CALL:
2799 {
2800 /* Only walk call arguments, lest we generate trampolines for
2801 direct calls. */
2802 unsigned long i, nargs = gimple_call_num_args (stmt);
2803 for (i = 0; i < nargs; i++)
2804 walk_tree (gimple_call_arg_ptr (stmt, i), convert_tramp_reference_op,
2805 wi, NULL);
2806 break;
2807 }
2808
2809 case GIMPLE_OMP_TEAMS:
2810 if (!gimple_omp_teams_host (as_a <gomp_teams *> (stmt)))
2811 {
2812 *handled_ops_p = false;
2813 return NULL_TREE;
2814 }
2815 goto do_parallel;
2816
2817 case GIMPLE_OMP_TARGET:
2818 if (!is_gimple_omp_offloaded (stmt))
2819 {
2820 *handled_ops_p = false;
2821 return NULL_TREE;
2822 }
2823 /* FALLTHRU */
2824 case GIMPLE_OMP_PARALLEL:
2825 case GIMPLE_OMP_TASK:
2826 do_parallel:
2827 {
2828 tree save_local_var_chain = info->new_local_var_chain;
2829 walk_gimple_op (stmt, convert_tramp_reference_op, wi);
2830 info->new_local_var_chain = NULL;
2831 char save_static_chain_added = info->static_chain_added;
2832 info->static_chain_added = 0;
2833 walk_body (convert_tramp_reference_stmt, convert_tramp_reference_op,
2834 info, gimple_omp_body_ptr (stmt));
2835 if (info->new_local_var_chain)
2836 declare_vars (info->new_local_var_chain,
2837 gimple_seq_first_stmt (gimple_omp_body (stmt)),
2838 false);
2839 for (int i = 0; i < 2; i++)
2840 {
2841 tree c, decl;
2842 if ((info->static_chain_added & (1 << i)) == 0)
2843 continue;
2844 decl = i ? get_chain_decl (info) : info->frame_decl;
2845 /* Don't add CHAIN.* or FRAME.* twice. */
2846 for (c = gimple_omp_taskreg_clauses (stmt);
2847 c;
2848 c = OMP_CLAUSE_CHAIN (c))
2849 if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
2850 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED)
2851 && OMP_CLAUSE_DECL (c) == decl)
2852 break;
2853 if (c == NULL && gimple_code (stmt) != GIMPLE_OMP_TARGET)
2854 {
2855 c = build_omp_clause (gimple_location (stmt),
2856 i ? OMP_CLAUSE_FIRSTPRIVATE
2857 : OMP_CLAUSE_SHARED);
2858 OMP_CLAUSE_DECL (c) = decl;
2859 OMP_CLAUSE_CHAIN (c) = gimple_omp_taskreg_clauses (stmt);
2860 gimple_omp_taskreg_set_clauses (stmt, c);
2861 }
2862 else if (c == NULL)
2863 {
2864 c = build_omp_clause (gimple_location (stmt),
2865 OMP_CLAUSE_MAP);
2866 OMP_CLAUSE_DECL (c) = decl;
2867 OMP_CLAUSE_SET_MAP_KIND (c,
2868 i ? GOMP_MAP_TO : GOMP_MAP_TOFROM);
2869 OMP_CLAUSE_SIZE (c) = DECL_SIZE_UNIT (decl);
2870 OMP_CLAUSE_CHAIN (c) = gimple_omp_target_clauses (stmt);
2871 gimple_omp_target_set_clauses (as_a <gomp_target *> (stmt),
2872 c);
2873 }
2874 }
2875 info->new_local_var_chain = save_local_var_chain;
2876 info->static_chain_added |= save_static_chain_added;
2877 }
2878 break;
2879
2880 default:
2881 *handled_ops_p = false;
2882 return NULL_TREE;
2883 }
2884
2885 *handled_ops_p = true;
2886 return NULL_TREE;
2887 }
2888
2889
2890
2891 /* Called via walk_function+walk_gimple_stmt, rewrite all GIMPLE_CALLs
2892 that reference nested functions to make sure that the static chain
2893 is set up properly for the call. */
2894
2895 static tree
2896 convert_gimple_call (gimple_stmt_iterator *gsi, bool *handled_ops_p,
2897 struct walk_stmt_info *wi)
2898 {
2899 struct nesting_info *const info = (struct nesting_info *) wi->info;
2900 tree decl, target_context;
2901 char save_static_chain_added;
2902 int i;
2903 gimple *stmt = gsi_stmt (*gsi);
2904
2905 switch (gimple_code (stmt))
2906 {
2907 case GIMPLE_CALL:
2908 if (gimple_call_chain (stmt))
2909 break;
2910 decl = gimple_call_fndecl (stmt);
2911 if (!decl)
2912 break;
2913 target_context = decl_function_context (decl);
2914 if (target_context && DECL_STATIC_CHAIN (decl))
2915 {
2916 struct nesting_info *i = info;
2917 while (i && i->context != target_context)
2918 i = i->outer;
2919 /* If none of the outer contexts is the target context, this means
2920 that the function is called in a wrong context. */
2921 if (!i)
2922 internal_error ("%s from %s called in %s",
2923 IDENTIFIER_POINTER (DECL_NAME (decl)),
2924 IDENTIFIER_POINTER (DECL_NAME (target_context)),
2925 IDENTIFIER_POINTER (DECL_NAME (info->context)));
2926
2927 gimple_call_set_chain (as_a <gcall *> (stmt),
2928 get_static_chain (info, target_context,
2929 &wi->gsi));
2930 info->static_chain_added |= (1 << (info->context != target_context));
2931 }
2932 break;
2933
2934 case GIMPLE_OMP_TEAMS:
2935 if (!gimple_omp_teams_host (as_a <gomp_teams *> (stmt)))
2936 {
2937 walk_body (convert_gimple_call, NULL, info,
2938 gimple_omp_body_ptr (stmt));
2939 break;
2940 }
2941 /* FALLTHRU */
2942
2943 case GIMPLE_OMP_PARALLEL:
2944 case GIMPLE_OMP_TASK:
2945 save_static_chain_added = info->static_chain_added;
2946 info->static_chain_added = 0;
2947 walk_body (convert_gimple_call, NULL, info, gimple_omp_body_ptr (stmt));
2948 for (i = 0; i < 2; i++)
2949 {
2950 tree c, decl;
2951 if ((info->static_chain_added & (1 << i)) == 0)
2952 continue;
2953 decl = i ? get_chain_decl (info) : info->frame_decl;
2954 /* Don't add CHAIN.* or FRAME.* twice. */
2955 for (c = gimple_omp_taskreg_clauses (stmt);
2956 c;
2957 c = OMP_CLAUSE_CHAIN (c))
2958 if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
2959 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED)
2960 && OMP_CLAUSE_DECL (c) == decl)
2961 break;
2962 if (c == NULL)
2963 {
2964 c = build_omp_clause (gimple_location (stmt),
2965 i ? OMP_CLAUSE_FIRSTPRIVATE
2966 : OMP_CLAUSE_SHARED);
2967 OMP_CLAUSE_DECL (c) = decl;
2968 OMP_CLAUSE_CHAIN (c) = gimple_omp_taskreg_clauses (stmt);
2969 gimple_omp_taskreg_set_clauses (stmt, c);
2970 }
2971 }
2972 info->static_chain_added |= save_static_chain_added;
2973 break;
2974
2975 case GIMPLE_OMP_TARGET:
2976 if (!is_gimple_omp_offloaded (stmt))
2977 {
2978 walk_body (convert_gimple_call, NULL, info, gimple_omp_body_ptr (stmt));
2979 break;
2980 }
2981 save_static_chain_added = info->static_chain_added;
2982 info->static_chain_added = 0;
2983 walk_body (convert_gimple_call, NULL, info, gimple_omp_body_ptr (stmt));
2984 for (i = 0; i < 2; i++)
2985 {
2986 tree c, decl;
2987 if ((info->static_chain_added & (1 << i)) == 0)
2988 continue;
2989 decl = i ? get_chain_decl (info) : info->frame_decl;
2990 /* Don't add CHAIN.* or FRAME.* twice. */
2991 for (c = gimple_omp_target_clauses (stmt);
2992 c;
2993 c = OMP_CLAUSE_CHAIN (c))
2994 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
2995 && OMP_CLAUSE_DECL (c) == decl)
2996 break;
2997 if (c == NULL)
2998 {
2999 c = build_omp_clause (gimple_location (stmt), OMP_CLAUSE_MAP);
3000 OMP_CLAUSE_DECL (c) = decl;
3001 OMP_CLAUSE_SET_MAP_KIND (c, i ? GOMP_MAP_TO : GOMP_MAP_TOFROM);
3002 OMP_CLAUSE_SIZE (c) = DECL_SIZE_UNIT (decl);
3003 OMP_CLAUSE_CHAIN (c) = gimple_omp_target_clauses (stmt);
3004 gimple_omp_target_set_clauses (as_a <gomp_target *> (stmt),
3005 c);
3006 }
3007 }
3008 info->static_chain_added |= save_static_chain_added;
3009 break;
3010
3011 case GIMPLE_OMP_FOR:
3012 walk_body (convert_gimple_call, NULL, info,
3013 gimple_omp_for_pre_body_ptr (stmt));
3014 /* FALLTHRU */
3015 case GIMPLE_OMP_SECTIONS:
3016 case GIMPLE_OMP_SECTION:
3017 case GIMPLE_OMP_SINGLE:
3018 case GIMPLE_OMP_MASTER:
3019 case GIMPLE_OMP_TASKGROUP:
3020 case GIMPLE_OMP_ORDERED:
3021 case GIMPLE_OMP_SCAN:
3022 case GIMPLE_OMP_CRITICAL:
3023 walk_body (convert_gimple_call, NULL, info, gimple_omp_body_ptr (stmt));
3024 break;
3025
3026 default:
3027 /* Keep looking for other operands. */
3028 *handled_ops_p = false;
3029 return NULL_TREE;
3030 }
3031
3032 *handled_ops_p = true;
3033 return NULL_TREE;
3034 }
3035
3036 /* Walk the nesting tree starting with ROOT. Convert all trampolines and
3037 call expressions. At the same time, determine if a nested function
3038 actually uses its static chain; if not, remember that. */
3039
3040 static void
3041 convert_all_function_calls (struct nesting_info *root)
3042 {
3043 unsigned int chain_count = 0, old_chain_count, iter_count;
3044 struct nesting_info *n;
3045
3046 /* First, optimistically clear static_chain for all decls that haven't
3047 used the static chain already for variable access. But always create
3048 it if not optimizing. This makes it possible to reconstruct the static
3049 nesting tree at run time and thus to resolve up-level references from
3050 within the debugger. */
3051 FOR_EACH_NEST_INFO (n, root)
3052 {
3053 if (n->thunk_p)
3054 continue;
3055 tree decl = n->context;
3056 if (!optimize)
3057 {
3058 if (n->inner)
3059 (void) get_frame_type (n);
3060 if (n->outer)
3061 (void) get_chain_decl (n);
3062 }
3063 else if (!n->outer || (!n->chain_decl && !n->chain_field))
3064 {
3065 DECL_STATIC_CHAIN (decl) = 0;
3066 if (dump_file && (dump_flags & TDF_DETAILS))
3067 fprintf (dump_file, "Guessing no static-chain for %s\n",
3068 lang_hooks.decl_printable_name (decl, 2));
3069 }
3070 else
3071 DECL_STATIC_CHAIN (decl) = 1;
3072 chain_count += DECL_STATIC_CHAIN (decl);
3073 }
3074
3075 FOR_EACH_NEST_INFO (n, root)
3076 if (n->thunk_p)
3077 {
3078 tree decl = n->context;
3079 tree alias = thunk_info::get (cgraph_node::get (decl))->alias;
3080 DECL_STATIC_CHAIN (decl) = DECL_STATIC_CHAIN (alias);
3081 }
3082
3083 /* Walk the functions and perform transformations. Note that these
3084 transformations can induce new uses of the static chain, which in turn
3085 require re-examining all users of the decl. */
3086 /* ??? It would make sense to try to use the call graph to speed this up,
3087 but the call graph hasn't really been built yet. Even if it did, we
3088 would still need to iterate in this loop since address-of references
3089 wouldn't show up in the callgraph anyway. */
3090 iter_count = 0;
3091 do
3092 {
3093 old_chain_count = chain_count;
3094 chain_count = 0;
3095 iter_count++;
3096
3097 if (dump_file && (dump_flags & TDF_DETAILS))
3098 fputc ('\n', dump_file);
3099
3100 FOR_EACH_NEST_INFO (n, root)
3101 {
3102 if (n->thunk_p)
3103 continue;
3104 tree decl = n->context;
3105 walk_function (convert_tramp_reference_stmt,
3106 convert_tramp_reference_op, n);
3107 walk_function (convert_gimple_call, NULL, n);
3108 chain_count += DECL_STATIC_CHAIN (decl);
3109 }
3110
3111 FOR_EACH_NEST_INFO (n, root)
3112 if (n->thunk_p)
3113 {
3114 tree decl = n->context;
3115 tree alias = thunk_info::get (cgraph_node::get (decl))->alias;
3116 DECL_STATIC_CHAIN (decl) = DECL_STATIC_CHAIN (alias);
3117 }
3118 }
3119 while (chain_count != old_chain_count);
3120
3121 if (dump_file && (dump_flags & TDF_DETAILS))
3122 fprintf (dump_file, "convert_all_function_calls iterations: %u\n\n",
3123 iter_count);
3124 }
3125
3126 struct nesting_copy_body_data
3127 {
3128 copy_body_data cb;
3129 struct nesting_info *root;
3130 };
3131
3132 /* A helper subroutine for debug_var_chain type remapping. */
3133
3134 static tree
3135 nesting_copy_decl (tree decl, copy_body_data *id)
3136 {
3137 struct nesting_copy_body_data *nid = (struct nesting_copy_body_data *) id;
3138 tree *slot = nid->root->var_map->get (decl);
3139
3140 if (slot)
3141 return (tree) *slot;
3142
3143 if (TREE_CODE (decl) == TYPE_DECL && DECL_ORIGINAL_TYPE (decl))
3144 {
3145 tree new_decl = copy_decl_no_change (decl, id);
3146 DECL_ORIGINAL_TYPE (new_decl)
3147 = remap_type (DECL_ORIGINAL_TYPE (decl), id);
3148 return new_decl;
3149 }
3150
3151 if (VAR_P (decl)
3152 || TREE_CODE (decl) == PARM_DECL
3153 || TREE_CODE (decl) == RESULT_DECL)
3154 return decl;
3155
3156 return copy_decl_no_change (decl, id);
3157 }
3158
3159 /* A helper function for remap_vla_decls. See if *TP contains
3160 some remapped variables. */
3161
3162 static tree
3163 contains_remapped_vars (tree *tp, int *walk_subtrees, void *data)
3164 {
3165 struct nesting_info *root = (struct nesting_info *) data;
3166 tree t = *tp;
3167
3168 if (DECL_P (t))
3169 {
3170 *walk_subtrees = 0;
3171 tree *slot = root->var_map->get (t);
3172
3173 if (slot)
3174 return *slot;
3175 }
3176 return NULL;
3177 }
3178
3179 /* Remap VLA decls in BLOCK and subblocks if remapped variables are
3180 involved. */
3181
3182 static void
3183 remap_vla_decls (tree block, struct nesting_info *root)
3184 {
3185 tree var, subblock, val, type;
3186 struct nesting_copy_body_data id;
3187
3188 for (subblock = BLOCK_SUBBLOCKS (block);
3189 subblock;
3190 subblock = BLOCK_CHAIN (subblock))
3191 remap_vla_decls (subblock, root);
3192
3193 for (var = BLOCK_VARS (block); var; var = DECL_CHAIN (var))
3194 if (VAR_P (var) && DECL_HAS_VALUE_EXPR_P (var))
3195 {
3196 val = DECL_VALUE_EXPR (var);
3197 type = TREE_TYPE (var);
3198
3199 if (!(TREE_CODE (val) == INDIRECT_REF
3200 && TREE_CODE (TREE_OPERAND (val, 0)) == VAR_DECL
3201 && variably_modified_type_p (type, NULL)))
3202 continue;
3203
3204 if (root->var_map->get (TREE_OPERAND (val, 0))
3205 || walk_tree (&type, contains_remapped_vars, root, NULL))
3206 break;
3207 }
3208
3209 if (var == NULL_TREE)
3210 return;
3211
3212 memset (&id, 0, sizeof (id));
3213 id.cb.copy_decl = nesting_copy_decl;
3214 id.cb.decl_map = new hash_map<tree, tree>;
3215 id.root = root;
3216
3217 for (; var; var = DECL_CHAIN (var))
3218 if (VAR_P (var) && DECL_HAS_VALUE_EXPR_P (var))
3219 {
3220 struct nesting_info *i;
3221 tree newt, context;
3222
3223 val = DECL_VALUE_EXPR (var);
3224 type = TREE_TYPE (var);
3225
3226 if (!(TREE_CODE (val) == INDIRECT_REF
3227 && TREE_CODE (TREE_OPERAND (val, 0)) == VAR_DECL
3228 && variably_modified_type_p (type, NULL)))
3229 continue;
3230
3231 tree *slot = root->var_map->get (TREE_OPERAND (val, 0));
3232 if (!slot && !walk_tree (&type, contains_remapped_vars, root, NULL))
3233 continue;
3234
3235 context = decl_function_context (var);
3236 for (i = root; i; i = i->outer)
3237 if (i->context == context)
3238 break;
3239
3240 if (i == NULL)
3241 continue;
3242
3243 /* Fully expand value expressions. This avoids having debug variables
3244 only referenced from them and that can be swept during GC. */
3245 if (slot)
3246 {
3247 tree t = (tree) *slot;
3248 gcc_assert (DECL_P (t) && DECL_HAS_VALUE_EXPR_P (t));
3249 val = build1 (INDIRECT_REF, TREE_TYPE (val), DECL_VALUE_EXPR (t));
3250 }
3251
3252 id.cb.src_fn = i->context;
3253 id.cb.dst_fn = i->context;
3254 id.cb.src_cfun = DECL_STRUCT_FUNCTION (root->context);
3255
3256 TREE_TYPE (var) = newt = remap_type (type, &id.cb);
3257 while (POINTER_TYPE_P (newt) && !TYPE_NAME (newt))
3258 {
3259 newt = TREE_TYPE (newt);
3260 type = TREE_TYPE (type);
3261 }
3262 if (TYPE_NAME (newt)
3263 && TREE_CODE (TYPE_NAME (newt)) == TYPE_DECL
3264 && DECL_ORIGINAL_TYPE (TYPE_NAME (newt))
3265 && newt != type
3266 && TYPE_NAME (newt) == TYPE_NAME (type))
3267 TYPE_NAME (newt) = remap_decl (TYPE_NAME (newt), &id.cb);
3268
3269 walk_tree (&val, copy_tree_body_r, &id.cb, NULL);
3270 if (val != DECL_VALUE_EXPR (var))
3271 SET_DECL_VALUE_EXPR (var, val);
3272 }
3273
3274 delete id.cb.decl_map;
3275 }
3276
3277 /* Fixup VLA decls in BLOCK and subblocks if remapped variables are
3278 involved. */
3279
3280 static void
3281 fixup_vla_decls (tree block)
3282 {
3283 for (tree var = BLOCK_VARS (block); var; var = DECL_CHAIN (var))
3284 if (VAR_P (var) && DECL_HAS_VALUE_EXPR_P (var))
3285 {
3286 tree val = DECL_VALUE_EXPR (var);
3287
3288 if (!(TREE_CODE (val) == INDIRECT_REF
3289 && VAR_P (TREE_OPERAND (val, 0))
3290 && DECL_HAS_VALUE_EXPR_P (TREE_OPERAND (val, 0))))
3291 continue;
3292
3293 /* Fully expand value expressions. This avoids having debug variables
3294 only referenced from them and that can be swept during GC. */
3295 val = build1 (INDIRECT_REF, TREE_TYPE (val),
3296 DECL_VALUE_EXPR (TREE_OPERAND (val, 0)));
3297 SET_DECL_VALUE_EXPR (var, val);
3298 }
3299
3300 for (tree sub = BLOCK_SUBBLOCKS (block); sub; sub = BLOCK_CHAIN (sub))
3301 fixup_vla_decls (sub);
3302 }
3303
3304 /* Fold the MEM_REF *E. */
3305 bool
3306 fold_mem_refs (tree *const &e, void *data ATTRIBUTE_UNUSED)
3307 {
3308 tree *ref_p = CONST_CAST2 (tree *, const tree *, (const tree *)e);
3309 *ref_p = fold (*ref_p);
3310 return true;
3311 }
3312
3313 /* Given DECL, a nested function, build an initialization call for FIELD,
3314 the trampoline or descriptor for DECL, using FUNC as the function. */
3315
3316 static gcall *
3317 build_init_call_stmt (struct nesting_info *info, tree decl, tree field,
3318 tree func)
3319 {
3320 tree arg1, arg2, arg3, x;
3321
3322 gcc_assert (DECL_STATIC_CHAIN (decl));
3323 arg3 = build_addr (info->frame_decl);
3324
3325 arg2 = build_addr (decl);
3326
3327 x = build3 (COMPONENT_REF, TREE_TYPE (field),
3328 info->frame_decl, field, NULL_TREE);
3329 arg1 = build_addr (x);
3330
3331 return gimple_build_call (func, 3, arg1, arg2, arg3);
3332 }
3333
3334 /* Do "everything else" to clean up or complete state collected by the various
3335 walking passes -- create a field to hold the frame base address, lay out the
3336 types and decls, generate code to initialize the frame decl, store critical
3337 expressions in the struct function for rtl to find. */
3338
3339 static void
3340 finalize_nesting_tree_1 (struct nesting_info *root)
3341 {
3342 gimple_seq stmt_list = NULL;
3343 gimple *stmt;
3344 tree context = root->context;
3345 struct function *sf;
3346
3347 if (root->thunk_p)
3348 return;
3349
3350 /* If we created a non-local frame type or decl, we need to lay them
3351 out at this time. */
3352 if (root->frame_type)
3353 {
3354 /* Debugging information needs to compute the frame base address of the
3355 parent frame out of the static chain from the nested frame.
3356
3357 The static chain is the address of the FRAME record, so one could
3358 imagine it would be possible to compute the frame base address just
3359 adding a constant offset to this address. Unfortunately, this is not
3360 possible: if the FRAME object has alignment constraints that are
3361 stronger than the stack, then the offset between the frame base and
3362 the FRAME object will be dynamic.
3363
3364 What we do instead is to append a field to the FRAME object that holds
3365 the frame base address: then debug info just has to fetch this
3366 field. */
3367
3368 /* Debugging information will refer to the CFA as the frame base
3369 address: we will do the same here. */
3370 const tree frame_addr_fndecl
3371 = builtin_decl_explicit (BUILT_IN_DWARF_CFA);
3372
3373 /* Create a field in the FRAME record to hold the frame base address for
3374 this stack frame. Since it will be used only by the debugger, put it
3375 at the end of the record in order not to shift all other offsets. */
3376 tree fb_decl = make_node (FIELD_DECL);
3377
3378 DECL_NAME (fb_decl) = get_identifier ("FRAME_BASE.PARENT");
3379 TREE_TYPE (fb_decl) = ptr_type_node;
3380 TREE_ADDRESSABLE (fb_decl) = 1;
3381 DECL_CONTEXT (fb_decl) = root->frame_type;
3382 TYPE_FIELDS (root->frame_type) = chainon (TYPE_FIELDS (root->frame_type),
3383 fb_decl);
3384
3385 /* In some cases the frame type will trigger the -Wpadded warning.
3386 This is not helpful; suppress it. */
3387 int save_warn_padded = warn_padded;
3388 warn_padded = 0;
3389 layout_type (root->frame_type);
3390 warn_padded = save_warn_padded;
3391 layout_decl (root->frame_decl, 0);
3392
3393 /* Initialize the frame base address field. If the builtin we need is
3394 not available, set it to NULL so that debugging information does not
3395 reference junk. */
3396 tree fb_ref = build3 (COMPONENT_REF, TREE_TYPE (fb_decl),
3397 root->frame_decl, fb_decl, NULL_TREE);
3398 tree fb_tmp;
3399
3400 if (frame_addr_fndecl != NULL_TREE)
3401 {
3402 gcall *fb_gimple = gimple_build_call (frame_addr_fndecl, 1,
3403 integer_zero_node);
3404 gimple_stmt_iterator gsi = gsi_last (stmt_list);
3405
3406 fb_tmp = init_tmp_var_with_call (root, &gsi, fb_gimple);
3407 }
3408 else
3409 fb_tmp = build_int_cst (TREE_TYPE (fb_ref), 0);
3410 gimple_seq_add_stmt (&stmt_list,
3411 gimple_build_assign (fb_ref, fb_tmp));
3412
3413 declare_vars (root->frame_decl,
3414 gimple_seq_first_stmt (gimple_body (context)), true);
3415 }
3416
3417 /* If any parameters were referenced non-locally, then we need to insert
3418 a copy or a pointer. */
3419 if (root->any_parm_remapped)
3420 {
3421 tree p;
3422 for (p = DECL_ARGUMENTS (context); p ; p = DECL_CHAIN (p))
3423 {
3424 tree field, x, y;
3425
3426 field = lookup_field_for_decl (root, p, NO_INSERT);
3427 if (!field)
3428 continue;
3429
3430 if (use_pointer_in_frame (p))
3431 x = build_addr (p);
3432 else
3433 x = p;
3434
3435 /* If the assignment is from a non-register the stmt is
3436 not valid gimple. Make it so by using a temporary instead. */
3437 if (!is_gimple_reg (x)
3438 && is_gimple_reg_type (TREE_TYPE (x)))
3439 {
3440 gimple_stmt_iterator gsi = gsi_last (stmt_list);
3441 x = init_tmp_var (root, x, &gsi);
3442 }
3443
3444 y = build3 (COMPONENT_REF, TREE_TYPE (field),
3445 root->frame_decl, field, NULL_TREE);
3446 stmt = gimple_build_assign (y, x);
3447 gimple_seq_add_stmt (&stmt_list, stmt);
3448 }
3449 }
3450
3451 /* If a chain_field was created, then it needs to be initialized
3452 from chain_decl. */
3453 if (root->chain_field)
3454 {
3455 tree x = build3 (COMPONENT_REF, TREE_TYPE (root->chain_field),
3456 root->frame_decl, root->chain_field, NULL_TREE);
3457 stmt = gimple_build_assign (x, get_chain_decl (root));
3458 gimple_seq_add_stmt (&stmt_list, stmt);
3459 }
3460
3461 /* If trampolines were created, then we need to initialize them. */
3462 if (root->any_tramp_created)
3463 {
3464 struct nesting_info *i;
3465 for (i = root->inner; i ; i = i->next)
3466 {
3467 tree field, x;
3468
3469 field = lookup_tramp_for_decl (root, i->context, NO_INSERT);
3470 if (!field)
3471 continue;
3472
3473 x = builtin_decl_implicit (BUILT_IN_INIT_TRAMPOLINE);
3474 stmt = build_init_call_stmt (root, i->context, field, x);
3475 gimple_seq_add_stmt (&stmt_list, stmt);
3476 }
3477 }
3478
3479 /* If descriptors were created, then we need to initialize them. */
3480 if (root->any_descr_created)
3481 {
3482 struct nesting_info *i;
3483 for (i = root->inner; i ; i = i->next)
3484 {
3485 tree field, x;
3486
3487 field = lookup_descr_for_decl (root, i->context, NO_INSERT);
3488 if (!field)
3489 continue;
3490
3491 x = builtin_decl_implicit (BUILT_IN_INIT_DESCRIPTOR);
3492 stmt = build_init_call_stmt (root, i->context, field, x);
3493 gimple_seq_add_stmt (&stmt_list, stmt);
3494 }
3495 }
3496
3497 /* If we created initialization statements, insert them. */
3498 if (stmt_list)
3499 {
3500 gbind *bind;
3501 annotate_all_with_location (stmt_list, DECL_SOURCE_LOCATION (context));
3502 bind = gimple_seq_first_stmt_as_a_bind (gimple_body (context));
3503 gimple_seq_add_seq (&stmt_list, gimple_bind_body (bind));
3504 gimple_bind_set_body (bind, stmt_list);
3505 }
3506
3507 /* If a chain_decl was created, then it needs to be registered with
3508 struct function so that it gets initialized from the static chain
3509 register at the beginning of the function. */
3510 sf = DECL_STRUCT_FUNCTION (root->context);
3511 sf->static_chain_decl = root->chain_decl;
3512
3513 /* Similarly for the non-local goto save area. */
3514 if (root->nl_goto_field)
3515 {
3516 sf->nonlocal_goto_save_area
3517 = get_frame_field (root, context, root->nl_goto_field, NULL);
3518 sf->has_nonlocal_label = 1;
3519 }
3520
3521 /* Make sure all new local variables get inserted into the
3522 proper BIND_EXPR. */
3523 if (root->new_local_var_chain)
3524 declare_vars (root->new_local_var_chain,
3525 gimple_seq_first_stmt (gimple_body (root->context)),
3526 false);
3527
3528 if (root->debug_var_chain)
3529 {
3530 tree debug_var;
3531 gbind *scope;
3532
3533 remap_vla_decls (DECL_INITIAL (root->context), root);
3534
3535 for (debug_var = root->debug_var_chain; debug_var;
3536 debug_var = DECL_CHAIN (debug_var))
3537 if (variably_modified_type_p (TREE_TYPE (debug_var), NULL))
3538 break;
3539
3540 /* If there are any debug decls with variable length types,
3541 remap those types using other debug_var_chain variables. */
3542 if (debug_var)
3543 {
3544 struct nesting_copy_body_data id;
3545
3546 memset (&id, 0, sizeof (id));
3547 id.cb.copy_decl = nesting_copy_decl;
3548 id.cb.decl_map = new hash_map<tree, tree>;
3549 id.root = root;
3550
3551 for (; debug_var; debug_var = DECL_CHAIN (debug_var))
3552 if (variably_modified_type_p (TREE_TYPE (debug_var), NULL))
3553 {
3554 tree type = TREE_TYPE (debug_var);
3555 tree newt, t = type;
3556 struct nesting_info *i;
3557
3558 for (i = root; i; i = i->outer)
3559 if (variably_modified_type_p (type, i->context))
3560 break;
3561
3562 if (i == NULL)
3563 continue;
3564
3565 id.cb.src_fn = i->context;
3566 id.cb.dst_fn = i->context;
3567 id.cb.src_cfun = DECL_STRUCT_FUNCTION (root->context);
3568
3569 TREE_TYPE (debug_var) = newt = remap_type (type, &id.cb);
3570 while (POINTER_TYPE_P (newt) && !TYPE_NAME (newt))
3571 {
3572 newt = TREE_TYPE (newt);
3573 t = TREE_TYPE (t);
3574 }
3575 if (TYPE_NAME (newt)
3576 && TREE_CODE (TYPE_NAME (newt)) == TYPE_DECL
3577 && DECL_ORIGINAL_TYPE (TYPE_NAME (newt))
3578 && newt != t
3579 && TYPE_NAME (newt) == TYPE_NAME (t))
3580 TYPE_NAME (newt) = remap_decl (TYPE_NAME (newt), &id.cb);
3581 }
3582
3583 delete id.cb.decl_map;
3584 }
3585
3586 scope = gimple_seq_first_stmt_as_a_bind (gimple_body (root->context));
3587 if (gimple_bind_block (scope))
3588 declare_vars (root->debug_var_chain, scope, true);
3589 else
3590 BLOCK_VARS (DECL_INITIAL (root->context))
3591 = chainon (BLOCK_VARS (DECL_INITIAL (root->context)),
3592 root->debug_var_chain);
3593 }
3594 else
3595 fixup_vla_decls (DECL_INITIAL (root->context));
3596
3597 /* Fold the rewritten MEM_REF trees. */
3598 root->mem_refs->traverse<void *, fold_mem_refs> (NULL);
3599
3600 /* Dump the translated tree function. */
3601 if (dump_file)
3602 {
3603 fputs ("\n\n", dump_file);
3604 dump_function_to_file (root->context, dump_file, dump_flags);
3605 }
3606 }
3607
3608 static void
3609 finalize_nesting_tree (struct nesting_info *root)
3610 {
3611 struct nesting_info *n;
3612 FOR_EACH_NEST_INFO (n, root)
3613 finalize_nesting_tree_1 (n);
3614 }
3615
3616 /* Unnest the nodes and pass them to cgraph. */
3617
3618 static void
3619 unnest_nesting_tree_1 (struct nesting_info *root)
3620 {
3621 struct cgraph_node *node = cgraph_node::get (root->context);
3622
3623 /* For nested functions update the cgraph to reflect unnesting.
3624 We also delay finalizing of these functions up to this point. */
3625 if (nested_function_info::get (node)->origin)
3626 {
3627 unnest_function (node);
3628 if (!root->thunk_p)
3629 cgraph_node::finalize_function (root->context, true);
3630 }
3631 }
3632
3633 static void
3634 unnest_nesting_tree (struct nesting_info *root)
3635 {
3636 struct nesting_info *n;
3637 FOR_EACH_NEST_INFO (n, root)
3638 unnest_nesting_tree_1 (n);
3639 }
3640
3641 /* Free the data structures allocated during this pass. */
3642
3643 static void
3644 free_nesting_tree (struct nesting_info *root)
3645 {
3646 struct nesting_info *node, *next;
3647
3648 node = iter_nestinfo_start (root);
3649 do
3650 {
3651 next = iter_nestinfo_next (node);
3652 delete node->var_map;
3653 delete node->field_map;
3654 delete node->mem_refs;
3655 free (node);
3656 node = next;
3657 }
3658 while (node);
3659 }
3660
3661 /* Gimplify a function and all its nested functions. */
3662 static void
3663 gimplify_all_functions (struct cgraph_node *root)
3664 {
3665 struct cgraph_node *iter;
3666 if (!gimple_body (root->decl))
3667 gimplify_function_tree (root->decl);
3668 for (iter = first_nested_function (root); iter;
3669 iter = next_nested_function (iter))
3670 if (!iter->thunk)
3671 gimplify_all_functions (iter);
3672 }
3673
3674 /* Main entry point for this pass. Process FNDECL and all of its nested
3675 subroutines and turn them into something less tightly bound. */
3676
3677 void
3678 lower_nested_functions (tree fndecl)
3679 {
3680 struct cgraph_node *cgn;
3681 struct nesting_info *root;
3682
3683 /* If there are no nested functions, there's nothing to do. */
3684 cgn = cgraph_node::get (fndecl);
3685 if (!first_nested_function (cgn))
3686 return;
3687
3688 gimplify_all_functions (cgn);
3689
3690 set_dump_file (dump_begin (TDI_nested, &dump_flags));
3691 if (dump_file)
3692 fprintf (dump_file, "\n;; Function %s\n\n",
3693 lang_hooks.decl_printable_name (fndecl, 2));
3694
3695 bitmap_obstack_initialize (&nesting_info_bitmap_obstack);
3696 root = create_nesting_tree (cgn);
3697
3698 walk_all_functions (convert_nonlocal_reference_stmt,
3699 convert_nonlocal_reference_op,
3700 root);
3701 walk_all_functions (convert_local_reference_stmt,
3702 convert_local_reference_op,
3703 root);
3704 walk_all_functions (convert_nl_goto_reference, NULL, root);
3705 walk_all_functions (convert_nl_goto_receiver, NULL, root);
3706
3707 convert_all_function_calls (root);
3708 finalize_nesting_tree (root);
3709 unnest_nesting_tree (root);
3710
3711 free_nesting_tree (root);
3712 bitmap_obstack_release (&nesting_info_bitmap_obstack);
3713
3714 if (dump_file)
3715 {
3716 dump_end (TDI_nested, dump_file);
3717 set_dump_file (NULL);
3718 }
3719 }
3720
3721 #include "gt-tree-nested.h"