1 /* Gimple IR support functions.
3 Copyright 2007, 2008, 2009, 2010, 2011 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"
29 #include "hard-reg-set.h"
30 #include "basic-block.h"
32 #include "diagnostic.h"
33 #include "tree-flow.h"
34 #include "value-prof.h"
38 #include "langhooks.h"
40 /* Global type table. FIXME lto, it should be possible to re-use some
41 of the type hashing routines in tree.c (type_hash_canon, type_hash_lookup,
42 etc), but those assume that types were built with the various
43 build_*_type routines which is not the case with the streamer. */
44 static GTY((if_marked ("ggc_marked_p"), param_is (union tree_node)))
46 static GTY((if_marked ("ggc_marked_p"), param_is (union tree_node)))
47 htab_t gimple_canonical_types;
48 static GTY((if_marked ("tree_int_map_marked_p"), param_is (struct tree_int_map)))
49 htab_t type_hash_cache;
50 static GTY((if_marked ("tree_int_map_marked_p"), param_is (struct tree_int_map)))
51 htab_t canonical_type_hash_cache;
53 /* All the tuples have their operand vector (if present) at the very bottom
54 of the structure. Therefore, the offset required to find the
55 operands vector the size of the structure minus the size of the 1
56 element tree array at the end (see gimple_ops). */
57 #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) \
58 (HAS_TREE_OP ? sizeof (struct STRUCT) - sizeof (tree) : 0),
59 EXPORTED_CONST size_t gimple_ops_offset_[] = {
60 #include "gsstruct.def"
64 #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) sizeof(struct STRUCT),
65 static const size_t gsstruct_code_size[] = {
66 #include "gsstruct.def"
70 #define DEFGSCODE(SYM, NAME, GSSCODE) NAME,
71 const char *const gimple_code_name[] = {
76 #define DEFGSCODE(SYM, NAME, GSSCODE) GSSCODE,
77 EXPORTED_CONST enum gimple_statement_structure_enum gss_for_code_[] = {
82 #ifdef GATHER_STATISTICS
85 int gimple_alloc_counts[(int) gimple_alloc_kind_all];
86 int gimple_alloc_sizes[(int) gimple_alloc_kind_all];
88 /* Keep in sync with gimple.h:enum gimple_alloc_kind. */
89 static const char * const gimple_alloc_kind_names[] = {
97 #endif /* GATHER_STATISTICS */
99 /* A cache of gimple_seq objects. Sequences are created and destroyed
100 fairly often during gimplification. */
101 static GTY ((deletable)) struct gimple_seq_d *gimple_seq_cache;
103 /* Private API manipulation functions shared only with some
105 extern void gimple_set_stored_syms (gimple, bitmap, bitmap_obstack *);
106 extern void gimple_set_loaded_syms (gimple, bitmap, bitmap_obstack *);
108 /* Gimple tuple constructors.
109 Note: Any constructor taking a ``gimple_seq'' as a parameter, can
110 be passed a NULL to start with an empty sequence. */
112 /* Set the code for statement G to CODE. */
115 gimple_set_code (gimple g, enum gimple_code code)
117 g->gsbase.code = code;
120 /* Return the number of bytes needed to hold a GIMPLE statement with
124 gimple_size (enum gimple_code code)
126 return gsstruct_code_size[gss_for_code (code)];
129 /* Allocate memory for a GIMPLE statement with code CODE and NUM_OPS
133 gimple_alloc_stat (enum gimple_code code, unsigned num_ops MEM_STAT_DECL)
138 size = gimple_size (code);
140 size += sizeof (tree) * (num_ops - 1);
142 #ifdef GATHER_STATISTICS
144 enum gimple_alloc_kind kind = gimple_alloc_kind (code);
145 gimple_alloc_counts[(int) kind]++;
146 gimple_alloc_sizes[(int) kind] += size;
150 stmt = ggc_alloc_cleared_gimple_statement_d_stat (size PASS_MEM_STAT);
151 gimple_set_code (stmt, code);
152 gimple_set_num_ops (stmt, num_ops);
154 /* Do not call gimple_set_modified here as it has other side
155 effects and this tuple is still not completely built. */
156 stmt->gsbase.modified = 1;
161 /* Set SUBCODE to be the code of the expression computed by statement G. */
164 gimple_set_subcode (gimple g, unsigned subcode)
166 /* We only have 16 bits for the RHS code. Assert that we are not
168 gcc_assert (subcode < (1 << 16));
169 g->gsbase.subcode = subcode;
174 /* Build a tuple with operands. CODE is the statement to build (which
175 must be one of the GIMPLE_WITH_OPS tuples). SUBCODE is the sub-code
176 for the new tuple. NUM_OPS is the number of operands to allocate. */
178 #define gimple_build_with_ops(c, s, n) \
179 gimple_build_with_ops_stat (c, s, n MEM_STAT_INFO)
182 gimple_build_with_ops_stat (enum gimple_code code, unsigned subcode,
183 unsigned num_ops MEM_STAT_DECL)
185 gimple s = gimple_alloc_stat (code, num_ops PASS_MEM_STAT);
186 gimple_set_subcode (s, subcode);
192 /* Build a GIMPLE_RETURN statement returning RETVAL. */
195 gimple_build_return (tree retval)
197 gimple s = gimple_build_with_ops (GIMPLE_RETURN, ERROR_MARK, 1);
199 gimple_return_set_retval (s, retval);
203 /* Reset alias information on call S. */
206 gimple_call_reset_alias_info (gimple s)
208 if (gimple_call_flags (s) & ECF_CONST)
209 memset (gimple_call_use_set (s), 0, sizeof (struct pt_solution));
211 pt_solution_reset (gimple_call_use_set (s));
212 if (gimple_call_flags (s) & (ECF_CONST|ECF_PURE|ECF_NOVOPS))
213 memset (gimple_call_clobber_set (s), 0, sizeof (struct pt_solution));
215 pt_solution_reset (gimple_call_clobber_set (s));
218 /* Helper for gimple_build_call, gimple_build_call_valist,
219 gimple_build_call_vec and gimple_build_call_from_tree. Build the basic
220 components of a GIMPLE_CALL statement to function FN with NARGS
224 gimple_build_call_1 (tree fn, unsigned nargs)
226 gimple s = gimple_build_with_ops (GIMPLE_CALL, ERROR_MARK, nargs + 3);
227 if (TREE_CODE (fn) == FUNCTION_DECL)
228 fn = build_fold_addr_expr (fn);
229 gimple_set_op (s, 1, fn);
230 gimple_call_set_fntype (s, TREE_TYPE (TREE_TYPE (fn)));
231 gimple_call_reset_alias_info (s);
236 /* Build a GIMPLE_CALL statement to function FN with the arguments
237 specified in vector ARGS. */
240 gimple_build_call_vec (tree fn, VEC(tree, heap) *args)
243 unsigned nargs = VEC_length (tree, args);
244 gimple call = gimple_build_call_1 (fn, nargs);
246 for (i = 0; i < nargs; i++)
247 gimple_call_set_arg (call, i, VEC_index (tree, args, i));
253 /* Build a GIMPLE_CALL statement to function FN. NARGS is the number of
254 arguments. The ... are the arguments. */
257 gimple_build_call (tree fn, unsigned nargs, ...)
263 gcc_assert (TREE_CODE (fn) == FUNCTION_DECL || is_gimple_call_addr (fn));
265 call = gimple_build_call_1 (fn, nargs);
267 va_start (ap, nargs);
268 for (i = 0; i < nargs; i++)
269 gimple_call_set_arg (call, i, va_arg (ap, tree));
276 /* Build a GIMPLE_CALL statement to function FN. NARGS is the number of
277 arguments. AP contains the arguments. */
280 gimple_build_call_valist (tree fn, unsigned nargs, va_list ap)
285 gcc_assert (TREE_CODE (fn) == FUNCTION_DECL || is_gimple_call_addr (fn));
287 call = gimple_build_call_1 (fn, nargs);
289 for (i = 0; i < nargs; i++)
290 gimple_call_set_arg (call, i, va_arg (ap, tree));
296 /* Helper for gimple_build_call_internal and gimple_build_call_internal_vec.
297 Build the basic components of a GIMPLE_CALL statement to internal
298 function FN with NARGS arguments. */
301 gimple_build_call_internal_1 (enum internal_fn fn, unsigned nargs)
303 gimple s = gimple_build_with_ops (GIMPLE_CALL, ERROR_MARK, nargs + 3);
304 s->gsbase.subcode |= GF_CALL_INTERNAL;
305 gimple_call_set_internal_fn (s, fn);
306 gimple_call_reset_alias_info (s);
311 /* Build a GIMPLE_CALL statement to internal function FN. NARGS is
312 the number of arguments. The ... are the arguments. */
315 gimple_build_call_internal (enum internal_fn fn, unsigned nargs, ...)
321 call = gimple_build_call_internal_1 (fn, nargs);
322 va_start (ap, nargs);
323 for (i = 0; i < nargs; i++)
324 gimple_call_set_arg (call, i, va_arg (ap, tree));
331 /* Build a GIMPLE_CALL statement to internal function FN with the arguments
332 specified in vector ARGS. */
335 gimple_build_call_internal_vec (enum internal_fn fn, VEC(tree, heap) *args)
340 nargs = VEC_length (tree, args);
341 call = gimple_build_call_internal_1 (fn, nargs);
342 for (i = 0; i < nargs; i++)
343 gimple_call_set_arg (call, i, VEC_index (tree, args, i));
349 /* Build a GIMPLE_CALL statement from CALL_EXPR T. Note that T is
350 assumed to be in GIMPLE form already. Minimal checking is done of
354 gimple_build_call_from_tree (tree t)
358 tree fndecl = get_callee_fndecl (t);
360 gcc_assert (TREE_CODE (t) == CALL_EXPR);
362 nargs = call_expr_nargs (t);
363 call = gimple_build_call_1 (fndecl ? fndecl : CALL_EXPR_FN (t), nargs);
365 for (i = 0; i < nargs; i++)
366 gimple_call_set_arg (call, i, CALL_EXPR_ARG (t, i));
368 gimple_set_block (call, TREE_BLOCK (t));
370 /* Carry all the CALL_EXPR flags to the new GIMPLE_CALL. */
371 gimple_call_set_chain (call, CALL_EXPR_STATIC_CHAIN (t));
372 gimple_call_set_tail (call, CALL_EXPR_TAILCALL (t));
373 gimple_call_set_return_slot_opt (call, CALL_EXPR_RETURN_SLOT_OPT (t));
375 && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
376 && (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA
377 || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA_WITH_ALIGN))
378 gimple_call_set_alloca_for_var (call, CALL_ALLOCA_FOR_VAR_P (t));
380 gimple_call_set_from_thunk (call, CALL_FROM_THUNK_P (t));
381 gimple_call_set_va_arg_pack (call, CALL_EXPR_VA_ARG_PACK (t));
382 gimple_call_set_nothrow (call, TREE_NOTHROW (t));
383 gimple_set_no_warning (call, TREE_NO_WARNING (t));
389 /* Extract the operands and code for expression EXPR into *SUBCODE_P,
390 *OP1_P, *OP2_P and *OP3_P respectively. */
393 extract_ops_from_tree_1 (tree expr, enum tree_code *subcode_p, tree *op1_p,
394 tree *op2_p, tree *op3_p)
396 enum gimple_rhs_class grhs_class;
398 *subcode_p = TREE_CODE (expr);
399 grhs_class = get_gimple_rhs_class (*subcode_p);
401 if (grhs_class == GIMPLE_TERNARY_RHS)
403 *op1_p = TREE_OPERAND (expr, 0);
404 *op2_p = TREE_OPERAND (expr, 1);
405 *op3_p = TREE_OPERAND (expr, 2);
407 else if (grhs_class == GIMPLE_BINARY_RHS)
409 *op1_p = TREE_OPERAND (expr, 0);
410 *op2_p = TREE_OPERAND (expr, 1);
413 else if (grhs_class == GIMPLE_UNARY_RHS)
415 *op1_p = TREE_OPERAND (expr, 0);
419 else if (grhs_class == GIMPLE_SINGLE_RHS)
430 /* Build a GIMPLE_ASSIGN statement.
432 LHS of the assignment.
433 RHS of the assignment which can be unary or binary. */
436 gimple_build_assign_stat (tree lhs, tree rhs MEM_STAT_DECL)
438 enum tree_code subcode;
441 extract_ops_from_tree_1 (rhs, &subcode, &op1, &op2, &op3);
442 return gimple_build_assign_with_ops_stat (subcode, lhs, op1, op2, op3
447 /* Build a GIMPLE_ASSIGN statement with sub-code SUBCODE and operands
448 OP1 and OP2. If OP2 is NULL then SUBCODE must be of class
449 GIMPLE_UNARY_RHS or GIMPLE_SINGLE_RHS. */
452 gimple_build_assign_with_ops_stat (enum tree_code subcode, tree lhs, tree op1,
453 tree op2, tree op3 MEM_STAT_DECL)
458 /* Need 1 operand for LHS and 1 or 2 for the RHS (depending on the
460 num_ops = get_gimple_rhs_num_ops (subcode) + 1;
462 p = gimple_build_with_ops_stat (GIMPLE_ASSIGN, (unsigned)subcode, num_ops
464 gimple_assign_set_lhs (p, lhs);
465 gimple_assign_set_rhs1 (p, op1);
468 gcc_assert (num_ops > 2);
469 gimple_assign_set_rhs2 (p, op2);
474 gcc_assert (num_ops > 3);
475 gimple_assign_set_rhs3 (p, op3);
482 /* Build a new GIMPLE_ASSIGN tuple and append it to the end of *SEQ_P.
484 DST/SRC are the destination and source respectively. You can pass
485 ungimplified trees in DST or SRC, in which case they will be
486 converted to a gimple operand if necessary.
488 This function returns the newly created GIMPLE_ASSIGN tuple. */
491 gimplify_assign (tree dst, tree src, gimple_seq *seq_p)
493 tree t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
494 gimplify_and_add (t, seq_p);
496 return gimple_seq_last_stmt (*seq_p);
500 /* Build a GIMPLE_COND statement.
502 PRED is the condition used to compare LHS and the RHS.
503 T_LABEL is the label to jump to if the condition is true.
504 F_LABEL is the label to jump to otherwise. */
507 gimple_build_cond (enum tree_code pred_code, tree lhs, tree rhs,
508 tree t_label, tree f_label)
512 gcc_assert (TREE_CODE_CLASS (pred_code) == tcc_comparison);
513 p = gimple_build_with_ops (GIMPLE_COND, pred_code, 4);
514 gimple_cond_set_lhs (p, lhs);
515 gimple_cond_set_rhs (p, rhs);
516 gimple_cond_set_true_label (p, t_label);
517 gimple_cond_set_false_label (p, f_label);
522 /* Extract operands for a GIMPLE_COND statement out of COND_EXPR tree COND. */
525 gimple_cond_get_ops_from_tree (tree cond, enum tree_code *code_p,
526 tree *lhs_p, tree *rhs_p)
528 gcc_assert (TREE_CODE_CLASS (TREE_CODE (cond)) == tcc_comparison
529 || TREE_CODE (cond) == TRUTH_NOT_EXPR
530 || is_gimple_min_invariant (cond)
531 || SSA_VAR_P (cond));
533 extract_ops_from_tree (cond, code_p, lhs_p, rhs_p);
535 /* Canonicalize conditionals of the form 'if (!VAL)'. */
536 if (*code_p == TRUTH_NOT_EXPR)
539 gcc_assert (*lhs_p && *rhs_p == NULL_TREE);
540 *rhs_p = build_zero_cst (TREE_TYPE (*lhs_p));
542 /* Canonicalize conditionals of the form 'if (VAL)' */
543 else if (TREE_CODE_CLASS (*code_p) != tcc_comparison)
546 gcc_assert (*lhs_p && *rhs_p == NULL_TREE);
547 *rhs_p = build_zero_cst (TREE_TYPE (*lhs_p));
552 /* Build a GIMPLE_COND statement from the conditional expression tree
553 COND. T_LABEL and F_LABEL are as in gimple_build_cond. */
556 gimple_build_cond_from_tree (tree cond, tree t_label, tree f_label)
561 gimple_cond_get_ops_from_tree (cond, &code, &lhs, &rhs);
562 return gimple_build_cond (code, lhs, rhs, t_label, f_label);
565 /* Set code, lhs, and rhs of a GIMPLE_COND from a suitable
566 boolean expression tree COND. */
569 gimple_cond_set_condition_from_tree (gimple stmt, tree cond)
574 gimple_cond_get_ops_from_tree (cond, &code, &lhs, &rhs);
575 gimple_cond_set_condition (stmt, code, lhs, rhs);
578 /* Build a GIMPLE_LABEL statement for LABEL. */
581 gimple_build_label (tree label)
583 gimple p = gimple_build_with_ops (GIMPLE_LABEL, ERROR_MARK, 1);
584 gimple_label_set_label (p, label);
588 /* Build a GIMPLE_GOTO statement to label DEST. */
591 gimple_build_goto (tree dest)
593 gimple p = gimple_build_with_ops (GIMPLE_GOTO, ERROR_MARK, 1);
594 gimple_goto_set_dest (p, dest);
599 /* Build a GIMPLE_NOP statement. */
602 gimple_build_nop (void)
604 return gimple_alloc (GIMPLE_NOP, 0);
608 /* Build a GIMPLE_BIND statement.
609 VARS are the variables in BODY.
610 BLOCK is the containing block. */
613 gimple_build_bind (tree vars, gimple_seq body, tree block)
615 gimple p = gimple_alloc (GIMPLE_BIND, 0);
616 gimple_bind_set_vars (p, vars);
618 gimple_bind_set_body (p, body);
620 gimple_bind_set_block (p, block);
624 /* Helper function to set the simple fields of a asm stmt.
626 STRING is a pointer to a string that is the asm blocks assembly code.
627 NINPUT is the number of register inputs.
628 NOUTPUT is the number of register outputs.
629 NCLOBBERS is the number of clobbered registers.
633 gimple_build_asm_1 (const char *string, unsigned ninputs, unsigned noutputs,
634 unsigned nclobbers, unsigned nlabels)
637 int size = strlen (string);
639 /* ASMs with labels cannot have outputs. This should have been
640 enforced by the front end. */
641 gcc_assert (nlabels == 0 || noutputs == 0);
643 p = gimple_build_with_ops (GIMPLE_ASM, ERROR_MARK,
644 ninputs + noutputs + nclobbers + nlabels);
646 p->gimple_asm.ni = ninputs;
647 p->gimple_asm.no = noutputs;
648 p->gimple_asm.nc = nclobbers;
649 p->gimple_asm.nl = nlabels;
650 p->gimple_asm.string = ggc_alloc_string (string, size);
652 #ifdef GATHER_STATISTICS
653 gimple_alloc_sizes[(int) gimple_alloc_kind (GIMPLE_ASM)] += size;
659 /* Build a GIMPLE_ASM statement.
661 STRING is the assembly code.
662 NINPUT is the number of register inputs.
663 NOUTPUT is the number of register outputs.
664 NCLOBBERS is the number of clobbered registers.
665 INPUTS is a vector of the input register parameters.
666 OUTPUTS is a vector of the output register parameters.
667 CLOBBERS is a vector of the clobbered register parameters.
668 LABELS is a vector of destination labels. */
671 gimple_build_asm_vec (const char *string, VEC(tree,gc)* inputs,
672 VEC(tree,gc)* outputs, VEC(tree,gc)* clobbers,
673 VEC(tree,gc)* labels)
678 p = gimple_build_asm_1 (string,
679 VEC_length (tree, inputs),
680 VEC_length (tree, outputs),
681 VEC_length (tree, clobbers),
682 VEC_length (tree, labels));
684 for (i = 0; i < VEC_length (tree, inputs); i++)
685 gimple_asm_set_input_op (p, i, VEC_index (tree, inputs, i));
687 for (i = 0; i < VEC_length (tree, outputs); i++)
688 gimple_asm_set_output_op (p, i, VEC_index (tree, outputs, i));
690 for (i = 0; i < VEC_length (tree, clobbers); i++)
691 gimple_asm_set_clobber_op (p, i, VEC_index (tree, clobbers, i));
693 for (i = 0; i < VEC_length (tree, labels); i++)
694 gimple_asm_set_label_op (p, i, VEC_index (tree, labels, i));
699 /* Build a GIMPLE_CATCH statement.
701 TYPES are the catch types.
702 HANDLER is the exception handler. */
705 gimple_build_catch (tree types, gimple_seq handler)
707 gimple p = gimple_alloc (GIMPLE_CATCH, 0);
708 gimple_catch_set_types (p, types);
710 gimple_catch_set_handler (p, handler);
715 /* Build a GIMPLE_EH_FILTER statement.
717 TYPES are the filter's types.
718 FAILURE is the filter's failure action. */
721 gimple_build_eh_filter (tree types, gimple_seq failure)
723 gimple p = gimple_alloc (GIMPLE_EH_FILTER, 0);
724 gimple_eh_filter_set_types (p, types);
726 gimple_eh_filter_set_failure (p, failure);
731 /* Build a GIMPLE_EH_MUST_NOT_THROW statement. */
734 gimple_build_eh_must_not_throw (tree decl)
736 gimple p = gimple_alloc (GIMPLE_EH_MUST_NOT_THROW, 0);
738 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
739 gcc_assert (flags_from_decl_or_type (decl) & ECF_NORETURN);
740 gimple_eh_must_not_throw_set_fndecl (p, decl);
745 /* Build a GIMPLE_EH_ELSE statement. */
748 gimple_build_eh_else (gimple_seq n_body, gimple_seq e_body)
750 gimple p = gimple_alloc (GIMPLE_EH_ELSE, 0);
751 gimple_eh_else_set_n_body (p, n_body);
752 gimple_eh_else_set_e_body (p, e_body);
756 /* Build a GIMPLE_TRY statement.
758 EVAL is the expression to evaluate.
759 CLEANUP is the cleanup expression.
760 KIND is either GIMPLE_TRY_CATCH or GIMPLE_TRY_FINALLY depending on
761 whether this is a try/catch or a try/finally respectively. */
764 gimple_build_try (gimple_seq eval, gimple_seq cleanup,
765 enum gimple_try_flags kind)
769 gcc_assert (kind == GIMPLE_TRY_CATCH || kind == GIMPLE_TRY_FINALLY);
770 p = gimple_alloc (GIMPLE_TRY, 0);
771 gimple_set_subcode (p, kind);
773 gimple_try_set_eval (p, eval);
775 gimple_try_set_cleanup (p, cleanup);
780 /* Construct a GIMPLE_WITH_CLEANUP_EXPR statement.
782 CLEANUP is the cleanup expression. */
785 gimple_build_wce (gimple_seq cleanup)
787 gimple p = gimple_alloc (GIMPLE_WITH_CLEANUP_EXPR, 0);
789 gimple_wce_set_cleanup (p, cleanup);
795 /* Build a GIMPLE_RESX statement. */
798 gimple_build_resx (int region)
800 gimple p = gimple_build_with_ops (GIMPLE_RESX, ERROR_MARK, 0);
801 p->gimple_eh_ctrl.region = region;
806 /* The helper for constructing a gimple switch statement.
807 INDEX is the switch's index.
808 NLABELS is the number of labels in the switch excluding the default.
809 DEFAULT_LABEL is the default label for the switch statement. */
812 gimple_build_switch_nlabels (unsigned nlabels, tree index, tree default_label)
814 /* nlabels + 1 default label + 1 index. */
815 gimple p = gimple_build_with_ops (GIMPLE_SWITCH, ERROR_MARK,
816 1 + (default_label != NULL) + nlabels);
817 gimple_switch_set_index (p, index);
819 gimple_switch_set_default_label (p, default_label);
824 /* Build a GIMPLE_SWITCH statement.
826 INDEX is the switch's index.
827 NLABELS is the number of labels in the switch excluding the DEFAULT_LABEL.
828 ... are the labels excluding the default. */
831 gimple_build_switch (unsigned nlabels, tree index, tree default_label, ...)
835 gimple p = gimple_build_switch_nlabels (nlabels, index, default_label);
837 /* Store the rest of the labels. */
838 va_start (al, default_label);
839 offset = (default_label != NULL);
840 for (i = 0; i < nlabels; i++)
841 gimple_switch_set_label (p, i + offset, va_arg (al, tree));
848 /* Build a GIMPLE_SWITCH statement.
850 INDEX is the switch's index.
851 DEFAULT_LABEL is the default label
852 ARGS is a vector of labels excluding the default. */
855 gimple_build_switch_vec (tree index, tree default_label, VEC(tree, heap) *args)
857 unsigned i, offset, nlabels = VEC_length (tree, args);
858 gimple p = gimple_build_switch_nlabels (nlabels, index, default_label);
860 /* Copy the labels from the vector to the switch statement. */
861 offset = (default_label != NULL);
862 for (i = 0; i < nlabels; i++)
863 gimple_switch_set_label (p, i + offset, VEC_index (tree, args, i));
868 /* Build a GIMPLE_EH_DISPATCH statement. */
871 gimple_build_eh_dispatch (int region)
873 gimple p = gimple_build_with_ops (GIMPLE_EH_DISPATCH, ERROR_MARK, 0);
874 p->gimple_eh_ctrl.region = region;
878 /* Build a new GIMPLE_DEBUG_BIND statement.
880 VAR is bound to VALUE; block and location are taken from STMT. */
883 gimple_build_debug_bind_stat (tree var, tree value, gimple stmt MEM_STAT_DECL)
885 gimple p = gimple_build_with_ops_stat (GIMPLE_DEBUG,
886 (unsigned)GIMPLE_DEBUG_BIND, 2
889 gimple_debug_bind_set_var (p, var);
890 gimple_debug_bind_set_value (p, value);
893 gimple_set_block (p, gimple_block (stmt));
894 gimple_set_location (p, gimple_location (stmt));
901 /* Build a new GIMPLE_DEBUG_SOURCE_BIND statement.
903 VAR is bound to VALUE; block and location are taken from STMT. */
906 gimple_build_debug_source_bind_stat (tree var, tree value,
907 gimple stmt MEM_STAT_DECL)
909 gimple p = gimple_build_with_ops_stat (GIMPLE_DEBUG,
910 (unsigned)GIMPLE_DEBUG_SOURCE_BIND, 2
913 gimple_debug_source_bind_set_var (p, var);
914 gimple_debug_source_bind_set_value (p, value);
917 gimple_set_block (p, gimple_block (stmt));
918 gimple_set_location (p, gimple_location (stmt));
925 /* Build a GIMPLE_OMP_CRITICAL statement.
927 BODY is the sequence of statements for which only one thread can execute.
928 NAME is optional identifier for this critical block. */
931 gimple_build_omp_critical (gimple_seq body, tree name)
933 gimple p = gimple_alloc (GIMPLE_OMP_CRITICAL, 0);
934 gimple_omp_critical_set_name (p, name);
936 gimple_omp_set_body (p, body);
941 /* Build a GIMPLE_OMP_FOR statement.
943 BODY is sequence of statements inside the for loop.
944 CLAUSES, are any of the OMP loop construct's clauses: private, firstprivate,
945 lastprivate, reductions, ordered, schedule, and nowait.
946 COLLAPSE is the collapse count.
947 PRE_BODY is the sequence of statements that are loop invariant. */
950 gimple_build_omp_for (gimple_seq body, tree clauses, size_t collapse,
953 gimple p = gimple_alloc (GIMPLE_OMP_FOR, 0);
955 gimple_omp_set_body (p, body);
956 gimple_omp_for_set_clauses (p, clauses);
957 p->gimple_omp_for.collapse = collapse;
958 p->gimple_omp_for.iter
959 = ggc_alloc_cleared_vec_gimple_omp_for_iter (collapse);
961 gimple_omp_for_set_pre_body (p, pre_body);
967 /* Build a GIMPLE_OMP_PARALLEL statement.
969 BODY is sequence of statements which are executed in parallel.
970 CLAUSES, are the OMP parallel construct's clauses.
971 CHILD_FN is the function created for the parallel threads to execute.
972 DATA_ARG are the shared data argument(s). */
975 gimple_build_omp_parallel (gimple_seq body, tree clauses, tree child_fn,
978 gimple p = gimple_alloc (GIMPLE_OMP_PARALLEL, 0);
980 gimple_omp_set_body (p, body);
981 gimple_omp_parallel_set_clauses (p, clauses);
982 gimple_omp_parallel_set_child_fn (p, child_fn);
983 gimple_omp_parallel_set_data_arg (p, data_arg);
989 /* Build a GIMPLE_OMP_TASK statement.
991 BODY is sequence of statements which are executed by the explicit task.
992 CLAUSES, are the OMP parallel construct's clauses.
993 CHILD_FN is the function created for the parallel threads to execute.
994 DATA_ARG are the shared data argument(s).
995 COPY_FN is the optional function for firstprivate initialization.
996 ARG_SIZE and ARG_ALIGN are size and alignment of the data block. */
999 gimple_build_omp_task (gimple_seq body, tree clauses, tree child_fn,
1000 tree data_arg, tree copy_fn, tree arg_size,
1003 gimple p = gimple_alloc (GIMPLE_OMP_TASK, 0);
1005 gimple_omp_set_body (p, body);
1006 gimple_omp_task_set_clauses (p, clauses);
1007 gimple_omp_task_set_child_fn (p, child_fn);
1008 gimple_omp_task_set_data_arg (p, data_arg);
1009 gimple_omp_task_set_copy_fn (p, copy_fn);
1010 gimple_omp_task_set_arg_size (p, arg_size);
1011 gimple_omp_task_set_arg_align (p, arg_align);
1017 /* Build a GIMPLE_OMP_SECTION statement for a sections statement.
1019 BODY is the sequence of statements in the section. */
1022 gimple_build_omp_section (gimple_seq body)
1024 gimple p = gimple_alloc (GIMPLE_OMP_SECTION, 0);
1026 gimple_omp_set_body (p, body);
1032 /* Build a GIMPLE_OMP_MASTER statement.
1034 BODY is the sequence of statements to be executed by just the master. */
1037 gimple_build_omp_master (gimple_seq body)
1039 gimple p = gimple_alloc (GIMPLE_OMP_MASTER, 0);
1041 gimple_omp_set_body (p, body);
1047 /* Build a GIMPLE_OMP_CONTINUE statement.
1049 CONTROL_DEF is the definition of the control variable.
1050 CONTROL_USE is the use of the control variable. */
1053 gimple_build_omp_continue (tree control_def, tree control_use)
1055 gimple p = gimple_alloc (GIMPLE_OMP_CONTINUE, 0);
1056 gimple_omp_continue_set_control_def (p, control_def);
1057 gimple_omp_continue_set_control_use (p, control_use);
1061 /* Build a GIMPLE_OMP_ORDERED statement.
1063 BODY is the sequence of statements inside a loop that will executed in
1067 gimple_build_omp_ordered (gimple_seq body)
1069 gimple p = gimple_alloc (GIMPLE_OMP_ORDERED, 0);
1071 gimple_omp_set_body (p, body);
1077 /* Build a GIMPLE_OMP_RETURN statement.
1078 WAIT_P is true if this is a non-waiting return. */
1081 gimple_build_omp_return (bool wait_p)
1083 gimple p = gimple_alloc (GIMPLE_OMP_RETURN, 0);
1085 gimple_omp_return_set_nowait (p);
1091 /* Build a GIMPLE_OMP_SECTIONS statement.
1093 BODY is a sequence of section statements.
1094 CLAUSES are any of the OMP sections contsruct's clauses: private,
1095 firstprivate, lastprivate, reduction, and nowait. */
1098 gimple_build_omp_sections (gimple_seq body, tree clauses)
1100 gimple p = gimple_alloc (GIMPLE_OMP_SECTIONS, 0);
1102 gimple_omp_set_body (p, body);
1103 gimple_omp_sections_set_clauses (p, clauses);
1109 /* Build a GIMPLE_OMP_SECTIONS_SWITCH. */
1112 gimple_build_omp_sections_switch (void)
1114 return gimple_alloc (GIMPLE_OMP_SECTIONS_SWITCH, 0);
1118 /* Build a GIMPLE_OMP_SINGLE statement.
1120 BODY is the sequence of statements that will be executed once.
1121 CLAUSES are any of the OMP single construct's clauses: private, firstprivate,
1122 copyprivate, nowait. */
1125 gimple_build_omp_single (gimple_seq body, tree clauses)
1127 gimple p = gimple_alloc (GIMPLE_OMP_SINGLE, 0);
1129 gimple_omp_set_body (p, body);
1130 gimple_omp_single_set_clauses (p, clauses);
1136 /* Build a GIMPLE_OMP_ATOMIC_LOAD statement. */
1139 gimple_build_omp_atomic_load (tree lhs, tree rhs)
1141 gimple p = gimple_alloc (GIMPLE_OMP_ATOMIC_LOAD, 0);
1142 gimple_omp_atomic_load_set_lhs (p, lhs);
1143 gimple_omp_atomic_load_set_rhs (p, rhs);
1147 /* Build a GIMPLE_OMP_ATOMIC_STORE statement.
1149 VAL is the value we are storing. */
1152 gimple_build_omp_atomic_store (tree val)
1154 gimple p = gimple_alloc (GIMPLE_OMP_ATOMIC_STORE, 0);
1155 gimple_omp_atomic_store_set_val (p, val);
1159 /* Build a GIMPLE_TRANSACTION statement. */
1162 gimple_build_transaction (gimple_seq body, tree label)
1164 gimple p = gimple_alloc (GIMPLE_TRANSACTION, 0);
1165 gimple_transaction_set_body (p, body);
1166 gimple_transaction_set_label (p, label);
1170 /* Build a GIMPLE_PREDICT statement. PREDICT is one of the predictors from
1171 predict.def, OUTCOME is NOT_TAKEN or TAKEN. */
1174 gimple_build_predict (enum br_predictor predictor, enum prediction outcome)
1176 gimple p = gimple_alloc (GIMPLE_PREDICT, 0);
1177 /* Ensure all the predictors fit into the lower bits of the subcode. */
1178 gcc_assert ((int) END_PREDICTORS <= GF_PREDICT_TAKEN);
1179 gimple_predict_set_predictor (p, predictor);
1180 gimple_predict_set_outcome (p, outcome);
1184 #if defined ENABLE_GIMPLE_CHECKING
1185 /* Complain of a gimple type mismatch and die. */
1188 gimple_check_failed (const_gimple gs, const char *file, int line,
1189 const char *function, enum gimple_code code,
1190 enum tree_code subcode)
1192 internal_error ("gimple check: expected %s(%s), have %s(%s) in %s, at %s:%d",
1193 gimple_code_name[code],
1194 tree_code_name[subcode],
1195 gimple_code_name[gimple_code (gs)],
1196 gs->gsbase.subcode > 0
1197 ? tree_code_name[gs->gsbase.subcode]
1199 function, trim_filename (file), line);
1201 #endif /* ENABLE_GIMPLE_CHECKING */
1204 /* Allocate a new GIMPLE sequence in GC memory and return it. If
1205 there are free sequences in GIMPLE_SEQ_CACHE return one of those
1209 gimple_seq_alloc (void)
1211 gimple_seq seq = gimple_seq_cache;
1214 gimple_seq_cache = gimple_seq_cache->next_free;
1215 gcc_assert (gimple_seq_cache != seq);
1216 memset (seq, 0, sizeof (*seq));
1220 seq = ggc_alloc_cleared_gimple_seq_d ();
1221 #ifdef GATHER_STATISTICS
1222 gimple_alloc_counts[(int) gimple_alloc_kind_seq]++;
1223 gimple_alloc_sizes[(int) gimple_alloc_kind_seq] += sizeof (*seq);
1230 /* Return SEQ to the free pool of GIMPLE sequences. */
1233 gimple_seq_free (gimple_seq seq)
1238 gcc_assert (gimple_seq_first (seq) == NULL);
1239 gcc_assert (gimple_seq_last (seq) == NULL);
1241 /* If this triggers, it's a sign that the same list is being freed
1243 gcc_assert (seq != gimple_seq_cache || gimple_seq_cache == NULL);
1245 /* Add SEQ to the pool of free sequences. */
1246 seq->next_free = gimple_seq_cache;
1247 gimple_seq_cache = seq;
1251 /* Link gimple statement GS to the end of the sequence *SEQ_P. If
1252 *SEQ_P is NULL, a new sequence is allocated. */
1255 gimple_seq_add_stmt (gimple_seq *seq_p, gimple gs)
1257 gimple_stmt_iterator si;
1263 *seq_p = gimple_seq_alloc ();
1265 si = gsi_last (*seq_p);
1266 gsi_insert_after (&si, gs, GSI_NEW_STMT);
1270 /* Append sequence SRC to the end of sequence *DST_P. If *DST_P is
1271 NULL, a new sequence is allocated. */
1274 gimple_seq_add_seq (gimple_seq *dst_p, gimple_seq src)
1276 gimple_stmt_iterator si;
1282 *dst_p = gimple_seq_alloc ();
1284 si = gsi_last (*dst_p);
1285 gsi_insert_seq_after (&si, src, GSI_NEW_STMT);
1289 /* Helper function of empty_body_p. Return true if STMT is an empty
1293 empty_stmt_p (gimple stmt)
1295 if (gimple_code (stmt) == GIMPLE_NOP)
1297 if (gimple_code (stmt) == GIMPLE_BIND)
1298 return empty_body_p (gimple_bind_body (stmt));
1303 /* Return true if BODY contains nothing but empty statements. */
1306 empty_body_p (gimple_seq body)
1308 gimple_stmt_iterator i;
1310 if (gimple_seq_empty_p (body))
1312 for (i = gsi_start (body); !gsi_end_p (i); gsi_next (&i))
1313 if (!empty_stmt_p (gsi_stmt (i))
1314 && !is_gimple_debug (gsi_stmt (i)))
1321 /* Perform a deep copy of sequence SRC and return the result. */
1324 gimple_seq_copy (gimple_seq src)
1326 gimple_stmt_iterator gsi;
1327 gimple_seq new_seq = gimple_seq_alloc ();
1330 for (gsi = gsi_start (src); !gsi_end_p (gsi); gsi_next (&gsi))
1332 stmt = gimple_copy (gsi_stmt (gsi));
1333 gimple_seq_add_stmt (&new_seq, stmt);
1340 /* Walk all the statements in the sequence SEQ calling walk_gimple_stmt
1341 on each one. WI is as in walk_gimple_stmt.
1343 If walk_gimple_stmt returns non-NULL, the walk is stopped, and the
1344 value is stored in WI->CALLBACK_RESULT. Also, the statement that
1345 produced the value is returned if this statement has not been
1346 removed by a callback (wi->removed_stmt). If the statement has
1347 been removed, NULL is returned.
1349 Otherwise, all the statements are walked and NULL returned. */
1352 walk_gimple_seq (gimple_seq seq, walk_stmt_fn callback_stmt,
1353 walk_tree_fn callback_op, struct walk_stmt_info *wi)
1355 gimple_stmt_iterator gsi;
1357 for (gsi = gsi_start (seq); !gsi_end_p (gsi); )
1359 tree ret = walk_gimple_stmt (&gsi, callback_stmt, callback_op, wi);
1362 /* If CALLBACK_STMT or CALLBACK_OP return a value, WI must exist
1365 wi->callback_result = ret;
1367 return wi->removed_stmt ? NULL : gsi_stmt (gsi);
1370 if (!wi->removed_stmt)
1375 wi->callback_result = NULL_TREE;
1381 /* Helper function for walk_gimple_stmt. Walk operands of a GIMPLE_ASM. */
1384 walk_gimple_asm (gimple stmt, walk_tree_fn callback_op,
1385 struct walk_stmt_info *wi)
1389 const char **oconstraints;
1391 const char *constraint;
1392 bool allows_mem, allows_reg, is_inout;
1394 noutputs = gimple_asm_noutputs (stmt);
1395 oconstraints = (const char **) alloca ((noutputs) * sizeof (const char *));
1400 for (i = 0; i < noutputs; i++)
1402 op = gimple_asm_output_op (stmt, i);
1403 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op)));
1404 oconstraints[i] = constraint;
1405 parse_output_constraint (&constraint, i, 0, 0, &allows_mem, &allows_reg,
1408 wi->val_only = (allows_reg || !allows_mem);
1409 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
1414 n = gimple_asm_ninputs (stmt);
1415 for (i = 0; i < n; i++)
1417 op = gimple_asm_input_op (stmt, i);
1418 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op)));
1419 parse_input_constraint (&constraint, 0, 0, noutputs, 0,
1420 oconstraints, &allows_mem, &allows_reg);
1423 wi->val_only = (allows_reg || !allows_mem);
1424 /* Although input "m" is not really a LHS, we need a lvalue. */
1425 wi->is_lhs = !wi->val_only;
1427 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
1435 wi->val_only = true;
1438 n = gimple_asm_nlabels (stmt);
1439 for (i = 0; i < n; i++)
1441 op = gimple_asm_label_op (stmt, i);
1442 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
1451 /* Helper function of WALK_GIMPLE_STMT. Walk every tree operand in
1452 STMT. CALLBACK_OP and WI are as in WALK_GIMPLE_STMT.
1454 CALLBACK_OP is called on each operand of STMT via walk_tree.
1455 Additional parameters to walk_tree must be stored in WI. For each operand
1456 OP, walk_tree is called as:
1458 walk_tree (&OP, CALLBACK_OP, WI, WI->PSET)
1460 If CALLBACK_OP returns non-NULL for an operand, the remaining
1461 operands are not scanned.
1463 The return value is that returned by the last call to walk_tree, or
1464 NULL_TREE if no CALLBACK_OP is specified. */
1467 walk_gimple_op (gimple stmt, walk_tree_fn callback_op,
1468 struct walk_stmt_info *wi)
1470 struct pointer_set_t *pset = (wi) ? wi->pset : NULL;
1472 tree ret = NULL_TREE;
1474 switch (gimple_code (stmt))
1477 /* Walk the RHS operands. If the LHS is of a non-renamable type or
1478 is a register variable, we may use a COMPONENT_REF on the RHS. */
1481 tree lhs = gimple_assign_lhs (stmt);
1483 = (is_gimple_reg_type (TREE_TYPE (lhs)) && !is_gimple_reg (lhs))
1484 || gimple_assign_rhs_class (stmt) != GIMPLE_SINGLE_RHS;
1487 for (i = 1; i < gimple_num_ops (stmt); i++)
1489 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi,
1495 /* Walk the LHS. If the RHS is appropriate for a memory, we
1496 may use a COMPONENT_REF on the LHS. */
1499 /* If the RHS is of a non-renamable type or is a register variable,
1500 we may use a COMPONENT_REF on the LHS. */
1501 tree rhs1 = gimple_assign_rhs1 (stmt);
1503 = (is_gimple_reg_type (TREE_TYPE (rhs1)) && !is_gimple_reg (rhs1))
1504 || gimple_assign_rhs_class (stmt) != GIMPLE_SINGLE_RHS;
1508 ret = walk_tree (gimple_op_ptr (stmt, 0), callback_op, wi, pset);
1514 wi->val_only = true;
1523 wi->val_only = true;
1526 ret = walk_tree (gimple_call_chain_ptr (stmt), callback_op, wi, pset);
1530 ret = walk_tree (gimple_call_fn_ptr (stmt), callback_op, wi, pset);
1534 for (i = 0; i < gimple_call_num_args (stmt); i++)
1538 = is_gimple_reg_type (TREE_TYPE (gimple_call_arg (stmt, i)));
1539 ret = walk_tree (gimple_call_arg_ptr (stmt, i), callback_op, wi,
1545 if (gimple_call_lhs (stmt))
1551 = is_gimple_reg_type (TREE_TYPE (gimple_call_lhs (stmt)));
1554 ret = walk_tree (gimple_call_lhs_ptr (stmt), callback_op, wi, pset);
1562 wi->val_only = true;
1567 ret = walk_tree (gimple_catch_types_ptr (stmt), callback_op, wi,
1573 case GIMPLE_EH_FILTER:
1574 ret = walk_tree (gimple_eh_filter_types_ptr (stmt), callback_op, wi,
1581 ret = walk_gimple_asm (stmt, callback_op, wi);
1586 case GIMPLE_OMP_CONTINUE:
1587 ret = walk_tree (gimple_omp_continue_control_def_ptr (stmt),
1588 callback_op, wi, pset);
1592 ret = walk_tree (gimple_omp_continue_control_use_ptr (stmt),
1593 callback_op, wi, pset);
1598 case GIMPLE_OMP_CRITICAL:
1599 ret = walk_tree (gimple_omp_critical_name_ptr (stmt), callback_op, wi,
1605 case GIMPLE_OMP_FOR:
1606 ret = walk_tree (gimple_omp_for_clauses_ptr (stmt), callback_op, wi,
1610 for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
1612 ret = walk_tree (gimple_omp_for_index_ptr (stmt, i), callback_op,
1616 ret = walk_tree (gimple_omp_for_initial_ptr (stmt, i), callback_op,
1620 ret = walk_tree (gimple_omp_for_final_ptr (stmt, i), callback_op,
1624 ret = walk_tree (gimple_omp_for_incr_ptr (stmt, i), callback_op,
1631 case GIMPLE_OMP_PARALLEL:
1632 ret = walk_tree (gimple_omp_parallel_clauses_ptr (stmt), callback_op,
1636 ret = walk_tree (gimple_omp_parallel_child_fn_ptr (stmt), callback_op,
1640 ret = walk_tree (gimple_omp_parallel_data_arg_ptr (stmt), callback_op,
1646 case GIMPLE_OMP_TASK:
1647 ret = walk_tree (gimple_omp_task_clauses_ptr (stmt), callback_op,
1651 ret = walk_tree (gimple_omp_task_child_fn_ptr (stmt), callback_op,
1655 ret = walk_tree (gimple_omp_task_data_arg_ptr (stmt), callback_op,
1659 ret = walk_tree (gimple_omp_task_copy_fn_ptr (stmt), callback_op,
1663 ret = walk_tree (gimple_omp_task_arg_size_ptr (stmt), callback_op,
1667 ret = walk_tree (gimple_omp_task_arg_align_ptr (stmt), callback_op,
1673 case GIMPLE_OMP_SECTIONS:
1674 ret = walk_tree (gimple_omp_sections_clauses_ptr (stmt), callback_op,
1679 ret = walk_tree (gimple_omp_sections_control_ptr (stmt), callback_op,
1686 case GIMPLE_OMP_SINGLE:
1687 ret = walk_tree (gimple_omp_single_clauses_ptr (stmt), callback_op, wi,
1693 case GIMPLE_OMP_ATOMIC_LOAD:
1694 ret = walk_tree (gimple_omp_atomic_load_lhs_ptr (stmt), callback_op, wi,
1699 ret = walk_tree (gimple_omp_atomic_load_rhs_ptr (stmt), callback_op, wi,
1705 case GIMPLE_OMP_ATOMIC_STORE:
1706 ret = walk_tree (gimple_omp_atomic_store_val_ptr (stmt), callback_op,
1712 case GIMPLE_TRANSACTION:
1713 ret = walk_tree (gimple_transaction_label_ptr (stmt), callback_op,
1719 /* Tuples that do not have operands. */
1722 case GIMPLE_OMP_RETURN:
1723 case GIMPLE_PREDICT:
1728 enum gimple_statement_structure_enum gss;
1729 gss = gimple_statement_structure (stmt);
1730 if (gss == GSS_WITH_OPS || gss == GSS_WITH_MEM_OPS)
1731 for (i = 0; i < gimple_num_ops (stmt); i++)
1733 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi, pset);
1745 /* Walk the current statement in GSI (optionally using traversal state
1746 stored in WI). If WI is NULL, no state is kept during traversal.
1747 The callback CALLBACK_STMT is called. If CALLBACK_STMT indicates
1748 that it has handled all the operands of the statement, its return
1749 value is returned. Otherwise, the return value from CALLBACK_STMT
1750 is discarded and its operands are scanned.
1752 If CALLBACK_STMT is NULL or it didn't handle the operands,
1753 CALLBACK_OP is called on each operand of the statement via
1754 walk_gimple_op. If walk_gimple_op returns non-NULL for any
1755 operand, the remaining operands are not scanned. In this case, the
1756 return value from CALLBACK_OP is returned.
1758 In any other case, NULL_TREE is returned. */
1761 walk_gimple_stmt (gimple_stmt_iterator *gsi, walk_stmt_fn callback_stmt,
1762 walk_tree_fn callback_op, struct walk_stmt_info *wi)
1766 gimple stmt = gsi_stmt (*gsi);
1771 wi->removed_stmt = false;
1773 if (wi->want_locations && gimple_has_location (stmt))
1774 input_location = gimple_location (stmt);
1779 /* Invoke the statement callback. Return if the callback handled
1780 all of STMT operands by itself. */
1783 bool handled_ops = false;
1784 tree_ret = callback_stmt (gsi, &handled_ops, wi);
1788 /* If CALLBACK_STMT did not handle operands, it should not have
1789 a value to return. */
1790 gcc_assert (tree_ret == NULL);
1792 if (wi && wi->removed_stmt)
1795 /* Re-read stmt in case the callback changed it. */
1796 stmt = gsi_stmt (*gsi);
1799 /* If CALLBACK_OP is defined, invoke it on every operand of STMT. */
1802 tree_ret = walk_gimple_op (stmt, callback_op, wi);
1807 /* If STMT can have statements inside (e.g. GIMPLE_BIND), walk them. */
1808 switch (gimple_code (stmt))
1811 ret = walk_gimple_seq (gimple_bind_body (stmt), callback_stmt,
1814 return wi->callback_result;
1818 ret = walk_gimple_seq (gimple_catch_handler (stmt), callback_stmt,
1821 return wi->callback_result;
1824 case GIMPLE_EH_FILTER:
1825 ret = walk_gimple_seq (gimple_eh_filter_failure (stmt), callback_stmt,
1828 return wi->callback_result;
1831 case GIMPLE_EH_ELSE:
1832 ret = walk_gimple_seq (gimple_eh_else_n_body (stmt),
1833 callback_stmt, callback_op, wi);
1835 return wi->callback_result;
1836 ret = walk_gimple_seq (gimple_eh_else_e_body (stmt),
1837 callback_stmt, callback_op, wi);
1839 return wi->callback_result;
1843 ret = walk_gimple_seq (gimple_try_eval (stmt), callback_stmt, callback_op,
1846 return wi->callback_result;
1848 ret = walk_gimple_seq (gimple_try_cleanup (stmt), callback_stmt,
1851 return wi->callback_result;
1854 case GIMPLE_OMP_FOR:
1855 ret = walk_gimple_seq (gimple_omp_for_pre_body (stmt), callback_stmt,
1858 return wi->callback_result;
1861 case GIMPLE_OMP_CRITICAL:
1862 case GIMPLE_OMP_MASTER:
1863 case GIMPLE_OMP_ORDERED:
1864 case GIMPLE_OMP_SECTION:
1865 case GIMPLE_OMP_PARALLEL:
1866 case GIMPLE_OMP_TASK:
1867 case GIMPLE_OMP_SECTIONS:
1868 case GIMPLE_OMP_SINGLE:
1869 ret = walk_gimple_seq (gimple_omp_body (stmt), callback_stmt,
1872 return wi->callback_result;
1875 case GIMPLE_WITH_CLEANUP_EXPR:
1876 ret = walk_gimple_seq (gimple_wce_cleanup (stmt), callback_stmt,
1879 return wi->callback_result;
1882 case GIMPLE_TRANSACTION:
1883 ret = walk_gimple_seq (gimple_transaction_body (stmt),
1884 callback_stmt, callback_op, wi);
1886 return wi->callback_result;
1890 gcc_assert (!gimple_has_substatements (stmt));
1898 /* Set sequence SEQ to be the GIMPLE body for function FN. */
1901 gimple_set_body (tree fndecl, gimple_seq seq)
1903 struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
1906 /* If FNDECL still does not have a function structure associated
1907 with it, then it does not make sense for it to receive a
1909 gcc_assert (seq == NULL);
1912 fn->gimple_body = seq;
1916 /* Return the body of GIMPLE statements for function FN. After the
1917 CFG pass, the function body doesn't exist anymore because it has
1918 been split up into basic blocks. In this case, it returns
1922 gimple_body (tree fndecl)
1924 struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
1925 return fn ? fn->gimple_body : NULL;
1928 /* Return true when FNDECL has Gimple body either in unlowered
1931 gimple_has_body_p (tree fndecl)
1933 struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
1934 return (gimple_body (fndecl) || (fn && fn->cfg));
1937 /* Return true if calls C1 and C2 are known to go to the same function. */
1940 gimple_call_same_target_p (const_gimple c1, const_gimple c2)
1942 if (gimple_call_internal_p (c1))
1943 return (gimple_call_internal_p (c2)
1944 && gimple_call_internal_fn (c1) == gimple_call_internal_fn (c2));
1946 return (gimple_call_fn (c1) == gimple_call_fn (c2)
1947 || (gimple_call_fndecl (c1)
1948 && gimple_call_fndecl (c1) == gimple_call_fndecl (c2)));
1951 /* Detect flags from a GIMPLE_CALL. This is just like
1952 call_expr_flags, but for gimple tuples. */
1955 gimple_call_flags (const_gimple stmt)
1958 tree decl = gimple_call_fndecl (stmt);
1961 flags = flags_from_decl_or_type (decl);
1962 else if (gimple_call_internal_p (stmt))
1963 flags = internal_fn_flags (gimple_call_internal_fn (stmt));
1965 flags = flags_from_decl_or_type (gimple_call_fntype (stmt));
1967 if (stmt->gsbase.subcode & GF_CALL_NOTHROW)
1968 flags |= ECF_NOTHROW;
1973 /* Return the "fn spec" string for call STMT. */
1976 gimple_call_fnspec (const_gimple stmt)
1980 type = gimple_call_fntype (stmt);
1984 attr = lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type));
1988 return TREE_VALUE (TREE_VALUE (attr));
1991 /* Detects argument flags for argument number ARG on call STMT. */
1994 gimple_call_arg_flags (const_gimple stmt, unsigned arg)
1996 tree attr = gimple_call_fnspec (stmt);
1998 if (!attr || 1 + arg >= (unsigned) TREE_STRING_LENGTH (attr))
2001 switch (TREE_STRING_POINTER (attr)[1 + arg])
2008 return EAF_DIRECT | EAF_NOCLOBBER | EAF_NOESCAPE;
2011 return EAF_NOCLOBBER | EAF_NOESCAPE;
2014 return EAF_DIRECT | EAF_NOESCAPE;
2017 return EAF_NOESCAPE;
2025 /* Detects return flags for the call STMT. */
2028 gimple_call_return_flags (const_gimple stmt)
2032 if (gimple_call_flags (stmt) & ECF_MALLOC)
2035 attr = gimple_call_fnspec (stmt);
2036 if (!attr || TREE_STRING_LENGTH (attr) < 1)
2039 switch (TREE_STRING_POINTER (attr)[0])
2045 return ERF_RETURNS_ARG | (TREE_STRING_POINTER (attr)[0] - '1');
2057 /* Return true if GS is a copy assignment. */
2060 gimple_assign_copy_p (gimple gs)
2062 return (gimple_assign_single_p (gs)
2063 && is_gimple_val (gimple_op (gs, 1)));
2067 /* Return true if GS is a SSA_NAME copy assignment. */
2070 gimple_assign_ssa_name_copy_p (gimple gs)
2072 return (gimple_assign_single_p (gs)
2073 && TREE_CODE (gimple_assign_lhs (gs)) == SSA_NAME
2074 && TREE_CODE (gimple_assign_rhs1 (gs)) == SSA_NAME);
2078 /* Return true if GS is an assignment with a unary RHS, but the
2079 operator has no effect on the assigned value. The logic is adapted
2080 from STRIP_NOPS. This predicate is intended to be used in tuplifying
2081 instances in which STRIP_NOPS was previously applied to the RHS of
2084 NOTE: In the use cases that led to the creation of this function
2085 and of gimple_assign_single_p, it is typical to test for either
2086 condition and to proceed in the same manner. In each case, the
2087 assigned value is represented by the single RHS operand of the
2088 assignment. I suspect there may be cases where gimple_assign_copy_p,
2089 gimple_assign_single_p, or equivalent logic is used where a similar
2090 treatment of unary NOPs is appropriate. */
2093 gimple_assign_unary_nop_p (gimple gs)
2095 return (is_gimple_assign (gs)
2096 && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs))
2097 || gimple_assign_rhs_code (gs) == NON_LVALUE_EXPR)
2098 && gimple_assign_rhs1 (gs) != error_mark_node
2099 && (TYPE_MODE (TREE_TYPE (gimple_assign_lhs (gs)))
2100 == TYPE_MODE (TREE_TYPE (gimple_assign_rhs1 (gs)))));
2103 /* Set BB to be the basic block holding G. */
2106 gimple_set_bb (gimple stmt, basic_block bb)
2108 stmt->gsbase.bb = bb;
2110 /* If the statement is a label, add the label to block-to-labels map
2111 so that we can speed up edge creation for GIMPLE_GOTOs. */
2112 if (cfun->cfg && gimple_code (stmt) == GIMPLE_LABEL)
2117 t = gimple_label_label (stmt);
2118 uid = LABEL_DECL_UID (t);
2121 unsigned old_len = VEC_length (basic_block, label_to_block_map);
2122 LABEL_DECL_UID (t) = uid = cfun->cfg->last_label_uid++;
2123 if (old_len <= (unsigned) uid)
2125 unsigned new_len = 3 * uid / 2 + 1;
2127 VEC_safe_grow_cleared (basic_block, gc, label_to_block_map,
2132 VEC_replace (basic_block, label_to_block_map, uid, bb);
2137 /* Modify the RHS of the assignment pointed-to by GSI using the
2138 operands in the expression tree EXPR.
2140 NOTE: The statement pointed-to by GSI may be reallocated if it
2141 did not have enough operand slots.
2143 This function is useful to convert an existing tree expression into
2144 the flat representation used for the RHS of a GIMPLE assignment.
2145 It will reallocate memory as needed to expand or shrink the number
2146 of operand slots needed to represent EXPR.
2148 NOTE: If you find yourself building a tree and then calling this
2149 function, you are most certainly doing it the slow way. It is much
2150 better to build a new assignment or to use the function
2151 gimple_assign_set_rhs_with_ops, which does not require an
2152 expression tree to be built. */
2155 gimple_assign_set_rhs_from_tree (gimple_stmt_iterator *gsi, tree expr)
2157 enum tree_code subcode;
2160 extract_ops_from_tree_1 (expr, &subcode, &op1, &op2, &op3);
2161 gimple_assign_set_rhs_with_ops_1 (gsi, subcode, op1, op2, op3);
2165 /* Set the RHS of assignment statement pointed-to by GSI to CODE with
2166 operands OP1, OP2 and OP3.
2168 NOTE: The statement pointed-to by GSI may be reallocated if it
2169 did not have enough operand slots. */
2172 gimple_assign_set_rhs_with_ops_1 (gimple_stmt_iterator *gsi, enum tree_code code,
2173 tree op1, tree op2, tree op3)
2175 unsigned new_rhs_ops = get_gimple_rhs_num_ops (code);
2176 gimple stmt = gsi_stmt (*gsi);
2178 /* If the new CODE needs more operands, allocate a new statement. */
2179 if (gimple_num_ops (stmt) < new_rhs_ops + 1)
2181 tree lhs = gimple_assign_lhs (stmt);
2182 gimple new_stmt = gimple_alloc (gimple_code (stmt), new_rhs_ops + 1);
2183 memcpy (new_stmt, stmt, gimple_size (gimple_code (stmt)));
2184 gsi_replace (gsi, new_stmt, true);
2187 /* The LHS needs to be reset as this also changes the SSA name
2189 gimple_assign_set_lhs (stmt, lhs);
2192 gimple_set_num_ops (stmt, new_rhs_ops + 1);
2193 gimple_set_subcode (stmt, code);
2194 gimple_assign_set_rhs1 (stmt, op1);
2195 if (new_rhs_ops > 1)
2196 gimple_assign_set_rhs2 (stmt, op2);
2197 if (new_rhs_ops > 2)
2198 gimple_assign_set_rhs3 (stmt, op3);
2202 /* Return the LHS of a statement that performs an assignment,
2203 either a GIMPLE_ASSIGN or a GIMPLE_CALL. Returns NULL_TREE
2204 for a call to a function that returns no value, or for a
2205 statement other than an assignment or a call. */
2208 gimple_get_lhs (const_gimple stmt)
2210 enum gimple_code code = gimple_code (stmt);
2212 if (code == GIMPLE_ASSIGN)
2213 return gimple_assign_lhs (stmt);
2214 else if (code == GIMPLE_CALL)
2215 return gimple_call_lhs (stmt);
2221 /* Set the LHS of a statement that performs an assignment,
2222 either a GIMPLE_ASSIGN or a GIMPLE_CALL. */
2225 gimple_set_lhs (gimple stmt, tree lhs)
2227 enum gimple_code code = gimple_code (stmt);
2229 if (code == GIMPLE_ASSIGN)
2230 gimple_assign_set_lhs (stmt, lhs);
2231 else if (code == GIMPLE_CALL)
2232 gimple_call_set_lhs (stmt, lhs);
2237 /* Replace the LHS of STMT, an assignment, either a GIMPLE_ASSIGN or a
2238 GIMPLE_CALL, with NLHS, in preparation for modifying the RHS to an
2239 expression with a different value.
2241 This will update any annotations (say debug bind stmts) referring
2242 to the original LHS, so that they use the RHS instead. This is
2243 done even if NLHS and LHS are the same, for it is understood that
2244 the RHS will be modified afterwards, and NLHS will not be assigned
2245 an equivalent value.
2247 Adjusting any non-annotation uses of the LHS, if needed, is a
2248 responsibility of the caller.
2250 The effect of this call should be pretty much the same as that of
2251 inserting a copy of STMT before STMT, and then removing the
2252 original stmt, at which time gsi_remove() would have update
2253 annotations, but using this function saves all the inserting,
2254 copying and removing. */
2257 gimple_replace_lhs (gimple stmt, tree nlhs)
2259 if (MAY_HAVE_DEBUG_STMTS)
2261 tree lhs = gimple_get_lhs (stmt);
2263 gcc_assert (SSA_NAME_DEF_STMT (lhs) == stmt);
2265 insert_debug_temp_for_var_def (NULL, lhs);
2268 gimple_set_lhs (stmt, nlhs);
2271 /* Return a deep copy of statement STMT. All the operands from STMT
2272 are reallocated and copied using unshare_expr. The DEF, USE, VDEF
2273 and VUSE operand arrays are set to empty in the new copy. */
2276 gimple_copy (gimple stmt)
2278 enum gimple_code code = gimple_code (stmt);
2279 unsigned num_ops = gimple_num_ops (stmt);
2280 gimple copy = gimple_alloc (code, num_ops);
2283 /* Shallow copy all the fields from STMT. */
2284 memcpy (copy, stmt, gimple_size (code));
2286 /* If STMT has sub-statements, deep-copy them as well. */
2287 if (gimple_has_substatements (stmt))
2292 switch (gimple_code (stmt))
2295 new_seq = gimple_seq_copy (gimple_bind_body (stmt));
2296 gimple_bind_set_body (copy, new_seq);
2297 gimple_bind_set_vars (copy, unshare_expr (gimple_bind_vars (stmt)));
2298 gimple_bind_set_block (copy, gimple_bind_block (stmt));
2302 new_seq = gimple_seq_copy (gimple_catch_handler (stmt));
2303 gimple_catch_set_handler (copy, new_seq);
2304 t = unshare_expr (gimple_catch_types (stmt));
2305 gimple_catch_set_types (copy, t);
2308 case GIMPLE_EH_FILTER:
2309 new_seq = gimple_seq_copy (gimple_eh_filter_failure (stmt));
2310 gimple_eh_filter_set_failure (copy, new_seq);
2311 t = unshare_expr (gimple_eh_filter_types (stmt));
2312 gimple_eh_filter_set_types (copy, t);
2315 case GIMPLE_EH_ELSE:
2316 new_seq = gimple_seq_copy (gimple_eh_else_n_body (stmt));
2317 gimple_eh_else_set_n_body (copy, new_seq);
2318 new_seq = gimple_seq_copy (gimple_eh_else_e_body (stmt));
2319 gimple_eh_else_set_e_body (copy, new_seq);
2323 new_seq = gimple_seq_copy (gimple_try_eval (stmt));
2324 gimple_try_set_eval (copy, new_seq);
2325 new_seq = gimple_seq_copy (gimple_try_cleanup (stmt));
2326 gimple_try_set_cleanup (copy, new_seq);
2329 case GIMPLE_OMP_FOR:
2330 new_seq = gimple_seq_copy (gimple_omp_for_pre_body (stmt));
2331 gimple_omp_for_set_pre_body (copy, new_seq);
2332 t = unshare_expr (gimple_omp_for_clauses (stmt));
2333 gimple_omp_for_set_clauses (copy, t);
2334 copy->gimple_omp_for.iter
2335 = ggc_alloc_vec_gimple_omp_for_iter
2336 (gimple_omp_for_collapse (stmt));
2337 for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
2339 gimple_omp_for_set_cond (copy, i,
2340 gimple_omp_for_cond (stmt, i));
2341 gimple_omp_for_set_index (copy, i,
2342 gimple_omp_for_index (stmt, i));
2343 t = unshare_expr (gimple_omp_for_initial (stmt, i));
2344 gimple_omp_for_set_initial (copy, i, t);
2345 t = unshare_expr (gimple_omp_for_final (stmt, i));
2346 gimple_omp_for_set_final (copy, i, t);
2347 t = unshare_expr (gimple_omp_for_incr (stmt, i));
2348 gimple_omp_for_set_incr (copy, i, t);
2352 case GIMPLE_OMP_PARALLEL:
2353 t = unshare_expr (gimple_omp_parallel_clauses (stmt));
2354 gimple_omp_parallel_set_clauses (copy, t);
2355 t = unshare_expr (gimple_omp_parallel_child_fn (stmt));
2356 gimple_omp_parallel_set_child_fn (copy, t);
2357 t = unshare_expr (gimple_omp_parallel_data_arg (stmt));
2358 gimple_omp_parallel_set_data_arg (copy, t);
2361 case GIMPLE_OMP_TASK:
2362 t = unshare_expr (gimple_omp_task_clauses (stmt));
2363 gimple_omp_task_set_clauses (copy, t);
2364 t = unshare_expr (gimple_omp_task_child_fn (stmt));
2365 gimple_omp_task_set_child_fn (copy, t);
2366 t = unshare_expr (gimple_omp_task_data_arg (stmt));
2367 gimple_omp_task_set_data_arg (copy, t);
2368 t = unshare_expr (gimple_omp_task_copy_fn (stmt));
2369 gimple_omp_task_set_copy_fn (copy, t);
2370 t = unshare_expr (gimple_omp_task_arg_size (stmt));
2371 gimple_omp_task_set_arg_size (copy, t);
2372 t = unshare_expr (gimple_omp_task_arg_align (stmt));
2373 gimple_omp_task_set_arg_align (copy, t);
2376 case GIMPLE_OMP_CRITICAL:
2377 t = unshare_expr (gimple_omp_critical_name (stmt));
2378 gimple_omp_critical_set_name (copy, t);
2381 case GIMPLE_OMP_SECTIONS:
2382 t = unshare_expr (gimple_omp_sections_clauses (stmt));
2383 gimple_omp_sections_set_clauses (copy, t);
2384 t = unshare_expr (gimple_omp_sections_control (stmt));
2385 gimple_omp_sections_set_control (copy, t);
2388 case GIMPLE_OMP_SINGLE:
2389 case GIMPLE_OMP_SECTION:
2390 case GIMPLE_OMP_MASTER:
2391 case GIMPLE_OMP_ORDERED:
2393 new_seq = gimple_seq_copy (gimple_omp_body (stmt));
2394 gimple_omp_set_body (copy, new_seq);
2397 case GIMPLE_TRANSACTION:
2398 new_seq = gimple_seq_copy (gimple_transaction_body (stmt));
2399 gimple_transaction_set_body (copy, new_seq);
2402 case GIMPLE_WITH_CLEANUP_EXPR:
2403 new_seq = gimple_seq_copy (gimple_wce_cleanup (stmt));
2404 gimple_wce_set_cleanup (copy, new_seq);
2412 /* Make copy of operands. */
2415 for (i = 0; i < num_ops; i++)
2416 gimple_set_op (copy, i, unshare_expr (gimple_op (stmt, i)));
2418 /* Clear out SSA operand vectors on COPY. */
2419 if (gimple_has_ops (stmt))
2421 gimple_set_def_ops (copy, NULL);
2422 gimple_set_use_ops (copy, NULL);
2425 if (gimple_has_mem_ops (stmt))
2427 gimple_set_vdef (copy, gimple_vdef (stmt));
2428 gimple_set_vuse (copy, gimple_vuse (stmt));
2431 /* SSA operands need to be updated. */
2432 gimple_set_modified (copy, true);
2439 /* Set the MODIFIED flag to MODIFIEDP, iff the gimple statement G has
2440 a MODIFIED field. */
2443 gimple_set_modified (gimple s, bool modifiedp)
2445 if (gimple_has_ops (s))
2446 s->gsbase.modified = (unsigned) modifiedp;
2450 /* Return true if statement S has side-effects. We consider a
2451 statement to have side effects if:
2453 - It is a GIMPLE_CALL not marked with ECF_PURE or ECF_CONST.
2454 - Any of its operands are marked TREE_THIS_VOLATILE or TREE_SIDE_EFFECTS. */
2457 gimple_has_side_effects (const_gimple s)
2459 if (is_gimple_debug (s))
2462 /* We don't have to scan the arguments to check for
2463 volatile arguments, though, at present, we still
2464 do a scan to check for TREE_SIDE_EFFECTS. */
2465 if (gimple_has_volatile_ops (s))
2468 if (gimple_code (s) == GIMPLE_ASM
2469 && gimple_asm_volatile_p (s))
2472 if (is_gimple_call (s))
2474 int flags = gimple_call_flags (s);
2476 /* An infinite loop is considered a side effect. */
2477 if (!(flags & (ECF_CONST | ECF_PURE))
2478 || (flags & ECF_LOOPING_CONST_OR_PURE))
2487 /* Helper for gimple_could_trap_p and gimple_assign_rhs_could_trap_p.
2488 Return true if S can trap. When INCLUDE_MEM is true, check whether
2489 the memory operations could trap. When INCLUDE_STORES is true and
2490 S is a GIMPLE_ASSIGN, the LHS of the assignment is also checked. */
2493 gimple_could_trap_p_1 (gimple s, bool include_mem, bool include_stores)
2495 tree t, div = NULL_TREE;
2500 unsigned i, start = (is_gimple_assign (s) && !include_stores) ? 1 : 0;
2502 for (i = start; i < gimple_num_ops (s); i++)
2503 if (tree_could_trap_p (gimple_op (s, i)))
2507 switch (gimple_code (s))
2510 return gimple_asm_volatile_p (s);
2513 t = gimple_call_fndecl (s);
2514 /* Assume that calls to weak functions may trap. */
2515 if (!t || !DECL_P (t) || DECL_WEAK (t))
2520 t = gimple_expr_type (s);
2521 op = gimple_assign_rhs_code (s);
2522 if (get_gimple_rhs_class (op) == GIMPLE_BINARY_RHS)
2523 div = gimple_assign_rhs2 (s);
2524 return (operation_could_trap_p (op, FLOAT_TYPE_P (t),
2525 (INTEGRAL_TYPE_P (t)
2526 && TYPE_OVERFLOW_TRAPS (t)),
2536 /* Return true if statement S can trap. */
2539 gimple_could_trap_p (gimple s)
2541 return gimple_could_trap_p_1 (s, true, true);
2544 /* Return true if RHS of a GIMPLE_ASSIGN S can trap. */
2547 gimple_assign_rhs_could_trap_p (gimple s)
2549 gcc_assert (is_gimple_assign (s));
2550 return gimple_could_trap_p_1 (s, true, false);
2554 /* Print debugging information for gimple stmts generated. */
2557 dump_gimple_statistics (void)
2559 #ifdef GATHER_STATISTICS
2560 int i, total_tuples = 0, total_bytes = 0;
2562 fprintf (stderr, "\nGIMPLE statements\n");
2563 fprintf (stderr, "Kind Stmts Bytes\n");
2564 fprintf (stderr, "---------------------------------------\n");
2565 for (i = 0; i < (int) gimple_alloc_kind_all; ++i)
2567 fprintf (stderr, "%-20s %7d %10d\n", gimple_alloc_kind_names[i],
2568 gimple_alloc_counts[i], gimple_alloc_sizes[i]);
2569 total_tuples += gimple_alloc_counts[i];
2570 total_bytes += gimple_alloc_sizes[i];
2572 fprintf (stderr, "---------------------------------------\n");
2573 fprintf (stderr, "%-20s %7d %10d\n", "Total", total_tuples, total_bytes);
2574 fprintf (stderr, "---------------------------------------\n");
2576 fprintf (stderr, "No gimple statistics\n");
2581 /* Return the number of operands needed on the RHS of a GIMPLE
2582 assignment for an expression with tree code CODE. */
2585 get_gimple_rhs_num_ops (enum tree_code code)
2587 enum gimple_rhs_class rhs_class = get_gimple_rhs_class (code);
2589 if (rhs_class == GIMPLE_UNARY_RHS || rhs_class == GIMPLE_SINGLE_RHS)
2591 else if (rhs_class == GIMPLE_BINARY_RHS)
2593 else if (rhs_class == GIMPLE_TERNARY_RHS)
2599 #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \
2601 ((TYPE) == tcc_unary ? GIMPLE_UNARY_RHS \
2602 : ((TYPE) == tcc_binary \
2603 || (TYPE) == tcc_comparison) ? GIMPLE_BINARY_RHS \
2604 : ((TYPE) == tcc_constant \
2605 || (TYPE) == tcc_declaration \
2606 || (TYPE) == tcc_reference) ? GIMPLE_SINGLE_RHS \
2607 : ((SYM) == TRUTH_AND_EXPR \
2608 || (SYM) == TRUTH_OR_EXPR \
2609 || (SYM) == TRUTH_XOR_EXPR) ? GIMPLE_BINARY_RHS \
2610 : (SYM) == TRUTH_NOT_EXPR ? GIMPLE_UNARY_RHS \
2611 : ((SYM) == COND_EXPR \
2612 || (SYM) == WIDEN_MULT_PLUS_EXPR \
2613 || (SYM) == WIDEN_MULT_MINUS_EXPR \
2614 || (SYM) == DOT_PROD_EXPR \
2615 || (SYM) == REALIGN_LOAD_EXPR \
2616 || (SYM) == VEC_COND_EXPR \
2617 || (SYM) == VEC_PERM_EXPR \
2618 || (SYM) == FMA_EXPR) ? GIMPLE_TERNARY_RHS \
2619 : ((SYM) == CONSTRUCTOR \
2620 || (SYM) == OBJ_TYPE_REF \
2621 || (SYM) == ASSERT_EXPR \
2622 || (SYM) == ADDR_EXPR \
2623 || (SYM) == WITH_SIZE_EXPR \
2624 || (SYM) == SSA_NAME) ? GIMPLE_SINGLE_RHS \
2625 : GIMPLE_INVALID_RHS),
2626 #define END_OF_BASE_TREE_CODES (unsigned char) GIMPLE_INVALID_RHS,
2628 const unsigned char gimple_rhs_class_table[] = {
2629 #include "all-tree.def"
2633 #undef END_OF_BASE_TREE_CODES
2635 /* For the definitive definition of GIMPLE, see doc/tree-ssa.texi. */
2637 /* Validation of GIMPLE expressions. */
2639 /* Return true if T is a valid LHS for a GIMPLE assignment expression. */
2642 is_gimple_lvalue (tree t)
2644 return (is_gimple_addressable (t)
2645 || TREE_CODE (t) == WITH_SIZE_EXPR
2646 /* These are complex lvalues, but don't have addresses, so they
2648 || TREE_CODE (t) == BIT_FIELD_REF);
2651 /* Return true if T is a GIMPLE condition. */
2654 is_gimple_condexpr (tree t)
2656 return (is_gimple_val (t) || (COMPARISON_CLASS_P (t)
2657 && !tree_could_throw_p (t)
2658 && is_gimple_val (TREE_OPERAND (t, 0))
2659 && is_gimple_val (TREE_OPERAND (t, 1))));
2662 /* Return true if T is something whose address can be taken. */
2665 is_gimple_addressable (tree t)
2667 return (is_gimple_id (t) || handled_component_p (t)
2668 || TREE_CODE (t) == MEM_REF);
2671 /* Return true if T is a valid gimple constant. */
2674 is_gimple_constant (const_tree t)
2676 switch (TREE_CODE (t))
2686 /* Vector constant constructors are gimple invariant. */
2688 if (TREE_TYPE (t) && TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE)
2689 return TREE_CONSTANT (t);
2698 /* Return true if T is a gimple address. */
2701 is_gimple_address (const_tree t)
2705 if (TREE_CODE (t) != ADDR_EXPR)
2708 op = TREE_OPERAND (t, 0);
2709 while (handled_component_p (op))
2711 if ((TREE_CODE (op) == ARRAY_REF
2712 || TREE_CODE (op) == ARRAY_RANGE_REF)
2713 && !is_gimple_val (TREE_OPERAND (op, 1)))
2716 op = TREE_OPERAND (op, 0);
2719 if (CONSTANT_CLASS_P (op) || TREE_CODE (op) == MEM_REF)
2722 switch (TREE_CODE (op))
2737 /* Return true if T is a gimple invariant address. */
2740 is_gimple_invariant_address (const_tree t)
2744 if (TREE_CODE (t) != ADDR_EXPR)
2747 op = strip_invariant_refs (TREE_OPERAND (t, 0));
2751 if (TREE_CODE (op) == MEM_REF)
2753 const_tree op0 = TREE_OPERAND (op, 0);
2754 return (TREE_CODE (op0) == ADDR_EXPR
2755 && (CONSTANT_CLASS_P (TREE_OPERAND (op0, 0))
2756 || decl_address_invariant_p (TREE_OPERAND (op0, 0))));
2759 return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op);
2762 /* Return true if T is a gimple invariant address at IPA level
2763 (so addresses of variables on stack are not allowed). */
2766 is_gimple_ip_invariant_address (const_tree t)
2770 if (TREE_CODE (t) != ADDR_EXPR)
2773 op = strip_invariant_refs (TREE_OPERAND (t, 0));
2777 if (TREE_CODE (op) == MEM_REF)
2779 const_tree op0 = TREE_OPERAND (op, 0);
2780 return (TREE_CODE (op0) == ADDR_EXPR
2781 && (CONSTANT_CLASS_P (TREE_OPERAND (op0, 0))
2782 || decl_address_ip_invariant_p (TREE_OPERAND (op0, 0))));
2785 return CONSTANT_CLASS_P (op) || decl_address_ip_invariant_p (op);
2788 /* Return true if T is a GIMPLE minimal invariant. It's a restricted
2789 form of function invariant. */
2792 is_gimple_min_invariant (const_tree t)
2794 if (TREE_CODE (t) == ADDR_EXPR)
2795 return is_gimple_invariant_address (t);
2797 return is_gimple_constant (t);
2800 /* Return true if T is a GIMPLE interprocedural invariant. It's a restricted
2801 form of gimple minimal invariant. */
2804 is_gimple_ip_invariant (const_tree t)
2806 if (TREE_CODE (t) == ADDR_EXPR)
2807 return is_gimple_ip_invariant_address (t);
2809 return is_gimple_constant (t);
2812 /* Return true if T is a variable. */
2815 is_gimple_variable (tree t)
2817 return (TREE_CODE (t) == VAR_DECL
2818 || TREE_CODE (t) == PARM_DECL
2819 || TREE_CODE (t) == RESULT_DECL
2820 || TREE_CODE (t) == SSA_NAME);
2823 /* Return true if T is a GIMPLE identifier (something with an address). */
2826 is_gimple_id (tree t)
2828 return (is_gimple_variable (t)
2829 || TREE_CODE (t) == FUNCTION_DECL
2830 || TREE_CODE (t) == LABEL_DECL
2831 || TREE_CODE (t) == CONST_DECL
2832 /* Allow string constants, since they are addressable. */
2833 || TREE_CODE (t) == STRING_CST);
2836 /* Return true if T is a non-aggregate register variable. */
2839 is_gimple_reg (tree t)
2841 if (TREE_CODE (t) == SSA_NAME)
2842 t = SSA_NAME_VAR (t);
2844 if (!is_gimple_variable (t))
2847 if (!is_gimple_reg_type (TREE_TYPE (t)))
2850 /* A volatile decl is not acceptable because we can't reuse it as
2851 needed. We need to copy it into a temp first. */
2852 if (TREE_THIS_VOLATILE (t))
2855 /* We define "registers" as things that can be renamed as needed,
2856 which with our infrastructure does not apply to memory. */
2857 if (needs_to_live_in_memory (t))
2860 /* Hard register variables are an interesting case. For those that
2861 are call-clobbered, we don't know where all the calls are, since
2862 we don't (want to) take into account which operations will turn
2863 into libcalls at the rtl level. For those that are call-saved,
2864 we don't currently model the fact that calls may in fact change
2865 global hard registers, nor do we examine ASM_CLOBBERS at the tree
2866 level, and so miss variable changes that might imply. All around,
2867 it seems safest to not do too much optimization with these at the
2868 tree level at all. We'll have to rely on the rtl optimizers to
2869 clean this up, as there we've got all the appropriate bits exposed. */
2870 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t))
2873 /* Complex and vector values must have been put into SSA-like form.
2874 That is, no assignments to the individual components. */
2875 if (TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE
2876 || TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE)
2877 return DECL_GIMPLE_REG_P (t);
2883 /* Return true if T is a GIMPLE rvalue, i.e. an identifier or a constant. */
2886 is_gimple_val (tree t)
2888 /* Make loads from volatiles and memory vars explicit. */
2889 if (is_gimple_variable (t)
2890 && is_gimple_reg_type (TREE_TYPE (t))
2891 && !is_gimple_reg (t))
2894 return (is_gimple_variable (t) || is_gimple_min_invariant (t));
2897 /* Similarly, but accept hard registers as inputs to asm statements. */
2900 is_gimple_asm_val (tree t)
2902 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t))
2905 return is_gimple_val (t);
2908 /* Return true if T is a GIMPLE minimal lvalue. */
2911 is_gimple_min_lval (tree t)
2913 if (!(t = CONST_CAST_TREE (strip_invariant_refs (t))))
2915 return (is_gimple_id (t) || TREE_CODE (t) == MEM_REF);
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 /* Return true if T is a valid address operand of a MEM_REF. */
2929 is_gimple_mem_ref_addr (tree t)
2931 return (is_gimple_reg (t)
2932 || TREE_CODE (t) == INTEGER_CST
2933 || (TREE_CODE (t) == ADDR_EXPR
2934 && (CONSTANT_CLASS_P (TREE_OPERAND (t, 0))
2935 || decl_address_invariant_p (TREE_OPERAND (t, 0)))));
2939 /* Given a memory reference expression T, return its base address.
2940 The base address of a memory reference expression is the main
2941 object being referenced. For instance, the base address for
2942 'array[i].fld[j]' is 'array'. You can think of this as stripping
2943 away the offset part from a memory address.
2945 This function calls handled_component_p to strip away all the inner
2946 parts of the memory reference until it reaches the base object. */
2949 get_base_address (tree t)
2951 while (handled_component_p (t))
2952 t = TREE_OPERAND (t, 0);
2954 if ((TREE_CODE (t) == MEM_REF
2955 || TREE_CODE (t) == TARGET_MEM_REF)
2956 && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
2957 t = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
2959 if (TREE_CODE (t) == SSA_NAME
2961 || TREE_CODE (t) == STRING_CST
2962 || TREE_CODE (t) == CONSTRUCTOR
2963 || INDIRECT_REF_P (t)
2964 || TREE_CODE (t) == MEM_REF
2965 || TREE_CODE (t) == TARGET_MEM_REF)
2972 recalculate_side_effects (tree t)
2974 enum tree_code code = TREE_CODE (t);
2975 int len = TREE_OPERAND_LENGTH (t);
2978 switch (TREE_CODE_CLASS (code))
2980 case tcc_expression:
2986 case PREDECREMENT_EXPR:
2987 case PREINCREMENT_EXPR:
2988 case POSTDECREMENT_EXPR:
2989 case POSTINCREMENT_EXPR:
2990 /* All of these have side-effects, no matter what their
2999 case tcc_comparison: /* a comparison expression */
3000 case tcc_unary: /* a unary arithmetic expression */
3001 case tcc_binary: /* a binary arithmetic expression */
3002 case tcc_reference: /* a reference */
3003 case tcc_vl_exp: /* a function call */
3004 TREE_SIDE_EFFECTS (t) = TREE_THIS_VOLATILE (t);
3005 for (i = 0; i < len; ++i)
3007 tree op = TREE_OPERAND (t, i);
3008 if (op && TREE_SIDE_EFFECTS (op))
3009 TREE_SIDE_EFFECTS (t) = 1;
3014 /* No side-effects. */
3022 /* Canonicalize a tree T for use in a COND_EXPR as conditional. Returns
3023 a canonicalized tree that is valid for a COND_EXPR or NULL_TREE, if
3024 we failed to create one. */
3027 canonicalize_cond_expr_cond (tree t)
3029 /* Strip conversions around boolean operations. */
3030 if (CONVERT_EXPR_P (t)
3031 && (truth_value_p (TREE_CODE (TREE_OPERAND (t, 0)))
3032 || TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0)))
3034 t = TREE_OPERAND (t, 0);
3036 /* For !x use x == 0. */
3037 if (TREE_CODE (t) == TRUTH_NOT_EXPR)
3039 tree top0 = TREE_OPERAND (t, 0);
3040 t = build2 (EQ_EXPR, TREE_TYPE (t),
3041 top0, build_int_cst (TREE_TYPE (top0), 0));
3043 /* For cmp ? 1 : 0 use cmp. */
3044 else if (TREE_CODE (t) == COND_EXPR
3045 && COMPARISON_CLASS_P (TREE_OPERAND (t, 0))
3046 && integer_onep (TREE_OPERAND (t, 1))
3047 && integer_zerop (TREE_OPERAND (t, 2)))
3049 tree top0 = TREE_OPERAND (t, 0);
3050 t = build2 (TREE_CODE (top0), TREE_TYPE (t),
3051 TREE_OPERAND (top0, 0), TREE_OPERAND (top0, 1));
3054 if (is_gimple_condexpr (t))
3060 /* Build a GIMPLE_CALL identical to STMT but skipping the arguments in
3061 the positions marked by the set ARGS_TO_SKIP. */
3064 gimple_call_copy_skip_args (gimple stmt, bitmap args_to_skip)
3067 int nargs = gimple_call_num_args (stmt);
3068 VEC(tree, heap) *vargs = VEC_alloc (tree, heap, nargs);
3071 for (i = 0; i < nargs; i++)
3072 if (!bitmap_bit_p (args_to_skip, i))
3073 VEC_quick_push (tree, vargs, gimple_call_arg (stmt, i));
3075 if (gimple_call_internal_p (stmt))
3076 new_stmt = gimple_build_call_internal_vec (gimple_call_internal_fn (stmt),
3079 new_stmt = gimple_build_call_vec (gimple_call_fn (stmt), vargs);
3080 VEC_free (tree, heap, vargs);
3081 if (gimple_call_lhs (stmt))
3082 gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt));
3084 gimple_set_vuse (new_stmt, gimple_vuse (stmt));
3085 gimple_set_vdef (new_stmt, gimple_vdef (stmt));
3087 gimple_set_block (new_stmt, gimple_block (stmt));
3088 if (gimple_has_location (stmt))
3089 gimple_set_location (new_stmt, gimple_location (stmt));
3090 gimple_call_copy_flags (new_stmt, stmt);
3091 gimple_call_set_chain (new_stmt, gimple_call_chain (stmt));
3093 gimple_set_modified (new_stmt, true);
3099 enum gtc_mode { GTC_MERGE = 0, GTC_DIAG = 1 };
3101 static hashval_t gimple_type_hash (const void *);
3103 /* Structure used to maintain a cache of some type pairs compared by
3104 gimple_types_compatible_p when comparing aggregate types. There are
3105 three possible values for SAME_P:
3107 -2: The pair (T1, T2) has just been inserted in the table.
3108 0: T1 and T2 are different types.
3109 1: T1 and T2 are the same type.
3111 The two elements in the SAME_P array are indexed by the comparison
3118 signed char same_p[2];
3120 typedef struct type_pair_d *type_pair_t;
3121 DEF_VEC_P(type_pair_t);
3122 DEF_VEC_ALLOC_P(type_pair_t,heap);
3124 #define GIMPLE_TYPE_PAIR_SIZE 16381
3125 struct type_pair_d *type_pair_cache;
3128 /* Lookup the pair of types T1 and T2 in *VISITED_P. Insert a new
3129 entry if none existed. */
3131 static inline type_pair_t
3132 lookup_type_pair (tree t1, tree t2)
3135 unsigned int uid1, uid2;
3137 if (type_pair_cache == NULL)
3138 type_pair_cache = XCNEWVEC (struct type_pair_d, GIMPLE_TYPE_PAIR_SIZE);
3140 if (TYPE_UID (t1) < TYPE_UID (t2))
3142 uid1 = TYPE_UID (t1);
3143 uid2 = TYPE_UID (t2);
3147 uid1 = TYPE_UID (t2);
3148 uid2 = TYPE_UID (t1);
3150 gcc_checking_assert (uid1 != uid2);
3152 /* iterative_hash_hashval_t imply an function calls.
3153 We know that UIDS are in limited range. */
3154 index = ((((unsigned HOST_WIDE_INT)uid1 << HOST_BITS_PER_WIDE_INT / 2) + uid2)
3155 % GIMPLE_TYPE_PAIR_SIZE);
3156 if (type_pair_cache [index].uid1 == uid1
3157 && type_pair_cache [index].uid2 == uid2)
3158 return &type_pair_cache[index];
3160 type_pair_cache [index].uid1 = uid1;
3161 type_pair_cache [index].uid2 = uid2;
3162 type_pair_cache [index].same_p[0] = -2;
3163 type_pair_cache [index].same_p[1] = -2;
3165 return &type_pair_cache[index];
3168 /* Per pointer state for the SCC finding. The on_sccstack flag
3169 is not strictly required, it is true when there is no hash value
3170 recorded for the type and false otherwise. But querying that
3175 unsigned int dfsnum;
3184 static unsigned int next_dfs_num;
3185 static unsigned int gtc_next_dfs_num;
3188 /* GIMPLE type merging cache. A direct-mapped cache based on TYPE_UID. */
3190 typedef struct GTY(()) gimple_type_leader_entry_s {
3193 } gimple_type_leader_entry;
3195 #define GIMPLE_TYPE_LEADER_SIZE 16381
3196 static GTY((deletable, length("GIMPLE_TYPE_LEADER_SIZE")))
3197 gimple_type_leader_entry *gimple_type_leader;
3199 /* Lookup an existing leader for T and return it or NULL_TREE, if
3200 there is none in the cache. */
3203 gimple_lookup_type_leader (tree t)
3205 gimple_type_leader_entry *leader;
3207 if (!gimple_type_leader)
3210 leader = &gimple_type_leader[TYPE_UID (t) % GIMPLE_TYPE_LEADER_SIZE];
3211 if (leader->type != t)
3214 return leader->leader;
3217 /* Return true if T1 and T2 have the same name. If FOR_COMPLETION_P is
3218 true then if any type has no name return false, otherwise return
3219 true if both types have no names. */
3222 compare_type_names_p (tree t1, tree t2)
3224 tree name1 = TYPE_NAME (t1);
3225 tree name2 = TYPE_NAME (t2);
3227 if ((name1 != NULL_TREE) != (name2 != NULL_TREE))
3230 if (name1 == NULL_TREE)
3233 /* Either both should be a TYPE_DECL or both an IDENTIFIER_NODE. */
3234 if (TREE_CODE (name1) != TREE_CODE (name2))
3237 if (TREE_CODE (name1) == TYPE_DECL)
3238 name1 = DECL_NAME (name1);
3239 gcc_checking_assert (!name1 || TREE_CODE (name1) == IDENTIFIER_NODE);
3241 if (TREE_CODE (name2) == TYPE_DECL)
3242 name2 = DECL_NAME (name2);
3243 gcc_checking_assert (!name2 || TREE_CODE (name2) == IDENTIFIER_NODE);
3245 /* Identifiers can be compared with pointer equality rather
3246 than a string comparison. */
3253 /* Return true if the field decls F1 and F2 are at the same offset.
3255 This is intended to be used on GIMPLE types only. */
3258 gimple_compare_field_offset (tree f1, tree f2)
3260 if (DECL_OFFSET_ALIGN (f1) == DECL_OFFSET_ALIGN (f2))
3262 tree offset1 = DECL_FIELD_OFFSET (f1);
3263 tree offset2 = DECL_FIELD_OFFSET (f2);
3264 return ((offset1 == offset2
3265 /* Once gimplification is done, self-referential offsets are
3266 instantiated as operand #2 of the COMPONENT_REF built for
3267 each access and reset. Therefore, they are not relevant
3268 anymore and fields are interchangeable provided that they
3269 represent the same access. */
3270 || (TREE_CODE (offset1) == PLACEHOLDER_EXPR
3271 && TREE_CODE (offset2) == PLACEHOLDER_EXPR
3272 && (DECL_SIZE (f1) == DECL_SIZE (f2)
3273 || (TREE_CODE (DECL_SIZE (f1)) == PLACEHOLDER_EXPR
3274 && TREE_CODE (DECL_SIZE (f2)) == PLACEHOLDER_EXPR)
3275 || operand_equal_p (DECL_SIZE (f1), DECL_SIZE (f2), 0))
3276 && DECL_ALIGN (f1) == DECL_ALIGN (f2))
3277 || operand_equal_p (offset1, offset2, 0))
3278 && tree_int_cst_equal (DECL_FIELD_BIT_OFFSET (f1),
3279 DECL_FIELD_BIT_OFFSET (f2)));
3282 /* Fortran and C do not always agree on what DECL_OFFSET_ALIGN
3283 should be, so handle differing ones specially by decomposing
3284 the offset into a byte and bit offset manually. */
3285 if (host_integerp (DECL_FIELD_OFFSET (f1), 0)
3286 && host_integerp (DECL_FIELD_OFFSET (f2), 0))
3288 unsigned HOST_WIDE_INT byte_offset1, byte_offset2;
3289 unsigned HOST_WIDE_INT bit_offset1, bit_offset2;
3290 bit_offset1 = TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f1));
3291 byte_offset1 = (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f1))
3292 + bit_offset1 / BITS_PER_UNIT);
3293 bit_offset2 = TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f2));
3294 byte_offset2 = (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f2))
3295 + bit_offset2 / BITS_PER_UNIT);
3296 if (byte_offset1 != byte_offset2)
3298 return bit_offset1 % BITS_PER_UNIT == bit_offset2 % BITS_PER_UNIT;
3305 gimple_types_compatible_p_1 (tree, tree, type_pair_t,
3306 VEC(type_pair_t, heap) **,
3307 struct pointer_map_t *, struct obstack *);
3309 /* DFS visit the edge from the callers type pair with state *STATE to
3310 the pair T1, T2 while operating in FOR_MERGING_P mode.
3311 Update the merging status if it is not part of the SCC containing the
3312 callers pair and return it.
3313 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
3316 gtc_visit (tree t1, tree t2,
3318 VEC(type_pair_t, heap) **sccstack,
3319 struct pointer_map_t *sccstate,
3320 struct obstack *sccstate_obstack)
3322 struct sccs *cstate = NULL;
3325 tree leader1, leader2;
3327 /* Check first for the obvious case of pointer identity. */
3331 /* Check that we have two types to compare. */
3332 if (t1 == NULL_TREE || t2 == NULL_TREE)
3335 /* Can't be the same type if the types don't have the same code. */
3336 if (TREE_CODE (t1) != TREE_CODE (t2))
3339 /* Can't be the same type if they have different CV qualifiers. */
3340 if (TYPE_QUALS (t1) != TYPE_QUALS (t2))
3343 if (TREE_ADDRESSABLE (t1) != TREE_ADDRESSABLE (t2))
3346 /* Void types and nullptr types are always the same. */
3347 if (TREE_CODE (t1) == VOID_TYPE
3348 || TREE_CODE (t1) == NULLPTR_TYPE)
3351 /* Can't be the same type if they have different alignment or mode. */
3352 if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2)
3353 || TYPE_MODE (t1) != TYPE_MODE (t2))
3356 /* Do some simple checks before doing three hashtable queries. */
3357 if (INTEGRAL_TYPE_P (t1)
3358 || SCALAR_FLOAT_TYPE_P (t1)
3359 || FIXED_POINT_TYPE_P (t1)
3360 || TREE_CODE (t1) == VECTOR_TYPE
3361 || TREE_CODE (t1) == COMPLEX_TYPE
3362 || TREE_CODE (t1) == OFFSET_TYPE
3363 || POINTER_TYPE_P (t1))
3365 /* Can't be the same type if they have different sign or precision. */
3366 if (TYPE_PRECISION (t1) != TYPE_PRECISION (t2)
3367 || TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2))
3370 if (TREE_CODE (t1) == INTEGER_TYPE
3371 && (TYPE_IS_SIZETYPE (t1) != TYPE_IS_SIZETYPE (t2)
3372 || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)))
3375 /* That's all we need to check for float and fixed-point types. */
3376 if (SCALAR_FLOAT_TYPE_P (t1)
3377 || FIXED_POINT_TYPE_P (t1))
3380 /* For other types fall thru to more complex checks. */
3383 /* If the types have been previously registered and found equal
3385 leader1 = gimple_lookup_type_leader (t1);
3386 leader2 = gimple_lookup_type_leader (t2);
3389 || (leader1 && leader1 == leader2))
3392 /* If the hash values of t1 and t2 are different the types can't
3393 possibly be the same. This helps keeping the type-pair hashtable
3394 small, only tracking comparisons for hash collisions. */
3395 if (gimple_type_hash (t1) != gimple_type_hash (t2))
3398 /* Allocate a new cache entry for this comparison. */
3399 p = lookup_type_pair (t1, t2);
3400 if (p->same_p[GTC_MERGE] == 0 || p->same_p[GTC_MERGE] == 1)
3402 /* We have already decided whether T1 and T2 are the
3403 same, return the cached result. */
3404 return p->same_p[GTC_MERGE] == 1;
3407 if ((slot = pointer_map_contains (sccstate, p)) != NULL)
3408 cstate = (struct sccs *)*slot;
3409 /* Not yet visited. DFS recurse. */
3412 gimple_types_compatible_p_1 (t1, t2, p,
3413 sccstack, sccstate, sccstate_obstack);
3414 cstate = (struct sccs *)* pointer_map_contains (sccstate, p);
3415 state->low = MIN (state->low, cstate->low);
3417 /* If the type is still on the SCC stack adjust the parents low. */
3418 if (cstate->dfsnum < state->dfsnum
3419 && cstate->on_sccstack)
3420 state->low = MIN (cstate->dfsnum, state->low);
3422 /* Return the current lattice value. We start with an equality
3423 assumption so types part of a SCC will be optimistically
3424 treated equal unless proven otherwise. */
3425 return cstate->u.same_p;
3428 /* Worker for gimple_types_compatible.
3429 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
3432 gimple_types_compatible_p_1 (tree t1, tree t2, type_pair_t p,
3433 VEC(type_pair_t, heap) **sccstack,
3434 struct pointer_map_t *sccstate,
3435 struct obstack *sccstate_obstack)
3439 gcc_assert (p->same_p[GTC_MERGE] == -2);
3441 state = XOBNEW (sccstate_obstack, struct sccs);
3442 *pointer_map_insert (sccstate, p) = state;
3444 VEC_safe_push (type_pair_t, heap, *sccstack, p);
3445 state->dfsnum = gtc_next_dfs_num++;
3446 state->low = state->dfsnum;
3447 state->on_sccstack = true;
3448 /* Start with an equality assumption. As we DFS recurse into child
3449 SCCs this assumption may get revisited. */
3450 state->u.same_p = 1;
3452 /* The struct tags shall compare equal. */
3453 if (!compare_type_names_p (t1, t2))
3454 goto different_types;
3456 /* We may not merge typedef types to the same type in different
3459 && TREE_CODE (TYPE_NAME (t1)) == TYPE_DECL
3460 && DECL_CONTEXT (TYPE_NAME (t1))
3461 && TYPE_P (DECL_CONTEXT (TYPE_NAME (t1))))
3463 if (!gtc_visit (DECL_CONTEXT (TYPE_NAME (t1)),
3464 DECL_CONTEXT (TYPE_NAME (t2)),
3465 state, sccstack, sccstate, sccstate_obstack))
3466 goto different_types;
3469 /* If their attributes are not the same they can't be the same type. */
3470 if (!attribute_list_equal (TYPE_ATTRIBUTES (t1), TYPE_ATTRIBUTES (t2)))
3471 goto different_types;
3473 /* Do type-specific comparisons. */
3474 switch (TREE_CODE (t1))
3478 if (!gtc_visit (TREE_TYPE (t1), TREE_TYPE (t2),
3479 state, sccstack, sccstate, sccstate_obstack))
3480 goto different_types;
3484 /* Array types are the same if the element types are the same and
3485 the number of elements are the same. */
3486 if (!gtc_visit (TREE_TYPE (t1), TREE_TYPE (t2),
3487 state, sccstack, sccstate, sccstate_obstack)
3488 || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)
3489 || TYPE_NONALIASED_COMPONENT (t1) != TYPE_NONALIASED_COMPONENT (t2))
3490 goto different_types;
3493 tree i1 = TYPE_DOMAIN (t1);
3494 tree i2 = TYPE_DOMAIN (t2);
3496 /* For an incomplete external array, the type domain can be
3497 NULL_TREE. Check this condition also. */
3498 if (i1 == NULL_TREE && i2 == NULL_TREE)
3500 else if (i1 == NULL_TREE || i2 == NULL_TREE)
3501 goto different_types;
3502 /* If for a complete array type the possibly gimplified sizes
3503 are different the types are different. */
3504 else if (((TYPE_SIZE (i1) != NULL) ^ (TYPE_SIZE (i2) != NULL))
3507 && !operand_equal_p (TYPE_SIZE (i1), TYPE_SIZE (i2), 0)))
3508 goto different_types;
3511 tree min1 = TYPE_MIN_VALUE (i1);
3512 tree min2 = TYPE_MIN_VALUE (i2);
3513 tree max1 = TYPE_MAX_VALUE (i1);
3514 tree max2 = TYPE_MAX_VALUE (i2);
3516 /* The minimum/maximum values have to be the same. */
3519 && ((TREE_CODE (min1) == PLACEHOLDER_EXPR
3520 && TREE_CODE (min2) == PLACEHOLDER_EXPR)
3521 || operand_equal_p (min1, min2, 0))))
3524 && ((TREE_CODE (max1) == PLACEHOLDER_EXPR
3525 && TREE_CODE (max2) == PLACEHOLDER_EXPR)
3526 || operand_equal_p (max1, max2, 0)))))
3529 goto different_types;
3534 /* Method types should belong to the same class. */
3535 if (!gtc_visit (TYPE_METHOD_BASETYPE (t1), TYPE_METHOD_BASETYPE (t2),
3536 state, sccstack, sccstate, sccstate_obstack))
3537 goto different_types;
3542 /* Function types are the same if the return type and arguments types
3544 if (!gtc_visit (TREE_TYPE (t1), TREE_TYPE (t2),
3545 state, sccstack, sccstate, sccstate_obstack))
3546 goto different_types;
3548 if (!comp_type_attributes (t1, t2))
3549 goto different_types;
3551 if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2))
3555 tree parms1, parms2;
3557 for (parms1 = TYPE_ARG_TYPES (t1), parms2 = TYPE_ARG_TYPES (t2);
3559 parms1 = TREE_CHAIN (parms1), parms2 = TREE_CHAIN (parms2))
3561 if (!gtc_visit (TREE_VALUE (parms1), TREE_VALUE (parms2),
3562 state, sccstack, sccstate, sccstate_obstack))
3563 goto different_types;
3566 if (parms1 || parms2)
3567 goto different_types;
3574 if (!gtc_visit (TREE_TYPE (t1), TREE_TYPE (t2),
3575 state, sccstack, sccstate, sccstate_obstack)
3576 || !gtc_visit (TYPE_OFFSET_BASETYPE (t1),
3577 TYPE_OFFSET_BASETYPE (t2),
3578 state, sccstack, sccstate, sccstate_obstack))
3579 goto different_types;
3585 case REFERENCE_TYPE:
3587 /* If the two pointers have different ref-all attributes,
3588 they can't be the same type. */
3589 if (TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2))
3590 goto different_types;
3592 /* Otherwise, pointer and reference types are the same if the
3593 pointed-to types are the same. */
3594 if (gtc_visit (TREE_TYPE (t1), TREE_TYPE (t2),
3595 state, sccstack, sccstate, sccstate_obstack))
3598 goto different_types;
3604 tree min1 = TYPE_MIN_VALUE (t1);
3605 tree max1 = TYPE_MAX_VALUE (t1);
3606 tree min2 = TYPE_MIN_VALUE (t2);
3607 tree max2 = TYPE_MAX_VALUE (t2);
3608 bool min_equal_p = false;
3609 bool max_equal_p = false;
3611 /* If either type has a minimum value, the other type must
3613 if (min1 == NULL_TREE && min2 == NULL_TREE)
3615 else if (min1 && min2 && operand_equal_p (min1, min2, 0))
3618 /* Likewise, if either type has a maximum value, the other
3619 type must have the same. */
3620 if (max1 == NULL_TREE && max2 == NULL_TREE)
3622 else if (max1 && max2 && operand_equal_p (max1, max2, 0))
3625 if (!min_equal_p || !max_equal_p)
3626 goto different_types;
3633 /* FIXME lto, we cannot check bounds on enumeral types because
3634 different front ends will produce different values.
3635 In C, enumeral types are integers, while in C++ each element
3636 will have its own symbolic value. We should decide how enums
3637 are to be represented in GIMPLE and have each front end lower
3641 /* For enumeral types, all the values must be the same. */
3642 if (TYPE_VALUES (t1) == TYPE_VALUES (t2))
3645 for (v1 = TYPE_VALUES (t1), v2 = TYPE_VALUES (t2);
3647 v1 = TREE_CHAIN (v1), v2 = TREE_CHAIN (v2))
3649 tree c1 = TREE_VALUE (v1);
3650 tree c2 = TREE_VALUE (v2);
3652 if (TREE_CODE (c1) == CONST_DECL)
3653 c1 = DECL_INITIAL (c1);
3655 if (TREE_CODE (c2) == CONST_DECL)
3656 c2 = DECL_INITIAL (c2);
3658 if (tree_int_cst_equal (c1, c2) != 1)
3659 goto different_types;
3661 if (TREE_PURPOSE (v1) != TREE_PURPOSE (v2))
3662 goto different_types;
3665 /* If one enumeration has more values than the other, they
3666 are not the same. */
3668 goto different_types;
3675 case QUAL_UNION_TYPE:
3679 /* For aggregate types, all the fields must be the same. */
3680 for (f1 = TYPE_FIELDS (t1), f2 = TYPE_FIELDS (t2);
3682 f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
3684 /* Different field kinds are not compatible. */
3685 if (TREE_CODE (f1) != TREE_CODE (f2))
3686 goto different_types;
3687 /* Field decls must have the same name and offset. */
3688 if (TREE_CODE (f1) == FIELD_DECL
3689 && (DECL_NONADDRESSABLE_P (f1) != DECL_NONADDRESSABLE_P (f2)
3690 || !gimple_compare_field_offset (f1, f2)))
3691 goto different_types;
3692 /* All entities should have the same name and type. */
3693 if (DECL_NAME (f1) != DECL_NAME (f2)
3694 || !gtc_visit (TREE_TYPE (f1), TREE_TYPE (f2),
3695 state, sccstack, sccstate, sccstate_obstack))
3696 goto different_types;
3699 /* If one aggregate has more fields than the other, they
3700 are not the same. */
3702 goto different_types;
3711 /* Common exit path for types that are not compatible. */
3713 state->u.same_p = 0;
3716 /* Common exit path for types that are compatible. */
3718 gcc_assert (state->u.same_p == 1);
3721 if (state->low == state->dfsnum)
3725 /* Pop off the SCC and set its cache values to the final
3726 comparison result. */
3729 struct sccs *cstate;
3730 x = VEC_pop (type_pair_t, *sccstack);
3731 cstate = (struct sccs *)*pointer_map_contains (sccstate, x);
3732 cstate->on_sccstack = false;
3733 x->same_p[GTC_MERGE] = state->u.same_p;
3738 return state->u.same_p;
3741 /* Return true iff T1 and T2 are structurally identical. When
3742 FOR_MERGING_P is true the an incomplete type and a complete type
3743 are considered different, otherwise they are considered compatible. */
3746 gimple_types_compatible_p (tree t1, tree t2)
3748 VEC(type_pair_t, heap) *sccstack = NULL;
3749 struct pointer_map_t *sccstate;
3750 struct obstack sccstate_obstack;
3751 type_pair_t p = NULL;
3753 tree leader1, leader2;
3755 /* Before starting to set up the SCC machinery handle simple cases. */
3757 /* Check first for the obvious case of pointer identity. */
3761 /* Check that we have two types to compare. */
3762 if (t1 == NULL_TREE || t2 == NULL_TREE)
3765 /* Can't be the same type if the types don't have the same code. */
3766 if (TREE_CODE (t1) != TREE_CODE (t2))
3769 /* Can't be the same type if they have different CV qualifiers. */
3770 if (TYPE_QUALS (t1) != TYPE_QUALS (t2))
3773 if (TREE_ADDRESSABLE (t1) != TREE_ADDRESSABLE (t2))
3776 /* Void types and nullptr types are always the same. */
3777 if (TREE_CODE (t1) == VOID_TYPE
3778 || TREE_CODE (t1) == NULLPTR_TYPE)
3781 /* Can't be the same type if they have different alignment or mode. */
3782 if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2)
3783 || TYPE_MODE (t1) != TYPE_MODE (t2))
3786 /* Do some simple checks before doing three hashtable queries. */
3787 if (INTEGRAL_TYPE_P (t1)
3788 || SCALAR_FLOAT_TYPE_P (t1)
3789 || FIXED_POINT_TYPE_P (t1)
3790 || TREE_CODE (t1) == VECTOR_TYPE
3791 || TREE_CODE (t1) == COMPLEX_TYPE
3792 || TREE_CODE (t1) == OFFSET_TYPE
3793 || POINTER_TYPE_P (t1))
3795 /* Can't be the same type if they have different sign or precision. */
3796 if (TYPE_PRECISION (t1) != TYPE_PRECISION (t2)
3797 || TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2))
3800 if (TREE_CODE (t1) == INTEGER_TYPE
3801 && (TYPE_IS_SIZETYPE (t1) != TYPE_IS_SIZETYPE (t2)
3802 || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)))
3805 /* That's all we need to check for float and fixed-point types. */
3806 if (SCALAR_FLOAT_TYPE_P (t1)
3807 || FIXED_POINT_TYPE_P (t1))
3810 /* For other types fall thru to more complex checks. */
3813 /* If the types have been previously registered and found equal
3815 leader1 = gimple_lookup_type_leader (t1);
3816 leader2 = gimple_lookup_type_leader (t2);
3819 || (leader1 && leader1 == leader2))
3822 /* If the hash values of t1 and t2 are different the types can't
3823 possibly be the same. This helps keeping the type-pair hashtable
3824 small, only tracking comparisons for hash collisions. */
3825 if (gimple_type_hash (t1) != gimple_type_hash (t2))
3828 /* If we've visited this type pair before (in the case of aggregates
3829 with self-referential types), and we made a decision, return it. */
3830 p = lookup_type_pair (t1, t2);
3831 if (p->same_p[GTC_MERGE] == 0 || p->same_p[GTC_MERGE] == 1)
3833 /* We have already decided whether T1 and T2 are the
3834 same, return the cached result. */
3835 return p->same_p[GTC_MERGE] == 1;
3838 /* Now set up the SCC machinery for the comparison. */
3839 gtc_next_dfs_num = 1;
3840 sccstate = pointer_map_create ();
3841 gcc_obstack_init (&sccstate_obstack);
3842 res = gimple_types_compatible_p_1 (t1, t2, p,
3843 &sccstack, sccstate, &sccstate_obstack);
3844 VEC_free (type_pair_t, heap, sccstack);
3845 pointer_map_destroy (sccstate);
3846 obstack_free (&sccstate_obstack, NULL);
3853 iterative_hash_gimple_type (tree, hashval_t, VEC(tree, heap) **,
3854 struct pointer_map_t *, struct obstack *);
3856 /* DFS visit the edge from the callers type with state *STATE to T.
3857 Update the callers type hash V with the hash for T if it is not part
3858 of the SCC containing the callers type and return it.
3859 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
3862 visit (tree t, struct sccs *state, hashval_t v,
3863 VEC (tree, heap) **sccstack,
3864 struct pointer_map_t *sccstate,
3865 struct obstack *sccstate_obstack)
3867 struct sccs *cstate = NULL;
3868 struct tree_int_map m;
3871 /* If there is a hash value recorded for this type then it can't
3872 possibly be part of our parent SCC. Simply mix in its hash. */
3874 if ((slot = htab_find_slot (type_hash_cache, &m, NO_INSERT))
3876 return iterative_hash_hashval_t (((struct tree_int_map *) *slot)->to, v);
3878 if ((slot = pointer_map_contains (sccstate, t)) != NULL)
3879 cstate = (struct sccs *)*slot;
3883 /* Not yet visited. DFS recurse. */
3884 tem = iterative_hash_gimple_type (t, v,
3885 sccstack, sccstate, sccstate_obstack);
3887 cstate = (struct sccs *)* pointer_map_contains (sccstate, t);
3888 state->low = MIN (state->low, cstate->low);
3889 /* If the type is no longer on the SCC stack and thus is not part
3890 of the parents SCC mix in its hash value. Otherwise we will
3891 ignore the type for hashing purposes and return the unaltered
3893 if (!cstate->on_sccstack)
3896 if (cstate->dfsnum < state->dfsnum
3897 && cstate->on_sccstack)
3898 state->low = MIN (cstate->dfsnum, state->low);
3900 /* We are part of our parents SCC, skip this type during hashing
3901 and return the unaltered hash value. */
3905 /* Hash NAME with the previous hash value V and return it. */
3908 iterative_hash_name (tree name, hashval_t v)
3912 v = iterative_hash_hashval_t (TREE_CODE (name), v);
3913 if (TREE_CODE (name) == TYPE_DECL)
3914 name = DECL_NAME (name);
3917 gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
3918 return iterative_hash_object (IDENTIFIER_HASH_VALUE (name), v);
3921 /* A type, hashvalue pair for sorting SCC members. */
3923 struct type_hash_pair {
3928 /* Compare two type, hashvalue pairs. */
3931 type_hash_pair_compare (const void *p1_, const void *p2_)
3933 const struct type_hash_pair *p1 = (const struct type_hash_pair *) p1_;
3934 const struct type_hash_pair *p2 = (const struct type_hash_pair *) p2_;
3935 if (p1->hash < p2->hash)
3937 else if (p1->hash > p2->hash)
3942 /* Returning a hash value for gimple type TYPE combined with VAL.
3943 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done.
3945 To hash a type we end up hashing in types that are reachable.
3946 Through pointers we can end up with cycles which messes up the
3947 required property that we need to compute the same hash value
3948 for structurally equivalent types. To avoid this we have to
3949 hash all types in a cycle (the SCC) in a commutative way. The
3950 easiest way is to not mix in the hashes of the SCC members at
3951 all. To make this work we have to delay setting the hash
3952 values of the SCC until it is complete. */
3955 iterative_hash_gimple_type (tree type, hashval_t val,
3956 VEC(tree, heap) **sccstack,
3957 struct pointer_map_t *sccstate,
3958 struct obstack *sccstate_obstack)
3964 /* Not visited during this DFS walk. */
3965 gcc_checking_assert (!pointer_map_contains (sccstate, type));
3966 state = XOBNEW (sccstate_obstack, struct sccs);
3967 *pointer_map_insert (sccstate, type) = state;
3969 VEC_safe_push (tree, heap, *sccstack, type);
3970 state->dfsnum = next_dfs_num++;
3971 state->low = state->dfsnum;
3972 state->on_sccstack = true;
3974 /* Combine a few common features of types so that types are grouped into
3975 smaller sets; when searching for existing matching types to merge,
3976 only existing types having the same features as the new type will be
3978 v = iterative_hash_name (TYPE_NAME (type), 0);
3979 if (TYPE_NAME (type)
3980 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3981 && DECL_CONTEXT (TYPE_NAME (type))
3982 && TYPE_P (DECL_CONTEXT (TYPE_NAME (type))))
3983 v = visit (DECL_CONTEXT (TYPE_NAME (type)), state, v,
3984 sccstack, sccstate, sccstate_obstack);
3985 v = iterative_hash_hashval_t (TREE_CODE (type), v);
3986 v = iterative_hash_hashval_t (TYPE_QUALS (type), v);
3987 v = iterative_hash_hashval_t (TREE_ADDRESSABLE (type), v);
3989 /* Do not hash the types size as this will cause differences in
3990 hash values for the complete vs. the incomplete type variant. */
3992 /* Incorporate common features of numerical types. */
3993 if (INTEGRAL_TYPE_P (type)
3994 || SCALAR_FLOAT_TYPE_P (type)
3995 || FIXED_POINT_TYPE_P (type))
3997 v = iterative_hash_hashval_t (TYPE_PRECISION (type), v);
3998 v = iterative_hash_hashval_t (TYPE_MODE (type), v);
3999 v = iterative_hash_hashval_t (TYPE_UNSIGNED (type), v);
4002 /* For pointer and reference types, fold in information about the type
4004 if (POINTER_TYPE_P (type))
4005 v = visit (TREE_TYPE (type), state, v,
4006 sccstack, sccstate, sccstate_obstack);
4008 /* For integer types hash the types min/max values and the string flag. */
4009 if (TREE_CODE (type) == INTEGER_TYPE)
4011 /* OMP lowering can introduce error_mark_node in place of
4012 random local decls in types. */
4013 if (TYPE_MIN_VALUE (type) != error_mark_node)
4014 v = iterative_hash_expr (TYPE_MIN_VALUE (type), v);
4015 if (TYPE_MAX_VALUE (type) != error_mark_node)
4016 v = iterative_hash_expr (TYPE_MAX_VALUE (type), v);
4017 v = iterative_hash_hashval_t (TYPE_STRING_FLAG (type), v);
4020 /* For array types hash their domain and the string flag. */
4021 if (TREE_CODE (type) == ARRAY_TYPE
4022 && TYPE_DOMAIN (type))
4024 v = iterative_hash_hashval_t (TYPE_STRING_FLAG (type), v);
4025 v = visit (TYPE_DOMAIN (type), state, v,
4026 sccstack, sccstate, sccstate_obstack);
4029 /* Recurse for aggregates with a single element type. */
4030 if (TREE_CODE (type) == ARRAY_TYPE
4031 || TREE_CODE (type) == COMPLEX_TYPE
4032 || TREE_CODE (type) == VECTOR_TYPE)
4033 v = visit (TREE_TYPE (type), state, v,
4034 sccstack, sccstate, sccstate_obstack);
4036 /* Incorporate function return and argument types. */
4037 if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
4042 /* For method types also incorporate their parent class. */
4043 if (TREE_CODE (type) == METHOD_TYPE)
4044 v = visit (TYPE_METHOD_BASETYPE (type), state, v,
4045 sccstack, sccstate, sccstate_obstack);
4047 /* Check result and argument types. */
4048 v = visit (TREE_TYPE (type), state, v,
4049 sccstack, sccstate, sccstate_obstack);
4050 for (p = TYPE_ARG_TYPES (type), na = 0; p; p = TREE_CHAIN (p))
4052 v = visit (TREE_VALUE (p), state, v,
4053 sccstack, sccstate, sccstate_obstack);
4057 v = iterative_hash_hashval_t (na, v);
4060 if (RECORD_OR_UNION_TYPE_P (type))
4065 for (f = TYPE_FIELDS (type), nf = 0; f; f = TREE_CHAIN (f))
4067 v = iterative_hash_name (DECL_NAME (f), v);
4068 v = visit (TREE_TYPE (f), state, v,
4069 sccstack, sccstate, sccstate_obstack);
4073 v = iterative_hash_hashval_t (nf, v);
4076 /* Record hash for us. */
4079 /* See if we found an SCC. */
4080 if (state->low == state->dfsnum)
4083 struct tree_int_map *m;
4085 /* Pop off the SCC and set its hash values. */
4086 x = VEC_pop (tree, *sccstack);
4087 /* Optimize SCC size one. */
4090 state->on_sccstack = false;
4091 m = ggc_alloc_cleared_tree_int_map ();
4094 slot = htab_find_slot (type_hash_cache, m, INSERT);
4095 gcc_assert (!*slot);
4100 struct sccs *cstate;
4101 unsigned first, i, size, j;
4102 struct type_hash_pair *pairs;
4103 /* Pop off the SCC and build an array of type, hash pairs. */
4104 first = VEC_length (tree, *sccstack) - 1;
4105 while (VEC_index (tree, *sccstack, first) != type)
4107 size = VEC_length (tree, *sccstack) - first + 1;
4108 pairs = XALLOCAVEC (struct type_hash_pair, size);
4110 cstate = (struct sccs *)*pointer_map_contains (sccstate, x);
4111 cstate->on_sccstack = false;
4113 pairs[i].hash = cstate->u.hash;
4116 x = VEC_pop (tree, *sccstack);
4117 cstate = (struct sccs *)*pointer_map_contains (sccstate, x);
4118 cstate->on_sccstack = false;
4121 pairs[i].hash = cstate->u.hash;
4124 gcc_assert (i + 1 == size);
4125 /* Sort the arrays of type, hash pairs so that when we mix in
4126 all members of the SCC the hash value becomes independent on
4127 the order we visited the SCC. Disregard hashes equal to
4128 the hash of the type we mix into because we cannot guarantee
4129 a stable sort for those across different TUs. */
4130 qsort (pairs, size, sizeof (struct type_hash_pair),
4131 type_hash_pair_compare);
4132 for (i = 0; i < size; ++i)
4135 m = ggc_alloc_cleared_tree_int_map ();
4136 m->base.from = pairs[i].type;
4137 hash = pairs[i].hash;
4138 /* Skip same hashes. */
4139 for (j = i + 1; j < size && pairs[j].hash == pairs[i].hash; ++j)
4141 for (; j < size; ++j)
4142 hash = iterative_hash_hashval_t (pairs[j].hash, hash);
4143 for (j = 0; pairs[j].hash != pairs[i].hash; ++j)
4144 hash = iterative_hash_hashval_t (pairs[j].hash, hash);
4146 if (pairs[i].type == type)
4148 slot = htab_find_slot (type_hash_cache, m, INSERT);
4149 gcc_assert (!*slot);
4155 return iterative_hash_hashval_t (v, val);
4159 /* Returns a hash value for P (assumed to be a type). The hash value
4160 is computed using some distinguishing features of the type. Note
4161 that we cannot use pointer hashing here as we may be dealing with
4162 two distinct instances of the same type.
4164 This function should produce the same hash value for two compatible
4165 types according to gimple_types_compatible_p. */
4168 gimple_type_hash (const void *p)
4170 const_tree t = (const_tree) p;
4171 VEC(tree, heap) *sccstack = NULL;
4172 struct pointer_map_t *sccstate;
4173 struct obstack sccstate_obstack;
4176 struct tree_int_map m;
4178 if (type_hash_cache == NULL)
4179 type_hash_cache = htab_create_ggc (512, tree_int_map_hash,
4180 tree_int_map_eq, NULL);
4182 m.base.from = CONST_CAST_TREE (t);
4183 if ((slot = htab_find_slot (type_hash_cache, &m, NO_INSERT))
4185 return iterative_hash_hashval_t (((struct tree_int_map *) *slot)->to, 0);
4187 /* Perform a DFS walk and pre-hash all reachable types. */
4189 sccstate = pointer_map_create ();
4190 gcc_obstack_init (&sccstate_obstack);
4191 val = iterative_hash_gimple_type (CONST_CAST_TREE (t), 0,
4192 &sccstack, sccstate, &sccstate_obstack);
4193 VEC_free (tree, heap, sccstack);
4194 pointer_map_destroy (sccstate);
4195 obstack_free (&sccstate_obstack, NULL);
4200 /* Returning a hash value for gimple type TYPE combined with VAL.
4202 The hash value returned is equal for types considered compatible
4203 by gimple_canonical_types_compatible_p. */
4206 iterative_hash_canonical_type (tree type, hashval_t val)
4210 struct tree_int_map *mp, m;
4213 if ((slot = htab_find_slot (canonical_type_hash_cache, &m, INSERT))
4215 return iterative_hash_hashval_t (((struct tree_int_map *) *slot)->to, val);
4217 /* Combine a few common features of types so that types are grouped into
4218 smaller sets; when searching for existing matching types to merge,
4219 only existing types having the same features as the new type will be
4221 v = iterative_hash_hashval_t (TREE_CODE (type), 0);
4222 v = iterative_hash_hashval_t (TREE_ADDRESSABLE (type), v);
4223 v = iterative_hash_hashval_t (TYPE_ALIGN (type), v);
4224 v = iterative_hash_hashval_t (TYPE_MODE (type), v);
4226 /* Incorporate common features of numerical types. */
4227 if (INTEGRAL_TYPE_P (type)
4228 || SCALAR_FLOAT_TYPE_P (type)
4229 || FIXED_POINT_TYPE_P (type)
4230 || TREE_CODE (type) == VECTOR_TYPE
4231 || TREE_CODE (type) == COMPLEX_TYPE
4232 || TREE_CODE (type) == OFFSET_TYPE
4233 || POINTER_TYPE_P (type))
4235 v = iterative_hash_hashval_t (TYPE_PRECISION (type), v);
4236 v = iterative_hash_hashval_t (TYPE_UNSIGNED (type), v);
4239 /* For pointer and reference types, fold in information about the type
4240 pointed to but do not recurse to the pointed-to type. */
4241 if (POINTER_TYPE_P (type))
4243 v = iterative_hash_hashval_t (TYPE_REF_CAN_ALIAS_ALL (type), v);
4244 v = iterative_hash_hashval_t (TYPE_ADDR_SPACE (TREE_TYPE (type)), v);
4245 v = iterative_hash_hashval_t (TYPE_RESTRICT (type), v);
4246 v = iterative_hash_hashval_t (TREE_CODE (TREE_TYPE (type)), v);
4249 /* For integer types hash the types min/max values and the string flag. */
4250 if (TREE_CODE (type) == INTEGER_TYPE)
4252 v = iterative_hash_hashval_t (TYPE_STRING_FLAG (type), v);
4253 v = iterative_hash_hashval_t (TYPE_IS_SIZETYPE (type), v);
4256 /* For array types hash their domain and the string flag. */
4257 if (TREE_CODE (type) == ARRAY_TYPE
4258 && TYPE_DOMAIN (type))
4260 v = iterative_hash_hashval_t (TYPE_STRING_FLAG (type), v);
4261 v = iterative_hash_canonical_type (TYPE_DOMAIN (type), v);
4264 /* Recurse for aggregates with a single element type. */
4265 if (TREE_CODE (type) == ARRAY_TYPE
4266 || TREE_CODE (type) == COMPLEX_TYPE
4267 || TREE_CODE (type) == VECTOR_TYPE)
4268 v = iterative_hash_canonical_type (TREE_TYPE (type), v);
4270 /* Incorporate function return and argument types. */
4271 if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
4276 /* For method types also incorporate their parent class. */
4277 if (TREE_CODE (type) == METHOD_TYPE)
4278 v = iterative_hash_canonical_type (TYPE_METHOD_BASETYPE (type), v);
4280 v = iterative_hash_canonical_type (TREE_TYPE (type), v);
4282 for (p = TYPE_ARG_TYPES (type), na = 0; p; p = TREE_CHAIN (p))
4284 v = iterative_hash_canonical_type (TREE_VALUE (p), v);
4288 v = iterative_hash_hashval_t (na, v);
4291 if (RECORD_OR_UNION_TYPE_P (type))
4296 for (f = TYPE_FIELDS (type), nf = 0; f; f = TREE_CHAIN (f))
4297 if (TREE_CODE (f) == FIELD_DECL)
4299 v = iterative_hash_canonical_type (TREE_TYPE (f), v);
4303 v = iterative_hash_hashval_t (nf, v);
4306 /* Cache the just computed hash value. */
4307 mp = ggc_alloc_cleared_tree_int_map ();
4308 mp->base.from = type;
4310 *slot = (void *) mp;
4312 return iterative_hash_hashval_t (v, val);
4316 gimple_canonical_type_hash (const void *p)
4318 if (canonical_type_hash_cache == NULL)
4319 canonical_type_hash_cache = htab_create_ggc (512, tree_int_map_hash,
4320 tree_int_map_eq, NULL);
4322 return iterative_hash_canonical_type (CONST_CAST_TREE ((const_tree) p), 0);
4326 /* Returns nonzero if P1 and P2 are equal. */
4329 gimple_type_eq (const void *p1, const void *p2)
4331 const_tree t1 = (const_tree) p1;
4332 const_tree t2 = (const_tree) p2;
4333 return gimple_types_compatible_p (CONST_CAST_TREE (t1),
4334 CONST_CAST_TREE (t2));
4338 /* Worker for gimple_register_type.
4339 Register type T in the global type table gimple_types.
4340 When REGISTERING_MV is false first recurse for the main variant of T. */
4343 gimple_register_type_1 (tree t, bool registering_mv)
4346 gimple_type_leader_entry *leader;
4348 /* If we registered this type before return the cached result. */
4349 leader = &gimple_type_leader[TYPE_UID (t) % GIMPLE_TYPE_LEADER_SIZE];
4350 if (leader->type == t)
4351 return leader->leader;
4353 /* Always register the main variant first. This is important so we
4354 pick up the non-typedef variants as canonical, otherwise we'll end
4355 up taking typedef ids for structure tags during comparison.
4356 It also makes sure that main variants will be merged to main variants.
4357 As we are operating on a possibly partially fixed up type graph
4358 do not bother to recurse more than once, otherwise we may end up
4360 If we are registering a main variant it will either remain its
4361 own main variant or it will be merged to something else in which
4362 case we do not care for the main variant leader. */
4364 && TYPE_MAIN_VARIANT (t) != t)
4365 gimple_register_type_1 (TYPE_MAIN_VARIANT (t), true);
4367 /* See if we already have an equivalent type registered. */
4368 slot = htab_find_slot (gimple_types, t, INSERT);
4370 && *(tree *)slot != t)
4372 tree new_type = (tree) *((tree *) slot);
4374 leader->leader = new_type;
4378 /* If not, insert it to the cache and the hash. */
4385 /* Register type T in the global type table gimple_types.
4386 If another type T', compatible with T, already existed in
4387 gimple_types then return T', otherwise return T. This is used by
4388 LTO to merge identical types read from different TUs. */
4391 gimple_register_type (tree t)
4393 gcc_assert (TYPE_P (t));
4395 if (!gimple_type_leader)
4396 gimple_type_leader = ggc_alloc_cleared_vec_gimple_type_leader_entry_s
4397 (GIMPLE_TYPE_LEADER_SIZE);
4399 if (gimple_types == NULL)
4400 gimple_types = htab_create_ggc (16381, gimple_type_hash, gimple_type_eq, 0);
4402 return gimple_register_type_1 (t, false);
4405 /* The TYPE_CANONICAL merging machinery. It should closely resemble
4406 the middle-end types_compatible_p function. It needs to avoid
4407 claiming types are different for types that should be treated
4408 the same with respect to TBAA. Canonical types are also used
4409 for IL consistency checks via the useless_type_conversion_p
4410 predicate which does not handle all type kinds itself but falls
4411 back to pointer-comparison of TYPE_CANONICAL for aggregates
4414 /* Return true iff T1 and T2 are structurally identical for what
4415 TBAA is concerned. */
4418 gimple_canonical_types_compatible_p (tree t1, tree t2)
4420 /* Before starting to set up the SCC machinery handle simple cases. */
4422 /* Check first for the obvious case of pointer identity. */
4426 /* Check that we have two types to compare. */
4427 if (t1 == NULL_TREE || t2 == NULL_TREE)
4430 /* If the types have been previously registered and found equal
4432 if (TYPE_CANONICAL (t1)
4433 && TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2))
4436 /* Can't be the same type if the types don't have the same code. */
4437 if (TREE_CODE (t1) != TREE_CODE (t2))
4440 if (TREE_ADDRESSABLE (t1) != TREE_ADDRESSABLE (t2))
4443 /* Qualifiers do not matter for canonical type comparison purposes. */
4445 /* Void types and nullptr types are always the same. */
4446 if (TREE_CODE (t1) == VOID_TYPE
4447 || TREE_CODE (t1) == NULLPTR_TYPE)
4450 /* Can't be the same type if they have different alignment, or mode. */
4451 if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2)
4452 || TYPE_MODE (t1) != TYPE_MODE (t2))
4455 /* Non-aggregate types can be handled cheaply. */
4456 if (INTEGRAL_TYPE_P (t1)
4457 || SCALAR_FLOAT_TYPE_P (t1)
4458 || FIXED_POINT_TYPE_P (t1)
4459 || TREE_CODE (t1) == VECTOR_TYPE
4460 || TREE_CODE (t1) == COMPLEX_TYPE
4461 || TREE_CODE (t1) == OFFSET_TYPE
4462 || POINTER_TYPE_P (t1))
4464 /* Can't be the same type if they have different sign or precision. */
4465 if (TYPE_PRECISION (t1) != TYPE_PRECISION (t2)
4466 || TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2))
4469 if (TREE_CODE (t1) == INTEGER_TYPE
4470 && (TYPE_IS_SIZETYPE (t1) != TYPE_IS_SIZETYPE (t2)
4471 || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)))
4474 /* For canonical type comparisons we do not want to build SCCs
4475 so we cannot compare pointed-to types. But we can, for now,
4476 require the same pointed-to type kind and match what
4477 useless_type_conversion_p would do. */
4478 if (POINTER_TYPE_P (t1))
4480 /* If the two pointers have different ref-all attributes,
4481 they can't be the same type. */
4482 if (TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2))
4485 if (TYPE_ADDR_SPACE (TREE_TYPE (t1))
4486 != TYPE_ADDR_SPACE (TREE_TYPE (t2)))
4489 if (TYPE_RESTRICT (t1) != TYPE_RESTRICT (t2))
4492 if (TREE_CODE (TREE_TYPE (t1)) != TREE_CODE (TREE_TYPE (t2)))
4496 /* Tail-recurse to components. */
4497 if (TREE_CODE (t1) == VECTOR_TYPE
4498 || TREE_CODE (t1) == COMPLEX_TYPE)
4499 return gimple_canonical_types_compatible_p (TREE_TYPE (t1),
4505 /* If their attributes are not the same they can't be the same type. */
4506 if (!attribute_list_equal (TYPE_ATTRIBUTES (t1), TYPE_ATTRIBUTES (t2)))
4509 /* Do type-specific comparisons. */
4510 switch (TREE_CODE (t1))
4513 /* Array types are the same if the element types are the same and
4514 the number of elements are the same. */
4515 if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2))
4516 || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)
4517 || TYPE_NONALIASED_COMPONENT (t1) != TYPE_NONALIASED_COMPONENT (t2))
4521 tree i1 = TYPE_DOMAIN (t1);
4522 tree i2 = TYPE_DOMAIN (t2);
4524 /* For an incomplete external array, the type domain can be
4525 NULL_TREE. Check this condition also. */
4526 if (i1 == NULL_TREE && i2 == NULL_TREE)
4528 else if (i1 == NULL_TREE || i2 == NULL_TREE)
4530 /* If for a complete array type the possibly gimplified sizes
4531 are different the types are different. */
4532 else if (((TYPE_SIZE (i1) != NULL) ^ (TYPE_SIZE (i2) != NULL))
4535 && !operand_equal_p (TYPE_SIZE (i1), TYPE_SIZE (i2), 0)))
4539 tree min1 = TYPE_MIN_VALUE (i1);
4540 tree min2 = TYPE_MIN_VALUE (i2);
4541 tree max1 = TYPE_MAX_VALUE (i1);
4542 tree max2 = TYPE_MAX_VALUE (i2);
4544 /* The minimum/maximum values have to be the same. */
4547 && ((TREE_CODE (min1) == PLACEHOLDER_EXPR
4548 && TREE_CODE (min2) == PLACEHOLDER_EXPR)
4549 || operand_equal_p (min1, min2, 0))))
4552 && ((TREE_CODE (max1) == PLACEHOLDER_EXPR
4553 && TREE_CODE (max2) == PLACEHOLDER_EXPR)
4554 || operand_equal_p (max1, max2, 0)))))
4562 /* Method types should belong to the same class. */
4563 if (!gimple_canonical_types_compatible_p
4564 (TYPE_METHOD_BASETYPE (t1), TYPE_METHOD_BASETYPE (t2)))
4570 /* Function types are the same if the return type and arguments types
4572 if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2)))
4575 if (!comp_type_attributes (t1, t2))
4578 if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2))
4582 tree parms1, parms2;
4584 for (parms1 = TYPE_ARG_TYPES (t1), parms2 = TYPE_ARG_TYPES (t2);
4586 parms1 = TREE_CHAIN (parms1), parms2 = TREE_CHAIN (parms2))
4588 if (!gimple_canonical_types_compatible_p
4589 (TREE_VALUE (parms1), TREE_VALUE (parms2)))
4593 if (parms1 || parms2)
4601 case QUAL_UNION_TYPE:
4605 /* For aggregate types, all the fields must be the same. */
4606 for (f1 = TYPE_FIELDS (t1), f2 = TYPE_FIELDS (t2);
4608 f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
4610 /* Skip non-fields. */
4611 while (f1 && TREE_CODE (f1) != FIELD_DECL)
4612 f1 = TREE_CHAIN (f1);
4613 while (f2 && TREE_CODE (f2) != FIELD_DECL)
4614 f2 = TREE_CHAIN (f2);
4617 /* The fields must have the same name, offset and type. */
4618 if (DECL_NONADDRESSABLE_P (f1) != DECL_NONADDRESSABLE_P (f2)
4619 || !gimple_compare_field_offset (f1, f2)
4620 || !gimple_canonical_types_compatible_p
4621 (TREE_TYPE (f1), TREE_TYPE (f2)))
4625 /* If one aggregate has more fields than the other, they
4626 are not the same. */
4639 /* Returns nonzero if P1 and P2 are equal. */
4642 gimple_canonical_type_eq (const void *p1, const void *p2)
4644 const_tree t1 = (const_tree) p1;
4645 const_tree t2 = (const_tree) p2;
4646 return gimple_canonical_types_compatible_p (CONST_CAST_TREE (t1),
4647 CONST_CAST_TREE (t2));
4650 /* Register type T in the global type table gimple_types.
4651 If another type T', compatible with T, already existed in
4652 gimple_types then return T', otherwise return T. This is used by
4653 LTO to merge identical types read from different TUs.
4655 ??? This merging does not exactly match how the tree.c middle-end
4656 functions will assign TYPE_CANONICAL when new types are created
4657 during optimization (which at least happens for pointer and array
4661 gimple_register_canonical_type (tree t)
4665 gcc_assert (TYPE_P (t));
4667 if (TYPE_CANONICAL (t))
4668 return TYPE_CANONICAL (t);
4670 if (gimple_canonical_types == NULL)
4671 gimple_canonical_types = htab_create_ggc (16381, gimple_canonical_type_hash,
4672 gimple_canonical_type_eq, 0);
4674 slot = htab_find_slot (gimple_canonical_types, t, INSERT);
4676 && *(tree *)slot != t)
4678 tree new_type = (tree) *((tree *) slot);
4680 TYPE_CANONICAL (t) = new_type;
4685 TYPE_CANONICAL (t) = t;
4693 /* Show statistics on references to the global type table gimple_types. */
4696 print_gimple_types_stats (void)
4699 fprintf (stderr, "GIMPLE type table: size %ld, %ld elements, "
4700 "%ld searches, %ld collisions (ratio: %f)\n",
4701 (long) htab_size (gimple_types),
4702 (long) htab_elements (gimple_types),
4703 (long) gimple_types->searches,
4704 (long) gimple_types->collisions,
4705 htab_collisions (gimple_types));
4707 fprintf (stderr, "GIMPLE type table is empty\n");
4708 if (type_hash_cache)
4709 fprintf (stderr, "GIMPLE type hash table: size %ld, %ld elements, "
4710 "%ld searches, %ld collisions (ratio: %f)\n",
4711 (long) htab_size (type_hash_cache),
4712 (long) htab_elements (type_hash_cache),
4713 (long) type_hash_cache->searches,
4714 (long) type_hash_cache->collisions,
4715 htab_collisions (type_hash_cache));
4717 fprintf (stderr, "GIMPLE type hash table is empty\n");
4718 if (gimple_canonical_types)
4719 fprintf (stderr, "GIMPLE canonical type table: size %ld, %ld elements, "
4720 "%ld searches, %ld collisions (ratio: %f)\n",
4721 (long) htab_size (gimple_canonical_types),
4722 (long) htab_elements (gimple_canonical_types),
4723 (long) gimple_canonical_types->searches,
4724 (long) gimple_canonical_types->collisions,
4725 htab_collisions (gimple_canonical_types));
4727 fprintf (stderr, "GIMPLE canonical type table is empty\n");
4728 if (canonical_type_hash_cache)
4729 fprintf (stderr, "GIMPLE canonical type hash table: size %ld, %ld elements, "
4730 "%ld searches, %ld collisions (ratio: %f)\n",
4731 (long) htab_size (canonical_type_hash_cache),
4732 (long) htab_elements (canonical_type_hash_cache),
4733 (long) canonical_type_hash_cache->searches,
4734 (long) canonical_type_hash_cache->collisions,
4735 htab_collisions (canonical_type_hash_cache));
4737 fprintf (stderr, "GIMPLE canonical type hash table is empty\n");
4740 /* Free the gimple type hashtables used for LTO type merging. */
4743 free_gimple_type_tables (void)
4745 /* Last chance to print stats for the tables. */
4746 if (flag_lto_report)
4747 print_gimple_types_stats ();
4751 htab_delete (gimple_types);
4752 gimple_types = NULL;
4754 if (gimple_canonical_types)
4756 htab_delete (gimple_canonical_types);
4757 gimple_canonical_types = NULL;
4759 if (type_hash_cache)
4761 htab_delete (type_hash_cache);
4762 type_hash_cache = NULL;
4764 if (canonical_type_hash_cache)
4766 htab_delete (canonical_type_hash_cache);
4767 canonical_type_hash_cache = NULL;
4769 if (type_pair_cache)
4771 free (type_pair_cache);
4772 type_pair_cache = NULL;
4774 gimple_type_leader = NULL;
4778 /* Return a type the same as TYPE except unsigned or
4779 signed according to UNSIGNEDP. */
4782 gimple_signed_or_unsigned_type (bool unsignedp, tree type)
4786 type1 = TYPE_MAIN_VARIANT (type);
4787 if (type1 == signed_char_type_node
4788 || type1 == char_type_node
4789 || type1 == unsigned_char_type_node)
4790 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
4791 if (type1 == integer_type_node || type1 == unsigned_type_node)
4792 return unsignedp ? unsigned_type_node : integer_type_node;
4793 if (type1 == short_integer_type_node || type1 == short_unsigned_type_node)
4794 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
4795 if (type1 == long_integer_type_node || type1 == long_unsigned_type_node)
4796 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
4797 if (type1 == long_long_integer_type_node
4798 || type1 == long_long_unsigned_type_node)
4800 ? long_long_unsigned_type_node
4801 : long_long_integer_type_node;
4802 if (int128_integer_type_node && (type1 == int128_integer_type_node || type1 == int128_unsigned_type_node))
4804 ? int128_unsigned_type_node
4805 : int128_integer_type_node;
4806 #if HOST_BITS_PER_WIDE_INT >= 64
4807 if (type1 == intTI_type_node || type1 == unsigned_intTI_type_node)
4808 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
4810 if (type1 == intDI_type_node || type1 == unsigned_intDI_type_node)
4811 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
4812 if (type1 == intSI_type_node || type1 == unsigned_intSI_type_node)
4813 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
4814 if (type1 == intHI_type_node || type1 == unsigned_intHI_type_node)
4815 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
4816 if (type1 == intQI_type_node || type1 == unsigned_intQI_type_node)
4817 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
4819 #define GIMPLE_FIXED_TYPES(NAME) \
4820 if (type1 == short_ ## NAME ## _type_node \
4821 || type1 == unsigned_short_ ## NAME ## _type_node) \
4822 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
4823 : short_ ## NAME ## _type_node; \
4824 if (type1 == NAME ## _type_node \
4825 || type1 == unsigned_ ## NAME ## _type_node) \
4826 return unsignedp ? unsigned_ ## NAME ## _type_node \
4827 : NAME ## _type_node; \
4828 if (type1 == long_ ## NAME ## _type_node \
4829 || type1 == unsigned_long_ ## NAME ## _type_node) \
4830 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
4831 : long_ ## NAME ## _type_node; \
4832 if (type1 == long_long_ ## NAME ## _type_node \
4833 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
4834 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
4835 : long_long_ ## NAME ## _type_node;
4837 #define GIMPLE_FIXED_MODE_TYPES(NAME) \
4838 if (type1 == NAME ## _type_node \
4839 || type1 == u ## NAME ## _type_node) \
4840 return unsignedp ? u ## NAME ## _type_node \
4841 : NAME ## _type_node;
4843 #define GIMPLE_FIXED_TYPES_SAT(NAME) \
4844 if (type1 == sat_ ## short_ ## NAME ## _type_node \
4845 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
4846 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
4847 : sat_ ## short_ ## NAME ## _type_node; \
4848 if (type1 == sat_ ## NAME ## _type_node \
4849 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
4850 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
4851 : sat_ ## NAME ## _type_node; \
4852 if (type1 == sat_ ## long_ ## NAME ## _type_node \
4853 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
4854 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
4855 : sat_ ## long_ ## NAME ## _type_node; \
4856 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
4857 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
4858 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
4859 : sat_ ## long_long_ ## NAME ## _type_node;
4861 #define GIMPLE_FIXED_MODE_TYPES_SAT(NAME) \
4862 if (type1 == sat_ ## NAME ## _type_node \
4863 || type1 == sat_ ## u ## NAME ## _type_node) \
4864 return unsignedp ? sat_ ## u ## NAME ## _type_node \
4865 : sat_ ## NAME ## _type_node;
4867 GIMPLE_FIXED_TYPES (fract);
4868 GIMPLE_FIXED_TYPES_SAT (fract);
4869 GIMPLE_FIXED_TYPES (accum);
4870 GIMPLE_FIXED_TYPES_SAT (accum);
4872 GIMPLE_FIXED_MODE_TYPES (qq);
4873 GIMPLE_FIXED_MODE_TYPES (hq);
4874 GIMPLE_FIXED_MODE_TYPES (sq);
4875 GIMPLE_FIXED_MODE_TYPES (dq);
4876 GIMPLE_FIXED_MODE_TYPES (tq);
4877 GIMPLE_FIXED_MODE_TYPES_SAT (qq);
4878 GIMPLE_FIXED_MODE_TYPES_SAT (hq);
4879 GIMPLE_FIXED_MODE_TYPES_SAT (sq);
4880 GIMPLE_FIXED_MODE_TYPES_SAT (dq);
4881 GIMPLE_FIXED_MODE_TYPES_SAT (tq);
4882 GIMPLE_FIXED_MODE_TYPES (ha);
4883 GIMPLE_FIXED_MODE_TYPES (sa);
4884 GIMPLE_FIXED_MODE_TYPES (da);
4885 GIMPLE_FIXED_MODE_TYPES (ta);
4886 GIMPLE_FIXED_MODE_TYPES_SAT (ha);
4887 GIMPLE_FIXED_MODE_TYPES_SAT (sa);
4888 GIMPLE_FIXED_MODE_TYPES_SAT (da);
4889 GIMPLE_FIXED_MODE_TYPES_SAT (ta);
4891 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
4892 the precision; they have precision set to match their range, but
4893 may use a wider mode to match an ABI. If we change modes, we may
4894 wind up with bad conversions. For INTEGER_TYPEs in C, must check
4895 the precision as well, so as to yield correct results for
4896 bit-field types. C++ does not have these separate bit-field
4897 types, and producing a signed or unsigned variant of an
4898 ENUMERAL_TYPE may cause other problems as well. */
4899 if (!INTEGRAL_TYPE_P (type)
4900 || TYPE_UNSIGNED (type) == unsignedp)
4903 #define TYPE_OK(node) \
4904 (TYPE_MODE (type) == TYPE_MODE (node) \
4905 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
4906 if (TYPE_OK (signed_char_type_node))
4907 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
4908 if (TYPE_OK (integer_type_node))
4909 return unsignedp ? unsigned_type_node : integer_type_node;
4910 if (TYPE_OK (short_integer_type_node))
4911 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
4912 if (TYPE_OK (long_integer_type_node))
4913 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
4914 if (TYPE_OK (long_long_integer_type_node))
4916 ? long_long_unsigned_type_node
4917 : long_long_integer_type_node);
4918 if (int128_integer_type_node && TYPE_OK (int128_integer_type_node))
4920 ? int128_unsigned_type_node
4921 : int128_integer_type_node);
4923 #if HOST_BITS_PER_WIDE_INT >= 64
4924 if (TYPE_OK (intTI_type_node))
4925 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
4927 if (TYPE_OK (intDI_type_node))
4928 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
4929 if (TYPE_OK (intSI_type_node))
4930 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
4931 if (TYPE_OK (intHI_type_node))
4932 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
4933 if (TYPE_OK (intQI_type_node))
4934 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
4936 #undef GIMPLE_FIXED_TYPES
4937 #undef GIMPLE_FIXED_MODE_TYPES
4938 #undef GIMPLE_FIXED_TYPES_SAT
4939 #undef GIMPLE_FIXED_MODE_TYPES_SAT
4942 return build_nonstandard_integer_type (TYPE_PRECISION (type), unsignedp);
4946 /* Return an unsigned type the same as TYPE in other respects. */
4949 gimple_unsigned_type (tree type)
4951 return gimple_signed_or_unsigned_type (true, type);
4955 /* Return a signed type the same as TYPE in other respects. */
4958 gimple_signed_type (tree type)
4960 return gimple_signed_or_unsigned_type (false, type);
4964 /* Return the typed-based alias set for T, which may be an expression
4965 or a type. Return -1 if we don't do anything special. */
4968 gimple_get_alias_set (tree t)
4972 /* Permit type-punning when accessing a union, provided the access
4973 is directly through the union. For example, this code does not
4974 permit taking the address of a union member and then storing
4975 through it. Even the type-punning allowed here is a GCC
4976 extension, albeit a common and useful one; the C standard says
4977 that such accesses have implementation-defined behavior. */
4979 TREE_CODE (u) == COMPONENT_REF || TREE_CODE (u) == ARRAY_REF;
4980 u = TREE_OPERAND (u, 0))
4981 if (TREE_CODE (u) == COMPONENT_REF
4982 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u, 0))) == UNION_TYPE)
4985 /* That's all the expressions we handle specially. */
4989 /* For convenience, follow the C standard when dealing with
4990 character types. Any object may be accessed via an lvalue that
4991 has character type. */
4992 if (t == char_type_node
4993 || t == signed_char_type_node
4994 || t == unsigned_char_type_node)
4997 /* Allow aliasing between signed and unsigned variants of the same
4998 type. We treat the signed variant as canonical. */
4999 if (TREE_CODE (t) == INTEGER_TYPE && TYPE_UNSIGNED (t))
5001 tree t1 = gimple_signed_type (t);
5003 /* t1 == t can happen for boolean nodes which are always unsigned. */
5005 return get_alias_set (t1);
5012 /* Data structure used to count the number of dereferences to PTR
5013 inside an expression. */
5017 unsigned num_stores;
5021 /* Helper for count_uses_and_derefs. Called by walk_tree to look for
5022 (ALIGN/MISALIGNED_)INDIRECT_REF nodes for the pointer passed in DATA. */
5025 count_ptr_derefs (tree *tp, int *walk_subtrees, void *data)
5027 struct walk_stmt_info *wi_p = (struct walk_stmt_info *) data;
5028 struct count_ptr_d *count_p = (struct count_ptr_d *) wi_p->info;
5030 /* Do not walk inside ADDR_EXPR nodes. In the expression &ptr->fld,
5031 pointer 'ptr' is *not* dereferenced, it is simply used to compute
5032 the address of 'fld' as 'ptr + offsetof(fld)'. */
5033 if (TREE_CODE (*tp) == ADDR_EXPR)
5039 if (TREE_CODE (*tp) == MEM_REF && TREE_OPERAND (*tp, 0) == count_p->ptr)
5042 count_p->num_stores++;
5044 count_p->num_loads++;
5050 /* Count the number of direct and indirect uses for pointer PTR in
5051 statement STMT. The number of direct uses is stored in
5052 *NUM_USES_P. Indirect references are counted separately depending
5053 on whether they are store or load operations. The counts are
5054 stored in *NUM_STORES_P and *NUM_LOADS_P. */
5057 count_uses_and_derefs (tree ptr, gimple stmt, unsigned *num_uses_p,
5058 unsigned *num_loads_p, unsigned *num_stores_p)
5067 /* Find out the total number of uses of PTR in STMT. */
5068 FOR_EACH_SSA_TREE_OPERAND (use, stmt, i, SSA_OP_USE)
5072 /* Now count the number of indirect references to PTR. This is
5073 truly awful, but we don't have much choice. There are no parent
5074 pointers inside INDIRECT_REFs, so an expression like
5075 '*x_1 = foo (x_1, *x_1)' needs to be traversed piece by piece to
5076 find all the indirect and direct uses of x_1 inside. The only
5077 shortcut we can take is the fact that GIMPLE only allows
5078 INDIRECT_REFs inside the expressions below. */
5079 if (is_gimple_assign (stmt)
5080 || gimple_code (stmt) == GIMPLE_RETURN
5081 || gimple_code (stmt) == GIMPLE_ASM
5082 || is_gimple_call (stmt))
5084 struct walk_stmt_info wi;
5085 struct count_ptr_d count;
5088 count.num_stores = 0;
5089 count.num_loads = 0;
5091 memset (&wi, 0, sizeof (wi));
5093 walk_gimple_op (stmt, count_ptr_derefs, &wi);
5095 *num_stores_p = count.num_stores;
5096 *num_loads_p = count.num_loads;
5099 gcc_assert (*num_uses_p >= *num_loads_p + *num_stores_p);
5102 /* From a tree operand OP return the base of a load or store operation
5103 or NULL_TREE if OP is not a load or a store. */
5106 get_base_loadstore (tree op)
5108 while (handled_component_p (op))
5109 op = TREE_OPERAND (op, 0);
5111 || INDIRECT_REF_P (op)
5112 || TREE_CODE (op) == MEM_REF
5113 || TREE_CODE (op) == TARGET_MEM_REF)
5118 /* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE and
5119 VISIT_ADDR if non-NULL on loads, store and address-taken operands
5120 passing the STMT, the base of the operand and DATA to it. The base
5121 will be either a decl, an indirect reference (including TARGET_MEM_REF)
5122 or the argument of an address expression.
5123 Returns the results of these callbacks or'ed. */
5126 walk_stmt_load_store_addr_ops (gimple stmt, void *data,
5127 bool (*visit_load)(gimple, tree, void *),
5128 bool (*visit_store)(gimple, tree, void *),
5129 bool (*visit_addr)(gimple, tree, void *))
5133 if (gimple_assign_single_p (stmt))
5138 lhs = get_base_loadstore (gimple_assign_lhs (stmt));
5140 ret |= visit_store (stmt, lhs, data);
5142 rhs = gimple_assign_rhs1 (stmt);
5143 while (handled_component_p (rhs))
5144 rhs = TREE_OPERAND (rhs, 0);
5147 if (TREE_CODE (rhs) == ADDR_EXPR)
5148 ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), data);
5149 else if (TREE_CODE (rhs) == TARGET_MEM_REF
5150 && TREE_CODE (TMR_BASE (rhs)) == ADDR_EXPR)
5151 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (rhs), 0), data);
5152 else if (TREE_CODE (rhs) == OBJ_TYPE_REF
5153 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs)) == ADDR_EXPR)
5154 ret |= visit_addr (stmt, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs),
5156 else if (TREE_CODE (rhs) == CONSTRUCTOR)
5161 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (rhs), ix, val)
5162 if (TREE_CODE (val) == ADDR_EXPR)
5163 ret |= visit_addr (stmt, TREE_OPERAND (val, 0), data);
5164 else if (TREE_CODE (val) == OBJ_TYPE_REF
5165 && TREE_CODE (OBJ_TYPE_REF_OBJECT (val)) == ADDR_EXPR)
5166 ret |= visit_addr (stmt,
5167 TREE_OPERAND (OBJ_TYPE_REF_OBJECT (val),
5170 lhs = gimple_assign_lhs (stmt);
5171 if (TREE_CODE (lhs) == TARGET_MEM_REF
5172 && TREE_CODE (TMR_BASE (lhs)) == ADDR_EXPR)
5173 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (lhs), 0), data);
5177 rhs = get_base_loadstore (rhs);
5179 ret |= visit_load (stmt, rhs, data);
5183 && (is_gimple_assign (stmt)
5184 || gimple_code (stmt) == GIMPLE_COND))
5186 for (i = 0; i < gimple_num_ops (stmt); ++i)
5188 tree op = gimple_op (stmt, i);
5189 if (op == NULL_TREE)
5191 else if (TREE_CODE (op) == ADDR_EXPR)
5192 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
5193 /* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
5194 tree with two operands. */
5195 else if (i == 1 && COMPARISON_CLASS_P (op))
5197 if (TREE_CODE (TREE_OPERAND (op, 0)) == ADDR_EXPR)
5198 ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 0),
5200 if (TREE_CODE (TREE_OPERAND (op, 1)) == ADDR_EXPR)
5201 ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 1),
5206 else if (is_gimple_call (stmt))
5210 tree lhs = gimple_call_lhs (stmt);
5213 lhs = get_base_loadstore (lhs);
5215 ret |= visit_store (stmt, lhs, data);
5218 if (visit_load || visit_addr)
5219 for (i = 0; i < gimple_call_num_args (stmt); ++i)
5221 tree rhs = gimple_call_arg (stmt, i);
5223 && TREE_CODE (rhs) == ADDR_EXPR)
5224 ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), data);
5225 else if (visit_load)
5227 rhs = get_base_loadstore (rhs);
5229 ret |= visit_load (stmt, rhs, data);
5233 && gimple_call_chain (stmt)
5234 && TREE_CODE (gimple_call_chain (stmt)) == ADDR_EXPR)
5235 ret |= visit_addr (stmt, TREE_OPERAND (gimple_call_chain (stmt), 0),
5238 && gimple_call_return_slot_opt_p (stmt)
5239 && gimple_call_lhs (stmt) != NULL_TREE
5240 && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (stmt))))
5241 ret |= visit_addr (stmt, gimple_call_lhs (stmt), data);
5243 else if (gimple_code (stmt) == GIMPLE_ASM)
5246 const char *constraint;
5247 const char **oconstraints;
5248 bool allows_mem, allows_reg, is_inout;
5249 noutputs = gimple_asm_noutputs (stmt);
5250 oconstraints = XALLOCAVEC (const char *, noutputs);
5251 if (visit_store || visit_addr)
5252 for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
5254 tree link = gimple_asm_output_op (stmt, i);
5255 tree op = get_base_loadstore (TREE_VALUE (link));
5256 if (op && visit_store)
5257 ret |= visit_store (stmt, op, data);
5260 constraint = TREE_STRING_POINTER
5261 (TREE_VALUE (TREE_PURPOSE (link)));
5262 oconstraints[i] = constraint;
5263 parse_output_constraint (&constraint, i, 0, 0, &allows_mem,
5264 &allows_reg, &is_inout);
5265 if (op && !allows_reg && allows_mem)
5266 ret |= visit_addr (stmt, op, data);
5269 if (visit_load || visit_addr)
5270 for (i = 0; i < gimple_asm_ninputs (stmt); ++i)
5272 tree link = gimple_asm_input_op (stmt, i);
5273 tree op = TREE_VALUE (link);
5275 && TREE_CODE (op) == ADDR_EXPR)
5276 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
5277 else if (visit_load || visit_addr)
5279 op = get_base_loadstore (op);
5283 ret |= visit_load (stmt, op, data);
5286 constraint = TREE_STRING_POINTER
5287 (TREE_VALUE (TREE_PURPOSE (link)));
5288 parse_input_constraint (&constraint, 0, 0, noutputs,
5290 &allows_mem, &allows_reg);
5291 if (!allows_reg && allows_mem)
5292 ret |= visit_addr (stmt, op, data);
5298 else if (gimple_code (stmt) == GIMPLE_RETURN)
5300 tree op = gimple_return_retval (stmt);
5304 && TREE_CODE (op) == ADDR_EXPR)
5305 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
5306 else if (visit_load)
5308 op = get_base_loadstore (op);
5310 ret |= visit_load (stmt, op, data);
5315 && gimple_code (stmt) == GIMPLE_PHI)
5317 for (i = 0; i < gimple_phi_num_args (stmt); ++i)
5319 tree op = PHI_ARG_DEF (stmt, i);
5320 if (TREE_CODE (op) == ADDR_EXPR)
5321 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
5328 /* Like walk_stmt_load_store_addr_ops but with NULL visit_addr. IPA-CP
5329 should make a faster clone for this case. */
5332 walk_stmt_load_store_ops (gimple stmt, void *data,
5333 bool (*visit_load)(gimple, tree, void *),
5334 bool (*visit_store)(gimple, tree, void *))
5336 return walk_stmt_load_store_addr_ops (stmt, data,
5337 visit_load, visit_store, NULL);
5340 /* Helper for gimple_ior_addresses_taken_1. */
5343 gimple_ior_addresses_taken_1 (gimple stmt ATTRIBUTE_UNUSED,
5344 tree addr, void *data)
5346 bitmap addresses_taken = (bitmap)data;
5347 addr = get_base_address (addr);
5351 bitmap_set_bit (addresses_taken, DECL_UID (addr));
5357 /* Set the bit for the uid of all decls that have their address taken
5358 in STMT in the ADDRESSES_TAKEN bitmap. Returns true if there
5359 were any in this stmt. */
5362 gimple_ior_addresses_taken (bitmap addresses_taken, gimple stmt)
5364 return walk_stmt_load_store_addr_ops (stmt, addresses_taken, NULL, NULL,
5365 gimple_ior_addresses_taken_1);
5369 /* Return a printable name for symbol DECL. */
5372 gimple_decl_printable_name (tree decl, int verbosity)
5374 if (!DECL_NAME (decl))
5377 if (DECL_ASSEMBLER_NAME_SET_P (decl))
5379 const char *str, *mangled_str;
5380 int dmgl_opts = DMGL_NO_OPTS;
5384 dmgl_opts = DMGL_VERBOSE
5388 if (TREE_CODE (decl) == FUNCTION_DECL)
5389 dmgl_opts |= DMGL_PARAMS;
5392 mangled_str = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5393 str = cplus_demangle_v3 (mangled_str, dmgl_opts);
5394 return (str) ? str : mangled_str;
5397 return IDENTIFIER_POINTER (DECL_NAME (decl));
5400 /* Return true when STMT is builtins call to CODE. */
5403 gimple_call_builtin_p (gimple stmt, enum built_in_function code)
5406 return (is_gimple_call (stmt)
5407 && (fndecl = gimple_call_fndecl (stmt)) != NULL
5408 && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
5409 && DECL_FUNCTION_CODE (fndecl) == code);
5412 /* Return true if STMT clobbers memory. STMT is required to be a
5416 gimple_asm_clobbers_memory_p (const_gimple stmt)
5420 for (i = 0; i < gimple_asm_nclobbers (stmt); i++)
5422 tree op = gimple_asm_clobber_op (stmt, i);
5423 if (strcmp (TREE_STRING_POINTER (TREE_VALUE (op)), "memory") == 0)
5429 #include "gt-gimple.h"