1 /* Pass computing data for optimizing stdarg functions.
2 Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
3 Contributed by Jakub Jelinek <jakub@redhat.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
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/>. */
23 #include "coretypes.h"
27 #include "langhooks.h"
28 #include "diagnostic.h"
30 #include "tree-flow.h"
31 #include "tree-pass.h"
32 #include "tree-stdarg.h"
34 /* A simple pass that attempts to optimize stdarg functions on architectures
35 that need to save register arguments to stack on entry to stdarg functions.
36 If the function doesn't use any va_start macros, no registers need to
37 be saved. If va_start macros are used, the va_list variables don't escape
38 the function, it is only necessary to save registers that will be used
39 in va_arg macros. E.g. if va_arg is only used with integral types
40 in the function, floating point registers don't need to be saved, etc. */
43 /* Return true if basic block VA_ARG_BB is dominated by VA_START_BB and
44 is executed at most as many times as VA_START_BB. */
47 reachable_at_most_once (basic_block va_arg_bb
, basic_block va_start_bb
)
49 VEC (edge
, heap
) *stack
= NULL
;
55 if (va_arg_bb
== va_start_bb
)
58 if (! dominated_by_p (CDI_DOMINATORS
, va_arg_bb
, va_start_bb
))
61 visited
= sbitmap_alloc (last_basic_block
);
62 sbitmap_zero (visited
);
65 FOR_EACH_EDGE (e
, ei
, va_arg_bb
->preds
)
66 VEC_safe_push (edge
, heap
, stack
, e
);
68 while (! VEC_empty (edge
, stack
))
72 e
= VEC_pop (edge
, stack
);
75 if (e
->flags
& EDGE_COMPLEX
)
81 if (src
== va_start_bb
)
84 /* va_arg_bb can be executed more times than va_start_bb. */
91 gcc_assert (src
!= ENTRY_BLOCK_PTR
);
93 if (! TEST_BIT (visited
, src
->index
))
95 SET_BIT (visited
, src
->index
);
96 FOR_EACH_EDGE (e
, ei
, src
->preds
)
97 VEC_safe_push (edge
, heap
, stack
, e
);
101 VEC_free (edge
, heap
, stack
);
102 sbitmap_free (visited
);
107 /* For statement COUNTER = RHS, if RHS is COUNTER + constant,
108 return constant, otherwise return (unsigned HOST_WIDE_INT) -1.
109 GPR_P is true if this is GPR counter. */
111 static unsigned HOST_WIDE_INT
112 va_list_counter_bump (struct stdarg_info
*si
, tree counter
, tree rhs
,
115 tree stmt
, lhs
, orig_lhs
;
116 unsigned HOST_WIDE_INT ret
= 0, val
, counter_val
;
117 unsigned int max_size
;
119 if (si
->offsets
== NULL
)
123 si
->offsets
= XNEWVEC (int, num_ssa_names
);
124 for (i
= 0; i
< num_ssa_names
; ++i
)
128 counter_val
= gpr_p
? cfun
->va_list_gpr_size
: cfun
->va_list_fpr_size
;
129 max_size
= gpr_p
? VA_LIST_MAX_GPR_SIZE
: VA_LIST_MAX_FPR_SIZE
;
130 orig_lhs
= lhs
= rhs
;
133 if (si
->offsets
[SSA_NAME_VERSION (lhs
)] != -1)
135 if (counter_val
>= max_size
)
141 ret
-= counter_val
- si
->offsets
[SSA_NAME_VERSION (lhs
)];
145 stmt
= SSA_NAME_DEF_STMT (lhs
);
147 if (TREE_CODE (stmt
) != GIMPLE_MODIFY_STMT
148 || GIMPLE_STMT_OPERAND (stmt
, 0) != lhs
)
149 return (unsigned HOST_WIDE_INT
) -1;
151 rhs
= GIMPLE_STMT_OPERAND (stmt
, 1);
152 if (TREE_CODE (rhs
) == WITH_SIZE_EXPR
)
153 rhs
= TREE_OPERAND (rhs
, 0);
155 if (TREE_CODE (rhs
) == SSA_NAME
)
161 if (CONVERT_EXPR_P (rhs
)
162 && TREE_CODE (TREE_OPERAND (rhs
, 0)) == SSA_NAME
)
164 lhs
= TREE_OPERAND (rhs
, 0);
168 if ((TREE_CODE (rhs
) == POINTER_PLUS_EXPR
169 || TREE_CODE (rhs
) == PLUS_EXPR
)
170 && TREE_CODE (TREE_OPERAND (rhs
, 0)) == SSA_NAME
171 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == INTEGER_CST
172 && host_integerp (TREE_OPERAND (rhs
, 1), 1))
174 ret
+= tree_low_cst (TREE_OPERAND (rhs
, 1), 1);
175 lhs
= TREE_OPERAND (rhs
, 0);
179 if (TREE_CODE (counter
) != TREE_CODE (rhs
))
180 return (unsigned HOST_WIDE_INT
) -1;
182 if (TREE_CODE (counter
) == COMPONENT_REF
)
184 if (get_base_address (counter
) != get_base_address (rhs
)
185 || TREE_CODE (TREE_OPERAND (rhs
, 1)) != FIELD_DECL
186 || TREE_OPERAND (counter
, 1) != TREE_OPERAND (rhs
, 1))
187 return (unsigned HOST_WIDE_INT
) -1;
189 else if (counter
!= rhs
)
190 return (unsigned HOST_WIDE_INT
) -1;
196 val
= ret
+ counter_val
;
199 if (si
->offsets
[SSA_NAME_VERSION (lhs
)] != -1)
203 si
->offsets
[SSA_NAME_VERSION (lhs
)] = max_size
;
205 si
->offsets
[SSA_NAME_VERSION (lhs
)] = val
;
207 stmt
= SSA_NAME_DEF_STMT (lhs
);
209 rhs
= GIMPLE_STMT_OPERAND (stmt
, 1);
210 if (TREE_CODE (rhs
) == WITH_SIZE_EXPR
)
211 rhs
= TREE_OPERAND (rhs
, 0);
213 if (TREE_CODE (rhs
) == SSA_NAME
)
219 if (CONVERT_EXPR_P (rhs
)
220 && TREE_CODE (TREE_OPERAND (rhs
, 0)) == SSA_NAME
)
222 lhs
= TREE_OPERAND (rhs
, 0);
226 if ((TREE_CODE (rhs
) == POINTER_PLUS_EXPR
227 || TREE_CODE (rhs
) == PLUS_EXPR
)
228 && TREE_CODE (TREE_OPERAND (rhs
, 0)) == SSA_NAME
229 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == INTEGER_CST
230 && host_integerp (TREE_OPERAND (rhs
, 1), 1))
232 val
-= tree_low_cst (TREE_OPERAND (rhs
, 1), 1);
233 lhs
= TREE_OPERAND (rhs
, 0);
244 /* Called by walk_tree to look for references to va_list variables. */
247 find_va_list_reference (tree
*tp
, int *walk_subtrees ATTRIBUTE_UNUSED
,
250 bitmap va_list_vars
= (bitmap
) data
;
253 if (TREE_CODE (var
) == SSA_NAME
)
254 var
= SSA_NAME_VAR (var
);
256 if (TREE_CODE (var
) == VAR_DECL
257 && bitmap_bit_p (va_list_vars
, DECL_UID (var
)))
264 /* Helper function of va_list_counter_struct_op. Compute
265 cfun->va_list_{g,f}pr_size. AP is a va_list GPR/FPR counter,
266 if WRITE_P is true, seen in AP = VAR, otherwise seen in VAR = AP
267 statement. GPR_P is true if AP is a GPR counter, false if it is
271 va_list_counter_op (struct stdarg_info
*si
, tree ap
, tree var
, bool gpr_p
,
274 unsigned HOST_WIDE_INT increment
;
276 if (si
->compute_sizes
< 0)
278 si
->compute_sizes
= 0;
279 if (si
->va_start_count
== 1
280 && reachable_at_most_once (si
->bb
, si
->va_start_bb
))
281 si
->compute_sizes
= 1;
283 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
285 "bb%d will %sbe executed at most once for each va_start "
286 "in bb%d\n", si
->bb
->index
, si
->compute_sizes
? "" : "not ",
287 si
->va_start_bb
->index
);
292 && (increment
= va_list_counter_bump (si
, ap
, var
, gpr_p
)) + 1 > 1)
294 if (gpr_p
&& cfun
->va_list_gpr_size
+ increment
< VA_LIST_MAX_GPR_SIZE
)
296 cfun
->va_list_gpr_size
+= increment
;
300 if (!gpr_p
&& cfun
->va_list_fpr_size
+ increment
< VA_LIST_MAX_FPR_SIZE
)
302 cfun
->va_list_fpr_size
+= increment
;
307 if (write_p
|| !si
->compute_sizes
)
310 cfun
->va_list_gpr_size
= VA_LIST_MAX_GPR_SIZE
;
312 cfun
->va_list_fpr_size
= VA_LIST_MAX_FPR_SIZE
;
317 /* If AP is a va_list GPR/FPR counter, compute cfun->va_list_{g,f}pr_size.
318 If WRITE_P is true, AP has been seen in AP = VAR assignment, if WRITE_P
319 is false, AP has been seen in VAR = AP assignment.
320 Return true if the AP = VAR (resp. VAR = AP) statement is a recognized
321 va_arg operation that doesn't cause the va_list variable to escape
325 va_list_counter_struct_op (struct stdarg_info
*si
, tree ap
, tree var
,
330 if (TREE_CODE (ap
) != COMPONENT_REF
331 || TREE_CODE (TREE_OPERAND (ap
, 1)) != FIELD_DECL
)
334 if (TREE_CODE (var
) != SSA_NAME
335 || bitmap_bit_p (si
->va_list_vars
, DECL_UID (SSA_NAME_VAR (var
))))
338 base
= get_base_address (ap
);
339 if (TREE_CODE (base
) != VAR_DECL
340 || !bitmap_bit_p (si
->va_list_vars
, DECL_UID (base
)))
343 if (TREE_OPERAND (ap
, 1) == va_list_gpr_counter_field
)
344 va_list_counter_op (si
, ap
, var
, true, write_p
);
345 else if (TREE_OPERAND (ap
, 1) == va_list_fpr_counter_field
)
346 va_list_counter_op (si
, ap
, var
, false, write_p
);
352 /* Check for TEM = AP. Return true if found and the caller shouldn't
353 search for va_list references in the statement. */
356 va_list_ptr_read (struct stdarg_info
*si
, tree ap
, tree tem
)
358 if (TREE_CODE (ap
) != VAR_DECL
359 || !bitmap_bit_p (si
->va_list_vars
, DECL_UID (ap
)))
362 if (TREE_CODE (tem
) != SSA_NAME
363 || bitmap_bit_p (si
->va_list_vars
,
364 DECL_UID (SSA_NAME_VAR (tem
)))
365 || is_global_var (SSA_NAME_VAR (tem
)))
368 if (si
->compute_sizes
< 0)
370 si
->compute_sizes
= 0;
371 if (si
->va_start_count
== 1
372 && reachable_at_most_once (si
->bb
, si
->va_start_bb
))
373 si
->compute_sizes
= 1;
375 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
377 "bb%d will %sbe executed at most once for each va_start "
378 "in bb%d\n", si
->bb
->index
, si
->compute_sizes
? "" : "not ",
379 si
->va_start_bb
->index
);
382 /* For void * or char * va_list types, there is just one counter.
383 If va_arg is used in a loop, we don't know how many registers need
385 if (! si
->compute_sizes
)
388 if (va_list_counter_bump (si
, ap
, tem
, true) == (unsigned HOST_WIDE_INT
) -1)
391 /* Note the temporary, as we need to track whether it doesn't escape
392 the current function. */
393 bitmap_set_bit (si
->va_list_escape_vars
,
394 DECL_UID (SSA_NAME_VAR (tem
)));
403 sequence and update cfun->va_list_gpr_size. Return true if found. */
406 va_list_ptr_write (struct stdarg_info
*si
, tree ap
, tree tem2
)
408 unsigned HOST_WIDE_INT increment
;
410 if (TREE_CODE (ap
) != VAR_DECL
411 || !bitmap_bit_p (si
->va_list_vars
, DECL_UID (ap
)))
414 if (TREE_CODE (tem2
) != SSA_NAME
415 || bitmap_bit_p (si
->va_list_vars
, DECL_UID (SSA_NAME_VAR (tem2
))))
418 if (si
->compute_sizes
<= 0)
421 increment
= va_list_counter_bump (si
, ap
, tem2
, true);
422 if (increment
+ 1 <= 1)
425 if (cfun
->va_list_gpr_size
+ increment
< VA_LIST_MAX_GPR_SIZE
)
426 cfun
->va_list_gpr_size
+= increment
;
428 cfun
->va_list_gpr_size
= VA_LIST_MAX_GPR_SIZE
;
434 /* If RHS is X, (some type *) X or X + CST for X a temporary variable
435 containing value of some va_list variable plus optionally some constant,
436 either set si->va_list_escapes or add LHS to si->va_list_escape_vars,
437 depending whether LHS is a function local temporary. */
440 check_va_list_escapes (struct stdarg_info
*si
, tree lhs
, tree rhs
)
442 if (! POINTER_TYPE_P (TREE_TYPE (rhs
)))
445 if (((TREE_CODE (rhs
) == POINTER_PLUS_EXPR
446 || TREE_CODE (rhs
) == PLUS_EXPR
)
447 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == INTEGER_CST
)
448 || CONVERT_EXPR_P (rhs
))
449 rhs
= TREE_OPERAND (rhs
, 0);
451 if (TREE_CODE (rhs
) != SSA_NAME
452 || ! bitmap_bit_p (si
->va_list_escape_vars
,
453 DECL_UID (SSA_NAME_VAR (rhs
))))
456 if (TREE_CODE (lhs
) != SSA_NAME
|| is_global_var (SSA_NAME_VAR (lhs
)))
458 si
->va_list_escapes
= true;
462 if (si
->compute_sizes
< 0)
464 si
->compute_sizes
= 0;
465 if (si
->va_start_count
== 1
466 && reachable_at_most_once (si
->bb
, si
->va_start_bb
))
467 si
->compute_sizes
= 1;
469 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
471 "bb%d will %sbe executed at most once for each va_start "
472 "in bb%d\n", si
->bb
->index
, si
->compute_sizes
? "" : "not ",
473 si
->va_start_bb
->index
);
476 /* For void * or char * va_list types, there is just one counter.
477 If va_arg is used in a loop, we don't know how many registers need
479 if (! si
->compute_sizes
)
481 si
->va_list_escapes
= true;
485 if (va_list_counter_bump (si
, si
->va_start_ap
, lhs
, true)
486 == (unsigned HOST_WIDE_INT
) -1)
488 si
->va_list_escapes
= true;
492 bitmap_set_bit (si
->va_list_escape_vars
,
493 DECL_UID (SSA_NAME_VAR (lhs
)));
497 /* Check all uses of temporaries from si->va_list_escape_vars bitmap.
498 Return true if va_list might be escaping. */
501 check_all_va_list_escapes (struct stdarg_info
*si
)
507 block_stmt_iterator i
;
509 for (i
= bsi_start (bb
); !bsi_end_p (i
); bsi_next (&i
))
511 tree stmt
= bsi_stmt (i
), use
;
514 FOR_EACH_SSA_TREE_OPERAND (use
, stmt
, iter
, SSA_OP_ALL_USES
)
516 if (! bitmap_bit_p (si
->va_list_escape_vars
,
517 DECL_UID (SSA_NAME_VAR (use
))))
520 if (TREE_CODE (stmt
) == GIMPLE_MODIFY_STMT
)
522 tree lhs
= GIMPLE_STMT_OPERAND (stmt
, 0);
523 tree rhs
= GIMPLE_STMT_OPERAND (stmt
, 1);
525 if (TREE_CODE (rhs
) == WITH_SIZE_EXPR
)
526 rhs
= TREE_OPERAND (rhs
, 0);
529 if (TREE_CODE (rhs
) == INDIRECT_REF
530 && TREE_OPERAND (rhs
, 0) == use
531 && TYPE_SIZE_UNIT (TREE_TYPE (rhs
))
532 && host_integerp (TYPE_SIZE_UNIT (TREE_TYPE (rhs
)), 1)
533 && si
->offsets
[SSA_NAME_VERSION (use
)] != -1)
535 unsigned HOST_WIDE_INT gpr_size
;
536 tree access_size
= TYPE_SIZE_UNIT (TREE_TYPE (rhs
));
538 gpr_size
= si
->offsets
[SSA_NAME_VERSION (use
)]
539 + tree_low_cst (access_size
, 1);
540 if (gpr_size
>= VA_LIST_MAX_GPR_SIZE
)
541 cfun
->va_list_gpr_size
= VA_LIST_MAX_GPR_SIZE
;
542 else if (gpr_size
> cfun
->va_list_gpr_size
)
543 cfun
->va_list_gpr_size
= gpr_size
;
547 /* va_arg sequences may contain
548 other_ap_temp = ap_temp;
549 other_ap_temp = ap_temp + constant;
550 other_ap_temp = (some_type *) ap_temp;
553 if ((TREE_CODE (rhs
) == POINTER_PLUS_EXPR
554 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == INTEGER_CST
)
555 || CONVERT_EXPR_P (rhs
))
556 rhs
= TREE_OPERAND (rhs
, 0);
560 if (TREE_CODE (lhs
) == SSA_NAME
561 && bitmap_bit_p (si
->va_list_escape_vars
,
562 DECL_UID (SSA_NAME_VAR (lhs
))))
565 if (TREE_CODE (lhs
) == VAR_DECL
566 && bitmap_bit_p (si
->va_list_vars
,
572 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
574 fputs ("va_list escapes in ", dump_file
);
575 print_generic_expr (dump_file
, stmt
, dump_flags
);
576 fputc ('\n', dump_file
);
587 /* Return true if this optimization pass should be done.
588 It makes only sense for stdarg functions. */
591 gate_optimize_stdarg (void)
593 /* This optimization is only for stdarg functions. */
594 return cfun
->stdarg
!= 0;
598 /* Entry point to the stdarg optimization pass. */
601 execute_optimize_stdarg (void)
604 bool va_list_escapes
= false;
605 bool va_list_simple_ptr
;
606 struct stdarg_info si
;
607 const char *funcname
= NULL
;
609 cfun
->va_list_gpr_size
= 0;
610 cfun
->va_list_fpr_size
= 0;
611 memset (&si
, 0, sizeof (si
));
612 si
.va_list_vars
= BITMAP_ALLOC (NULL
);
613 si
.va_list_escape_vars
= BITMAP_ALLOC (NULL
);
616 funcname
= lang_hooks
.decl_printable_name (current_function_decl
, 2);
618 va_list_simple_ptr
= POINTER_TYPE_P (va_list_type_node
)
619 && (TREE_TYPE (va_list_type_node
) == void_type_node
620 || TREE_TYPE (va_list_type_node
) == char_type_node
);
621 gcc_assert (is_gimple_reg_type (va_list_type_node
) == va_list_simple_ptr
);
625 block_stmt_iterator i
;
627 for (i
= bsi_start (bb
); !bsi_end_p (i
); bsi_next (&i
))
629 tree stmt
= bsi_stmt (i
);
630 tree call
= get_call_expr_in (stmt
), callee
;
636 callee
= get_callee_fndecl (call
);
638 || DECL_BUILT_IN_CLASS (callee
) != BUILT_IN_NORMAL
)
641 switch (DECL_FUNCTION_CODE (callee
))
643 case BUILT_IN_VA_START
:
645 /* If old style builtins are used, don't optimize anything. */
646 case BUILT_IN_SAVEREGS
:
647 case BUILT_IN_ARGS_INFO
:
648 case BUILT_IN_NEXT_ARG
:
649 va_list_escapes
= true;
656 ap
= CALL_EXPR_ARG (call
, 0);
658 if (TREE_CODE (ap
) != ADDR_EXPR
)
660 va_list_escapes
= true;
663 ap
= TREE_OPERAND (ap
, 0);
664 if (TREE_CODE (ap
) == ARRAY_REF
)
666 if (! integer_zerop (TREE_OPERAND (ap
, 1)))
668 va_list_escapes
= true;
671 ap
= TREE_OPERAND (ap
, 0);
673 if (TYPE_MAIN_VARIANT (TREE_TYPE (ap
))
674 != TYPE_MAIN_VARIANT (va_list_type_node
)
675 || TREE_CODE (ap
) != VAR_DECL
)
677 va_list_escapes
= true;
681 if (is_global_var (ap
))
683 va_list_escapes
= true;
687 bitmap_set_bit (si
.va_list_vars
, DECL_UID (ap
));
689 /* VA_START_BB and VA_START_AP will be only used if there is just
690 one va_start in the function. */
699 /* If there were no va_start uses in the function, there is no need to
701 if (si
.va_start_count
== 0)
704 /* If some va_list arguments weren't local, we can't optimize. */
708 /* For void * or char * va_list, something useful can be done only
709 if there is just one va_start. */
710 if (va_list_simple_ptr
&& si
.va_start_count
> 1)
712 va_list_escapes
= true;
716 /* For struct * va_list, if the backend didn't tell us what the counter fields
717 are, there is nothing more we can do. */
718 if (!va_list_simple_ptr
719 && va_list_gpr_counter_field
== NULL_TREE
720 && va_list_fpr_counter_field
== NULL_TREE
)
722 va_list_escapes
= true;
726 /* For void * or char * va_list there is just one counter
727 (va_list itself). Use VA_LIST_GPR_SIZE for it. */
728 if (va_list_simple_ptr
)
729 cfun
->va_list_fpr_size
= VA_LIST_MAX_FPR_SIZE
;
731 calculate_dominance_info (CDI_DOMINATORS
);
735 block_stmt_iterator i
;
737 si
.compute_sizes
= -1;
740 /* For va_list_simple_ptr, we have to check PHI nodes too. We treat
741 them as assignments for the purpose of escape analysis. This is
742 not needed for non-simple va_list because virtual phis don't perform
743 any real data movement. */
744 if (va_list_simple_ptr
)
750 for (phi
= phi_nodes (bb
); phi
; phi
= PHI_CHAIN (phi
))
752 lhs
= PHI_RESULT (phi
);
754 if (!is_gimple_reg (lhs
))
757 FOR_EACH_PHI_ARG (uop
, phi
, soi
, SSA_OP_USE
)
759 rhs
= USE_FROM_PTR (uop
);
760 if (va_list_ptr_read (&si
, rhs
, lhs
))
762 else if (va_list_ptr_write (&si
, lhs
, rhs
))
765 check_va_list_escapes (&si
, lhs
, rhs
);
767 if (si
.va_list_escapes
768 || walk_tree (&phi
, find_va_list_reference
,
769 si
.va_list_vars
, NULL
))
771 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
773 fputs ("va_list escapes in ", dump_file
);
774 print_generic_expr (dump_file
, phi
, dump_flags
);
775 fputc ('\n', dump_file
);
777 va_list_escapes
= true;
783 for (i
= bsi_start (bb
);
784 !bsi_end_p (i
) && !va_list_escapes
;
787 tree stmt
= bsi_stmt (i
);
790 /* Don't look at __builtin_va_{start,end}, they are ok. */
791 call
= get_call_expr_in (stmt
);
794 tree callee
= get_callee_fndecl (call
);
797 && DECL_BUILT_IN_CLASS (callee
) == BUILT_IN_NORMAL
798 && (DECL_FUNCTION_CODE (callee
) == BUILT_IN_VA_START
799 || DECL_FUNCTION_CODE (callee
) == BUILT_IN_VA_END
))
803 if (TREE_CODE (stmt
) == GIMPLE_MODIFY_STMT
)
805 tree lhs
= GIMPLE_STMT_OPERAND (stmt
, 0);
806 tree rhs
= GIMPLE_STMT_OPERAND (stmt
, 1);
808 if (TREE_CODE (rhs
) == WITH_SIZE_EXPR
)
809 rhs
= TREE_OPERAND (rhs
, 0);
811 if (va_list_simple_ptr
)
813 /* Check for tem = ap. */
814 if (va_list_ptr_read (&si
, rhs
, lhs
))
817 /* Check for the last insn in:
822 else if (va_list_ptr_write (&si
, lhs
, rhs
))
826 check_va_list_escapes (&si
, lhs
, rhs
);
830 /* Check for ap[0].field = temp. */
831 if (va_list_counter_struct_op (&si
, lhs
, rhs
, true))
834 /* Check for temp = ap[0].field. */
835 else if (va_list_counter_struct_op (&si
, rhs
, lhs
, false))
838 /* Do any architecture specific checking. */
839 else if (targetm
.stdarg_optimize_hook
840 && targetm
.stdarg_optimize_hook (&si
, lhs
, rhs
))
845 /* All other uses of va_list are either va_copy (that is not handled
846 in this optimization), taking address of va_list variable or
847 passing va_list to other functions (in that case va_list might
848 escape the function and therefore va_start needs to set it up
849 fully), or some unexpected use of va_list. None of these should
850 happen in a gimplified VA_ARG_EXPR. */
851 if (si
.va_list_escapes
852 || walk_tree (&stmt
, find_va_list_reference
,
853 si
.va_list_vars
, NULL
))
855 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
857 fputs ("va_list escapes in ", dump_file
);
858 print_generic_expr (dump_file
, stmt
, dump_flags
);
859 fputc ('\n', dump_file
);
861 va_list_escapes
= true;
869 if (! va_list_escapes
870 && va_list_simple_ptr
871 && ! bitmap_empty_p (si
.va_list_escape_vars
)
872 && check_all_va_list_escapes (&si
))
873 va_list_escapes
= true;
878 cfun
->va_list_gpr_size
= VA_LIST_MAX_GPR_SIZE
;
879 cfun
->va_list_fpr_size
= VA_LIST_MAX_FPR_SIZE
;
881 BITMAP_FREE (si
.va_list_vars
);
882 BITMAP_FREE (si
.va_list_escape_vars
);
886 fprintf (dump_file
, "%s: va_list escapes %d, needs to save ",
887 funcname
, (int) va_list_escapes
);
888 if (cfun
->va_list_gpr_size
>= VA_LIST_MAX_GPR_SIZE
)
889 fputs ("all", dump_file
);
891 fprintf (dump_file
, "%d", cfun
->va_list_gpr_size
);
892 fputs (" GPR units and ", dump_file
);
893 if (cfun
->va_list_fpr_size
>= VA_LIST_MAX_FPR_SIZE
)
894 fputs ("all", dump_file
);
896 fprintf (dump_file
, "%d", cfun
->va_list_fpr_size
);
897 fputs (" FPR units.\n", dump_file
);
903 struct gimple_opt_pass pass_stdarg
=
908 gate_optimize_stdarg
, /* gate */
909 execute_optimize_stdarg
, /* execute */
912 0, /* static_pass_number */
914 PROP_cfg
| PROP_ssa
| PROP_alias
, /* properties_required */
915 0, /* properties_provided */
916 0, /* properties_destroyed */
917 0, /* todo_flags_start */
918 TODO_dump_func
/* todo_flags_finish */