]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/gimple.c
avx2-vpop-check.h: volatility is casted away in memcmp().
[thirdparty/gcc.git] / gcc / gimple.c
CommitLineData
726a989a
RB
1/* Gimple IR support functions.
2
d1e082c2 3 Copyright (C) 2007-2013 Free Software Foundation, Inc.
726a989a
RB
4 Contributed by Aldy Hernandez <aldyh@redhat.com>
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
10Software Foundation; either version 3, or (at your option) any later
11version.
12
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
17
18You should have received a copy of the GNU General Public License
19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
21
22#include "config.h"
23#include "system.h"
24#include "coretypes.h"
25#include "tm.h"
d7f09764 26#include "target.h"
726a989a
RB
27#include "tree.h"
28#include "ggc.h"
726a989a
RB
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"
d7f09764 36#include "alias.h"
4537ec0c 37#include "demangle.h"
0f443ad0 38#include "langhooks.h"
726a989a 39
b8f4e58f 40/* Global canonical type table. */
4490cae6
RG
41static GTY((if_marked ("ggc_marked_p"), param_is (union tree_node)))
42 htab_t gimple_canonical_types;
a844a60b
RG
43static GTY((if_marked ("tree_int_map_marked_p"), param_is (struct tree_int_map)))
44 htab_t canonical_type_hash_cache;
d7f09764 45
f2c4a81c 46/* All the tuples have their operand vector (if present) at the very bottom
726a989a
RB
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). */
f2c4a81c
RH
50#define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) \
51 (HAS_TREE_OP ? sizeof (struct STRUCT) - sizeof (tree) : 0),
6bc7bc14 52EXPORTED_CONST size_t gimple_ops_offset_[] = {
f2c4a81c
RH
53#include "gsstruct.def"
54};
55#undef DEFGSSTRUCT
56
57#define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) sizeof(struct STRUCT),
58static const size_t gsstruct_code_size[] = {
59#include "gsstruct.def"
60};
61#undef DEFGSSTRUCT
62
63#define DEFGSCODE(SYM, NAME, GSSCODE) NAME,
64const char *const gimple_code_name[] = {
65#include "gimple.def"
66};
67#undef DEFGSCODE
68
69#define DEFGSCODE(SYM, NAME, GSSCODE) GSSCODE,
70EXPORTED_CONST enum gimple_statement_structure_enum gss_for_code_[] = {
726a989a
RB
71#include "gimple.def"
72};
73#undef DEFGSCODE
74
726a989a
RB
75/* Gimple stats. */
76
77int gimple_alloc_counts[(int) gimple_alloc_kind_all];
78int gimple_alloc_sizes[(int) gimple_alloc_kind_all];
79
80/* Keep in sync with gimple.h:enum gimple_alloc_kind. */
81static const char * const gimple_alloc_kind_names[] = {
82 "assignments",
83 "phi nodes",
84 "conditionals",
726a989a
RB
85 "everything else"
86};
87
726a989a
RB
88/* Private API manipulation functions shared only with some
89 other files. */
90extern void gimple_set_stored_syms (gimple, bitmap, bitmap_obstack *);
91extern void gimple_set_loaded_syms (gimple, bitmap, bitmap_obstack *);
92
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. */
96
97/* Set the code for statement G to CODE. */
98
99static inline void
100gimple_set_code (gimple g, enum gimple_code code)
101{
102 g->gsbase.code = code;
103}
104
726a989a
RB
105/* Return the number of bytes needed to hold a GIMPLE statement with
106 code CODE. */
107
f2c4a81c 108static inline size_t
726a989a
RB
109gimple_size (enum gimple_code code)
110{
f2c4a81c 111 return gsstruct_code_size[gss_for_code (code)];
726a989a
RB
112}
113
726a989a
RB
114/* Allocate memory for a GIMPLE statement with code CODE and NUM_OPS
115 operands. */
116
d7f09764 117gimple
726a989a
RB
118gimple_alloc_stat (enum gimple_code code, unsigned num_ops MEM_STAT_DECL)
119{
120 size_t size;
121 gimple stmt;
122
123 size = gimple_size (code);
124 if (num_ops > 0)
125 size += sizeof (tree) * (num_ops - 1);
126
7aa6d18a
SB
127 if (GATHER_STATISTICS)
128 {
129 enum gimple_alloc_kind kind = gimple_alloc_kind (code);
130 gimple_alloc_counts[(int) kind]++;
131 gimple_alloc_sizes[(int) kind] += size;
132 }
726a989a 133
a9429e29 134 stmt = ggc_alloc_cleared_gimple_statement_d_stat (size PASS_MEM_STAT);
726a989a
RB
135 gimple_set_code (stmt, code);
136 gimple_set_num_ops (stmt, num_ops);
137
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;
355a7673 141 gimple_init_singleton (stmt);
726a989a
RB
142
143 return stmt;
144}
145
146/* Set SUBCODE to be the code of the expression computed by statement G. */
147
148static inline void
149gimple_set_subcode (gimple g, unsigned subcode)
150{
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;
155}
156
157
158
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
b8698a0f 161 for the new tuple. NUM_OPS is the number of operands to allocate. */
726a989a
RB
162
163#define gimple_build_with_ops(c, s, n) \
164 gimple_build_with_ops_stat (c, s, n MEM_STAT_INFO)
165
166static gimple
b5b8b0ac 167gimple_build_with_ops_stat (enum gimple_code code, unsigned subcode,
726a989a
RB
168 unsigned num_ops MEM_STAT_DECL)
169{
170 gimple s = gimple_alloc_stat (code, num_ops PASS_MEM_STAT);
171 gimple_set_subcode (s, subcode);
172
173 return s;
174}
175
176
177/* Build a GIMPLE_RETURN statement returning RETVAL. */
178
179gimple
180gimple_build_return (tree retval)
181{
bbbbb16a 182 gimple s = gimple_build_with_ops (GIMPLE_RETURN, ERROR_MARK, 1);
726a989a
RB
183 if (retval)
184 gimple_return_set_retval (s, retval);
185 return s;
186}
187
d086d311
RG
188/* Reset alias information on call S. */
189
190void
191gimple_call_reset_alias_info (gimple s)
192{
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));
201}
202
21860814
JJ
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. */
726a989a
RB
207
208static inline gimple
209gimple_build_call_1 (tree fn, unsigned nargs)
210{
bbbbb16a 211 gimple s = gimple_build_with_ops (GIMPLE_CALL, ERROR_MARK, nargs + 3);
7c9577be
RG
212 if (TREE_CODE (fn) == FUNCTION_DECL)
213 fn = build_fold_addr_expr (fn);
726a989a 214 gimple_set_op (s, 1, fn);
f20ca725 215 gimple_call_set_fntype (s, TREE_TYPE (TREE_TYPE (fn)));
d086d311 216 gimple_call_reset_alias_info (s);
726a989a
RB
217 return s;
218}
219
220
221/* Build a GIMPLE_CALL statement to function FN with the arguments
222 specified in vector ARGS. */
223
224gimple
9771b263 225gimple_build_call_vec (tree fn, vec<tree> args)
726a989a
RB
226{
227 unsigned i;
9771b263 228 unsigned nargs = args.length ();
726a989a
RB
229 gimple call = gimple_build_call_1 (fn, nargs);
230
231 for (i = 0; i < nargs; i++)
9771b263 232 gimple_call_set_arg (call, i, args[i]);
726a989a
RB
233
234 return call;
235}
236
237
238/* Build a GIMPLE_CALL statement to function FN. NARGS is the number of
239 arguments. The ... are the arguments. */
240
241gimple
242gimple_build_call (tree fn, unsigned nargs, ...)
243{
244 va_list ap;
245 gimple call;
246 unsigned i;
247
248 gcc_assert (TREE_CODE (fn) == FUNCTION_DECL || is_gimple_call_addr (fn));
249
250 call = gimple_build_call_1 (fn, nargs);
251
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);
256
257 return call;
258}
259
260
21860814
JJ
261/* Build a GIMPLE_CALL statement to function FN. NARGS is the number of
262 arguments. AP contains the arguments. */
263
264gimple
265gimple_build_call_valist (tree fn, unsigned nargs, va_list ap)
266{
267 gimple call;
268 unsigned i;
269
270 gcc_assert (TREE_CODE (fn) == FUNCTION_DECL || is_gimple_call_addr (fn));
271
272 call = gimple_build_call_1 (fn, nargs);
273
274 for (i = 0; i < nargs; i++)
275 gimple_call_set_arg (call, i, va_arg (ap, tree));
276
277 return call;
278}
279
280
25583c4f
RS
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. */
284
285static inline gimple
286gimple_build_call_internal_1 (enum internal_fn fn, unsigned nargs)
287{
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;
293}
294
295
296/* Build a GIMPLE_CALL statement to internal function FN. NARGS is
297 the number of arguments. The ... are the arguments. */
298
299gimple
300gimple_build_call_internal (enum internal_fn fn, unsigned nargs, ...)
301{
302 va_list ap;
303 gimple call;
304 unsigned i;
305
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);
311
312 return call;
313}
314
315
316/* Build a GIMPLE_CALL statement to internal function FN with the arguments
317 specified in vector ARGS. */
318
319gimple
9771b263 320gimple_build_call_internal_vec (enum internal_fn fn, vec<tree> args)
25583c4f
RS
321{
322 unsigned i, nargs;
323 gimple call;
324
9771b263 325 nargs = args.length ();
25583c4f
RS
326 call = gimple_build_call_internal_1 (fn, nargs);
327 for (i = 0; i < nargs; i++)
9771b263 328 gimple_call_set_arg (call, i, args[i]);
25583c4f
RS
329
330 return call;
331}
332
333
726a989a
RB
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. */
337
338gimple
339gimple_build_call_from_tree (tree t)
340{
341 unsigned i, nargs;
342 gimple call;
343 tree fndecl = get_callee_fndecl (t);
344
345 gcc_assert (TREE_CODE (t) == CALL_EXPR);
346
347 nargs = call_expr_nargs (t);
348 call = gimple_build_call_1 (fndecl ? fndecl : CALL_EXPR_FN (t), nargs);
349
350 for (i = 0; i < nargs; i++)
351 gimple_call_set_arg (call, i, CALL_EXPR_ARG (t, i));
352
353 gimple_set_block (call, TREE_BLOCK (t));
354
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));
726a989a 358 gimple_call_set_return_slot_opt (call, CALL_EXPR_RETURN_SLOT_OPT (t));
63d2a353
MM
359 if (fndecl
360 && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
13e49da9
TV
361 && (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA
362 || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA_WITH_ALIGN))
63d2a353
MM
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));
726a989a 366 gimple_call_set_va_arg_pack (call, CALL_EXPR_VA_ARG_PACK (t));
9bb1a81b 367 gimple_call_set_nothrow (call, TREE_NOTHROW (t));
d665b6e5 368 gimple_set_no_warning (call, TREE_NO_WARNING (t));
726a989a
RB
369
370 return call;
371}
372
373
374/* Extract the operands and code for expression EXPR into *SUBCODE_P,
0354c0c7 375 *OP1_P, *OP2_P and *OP3_P respectively. */
726a989a
RB
376
377void
0354c0c7
BS
378extract_ops_from_tree_1 (tree expr, enum tree_code *subcode_p, tree *op1_p,
379 tree *op2_p, tree *op3_p)
726a989a 380{
82d6e6fc 381 enum gimple_rhs_class grhs_class;
726a989a
RB
382
383 *subcode_p = TREE_CODE (expr);
82d6e6fc 384 grhs_class = get_gimple_rhs_class (*subcode_p);
726a989a 385
0354c0c7 386 if (grhs_class == GIMPLE_TERNARY_RHS)
726a989a
RB
387 {
388 *op1_p = TREE_OPERAND (expr, 0);
389 *op2_p = TREE_OPERAND (expr, 1);
0354c0c7
BS
390 *op3_p = TREE_OPERAND (expr, 2);
391 }
392 else if (grhs_class == GIMPLE_BINARY_RHS)
393 {
394 *op1_p = TREE_OPERAND (expr, 0);
395 *op2_p = TREE_OPERAND (expr, 1);
396 *op3_p = NULL_TREE;
726a989a 397 }
82d6e6fc 398 else if (grhs_class == GIMPLE_UNARY_RHS)
726a989a
RB
399 {
400 *op1_p = TREE_OPERAND (expr, 0);
401 *op2_p = NULL_TREE;
0354c0c7 402 *op3_p = NULL_TREE;
726a989a 403 }
82d6e6fc 404 else if (grhs_class == GIMPLE_SINGLE_RHS)
726a989a
RB
405 {
406 *op1_p = expr;
407 *op2_p = NULL_TREE;
0354c0c7 408 *op3_p = NULL_TREE;
726a989a
RB
409 }
410 else
411 gcc_unreachable ();
412}
413
414
415/* Build a GIMPLE_ASSIGN statement.
416
417 LHS of the assignment.
418 RHS of the assignment which can be unary or binary. */
419
420gimple
421gimple_build_assign_stat (tree lhs, tree rhs MEM_STAT_DECL)
422{
423 enum tree_code subcode;
0354c0c7 424 tree op1, op2, op3;
726a989a 425
0354c0c7 426 extract_ops_from_tree_1 (rhs, &subcode, &op1, &op2, &op3);
73804b12
RG
427 return gimple_build_assign_with_ops (subcode, lhs, op1, op2, op3
428 PASS_MEM_STAT);
726a989a
RB
429}
430
431
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. */
435
436gimple
73804b12
RG
437gimple_build_assign_with_ops (enum tree_code subcode, tree lhs, tree op1,
438 tree op2, tree op3 MEM_STAT_DECL)
726a989a
RB
439{
440 unsigned num_ops;
441 gimple p;
442
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;
b8698a0f 446
b5b8b0ac 447 p = gimple_build_with_ops_stat (GIMPLE_ASSIGN, (unsigned)subcode, num_ops
726a989a
RB
448 PASS_MEM_STAT);
449 gimple_assign_set_lhs (p, lhs);
450 gimple_assign_set_rhs1 (p, op1);
451 if (op2)
452 {
453 gcc_assert (num_ops > 2);
454 gimple_assign_set_rhs2 (p, op2);
455 }
456
0354c0c7
BS
457 if (op3)
458 {
459 gcc_assert (num_ops > 3);
460 gimple_assign_set_rhs3 (p, op3);
461 }
462
726a989a
RB
463 return p;
464}
465
73804b12
RG
466gimple
467gimple_build_assign_with_ops (enum tree_code subcode, tree lhs, tree op1,
468 tree op2 MEM_STAT_DECL)
469{
470 return gimple_build_assign_with_ops (subcode, lhs, op1, op2, NULL_TREE
471 PASS_MEM_STAT);
472}
473
726a989a
RB
474
475/* Build a new GIMPLE_ASSIGN tuple and append it to the end of *SEQ_P.
476
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.
480
481 This function returns the newly created GIMPLE_ASSIGN tuple. */
482
5fd8300b 483gimple
726a989a 484gimplify_assign (tree dst, tree src, gimple_seq *seq_p)
b8698a0f 485{
726a989a
RB
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);
490}
491
492
493/* Build a GIMPLE_COND statement.
494
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. */
498
499gimple
500gimple_build_cond (enum tree_code pred_code, tree lhs, tree rhs,
501 tree t_label, tree f_label)
502{
503 gimple p;
504
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;
512}
513
514
515/* Extract operands for a GIMPLE_COND statement out of COND_EXPR tree COND. */
516
517void
518gimple_cond_get_ops_from_tree (tree cond, enum tree_code *code_p,
519 tree *lhs_p, tree *rhs_p)
520{
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));
525
526 extract_ops_from_tree (cond, code_p, lhs_p, rhs_p);
527
528 /* Canonicalize conditionals of the form 'if (!VAL)'. */
529 if (*code_p == TRUTH_NOT_EXPR)
530 {
531 *code_p = EQ_EXPR;
532 gcc_assert (*lhs_p && *rhs_p == NULL_TREE);
e8160c9a 533 *rhs_p = build_zero_cst (TREE_TYPE (*lhs_p));
726a989a
RB
534 }
535 /* Canonicalize conditionals of the form 'if (VAL)' */
536 else if (TREE_CODE_CLASS (*code_p) != tcc_comparison)
537 {
538 *code_p = NE_EXPR;
539 gcc_assert (*lhs_p && *rhs_p == NULL_TREE);
e8160c9a 540 *rhs_p = build_zero_cst (TREE_TYPE (*lhs_p));
726a989a
RB
541 }
542}
543
544
545/* Build a GIMPLE_COND statement from the conditional expression tree
546 COND. T_LABEL and F_LABEL are as in gimple_build_cond. */
547
548gimple
549gimple_build_cond_from_tree (tree cond, tree t_label, tree f_label)
550{
551 enum tree_code code;
552 tree lhs, rhs;
553
554 gimple_cond_get_ops_from_tree (cond, &code, &lhs, &rhs);
555 return gimple_build_cond (code, lhs, rhs, t_label, f_label);
556}
557
558/* Set code, lhs, and rhs of a GIMPLE_COND from a suitable
559 boolean expression tree COND. */
560
561void
562gimple_cond_set_condition_from_tree (gimple stmt, tree cond)
563{
564 enum tree_code code;
565 tree lhs, rhs;
566
567 gimple_cond_get_ops_from_tree (cond, &code, &lhs, &rhs);
568 gimple_cond_set_condition (stmt, code, lhs, rhs);
569}
570
571/* Build a GIMPLE_LABEL statement for LABEL. */
572
573gimple
574gimple_build_label (tree label)
575{
bbbbb16a 576 gimple p = gimple_build_with_ops (GIMPLE_LABEL, ERROR_MARK, 1);
726a989a
RB
577 gimple_label_set_label (p, label);
578 return p;
579}
580
581/* Build a GIMPLE_GOTO statement to label DEST. */
582
583gimple
584gimple_build_goto (tree dest)
585{
bbbbb16a 586 gimple p = gimple_build_with_ops (GIMPLE_GOTO, ERROR_MARK, 1);
726a989a
RB
587 gimple_goto_set_dest (p, dest);
588 return p;
589}
590
591
592/* Build a GIMPLE_NOP statement. */
593
b8698a0f 594gimple
726a989a
RB
595gimple_build_nop (void)
596{
597 return gimple_alloc (GIMPLE_NOP, 0);
598}
599
600
601/* Build a GIMPLE_BIND statement.
602 VARS are the variables in BODY.
603 BLOCK is the containing block. */
604
605gimple
606gimple_build_bind (tree vars, gimple_seq body, tree block)
607{
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;
615}
616
617/* Helper function to set the simple fields of a asm stmt.
618
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.
623 */
624
625static inline gimple
b8698a0f 626gimple_build_asm_1 (const char *string, unsigned ninputs, unsigned noutputs,
1c384bf1 627 unsigned nclobbers, unsigned nlabels)
726a989a
RB
628{
629 gimple p;
630 int size = strlen (string);
631
1c384bf1
RH
632 /* ASMs with labels cannot have outputs. This should have been
633 enforced by the front end. */
634 gcc_assert (nlabels == 0 || noutputs == 0);
635
bbbbb16a 636 p = gimple_build_with_ops (GIMPLE_ASM, ERROR_MARK,
1c384bf1 637 ninputs + noutputs + nclobbers + nlabels);
726a989a
RB
638
639 p->gimple_asm.ni = ninputs;
640 p->gimple_asm.no = noutputs;
641 p->gimple_asm.nc = nclobbers;
1c384bf1 642 p->gimple_asm.nl = nlabels;
726a989a
RB
643 p->gimple_asm.string = ggc_alloc_string (string, size);
644
7aa6d18a
SB
645 if (GATHER_STATISTICS)
646 gimple_alloc_sizes[(int) gimple_alloc_kind (GIMPLE_ASM)] += size;
b8698a0f 647
726a989a
RB
648 return p;
649}
650
651/* Build a GIMPLE_ASM statement.
652
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.
1c384bf1
RH
659 CLOBBERS is a vector of the clobbered register parameters.
660 LABELS is a vector of destination labels. */
726a989a
RB
661
662gimple
9771b263
DN
663gimple_build_asm_vec (const char *string, vec<tree, va_gc> *inputs,
664 vec<tree, va_gc> *outputs, vec<tree, va_gc> *clobbers,
665 vec<tree, va_gc> *labels)
726a989a
RB
666{
667 gimple p;
668 unsigned i;
669
670 p = gimple_build_asm_1 (string,
9771b263
DN
671 vec_safe_length (inputs),
672 vec_safe_length (outputs),
673 vec_safe_length (clobbers),
674 vec_safe_length (labels));
b8698a0f 675
9771b263
DN
676 for (i = 0; i < vec_safe_length (inputs); i++)
677 gimple_asm_set_input_op (p, i, (*inputs)[i]);
726a989a 678
9771b263
DN
679 for (i = 0; i < vec_safe_length (outputs); i++)
680 gimple_asm_set_output_op (p, i, (*outputs)[i]);
726a989a 681
9771b263
DN
682 for (i = 0; i < vec_safe_length (clobbers); i++)
683 gimple_asm_set_clobber_op (p, i, (*clobbers)[i]);
b8698a0f 684
9771b263
DN
685 for (i = 0; i < vec_safe_length (labels); i++)
686 gimple_asm_set_label_op (p, i, (*labels)[i]);
b8698a0f 687
726a989a
RB
688 return p;
689}
690
691/* Build a GIMPLE_CATCH statement.
692
693 TYPES are the catch types.
694 HANDLER is the exception handler. */
695
696gimple
697gimple_build_catch (tree types, gimple_seq handler)
698{
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);
703
704 return p;
705}
706
707/* Build a GIMPLE_EH_FILTER statement.
708
709 TYPES are the filter's types.
710 FAILURE is the filter's failure action. */
711
712gimple
713gimple_build_eh_filter (tree types, gimple_seq failure)
714{
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);
719
720 return p;
721}
722
1d65f45c
RH
723/* Build a GIMPLE_EH_MUST_NOT_THROW statement. */
724
725gimple
726gimple_build_eh_must_not_throw (tree decl)
727{
786f715d 728 gimple p = gimple_alloc (GIMPLE_EH_MUST_NOT_THROW, 0);
1d65f45c
RH
729
730 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
731 gcc_assert (flags_from_decl_or_type (decl) & ECF_NORETURN);
d7f09764 732 gimple_eh_must_not_throw_set_fndecl (p, decl);
1d65f45c
RH
733
734 return p;
735}
736
0a35513e
AH
737/* Build a GIMPLE_EH_ELSE statement. */
738
739gimple
740gimple_build_eh_else (gimple_seq n_body, gimple_seq e_body)
741{
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;
746}
747
726a989a
RB
748/* Build a GIMPLE_TRY statement.
749
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. */
754
755gimple
756gimple_build_try (gimple_seq eval, gimple_seq cleanup,
757 enum gimple_try_flags kind)
758{
759 gimple p;
760
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);
768
769 return p;
770}
771
772/* Construct a GIMPLE_WITH_CLEANUP_EXPR statement.
773
774 CLEANUP is the cleanup expression. */
775
776gimple
777gimple_build_wce (gimple_seq cleanup)
778{
779 gimple p = gimple_alloc (GIMPLE_WITH_CLEANUP_EXPR, 0);
780 if (cleanup)
781 gimple_wce_set_cleanup (p, cleanup);
782
783 return p;
784}
785
786
1d65f45c 787/* Build a GIMPLE_RESX statement. */
726a989a
RB
788
789gimple
790gimple_build_resx (int region)
791{
1d65f45c
RH
792 gimple p = gimple_build_with_ops (GIMPLE_RESX, ERROR_MARK, 0);
793 p->gimple_eh_ctrl.region = region;
726a989a
RB
794 return p;
795}
796
797
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. */
802
b8698a0f 803gimple
1d65f45c 804gimple_build_switch_nlabels (unsigned nlabels, tree index, tree default_label)
726a989a
RB
805{
806 /* nlabels + 1 default label + 1 index. */
fd8d363e 807 gcc_checking_assert (default_label);
bbbbb16a 808 gimple p = gimple_build_with_ops (GIMPLE_SWITCH, ERROR_MARK,
fd8d363e 809 1 + 1 + nlabels);
726a989a 810 gimple_switch_set_index (p, index);
fd8d363e 811 gimple_switch_set_default_label (p, default_label);
726a989a
RB
812 return p;
813}
814
726a989a
RB
815/* Build a GIMPLE_SWITCH statement.
816
817 INDEX is the switch's index.
818 DEFAULT_LABEL is the default label
819 ARGS is a vector of labels excluding the default. */
820
821gimple
9771b263 822gimple_build_switch (tree index, tree default_label, vec<tree> args)
726a989a 823{
9771b263 824 unsigned i, nlabels = args.length ();
fd8d363e 825
1d65f45c 826 gimple p = gimple_build_switch_nlabels (nlabels, index, default_label);
726a989a 827
1d65f45c 828 /* Copy the labels from the vector to the switch statement. */
1d65f45c 829 for (i = 0; i < nlabels; i++)
9771b263 830 gimple_switch_set_label (p, i + 1, args[i]);
726a989a
RB
831
832 return p;
833}
834
1d65f45c
RH
835/* Build a GIMPLE_EH_DISPATCH statement. */
836
837gimple
838gimple_build_eh_dispatch (int region)
839{
840 gimple p = gimple_build_with_ops (GIMPLE_EH_DISPATCH, ERROR_MARK, 0);
841 p->gimple_eh_ctrl.region = region;
842 return p;
843}
726a989a 844
b5b8b0ac
AO
845/* Build a new GIMPLE_DEBUG_BIND statement.
846
847 VAR is bound to VALUE; block and location are taken from STMT. */
848
849gimple
850gimple_build_debug_bind_stat (tree var, tree value, gimple stmt MEM_STAT_DECL)
851{
852 gimple p = gimple_build_with_ops_stat (GIMPLE_DEBUG,
853 (unsigned)GIMPLE_DEBUG_BIND, 2
854 PASS_MEM_STAT);
855
856 gimple_debug_bind_set_var (p, var);
857 gimple_debug_bind_set_value (p, value);
858 if (stmt)
5368224f 859 gimple_set_location (p, gimple_location (stmt));
b5b8b0ac
AO
860
861 return p;
862}
863
864
ddb555ed
JJ
865/* Build a new GIMPLE_DEBUG_SOURCE_BIND statement.
866
867 VAR is bound to VALUE; block and location are taken from STMT. */
868
869gimple
870gimple_build_debug_source_bind_stat (tree var, tree value,
871 gimple stmt MEM_STAT_DECL)
872{
873 gimple p = gimple_build_with_ops_stat (GIMPLE_DEBUG,
874 (unsigned)GIMPLE_DEBUG_SOURCE_BIND, 2
875 PASS_MEM_STAT);
876
877 gimple_debug_source_bind_set_var (p, var);
878 gimple_debug_source_bind_set_value (p, value);
879 if (stmt)
5368224f 880 gimple_set_location (p, gimple_location (stmt));
ddb555ed
JJ
881
882 return p;
883}
884
885
726a989a
RB
886/* Build a GIMPLE_OMP_CRITICAL statement.
887
888 BODY is the sequence of statements for which only one thread can execute.
889 NAME is optional identifier for this critical block. */
890
b8698a0f 891gimple
726a989a
RB
892gimple_build_omp_critical (gimple_seq body, tree name)
893{
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);
898
899 return p;
900}
901
902/* Build a GIMPLE_OMP_FOR statement.
903
904 BODY is sequence of statements inside the for loop.
b8698a0f 905 CLAUSES, are any of the OMP loop construct's clauses: private, firstprivate,
726a989a
RB
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. */
909
910gimple
911gimple_build_omp_for (gimple_seq body, tree clauses, size_t collapse,
912 gimple_seq pre_body)
913{
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;
a9429e29
LB
919 p->gimple_omp_for.iter
920 = ggc_alloc_cleared_vec_gimple_omp_for_iter (collapse);
726a989a
RB
921 if (pre_body)
922 gimple_omp_for_set_pre_body (p, pre_body);
923
924 return p;
925}
926
927
928/* Build a GIMPLE_OMP_PARALLEL statement.
929
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). */
934
b8698a0f
L
935gimple
936gimple_build_omp_parallel (gimple_seq body, tree clauses, tree child_fn,
726a989a
RB
937 tree data_arg)
938{
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);
945
946 return p;
947}
948
949
950/* Build a GIMPLE_OMP_TASK statement.
951
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. */
958
b8698a0f 959gimple
726a989a
RB
960gimple_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)
963{
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);
973
974 return p;
975}
976
977
978/* Build a GIMPLE_OMP_SECTION statement for a sections statement.
979
980 BODY is the sequence of statements in the section. */
981
982gimple
983gimple_build_omp_section (gimple_seq body)
984{
985 gimple p = gimple_alloc (GIMPLE_OMP_SECTION, 0);
986 if (body)
987 gimple_omp_set_body (p, body);
988
989 return p;
990}
991
992
993/* Build a GIMPLE_OMP_MASTER statement.
994
995 BODY is the sequence of statements to be executed by just the master. */
996
b8698a0f 997gimple
726a989a
RB
998gimple_build_omp_master (gimple_seq body)
999{
1000 gimple p = gimple_alloc (GIMPLE_OMP_MASTER, 0);
1001 if (body)
1002 gimple_omp_set_body (p, body);
1003
1004 return p;
1005}
1006
1007
1008/* Build a GIMPLE_OMP_CONTINUE statement.
1009
1010 CONTROL_DEF is the definition of the control variable.
1011 CONTROL_USE is the use of the control variable. */
1012
b8698a0f 1013gimple
726a989a
RB
1014gimple_build_omp_continue (tree control_def, tree control_use)
1015{
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;
1020}
1021
1022/* Build a GIMPLE_OMP_ORDERED statement.
1023
1024 BODY is the sequence of statements inside a loop that will executed in
1025 sequence. */
1026
b8698a0f 1027gimple
726a989a
RB
1028gimple_build_omp_ordered (gimple_seq body)
1029{
1030 gimple p = gimple_alloc (GIMPLE_OMP_ORDERED, 0);
1031 if (body)
1032 gimple_omp_set_body (p, body);
1033
1034 return p;
1035}
1036
1037
1038/* Build a GIMPLE_OMP_RETURN statement.
1039 WAIT_P is true if this is a non-waiting return. */
1040
b8698a0f 1041gimple
726a989a
RB
1042gimple_build_omp_return (bool wait_p)
1043{
1044 gimple p = gimple_alloc (GIMPLE_OMP_RETURN, 0);
1045 if (wait_p)
1046 gimple_omp_return_set_nowait (p);
1047
1048 return p;
1049}
1050
1051
1052/* Build a GIMPLE_OMP_SECTIONS statement.
1053
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. */
1057
b8698a0f 1058gimple
726a989a
RB
1059gimple_build_omp_sections (gimple_seq body, tree clauses)
1060{
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);
1065
1066 return p;
1067}
1068
1069
1070/* Build a GIMPLE_OMP_SECTIONS_SWITCH. */
1071
1072gimple
1073gimple_build_omp_sections_switch (void)
1074{
1075 return gimple_alloc (GIMPLE_OMP_SECTIONS_SWITCH, 0);
1076}
1077
1078
1079/* Build a GIMPLE_OMP_SINGLE statement.
1080
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. */
1084
b8698a0f 1085gimple
726a989a
RB
1086gimple_build_omp_single (gimple_seq body, tree clauses)
1087{
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);
1092
1093 return p;
1094}
1095
1096
726a989a
RB
1097/* Build a GIMPLE_OMP_ATOMIC_LOAD statement. */
1098
1099gimple
1100gimple_build_omp_atomic_load (tree lhs, tree rhs)
1101{
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;
1106}
1107
1108/* Build a GIMPLE_OMP_ATOMIC_STORE statement.
1109
1110 VAL is the value we are storing. */
1111
1112gimple
1113gimple_build_omp_atomic_store (tree val)
1114{
1115 gimple p = gimple_alloc (GIMPLE_OMP_ATOMIC_STORE, 0);
1116 gimple_omp_atomic_store_set_val (p, val);
1117 return p;
1118}
1119
0a35513e
AH
1120/* Build a GIMPLE_TRANSACTION statement. */
1121
1122gimple
1123gimple_build_transaction (gimple_seq body, tree label)
1124{
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;
1129}
1130
726a989a
RB
1131/* Build a GIMPLE_PREDICT statement. PREDICT is one of the predictors from
1132 predict.def, OUTCOME is NOT_TAKEN or TAKEN. */
1133
1134gimple
1135gimple_build_predict (enum br_predictor predictor, enum prediction outcome)
1136{
1137 gimple p = gimple_alloc (GIMPLE_PREDICT, 0);
1138 /* Ensure all the predictors fit into the lower bits of the subcode. */
e0c68ce9 1139 gcc_assert ((int) END_PREDICTORS <= GF_PREDICT_TAKEN);
726a989a
RB
1140 gimple_predict_set_predictor (p, predictor);
1141 gimple_predict_set_outcome (p, outcome);
1142 return p;
1143}
1144
cea094ed 1145#if defined ENABLE_GIMPLE_CHECKING
726a989a
RB
1146/* Complain of a gimple type mismatch and die. */
1147
1148void
1149gimple_check_failed (const_gimple gs, const char *file, int line,
1150 const char *function, enum gimple_code code,
1151 enum tree_code subcode)
1152{
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);
1161}
726a989a
RB
1162#endif /* ENABLE_GIMPLE_CHECKING */
1163
1164
726a989a
RB
1165/* Link gimple statement GS to the end of the sequence *SEQ_P. If
1166 *SEQ_P is NULL, a new sequence is allocated. */
1167
1168void
1169gimple_seq_add_stmt (gimple_seq *seq_p, gimple gs)
1170{
1171 gimple_stmt_iterator si;
726a989a
RB
1172 if (gs == NULL)
1173 return;
1174
726a989a
RB
1175 si = gsi_last (*seq_p);
1176 gsi_insert_after (&si, gs, GSI_NEW_STMT);
1177}
1178
1179
1180/* Append sequence SRC to the end of sequence *DST_P. If *DST_P is
1181 NULL, a new sequence is allocated. */
1182
1183void
1184gimple_seq_add_seq (gimple_seq *dst_p, gimple_seq src)
1185{
1186 gimple_stmt_iterator si;
726a989a
RB
1187 if (src == NULL)
1188 return;
1189
726a989a
RB
1190 si = gsi_last (*dst_p);
1191 gsi_insert_seq_after (&si, src, GSI_NEW_STMT);
1192}
1193
1194
1195/* Helper function of empty_body_p. Return true if STMT is an empty
1196 statement. */
1197
1198static bool
1199empty_stmt_p (gimple stmt)
1200{
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;
1206}
1207
1208
1209/* Return true if BODY contains nothing but empty statements. */
1210
1211bool
1212empty_body_p (gimple_seq body)
1213{
1214 gimple_stmt_iterator i;
1215
726a989a
RB
1216 if (gimple_seq_empty_p (body))
1217 return true;
1218 for (i = gsi_start (body); !gsi_end_p (i); gsi_next (&i))
b5b8b0ac
AO
1219 if (!empty_stmt_p (gsi_stmt (i))
1220 && !is_gimple_debug (gsi_stmt (i)))
726a989a
RB
1221 return false;
1222
1223 return true;
1224}
1225
1226
1227/* Perform a deep copy of sequence SRC and return the result. */
1228
1229gimple_seq
1230gimple_seq_copy (gimple_seq src)
1231{
1232 gimple_stmt_iterator gsi;
355a7673 1233 gimple_seq new_seq = NULL;
726a989a
RB
1234 gimple stmt;
1235
1236 for (gsi = gsi_start (src); !gsi_end_p (gsi); gsi_next (&gsi))
1237 {
1238 stmt = gimple_copy (gsi_stmt (gsi));
82d6e6fc 1239 gimple_seq_add_stmt (&new_seq, stmt);
726a989a
RB
1240 }
1241
82d6e6fc 1242 return new_seq;
726a989a
RB
1243}
1244
1245
355a7673 1246/* Walk all the statements in the sequence *PSEQ calling walk_gimple_stmt
726a989a 1247 on each one. WI is as in walk_gimple_stmt.
b8698a0f 1248
0a35513e
AH
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.
726a989a
RB
1254
1255 Otherwise, all the statements are walked and NULL returned. */
1256
1257gimple
355a7673
MM
1258walk_gimple_seq_mod (gimple_seq *pseq, walk_stmt_fn callback_stmt,
1259 walk_tree_fn callback_op, struct walk_stmt_info *wi)
726a989a
RB
1260{
1261 gimple_stmt_iterator gsi;
1262
355a7673 1263 for (gsi = gsi_start (*pseq); !gsi_end_p (gsi); )
726a989a
RB
1264 {
1265 tree ret = walk_gimple_stmt (&gsi, callback_stmt, callback_op, wi);
1266 if (ret)
1267 {
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;
0a35513e
AH
1272
1273 return wi->removed_stmt ? NULL : gsi_stmt (gsi);
726a989a 1274 }
0a35513e
AH
1275
1276 if (!wi->removed_stmt)
1277 gsi_next (&gsi);
726a989a
RB
1278 }
1279
1280 if (wi)
1281 wi->callback_result = NULL_TREE;
1282
1283 return NULL;
1284}
1285
1286
355a7673
MM
1287/* Like walk_gimple_seq_mod, but ensure that the head of SEQ isn't
1288 changed by the callbacks. */
1289
1290gimple
1291walk_gimple_seq (gimple_seq seq, walk_stmt_fn callback_stmt,
1292 walk_tree_fn callback_op, struct walk_stmt_info *wi)
1293{
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;
1298}
1299
1300
726a989a
RB
1301/* Helper function for walk_gimple_stmt. Walk operands of a GIMPLE_ASM. */
1302
1303static tree
1304walk_gimple_asm (gimple stmt, walk_tree_fn callback_op,
1305 struct walk_stmt_info *wi)
1306{
1c384bf1 1307 tree ret, op;
726a989a
RB
1308 unsigned noutputs;
1309 const char **oconstraints;
1c384bf1 1310 unsigned i, n;
726a989a
RB
1311 const char *constraint;
1312 bool allows_mem, allows_reg, is_inout;
1313
1314 noutputs = gimple_asm_noutputs (stmt);
1315 oconstraints = (const char **) alloca ((noutputs) * sizeof (const char *));
1316
1317 if (wi)
1318 wi->is_lhs = true;
1319
1320 for (i = 0; i < noutputs; i++)
1321 {
1c384bf1 1322 op = gimple_asm_output_op (stmt, i);
726a989a
RB
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;
1332 }
1333
1c384bf1
RH
1334 n = gimple_asm_ninputs (stmt);
1335 for (i = 0; i < n; i++)
726a989a 1336 {
1c384bf1 1337 op = gimple_asm_input_op (stmt, i);
726a989a
RB
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)
1c384bf1
RH
1342 {
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;
1346 }
726a989a
RB
1347 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
1348 if (ret)
1349 return ret;
1350 }
1351
1352 if (wi)
1353 {
1354 wi->is_lhs = false;
1355 wi->val_only = true;
1356 }
1357
1c384bf1
RH
1358 n = gimple_asm_nlabels (stmt);
1359 for (i = 0; i < n; i++)
1360 {
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;
1365 }
1366
726a989a
RB
1367 return NULL_TREE;
1368}
1369
1370
1371/* Helper function of WALK_GIMPLE_STMT. Walk every tree operand in
1372 STMT. CALLBACK_OP and WI are as in WALK_GIMPLE_STMT.
1373
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:
1377
1378 walk_tree (&OP, CALLBACK_OP, WI, WI->PSET)
1379
1380 If CALLBACK_OP returns non-NULL for an operand, the remaining
1381 operands are not scanned.
1382
1383 The return value is that returned by the last call to walk_tree, or
1384 NULL_TREE if no CALLBACK_OP is specified. */
1385
6a4d4e8a 1386tree
726a989a
RB
1387walk_gimple_op (gimple stmt, walk_tree_fn callback_op,
1388 struct walk_stmt_info *wi)
1389{
1390 struct pointer_set_t *pset = (wi) ? wi->pset : NULL;
1391 unsigned i;
1392 tree ret = NULL_TREE;
1393
1394 switch (gimple_code (stmt))
1395 {
1396 case GIMPLE_ASSIGN:
cb3d597d
EB
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. */
726a989a 1399 if (wi)
cb3d597d
EB
1400 {
1401 tree lhs = gimple_assign_lhs (stmt);
1402 wi->val_only
1403 = (is_gimple_reg_type (TREE_TYPE (lhs)) && !is_gimple_reg (lhs))
b9af73fc 1404 || gimple_assign_rhs_class (stmt) != GIMPLE_SINGLE_RHS;
cb3d597d 1405 }
726a989a
RB
1406
1407 for (i = 1; i < gimple_num_ops (stmt); i++)
1408 {
1409 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi,
1410 pset);
1411 if (ret)
1412 return ret;
1413 }
1414
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)
1418 {
216820a4
RG
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. */
b9af73fc 1421 tree rhs1 = gimple_assign_rhs1 (stmt);
216820a4
RG
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;
726a989a
RB
1425 wi->is_lhs = true;
1426 }
1427
1428 ret = walk_tree (gimple_op_ptr (stmt, 0), callback_op, wi, pset);
1429 if (ret)
1430 return ret;
1431
1432 if (wi)
1433 {
1434 wi->val_only = true;
1435 wi->is_lhs = false;
1436 }
1437 break;
1438
1439 case GIMPLE_CALL:
1440 if (wi)
523968bf
RG
1441 {
1442 wi->is_lhs = false;
1443 wi->val_only = true;
1444 }
726a989a
RB
1445
1446 ret = walk_tree (gimple_call_chain_ptr (stmt), callback_op, wi, pset);
1447 if (ret)
1448 return ret;
1449
1450 ret = walk_tree (gimple_call_fn_ptr (stmt), callback_op, wi, pset);
1451 if (ret)
1452 return ret;
1453
1454 for (i = 0; i < gimple_call_num_args (stmt); i++)
1455 {
523968bf 1456 if (wi)
4d931f41
EB
1457 wi->val_only
1458 = is_gimple_reg_type (TREE_TYPE (gimple_call_arg (stmt, i)));
726a989a
RB
1459 ret = walk_tree (gimple_call_arg_ptr (stmt, i), callback_op, wi,
1460 pset);
1461 if (ret)
1462 return ret;
1463 }
1464
523968bf
RG
1465 if (gimple_call_lhs (stmt))
1466 {
1467 if (wi)
1468 {
1469 wi->is_lhs = true;
4d931f41
EB
1470 wi->val_only
1471 = is_gimple_reg_type (TREE_TYPE (gimple_call_lhs (stmt)));
523968bf 1472 }
726a989a 1473
523968bf
RG
1474 ret = walk_tree (gimple_call_lhs_ptr (stmt), callback_op, wi, pset);
1475 if (ret)
1476 return ret;
1477 }
726a989a
RB
1478
1479 if (wi)
523968bf
RG
1480 {
1481 wi->is_lhs = false;
1482 wi->val_only = true;
1483 }
726a989a
RB
1484 break;
1485
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;
1492
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;
1499
726a989a
RB
1500 case GIMPLE_ASM:
1501 ret = walk_gimple_asm (stmt, callback_op, wi);
1502 if (ret)
1503 return ret;
1504 break;
1505
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;
1511
1512 ret = walk_tree (gimple_omp_continue_control_use_ptr (stmt),
1513 callback_op, wi, pset);
1514 if (ret)
1515 return ret;
1516 break;
1517
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;
1524
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++)
1531 {
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);
1546 }
1547 if (ret)
1548 return ret;
1549 break;
1550
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;
1565
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;
1592
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;
1598
1599 ret = walk_tree (gimple_omp_sections_control_ptr (stmt), callback_op,
1600 wi, pset);
1601 if (ret)
1602 return ret;
1603
1604 break;
1605
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;
1612
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;
1618
1619 ret = walk_tree (gimple_omp_atomic_load_rhs_ptr (stmt), callback_op, wi,
1620 pset);
1621 if (ret)
1622 return ret;
1623 break;
1624
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;
1631
0a35513e
AH
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;
1638
726a989a
RB
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;
1645
1646 default:
1647 {
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++)
1652 {
1653 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi, pset);
1654 if (ret)
1655 return ret;
1656 }
1657 }
1658 break;
1659 }
1660
1661 return NULL_TREE;
1662}
1663
1664
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.
1671
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.
1677
1678 In any other case, NULL_TREE is returned. */
1679
1680tree
1681walk_gimple_stmt (gimple_stmt_iterator *gsi, walk_stmt_fn callback_stmt,
1682 walk_tree_fn callback_op, struct walk_stmt_info *wi)
1683{
1684 gimple ret;
1685 tree tree_ret;
1686 gimple stmt = gsi_stmt (*gsi);
1687
1688 if (wi)
0a35513e
AH
1689 {
1690 wi->gsi = *gsi;
1691 wi->removed_stmt = false;
726a989a 1692
0a35513e
AH
1693 if (wi->want_locations && gimple_has_location (stmt))
1694 input_location = gimple_location (stmt);
1695 }
726a989a
RB
1696
1697 ret = NULL;
1698
1699 /* Invoke the statement callback. Return if the callback handled
1700 all of STMT operands by itself. */
1701 if (callback_stmt)
1702 {
1703 bool handled_ops = false;
1704 tree_ret = callback_stmt (gsi, &handled_ops, wi);
1705 if (handled_ops)
1706 return tree_ret;
1707
1708 /* If CALLBACK_STMT did not handle operands, it should not have
1709 a value to return. */
1710 gcc_assert (tree_ret == NULL);
1711
0a35513e
AH
1712 if (wi && wi->removed_stmt)
1713 return NULL;
1714
726a989a
RB
1715 /* Re-read stmt in case the callback changed it. */
1716 stmt = gsi_stmt (*gsi);
1717 }
1718
1719 /* If CALLBACK_OP is defined, invoke it on every operand of STMT. */
1720 if (callback_op)
1721 {
1722 tree_ret = walk_gimple_op (stmt, callback_op, wi);
1723 if (tree_ret)
1724 return tree_ret;
1725 }
1726
1727 /* If STMT can have statements inside (e.g. GIMPLE_BIND), walk them. */
1728 switch (gimple_code (stmt))
1729 {
1730 case GIMPLE_BIND:
355a7673
MM
1731 ret = walk_gimple_seq_mod (gimple_bind_body_ptr (stmt), callback_stmt,
1732 callback_op, wi);
726a989a
RB
1733 if (ret)
1734 return wi->callback_result;
1735 break;
1736
1737 case GIMPLE_CATCH:
355a7673
MM
1738 ret = walk_gimple_seq_mod (gimple_catch_handler_ptr (stmt), callback_stmt,
1739 callback_op, wi);
726a989a
RB
1740 if (ret)
1741 return wi->callback_result;
1742 break;
1743
1744 case GIMPLE_EH_FILTER:
355a7673 1745 ret = walk_gimple_seq_mod (gimple_eh_filter_failure_ptr (stmt), callback_stmt,
726a989a
RB
1746 callback_op, wi);
1747 if (ret)
1748 return wi->callback_result;
1749 break;
1750
0a35513e 1751 case GIMPLE_EH_ELSE:
355a7673 1752 ret = walk_gimple_seq_mod (gimple_eh_else_n_body_ptr (stmt),
0a35513e
AH
1753 callback_stmt, callback_op, wi);
1754 if (ret)
1755 return wi->callback_result;
355a7673 1756 ret = walk_gimple_seq_mod (gimple_eh_else_e_body_ptr (stmt),
0a35513e
AH
1757 callback_stmt, callback_op, wi);
1758 if (ret)
1759 return wi->callback_result;
1760 break;
1761
726a989a 1762 case GIMPLE_TRY:
355a7673 1763 ret = walk_gimple_seq_mod (gimple_try_eval_ptr (stmt), callback_stmt, callback_op,
726a989a
RB
1764 wi);
1765 if (ret)
1766 return wi->callback_result;
1767
355a7673 1768 ret = walk_gimple_seq_mod (gimple_try_cleanup_ptr (stmt), callback_stmt,
726a989a
RB
1769 callback_op, wi);
1770 if (ret)
1771 return wi->callback_result;
1772 break;
1773
1774 case GIMPLE_OMP_FOR:
355a7673 1775 ret = walk_gimple_seq_mod (gimple_omp_for_pre_body_ptr (stmt), callback_stmt,
726a989a
RB
1776 callback_op, wi);
1777 if (ret)
1778 return wi->callback_result;
1779
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:
355a7673 1789 ret = walk_gimple_seq_mod (gimple_omp_body_ptr (stmt), callback_stmt,
0a35513e 1790 callback_op, wi);
726a989a
RB
1791 if (ret)
1792 return wi->callback_result;
1793 break;
1794
1795 case GIMPLE_WITH_CLEANUP_EXPR:
355a7673 1796 ret = walk_gimple_seq_mod (gimple_wce_cleanup_ptr (stmt), callback_stmt,
726a989a
RB
1797 callback_op, wi);
1798 if (ret)
1799 return wi->callback_result;
1800 break;
1801
0a35513e 1802 case GIMPLE_TRANSACTION:
355a7673 1803 ret = walk_gimple_seq_mod (gimple_transaction_body_ptr (stmt),
0a35513e
AH
1804 callback_stmt, callback_op, wi);
1805 if (ret)
1806 return wi->callback_result;
1807 break;
1808
726a989a
RB
1809 default:
1810 gcc_assert (!gimple_has_substatements (stmt));
1811 break;
1812 }
1813
1814 return NULL;
1815}
1816
1817
1818/* Set sequence SEQ to be the GIMPLE body for function FN. */
1819
1820void
1821gimple_set_body (tree fndecl, gimple_seq seq)
1822{
1823 struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
1824 if (fn == NULL)
1825 {
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);
1830 }
1831 else
1832 fn->gimple_body = seq;
1833}
1834
1835
abbd64b9
JS
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. */
726a989a
RB
1840
1841gimple_seq
1842gimple_body (tree fndecl)
1843{
1844 struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
1845 return fn ? fn->gimple_body : NULL;
1846}
1847
39ecc018
JH
1848/* Return true when FNDECL has Gimple body either in unlowered
1849 or CFG form. */
1850bool
1851gimple_has_body_p (tree fndecl)
1852{
1853 struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
1854 return (gimple_body (fndecl) || (fn && fn->cfg));
1855}
726a989a 1856
25583c4f
RS
1857/* Return true if calls C1 and C2 are known to go to the same function. */
1858
1859bool
1860gimple_call_same_target_p (const_gimple c1, const_gimple c2)
1861{
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)));
1869}
1870
726a989a
RB
1871/* Detect flags from a GIMPLE_CALL. This is just like
1872 call_expr_flags, but for gimple tuples. */
1873
1874int
1875gimple_call_flags (const_gimple stmt)
1876{
1877 int flags;
1878 tree decl = gimple_call_fndecl (stmt);
726a989a
RB
1879
1880 if (decl)
1881 flags = flags_from_decl_or_type (decl);
25583c4f
RS
1882 else if (gimple_call_internal_p (stmt))
1883 flags = internal_fn_flags (gimple_call_internal_fn (stmt));
726a989a 1884 else
97e03fa1 1885 flags = flags_from_decl_or_type (gimple_call_fntype (stmt));
726a989a 1886
9bb1a81b
JM
1887 if (stmt->gsbase.subcode & GF_CALL_NOTHROW)
1888 flags |= ECF_NOTHROW;
1889
726a989a
RB
1890 return flags;
1891}
1892
25583c4f
RS
1893/* Return the "fn spec" string for call STMT. */
1894
1895static tree
1896gimple_call_fnspec (const_gimple stmt)
1897{
1898 tree type, attr;
1899
1900 type = gimple_call_fntype (stmt);
1901 if (!type)
1902 return NULL_TREE;
1903
1904 attr = lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type));
1905 if (!attr)
1906 return NULL_TREE;
1907
1908 return TREE_VALUE (TREE_VALUE (attr));
1909}
1910
0b7b376d
RG
1911/* Detects argument flags for argument number ARG on call STMT. */
1912
1913int
1914gimple_call_arg_flags (const_gimple stmt, unsigned arg)
1915{
25583c4f 1916 tree attr = gimple_call_fnspec (stmt);
0b7b376d 1917
25583c4f 1918 if (!attr || 1 + arg >= (unsigned) TREE_STRING_LENGTH (attr))
0b7b376d
RG
1919 return 0;
1920
1921 switch (TREE_STRING_POINTER (attr)[1 + arg])
1922 {
1923 case 'x':
1924 case 'X':
1925 return EAF_UNUSED;
1926
1927 case 'R':
1928 return EAF_DIRECT | EAF_NOCLOBBER | EAF_NOESCAPE;
1929
1930 case 'r':
1931 return EAF_NOCLOBBER | EAF_NOESCAPE;
1932
1933 case 'W':
1934 return EAF_DIRECT | EAF_NOESCAPE;
1935
1936 case 'w':
1937 return EAF_NOESCAPE;
1938
1939 case '.':
1940 default:
1941 return 0;
1942 }
1943}
1944
1945/* Detects return flags for the call STMT. */
1946
1947int
1948gimple_call_return_flags (const_gimple stmt)
1949{
25583c4f 1950 tree attr;
0b7b376d
RG
1951
1952 if (gimple_call_flags (stmt) & ECF_MALLOC)
1953 return ERF_NOALIAS;
1954
25583c4f
RS
1955 attr = gimple_call_fnspec (stmt);
1956 if (!attr || TREE_STRING_LENGTH (attr) < 1)
0b7b376d
RG
1957 return 0;
1958
1959 switch (TREE_STRING_POINTER (attr)[0])
1960 {
1961 case '1':
1962 case '2':
1963 case '3':
1964 case '4':
1965 return ERF_RETURNS_ARG | (TREE_STRING_POINTER (attr)[0] - '1');
1966
1967 case 'm':
1968 return ERF_NOALIAS;
1969
1970 case '.':
1971 default:
1972 return 0;
1973 }
1974}
726a989a 1975
3dbe9454 1976
726a989a
RB
1977/* Return true if GS is a copy assignment. */
1978
1979bool
1980gimple_assign_copy_p (gimple gs)
1981{
3dbe9454
RG
1982 return (gimple_assign_single_p (gs)
1983 && is_gimple_val (gimple_op (gs, 1)));
726a989a
RB
1984}
1985
1986
1987/* Return true if GS is a SSA_NAME copy assignment. */
1988
1989bool
1990gimple_assign_ssa_name_copy_p (gimple gs)
1991{
3dbe9454 1992 return (gimple_assign_single_p (gs)
726a989a
RB
1993 && TREE_CODE (gimple_assign_lhs (gs)) == SSA_NAME
1994 && TREE_CODE (gimple_assign_rhs1 (gs)) == SSA_NAME);
1995}
1996
1997
726a989a
RB
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.
2003
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. */
b8698a0f 2011
726a989a
RB
2012bool
2013gimple_assign_unary_nop_p (gimple gs)
2014{
3dbe9454 2015 return (is_gimple_assign (gs)
1a87cf0c 2016 && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs))
726a989a
RB
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)))));
2021}
2022
2023/* Set BB to be the basic block holding G. */
2024
2025void
2026gimple_set_bb (gimple stmt, basic_block bb)
2027{
2028 stmt->gsbase.bb = bb;
2029
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)
2033 {
2034 tree t;
2035 int uid;
2036
2037 t = gimple_label_label (stmt);
2038 uid = LABEL_DECL_UID (t);
2039 if (uid == -1)
2040 {
9771b263 2041 unsigned old_len = vec_safe_length (label_to_block_map);
726a989a
RB
2042 LABEL_DECL_UID (t) = uid = cfun->cfg->last_label_uid++;
2043 if (old_len <= (unsigned) uid)
2044 {
5006671f 2045 unsigned new_len = 3 * uid / 2 + 1;
726a989a 2046
9771b263 2047 vec_safe_grow_cleared (label_to_block_map, new_len);
726a989a
RB
2048 }
2049 }
2050
9771b263 2051 (*label_to_block_map)[uid] = bb;
726a989a
RB
2052 }
2053}
2054
2055
726a989a
RB
2056/* Modify the RHS of the assignment pointed-to by GSI using the
2057 operands in the expression tree EXPR.
2058
2059 NOTE: The statement pointed-to by GSI may be reallocated if it
2060 did not have enough operand slots.
2061
2062 This function is useful to convert an existing tree expression into
2063 the flat representation used for the RHS of a GIMPLE assignment.
2064 It will reallocate memory as needed to expand or shrink the number
2065 of operand slots needed to represent EXPR.
2066
2067 NOTE: If you find yourself building a tree and then calling this
2068 function, you are most certainly doing it the slow way. It is much
2069 better to build a new assignment or to use the function
2070 gimple_assign_set_rhs_with_ops, which does not require an
2071 expression tree to be built. */
2072
2073void
2074gimple_assign_set_rhs_from_tree (gimple_stmt_iterator *gsi, tree expr)
2075{
2076 enum tree_code subcode;
0354c0c7 2077 tree op1, op2, op3;
726a989a 2078
0354c0c7
BS
2079 extract_ops_from_tree_1 (expr, &subcode, &op1, &op2, &op3);
2080 gimple_assign_set_rhs_with_ops_1 (gsi, subcode, op1, op2, op3);
726a989a
RB
2081}
2082
2083
2084/* Set the RHS of assignment statement pointed-to by GSI to CODE with
0354c0c7 2085 operands OP1, OP2 and OP3.
726a989a
RB
2086
2087 NOTE: The statement pointed-to by GSI may be reallocated if it
2088 did not have enough operand slots. */
2089
2090void
0354c0c7
BS
2091gimple_assign_set_rhs_with_ops_1 (gimple_stmt_iterator *gsi, enum tree_code code,
2092 tree op1, tree op2, tree op3)
726a989a
RB
2093{
2094 unsigned new_rhs_ops = get_gimple_rhs_num_ops (code);
2095 gimple stmt = gsi_stmt (*gsi);
2096
2097 /* If the new CODE needs more operands, allocate a new statement. */
2098 if (gimple_num_ops (stmt) < new_rhs_ops + 1)
2099 {
2100 tree lhs = gimple_assign_lhs (stmt);
2101 gimple new_stmt = gimple_alloc (gimple_code (stmt), new_rhs_ops + 1);
2102 memcpy (new_stmt, stmt, gimple_size (gimple_code (stmt)));
355a7673 2103 gimple_init_singleton (new_stmt);
726a989a
RB
2104 gsi_replace (gsi, new_stmt, true);
2105 stmt = new_stmt;
2106
2107 /* The LHS needs to be reset as this also changes the SSA name
2108 on the LHS. */
2109 gimple_assign_set_lhs (stmt, lhs);
2110 }
2111
2112 gimple_set_num_ops (stmt, new_rhs_ops + 1);
2113 gimple_set_subcode (stmt, code);
2114 gimple_assign_set_rhs1 (stmt, op1);
2115 if (new_rhs_ops > 1)
2116 gimple_assign_set_rhs2 (stmt, op2);
0354c0c7
BS
2117 if (new_rhs_ops > 2)
2118 gimple_assign_set_rhs3 (stmt, op3);
726a989a
RB
2119}
2120
2121
2122/* Return the LHS of a statement that performs an assignment,
2123 either a GIMPLE_ASSIGN or a GIMPLE_CALL. Returns NULL_TREE
2124 for a call to a function that returns no value, or for a
2125 statement other than an assignment or a call. */
2126
2127tree
2128gimple_get_lhs (const_gimple stmt)
2129{
e0c68ce9 2130 enum gimple_code code = gimple_code (stmt);
726a989a
RB
2131
2132 if (code == GIMPLE_ASSIGN)
2133 return gimple_assign_lhs (stmt);
2134 else if (code == GIMPLE_CALL)
2135 return gimple_call_lhs (stmt);
2136 else
2137 return NULL_TREE;
2138}
2139
2140
2141/* Set the LHS of a statement that performs an assignment,
2142 either a GIMPLE_ASSIGN or a GIMPLE_CALL. */
2143
2144void
2145gimple_set_lhs (gimple stmt, tree lhs)
2146{
e0c68ce9 2147 enum gimple_code code = gimple_code (stmt);
726a989a
RB
2148
2149 if (code == GIMPLE_ASSIGN)
2150 gimple_assign_set_lhs (stmt, lhs);
2151 else if (code == GIMPLE_CALL)
2152 gimple_call_set_lhs (stmt, lhs);
2153 else
2154 gcc_unreachable();
2155}
2156
21cf7180
AO
2157/* Replace the LHS of STMT, an assignment, either a GIMPLE_ASSIGN or a
2158 GIMPLE_CALL, with NLHS, in preparation for modifying the RHS to an
2159 expression with a different value.
2160
2161 This will update any annotations (say debug bind stmts) referring
2162 to the original LHS, so that they use the RHS instead. This is
2163 done even if NLHS and LHS are the same, for it is understood that
2164 the RHS will be modified afterwards, and NLHS will not be assigned
2165 an equivalent value.
2166
2167 Adjusting any non-annotation uses of the LHS, if needed, is a
2168 responsibility of the caller.
2169
2170 The effect of this call should be pretty much the same as that of
2171 inserting a copy of STMT before STMT, and then removing the
2172 original stmt, at which time gsi_remove() would have update
2173 annotations, but using this function saves all the inserting,
2174 copying and removing. */
2175
2176void
2177gimple_replace_lhs (gimple stmt, tree nlhs)
2178{
2179 if (MAY_HAVE_DEBUG_STMTS)
2180 {
2181 tree lhs = gimple_get_lhs (stmt);
2182
2183 gcc_assert (SSA_NAME_DEF_STMT (lhs) == stmt);
2184
2185 insert_debug_temp_for_var_def (NULL, lhs);
2186 }
2187
2188 gimple_set_lhs (stmt, nlhs);
2189}
726a989a
RB
2190
2191/* Return a deep copy of statement STMT. All the operands from STMT
2192 are reallocated and copied using unshare_expr. The DEF, USE, VDEF
355a7673
MM
2193 and VUSE operand arrays are set to empty in the new copy. The new
2194 copy isn't part of any sequence. */
726a989a
RB
2195
2196gimple
2197gimple_copy (gimple stmt)
2198{
2199 enum gimple_code code = gimple_code (stmt);
2200 unsigned num_ops = gimple_num_ops (stmt);
2201 gimple copy = gimple_alloc (code, num_ops);
2202 unsigned i;
2203
2204 /* Shallow copy all the fields from STMT. */
2205 memcpy (copy, stmt, gimple_size (code));
355a7673 2206 gimple_init_singleton (copy);
726a989a
RB
2207
2208 /* If STMT has sub-statements, deep-copy them as well. */
2209 if (gimple_has_substatements (stmt))
2210 {
2211 gimple_seq new_seq;
2212 tree t;
2213
2214 switch (gimple_code (stmt))
2215 {
2216 case GIMPLE_BIND:
2217 new_seq = gimple_seq_copy (gimple_bind_body (stmt));
2218 gimple_bind_set_body (copy, new_seq);
2219 gimple_bind_set_vars (copy, unshare_expr (gimple_bind_vars (stmt)));
2220 gimple_bind_set_block (copy, gimple_bind_block (stmt));
2221 break;
2222
2223 case GIMPLE_CATCH:
2224 new_seq = gimple_seq_copy (gimple_catch_handler (stmt));
2225 gimple_catch_set_handler (copy, new_seq);
2226 t = unshare_expr (gimple_catch_types (stmt));
2227 gimple_catch_set_types (copy, t);
2228 break;
2229
2230 case GIMPLE_EH_FILTER:
2231 new_seq = gimple_seq_copy (gimple_eh_filter_failure (stmt));
2232 gimple_eh_filter_set_failure (copy, new_seq);
2233 t = unshare_expr (gimple_eh_filter_types (stmt));
2234 gimple_eh_filter_set_types (copy, t);
2235 break;
2236
0a35513e
AH
2237 case GIMPLE_EH_ELSE:
2238 new_seq = gimple_seq_copy (gimple_eh_else_n_body (stmt));
2239 gimple_eh_else_set_n_body (copy, new_seq);
2240 new_seq = gimple_seq_copy (gimple_eh_else_e_body (stmt));
2241 gimple_eh_else_set_e_body (copy, new_seq);
2242 break;
2243
726a989a
RB
2244 case GIMPLE_TRY:
2245 new_seq = gimple_seq_copy (gimple_try_eval (stmt));
2246 gimple_try_set_eval (copy, new_seq);
2247 new_seq = gimple_seq_copy (gimple_try_cleanup (stmt));
2248 gimple_try_set_cleanup (copy, new_seq);
2249 break;
2250
2251 case GIMPLE_OMP_FOR:
2252 new_seq = gimple_seq_copy (gimple_omp_for_pre_body (stmt));
2253 gimple_omp_for_set_pre_body (copy, new_seq);
2254 t = unshare_expr (gimple_omp_for_clauses (stmt));
2255 gimple_omp_for_set_clauses (copy, t);
2256 copy->gimple_omp_for.iter
a9429e29
LB
2257 = ggc_alloc_vec_gimple_omp_for_iter
2258 (gimple_omp_for_collapse (stmt));
726a989a
RB
2259 for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
2260 {
2261 gimple_omp_for_set_cond (copy, i,
2262 gimple_omp_for_cond (stmt, i));
2263 gimple_omp_for_set_index (copy, i,
2264 gimple_omp_for_index (stmt, i));
2265 t = unshare_expr (gimple_omp_for_initial (stmt, i));
2266 gimple_omp_for_set_initial (copy, i, t);
2267 t = unshare_expr (gimple_omp_for_final (stmt, i));
2268 gimple_omp_for_set_final (copy, i, t);
2269 t = unshare_expr (gimple_omp_for_incr (stmt, i));
2270 gimple_omp_for_set_incr (copy, i, t);
2271 }
2272 goto copy_omp_body;
2273
2274 case GIMPLE_OMP_PARALLEL:
2275 t = unshare_expr (gimple_omp_parallel_clauses (stmt));
2276 gimple_omp_parallel_set_clauses (copy, t);
2277 t = unshare_expr (gimple_omp_parallel_child_fn (stmt));
2278 gimple_omp_parallel_set_child_fn (copy, t);
2279 t = unshare_expr (gimple_omp_parallel_data_arg (stmt));
2280 gimple_omp_parallel_set_data_arg (copy, t);
2281 goto copy_omp_body;
2282
2283 case GIMPLE_OMP_TASK:
2284 t = unshare_expr (gimple_omp_task_clauses (stmt));
2285 gimple_omp_task_set_clauses (copy, t);
2286 t = unshare_expr (gimple_omp_task_child_fn (stmt));
2287 gimple_omp_task_set_child_fn (copy, t);
2288 t = unshare_expr (gimple_omp_task_data_arg (stmt));
2289 gimple_omp_task_set_data_arg (copy, t);
2290 t = unshare_expr (gimple_omp_task_copy_fn (stmt));
2291 gimple_omp_task_set_copy_fn (copy, t);
2292 t = unshare_expr (gimple_omp_task_arg_size (stmt));
2293 gimple_omp_task_set_arg_size (copy, t);
2294 t = unshare_expr (gimple_omp_task_arg_align (stmt));
2295 gimple_omp_task_set_arg_align (copy, t);
2296 goto copy_omp_body;
2297
2298 case GIMPLE_OMP_CRITICAL:
2299 t = unshare_expr (gimple_omp_critical_name (stmt));
2300 gimple_omp_critical_set_name (copy, t);
2301 goto copy_omp_body;
2302
2303 case GIMPLE_OMP_SECTIONS:
2304 t = unshare_expr (gimple_omp_sections_clauses (stmt));
2305 gimple_omp_sections_set_clauses (copy, t);
2306 t = unshare_expr (gimple_omp_sections_control (stmt));
2307 gimple_omp_sections_set_control (copy, t);
2308 /* FALLTHRU */
2309
2310 case GIMPLE_OMP_SINGLE:
2311 case GIMPLE_OMP_SECTION:
2312 case GIMPLE_OMP_MASTER:
2313 case GIMPLE_OMP_ORDERED:
2314 copy_omp_body:
2315 new_seq = gimple_seq_copy (gimple_omp_body (stmt));
2316 gimple_omp_set_body (copy, new_seq);
2317 break;
2318
0a35513e
AH
2319 case GIMPLE_TRANSACTION:
2320 new_seq = gimple_seq_copy (gimple_transaction_body (stmt));
2321 gimple_transaction_set_body (copy, new_seq);
2322 break;
2323
726a989a
RB
2324 case GIMPLE_WITH_CLEANUP_EXPR:
2325 new_seq = gimple_seq_copy (gimple_wce_cleanup (stmt));
2326 gimple_wce_set_cleanup (copy, new_seq);
2327 break;
2328
2329 default:
2330 gcc_unreachable ();
2331 }
2332 }
2333
2334 /* Make copy of operands. */
483ef49f
RG
2335 for (i = 0; i < num_ops; i++)
2336 gimple_set_op (copy, i, unshare_expr (gimple_op (stmt, i)));
726a989a 2337
483ef49f
RG
2338 if (gimple_has_mem_ops (stmt))
2339 {
2340 gimple_set_vdef (copy, gimple_vdef (stmt));
2341 gimple_set_vuse (copy, gimple_vuse (stmt));
2342 }
726a989a 2343
483ef49f
RG
2344 /* Clear out SSA operand vectors on COPY. */
2345 if (gimple_has_ops (stmt))
2346 {
483ef49f 2347 gimple_set_use_ops (copy, NULL);
726a989a 2348
5006671f
RG
2349 /* SSA operands need to be updated. */
2350 gimple_set_modified (copy, true);
726a989a
RB
2351 }
2352
2353 return copy;
2354}
2355
2356
726a989a
RB
2357/* Return true if statement S has side-effects. We consider a
2358 statement to have side effects if:
2359
2360 - It is a GIMPLE_CALL not marked with ECF_PURE or ECF_CONST.
2361 - Any of its operands are marked TREE_THIS_VOLATILE or TREE_SIDE_EFFECTS. */
2362
2363bool
2364gimple_has_side_effects (const_gimple s)
2365{
b5b8b0ac
AO
2366 if (is_gimple_debug (s))
2367 return false;
2368
726a989a
RB
2369 /* We don't have to scan the arguments to check for
2370 volatile arguments, though, at present, we still
2371 do a scan to check for TREE_SIDE_EFFECTS. */
2372 if (gimple_has_volatile_ops (s))
2373 return true;
2374
179184e3
RG
2375 if (gimple_code (s) == GIMPLE_ASM
2376 && gimple_asm_volatile_p (s))
2377 return true;
2378
726a989a
RB
2379 if (is_gimple_call (s))
2380 {
723afc44 2381 int flags = gimple_call_flags (s);
726a989a 2382
723afc44
RG
2383 /* An infinite loop is considered a side effect. */
2384 if (!(flags & (ECF_CONST | ECF_PURE))
2385 || (flags & ECF_LOOPING_CONST_OR_PURE))
726a989a
RB
2386 return true;
2387
726a989a
RB
2388 return false;
2389 }
726a989a
RB
2390
2391 return false;
2392}
2393
726a989a 2394/* Helper for gimple_could_trap_p and gimple_assign_rhs_could_trap_p.
e1fd038a
SP
2395 Return true if S can trap. When INCLUDE_MEM is true, check whether
2396 the memory operations could trap. When INCLUDE_STORES is true and
2397 S is a GIMPLE_ASSIGN, the LHS of the assignment is also checked. */
726a989a 2398
e1fd038a
SP
2399bool
2400gimple_could_trap_p_1 (gimple s, bool include_mem, bool include_stores)
726a989a 2401{
726a989a
RB
2402 tree t, div = NULL_TREE;
2403 enum tree_code op;
2404
e1fd038a
SP
2405 if (include_mem)
2406 {
2407 unsigned i, start = (is_gimple_assign (s) && !include_stores) ? 1 : 0;
726a989a 2408
e1fd038a
SP
2409 for (i = start; i < gimple_num_ops (s); i++)
2410 if (tree_could_trap_p (gimple_op (s, i)))
2411 return true;
2412 }
726a989a
RB
2413
2414 switch (gimple_code (s))
2415 {
2416 case GIMPLE_ASM:
2417 return gimple_asm_volatile_p (s);
2418
2419 case GIMPLE_CALL:
2420 t = gimple_call_fndecl (s);
2421 /* Assume that calls to weak functions may trap. */
2422 if (!t || !DECL_P (t) || DECL_WEAK (t))
2423 return true;
2424 return false;
2425
2426 case GIMPLE_ASSIGN:
2427 t = gimple_expr_type (s);
2428 op = gimple_assign_rhs_code (s);
2429 if (get_gimple_rhs_class (op) == GIMPLE_BINARY_RHS)
2430 div = gimple_assign_rhs2 (s);
2431 return (operation_could_trap_p (op, FLOAT_TYPE_P (t),
2432 (INTEGRAL_TYPE_P (t)
2433 && TYPE_OVERFLOW_TRAPS (t)),
2434 div));
2435
2436 default:
2437 break;
2438 }
2439
2440 return false;
726a989a
RB
2441}
2442
726a989a
RB
2443/* Return true if statement S can trap. */
2444
2445bool
2446gimple_could_trap_p (gimple s)
2447{
e1fd038a 2448 return gimple_could_trap_p_1 (s, true, true);
726a989a
RB
2449}
2450
726a989a
RB
2451/* Return true if RHS of a GIMPLE_ASSIGN S can trap. */
2452
2453bool
2454gimple_assign_rhs_could_trap_p (gimple s)
2455{
2456 gcc_assert (is_gimple_assign (s));
e1fd038a 2457 return gimple_could_trap_p_1 (s, true, false);
726a989a
RB
2458}
2459
2460
2461/* Print debugging information for gimple stmts generated. */
2462
2463void
2464dump_gimple_statistics (void)
2465{
726a989a
RB
2466 int i, total_tuples = 0, total_bytes = 0;
2467
7aa6d18a
SB
2468 if (! GATHER_STATISTICS)
2469 {
2470 fprintf (stderr, "No gimple statistics\n");
2471 return;
2472 }
2473
726a989a
RB
2474 fprintf (stderr, "\nGIMPLE statements\n");
2475 fprintf (stderr, "Kind Stmts Bytes\n");
2476 fprintf (stderr, "---------------------------------------\n");
2477 for (i = 0; i < (int) gimple_alloc_kind_all; ++i)
2478 {
2479 fprintf (stderr, "%-20s %7d %10d\n", gimple_alloc_kind_names[i],
2480 gimple_alloc_counts[i], gimple_alloc_sizes[i]);
2481 total_tuples += gimple_alloc_counts[i];
2482 total_bytes += gimple_alloc_sizes[i];
2483 }
2484 fprintf (stderr, "---------------------------------------\n");
2485 fprintf (stderr, "%-20s %7d %10d\n", "Total", total_tuples, total_bytes);
2486 fprintf (stderr, "---------------------------------------\n");
726a989a
RB
2487}
2488
2489
726a989a
RB
2490/* Return the number of operands needed on the RHS of a GIMPLE
2491 assignment for an expression with tree code CODE. */
2492
2493unsigned
2494get_gimple_rhs_num_ops (enum tree_code code)
2495{
2496 enum gimple_rhs_class rhs_class = get_gimple_rhs_class (code);
2497
2498 if (rhs_class == GIMPLE_UNARY_RHS || rhs_class == GIMPLE_SINGLE_RHS)
2499 return 1;
2500 else if (rhs_class == GIMPLE_BINARY_RHS)
2501 return 2;
0354c0c7
BS
2502 else if (rhs_class == GIMPLE_TERNARY_RHS)
2503 return 3;
726a989a
RB
2504 else
2505 gcc_unreachable ();
2506}
2507
2508#define DEFTREECODE(SYM, STRING, TYPE, NARGS) \
2509 (unsigned char) \
2510 ((TYPE) == tcc_unary ? GIMPLE_UNARY_RHS \
2511 : ((TYPE) == tcc_binary \
2512 || (TYPE) == tcc_comparison) ? GIMPLE_BINARY_RHS \
2513 : ((TYPE) == tcc_constant \
2514 || (TYPE) == tcc_declaration \
2515 || (TYPE) == tcc_reference) ? GIMPLE_SINGLE_RHS \
2516 : ((SYM) == TRUTH_AND_EXPR \
2517 || (SYM) == TRUTH_OR_EXPR \
2518 || (SYM) == TRUTH_XOR_EXPR) ? GIMPLE_BINARY_RHS \
2519 : (SYM) == TRUTH_NOT_EXPR ? GIMPLE_UNARY_RHS \
4e71066d
RG
2520 : ((SYM) == COND_EXPR \
2521 || (SYM) == WIDEN_MULT_PLUS_EXPR \
16949072 2522 || (SYM) == WIDEN_MULT_MINUS_EXPR \
f471fe72
RG
2523 || (SYM) == DOT_PROD_EXPR \
2524 || (SYM) == REALIGN_LOAD_EXPR \
4e71066d 2525 || (SYM) == VEC_COND_EXPR \
2205ed25 2526 || (SYM) == VEC_PERM_EXPR \
16949072 2527 || (SYM) == FMA_EXPR) ? GIMPLE_TERNARY_RHS \
4e71066d 2528 : ((SYM) == CONSTRUCTOR \
726a989a
RB
2529 || (SYM) == OBJ_TYPE_REF \
2530 || (SYM) == ASSERT_EXPR \
2531 || (SYM) == ADDR_EXPR \
2532 || (SYM) == WITH_SIZE_EXPR \
4e71066d 2533 || (SYM) == SSA_NAME) ? GIMPLE_SINGLE_RHS \
726a989a
RB
2534 : GIMPLE_INVALID_RHS),
2535#define END_OF_BASE_TREE_CODES (unsigned char) GIMPLE_INVALID_RHS,
2536
2537const unsigned char gimple_rhs_class_table[] = {
2538#include "all-tree.def"
2539};
2540
2541#undef DEFTREECODE
2542#undef END_OF_BASE_TREE_CODES
2543
2544/* For the definitive definition of GIMPLE, see doc/tree-ssa.texi. */
2545
2546/* Validation of GIMPLE expressions. */
2547
726a989a
RB
2548/* Return true if T is a valid LHS for a GIMPLE assignment expression. */
2549
2550bool
2551is_gimple_lvalue (tree t)
2552{
2553 return (is_gimple_addressable (t)
2554 || TREE_CODE (t) == WITH_SIZE_EXPR
2555 /* These are complex lvalues, but don't have addresses, so they
2556 go here. */
2557 || TREE_CODE (t) == BIT_FIELD_REF);
2558}
2559
2560/* Return true if T is a GIMPLE condition. */
2561
2562bool
2563is_gimple_condexpr (tree t)
2564{
2565 return (is_gimple_val (t) || (COMPARISON_CLASS_P (t)
f9613c9a 2566 && !tree_could_throw_p (t)
726a989a
RB
2567 && is_gimple_val (TREE_OPERAND (t, 0))
2568 && is_gimple_val (TREE_OPERAND (t, 1))));
2569}
2570
2571/* Return true if T is something whose address can be taken. */
2572
2573bool
2574is_gimple_addressable (tree t)
2575{
70f34814
RG
2576 return (is_gimple_id (t) || handled_component_p (t)
2577 || TREE_CODE (t) == MEM_REF);
726a989a
RB
2578}
2579
2580/* Return true if T is a valid gimple constant. */
2581
2582bool
2583is_gimple_constant (const_tree t)
2584{
2585 switch (TREE_CODE (t))
2586 {
2587 case INTEGER_CST:
2588 case REAL_CST:
2589 case FIXED_CST:
2590 case STRING_CST:
2591 case COMPLEX_CST:
2592 case VECTOR_CST:
2593 return true;
2594
726a989a
RB
2595 default:
2596 return false;
2597 }
2598}
2599
2600/* Return true if T is a gimple address. */
2601
2602bool
2603is_gimple_address (const_tree t)
2604{
2605 tree op;
2606
2607 if (TREE_CODE (t) != ADDR_EXPR)
2608 return false;
2609
2610 op = TREE_OPERAND (t, 0);
2611 while (handled_component_p (op))
2612 {
2613 if ((TREE_CODE (op) == ARRAY_REF
2614 || TREE_CODE (op) == ARRAY_RANGE_REF)
2615 && !is_gimple_val (TREE_OPERAND (op, 1)))
2616 return false;
2617
2618 op = TREE_OPERAND (op, 0);
2619 }
2620
70f34814 2621 if (CONSTANT_CLASS_P (op) || TREE_CODE (op) == MEM_REF)
726a989a
RB
2622 return true;
2623
2624 switch (TREE_CODE (op))
2625 {
2626 case PARM_DECL:
2627 case RESULT_DECL:
2628 case LABEL_DECL:
2629 case FUNCTION_DECL:
2630 case VAR_DECL:
2631 case CONST_DECL:
2632 return true;
2633
2634 default:
2635 return false;
2636 }
2637}
2638
00fc2333
JH
2639/* Return true if T is a gimple invariant address. */
2640
2641bool
2642is_gimple_invariant_address (const_tree t)
2643{
2644 const_tree op;
2645
2646 if (TREE_CODE (t) != ADDR_EXPR)
2647 return false;
2648
2649 op = strip_invariant_refs (TREE_OPERAND (t, 0));
70f34814
RG
2650 if (!op)
2651 return false;
00fc2333 2652
70f34814
RG
2653 if (TREE_CODE (op) == MEM_REF)
2654 {
2655 const_tree op0 = TREE_OPERAND (op, 0);
2656 return (TREE_CODE (op0) == ADDR_EXPR
2657 && (CONSTANT_CLASS_P (TREE_OPERAND (op0, 0))
2658 || decl_address_invariant_p (TREE_OPERAND (op0, 0))));
2659 }
2660
2661 return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op);
00fc2333
JH
2662}
2663
2664/* Return true if T is a gimple invariant address at IPA level
2665 (so addresses of variables on stack are not allowed). */
2666
2667bool
2668is_gimple_ip_invariant_address (const_tree t)
2669{
2670 const_tree op;
2671
2672 if (TREE_CODE (t) != ADDR_EXPR)
2673 return false;
2674
2675 op = strip_invariant_refs (TREE_OPERAND (t, 0));
39cc8c3d
MJ
2676 if (!op)
2677 return false;
2678
2679 if (TREE_CODE (op) == MEM_REF)
2680 {
2681 const_tree op0 = TREE_OPERAND (op, 0);
2682 return (TREE_CODE (op0) == ADDR_EXPR
2683 && (CONSTANT_CLASS_P (TREE_OPERAND (op0, 0))
2684 || decl_address_ip_invariant_p (TREE_OPERAND (op0, 0))));
2685 }
00fc2333 2686
39cc8c3d 2687 return CONSTANT_CLASS_P (op) || decl_address_ip_invariant_p (op);
726a989a
RB
2688}
2689
2690/* Return true if T is a GIMPLE minimal invariant. It's a restricted
2691 form of function invariant. */
2692
2693bool
2694is_gimple_min_invariant (const_tree t)
2695{
2696 if (TREE_CODE (t) == ADDR_EXPR)
2697 return is_gimple_invariant_address (t);
2698
2699 return is_gimple_constant (t);
2700}
2701
00fc2333
JH
2702/* Return true if T is a GIMPLE interprocedural invariant. It's a restricted
2703 form of gimple minimal invariant. */
2704
2705bool
2706is_gimple_ip_invariant (const_tree t)
2707{
2708 if (TREE_CODE (t) == ADDR_EXPR)
2709 return is_gimple_ip_invariant_address (t);
2710
2711 return is_gimple_constant (t);
2712}
2713
726a989a
RB
2714/* Return true if T is a variable. */
2715
2716bool
2717is_gimple_variable (tree t)
2718{
2719 return (TREE_CODE (t) == VAR_DECL
2720 || TREE_CODE (t) == PARM_DECL
2721 || TREE_CODE (t) == RESULT_DECL
2722 || TREE_CODE (t) == SSA_NAME);
2723}
2724
2725/* Return true if T is a GIMPLE identifier (something with an address). */
2726
2727bool
2728is_gimple_id (tree t)
2729{
2730 return (is_gimple_variable (t)
2731 || TREE_CODE (t) == FUNCTION_DECL
2732 || TREE_CODE (t) == LABEL_DECL
2733 || TREE_CODE (t) == CONST_DECL
2734 /* Allow string constants, since they are addressable. */
2735 || TREE_CODE (t) == STRING_CST);
2736}
2737
726a989a
RB
2738/* Return true if T is a non-aggregate register variable. */
2739
2740bool
2741is_gimple_reg (tree t)
2742{
a471762f 2743 if (virtual_operand_p (t))
3828719a 2744 return false;
726a989a 2745
a471762f
RG
2746 if (TREE_CODE (t) == SSA_NAME)
2747 return true;
2748
726a989a
RB
2749 if (!is_gimple_variable (t))
2750 return false;
2751
2752 if (!is_gimple_reg_type (TREE_TYPE (t)))
2753 return false;
2754
2755 /* A volatile decl is not acceptable because we can't reuse it as
2756 needed. We need to copy it into a temp first. */
2757 if (TREE_THIS_VOLATILE (t))
2758 return false;
2759
2760 /* We define "registers" as things that can be renamed as needed,
2761 which with our infrastructure does not apply to memory. */
2762 if (needs_to_live_in_memory (t))
2763 return false;
2764
2765 /* Hard register variables are an interesting case. For those that
2766 are call-clobbered, we don't know where all the calls are, since
2767 we don't (want to) take into account which operations will turn
2768 into libcalls at the rtl level. For those that are call-saved,
2769 we don't currently model the fact that calls may in fact change
2770 global hard registers, nor do we examine ASM_CLOBBERS at the tree
2771 level, and so miss variable changes that might imply. All around,
2772 it seems safest to not do too much optimization with these at the
2773 tree level at all. We'll have to rely on the rtl optimizers to
2774 clean this up, as there we've got all the appropriate bits exposed. */
2775 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t))
2776 return false;
2777
4636b850
RG
2778 /* Complex and vector values must have been put into SSA-like form.
2779 That is, no assignments to the individual components. */
2780 if (TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE
2781 || TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE)
2782 return DECL_GIMPLE_REG_P (t);
2783
726a989a
RB
2784 return true;
2785}
2786
2787
726a989a
RB
2788/* Return true if T is a GIMPLE rvalue, i.e. an identifier or a constant. */
2789
2790bool
2791is_gimple_val (tree t)
2792{
2793 /* Make loads from volatiles and memory vars explicit. */
2794 if (is_gimple_variable (t)
2795 && is_gimple_reg_type (TREE_TYPE (t))
2796 && !is_gimple_reg (t))
2797 return false;
2798
726a989a
RB
2799 return (is_gimple_variable (t) || is_gimple_min_invariant (t));
2800}
2801
2802/* Similarly, but accept hard registers as inputs to asm statements. */
2803
2804bool
2805is_gimple_asm_val (tree t)
2806{
2807 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t))
2808 return true;
2809
2810 return is_gimple_val (t);
2811}
2812
2813/* Return true if T is a GIMPLE minimal lvalue. */
2814
2815bool
2816is_gimple_min_lval (tree t)
2817{
ba4d8f9d
RG
2818 if (!(t = CONST_CAST_TREE (strip_invariant_refs (t))))
2819 return false;
70f34814 2820 return (is_gimple_id (t) || TREE_CODE (t) == MEM_REF);
726a989a
RB
2821}
2822
726a989a
RB
2823/* Return true if T is a valid function operand of a CALL_EXPR. */
2824
2825bool
2826is_gimple_call_addr (tree t)
2827{
2828 return (TREE_CODE (t) == OBJ_TYPE_REF || is_gimple_val (t));
2829}
2830
70f34814
RG
2831/* Return true if T is a valid address operand of a MEM_REF. */
2832
2833bool
2834is_gimple_mem_ref_addr (tree t)
2835{
2836 return (is_gimple_reg (t)
2837 || TREE_CODE (t) == INTEGER_CST
2838 || (TREE_CODE (t) == ADDR_EXPR
2839 && (CONSTANT_CLASS_P (TREE_OPERAND (t, 0))
2840 || decl_address_invariant_p (TREE_OPERAND (t, 0)))));
2841}
2842
726a989a
RB
2843
2844/* Given a memory reference expression T, return its base address.
2845 The base address of a memory reference expression is the main
2846 object being referenced. For instance, the base address for
2847 'array[i].fld[j]' is 'array'. You can think of this as stripping
2848 away the offset part from a memory address.
2849
2850 This function calls handled_component_p to strip away all the inner
2851 parts of the memory reference until it reaches the base object. */
2852
2853tree
2854get_base_address (tree t)
2855{
2856 while (handled_component_p (t))
2857 t = TREE_OPERAND (t, 0);
b8698a0f 2858
4d948885
RG
2859 if ((TREE_CODE (t) == MEM_REF
2860 || TREE_CODE (t) == TARGET_MEM_REF)
70f34814
RG
2861 && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
2862 t = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
2863
5a27a197
RG
2864 /* ??? Either the alias oracle or all callers need to properly deal
2865 with WITH_SIZE_EXPRs before we can look through those. */
2866 if (TREE_CODE (t) == WITH_SIZE_EXPR)
726a989a 2867 return NULL_TREE;
5a27a197
RG
2868
2869 return t;
726a989a
RB
2870}
2871
2872void
2873recalculate_side_effects (tree t)
2874{
2875 enum tree_code code = TREE_CODE (t);
2876 int len = TREE_OPERAND_LENGTH (t);
2877 int i;
2878
2879 switch (TREE_CODE_CLASS (code))
2880 {
2881 case tcc_expression:
2882 switch (code)
2883 {
2884 case INIT_EXPR:
2885 case MODIFY_EXPR:
2886 case VA_ARG_EXPR:
2887 case PREDECREMENT_EXPR:
2888 case PREINCREMENT_EXPR:
2889 case POSTDECREMENT_EXPR:
2890 case POSTINCREMENT_EXPR:
2891 /* All of these have side-effects, no matter what their
2892 operands are. */
2893 return;
2894
2895 default:
2896 break;
2897 }
2898 /* Fall through. */
2899
2900 case tcc_comparison: /* a comparison expression */
2901 case tcc_unary: /* a unary arithmetic expression */
2902 case tcc_binary: /* a binary arithmetic expression */
2903 case tcc_reference: /* a reference */
2904 case tcc_vl_exp: /* a function call */
2905 TREE_SIDE_EFFECTS (t) = TREE_THIS_VOLATILE (t);
2906 for (i = 0; i < len; ++i)
2907 {
2908 tree op = TREE_OPERAND (t, i);
2909 if (op && TREE_SIDE_EFFECTS (op))
2910 TREE_SIDE_EFFECTS (t) = 1;
2911 }
2912 break;
2913
13f95bdb
EB
2914 case tcc_constant:
2915 /* No side-effects. */
2916 return;
2917
726a989a 2918 default:
726a989a
RB
2919 gcc_unreachable ();
2920 }
2921}
2922
2923/* Canonicalize a tree T for use in a COND_EXPR as conditional. Returns
2924 a canonicalized tree that is valid for a COND_EXPR or NULL_TREE, if
2925 we failed to create one. */
2926
2927tree
2928canonicalize_cond_expr_cond (tree t)
2929{
b66a1bac
RG
2930 /* Strip conversions around boolean operations. */
2931 if (CONVERT_EXPR_P (t)
9b80d091
KT
2932 && (truth_value_p (TREE_CODE (TREE_OPERAND (t, 0)))
2933 || TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0)))
2934 == BOOLEAN_TYPE))
b66a1bac
RG
2935 t = TREE_OPERAND (t, 0);
2936
726a989a 2937 /* For !x use x == 0. */
12430896 2938 if (TREE_CODE (t) == TRUTH_NOT_EXPR)
726a989a
RB
2939 {
2940 tree top0 = TREE_OPERAND (t, 0);
2941 t = build2 (EQ_EXPR, TREE_TYPE (t),
2942 top0, build_int_cst (TREE_TYPE (top0), 0));
2943 }
2944 /* For cmp ? 1 : 0 use cmp. */
2945 else if (TREE_CODE (t) == COND_EXPR
2946 && COMPARISON_CLASS_P (TREE_OPERAND (t, 0))
2947 && integer_onep (TREE_OPERAND (t, 1))
2948 && integer_zerop (TREE_OPERAND (t, 2)))
2949 {
2950 tree top0 = TREE_OPERAND (t, 0);
2951 t = build2 (TREE_CODE (top0), TREE_TYPE (t),
2952 TREE_OPERAND (top0, 0), TREE_OPERAND (top0, 1));
2953 }
4481581f
JL
2954 /* For x ^ y use x != y. */
2955 else if (TREE_CODE (t) == BIT_XOR_EXPR)
2956 t = build2 (NE_EXPR, TREE_TYPE (t),
2957 TREE_OPERAND (t, 0), TREE_OPERAND (t, 1));
2958
726a989a
RB
2959 if (is_gimple_condexpr (t))
2960 return t;
2961
2962 return NULL_TREE;
2963}
2964
e6c99067
DN
2965/* Build a GIMPLE_CALL identical to STMT but skipping the arguments in
2966 the positions marked by the set ARGS_TO_SKIP. */
2967
c6f7cfc1 2968gimple
5c0466b5 2969gimple_call_copy_skip_args (gimple stmt, bitmap args_to_skip)
c6f7cfc1
JH
2970{
2971 int i;
c6f7cfc1 2972 int nargs = gimple_call_num_args (stmt);
9771b263
DN
2973 vec<tree> vargs;
2974 vargs.create (nargs);
c6f7cfc1
JH
2975 gimple new_stmt;
2976
2977 for (i = 0; i < nargs; i++)
2978 if (!bitmap_bit_p (args_to_skip, i))
9771b263 2979 vargs.quick_push (gimple_call_arg (stmt, i));
c6f7cfc1 2980
25583c4f
RS
2981 if (gimple_call_internal_p (stmt))
2982 new_stmt = gimple_build_call_internal_vec (gimple_call_internal_fn (stmt),
2983 vargs);
2984 else
2985 new_stmt = gimple_build_call_vec (gimple_call_fn (stmt), vargs);
9771b263 2986 vargs.release ();
c6f7cfc1
JH
2987 if (gimple_call_lhs (stmt))
2988 gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt));
2989
5006671f
RG
2990 gimple_set_vuse (new_stmt, gimple_vuse (stmt));
2991 gimple_set_vdef (new_stmt, gimple_vdef (stmt));
2992
c6f7cfc1
JH
2993 if (gimple_has_location (stmt))
2994 gimple_set_location (new_stmt, gimple_location (stmt));
8d2adc24 2995 gimple_call_copy_flags (new_stmt, stmt);
c6f7cfc1 2996 gimple_call_set_chain (new_stmt, gimple_call_chain (stmt));
5006671f
RG
2997
2998 gimple_set_modified (new_stmt, true);
2999
c6f7cfc1
JH
3000 return new_stmt;
3001}
3002
5006671f 3003
d7f09764 3004
d025732d
EB
3005/* Return true if the field decls F1 and F2 are at the same offset.
3006
91f2fae8 3007 This is intended to be used on GIMPLE types only. */
d7f09764 3008
1e4bc4eb 3009bool
d025732d 3010gimple_compare_field_offset (tree f1, tree f2)
d7f09764
DN
3011{
3012 if (DECL_OFFSET_ALIGN (f1) == DECL_OFFSET_ALIGN (f2))
d025732d
EB
3013 {
3014 tree offset1 = DECL_FIELD_OFFSET (f1);
3015 tree offset2 = DECL_FIELD_OFFSET (f2);
3016 return ((offset1 == offset2
3017 /* Once gimplification is done, self-referential offsets are
3018 instantiated as operand #2 of the COMPONENT_REF built for
3019 each access and reset. Therefore, they are not relevant
3020 anymore and fields are interchangeable provided that they
3021 represent the same access. */
3022 || (TREE_CODE (offset1) == PLACEHOLDER_EXPR
3023 && TREE_CODE (offset2) == PLACEHOLDER_EXPR
3024 && (DECL_SIZE (f1) == DECL_SIZE (f2)
3025 || (TREE_CODE (DECL_SIZE (f1)) == PLACEHOLDER_EXPR
3026 && TREE_CODE (DECL_SIZE (f2)) == PLACEHOLDER_EXPR)
3027 || operand_equal_p (DECL_SIZE (f1), DECL_SIZE (f2), 0))
3028 && DECL_ALIGN (f1) == DECL_ALIGN (f2))
3029 || operand_equal_p (offset1, offset2, 0))
3030 && tree_int_cst_equal (DECL_FIELD_BIT_OFFSET (f1),
3031 DECL_FIELD_BIT_OFFSET (f2)));
3032 }
d7f09764
DN
3033
3034 /* Fortran and C do not always agree on what DECL_OFFSET_ALIGN
3035 should be, so handle differing ones specially by decomposing
3036 the offset into a byte and bit offset manually. */
3037 if (host_integerp (DECL_FIELD_OFFSET (f1), 0)
3038 && host_integerp (DECL_FIELD_OFFSET (f2), 0))
3039 {
3040 unsigned HOST_WIDE_INT byte_offset1, byte_offset2;
3041 unsigned HOST_WIDE_INT bit_offset1, bit_offset2;
3042 bit_offset1 = TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f1));
3043 byte_offset1 = (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f1))
3044 + bit_offset1 / BITS_PER_UNIT);
3045 bit_offset2 = TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f2));
3046 byte_offset2 = (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f2))
3047 + bit_offset2 / BITS_PER_UNIT);
3048 if (byte_offset1 != byte_offset2)
3049 return false;
3050 return bit_offset1 % BITS_PER_UNIT == bit_offset2 % BITS_PER_UNIT;
3051 }
3052
3053 return false;
3054}
3055
825b27de
RG
3056/* Returning a hash value for gimple type TYPE combined with VAL.
3057
3058 The hash value returned is equal for types considered compatible
3059 by gimple_canonical_types_compatible_p. */
3060
3061static hashval_t
3062iterative_hash_canonical_type (tree type, hashval_t val)
3063{
3064 hashval_t v;
3065 void **slot;
3066 struct tree_int_map *mp, m;
3067
3068 m.base.from = type;
3069 if ((slot = htab_find_slot (canonical_type_hash_cache, &m, INSERT))
3070 && *slot)
d0340959 3071 return iterative_hash_hashval_t (((struct tree_int_map *) *slot)->to, val);
825b27de
RG
3072
3073 /* Combine a few common features of types so that types are grouped into
3074 smaller sets; when searching for existing matching types to merge,
3075 only existing types having the same features as the new type will be
3076 checked. */
3077 v = iterative_hash_hashval_t (TREE_CODE (type), 0);
825b27de 3078 v = iterative_hash_hashval_t (TREE_ADDRESSABLE (type), v);
61332f77
RG
3079 v = iterative_hash_hashval_t (TYPE_ALIGN (type), v);
3080 v = iterative_hash_hashval_t (TYPE_MODE (type), v);
825b27de
RG
3081
3082 /* Incorporate common features of numerical types. */
3083 if (INTEGRAL_TYPE_P (type)
3084 || SCALAR_FLOAT_TYPE_P (type)
61332f77
RG
3085 || FIXED_POINT_TYPE_P (type)
3086 || TREE_CODE (type) == VECTOR_TYPE
3087 || TREE_CODE (type) == COMPLEX_TYPE
3088 || TREE_CODE (type) == OFFSET_TYPE
3089 || POINTER_TYPE_P (type))
825b27de
RG
3090 {
3091 v = iterative_hash_hashval_t (TYPE_PRECISION (type), v);
825b27de
RG
3092 v = iterative_hash_hashval_t (TYPE_UNSIGNED (type), v);
3093 }
3094
3095 /* For pointer and reference types, fold in information about the type
3096 pointed to but do not recurse to the pointed-to type. */
3097 if (POINTER_TYPE_P (type))
3098 {
3099 v = iterative_hash_hashval_t (TYPE_REF_CAN_ALIAS_ALL (type), v);
61332f77
RG
3100 v = iterative_hash_hashval_t (TYPE_ADDR_SPACE (TREE_TYPE (type)), v);
3101 v = iterative_hash_hashval_t (TYPE_RESTRICT (type), v);
825b27de
RG
3102 v = iterative_hash_hashval_t (TREE_CODE (TREE_TYPE (type)), v);
3103 }
3104
2e745103 3105 /* For integer types hash only the string flag. */
825b27de 3106 if (TREE_CODE (type) == INTEGER_TYPE)
3ac8781c 3107 v = iterative_hash_hashval_t (TYPE_STRING_FLAG (type), v);
825b27de 3108
2e745103
EB
3109 /* For array types hash the domain bounds and the string flag. */
3110 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type))
825b27de
RG
3111 {
3112 v = iterative_hash_hashval_t (TYPE_STRING_FLAG (type), v);
2e745103
EB
3113 /* OMP lowering can introduce error_mark_node in place of
3114 random local decls in types. */
3115 if (TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != error_mark_node)
3116 v = iterative_hash_expr (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), v);
3117 if (TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != error_mark_node)
3118 v = iterative_hash_expr (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), v);
825b27de
RG
3119 }
3120
3121 /* Recurse for aggregates with a single element type. */
3122 if (TREE_CODE (type) == ARRAY_TYPE
3123 || TREE_CODE (type) == COMPLEX_TYPE
3124 || TREE_CODE (type) == VECTOR_TYPE)
3125 v = iterative_hash_canonical_type (TREE_TYPE (type), v);
3126
3127 /* Incorporate function return and argument types. */
3128 if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
3129 {
3130 unsigned na;
3131 tree p;
3132
3133 /* For method types also incorporate their parent class. */
3134 if (TREE_CODE (type) == METHOD_TYPE)
3135 v = iterative_hash_canonical_type (TYPE_METHOD_BASETYPE (type), v);
3136
6a20ce76 3137 v = iterative_hash_canonical_type (TREE_TYPE (type), v);
825b27de
RG
3138
3139 for (p = TYPE_ARG_TYPES (type), na = 0; p; p = TREE_CHAIN (p))
3140 {
6a20ce76 3141 v = iterative_hash_canonical_type (TREE_VALUE (p), v);
825b27de
RG
3142 na++;
3143 }
3144
3145 v = iterative_hash_hashval_t (na, v);
3146 }
3147
aa47290b 3148 if (RECORD_OR_UNION_TYPE_P (type))
825b27de
RG
3149 {
3150 unsigned nf;
3151 tree f;
3152
3153 for (f = TYPE_FIELDS (type), nf = 0; f; f = TREE_CHAIN (f))
e7cfe241
RG
3154 if (TREE_CODE (f) == FIELD_DECL)
3155 {
3156 v = iterative_hash_canonical_type (TREE_TYPE (f), v);
3157 nf++;
3158 }
825b27de
RG
3159
3160 v = iterative_hash_hashval_t (nf, v);
3161 }
3162
3163 /* Cache the just computed hash value. */
3164 mp = ggc_alloc_cleared_tree_int_map ();
3165 mp->base.from = type;
3166 mp->to = v;
3167 *slot = (void *) mp;
3168
3169 return iterative_hash_hashval_t (v, val);
3170}
3171
a844a60b
RG
3172static hashval_t
3173gimple_canonical_type_hash (const void *p)
3174{
825b27de
RG
3175 if (canonical_type_hash_cache == NULL)
3176 canonical_type_hash_cache = htab_create_ggc (512, tree_int_map_hash,
3177 tree_int_map_eq, NULL);
3178
3179 return iterative_hash_canonical_type (CONST_CAST_TREE ((const_tree) p), 0);
a844a60b
RG
3180}
3181
d7f09764 3182
93b2a207 3183
4490cae6 3184
825b27de
RG
3185/* The TYPE_CANONICAL merging machinery. It should closely resemble
3186 the middle-end types_compatible_p function. It needs to avoid
3187 claiming types are different for types that should be treated
3188 the same with respect to TBAA. Canonical types are also used
3189 for IL consistency checks via the useless_type_conversion_p
3190 predicate which does not handle all type kinds itself but falls
3191 back to pointer-comparison of TYPE_CANONICAL for aggregates
3192 for example. */
3193
3194/* Return true iff T1 and T2 are structurally identical for what
3195 TBAA is concerned. */
3196
3197static bool
3198gimple_canonical_types_compatible_p (tree t1, tree t2)
3199{
825b27de
RG
3200 /* Before starting to set up the SCC machinery handle simple cases. */
3201
3202 /* Check first for the obvious case of pointer identity. */
3203 if (t1 == t2)
3204 return true;
3205
3206 /* Check that we have two types to compare. */
3207 if (t1 == NULL_TREE || t2 == NULL_TREE)
3208 return false;
3209
3210 /* If the types have been previously registered and found equal
3211 they still are. */
3212 if (TYPE_CANONICAL (t1)
3213 && TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2))
3214 return true;
3215
3216 /* Can't be the same type if the types don't have the same code. */
3217 if (TREE_CODE (t1) != TREE_CODE (t2))
3218 return false;
3219
61332f77 3220 if (TREE_ADDRESSABLE (t1) != TREE_ADDRESSABLE (t2))
825b27de
RG
3221 return false;
3222
61332f77
RG
3223 /* Qualifiers do not matter for canonical type comparison purposes. */
3224
3225 /* Void types and nullptr types are always the same. */
3226 if (TREE_CODE (t1) == VOID_TYPE
3227 || TREE_CODE (t1) == NULLPTR_TYPE)
825b27de
RG
3228 return true;
3229
61332f77
RG
3230 /* Can't be the same type if they have different alignment, or mode. */
3231 if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2)
3232 || TYPE_MODE (t1) != TYPE_MODE (t2))
3233 return false;
3234
3235 /* Non-aggregate types can be handled cheaply. */
825b27de
RG
3236 if (INTEGRAL_TYPE_P (t1)
3237 || SCALAR_FLOAT_TYPE_P (t1)
3238 || FIXED_POINT_TYPE_P (t1)
3239 || TREE_CODE (t1) == VECTOR_TYPE
3240 || TREE_CODE (t1) == COMPLEX_TYPE
61332f77
RG
3241 || TREE_CODE (t1) == OFFSET_TYPE
3242 || POINTER_TYPE_P (t1))
825b27de 3243 {
61332f77
RG
3244 /* Can't be the same type if they have different sign or precision. */
3245 if (TYPE_PRECISION (t1) != TYPE_PRECISION (t2)
825b27de
RG
3246 || TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2))
3247 return false;
3248
3249 if (TREE_CODE (t1) == INTEGER_TYPE
3ac8781c 3250 && TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2))
825b27de
RG
3251 return false;
3252
61332f77
RG
3253 /* For canonical type comparisons we do not want to build SCCs
3254 so we cannot compare pointed-to types. But we can, for now,
3255 require the same pointed-to type kind and match what
3256 useless_type_conversion_p would do. */
3257 if (POINTER_TYPE_P (t1))
3258 {
3259 /* If the two pointers have different ref-all attributes,
3260 they can't be the same type. */
3261 if (TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2))
3262 return false;
825b27de 3263
61332f77
RG
3264 if (TYPE_ADDR_SPACE (TREE_TYPE (t1))
3265 != TYPE_ADDR_SPACE (TREE_TYPE (t2)))
3266 return false;
825b27de 3267
61332f77
RG
3268 if (TYPE_RESTRICT (t1) != TYPE_RESTRICT (t2))
3269 return false;
3270
3271 if (TREE_CODE (TREE_TYPE (t1)) != TREE_CODE (TREE_TYPE (t2)))
3272 return false;
3273 }
3274
3275 /* Tail-recurse to components. */
3276 if (TREE_CODE (t1) == VECTOR_TYPE
3277 || TREE_CODE (t1) == COMPLEX_TYPE)
3278 return gimple_canonical_types_compatible_p (TREE_TYPE (t1),
3279 TREE_TYPE (t2));
3280
3281 return true;
825b27de
RG
3282 }
3283
825b27de
RG
3284 /* Do type-specific comparisons. */
3285 switch (TREE_CODE (t1))
3286 {
825b27de
RG
3287 case ARRAY_TYPE:
3288 /* Array types are the same if the element types are the same and
3289 the number of elements are the same. */
3290 if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2))
3291 || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)
3292 || TYPE_NONALIASED_COMPONENT (t1) != TYPE_NONALIASED_COMPONENT (t2))
b8a71aed 3293 return false;
825b27de
RG
3294 else
3295 {
3296 tree i1 = TYPE_DOMAIN (t1);
3297 tree i2 = TYPE_DOMAIN (t2);
3298
3299 /* For an incomplete external array, the type domain can be
3300 NULL_TREE. Check this condition also. */
3301 if (i1 == NULL_TREE && i2 == NULL_TREE)
b8a71aed 3302 return true;
825b27de 3303 else if (i1 == NULL_TREE || i2 == NULL_TREE)
b8a71aed 3304 return false;
825b27de
RG
3305 else
3306 {
3307 tree min1 = TYPE_MIN_VALUE (i1);
3308 tree min2 = TYPE_MIN_VALUE (i2);
3309 tree max1 = TYPE_MAX_VALUE (i1);
3310 tree max2 = TYPE_MAX_VALUE (i2);
3311
3312 /* The minimum/maximum values have to be the same. */
3313 if ((min1 == min2
3314 || (min1 && min2
3315 && ((TREE_CODE (min1) == PLACEHOLDER_EXPR
3316 && TREE_CODE (min2) == PLACEHOLDER_EXPR)
3317 || operand_equal_p (min1, min2, 0))))
3318 && (max1 == max2
3319 || (max1 && max2
3320 && ((TREE_CODE (max1) == PLACEHOLDER_EXPR
3321 && TREE_CODE (max2) == PLACEHOLDER_EXPR)
3322 || operand_equal_p (max1, max2, 0)))))
b8a71aed 3323 return true;
825b27de 3324 else
b8a71aed 3325 return false;
825b27de
RG
3326 }
3327 }
3328
3329 case METHOD_TYPE:
825b27de
RG
3330 case FUNCTION_TYPE:
3331 /* Function types are the same if the return type and arguments types
3332 are the same. */
6a20ce76 3333 if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2)))
b8a71aed 3334 return false;
825b27de
RG
3335
3336 if (!comp_type_attributes (t1, t2))
b8a71aed 3337 return false;
825b27de
RG
3338
3339 if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2))
b8a71aed 3340 return true;
825b27de
RG
3341 else
3342 {
3343 tree parms1, parms2;
3344
3345 for (parms1 = TYPE_ARG_TYPES (t1), parms2 = TYPE_ARG_TYPES (t2);
3346 parms1 && parms2;
3347 parms1 = TREE_CHAIN (parms1), parms2 = TREE_CHAIN (parms2))
3348 {
6a20ce76
RG
3349 if (!gimple_canonical_types_compatible_p
3350 (TREE_VALUE (parms1), TREE_VALUE (parms2)))
b8a71aed 3351 return false;
825b27de
RG
3352 }
3353
3354 if (parms1 || parms2)
b8a71aed 3355 return false;
825b27de 3356
b8a71aed 3357 return true;
825b27de
RG
3358 }
3359
825b27de
RG
3360 case RECORD_TYPE:
3361 case UNION_TYPE:
3362 case QUAL_UNION_TYPE:
3363 {
3364 tree f1, f2;
3365
3366 /* For aggregate types, all the fields must be the same. */
3367 for (f1 = TYPE_FIELDS (t1), f2 = TYPE_FIELDS (t2);
4acd1c84 3368 f1 || f2;
825b27de
RG
3369 f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
3370 {
e7cfe241
RG
3371 /* Skip non-fields. */
3372 while (f1 && TREE_CODE (f1) != FIELD_DECL)
3373 f1 = TREE_CHAIN (f1);
3374 while (f2 && TREE_CODE (f2) != FIELD_DECL)
3375 f2 = TREE_CHAIN (f2);
3376 if (!f1 || !f2)
3377 break;
825b27de
RG
3378 /* The fields must have the same name, offset and type. */
3379 if (DECL_NONADDRESSABLE_P (f1) != DECL_NONADDRESSABLE_P (f2)
3380 || !gimple_compare_field_offset (f1, f2)
3381 || !gimple_canonical_types_compatible_p
3382 (TREE_TYPE (f1), TREE_TYPE (f2)))
b8a71aed 3383 return false;
825b27de
RG
3384 }
3385
3386 /* If one aggregate has more fields than the other, they
3387 are not the same. */
3388 if (f1 || f2)
b8a71aed 3389 return false;
825b27de 3390
b8a71aed 3391 return true;
825b27de
RG
3392 }
3393
3394 default:
3395 gcc_unreachable ();
3396 }
825b27de
RG
3397}
3398
3399
4490cae6
RG
3400/* Returns nonzero if P1 and P2 are equal. */
3401
3402static int
3403gimple_canonical_type_eq (const void *p1, const void *p2)
3404{
3405 const_tree t1 = (const_tree) p1;
3406 const_tree t2 = (const_tree) p2;
825b27de
RG
3407 return gimple_canonical_types_compatible_p (CONST_CAST_TREE (t1),
3408 CONST_CAST_TREE (t2));
4490cae6
RG
3409}
3410
3411/* Register type T in the global type table gimple_types.
3412 If another type T', compatible with T, already existed in
3413 gimple_types then return T', otherwise return T. This is used by
96d91dcf
RG
3414 LTO to merge identical types read from different TUs.
3415
3416 ??? This merging does not exactly match how the tree.c middle-end
3417 functions will assign TYPE_CANONICAL when new types are created
3418 during optimization (which at least happens for pointer and array
3419 types). */
4490cae6
RG
3420
3421tree
3422gimple_register_canonical_type (tree t)
3423{
3424 void **slot;
3425
3426 gcc_assert (TYPE_P (t));
3427
61332f77
RG
3428 if (TYPE_CANONICAL (t))
3429 return TYPE_CANONICAL (t);
3430
4490cae6 3431 if (gimple_canonical_types == NULL)
a844a60b 3432 gimple_canonical_types = htab_create_ggc (16381, gimple_canonical_type_hash,
4490cae6
RG
3433 gimple_canonical_type_eq, 0);
3434
3435 slot = htab_find_slot (gimple_canonical_types, t, INSERT);
3436 if (*slot
3437 && *(tree *)slot != t)
3438 {
3439 tree new_type = (tree) *((tree *) slot);
3440
3441 TYPE_CANONICAL (t) = new_type;
3442 t = new_type;
3443 }
3444 else
3445 {
3446 TYPE_CANONICAL (t) = t;
4a2ac96f
RG
3447 *slot = (void *) t;
3448 }
d7f09764
DN
3449
3450 return t;
3451}
3452
3453
3454/* Show statistics on references to the global type table gimple_types. */
3455
3456void
b8f4e58f 3457print_gimple_types_stats (const char *pfx)
d7f09764 3458{
4490cae6 3459 if (gimple_canonical_types)
b8f4e58f
RG
3460 fprintf (stderr, "[%s] GIMPLE canonical type table: size %ld, "
3461 "%ld elements, %ld searches, %ld collisions (ratio: %f)\n", pfx,
4490cae6
RG
3462 (long) htab_size (gimple_canonical_types),
3463 (long) htab_elements (gimple_canonical_types),
3464 (long) gimple_canonical_types->searches,
3465 (long) gimple_canonical_types->collisions,
3466 htab_collisions (gimple_canonical_types));
3467 else
b8f4e58f 3468 fprintf (stderr, "[%s] GIMPLE canonical type table is empty\n", pfx);
a844a60b 3469 if (canonical_type_hash_cache)
b8f4e58f
RG
3470 fprintf (stderr, "[%s] GIMPLE canonical type hash table: size %ld, "
3471 "%ld elements, %ld searches, %ld collisions (ratio: %f)\n", pfx,
a844a60b
RG
3472 (long) htab_size (canonical_type_hash_cache),
3473 (long) htab_elements (canonical_type_hash_cache),
3474 (long) canonical_type_hash_cache->searches,
3475 (long) canonical_type_hash_cache->collisions,
3476 htab_collisions (canonical_type_hash_cache));
0f443ad0 3477 else
b8f4e58f 3478 fprintf (stderr, "[%s] GIMPLE canonical type hash table is empty\n", pfx);
d7f09764
DN
3479}
3480
0d0bfe17
RG
3481/* Free the gimple type hashtables used for LTO type merging. */
3482
3483void
3484free_gimple_type_tables (void)
3485{
4490cae6
RG
3486 if (gimple_canonical_types)
3487 {
3488 htab_delete (gimple_canonical_types);
3489 gimple_canonical_types = NULL;
3490 }
a844a60b
RG
3491 if (canonical_type_hash_cache)
3492 {
3493 htab_delete (canonical_type_hash_cache);
3494 canonical_type_hash_cache = NULL;
3495 }
0d0bfe17
RG
3496}
3497
d7f09764
DN
3498
3499/* Return a type the same as TYPE except unsigned or
3500 signed according to UNSIGNEDP. */
3501
3502static tree
3503gimple_signed_or_unsigned_type (bool unsignedp, tree type)
3504{
3505 tree type1;
3506
3507 type1 = TYPE_MAIN_VARIANT (type);
3508 if (type1 == signed_char_type_node
3509 || type1 == char_type_node
3510 || type1 == unsigned_char_type_node)
3511 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
3512 if (type1 == integer_type_node || type1 == unsigned_type_node)
3513 return unsignedp ? unsigned_type_node : integer_type_node;
3514 if (type1 == short_integer_type_node || type1 == short_unsigned_type_node)
3515 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
3516 if (type1 == long_integer_type_node || type1 == long_unsigned_type_node)
3517 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
3518 if (type1 == long_long_integer_type_node
3519 || type1 == long_long_unsigned_type_node)
3520 return unsignedp
3521 ? long_long_unsigned_type_node
3522 : long_long_integer_type_node;
a6766312
KT
3523 if (int128_integer_type_node && (type1 == int128_integer_type_node || type1 == int128_unsigned_type_node))
3524 return unsignedp
3525 ? int128_unsigned_type_node
3526 : int128_integer_type_node;
d7f09764
DN
3527#if HOST_BITS_PER_WIDE_INT >= 64
3528 if (type1 == intTI_type_node || type1 == unsigned_intTI_type_node)
3529 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
3530#endif
3531 if (type1 == intDI_type_node || type1 == unsigned_intDI_type_node)
3532 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
3533 if (type1 == intSI_type_node || type1 == unsigned_intSI_type_node)
3534 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
3535 if (type1 == intHI_type_node || type1 == unsigned_intHI_type_node)
3536 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
3537 if (type1 == intQI_type_node || type1 == unsigned_intQI_type_node)
3538 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
3539
3540#define GIMPLE_FIXED_TYPES(NAME) \
3541 if (type1 == short_ ## NAME ## _type_node \
3542 || type1 == unsigned_short_ ## NAME ## _type_node) \
3543 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
3544 : short_ ## NAME ## _type_node; \
3545 if (type1 == NAME ## _type_node \
3546 || type1 == unsigned_ ## NAME ## _type_node) \
3547 return unsignedp ? unsigned_ ## NAME ## _type_node \
3548 : NAME ## _type_node; \
3549 if (type1 == long_ ## NAME ## _type_node \
3550 || type1 == unsigned_long_ ## NAME ## _type_node) \
3551 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
3552 : long_ ## NAME ## _type_node; \
3553 if (type1 == long_long_ ## NAME ## _type_node \
3554 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
3555 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
3556 : long_long_ ## NAME ## _type_node;
3557
3558#define GIMPLE_FIXED_MODE_TYPES(NAME) \
3559 if (type1 == NAME ## _type_node \
3560 || type1 == u ## NAME ## _type_node) \
3561 return unsignedp ? u ## NAME ## _type_node \
3562 : NAME ## _type_node;
3563
3564#define GIMPLE_FIXED_TYPES_SAT(NAME) \
3565 if (type1 == sat_ ## short_ ## NAME ## _type_node \
3566 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
3567 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
3568 : sat_ ## short_ ## NAME ## _type_node; \
3569 if (type1 == sat_ ## NAME ## _type_node \
3570 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
3571 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
3572 : sat_ ## NAME ## _type_node; \
3573 if (type1 == sat_ ## long_ ## NAME ## _type_node \
3574 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
3575 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
3576 : sat_ ## long_ ## NAME ## _type_node; \
3577 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
3578 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
3579 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
3580 : sat_ ## long_long_ ## NAME ## _type_node;
3581
3582#define GIMPLE_FIXED_MODE_TYPES_SAT(NAME) \
3583 if (type1 == sat_ ## NAME ## _type_node \
3584 || type1 == sat_ ## u ## NAME ## _type_node) \
3585 return unsignedp ? sat_ ## u ## NAME ## _type_node \
3586 : sat_ ## NAME ## _type_node;
3587
3588 GIMPLE_FIXED_TYPES (fract);
3589 GIMPLE_FIXED_TYPES_SAT (fract);
3590 GIMPLE_FIXED_TYPES (accum);
3591 GIMPLE_FIXED_TYPES_SAT (accum);
3592
3593 GIMPLE_FIXED_MODE_TYPES (qq);
3594 GIMPLE_FIXED_MODE_TYPES (hq);
3595 GIMPLE_FIXED_MODE_TYPES (sq);
3596 GIMPLE_FIXED_MODE_TYPES (dq);
3597 GIMPLE_FIXED_MODE_TYPES (tq);
3598 GIMPLE_FIXED_MODE_TYPES_SAT (qq);
3599 GIMPLE_FIXED_MODE_TYPES_SAT (hq);
3600 GIMPLE_FIXED_MODE_TYPES_SAT (sq);
3601 GIMPLE_FIXED_MODE_TYPES_SAT (dq);
3602 GIMPLE_FIXED_MODE_TYPES_SAT (tq);
3603 GIMPLE_FIXED_MODE_TYPES (ha);
3604 GIMPLE_FIXED_MODE_TYPES (sa);
3605 GIMPLE_FIXED_MODE_TYPES (da);
3606 GIMPLE_FIXED_MODE_TYPES (ta);
3607 GIMPLE_FIXED_MODE_TYPES_SAT (ha);
3608 GIMPLE_FIXED_MODE_TYPES_SAT (sa);
3609 GIMPLE_FIXED_MODE_TYPES_SAT (da);
3610 GIMPLE_FIXED_MODE_TYPES_SAT (ta);
3611
3612 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
3613 the precision; they have precision set to match their range, but
3614 may use a wider mode to match an ABI. If we change modes, we may
3615 wind up with bad conversions. For INTEGER_TYPEs in C, must check
3616 the precision as well, so as to yield correct results for
3617 bit-field types. C++ does not have these separate bit-field
3618 types, and producing a signed or unsigned variant of an
3619 ENUMERAL_TYPE may cause other problems as well. */
3620 if (!INTEGRAL_TYPE_P (type)
3621 || TYPE_UNSIGNED (type) == unsignedp)
3622 return type;
3623
3624#define TYPE_OK(node) \
3625 (TYPE_MODE (type) == TYPE_MODE (node) \
3626 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
3627 if (TYPE_OK (signed_char_type_node))
3628 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
3629 if (TYPE_OK (integer_type_node))
3630 return unsignedp ? unsigned_type_node : integer_type_node;
3631 if (TYPE_OK (short_integer_type_node))
3632 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
3633 if (TYPE_OK (long_integer_type_node))
3634 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
3635 if (TYPE_OK (long_long_integer_type_node))
3636 return (unsignedp
3637 ? long_long_unsigned_type_node
3638 : long_long_integer_type_node);
a6766312
KT
3639 if (int128_integer_type_node && TYPE_OK (int128_integer_type_node))
3640 return (unsignedp
3641 ? int128_unsigned_type_node
3642 : int128_integer_type_node);
d7f09764
DN
3643
3644#if HOST_BITS_PER_WIDE_INT >= 64
3645 if (TYPE_OK (intTI_type_node))
3646 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
3647#endif
3648 if (TYPE_OK (intDI_type_node))
3649 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
3650 if (TYPE_OK (intSI_type_node))
3651 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
3652 if (TYPE_OK (intHI_type_node))
3653 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
3654 if (TYPE_OK (intQI_type_node))
3655 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
3656
3657#undef GIMPLE_FIXED_TYPES
3658#undef GIMPLE_FIXED_MODE_TYPES
3659#undef GIMPLE_FIXED_TYPES_SAT
3660#undef GIMPLE_FIXED_MODE_TYPES_SAT
3661#undef TYPE_OK
3662
3663 return build_nonstandard_integer_type (TYPE_PRECISION (type), unsignedp);
3664}
3665
3666
3667/* Return an unsigned type the same as TYPE in other respects. */
3668
3669tree
3670gimple_unsigned_type (tree type)
3671{
3672 return gimple_signed_or_unsigned_type (true, type);
3673}
3674
3675
3676/* Return a signed type the same as TYPE in other respects. */
3677
3678tree
3679gimple_signed_type (tree type)
3680{
3681 return gimple_signed_or_unsigned_type (false, type);
3682}
3683
3684
3685/* Return the typed-based alias set for T, which may be an expression
3686 or a type. Return -1 if we don't do anything special. */
3687
3688alias_set_type
3689gimple_get_alias_set (tree t)
3690{
3691 tree u;
3692
3693 /* Permit type-punning when accessing a union, provided the access
3694 is directly through the union. For example, this code does not
3695 permit taking the address of a union member and then storing
3696 through it. Even the type-punning allowed here is a GCC
3697 extension, albeit a common and useful one; the C standard says
3698 that such accesses have implementation-defined behavior. */
3699 for (u = t;
3700 TREE_CODE (u) == COMPONENT_REF || TREE_CODE (u) == ARRAY_REF;
3701 u = TREE_OPERAND (u, 0))
3702 if (TREE_CODE (u) == COMPONENT_REF
3703 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u, 0))) == UNION_TYPE)
3704 return 0;
3705
3706 /* That's all the expressions we handle specially. */
3707 if (!TYPE_P (t))
3708 return -1;
3709
3710 /* For convenience, follow the C standard when dealing with
3711 character types. Any object may be accessed via an lvalue that
3712 has character type. */
3713 if (t == char_type_node
3714 || t == signed_char_type_node
3715 || t == unsigned_char_type_node)
3716 return 0;
3717
3718 /* Allow aliasing between signed and unsigned variants of the same
3719 type. We treat the signed variant as canonical. */
3720 if (TREE_CODE (t) == INTEGER_TYPE && TYPE_UNSIGNED (t))
3721 {
3722 tree t1 = gimple_signed_type (t);
3723
3724 /* t1 == t can happen for boolean nodes which are always unsigned. */
3725 if (t1 != t)
3726 return get_alias_set (t1);
3727 }
d7f09764
DN
3728
3729 return -1;
3730}
3731
3732
5006671f
RG
3733/* Data structure used to count the number of dereferences to PTR
3734 inside an expression. */
3735struct count_ptr_d
3736{
3737 tree ptr;
3738 unsigned num_stores;
3739 unsigned num_loads;
3740};
3741
3742/* Helper for count_uses_and_derefs. Called by walk_tree to look for
3743 (ALIGN/MISALIGNED_)INDIRECT_REF nodes for the pointer passed in DATA. */
3744
3745static tree
3746count_ptr_derefs (tree *tp, int *walk_subtrees, void *data)
3747{
3748 struct walk_stmt_info *wi_p = (struct walk_stmt_info *) data;
3749 struct count_ptr_d *count_p = (struct count_ptr_d *) wi_p->info;
3750
3751 /* Do not walk inside ADDR_EXPR nodes. In the expression &ptr->fld,
3752 pointer 'ptr' is *not* dereferenced, it is simply used to compute
3753 the address of 'fld' as 'ptr + offsetof(fld)'. */
3754 if (TREE_CODE (*tp) == ADDR_EXPR)
3755 {
3756 *walk_subtrees = 0;
3757 return NULL_TREE;
3758 }
3759
70f34814 3760 if (TREE_CODE (*tp) == MEM_REF && TREE_OPERAND (*tp, 0) == count_p->ptr)
5006671f
RG
3761 {
3762 if (wi_p->is_lhs)
3763 count_p->num_stores++;
3764 else
3765 count_p->num_loads++;
3766 }
3767
3768 return NULL_TREE;
3769}
3770
3771/* Count the number of direct and indirect uses for pointer PTR in
3772 statement STMT. The number of direct uses is stored in
3773 *NUM_USES_P. Indirect references are counted separately depending
3774 on whether they are store or load operations. The counts are
3775 stored in *NUM_STORES_P and *NUM_LOADS_P. */
3776
3777void
3778count_uses_and_derefs (tree ptr, gimple stmt, unsigned *num_uses_p,
3779 unsigned *num_loads_p, unsigned *num_stores_p)
3780{
3781 ssa_op_iter i;
3782 tree use;
3783
3784 *num_uses_p = 0;
3785 *num_loads_p = 0;
3786 *num_stores_p = 0;
3787
3788 /* Find out the total number of uses of PTR in STMT. */
3789 FOR_EACH_SSA_TREE_OPERAND (use, stmt, i, SSA_OP_USE)
3790 if (use == ptr)
3791 (*num_uses_p)++;
3792
3793 /* Now count the number of indirect references to PTR. This is
3794 truly awful, but we don't have much choice. There are no parent
3795 pointers inside INDIRECT_REFs, so an expression like
3796 '*x_1 = foo (x_1, *x_1)' needs to be traversed piece by piece to
3797 find all the indirect and direct uses of x_1 inside. The only
3798 shortcut we can take is the fact that GIMPLE only allows
3799 INDIRECT_REFs inside the expressions below. */
3800 if (is_gimple_assign (stmt)
3801 || gimple_code (stmt) == GIMPLE_RETURN
3802 || gimple_code (stmt) == GIMPLE_ASM
3803 || is_gimple_call (stmt))
3804 {
3805 struct walk_stmt_info wi;
3806 struct count_ptr_d count;
3807
3808 count.ptr = ptr;
3809 count.num_stores = 0;
3810 count.num_loads = 0;
3811
3812 memset (&wi, 0, sizeof (wi));
3813 wi.info = &count;
3814 walk_gimple_op (stmt, count_ptr_derefs, &wi);
3815
3816 *num_stores_p = count.num_stores;
3817 *num_loads_p = count.num_loads;
3818 }
3819
3820 gcc_assert (*num_uses_p >= *num_loads_p + *num_stores_p);
3821}
3822
346ef3fa
RG
3823/* From a tree operand OP return the base of a load or store operation
3824 or NULL_TREE if OP is not a load or a store. */
3825
3826static tree
3827get_base_loadstore (tree op)
3828{
3829 while (handled_component_p (op))
3830 op = TREE_OPERAND (op, 0);
3831 if (DECL_P (op)
3832 || INDIRECT_REF_P (op)
70f34814 3833 || TREE_CODE (op) == MEM_REF
346ef3fa
RG
3834 || TREE_CODE (op) == TARGET_MEM_REF)
3835 return op;
3836 return NULL_TREE;
3837}
3838
3839/* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE and
3840 VISIT_ADDR if non-NULL on loads, store and address-taken operands
3841 passing the STMT, the base of the operand and DATA to it. The base
3842 will be either a decl, an indirect reference (including TARGET_MEM_REF)
3843 or the argument of an address expression.
3844 Returns the results of these callbacks or'ed. */
3845
3846bool
3847walk_stmt_load_store_addr_ops (gimple stmt, void *data,
3848 bool (*visit_load)(gimple, tree, void *),
3849 bool (*visit_store)(gimple, tree, void *),
3850 bool (*visit_addr)(gimple, tree, void *))
3851{
3852 bool ret = false;
3853 unsigned i;
3854 if (gimple_assign_single_p (stmt))
3855 {
3856 tree lhs, rhs;
3857 if (visit_store)
3858 {
3859 lhs = get_base_loadstore (gimple_assign_lhs (stmt));
3860 if (lhs)
3861 ret |= visit_store (stmt, lhs, data);
3862 }
3863 rhs = gimple_assign_rhs1 (stmt);
ad8a1ac0
RG
3864 while (handled_component_p (rhs))
3865 rhs = TREE_OPERAND (rhs, 0);
346ef3fa
RG
3866 if (visit_addr)
3867 {
3868 if (TREE_CODE (rhs) == ADDR_EXPR)
3869 ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), data);
3870 else if (TREE_CODE (rhs) == TARGET_MEM_REF
3871 && TREE_CODE (TMR_BASE (rhs)) == ADDR_EXPR)
3872 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (rhs), 0), data);
3873 else if (TREE_CODE (rhs) == OBJ_TYPE_REF
3874 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs)) == ADDR_EXPR)
3875 ret |= visit_addr (stmt, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs),
3876 0), data);
cb3d2e33
JJ
3877 else if (TREE_CODE (rhs) == CONSTRUCTOR)
3878 {
3879 unsigned int ix;
3880 tree val;
3881
3882 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (rhs), ix, val)
3883 if (TREE_CODE (val) == ADDR_EXPR)
3884 ret |= visit_addr (stmt, TREE_OPERAND (val, 0), data);
3885 else if (TREE_CODE (val) == OBJ_TYPE_REF
3886 && TREE_CODE (OBJ_TYPE_REF_OBJECT (val)) == ADDR_EXPR)
3887 ret |= visit_addr (stmt,
3888 TREE_OPERAND (OBJ_TYPE_REF_OBJECT (val),
3889 0), data);
3890 }
fff1894c
AB
3891 lhs = gimple_assign_lhs (stmt);
3892 if (TREE_CODE (lhs) == TARGET_MEM_REF
fff1894c
AB
3893 && TREE_CODE (TMR_BASE (lhs)) == ADDR_EXPR)
3894 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (lhs), 0), data);
346ef3fa
RG
3895 }
3896 if (visit_load)
3897 {
3898 rhs = get_base_loadstore (rhs);
3899 if (rhs)
3900 ret |= visit_load (stmt, rhs, data);
3901 }
3902 }
3903 else if (visit_addr
3904 && (is_gimple_assign (stmt)
4d7a65ea 3905 || gimple_code (stmt) == GIMPLE_COND))
346ef3fa
RG
3906 {
3907 for (i = 0; i < gimple_num_ops (stmt); ++i)
9dd58aa4
JJ
3908 {
3909 tree op = gimple_op (stmt, i);
3910 if (op == NULL_TREE)
3911 ;
3912 else if (TREE_CODE (op) == ADDR_EXPR)
3913 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
3914 /* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
3915 tree with two operands. */
3916 else if (i == 1 && COMPARISON_CLASS_P (op))
3917 {
3918 if (TREE_CODE (TREE_OPERAND (op, 0)) == ADDR_EXPR)
3919 ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 0),
3920 0), data);
3921 if (TREE_CODE (TREE_OPERAND (op, 1)) == ADDR_EXPR)
3922 ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 1),
3923 0), data);
3924 }
3925 }
346ef3fa
RG
3926 }
3927 else if (is_gimple_call (stmt))
3928 {
3929 if (visit_store)
3930 {
3931 tree lhs = gimple_call_lhs (stmt);
3932 if (lhs)
3933 {
3934 lhs = get_base_loadstore (lhs);
3935 if (lhs)
3936 ret |= visit_store (stmt, lhs, data);
3937 }
3938 }
3939 if (visit_load || visit_addr)
3940 for (i = 0; i < gimple_call_num_args (stmt); ++i)
3941 {
3942 tree rhs = gimple_call_arg (stmt, i);
3943 if (visit_addr
3944 && TREE_CODE (rhs) == ADDR_EXPR)
3945 ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), data);
3946 else if (visit_load)
3947 {
3948 rhs = get_base_loadstore (rhs);
3949 if (rhs)
3950 ret |= visit_load (stmt, rhs, data);
3951 }
3952 }
3953 if (visit_addr
3954 && gimple_call_chain (stmt)
3955 && TREE_CODE (gimple_call_chain (stmt)) == ADDR_EXPR)
3956 ret |= visit_addr (stmt, TREE_OPERAND (gimple_call_chain (stmt), 0),
3957 data);
1d24fdd9
RG
3958 if (visit_addr
3959 && gimple_call_return_slot_opt_p (stmt)
3960 && gimple_call_lhs (stmt) != NULL_TREE
4d61856d 3961 && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (stmt))))
1d24fdd9 3962 ret |= visit_addr (stmt, gimple_call_lhs (stmt), data);
346ef3fa
RG
3963 }
3964 else if (gimple_code (stmt) == GIMPLE_ASM)
3965 {
3966 unsigned noutputs;
3967 const char *constraint;
3968 const char **oconstraints;
3969 bool allows_mem, allows_reg, is_inout;
3970 noutputs = gimple_asm_noutputs (stmt);
3971 oconstraints = XALLOCAVEC (const char *, noutputs);
3972 if (visit_store || visit_addr)
3973 for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
3974 {
3975 tree link = gimple_asm_output_op (stmt, i);
3976 tree op = get_base_loadstore (TREE_VALUE (link));
3977 if (op && visit_store)
3978 ret |= visit_store (stmt, op, data);
3979 if (visit_addr)
3980 {
3981 constraint = TREE_STRING_POINTER
3982 (TREE_VALUE (TREE_PURPOSE (link)));
3983 oconstraints[i] = constraint;
3984 parse_output_constraint (&constraint, i, 0, 0, &allows_mem,
3985 &allows_reg, &is_inout);
3986 if (op && !allows_reg && allows_mem)
3987 ret |= visit_addr (stmt, op, data);
3988 }
3989 }
3990 if (visit_load || visit_addr)
3991 for (i = 0; i < gimple_asm_ninputs (stmt); ++i)
3992 {
3993 tree link = gimple_asm_input_op (stmt, i);
3994 tree op = TREE_VALUE (link);
3995 if (visit_addr
3996 && TREE_CODE (op) == ADDR_EXPR)
3997 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
3998 else if (visit_load || visit_addr)
3999 {
4000 op = get_base_loadstore (op);
4001 if (op)
4002 {
4003 if (visit_load)
4004 ret |= visit_load (stmt, op, data);
4005 if (visit_addr)
4006 {
4007 constraint = TREE_STRING_POINTER
4008 (TREE_VALUE (TREE_PURPOSE (link)));
4009 parse_input_constraint (&constraint, 0, 0, noutputs,
4010 0, oconstraints,
4011 &allows_mem, &allows_reg);
4012 if (!allows_reg && allows_mem)
4013 ret |= visit_addr (stmt, op, data);
4014 }
4015 }
4016 }
4017 }
4018 }
4019 else if (gimple_code (stmt) == GIMPLE_RETURN)
4020 {
4021 tree op = gimple_return_retval (stmt);
4022 if (op)
4023 {
4024 if (visit_addr
4025 && TREE_CODE (op) == ADDR_EXPR)
4026 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
4027 else if (visit_load)
4028 {
4029 op = get_base_loadstore (op);
4030 if (op)
4031 ret |= visit_load (stmt, op, data);
4032 }
4033 }
4034 }
4035 else if (visit_addr
4036 && gimple_code (stmt) == GIMPLE_PHI)
4037 {
4038 for (i = 0; i < gimple_phi_num_args (stmt); ++i)
4039 {
4040 tree op = PHI_ARG_DEF (stmt, i);
4041 if (TREE_CODE (op) == ADDR_EXPR)
4042 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
4043 }
4044 }
4045
4046 return ret;
4047}
4048
4049/* Like walk_stmt_load_store_addr_ops but with NULL visit_addr. IPA-CP
4050 should make a faster clone for this case. */
4051
4052bool
4053walk_stmt_load_store_ops (gimple stmt, void *data,
4054 bool (*visit_load)(gimple, tree, void *),
4055 bool (*visit_store)(gimple, tree, void *))
4056{
4057 return walk_stmt_load_store_addr_ops (stmt, data,
4058 visit_load, visit_store, NULL);
4059}
4060
ccacdf06
RG
4061/* Helper for gimple_ior_addresses_taken_1. */
4062
4063static bool
4064gimple_ior_addresses_taken_1 (gimple stmt ATTRIBUTE_UNUSED,
4065 tree addr, void *data)
4066{
4067 bitmap addresses_taken = (bitmap)data;
2ea9dc64
RG
4068 addr = get_base_address (addr);
4069 if (addr
4070 && DECL_P (addr))
ccacdf06
RG
4071 {
4072 bitmap_set_bit (addresses_taken, DECL_UID (addr));
4073 return true;
4074 }
4075 return false;
4076}
4077
4078/* Set the bit for the uid of all decls that have their address taken
4079 in STMT in the ADDRESSES_TAKEN bitmap. Returns true if there
4080 were any in this stmt. */
4081
4082bool
4083gimple_ior_addresses_taken (bitmap addresses_taken, gimple stmt)
4084{
4085 return walk_stmt_load_store_addr_ops (stmt, addresses_taken, NULL, NULL,
4086 gimple_ior_addresses_taken_1);
4087}
4088
4537ec0c
DN
4089
4090/* Return a printable name for symbol DECL. */
4091
4092const char *
4093gimple_decl_printable_name (tree decl, int verbosity)
4094{
98b2dfbb
RG
4095 if (!DECL_NAME (decl))
4096 return NULL;
4537ec0c
DN
4097
4098 if (DECL_ASSEMBLER_NAME_SET_P (decl))
4099 {
4100 const char *str, *mangled_str;
4101 int dmgl_opts = DMGL_NO_OPTS;
4102
4103 if (verbosity >= 2)
4104 {
4105 dmgl_opts = DMGL_VERBOSE
4537ec0c
DN
4106 | DMGL_ANSI
4107 | DMGL_GNU_V3
4108 | DMGL_RET_POSTFIX;
4109 if (TREE_CODE (decl) == FUNCTION_DECL)
4110 dmgl_opts |= DMGL_PARAMS;
4111 }
4112
4113 mangled_str = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4114 str = cplus_demangle_v3 (mangled_str, dmgl_opts);
4115 return (str) ? str : mangled_str;
4116 }
4117
4118 return IDENTIFIER_POINTER (DECL_NAME (decl));
4119}
4120
25ae5027
DS
4121/* Return TRUE iff stmt is a call to a built-in function. */
4122
4123bool
4124is_gimple_builtin_call (gimple stmt)
4125{
4126 tree callee;
4127
4128 if (is_gimple_call (stmt)
4129 && (callee = gimple_call_fndecl (stmt))
4130 && is_builtin_fn (callee)
4131 && DECL_BUILT_IN_CLASS (callee) == BUILT_IN_NORMAL)
4132 return true;
4133
4134 return false;
4135}
4136
3626621a
RB
4137/* Return true when STMTs arguments match those of FNDECL. */
4138
4139static bool
4140validate_call (gimple stmt, tree fndecl)
4141{
4142 tree targs = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
4143 unsigned nargs = gimple_call_num_args (stmt);
4144 for (unsigned i = 0; i < nargs; ++i)
4145 {
4146 /* Variadic args follow. */
4147 if (!targs)
4148 return true;
4149 tree arg = gimple_call_arg (stmt, i);
4150 if (INTEGRAL_TYPE_P (TREE_TYPE (arg))
4151 && INTEGRAL_TYPE_P (TREE_VALUE (targs)))
4152 ;
4153 else if (POINTER_TYPE_P (TREE_TYPE (arg))
4154 && POINTER_TYPE_P (TREE_VALUE (targs)))
4155 ;
4156 else if (TREE_CODE (TREE_TYPE (arg))
4157 != TREE_CODE (TREE_VALUE (targs)))
4158 return false;
4159 targs = TREE_CHAIN (targs);
4160 }
4161 if (targs && !VOID_TYPE_P (TREE_VALUE (targs)))
4162 return false;
4163 return true;
4164}
4165
4166/* Return true when STMT is builtins call to CLASS. */
4167
4168bool
4169gimple_call_builtin_p (gimple stmt, enum built_in_class klass)
4170{
4171 tree fndecl;
4172 if (is_gimple_call (stmt)
4173 && (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE
4174 && DECL_BUILT_IN_CLASS (fndecl) == klass)
4175 return validate_call (stmt, fndecl);
4176 return false;
4177}
4178
4179/* Return true when STMT is builtins call to CODE of CLASS. */
c54c785d
JH
4180
4181bool
4182gimple_call_builtin_p (gimple stmt, enum built_in_function code)
4183{
4184 tree fndecl;
3626621a
RB
4185 if (is_gimple_call (stmt)
4186 && (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE
4187 && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
4188 && DECL_FUNCTION_CODE (fndecl) == code)
4189 return validate_call (stmt, fndecl);
4190 return false;
c54c785d
JH
4191}
4192
edcdea5b
NF
4193/* Return true if STMT clobbers memory. STMT is required to be a
4194 GIMPLE_ASM. */
4195
4196bool
4197gimple_asm_clobbers_memory_p (const_gimple stmt)
4198{
4199 unsigned i;
4200
4201 for (i = 0; i < gimple_asm_nclobbers (stmt); i++)
4202 {
4203 tree op = gimple_asm_clobber_op (stmt, i);
4204 if (strcmp (TREE_STRING_POINTER (TREE_VALUE (op)), "memory") == 0)
4205 return true;
4206 }
4207
4208 return false;
4209}
726a989a 4210#include "gt-gimple.h"