1 /* Gimple IR support functions.
3 Copyright 2007, 2008, 2009 Free Software Foundation, Inc.
4 Contributed by Aldy Hernandez <aldyh@redhat.com>
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"
28 #include "hard-reg-set.h"
29 #include "basic-block.h"
32 #include "diagnostic.h"
33 #include "tree-flow.h"
34 #include "value-prof.h"
37 #define DEFGSCODE(SYM, NAME, STRUCT) NAME,
38 const char *const gimple_code_name[] = {
43 /* All the tuples have their operand vector at the very bottom
44 of the structure. Therefore, the offset required to find the
45 operands vector the size of the structure minus the size of the 1
46 element tree array at the end (see gimple_ops). */
47 #define DEFGSCODE(SYM, NAME, STRUCT) (sizeof (STRUCT) - sizeof (tree)),
48 const size_t gimple_ops_offset_[] = {
53 #ifdef GATHER_STATISTICS
56 int gimple_alloc_counts[(int) gimple_alloc_kind_all];
57 int gimple_alloc_sizes[(int) gimple_alloc_kind_all];
59 /* Keep in sync with gimple.h:enum gimple_alloc_kind. */
60 static const char * const gimple_alloc_kind_names[] = {
68 #endif /* GATHER_STATISTICS */
70 /* A cache of gimple_seq objects. Sequences are created and destroyed
71 fairly often during gimplification. */
72 static GTY ((deletable)) struct gimple_seq_d *gimple_seq_cache;
74 /* Private API manipulation functions shared only with some
76 extern void gimple_set_stored_syms (gimple, bitmap, bitmap_obstack *);
77 extern void gimple_set_loaded_syms (gimple, bitmap, bitmap_obstack *);
79 /* Gimple tuple constructors.
80 Note: Any constructor taking a ``gimple_seq'' as a parameter, can
81 be passed a NULL to start with an empty sequence. */
83 /* Set the code for statement G to CODE. */
86 gimple_set_code (gimple g, enum gimple_code code)
88 g->gsbase.code = code;
92 /* Return the GSS_* identifier for the given GIMPLE statement CODE. */
94 static enum gimple_statement_structure_enum
95 gss_for_code (enum gimple_code code)
101 case GIMPLE_RETURN: return GSS_WITH_MEM_OPS;
105 case GIMPLE_CHANGE_DYNAMIC_TYPE:
106 case GIMPLE_SWITCH: return GSS_WITH_OPS;
107 case GIMPLE_ASM: return GSS_ASM;
108 case GIMPLE_BIND: return GSS_BIND;
109 case GIMPLE_CATCH: return GSS_CATCH;
110 case GIMPLE_EH_FILTER: return GSS_EH_FILTER;
111 case GIMPLE_NOP: return GSS_BASE;
112 case GIMPLE_PHI: return GSS_PHI;
113 case GIMPLE_RESX: return GSS_RESX;
114 case GIMPLE_TRY: return GSS_TRY;
115 case GIMPLE_WITH_CLEANUP_EXPR: return GSS_WCE;
116 case GIMPLE_OMP_CRITICAL: return GSS_OMP_CRITICAL;
117 case GIMPLE_OMP_FOR: return GSS_OMP_FOR;
118 case GIMPLE_OMP_MASTER:
119 case GIMPLE_OMP_ORDERED:
120 case GIMPLE_OMP_SECTION: return GSS_OMP;
121 case GIMPLE_OMP_RETURN:
122 case GIMPLE_OMP_SECTIONS_SWITCH: return GSS_BASE;
123 case GIMPLE_OMP_CONTINUE: return GSS_OMP_CONTINUE;
124 case GIMPLE_OMP_PARALLEL: return GSS_OMP_PARALLEL;
125 case GIMPLE_OMP_TASK: return GSS_OMP_TASK;
126 case GIMPLE_OMP_SECTIONS: return GSS_OMP_SECTIONS;
127 case GIMPLE_OMP_SINGLE: return GSS_OMP_SINGLE;
128 case GIMPLE_OMP_ATOMIC_LOAD: return GSS_OMP_ATOMIC_LOAD;
129 case GIMPLE_OMP_ATOMIC_STORE: return GSS_OMP_ATOMIC_STORE;
130 case GIMPLE_PREDICT: return GSS_BASE;
131 default: gcc_unreachable ();
136 /* Return the number of bytes needed to hold a GIMPLE statement with
140 gimple_size (enum gimple_code code)
142 enum gimple_statement_structure_enum gss = gss_for_code (code);
144 if (gss == GSS_WITH_OPS)
145 return sizeof (struct gimple_statement_with_ops);
146 else if (gss == GSS_WITH_MEM_OPS)
147 return sizeof (struct gimple_statement_with_memory_ops);
152 return sizeof (struct gimple_statement_asm);
154 return sizeof (struct gimple_statement_base);
156 return sizeof (struct gimple_statement_bind);
158 return sizeof (struct gimple_statement_catch);
159 case GIMPLE_EH_FILTER:
160 return sizeof (struct gimple_statement_eh_filter);
162 return sizeof (struct gimple_statement_try);
164 return sizeof (struct gimple_statement_resx);
165 case GIMPLE_OMP_CRITICAL:
166 return sizeof (struct gimple_statement_omp_critical);
168 return sizeof (struct gimple_statement_omp_for);
169 case GIMPLE_OMP_PARALLEL:
170 return sizeof (struct gimple_statement_omp_parallel);
171 case GIMPLE_OMP_TASK:
172 return sizeof (struct gimple_statement_omp_task);
173 case GIMPLE_OMP_SECTION:
174 case GIMPLE_OMP_MASTER:
175 case GIMPLE_OMP_ORDERED:
176 return sizeof (struct gimple_statement_omp);
177 case GIMPLE_OMP_RETURN:
178 return sizeof (struct gimple_statement_base);
179 case GIMPLE_OMP_CONTINUE:
180 return sizeof (struct gimple_statement_omp_continue);
181 case GIMPLE_OMP_SECTIONS:
182 return sizeof (struct gimple_statement_omp_sections);
183 case GIMPLE_OMP_SECTIONS_SWITCH:
184 return sizeof (struct gimple_statement_base);
185 case GIMPLE_OMP_SINGLE:
186 return sizeof (struct gimple_statement_omp_single);
187 case GIMPLE_OMP_ATOMIC_LOAD:
188 return sizeof (struct gimple_statement_omp_atomic_load);
189 case GIMPLE_OMP_ATOMIC_STORE:
190 return sizeof (struct gimple_statement_omp_atomic_store);
191 case GIMPLE_WITH_CLEANUP_EXPR:
192 return sizeof (struct gimple_statement_wce);
193 case GIMPLE_CHANGE_DYNAMIC_TYPE:
194 return sizeof (struct gimple_statement_with_ops);
196 return sizeof (struct gimple_statement_base);
205 /* Allocate memory for a GIMPLE statement with code CODE and NUM_OPS
208 #define gimple_alloc(c, n) gimple_alloc_stat (c, n MEM_STAT_INFO)
210 gimple_alloc_stat (enum gimple_code code, unsigned num_ops MEM_STAT_DECL)
215 size = gimple_size (code);
217 size += sizeof (tree) * (num_ops - 1);
219 #ifdef GATHER_STATISTICS
221 enum gimple_alloc_kind kind = gimple_alloc_kind (code);
222 gimple_alloc_counts[(int) kind]++;
223 gimple_alloc_sizes[(int) kind] += size;
227 stmt = (gimple) ggc_alloc_cleared_stat (size PASS_MEM_STAT);
228 gimple_set_code (stmt, code);
229 gimple_set_num_ops (stmt, num_ops);
231 /* Do not call gimple_set_modified here as it has other side
232 effects and this tuple is still not completely built. */
233 stmt->gsbase.modified = 1;
238 /* Set SUBCODE to be the code of the expression computed by statement G. */
241 gimple_set_subcode (gimple g, unsigned subcode)
243 /* We only have 16 bits for the RHS code. Assert that we are not
245 gcc_assert (subcode < (1 << 16));
246 g->gsbase.subcode = subcode;
251 /* Build a tuple with operands. CODE is the statement to build (which
252 must be one of the GIMPLE_WITH_OPS tuples). SUBCODE is the sub-code
253 for the new tuple. NUM_OPS is the number of operands to allocate. */
255 #define gimple_build_with_ops(c, s, n) \
256 gimple_build_with_ops_stat (c, s, n MEM_STAT_INFO)
259 gimple_build_with_ops_stat (enum gimple_code code, enum tree_code subcode,
260 unsigned num_ops MEM_STAT_DECL)
262 gimple s = gimple_alloc_stat (code, num_ops PASS_MEM_STAT);
263 gimple_set_subcode (s, subcode);
269 /* Build a GIMPLE_RETURN statement returning RETVAL. */
272 gimple_build_return (tree retval)
274 gimple s = gimple_build_with_ops (GIMPLE_RETURN, ERROR_MARK, 1);
276 gimple_return_set_retval (s, retval);
280 /* Helper for gimple_build_call, gimple_build_call_vec and
281 gimple_build_call_from_tree. Build the basic components of a
282 GIMPLE_CALL statement to function FN with NARGS arguments. */
285 gimple_build_call_1 (tree fn, unsigned nargs)
287 gimple s = gimple_build_with_ops (GIMPLE_CALL, ERROR_MARK, nargs + 3);
288 if (TREE_CODE (fn) == FUNCTION_DECL)
289 fn = build_fold_addr_expr (fn);
290 gimple_set_op (s, 1, fn);
295 /* Build a GIMPLE_CALL statement to function FN with the arguments
296 specified in vector ARGS. */
299 gimple_build_call_vec (tree fn, VEC(tree, heap) *args)
302 unsigned nargs = VEC_length (tree, args);
303 gimple call = gimple_build_call_1 (fn, nargs);
305 for (i = 0; i < nargs; i++)
306 gimple_call_set_arg (call, i, VEC_index (tree, args, i));
312 /* Build a GIMPLE_CALL statement to function FN. NARGS is the number of
313 arguments. The ... are the arguments. */
316 gimple_build_call (tree fn, unsigned nargs, ...)
322 gcc_assert (TREE_CODE (fn) == FUNCTION_DECL || is_gimple_call_addr (fn));
324 call = gimple_build_call_1 (fn, nargs);
326 va_start (ap, nargs);
327 for (i = 0; i < nargs; i++)
328 gimple_call_set_arg (call, i, va_arg (ap, tree));
335 /* Build a GIMPLE_CALL statement from CALL_EXPR T. Note that T is
336 assumed to be in GIMPLE form already. Minimal checking is done of
340 gimple_build_call_from_tree (tree t)
344 tree fndecl = get_callee_fndecl (t);
346 gcc_assert (TREE_CODE (t) == CALL_EXPR);
348 nargs = call_expr_nargs (t);
349 call = gimple_build_call_1 (fndecl ? fndecl : CALL_EXPR_FN (t), nargs);
351 for (i = 0; i < nargs; i++)
352 gimple_call_set_arg (call, i, CALL_EXPR_ARG (t, i));
354 gimple_set_block (call, TREE_BLOCK (t));
356 /* Carry all the CALL_EXPR flags to the new GIMPLE_CALL. */
357 gimple_call_set_chain (call, CALL_EXPR_STATIC_CHAIN (t));
358 gimple_call_set_tail (call, CALL_EXPR_TAILCALL (t));
359 gimple_call_set_cannot_inline (call, CALL_CANNOT_INLINE_P (t));
360 gimple_call_set_return_slot_opt (call, CALL_EXPR_RETURN_SLOT_OPT (t));
361 gimple_call_set_from_thunk (call, CALL_FROM_THUNK_P (t));
362 gimple_call_set_va_arg_pack (call, CALL_EXPR_VA_ARG_PACK (t));
368 /* Extract the operands and code for expression EXPR into *SUBCODE_P,
369 *OP1_P and *OP2_P respectively. */
372 extract_ops_from_tree (tree expr, enum tree_code *subcode_p, tree *op1_p,
375 enum gimple_rhs_class grhs_class;
377 *subcode_p = TREE_CODE (expr);
378 grhs_class = get_gimple_rhs_class (*subcode_p);
380 if (grhs_class == GIMPLE_BINARY_RHS)
382 *op1_p = TREE_OPERAND (expr, 0);
383 *op2_p = TREE_OPERAND (expr, 1);
385 else if (grhs_class == GIMPLE_UNARY_RHS)
387 *op1_p = TREE_OPERAND (expr, 0);
390 else if (grhs_class == GIMPLE_SINGLE_RHS)
400 /* Build a GIMPLE_ASSIGN statement.
402 LHS of the assignment.
403 RHS of the assignment which can be unary or binary. */
406 gimple_build_assign_stat (tree lhs, tree rhs MEM_STAT_DECL)
408 enum tree_code subcode;
411 extract_ops_from_tree (rhs, &subcode, &op1, &op2);
412 return gimple_build_assign_with_ops_stat (subcode, lhs, op1, op2
417 /* Build a GIMPLE_ASSIGN statement with sub-code SUBCODE and operands
418 OP1 and OP2. If OP2 is NULL then SUBCODE must be of class
419 GIMPLE_UNARY_RHS or GIMPLE_SINGLE_RHS. */
422 gimple_build_assign_with_ops_stat (enum tree_code subcode, tree lhs, tree op1,
423 tree op2 MEM_STAT_DECL)
428 /* Need 1 operand for LHS and 1 or 2 for the RHS (depending on the
430 num_ops = get_gimple_rhs_num_ops (subcode) + 1;
432 p = gimple_build_with_ops_stat (GIMPLE_ASSIGN, subcode, num_ops
434 gimple_assign_set_lhs (p, lhs);
435 gimple_assign_set_rhs1 (p, op1);
438 gcc_assert (num_ops > 2);
439 gimple_assign_set_rhs2 (p, op2);
446 /* Build a new GIMPLE_ASSIGN tuple and append it to the end of *SEQ_P.
448 DST/SRC are the destination and source respectively. You can pass
449 ungimplified trees in DST or SRC, in which case they will be
450 converted to a gimple operand if necessary.
452 This function returns the newly created GIMPLE_ASSIGN tuple. */
455 gimplify_assign (tree dst, tree src, gimple_seq *seq_p)
457 tree t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
458 gimplify_and_add (t, seq_p);
460 return gimple_seq_last_stmt (*seq_p);
464 /* Build a GIMPLE_COND statement.
466 PRED is the condition used to compare LHS and the RHS.
467 T_LABEL is the label to jump to if the condition is true.
468 F_LABEL is the label to jump to otherwise. */
471 gimple_build_cond (enum tree_code pred_code, tree lhs, tree rhs,
472 tree t_label, tree f_label)
476 gcc_assert (TREE_CODE_CLASS (pred_code) == tcc_comparison);
477 p = gimple_build_with_ops (GIMPLE_COND, pred_code, 4);
478 gimple_cond_set_lhs (p, lhs);
479 gimple_cond_set_rhs (p, rhs);
480 gimple_cond_set_true_label (p, t_label);
481 gimple_cond_set_false_label (p, f_label);
486 /* Extract operands for a GIMPLE_COND statement out of COND_EXPR tree COND. */
489 gimple_cond_get_ops_from_tree (tree cond, enum tree_code *code_p,
490 tree *lhs_p, tree *rhs_p)
492 gcc_assert (TREE_CODE_CLASS (TREE_CODE (cond)) == tcc_comparison
493 || TREE_CODE (cond) == TRUTH_NOT_EXPR
494 || is_gimple_min_invariant (cond)
495 || SSA_VAR_P (cond));
497 extract_ops_from_tree (cond, code_p, lhs_p, rhs_p);
499 /* Canonicalize conditionals of the form 'if (!VAL)'. */
500 if (*code_p == TRUTH_NOT_EXPR)
503 gcc_assert (*lhs_p && *rhs_p == NULL_TREE);
504 *rhs_p = fold_convert (TREE_TYPE (*lhs_p), integer_zero_node);
506 /* Canonicalize conditionals of the form 'if (VAL)' */
507 else if (TREE_CODE_CLASS (*code_p) != tcc_comparison)
510 gcc_assert (*lhs_p && *rhs_p == NULL_TREE);
511 *rhs_p = fold_convert (TREE_TYPE (*lhs_p), integer_zero_node);
516 /* Build a GIMPLE_COND statement from the conditional expression tree
517 COND. T_LABEL and F_LABEL are as in gimple_build_cond. */
520 gimple_build_cond_from_tree (tree cond, tree t_label, tree f_label)
525 gimple_cond_get_ops_from_tree (cond, &code, &lhs, &rhs);
526 return gimple_build_cond (code, lhs, rhs, t_label, f_label);
529 /* Set code, lhs, and rhs of a GIMPLE_COND from a suitable
530 boolean expression tree COND. */
533 gimple_cond_set_condition_from_tree (gimple stmt, tree cond)
538 gimple_cond_get_ops_from_tree (cond, &code, &lhs, &rhs);
539 gimple_cond_set_condition (stmt, code, lhs, rhs);
542 /* Build a GIMPLE_LABEL statement for LABEL. */
545 gimple_build_label (tree label)
547 gimple p = gimple_build_with_ops (GIMPLE_LABEL, ERROR_MARK, 1);
548 gimple_label_set_label (p, label);
552 /* Build a GIMPLE_GOTO statement to label DEST. */
555 gimple_build_goto (tree dest)
557 gimple p = gimple_build_with_ops (GIMPLE_GOTO, ERROR_MARK, 1);
558 gimple_goto_set_dest (p, dest);
563 /* Build a GIMPLE_NOP statement. */
566 gimple_build_nop (void)
568 return gimple_alloc (GIMPLE_NOP, 0);
572 /* Build a GIMPLE_BIND statement.
573 VARS are the variables in BODY.
574 BLOCK is the containing block. */
577 gimple_build_bind (tree vars, gimple_seq body, tree block)
579 gimple p = gimple_alloc (GIMPLE_BIND, 0);
580 gimple_bind_set_vars (p, vars);
582 gimple_bind_set_body (p, body);
584 gimple_bind_set_block (p, block);
588 /* Helper function to set the simple fields of a asm stmt.
590 STRING is a pointer to a string that is the asm blocks assembly code.
591 NINPUT is the number of register inputs.
592 NOUTPUT is the number of register outputs.
593 NCLOBBERS is the number of clobbered registers.
597 gimple_build_asm_1 (const char *string, unsigned ninputs, unsigned noutputs,
601 int size = strlen (string);
603 p = gimple_build_with_ops (GIMPLE_ASM, ERROR_MARK,
604 ninputs + noutputs + nclobbers);
606 p->gimple_asm.ni = ninputs;
607 p->gimple_asm.no = noutputs;
608 p->gimple_asm.nc = nclobbers;
609 p->gimple_asm.string = ggc_alloc_string (string, size);
611 #ifdef GATHER_STATISTICS
612 gimple_alloc_sizes[(int) gimple_alloc_kind (GIMPLE_ASM)] += size;
618 /* Build a GIMPLE_ASM statement.
620 STRING is the assembly code.
621 NINPUT is the number of register inputs.
622 NOUTPUT is the number of register outputs.
623 NCLOBBERS is the number of clobbered registers.
624 INPUTS is a vector of the input register parameters.
625 OUTPUTS is a vector of the output register parameters.
626 CLOBBERS is a vector of the clobbered register parameters. */
629 gimple_build_asm_vec (const char *string, VEC(tree,gc)* inputs,
630 VEC(tree,gc)* outputs, VEC(tree,gc)* clobbers)
635 p = gimple_build_asm_1 (string,
636 VEC_length (tree, inputs),
637 VEC_length (tree, outputs),
638 VEC_length (tree, clobbers));
640 for (i = 0; i < VEC_length (tree, inputs); i++)
641 gimple_asm_set_input_op (p, i, VEC_index (tree, inputs, i));
643 for (i = 0; i < VEC_length (tree, outputs); i++)
644 gimple_asm_set_output_op (p, i, VEC_index (tree, outputs, i));
646 for (i = 0; i < VEC_length (tree, clobbers); i++)
647 gimple_asm_set_clobber_op (p, i, VEC_index (tree, clobbers, i));
652 /* Build a GIMPLE_ASM statement.
654 STRING is the assembly code.
655 NINPUT is the number of register inputs.
656 NOUTPUT is the number of register outputs.
657 NCLOBBERS is the number of clobbered registers.
658 ... are trees for each input, output and clobbered register. */
661 gimple_build_asm (const char *string, unsigned ninputs, unsigned noutputs,
662 unsigned nclobbers, ...)
668 p = gimple_build_asm_1 (string, ninputs, noutputs, nclobbers);
670 va_start (ap, nclobbers);
672 for (i = 0; i < ninputs; i++)
673 gimple_asm_set_input_op (p, i, va_arg (ap, tree));
675 for (i = 0; i < noutputs; i++)
676 gimple_asm_set_output_op (p, i, va_arg (ap, tree));
678 for (i = 0; i < nclobbers; i++)
679 gimple_asm_set_clobber_op (p, i, va_arg (ap, tree));
686 /* Build a GIMPLE_CATCH statement.
688 TYPES are the catch types.
689 HANDLER is the exception handler. */
692 gimple_build_catch (tree types, gimple_seq handler)
694 gimple p = gimple_alloc (GIMPLE_CATCH, 0);
695 gimple_catch_set_types (p, types);
697 gimple_catch_set_handler (p, handler);
702 /* Build a GIMPLE_EH_FILTER statement.
704 TYPES are the filter's types.
705 FAILURE is the filter's failure action. */
708 gimple_build_eh_filter (tree types, gimple_seq failure)
710 gimple p = gimple_alloc (GIMPLE_EH_FILTER, 0);
711 gimple_eh_filter_set_types (p, types);
713 gimple_eh_filter_set_failure (p, failure);
718 /* Build a GIMPLE_TRY statement.
720 EVAL is the expression to evaluate.
721 CLEANUP is the cleanup expression.
722 KIND is either GIMPLE_TRY_CATCH or GIMPLE_TRY_FINALLY depending on
723 whether this is a try/catch or a try/finally respectively. */
726 gimple_build_try (gimple_seq eval, gimple_seq cleanup,
727 enum gimple_try_flags kind)
731 gcc_assert (kind == GIMPLE_TRY_CATCH || kind == GIMPLE_TRY_FINALLY);
732 p = gimple_alloc (GIMPLE_TRY, 0);
733 gimple_set_subcode (p, kind);
735 gimple_try_set_eval (p, eval);
737 gimple_try_set_cleanup (p, cleanup);
742 /* Construct a GIMPLE_WITH_CLEANUP_EXPR statement.
744 CLEANUP is the cleanup expression. */
747 gimple_build_wce (gimple_seq cleanup)
749 gimple p = gimple_alloc (GIMPLE_WITH_CLEANUP_EXPR, 0);
751 gimple_wce_set_cleanup (p, cleanup);
757 /* Build a GIMPLE_RESX statement.
759 REGION is the region number from which this resx causes control flow to
763 gimple_build_resx (int region)
765 gimple p = gimple_alloc (GIMPLE_RESX, 0);
766 gimple_resx_set_region (p, region);
771 /* The helper for constructing a gimple switch statement.
772 INDEX is the switch's index.
773 NLABELS is the number of labels in the switch excluding the default.
774 DEFAULT_LABEL is the default label for the switch statement. */
777 gimple_build_switch_1 (unsigned nlabels, tree index, tree default_label)
779 /* nlabels + 1 default label + 1 index. */
780 gimple p = gimple_build_with_ops (GIMPLE_SWITCH, ERROR_MARK,
782 gimple_switch_set_index (p, index);
783 gimple_switch_set_default_label (p, default_label);
788 /* Build a GIMPLE_SWITCH statement.
790 INDEX is the switch's index.
791 NLABELS is the number of labels in the switch excluding the DEFAULT_LABEL.
792 ... are the labels excluding the default. */
795 gimple_build_switch (unsigned nlabels, tree index, tree default_label, ...)
801 p = gimple_build_switch_1 (nlabels, index, default_label);
803 /* Store the rest of the labels. */
804 va_start (al, default_label);
805 for (i = 1; i <= nlabels; i++)
806 gimple_switch_set_label (p, i, va_arg (al, tree));
813 /* Build a GIMPLE_SWITCH statement.
815 INDEX is the switch's index.
816 DEFAULT_LABEL is the default label
817 ARGS is a vector of labels excluding the default. */
820 gimple_build_switch_vec (tree index, tree default_label, VEC(tree, heap) *args)
823 unsigned nlabels = VEC_length (tree, args);
824 gimple p = gimple_build_switch_1 (nlabels, index, default_label);
826 /* Put labels in labels[1 - (nlabels + 1)].
827 Default label is in labels[0]. */
828 for (i = 1; i <= nlabels; i++)
829 gimple_switch_set_label (p, i, VEC_index (tree, args, i - 1));
835 /* Build a GIMPLE_OMP_CRITICAL statement.
837 BODY is the sequence of statements for which only one thread can execute.
838 NAME is optional identifier for this critical block. */
841 gimple_build_omp_critical (gimple_seq body, tree name)
843 gimple p = gimple_alloc (GIMPLE_OMP_CRITICAL, 0);
844 gimple_omp_critical_set_name (p, name);
846 gimple_omp_set_body (p, body);
851 /* Build a GIMPLE_OMP_FOR statement.
853 BODY is sequence of statements inside the for loop.
854 CLAUSES, are any of the OMP loop construct's clauses: private, firstprivate,
855 lastprivate, reductions, ordered, schedule, and nowait.
856 COLLAPSE is the collapse count.
857 PRE_BODY is the sequence of statements that are loop invariant. */
860 gimple_build_omp_for (gimple_seq body, tree clauses, size_t collapse,
863 gimple p = gimple_alloc (GIMPLE_OMP_FOR, 0);
865 gimple_omp_set_body (p, body);
866 gimple_omp_for_set_clauses (p, clauses);
867 p->gimple_omp_for.collapse = collapse;
868 p->gimple_omp_for.iter = GGC_CNEWVEC (struct gimple_omp_for_iter, collapse);
870 gimple_omp_for_set_pre_body (p, pre_body);
876 /* Build a GIMPLE_OMP_PARALLEL statement.
878 BODY is sequence of statements which are executed in parallel.
879 CLAUSES, are the OMP parallel construct's clauses.
880 CHILD_FN is the function created for the parallel threads to execute.
881 DATA_ARG are the shared data argument(s). */
884 gimple_build_omp_parallel (gimple_seq body, tree clauses, tree child_fn,
887 gimple p = gimple_alloc (GIMPLE_OMP_PARALLEL, 0);
889 gimple_omp_set_body (p, body);
890 gimple_omp_parallel_set_clauses (p, clauses);
891 gimple_omp_parallel_set_child_fn (p, child_fn);
892 gimple_omp_parallel_set_data_arg (p, data_arg);
898 /* Build a GIMPLE_OMP_TASK statement.
900 BODY is sequence of statements which are executed by the explicit task.
901 CLAUSES, are the OMP parallel construct's clauses.
902 CHILD_FN is the function created for the parallel threads to execute.
903 DATA_ARG are the shared data argument(s).
904 COPY_FN is the optional function for firstprivate initialization.
905 ARG_SIZE and ARG_ALIGN are size and alignment of the data block. */
908 gimple_build_omp_task (gimple_seq body, tree clauses, tree child_fn,
909 tree data_arg, tree copy_fn, tree arg_size,
912 gimple p = gimple_alloc (GIMPLE_OMP_TASK, 0);
914 gimple_omp_set_body (p, body);
915 gimple_omp_task_set_clauses (p, clauses);
916 gimple_omp_task_set_child_fn (p, child_fn);
917 gimple_omp_task_set_data_arg (p, data_arg);
918 gimple_omp_task_set_copy_fn (p, copy_fn);
919 gimple_omp_task_set_arg_size (p, arg_size);
920 gimple_omp_task_set_arg_align (p, arg_align);
926 /* Build a GIMPLE_OMP_SECTION statement for a sections statement.
928 BODY is the sequence of statements in the section. */
931 gimple_build_omp_section (gimple_seq body)
933 gimple p = gimple_alloc (GIMPLE_OMP_SECTION, 0);
935 gimple_omp_set_body (p, body);
941 /* Build a GIMPLE_OMP_MASTER statement.
943 BODY is the sequence of statements to be executed by just the master. */
946 gimple_build_omp_master (gimple_seq body)
948 gimple p = gimple_alloc (GIMPLE_OMP_MASTER, 0);
950 gimple_omp_set_body (p, body);
956 /* Build a GIMPLE_OMP_CONTINUE statement.
958 CONTROL_DEF is the definition of the control variable.
959 CONTROL_USE is the use of the control variable. */
962 gimple_build_omp_continue (tree control_def, tree control_use)
964 gimple p = gimple_alloc (GIMPLE_OMP_CONTINUE, 0);
965 gimple_omp_continue_set_control_def (p, control_def);
966 gimple_omp_continue_set_control_use (p, control_use);
970 /* Build a GIMPLE_OMP_ORDERED statement.
972 BODY is the sequence of statements inside a loop that will executed in
976 gimple_build_omp_ordered (gimple_seq body)
978 gimple p = gimple_alloc (GIMPLE_OMP_ORDERED, 0);
980 gimple_omp_set_body (p, body);
986 /* Build a GIMPLE_OMP_RETURN statement.
987 WAIT_P is true if this is a non-waiting return. */
990 gimple_build_omp_return (bool wait_p)
992 gimple p = gimple_alloc (GIMPLE_OMP_RETURN, 0);
994 gimple_omp_return_set_nowait (p);
1000 /* Build a GIMPLE_OMP_SECTIONS statement.
1002 BODY is a sequence of section statements.
1003 CLAUSES are any of the OMP sections contsruct's clauses: private,
1004 firstprivate, lastprivate, reduction, and nowait. */
1007 gimple_build_omp_sections (gimple_seq body, tree clauses)
1009 gimple p = gimple_alloc (GIMPLE_OMP_SECTIONS, 0);
1011 gimple_omp_set_body (p, body);
1012 gimple_omp_sections_set_clauses (p, clauses);
1018 /* Build a GIMPLE_OMP_SECTIONS_SWITCH. */
1021 gimple_build_omp_sections_switch (void)
1023 return gimple_alloc (GIMPLE_OMP_SECTIONS_SWITCH, 0);
1027 /* Build a GIMPLE_OMP_SINGLE statement.
1029 BODY is the sequence of statements that will be executed once.
1030 CLAUSES are any of the OMP single construct's clauses: private, firstprivate,
1031 copyprivate, nowait. */
1034 gimple_build_omp_single (gimple_seq body, tree clauses)
1036 gimple p = gimple_alloc (GIMPLE_OMP_SINGLE, 0);
1038 gimple_omp_set_body (p, body);
1039 gimple_omp_single_set_clauses (p, clauses);
1045 /* Build a GIMPLE_CHANGE_DYNAMIC_TYPE statement. TYPE is the new type
1046 for the location PTR. */
1049 gimple_build_cdt (tree type, tree ptr)
1051 gimple p = gimple_build_with_ops (GIMPLE_CHANGE_DYNAMIC_TYPE, ERROR_MARK, 2);
1052 gimple_cdt_set_new_type (p, type);
1053 gimple_cdt_set_location (p, ptr);
1059 /* Build a GIMPLE_OMP_ATOMIC_LOAD statement. */
1062 gimple_build_omp_atomic_load (tree lhs, tree rhs)
1064 gimple p = gimple_alloc (GIMPLE_OMP_ATOMIC_LOAD, 0);
1065 gimple_omp_atomic_load_set_lhs (p, lhs);
1066 gimple_omp_atomic_load_set_rhs (p, rhs);
1070 /* Build a GIMPLE_OMP_ATOMIC_STORE statement.
1072 VAL is the value we are storing. */
1075 gimple_build_omp_atomic_store (tree val)
1077 gimple p = gimple_alloc (GIMPLE_OMP_ATOMIC_STORE, 0);
1078 gimple_omp_atomic_store_set_val (p, val);
1082 /* Build a GIMPLE_PREDICT statement. PREDICT is one of the predictors from
1083 predict.def, OUTCOME is NOT_TAKEN or TAKEN. */
1086 gimple_build_predict (enum br_predictor predictor, enum prediction outcome)
1088 gimple p = gimple_alloc (GIMPLE_PREDICT, 0);
1089 /* Ensure all the predictors fit into the lower bits of the subcode. */
1090 gcc_assert ((int) END_PREDICTORS <= GF_PREDICT_TAKEN);
1091 gimple_predict_set_predictor (p, predictor);
1092 gimple_predict_set_outcome (p, outcome);
1096 /* Return which gimple structure is used by T. The enums here are defined
1099 enum gimple_statement_structure_enum
1100 gimple_statement_structure (gimple gs)
1102 return gss_for_code (gimple_code (gs));
1105 #if defined ENABLE_GIMPLE_CHECKING
1106 /* Complain of a gimple type mismatch and die. */
1109 gimple_check_failed (const_gimple gs, const char *file, int line,
1110 const char *function, enum gimple_code code,
1111 enum tree_code subcode)
1113 internal_error ("gimple check: expected %s(%s), have %s(%s) in %s, at %s:%d",
1114 gimple_code_name[code],
1115 tree_code_name[subcode],
1116 gimple_code_name[gimple_code (gs)],
1117 gs->gsbase.subcode > 0
1118 ? tree_code_name[gs->gsbase.subcode]
1120 function, trim_filename (file), line);
1122 #endif /* ENABLE_GIMPLE_CHECKING */
1125 /* Allocate a new GIMPLE sequence in GC memory and return it. If
1126 there are free sequences in GIMPLE_SEQ_CACHE return one of those
1130 gimple_seq_alloc (void)
1132 gimple_seq seq = gimple_seq_cache;
1135 gimple_seq_cache = gimple_seq_cache->next_free;
1136 gcc_assert (gimple_seq_cache != seq);
1137 memset (seq, 0, sizeof (*seq));
1141 seq = (gimple_seq) ggc_alloc_cleared (sizeof (*seq));
1142 #ifdef GATHER_STATISTICS
1143 gimple_alloc_counts[(int) gimple_alloc_kind_seq]++;
1144 gimple_alloc_sizes[(int) gimple_alloc_kind_seq] += sizeof (*seq);
1151 /* Return SEQ to the free pool of GIMPLE sequences. */
1154 gimple_seq_free (gimple_seq seq)
1159 gcc_assert (gimple_seq_first (seq) == NULL);
1160 gcc_assert (gimple_seq_last (seq) == NULL);
1162 /* If this triggers, it's a sign that the same list is being freed
1164 gcc_assert (seq != gimple_seq_cache || gimple_seq_cache == NULL);
1166 /* Add SEQ to the pool of free sequences. */
1167 seq->next_free = gimple_seq_cache;
1168 gimple_seq_cache = seq;
1172 /* Link gimple statement GS to the end of the sequence *SEQ_P. If
1173 *SEQ_P is NULL, a new sequence is allocated. */
1176 gimple_seq_add_stmt (gimple_seq *seq_p, gimple gs)
1178 gimple_stmt_iterator si;
1184 *seq_p = gimple_seq_alloc ();
1186 si = gsi_last (*seq_p);
1187 gsi_insert_after (&si, gs, GSI_NEW_STMT);
1191 /* Append sequence SRC to the end of sequence *DST_P. If *DST_P is
1192 NULL, a new sequence is allocated. */
1195 gimple_seq_add_seq (gimple_seq *dst_p, gimple_seq src)
1197 gimple_stmt_iterator si;
1203 *dst_p = gimple_seq_alloc ();
1205 si = gsi_last (*dst_p);
1206 gsi_insert_seq_after (&si, src, GSI_NEW_STMT);
1210 /* Helper function of empty_body_p. Return true if STMT is an empty
1214 empty_stmt_p (gimple stmt)
1216 if (gimple_code (stmt) == GIMPLE_NOP)
1218 if (gimple_code (stmt) == GIMPLE_BIND)
1219 return empty_body_p (gimple_bind_body (stmt));
1224 /* Return true if BODY contains nothing but empty statements. */
1227 empty_body_p (gimple_seq body)
1229 gimple_stmt_iterator i;
1232 if (gimple_seq_empty_p (body))
1234 for (i = gsi_start (body); !gsi_end_p (i); gsi_next (&i))
1235 if (!empty_stmt_p (gsi_stmt (i)))
1242 /* Perform a deep copy of sequence SRC and return the result. */
1245 gimple_seq_copy (gimple_seq src)
1247 gimple_stmt_iterator gsi;
1248 gimple_seq new_seq = gimple_seq_alloc ();
1251 for (gsi = gsi_start (src); !gsi_end_p (gsi); gsi_next (&gsi))
1253 stmt = gimple_copy (gsi_stmt (gsi));
1254 gimple_seq_add_stmt (&new_seq, stmt);
1261 /* Walk all the statements in the sequence SEQ calling walk_gimple_stmt
1262 on each one. WI is as in walk_gimple_stmt.
1264 If walk_gimple_stmt returns non-NULL, the walk is stopped, the
1265 value is stored in WI->CALLBACK_RESULT and the statement that
1266 produced the value is returned.
1268 Otherwise, all the statements are walked and NULL returned. */
1271 walk_gimple_seq (gimple_seq seq, walk_stmt_fn callback_stmt,
1272 walk_tree_fn callback_op, struct walk_stmt_info *wi)
1274 gimple_stmt_iterator gsi;
1276 for (gsi = gsi_start (seq); !gsi_end_p (gsi); gsi_next (&gsi))
1278 tree ret = walk_gimple_stmt (&gsi, callback_stmt, callback_op, wi);
1281 /* If CALLBACK_STMT or CALLBACK_OP return a value, WI must exist
1284 wi->callback_result = ret;
1285 return gsi_stmt (gsi);
1290 wi->callback_result = NULL_TREE;
1296 /* Helper function for walk_gimple_stmt. Walk operands of a GIMPLE_ASM. */
1299 walk_gimple_asm (gimple stmt, walk_tree_fn callback_op,
1300 struct walk_stmt_info *wi)
1304 const char **oconstraints;
1306 const char *constraint;
1307 bool allows_mem, allows_reg, is_inout;
1309 noutputs = gimple_asm_noutputs (stmt);
1310 oconstraints = (const char **) alloca ((noutputs) * sizeof (const char *));
1315 for (i = 0; i < noutputs; i++)
1317 tree op = gimple_asm_output_op (stmt, i);
1318 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op)));
1319 oconstraints[i] = constraint;
1320 parse_output_constraint (&constraint, i, 0, 0, &allows_mem, &allows_reg,
1323 wi->val_only = (allows_reg || !allows_mem);
1324 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
1329 for (i = 0; i < gimple_asm_ninputs (stmt); i++)
1331 tree op = gimple_asm_input_op (stmt, i);
1332 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op)));
1333 parse_input_constraint (&constraint, 0, 0, noutputs, 0,
1334 oconstraints, &allows_mem, &allows_reg);
1336 wi->val_only = (allows_reg || !allows_mem);
1338 /* Although input "m" is not really a LHS, we need a lvalue. */
1340 wi->is_lhs = !wi->val_only;
1341 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
1349 wi->val_only = true;
1356 /* Helper function of WALK_GIMPLE_STMT. Walk every tree operand in
1357 STMT. CALLBACK_OP and WI are as in WALK_GIMPLE_STMT.
1359 CALLBACK_OP is called on each operand of STMT via walk_tree.
1360 Additional parameters to walk_tree must be stored in WI. For each operand
1361 OP, walk_tree is called as:
1363 walk_tree (&OP, CALLBACK_OP, WI, WI->PSET)
1365 If CALLBACK_OP returns non-NULL for an operand, the remaining
1366 operands are not scanned.
1368 The return value is that returned by the last call to walk_tree, or
1369 NULL_TREE if no CALLBACK_OP is specified. */
1372 walk_gimple_op (gimple stmt, walk_tree_fn callback_op,
1373 struct walk_stmt_info *wi)
1375 struct pointer_set_t *pset = (wi) ? wi->pset : NULL;
1377 tree ret = NULL_TREE;
1379 switch (gimple_code (stmt))
1382 /* Walk the RHS operands. A formal temporary LHS may use a
1383 COMPONENT_REF RHS. */
1385 wi->val_only = !is_gimple_reg (gimple_assign_lhs (stmt))
1386 || !gimple_assign_single_p (stmt);
1388 for (i = 1; i < gimple_num_ops (stmt); i++)
1390 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi,
1396 /* Walk the LHS. If the RHS is appropriate for a memory, we
1397 may use a COMPONENT_REF on the LHS. */
1400 /* If the RHS has more than 1 operand, it is not appropriate
1402 wi->val_only = !is_gimple_mem_rhs (gimple_assign_rhs1 (stmt))
1403 || !gimple_assign_single_p (stmt);
1407 ret = walk_tree (gimple_op_ptr (stmt, 0), callback_op, wi, pset);
1413 wi->val_only = true;
1422 ret = walk_tree (gimple_call_chain_ptr (stmt), callback_op, wi, pset);
1426 ret = walk_tree (gimple_call_fn_ptr (stmt), callback_op, wi, pset);
1430 for (i = 0; i < gimple_call_num_args (stmt); i++)
1432 ret = walk_tree (gimple_call_arg_ptr (stmt, i), callback_op, wi,
1441 ret = walk_tree (gimple_call_lhs_ptr (stmt), callback_op, wi, pset);
1450 ret = walk_tree (gimple_catch_types_ptr (stmt), callback_op, wi,
1456 case GIMPLE_EH_FILTER:
1457 ret = walk_tree (gimple_eh_filter_types_ptr (stmt), callback_op, wi,
1463 case GIMPLE_CHANGE_DYNAMIC_TYPE:
1464 ret = walk_tree (gimple_cdt_location_ptr (stmt), callback_op, wi, pset);
1468 ret = walk_tree (gimple_cdt_new_type_ptr (stmt), callback_op, wi, pset);
1474 ret = walk_gimple_asm (stmt, callback_op, wi);
1479 case GIMPLE_OMP_CONTINUE:
1480 ret = walk_tree (gimple_omp_continue_control_def_ptr (stmt),
1481 callback_op, wi, pset);
1485 ret = walk_tree (gimple_omp_continue_control_use_ptr (stmt),
1486 callback_op, wi, pset);
1491 case GIMPLE_OMP_CRITICAL:
1492 ret = walk_tree (gimple_omp_critical_name_ptr (stmt), callback_op, wi,
1498 case GIMPLE_OMP_FOR:
1499 ret = walk_tree (gimple_omp_for_clauses_ptr (stmt), callback_op, wi,
1503 for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
1505 ret = walk_tree (gimple_omp_for_index_ptr (stmt, i), callback_op,
1509 ret = walk_tree (gimple_omp_for_initial_ptr (stmt, i), callback_op,
1513 ret = walk_tree (gimple_omp_for_final_ptr (stmt, i), callback_op,
1517 ret = walk_tree (gimple_omp_for_incr_ptr (stmt, i), callback_op,
1524 case GIMPLE_OMP_PARALLEL:
1525 ret = walk_tree (gimple_omp_parallel_clauses_ptr (stmt), callback_op,
1529 ret = walk_tree (gimple_omp_parallel_child_fn_ptr (stmt), callback_op,
1533 ret = walk_tree (gimple_omp_parallel_data_arg_ptr (stmt), callback_op,
1539 case GIMPLE_OMP_TASK:
1540 ret = walk_tree (gimple_omp_task_clauses_ptr (stmt), callback_op,
1544 ret = walk_tree (gimple_omp_task_child_fn_ptr (stmt), callback_op,
1548 ret = walk_tree (gimple_omp_task_data_arg_ptr (stmt), callback_op,
1552 ret = walk_tree (gimple_omp_task_copy_fn_ptr (stmt), callback_op,
1556 ret = walk_tree (gimple_omp_task_arg_size_ptr (stmt), callback_op,
1560 ret = walk_tree (gimple_omp_task_arg_align_ptr (stmt), callback_op,
1566 case GIMPLE_OMP_SECTIONS:
1567 ret = walk_tree (gimple_omp_sections_clauses_ptr (stmt), callback_op,
1572 ret = walk_tree (gimple_omp_sections_control_ptr (stmt), callback_op,
1579 case GIMPLE_OMP_SINGLE:
1580 ret = walk_tree (gimple_omp_single_clauses_ptr (stmt), callback_op, wi,
1586 case GIMPLE_OMP_ATOMIC_LOAD:
1587 ret = walk_tree (gimple_omp_atomic_load_lhs_ptr (stmt), callback_op, wi,
1592 ret = walk_tree (gimple_omp_atomic_load_rhs_ptr (stmt), callback_op, wi,
1598 case GIMPLE_OMP_ATOMIC_STORE:
1599 ret = walk_tree (gimple_omp_atomic_store_val_ptr (stmt), callback_op,
1605 /* Tuples that do not have operands. */
1608 case GIMPLE_OMP_RETURN:
1609 case GIMPLE_PREDICT:
1614 enum gimple_statement_structure_enum gss;
1615 gss = gimple_statement_structure (stmt);
1616 if (gss == GSS_WITH_OPS || gss == GSS_WITH_MEM_OPS)
1617 for (i = 0; i < gimple_num_ops (stmt); i++)
1619 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi, pset);
1631 /* Walk the current statement in GSI (optionally using traversal state
1632 stored in WI). If WI is NULL, no state is kept during traversal.
1633 The callback CALLBACK_STMT is called. If CALLBACK_STMT indicates
1634 that it has handled all the operands of the statement, its return
1635 value is returned. Otherwise, the return value from CALLBACK_STMT
1636 is discarded and its operands are scanned.
1638 If CALLBACK_STMT is NULL or it didn't handle the operands,
1639 CALLBACK_OP is called on each operand of the statement via
1640 walk_gimple_op. If walk_gimple_op returns non-NULL for any
1641 operand, the remaining operands are not scanned. In this case, the
1642 return value from CALLBACK_OP is returned.
1644 In any other case, NULL_TREE is returned. */
1647 walk_gimple_stmt (gimple_stmt_iterator *gsi, walk_stmt_fn callback_stmt,
1648 walk_tree_fn callback_op, struct walk_stmt_info *wi)
1652 gimple stmt = gsi_stmt (*gsi);
1657 if (wi && wi->want_locations && gimple_has_location (stmt))
1658 input_location = gimple_location (stmt);
1662 /* Invoke the statement callback. Return if the callback handled
1663 all of STMT operands by itself. */
1666 bool handled_ops = false;
1667 tree_ret = callback_stmt (gsi, &handled_ops, wi);
1671 /* If CALLBACK_STMT did not handle operands, it should not have
1672 a value to return. */
1673 gcc_assert (tree_ret == NULL);
1675 /* Re-read stmt in case the callback changed it. */
1676 stmt = gsi_stmt (*gsi);
1679 /* If CALLBACK_OP is defined, invoke it on every operand of STMT. */
1682 tree_ret = walk_gimple_op (stmt, callback_op, wi);
1687 /* If STMT can have statements inside (e.g. GIMPLE_BIND), walk them. */
1688 switch (gimple_code (stmt))
1691 ret = walk_gimple_seq (gimple_bind_body (stmt), callback_stmt,
1694 return wi->callback_result;
1698 ret = walk_gimple_seq (gimple_catch_handler (stmt), callback_stmt,
1701 return wi->callback_result;
1704 case GIMPLE_EH_FILTER:
1705 ret = walk_gimple_seq (gimple_eh_filter_failure (stmt), callback_stmt,
1708 return wi->callback_result;
1712 ret = walk_gimple_seq (gimple_try_eval (stmt), callback_stmt, callback_op,
1715 return wi->callback_result;
1717 ret = walk_gimple_seq (gimple_try_cleanup (stmt), callback_stmt,
1720 return wi->callback_result;
1723 case GIMPLE_OMP_FOR:
1724 ret = walk_gimple_seq (gimple_omp_for_pre_body (stmt), callback_stmt,
1727 return wi->callback_result;
1730 case GIMPLE_OMP_CRITICAL:
1731 case GIMPLE_OMP_MASTER:
1732 case GIMPLE_OMP_ORDERED:
1733 case GIMPLE_OMP_SECTION:
1734 case GIMPLE_OMP_PARALLEL:
1735 case GIMPLE_OMP_TASK:
1736 case GIMPLE_OMP_SECTIONS:
1737 case GIMPLE_OMP_SINGLE:
1738 ret = walk_gimple_seq (gimple_omp_body (stmt), callback_stmt, callback_op,
1741 return wi->callback_result;
1744 case GIMPLE_WITH_CLEANUP_EXPR:
1745 ret = walk_gimple_seq (gimple_wce_cleanup (stmt), callback_stmt,
1748 return wi->callback_result;
1752 gcc_assert (!gimple_has_substatements (stmt));
1760 /* Set sequence SEQ to be the GIMPLE body for function FN. */
1763 gimple_set_body (tree fndecl, gimple_seq seq)
1765 struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
1768 /* If FNDECL still does not have a function structure associated
1769 with it, then it does not make sense for it to receive a
1771 gcc_assert (seq == NULL);
1774 fn->gimple_body = seq;
1778 /* Return the body of GIMPLE statements for function FN. */
1781 gimple_body (tree fndecl)
1783 struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
1784 return fn ? fn->gimple_body : NULL;
1787 /* Return true when FNDECL has Gimple body either in unlowered
1790 gimple_has_body_p (tree fndecl)
1792 struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
1793 return (gimple_body (fndecl) || (fn && fn->cfg));
1796 /* Detect flags from a GIMPLE_CALL. This is just like
1797 call_expr_flags, but for gimple tuples. */
1800 gimple_call_flags (const_gimple stmt)
1803 tree decl = gimple_call_fndecl (stmt);
1807 flags = flags_from_decl_or_type (decl);
1810 t = TREE_TYPE (gimple_call_fn (stmt));
1811 if (t && TREE_CODE (t) == POINTER_TYPE)
1812 flags = flags_from_decl_or_type (TREE_TYPE (t));
1821 /* Return true if GS is a copy assignment. */
1824 gimple_assign_copy_p (gimple gs)
1826 return gimple_code (gs) == GIMPLE_ASSIGN
1827 && get_gimple_rhs_class (gimple_assign_rhs_code (gs))
1828 == GIMPLE_SINGLE_RHS
1829 && is_gimple_val (gimple_op (gs, 1));
1833 /* Return true if GS is a SSA_NAME copy assignment. */
1836 gimple_assign_ssa_name_copy_p (gimple gs)
1838 return (gimple_code (gs) == GIMPLE_ASSIGN
1839 && (get_gimple_rhs_class (gimple_assign_rhs_code (gs))
1840 == GIMPLE_SINGLE_RHS)
1841 && TREE_CODE (gimple_assign_lhs (gs)) == SSA_NAME
1842 && TREE_CODE (gimple_assign_rhs1 (gs)) == SSA_NAME);
1846 /* Return true if GS is an assignment with a singleton RHS, i.e.,
1847 there is no operator associated with the assignment itself.
1848 Unlike gimple_assign_copy_p, this predicate returns true for
1849 any RHS operand, including those that perform an operation
1850 and do not have the semantics of a copy, such as COND_EXPR. */
1853 gimple_assign_single_p (gimple gs)
1855 return (gimple_code (gs) == GIMPLE_ASSIGN
1856 && get_gimple_rhs_class (gimple_assign_rhs_code (gs))
1857 == GIMPLE_SINGLE_RHS);
1860 /* Return true if GS is an assignment with a unary RHS, but the
1861 operator has no effect on the assigned value. The logic is adapted
1862 from STRIP_NOPS. This predicate is intended to be used in tuplifying
1863 instances in which STRIP_NOPS was previously applied to the RHS of
1866 NOTE: In the use cases that led to the creation of this function
1867 and of gimple_assign_single_p, it is typical to test for either
1868 condition and to proceed in the same manner. In each case, the
1869 assigned value is represented by the single RHS operand of the
1870 assignment. I suspect there may be cases where gimple_assign_copy_p,
1871 gimple_assign_single_p, or equivalent logic is used where a similar
1872 treatment of unary NOPs is appropriate. */
1875 gimple_assign_unary_nop_p (gimple gs)
1877 return (gimple_code (gs) == GIMPLE_ASSIGN
1878 && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs))
1879 || gimple_assign_rhs_code (gs) == NON_LVALUE_EXPR)
1880 && gimple_assign_rhs1 (gs) != error_mark_node
1881 && (TYPE_MODE (TREE_TYPE (gimple_assign_lhs (gs)))
1882 == TYPE_MODE (TREE_TYPE (gimple_assign_rhs1 (gs)))));
1885 /* Set BB to be the basic block holding G. */
1888 gimple_set_bb (gimple stmt, basic_block bb)
1890 stmt->gsbase.bb = bb;
1892 /* If the statement is a label, add the label to block-to-labels map
1893 so that we can speed up edge creation for GIMPLE_GOTOs. */
1894 if (cfun->cfg && gimple_code (stmt) == GIMPLE_LABEL)
1899 t = gimple_label_label (stmt);
1900 uid = LABEL_DECL_UID (t);
1903 unsigned old_len = VEC_length (basic_block, label_to_block_map);
1904 LABEL_DECL_UID (t) = uid = cfun->cfg->last_label_uid++;
1905 if (old_len <= (unsigned) uid)
1907 unsigned new_len = 3 * uid / 2 + 1;
1909 VEC_safe_grow_cleared (basic_block, gc, label_to_block_map,
1914 VEC_replace (basic_block, label_to_block_map, uid, bb);
1919 /* Fold the expression computed by STMT. If the expression can be
1920 folded, return the folded result, otherwise return NULL. STMT is
1924 gimple_fold (const_gimple stmt)
1926 switch (gimple_code (stmt))
1929 return fold_binary (gimple_cond_code (stmt),
1931 gimple_cond_lhs (stmt),
1932 gimple_cond_rhs (stmt));
1935 switch (get_gimple_rhs_class (gimple_assign_rhs_code (stmt)))
1937 case GIMPLE_UNARY_RHS:
1938 return fold_unary (gimple_assign_rhs_code (stmt),
1939 TREE_TYPE (gimple_assign_lhs (stmt)),
1940 gimple_assign_rhs1 (stmt));
1941 case GIMPLE_BINARY_RHS:
1942 return fold_binary (gimple_assign_rhs_code (stmt),
1943 TREE_TYPE (gimple_assign_lhs (stmt)),
1944 gimple_assign_rhs1 (stmt),
1945 gimple_assign_rhs2 (stmt));
1946 case GIMPLE_SINGLE_RHS:
1947 return fold (gimple_assign_rhs1 (stmt));
1953 return gimple_switch_index (stmt);
1966 /* Modify the RHS of the assignment pointed-to by GSI using the
1967 operands in the expression tree EXPR.
1969 NOTE: The statement pointed-to by GSI may be reallocated if it
1970 did not have enough operand slots.
1972 This function is useful to convert an existing tree expression into
1973 the flat representation used for the RHS of a GIMPLE assignment.
1974 It will reallocate memory as needed to expand or shrink the number
1975 of operand slots needed to represent EXPR.
1977 NOTE: If you find yourself building a tree and then calling this
1978 function, you are most certainly doing it the slow way. It is much
1979 better to build a new assignment or to use the function
1980 gimple_assign_set_rhs_with_ops, which does not require an
1981 expression tree to be built. */
1984 gimple_assign_set_rhs_from_tree (gimple_stmt_iterator *gsi, tree expr)
1986 enum tree_code subcode;
1989 extract_ops_from_tree (expr, &subcode, &op1, &op2);
1990 gimple_assign_set_rhs_with_ops (gsi, subcode, op1, op2);
1994 /* Set the RHS of assignment statement pointed-to by GSI to CODE with
1995 operands OP1 and OP2.
1997 NOTE: The statement pointed-to by GSI may be reallocated if it
1998 did not have enough operand slots. */
2001 gimple_assign_set_rhs_with_ops (gimple_stmt_iterator *gsi, enum tree_code code,
2004 unsigned new_rhs_ops = get_gimple_rhs_num_ops (code);
2005 gimple stmt = gsi_stmt (*gsi);
2007 /* If the new CODE needs more operands, allocate a new statement. */
2008 if (gimple_num_ops (stmt) < new_rhs_ops + 1)
2010 tree lhs = gimple_assign_lhs (stmt);
2011 gimple new_stmt = gimple_alloc (gimple_code (stmt), new_rhs_ops + 1);
2012 memcpy (new_stmt, stmt, gimple_size (gimple_code (stmt)));
2013 gsi_replace (gsi, new_stmt, true);
2016 /* The LHS needs to be reset as this also changes the SSA name
2018 gimple_assign_set_lhs (stmt, lhs);
2021 gimple_set_num_ops (stmt, new_rhs_ops + 1);
2022 gimple_set_subcode (stmt, code);
2023 gimple_assign_set_rhs1 (stmt, op1);
2024 if (new_rhs_ops > 1)
2025 gimple_assign_set_rhs2 (stmt, op2);
2029 /* Return the LHS of a statement that performs an assignment,
2030 either a GIMPLE_ASSIGN or a GIMPLE_CALL. Returns NULL_TREE
2031 for a call to a function that returns no value, or for a
2032 statement other than an assignment or a call. */
2035 gimple_get_lhs (const_gimple stmt)
2037 enum gimple_code code = gimple_code (stmt);
2039 if (code == GIMPLE_ASSIGN)
2040 return gimple_assign_lhs (stmt);
2041 else if (code == GIMPLE_CALL)
2042 return gimple_call_lhs (stmt);
2048 /* Set the LHS of a statement that performs an assignment,
2049 either a GIMPLE_ASSIGN or a GIMPLE_CALL. */
2052 gimple_set_lhs (gimple stmt, tree lhs)
2054 enum gimple_code code = gimple_code (stmt);
2056 if (code == GIMPLE_ASSIGN)
2057 gimple_assign_set_lhs (stmt, lhs);
2058 else if (code == GIMPLE_CALL)
2059 gimple_call_set_lhs (stmt, lhs);
2065 /* Return a deep copy of statement STMT. All the operands from STMT
2066 are reallocated and copied using unshare_expr. The DEF, USE, VDEF
2067 and VUSE operand arrays are set to empty in the new copy. */
2070 gimple_copy (gimple stmt)
2072 enum gimple_code code = gimple_code (stmt);
2073 unsigned num_ops = gimple_num_ops (stmt);
2074 gimple copy = gimple_alloc (code, num_ops);
2077 /* Shallow copy all the fields from STMT. */
2078 memcpy (copy, stmt, gimple_size (code));
2080 /* If STMT has sub-statements, deep-copy them as well. */
2081 if (gimple_has_substatements (stmt))
2086 switch (gimple_code (stmt))
2089 new_seq = gimple_seq_copy (gimple_bind_body (stmt));
2090 gimple_bind_set_body (copy, new_seq);
2091 gimple_bind_set_vars (copy, unshare_expr (gimple_bind_vars (stmt)));
2092 gimple_bind_set_block (copy, gimple_bind_block (stmt));
2096 new_seq = gimple_seq_copy (gimple_catch_handler (stmt));
2097 gimple_catch_set_handler (copy, new_seq);
2098 t = unshare_expr (gimple_catch_types (stmt));
2099 gimple_catch_set_types (copy, t);
2102 case GIMPLE_EH_FILTER:
2103 new_seq = gimple_seq_copy (gimple_eh_filter_failure (stmt));
2104 gimple_eh_filter_set_failure (copy, new_seq);
2105 t = unshare_expr (gimple_eh_filter_types (stmt));
2106 gimple_eh_filter_set_types (copy, t);
2110 new_seq = gimple_seq_copy (gimple_try_eval (stmt));
2111 gimple_try_set_eval (copy, new_seq);
2112 new_seq = gimple_seq_copy (gimple_try_cleanup (stmt));
2113 gimple_try_set_cleanup (copy, new_seq);
2116 case GIMPLE_OMP_FOR:
2117 new_seq = gimple_seq_copy (gimple_omp_for_pre_body (stmt));
2118 gimple_omp_for_set_pre_body (copy, new_seq);
2119 t = unshare_expr (gimple_omp_for_clauses (stmt));
2120 gimple_omp_for_set_clauses (copy, t);
2121 copy->gimple_omp_for.iter
2122 = GGC_NEWVEC (struct gimple_omp_for_iter,
2123 gimple_omp_for_collapse (stmt));
2124 for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
2126 gimple_omp_for_set_cond (copy, i,
2127 gimple_omp_for_cond (stmt, i));
2128 gimple_omp_for_set_index (copy, i,
2129 gimple_omp_for_index (stmt, i));
2130 t = unshare_expr (gimple_omp_for_initial (stmt, i));
2131 gimple_omp_for_set_initial (copy, i, t);
2132 t = unshare_expr (gimple_omp_for_final (stmt, i));
2133 gimple_omp_for_set_final (copy, i, t);
2134 t = unshare_expr (gimple_omp_for_incr (stmt, i));
2135 gimple_omp_for_set_incr (copy, i, t);
2139 case GIMPLE_OMP_PARALLEL:
2140 t = unshare_expr (gimple_omp_parallel_clauses (stmt));
2141 gimple_omp_parallel_set_clauses (copy, t);
2142 t = unshare_expr (gimple_omp_parallel_child_fn (stmt));
2143 gimple_omp_parallel_set_child_fn (copy, t);
2144 t = unshare_expr (gimple_omp_parallel_data_arg (stmt));
2145 gimple_omp_parallel_set_data_arg (copy, t);
2148 case GIMPLE_OMP_TASK:
2149 t = unshare_expr (gimple_omp_task_clauses (stmt));
2150 gimple_omp_task_set_clauses (copy, t);
2151 t = unshare_expr (gimple_omp_task_child_fn (stmt));
2152 gimple_omp_task_set_child_fn (copy, t);
2153 t = unshare_expr (gimple_omp_task_data_arg (stmt));
2154 gimple_omp_task_set_data_arg (copy, t);
2155 t = unshare_expr (gimple_omp_task_copy_fn (stmt));
2156 gimple_omp_task_set_copy_fn (copy, t);
2157 t = unshare_expr (gimple_omp_task_arg_size (stmt));
2158 gimple_omp_task_set_arg_size (copy, t);
2159 t = unshare_expr (gimple_omp_task_arg_align (stmt));
2160 gimple_omp_task_set_arg_align (copy, t);
2163 case GIMPLE_OMP_CRITICAL:
2164 t = unshare_expr (gimple_omp_critical_name (stmt));
2165 gimple_omp_critical_set_name (copy, t);
2168 case GIMPLE_OMP_SECTIONS:
2169 t = unshare_expr (gimple_omp_sections_clauses (stmt));
2170 gimple_omp_sections_set_clauses (copy, t);
2171 t = unshare_expr (gimple_omp_sections_control (stmt));
2172 gimple_omp_sections_set_control (copy, t);
2175 case GIMPLE_OMP_SINGLE:
2176 case GIMPLE_OMP_SECTION:
2177 case GIMPLE_OMP_MASTER:
2178 case GIMPLE_OMP_ORDERED:
2180 new_seq = gimple_seq_copy (gimple_omp_body (stmt));
2181 gimple_omp_set_body (copy, new_seq);
2184 case GIMPLE_WITH_CLEANUP_EXPR:
2185 new_seq = gimple_seq_copy (gimple_wce_cleanup (stmt));
2186 gimple_wce_set_cleanup (copy, new_seq);
2194 /* Make copy of operands. */
2197 for (i = 0; i < num_ops; i++)
2198 gimple_set_op (copy, i, unshare_expr (gimple_op (stmt, i)));
2200 /* Clear out SSA operand vectors on COPY. */
2201 if (gimple_has_ops (stmt))
2203 gimple_set_def_ops (copy, NULL);
2204 gimple_set_use_ops (copy, NULL);
2207 if (gimple_has_mem_ops (stmt))
2209 gimple_set_vdef (copy, gimple_vdef (stmt));
2210 gimple_set_vuse (copy, gimple_vuse (stmt));
2213 /* SSA operands need to be updated. */
2214 gimple_set_modified (copy, true);
2221 /* Set the MODIFIED flag to MODIFIEDP, iff the gimple statement G has
2222 a MODIFIED field. */
2225 gimple_set_modified (gimple s, bool modifiedp)
2227 if (gimple_has_ops (s))
2229 s->gsbase.modified = (unsigned) modifiedp;
2233 && is_gimple_call (s)
2234 && gimple_call_noreturn_p (s))
2235 VEC_safe_push (gimple, gc, MODIFIED_NORETURN_CALLS (cfun), s);
2240 /* Return true if statement S has side-effects. We consider a
2241 statement to have side effects if:
2243 - It is a GIMPLE_CALL not marked with ECF_PURE or ECF_CONST.
2244 - Any of its operands are marked TREE_THIS_VOLATILE or TREE_SIDE_EFFECTS. */
2247 gimple_has_side_effects (const_gimple s)
2251 /* We don't have to scan the arguments to check for
2252 volatile arguments, though, at present, we still
2253 do a scan to check for TREE_SIDE_EFFECTS. */
2254 if (gimple_has_volatile_ops (s))
2257 if (is_gimple_call (s))
2259 unsigned nargs = gimple_call_num_args (s);
2261 if (!(gimple_call_flags (s) & (ECF_CONST | ECF_PURE)))
2263 else if (gimple_call_flags (s) & ECF_LOOPING_CONST_OR_PURE)
2264 /* An infinite loop is considered a side effect. */
2267 if (gimple_call_lhs (s)
2268 && TREE_SIDE_EFFECTS (gimple_call_lhs (s)))
2270 gcc_assert (gimple_has_volatile_ops (s));
2274 if (TREE_SIDE_EFFECTS (gimple_call_fn (s)))
2277 for (i = 0; i < nargs; i++)
2278 if (TREE_SIDE_EFFECTS (gimple_call_arg (s, i)))
2280 gcc_assert (gimple_has_volatile_ops (s));
2288 for (i = 0; i < gimple_num_ops (s); i++)
2289 if (TREE_SIDE_EFFECTS (gimple_op (s, i)))
2291 gcc_assert (gimple_has_volatile_ops (s));
2299 /* Return true if the RHS of statement S has side effects.
2300 We may use it to determine if it is admissable to replace
2301 an assignment or call with a copy of a previously-computed
2302 value. In such cases, side-effects due the the LHS are
2306 gimple_rhs_has_side_effects (const_gimple s)
2310 if (is_gimple_call (s))
2312 unsigned nargs = gimple_call_num_args (s);
2314 if (!(gimple_call_flags (s) & (ECF_CONST | ECF_PURE)))
2317 /* We cannot use gimple_has_volatile_ops here,
2318 because we must ignore a volatile LHS. */
2319 if (TREE_SIDE_EFFECTS (gimple_call_fn (s))
2320 || TREE_THIS_VOLATILE (gimple_call_fn (s)))
2322 gcc_assert (gimple_has_volatile_ops (s));
2326 for (i = 0; i < nargs; i++)
2327 if (TREE_SIDE_EFFECTS (gimple_call_arg (s, i))
2328 || TREE_THIS_VOLATILE (gimple_call_arg (s, i)))
2333 else if (is_gimple_assign (s))
2335 /* Skip the first operand, the LHS. */
2336 for (i = 1; i < gimple_num_ops (s); i++)
2337 if (TREE_SIDE_EFFECTS (gimple_op (s, i))
2338 || TREE_THIS_VOLATILE (gimple_op (s, i)))
2340 gcc_assert (gimple_has_volatile_ops (s));
2346 /* For statements without an LHS, examine all arguments. */
2347 for (i = 0; i < gimple_num_ops (s); i++)
2348 if (TREE_SIDE_EFFECTS (gimple_op (s, i))
2349 || TREE_THIS_VOLATILE (gimple_op (s, i)))
2351 gcc_assert (gimple_has_volatile_ops (s));
2360 /* Helper for gimple_could_trap_p and gimple_assign_rhs_could_trap_p.
2361 Return true if S can trap. If INCLUDE_LHS is true and S is a
2362 GIMPLE_ASSIGN, the LHS of the assignment is also checked.
2363 Otherwise, only the RHS of the assignment is checked. */
2366 gimple_could_trap_p_1 (gimple s, bool include_lhs)
2369 tree t, div = NULL_TREE;
2372 start = (is_gimple_assign (s) && !include_lhs) ? 1 : 0;
2374 for (i = start; i < gimple_num_ops (s); i++)
2375 if (tree_could_trap_p (gimple_op (s, i)))
2378 switch (gimple_code (s))
2381 return gimple_asm_volatile_p (s);
2384 t = gimple_call_fndecl (s);
2385 /* Assume that calls to weak functions may trap. */
2386 if (!t || !DECL_P (t) || DECL_WEAK (t))
2391 t = gimple_expr_type (s);
2392 op = gimple_assign_rhs_code (s);
2393 if (get_gimple_rhs_class (op) == GIMPLE_BINARY_RHS)
2394 div = gimple_assign_rhs2 (s);
2395 return (operation_could_trap_p (op, FLOAT_TYPE_P (t),
2396 (INTEGRAL_TYPE_P (t)
2397 && TYPE_OVERFLOW_TRAPS (t)),
2409 /* Return true if statement S can trap. */
2412 gimple_could_trap_p (gimple s)
2414 return gimple_could_trap_p_1 (s, true);
2418 /* Return true if RHS of a GIMPLE_ASSIGN S can trap. */
2421 gimple_assign_rhs_could_trap_p (gimple s)
2423 gcc_assert (is_gimple_assign (s));
2424 return gimple_could_trap_p_1 (s, false);
2428 /* Print debugging information for gimple stmts generated. */
2431 dump_gimple_statistics (void)
2433 #ifdef GATHER_STATISTICS
2434 int i, total_tuples = 0, total_bytes = 0;
2436 fprintf (stderr, "\nGIMPLE statements\n");
2437 fprintf (stderr, "Kind Stmts Bytes\n");
2438 fprintf (stderr, "---------------------------------------\n");
2439 for (i = 0; i < (int) gimple_alloc_kind_all; ++i)
2441 fprintf (stderr, "%-20s %7d %10d\n", gimple_alloc_kind_names[i],
2442 gimple_alloc_counts[i], gimple_alloc_sizes[i]);
2443 total_tuples += gimple_alloc_counts[i];
2444 total_bytes += gimple_alloc_sizes[i];
2446 fprintf (stderr, "---------------------------------------\n");
2447 fprintf (stderr, "%-20s %7d %10d\n", "Total", total_tuples, total_bytes);
2448 fprintf (stderr, "---------------------------------------\n");
2450 fprintf (stderr, "No gimple statistics\n");
2455 /* Return the number of operands needed on the RHS of a GIMPLE
2456 assignment for an expression with tree code CODE. */
2459 get_gimple_rhs_num_ops (enum tree_code code)
2461 enum gimple_rhs_class rhs_class = get_gimple_rhs_class (code);
2463 if (rhs_class == GIMPLE_UNARY_RHS || rhs_class == GIMPLE_SINGLE_RHS)
2465 else if (rhs_class == GIMPLE_BINARY_RHS)
2471 #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \
2473 ((TYPE) == tcc_unary ? GIMPLE_UNARY_RHS \
2474 : ((TYPE) == tcc_binary \
2475 || (TYPE) == tcc_comparison) ? GIMPLE_BINARY_RHS \
2476 : ((TYPE) == tcc_constant \
2477 || (TYPE) == tcc_declaration \
2478 || (TYPE) == tcc_reference) ? GIMPLE_SINGLE_RHS \
2479 : ((SYM) == TRUTH_AND_EXPR \
2480 || (SYM) == TRUTH_OR_EXPR \
2481 || (SYM) == TRUTH_XOR_EXPR) ? GIMPLE_BINARY_RHS \
2482 : (SYM) == TRUTH_NOT_EXPR ? GIMPLE_UNARY_RHS \
2483 : ((SYM) == COND_EXPR \
2484 || (SYM) == CONSTRUCTOR \
2485 || (SYM) == OBJ_TYPE_REF \
2486 || (SYM) == ASSERT_EXPR \
2487 || (SYM) == ADDR_EXPR \
2488 || (SYM) == WITH_SIZE_EXPR \
2489 || (SYM) == EXC_PTR_EXPR \
2490 || (SYM) == SSA_NAME \
2491 || (SYM) == FILTER_EXPR \
2492 || (SYM) == POLYNOMIAL_CHREC \
2493 || (SYM) == DOT_PROD_EXPR \
2494 || (SYM) == VEC_COND_EXPR \
2495 || (SYM) == REALIGN_LOAD_EXPR) ? GIMPLE_SINGLE_RHS \
2496 : GIMPLE_INVALID_RHS),
2497 #define END_OF_BASE_TREE_CODES (unsigned char) GIMPLE_INVALID_RHS,
2499 const unsigned char gimple_rhs_class_table[] = {
2500 #include "all-tree.def"
2504 #undef END_OF_BASE_TREE_CODES
2506 /* For the definitive definition of GIMPLE, see doc/tree-ssa.texi. */
2508 /* Validation of GIMPLE expressions. */
2510 /* Return true if OP is an acceptable tree node to be used as a GIMPLE
2514 is_gimple_operand (const_tree op)
2516 return op && get_gimple_rhs_class (TREE_CODE (op)) == GIMPLE_SINGLE_RHS;
2519 /* Returns true iff T is a valid RHS for an assignment to a renamed
2520 user -- or front-end generated artificial -- variable. */
2523 is_gimple_reg_rhs (tree t)
2525 return get_gimple_rhs_class (TREE_CODE (t)) != GIMPLE_INVALID_RHS;
2528 /* Returns true iff T is a valid RHS for an assignment to an un-renamed
2529 LHS, or for a call argument. */
2532 is_gimple_mem_rhs (tree t)
2534 /* If we're dealing with a renamable type, either source or dest must be
2535 a renamed variable. */
2536 if (is_gimple_reg_type (TREE_TYPE (t)))
2537 return is_gimple_val (t);
2539 return is_gimple_val (t) || is_gimple_lvalue (t);
2542 /* Return true if T is a valid LHS for a GIMPLE assignment expression. */
2545 is_gimple_lvalue (tree t)
2547 return (is_gimple_addressable (t)
2548 || TREE_CODE (t) == WITH_SIZE_EXPR
2549 /* These are complex lvalues, but don't have addresses, so they
2551 || TREE_CODE (t) == BIT_FIELD_REF);
2554 /* Return true if T is a GIMPLE condition. */
2557 is_gimple_condexpr (tree t)
2559 return (is_gimple_val (t) || (COMPARISON_CLASS_P (t)
2560 && !tree_could_trap_p (t)
2561 && is_gimple_val (TREE_OPERAND (t, 0))
2562 && is_gimple_val (TREE_OPERAND (t, 1))));
2565 /* Return true if T is something whose address can be taken. */
2568 is_gimple_addressable (tree t)
2570 return (is_gimple_id (t) || handled_component_p (t) || INDIRECT_REF_P (t));
2573 /* Return true if T is a valid gimple constant. */
2576 is_gimple_constant (const_tree t)
2578 switch (TREE_CODE (t))
2588 /* Vector constant constructors are gimple invariant. */
2590 if (TREE_TYPE (t) && TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE)
2591 return TREE_CONSTANT (t);
2600 /* Return true if T is a gimple address. */
2603 is_gimple_address (const_tree t)
2607 if (TREE_CODE (t) != ADDR_EXPR)
2610 op = TREE_OPERAND (t, 0);
2611 while (handled_component_p (op))
2613 if ((TREE_CODE (op) == ARRAY_REF
2614 || TREE_CODE (op) == ARRAY_RANGE_REF)
2615 && !is_gimple_val (TREE_OPERAND (op, 1)))
2618 op = TREE_OPERAND (op, 0);
2621 if (CONSTANT_CLASS_P (op) || INDIRECT_REF_P (op))
2624 switch (TREE_CODE (op))
2639 /* Strip out all handled components that produce invariant
2643 strip_invariant_refs (const_tree op)
2645 while (handled_component_p (op))
2647 switch (TREE_CODE (op))
2650 case ARRAY_RANGE_REF:
2651 if (!is_gimple_constant (TREE_OPERAND (op, 1))
2652 || TREE_OPERAND (op, 2) != NULL_TREE
2653 || TREE_OPERAND (op, 3) != NULL_TREE)
2658 if (TREE_OPERAND (op, 2) != NULL_TREE)
2664 op = TREE_OPERAND (op, 0);
2670 /* Return true if T is a gimple invariant address. */
2673 is_gimple_invariant_address (const_tree t)
2677 if (TREE_CODE (t) != ADDR_EXPR)
2680 op = strip_invariant_refs (TREE_OPERAND (t, 0));
2682 return op && (CONSTANT_CLASS_P (op) || decl_address_invariant_p (op));
2685 /* Return true if T is a gimple invariant address at IPA level
2686 (so addresses of variables on stack are not allowed). */
2689 is_gimple_ip_invariant_address (const_tree t)
2693 if (TREE_CODE (t) != ADDR_EXPR)
2696 op = strip_invariant_refs (TREE_OPERAND (t, 0));
2698 return op && (CONSTANT_CLASS_P (op) || decl_address_ip_invariant_p (op));
2701 /* Return true if T is a GIMPLE minimal invariant. It's a restricted
2702 form of function invariant. */
2705 is_gimple_min_invariant (const_tree t)
2707 if (TREE_CODE (t) == ADDR_EXPR)
2708 return is_gimple_invariant_address (t);
2710 return is_gimple_constant (t);
2713 /* Return true if T is a GIMPLE interprocedural invariant. It's a restricted
2714 form of gimple minimal invariant. */
2717 is_gimple_ip_invariant (const_tree t)
2719 if (TREE_CODE (t) == ADDR_EXPR)
2720 return is_gimple_ip_invariant_address (t);
2722 return is_gimple_constant (t);
2725 /* Return true if T looks like a valid GIMPLE statement. */
2728 is_gimple_stmt (tree t)
2730 const enum tree_code code = TREE_CODE (t);
2735 /* The only valid NOP_EXPR is the empty statement. */
2736 return IS_EMPTY_STMT (t);
2740 /* These are only valid if they're void. */
2741 return TREE_TYPE (t) == NULL || VOID_TYPE_P (TREE_TYPE (t));
2747 case CASE_LABEL_EXPR:
2748 case TRY_CATCH_EXPR:
2749 case TRY_FINALLY_EXPR:
2750 case EH_FILTER_EXPR:
2752 case CHANGE_DYNAMIC_TYPE_EXPR:
2755 case STATEMENT_LIST:
2765 /* These are always void. */
2771 /* These are valid regardless of their type. */
2779 /* Return true if T is a variable. */
2782 is_gimple_variable (tree t)
2784 return (TREE_CODE (t) == VAR_DECL
2785 || TREE_CODE (t) == PARM_DECL
2786 || TREE_CODE (t) == RESULT_DECL
2787 || TREE_CODE (t) == SSA_NAME);
2790 /* Return true if T is a GIMPLE identifier (something with an address). */
2793 is_gimple_id (tree t)
2795 return (is_gimple_variable (t)
2796 || TREE_CODE (t) == FUNCTION_DECL
2797 || TREE_CODE (t) == LABEL_DECL
2798 || TREE_CODE (t) == CONST_DECL
2799 /* Allow string constants, since they are addressable. */
2800 || TREE_CODE (t) == STRING_CST);
2803 /* Return true if TYPE is a suitable type for a scalar register variable. */
2806 is_gimple_reg_type (tree type)
2808 return !AGGREGATE_TYPE_P (type);
2811 /* Return true if T is a non-aggregate register variable. */
2814 is_gimple_reg (tree t)
2816 if (TREE_CODE (t) == SSA_NAME)
2817 t = SSA_NAME_VAR (t);
2819 if (!is_gimple_variable (t))
2822 if (!is_gimple_reg_type (TREE_TYPE (t)))
2825 /* A volatile decl is not acceptable because we can't reuse it as
2826 needed. We need to copy it into a temp first. */
2827 if (TREE_THIS_VOLATILE (t))
2830 /* We define "registers" as things that can be renamed as needed,
2831 which with our infrastructure does not apply to memory. */
2832 if (needs_to_live_in_memory (t))
2835 /* Hard register variables are an interesting case. For those that
2836 are call-clobbered, we don't know where all the calls are, since
2837 we don't (want to) take into account which operations will turn
2838 into libcalls at the rtl level. For those that are call-saved,
2839 we don't currently model the fact that calls may in fact change
2840 global hard registers, nor do we examine ASM_CLOBBERS at the tree
2841 level, and so miss variable changes that might imply. All around,
2842 it seems safest to not do too much optimization with these at the
2843 tree level at all. We'll have to rely on the rtl optimizers to
2844 clean this up, as there we've got all the appropriate bits exposed. */
2845 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t))
2848 /* Complex and vector values must have been put into SSA-like form.
2849 That is, no assignments to the individual components. */
2850 if (TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE
2851 || TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE)
2852 return DECL_GIMPLE_REG_P (t);
2858 /* Return true if T is a GIMPLE variable whose address is not needed. */
2861 is_gimple_non_addressable (tree t)
2863 if (TREE_CODE (t) == SSA_NAME)
2864 t = SSA_NAME_VAR (t);
2866 return (is_gimple_variable (t) && ! needs_to_live_in_memory (t));
2869 /* Return true if T is a GIMPLE rvalue, i.e. an identifier or a constant. */
2872 is_gimple_val (tree t)
2874 /* Make loads from volatiles and memory vars explicit. */
2875 if (is_gimple_variable (t)
2876 && is_gimple_reg_type (TREE_TYPE (t))
2877 && !is_gimple_reg (t))
2880 /* FIXME make these decls. That can happen only when we expose the
2881 entire landing-pad construct at the tree level. */
2882 if (TREE_CODE (t) == EXC_PTR_EXPR || TREE_CODE (t) == FILTER_EXPR)
2885 return (is_gimple_variable (t) || is_gimple_min_invariant (t));
2888 /* Similarly, but accept hard registers as inputs to asm statements. */
2891 is_gimple_asm_val (tree t)
2893 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t))
2896 return is_gimple_val (t);
2899 /* Return true if T is a GIMPLE minimal lvalue. */
2902 is_gimple_min_lval (tree t)
2904 if (!(t = CONST_CAST_TREE (strip_invariant_refs (t))))
2906 return (is_gimple_id (t) || TREE_CODE (t) == INDIRECT_REF);
2909 /* Return true if T is a typecast operation. */
2912 is_gimple_cast (tree t)
2914 return (CONVERT_EXPR_P (t)
2915 || TREE_CODE (t) == FIX_TRUNC_EXPR);
2918 /* Return true if T is a valid function operand of a CALL_EXPR. */
2921 is_gimple_call_addr (tree t)
2923 return (TREE_CODE (t) == OBJ_TYPE_REF || is_gimple_val (t));
2926 /* If T makes a function call, return the corresponding CALL_EXPR operand.
2927 Otherwise, return NULL_TREE. */
2930 get_call_expr_in (tree t)
2932 if (TREE_CODE (t) == MODIFY_EXPR)
2933 t = TREE_OPERAND (t, 1);
2934 if (TREE_CODE (t) == WITH_SIZE_EXPR)
2935 t = TREE_OPERAND (t, 0);
2936 if (TREE_CODE (t) == CALL_EXPR)
2942 /* Given a memory reference expression T, return its base address.
2943 The base address of a memory reference expression is the main
2944 object being referenced. For instance, the base address for
2945 'array[i].fld[j]' is 'array'. You can think of this as stripping
2946 away the offset part from a memory address.
2948 This function calls handled_component_p to strip away all the inner
2949 parts of the memory reference until it reaches the base object. */
2952 get_base_address (tree t)
2954 while (handled_component_p (t))
2955 t = TREE_OPERAND (t, 0);
2958 || TREE_CODE (t) == STRING_CST
2959 || TREE_CODE (t) == CONSTRUCTOR
2960 || INDIRECT_REF_P (t))
2967 recalculate_side_effects (tree t)
2969 enum tree_code code = TREE_CODE (t);
2970 int len = TREE_OPERAND_LENGTH (t);
2973 switch (TREE_CODE_CLASS (code))
2975 case tcc_expression:
2981 case PREDECREMENT_EXPR:
2982 case PREINCREMENT_EXPR:
2983 case POSTDECREMENT_EXPR:
2984 case POSTINCREMENT_EXPR:
2985 /* All of these have side-effects, no matter what their
2994 case tcc_comparison: /* a comparison expression */
2995 case tcc_unary: /* a unary arithmetic expression */
2996 case tcc_binary: /* a binary arithmetic expression */
2997 case tcc_reference: /* a reference */
2998 case tcc_vl_exp: /* a function call */
2999 TREE_SIDE_EFFECTS (t) = TREE_THIS_VOLATILE (t);
3000 for (i = 0; i < len; ++i)
3002 tree op = TREE_OPERAND (t, i);
3003 if (op && TREE_SIDE_EFFECTS (op))
3004 TREE_SIDE_EFFECTS (t) = 1;
3009 /* No side-effects. */
3017 /* Canonicalize a tree T for use in a COND_EXPR as conditional. Returns
3018 a canonicalized tree that is valid for a COND_EXPR or NULL_TREE, if
3019 we failed to create one. */
3022 canonicalize_cond_expr_cond (tree t)
3024 /* For (bool)x use x != 0. */
3025 if (TREE_CODE (t) == NOP_EXPR
3026 && TREE_TYPE (t) == boolean_type_node)
3028 tree top0 = TREE_OPERAND (t, 0);
3029 t = build2 (NE_EXPR, TREE_TYPE (t),
3030 top0, build_int_cst (TREE_TYPE (top0), 0));
3032 /* For !x use x == 0. */
3033 else if (TREE_CODE (t) == TRUTH_NOT_EXPR)
3035 tree top0 = TREE_OPERAND (t, 0);
3036 t = build2 (EQ_EXPR, TREE_TYPE (t),
3037 top0, build_int_cst (TREE_TYPE (top0), 0));
3039 /* For cmp ? 1 : 0 use cmp. */
3040 else if (TREE_CODE (t) == COND_EXPR
3041 && COMPARISON_CLASS_P (TREE_OPERAND (t, 0))
3042 && integer_onep (TREE_OPERAND (t, 1))
3043 && integer_zerop (TREE_OPERAND (t, 2)))
3045 tree top0 = TREE_OPERAND (t, 0);
3046 t = build2 (TREE_CODE (top0), TREE_TYPE (t),
3047 TREE_OPERAND (top0, 0), TREE_OPERAND (top0, 1));
3050 if (is_gimple_condexpr (t))
3056 /* Build a GIMPLE_CALL identical to STMT but skipping the arguments in
3057 the positions marked by the set ARGS_TO_SKIP. */
3060 gimple_call_copy_skip_args (gimple stmt, bitmap args_to_skip)
3063 tree fn = gimple_call_fn (stmt);
3064 int nargs = gimple_call_num_args (stmt);
3065 VEC(tree, heap) *vargs = VEC_alloc (tree, heap, nargs);
3068 for (i = 0; i < nargs; i++)
3069 if (!bitmap_bit_p (args_to_skip, i))
3070 VEC_quick_push (tree, vargs, gimple_call_arg (stmt, i));
3072 new_stmt = gimple_build_call_vec (fn, vargs);
3073 VEC_free (tree, heap, vargs);
3074 if (gimple_call_lhs (stmt))
3075 gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt));
3077 gimple_set_vuse (new_stmt, gimple_vuse (stmt));
3078 gimple_set_vdef (new_stmt, gimple_vdef (stmt));
3080 gimple_set_block (new_stmt, gimple_block (stmt));
3081 if (gimple_has_location (stmt))
3082 gimple_set_location (new_stmt, gimple_location (stmt));
3084 /* Carry all the flags to the new GIMPLE_CALL. */
3085 gimple_call_set_chain (new_stmt, gimple_call_chain (stmt));
3086 gimple_call_set_tail (new_stmt, gimple_call_tail_p (stmt));
3087 gimple_call_set_cannot_inline (new_stmt, gimple_call_cannot_inline_p (stmt));
3088 gimple_call_set_return_slot_opt (new_stmt, gimple_call_return_slot_opt_p (stmt));
3089 gimple_call_set_from_thunk (new_stmt, gimple_call_from_thunk_p (stmt));
3090 gimple_call_set_va_arg_pack (new_stmt, gimple_call_va_arg_pack_p (stmt));
3092 gimple_set_modified (new_stmt, true);
3098 /* Data structure used to count the number of dereferences to PTR
3099 inside an expression. */
3103 unsigned num_stores;
3107 /* Helper for count_uses_and_derefs. Called by walk_tree to look for
3108 (ALIGN/MISALIGNED_)INDIRECT_REF nodes for the pointer passed in DATA. */
3111 count_ptr_derefs (tree *tp, int *walk_subtrees, void *data)
3113 struct walk_stmt_info *wi_p = (struct walk_stmt_info *) data;
3114 struct count_ptr_d *count_p = (struct count_ptr_d *) wi_p->info;
3116 /* Do not walk inside ADDR_EXPR nodes. In the expression &ptr->fld,
3117 pointer 'ptr' is *not* dereferenced, it is simply used to compute
3118 the address of 'fld' as 'ptr + offsetof(fld)'. */
3119 if (TREE_CODE (*tp) == ADDR_EXPR)
3125 if (INDIRECT_REF_P (*tp) && TREE_OPERAND (*tp, 0) == count_p->ptr)
3128 count_p->num_stores++;
3130 count_p->num_loads++;
3136 /* Count the number of direct and indirect uses for pointer PTR in
3137 statement STMT. The number of direct uses is stored in
3138 *NUM_USES_P. Indirect references are counted separately depending
3139 on whether they are store or load operations. The counts are
3140 stored in *NUM_STORES_P and *NUM_LOADS_P. */
3143 count_uses_and_derefs (tree ptr, gimple stmt, unsigned *num_uses_p,
3144 unsigned *num_loads_p, unsigned *num_stores_p)
3153 /* Find out the total number of uses of PTR in STMT. */
3154 FOR_EACH_SSA_TREE_OPERAND (use, stmt, i, SSA_OP_USE)
3158 /* Now count the number of indirect references to PTR. This is
3159 truly awful, but we don't have much choice. There are no parent
3160 pointers inside INDIRECT_REFs, so an expression like
3161 '*x_1 = foo (x_1, *x_1)' needs to be traversed piece by piece to
3162 find all the indirect and direct uses of x_1 inside. The only
3163 shortcut we can take is the fact that GIMPLE only allows
3164 INDIRECT_REFs inside the expressions below. */
3165 if (is_gimple_assign (stmt)
3166 || gimple_code (stmt) == GIMPLE_RETURN
3167 || gimple_code (stmt) == GIMPLE_ASM
3168 || is_gimple_call (stmt))
3170 struct walk_stmt_info wi;
3171 struct count_ptr_d count;
3174 count.num_stores = 0;
3175 count.num_loads = 0;
3177 memset (&wi, 0, sizeof (wi));
3179 walk_gimple_op (stmt, count_ptr_derefs, &wi);
3181 *num_stores_p = count.num_stores;
3182 *num_loads_p = count.num_loads;
3185 gcc_assert (*num_uses_p >= *num_loads_p + *num_stores_p);
3188 /* From a tree operand OP return the base of a load or store operation
3189 or NULL_TREE if OP is not a load or a store. */
3192 get_base_loadstore (tree op)
3194 while (handled_component_p (op))
3195 op = TREE_OPERAND (op, 0);
3197 || INDIRECT_REF_P (op)
3198 || TREE_CODE (op) == TARGET_MEM_REF)
3203 /* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE and
3204 VISIT_ADDR if non-NULL on loads, store and address-taken operands
3205 passing the STMT, the base of the operand and DATA to it. The base
3206 will be either a decl, an indirect reference (including TARGET_MEM_REF)
3207 or the argument of an address expression.
3208 Returns the results of these callbacks or'ed. */
3211 walk_stmt_load_store_addr_ops (gimple stmt, void *data,
3212 bool (*visit_load)(gimple, tree, void *),
3213 bool (*visit_store)(gimple, tree, void *),
3214 bool (*visit_addr)(gimple, tree, void *))
3218 if (gimple_assign_single_p (stmt))
3223 lhs = get_base_loadstore (gimple_assign_lhs (stmt));
3225 ret |= visit_store (stmt, lhs, data);
3227 rhs = gimple_assign_rhs1 (stmt);
3228 while (handled_component_p (rhs))
3229 rhs = TREE_OPERAND (rhs, 0);
3232 if (TREE_CODE (rhs) == ADDR_EXPR)
3233 ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), data);
3234 else if (TREE_CODE (rhs) == TARGET_MEM_REF
3235 && TMR_BASE (rhs) != NULL_TREE
3236 && TREE_CODE (TMR_BASE (rhs)) == ADDR_EXPR)
3237 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (rhs), 0), data);
3238 else if (TREE_CODE (rhs) == OBJ_TYPE_REF
3239 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs)) == ADDR_EXPR)
3240 ret |= visit_addr (stmt, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs),
3242 lhs = gimple_assign_lhs (stmt);
3243 if (TREE_CODE (lhs) == TARGET_MEM_REF
3244 && TMR_BASE (lhs) != NULL_TREE
3245 && TREE_CODE (TMR_BASE (lhs)) == ADDR_EXPR)
3246 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (lhs), 0), data);
3250 rhs = get_base_loadstore (rhs);
3252 ret |= visit_load (stmt, rhs, data);
3256 && (is_gimple_assign (stmt)
3257 || gimple_code (stmt) == GIMPLE_COND
3258 || gimple_code (stmt) == GIMPLE_CHANGE_DYNAMIC_TYPE))
3260 for (i = 0; i < gimple_num_ops (stmt); ++i)
3261 if (gimple_op (stmt, i)
3262 && TREE_CODE (gimple_op (stmt, i)) == ADDR_EXPR)
3263 ret |= visit_addr (stmt, TREE_OPERAND (gimple_op (stmt, i), 0), data);
3265 else if (is_gimple_call (stmt))
3269 tree lhs = gimple_call_lhs (stmt);
3272 lhs = get_base_loadstore (lhs);
3274 ret |= visit_store (stmt, lhs, data);
3277 if (visit_load || visit_addr)
3278 for (i = 0; i < gimple_call_num_args (stmt); ++i)
3280 tree rhs = gimple_call_arg (stmt, i);
3282 && TREE_CODE (rhs) == ADDR_EXPR)
3283 ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), data);
3284 else if (visit_load)
3286 rhs = get_base_loadstore (rhs);
3288 ret |= visit_load (stmt, rhs, data);
3292 && gimple_call_chain (stmt)
3293 && TREE_CODE (gimple_call_chain (stmt)) == ADDR_EXPR)
3294 ret |= visit_addr (stmt, TREE_OPERAND (gimple_call_chain (stmt), 0),
3297 else if (gimple_code (stmt) == GIMPLE_ASM)
3300 const char *constraint;
3301 const char **oconstraints;
3302 bool allows_mem, allows_reg, is_inout;
3303 noutputs = gimple_asm_noutputs (stmt);
3304 oconstraints = XALLOCAVEC (const char *, noutputs);
3305 if (visit_store || visit_addr)
3306 for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
3308 tree link = gimple_asm_output_op (stmt, i);
3309 tree op = get_base_loadstore (TREE_VALUE (link));
3310 if (op && visit_store)
3311 ret |= visit_store (stmt, op, data);
3314 constraint = TREE_STRING_POINTER
3315 (TREE_VALUE (TREE_PURPOSE (link)));
3316 oconstraints[i] = constraint;
3317 parse_output_constraint (&constraint, i, 0, 0, &allows_mem,
3318 &allows_reg, &is_inout);
3319 if (op && !allows_reg && allows_mem)
3320 ret |= visit_addr (stmt, op, data);
3323 if (visit_load || visit_addr)
3324 for (i = 0; i < gimple_asm_ninputs (stmt); ++i)
3326 tree link = gimple_asm_input_op (stmt, i);
3327 tree op = TREE_VALUE (link);
3329 && TREE_CODE (op) == ADDR_EXPR)
3330 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
3331 else if (visit_load || visit_addr)
3333 op = get_base_loadstore (op);
3337 ret |= visit_load (stmt, op, data);
3340 constraint = TREE_STRING_POINTER
3341 (TREE_VALUE (TREE_PURPOSE (link)));
3342 parse_input_constraint (&constraint, 0, 0, noutputs,
3344 &allows_mem, &allows_reg);
3345 if (!allows_reg && allows_mem)
3346 ret |= visit_addr (stmt, op, data);
3352 else if (gimple_code (stmt) == GIMPLE_RETURN)
3354 tree op = gimple_return_retval (stmt);
3358 && TREE_CODE (op) == ADDR_EXPR)
3359 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
3360 else if (visit_load)
3362 op = get_base_loadstore (op);
3364 ret |= visit_load (stmt, op, data);
3369 && gimple_code (stmt) == GIMPLE_PHI)
3371 for (i = 0; i < gimple_phi_num_args (stmt); ++i)
3373 tree op = PHI_ARG_DEF (stmt, i);
3374 if (TREE_CODE (op) == ADDR_EXPR)
3375 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
3382 /* Like walk_stmt_load_store_addr_ops but with NULL visit_addr. IPA-CP
3383 should make a faster clone for this case. */
3386 walk_stmt_load_store_ops (gimple stmt, void *data,
3387 bool (*visit_load)(gimple, tree, void *),
3388 bool (*visit_store)(gimple, tree, void *))
3390 return walk_stmt_load_store_addr_ops (stmt, data,
3391 visit_load, visit_store, NULL);
3394 /* Helper for gimple_ior_addresses_taken_1. */
3397 gimple_ior_addresses_taken_1 (gimple stmt ATTRIBUTE_UNUSED,
3398 tree addr, void *data)
3400 bitmap addresses_taken = (bitmap)data;
3401 while (handled_component_p (addr))
3402 addr = TREE_OPERAND (addr, 0);
3405 bitmap_set_bit (addresses_taken, DECL_UID (addr));
3411 /* Set the bit for the uid of all decls that have their address taken
3412 in STMT in the ADDRESSES_TAKEN bitmap. Returns true if there
3413 were any in this stmt. */
3416 gimple_ior_addresses_taken (bitmap addresses_taken, gimple stmt)
3418 return walk_stmt_load_store_addr_ops (stmt, addresses_taken, NULL, NULL,
3419 gimple_ior_addresses_taken_1);
3422 #include "gt-gimple.h"