1 /* GIMPLE lowering pass. Converts High GIMPLE into Low GIMPLE.
3 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
29 #include "tree-iterator.h"
30 #include "tree-inline.h"
31 #include "diagnostic.h"
32 #include "langhooks.h"
33 #include "langhooks-def.h"
34 #include "tree-flow.h"
42 #include "tree-pass.h"
44 /* The differences between High GIMPLE and Low GIMPLE are the
47 1- Lexical scopes are removed (i.e., GIMPLE_BIND disappears).
49 2- GIMPLE_TRY and GIMPLE_CATCH are converted to abnormal control
50 flow and exception regions are built as an on-the-side region
51 hierarchy (See tree-eh.c:lower_eh_constructs).
53 3- Multiple identical return statements are grouped into a single
54 return and gotos to the unique return site. */
56 /* Match a return statement with a label. During lowering, we identify
57 identical return statements and replace duplicates with a jump to
58 the corresponding label. */
59 struct return_statements_t
64 typedef struct return_statements_t return_statements_t
;
66 DEF_VEC_O(return_statements_t
);
67 DEF_VEC_ALLOC_O(return_statements_t
,heap
);
71 /* Block the current statement belongs to. */
74 /* A vector of label and return statements to be moved to the end
76 VEC(return_statements_t
,heap
) *return_statements
;
78 /* True if the current statement cannot fall through. */
81 /* True if the function calls __builtin_setjmp. */
82 bool calls_builtin_setjmp
;
85 static void lower_stmt (gimple_stmt_iterator
*, struct lower_data
*);
86 static void lower_gimple_bind (gimple_stmt_iterator
*, struct lower_data
*);
87 static void lower_gimple_return (gimple_stmt_iterator
*, struct lower_data
*);
88 static void lower_builtin_setjmp (gimple_stmt_iterator
*);
91 /* Lower the body of current_function_decl from High GIMPLE into Low
95 lower_function_body (void)
97 struct lower_data data
;
98 gimple_seq body
= gimple_body (current_function_decl
);
99 gimple_seq lowered_body
;
100 gimple_stmt_iterator i
;
105 /* The gimplifier should've left a body of exactly one statement,
106 namely a GIMPLE_BIND. */
107 gcc_assert (gimple_seq_first (body
) == gimple_seq_last (body
)
108 && gimple_code (gimple_seq_first_stmt (body
)) == GIMPLE_BIND
);
110 memset (&data
, 0, sizeof (data
));
111 data
.block
= DECL_INITIAL (current_function_decl
);
112 BLOCK_SUBBLOCKS (data
.block
) = NULL_TREE
;
113 BLOCK_CHAIN (data
.block
) = NULL_TREE
;
114 TREE_ASM_WRITTEN (data
.block
) = 1;
115 data
.return_statements
= VEC_alloc (return_statements_t
, heap
, 8);
117 bind
= gimple_seq_first_stmt (body
);
119 gimple_seq_add_stmt (&lowered_body
, bind
);
120 i
= gsi_start (lowered_body
);
121 lower_gimple_bind (&i
, &data
);
123 /* Once the old body has been lowered, replace it with the new
125 gimple_set_body (current_function_decl
, lowered_body
);
127 i
= gsi_last (lowered_body
);
129 /* If the function falls off the end, we need a null return statement.
130 If we've already got one in the return_statements vector, we don't
131 need to do anything special. Otherwise build one by hand. */
132 if (gimple_seq_may_fallthru (lowered_body
)
133 && (VEC_empty (return_statements_t
, data
.return_statements
)
134 || gimple_return_retval (VEC_last (return_statements_t
,
135 data
.return_statements
)->stmt
) != NULL
))
137 x
= gimple_build_return (NULL
);
138 gimple_set_location (x
, cfun
->function_end_locus
);
139 gimple_set_block (x
, DECL_INITIAL (current_function_decl
));
140 gsi_insert_after (&i
, x
, GSI_CONTINUE_LINKING
);
143 /* If we lowered any return statements, emit the representative
144 at the end of the function. */
145 while (!VEC_empty (return_statements_t
, data
.return_statements
))
147 return_statements_t t
;
149 /* Unfortunately, we can't use VEC_pop because it returns void for
151 t
= *VEC_last (return_statements_t
, data
.return_statements
);
152 VEC_truncate (return_statements_t
,
153 data
.return_statements
,
154 VEC_length (return_statements_t
,
155 data
.return_statements
) - 1);
157 x
= gimple_build_label (t
.label
);
158 gsi_insert_after (&i
, x
, GSI_CONTINUE_LINKING
);
160 /* Remove the line number from the representative return statement.
161 It now fills in for many such returns. Failure to remove this
162 will result in incorrect results for coverage analysis. */
163 gimple_set_location (t
.stmt
, UNKNOWN_LOCATION
);
164 gsi_insert_after (&i
, t
.stmt
, GSI_CONTINUE_LINKING
);
167 /* If the function calls __builtin_setjmp, we need to emit the computed
168 goto that will serve as the unique dispatcher for all the receivers. */
169 if (data
.calls_builtin_setjmp
)
171 tree disp_label
, disp_var
, arg
;
173 /* Build 'DISP_LABEL:' and insert. */
174 disp_label
= create_artificial_label (cfun
->function_end_locus
);
175 /* This mark will create forward edges from every call site. */
176 DECL_NONLOCAL (disp_label
) = 1;
177 cfun
->has_nonlocal_label
= 1;
178 x
= gimple_build_label (disp_label
);
179 gsi_insert_after (&i
, x
, GSI_CONTINUE_LINKING
);
181 /* Build 'DISP_VAR = __builtin_setjmp_dispatcher (DISP_LABEL);'
183 disp_var
= create_tmp_var (ptr_type_node
, "setjmpvar");
184 arg
= build_addr (disp_label
, current_function_decl
);
185 t
= implicit_built_in_decls
[BUILT_IN_SETJMP_DISPATCHER
];
186 x
= gimple_build_call (t
, 1, arg
);
187 gimple_call_set_lhs (x
, disp_var
);
189 /* Build 'goto DISP_VAR;' and insert. */
190 gsi_insert_after (&i
, x
, GSI_CONTINUE_LINKING
);
191 x
= gimple_build_goto (disp_var
);
192 gsi_insert_after (&i
, x
, GSI_CONTINUE_LINKING
);
195 gcc_assert (data
.block
== DECL_INITIAL (current_function_decl
));
196 BLOCK_SUBBLOCKS (data
.block
)
197 = blocks_nreverse (BLOCK_SUBBLOCKS (data
.block
));
199 clear_block_marks (data
.block
);
200 VEC_free(return_statements_t
, heap
, data
.return_statements
);
204 struct gimple_opt_pass pass_lower_cf
=
210 lower_function_body
, /* execute */
213 0, /* static_pass_number */
215 PROP_gimple_any
, /* properties_required */
216 PROP_gimple_lcf
, /* properties_provided */
217 0, /* properties_destroyed */
218 0, /* todo_flags_start */
219 TODO_dump_func
/* todo_flags_finish */
224 /* Verify if the type of the argument matches that of the function
225 declaration. If we cannot verify this or there is a mismatch,
229 gimple_check_call_args (gimple stmt
)
231 tree fndecl
, parms
, p
;
232 unsigned int i
, nargs
;
234 nargs
= gimple_call_num_args (stmt
);
236 /* Get argument types for verification. */
237 fndecl
= gimple_call_fndecl (stmt
);
240 parms
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
241 else if (POINTER_TYPE_P (TREE_TYPE (gimple_call_fn (stmt
))))
242 parms
= TYPE_ARG_TYPES (TREE_TYPE (TREE_TYPE (gimple_call_fn (stmt
))));
244 /* Verify if the type of the argument matches that of the function
245 declaration. If we cannot verify this or there is a mismatch,
247 if (fndecl
&& DECL_ARGUMENTS (fndecl
))
249 for (i
= 0, p
= DECL_ARGUMENTS (fndecl
);
251 i
++, p
= TREE_CHAIN (p
))
253 /* We cannot distinguish a varargs function from the case
254 of excess parameters, still deferring the inlining decision
255 to the callee is possible. */
258 if (p
== error_mark_node
259 || gimple_call_arg (stmt
, i
) == error_mark_node
260 || !fold_convertible_p (DECL_ARG_TYPE (p
),
261 gimple_call_arg (stmt
, i
)))
267 for (i
= 0, p
= parms
; i
< nargs
; i
++, p
= TREE_CHAIN (p
))
269 /* If this is a varargs function defer inlining decision
273 if (TREE_VALUE (p
) == error_mark_node
274 || gimple_call_arg (stmt
, i
) == error_mark_node
275 || TREE_CODE (TREE_VALUE (p
)) == VOID_TYPE
276 || !fold_convertible_p (TREE_VALUE (p
),
277 gimple_call_arg (stmt
, i
)))
290 /* Lower sequence SEQ. Unlike gimplification the statements are not relowered
291 when they are changed -- if this has to be done, the lowering routine must
292 do it explicitly. DATA is passed through the recursion. */
295 lower_sequence (gimple_seq seq
, struct lower_data
*data
)
297 gimple_stmt_iterator gsi
;
299 for (gsi
= gsi_start (seq
); !gsi_end_p (gsi
); )
300 lower_stmt (&gsi
, data
);
304 /* Lower the OpenMP directive statement pointed by GSI. DATA is
305 passed through the recursion. */
308 lower_omp_directive (gimple_stmt_iterator
*gsi
, struct lower_data
*data
)
312 stmt
= gsi_stmt (*gsi
);
314 lower_sequence (gimple_omp_body (stmt
), data
);
315 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
316 gsi_insert_seq_before (gsi
, gimple_omp_body (stmt
), GSI_SAME_STMT
);
317 gimple_omp_set_body (stmt
, NULL
);
318 gsi_remove (gsi
, false);
322 /* Lower statement GSI. DATA is passed through the recursion. We try to
323 track the fallthruness of statements and get rid of unreachable return
324 statements in order to prevent the EH lowering pass from adding useless
325 edges that can cause bogus warnings to be issued later; this guess need
326 not be 100% accurate, simply be conservative and reset cannot_fallthru
327 to false if we don't know. */
330 lower_stmt (gimple_stmt_iterator
*gsi
, struct lower_data
*data
)
332 gimple stmt
= gsi_stmt (*gsi
);
334 gimple_set_block (stmt
, data
->block
);
336 switch (gimple_code (stmt
))
339 lower_gimple_bind (gsi
, data
);
340 /* Propagate fallthruness. */
346 data
->cannot_fallthru
= true;
351 if (data
->cannot_fallthru
)
353 gsi_remove (gsi
, false);
354 /* Propagate fallthruness. */
358 lower_gimple_return (gsi
, data
);
359 data
->cannot_fallthru
= true;
365 bool try_cannot_fallthru
;
366 lower_sequence (gimple_try_eval (stmt
), data
);
367 try_cannot_fallthru
= data
->cannot_fallthru
;
368 data
->cannot_fallthru
= false;
369 lower_sequence (gimple_try_cleanup (stmt
), data
);
370 /* See gimple_stmt_may_fallthru for the rationale. */
371 if (gimple_try_kind (stmt
) == GIMPLE_TRY_FINALLY
)
373 data
->cannot_fallthru
|= try_cannot_fallthru
;
381 data
->cannot_fallthru
= false;
382 lower_sequence (gimple_catch_handler (stmt
), data
);
385 case GIMPLE_EH_FILTER
:
386 data
->cannot_fallthru
= false;
387 lower_sequence (gimple_eh_filter_failure (stmt
), data
);
395 case GIMPLE_EH_MUST_NOT_THROW
:
397 case GIMPLE_OMP_SECTIONS
:
398 case GIMPLE_OMP_SECTIONS_SWITCH
:
399 case GIMPLE_OMP_SECTION
:
400 case GIMPLE_OMP_SINGLE
:
401 case GIMPLE_OMP_MASTER
:
402 case GIMPLE_OMP_ORDERED
:
403 case GIMPLE_OMP_CRITICAL
:
404 case GIMPLE_OMP_RETURN
:
405 case GIMPLE_OMP_ATOMIC_LOAD
:
406 case GIMPLE_OMP_ATOMIC_STORE
:
407 case GIMPLE_OMP_CONTINUE
:
412 tree decl
= gimple_call_fndecl (stmt
);
415 && DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
416 && DECL_FUNCTION_CODE (decl
) == BUILT_IN_SETJMP
)
418 lower_builtin_setjmp (gsi
);
419 data
->cannot_fallthru
= false;
420 data
->calls_builtin_setjmp
= true;
424 if (decl
&& (flags_from_decl_or_type (decl
) & ECF_NORETURN
))
426 data
->cannot_fallthru
= true;
433 case GIMPLE_OMP_PARALLEL
:
434 case GIMPLE_OMP_TASK
:
435 data
->cannot_fallthru
= false;
436 lower_omp_directive (gsi
, data
);
437 data
->cannot_fallthru
= false;
444 data
->cannot_fallthru
= false;
448 /* Lower a bind_expr TSI. DATA is passed through the recursion. */
451 lower_gimple_bind (gimple_stmt_iterator
*gsi
, struct lower_data
*data
)
453 tree old_block
= data
->block
;
454 gimple stmt
= gsi_stmt (*gsi
);
455 tree new_block
= gimple_bind_block (stmt
);
459 if (new_block
== old_block
)
461 /* The outermost block of the original function may not be the
462 outermost statement chain of the gimplified function. So we
463 may see the outermost block just inside the function. */
464 gcc_assert (new_block
== DECL_INITIAL (current_function_decl
));
469 /* We do not expect to handle duplicate blocks. */
470 gcc_assert (!TREE_ASM_WRITTEN (new_block
));
471 TREE_ASM_WRITTEN (new_block
) = 1;
473 /* Block tree may get clobbered by inlining. Normally this would
474 be fixed in rest_of_decl_compilation using block notes, but
475 since we are not going to emit them, it is up to us. */
476 BLOCK_CHAIN (new_block
) = BLOCK_SUBBLOCKS (old_block
);
477 BLOCK_SUBBLOCKS (old_block
) = new_block
;
478 BLOCK_SUBBLOCKS (new_block
) = NULL_TREE
;
479 BLOCK_SUPERCONTEXT (new_block
) = old_block
;
481 data
->block
= new_block
;
485 record_vars (gimple_bind_vars (stmt
));
486 lower_sequence (gimple_bind_body (stmt
), data
);
490 gcc_assert (data
->block
== new_block
);
492 BLOCK_SUBBLOCKS (new_block
)
493 = blocks_nreverse (BLOCK_SUBBLOCKS (new_block
));
494 data
->block
= old_block
;
497 /* The GIMPLE_BIND no longer carries any useful information -- kill it. */
498 gsi_insert_seq_before (gsi
, gimple_bind_body (stmt
), GSI_SAME_STMT
);
499 gsi_remove (gsi
, false);
502 /* Try to determine whether a TRY_CATCH expression can fall through.
503 This is a subroutine of block_may_fallthru. */
506 try_catch_may_fallthru (const_tree stmt
)
508 tree_stmt_iterator i
;
510 /* If the TRY block can fall through, the whole TRY_CATCH can
512 if (block_may_fallthru (TREE_OPERAND (stmt
, 0)))
515 i
= tsi_start (TREE_OPERAND (stmt
, 1));
516 switch (TREE_CODE (tsi_stmt (i
)))
519 /* We expect to see a sequence of CATCH_EXPR trees, each with a
520 catch expression and a body. The whole TRY_CATCH may fall
521 through iff any of the catch bodies falls through. */
522 for (; !tsi_end_p (i
); tsi_next (&i
))
524 if (block_may_fallthru (CATCH_BODY (tsi_stmt (i
))))
530 /* The exception filter expression only matters if there is an
531 exception. If the exception does not match EH_FILTER_TYPES,
532 we will execute EH_FILTER_FAILURE, and we will fall through
533 if that falls through. If the exception does match
534 EH_FILTER_TYPES, the stack unwinder will continue up the
535 stack, so we will not fall through. We don't know whether we
536 will throw an exception which matches EH_FILTER_TYPES or not,
537 so we just ignore EH_FILTER_TYPES and assume that we might
538 throw an exception which doesn't match. */
539 return block_may_fallthru (EH_FILTER_FAILURE (tsi_stmt (i
)));
542 /* This case represents statements to be executed when an
543 exception occurs. Those statements are implicitly followed
544 by a RESX statement to resume execution after the exception.
545 So in this case the TRY_CATCH never falls through. */
551 /* Same as above, but for a GIMPLE_TRY_CATCH. */
554 gimple_try_catch_may_fallthru (gimple stmt
)
556 gimple_stmt_iterator i
;
558 /* We don't handle GIMPLE_TRY_FINALLY. */
559 gcc_assert (gimple_try_kind (stmt
) == GIMPLE_TRY_CATCH
);
561 /* If the TRY block can fall through, the whole TRY_CATCH can
563 if (gimple_seq_may_fallthru (gimple_try_eval (stmt
)))
566 i
= gsi_start (gimple_try_cleanup (stmt
));
567 switch (gimple_code (gsi_stmt (i
)))
570 /* We expect to see a sequence of GIMPLE_CATCH stmts, each with a
571 catch expression and a body. The whole try/catch may fall
572 through iff any of the catch bodies falls through. */
573 for (; !gsi_end_p (i
); gsi_next (&i
))
575 if (gimple_seq_may_fallthru (gimple_catch_handler (gsi_stmt (i
))))
580 case GIMPLE_EH_FILTER
:
581 /* The exception filter expression only matters if there is an
582 exception. If the exception does not match EH_FILTER_TYPES,
583 we will execute EH_FILTER_FAILURE, and we will fall through
584 if that falls through. If the exception does match
585 EH_FILTER_TYPES, the stack unwinder will continue up the
586 stack, so we will not fall through. We don't know whether we
587 will throw an exception which matches EH_FILTER_TYPES or not,
588 so we just ignore EH_FILTER_TYPES and assume that we might
589 throw an exception which doesn't match. */
590 return gimple_seq_may_fallthru (gimple_eh_filter_failure (gsi_stmt (i
)));
593 /* This case represents statements to be executed when an
594 exception occurs. Those statements are implicitly followed
595 by a GIMPLE_RESX to resume execution after the exception. So
596 in this case the try/catch never falls through. */
602 /* Try to determine if we can fall out of the bottom of BLOCK. This guess
603 need not be 100% accurate; simply be conservative and return true if we
604 don't know. This is used only to avoid stupidly generating extra code.
605 If we're wrong, we'll just delete the extra code later. */
608 block_may_fallthru (const_tree block
)
610 /* This CONST_CAST is okay because expr_last returns its argument
611 unmodified and we assign it to a const_tree. */
612 const_tree stmt
= expr_last (CONST_CAST_TREE(block
));
614 switch (stmt
? TREE_CODE (stmt
) : ERROR_MARK
)
618 /* Easy cases. If the last statement of the block implies
619 control transfer, then we can't fall through. */
623 /* If SWITCH_LABELS is set, this is lowered, and represents a
624 branch to a selected label and hence can not fall through.
625 Otherwise SWITCH_BODY is set, and the switch can fall
627 return SWITCH_LABELS (stmt
) == NULL_TREE
;
630 if (block_may_fallthru (COND_EXPR_THEN (stmt
)))
632 return block_may_fallthru (COND_EXPR_ELSE (stmt
));
635 return block_may_fallthru (BIND_EXPR_BODY (stmt
));
638 return try_catch_may_fallthru (stmt
);
640 case TRY_FINALLY_EXPR
:
641 /* The finally clause is always executed after the try clause,
642 so if it does not fall through, then the try-finally will not
643 fall through. Otherwise, if the try clause does not fall
644 through, then when the finally clause falls through it will
645 resume execution wherever the try clause was going. So the
646 whole try-finally will only fall through if both the try
647 clause and the finally clause fall through. */
648 return (block_may_fallthru (TREE_OPERAND (stmt
, 0))
649 && block_may_fallthru (TREE_OPERAND (stmt
, 1)));
652 if (TREE_CODE (TREE_OPERAND (stmt
, 1)) == CALL_EXPR
)
653 stmt
= TREE_OPERAND (stmt
, 1);
659 /* Functions that do not return do not fall through. */
660 return (call_expr_flags (stmt
) & ECF_NORETURN
) == 0;
662 case CLEANUP_POINT_EXPR
:
663 return block_may_fallthru (TREE_OPERAND (stmt
, 0));
671 /* Try to determine if we can continue executing the statement
672 immediately following STMT. This guess need not be 100% accurate;
673 simply be conservative and return true if we don't know. This is
674 used only to avoid stupidly generating extra code. If we're wrong,
675 we'll just delete the extra code later. */
678 gimple_stmt_may_fallthru (gimple stmt
)
683 switch (gimple_code (stmt
))
688 /* Easy cases. If the last statement of the seq implies
689 control transfer, then we can't fall through. */
693 /* Switch has already been lowered and represents a branch
694 to a selected label and hence can't fall through. */
698 /* GIMPLE_COND's are already lowered into a two-way branch. They
699 can't fall through. */
703 return gimple_seq_may_fallthru (gimple_bind_body (stmt
));
706 if (gimple_try_kind (stmt
) == GIMPLE_TRY_CATCH
)
707 return gimple_try_catch_may_fallthru (stmt
);
709 /* It must be a GIMPLE_TRY_FINALLY. */
711 /* The finally clause is always executed after the try clause,
712 so if it does not fall through, then the try-finally will not
713 fall through. Otherwise, if the try clause does not fall
714 through, then when the finally clause falls through it will
715 resume execution wherever the try clause was going. So the
716 whole try-finally will only fall through if both the try
717 clause and the finally clause fall through. */
718 return (gimple_seq_may_fallthru (gimple_try_eval (stmt
))
719 && gimple_seq_may_fallthru (gimple_try_cleanup (stmt
)));
722 /* Functions that do not return do not fall through. */
723 return (gimple_call_flags (stmt
) & ECF_NORETURN
) == 0;
731 /* Same as gimple_stmt_may_fallthru, but for the gimple sequence SEQ. */
734 gimple_seq_may_fallthru (gimple_seq seq
)
736 return gimple_stmt_may_fallthru (gimple_seq_last_stmt (seq
));
740 /* Lower a GIMPLE_RETURN GSI. DATA is passed through the recursion. */
743 lower_gimple_return (gimple_stmt_iterator
*gsi
, struct lower_data
*data
)
745 gimple stmt
= gsi_stmt (*gsi
);
748 return_statements_t tmp_rs
;
750 /* Match this up with an existing return statement that's been created. */
751 for (i
= VEC_length (return_statements_t
, data
->return_statements
) - 1;
754 tmp_rs
= *VEC_index (return_statements_t
, data
->return_statements
, i
);
756 if (gimple_return_retval (stmt
) == gimple_return_retval (tmp_rs
.stmt
))
760 /* Not found. Create a new label and record the return statement. */
761 tmp_rs
.label
= create_artificial_label (cfun
->function_end_locus
);
763 VEC_safe_push (return_statements_t
, heap
, data
->return_statements
, &tmp_rs
);
765 /* Generate a goto statement and remove the return statement. */
767 t
= gimple_build_goto (tmp_rs
.label
);
768 gimple_set_location (t
, gimple_location (stmt
));
769 gimple_set_block (t
, gimple_block (stmt
));
770 gsi_insert_before (gsi
, t
, GSI_SAME_STMT
);
771 gsi_remove (gsi
, false);
774 /* Lower a __builtin_setjmp GSI.
776 __builtin_setjmp is passed a pointer to an array of five words (not
777 all will be used on all machines). It operates similarly to the C
778 library function of the same name, but is more efficient.
780 It is lowered into 3 other builtins, namely __builtin_setjmp_setup,
781 __builtin_setjmp_dispatcher and __builtin_setjmp_receiver, but with
782 __builtin_setjmp_dispatcher shared among all the instances; that's
783 why it is only emitted at the end by lower_function_body.
785 After full lowering, the body of the function should look like:
794 __builtin_setjmp_setup (&buf, &<D1847>);
798 __builtin_setjmp_receiver (&<D1847>);
801 if (D.1844 == 0) goto <D1848>; else goto <D1849>;
805 __builtin_setjmp_setup (&buf, &<D2847>);
809 __builtin_setjmp_receiver (&<D2847>);
812 if (D.2844 == 0) goto <D2848>; else goto <D2849>;
818 <D3853>: [non-local];
819 setjmpvar.0 = __builtin_setjmp_dispatcher (&<D3853>);
823 The dispatcher block will be both the unique destination of all the
824 abnormal call edges and the unique source of all the abnormal edges
825 to the receivers, thus keeping the complexity explosion localized. */
828 lower_builtin_setjmp (gimple_stmt_iterator
*gsi
)
830 gimple stmt
= gsi_stmt (*gsi
);
831 location_t loc
= gimple_location (stmt
);
832 tree cont_label
= create_artificial_label (loc
);
833 tree next_label
= create_artificial_label (loc
);
837 /* NEXT_LABEL is the label __builtin_longjmp will jump to. Its address is
838 passed to both __builtin_setjmp_setup and __builtin_setjmp_receiver. */
839 FORCED_LABEL (next_label
) = 1;
841 dest
= gimple_call_lhs (stmt
);
843 /* Build '__builtin_setjmp_setup (BUF, NEXT_LABEL)' and insert. */
844 arg
= build_addr (next_label
, current_function_decl
);
845 t
= implicit_built_in_decls
[BUILT_IN_SETJMP_SETUP
];
846 g
= gimple_build_call (t
, 2, gimple_call_arg (stmt
, 0), arg
);
847 gimple_set_location (g
, loc
);
848 gimple_set_block (g
, gimple_block (stmt
));
849 gsi_insert_before (gsi
, g
, GSI_SAME_STMT
);
851 /* Build 'DEST = 0' and insert. */
854 g
= gimple_build_assign (dest
, fold_convert_loc (loc
, TREE_TYPE (dest
),
856 gimple_set_location (g
, loc
);
857 gimple_set_block (g
, gimple_block (stmt
));
858 gsi_insert_before (gsi
, g
, GSI_SAME_STMT
);
861 /* Build 'goto CONT_LABEL' and insert. */
862 g
= gimple_build_goto (cont_label
);
863 gsi_insert_before (gsi
, g
, GSI_SAME_STMT
);
865 /* Build 'NEXT_LABEL:' and insert. */
866 g
= gimple_build_label (next_label
);
867 gsi_insert_before (gsi
, g
, GSI_SAME_STMT
);
869 /* Build '__builtin_setjmp_receiver (NEXT_LABEL)' and insert. */
870 arg
= build_addr (next_label
, current_function_decl
);
871 t
= implicit_built_in_decls
[BUILT_IN_SETJMP_RECEIVER
];
872 g
= gimple_build_call (t
, 1, arg
);
873 gimple_set_location (g
, loc
);
874 gimple_set_block (g
, gimple_block (stmt
));
875 gsi_insert_before (gsi
, g
, GSI_SAME_STMT
);
877 /* Build 'DEST = 1' and insert. */
880 g
= gimple_build_assign (dest
, fold_convert_loc (loc
, TREE_TYPE (dest
),
882 gimple_set_location (g
, loc
);
883 gimple_set_block (g
, gimple_block (stmt
));
884 gsi_insert_before (gsi
, g
, GSI_SAME_STMT
);
887 /* Build 'CONT_LABEL:' and insert. */
888 g
= gimple_build_label (cont_label
);
889 gsi_insert_before (gsi
, g
, GSI_SAME_STMT
);
891 /* Remove the call to __builtin_setjmp. */
892 gsi_remove (gsi
, false);
896 /* Record the variables in VARS into function FN. */
899 record_vars_into (tree vars
, tree fn
)
901 if (fn
!= current_function_decl
)
902 push_cfun (DECL_STRUCT_FUNCTION (fn
));
904 for (; vars
; vars
= TREE_CHAIN (vars
))
908 /* BIND_EXPRs contains also function/type/constant declarations
909 we don't need to care about. */
910 if (TREE_CODE (var
) != VAR_DECL
)
913 /* Nothing to do in this case. */
914 if (DECL_EXTERNAL (var
))
917 /* Record the variable. */
918 cfun
->local_decls
= tree_cons (NULL_TREE
, var
,
922 if (fn
!= current_function_decl
)
927 /* Record the variables in VARS into current_function_decl. */
930 record_vars (tree vars
)
932 record_vars_into (vars
, current_function_decl
);