* config/darwin.c (darwin_assemble_visibility): Treat
[official-gcc.git] / gcc / gimple.c
blob6088682e04c760dcca216c4c14a7f705551de64f
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
11 version.
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
16 for more details.
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/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "target.h"
27 #include "tree.h"
28 #include "ggc.h"
29 #include "hard-reg-set.h"
30 #include "basic-block.h"
31 #include "gimple.h"
32 #include "diagnostic.h"
33 #include "tree-flow.h"
34 #include "value-prof.h"
35 #include "flags.h"
36 #include "alias.h"
37 #include "demangle.h"
38 #include "langhooks.h"
40 /* Global canonical type table. */
41 static GTY((if_marked ("ggc_marked_p"), param_is (union tree_node)))
42 htab_t gimple_canonical_types;
43 static GTY((if_marked ("tree_int_map_marked_p"), param_is (struct tree_int_map)))
44 htab_t canonical_type_hash_cache;
46 /* All the tuples have their operand vector (if present) at the very bottom
47 of the structure. Therefore, the offset required to find the
48 operands vector the size of the structure minus the size of the 1
49 element tree array at the end (see gimple_ops). */
50 #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) \
51 (HAS_TREE_OP ? sizeof (struct STRUCT) - sizeof (tree) : 0),
52 EXPORTED_CONST size_t gimple_ops_offset_[] = {
53 #include "gsstruct.def"
55 #undef DEFGSSTRUCT
57 #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) sizeof(struct STRUCT),
58 static const size_t gsstruct_code_size[] = {
59 #include "gsstruct.def"
61 #undef DEFGSSTRUCT
63 #define DEFGSCODE(SYM, NAME, GSSCODE) NAME,
64 const char *const gimple_code_name[] = {
65 #include "gimple.def"
67 #undef DEFGSCODE
69 #define DEFGSCODE(SYM, NAME, GSSCODE) GSSCODE,
70 EXPORTED_CONST enum gimple_statement_structure_enum gss_for_code_[] = {
71 #include "gimple.def"
73 #undef DEFGSCODE
75 /* Gimple stats. */
77 int gimple_alloc_counts[(int) gimple_alloc_kind_all];
78 int gimple_alloc_sizes[(int) gimple_alloc_kind_all];
80 /* Keep in sync with gimple.h:enum gimple_alloc_kind. */
81 static const char * const gimple_alloc_kind_names[] = {
82 "assignments",
83 "phi nodes",
84 "conditionals",
85 "everything else"
88 /* Private API manipulation functions shared only with some
89 other files. */
90 extern void gimple_set_stored_syms (gimple, bitmap, bitmap_obstack *);
91 extern void gimple_set_loaded_syms (gimple, bitmap, bitmap_obstack *);
93 /* Gimple tuple constructors.
94 Note: Any constructor taking a ``gimple_seq'' as a parameter, can
95 be passed a NULL to start with an empty sequence. */
97 /* Set the code for statement G to CODE. */
99 static inline void
100 gimple_set_code (gimple g, enum gimple_code code)
102 g->gsbase.code = code;
105 /* Return the number of bytes needed to hold a GIMPLE statement with
106 code CODE. */
108 static inline size_t
109 gimple_size (enum gimple_code code)
111 return gsstruct_code_size[gss_for_code (code)];
114 /* Allocate memory for a GIMPLE statement with code CODE and NUM_OPS
115 operands. */
117 gimple
118 gimple_alloc_stat (enum gimple_code code, unsigned num_ops MEM_STAT_DECL)
120 size_t size;
121 gimple stmt;
123 size = gimple_size (code);
124 if (num_ops > 0)
125 size += sizeof (tree) * (num_ops - 1);
127 if (GATHER_STATISTICS)
129 enum gimple_alloc_kind kind = gimple_alloc_kind (code);
130 gimple_alloc_counts[(int) kind]++;
131 gimple_alloc_sizes[(int) kind] += size;
134 stmt = ggc_alloc_cleared_gimple_statement_d_stat (size PASS_MEM_STAT);
135 gimple_set_code (stmt, code);
136 gimple_set_num_ops (stmt, num_ops);
138 /* Do not call gimple_set_modified here as it has other side
139 effects and this tuple is still not completely built. */
140 stmt->gsbase.modified = 1;
141 gimple_init_singleton (stmt);
143 return stmt;
146 /* Set SUBCODE to be the code of the expression computed by statement G. */
148 static inline void
149 gimple_set_subcode (gimple g, unsigned subcode)
151 /* We only have 16 bits for the RHS code. Assert that we are not
152 overflowing it. */
153 gcc_assert (subcode < (1 << 16));
154 g->gsbase.subcode = subcode;
159 /* Build a tuple with operands. CODE is the statement to build (which
160 must be one of the GIMPLE_WITH_OPS tuples). SUBCODE is the sub-code
161 for the new tuple. NUM_OPS is the number of operands to allocate. */
163 #define gimple_build_with_ops(c, s, n) \
164 gimple_build_with_ops_stat (c, s, n MEM_STAT_INFO)
166 static gimple
167 gimple_build_with_ops_stat (enum gimple_code code, unsigned subcode,
168 unsigned num_ops MEM_STAT_DECL)
170 gimple s = gimple_alloc_stat (code, num_ops PASS_MEM_STAT);
171 gimple_set_subcode (s, subcode);
173 return s;
177 /* Build a GIMPLE_RETURN statement returning RETVAL. */
179 gimple
180 gimple_build_return (tree retval)
182 gimple s = gimple_build_with_ops (GIMPLE_RETURN, ERROR_MARK, 1);
183 if (retval)
184 gimple_return_set_retval (s, retval);
185 return s;
188 /* Reset alias information on call S. */
190 void
191 gimple_call_reset_alias_info (gimple s)
193 if (gimple_call_flags (s) & ECF_CONST)
194 memset (gimple_call_use_set (s), 0, sizeof (struct pt_solution));
195 else
196 pt_solution_reset (gimple_call_use_set (s));
197 if (gimple_call_flags (s) & (ECF_CONST|ECF_PURE|ECF_NOVOPS))
198 memset (gimple_call_clobber_set (s), 0, sizeof (struct pt_solution));
199 else
200 pt_solution_reset (gimple_call_clobber_set (s));
203 /* Helper for gimple_build_call, gimple_build_call_valist,
204 gimple_build_call_vec and gimple_build_call_from_tree. Build the basic
205 components of a GIMPLE_CALL statement to function FN with NARGS
206 arguments. */
208 static inline gimple
209 gimple_build_call_1 (tree fn, unsigned nargs)
211 gimple s = gimple_build_with_ops (GIMPLE_CALL, ERROR_MARK, nargs + 3);
212 if (TREE_CODE (fn) == FUNCTION_DECL)
213 fn = build_fold_addr_expr (fn);
214 gimple_set_op (s, 1, fn);
215 gimple_call_set_fntype (s, TREE_TYPE (TREE_TYPE (fn)));
216 gimple_call_reset_alias_info (s);
217 return s;
221 /* Build a GIMPLE_CALL statement to function FN with the arguments
222 specified in vector ARGS. */
224 gimple
225 gimple_build_call_vec (tree fn, VEC(tree, heap) *args)
227 unsigned i;
228 unsigned nargs = VEC_length (tree, args);
229 gimple call = gimple_build_call_1 (fn, nargs);
231 for (i = 0; i < nargs; i++)
232 gimple_call_set_arg (call, i, VEC_index (tree, args, i));
234 return call;
238 /* Build a GIMPLE_CALL statement to function FN. NARGS is the number of
239 arguments. The ... are the arguments. */
241 gimple
242 gimple_build_call (tree fn, unsigned nargs, ...)
244 va_list ap;
245 gimple call;
246 unsigned i;
248 gcc_assert (TREE_CODE (fn) == FUNCTION_DECL || is_gimple_call_addr (fn));
250 call = gimple_build_call_1 (fn, nargs);
252 va_start (ap, nargs);
253 for (i = 0; i < nargs; i++)
254 gimple_call_set_arg (call, i, va_arg (ap, tree));
255 va_end (ap);
257 return call;
261 /* Build a GIMPLE_CALL statement to function FN. NARGS is the number of
262 arguments. AP contains the arguments. */
264 gimple
265 gimple_build_call_valist (tree fn, unsigned nargs, va_list ap)
267 gimple call;
268 unsigned i;
270 gcc_assert (TREE_CODE (fn) == FUNCTION_DECL || is_gimple_call_addr (fn));
272 call = gimple_build_call_1 (fn, nargs);
274 for (i = 0; i < nargs; i++)
275 gimple_call_set_arg (call, i, va_arg (ap, tree));
277 return call;
281 /* Helper for gimple_build_call_internal and gimple_build_call_internal_vec.
282 Build the basic components of a GIMPLE_CALL statement to internal
283 function FN with NARGS arguments. */
285 static inline gimple
286 gimple_build_call_internal_1 (enum internal_fn fn, unsigned nargs)
288 gimple s = gimple_build_with_ops (GIMPLE_CALL, ERROR_MARK, nargs + 3);
289 s->gsbase.subcode |= GF_CALL_INTERNAL;
290 gimple_call_set_internal_fn (s, fn);
291 gimple_call_reset_alias_info (s);
292 return s;
296 /* Build a GIMPLE_CALL statement to internal function FN. NARGS is
297 the number of arguments. The ... are the arguments. */
299 gimple
300 gimple_build_call_internal (enum internal_fn fn, unsigned nargs, ...)
302 va_list ap;
303 gimple call;
304 unsigned i;
306 call = gimple_build_call_internal_1 (fn, nargs);
307 va_start (ap, nargs);
308 for (i = 0; i < nargs; i++)
309 gimple_call_set_arg (call, i, va_arg (ap, tree));
310 va_end (ap);
312 return call;
316 /* Build a GIMPLE_CALL statement to internal function FN with the arguments
317 specified in vector ARGS. */
319 gimple
320 gimple_build_call_internal_vec (enum internal_fn fn, VEC(tree, heap) *args)
322 unsigned i, nargs;
323 gimple call;
325 nargs = VEC_length (tree, args);
326 call = gimple_build_call_internal_1 (fn, nargs);
327 for (i = 0; i < nargs; i++)
328 gimple_call_set_arg (call, i, VEC_index (tree, args, i));
330 return call;
334 /* Build a GIMPLE_CALL statement from CALL_EXPR T. Note that T is
335 assumed to be in GIMPLE form already. Minimal checking is done of
336 this fact. */
338 gimple
339 gimple_build_call_from_tree (tree t)
341 unsigned i, nargs;
342 gimple call;
343 tree fndecl = get_callee_fndecl (t);
345 gcc_assert (TREE_CODE (t) == CALL_EXPR);
347 nargs = call_expr_nargs (t);
348 call = gimple_build_call_1 (fndecl ? fndecl : CALL_EXPR_FN (t), nargs);
350 for (i = 0; i < nargs; i++)
351 gimple_call_set_arg (call, i, CALL_EXPR_ARG (t, i));
353 gimple_set_block (call, TREE_BLOCK (t));
355 /* Carry all the CALL_EXPR flags to the new GIMPLE_CALL. */
356 gimple_call_set_chain (call, CALL_EXPR_STATIC_CHAIN (t));
357 gimple_call_set_tail (call, CALL_EXPR_TAILCALL (t));
358 gimple_call_set_return_slot_opt (call, CALL_EXPR_RETURN_SLOT_OPT (t));
359 if (fndecl
360 && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
361 && (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA
362 || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA_WITH_ALIGN))
363 gimple_call_set_alloca_for_var (call, CALL_ALLOCA_FOR_VAR_P (t));
364 else
365 gimple_call_set_from_thunk (call, CALL_FROM_THUNK_P (t));
366 gimple_call_set_va_arg_pack (call, CALL_EXPR_VA_ARG_PACK (t));
367 gimple_call_set_nothrow (call, TREE_NOTHROW (t));
368 gimple_set_no_warning (call, TREE_NO_WARNING (t));
370 return call;
374 /* Extract the operands and code for expression EXPR into *SUBCODE_P,
375 *OP1_P, *OP2_P and *OP3_P respectively. */
377 void
378 extract_ops_from_tree_1 (tree expr, enum tree_code *subcode_p, tree *op1_p,
379 tree *op2_p, tree *op3_p)
381 enum gimple_rhs_class grhs_class;
383 *subcode_p = TREE_CODE (expr);
384 grhs_class = get_gimple_rhs_class (*subcode_p);
386 if (grhs_class == GIMPLE_TERNARY_RHS)
388 *op1_p = TREE_OPERAND (expr, 0);
389 *op2_p = TREE_OPERAND (expr, 1);
390 *op3_p = TREE_OPERAND (expr, 2);
392 else if (grhs_class == GIMPLE_BINARY_RHS)
394 *op1_p = TREE_OPERAND (expr, 0);
395 *op2_p = TREE_OPERAND (expr, 1);
396 *op3_p = NULL_TREE;
398 else if (grhs_class == GIMPLE_UNARY_RHS)
400 *op1_p = TREE_OPERAND (expr, 0);
401 *op2_p = NULL_TREE;
402 *op3_p = NULL_TREE;
404 else if (grhs_class == GIMPLE_SINGLE_RHS)
406 *op1_p = expr;
407 *op2_p = NULL_TREE;
408 *op3_p = NULL_TREE;
410 else
411 gcc_unreachable ();
415 /* Build a GIMPLE_ASSIGN statement.
417 LHS of the assignment.
418 RHS of the assignment which can be unary or binary. */
420 gimple
421 gimple_build_assign_stat (tree lhs, tree rhs MEM_STAT_DECL)
423 enum tree_code subcode;
424 tree op1, op2, op3;
426 extract_ops_from_tree_1 (rhs, &subcode, &op1, &op2, &op3);
427 return gimple_build_assign_with_ops (subcode, lhs, op1, op2, op3
428 PASS_MEM_STAT);
432 /* Build a GIMPLE_ASSIGN statement with sub-code SUBCODE and operands
433 OP1 and OP2. If OP2 is NULL then SUBCODE must be of class
434 GIMPLE_UNARY_RHS or GIMPLE_SINGLE_RHS. */
436 gimple
437 gimple_build_assign_with_ops (enum tree_code subcode, tree lhs, tree op1,
438 tree op2, tree op3 MEM_STAT_DECL)
440 unsigned num_ops;
441 gimple p;
443 /* Need 1 operand for LHS and 1 or 2 for the RHS (depending on the
444 code). */
445 num_ops = get_gimple_rhs_num_ops (subcode) + 1;
447 p = gimple_build_with_ops_stat (GIMPLE_ASSIGN, (unsigned)subcode, num_ops
448 PASS_MEM_STAT);
449 gimple_assign_set_lhs (p, lhs);
450 gimple_assign_set_rhs1 (p, op1);
451 if (op2)
453 gcc_assert (num_ops > 2);
454 gimple_assign_set_rhs2 (p, op2);
457 if (op3)
459 gcc_assert (num_ops > 3);
460 gimple_assign_set_rhs3 (p, op3);
463 return p;
466 gimple
467 gimple_build_assign_with_ops (enum tree_code subcode, tree lhs, tree op1,
468 tree op2 MEM_STAT_DECL)
470 return gimple_build_assign_with_ops (subcode, lhs, op1, op2, NULL_TREE
471 PASS_MEM_STAT);
475 /* Build a new GIMPLE_ASSIGN tuple and append it to the end of *SEQ_P.
477 DST/SRC are the destination and source respectively. You can pass
478 ungimplified trees in DST or SRC, in which case they will be
479 converted to a gimple operand if necessary.
481 This function returns the newly created GIMPLE_ASSIGN tuple. */
483 gimple
484 gimplify_assign (tree dst, tree src, gimple_seq *seq_p)
486 tree t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
487 gimplify_and_add (t, seq_p);
488 ggc_free (t);
489 return gimple_seq_last_stmt (*seq_p);
493 /* Build a GIMPLE_COND statement.
495 PRED is the condition used to compare LHS and the RHS.
496 T_LABEL is the label to jump to if the condition is true.
497 F_LABEL is the label to jump to otherwise. */
499 gimple
500 gimple_build_cond (enum tree_code pred_code, tree lhs, tree rhs,
501 tree t_label, tree f_label)
503 gimple p;
505 gcc_assert (TREE_CODE_CLASS (pred_code) == tcc_comparison);
506 p = gimple_build_with_ops (GIMPLE_COND, pred_code, 4);
507 gimple_cond_set_lhs (p, lhs);
508 gimple_cond_set_rhs (p, rhs);
509 gimple_cond_set_true_label (p, t_label);
510 gimple_cond_set_false_label (p, f_label);
511 return p;
515 /* Extract operands for a GIMPLE_COND statement out of COND_EXPR tree COND. */
517 void
518 gimple_cond_get_ops_from_tree (tree cond, enum tree_code *code_p,
519 tree *lhs_p, tree *rhs_p)
521 gcc_assert (TREE_CODE_CLASS (TREE_CODE (cond)) == tcc_comparison
522 || TREE_CODE (cond) == TRUTH_NOT_EXPR
523 || is_gimple_min_invariant (cond)
524 || SSA_VAR_P (cond));
526 extract_ops_from_tree (cond, code_p, lhs_p, rhs_p);
528 /* Canonicalize conditionals of the form 'if (!VAL)'. */
529 if (*code_p == TRUTH_NOT_EXPR)
531 *code_p = EQ_EXPR;
532 gcc_assert (*lhs_p && *rhs_p == NULL_TREE);
533 *rhs_p = build_zero_cst (TREE_TYPE (*lhs_p));
535 /* Canonicalize conditionals of the form 'if (VAL)' */
536 else if (TREE_CODE_CLASS (*code_p) != tcc_comparison)
538 *code_p = NE_EXPR;
539 gcc_assert (*lhs_p && *rhs_p == NULL_TREE);
540 *rhs_p = build_zero_cst (TREE_TYPE (*lhs_p));
545 /* Build a GIMPLE_COND statement from the conditional expression tree
546 COND. T_LABEL and F_LABEL are as in gimple_build_cond. */
548 gimple
549 gimple_build_cond_from_tree (tree cond, tree t_label, tree f_label)
551 enum tree_code code;
552 tree lhs, rhs;
554 gimple_cond_get_ops_from_tree (cond, &code, &lhs, &rhs);
555 return gimple_build_cond (code, lhs, rhs, t_label, f_label);
558 /* Set code, lhs, and rhs of a GIMPLE_COND from a suitable
559 boolean expression tree COND. */
561 void
562 gimple_cond_set_condition_from_tree (gimple stmt, tree cond)
564 enum tree_code code;
565 tree lhs, rhs;
567 gimple_cond_get_ops_from_tree (cond, &code, &lhs, &rhs);
568 gimple_cond_set_condition (stmt, code, lhs, rhs);
571 /* Build a GIMPLE_LABEL statement for LABEL. */
573 gimple
574 gimple_build_label (tree label)
576 gimple p = gimple_build_with_ops (GIMPLE_LABEL, ERROR_MARK, 1);
577 gimple_label_set_label (p, label);
578 return p;
581 /* Build a GIMPLE_GOTO statement to label DEST. */
583 gimple
584 gimple_build_goto (tree dest)
586 gimple p = gimple_build_with_ops (GIMPLE_GOTO, ERROR_MARK, 1);
587 gimple_goto_set_dest (p, dest);
588 return p;
592 /* Build a GIMPLE_NOP statement. */
594 gimple
595 gimple_build_nop (void)
597 return gimple_alloc (GIMPLE_NOP, 0);
601 /* Build a GIMPLE_BIND statement.
602 VARS are the variables in BODY.
603 BLOCK is the containing block. */
605 gimple
606 gimple_build_bind (tree vars, gimple_seq body, tree block)
608 gimple p = gimple_alloc (GIMPLE_BIND, 0);
609 gimple_bind_set_vars (p, vars);
610 if (body)
611 gimple_bind_set_body (p, body);
612 if (block)
613 gimple_bind_set_block (p, block);
614 return p;
617 /* Helper function to set the simple fields of a asm stmt.
619 STRING is a pointer to a string that is the asm blocks assembly code.
620 NINPUT is the number of register inputs.
621 NOUTPUT is the number of register outputs.
622 NCLOBBERS is the number of clobbered registers.
625 static inline gimple
626 gimple_build_asm_1 (const char *string, unsigned ninputs, unsigned noutputs,
627 unsigned nclobbers, unsigned nlabels)
629 gimple p;
630 int size = strlen (string);
632 /* ASMs with labels cannot have outputs. This should have been
633 enforced by the front end. */
634 gcc_assert (nlabels == 0 || noutputs == 0);
636 p = gimple_build_with_ops (GIMPLE_ASM, ERROR_MARK,
637 ninputs + noutputs + nclobbers + nlabels);
639 p->gimple_asm.ni = ninputs;
640 p->gimple_asm.no = noutputs;
641 p->gimple_asm.nc = nclobbers;
642 p->gimple_asm.nl = nlabels;
643 p->gimple_asm.string = ggc_alloc_string (string, size);
645 if (GATHER_STATISTICS)
646 gimple_alloc_sizes[(int) gimple_alloc_kind (GIMPLE_ASM)] += size;
648 return p;
651 /* Build a GIMPLE_ASM statement.
653 STRING is the assembly code.
654 NINPUT is the number of register inputs.
655 NOUTPUT is the number of register outputs.
656 NCLOBBERS is the number of clobbered registers.
657 INPUTS is a vector of the input register parameters.
658 OUTPUTS is a vector of the output register parameters.
659 CLOBBERS is a vector of the clobbered register parameters.
660 LABELS is a vector of destination labels. */
662 gimple
663 gimple_build_asm_vec (const char *string, VEC(tree,gc)* inputs,
664 VEC(tree,gc)* outputs, VEC(tree,gc)* clobbers,
665 VEC(tree,gc)* labels)
667 gimple p;
668 unsigned i;
670 p = gimple_build_asm_1 (string,
671 VEC_length (tree, inputs),
672 VEC_length (tree, outputs),
673 VEC_length (tree, clobbers),
674 VEC_length (tree, labels));
676 for (i = 0; i < VEC_length (tree, inputs); i++)
677 gimple_asm_set_input_op (p, i, VEC_index (tree, inputs, i));
679 for (i = 0; i < VEC_length (tree, outputs); i++)
680 gimple_asm_set_output_op (p, i, VEC_index (tree, outputs, i));
682 for (i = 0; i < VEC_length (tree, clobbers); i++)
683 gimple_asm_set_clobber_op (p, i, VEC_index (tree, clobbers, i));
685 for (i = 0; i < VEC_length (tree, labels); i++)
686 gimple_asm_set_label_op (p, i, VEC_index (tree, labels, i));
688 return p;
691 /* Build a GIMPLE_CATCH statement.
693 TYPES are the catch types.
694 HANDLER is the exception handler. */
696 gimple
697 gimple_build_catch (tree types, gimple_seq handler)
699 gimple p = gimple_alloc (GIMPLE_CATCH, 0);
700 gimple_catch_set_types (p, types);
701 if (handler)
702 gimple_catch_set_handler (p, handler);
704 return p;
707 /* Build a GIMPLE_EH_FILTER statement.
709 TYPES are the filter's types.
710 FAILURE is the filter's failure action. */
712 gimple
713 gimple_build_eh_filter (tree types, gimple_seq failure)
715 gimple p = gimple_alloc (GIMPLE_EH_FILTER, 0);
716 gimple_eh_filter_set_types (p, types);
717 if (failure)
718 gimple_eh_filter_set_failure (p, failure);
720 return p;
723 /* Build a GIMPLE_EH_MUST_NOT_THROW statement. */
725 gimple
726 gimple_build_eh_must_not_throw (tree decl)
728 gimple p = gimple_alloc (GIMPLE_EH_MUST_NOT_THROW, 0);
730 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
731 gcc_assert (flags_from_decl_or_type (decl) & ECF_NORETURN);
732 gimple_eh_must_not_throw_set_fndecl (p, decl);
734 return p;
737 /* Build a GIMPLE_EH_ELSE statement. */
739 gimple
740 gimple_build_eh_else (gimple_seq n_body, gimple_seq e_body)
742 gimple p = gimple_alloc (GIMPLE_EH_ELSE, 0);
743 gimple_eh_else_set_n_body (p, n_body);
744 gimple_eh_else_set_e_body (p, e_body);
745 return p;
748 /* Build a GIMPLE_TRY statement.
750 EVAL is the expression to evaluate.
751 CLEANUP is the cleanup expression.
752 KIND is either GIMPLE_TRY_CATCH or GIMPLE_TRY_FINALLY depending on
753 whether this is a try/catch or a try/finally respectively. */
755 gimple
756 gimple_build_try (gimple_seq eval, gimple_seq cleanup,
757 enum gimple_try_flags kind)
759 gimple p;
761 gcc_assert (kind == GIMPLE_TRY_CATCH || kind == GIMPLE_TRY_FINALLY);
762 p = gimple_alloc (GIMPLE_TRY, 0);
763 gimple_set_subcode (p, kind);
764 if (eval)
765 gimple_try_set_eval (p, eval);
766 if (cleanup)
767 gimple_try_set_cleanup (p, cleanup);
769 return p;
772 /* Construct a GIMPLE_WITH_CLEANUP_EXPR statement.
774 CLEANUP is the cleanup expression. */
776 gimple
777 gimple_build_wce (gimple_seq cleanup)
779 gimple p = gimple_alloc (GIMPLE_WITH_CLEANUP_EXPR, 0);
780 if (cleanup)
781 gimple_wce_set_cleanup (p, cleanup);
783 return p;
787 /* Build a GIMPLE_RESX statement. */
789 gimple
790 gimple_build_resx (int region)
792 gimple p = gimple_build_with_ops (GIMPLE_RESX, ERROR_MARK, 0);
793 p->gimple_eh_ctrl.region = region;
794 return p;
798 /* The helper for constructing a gimple switch statement.
799 INDEX is the switch's index.
800 NLABELS is the number of labels in the switch excluding the default.
801 DEFAULT_LABEL is the default label for the switch statement. */
803 gimple
804 gimple_build_switch_nlabels (unsigned nlabels, tree index, tree default_label)
806 /* nlabels + 1 default label + 1 index. */
807 gcc_checking_assert (default_label);
808 gimple p = gimple_build_with_ops (GIMPLE_SWITCH, ERROR_MARK,
809 1 + 1 + nlabels);
810 gimple_switch_set_index (p, index);
811 gimple_switch_set_default_label (p, default_label);
812 return p;
815 /* Build a GIMPLE_SWITCH statement.
817 INDEX is the switch's index.
818 DEFAULT_LABEL is the default label
819 ARGS is a vector of labels excluding the default. */
821 gimple
822 gimple_build_switch (tree index, tree default_label, VEC(tree, heap) *args)
824 unsigned i, nlabels = VEC_length (tree, args);
826 gimple p = gimple_build_switch_nlabels (nlabels, index, default_label);
828 /* Copy the labels from the vector to the switch statement. */
829 for (i = 0; i < nlabels; i++)
830 gimple_switch_set_label (p, i + 1, VEC_index (tree, args, i));
832 return p;
835 /* Build a GIMPLE_EH_DISPATCH statement. */
837 gimple
838 gimple_build_eh_dispatch (int region)
840 gimple p = gimple_build_with_ops (GIMPLE_EH_DISPATCH, ERROR_MARK, 0);
841 p->gimple_eh_ctrl.region = region;
842 return p;
845 /* Build a new GIMPLE_DEBUG_BIND statement.
847 VAR is bound to VALUE; block and location are taken from STMT. */
849 gimple
850 gimple_build_debug_bind_stat (tree var, tree value, gimple stmt MEM_STAT_DECL)
852 gimple p = gimple_build_with_ops_stat (GIMPLE_DEBUG,
853 (unsigned)GIMPLE_DEBUG_BIND, 2
854 PASS_MEM_STAT);
856 gimple_debug_bind_set_var (p, var);
857 gimple_debug_bind_set_value (p, value);
858 if (stmt)
859 gimple_set_location (p, gimple_location (stmt));
861 return p;
865 /* Build a new GIMPLE_DEBUG_SOURCE_BIND statement.
867 VAR is bound to VALUE; block and location are taken from STMT. */
869 gimple
870 gimple_build_debug_source_bind_stat (tree var, tree value,
871 gimple stmt MEM_STAT_DECL)
873 gimple p = gimple_build_with_ops_stat (GIMPLE_DEBUG,
874 (unsigned)GIMPLE_DEBUG_SOURCE_BIND, 2
875 PASS_MEM_STAT);
877 gimple_debug_source_bind_set_var (p, var);
878 gimple_debug_source_bind_set_value (p, value);
879 if (stmt)
880 gimple_set_location (p, gimple_location (stmt));
882 return p;
886 /* Build a GIMPLE_OMP_CRITICAL statement.
888 BODY is the sequence of statements for which only one thread can execute.
889 NAME is optional identifier for this critical block. */
891 gimple
892 gimple_build_omp_critical (gimple_seq body, tree name)
894 gimple p = gimple_alloc (GIMPLE_OMP_CRITICAL, 0);
895 gimple_omp_critical_set_name (p, name);
896 if (body)
897 gimple_omp_set_body (p, body);
899 return p;
902 /* Build a GIMPLE_OMP_FOR statement.
904 BODY is sequence of statements inside the for loop.
905 CLAUSES, are any of the OMP loop construct's clauses: private, firstprivate,
906 lastprivate, reductions, ordered, schedule, and nowait.
907 COLLAPSE is the collapse count.
908 PRE_BODY is the sequence of statements that are loop invariant. */
910 gimple
911 gimple_build_omp_for (gimple_seq body, tree clauses, size_t collapse,
912 gimple_seq pre_body)
914 gimple p = gimple_alloc (GIMPLE_OMP_FOR, 0);
915 if (body)
916 gimple_omp_set_body (p, body);
917 gimple_omp_for_set_clauses (p, clauses);
918 p->gimple_omp_for.collapse = collapse;
919 p->gimple_omp_for.iter
920 = ggc_alloc_cleared_vec_gimple_omp_for_iter (collapse);
921 if (pre_body)
922 gimple_omp_for_set_pre_body (p, pre_body);
924 return p;
928 /* Build a GIMPLE_OMP_PARALLEL statement.
930 BODY is sequence of statements which are executed in parallel.
931 CLAUSES, are the OMP parallel construct's clauses.
932 CHILD_FN is the function created for the parallel threads to execute.
933 DATA_ARG are the shared data argument(s). */
935 gimple
936 gimple_build_omp_parallel (gimple_seq body, tree clauses, tree child_fn,
937 tree data_arg)
939 gimple p = gimple_alloc (GIMPLE_OMP_PARALLEL, 0);
940 if (body)
941 gimple_omp_set_body (p, body);
942 gimple_omp_parallel_set_clauses (p, clauses);
943 gimple_omp_parallel_set_child_fn (p, child_fn);
944 gimple_omp_parallel_set_data_arg (p, data_arg);
946 return p;
950 /* Build a GIMPLE_OMP_TASK statement.
952 BODY is sequence of statements which are executed by the explicit task.
953 CLAUSES, are the OMP parallel construct's clauses.
954 CHILD_FN is the function created for the parallel threads to execute.
955 DATA_ARG are the shared data argument(s).
956 COPY_FN is the optional function for firstprivate initialization.
957 ARG_SIZE and ARG_ALIGN are size and alignment of the data block. */
959 gimple
960 gimple_build_omp_task (gimple_seq body, tree clauses, tree child_fn,
961 tree data_arg, tree copy_fn, tree arg_size,
962 tree arg_align)
964 gimple p = gimple_alloc (GIMPLE_OMP_TASK, 0);
965 if (body)
966 gimple_omp_set_body (p, body);
967 gimple_omp_task_set_clauses (p, clauses);
968 gimple_omp_task_set_child_fn (p, child_fn);
969 gimple_omp_task_set_data_arg (p, data_arg);
970 gimple_omp_task_set_copy_fn (p, copy_fn);
971 gimple_omp_task_set_arg_size (p, arg_size);
972 gimple_omp_task_set_arg_align (p, arg_align);
974 return p;
978 /* Build a GIMPLE_OMP_SECTION statement for a sections statement.
980 BODY is the sequence of statements in the section. */
982 gimple
983 gimple_build_omp_section (gimple_seq body)
985 gimple p = gimple_alloc (GIMPLE_OMP_SECTION, 0);
986 if (body)
987 gimple_omp_set_body (p, body);
989 return p;
993 /* Build a GIMPLE_OMP_MASTER statement.
995 BODY is the sequence of statements to be executed by just the master. */
997 gimple
998 gimple_build_omp_master (gimple_seq body)
1000 gimple p = gimple_alloc (GIMPLE_OMP_MASTER, 0);
1001 if (body)
1002 gimple_omp_set_body (p, body);
1004 return p;
1008 /* Build a GIMPLE_OMP_CONTINUE statement.
1010 CONTROL_DEF is the definition of the control variable.
1011 CONTROL_USE is the use of the control variable. */
1013 gimple
1014 gimple_build_omp_continue (tree control_def, tree control_use)
1016 gimple p = gimple_alloc (GIMPLE_OMP_CONTINUE, 0);
1017 gimple_omp_continue_set_control_def (p, control_def);
1018 gimple_omp_continue_set_control_use (p, control_use);
1019 return p;
1022 /* Build a GIMPLE_OMP_ORDERED statement.
1024 BODY is the sequence of statements inside a loop that will executed in
1025 sequence. */
1027 gimple
1028 gimple_build_omp_ordered (gimple_seq body)
1030 gimple p = gimple_alloc (GIMPLE_OMP_ORDERED, 0);
1031 if (body)
1032 gimple_omp_set_body (p, body);
1034 return p;
1038 /* Build a GIMPLE_OMP_RETURN statement.
1039 WAIT_P is true if this is a non-waiting return. */
1041 gimple
1042 gimple_build_omp_return (bool wait_p)
1044 gimple p = gimple_alloc (GIMPLE_OMP_RETURN, 0);
1045 if (wait_p)
1046 gimple_omp_return_set_nowait (p);
1048 return p;
1052 /* Build a GIMPLE_OMP_SECTIONS statement.
1054 BODY is a sequence of section statements.
1055 CLAUSES are any of the OMP sections contsruct's clauses: private,
1056 firstprivate, lastprivate, reduction, and nowait. */
1058 gimple
1059 gimple_build_omp_sections (gimple_seq body, tree clauses)
1061 gimple p = gimple_alloc (GIMPLE_OMP_SECTIONS, 0);
1062 if (body)
1063 gimple_omp_set_body (p, body);
1064 gimple_omp_sections_set_clauses (p, clauses);
1066 return p;
1070 /* Build a GIMPLE_OMP_SECTIONS_SWITCH. */
1072 gimple
1073 gimple_build_omp_sections_switch (void)
1075 return gimple_alloc (GIMPLE_OMP_SECTIONS_SWITCH, 0);
1079 /* Build a GIMPLE_OMP_SINGLE statement.
1081 BODY is the sequence of statements that will be executed once.
1082 CLAUSES are any of the OMP single construct's clauses: private, firstprivate,
1083 copyprivate, nowait. */
1085 gimple
1086 gimple_build_omp_single (gimple_seq body, tree clauses)
1088 gimple p = gimple_alloc (GIMPLE_OMP_SINGLE, 0);
1089 if (body)
1090 gimple_omp_set_body (p, body);
1091 gimple_omp_single_set_clauses (p, clauses);
1093 return p;
1097 /* Build a GIMPLE_OMP_ATOMIC_LOAD statement. */
1099 gimple
1100 gimple_build_omp_atomic_load (tree lhs, tree rhs)
1102 gimple p = gimple_alloc (GIMPLE_OMP_ATOMIC_LOAD, 0);
1103 gimple_omp_atomic_load_set_lhs (p, lhs);
1104 gimple_omp_atomic_load_set_rhs (p, rhs);
1105 return p;
1108 /* Build a GIMPLE_OMP_ATOMIC_STORE statement.
1110 VAL is the value we are storing. */
1112 gimple
1113 gimple_build_omp_atomic_store (tree val)
1115 gimple p = gimple_alloc (GIMPLE_OMP_ATOMIC_STORE, 0);
1116 gimple_omp_atomic_store_set_val (p, val);
1117 return p;
1120 /* Build a GIMPLE_TRANSACTION statement. */
1122 gimple
1123 gimple_build_transaction (gimple_seq body, tree label)
1125 gimple p = gimple_alloc (GIMPLE_TRANSACTION, 0);
1126 gimple_transaction_set_body (p, body);
1127 gimple_transaction_set_label (p, label);
1128 return p;
1131 /* Build a GIMPLE_PREDICT statement. PREDICT is one of the predictors from
1132 predict.def, OUTCOME is NOT_TAKEN or TAKEN. */
1134 gimple
1135 gimple_build_predict (enum br_predictor predictor, enum prediction outcome)
1137 gimple p = gimple_alloc (GIMPLE_PREDICT, 0);
1138 /* Ensure all the predictors fit into the lower bits of the subcode. */
1139 gcc_assert ((int) END_PREDICTORS <= GF_PREDICT_TAKEN);
1140 gimple_predict_set_predictor (p, predictor);
1141 gimple_predict_set_outcome (p, outcome);
1142 return p;
1145 #if defined ENABLE_GIMPLE_CHECKING
1146 /* Complain of a gimple type mismatch and die. */
1148 void
1149 gimple_check_failed (const_gimple gs, const char *file, int line,
1150 const char *function, enum gimple_code code,
1151 enum tree_code subcode)
1153 internal_error ("gimple check: expected %s(%s), have %s(%s) in %s, at %s:%d",
1154 gimple_code_name[code],
1155 tree_code_name[subcode],
1156 gimple_code_name[gimple_code (gs)],
1157 gs->gsbase.subcode > 0
1158 ? tree_code_name[gs->gsbase.subcode]
1159 : "",
1160 function, trim_filename (file), line);
1162 #endif /* ENABLE_GIMPLE_CHECKING */
1165 /* Link gimple statement GS to the end of the sequence *SEQ_P. If
1166 *SEQ_P is NULL, a new sequence is allocated. */
1168 void
1169 gimple_seq_add_stmt (gimple_seq *seq_p, gimple gs)
1171 gimple_stmt_iterator si;
1172 if (gs == NULL)
1173 return;
1175 si = gsi_last (*seq_p);
1176 gsi_insert_after (&si, gs, GSI_NEW_STMT);
1180 /* Append sequence SRC to the end of sequence *DST_P. If *DST_P is
1181 NULL, a new sequence is allocated. */
1183 void
1184 gimple_seq_add_seq (gimple_seq *dst_p, gimple_seq src)
1186 gimple_stmt_iterator si;
1187 if (src == NULL)
1188 return;
1190 si = gsi_last (*dst_p);
1191 gsi_insert_seq_after (&si, src, GSI_NEW_STMT);
1195 /* Helper function of empty_body_p. Return true if STMT is an empty
1196 statement. */
1198 static bool
1199 empty_stmt_p (gimple stmt)
1201 if (gimple_code (stmt) == GIMPLE_NOP)
1202 return true;
1203 if (gimple_code (stmt) == GIMPLE_BIND)
1204 return empty_body_p (gimple_bind_body (stmt));
1205 return false;
1209 /* Return true if BODY contains nothing but empty statements. */
1211 bool
1212 empty_body_p (gimple_seq body)
1214 gimple_stmt_iterator i;
1216 if (gimple_seq_empty_p (body))
1217 return true;
1218 for (i = gsi_start (body); !gsi_end_p (i); gsi_next (&i))
1219 if (!empty_stmt_p (gsi_stmt (i))
1220 && !is_gimple_debug (gsi_stmt (i)))
1221 return false;
1223 return true;
1227 /* Perform a deep copy of sequence SRC and return the result. */
1229 gimple_seq
1230 gimple_seq_copy (gimple_seq src)
1232 gimple_stmt_iterator gsi;
1233 gimple_seq new_seq = NULL;
1234 gimple stmt;
1236 for (gsi = gsi_start (src); !gsi_end_p (gsi); gsi_next (&gsi))
1238 stmt = gimple_copy (gsi_stmt (gsi));
1239 gimple_seq_add_stmt (&new_seq, stmt);
1242 return new_seq;
1246 /* Walk all the statements in the sequence *PSEQ calling walk_gimple_stmt
1247 on each one. WI is as in walk_gimple_stmt.
1249 If walk_gimple_stmt returns non-NULL, the walk is stopped, and the
1250 value is stored in WI->CALLBACK_RESULT. Also, the statement that
1251 produced the value is returned if this statement has not been
1252 removed by a callback (wi->removed_stmt). If the statement has
1253 been removed, NULL is returned.
1255 Otherwise, all the statements are walked and NULL returned. */
1257 gimple
1258 walk_gimple_seq_mod (gimple_seq *pseq, walk_stmt_fn callback_stmt,
1259 walk_tree_fn callback_op, struct walk_stmt_info *wi)
1261 gimple_stmt_iterator gsi;
1263 for (gsi = gsi_start (*pseq); !gsi_end_p (gsi); )
1265 tree ret = walk_gimple_stmt (&gsi, callback_stmt, callback_op, wi);
1266 if (ret)
1268 /* If CALLBACK_STMT or CALLBACK_OP return a value, WI must exist
1269 to hold it. */
1270 gcc_assert (wi);
1271 wi->callback_result = ret;
1273 return wi->removed_stmt ? NULL : gsi_stmt (gsi);
1276 if (!wi->removed_stmt)
1277 gsi_next (&gsi);
1280 if (wi)
1281 wi->callback_result = NULL_TREE;
1283 return NULL;
1287 /* Like walk_gimple_seq_mod, but ensure that the head of SEQ isn't
1288 changed by the callbacks. */
1290 gimple
1291 walk_gimple_seq (gimple_seq seq, walk_stmt_fn callback_stmt,
1292 walk_tree_fn callback_op, struct walk_stmt_info *wi)
1294 gimple_seq seq2 = seq;
1295 gimple ret = walk_gimple_seq_mod (&seq2, callback_stmt, callback_op, wi);
1296 gcc_assert (seq2 == seq);
1297 return ret;
1301 /* Helper function for walk_gimple_stmt. Walk operands of a GIMPLE_ASM. */
1303 static tree
1304 walk_gimple_asm (gimple stmt, walk_tree_fn callback_op,
1305 struct walk_stmt_info *wi)
1307 tree ret, op;
1308 unsigned noutputs;
1309 const char **oconstraints;
1310 unsigned i, n;
1311 const char *constraint;
1312 bool allows_mem, allows_reg, is_inout;
1314 noutputs = gimple_asm_noutputs (stmt);
1315 oconstraints = (const char **) alloca ((noutputs) * sizeof (const char *));
1317 if (wi)
1318 wi->is_lhs = true;
1320 for (i = 0; i < noutputs; i++)
1322 op = gimple_asm_output_op (stmt, i);
1323 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op)));
1324 oconstraints[i] = constraint;
1325 parse_output_constraint (&constraint, i, 0, 0, &allows_mem, &allows_reg,
1326 &is_inout);
1327 if (wi)
1328 wi->val_only = (allows_reg || !allows_mem);
1329 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
1330 if (ret)
1331 return ret;
1334 n = gimple_asm_ninputs (stmt);
1335 for (i = 0; i < n; i++)
1337 op = gimple_asm_input_op (stmt, i);
1338 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op)));
1339 parse_input_constraint (&constraint, 0, 0, noutputs, 0,
1340 oconstraints, &allows_mem, &allows_reg);
1341 if (wi)
1343 wi->val_only = (allows_reg || !allows_mem);
1344 /* Although input "m" is not really a LHS, we need a lvalue. */
1345 wi->is_lhs = !wi->val_only;
1347 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
1348 if (ret)
1349 return ret;
1352 if (wi)
1354 wi->is_lhs = false;
1355 wi->val_only = true;
1358 n = gimple_asm_nlabels (stmt);
1359 for (i = 0; i < n; i++)
1361 op = gimple_asm_label_op (stmt, i);
1362 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
1363 if (ret)
1364 return ret;
1367 return NULL_TREE;
1371 /* Helper function of WALK_GIMPLE_STMT. Walk every tree operand in
1372 STMT. CALLBACK_OP and WI are as in WALK_GIMPLE_STMT.
1374 CALLBACK_OP is called on each operand of STMT via walk_tree.
1375 Additional parameters to walk_tree must be stored in WI. For each operand
1376 OP, walk_tree is called as:
1378 walk_tree (&OP, CALLBACK_OP, WI, WI->PSET)
1380 If CALLBACK_OP returns non-NULL for an operand, the remaining
1381 operands are not scanned.
1383 The return value is that returned by the last call to walk_tree, or
1384 NULL_TREE if no CALLBACK_OP is specified. */
1386 tree
1387 walk_gimple_op (gimple stmt, walk_tree_fn callback_op,
1388 struct walk_stmt_info *wi)
1390 struct pointer_set_t *pset = (wi) ? wi->pset : NULL;
1391 unsigned i;
1392 tree ret = NULL_TREE;
1394 switch (gimple_code (stmt))
1396 case GIMPLE_ASSIGN:
1397 /* Walk the RHS operands. If the LHS is of a non-renamable type or
1398 is a register variable, we may use a COMPONENT_REF on the RHS. */
1399 if (wi)
1401 tree lhs = gimple_assign_lhs (stmt);
1402 wi->val_only
1403 = (is_gimple_reg_type (TREE_TYPE (lhs)) && !is_gimple_reg (lhs))
1404 || gimple_assign_rhs_class (stmt) != GIMPLE_SINGLE_RHS;
1407 for (i = 1; i < gimple_num_ops (stmt); i++)
1409 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi,
1410 pset);
1411 if (ret)
1412 return ret;
1415 /* Walk the LHS. If the RHS is appropriate for a memory, we
1416 may use a COMPONENT_REF on the LHS. */
1417 if (wi)
1419 /* If the RHS is of a non-renamable type or is a register variable,
1420 we may use a COMPONENT_REF on the LHS. */
1421 tree rhs1 = gimple_assign_rhs1 (stmt);
1422 wi->val_only
1423 = (is_gimple_reg_type (TREE_TYPE (rhs1)) && !is_gimple_reg (rhs1))
1424 || gimple_assign_rhs_class (stmt) != GIMPLE_SINGLE_RHS;
1425 wi->is_lhs = true;
1428 ret = walk_tree (gimple_op_ptr (stmt, 0), callback_op, wi, pset);
1429 if (ret)
1430 return ret;
1432 if (wi)
1434 wi->val_only = true;
1435 wi->is_lhs = false;
1437 break;
1439 case GIMPLE_CALL:
1440 if (wi)
1442 wi->is_lhs = false;
1443 wi->val_only = true;
1446 ret = walk_tree (gimple_call_chain_ptr (stmt), callback_op, wi, pset);
1447 if (ret)
1448 return ret;
1450 ret = walk_tree (gimple_call_fn_ptr (stmt), callback_op, wi, pset);
1451 if (ret)
1452 return ret;
1454 for (i = 0; i < gimple_call_num_args (stmt); i++)
1456 if (wi)
1457 wi->val_only
1458 = is_gimple_reg_type (TREE_TYPE (gimple_call_arg (stmt, i)));
1459 ret = walk_tree (gimple_call_arg_ptr (stmt, i), callback_op, wi,
1460 pset);
1461 if (ret)
1462 return ret;
1465 if (gimple_call_lhs (stmt))
1467 if (wi)
1469 wi->is_lhs = true;
1470 wi->val_only
1471 = is_gimple_reg_type (TREE_TYPE (gimple_call_lhs (stmt)));
1474 ret = walk_tree (gimple_call_lhs_ptr (stmt), callback_op, wi, pset);
1475 if (ret)
1476 return ret;
1479 if (wi)
1481 wi->is_lhs = false;
1482 wi->val_only = true;
1484 break;
1486 case GIMPLE_CATCH:
1487 ret = walk_tree (gimple_catch_types_ptr (stmt), callback_op, wi,
1488 pset);
1489 if (ret)
1490 return ret;
1491 break;
1493 case GIMPLE_EH_FILTER:
1494 ret = walk_tree (gimple_eh_filter_types_ptr (stmt), callback_op, wi,
1495 pset);
1496 if (ret)
1497 return ret;
1498 break;
1500 case GIMPLE_ASM:
1501 ret = walk_gimple_asm (stmt, callback_op, wi);
1502 if (ret)
1503 return ret;
1504 break;
1506 case GIMPLE_OMP_CONTINUE:
1507 ret = walk_tree (gimple_omp_continue_control_def_ptr (stmt),
1508 callback_op, wi, pset);
1509 if (ret)
1510 return ret;
1512 ret = walk_tree (gimple_omp_continue_control_use_ptr (stmt),
1513 callback_op, wi, pset);
1514 if (ret)
1515 return ret;
1516 break;
1518 case GIMPLE_OMP_CRITICAL:
1519 ret = walk_tree (gimple_omp_critical_name_ptr (stmt), callback_op, wi,
1520 pset);
1521 if (ret)
1522 return ret;
1523 break;
1525 case GIMPLE_OMP_FOR:
1526 ret = walk_tree (gimple_omp_for_clauses_ptr (stmt), callback_op, wi,
1527 pset);
1528 if (ret)
1529 return ret;
1530 for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
1532 ret = walk_tree (gimple_omp_for_index_ptr (stmt, i), callback_op,
1533 wi, pset);
1534 if (ret)
1535 return ret;
1536 ret = walk_tree (gimple_omp_for_initial_ptr (stmt, i), callback_op,
1537 wi, pset);
1538 if (ret)
1539 return ret;
1540 ret = walk_tree (gimple_omp_for_final_ptr (stmt, i), callback_op,
1541 wi, pset);
1542 if (ret)
1543 return ret;
1544 ret = walk_tree (gimple_omp_for_incr_ptr (stmt, i), callback_op,
1545 wi, pset);
1547 if (ret)
1548 return ret;
1549 break;
1551 case GIMPLE_OMP_PARALLEL:
1552 ret = walk_tree (gimple_omp_parallel_clauses_ptr (stmt), callback_op,
1553 wi, pset);
1554 if (ret)
1555 return ret;
1556 ret = walk_tree (gimple_omp_parallel_child_fn_ptr (stmt), callback_op,
1557 wi, pset);
1558 if (ret)
1559 return ret;
1560 ret = walk_tree (gimple_omp_parallel_data_arg_ptr (stmt), callback_op,
1561 wi, pset);
1562 if (ret)
1563 return ret;
1564 break;
1566 case GIMPLE_OMP_TASK:
1567 ret = walk_tree (gimple_omp_task_clauses_ptr (stmt), callback_op,
1568 wi, pset);
1569 if (ret)
1570 return ret;
1571 ret = walk_tree (gimple_omp_task_child_fn_ptr (stmt), callback_op,
1572 wi, pset);
1573 if (ret)
1574 return ret;
1575 ret = walk_tree (gimple_omp_task_data_arg_ptr (stmt), callback_op,
1576 wi, pset);
1577 if (ret)
1578 return ret;
1579 ret = walk_tree (gimple_omp_task_copy_fn_ptr (stmt), callback_op,
1580 wi, pset);
1581 if (ret)
1582 return ret;
1583 ret = walk_tree (gimple_omp_task_arg_size_ptr (stmt), callback_op,
1584 wi, pset);
1585 if (ret)
1586 return ret;
1587 ret = walk_tree (gimple_omp_task_arg_align_ptr (stmt), callback_op,
1588 wi, pset);
1589 if (ret)
1590 return ret;
1591 break;
1593 case GIMPLE_OMP_SECTIONS:
1594 ret = walk_tree (gimple_omp_sections_clauses_ptr (stmt), callback_op,
1595 wi, pset);
1596 if (ret)
1597 return ret;
1599 ret = walk_tree (gimple_omp_sections_control_ptr (stmt), callback_op,
1600 wi, pset);
1601 if (ret)
1602 return ret;
1604 break;
1606 case GIMPLE_OMP_SINGLE:
1607 ret = walk_tree (gimple_omp_single_clauses_ptr (stmt), callback_op, wi,
1608 pset);
1609 if (ret)
1610 return ret;
1611 break;
1613 case GIMPLE_OMP_ATOMIC_LOAD:
1614 ret = walk_tree (gimple_omp_atomic_load_lhs_ptr (stmt), callback_op, wi,
1615 pset);
1616 if (ret)
1617 return ret;
1619 ret = walk_tree (gimple_omp_atomic_load_rhs_ptr (stmt), callback_op, wi,
1620 pset);
1621 if (ret)
1622 return ret;
1623 break;
1625 case GIMPLE_OMP_ATOMIC_STORE:
1626 ret = walk_tree (gimple_omp_atomic_store_val_ptr (stmt), callback_op,
1627 wi, pset);
1628 if (ret)
1629 return ret;
1630 break;
1632 case GIMPLE_TRANSACTION:
1633 ret = walk_tree (gimple_transaction_label_ptr (stmt), callback_op,
1634 wi, pset);
1635 if (ret)
1636 return ret;
1637 break;
1639 /* Tuples that do not have operands. */
1640 case GIMPLE_NOP:
1641 case GIMPLE_RESX:
1642 case GIMPLE_OMP_RETURN:
1643 case GIMPLE_PREDICT:
1644 break;
1646 default:
1648 enum gimple_statement_structure_enum gss;
1649 gss = gimple_statement_structure (stmt);
1650 if (gss == GSS_WITH_OPS || gss == GSS_WITH_MEM_OPS)
1651 for (i = 0; i < gimple_num_ops (stmt); i++)
1653 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi, pset);
1654 if (ret)
1655 return ret;
1658 break;
1661 return NULL_TREE;
1665 /* Walk the current statement in GSI (optionally using traversal state
1666 stored in WI). If WI is NULL, no state is kept during traversal.
1667 The callback CALLBACK_STMT is called. If CALLBACK_STMT indicates
1668 that it has handled all the operands of the statement, its return
1669 value is returned. Otherwise, the return value from CALLBACK_STMT
1670 is discarded and its operands are scanned.
1672 If CALLBACK_STMT is NULL or it didn't handle the operands,
1673 CALLBACK_OP is called on each operand of the statement via
1674 walk_gimple_op. If walk_gimple_op returns non-NULL for any
1675 operand, the remaining operands are not scanned. In this case, the
1676 return value from CALLBACK_OP is returned.
1678 In any other case, NULL_TREE is returned. */
1680 tree
1681 walk_gimple_stmt (gimple_stmt_iterator *gsi, walk_stmt_fn callback_stmt,
1682 walk_tree_fn callback_op, struct walk_stmt_info *wi)
1684 gimple ret;
1685 tree tree_ret;
1686 gimple stmt = gsi_stmt (*gsi);
1688 if (wi)
1690 wi->gsi = *gsi;
1691 wi->removed_stmt = false;
1693 if (wi->want_locations && gimple_has_location (stmt))
1694 input_location = gimple_location (stmt);
1697 ret = NULL;
1699 /* Invoke the statement callback. Return if the callback handled
1700 all of STMT operands by itself. */
1701 if (callback_stmt)
1703 bool handled_ops = false;
1704 tree_ret = callback_stmt (gsi, &handled_ops, wi);
1705 if (handled_ops)
1706 return tree_ret;
1708 /* If CALLBACK_STMT did not handle operands, it should not have
1709 a value to return. */
1710 gcc_assert (tree_ret == NULL);
1712 if (wi && wi->removed_stmt)
1713 return NULL;
1715 /* Re-read stmt in case the callback changed it. */
1716 stmt = gsi_stmt (*gsi);
1719 /* If CALLBACK_OP is defined, invoke it on every operand of STMT. */
1720 if (callback_op)
1722 tree_ret = walk_gimple_op (stmt, callback_op, wi);
1723 if (tree_ret)
1724 return tree_ret;
1727 /* If STMT can have statements inside (e.g. GIMPLE_BIND), walk them. */
1728 switch (gimple_code (stmt))
1730 case GIMPLE_BIND:
1731 ret = walk_gimple_seq_mod (gimple_bind_body_ptr (stmt), callback_stmt,
1732 callback_op, wi);
1733 if (ret)
1734 return wi->callback_result;
1735 break;
1737 case GIMPLE_CATCH:
1738 ret = walk_gimple_seq_mod (gimple_catch_handler_ptr (stmt), callback_stmt,
1739 callback_op, wi);
1740 if (ret)
1741 return wi->callback_result;
1742 break;
1744 case GIMPLE_EH_FILTER:
1745 ret = walk_gimple_seq_mod (gimple_eh_filter_failure_ptr (stmt), callback_stmt,
1746 callback_op, wi);
1747 if (ret)
1748 return wi->callback_result;
1749 break;
1751 case GIMPLE_EH_ELSE:
1752 ret = walk_gimple_seq_mod (gimple_eh_else_n_body_ptr (stmt),
1753 callback_stmt, callback_op, wi);
1754 if (ret)
1755 return wi->callback_result;
1756 ret = walk_gimple_seq_mod (gimple_eh_else_e_body_ptr (stmt),
1757 callback_stmt, callback_op, wi);
1758 if (ret)
1759 return wi->callback_result;
1760 break;
1762 case GIMPLE_TRY:
1763 ret = walk_gimple_seq_mod (gimple_try_eval_ptr (stmt), callback_stmt, callback_op,
1764 wi);
1765 if (ret)
1766 return wi->callback_result;
1768 ret = walk_gimple_seq_mod (gimple_try_cleanup_ptr (stmt), callback_stmt,
1769 callback_op, wi);
1770 if (ret)
1771 return wi->callback_result;
1772 break;
1774 case GIMPLE_OMP_FOR:
1775 ret = walk_gimple_seq_mod (gimple_omp_for_pre_body_ptr (stmt), callback_stmt,
1776 callback_op, wi);
1777 if (ret)
1778 return wi->callback_result;
1780 /* FALL THROUGH. */
1781 case GIMPLE_OMP_CRITICAL:
1782 case GIMPLE_OMP_MASTER:
1783 case GIMPLE_OMP_ORDERED:
1784 case GIMPLE_OMP_SECTION:
1785 case GIMPLE_OMP_PARALLEL:
1786 case GIMPLE_OMP_TASK:
1787 case GIMPLE_OMP_SECTIONS:
1788 case GIMPLE_OMP_SINGLE:
1789 ret = walk_gimple_seq_mod (gimple_omp_body_ptr (stmt), callback_stmt,
1790 callback_op, wi);
1791 if (ret)
1792 return wi->callback_result;
1793 break;
1795 case GIMPLE_WITH_CLEANUP_EXPR:
1796 ret = walk_gimple_seq_mod (gimple_wce_cleanup_ptr (stmt), callback_stmt,
1797 callback_op, wi);
1798 if (ret)
1799 return wi->callback_result;
1800 break;
1802 case GIMPLE_TRANSACTION:
1803 ret = walk_gimple_seq_mod (gimple_transaction_body_ptr (stmt),
1804 callback_stmt, callback_op, wi);
1805 if (ret)
1806 return wi->callback_result;
1807 break;
1809 default:
1810 gcc_assert (!gimple_has_substatements (stmt));
1811 break;
1814 return NULL;
1818 /* Set sequence SEQ to be the GIMPLE body for function FN. */
1820 void
1821 gimple_set_body (tree fndecl, gimple_seq seq)
1823 struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
1824 if (fn == NULL)
1826 /* If FNDECL still does not have a function structure associated
1827 with it, then it does not make sense for it to receive a
1828 GIMPLE body. */
1829 gcc_assert (seq == NULL);
1831 else
1832 fn->gimple_body = seq;
1836 /* Return the body of GIMPLE statements for function FN. After the
1837 CFG pass, the function body doesn't exist anymore because it has
1838 been split up into basic blocks. In this case, it returns
1839 NULL. */
1841 gimple_seq
1842 gimple_body (tree fndecl)
1844 struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
1845 return fn ? fn->gimple_body : NULL;
1848 /* Return true when FNDECL has Gimple body either in unlowered
1849 or CFG form. */
1850 bool
1851 gimple_has_body_p (tree fndecl)
1853 struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
1854 return (gimple_body (fndecl) || (fn && fn->cfg));
1857 /* Return true if calls C1 and C2 are known to go to the same function. */
1859 bool
1860 gimple_call_same_target_p (const_gimple c1, const_gimple c2)
1862 if (gimple_call_internal_p (c1))
1863 return (gimple_call_internal_p (c2)
1864 && gimple_call_internal_fn (c1) == gimple_call_internal_fn (c2));
1865 else
1866 return (gimple_call_fn (c1) == gimple_call_fn (c2)
1867 || (gimple_call_fndecl (c1)
1868 && gimple_call_fndecl (c1) == gimple_call_fndecl (c2)));
1871 /* Detect flags from a GIMPLE_CALL. This is just like
1872 call_expr_flags, but for gimple tuples. */
1875 gimple_call_flags (const_gimple stmt)
1877 int flags;
1878 tree decl = gimple_call_fndecl (stmt);
1880 if (decl)
1881 flags = flags_from_decl_or_type (decl);
1882 else if (gimple_call_internal_p (stmt))
1883 flags = internal_fn_flags (gimple_call_internal_fn (stmt));
1884 else
1885 flags = flags_from_decl_or_type (gimple_call_fntype (stmt));
1887 if (stmt->gsbase.subcode & GF_CALL_NOTHROW)
1888 flags |= ECF_NOTHROW;
1890 return flags;
1893 /* Return the "fn spec" string for call STMT. */
1895 static tree
1896 gimple_call_fnspec (const_gimple stmt)
1898 tree type, attr;
1900 type = gimple_call_fntype (stmt);
1901 if (!type)
1902 return NULL_TREE;
1904 attr = lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type));
1905 if (!attr)
1906 return NULL_TREE;
1908 return TREE_VALUE (TREE_VALUE (attr));
1911 /* Detects argument flags for argument number ARG on call STMT. */
1914 gimple_call_arg_flags (const_gimple stmt, unsigned arg)
1916 tree attr = gimple_call_fnspec (stmt);
1918 if (!attr || 1 + arg >= (unsigned) TREE_STRING_LENGTH (attr))
1919 return 0;
1921 switch (TREE_STRING_POINTER (attr)[1 + arg])
1923 case 'x':
1924 case 'X':
1925 return EAF_UNUSED;
1927 case 'R':
1928 return EAF_DIRECT | EAF_NOCLOBBER | EAF_NOESCAPE;
1930 case 'r':
1931 return EAF_NOCLOBBER | EAF_NOESCAPE;
1933 case 'W':
1934 return EAF_DIRECT | EAF_NOESCAPE;
1936 case 'w':
1937 return EAF_NOESCAPE;
1939 case '.':
1940 default:
1941 return 0;
1945 /* Detects return flags for the call STMT. */
1948 gimple_call_return_flags (const_gimple stmt)
1950 tree attr;
1952 if (gimple_call_flags (stmt) & ECF_MALLOC)
1953 return ERF_NOALIAS;
1955 attr = gimple_call_fnspec (stmt);
1956 if (!attr || TREE_STRING_LENGTH (attr) < 1)
1957 return 0;
1959 switch (TREE_STRING_POINTER (attr)[0])
1961 case '1':
1962 case '2':
1963 case '3':
1964 case '4':
1965 return ERF_RETURNS_ARG | (TREE_STRING_POINTER (attr)[0] - '1');
1967 case 'm':
1968 return ERF_NOALIAS;
1970 case '.':
1971 default:
1972 return 0;
1977 /* Return true if GS is a copy assignment. */
1979 bool
1980 gimple_assign_copy_p (gimple gs)
1982 return (gimple_assign_single_p (gs)
1983 && is_gimple_val (gimple_op (gs, 1)));
1987 /* Return true if GS is a SSA_NAME copy assignment. */
1989 bool
1990 gimple_assign_ssa_name_copy_p (gimple gs)
1992 return (gimple_assign_single_p (gs)
1993 && TREE_CODE (gimple_assign_lhs (gs)) == SSA_NAME
1994 && TREE_CODE (gimple_assign_rhs1 (gs)) == SSA_NAME);
1998 /* Return true if GS is an assignment with a unary RHS, but the
1999 operator has no effect on the assigned value. The logic is adapted
2000 from STRIP_NOPS. This predicate is intended to be used in tuplifying
2001 instances in which STRIP_NOPS was previously applied to the RHS of
2002 an assignment.
2004 NOTE: In the use cases that led to the creation of this function
2005 and of gimple_assign_single_p, it is typical to test for either
2006 condition and to proceed in the same manner. In each case, the
2007 assigned value is represented by the single RHS operand of the
2008 assignment. I suspect there may be cases where gimple_assign_copy_p,
2009 gimple_assign_single_p, or equivalent logic is used where a similar
2010 treatment of unary NOPs is appropriate. */
2012 bool
2013 gimple_assign_unary_nop_p (gimple gs)
2015 return (is_gimple_assign (gs)
2016 && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs))
2017 || gimple_assign_rhs_code (gs) == NON_LVALUE_EXPR)
2018 && gimple_assign_rhs1 (gs) != error_mark_node
2019 && (TYPE_MODE (TREE_TYPE (gimple_assign_lhs (gs)))
2020 == TYPE_MODE (TREE_TYPE (gimple_assign_rhs1 (gs)))));
2023 /* Set BB to be the basic block holding G. */
2025 void
2026 gimple_set_bb (gimple stmt, basic_block bb)
2028 stmt->gsbase.bb = bb;
2030 /* If the statement is a label, add the label to block-to-labels map
2031 so that we can speed up edge creation for GIMPLE_GOTOs. */
2032 if (cfun->cfg && gimple_code (stmt) == GIMPLE_LABEL)
2034 tree t;
2035 int uid;
2037 t = gimple_label_label (stmt);
2038 uid = LABEL_DECL_UID (t);
2039 if (uid == -1)
2041 unsigned old_len = VEC_length (basic_block, label_to_block_map);
2042 LABEL_DECL_UID (t) = uid = cfun->cfg->last_label_uid++;
2043 if (old_len <= (unsigned) uid)
2045 unsigned new_len = 3 * uid / 2 + 1;
2047 VEC_safe_grow_cleared (basic_block, gc, label_to_block_map,
2048 new_len);
2052 VEC_replace (basic_block, label_to_block_map, uid, bb);
2057 /* Modify the RHS of the assignment pointed-to by GSI using the
2058 operands in the expression tree EXPR.
2060 NOTE: The statement pointed-to by GSI may be reallocated if it
2061 did not have enough operand slots.
2063 This function is useful to convert an existing tree expression into
2064 the flat representation used for the RHS of a GIMPLE assignment.
2065 It will reallocate memory as needed to expand or shrink the number
2066 of operand slots needed to represent EXPR.
2068 NOTE: If you find yourself building a tree and then calling this
2069 function, you are most certainly doing it the slow way. It is much
2070 better to build a new assignment or to use the function
2071 gimple_assign_set_rhs_with_ops, which does not require an
2072 expression tree to be built. */
2074 void
2075 gimple_assign_set_rhs_from_tree (gimple_stmt_iterator *gsi, tree expr)
2077 enum tree_code subcode;
2078 tree op1, op2, op3;
2080 extract_ops_from_tree_1 (expr, &subcode, &op1, &op2, &op3);
2081 gimple_assign_set_rhs_with_ops_1 (gsi, subcode, op1, op2, op3);
2085 /* Set the RHS of assignment statement pointed-to by GSI to CODE with
2086 operands OP1, OP2 and OP3.
2088 NOTE: The statement pointed-to by GSI may be reallocated if it
2089 did not have enough operand slots. */
2091 void
2092 gimple_assign_set_rhs_with_ops_1 (gimple_stmt_iterator *gsi, enum tree_code code,
2093 tree op1, tree op2, tree op3)
2095 unsigned new_rhs_ops = get_gimple_rhs_num_ops (code);
2096 gimple stmt = gsi_stmt (*gsi);
2098 /* If the new CODE needs more operands, allocate a new statement. */
2099 if (gimple_num_ops (stmt) < new_rhs_ops + 1)
2101 tree lhs = gimple_assign_lhs (stmt);
2102 gimple new_stmt = gimple_alloc (gimple_code (stmt), new_rhs_ops + 1);
2103 memcpy (new_stmt, stmt, gimple_size (gimple_code (stmt)));
2104 gimple_init_singleton (new_stmt);
2105 gsi_replace (gsi, new_stmt, true);
2106 stmt = new_stmt;
2108 /* The LHS needs to be reset as this also changes the SSA name
2109 on the LHS. */
2110 gimple_assign_set_lhs (stmt, lhs);
2113 gimple_set_num_ops (stmt, new_rhs_ops + 1);
2114 gimple_set_subcode (stmt, code);
2115 gimple_assign_set_rhs1 (stmt, op1);
2116 if (new_rhs_ops > 1)
2117 gimple_assign_set_rhs2 (stmt, op2);
2118 if (new_rhs_ops > 2)
2119 gimple_assign_set_rhs3 (stmt, op3);
2123 /* Return the LHS of a statement that performs an assignment,
2124 either a GIMPLE_ASSIGN or a GIMPLE_CALL. Returns NULL_TREE
2125 for a call to a function that returns no value, or for a
2126 statement other than an assignment or a call. */
2128 tree
2129 gimple_get_lhs (const_gimple stmt)
2131 enum gimple_code code = gimple_code (stmt);
2133 if (code == GIMPLE_ASSIGN)
2134 return gimple_assign_lhs (stmt);
2135 else if (code == GIMPLE_CALL)
2136 return gimple_call_lhs (stmt);
2137 else
2138 return NULL_TREE;
2142 /* Set the LHS of a statement that performs an assignment,
2143 either a GIMPLE_ASSIGN or a GIMPLE_CALL. */
2145 void
2146 gimple_set_lhs (gimple stmt, tree lhs)
2148 enum gimple_code code = gimple_code (stmt);
2150 if (code == GIMPLE_ASSIGN)
2151 gimple_assign_set_lhs (stmt, lhs);
2152 else if (code == GIMPLE_CALL)
2153 gimple_call_set_lhs (stmt, lhs);
2154 else
2155 gcc_unreachable();
2158 /* Replace the LHS of STMT, an assignment, either a GIMPLE_ASSIGN or a
2159 GIMPLE_CALL, with NLHS, in preparation for modifying the RHS to an
2160 expression with a different value.
2162 This will update any annotations (say debug bind stmts) referring
2163 to the original LHS, so that they use the RHS instead. This is
2164 done even if NLHS and LHS are the same, for it is understood that
2165 the RHS will be modified afterwards, and NLHS will not be assigned
2166 an equivalent value.
2168 Adjusting any non-annotation uses of the LHS, if needed, is a
2169 responsibility of the caller.
2171 The effect of this call should be pretty much the same as that of
2172 inserting a copy of STMT before STMT, and then removing the
2173 original stmt, at which time gsi_remove() would have update
2174 annotations, but using this function saves all the inserting,
2175 copying and removing. */
2177 void
2178 gimple_replace_lhs (gimple stmt, tree nlhs)
2180 if (MAY_HAVE_DEBUG_STMTS)
2182 tree lhs = gimple_get_lhs (stmt);
2184 gcc_assert (SSA_NAME_DEF_STMT (lhs) == stmt);
2186 insert_debug_temp_for_var_def (NULL, lhs);
2189 gimple_set_lhs (stmt, nlhs);
2192 /* Return a deep copy of statement STMT. All the operands from STMT
2193 are reallocated and copied using unshare_expr. The DEF, USE, VDEF
2194 and VUSE operand arrays are set to empty in the new copy. The new
2195 copy isn't part of any sequence. */
2197 gimple
2198 gimple_copy (gimple stmt)
2200 enum gimple_code code = gimple_code (stmt);
2201 unsigned num_ops = gimple_num_ops (stmt);
2202 gimple copy = gimple_alloc (code, num_ops);
2203 unsigned i;
2205 /* Shallow copy all the fields from STMT. */
2206 memcpy (copy, stmt, gimple_size (code));
2207 gimple_init_singleton (copy);
2209 /* If STMT has sub-statements, deep-copy them as well. */
2210 if (gimple_has_substatements (stmt))
2212 gimple_seq new_seq;
2213 tree t;
2215 switch (gimple_code (stmt))
2217 case GIMPLE_BIND:
2218 new_seq = gimple_seq_copy (gimple_bind_body (stmt));
2219 gimple_bind_set_body (copy, new_seq);
2220 gimple_bind_set_vars (copy, unshare_expr (gimple_bind_vars (stmt)));
2221 gimple_bind_set_block (copy, gimple_bind_block (stmt));
2222 break;
2224 case GIMPLE_CATCH:
2225 new_seq = gimple_seq_copy (gimple_catch_handler (stmt));
2226 gimple_catch_set_handler (copy, new_seq);
2227 t = unshare_expr (gimple_catch_types (stmt));
2228 gimple_catch_set_types (copy, t);
2229 break;
2231 case GIMPLE_EH_FILTER:
2232 new_seq = gimple_seq_copy (gimple_eh_filter_failure (stmt));
2233 gimple_eh_filter_set_failure (copy, new_seq);
2234 t = unshare_expr (gimple_eh_filter_types (stmt));
2235 gimple_eh_filter_set_types (copy, t);
2236 break;
2238 case GIMPLE_EH_ELSE:
2239 new_seq = gimple_seq_copy (gimple_eh_else_n_body (stmt));
2240 gimple_eh_else_set_n_body (copy, new_seq);
2241 new_seq = gimple_seq_copy (gimple_eh_else_e_body (stmt));
2242 gimple_eh_else_set_e_body (copy, new_seq);
2243 break;
2245 case GIMPLE_TRY:
2246 new_seq = gimple_seq_copy (gimple_try_eval (stmt));
2247 gimple_try_set_eval (copy, new_seq);
2248 new_seq = gimple_seq_copy (gimple_try_cleanup (stmt));
2249 gimple_try_set_cleanup (copy, new_seq);
2250 break;
2252 case GIMPLE_OMP_FOR:
2253 new_seq = gimple_seq_copy (gimple_omp_for_pre_body (stmt));
2254 gimple_omp_for_set_pre_body (copy, new_seq);
2255 t = unshare_expr (gimple_omp_for_clauses (stmt));
2256 gimple_omp_for_set_clauses (copy, t);
2257 copy->gimple_omp_for.iter
2258 = ggc_alloc_vec_gimple_omp_for_iter
2259 (gimple_omp_for_collapse (stmt));
2260 for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
2262 gimple_omp_for_set_cond (copy, i,
2263 gimple_omp_for_cond (stmt, i));
2264 gimple_omp_for_set_index (copy, i,
2265 gimple_omp_for_index (stmt, i));
2266 t = unshare_expr (gimple_omp_for_initial (stmt, i));
2267 gimple_omp_for_set_initial (copy, i, t);
2268 t = unshare_expr (gimple_omp_for_final (stmt, i));
2269 gimple_omp_for_set_final (copy, i, t);
2270 t = unshare_expr (gimple_omp_for_incr (stmt, i));
2271 gimple_omp_for_set_incr (copy, i, t);
2273 goto copy_omp_body;
2275 case GIMPLE_OMP_PARALLEL:
2276 t = unshare_expr (gimple_omp_parallel_clauses (stmt));
2277 gimple_omp_parallel_set_clauses (copy, t);
2278 t = unshare_expr (gimple_omp_parallel_child_fn (stmt));
2279 gimple_omp_parallel_set_child_fn (copy, t);
2280 t = unshare_expr (gimple_omp_parallel_data_arg (stmt));
2281 gimple_omp_parallel_set_data_arg (copy, t);
2282 goto copy_omp_body;
2284 case GIMPLE_OMP_TASK:
2285 t = unshare_expr (gimple_omp_task_clauses (stmt));
2286 gimple_omp_task_set_clauses (copy, t);
2287 t = unshare_expr (gimple_omp_task_child_fn (stmt));
2288 gimple_omp_task_set_child_fn (copy, t);
2289 t = unshare_expr (gimple_omp_task_data_arg (stmt));
2290 gimple_omp_task_set_data_arg (copy, t);
2291 t = unshare_expr (gimple_omp_task_copy_fn (stmt));
2292 gimple_omp_task_set_copy_fn (copy, t);
2293 t = unshare_expr (gimple_omp_task_arg_size (stmt));
2294 gimple_omp_task_set_arg_size (copy, t);
2295 t = unshare_expr (gimple_omp_task_arg_align (stmt));
2296 gimple_omp_task_set_arg_align (copy, t);
2297 goto copy_omp_body;
2299 case GIMPLE_OMP_CRITICAL:
2300 t = unshare_expr (gimple_omp_critical_name (stmt));
2301 gimple_omp_critical_set_name (copy, t);
2302 goto copy_omp_body;
2304 case GIMPLE_OMP_SECTIONS:
2305 t = unshare_expr (gimple_omp_sections_clauses (stmt));
2306 gimple_omp_sections_set_clauses (copy, t);
2307 t = unshare_expr (gimple_omp_sections_control (stmt));
2308 gimple_omp_sections_set_control (copy, t);
2309 /* FALLTHRU */
2311 case GIMPLE_OMP_SINGLE:
2312 case GIMPLE_OMP_SECTION:
2313 case GIMPLE_OMP_MASTER:
2314 case GIMPLE_OMP_ORDERED:
2315 copy_omp_body:
2316 new_seq = gimple_seq_copy (gimple_omp_body (stmt));
2317 gimple_omp_set_body (copy, new_seq);
2318 break;
2320 case GIMPLE_TRANSACTION:
2321 new_seq = gimple_seq_copy (gimple_transaction_body (stmt));
2322 gimple_transaction_set_body (copy, new_seq);
2323 break;
2325 case GIMPLE_WITH_CLEANUP_EXPR:
2326 new_seq = gimple_seq_copy (gimple_wce_cleanup (stmt));
2327 gimple_wce_set_cleanup (copy, new_seq);
2328 break;
2330 default:
2331 gcc_unreachable ();
2335 /* Make copy of operands. */
2336 for (i = 0; i < num_ops; i++)
2337 gimple_set_op (copy, i, unshare_expr (gimple_op (stmt, i)));
2339 if (gimple_has_mem_ops (stmt))
2341 gimple_set_vdef (copy, gimple_vdef (stmt));
2342 gimple_set_vuse (copy, gimple_vuse (stmt));
2345 /* Clear out SSA operand vectors on COPY. */
2346 if (gimple_has_ops (stmt))
2348 gimple_set_def_ops (copy, NULL);
2349 gimple_set_use_ops (copy, NULL);
2351 /* SSA operands need to be updated. */
2352 gimple_set_modified (copy, true);
2355 return copy;
2359 /* Return true if statement S has side-effects. We consider a
2360 statement to have side effects if:
2362 - It is a GIMPLE_CALL not marked with ECF_PURE or ECF_CONST.
2363 - Any of its operands are marked TREE_THIS_VOLATILE or TREE_SIDE_EFFECTS. */
2365 bool
2366 gimple_has_side_effects (const_gimple s)
2368 if (is_gimple_debug (s))
2369 return false;
2371 /* We don't have to scan the arguments to check for
2372 volatile arguments, though, at present, we still
2373 do a scan to check for TREE_SIDE_EFFECTS. */
2374 if (gimple_has_volatile_ops (s))
2375 return true;
2377 if (gimple_code (s) == GIMPLE_ASM
2378 && gimple_asm_volatile_p (s))
2379 return true;
2381 if (is_gimple_call (s))
2383 int flags = gimple_call_flags (s);
2385 /* An infinite loop is considered a side effect. */
2386 if (!(flags & (ECF_CONST | ECF_PURE))
2387 || (flags & ECF_LOOPING_CONST_OR_PURE))
2388 return true;
2390 return false;
2393 return false;
2396 /* Helper for gimple_could_trap_p and gimple_assign_rhs_could_trap_p.
2397 Return true if S can trap. When INCLUDE_MEM is true, check whether
2398 the memory operations could trap. When INCLUDE_STORES is true and
2399 S is a GIMPLE_ASSIGN, the LHS of the assignment is also checked. */
2401 bool
2402 gimple_could_trap_p_1 (gimple s, bool include_mem, bool include_stores)
2404 tree t, div = NULL_TREE;
2405 enum tree_code op;
2407 if (include_mem)
2409 unsigned i, start = (is_gimple_assign (s) && !include_stores) ? 1 : 0;
2411 for (i = start; i < gimple_num_ops (s); i++)
2412 if (tree_could_trap_p (gimple_op (s, i)))
2413 return true;
2416 switch (gimple_code (s))
2418 case GIMPLE_ASM:
2419 return gimple_asm_volatile_p (s);
2421 case GIMPLE_CALL:
2422 t = gimple_call_fndecl (s);
2423 /* Assume that calls to weak functions may trap. */
2424 if (!t || !DECL_P (t) || DECL_WEAK (t))
2425 return true;
2426 return false;
2428 case GIMPLE_ASSIGN:
2429 t = gimple_expr_type (s);
2430 op = gimple_assign_rhs_code (s);
2431 if (get_gimple_rhs_class (op) == GIMPLE_BINARY_RHS)
2432 div = gimple_assign_rhs2 (s);
2433 return (operation_could_trap_p (op, FLOAT_TYPE_P (t),
2434 (INTEGRAL_TYPE_P (t)
2435 && TYPE_OVERFLOW_TRAPS (t)),
2436 div));
2438 default:
2439 break;
2442 return false;
2445 /* Return true if statement S can trap. */
2447 bool
2448 gimple_could_trap_p (gimple s)
2450 return gimple_could_trap_p_1 (s, true, true);
2453 /* Return true if RHS of a GIMPLE_ASSIGN S can trap. */
2455 bool
2456 gimple_assign_rhs_could_trap_p (gimple s)
2458 gcc_assert (is_gimple_assign (s));
2459 return gimple_could_trap_p_1 (s, true, false);
2463 /* Print debugging information for gimple stmts generated. */
2465 void
2466 dump_gimple_statistics (void)
2468 int i, total_tuples = 0, total_bytes = 0;
2470 if (! GATHER_STATISTICS)
2472 fprintf (stderr, "No gimple statistics\n");
2473 return;
2476 fprintf (stderr, "\nGIMPLE statements\n");
2477 fprintf (stderr, "Kind Stmts Bytes\n");
2478 fprintf (stderr, "---------------------------------------\n");
2479 for (i = 0; i < (int) gimple_alloc_kind_all; ++i)
2481 fprintf (stderr, "%-20s %7d %10d\n", gimple_alloc_kind_names[i],
2482 gimple_alloc_counts[i], gimple_alloc_sizes[i]);
2483 total_tuples += gimple_alloc_counts[i];
2484 total_bytes += gimple_alloc_sizes[i];
2486 fprintf (stderr, "---------------------------------------\n");
2487 fprintf (stderr, "%-20s %7d %10d\n", "Total", total_tuples, total_bytes);
2488 fprintf (stderr, "---------------------------------------\n");
2492 /* Return the number of operands needed on the RHS of a GIMPLE
2493 assignment for an expression with tree code CODE. */
2495 unsigned
2496 get_gimple_rhs_num_ops (enum tree_code code)
2498 enum gimple_rhs_class rhs_class = get_gimple_rhs_class (code);
2500 if (rhs_class == GIMPLE_UNARY_RHS || rhs_class == GIMPLE_SINGLE_RHS)
2501 return 1;
2502 else if (rhs_class == GIMPLE_BINARY_RHS)
2503 return 2;
2504 else if (rhs_class == GIMPLE_TERNARY_RHS)
2505 return 3;
2506 else
2507 gcc_unreachable ();
2510 #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \
2511 (unsigned char) \
2512 ((TYPE) == tcc_unary ? GIMPLE_UNARY_RHS \
2513 : ((TYPE) == tcc_binary \
2514 || (TYPE) == tcc_comparison) ? GIMPLE_BINARY_RHS \
2515 : ((TYPE) == tcc_constant \
2516 || (TYPE) == tcc_declaration \
2517 || (TYPE) == tcc_reference) ? GIMPLE_SINGLE_RHS \
2518 : ((SYM) == TRUTH_AND_EXPR \
2519 || (SYM) == TRUTH_OR_EXPR \
2520 || (SYM) == TRUTH_XOR_EXPR) ? GIMPLE_BINARY_RHS \
2521 : (SYM) == TRUTH_NOT_EXPR ? GIMPLE_UNARY_RHS \
2522 : ((SYM) == COND_EXPR \
2523 || (SYM) == WIDEN_MULT_PLUS_EXPR \
2524 || (SYM) == WIDEN_MULT_MINUS_EXPR \
2525 || (SYM) == DOT_PROD_EXPR \
2526 || (SYM) == REALIGN_LOAD_EXPR \
2527 || (SYM) == VEC_COND_EXPR \
2528 || (SYM) == VEC_PERM_EXPR \
2529 || (SYM) == FMA_EXPR) ? GIMPLE_TERNARY_RHS \
2530 : ((SYM) == CONSTRUCTOR \
2531 || (SYM) == OBJ_TYPE_REF \
2532 || (SYM) == ASSERT_EXPR \
2533 || (SYM) == ADDR_EXPR \
2534 || (SYM) == WITH_SIZE_EXPR \
2535 || (SYM) == SSA_NAME) ? GIMPLE_SINGLE_RHS \
2536 : GIMPLE_INVALID_RHS),
2537 #define END_OF_BASE_TREE_CODES (unsigned char) GIMPLE_INVALID_RHS,
2539 const unsigned char gimple_rhs_class_table[] = {
2540 #include "all-tree.def"
2543 #undef DEFTREECODE
2544 #undef END_OF_BASE_TREE_CODES
2546 /* For the definitive definition of GIMPLE, see doc/tree-ssa.texi. */
2548 /* Validation of GIMPLE expressions. */
2550 /* Return true if T is a valid LHS for a GIMPLE assignment expression. */
2552 bool
2553 is_gimple_lvalue (tree t)
2555 return (is_gimple_addressable (t)
2556 || TREE_CODE (t) == WITH_SIZE_EXPR
2557 /* These are complex lvalues, but don't have addresses, so they
2558 go here. */
2559 || TREE_CODE (t) == BIT_FIELD_REF);
2562 /* Return true if T is a GIMPLE condition. */
2564 bool
2565 is_gimple_condexpr (tree t)
2567 return (is_gimple_val (t) || (COMPARISON_CLASS_P (t)
2568 && !tree_could_throw_p (t)
2569 && is_gimple_val (TREE_OPERAND (t, 0))
2570 && is_gimple_val (TREE_OPERAND (t, 1))));
2573 /* Return true if T is something whose address can be taken. */
2575 bool
2576 is_gimple_addressable (tree t)
2578 return (is_gimple_id (t) || handled_component_p (t)
2579 || TREE_CODE (t) == MEM_REF);
2582 /* Return true if T is a valid gimple constant. */
2584 bool
2585 is_gimple_constant (const_tree t)
2587 switch (TREE_CODE (t))
2589 case INTEGER_CST:
2590 case REAL_CST:
2591 case FIXED_CST:
2592 case STRING_CST:
2593 case COMPLEX_CST:
2594 case VECTOR_CST:
2595 return true;
2597 /* Vector constant constructors are gimple invariant. */
2598 case CONSTRUCTOR:
2599 if (TREE_TYPE (t) && TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE)
2600 return TREE_CONSTANT (t);
2601 else
2602 return false;
2604 default:
2605 return false;
2609 /* Return true if T is a gimple address. */
2611 bool
2612 is_gimple_address (const_tree t)
2614 tree op;
2616 if (TREE_CODE (t) != ADDR_EXPR)
2617 return false;
2619 op = TREE_OPERAND (t, 0);
2620 while (handled_component_p (op))
2622 if ((TREE_CODE (op) == ARRAY_REF
2623 || TREE_CODE (op) == ARRAY_RANGE_REF)
2624 && !is_gimple_val (TREE_OPERAND (op, 1)))
2625 return false;
2627 op = TREE_OPERAND (op, 0);
2630 if (CONSTANT_CLASS_P (op) || TREE_CODE (op) == MEM_REF)
2631 return true;
2633 switch (TREE_CODE (op))
2635 case PARM_DECL:
2636 case RESULT_DECL:
2637 case LABEL_DECL:
2638 case FUNCTION_DECL:
2639 case VAR_DECL:
2640 case CONST_DECL:
2641 return true;
2643 default:
2644 return false;
2648 /* Return true if T is a gimple invariant address. */
2650 bool
2651 is_gimple_invariant_address (const_tree t)
2653 const_tree op;
2655 if (TREE_CODE (t) != ADDR_EXPR)
2656 return false;
2658 op = strip_invariant_refs (TREE_OPERAND (t, 0));
2659 if (!op)
2660 return false;
2662 if (TREE_CODE (op) == MEM_REF)
2664 const_tree op0 = TREE_OPERAND (op, 0);
2665 return (TREE_CODE (op0) == ADDR_EXPR
2666 && (CONSTANT_CLASS_P (TREE_OPERAND (op0, 0))
2667 || decl_address_invariant_p (TREE_OPERAND (op0, 0))));
2670 return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op);
2673 /* Return true if T is a gimple invariant address at IPA level
2674 (so addresses of variables on stack are not allowed). */
2676 bool
2677 is_gimple_ip_invariant_address (const_tree t)
2679 const_tree op;
2681 if (TREE_CODE (t) != ADDR_EXPR)
2682 return false;
2684 op = strip_invariant_refs (TREE_OPERAND (t, 0));
2685 if (!op)
2686 return false;
2688 if (TREE_CODE (op) == MEM_REF)
2690 const_tree op0 = TREE_OPERAND (op, 0);
2691 return (TREE_CODE (op0) == ADDR_EXPR
2692 && (CONSTANT_CLASS_P (TREE_OPERAND (op0, 0))
2693 || decl_address_ip_invariant_p (TREE_OPERAND (op0, 0))));
2696 return CONSTANT_CLASS_P (op) || decl_address_ip_invariant_p (op);
2699 /* Return true if T is a GIMPLE minimal invariant. It's a restricted
2700 form of function invariant. */
2702 bool
2703 is_gimple_min_invariant (const_tree t)
2705 if (TREE_CODE (t) == ADDR_EXPR)
2706 return is_gimple_invariant_address (t);
2708 return is_gimple_constant (t);
2711 /* Return true if T is a GIMPLE interprocedural invariant. It's a restricted
2712 form of gimple minimal invariant. */
2714 bool
2715 is_gimple_ip_invariant (const_tree t)
2717 if (TREE_CODE (t) == ADDR_EXPR)
2718 return is_gimple_ip_invariant_address (t);
2720 return is_gimple_constant (t);
2723 /* Return true if T is a variable. */
2725 bool
2726 is_gimple_variable (tree t)
2728 return (TREE_CODE (t) == VAR_DECL
2729 || TREE_CODE (t) == PARM_DECL
2730 || TREE_CODE (t) == RESULT_DECL
2731 || TREE_CODE (t) == SSA_NAME);
2734 /* Return true if T is a GIMPLE identifier (something with an address). */
2736 bool
2737 is_gimple_id (tree t)
2739 return (is_gimple_variable (t)
2740 || TREE_CODE (t) == FUNCTION_DECL
2741 || TREE_CODE (t) == LABEL_DECL
2742 || TREE_CODE (t) == CONST_DECL
2743 /* Allow string constants, since they are addressable. */
2744 || TREE_CODE (t) == STRING_CST);
2747 /* Return true if T is a non-aggregate register variable. */
2749 bool
2750 is_gimple_reg (tree t)
2752 if (virtual_operand_p (t))
2753 return false;
2755 if (TREE_CODE (t) == SSA_NAME)
2756 return true;
2758 if (!is_gimple_variable (t))
2759 return false;
2761 if (!is_gimple_reg_type (TREE_TYPE (t)))
2762 return false;
2764 /* A volatile decl is not acceptable because we can't reuse it as
2765 needed. We need to copy it into a temp first. */
2766 if (TREE_THIS_VOLATILE (t))
2767 return false;
2769 /* We define "registers" as things that can be renamed as needed,
2770 which with our infrastructure does not apply to memory. */
2771 if (needs_to_live_in_memory (t))
2772 return false;
2774 /* Hard register variables are an interesting case. For those that
2775 are call-clobbered, we don't know where all the calls are, since
2776 we don't (want to) take into account which operations will turn
2777 into libcalls at the rtl level. For those that are call-saved,
2778 we don't currently model the fact that calls may in fact change
2779 global hard registers, nor do we examine ASM_CLOBBERS at the tree
2780 level, and so miss variable changes that might imply. All around,
2781 it seems safest to not do too much optimization with these at the
2782 tree level at all. We'll have to rely on the rtl optimizers to
2783 clean this up, as there we've got all the appropriate bits exposed. */
2784 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t))
2785 return false;
2787 /* Complex and vector values must have been put into SSA-like form.
2788 That is, no assignments to the individual components. */
2789 if (TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE
2790 || TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE)
2791 return DECL_GIMPLE_REG_P (t);
2793 return true;
2797 /* Return true if T is a GIMPLE rvalue, i.e. an identifier or a constant. */
2799 bool
2800 is_gimple_val (tree t)
2802 /* Make loads from volatiles and memory vars explicit. */
2803 if (is_gimple_variable (t)
2804 && is_gimple_reg_type (TREE_TYPE (t))
2805 && !is_gimple_reg (t))
2806 return false;
2808 return (is_gimple_variable (t) || is_gimple_min_invariant (t));
2811 /* Similarly, but accept hard registers as inputs to asm statements. */
2813 bool
2814 is_gimple_asm_val (tree t)
2816 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t))
2817 return true;
2819 return is_gimple_val (t);
2822 /* Return true if T is a GIMPLE minimal lvalue. */
2824 bool
2825 is_gimple_min_lval (tree t)
2827 if (!(t = CONST_CAST_TREE (strip_invariant_refs (t))))
2828 return false;
2829 return (is_gimple_id (t) || TREE_CODE (t) == MEM_REF);
2832 /* Return true if T is a valid function operand of a CALL_EXPR. */
2834 bool
2835 is_gimple_call_addr (tree t)
2837 return (TREE_CODE (t) == OBJ_TYPE_REF || is_gimple_val (t));
2840 /* Return true if T is a valid address operand of a MEM_REF. */
2842 bool
2843 is_gimple_mem_ref_addr (tree t)
2845 return (is_gimple_reg (t)
2846 || TREE_CODE (t) == INTEGER_CST
2847 || (TREE_CODE (t) == ADDR_EXPR
2848 && (CONSTANT_CLASS_P (TREE_OPERAND (t, 0))
2849 || decl_address_invariant_p (TREE_OPERAND (t, 0)))));
2853 /* Given a memory reference expression T, return its base address.
2854 The base address of a memory reference expression is the main
2855 object being referenced. For instance, the base address for
2856 'array[i].fld[j]' is 'array'. You can think of this as stripping
2857 away the offset part from a memory address.
2859 This function calls handled_component_p to strip away all the inner
2860 parts of the memory reference until it reaches the base object. */
2862 tree
2863 get_base_address (tree t)
2865 while (handled_component_p (t))
2866 t = TREE_OPERAND (t, 0);
2868 if ((TREE_CODE (t) == MEM_REF
2869 || TREE_CODE (t) == TARGET_MEM_REF)
2870 && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
2871 t = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
2873 /* ??? Either the alias oracle or all callers need to properly deal
2874 with WITH_SIZE_EXPRs before we can look through those. */
2875 if (TREE_CODE (t) == WITH_SIZE_EXPR)
2876 return NULL_TREE;
2878 return t;
2881 void
2882 recalculate_side_effects (tree t)
2884 enum tree_code code = TREE_CODE (t);
2885 int len = TREE_OPERAND_LENGTH (t);
2886 int i;
2888 switch (TREE_CODE_CLASS (code))
2890 case tcc_expression:
2891 switch (code)
2893 case INIT_EXPR:
2894 case MODIFY_EXPR:
2895 case VA_ARG_EXPR:
2896 case PREDECREMENT_EXPR:
2897 case PREINCREMENT_EXPR:
2898 case POSTDECREMENT_EXPR:
2899 case POSTINCREMENT_EXPR:
2900 /* All of these have side-effects, no matter what their
2901 operands are. */
2902 return;
2904 default:
2905 break;
2907 /* Fall through. */
2909 case tcc_comparison: /* a comparison expression */
2910 case tcc_unary: /* a unary arithmetic expression */
2911 case tcc_binary: /* a binary arithmetic expression */
2912 case tcc_reference: /* a reference */
2913 case tcc_vl_exp: /* a function call */
2914 TREE_SIDE_EFFECTS (t) = TREE_THIS_VOLATILE (t);
2915 for (i = 0; i < len; ++i)
2917 tree op = TREE_OPERAND (t, i);
2918 if (op && TREE_SIDE_EFFECTS (op))
2919 TREE_SIDE_EFFECTS (t) = 1;
2921 break;
2923 case tcc_constant:
2924 /* No side-effects. */
2925 return;
2927 default:
2928 gcc_unreachable ();
2932 /* Canonicalize a tree T for use in a COND_EXPR as conditional. Returns
2933 a canonicalized tree that is valid for a COND_EXPR or NULL_TREE, if
2934 we failed to create one. */
2936 tree
2937 canonicalize_cond_expr_cond (tree t)
2939 /* Strip conversions around boolean operations. */
2940 if (CONVERT_EXPR_P (t)
2941 && (truth_value_p (TREE_CODE (TREE_OPERAND (t, 0)))
2942 || TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0)))
2943 == BOOLEAN_TYPE))
2944 t = TREE_OPERAND (t, 0);
2946 /* For !x use x == 0. */
2947 if (TREE_CODE (t) == TRUTH_NOT_EXPR)
2949 tree top0 = TREE_OPERAND (t, 0);
2950 t = build2 (EQ_EXPR, TREE_TYPE (t),
2951 top0, build_int_cst (TREE_TYPE (top0), 0));
2953 /* For cmp ? 1 : 0 use cmp. */
2954 else if (TREE_CODE (t) == COND_EXPR
2955 && COMPARISON_CLASS_P (TREE_OPERAND (t, 0))
2956 && integer_onep (TREE_OPERAND (t, 1))
2957 && integer_zerop (TREE_OPERAND (t, 2)))
2959 tree top0 = TREE_OPERAND (t, 0);
2960 t = build2 (TREE_CODE (top0), TREE_TYPE (t),
2961 TREE_OPERAND (top0, 0), TREE_OPERAND (top0, 1));
2964 if (is_gimple_condexpr (t))
2965 return t;
2967 return NULL_TREE;
2970 /* Build a GIMPLE_CALL identical to STMT but skipping the arguments in
2971 the positions marked by the set ARGS_TO_SKIP. */
2973 gimple
2974 gimple_call_copy_skip_args (gimple stmt, bitmap args_to_skip)
2976 int i;
2977 int nargs = gimple_call_num_args (stmt);
2978 VEC(tree, heap) *vargs = VEC_alloc (tree, heap, nargs);
2979 gimple new_stmt;
2981 for (i = 0; i < nargs; i++)
2982 if (!bitmap_bit_p (args_to_skip, i))
2983 VEC_quick_push (tree, vargs, gimple_call_arg (stmt, i));
2985 if (gimple_call_internal_p (stmt))
2986 new_stmt = gimple_build_call_internal_vec (gimple_call_internal_fn (stmt),
2987 vargs);
2988 else
2989 new_stmt = gimple_build_call_vec (gimple_call_fn (stmt), vargs);
2990 VEC_free (tree, heap, vargs);
2991 if (gimple_call_lhs (stmt))
2992 gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt));
2994 gimple_set_vuse (new_stmt, gimple_vuse (stmt));
2995 gimple_set_vdef (new_stmt, gimple_vdef (stmt));
2997 if (gimple_has_location (stmt))
2998 gimple_set_location (new_stmt, gimple_location (stmt));
2999 gimple_call_copy_flags (new_stmt, stmt);
3000 gimple_call_set_chain (new_stmt, gimple_call_chain (stmt));
3002 gimple_set_modified (new_stmt, true);
3004 return new_stmt;
3009 /* Return true if the field decls F1 and F2 are at the same offset.
3011 This is intended to be used on GIMPLE types only. */
3013 bool
3014 gimple_compare_field_offset (tree f1, tree f2)
3016 if (DECL_OFFSET_ALIGN (f1) == DECL_OFFSET_ALIGN (f2))
3018 tree offset1 = DECL_FIELD_OFFSET (f1);
3019 tree offset2 = DECL_FIELD_OFFSET (f2);
3020 return ((offset1 == offset2
3021 /* Once gimplification is done, self-referential offsets are
3022 instantiated as operand #2 of the COMPONENT_REF built for
3023 each access and reset. Therefore, they are not relevant
3024 anymore and fields are interchangeable provided that they
3025 represent the same access. */
3026 || (TREE_CODE (offset1) == PLACEHOLDER_EXPR
3027 && TREE_CODE (offset2) == PLACEHOLDER_EXPR
3028 && (DECL_SIZE (f1) == DECL_SIZE (f2)
3029 || (TREE_CODE (DECL_SIZE (f1)) == PLACEHOLDER_EXPR
3030 && TREE_CODE (DECL_SIZE (f2)) == PLACEHOLDER_EXPR)
3031 || operand_equal_p (DECL_SIZE (f1), DECL_SIZE (f2), 0))
3032 && DECL_ALIGN (f1) == DECL_ALIGN (f2))
3033 || operand_equal_p (offset1, offset2, 0))
3034 && tree_int_cst_equal (DECL_FIELD_BIT_OFFSET (f1),
3035 DECL_FIELD_BIT_OFFSET (f2)));
3038 /* Fortran and C do not always agree on what DECL_OFFSET_ALIGN
3039 should be, so handle differing ones specially by decomposing
3040 the offset into a byte and bit offset manually. */
3041 if (host_integerp (DECL_FIELD_OFFSET (f1), 0)
3042 && host_integerp (DECL_FIELD_OFFSET (f2), 0))
3044 unsigned HOST_WIDE_INT byte_offset1, byte_offset2;
3045 unsigned HOST_WIDE_INT bit_offset1, bit_offset2;
3046 bit_offset1 = TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f1));
3047 byte_offset1 = (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f1))
3048 + bit_offset1 / BITS_PER_UNIT);
3049 bit_offset2 = TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f2));
3050 byte_offset2 = (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f2))
3051 + bit_offset2 / BITS_PER_UNIT);
3052 if (byte_offset1 != byte_offset2)
3053 return false;
3054 return bit_offset1 % BITS_PER_UNIT == bit_offset2 % BITS_PER_UNIT;
3057 return false;
3060 /* Returning a hash value for gimple type TYPE combined with VAL.
3062 The hash value returned is equal for types considered compatible
3063 by gimple_canonical_types_compatible_p. */
3065 static hashval_t
3066 iterative_hash_canonical_type (tree type, hashval_t val)
3068 hashval_t v;
3069 void **slot;
3070 struct tree_int_map *mp, m;
3072 m.base.from = type;
3073 if ((slot = htab_find_slot (canonical_type_hash_cache, &m, INSERT))
3074 && *slot)
3075 return iterative_hash_hashval_t (((struct tree_int_map *) *slot)->to, val);
3077 /* Combine a few common features of types so that types are grouped into
3078 smaller sets; when searching for existing matching types to merge,
3079 only existing types having the same features as the new type will be
3080 checked. */
3081 v = iterative_hash_hashval_t (TREE_CODE (type), 0);
3082 v = iterative_hash_hashval_t (TREE_ADDRESSABLE (type), v);
3083 v = iterative_hash_hashval_t (TYPE_ALIGN (type), v);
3084 v = iterative_hash_hashval_t (TYPE_MODE (type), v);
3086 /* Incorporate common features of numerical types. */
3087 if (INTEGRAL_TYPE_P (type)
3088 || SCALAR_FLOAT_TYPE_P (type)
3089 || FIXED_POINT_TYPE_P (type)
3090 || TREE_CODE (type) == VECTOR_TYPE
3091 || TREE_CODE (type) == COMPLEX_TYPE
3092 || TREE_CODE (type) == OFFSET_TYPE
3093 || POINTER_TYPE_P (type))
3095 v = iterative_hash_hashval_t (TYPE_PRECISION (type), v);
3096 v = iterative_hash_hashval_t (TYPE_UNSIGNED (type), v);
3099 /* For pointer and reference types, fold in information about the type
3100 pointed to but do not recurse to the pointed-to type. */
3101 if (POINTER_TYPE_P (type))
3103 v = iterative_hash_hashval_t (TYPE_REF_CAN_ALIAS_ALL (type), v);
3104 v = iterative_hash_hashval_t (TYPE_ADDR_SPACE (TREE_TYPE (type)), v);
3105 v = iterative_hash_hashval_t (TYPE_RESTRICT (type), v);
3106 v = iterative_hash_hashval_t (TREE_CODE (TREE_TYPE (type)), v);
3109 /* For integer types hash only the string flag. */
3110 if (TREE_CODE (type) == INTEGER_TYPE)
3111 v = iterative_hash_hashval_t (TYPE_STRING_FLAG (type), v);
3113 /* For array types hash the domain bounds and the string flag. */
3114 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type))
3116 v = iterative_hash_hashval_t (TYPE_STRING_FLAG (type), v);
3117 /* OMP lowering can introduce error_mark_node in place of
3118 random local decls in types. */
3119 if (TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != error_mark_node)
3120 v = iterative_hash_expr (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), v);
3121 if (TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != error_mark_node)
3122 v = iterative_hash_expr (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), v);
3125 /* Recurse for aggregates with a single element type. */
3126 if (TREE_CODE (type) == ARRAY_TYPE
3127 || TREE_CODE (type) == COMPLEX_TYPE
3128 || TREE_CODE (type) == VECTOR_TYPE)
3129 v = iterative_hash_canonical_type (TREE_TYPE (type), v);
3131 /* Incorporate function return and argument types. */
3132 if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
3134 unsigned na;
3135 tree p;
3137 /* For method types also incorporate their parent class. */
3138 if (TREE_CODE (type) == METHOD_TYPE)
3139 v = iterative_hash_canonical_type (TYPE_METHOD_BASETYPE (type), v);
3141 v = iterative_hash_canonical_type (TREE_TYPE (type), v);
3143 for (p = TYPE_ARG_TYPES (type), na = 0; p; p = TREE_CHAIN (p))
3145 v = iterative_hash_canonical_type (TREE_VALUE (p), v);
3146 na++;
3149 v = iterative_hash_hashval_t (na, v);
3152 if (RECORD_OR_UNION_TYPE_P (type))
3154 unsigned nf;
3155 tree f;
3157 for (f = TYPE_FIELDS (type), nf = 0; f; f = TREE_CHAIN (f))
3158 if (TREE_CODE (f) == FIELD_DECL)
3160 v = iterative_hash_canonical_type (TREE_TYPE (f), v);
3161 nf++;
3164 v = iterative_hash_hashval_t (nf, v);
3167 /* Cache the just computed hash value. */
3168 mp = ggc_alloc_cleared_tree_int_map ();
3169 mp->base.from = type;
3170 mp->to = v;
3171 *slot = (void *) mp;
3173 return iterative_hash_hashval_t (v, val);
3176 static hashval_t
3177 gimple_canonical_type_hash (const void *p)
3179 if (canonical_type_hash_cache == NULL)
3180 canonical_type_hash_cache = htab_create_ggc (512, tree_int_map_hash,
3181 tree_int_map_eq, NULL);
3183 return iterative_hash_canonical_type (CONST_CAST_TREE ((const_tree) p), 0);
3189 /* The TYPE_CANONICAL merging machinery. It should closely resemble
3190 the middle-end types_compatible_p function. It needs to avoid
3191 claiming types are different for types that should be treated
3192 the same with respect to TBAA. Canonical types are also used
3193 for IL consistency checks via the useless_type_conversion_p
3194 predicate which does not handle all type kinds itself but falls
3195 back to pointer-comparison of TYPE_CANONICAL for aggregates
3196 for example. */
3198 /* Return true iff T1 and T2 are structurally identical for what
3199 TBAA is concerned. */
3201 static bool
3202 gimple_canonical_types_compatible_p (tree t1, tree t2)
3204 /* Before starting to set up the SCC machinery handle simple cases. */
3206 /* Check first for the obvious case of pointer identity. */
3207 if (t1 == t2)
3208 return true;
3210 /* Check that we have two types to compare. */
3211 if (t1 == NULL_TREE || t2 == NULL_TREE)
3212 return false;
3214 /* If the types have been previously registered and found equal
3215 they still are. */
3216 if (TYPE_CANONICAL (t1)
3217 && TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2))
3218 return true;
3220 /* Can't be the same type if the types don't have the same code. */
3221 if (TREE_CODE (t1) != TREE_CODE (t2))
3222 return false;
3224 if (TREE_ADDRESSABLE (t1) != TREE_ADDRESSABLE (t2))
3225 return false;
3227 /* Qualifiers do not matter for canonical type comparison purposes. */
3229 /* Void types and nullptr types are always the same. */
3230 if (TREE_CODE (t1) == VOID_TYPE
3231 || TREE_CODE (t1) == NULLPTR_TYPE)
3232 return true;
3234 /* Can't be the same type if they have different alignment, or mode. */
3235 if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2)
3236 || TYPE_MODE (t1) != TYPE_MODE (t2))
3237 return false;
3239 /* Non-aggregate types can be handled cheaply. */
3240 if (INTEGRAL_TYPE_P (t1)
3241 || SCALAR_FLOAT_TYPE_P (t1)
3242 || FIXED_POINT_TYPE_P (t1)
3243 || TREE_CODE (t1) == VECTOR_TYPE
3244 || TREE_CODE (t1) == COMPLEX_TYPE
3245 || TREE_CODE (t1) == OFFSET_TYPE
3246 || POINTER_TYPE_P (t1))
3248 /* Can't be the same type if they have different sign or precision. */
3249 if (TYPE_PRECISION (t1) != TYPE_PRECISION (t2)
3250 || TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2))
3251 return false;
3253 if (TREE_CODE (t1) == INTEGER_TYPE
3254 && TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2))
3255 return false;
3257 /* For canonical type comparisons we do not want to build SCCs
3258 so we cannot compare pointed-to types. But we can, for now,
3259 require the same pointed-to type kind and match what
3260 useless_type_conversion_p would do. */
3261 if (POINTER_TYPE_P (t1))
3263 /* If the two pointers have different ref-all attributes,
3264 they can't be the same type. */
3265 if (TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2))
3266 return false;
3268 if (TYPE_ADDR_SPACE (TREE_TYPE (t1))
3269 != TYPE_ADDR_SPACE (TREE_TYPE (t2)))
3270 return false;
3272 if (TYPE_RESTRICT (t1) != TYPE_RESTRICT (t2))
3273 return false;
3275 if (TREE_CODE (TREE_TYPE (t1)) != TREE_CODE (TREE_TYPE (t2)))
3276 return false;
3279 /* Tail-recurse to components. */
3280 if (TREE_CODE (t1) == VECTOR_TYPE
3281 || TREE_CODE (t1) == COMPLEX_TYPE)
3282 return gimple_canonical_types_compatible_p (TREE_TYPE (t1),
3283 TREE_TYPE (t2));
3285 return true;
3288 /* Do type-specific comparisons. */
3289 switch (TREE_CODE (t1))
3291 case ARRAY_TYPE:
3292 /* Array types are the same if the element types are the same and
3293 the number of elements are the same. */
3294 if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2))
3295 || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)
3296 || TYPE_NONALIASED_COMPONENT (t1) != TYPE_NONALIASED_COMPONENT (t2))
3297 return false;
3298 else
3300 tree i1 = TYPE_DOMAIN (t1);
3301 tree i2 = TYPE_DOMAIN (t2);
3303 /* For an incomplete external array, the type domain can be
3304 NULL_TREE. Check this condition also. */
3305 if (i1 == NULL_TREE && i2 == NULL_TREE)
3306 return true;
3307 else if (i1 == NULL_TREE || i2 == NULL_TREE)
3308 return false;
3309 else
3311 tree min1 = TYPE_MIN_VALUE (i1);
3312 tree min2 = TYPE_MIN_VALUE (i2);
3313 tree max1 = TYPE_MAX_VALUE (i1);
3314 tree max2 = TYPE_MAX_VALUE (i2);
3316 /* The minimum/maximum values have to be the same. */
3317 if ((min1 == min2
3318 || (min1 && min2
3319 && ((TREE_CODE (min1) == PLACEHOLDER_EXPR
3320 && TREE_CODE (min2) == PLACEHOLDER_EXPR)
3321 || operand_equal_p (min1, min2, 0))))
3322 && (max1 == max2
3323 || (max1 && max2
3324 && ((TREE_CODE (max1) == PLACEHOLDER_EXPR
3325 && TREE_CODE (max2) == PLACEHOLDER_EXPR)
3326 || operand_equal_p (max1, max2, 0)))))
3327 return true;
3328 else
3329 return false;
3333 case METHOD_TYPE:
3334 case FUNCTION_TYPE:
3335 /* Function types are the same if the return type and arguments types
3336 are the same. */
3337 if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2)))
3338 return false;
3340 if (!comp_type_attributes (t1, t2))
3341 return false;
3343 if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2))
3344 return true;
3345 else
3347 tree parms1, parms2;
3349 for (parms1 = TYPE_ARG_TYPES (t1), parms2 = TYPE_ARG_TYPES (t2);
3350 parms1 && parms2;
3351 parms1 = TREE_CHAIN (parms1), parms2 = TREE_CHAIN (parms2))
3353 if (!gimple_canonical_types_compatible_p
3354 (TREE_VALUE (parms1), TREE_VALUE (parms2)))
3355 return false;
3358 if (parms1 || parms2)
3359 return false;
3361 return true;
3364 case RECORD_TYPE:
3365 case UNION_TYPE:
3366 case QUAL_UNION_TYPE:
3368 tree f1, f2;
3370 /* For aggregate types, all the fields must be the same. */
3371 for (f1 = TYPE_FIELDS (t1), f2 = TYPE_FIELDS (t2);
3372 f1 || f2;
3373 f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
3375 /* Skip non-fields. */
3376 while (f1 && TREE_CODE (f1) != FIELD_DECL)
3377 f1 = TREE_CHAIN (f1);
3378 while (f2 && TREE_CODE (f2) != FIELD_DECL)
3379 f2 = TREE_CHAIN (f2);
3380 if (!f1 || !f2)
3381 break;
3382 /* The fields must have the same name, offset and type. */
3383 if (DECL_NONADDRESSABLE_P (f1) != DECL_NONADDRESSABLE_P (f2)
3384 || !gimple_compare_field_offset (f1, f2)
3385 || !gimple_canonical_types_compatible_p
3386 (TREE_TYPE (f1), TREE_TYPE (f2)))
3387 return false;
3390 /* If one aggregate has more fields than the other, they
3391 are not the same. */
3392 if (f1 || f2)
3393 return false;
3395 return true;
3398 default:
3399 gcc_unreachable ();
3404 /* Returns nonzero if P1 and P2 are equal. */
3406 static int
3407 gimple_canonical_type_eq (const void *p1, const void *p2)
3409 const_tree t1 = (const_tree) p1;
3410 const_tree t2 = (const_tree) p2;
3411 return gimple_canonical_types_compatible_p (CONST_CAST_TREE (t1),
3412 CONST_CAST_TREE (t2));
3415 /* Register type T in the global type table gimple_types.
3416 If another type T', compatible with T, already existed in
3417 gimple_types then return T', otherwise return T. This is used by
3418 LTO to merge identical types read from different TUs.
3420 ??? This merging does not exactly match how the tree.c middle-end
3421 functions will assign TYPE_CANONICAL when new types are created
3422 during optimization (which at least happens for pointer and array
3423 types). */
3425 tree
3426 gimple_register_canonical_type (tree t)
3428 void **slot;
3430 gcc_assert (TYPE_P (t));
3432 if (TYPE_CANONICAL (t))
3433 return TYPE_CANONICAL (t);
3435 if (gimple_canonical_types == NULL)
3436 gimple_canonical_types = htab_create_ggc (16381, gimple_canonical_type_hash,
3437 gimple_canonical_type_eq, 0);
3439 slot = htab_find_slot (gimple_canonical_types, t, INSERT);
3440 if (*slot
3441 && *(tree *)slot != t)
3443 tree new_type = (tree) *((tree *) slot);
3445 TYPE_CANONICAL (t) = new_type;
3446 t = new_type;
3448 else
3450 TYPE_CANONICAL (t) = t;
3451 *slot = (void *) t;
3454 return t;
3458 /* Show statistics on references to the global type table gimple_types. */
3460 void
3461 print_gimple_types_stats (const char *pfx)
3463 if (gimple_canonical_types)
3464 fprintf (stderr, "[%s] GIMPLE canonical type table: size %ld, "
3465 "%ld elements, %ld searches, %ld collisions (ratio: %f)\n", pfx,
3466 (long) htab_size (gimple_canonical_types),
3467 (long) htab_elements (gimple_canonical_types),
3468 (long) gimple_canonical_types->searches,
3469 (long) gimple_canonical_types->collisions,
3470 htab_collisions (gimple_canonical_types));
3471 else
3472 fprintf (stderr, "[%s] GIMPLE canonical type table is empty\n", pfx);
3473 if (canonical_type_hash_cache)
3474 fprintf (stderr, "[%s] GIMPLE canonical type hash table: size %ld, "
3475 "%ld elements, %ld searches, %ld collisions (ratio: %f)\n", pfx,
3476 (long) htab_size (canonical_type_hash_cache),
3477 (long) htab_elements (canonical_type_hash_cache),
3478 (long) canonical_type_hash_cache->searches,
3479 (long) canonical_type_hash_cache->collisions,
3480 htab_collisions (canonical_type_hash_cache));
3481 else
3482 fprintf (stderr, "[%s] GIMPLE canonical type hash table is empty\n", pfx);
3485 /* Free the gimple type hashtables used for LTO type merging. */
3487 void
3488 free_gimple_type_tables (void)
3490 if (gimple_canonical_types)
3492 htab_delete (gimple_canonical_types);
3493 gimple_canonical_types = NULL;
3495 if (canonical_type_hash_cache)
3497 htab_delete (canonical_type_hash_cache);
3498 canonical_type_hash_cache = NULL;
3503 /* Return a type the same as TYPE except unsigned or
3504 signed according to UNSIGNEDP. */
3506 static tree
3507 gimple_signed_or_unsigned_type (bool unsignedp, tree type)
3509 tree type1;
3511 type1 = TYPE_MAIN_VARIANT (type);
3512 if (type1 == signed_char_type_node
3513 || type1 == char_type_node
3514 || type1 == unsigned_char_type_node)
3515 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
3516 if (type1 == integer_type_node || type1 == unsigned_type_node)
3517 return unsignedp ? unsigned_type_node : integer_type_node;
3518 if (type1 == short_integer_type_node || type1 == short_unsigned_type_node)
3519 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
3520 if (type1 == long_integer_type_node || type1 == long_unsigned_type_node)
3521 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
3522 if (type1 == long_long_integer_type_node
3523 || type1 == long_long_unsigned_type_node)
3524 return unsignedp
3525 ? long_long_unsigned_type_node
3526 : long_long_integer_type_node;
3527 if (int128_integer_type_node && (type1 == int128_integer_type_node || type1 == int128_unsigned_type_node))
3528 return unsignedp
3529 ? int128_unsigned_type_node
3530 : int128_integer_type_node;
3531 #if HOST_BITS_PER_WIDE_INT >= 64
3532 if (type1 == intTI_type_node || type1 == unsigned_intTI_type_node)
3533 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
3534 #endif
3535 if (type1 == intDI_type_node || type1 == unsigned_intDI_type_node)
3536 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
3537 if (type1 == intSI_type_node || type1 == unsigned_intSI_type_node)
3538 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
3539 if (type1 == intHI_type_node || type1 == unsigned_intHI_type_node)
3540 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
3541 if (type1 == intQI_type_node || type1 == unsigned_intQI_type_node)
3542 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
3544 #define GIMPLE_FIXED_TYPES(NAME) \
3545 if (type1 == short_ ## NAME ## _type_node \
3546 || type1 == unsigned_short_ ## NAME ## _type_node) \
3547 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
3548 : short_ ## NAME ## _type_node; \
3549 if (type1 == NAME ## _type_node \
3550 || type1 == unsigned_ ## NAME ## _type_node) \
3551 return unsignedp ? unsigned_ ## NAME ## _type_node \
3552 : NAME ## _type_node; \
3553 if (type1 == long_ ## NAME ## _type_node \
3554 || type1 == unsigned_long_ ## NAME ## _type_node) \
3555 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
3556 : long_ ## NAME ## _type_node; \
3557 if (type1 == long_long_ ## NAME ## _type_node \
3558 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
3559 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
3560 : long_long_ ## NAME ## _type_node;
3562 #define GIMPLE_FIXED_MODE_TYPES(NAME) \
3563 if (type1 == NAME ## _type_node \
3564 || type1 == u ## NAME ## _type_node) \
3565 return unsignedp ? u ## NAME ## _type_node \
3566 : NAME ## _type_node;
3568 #define GIMPLE_FIXED_TYPES_SAT(NAME) \
3569 if (type1 == sat_ ## short_ ## NAME ## _type_node \
3570 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
3571 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
3572 : sat_ ## short_ ## NAME ## _type_node; \
3573 if (type1 == sat_ ## NAME ## _type_node \
3574 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
3575 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
3576 : sat_ ## NAME ## _type_node; \
3577 if (type1 == sat_ ## long_ ## NAME ## _type_node \
3578 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
3579 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
3580 : sat_ ## long_ ## NAME ## _type_node; \
3581 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
3582 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
3583 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
3584 : sat_ ## long_long_ ## NAME ## _type_node;
3586 #define GIMPLE_FIXED_MODE_TYPES_SAT(NAME) \
3587 if (type1 == sat_ ## NAME ## _type_node \
3588 || type1 == sat_ ## u ## NAME ## _type_node) \
3589 return unsignedp ? sat_ ## u ## NAME ## _type_node \
3590 : sat_ ## NAME ## _type_node;
3592 GIMPLE_FIXED_TYPES (fract);
3593 GIMPLE_FIXED_TYPES_SAT (fract);
3594 GIMPLE_FIXED_TYPES (accum);
3595 GIMPLE_FIXED_TYPES_SAT (accum);
3597 GIMPLE_FIXED_MODE_TYPES (qq);
3598 GIMPLE_FIXED_MODE_TYPES (hq);
3599 GIMPLE_FIXED_MODE_TYPES (sq);
3600 GIMPLE_FIXED_MODE_TYPES (dq);
3601 GIMPLE_FIXED_MODE_TYPES (tq);
3602 GIMPLE_FIXED_MODE_TYPES_SAT (qq);
3603 GIMPLE_FIXED_MODE_TYPES_SAT (hq);
3604 GIMPLE_FIXED_MODE_TYPES_SAT (sq);
3605 GIMPLE_FIXED_MODE_TYPES_SAT (dq);
3606 GIMPLE_FIXED_MODE_TYPES_SAT (tq);
3607 GIMPLE_FIXED_MODE_TYPES (ha);
3608 GIMPLE_FIXED_MODE_TYPES (sa);
3609 GIMPLE_FIXED_MODE_TYPES (da);
3610 GIMPLE_FIXED_MODE_TYPES (ta);
3611 GIMPLE_FIXED_MODE_TYPES_SAT (ha);
3612 GIMPLE_FIXED_MODE_TYPES_SAT (sa);
3613 GIMPLE_FIXED_MODE_TYPES_SAT (da);
3614 GIMPLE_FIXED_MODE_TYPES_SAT (ta);
3616 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
3617 the precision; they have precision set to match their range, but
3618 may use a wider mode to match an ABI. If we change modes, we may
3619 wind up with bad conversions. For INTEGER_TYPEs in C, must check
3620 the precision as well, so as to yield correct results for
3621 bit-field types. C++ does not have these separate bit-field
3622 types, and producing a signed or unsigned variant of an
3623 ENUMERAL_TYPE may cause other problems as well. */
3624 if (!INTEGRAL_TYPE_P (type)
3625 || TYPE_UNSIGNED (type) == unsignedp)
3626 return type;
3628 #define TYPE_OK(node) \
3629 (TYPE_MODE (type) == TYPE_MODE (node) \
3630 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
3631 if (TYPE_OK (signed_char_type_node))
3632 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
3633 if (TYPE_OK (integer_type_node))
3634 return unsignedp ? unsigned_type_node : integer_type_node;
3635 if (TYPE_OK (short_integer_type_node))
3636 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
3637 if (TYPE_OK (long_integer_type_node))
3638 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
3639 if (TYPE_OK (long_long_integer_type_node))
3640 return (unsignedp
3641 ? long_long_unsigned_type_node
3642 : long_long_integer_type_node);
3643 if (int128_integer_type_node && TYPE_OK (int128_integer_type_node))
3644 return (unsignedp
3645 ? int128_unsigned_type_node
3646 : int128_integer_type_node);
3648 #if HOST_BITS_PER_WIDE_INT >= 64
3649 if (TYPE_OK (intTI_type_node))
3650 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
3651 #endif
3652 if (TYPE_OK (intDI_type_node))
3653 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
3654 if (TYPE_OK (intSI_type_node))
3655 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
3656 if (TYPE_OK (intHI_type_node))
3657 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
3658 if (TYPE_OK (intQI_type_node))
3659 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
3661 #undef GIMPLE_FIXED_TYPES
3662 #undef GIMPLE_FIXED_MODE_TYPES
3663 #undef GIMPLE_FIXED_TYPES_SAT
3664 #undef GIMPLE_FIXED_MODE_TYPES_SAT
3665 #undef TYPE_OK
3667 return build_nonstandard_integer_type (TYPE_PRECISION (type), unsignedp);
3671 /* Return an unsigned type the same as TYPE in other respects. */
3673 tree
3674 gimple_unsigned_type (tree type)
3676 return gimple_signed_or_unsigned_type (true, type);
3680 /* Return a signed type the same as TYPE in other respects. */
3682 tree
3683 gimple_signed_type (tree type)
3685 return gimple_signed_or_unsigned_type (false, type);
3689 /* Return the typed-based alias set for T, which may be an expression
3690 or a type. Return -1 if we don't do anything special. */
3692 alias_set_type
3693 gimple_get_alias_set (tree t)
3695 tree u;
3697 /* Permit type-punning when accessing a union, provided the access
3698 is directly through the union. For example, this code does not
3699 permit taking the address of a union member and then storing
3700 through it. Even the type-punning allowed here is a GCC
3701 extension, albeit a common and useful one; the C standard says
3702 that such accesses have implementation-defined behavior. */
3703 for (u = t;
3704 TREE_CODE (u) == COMPONENT_REF || TREE_CODE (u) == ARRAY_REF;
3705 u = TREE_OPERAND (u, 0))
3706 if (TREE_CODE (u) == COMPONENT_REF
3707 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u, 0))) == UNION_TYPE)
3708 return 0;
3710 /* That's all the expressions we handle specially. */
3711 if (!TYPE_P (t))
3712 return -1;
3714 /* For convenience, follow the C standard when dealing with
3715 character types. Any object may be accessed via an lvalue that
3716 has character type. */
3717 if (t == char_type_node
3718 || t == signed_char_type_node
3719 || t == unsigned_char_type_node)
3720 return 0;
3722 /* Allow aliasing between signed and unsigned variants of the same
3723 type. We treat the signed variant as canonical. */
3724 if (TREE_CODE (t) == INTEGER_TYPE && TYPE_UNSIGNED (t))
3726 tree t1 = gimple_signed_type (t);
3728 /* t1 == t can happen for boolean nodes which are always unsigned. */
3729 if (t1 != t)
3730 return get_alias_set (t1);
3733 return -1;
3737 /* Data structure used to count the number of dereferences to PTR
3738 inside an expression. */
3739 struct count_ptr_d
3741 tree ptr;
3742 unsigned num_stores;
3743 unsigned num_loads;
3746 /* Helper for count_uses_and_derefs. Called by walk_tree to look for
3747 (ALIGN/MISALIGNED_)INDIRECT_REF nodes for the pointer passed in DATA. */
3749 static tree
3750 count_ptr_derefs (tree *tp, int *walk_subtrees, void *data)
3752 struct walk_stmt_info *wi_p = (struct walk_stmt_info *) data;
3753 struct count_ptr_d *count_p = (struct count_ptr_d *) wi_p->info;
3755 /* Do not walk inside ADDR_EXPR nodes. In the expression &ptr->fld,
3756 pointer 'ptr' is *not* dereferenced, it is simply used to compute
3757 the address of 'fld' as 'ptr + offsetof(fld)'. */
3758 if (TREE_CODE (*tp) == ADDR_EXPR)
3760 *walk_subtrees = 0;
3761 return NULL_TREE;
3764 if (TREE_CODE (*tp) == MEM_REF && TREE_OPERAND (*tp, 0) == count_p->ptr)
3766 if (wi_p->is_lhs)
3767 count_p->num_stores++;
3768 else
3769 count_p->num_loads++;
3772 return NULL_TREE;
3775 /* Count the number of direct and indirect uses for pointer PTR in
3776 statement STMT. The number of direct uses is stored in
3777 *NUM_USES_P. Indirect references are counted separately depending
3778 on whether they are store or load operations. The counts are
3779 stored in *NUM_STORES_P and *NUM_LOADS_P. */
3781 void
3782 count_uses_and_derefs (tree ptr, gimple stmt, unsigned *num_uses_p,
3783 unsigned *num_loads_p, unsigned *num_stores_p)
3785 ssa_op_iter i;
3786 tree use;
3788 *num_uses_p = 0;
3789 *num_loads_p = 0;
3790 *num_stores_p = 0;
3792 /* Find out the total number of uses of PTR in STMT. */
3793 FOR_EACH_SSA_TREE_OPERAND (use, stmt, i, SSA_OP_USE)
3794 if (use == ptr)
3795 (*num_uses_p)++;
3797 /* Now count the number of indirect references to PTR. This is
3798 truly awful, but we don't have much choice. There are no parent
3799 pointers inside INDIRECT_REFs, so an expression like
3800 '*x_1 = foo (x_1, *x_1)' needs to be traversed piece by piece to
3801 find all the indirect and direct uses of x_1 inside. The only
3802 shortcut we can take is the fact that GIMPLE only allows
3803 INDIRECT_REFs inside the expressions below. */
3804 if (is_gimple_assign (stmt)
3805 || gimple_code (stmt) == GIMPLE_RETURN
3806 || gimple_code (stmt) == GIMPLE_ASM
3807 || is_gimple_call (stmt))
3809 struct walk_stmt_info wi;
3810 struct count_ptr_d count;
3812 count.ptr = ptr;
3813 count.num_stores = 0;
3814 count.num_loads = 0;
3816 memset (&wi, 0, sizeof (wi));
3817 wi.info = &count;
3818 walk_gimple_op (stmt, count_ptr_derefs, &wi);
3820 *num_stores_p = count.num_stores;
3821 *num_loads_p = count.num_loads;
3824 gcc_assert (*num_uses_p >= *num_loads_p + *num_stores_p);
3827 /* From a tree operand OP return the base of a load or store operation
3828 or NULL_TREE if OP is not a load or a store. */
3830 static tree
3831 get_base_loadstore (tree op)
3833 while (handled_component_p (op))
3834 op = TREE_OPERAND (op, 0);
3835 if (DECL_P (op)
3836 || INDIRECT_REF_P (op)
3837 || TREE_CODE (op) == MEM_REF
3838 || TREE_CODE (op) == TARGET_MEM_REF)
3839 return op;
3840 return NULL_TREE;
3843 /* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE and
3844 VISIT_ADDR if non-NULL on loads, store and address-taken operands
3845 passing the STMT, the base of the operand and DATA to it. The base
3846 will be either a decl, an indirect reference (including TARGET_MEM_REF)
3847 or the argument of an address expression.
3848 Returns the results of these callbacks or'ed. */
3850 bool
3851 walk_stmt_load_store_addr_ops (gimple stmt, void *data,
3852 bool (*visit_load)(gimple, tree, void *),
3853 bool (*visit_store)(gimple, tree, void *),
3854 bool (*visit_addr)(gimple, tree, void *))
3856 bool ret = false;
3857 unsigned i;
3858 if (gimple_assign_single_p (stmt))
3860 tree lhs, rhs;
3861 if (visit_store)
3863 lhs = get_base_loadstore (gimple_assign_lhs (stmt));
3864 if (lhs)
3865 ret |= visit_store (stmt, lhs, data);
3867 rhs = gimple_assign_rhs1 (stmt);
3868 while (handled_component_p (rhs))
3869 rhs = TREE_OPERAND (rhs, 0);
3870 if (visit_addr)
3872 if (TREE_CODE (rhs) == ADDR_EXPR)
3873 ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), data);
3874 else if (TREE_CODE (rhs) == TARGET_MEM_REF
3875 && TREE_CODE (TMR_BASE (rhs)) == ADDR_EXPR)
3876 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (rhs), 0), data);
3877 else if (TREE_CODE (rhs) == OBJ_TYPE_REF
3878 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs)) == ADDR_EXPR)
3879 ret |= visit_addr (stmt, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs),
3880 0), data);
3881 else if (TREE_CODE (rhs) == CONSTRUCTOR)
3883 unsigned int ix;
3884 tree val;
3886 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (rhs), ix, val)
3887 if (TREE_CODE (val) == ADDR_EXPR)
3888 ret |= visit_addr (stmt, TREE_OPERAND (val, 0), data);
3889 else if (TREE_CODE (val) == OBJ_TYPE_REF
3890 && TREE_CODE (OBJ_TYPE_REF_OBJECT (val)) == ADDR_EXPR)
3891 ret |= visit_addr (stmt,
3892 TREE_OPERAND (OBJ_TYPE_REF_OBJECT (val),
3893 0), data);
3895 lhs = gimple_assign_lhs (stmt);
3896 if (TREE_CODE (lhs) == TARGET_MEM_REF
3897 && TREE_CODE (TMR_BASE (lhs)) == ADDR_EXPR)
3898 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (lhs), 0), data);
3900 if (visit_load)
3902 rhs = get_base_loadstore (rhs);
3903 if (rhs)
3904 ret |= visit_load (stmt, rhs, data);
3907 else if (visit_addr
3908 && (is_gimple_assign (stmt)
3909 || gimple_code (stmt) == GIMPLE_COND))
3911 for (i = 0; i < gimple_num_ops (stmt); ++i)
3913 tree op = gimple_op (stmt, i);
3914 if (op == NULL_TREE)
3916 else if (TREE_CODE (op) == ADDR_EXPR)
3917 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
3918 /* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
3919 tree with two operands. */
3920 else if (i == 1 && COMPARISON_CLASS_P (op))
3922 if (TREE_CODE (TREE_OPERAND (op, 0)) == ADDR_EXPR)
3923 ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 0),
3924 0), data);
3925 if (TREE_CODE (TREE_OPERAND (op, 1)) == ADDR_EXPR)
3926 ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 1),
3927 0), data);
3931 else if (is_gimple_call (stmt))
3933 if (visit_store)
3935 tree lhs = gimple_call_lhs (stmt);
3936 if (lhs)
3938 lhs = get_base_loadstore (lhs);
3939 if (lhs)
3940 ret |= visit_store (stmt, lhs, data);
3943 if (visit_load || visit_addr)
3944 for (i = 0; i < gimple_call_num_args (stmt); ++i)
3946 tree rhs = gimple_call_arg (stmt, i);
3947 if (visit_addr
3948 && TREE_CODE (rhs) == ADDR_EXPR)
3949 ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), data);
3950 else if (visit_load)
3952 rhs = get_base_loadstore (rhs);
3953 if (rhs)
3954 ret |= visit_load (stmt, rhs, data);
3957 if (visit_addr
3958 && gimple_call_chain (stmt)
3959 && TREE_CODE (gimple_call_chain (stmt)) == ADDR_EXPR)
3960 ret |= visit_addr (stmt, TREE_OPERAND (gimple_call_chain (stmt), 0),
3961 data);
3962 if (visit_addr
3963 && gimple_call_return_slot_opt_p (stmt)
3964 && gimple_call_lhs (stmt) != NULL_TREE
3965 && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (stmt))))
3966 ret |= visit_addr (stmt, gimple_call_lhs (stmt), data);
3968 else if (gimple_code (stmt) == GIMPLE_ASM)
3970 unsigned noutputs;
3971 const char *constraint;
3972 const char **oconstraints;
3973 bool allows_mem, allows_reg, is_inout;
3974 noutputs = gimple_asm_noutputs (stmt);
3975 oconstraints = XALLOCAVEC (const char *, noutputs);
3976 if (visit_store || visit_addr)
3977 for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
3979 tree link = gimple_asm_output_op (stmt, i);
3980 tree op = get_base_loadstore (TREE_VALUE (link));
3981 if (op && visit_store)
3982 ret |= visit_store (stmt, op, data);
3983 if (visit_addr)
3985 constraint = TREE_STRING_POINTER
3986 (TREE_VALUE (TREE_PURPOSE (link)));
3987 oconstraints[i] = constraint;
3988 parse_output_constraint (&constraint, i, 0, 0, &allows_mem,
3989 &allows_reg, &is_inout);
3990 if (op && !allows_reg && allows_mem)
3991 ret |= visit_addr (stmt, op, data);
3994 if (visit_load || visit_addr)
3995 for (i = 0; i < gimple_asm_ninputs (stmt); ++i)
3997 tree link = gimple_asm_input_op (stmt, i);
3998 tree op = TREE_VALUE (link);
3999 if (visit_addr
4000 && TREE_CODE (op) == ADDR_EXPR)
4001 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
4002 else if (visit_load || visit_addr)
4004 op = get_base_loadstore (op);
4005 if (op)
4007 if (visit_load)
4008 ret |= visit_load (stmt, op, data);
4009 if (visit_addr)
4011 constraint = TREE_STRING_POINTER
4012 (TREE_VALUE (TREE_PURPOSE (link)));
4013 parse_input_constraint (&constraint, 0, 0, noutputs,
4014 0, oconstraints,
4015 &allows_mem, &allows_reg);
4016 if (!allows_reg && allows_mem)
4017 ret |= visit_addr (stmt, op, data);
4023 else if (gimple_code (stmt) == GIMPLE_RETURN)
4025 tree op = gimple_return_retval (stmt);
4026 if (op)
4028 if (visit_addr
4029 && TREE_CODE (op) == ADDR_EXPR)
4030 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
4031 else if (visit_load)
4033 op = get_base_loadstore (op);
4034 if (op)
4035 ret |= visit_load (stmt, op, data);
4039 else if (visit_addr
4040 && gimple_code (stmt) == GIMPLE_PHI)
4042 for (i = 0; i < gimple_phi_num_args (stmt); ++i)
4044 tree op = PHI_ARG_DEF (stmt, i);
4045 if (TREE_CODE (op) == ADDR_EXPR)
4046 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
4050 return ret;
4053 /* Like walk_stmt_load_store_addr_ops but with NULL visit_addr. IPA-CP
4054 should make a faster clone for this case. */
4056 bool
4057 walk_stmt_load_store_ops (gimple stmt, void *data,
4058 bool (*visit_load)(gimple, tree, void *),
4059 bool (*visit_store)(gimple, tree, void *))
4061 return walk_stmt_load_store_addr_ops (stmt, data,
4062 visit_load, visit_store, NULL);
4065 /* Helper for gimple_ior_addresses_taken_1. */
4067 static bool
4068 gimple_ior_addresses_taken_1 (gimple stmt ATTRIBUTE_UNUSED,
4069 tree addr, void *data)
4071 bitmap addresses_taken = (bitmap)data;
4072 addr = get_base_address (addr);
4073 if (addr
4074 && DECL_P (addr))
4076 bitmap_set_bit (addresses_taken, DECL_UID (addr));
4077 return true;
4079 return false;
4082 /* Set the bit for the uid of all decls that have their address taken
4083 in STMT in the ADDRESSES_TAKEN bitmap. Returns true if there
4084 were any in this stmt. */
4086 bool
4087 gimple_ior_addresses_taken (bitmap addresses_taken, gimple stmt)
4089 return walk_stmt_load_store_addr_ops (stmt, addresses_taken, NULL, NULL,
4090 gimple_ior_addresses_taken_1);
4094 /* Return a printable name for symbol DECL. */
4096 const char *
4097 gimple_decl_printable_name (tree decl, int verbosity)
4099 if (!DECL_NAME (decl))
4100 return NULL;
4102 if (DECL_ASSEMBLER_NAME_SET_P (decl))
4104 const char *str, *mangled_str;
4105 int dmgl_opts = DMGL_NO_OPTS;
4107 if (verbosity >= 2)
4109 dmgl_opts = DMGL_VERBOSE
4110 | DMGL_ANSI
4111 | DMGL_GNU_V3
4112 | DMGL_RET_POSTFIX;
4113 if (TREE_CODE (decl) == FUNCTION_DECL)
4114 dmgl_opts |= DMGL_PARAMS;
4117 mangled_str = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4118 str = cplus_demangle_v3 (mangled_str, dmgl_opts);
4119 return (str) ? str : mangled_str;
4122 return IDENTIFIER_POINTER (DECL_NAME (decl));
4125 /* Return true when STMT is builtins call to CODE. */
4127 bool
4128 gimple_call_builtin_p (gimple stmt, enum built_in_function code)
4130 tree fndecl;
4131 return (is_gimple_call (stmt)
4132 && (fndecl = gimple_call_fndecl (stmt)) != NULL
4133 && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
4134 && DECL_FUNCTION_CODE (fndecl) == code);
4137 /* Return true if STMT clobbers memory. STMT is required to be a
4138 GIMPLE_ASM. */
4140 bool
4141 gimple_asm_clobbers_memory_p (const_gimple stmt)
4143 unsigned i;
4145 for (i = 0; i < gimple_asm_nclobbers (stmt); i++)
4147 tree op = gimple_asm_clobber_op (stmt, i);
4148 if (strcmp (TREE_STRING_POINTER (TREE_VALUE (op)), "memory") == 0)
4149 return true;
4152 return false;
4154 #include "gt-gimple.h"