]> gcc.gnu.org Git - gcc.git/blob - gcc/gimple-low.c
Add target hook invoked when cfun changes.
[gcc.git] / gcc / gimple-low.c
1 /* Tree lowering pass. Lowers GIMPLE into unstructured form.
2
3 Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "tree.h"
26 #include "rtl.h"
27 #include "varray.h"
28 #include "tree-gimple.h"
29 #include "tree-inline.h"
30 #include "diagnostic.h"
31 #include "langhooks.h"
32 #include "langhooks-def.h"
33 #include "tree-flow.h"
34 #include "timevar.h"
35 #include "except.h"
36 #include "hashtab.h"
37 #include "flags.h"
38 #include "function.h"
39 #include "expr.h"
40 #include "toplev.h"
41 #include "tree-pass.h"
42
43 struct lower_data
44 {
45 /* Block the current statement belongs to. */
46 tree block;
47
48 /* A TREE_LIST of label and return statements to be moved to the end
49 of the function. */
50 tree return_statements;
51
52 /* True if the function calls __builtin_setjmp. */
53 bool calls_builtin_setjmp;
54 };
55
56 static void lower_stmt (tree_stmt_iterator *, struct lower_data *);
57 static void lower_bind_expr (tree_stmt_iterator *, struct lower_data *);
58 static void lower_cond_expr (tree_stmt_iterator *, struct lower_data *);
59 static void lower_return_expr (tree_stmt_iterator *, struct lower_data *);
60 static void lower_builtin_setjmp (tree_stmt_iterator *);
61
62 /* Lower the body of current_function_decl. */
63
64 static unsigned int
65 lower_function_body (void)
66 {
67 struct lower_data data;
68 tree *body_p = &DECL_SAVED_TREE (current_function_decl);
69 tree bind = *body_p;
70 tree_stmt_iterator i;
71 tree t, x;
72
73 gcc_assert (TREE_CODE (bind) == BIND_EXPR);
74
75 memset (&data, 0, sizeof (data));
76 data.block = DECL_INITIAL (current_function_decl);
77 BLOCK_SUBBLOCKS (data.block) = NULL_TREE;
78 BLOCK_CHAIN (data.block) = NULL_TREE;
79 TREE_ASM_WRITTEN (data.block) = 1;
80
81 *body_p = alloc_stmt_list ();
82 i = tsi_start (*body_p);
83 tsi_link_after (&i, bind, TSI_NEW_STMT);
84 lower_bind_expr (&i, &data);
85
86 i = tsi_last (*body_p);
87
88 /* If the function falls off the end, we need a null return statement.
89 If we've already got one in the return_statements list, we don't
90 need to do anything special. Otherwise build one by hand. */
91 if (block_may_fallthru (*body_p)
92 && (data.return_statements == NULL
93 || TREE_OPERAND (TREE_VALUE (data.return_statements), 0) != NULL))
94 {
95 x = build1 (RETURN_EXPR, void_type_node, NULL);
96 SET_EXPR_LOCATION (x, cfun->function_end_locus);
97 tsi_link_after (&i, x, TSI_CONTINUE_LINKING);
98 }
99
100 /* If we lowered any return statements, emit the representative
101 at the end of the function. */
102 for (t = data.return_statements ; t ; t = TREE_CHAIN (t))
103 {
104 x = build1 (LABEL_EXPR, void_type_node, TREE_PURPOSE (t));
105 tsi_link_after (&i, x, TSI_CONTINUE_LINKING);
106
107 /* Remove the line number from the representative return statement.
108 It now fills in for many such returns. Failure to remove this
109 will result in incorrect results for coverage analysis. */
110 x = TREE_VALUE (t);
111 #ifdef USE_MAPPED_LOCATION
112 SET_EXPR_LOCATION (x, UNKNOWN_LOCATION);
113 #else
114 SET_EXPR_LOCUS (x, NULL);
115 #endif
116 tsi_link_after (&i, x, TSI_CONTINUE_LINKING);
117 }
118
119 /* If the function calls __builtin_setjmp, we need to emit the computed
120 goto that will serve as the unique dispatcher for all the receivers. */
121 if (data.calls_builtin_setjmp)
122 {
123 tree disp_label, disp_var, arg;
124
125 /* Build 'DISP_LABEL:' and insert. */
126 disp_label = create_artificial_label ();
127 /* This mark will create forward edges from every call site. */
128 DECL_NONLOCAL (disp_label) = 1;
129 current_function_has_nonlocal_label = 1;
130 x = build1 (LABEL_EXPR, void_type_node, disp_label);
131 tsi_link_after (&i, x, TSI_CONTINUE_LINKING);
132
133 /* Build 'DISP_VAR = __builtin_setjmp_dispatcher (DISP_LABEL);'
134 and insert. */
135 disp_var = create_tmp_var (ptr_type_node, "setjmpvar");
136 arg = build_addr (disp_label, current_function_decl);
137 t = implicit_built_in_decls[BUILT_IN_SETJMP_DISPATCHER];
138 t = build_call_expr (t, 1, arg);
139 x = build_gimple_modify_stmt (disp_var, t);
140
141 /* Build 'goto DISP_VAR;' and insert. */
142 tsi_link_after (&i, x, TSI_CONTINUE_LINKING);
143 x = build1 (GOTO_EXPR, void_type_node, disp_var);
144 tsi_link_after (&i, x, TSI_CONTINUE_LINKING);
145 }
146
147 gcc_assert (data.block == DECL_INITIAL (current_function_decl));
148 BLOCK_SUBBLOCKS (data.block)
149 = blocks_nreverse (BLOCK_SUBBLOCKS (data.block));
150
151 clear_block_marks (data.block);
152 return 0;
153 }
154
155 struct tree_opt_pass pass_lower_cf =
156 {
157 "lower", /* name */
158 NULL, /* gate */
159 lower_function_body, /* execute */
160 NULL, /* sub */
161 NULL, /* next */
162 0, /* static_pass_number */
163 0, /* tv_id */
164 PROP_gimple_any, /* properties_required */
165 PROP_gimple_lcf, /* properties_provided */
166 0, /* properties_destroyed */
167 0, /* todo_flags_start */
168 TODO_dump_func, /* todo_flags_finish */
169 0 /* letter */
170 };
171
172
173 /* Lower the EXPR. Unlike gimplification the statements are not relowered
174 when they are changed -- if this has to be done, the lowering routine must
175 do it explicitly. DATA is passed through the recursion. */
176
177 static void
178 lower_stmt_body (tree expr, struct lower_data *data)
179 {
180 tree_stmt_iterator tsi;
181
182 for (tsi = tsi_start (expr); !tsi_end_p (tsi); )
183 lower_stmt (&tsi, data);
184 }
185
186
187 /* Lower the OpenMP directive statement pointed by TSI. DATA is
188 passed through the recursion. */
189
190 static void
191 lower_omp_directive (tree_stmt_iterator *tsi, struct lower_data *data)
192 {
193 tree stmt;
194
195 stmt = tsi_stmt (*tsi);
196
197 lower_stmt_body (OMP_BODY (stmt), data);
198 tsi_link_before (tsi, stmt, TSI_SAME_STMT);
199 tsi_link_before (tsi, OMP_BODY (stmt), TSI_SAME_STMT);
200 OMP_BODY (stmt) = NULL_TREE;
201 tsi_delink (tsi);
202 }
203
204
205 /* Lower statement TSI. DATA is passed through the recursion. */
206
207 static void
208 lower_stmt (tree_stmt_iterator *tsi, struct lower_data *data)
209 {
210 tree stmt = tsi_stmt (*tsi);
211
212 if (EXPR_HAS_LOCATION (stmt) && data)
213 TREE_BLOCK (stmt) = data->block;
214
215 switch (TREE_CODE (stmt))
216 {
217 case BIND_EXPR:
218 lower_bind_expr (tsi, data);
219 return;
220 case COND_EXPR:
221 lower_cond_expr (tsi, data);
222 return;
223 case RETURN_EXPR:
224 lower_return_expr (tsi, data);
225 return;
226
227 case TRY_FINALLY_EXPR:
228 case TRY_CATCH_EXPR:
229 lower_stmt_body (TREE_OPERAND (stmt, 0), data);
230 lower_stmt_body (TREE_OPERAND (stmt, 1), data);
231 break;
232 case CATCH_EXPR:
233 lower_stmt_body (CATCH_BODY (stmt), data);
234 break;
235 case EH_FILTER_EXPR:
236 lower_stmt_body (EH_FILTER_FAILURE (stmt), data);
237 break;
238
239 case NOP_EXPR:
240 case ASM_EXPR:
241 case GOTO_EXPR:
242 case LABEL_EXPR:
243 case SWITCH_EXPR:
244 case CHANGE_DYNAMIC_TYPE_EXPR:
245 case OMP_FOR:
246 case OMP_SECTIONS:
247 case OMP_SECTIONS_SWITCH:
248 case OMP_SECTION:
249 case OMP_SINGLE:
250 case OMP_MASTER:
251 case OMP_ORDERED:
252 case OMP_CRITICAL:
253 case OMP_RETURN:
254 case OMP_CONTINUE:
255 break;
256
257 case GIMPLE_MODIFY_STMT:
258 if (TREE_CODE (GIMPLE_STMT_OPERAND (stmt, 1)) == CALL_EXPR)
259 stmt = GIMPLE_STMT_OPERAND (stmt, 1);
260 else
261 break;
262 /* FALLTHRU */
263
264 case CALL_EXPR:
265 {
266 tree decl = get_callee_fndecl (stmt);
267 if (decl
268 && DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
269 && DECL_FUNCTION_CODE (decl) == BUILT_IN_SETJMP)
270 {
271 data->calls_builtin_setjmp = true;
272 lower_builtin_setjmp (tsi);
273 return;
274 }
275 }
276 break;
277
278 case OMP_PARALLEL:
279 lower_omp_directive (tsi, data);
280 return;
281
282 default:
283 gcc_unreachable ();
284 }
285
286 tsi_next (tsi);
287 }
288
289 /* Lower a bind_expr TSI. DATA is passed through the recursion. */
290
291 static void
292 lower_bind_expr (tree_stmt_iterator *tsi, struct lower_data *data)
293 {
294 tree old_block = data->block;
295 tree stmt = tsi_stmt (*tsi);
296 tree new_block = BIND_EXPR_BLOCK (stmt);
297
298 if (new_block)
299 {
300 if (new_block == old_block)
301 {
302 /* The outermost block of the original function may not be the
303 outermost statement chain of the gimplified function. So we
304 may see the outermost block just inside the function. */
305 gcc_assert (new_block == DECL_INITIAL (current_function_decl));
306 new_block = NULL;
307 }
308 else
309 {
310 /* We do not expect to handle duplicate blocks. */
311 gcc_assert (!TREE_ASM_WRITTEN (new_block));
312 TREE_ASM_WRITTEN (new_block) = 1;
313
314 /* Block tree may get clobbered by inlining. Normally this would
315 be fixed in rest_of_decl_compilation using block notes, but
316 since we are not going to emit them, it is up to us. */
317 BLOCK_CHAIN (new_block) = BLOCK_SUBBLOCKS (old_block);
318 BLOCK_SUBBLOCKS (old_block) = new_block;
319 BLOCK_SUBBLOCKS (new_block) = NULL_TREE;
320 BLOCK_SUPERCONTEXT (new_block) = old_block;
321
322 data->block = new_block;
323 }
324 }
325
326 record_vars (BIND_EXPR_VARS (stmt));
327 lower_stmt_body (BIND_EXPR_BODY (stmt), data);
328
329 if (new_block)
330 {
331 gcc_assert (data->block == new_block);
332
333 BLOCK_SUBBLOCKS (new_block)
334 = blocks_nreverse (BLOCK_SUBBLOCKS (new_block));
335 data->block = old_block;
336 }
337
338 /* The BIND_EXPR no longer carries any useful information -- kill it. */
339 tsi_link_before (tsi, BIND_EXPR_BODY (stmt), TSI_SAME_STMT);
340 tsi_delink (tsi);
341 }
342
343 /* Try to determine whether a TRY_CATCH expression can fall through.
344 This is a subroutine of block_may_fallthru. */
345
346 static bool
347 try_catch_may_fallthru (const_tree stmt)
348 {
349 tree_stmt_iterator i;
350
351 /* If the TRY block can fall through, the whole TRY_CATCH can
352 fall through. */
353 if (block_may_fallthru (TREE_OPERAND (stmt, 0)))
354 return true;
355
356 i = tsi_start (TREE_OPERAND (stmt, 1));
357 switch (TREE_CODE (tsi_stmt (i)))
358 {
359 case CATCH_EXPR:
360 /* We expect to see a sequence of CATCH_EXPR trees, each with a
361 catch expression and a body. The whole TRY_CATCH may fall
362 through iff any of the catch bodies falls through. */
363 for (; !tsi_end_p (i); tsi_next (&i))
364 {
365 if (block_may_fallthru (CATCH_BODY (tsi_stmt (i))))
366 return true;
367 }
368 return false;
369
370 case EH_FILTER_EXPR:
371 /* The exception filter expression only matters if there is an
372 exception. If the exception does not match EH_FILTER_TYPES,
373 we will execute EH_FILTER_FAILURE, and we will fall through
374 if that falls through. If the exception does match
375 EH_FILTER_TYPES, the stack unwinder will continue up the
376 stack, so we will not fall through. We don't know whether we
377 will throw an exception which matches EH_FILTER_TYPES or not,
378 so we just ignore EH_FILTER_TYPES and assume that we might
379 throw an exception which doesn't match. */
380 return block_may_fallthru (EH_FILTER_FAILURE (tsi_stmt (i)));
381
382 default:
383 /* This case represents statements to be executed when an
384 exception occurs. Those statements are implicitly followed
385 by a RESX_EXPR to resume execution after the exception. So
386 in this case the TRY_CATCH never falls through. */
387 return false;
388 }
389 }
390
391 /* Try to determine if we can fall out of the bottom of BLOCK. This guess
392 need not be 100% accurate; simply be conservative and return true if we
393 don't know. This is used only to avoid stupidly generating extra code.
394 If we're wrong, we'll just delete the extra code later. */
395
396 bool
397 block_may_fallthru (const_tree block)
398 {
399 /* This CONST_CAST is okay because expr_last returns it's argument
400 unmodified and we assign it to a const_tree. */
401 const_tree stmt = expr_last (CONST_CAST_TREE(block));
402
403 switch (stmt ? TREE_CODE (stmt) : ERROR_MARK)
404 {
405 case GOTO_EXPR:
406 case RETURN_EXPR:
407 case RESX_EXPR:
408 /* Easy cases. If the last statement of the block implies
409 control transfer, then we can't fall through. */
410 return false;
411
412 case SWITCH_EXPR:
413 /* If SWITCH_LABELS is set, this is lowered, and represents a
414 branch to a selected label and hence can not fall through.
415 Otherwise SWITCH_BODY is set, and the switch can fall
416 through. */
417 return SWITCH_LABELS (stmt) == NULL_TREE;
418
419 case COND_EXPR:
420 if (block_may_fallthru (COND_EXPR_THEN (stmt)))
421 return true;
422 return block_may_fallthru (COND_EXPR_ELSE (stmt));
423
424 case BIND_EXPR:
425 return block_may_fallthru (BIND_EXPR_BODY (stmt));
426
427 case TRY_CATCH_EXPR:
428 return try_catch_may_fallthru (stmt);
429
430 case TRY_FINALLY_EXPR:
431 /* The finally clause is always executed after the try clause,
432 so if it does not fall through, then the try-finally will not
433 fall through. Otherwise, if the try clause does not fall
434 through, then when the finally clause falls through it will
435 resume execution wherever the try clause was going. So the
436 whole try-finally will only fall through if both the try
437 clause and the finally clause fall through. */
438 return (block_may_fallthru (TREE_OPERAND (stmt, 0))
439 && block_may_fallthru (TREE_OPERAND (stmt, 1)));
440
441 case GIMPLE_MODIFY_STMT:
442 if (TREE_CODE (GIMPLE_STMT_OPERAND (stmt, 1)) == CALL_EXPR)
443 stmt = GIMPLE_STMT_OPERAND (stmt, 1);
444 else
445 return true;
446 /* FALLTHRU */
447
448 case CALL_EXPR:
449 /* Functions that do not return do not fall through. */
450 return (call_expr_flags (stmt) & ECF_NORETURN) == 0;
451
452 case CLEANUP_POINT_EXPR:
453 return block_may_fallthru (TREE_OPERAND (stmt, 0));
454
455 default:
456 return true;
457 }
458 }
459
460 /* Lower a cond_expr TSI. DATA is passed through the recursion. */
461
462 static void
463 lower_cond_expr (tree_stmt_iterator *tsi, struct lower_data *data)
464 {
465 tree stmt = tsi_stmt (*tsi);
466 bool then_is_goto, else_is_goto;
467 tree then_branch, else_branch;
468 tree then_goto, else_goto;
469
470 then_branch = COND_EXPR_THEN (stmt);
471 else_branch = COND_EXPR_ELSE (stmt);
472
473 lower_stmt_body (then_branch, data);
474 lower_stmt_body (else_branch, data);
475
476 then_goto = expr_only (then_branch);
477 then_is_goto = then_goto && simple_goto_p (then_goto);
478
479 else_goto = expr_only (else_branch);
480 else_is_goto = else_goto && simple_goto_p (else_goto);
481
482 if (!then_is_goto || !else_is_goto)
483 {
484 tree then_label, else_label, end_label, t;
485
486 then_label = NULL_TREE;
487 else_label = NULL_TREE;
488 end_label = NULL_TREE;
489
490 /* Replace the cond_expr with explicit gotos. */
491 if (!then_is_goto)
492 {
493 t = build1 (LABEL_EXPR, void_type_node, NULL_TREE);
494 if (TREE_SIDE_EFFECTS (then_branch))
495 then_label = t;
496 else
497 end_label = t;
498 then_goto = build_and_jump (&LABEL_EXPR_LABEL (t));
499 }
500
501 if (!else_is_goto)
502 {
503 t = build1 (LABEL_EXPR, void_type_node, NULL_TREE);
504 if (TREE_SIDE_EFFECTS (else_branch))
505 else_label = t;
506 else
507 {
508 /* Both THEN and ELSE can be no-ops if one or both contained an
509 empty BIND_EXPR that was associated with the toplevel block
510 of an inlined function. In that case remove_useless_stmts
511 can't have cleaned things up for us; kill the whole
512 conditional now. */
513 if (end_label)
514 {
515 tsi_delink (tsi);
516 return;
517 }
518 else
519 end_label = t;
520 }
521 else_goto = build_and_jump (&LABEL_EXPR_LABEL (t));
522 }
523
524 if (then_label)
525 {
526 bool may_fallthru = block_may_fallthru (then_branch);
527
528 tsi_link_after (tsi, then_label, TSI_CONTINUE_LINKING);
529 tsi_link_after (tsi, then_branch, TSI_CONTINUE_LINKING);
530
531 if (else_label && may_fallthru)
532 {
533 end_label = build1 (LABEL_EXPR, void_type_node, NULL_TREE);
534 t = build_and_jump (&LABEL_EXPR_LABEL (end_label));
535 tsi_link_after (tsi, t, TSI_CONTINUE_LINKING);
536 }
537 }
538
539 if (else_label)
540 {
541 tsi_link_after (tsi, else_label, TSI_CONTINUE_LINKING);
542 tsi_link_after (tsi, else_branch, TSI_CONTINUE_LINKING);
543 }
544
545 if (end_label)
546 tsi_link_after (tsi, end_label, TSI_CONTINUE_LINKING);
547 }
548
549 COND_EXPR_THEN (stmt) = then_goto;
550 COND_EXPR_ELSE (stmt) = else_goto;
551
552 tsi_next (tsi);
553 }
554
555 /* Lower a return_expr TSI. DATA is passed through the recursion. */
556
557 static void
558 lower_return_expr (tree_stmt_iterator *tsi, struct lower_data *data)
559 {
560 tree stmt = tsi_stmt (*tsi);
561 tree value, t, label;
562
563 /* Extract the value being returned. */
564 value = TREE_OPERAND (stmt, 0);
565 if (value && TREE_CODE (value) == GIMPLE_MODIFY_STMT)
566 value = GIMPLE_STMT_OPERAND (value, 1);
567
568 /* Match this up with an existing return statement that's been created. */
569 for (t = data->return_statements; t ; t = TREE_CHAIN (t))
570 {
571 tree tvalue = TREE_OPERAND (TREE_VALUE (t), 0);
572 if (tvalue && TREE_CODE (tvalue) == GIMPLE_MODIFY_STMT)
573 tvalue = GIMPLE_STMT_OPERAND (tvalue, 1);
574
575 if (value == tvalue)
576 {
577 label = TREE_PURPOSE (t);
578 goto found;
579 }
580 }
581
582 /* Not found. Create a new label and record the return statement. */
583 label = create_artificial_label ();
584 data->return_statements = tree_cons (label, stmt, data->return_statements);
585
586 /* Generate a goto statement and remove the return statement. */
587 found:
588 t = build1 (GOTO_EXPR, void_type_node, label);
589 SET_EXPR_LOCUS (t, EXPR_LOCUS (stmt));
590 tsi_link_before (tsi, t, TSI_SAME_STMT);
591 tsi_delink (tsi);
592 }
593
594 /* Lower a __builtin_setjmp TSI.
595
596 __builtin_setjmp is passed a pointer to an array of five words (not
597 all will be used on all machines). It operates similarly to the C
598 library function of the same name, but is more efficient.
599
600 It is lowered into 3 other builtins, namely __builtin_setjmp_setup,
601 __builtin_setjmp_dispatcher and __builtin_setjmp_receiver, but with
602 __builtin_setjmp_dispatcher shared among all the instances; that's
603 why it is only emitted at the end by lower_function_body.
604
605 After full lowering, the body of the function should look like:
606
607 {
608 void * setjmpvar.0;
609 int D.1844;
610 int D.2844;
611
612 [...]
613
614 __builtin_setjmp_setup (&buf, &<D1847>);
615 D.1844 = 0;
616 goto <D1846>;
617 <D1847>:;
618 __builtin_setjmp_receiver (&<D1847>);
619 D.1844 = 1;
620 <D1846>:;
621 if (D.1844 == 0) goto <D1848>; else goto <D1849>;
622
623 [...]
624
625 __builtin_setjmp_setup (&buf, &<D2847>);
626 D.2844 = 0;
627 goto <D2846>;
628 <D2847>:;
629 __builtin_setjmp_receiver (&<D2847>);
630 D.2844 = 1;
631 <D2846>:;
632 if (D.2844 == 0) goto <D2848>; else goto <D2849>;
633
634 [...]
635
636 <D3850>:;
637 return;
638 <D3853>: [non-local];
639 setjmpvar.0 = __builtin_setjmp_dispatcher (&<D3853>);
640 goto setjmpvar.0;
641 }
642
643 The dispatcher block will be both the unique destination of all the
644 abnormal call edges and the unique source of all the abnormal edges
645 to the receivers, thus keeping the complexity explosion localized. */
646
647 static void
648 lower_builtin_setjmp (tree_stmt_iterator *tsi)
649 {
650 tree stmt = tsi_stmt (*tsi);
651 tree cont_label = create_artificial_label ();
652 tree next_label = create_artificial_label ();
653 tree dest, t, arg;
654
655 /* NEXT_LABEL is the label __builtin_longjmp will jump to. Its address is
656 passed to both __builtin_setjmp_setup and __builtin_setjmp_receiver. */
657 FORCED_LABEL (next_label) = 1;
658
659 if (TREE_CODE (stmt) == GIMPLE_MODIFY_STMT)
660 {
661 dest = GIMPLE_STMT_OPERAND (stmt, 0);
662 stmt = GIMPLE_STMT_OPERAND (stmt, 1);
663 }
664 else
665 dest = NULL_TREE;
666
667 /* Build '__builtin_setjmp_setup (BUF, NEXT_LABEL)' and insert. */
668 arg = build_addr (next_label, current_function_decl);
669 t = implicit_built_in_decls[BUILT_IN_SETJMP_SETUP];
670 t = build_call_expr (t, 2, CALL_EXPR_ARG (stmt, 0), arg);
671 SET_EXPR_LOCUS (t, EXPR_LOCUS (stmt));
672 tsi_link_before (tsi, t, TSI_SAME_STMT);
673
674 /* Build 'DEST = 0' and insert. */
675 if (dest)
676 {
677 t = build_gimple_modify_stmt (dest, fold_convert (TREE_TYPE (dest),
678 integer_zero_node));
679 SET_EXPR_LOCUS (t, EXPR_LOCUS (stmt));
680 tsi_link_before (tsi, t, TSI_SAME_STMT);
681 }
682
683 /* Build 'goto CONT_LABEL' and insert. */
684 t = build1 (GOTO_EXPR, void_type_node, cont_label);
685 tsi_link_before (tsi, t, TSI_SAME_STMT);
686
687 /* Build 'NEXT_LABEL:' and insert. */
688 t = build1 (LABEL_EXPR, void_type_node, next_label);
689 tsi_link_before (tsi, t, TSI_SAME_STMT);
690
691 /* Build '__builtin_setjmp_receiver (NEXT_LABEL)' and insert. */
692 arg = build_addr (next_label, current_function_decl);
693 t = implicit_built_in_decls[BUILT_IN_SETJMP_RECEIVER];
694 t = build_call_expr (t, 1, arg);
695 SET_EXPR_LOCUS (t, EXPR_LOCUS (stmt));
696 tsi_link_before (tsi, t, TSI_SAME_STMT);
697
698 /* Build 'DEST = 1' and insert. */
699 if (dest)
700 {
701 t = build_gimple_modify_stmt (dest, fold_convert (TREE_TYPE (dest),
702 integer_one_node));
703 SET_EXPR_LOCUS (t, EXPR_LOCUS (stmt));
704 tsi_link_before (tsi, t, TSI_SAME_STMT);
705 }
706
707 /* Build 'CONT_LABEL:' and insert. */
708 t = build1 (LABEL_EXPR, void_type_node, cont_label);
709 tsi_link_before (tsi, t, TSI_SAME_STMT);
710
711 /* Remove the call to __builtin_setjmp. */
712 tsi_delink (tsi);
713 }
714 \f
715
716 /* Record the variables in VARS into function FN. */
717
718 void
719 record_vars_into (tree vars, tree fn)
720 {
721 if (fn != current_function_decl)
722 push_cfun (DECL_STRUCT_FUNCTION (fn));
723
724 for (; vars; vars = TREE_CHAIN (vars))
725 {
726 tree var = vars;
727
728 /* BIND_EXPRs contains also function/type/constant declarations
729 we don't need to care about. */
730 if (TREE_CODE (var) != VAR_DECL)
731 continue;
732
733 /* Nothing to do in this case. */
734 if (DECL_EXTERNAL (var))
735 continue;
736
737 /* Record the variable. */
738 cfun->unexpanded_var_list = tree_cons (NULL_TREE, var,
739 cfun->unexpanded_var_list);
740 }
741
742 if (fn != current_function_decl)
743 pop_cfun ();
744 }
745
746
747 /* Record the variables in VARS into current_function_decl. */
748
749 void
750 record_vars (tree vars)
751 {
752 record_vars_into (vars, current_function_decl);
753 }
754
755
756 /* Mark BLOCK used if it has a used variable in it, then recurse over its
757 subblocks. */
758
759 static void
760 mark_blocks_with_used_vars (tree block)
761 {
762 tree var;
763 tree subblock;
764
765 if (!TREE_USED (block))
766 {
767 for (var = BLOCK_VARS (block);
768 var;
769 var = TREE_CHAIN (var))
770 {
771 if (TREE_USED (var))
772 {
773 TREE_USED (block) = true;
774 break;
775 }
776 }
777 }
778 for (subblock = BLOCK_SUBBLOCKS (block);
779 subblock;
780 subblock = BLOCK_CHAIN (subblock))
781 mark_blocks_with_used_vars (subblock);
782 }
783
784 /* Mark the used attribute on blocks correctly. */
785
786 static unsigned int
787 mark_used_blocks (void)
788 {
789 mark_blocks_with_used_vars (DECL_INITIAL (current_function_decl));
790 return 0;
791 }
792
793
794 struct tree_opt_pass pass_mark_used_blocks =
795 {
796 "blocks", /* name */
797 NULL, /* gate */
798 mark_used_blocks, /* execute */
799 NULL, /* sub */
800 NULL, /* next */
801 0, /* static_pass_number */
802 0, /* tv_id */
803 0, /* properties_required */
804 0, /* properties_provided */
805 0, /* properties_destroyed */
806 0, /* todo_flags_start */
807 TODO_dump_func, /* todo_flags_finish */
808 0 /* letter */
809 };
This page took 0.066774 seconds and 6 git commands to generate.