]>
Commit | Line | Data |
---|---|---|
75a70cf9 | 1 | /* Gimple IR support functions. |
2 | ||
1eb1b33f | 3 | Copyright 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
75a70cf9 | 4 | Contributed by Aldy Hernandez <aldyh@redhat.com> |
5 | ||
6 | This file is part of GCC. | |
7 | ||
8 | GCC is free software; you can redistribute it and/or modify it under | |
9 | the terms of the GNU General Public License as published by the Free | |
10 | Software Foundation; either version 3, or (at your option) any later | |
11 | version. | |
12 | ||
13 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
14 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 | for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GCC; see the file COPYING3. If not see | |
20 | <http://www.gnu.org/licenses/>. */ | |
21 | ||
22 | #include "config.h" | |
23 | #include "system.h" | |
24 | #include "coretypes.h" | |
25 | #include "tm.h" | |
7bfefa9d | 26 | #include "target.h" |
75a70cf9 | 27 | #include "tree.h" |
28 | #include "ggc.h" | |
75a70cf9 | 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" | |
7bfefa9d | 36 | #include "alias.h" |
34e5cced | 37 | #include "demangle.h" |
7a52b640 | 38 | #include "langhooks.h" |
75a70cf9 | 39 | |
7bfefa9d | 40 | /* Global type table. FIXME lto, it should be possible to re-use some |
41 | of the type hashing routines in tree.c (type_hash_canon, type_hash_lookup, | |
42 | etc), but those assume that types were built with the various | |
43 | build_*_type routines which is not the case with the streamer. */ | |
7a52b640 | 44 | static GTY((if_marked ("ggc_marked_p"), param_is (union tree_node))) |
45 | htab_t gimple_types; | |
7a3ccc3b | 46 | static GTY((if_marked ("ggc_marked_p"), param_is (union tree_node))) |
47 | htab_t gimple_canonical_types; | |
7a52b640 | 48 | static GTY((if_marked ("tree_int_map_marked_p"), param_is (struct tree_int_map))) |
49 | htab_t type_hash_cache; | |
d1fb5d85 | 50 | static GTY((if_marked ("tree_int_map_marked_p"), param_is (struct tree_int_map))) |
51 | htab_t canonical_type_hash_cache; | |
7bfefa9d | 52 | |
1fed3255 | 53 | /* All the tuples have their operand vector (if present) at the very bottom |
75a70cf9 | 54 | of the structure. Therefore, the offset required to find the |
55 | operands vector the size of the structure minus the size of the 1 | |
56 | element tree array at the end (see gimple_ops). */ | |
1fed3255 | 57 | #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) \ |
58 | (HAS_TREE_OP ? sizeof (struct STRUCT) - sizeof (tree) : 0), | |
cd819d2f | 59 | EXPORTED_CONST size_t gimple_ops_offset_[] = { |
1fed3255 | 60 | #include "gsstruct.def" |
61 | }; | |
62 | #undef DEFGSSTRUCT | |
63 | ||
64 | #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) sizeof(struct STRUCT), | |
65 | static const size_t gsstruct_code_size[] = { | |
66 | #include "gsstruct.def" | |
67 | }; | |
68 | #undef DEFGSSTRUCT | |
69 | ||
70 | #define DEFGSCODE(SYM, NAME, GSSCODE) NAME, | |
71 | const char *const gimple_code_name[] = { | |
72 | #include "gimple.def" | |
73 | }; | |
74 | #undef DEFGSCODE | |
75 | ||
76 | #define DEFGSCODE(SYM, NAME, GSSCODE) GSSCODE, | |
77 | EXPORTED_CONST enum gimple_statement_structure_enum gss_for_code_[] = { | |
75a70cf9 | 78 | #include "gimple.def" |
79 | }; | |
80 | #undef DEFGSCODE | |
81 | ||
82 | #ifdef GATHER_STATISTICS | |
83 | /* Gimple stats. */ | |
84 | ||
85 | int gimple_alloc_counts[(int) gimple_alloc_kind_all]; | |
86 | int gimple_alloc_sizes[(int) gimple_alloc_kind_all]; | |
87 | ||
88 | /* Keep in sync with gimple.h:enum gimple_alloc_kind. */ | |
89 | static const char * const gimple_alloc_kind_names[] = { | |
90 | "assignments", | |
91 | "phi nodes", | |
92 | "conditionals", | |
93 | "sequences", | |
94 | "everything else" | |
95 | }; | |
96 | ||
97 | #endif /* GATHER_STATISTICS */ | |
98 | ||
99 | /* A cache of gimple_seq objects. Sequences are created and destroyed | |
100 | fairly often during gimplification. */ | |
101 | static GTY ((deletable)) struct gimple_seq_d *gimple_seq_cache; | |
102 | ||
103 | /* Private API manipulation functions shared only with some | |
104 | other files. */ | |
105 | extern void gimple_set_stored_syms (gimple, bitmap, bitmap_obstack *); | |
106 | extern void gimple_set_loaded_syms (gimple, bitmap, bitmap_obstack *); | |
107 | ||
108 | /* Gimple tuple constructors. | |
109 | Note: Any constructor taking a ``gimple_seq'' as a parameter, can | |
110 | be passed a NULL to start with an empty sequence. */ | |
111 | ||
112 | /* Set the code for statement G to CODE. */ | |
113 | ||
114 | static inline void | |
115 | gimple_set_code (gimple g, enum gimple_code code) | |
116 | { | |
117 | g->gsbase.code = code; | |
118 | } | |
119 | ||
75a70cf9 | 120 | /* Return the number of bytes needed to hold a GIMPLE statement with |
121 | code CODE. */ | |
122 | ||
1fed3255 | 123 | static inline size_t |
75a70cf9 | 124 | gimple_size (enum gimple_code code) |
125 | { | |
1fed3255 | 126 | return gsstruct_code_size[gss_for_code (code)]; |
75a70cf9 | 127 | } |
128 | ||
75a70cf9 | 129 | /* Allocate memory for a GIMPLE statement with code CODE and NUM_OPS |
130 | operands. */ | |
131 | ||
7bfefa9d | 132 | gimple |
75a70cf9 | 133 | gimple_alloc_stat (enum gimple_code code, unsigned num_ops MEM_STAT_DECL) |
134 | { | |
135 | size_t size; | |
136 | gimple stmt; | |
137 | ||
138 | size = gimple_size (code); | |
139 | if (num_ops > 0) | |
140 | size += sizeof (tree) * (num_ops - 1); | |
141 | ||
142 | #ifdef GATHER_STATISTICS | |
143 | { | |
144 | enum gimple_alloc_kind kind = gimple_alloc_kind (code); | |
145 | gimple_alloc_counts[(int) kind]++; | |
146 | gimple_alloc_sizes[(int) kind] += size; | |
147 | } | |
148 | #endif | |
149 | ||
ba72912a | 150 | stmt = ggc_alloc_cleared_gimple_statement_d_stat (size PASS_MEM_STAT); |
75a70cf9 | 151 | gimple_set_code (stmt, code); |
152 | gimple_set_num_ops (stmt, num_ops); | |
153 | ||
154 | /* Do not call gimple_set_modified here as it has other side | |
155 | effects and this tuple is still not completely built. */ | |
156 | stmt->gsbase.modified = 1; | |
157 | ||
158 | return stmt; | |
159 | } | |
160 | ||
161 | /* Set SUBCODE to be the code of the expression computed by statement G. */ | |
162 | ||
163 | static inline void | |
164 | gimple_set_subcode (gimple g, unsigned subcode) | |
165 | { | |
166 | /* We only have 16 bits for the RHS code. Assert that we are not | |
167 | overflowing it. */ | |
168 | gcc_assert (subcode < (1 << 16)); | |
169 | g->gsbase.subcode = subcode; | |
170 | } | |
171 | ||
172 | ||
173 | ||
174 | /* Build a tuple with operands. CODE is the statement to build (which | |
175 | must be one of the GIMPLE_WITH_OPS tuples). SUBCODE is the sub-code | |
48e1416a | 176 | for the new tuple. NUM_OPS is the number of operands to allocate. */ |
75a70cf9 | 177 | |
178 | #define gimple_build_with_ops(c, s, n) \ | |
179 | gimple_build_with_ops_stat (c, s, n MEM_STAT_INFO) | |
180 | ||
181 | static gimple | |
9845d120 | 182 | gimple_build_with_ops_stat (enum gimple_code code, unsigned subcode, |
75a70cf9 | 183 | unsigned num_ops MEM_STAT_DECL) |
184 | { | |
185 | gimple s = gimple_alloc_stat (code, num_ops PASS_MEM_STAT); | |
186 | gimple_set_subcode (s, subcode); | |
187 | ||
188 | return s; | |
189 | } | |
190 | ||
191 | ||
192 | /* Build a GIMPLE_RETURN statement returning RETVAL. */ | |
193 | ||
194 | gimple | |
195 | gimple_build_return (tree retval) | |
196 | { | |
b9c74b4d | 197 | gimple s = gimple_build_with_ops (GIMPLE_RETURN, ERROR_MARK, 1); |
75a70cf9 | 198 | if (retval) |
199 | gimple_return_set_retval (s, retval); | |
200 | return s; | |
201 | } | |
202 | ||
cb245216 | 203 | /* Reset alias information on call S. */ |
204 | ||
205 | void | |
206 | gimple_call_reset_alias_info (gimple s) | |
207 | { | |
208 | if (gimple_call_flags (s) & ECF_CONST) | |
209 | memset (gimple_call_use_set (s), 0, sizeof (struct pt_solution)); | |
210 | else | |
211 | pt_solution_reset (gimple_call_use_set (s)); | |
212 | if (gimple_call_flags (s) & (ECF_CONST|ECF_PURE|ECF_NOVOPS)) | |
213 | memset (gimple_call_clobber_set (s), 0, sizeof (struct pt_solution)); | |
214 | else | |
215 | pt_solution_reset (gimple_call_clobber_set (s)); | |
216 | } | |
217 | ||
75a70cf9 | 218 | /* Helper for gimple_build_call, gimple_build_call_vec and |
219 | gimple_build_call_from_tree. Build the basic components of a | |
220 | GIMPLE_CALL statement to function FN with NARGS arguments. */ | |
221 | ||
222 | static inline gimple | |
223 | gimple_build_call_1 (tree fn, unsigned nargs) | |
224 | { | |
b9c74b4d | 225 | gimple s = gimple_build_with_ops (GIMPLE_CALL, ERROR_MARK, nargs + 3); |
0acacf9e | 226 | if (TREE_CODE (fn) == FUNCTION_DECL) |
227 | fn = build_fold_addr_expr (fn); | |
75a70cf9 | 228 | gimple_set_op (s, 1, fn); |
39f59e65 | 229 | gimple_call_set_fntype (s, TREE_TYPE (TREE_TYPE (fn))); |
cb245216 | 230 | gimple_call_reset_alias_info (s); |
75a70cf9 | 231 | return s; |
232 | } | |
233 | ||
234 | ||
235 | /* Build a GIMPLE_CALL statement to function FN with the arguments | |
236 | specified in vector ARGS. */ | |
237 | ||
238 | gimple | |
239 | gimple_build_call_vec (tree fn, VEC(tree, heap) *args) | |
240 | { | |
241 | unsigned i; | |
242 | unsigned nargs = VEC_length (tree, args); | |
243 | gimple call = gimple_build_call_1 (fn, nargs); | |
244 | ||
245 | for (i = 0; i < nargs; i++) | |
246 | gimple_call_set_arg (call, i, VEC_index (tree, args, i)); | |
247 | ||
248 | return call; | |
249 | } | |
250 | ||
251 | ||
252 | /* Build a GIMPLE_CALL statement to function FN. NARGS is the number of | |
253 | arguments. The ... are the arguments. */ | |
254 | ||
255 | gimple | |
256 | gimple_build_call (tree fn, unsigned nargs, ...) | |
257 | { | |
258 | va_list ap; | |
259 | gimple call; | |
260 | unsigned i; | |
261 | ||
262 | gcc_assert (TREE_CODE (fn) == FUNCTION_DECL || is_gimple_call_addr (fn)); | |
263 | ||
264 | call = gimple_build_call_1 (fn, nargs); | |
265 | ||
266 | va_start (ap, nargs); | |
267 | for (i = 0; i < nargs; i++) | |
268 | gimple_call_set_arg (call, i, va_arg (ap, tree)); | |
269 | va_end (ap); | |
270 | ||
271 | return call; | |
272 | } | |
273 | ||
274 | ||
fb049fba | 275 | /* Helper for gimple_build_call_internal and gimple_build_call_internal_vec. |
276 | Build the basic components of a GIMPLE_CALL statement to internal | |
277 | function FN with NARGS arguments. */ | |
278 | ||
279 | static inline gimple | |
280 | gimple_build_call_internal_1 (enum internal_fn fn, unsigned nargs) | |
281 | { | |
282 | gimple s = gimple_build_with_ops (GIMPLE_CALL, ERROR_MARK, nargs + 3); | |
283 | s->gsbase.subcode |= GF_CALL_INTERNAL; | |
284 | gimple_call_set_internal_fn (s, fn); | |
285 | gimple_call_reset_alias_info (s); | |
286 | return s; | |
287 | } | |
288 | ||
289 | ||
290 | /* Build a GIMPLE_CALL statement to internal function FN. NARGS is | |
291 | the number of arguments. The ... are the arguments. */ | |
292 | ||
293 | gimple | |
294 | gimple_build_call_internal (enum internal_fn fn, unsigned nargs, ...) | |
295 | { | |
296 | va_list ap; | |
297 | gimple call; | |
298 | unsigned i; | |
299 | ||
300 | call = gimple_build_call_internal_1 (fn, nargs); | |
301 | va_start (ap, nargs); | |
302 | for (i = 0; i < nargs; i++) | |
303 | gimple_call_set_arg (call, i, va_arg (ap, tree)); | |
304 | va_end (ap); | |
305 | ||
306 | return call; | |
307 | } | |
308 | ||
309 | ||
310 | /* Build a GIMPLE_CALL statement to internal function FN with the arguments | |
311 | specified in vector ARGS. */ | |
312 | ||
313 | gimple | |
314 | gimple_build_call_internal_vec (enum internal_fn fn, VEC(tree, heap) *args) | |
315 | { | |
316 | unsigned i, nargs; | |
317 | gimple call; | |
318 | ||
319 | nargs = VEC_length (tree, args); | |
320 | call = gimple_build_call_internal_1 (fn, nargs); | |
321 | for (i = 0; i < nargs; i++) | |
322 | gimple_call_set_arg (call, i, VEC_index (tree, args, i)); | |
323 | ||
324 | return call; | |
325 | } | |
326 | ||
327 | ||
75a70cf9 | 328 | /* Build a GIMPLE_CALL statement from CALL_EXPR T. Note that T is |
329 | assumed to be in GIMPLE form already. Minimal checking is done of | |
330 | this fact. */ | |
331 | ||
332 | gimple | |
333 | gimple_build_call_from_tree (tree t) | |
334 | { | |
335 | unsigned i, nargs; | |
336 | gimple call; | |
337 | tree fndecl = get_callee_fndecl (t); | |
338 | ||
339 | gcc_assert (TREE_CODE (t) == CALL_EXPR); | |
340 | ||
341 | nargs = call_expr_nargs (t); | |
342 | call = gimple_build_call_1 (fndecl ? fndecl : CALL_EXPR_FN (t), nargs); | |
343 | ||
344 | for (i = 0; i < nargs; i++) | |
345 | gimple_call_set_arg (call, i, CALL_EXPR_ARG (t, i)); | |
346 | ||
347 | gimple_set_block (call, TREE_BLOCK (t)); | |
348 | ||
349 | /* Carry all the CALL_EXPR flags to the new GIMPLE_CALL. */ | |
350 | gimple_call_set_chain (call, CALL_EXPR_STATIC_CHAIN (t)); | |
351 | gimple_call_set_tail (call, CALL_EXPR_TAILCALL (t)); | |
352 | gimple_call_set_cannot_inline (call, CALL_CANNOT_INLINE_P (t)); | |
353 | gimple_call_set_return_slot_opt (call, CALL_EXPR_RETURN_SLOT_OPT (t)); | |
a882d754 | 354 | if (fndecl |
355 | && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL | |
356 | && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA) | |
357 | gimple_call_set_alloca_for_var (call, CALL_ALLOCA_FOR_VAR_P (t)); | |
358 | else | |
359 | gimple_call_set_from_thunk (call, CALL_FROM_THUNK_P (t)); | |
75a70cf9 | 360 | gimple_call_set_va_arg_pack (call, CALL_EXPR_VA_ARG_PACK (t)); |
1d3f675f | 361 | gimple_call_set_nothrow (call, TREE_NOTHROW (t)); |
e627cda1 | 362 | gimple_set_no_warning (call, TREE_NO_WARNING (t)); |
75a70cf9 | 363 | |
364 | return call; | |
365 | } | |
366 | ||
367 | ||
368 | /* Extract the operands and code for expression EXPR into *SUBCODE_P, | |
00f4f705 | 369 | *OP1_P, *OP2_P and *OP3_P respectively. */ |
75a70cf9 | 370 | |
371 | void | |
00f4f705 | 372 | extract_ops_from_tree_1 (tree expr, enum tree_code *subcode_p, tree *op1_p, |
373 | tree *op2_p, tree *op3_p) | |
75a70cf9 | 374 | { |
f4e36c33 | 375 | enum gimple_rhs_class grhs_class; |
75a70cf9 | 376 | |
377 | *subcode_p = TREE_CODE (expr); | |
f4e36c33 | 378 | grhs_class = get_gimple_rhs_class (*subcode_p); |
75a70cf9 | 379 | |
00f4f705 | 380 | if (grhs_class == GIMPLE_TERNARY_RHS) |
75a70cf9 | 381 | { |
382 | *op1_p = TREE_OPERAND (expr, 0); | |
383 | *op2_p = TREE_OPERAND (expr, 1); | |
00f4f705 | 384 | *op3_p = TREE_OPERAND (expr, 2); |
385 | } | |
386 | else if (grhs_class == GIMPLE_BINARY_RHS) | |
387 | { | |
388 | *op1_p = TREE_OPERAND (expr, 0); | |
389 | *op2_p = TREE_OPERAND (expr, 1); | |
390 | *op3_p = NULL_TREE; | |
75a70cf9 | 391 | } |
f4e36c33 | 392 | else if (grhs_class == GIMPLE_UNARY_RHS) |
75a70cf9 | 393 | { |
394 | *op1_p = TREE_OPERAND (expr, 0); | |
395 | *op2_p = NULL_TREE; | |
00f4f705 | 396 | *op3_p = NULL_TREE; |
75a70cf9 | 397 | } |
f4e36c33 | 398 | else if (grhs_class == GIMPLE_SINGLE_RHS) |
75a70cf9 | 399 | { |
400 | *op1_p = expr; | |
401 | *op2_p = NULL_TREE; | |
00f4f705 | 402 | *op3_p = NULL_TREE; |
75a70cf9 | 403 | } |
404 | else | |
405 | gcc_unreachable (); | |
406 | } | |
407 | ||
408 | ||
409 | /* Build a GIMPLE_ASSIGN statement. | |
410 | ||
411 | LHS of the assignment. | |
412 | RHS of the assignment which can be unary or binary. */ | |
413 | ||
414 | gimple | |
415 | gimple_build_assign_stat (tree lhs, tree rhs MEM_STAT_DECL) | |
416 | { | |
417 | enum tree_code subcode; | |
00f4f705 | 418 | tree op1, op2, op3; |
75a70cf9 | 419 | |
00f4f705 | 420 | extract_ops_from_tree_1 (rhs, &subcode, &op1, &op2, &op3); |
421 | return gimple_build_assign_with_ops_stat (subcode, lhs, op1, op2, op3 | |
75a70cf9 | 422 | PASS_MEM_STAT); |
423 | } | |
424 | ||
425 | ||
426 | /* Build a GIMPLE_ASSIGN statement with sub-code SUBCODE and operands | |
427 | OP1 and OP2. If OP2 is NULL then SUBCODE must be of class | |
428 | GIMPLE_UNARY_RHS or GIMPLE_SINGLE_RHS. */ | |
429 | ||
430 | gimple | |
431 | gimple_build_assign_with_ops_stat (enum tree_code subcode, tree lhs, tree op1, | |
00f4f705 | 432 | tree op2, tree op3 MEM_STAT_DECL) |
75a70cf9 | 433 | { |
434 | unsigned num_ops; | |
435 | gimple p; | |
436 | ||
437 | /* Need 1 operand for LHS and 1 or 2 for the RHS (depending on the | |
438 | code). */ | |
439 | num_ops = get_gimple_rhs_num_ops (subcode) + 1; | |
48e1416a | 440 | |
9845d120 | 441 | p = gimple_build_with_ops_stat (GIMPLE_ASSIGN, (unsigned)subcode, num_ops |
75a70cf9 | 442 | PASS_MEM_STAT); |
443 | gimple_assign_set_lhs (p, lhs); | |
444 | gimple_assign_set_rhs1 (p, op1); | |
445 | if (op2) | |
446 | { | |
447 | gcc_assert (num_ops > 2); | |
448 | gimple_assign_set_rhs2 (p, op2); | |
449 | } | |
450 | ||
00f4f705 | 451 | if (op3) |
452 | { | |
453 | gcc_assert (num_ops > 3); | |
454 | gimple_assign_set_rhs3 (p, op3); | |
455 | } | |
456 | ||
75a70cf9 | 457 | return p; |
458 | } | |
459 | ||
460 | ||
461 | /* Build a new GIMPLE_ASSIGN tuple and append it to the end of *SEQ_P. | |
462 | ||
463 | DST/SRC are the destination and source respectively. You can pass | |
464 | ungimplified trees in DST or SRC, in which case they will be | |
465 | converted to a gimple operand if necessary. | |
466 | ||
467 | This function returns the newly created GIMPLE_ASSIGN tuple. */ | |
468 | ||
c623bf22 | 469 | gimple |
75a70cf9 | 470 | gimplify_assign (tree dst, tree src, gimple_seq *seq_p) |
48e1416a | 471 | { |
75a70cf9 | 472 | tree t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src); |
473 | gimplify_and_add (t, seq_p); | |
474 | ggc_free (t); | |
475 | return gimple_seq_last_stmt (*seq_p); | |
476 | } | |
477 | ||
478 | ||
479 | /* Build a GIMPLE_COND statement. | |
480 | ||
481 | PRED is the condition used to compare LHS and the RHS. | |
482 | T_LABEL is the label to jump to if the condition is true. | |
483 | F_LABEL is the label to jump to otherwise. */ | |
484 | ||
485 | gimple | |
486 | gimple_build_cond (enum tree_code pred_code, tree lhs, tree rhs, | |
487 | tree t_label, tree f_label) | |
488 | { | |
489 | gimple p; | |
490 | ||
491 | gcc_assert (TREE_CODE_CLASS (pred_code) == tcc_comparison); | |
492 | p = gimple_build_with_ops (GIMPLE_COND, pred_code, 4); | |
493 | gimple_cond_set_lhs (p, lhs); | |
494 | gimple_cond_set_rhs (p, rhs); | |
495 | gimple_cond_set_true_label (p, t_label); | |
496 | gimple_cond_set_false_label (p, f_label); | |
497 | return p; | |
498 | } | |
499 | ||
500 | ||
501 | /* Extract operands for a GIMPLE_COND statement out of COND_EXPR tree COND. */ | |
502 | ||
503 | void | |
504 | gimple_cond_get_ops_from_tree (tree cond, enum tree_code *code_p, | |
505 | tree *lhs_p, tree *rhs_p) | |
506 | { | |
507 | gcc_assert (TREE_CODE_CLASS (TREE_CODE (cond)) == tcc_comparison | |
508 | || TREE_CODE (cond) == TRUTH_NOT_EXPR | |
509 | || is_gimple_min_invariant (cond) | |
510 | || SSA_VAR_P (cond)); | |
511 | ||
512 | extract_ops_from_tree (cond, code_p, lhs_p, rhs_p); | |
513 | ||
514 | /* Canonicalize conditionals of the form 'if (!VAL)'. */ | |
515 | if (*code_p == TRUTH_NOT_EXPR) | |
516 | { | |
517 | *code_p = EQ_EXPR; | |
518 | gcc_assert (*lhs_p && *rhs_p == NULL_TREE); | |
385f3f36 | 519 | *rhs_p = build_zero_cst (TREE_TYPE (*lhs_p)); |
75a70cf9 | 520 | } |
521 | /* Canonicalize conditionals of the form 'if (VAL)' */ | |
522 | else if (TREE_CODE_CLASS (*code_p) != tcc_comparison) | |
523 | { | |
524 | *code_p = NE_EXPR; | |
525 | gcc_assert (*lhs_p && *rhs_p == NULL_TREE); | |
385f3f36 | 526 | *rhs_p = build_zero_cst (TREE_TYPE (*lhs_p)); |
75a70cf9 | 527 | } |
528 | } | |
529 | ||
530 | ||
531 | /* Build a GIMPLE_COND statement from the conditional expression tree | |
532 | COND. T_LABEL and F_LABEL are as in gimple_build_cond. */ | |
533 | ||
534 | gimple | |
535 | gimple_build_cond_from_tree (tree cond, tree t_label, tree f_label) | |
536 | { | |
537 | enum tree_code code; | |
538 | tree lhs, rhs; | |
539 | ||
540 | gimple_cond_get_ops_from_tree (cond, &code, &lhs, &rhs); | |
541 | return gimple_build_cond (code, lhs, rhs, t_label, f_label); | |
542 | } | |
543 | ||
544 | /* Set code, lhs, and rhs of a GIMPLE_COND from a suitable | |
545 | boolean expression tree COND. */ | |
546 | ||
547 | void | |
548 | gimple_cond_set_condition_from_tree (gimple stmt, tree cond) | |
549 | { | |
550 | enum tree_code code; | |
551 | tree lhs, rhs; | |
552 | ||
553 | gimple_cond_get_ops_from_tree (cond, &code, &lhs, &rhs); | |
554 | gimple_cond_set_condition (stmt, code, lhs, rhs); | |
555 | } | |
556 | ||
557 | /* Build a GIMPLE_LABEL statement for LABEL. */ | |
558 | ||
559 | gimple | |
560 | gimple_build_label (tree label) | |
561 | { | |
b9c74b4d | 562 | gimple p = gimple_build_with_ops (GIMPLE_LABEL, ERROR_MARK, 1); |
75a70cf9 | 563 | gimple_label_set_label (p, label); |
564 | return p; | |
565 | } | |
566 | ||
567 | /* Build a GIMPLE_GOTO statement to label DEST. */ | |
568 | ||
569 | gimple | |
570 | gimple_build_goto (tree dest) | |
571 | { | |
b9c74b4d | 572 | gimple p = gimple_build_with_ops (GIMPLE_GOTO, ERROR_MARK, 1); |
75a70cf9 | 573 | gimple_goto_set_dest (p, dest); |
574 | return p; | |
575 | } | |
576 | ||
577 | ||
578 | /* Build a GIMPLE_NOP statement. */ | |
579 | ||
48e1416a | 580 | gimple |
75a70cf9 | 581 | gimple_build_nop (void) |
582 | { | |
583 | return gimple_alloc (GIMPLE_NOP, 0); | |
584 | } | |
585 | ||
586 | ||
587 | /* Build a GIMPLE_BIND statement. | |
588 | VARS are the variables in BODY. | |
589 | BLOCK is the containing block. */ | |
590 | ||
591 | gimple | |
592 | gimple_build_bind (tree vars, gimple_seq body, tree block) | |
593 | { | |
594 | gimple p = gimple_alloc (GIMPLE_BIND, 0); | |
595 | gimple_bind_set_vars (p, vars); | |
596 | if (body) | |
597 | gimple_bind_set_body (p, body); | |
598 | if (block) | |
599 | gimple_bind_set_block (p, block); | |
600 | return p; | |
601 | } | |
602 | ||
603 | /* Helper function to set the simple fields of a asm stmt. | |
604 | ||
605 | STRING is a pointer to a string that is the asm blocks assembly code. | |
606 | NINPUT is the number of register inputs. | |
607 | NOUTPUT is the number of register outputs. | |
608 | NCLOBBERS is the number of clobbered registers. | |
609 | */ | |
610 | ||
611 | static inline gimple | |
48e1416a | 612 | gimple_build_asm_1 (const char *string, unsigned ninputs, unsigned noutputs, |
78f55ca8 | 613 | unsigned nclobbers, unsigned nlabels) |
75a70cf9 | 614 | { |
615 | gimple p; | |
616 | int size = strlen (string); | |
617 | ||
78f55ca8 | 618 | /* ASMs with labels cannot have outputs. This should have been |
619 | enforced by the front end. */ | |
620 | gcc_assert (nlabels == 0 || noutputs == 0); | |
621 | ||
b9c74b4d | 622 | p = gimple_build_with_ops (GIMPLE_ASM, ERROR_MARK, |
78f55ca8 | 623 | ninputs + noutputs + nclobbers + nlabels); |
75a70cf9 | 624 | |
625 | p->gimple_asm.ni = ninputs; | |
626 | p->gimple_asm.no = noutputs; | |
627 | p->gimple_asm.nc = nclobbers; | |
78f55ca8 | 628 | p->gimple_asm.nl = nlabels; |
75a70cf9 | 629 | p->gimple_asm.string = ggc_alloc_string (string, size); |
630 | ||
631 | #ifdef GATHER_STATISTICS | |
632 | gimple_alloc_sizes[(int) gimple_alloc_kind (GIMPLE_ASM)] += size; | |
633 | #endif | |
48e1416a | 634 | |
75a70cf9 | 635 | return p; |
636 | } | |
637 | ||
638 | /* Build a GIMPLE_ASM statement. | |
639 | ||
640 | STRING is the assembly code. | |
641 | NINPUT is the number of register inputs. | |
642 | NOUTPUT is the number of register outputs. | |
643 | NCLOBBERS is the number of clobbered registers. | |
644 | INPUTS is a vector of the input register parameters. | |
645 | OUTPUTS is a vector of the output register parameters. | |
78f55ca8 | 646 | CLOBBERS is a vector of the clobbered register parameters. |
647 | LABELS is a vector of destination labels. */ | |
75a70cf9 | 648 | |
649 | gimple | |
48e1416a | 650 | gimple_build_asm_vec (const char *string, VEC(tree,gc)* inputs, |
78f55ca8 | 651 | VEC(tree,gc)* outputs, VEC(tree,gc)* clobbers, |
652 | VEC(tree,gc)* labels) | |
75a70cf9 | 653 | { |
654 | gimple p; | |
655 | unsigned i; | |
656 | ||
657 | p = gimple_build_asm_1 (string, | |
658 | VEC_length (tree, inputs), | |
48e1416a | 659 | VEC_length (tree, outputs), |
78f55ca8 | 660 | VEC_length (tree, clobbers), |
661 | VEC_length (tree, labels)); | |
48e1416a | 662 | |
75a70cf9 | 663 | for (i = 0; i < VEC_length (tree, inputs); i++) |
664 | gimple_asm_set_input_op (p, i, VEC_index (tree, inputs, i)); | |
665 | ||
666 | for (i = 0; i < VEC_length (tree, outputs); i++) | |
667 | gimple_asm_set_output_op (p, i, VEC_index (tree, outputs, i)); | |
668 | ||
669 | for (i = 0; i < VEC_length (tree, clobbers); i++) | |
670 | gimple_asm_set_clobber_op (p, i, VEC_index (tree, clobbers, i)); | |
48e1416a | 671 | |
78f55ca8 | 672 | for (i = 0; i < VEC_length (tree, labels); i++) |
673 | gimple_asm_set_label_op (p, i, VEC_index (tree, labels, i)); | |
48e1416a | 674 | |
75a70cf9 | 675 | return p; |
676 | } | |
677 | ||
678 | /* Build a GIMPLE_CATCH statement. | |
679 | ||
680 | TYPES are the catch types. | |
681 | HANDLER is the exception handler. */ | |
682 | ||
683 | gimple | |
684 | gimple_build_catch (tree types, gimple_seq handler) | |
685 | { | |
686 | gimple p = gimple_alloc (GIMPLE_CATCH, 0); | |
687 | gimple_catch_set_types (p, types); | |
688 | if (handler) | |
689 | gimple_catch_set_handler (p, handler); | |
690 | ||
691 | return p; | |
692 | } | |
693 | ||
694 | /* Build a GIMPLE_EH_FILTER statement. | |
695 | ||
696 | TYPES are the filter's types. | |
697 | FAILURE is the filter's failure action. */ | |
698 | ||
699 | gimple | |
700 | gimple_build_eh_filter (tree types, gimple_seq failure) | |
701 | { | |
702 | gimple p = gimple_alloc (GIMPLE_EH_FILTER, 0); | |
703 | gimple_eh_filter_set_types (p, types); | |
704 | if (failure) | |
705 | gimple_eh_filter_set_failure (p, failure); | |
706 | ||
707 | return p; | |
708 | } | |
709 | ||
e38def9c | 710 | /* Build a GIMPLE_EH_MUST_NOT_THROW statement. */ |
711 | ||
712 | gimple | |
713 | gimple_build_eh_must_not_throw (tree decl) | |
714 | { | |
73bb17ce | 715 | gimple p = gimple_alloc (GIMPLE_EH_MUST_NOT_THROW, 0); |
e38def9c | 716 | |
717 | gcc_assert (TREE_CODE (decl) == FUNCTION_DECL); | |
718 | gcc_assert (flags_from_decl_or_type (decl) & ECF_NORETURN); | |
7bfefa9d | 719 | gimple_eh_must_not_throw_set_fndecl (p, decl); |
e38def9c | 720 | |
721 | return p; | |
722 | } | |
723 | ||
75a70cf9 | 724 | /* Build a GIMPLE_TRY statement. |
725 | ||
726 | EVAL is the expression to evaluate. | |
727 | CLEANUP is the cleanup expression. | |
728 | KIND is either GIMPLE_TRY_CATCH or GIMPLE_TRY_FINALLY depending on | |
729 | whether this is a try/catch or a try/finally respectively. */ | |
730 | ||
731 | gimple | |
732 | gimple_build_try (gimple_seq eval, gimple_seq cleanup, | |
733 | enum gimple_try_flags kind) | |
734 | { | |
735 | gimple p; | |
736 | ||
737 | gcc_assert (kind == GIMPLE_TRY_CATCH || kind == GIMPLE_TRY_FINALLY); | |
738 | p = gimple_alloc (GIMPLE_TRY, 0); | |
739 | gimple_set_subcode (p, kind); | |
740 | if (eval) | |
741 | gimple_try_set_eval (p, eval); | |
742 | if (cleanup) | |
743 | gimple_try_set_cleanup (p, cleanup); | |
744 | ||
745 | return p; | |
746 | } | |
747 | ||
748 | /* Construct a GIMPLE_WITH_CLEANUP_EXPR statement. | |
749 | ||
750 | CLEANUP is the cleanup expression. */ | |
751 | ||
752 | gimple | |
753 | gimple_build_wce (gimple_seq cleanup) | |
754 | { | |
755 | gimple p = gimple_alloc (GIMPLE_WITH_CLEANUP_EXPR, 0); | |
756 | if (cleanup) | |
757 | gimple_wce_set_cleanup (p, cleanup); | |
758 | ||
759 | return p; | |
760 | } | |
761 | ||
762 | ||
e38def9c | 763 | /* Build a GIMPLE_RESX statement. */ |
75a70cf9 | 764 | |
765 | gimple | |
766 | gimple_build_resx (int region) | |
767 | { | |
e38def9c | 768 | gimple p = gimple_build_with_ops (GIMPLE_RESX, ERROR_MARK, 0); |
769 | p->gimple_eh_ctrl.region = region; | |
75a70cf9 | 770 | return p; |
771 | } | |
772 | ||
773 | ||
774 | /* The helper for constructing a gimple switch statement. | |
775 | INDEX is the switch's index. | |
776 | NLABELS is the number of labels in the switch excluding the default. | |
777 | DEFAULT_LABEL is the default label for the switch statement. */ | |
778 | ||
48e1416a | 779 | gimple |
e38def9c | 780 | gimple_build_switch_nlabels (unsigned nlabels, tree index, tree default_label) |
75a70cf9 | 781 | { |
782 | /* nlabels + 1 default label + 1 index. */ | |
b9c74b4d | 783 | gimple p = gimple_build_with_ops (GIMPLE_SWITCH, ERROR_MARK, |
e38def9c | 784 | 1 + (default_label != NULL) + nlabels); |
75a70cf9 | 785 | gimple_switch_set_index (p, index); |
e38def9c | 786 | if (default_label) |
787 | gimple_switch_set_default_label (p, default_label); | |
75a70cf9 | 788 | return p; |
789 | } | |
790 | ||
791 | ||
792 | /* Build a GIMPLE_SWITCH statement. | |
793 | ||
794 | INDEX is the switch's index. | |
48e1416a | 795 | NLABELS is the number of labels in the switch excluding the DEFAULT_LABEL. |
75a70cf9 | 796 | ... are the labels excluding the default. */ |
797 | ||
48e1416a | 798 | gimple |
75a70cf9 | 799 | gimple_build_switch (unsigned nlabels, tree index, tree default_label, ...) |
800 | { | |
801 | va_list al; | |
e38def9c | 802 | unsigned i, offset; |
803 | gimple p = gimple_build_switch_nlabels (nlabels, index, default_label); | |
75a70cf9 | 804 | |
805 | /* Store the rest of the labels. */ | |
806 | va_start (al, default_label); | |
e38def9c | 807 | offset = (default_label != NULL); |
808 | for (i = 0; i < nlabels; i++) | |
809 | gimple_switch_set_label (p, i + offset, va_arg (al, tree)); | |
75a70cf9 | 810 | va_end (al); |
811 | ||
812 | return p; | |
813 | } | |
814 | ||
815 | ||
816 | /* Build a GIMPLE_SWITCH statement. | |
817 | ||
818 | INDEX is the switch's index. | |
819 | DEFAULT_LABEL is the default label | |
820 | ARGS is a vector of labels excluding the default. */ | |
821 | ||
822 | gimple | |
823 | gimple_build_switch_vec (tree index, tree default_label, VEC(tree, heap) *args) | |
824 | { | |
e38def9c | 825 | unsigned i, offset, nlabels = VEC_length (tree, args); |
826 | gimple p = gimple_build_switch_nlabels (nlabels, index, default_label); | |
75a70cf9 | 827 | |
e38def9c | 828 | /* Copy the labels from the vector to the switch statement. */ |
829 | offset = (default_label != NULL); | |
830 | for (i = 0; i < nlabels; i++) | |
831 | gimple_switch_set_label (p, i + offset, VEC_index (tree, args, i)); | |
75a70cf9 | 832 | |
833 | return p; | |
834 | } | |
835 | ||
e38def9c | 836 | /* Build a GIMPLE_EH_DISPATCH statement. */ |
837 | ||
838 | gimple | |
839 | gimple_build_eh_dispatch (int region) | |
840 | { | |
841 | gimple p = gimple_build_with_ops (GIMPLE_EH_DISPATCH, ERROR_MARK, 0); | |
842 | p->gimple_eh_ctrl.region = region; | |
843 | return p; | |
844 | } | |
75a70cf9 | 845 | |
9845d120 | 846 | /* Build a new GIMPLE_DEBUG_BIND statement. |
847 | ||
848 | VAR is bound to VALUE; block and location are taken from STMT. */ | |
849 | ||
850 | gimple | |
851 | gimple_build_debug_bind_stat (tree var, tree value, gimple stmt MEM_STAT_DECL) | |
852 | { | |
853 | gimple p = gimple_build_with_ops_stat (GIMPLE_DEBUG, | |
854 | (unsigned)GIMPLE_DEBUG_BIND, 2 | |
855 | PASS_MEM_STAT); | |
856 | ||
857 | gimple_debug_bind_set_var (p, var); | |
858 | gimple_debug_bind_set_value (p, value); | |
859 | if (stmt) | |
860 | { | |
861 | gimple_set_block (p, gimple_block (stmt)); | |
862 | gimple_set_location (p, gimple_location (stmt)); | |
863 | } | |
864 | ||
865 | return p; | |
866 | } | |
867 | ||
868 | ||
75a70cf9 | 869 | /* Build a GIMPLE_OMP_CRITICAL statement. |
870 | ||
871 | BODY is the sequence of statements for which only one thread can execute. | |
872 | NAME is optional identifier for this critical block. */ | |
873 | ||
48e1416a | 874 | gimple |
75a70cf9 | 875 | gimple_build_omp_critical (gimple_seq body, tree name) |
876 | { | |
877 | gimple p = gimple_alloc (GIMPLE_OMP_CRITICAL, 0); | |
878 | gimple_omp_critical_set_name (p, name); | |
879 | if (body) | |
880 | gimple_omp_set_body (p, body); | |
881 | ||
882 | return p; | |
883 | } | |
884 | ||
885 | /* Build a GIMPLE_OMP_FOR statement. | |
886 | ||
887 | BODY is sequence of statements inside the for loop. | |
48e1416a | 888 | CLAUSES, are any of the OMP loop construct's clauses: private, firstprivate, |
75a70cf9 | 889 | lastprivate, reductions, ordered, schedule, and nowait. |
890 | COLLAPSE is the collapse count. | |
891 | PRE_BODY is the sequence of statements that are loop invariant. */ | |
892 | ||
893 | gimple | |
894 | gimple_build_omp_for (gimple_seq body, tree clauses, size_t collapse, | |
895 | gimple_seq pre_body) | |
896 | { | |
897 | gimple p = gimple_alloc (GIMPLE_OMP_FOR, 0); | |
898 | if (body) | |
899 | gimple_omp_set_body (p, body); | |
900 | gimple_omp_for_set_clauses (p, clauses); | |
901 | p->gimple_omp_for.collapse = collapse; | |
ba72912a | 902 | p->gimple_omp_for.iter |
903 | = ggc_alloc_cleared_vec_gimple_omp_for_iter (collapse); | |
75a70cf9 | 904 | if (pre_body) |
905 | gimple_omp_for_set_pre_body (p, pre_body); | |
906 | ||
907 | return p; | |
908 | } | |
909 | ||
910 | ||
911 | /* Build a GIMPLE_OMP_PARALLEL statement. | |
912 | ||
913 | BODY is sequence of statements which are executed in parallel. | |
914 | CLAUSES, are the OMP parallel construct's clauses. | |
915 | CHILD_FN is the function created for the parallel threads to execute. | |
916 | DATA_ARG are the shared data argument(s). */ | |
917 | ||
48e1416a | 918 | gimple |
919 | gimple_build_omp_parallel (gimple_seq body, tree clauses, tree child_fn, | |
75a70cf9 | 920 | tree data_arg) |
921 | { | |
922 | gimple p = gimple_alloc (GIMPLE_OMP_PARALLEL, 0); | |
923 | if (body) | |
924 | gimple_omp_set_body (p, body); | |
925 | gimple_omp_parallel_set_clauses (p, clauses); | |
926 | gimple_omp_parallel_set_child_fn (p, child_fn); | |
927 | gimple_omp_parallel_set_data_arg (p, data_arg); | |
928 | ||
929 | return p; | |
930 | } | |
931 | ||
932 | ||
933 | /* Build a GIMPLE_OMP_TASK statement. | |
934 | ||
935 | BODY is sequence of statements which are executed by the explicit task. | |
936 | CLAUSES, are the OMP parallel construct's clauses. | |
937 | CHILD_FN is the function created for the parallel threads to execute. | |
938 | DATA_ARG are the shared data argument(s). | |
939 | COPY_FN is the optional function for firstprivate initialization. | |
940 | ARG_SIZE and ARG_ALIGN are size and alignment of the data block. */ | |
941 | ||
48e1416a | 942 | gimple |
75a70cf9 | 943 | gimple_build_omp_task (gimple_seq body, tree clauses, tree child_fn, |
944 | tree data_arg, tree copy_fn, tree arg_size, | |
945 | tree arg_align) | |
946 | { | |
947 | gimple p = gimple_alloc (GIMPLE_OMP_TASK, 0); | |
948 | if (body) | |
949 | gimple_omp_set_body (p, body); | |
950 | gimple_omp_task_set_clauses (p, clauses); | |
951 | gimple_omp_task_set_child_fn (p, child_fn); | |
952 | gimple_omp_task_set_data_arg (p, data_arg); | |
953 | gimple_omp_task_set_copy_fn (p, copy_fn); | |
954 | gimple_omp_task_set_arg_size (p, arg_size); | |
955 | gimple_omp_task_set_arg_align (p, arg_align); | |
956 | ||
957 | return p; | |
958 | } | |
959 | ||
960 | ||
961 | /* Build a GIMPLE_OMP_SECTION statement for a sections statement. | |
962 | ||
963 | BODY is the sequence of statements in the section. */ | |
964 | ||
965 | gimple | |
966 | gimple_build_omp_section (gimple_seq body) | |
967 | { | |
968 | gimple p = gimple_alloc (GIMPLE_OMP_SECTION, 0); | |
969 | if (body) | |
970 | gimple_omp_set_body (p, body); | |
971 | ||
972 | return p; | |
973 | } | |
974 | ||
975 | ||
976 | /* Build a GIMPLE_OMP_MASTER statement. | |
977 | ||
978 | BODY is the sequence of statements to be executed by just the master. */ | |
979 | ||
48e1416a | 980 | gimple |
75a70cf9 | 981 | gimple_build_omp_master (gimple_seq body) |
982 | { | |
983 | gimple p = gimple_alloc (GIMPLE_OMP_MASTER, 0); | |
984 | if (body) | |
985 | gimple_omp_set_body (p, body); | |
986 | ||
987 | return p; | |
988 | } | |
989 | ||
990 | ||
991 | /* Build a GIMPLE_OMP_CONTINUE statement. | |
992 | ||
993 | CONTROL_DEF is the definition of the control variable. | |
994 | CONTROL_USE is the use of the control variable. */ | |
995 | ||
48e1416a | 996 | gimple |
75a70cf9 | 997 | gimple_build_omp_continue (tree control_def, tree control_use) |
998 | { | |
999 | gimple p = gimple_alloc (GIMPLE_OMP_CONTINUE, 0); | |
1000 | gimple_omp_continue_set_control_def (p, control_def); | |
1001 | gimple_omp_continue_set_control_use (p, control_use); | |
1002 | return p; | |
1003 | } | |
1004 | ||
1005 | /* Build a GIMPLE_OMP_ORDERED statement. | |
1006 | ||
1007 | BODY is the sequence of statements inside a loop that will executed in | |
1008 | sequence. */ | |
1009 | ||
48e1416a | 1010 | gimple |
75a70cf9 | 1011 | gimple_build_omp_ordered (gimple_seq body) |
1012 | { | |
1013 | gimple p = gimple_alloc (GIMPLE_OMP_ORDERED, 0); | |
1014 | if (body) | |
1015 | gimple_omp_set_body (p, body); | |
1016 | ||
1017 | return p; | |
1018 | } | |
1019 | ||
1020 | ||
1021 | /* Build a GIMPLE_OMP_RETURN statement. | |
1022 | WAIT_P is true if this is a non-waiting return. */ | |
1023 | ||
48e1416a | 1024 | gimple |
75a70cf9 | 1025 | gimple_build_omp_return (bool wait_p) |
1026 | { | |
1027 | gimple p = gimple_alloc (GIMPLE_OMP_RETURN, 0); | |
1028 | if (wait_p) | |
1029 | gimple_omp_return_set_nowait (p); | |
1030 | ||
1031 | return p; | |
1032 | } | |
1033 | ||
1034 | ||
1035 | /* Build a GIMPLE_OMP_SECTIONS statement. | |
1036 | ||
1037 | BODY is a sequence of section statements. | |
1038 | CLAUSES are any of the OMP sections contsruct's clauses: private, | |
1039 | firstprivate, lastprivate, reduction, and nowait. */ | |
1040 | ||
48e1416a | 1041 | gimple |
75a70cf9 | 1042 | gimple_build_omp_sections (gimple_seq body, tree clauses) |
1043 | { | |
1044 | gimple p = gimple_alloc (GIMPLE_OMP_SECTIONS, 0); | |
1045 | if (body) | |
1046 | gimple_omp_set_body (p, body); | |
1047 | gimple_omp_sections_set_clauses (p, clauses); | |
1048 | ||
1049 | return p; | |
1050 | } | |
1051 | ||
1052 | ||
1053 | /* Build a GIMPLE_OMP_SECTIONS_SWITCH. */ | |
1054 | ||
1055 | gimple | |
1056 | gimple_build_omp_sections_switch (void) | |
1057 | { | |
1058 | return gimple_alloc (GIMPLE_OMP_SECTIONS_SWITCH, 0); | |
1059 | } | |
1060 | ||
1061 | ||
1062 | /* Build a GIMPLE_OMP_SINGLE statement. | |
1063 | ||
1064 | BODY is the sequence of statements that will be executed once. | |
1065 | CLAUSES are any of the OMP single construct's clauses: private, firstprivate, | |
1066 | copyprivate, nowait. */ | |
1067 | ||
48e1416a | 1068 | gimple |
75a70cf9 | 1069 | gimple_build_omp_single (gimple_seq body, tree clauses) |
1070 | { | |
1071 | gimple p = gimple_alloc (GIMPLE_OMP_SINGLE, 0); | |
1072 | if (body) | |
1073 | gimple_omp_set_body (p, body); | |
1074 | gimple_omp_single_set_clauses (p, clauses); | |
1075 | ||
1076 | return p; | |
1077 | } | |
1078 | ||
1079 | ||
75a70cf9 | 1080 | /* Build a GIMPLE_OMP_ATOMIC_LOAD statement. */ |
1081 | ||
1082 | gimple | |
1083 | gimple_build_omp_atomic_load (tree lhs, tree rhs) | |
1084 | { | |
1085 | gimple p = gimple_alloc (GIMPLE_OMP_ATOMIC_LOAD, 0); | |
1086 | gimple_omp_atomic_load_set_lhs (p, lhs); | |
1087 | gimple_omp_atomic_load_set_rhs (p, rhs); | |
1088 | return p; | |
1089 | } | |
1090 | ||
1091 | /* Build a GIMPLE_OMP_ATOMIC_STORE statement. | |
1092 | ||
1093 | VAL is the value we are storing. */ | |
1094 | ||
1095 | gimple | |
1096 | gimple_build_omp_atomic_store (tree val) | |
1097 | { | |
1098 | gimple p = gimple_alloc (GIMPLE_OMP_ATOMIC_STORE, 0); | |
1099 | gimple_omp_atomic_store_set_val (p, val); | |
1100 | return p; | |
1101 | } | |
1102 | ||
1103 | /* Build a GIMPLE_PREDICT statement. PREDICT is one of the predictors from | |
1104 | predict.def, OUTCOME is NOT_TAKEN or TAKEN. */ | |
1105 | ||
1106 | gimple | |
1107 | gimple_build_predict (enum br_predictor predictor, enum prediction outcome) | |
1108 | { | |
1109 | gimple p = gimple_alloc (GIMPLE_PREDICT, 0); | |
1110 | /* Ensure all the predictors fit into the lower bits of the subcode. */ | |
590c3166 | 1111 | gcc_assert ((int) END_PREDICTORS <= GF_PREDICT_TAKEN); |
75a70cf9 | 1112 | gimple_predict_set_predictor (p, predictor); |
1113 | gimple_predict_set_outcome (p, outcome); | |
1114 | return p; | |
1115 | } | |
1116 | ||
384dcddb | 1117 | #if defined ENABLE_GIMPLE_CHECKING |
75a70cf9 | 1118 | /* Complain of a gimple type mismatch and die. */ |
1119 | ||
1120 | void | |
1121 | gimple_check_failed (const_gimple gs, const char *file, int line, | |
1122 | const char *function, enum gimple_code code, | |
1123 | enum tree_code subcode) | |
1124 | { | |
1125 | internal_error ("gimple check: expected %s(%s), have %s(%s) in %s, at %s:%d", | |
1126 | gimple_code_name[code], | |
1127 | tree_code_name[subcode], | |
1128 | gimple_code_name[gimple_code (gs)], | |
1129 | gs->gsbase.subcode > 0 | |
1130 | ? tree_code_name[gs->gsbase.subcode] | |
1131 | : "", | |
1132 | function, trim_filename (file), line); | |
1133 | } | |
75a70cf9 | 1134 | #endif /* ENABLE_GIMPLE_CHECKING */ |
1135 | ||
1136 | ||
1137 | /* Allocate a new GIMPLE sequence in GC memory and return it. If | |
1138 | there are free sequences in GIMPLE_SEQ_CACHE return one of those | |
1139 | instead. */ | |
1140 | ||
1141 | gimple_seq | |
1142 | gimple_seq_alloc (void) | |
1143 | { | |
1144 | gimple_seq seq = gimple_seq_cache; | |
1145 | if (seq) | |
1146 | { | |
1147 | gimple_seq_cache = gimple_seq_cache->next_free; | |
1148 | gcc_assert (gimple_seq_cache != seq); | |
1149 | memset (seq, 0, sizeof (*seq)); | |
1150 | } | |
1151 | else | |
1152 | { | |
ba72912a | 1153 | seq = ggc_alloc_cleared_gimple_seq_d (); |
75a70cf9 | 1154 | #ifdef GATHER_STATISTICS |
1155 | gimple_alloc_counts[(int) gimple_alloc_kind_seq]++; | |
1156 | gimple_alloc_sizes[(int) gimple_alloc_kind_seq] += sizeof (*seq); | |
1157 | #endif | |
1158 | } | |
1159 | ||
1160 | return seq; | |
1161 | } | |
1162 | ||
1163 | /* Return SEQ to the free pool of GIMPLE sequences. */ | |
1164 | ||
1165 | void | |
1166 | gimple_seq_free (gimple_seq seq) | |
1167 | { | |
1168 | if (seq == NULL) | |
1169 | return; | |
1170 | ||
1171 | gcc_assert (gimple_seq_first (seq) == NULL); | |
1172 | gcc_assert (gimple_seq_last (seq) == NULL); | |
1173 | ||
1174 | /* If this triggers, it's a sign that the same list is being freed | |
1175 | twice. */ | |
1176 | gcc_assert (seq != gimple_seq_cache || gimple_seq_cache == NULL); | |
48e1416a | 1177 | |
75a70cf9 | 1178 | /* Add SEQ to the pool of free sequences. */ |
1179 | seq->next_free = gimple_seq_cache; | |
1180 | gimple_seq_cache = seq; | |
1181 | } | |
1182 | ||
1183 | ||
1184 | /* Link gimple statement GS to the end of the sequence *SEQ_P. If | |
1185 | *SEQ_P is NULL, a new sequence is allocated. */ | |
1186 | ||
1187 | void | |
1188 | gimple_seq_add_stmt (gimple_seq *seq_p, gimple gs) | |
1189 | { | |
1190 | gimple_stmt_iterator si; | |
1191 | ||
1192 | if (gs == NULL) | |
1193 | return; | |
1194 | ||
1195 | if (*seq_p == NULL) | |
1196 | *seq_p = gimple_seq_alloc (); | |
1197 | ||
1198 | si = gsi_last (*seq_p); | |
1199 | gsi_insert_after (&si, gs, GSI_NEW_STMT); | |
1200 | } | |
1201 | ||
1202 | ||
1203 | /* Append sequence SRC to the end of sequence *DST_P. If *DST_P is | |
1204 | NULL, a new sequence is allocated. */ | |
1205 | ||
1206 | void | |
1207 | gimple_seq_add_seq (gimple_seq *dst_p, gimple_seq src) | |
1208 | { | |
1209 | gimple_stmt_iterator si; | |
1210 | ||
1211 | if (src == NULL) | |
1212 | return; | |
1213 | ||
1214 | if (*dst_p == NULL) | |
1215 | *dst_p = gimple_seq_alloc (); | |
1216 | ||
1217 | si = gsi_last (*dst_p); | |
1218 | gsi_insert_seq_after (&si, src, GSI_NEW_STMT); | |
1219 | } | |
1220 | ||
1221 | ||
1222 | /* Helper function of empty_body_p. Return true if STMT is an empty | |
1223 | statement. */ | |
1224 | ||
1225 | static bool | |
1226 | empty_stmt_p (gimple stmt) | |
1227 | { | |
1228 | if (gimple_code (stmt) == GIMPLE_NOP) | |
1229 | return true; | |
1230 | if (gimple_code (stmt) == GIMPLE_BIND) | |
1231 | return empty_body_p (gimple_bind_body (stmt)); | |
1232 | return false; | |
1233 | } | |
1234 | ||
1235 | ||
1236 | /* Return true if BODY contains nothing but empty statements. */ | |
1237 | ||
1238 | bool | |
1239 | empty_body_p (gimple_seq body) | |
1240 | { | |
1241 | gimple_stmt_iterator i; | |
1242 | ||
75a70cf9 | 1243 | if (gimple_seq_empty_p (body)) |
1244 | return true; | |
1245 | for (i = gsi_start (body); !gsi_end_p (i); gsi_next (&i)) | |
9845d120 | 1246 | if (!empty_stmt_p (gsi_stmt (i)) |
1247 | && !is_gimple_debug (gsi_stmt (i))) | |
75a70cf9 | 1248 | return false; |
1249 | ||
1250 | return true; | |
1251 | } | |
1252 | ||
1253 | ||
1254 | /* Perform a deep copy of sequence SRC and return the result. */ | |
1255 | ||
1256 | gimple_seq | |
1257 | gimple_seq_copy (gimple_seq src) | |
1258 | { | |
1259 | gimple_stmt_iterator gsi; | |
f4e36c33 | 1260 | gimple_seq new_seq = gimple_seq_alloc (); |
75a70cf9 | 1261 | gimple stmt; |
1262 | ||
1263 | for (gsi = gsi_start (src); !gsi_end_p (gsi); gsi_next (&gsi)) | |
1264 | { | |
1265 | stmt = gimple_copy (gsi_stmt (gsi)); | |
f4e36c33 | 1266 | gimple_seq_add_stmt (&new_seq, stmt); |
75a70cf9 | 1267 | } |
1268 | ||
f4e36c33 | 1269 | return new_seq; |
75a70cf9 | 1270 | } |
1271 | ||
1272 | ||
1273 | /* Walk all the statements in the sequence SEQ calling walk_gimple_stmt | |
1274 | on each one. WI is as in walk_gimple_stmt. | |
48e1416a | 1275 | |
75a70cf9 | 1276 | If walk_gimple_stmt returns non-NULL, the walk is stopped, the |
1277 | value is stored in WI->CALLBACK_RESULT and the statement that | |
1278 | produced the value is returned. | |
1279 | ||
1280 | Otherwise, all the statements are walked and NULL returned. */ | |
1281 | ||
1282 | gimple | |
1283 | walk_gimple_seq (gimple_seq seq, walk_stmt_fn callback_stmt, | |
1284 | walk_tree_fn callback_op, struct walk_stmt_info *wi) | |
1285 | { | |
1286 | gimple_stmt_iterator gsi; | |
1287 | ||
1288 | for (gsi = gsi_start (seq); !gsi_end_p (gsi); gsi_next (&gsi)) | |
1289 | { | |
1290 | tree ret = walk_gimple_stmt (&gsi, callback_stmt, callback_op, wi); | |
1291 | if (ret) | |
1292 | { | |
1293 | /* If CALLBACK_STMT or CALLBACK_OP return a value, WI must exist | |
1294 | to hold it. */ | |
1295 | gcc_assert (wi); | |
1296 | wi->callback_result = ret; | |
1297 | return gsi_stmt (gsi); | |
1298 | } | |
1299 | } | |
1300 | ||
1301 | if (wi) | |
1302 | wi->callback_result = NULL_TREE; | |
1303 | ||
1304 | return NULL; | |
1305 | } | |
1306 | ||
1307 | ||
1308 | /* Helper function for walk_gimple_stmt. Walk operands of a GIMPLE_ASM. */ | |
1309 | ||
1310 | static tree | |
1311 | walk_gimple_asm (gimple stmt, walk_tree_fn callback_op, | |
1312 | struct walk_stmt_info *wi) | |
1313 | { | |
78f55ca8 | 1314 | tree ret, op; |
75a70cf9 | 1315 | unsigned noutputs; |
1316 | const char **oconstraints; | |
78f55ca8 | 1317 | unsigned i, n; |
75a70cf9 | 1318 | const char *constraint; |
1319 | bool allows_mem, allows_reg, is_inout; | |
1320 | ||
1321 | noutputs = gimple_asm_noutputs (stmt); | |
1322 | oconstraints = (const char **) alloca ((noutputs) * sizeof (const char *)); | |
1323 | ||
1324 | if (wi) | |
1325 | wi->is_lhs = true; | |
1326 | ||
1327 | for (i = 0; i < noutputs; i++) | |
1328 | { | |
78f55ca8 | 1329 | op = gimple_asm_output_op (stmt, i); |
75a70cf9 | 1330 | constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op))); |
1331 | oconstraints[i] = constraint; | |
1332 | parse_output_constraint (&constraint, i, 0, 0, &allows_mem, &allows_reg, | |
1333 | &is_inout); | |
1334 | if (wi) | |
1335 | wi->val_only = (allows_reg || !allows_mem); | |
1336 | ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL); | |
1337 | if (ret) | |
1338 | return ret; | |
1339 | } | |
1340 | ||
78f55ca8 | 1341 | n = gimple_asm_ninputs (stmt); |
1342 | for (i = 0; i < n; i++) | |
75a70cf9 | 1343 | { |
78f55ca8 | 1344 | op = gimple_asm_input_op (stmt, i); |
75a70cf9 | 1345 | constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op))); |
1346 | parse_input_constraint (&constraint, 0, 0, noutputs, 0, | |
1347 | oconstraints, &allows_mem, &allows_reg); | |
1348 | if (wi) | |
78f55ca8 | 1349 | { |
1350 | wi->val_only = (allows_reg || !allows_mem); | |
1351 | /* Although input "m" is not really a LHS, we need a lvalue. */ | |
1352 | wi->is_lhs = !wi->val_only; | |
1353 | } | |
75a70cf9 | 1354 | ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL); |
1355 | if (ret) | |
1356 | return ret; | |
1357 | } | |
1358 | ||
1359 | if (wi) | |
1360 | { | |
1361 | wi->is_lhs = false; | |
1362 | wi->val_only = true; | |
1363 | } | |
1364 | ||
78f55ca8 | 1365 | n = gimple_asm_nlabels (stmt); |
1366 | for (i = 0; i < n; i++) | |
1367 | { | |
1368 | op = gimple_asm_label_op (stmt, i); | |
1369 | ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL); | |
1370 | if (ret) | |
1371 | return ret; | |
1372 | } | |
1373 | ||
75a70cf9 | 1374 | return NULL_TREE; |
1375 | } | |
1376 | ||
1377 | ||
1378 | /* Helper function of WALK_GIMPLE_STMT. Walk every tree operand in | |
1379 | STMT. CALLBACK_OP and WI are as in WALK_GIMPLE_STMT. | |
1380 | ||
1381 | CALLBACK_OP is called on each operand of STMT via walk_tree. | |
1382 | Additional parameters to walk_tree must be stored in WI. For each operand | |
1383 | OP, walk_tree is called as: | |
1384 | ||
1385 | walk_tree (&OP, CALLBACK_OP, WI, WI->PSET) | |
1386 | ||
1387 | If CALLBACK_OP returns non-NULL for an operand, the remaining | |
1388 | operands are not scanned. | |
1389 | ||
1390 | The return value is that returned by the last call to walk_tree, or | |
1391 | NULL_TREE if no CALLBACK_OP is specified. */ | |
1392 | ||
1eb1b33f | 1393 | tree |
75a70cf9 | 1394 | walk_gimple_op (gimple stmt, walk_tree_fn callback_op, |
1395 | struct walk_stmt_info *wi) | |
1396 | { | |
1397 | struct pointer_set_t *pset = (wi) ? wi->pset : NULL; | |
1398 | unsigned i; | |
1399 | tree ret = NULL_TREE; | |
1400 | ||
1401 | switch (gimple_code (stmt)) | |
1402 | { | |
1403 | case GIMPLE_ASSIGN: | |
e568189f | 1404 | /* Walk the RHS operands. If the LHS is of a non-renamable type or |
1405 | is a register variable, we may use a COMPONENT_REF on the RHS. */ | |
75a70cf9 | 1406 | if (wi) |
e568189f | 1407 | { |
1408 | tree lhs = gimple_assign_lhs (stmt); | |
1409 | wi->val_only | |
1410 | = (is_gimple_reg_type (TREE_TYPE (lhs)) && !is_gimple_reg (lhs)) | |
1411 | || !gimple_assign_single_p (stmt); | |
1412 | } | |
75a70cf9 | 1413 | |
1414 | for (i = 1; i < gimple_num_ops (stmt); i++) | |
1415 | { | |
1416 | ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi, | |
1417 | pset); | |
1418 | if (ret) | |
1419 | return ret; | |
1420 | } | |
1421 | ||
1422 | /* Walk the LHS. If the RHS is appropriate for a memory, we | |
1423 | may use a COMPONENT_REF on the LHS. */ | |
1424 | if (wi) | |
1425 | { | |
1426 | /* If the RHS has more than 1 operand, it is not appropriate | |
1427 | for the memory. */ | |
1428 | wi->val_only = !is_gimple_mem_rhs (gimple_assign_rhs1 (stmt)) | |
1429 | || !gimple_assign_single_p (stmt); | |
1430 | wi->is_lhs = true; | |
1431 | } | |
1432 | ||
1433 | ret = walk_tree (gimple_op_ptr (stmt, 0), callback_op, wi, pset); | |
1434 | if (ret) | |
1435 | return ret; | |
1436 | ||
1437 | if (wi) | |
1438 | { | |
1439 | wi->val_only = true; | |
1440 | wi->is_lhs = false; | |
1441 | } | |
1442 | break; | |
1443 | ||
1444 | case GIMPLE_CALL: | |
1445 | if (wi) | |
251e7603 | 1446 | { |
1447 | wi->is_lhs = false; | |
1448 | wi->val_only = true; | |
1449 | } | |
75a70cf9 | 1450 | |
1451 | ret = walk_tree (gimple_call_chain_ptr (stmt), callback_op, wi, pset); | |
1452 | if (ret) | |
1453 | return ret; | |
1454 | ||
1455 | ret = walk_tree (gimple_call_fn_ptr (stmt), callback_op, wi, pset); | |
1456 | if (ret) | |
1457 | return ret; | |
1458 | ||
1459 | for (i = 0; i < gimple_call_num_args (stmt); i++) | |
1460 | { | |
251e7603 | 1461 | if (wi) |
d5c50c6d | 1462 | wi->val_only |
1463 | = is_gimple_reg_type (TREE_TYPE (gimple_call_arg (stmt, i))); | |
75a70cf9 | 1464 | ret = walk_tree (gimple_call_arg_ptr (stmt, i), callback_op, wi, |
1465 | pset); | |
1466 | if (ret) | |
1467 | return ret; | |
1468 | } | |
1469 | ||
251e7603 | 1470 | if (gimple_call_lhs (stmt)) |
1471 | { | |
1472 | if (wi) | |
1473 | { | |
1474 | wi->is_lhs = true; | |
d5c50c6d | 1475 | wi->val_only |
1476 | = is_gimple_reg_type (TREE_TYPE (gimple_call_lhs (stmt))); | |
251e7603 | 1477 | } |
75a70cf9 | 1478 | |
251e7603 | 1479 | ret = walk_tree (gimple_call_lhs_ptr (stmt), callback_op, wi, pset); |
1480 | if (ret) | |
1481 | return ret; | |
1482 | } | |
75a70cf9 | 1483 | |
1484 | if (wi) | |
251e7603 | 1485 | { |
1486 | wi->is_lhs = false; | |
1487 | wi->val_only = true; | |
1488 | } | |
75a70cf9 | 1489 | break; |
1490 | ||
1491 | case GIMPLE_CATCH: | |
1492 | ret = walk_tree (gimple_catch_types_ptr (stmt), callback_op, wi, | |
1493 | pset); | |
1494 | if (ret) | |
1495 | return ret; | |
1496 | break; | |
1497 | ||
1498 | case GIMPLE_EH_FILTER: | |
1499 | ret = walk_tree (gimple_eh_filter_types_ptr (stmt), callback_op, wi, | |
1500 | pset); | |
1501 | if (ret) | |
1502 | return ret; | |
1503 | break; | |
1504 | ||
75a70cf9 | 1505 | case GIMPLE_ASM: |
1506 | ret = walk_gimple_asm (stmt, callback_op, wi); | |
1507 | if (ret) | |
1508 | return ret; | |
1509 | break; | |
1510 | ||
1511 | case GIMPLE_OMP_CONTINUE: | |
1512 | ret = walk_tree (gimple_omp_continue_control_def_ptr (stmt), | |
1513 | callback_op, wi, pset); | |
1514 | if (ret) | |
1515 | return ret; | |
1516 | ||
1517 | ret = walk_tree (gimple_omp_continue_control_use_ptr (stmt), | |
1518 | callback_op, wi, pset); | |
1519 | if (ret) | |
1520 | return ret; | |
1521 | break; | |
1522 | ||
1523 | case GIMPLE_OMP_CRITICAL: | |
1524 | ret = walk_tree (gimple_omp_critical_name_ptr (stmt), callback_op, wi, | |
1525 | pset); | |
1526 | if (ret) | |
1527 | return ret; | |
1528 | break; | |
1529 | ||
1530 | case GIMPLE_OMP_FOR: | |
1531 | ret = walk_tree (gimple_omp_for_clauses_ptr (stmt), callback_op, wi, | |
1532 | pset); | |
1533 | if (ret) | |
1534 | return ret; | |
1535 | for (i = 0; i < gimple_omp_for_collapse (stmt); i++) | |
1536 | { | |
1537 | ret = walk_tree (gimple_omp_for_index_ptr (stmt, i), callback_op, | |
1538 | wi, pset); | |
1539 | if (ret) | |
1540 | return ret; | |
1541 | ret = walk_tree (gimple_omp_for_initial_ptr (stmt, i), callback_op, | |
1542 | wi, pset); | |
1543 | if (ret) | |
1544 | return ret; | |
1545 | ret = walk_tree (gimple_omp_for_final_ptr (stmt, i), callback_op, | |
1546 | wi, pset); | |
1547 | if (ret) | |
1548 | return ret; | |
1549 | ret = walk_tree (gimple_omp_for_incr_ptr (stmt, i), callback_op, | |
1550 | wi, pset); | |
1551 | } | |
1552 | if (ret) | |
1553 | return ret; | |
1554 | break; | |
1555 | ||
1556 | case GIMPLE_OMP_PARALLEL: | |
1557 | ret = walk_tree (gimple_omp_parallel_clauses_ptr (stmt), callback_op, | |
1558 | wi, pset); | |
1559 | if (ret) | |
1560 | return ret; | |
1561 | ret = walk_tree (gimple_omp_parallel_child_fn_ptr (stmt), callback_op, | |
1562 | wi, pset); | |
1563 | if (ret) | |
1564 | return ret; | |
1565 | ret = walk_tree (gimple_omp_parallel_data_arg_ptr (stmt), callback_op, | |
1566 | wi, pset); | |
1567 | if (ret) | |
1568 | return ret; | |
1569 | break; | |
1570 | ||
1571 | case GIMPLE_OMP_TASK: | |
1572 | ret = walk_tree (gimple_omp_task_clauses_ptr (stmt), callback_op, | |
1573 | wi, pset); | |
1574 | if (ret) | |
1575 | return ret; | |
1576 | ret = walk_tree (gimple_omp_task_child_fn_ptr (stmt), callback_op, | |
1577 | wi, pset); | |
1578 | if (ret) | |
1579 | return ret; | |
1580 | ret = walk_tree (gimple_omp_task_data_arg_ptr (stmt), callback_op, | |
1581 | wi, pset); | |
1582 | if (ret) | |
1583 | return ret; | |
1584 | ret = walk_tree (gimple_omp_task_copy_fn_ptr (stmt), callback_op, | |
1585 | wi, pset); | |
1586 | if (ret) | |
1587 | return ret; | |
1588 | ret = walk_tree (gimple_omp_task_arg_size_ptr (stmt), callback_op, | |
1589 | wi, pset); | |
1590 | if (ret) | |
1591 | return ret; | |
1592 | ret = walk_tree (gimple_omp_task_arg_align_ptr (stmt), callback_op, | |
1593 | wi, pset); | |
1594 | if (ret) | |
1595 | return ret; | |
1596 | break; | |
1597 | ||
1598 | case GIMPLE_OMP_SECTIONS: | |
1599 | ret = walk_tree (gimple_omp_sections_clauses_ptr (stmt), callback_op, | |
1600 | wi, pset); | |
1601 | if (ret) | |
1602 | return ret; | |
1603 | ||
1604 | ret = walk_tree (gimple_omp_sections_control_ptr (stmt), callback_op, | |
1605 | wi, pset); | |
1606 | if (ret) | |
1607 | return ret; | |
1608 | ||
1609 | break; | |
1610 | ||
1611 | case GIMPLE_OMP_SINGLE: | |
1612 | ret = walk_tree (gimple_omp_single_clauses_ptr (stmt), callback_op, wi, | |
1613 | pset); | |
1614 | if (ret) | |
1615 | return ret; | |
1616 | break; | |
1617 | ||
1618 | case GIMPLE_OMP_ATOMIC_LOAD: | |
1619 | ret = walk_tree (gimple_omp_atomic_load_lhs_ptr (stmt), callback_op, wi, | |
1620 | pset); | |
1621 | if (ret) | |
1622 | return ret; | |
1623 | ||
1624 | ret = walk_tree (gimple_omp_atomic_load_rhs_ptr (stmt), callback_op, wi, | |
1625 | pset); | |
1626 | if (ret) | |
1627 | return ret; | |
1628 | break; | |
1629 | ||
1630 | case GIMPLE_OMP_ATOMIC_STORE: | |
1631 | ret = walk_tree (gimple_omp_atomic_store_val_ptr (stmt), callback_op, | |
1632 | wi, pset); | |
1633 | if (ret) | |
1634 | return ret; | |
1635 | break; | |
1636 | ||
1637 | /* Tuples that do not have operands. */ | |
1638 | case GIMPLE_NOP: | |
1639 | case GIMPLE_RESX: | |
1640 | case GIMPLE_OMP_RETURN: | |
1641 | case GIMPLE_PREDICT: | |
1642 | break; | |
1643 | ||
1644 | default: | |
1645 | { | |
1646 | enum gimple_statement_structure_enum gss; | |
1647 | gss = gimple_statement_structure (stmt); | |
1648 | if (gss == GSS_WITH_OPS || gss == GSS_WITH_MEM_OPS) | |
1649 | for (i = 0; i < gimple_num_ops (stmt); i++) | |
1650 | { | |
1651 | ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi, pset); | |
1652 | if (ret) | |
1653 | return ret; | |
1654 | } | |
1655 | } | |
1656 | break; | |
1657 | } | |
1658 | ||
1659 | return NULL_TREE; | |
1660 | } | |
1661 | ||
1662 | ||
1663 | /* Walk the current statement in GSI (optionally using traversal state | |
1664 | stored in WI). If WI is NULL, no state is kept during traversal. | |
1665 | The callback CALLBACK_STMT is called. If CALLBACK_STMT indicates | |
1666 | that it has handled all the operands of the statement, its return | |
1667 | value is returned. Otherwise, the return value from CALLBACK_STMT | |
1668 | is discarded and its operands are scanned. | |
1669 | ||
1670 | If CALLBACK_STMT is NULL or it didn't handle the operands, | |
1671 | CALLBACK_OP is called on each operand of the statement via | |
1672 | walk_gimple_op. If walk_gimple_op returns non-NULL for any | |
1673 | operand, the remaining operands are not scanned. In this case, the | |
1674 | return value from CALLBACK_OP is returned. | |
1675 | ||
1676 | In any other case, NULL_TREE is returned. */ | |
1677 | ||
1678 | tree | |
1679 | walk_gimple_stmt (gimple_stmt_iterator *gsi, walk_stmt_fn callback_stmt, | |
1680 | walk_tree_fn callback_op, struct walk_stmt_info *wi) | |
1681 | { | |
1682 | gimple ret; | |
1683 | tree tree_ret; | |
1684 | gimple stmt = gsi_stmt (*gsi); | |
1685 | ||
1686 | if (wi) | |
1687 | wi->gsi = *gsi; | |
1688 | ||
1689 | if (wi && wi->want_locations && gimple_has_location (stmt)) | |
1690 | input_location = gimple_location (stmt); | |
1691 | ||
1692 | ret = NULL; | |
1693 | ||
1694 | /* Invoke the statement callback. Return if the callback handled | |
1695 | all of STMT operands by itself. */ | |
1696 | if (callback_stmt) | |
1697 | { | |
1698 | bool handled_ops = false; | |
1699 | tree_ret = callback_stmt (gsi, &handled_ops, wi); | |
1700 | if (handled_ops) | |
1701 | return tree_ret; | |
1702 | ||
1703 | /* If CALLBACK_STMT did not handle operands, it should not have | |
1704 | a value to return. */ | |
1705 | gcc_assert (tree_ret == NULL); | |
1706 | ||
1707 | /* Re-read stmt in case the callback changed it. */ | |
1708 | stmt = gsi_stmt (*gsi); | |
1709 | } | |
1710 | ||
1711 | /* If CALLBACK_OP is defined, invoke it on every operand of STMT. */ | |
1712 | if (callback_op) | |
1713 | { | |
1714 | tree_ret = walk_gimple_op (stmt, callback_op, wi); | |
1715 | if (tree_ret) | |
1716 | return tree_ret; | |
1717 | } | |
1718 | ||
1719 | /* If STMT can have statements inside (e.g. GIMPLE_BIND), walk them. */ | |
1720 | switch (gimple_code (stmt)) | |
1721 | { | |
1722 | case GIMPLE_BIND: | |
1723 | ret = walk_gimple_seq (gimple_bind_body (stmt), callback_stmt, | |
1724 | callback_op, wi); | |
1725 | if (ret) | |
1726 | return wi->callback_result; | |
1727 | break; | |
1728 | ||
1729 | case GIMPLE_CATCH: | |
1730 | ret = walk_gimple_seq (gimple_catch_handler (stmt), callback_stmt, | |
1731 | callback_op, wi); | |
1732 | if (ret) | |
1733 | return wi->callback_result; | |
1734 | break; | |
1735 | ||
1736 | case GIMPLE_EH_FILTER: | |
1737 | ret = walk_gimple_seq (gimple_eh_filter_failure (stmt), callback_stmt, | |
1738 | callback_op, wi); | |
1739 | if (ret) | |
1740 | return wi->callback_result; | |
1741 | break; | |
1742 | ||
1743 | case GIMPLE_TRY: | |
1744 | ret = walk_gimple_seq (gimple_try_eval (stmt), callback_stmt, callback_op, | |
1745 | wi); | |
1746 | if (ret) | |
1747 | return wi->callback_result; | |
1748 | ||
1749 | ret = walk_gimple_seq (gimple_try_cleanup (stmt), callback_stmt, | |
1750 | callback_op, wi); | |
1751 | if (ret) | |
1752 | return wi->callback_result; | |
1753 | break; | |
1754 | ||
1755 | case GIMPLE_OMP_FOR: | |
1756 | ret = walk_gimple_seq (gimple_omp_for_pre_body (stmt), callback_stmt, | |
1757 | callback_op, wi); | |
1758 | if (ret) | |
1759 | return wi->callback_result; | |
1760 | ||
1761 | /* FALL THROUGH. */ | |
1762 | case GIMPLE_OMP_CRITICAL: | |
1763 | case GIMPLE_OMP_MASTER: | |
1764 | case GIMPLE_OMP_ORDERED: | |
1765 | case GIMPLE_OMP_SECTION: | |
1766 | case GIMPLE_OMP_PARALLEL: | |
1767 | case GIMPLE_OMP_TASK: | |
1768 | case GIMPLE_OMP_SECTIONS: | |
1769 | case GIMPLE_OMP_SINGLE: | |
1770 | ret = walk_gimple_seq (gimple_omp_body (stmt), callback_stmt, callback_op, | |
1771 | wi); | |
1772 | if (ret) | |
1773 | return wi->callback_result; | |
1774 | break; | |
1775 | ||
1776 | case GIMPLE_WITH_CLEANUP_EXPR: | |
1777 | ret = walk_gimple_seq (gimple_wce_cleanup (stmt), callback_stmt, | |
1778 | callback_op, wi); | |
1779 | if (ret) | |
1780 | return wi->callback_result; | |
1781 | break; | |
1782 | ||
1783 | default: | |
1784 | gcc_assert (!gimple_has_substatements (stmt)); | |
1785 | break; | |
1786 | } | |
1787 | ||
1788 | return NULL; | |
1789 | } | |
1790 | ||
1791 | ||
1792 | /* Set sequence SEQ to be the GIMPLE body for function FN. */ | |
1793 | ||
1794 | void | |
1795 | gimple_set_body (tree fndecl, gimple_seq seq) | |
1796 | { | |
1797 | struct function *fn = DECL_STRUCT_FUNCTION (fndecl); | |
1798 | if (fn == NULL) | |
1799 | { | |
1800 | /* If FNDECL still does not have a function structure associated | |
1801 | with it, then it does not make sense for it to receive a | |
1802 | GIMPLE body. */ | |
1803 | gcc_assert (seq == NULL); | |
1804 | } | |
1805 | else | |
1806 | fn->gimple_body = seq; | |
1807 | } | |
1808 | ||
1809 | ||
0874e443 | 1810 | /* Return the body of GIMPLE statements for function FN. After the |
1811 | CFG pass, the function body doesn't exist anymore because it has | |
1812 | been split up into basic blocks. In this case, it returns | |
1813 | NULL. */ | |
75a70cf9 | 1814 | |
1815 | gimple_seq | |
1816 | gimple_body (tree fndecl) | |
1817 | { | |
1818 | struct function *fn = DECL_STRUCT_FUNCTION (fndecl); | |
1819 | return fn ? fn->gimple_body : NULL; | |
1820 | } | |
1821 | ||
1a1a827a | 1822 | /* Return true when FNDECL has Gimple body either in unlowered |
1823 | or CFG form. */ | |
1824 | bool | |
1825 | gimple_has_body_p (tree fndecl) | |
1826 | { | |
1827 | struct function *fn = DECL_STRUCT_FUNCTION (fndecl); | |
1828 | return (gimple_body (fndecl) || (fn && fn->cfg)); | |
1829 | } | |
75a70cf9 | 1830 | |
fb049fba | 1831 | /* Return true if calls C1 and C2 are known to go to the same function. */ |
1832 | ||
1833 | bool | |
1834 | gimple_call_same_target_p (const_gimple c1, const_gimple c2) | |
1835 | { | |
1836 | if (gimple_call_internal_p (c1)) | |
1837 | return (gimple_call_internal_p (c2) | |
1838 | && gimple_call_internal_fn (c1) == gimple_call_internal_fn (c2)); | |
1839 | else | |
1840 | return (gimple_call_fn (c1) == gimple_call_fn (c2) | |
1841 | || (gimple_call_fndecl (c1) | |
1842 | && gimple_call_fndecl (c1) == gimple_call_fndecl (c2))); | |
1843 | } | |
1844 | ||
75a70cf9 | 1845 | /* Detect flags from a GIMPLE_CALL. This is just like |
1846 | call_expr_flags, but for gimple tuples. */ | |
1847 | ||
1848 | int | |
1849 | gimple_call_flags (const_gimple stmt) | |
1850 | { | |
1851 | int flags; | |
1852 | tree decl = gimple_call_fndecl (stmt); | |
75a70cf9 | 1853 | |
1854 | if (decl) | |
1855 | flags = flags_from_decl_or_type (decl); | |
fb049fba | 1856 | else if (gimple_call_internal_p (stmt)) |
1857 | flags = internal_fn_flags (gimple_call_internal_fn (stmt)); | |
75a70cf9 | 1858 | else |
d71dc717 | 1859 | flags = flags_from_decl_or_type (gimple_call_fntype (stmt)); |
75a70cf9 | 1860 | |
1d3f675f | 1861 | if (stmt->gsbase.subcode & GF_CALL_NOTHROW) |
1862 | flags |= ECF_NOTHROW; | |
1863 | ||
75a70cf9 | 1864 | return flags; |
1865 | } | |
1866 | ||
fb049fba | 1867 | /* Return the "fn spec" string for call STMT. */ |
1868 | ||
1869 | static tree | |
1870 | gimple_call_fnspec (const_gimple stmt) | |
1871 | { | |
1872 | tree type, attr; | |
1873 | ||
1874 | type = gimple_call_fntype (stmt); | |
1875 | if (!type) | |
1876 | return NULL_TREE; | |
1877 | ||
1878 | attr = lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type)); | |
1879 | if (!attr) | |
1880 | return NULL_TREE; | |
1881 | ||
1882 | return TREE_VALUE (TREE_VALUE (attr)); | |
1883 | } | |
1884 | ||
8ce86007 | 1885 | /* Detects argument flags for argument number ARG on call STMT. */ |
1886 | ||
1887 | int | |
1888 | gimple_call_arg_flags (const_gimple stmt, unsigned arg) | |
1889 | { | |
fb049fba | 1890 | tree attr = gimple_call_fnspec (stmt); |
8ce86007 | 1891 | |
fb049fba | 1892 | if (!attr || 1 + arg >= (unsigned) TREE_STRING_LENGTH (attr)) |
8ce86007 | 1893 | return 0; |
1894 | ||
1895 | switch (TREE_STRING_POINTER (attr)[1 + arg]) | |
1896 | { | |
1897 | case 'x': | |
1898 | case 'X': | |
1899 | return EAF_UNUSED; | |
1900 | ||
1901 | case 'R': | |
1902 | return EAF_DIRECT | EAF_NOCLOBBER | EAF_NOESCAPE; | |
1903 | ||
1904 | case 'r': | |
1905 | return EAF_NOCLOBBER | EAF_NOESCAPE; | |
1906 | ||
1907 | case 'W': | |
1908 | return EAF_DIRECT | EAF_NOESCAPE; | |
1909 | ||
1910 | case 'w': | |
1911 | return EAF_NOESCAPE; | |
1912 | ||
1913 | case '.': | |
1914 | default: | |
1915 | return 0; | |
1916 | } | |
1917 | } | |
1918 | ||
1919 | /* Detects return flags for the call STMT. */ | |
1920 | ||
1921 | int | |
1922 | gimple_call_return_flags (const_gimple stmt) | |
1923 | { | |
fb049fba | 1924 | tree attr; |
8ce86007 | 1925 | |
1926 | if (gimple_call_flags (stmt) & ECF_MALLOC) | |
1927 | return ERF_NOALIAS; | |
1928 | ||
fb049fba | 1929 | attr = gimple_call_fnspec (stmt); |
1930 | if (!attr || TREE_STRING_LENGTH (attr) < 1) | |
8ce86007 | 1931 | return 0; |
1932 | ||
1933 | switch (TREE_STRING_POINTER (attr)[0]) | |
1934 | { | |
1935 | case '1': | |
1936 | case '2': | |
1937 | case '3': | |
1938 | case '4': | |
1939 | return ERF_RETURNS_ARG | (TREE_STRING_POINTER (attr)[0] - '1'); | |
1940 | ||
1941 | case 'm': | |
1942 | return ERF_NOALIAS; | |
1943 | ||
1944 | case '.': | |
1945 | default: | |
1946 | return 0; | |
1947 | } | |
1948 | } | |
75a70cf9 | 1949 | |
09937c79 | 1950 | |
75a70cf9 | 1951 | /* Return true if GS is a copy assignment. */ |
1952 | ||
1953 | bool | |
1954 | gimple_assign_copy_p (gimple gs) | |
1955 | { | |
09937c79 | 1956 | return (gimple_assign_single_p (gs) |
1957 | && is_gimple_val (gimple_op (gs, 1))); | |
75a70cf9 | 1958 | } |
1959 | ||
1960 | ||
1961 | /* Return true if GS is a SSA_NAME copy assignment. */ | |
1962 | ||
1963 | bool | |
1964 | gimple_assign_ssa_name_copy_p (gimple gs) | |
1965 | { | |
09937c79 | 1966 | return (gimple_assign_single_p (gs) |
75a70cf9 | 1967 | && TREE_CODE (gimple_assign_lhs (gs)) == SSA_NAME |
1968 | && TREE_CODE (gimple_assign_rhs1 (gs)) == SSA_NAME); | |
1969 | } | |
1970 | ||
1971 | ||
75a70cf9 | 1972 | /* Return true if GS is an assignment with a unary RHS, but the |
1973 | operator has no effect on the assigned value. The logic is adapted | |
1974 | from STRIP_NOPS. This predicate is intended to be used in tuplifying | |
1975 | instances in which STRIP_NOPS was previously applied to the RHS of | |
1976 | an assignment. | |
1977 | ||
1978 | NOTE: In the use cases that led to the creation of this function | |
1979 | and of gimple_assign_single_p, it is typical to test for either | |
1980 | condition and to proceed in the same manner. In each case, the | |
1981 | assigned value is represented by the single RHS operand of the | |
1982 | assignment. I suspect there may be cases where gimple_assign_copy_p, | |
1983 | gimple_assign_single_p, or equivalent logic is used where a similar | |
1984 | treatment of unary NOPs is appropriate. */ | |
48e1416a | 1985 | |
75a70cf9 | 1986 | bool |
1987 | gimple_assign_unary_nop_p (gimple gs) | |
1988 | { | |
09937c79 | 1989 | return (is_gimple_assign (gs) |
d9659041 | 1990 | && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs)) |
75a70cf9 | 1991 | || gimple_assign_rhs_code (gs) == NON_LVALUE_EXPR) |
1992 | && gimple_assign_rhs1 (gs) != error_mark_node | |
1993 | && (TYPE_MODE (TREE_TYPE (gimple_assign_lhs (gs))) | |
1994 | == TYPE_MODE (TREE_TYPE (gimple_assign_rhs1 (gs))))); | |
1995 | } | |
1996 | ||
1997 | /* Set BB to be the basic block holding G. */ | |
1998 | ||
1999 | void | |
2000 | gimple_set_bb (gimple stmt, basic_block bb) | |
2001 | { | |
2002 | stmt->gsbase.bb = bb; | |
2003 | ||
2004 | /* If the statement is a label, add the label to block-to-labels map | |
2005 | so that we can speed up edge creation for GIMPLE_GOTOs. */ | |
2006 | if (cfun->cfg && gimple_code (stmt) == GIMPLE_LABEL) | |
2007 | { | |
2008 | tree t; | |
2009 | int uid; | |
2010 | ||
2011 | t = gimple_label_label (stmt); | |
2012 | uid = LABEL_DECL_UID (t); | |
2013 | if (uid == -1) | |
2014 | { | |
2015 | unsigned old_len = VEC_length (basic_block, label_to_block_map); | |
2016 | LABEL_DECL_UID (t) = uid = cfun->cfg->last_label_uid++; | |
2017 | if (old_len <= (unsigned) uid) | |
2018 | { | |
dd277d48 | 2019 | unsigned new_len = 3 * uid / 2 + 1; |
75a70cf9 | 2020 | |
2021 | VEC_safe_grow_cleared (basic_block, gc, label_to_block_map, | |
2022 | new_len); | |
2023 | } | |
2024 | } | |
2025 | ||
2026 | VEC_replace (basic_block, label_to_block_map, uid, bb); | |
2027 | } | |
2028 | } | |
2029 | ||
2030 | ||
75a70cf9 | 2031 | /* Modify the RHS of the assignment pointed-to by GSI using the |
2032 | operands in the expression tree EXPR. | |
2033 | ||
2034 | NOTE: The statement pointed-to by GSI may be reallocated if it | |
2035 | did not have enough operand slots. | |
2036 | ||
2037 | This function is useful to convert an existing tree expression into | |
2038 | the flat representation used for the RHS of a GIMPLE assignment. | |
2039 | It will reallocate memory as needed to expand or shrink the number | |
2040 | of operand slots needed to represent EXPR. | |
2041 | ||
2042 | NOTE: If you find yourself building a tree and then calling this | |
2043 | function, you are most certainly doing it the slow way. It is much | |
2044 | better to build a new assignment or to use the function | |
2045 | gimple_assign_set_rhs_with_ops, which does not require an | |
2046 | expression tree to be built. */ | |
2047 | ||
2048 | void | |
2049 | gimple_assign_set_rhs_from_tree (gimple_stmt_iterator *gsi, tree expr) | |
2050 | { | |
2051 | enum tree_code subcode; | |
00f4f705 | 2052 | tree op1, op2, op3; |
75a70cf9 | 2053 | |
00f4f705 | 2054 | extract_ops_from_tree_1 (expr, &subcode, &op1, &op2, &op3); |
2055 | gimple_assign_set_rhs_with_ops_1 (gsi, subcode, op1, op2, op3); | |
75a70cf9 | 2056 | } |
2057 | ||
2058 | ||
2059 | /* Set the RHS of assignment statement pointed-to by GSI to CODE with | |
00f4f705 | 2060 | operands OP1, OP2 and OP3. |
75a70cf9 | 2061 | |
2062 | NOTE: The statement pointed-to by GSI may be reallocated if it | |
2063 | did not have enough operand slots. */ | |
2064 | ||
2065 | void | |
00f4f705 | 2066 | gimple_assign_set_rhs_with_ops_1 (gimple_stmt_iterator *gsi, enum tree_code code, |
2067 | tree op1, tree op2, tree op3) | |
75a70cf9 | 2068 | { |
2069 | unsigned new_rhs_ops = get_gimple_rhs_num_ops (code); | |
2070 | gimple stmt = gsi_stmt (*gsi); | |
2071 | ||
2072 | /* If the new CODE needs more operands, allocate a new statement. */ | |
2073 | if (gimple_num_ops (stmt) < new_rhs_ops + 1) | |
2074 | { | |
2075 | tree lhs = gimple_assign_lhs (stmt); | |
2076 | gimple new_stmt = gimple_alloc (gimple_code (stmt), new_rhs_ops + 1); | |
2077 | memcpy (new_stmt, stmt, gimple_size (gimple_code (stmt))); | |
2078 | gsi_replace (gsi, new_stmt, true); | |
2079 | stmt = new_stmt; | |
2080 | ||
2081 | /* The LHS needs to be reset as this also changes the SSA name | |
2082 | on the LHS. */ | |
2083 | gimple_assign_set_lhs (stmt, lhs); | |
2084 | } | |
2085 | ||
2086 | gimple_set_num_ops (stmt, new_rhs_ops + 1); | |
2087 | gimple_set_subcode (stmt, code); | |
2088 | gimple_assign_set_rhs1 (stmt, op1); | |
2089 | if (new_rhs_ops > 1) | |
2090 | gimple_assign_set_rhs2 (stmt, op2); | |
00f4f705 | 2091 | if (new_rhs_ops > 2) |
2092 | gimple_assign_set_rhs3 (stmt, op3); | |
75a70cf9 | 2093 | } |
2094 | ||
2095 | ||
2096 | /* Return the LHS of a statement that performs an assignment, | |
2097 | either a GIMPLE_ASSIGN or a GIMPLE_CALL. Returns NULL_TREE | |
2098 | for a call to a function that returns no value, or for a | |
2099 | statement other than an assignment or a call. */ | |
2100 | ||
2101 | tree | |
2102 | gimple_get_lhs (const_gimple stmt) | |
2103 | { | |
590c3166 | 2104 | enum gimple_code code = gimple_code (stmt); |
75a70cf9 | 2105 | |
2106 | if (code == GIMPLE_ASSIGN) | |
2107 | return gimple_assign_lhs (stmt); | |
2108 | else if (code == GIMPLE_CALL) | |
2109 | return gimple_call_lhs (stmt); | |
2110 | else | |
2111 | return NULL_TREE; | |
2112 | } | |
2113 | ||
2114 | ||
2115 | /* Set the LHS of a statement that performs an assignment, | |
2116 | either a GIMPLE_ASSIGN or a GIMPLE_CALL. */ | |
2117 | ||
2118 | void | |
2119 | gimple_set_lhs (gimple stmt, tree lhs) | |
2120 | { | |
590c3166 | 2121 | enum gimple_code code = gimple_code (stmt); |
75a70cf9 | 2122 | |
2123 | if (code == GIMPLE_ASSIGN) | |
2124 | gimple_assign_set_lhs (stmt, lhs); | |
2125 | else if (code == GIMPLE_CALL) | |
2126 | gimple_call_set_lhs (stmt, lhs); | |
2127 | else | |
2128 | gcc_unreachable(); | |
2129 | } | |
2130 | ||
5fb3d93f | 2131 | /* Replace the LHS of STMT, an assignment, either a GIMPLE_ASSIGN or a |
2132 | GIMPLE_CALL, with NLHS, in preparation for modifying the RHS to an | |
2133 | expression with a different value. | |
2134 | ||
2135 | This will update any annotations (say debug bind stmts) referring | |
2136 | to the original LHS, so that they use the RHS instead. This is | |
2137 | done even if NLHS and LHS are the same, for it is understood that | |
2138 | the RHS will be modified afterwards, and NLHS will not be assigned | |
2139 | an equivalent value. | |
2140 | ||
2141 | Adjusting any non-annotation uses of the LHS, if needed, is a | |
2142 | responsibility of the caller. | |
2143 | ||
2144 | The effect of this call should be pretty much the same as that of | |
2145 | inserting a copy of STMT before STMT, and then removing the | |
2146 | original stmt, at which time gsi_remove() would have update | |
2147 | annotations, but using this function saves all the inserting, | |
2148 | copying and removing. */ | |
2149 | ||
2150 | void | |
2151 | gimple_replace_lhs (gimple stmt, tree nlhs) | |
2152 | { | |
2153 | if (MAY_HAVE_DEBUG_STMTS) | |
2154 | { | |
2155 | tree lhs = gimple_get_lhs (stmt); | |
2156 | ||
2157 | gcc_assert (SSA_NAME_DEF_STMT (lhs) == stmt); | |
2158 | ||
2159 | insert_debug_temp_for_var_def (NULL, lhs); | |
2160 | } | |
2161 | ||
2162 | gimple_set_lhs (stmt, nlhs); | |
2163 | } | |
75a70cf9 | 2164 | |
2165 | /* Return a deep copy of statement STMT. All the operands from STMT | |
2166 | are reallocated and copied using unshare_expr. The DEF, USE, VDEF | |
2167 | and VUSE operand arrays are set to empty in the new copy. */ | |
2168 | ||
2169 | gimple | |
2170 | gimple_copy (gimple stmt) | |
2171 | { | |
2172 | enum gimple_code code = gimple_code (stmt); | |
2173 | unsigned num_ops = gimple_num_ops (stmt); | |
2174 | gimple copy = gimple_alloc (code, num_ops); | |
2175 | unsigned i; | |
2176 | ||
2177 | /* Shallow copy all the fields from STMT. */ | |
2178 | memcpy (copy, stmt, gimple_size (code)); | |
2179 | ||
2180 | /* If STMT has sub-statements, deep-copy them as well. */ | |
2181 | if (gimple_has_substatements (stmt)) | |
2182 | { | |
2183 | gimple_seq new_seq; | |
2184 | tree t; | |
2185 | ||
2186 | switch (gimple_code (stmt)) | |
2187 | { | |
2188 | case GIMPLE_BIND: | |
2189 | new_seq = gimple_seq_copy (gimple_bind_body (stmt)); | |
2190 | gimple_bind_set_body (copy, new_seq); | |
2191 | gimple_bind_set_vars (copy, unshare_expr (gimple_bind_vars (stmt))); | |
2192 | gimple_bind_set_block (copy, gimple_bind_block (stmt)); | |
2193 | break; | |
2194 | ||
2195 | case GIMPLE_CATCH: | |
2196 | new_seq = gimple_seq_copy (gimple_catch_handler (stmt)); | |
2197 | gimple_catch_set_handler (copy, new_seq); | |
2198 | t = unshare_expr (gimple_catch_types (stmt)); | |
2199 | gimple_catch_set_types (copy, t); | |
2200 | break; | |
2201 | ||
2202 | case GIMPLE_EH_FILTER: | |
2203 | new_seq = gimple_seq_copy (gimple_eh_filter_failure (stmt)); | |
2204 | gimple_eh_filter_set_failure (copy, new_seq); | |
2205 | t = unshare_expr (gimple_eh_filter_types (stmt)); | |
2206 | gimple_eh_filter_set_types (copy, t); | |
2207 | break; | |
2208 | ||
2209 | case GIMPLE_TRY: | |
2210 | new_seq = gimple_seq_copy (gimple_try_eval (stmt)); | |
2211 | gimple_try_set_eval (copy, new_seq); | |
2212 | new_seq = gimple_seq_copy (gimple_try_cleanup (stmt)); | |
2213 | gimple_try_set_cleanup (copy, new_seq); | |
2214 | break; | |
2215 | ||
2216 | case GIMPLE_OMP_FOR: | |
2217 | new_seq = gimple_seq_copy (gimple_omp_for_pre_body (stmt)); | |
2218 | gimple_omp_for_set_pre_body (copy, new_seq); | |
2219 | t = unshare_expr (gimple_omp_for_clauses (stmt)); | |
2220 | gimple_omp_for_set_clauses (copy, t); | |
2221 | copy->gimple_omp_for.iter | |
ba72912a | 2222 | = ggc_alloc_vec_gimple_omp_for_iter |
2223 | (gimple_omp_for_collapse (stmt)); | |
75a70cf9 | 2224 | for (i = 0; i < gimple_omp_for_collapse (stmt); i++) |
2225 | { | |
2226 | gimple_omp_for_set_cond (copy, i, | |
2227 | gimple_omp_for_cond (stmt, i)); | |
2228 | gimple_omp_for_set_index (copy, i, | |
2229 | gimple_omp_for_index (stmt, i)); | |
2230 | t = unshare_expr (gimple_omp_for_initial (stmt, i)); | |
2231 | gimple_omp_for_set_initial (copy, i, t); | |
2232 | t = unshare_expr (gimple_omp_for_final (stmt, i)); | |
2233 | gimple_omp_for_set_final (copy, i, t); | |
2234 | t = unshare_expr (gimple_omp_for_incr (stmt, i)); | |
2235 | gimple_omp_for_set_incr (copy, i, t); | |
2236 | } | |
2237 | goto copy_omp_body; | |
2238 | ||
2239 | case GIMPLE_OMP_PARALLEL: | |
2240 | t = unshare_expr (gimple_omp_parallel_clauses (stmt)); | |
2241 | gimple_omp_parallel_set_clauses (copy, t); | |
2242 | t = unshare_expr (gimple_omp_parallel_child_fn (stmt)); | |
2243 | gimple_omp_parallel_set_child_fn (copy, t); | |
2244 | t = unshare_expr (gimple_omp_parallel_data_arg (stmt)); | |
2245 | gimple_omp_parallel_set_data_arg (copy, t); | |
2246 | goto copy_omp_body; | |
2247 | ||
2248 | case GIMPLE_OMP_TASK: | |
2249 | t = unshare_expr (gimple_omp_task_clauses (stmt)); | |
2250 | gimple_omp_task_set_clauses (copy, t); | |
2251 | t = unshare_expr (gimple_omp_task_child_fn (stmt)); | |
2252 | gimple_omp_task_set_child_fn (copy, t); | |
2253 | t = unshare_expr (gimple_omp_task_data_arg (stmt)); | |
2254 | gimple_omp_task_set_data_arg (copy, t); | |
2255 | t = unshare_expr (gimple_omp_task_copy_fn (stmt)); | |
2256 | gimple_omp_task_set_copy_fn (copy, t); | |
2257 | t = unshare_expr (gimple_omp_task_arg_size (stmt)); | |
2258 | gimple_omp_task_set_arg_size (copy, t); | |
2259 | t = unshare_expr (gimple_omp_task_arg_align (stmt)); | |
2260 | gimple_omp_task_set_arg_align (copy, t); | |
2261 | goto copy_omp_body; | |
2262 | ||
2263 | case GIMPLE_OMP_CRITICAL: | |
2264 | t = unshare_expr (gimple_omp_critical_name (stmt)); | |
2265 | gimple_omp_critical_set_name (copy, t); | |
2266 | goto copy_omp_body; | |
2267 | ||
2268 | case GIMPLE_OMP_SECTIONS: | |
2269 | t = unshare_expr (gimple_omp_sections_clauses (stmt)); | |
2270 | gimple_omp_sections_set_clauses (copy, t); | |
2271 | t = unshare_expr (gimple_omp_sections_control (stmt)); | |
2272 | gimple_omp_sections_set_control (copy, t); | |
2273 | /* FALLTHRU */ | |
2274 | ||
2275 | case GIMPLE_OMP_SINGLE: | |
2276 | case GIMPLE_OMP_SECTION: | |
2277 | case GIMPLE_OMP_MASTER: | |
2278 | case GIMPLE_OMP_ORDERED: | |
2279 | copy_omp_body: | |
2280 | new_seq = gimple_seq_copy (gimple_omp_body (stmt)); | |
2281 | gimple_omp_set_body (copy, new_seq); | |
2282 | break; | |
2283 | ||
2284 | case GIMPLE_WITH_CLEANUP_EXPR: | |
2285 | new_seq = gimple_seq_copy (gimple_wce_cleanup (stmt)); | |
2286 | gimple_wce_set_cleanup (copy, new_seq); | |
2287 | break; | |
2288 | ||
2289 | default: | |
2290 | gcc_unreachable (); | |
2291 | } | |
2292 | } | |
2293 | ||
2294 | /* Make copy of operands. */ | |
2295 | if (num_ops > 0) | |
2296 | { | |
2297 | for (i = 0; i < num_ops; i++) | |
2298 | gimple_set_op (copy, i, unshare_expr (gimple_op (stmt, i))); | |
2299 | ||
6d5ec6f8 | 2300 | /* Clear out SSA operand vectors on COPY. */ |
75a70cf9 | 2301 | if (gimple_has_ops (stmt)) |
2302 | { | |
2303 | gimple_set_def_ops (copy, NULL); | |
2304 | gimple_set_use_ops (copy, NULL); | |
75a70cf9 | 2305 | } |
2306 | ||
2307 | if (gimple_has_mem_ops (stmt)) | |
2308 | { | |
dd277d48 | 2309 | gimple_set_vdef (copy, gimple_vdef (stmt)); |
2310 | gimple_set_vuse (copy, gimple_vuse (stmt)); | |
75a70cf9 | 2311 | } |
2312 | ||
dd277d48 | 2313 | /* SSA operands need to be updated. */ |
2314 | gimple_set_modified (copy, true); | |
75a70cf9 | 2315 | } |
2316 | ||
2317 | return copy; | |
2318 | } | |
2319 | ||
2320 | ||
2321 | /* Set the MODIFIED flag to MODIFIEDP, iff the gimple statement G has | |
2322 | a MODIFIED field. */ | |
2323 | ||
2324 | void | |
2325 | gimple_set_modified (gimple s, bool modifiedp) | |
2326 | { | |
2327 | if (gimple_has_ops (s)) | |
e1f47fd3 | 2328 | s->gsbase.modified = (unsigned) modifiedp; |
75a70cf9 | 2329 | } |
2330 | ||
2331 | ||
2332 | /* Return true if statement S has side-effects. We consider a | |
2333 | statement to have side effects if: | |
2334 | ||
2335 | - It is a GIMPLE_CALL not marked with ECF_PURE or ECF_CONST. | |
2336 | - Any of its operands are marked TREE_THIS_VOLATILE or TREE_SIDE_EFFECTS. */ | |
2337 | ||
2338 | bool | |
2339 | gimple_has_side_effects (const_gimple s) | |
2340 | { | |
2341 | unsigned i; | |
2342 | ||
9845d120 | 2343 | if (is_gimple_debug (s)) |
2344 | return false; | |
2345 | ||
75a70cf9 | 2346 | /* We don't have to scan the arguments to check for |
2347 | volatile arguments, though, at present, we still | |
2348 | do a scan to check for TREE_SIDE_EFFECTS. */ | |
2349 | if (gimple_has_volatile_ops (s)) | |
2350 | return true; | |
2351 | ||
b523dd6d | 2352 | if (gimple_code (s) == GIMPLE_ASM |
2353 | && gimple_asm_volatile_p (s)) | |
2354 | return true; | |
2355 | ||
75a70cf9 | 2356 | if (is_gimple_call (s)) |
2357 | { | |
2358 | unsigned nargs = gimple_call_num_args (s); | |
fb049fba | 2359 | tree fn; |
75a70cf9 | 2360 | |
2361 | if (!(gimple_call_flags (s) & (ECF_CONST | ECF_PURE))) | |
2362 | return true; | |
2363 | else if (gimple_call_flags (s) & ECF_LOOPING_CONST_OR_PURE) | |
2364 | /* An infinite loop is considered a side effect. */ | |
2365 | return true; | |
2366 | ||
2367 | if (gimple_call_lhs (s) | |
2368 | && TREE_SIDE_EFFECTS (gimple_call_lhs (s))) | |
2369 | { | |
b523dd6d | 2370 | gcc_checking_assert (gimple_has_volatile_ops (s)); |
75a70cf9 | 2371 | return true; |
2372 | } | |
2373 | ||
fb049fba | 2374 | fn = gimple_call_fn (s); |
2375 | if (fn && TREE_SIDE_EFFECTS (fn)) | |
75a70cf9 | 2376 | return true; |
2377 | ||
2378 | for (i = 0; i < nargs; i++) | |
2379 | if (TREE_SIDE_EFFECTS (gimple_call_arg (s, i))) | |
2380 | { | |
b523dd6d | 2381 | gcc_checking_assert (gimple_has_volatile_ops (s)); |
75a70cf9 | 2382 | return true; |
2383 | } | |
2384 | ||
2385 | return false; | |
2386 | } | |
2387 | else | |
2388 | { | |
2389 | for (i = 0; i < gimple_num_ops (s); i++) | |
b523dd6d | 2390 | { |
2391 | tree op = gimple_op (s, i); | |
2392 | if (op && TREE_SIDE_EFFECTS (op)) | |
2393 | { | |
2394 | gcc_checking_assert (gimple_has_volatile_ops (s)); | |
2395 | return true; | |
2396 | } | |
2397 | } | |
75a70cf9 | 2398 | } |
2399 | ||
2400 | return false; | |
2401 | } | |
2402 | ||
2403 | /* Return true if the RHS of statement S has side effects. | |
2404 | We may use it to determine if it is admissable to replace | |
2405 | an assignment or call with a copy of a previously-computed | |
851d9296 | 2406 | value. In such cases, side-effects due to the LHS are |
75a70cf9 | 2407 | preserved. */ |
2408 | ||
2409 | bool | |
2410 | gimple_rhs_has_side_effects (const_gimple s) | |
2411 | { | |
2412 | unsigned i; | |
2413 | ||
2414 | if (is_gimple_call (s)) | |
2415 | { | |
2416 | unsigned nargs = gimple_call_num_args (s); | |
fb049fba | 2417 | tree fn; |
75a70cf9 | 2418 | |
2419 | if (!(gimple_call_flags (s) & (ECF_CONST | ECF_PURE))) | |
2420 | return true; | |
2421 | ||
2422 | /* We cannot use gimple_has_volatile_ops here, | |
2423 | because we must ignore a volatile LHS. */ | |
fb049fba | 2424 | fn = gimple_call_fn (s); |
2425 | if (fn && (TREE_SIDE_EFFECTS (fn) || TREE_THIS_VOLATILE (fn))) | |
75a70cf9 | 2426 | { |
2427 | gcc_assert (gimple_has_volatile_ops (s)); | |
2428 | return true; | |
2429 | } | |
2430 | ||
2431 | for (i = 0; i < nargs; i++) | |
2432 | if (TREE_SIDE_EFFECTS (gimple_call_arg (s, i)) | |
2433 | || TREE_THIS_VOLATILE (gimple_call_arg (s, i))) | |
2434 | return true; | |
2435 | ||
2436 | return false; | |
2437 | } | |
2438 | else if (is_gimple_assign (s)) | |
2439 | { | |
2440 | /* Skip the first operand, the LHS. */ | |
2441 | for (i = 1; i < gimple_num_ops (s); i++) | |
2442 | if (TREE_SIDE_EFFECTS (gimple_op (s, i)) | |
2443 | || TREE_THIS_VOLATILE (gimple_op (s, i))) | |
2444 | { | |
2445 | gcc_assert (gimple_has_volatile_ops (s)); | |
2446 | return true; | |
2447 | } | |
2448 | } | |
9845d120 | 2449 | else if (is_gimple_debug (s)) |
2450 | return false; | |
75a70cf9 | 2451 | else |
2452 | { | |
2453 | /* For statements without an LHS, examine all arguments. */ | |
2454 | for (i = 0; i < gimple_num_ops (s); i++) | |
2455 | if (TREE_SIDE_EFFECTS (gimple_op (s, i)) | |
2456 | || TREE_THIS_VOLATILE (gimple_op (s, i))) | |
2457 | { | |
2458 | gcc_assert (gimple_has_volatile_ops (s)); | |
2459 | return true; | |
2460 | } | |
2461 | } | |
2462 | ||
2463 | return false; | |
2464 | } | |
2465 | ||
75a70cf9 | 2466 | /* Helper for gimple_could_trap_p and gimple_assign_rhs_could_trap_p. |
e1cc68bd | 2467 | Return true if S can trap. When INCLUDE_MEM is true, check whether |
2468 | the memory operations could trap. When INCLUDE_STORES is true and | |
2469 | S is a GIMPLE_ASSIGN, the LHS of the assignment is also checked. */ | |
75a70cf9 | 2470 | |
e1cc68bd | 2471 | bool |
2472 | gimple_could_trap_p_1 (gimple s, bool include_mem, bool include_stores) | |
75a70cf9 | 2473 | { |
75a70cf9 | 2474 | tree t, div = NULL_TREE; |
2475 | enum tree_code op; | |
2476 | ||
e1cc68bd | 2477 | if (include_mem) |
2478 | { | |
2479 | unsigned i, start = (is_gimple_assign (s) && !include_stores) ? 1 : 0; | |
75a70cf9 | 2480 | |
e1cc68bd | 2481 | for (i = start; i < gimple_num_ops (s); i++) |
2482 | if (tree_could_trap_p (gimple_op (s, i))) | |
2483 | return true; | |
2484 | } | |
75a70cf9 | 2485 | |
2486 | switch (gimple_code (s)) | |
2487 | { | |
2488 | case GIMPLE_ASM: | |
2489 | return gimple_asm_volatile_p (s); | |
2490 | ||
2491 | case GIMPLE_CALL: | |
2492 | t = gimple_call_fndecl (s); | |
2493 | /* Assume that calls to weak functions may trap. */ | |
2494 | if (!t || !DECL_P (t) || DECL_WEAK (t)) | |
2495 | return true; | |
2496 | return false; | |
2497 | ||
2498 | case GIMPLE_ASSIGN: | |
2499 | t = gimple_expr_type (s); | |
2500 | op = gimple_assign_rhs_code (s); | |
2501 | if (get_gimple_rhs_class (op) == GIMPLE_BINARY_RHS) | |
2502 | div = gimple_assign_rhs2 (s); | |
2503 | return (operation_could_trap_p (op, FLOAT_TYPE_P (t), | |
2504 | (INTEGRAL_TYPE_P (t) | |
2505 | && TYPE_OVERFLOW_TRAPS (t)), | |
2506 | div)); | |
2507 | ||
2508 | default: | |
2509 | break; | |
2510 | } | |
2511 | ||
2512 | return false; | |
75a70cf9 | 2513 | } |
2514 | ||
75a70cf9 | 2515 | /* Return true if statement S can trap. */ |
2516 | ||
2517 | bool | |
2518 | gimple_could_trap_p (gimple s) | |
2519 | { | |
e1cc68bd | 2520 | return gimple_could_trap_p_1 (s, true, true); |
75a70cf9 | 2521 | } |
2522 | ||
75a70cf9 | 2523 | /* Return true if RHS of a GIMPLE_ASSIGN S can trap. */ |
2524 | ||
2525 | bool | |
2526 | gimple_assign_rhs_could_trap_p (gimple s) | |
2527 | { | |
2528 | gcc_assert (is_gimple_assign (s)); | |
e1cc68bd | 2529 | return gimple_could_trap_p_1 (s, true, false); |
75a70cf9 | 2530 | } |
2531 | ||
2532 | ||
2533 | /* Print debugging information for gimple stmts generated. */ | |
2534 | ||
2535 | void | |
2536 | dump_gimple_statistics (void) | |
2537 | { | |
2538 | #ifdef GATHER_STATISTICS | |
2539 | int i, total_tuples = 0, total_bytes = 0; | |
2540 | ||
2541 | fprintf (stderr, "\nGIMPLE statements\n"); | |
2542 | fprintf (stderr, "Kind Stmts Bytes\n"); | |
2543 | fprintf (stderr, "---------------------------------------\n"); | |
2544 | for (i = 0; i < (int) gimple_alloc_kind_all; ++i) | |
2545 | { | |
2546 | fprintf (stderr, "%-20s %7d %10d\n", gimple_alloc_kind_names[i], | |
2547 | gimple_alloc_counts[i], gimple_alloc_sizes[i]); | |
2548 | total_tuples += gimple_alloc_counts[i]; | |
2549 | total_bytes += gimple_alloc_sizes[i]; | |
2550 | } | |
2551 | fprintf (stderr, "---------------------------------------\n"); | |
2552 | fprintf (stderr, "%-20s %7d %10d\n", "Total", total_tuples, total_bytes); | |
2553 | fprintf (stderr, "---------------------------------------\n"); | |
2554 | #else | |
2555 | fprintf (stderr, "No gimple statistics\n"); | |
2556 | #endif | |
2557 | } | |
2558 | ||
2559 | ||
75a70cf9 | 2560 | /* Return the number of operands needed on the RHS of a GIMPLE |
2561 | assignment for an expression with tree code CODE. */ | |
2562 | ||
2563 | unsigned | |
2564 | get_gimple_rhs_num_ops (enum tree_code code) | |
2565 | { | |
2566 | enum gimple_rhs_class rhs_class = get_gimple_rhs_class (code); | |
2567 | ||
2568 | if (rhs_class == GIMPLE_UNARY_RHS || rhs_class == GIMPLE_SINGLE_RHS) | |
2569 | return 1; | |
2570 | else if (rhs_class == GIMPLE_BINARY_RHS) | |
2571 | return 2; | |
00f4f705 | 2572 | else if (rhs_class == GIMPLE_TERNARY_RHS) |
2573 | return 3; | |
75a70cf9 | 2574 | else |
2575 | gcc_unreachable (); | |
2576 | } | |
2577 | ||
2578 | #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \ | |
2579 | (unsigned char) \ | |
2580 | ((TYPE) == tcc_unary ? GIMPLE_UNARY_RHS \ | |
2581 | : ((TYPE) == tcc_binary \ | |
2582 | || (TYPE) == tcc_comparison) ? GIMPLE_BINARY_RHS \ | |
2583 | : ((TYPE) == tcc_constant \ | |
2584 | || (TYPE) == tcc_declaration \ | |
2585 | || (TYPE) == tcc_reference) ? GIMPLE_SINGLE_RHS \ | |
2586 | : ((SYM) == TRUTH_AND_EXPR \ | |
2587 | || (SYM) == TRUTH_OR_EXPR \ | |
2588 | || (SYM) == TRUTH_XOR_EXPR) ? GIMPLE_BINARY_RHS \ | |
2589 | : (SYM) == TRUTH_NOT_EXPR ? GIMPLE_UNARY_RHS \ | |
00f4f705 | 2590 | : ((SYM) == WIDEN_MULT_PLUS_EXPR \ |
b9be572e | 2591 | || (SYM) == WIDEN_MULT_MINUS_EXPR \ |
c86930b0 | 2592 | || (SYM) == DOT_PROD_EXPR \ |
2593 | || (SYM) == REALIGN_LOAD_EXPR \ | |
b9be572e | 2594 | || (SYM) == FMA_EXPR) ? GIMPLE_TERNARY_RHS \ |
75a70cf9 | 2595 | : ((SYM) == COND_EXPR \ |
2596 | || (SYM) == CONSTRUCTOR \ | |
2597 | || (SYM) == OBJ_TYPE_REF \ | |
2598 | || (SYM) == ASSERT_EXPR \ | |
2599 | || (SYM) == ADDR_EXPR \ | |
2600 | || (SYM) == WITH_SIZE_EXPR \ | |
75a70cf9 | 2601 | || (SYM) == SSA_NAME \ |
c86930b0 | 2602 | || (SYM) == VEC_COND_EXPR) ? GIMPLE_SINGLE_RHS \ |
75a70cf9 | 2603 | : GIMPLE_INVALID_RHS), |
2604 | #define END_OF_BASE_TREE_CODES (unsigned char) GIMPLE_INVALID_RHS, | |
2605 | ||
2606 | const unsigned char gimple_rhs_class_table[] = { | |
2607 | #include "all-tree.def" | |
2608 | }; | |
2609 | ||
2610 | #undef DEFTREECODE | |
2611 | #undef END_OF_BASE_TREE_CODES | |
2612 | ||
2613 | /* For the definitive definition of GIMPLE, see doc/tree-ssa.texi. */ | |
2614 | ||
2615 | /* Validation of GIMPLE expressions. */ | |
2616 | ||
75a70cf9 | 2617 | /* Returns true iff T is a valid RHS for an assignment to a renamed |
2618 | user -- or front-end generated artificial -- variable. */ | |
2619 | ||
2620 | bool | |
2621 | is_gimple_reg_rhs (tree t) | |
2622 | { | |
47f11e84 | 2623 | return get_gimple_rhs_class (TREE_CODE (t)) != GIMPLE_INVALID_RHS; |
75a70cf9 | 2624 | } |
2625 | ||
2626 | /* Returns true iff T is a valid RHS for an assignment to an un-renamed | |
2627 | LHS, or for a call argument. */ | |
2628 | ||
2629 | bool | |
2630 | is_gimple_mem_rhs (tree t) | |
2631 | { | |
2632 | /* If we're dealing with a renamable type, either source or dest must be | |
2633 | a renamed variable. */ | |
2634 | if (is_gimple_reg_type (TREE_TYPE (t))) | |
2635 | return is_gimple_val (t); | |
2636 | else | |
47f11e84 | 2637 | return is_gimple_val (t) || is_gimple_lvalue (t); |
75a70cf9 | 2638 | } |
2639 | ||
2640 | /* Return true if T is a valid LHS for a GIMPLE assignment expression. */ | |
2641 | ||
2642 | bool | |
2643 | is_gimple_lvalue (tree t) | |
2644 | { | |
2645 | return (is_gimple_addressable (t) | |
2646 | || TREE_CODE (t) == WITH_SIZE_EXPR | |
2647 | /* These are complex lvalues, but don't have addresses, so they | |
2648 | go here. */ | |
2649 | || TREE_CODE (t) == BIT_FIELD_REF); | |
2650 | } | |
2651 | ||
2652 | /* Return true if T is a GIMPLE condition. */ | |
2653 | ||
2654 | bool | |
2655 | is_gimple_condexpr (tree t) | |
2656 | { | |
2657 | return (is_gimple_val (t) || (COMPARISON_CLASS_P (t) | |
4c76cf91 | 2658 | && !tree_could_throw_p (t) |
75a70cf9 | 2659 | && is_gimple_val (TREE_OPERAND (t, 0)) |
2660 | && is_gimple_val (TREE_OPERAND (t, 1)))); | |
2661 | } | |
2662 | ||
2663 | /* Return true if T is something whose address can be taken. */ | |
2664 | ||
2665 | bool | |
2666 | is_gimple_addressable (tree t) | |
2667 | { | |
182cf5a9 | 2668 | return (is_gimple_id (t) || handled_component_p (t) |
2669 | || TREE_CODE (t) == MEM_REF); | |
75a70cf9 | 2670 | } |
2671 | ||
2672 | /* Return true if T is a valid gimple constant. */ | |
2673 | ||
2674 | bool | |
2675 | is_gimple_constant (const_tree t) | |
2676 | { | |
2677 | switch (TREE_CODE (t)) | |
2678 | { | |
2679 | case INTEGER_CST: | |
2680 | case REAL_CST: | |
2681 | case FIXED_CST: | |
2682 | case STRING_CST: | |
2683 | case COMPLEX_CST: | |
2684 | case VECTOR_CST: | |
2685 | return true; | |
2686 | ||
2687 | /* Vector constant constructors are gimple invariant. */ | |
2688 | case CONSTRUCTOR: | |
2689 | if (TREE_TYPE (t) && TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE) | |
2690 | return TREE_CONSTANT (t); | |
2691 | else | |
2692 | return false; | |
2693 | ||
2694 | default: | |
2695 | return false; | |
2696 | } | |
2697 | } | |
2698 | ||
2699 | /* Return true if T is a gimple address. */ | |
2700 | ||
2701 | bool | |
2702 | is_gimple_address (const_tree t) | |
2703 | { | |
2704 | tree op; | |
2705 | ||
2706 | if (TREE_CODE (t) != ADDR_EXPR) | |
2707 | return false; | |
2708 | ||
2709 | op = TREE_OPERAND (t, 0); | |
2710 | while (handled_component_p (op)) | |
2711 | { | |
2712 | if ((TREE_CODE (op) == ARRAY_REF | |
2713 | || TREE_CODE (op) == ARRAY_RANGE_REF) | |
2714 | && !is_gimple_val (TREE_OPERAND (op, 1))) | |
2715 | return false; | |
2716 | ||
2717 | op = TREE_OPERAND (op, 0); | |
2718 | } | |
2719 | ||
182cf5a9 | 2720 | if (CONSTANT_CLASS_P (op) || TREE_CODE (op) == MEM_REF) |
75a70cf9 | 2721 | return true; |
2722 | ||
2723 | switch (TREE_CODE (op)) | |
2724 | { | |
2725 | case PARM_DECL: | |
2726 | case RESULT_DECL: | |
2727 | case LABEL_DECL: | |
2728 | case FUNCTION_DECL: | |
2729 | case VAR_DECL: | |
2730 | case CONST_DECL: | |
2731 | return true; | |
2732 | ||
2733 | default: | |
2734 | return false; | |
2735 | } | |
2736 | } | |
2737 | ||
b9c94ed7 | 2738 | /* Strip out all handled components that produce invariant |
2739 | offsets. */ | |
75a70cf9 | 2740 | |
b9c94ed7 | 2741 | static const_tree |
2742 | strip_invariant_refs (const_tree op) | |
75a70cf9 | 2743 | { |
75a70cf9 | 2744 | while (handled_component_p (op)) |
2745 | { | |
2746 | switch (TREE_CODE (op)) | |
2747 | { | |
2748 | case ARRAY_REF: | |
2749 | case ARRAY_RANGE_REF: | |
2750 | if (!is_gimple_constant (TREE_OPERAND (op, 1)) | |
2751 | || TREE_OPERAND (op, 2) != NULL_TREE | |
2752 | || TREE_OPERAND (op, 3) != NULL_TREE) | |
b9c94ed7 | 2753 | return NULL; |
75a70cf9 | 2754 | break; |
2755 | ||
2756 | case COMPONENT_REF: | |
2757 | if (TREE_OPERAND (op, 2) != NULL_TREE) | |
b9c94ed7 | 2758 | return NULL; |
75a70cf9 | 2759 | break; |
2760 | ||
2761 | default:; | |
2762 | } | |
2763 | op = TREE_OPERAND (op, 0); | |
2764 | } | |
2765 | ||
b9c94ed7 | 2766 | return op; |
2767 | } | |
2768 | ||
2769 | /* Return true if T is a gimple invariant address. */ | |
2770 | ||
2771 | bool | |
2772 | is_gimple_invariant_address (const_tree t) | |
2773 | { | |
2774 | const_tree op; | |
2775 | ||
2776 | if (TREE_CODE (t) != ADDR_EXPR) | |
2777 | return false; | |
2778 | ||
2779 | op = strip_invariant_refs (TREE_OPERAND (t, 0)); | |
182cf5a9 | 2780 | if (!op) |
2781 | return false; | |
b9c94ed7 | 2782 | |
182cf5a9 | 2783 | if (TREE_CODE (op) == MEM_REF) |
2784 | { | |
2785 | const_tree op0 = TREE_OPERAND (op, 0); | |
2786 | return (TREE_CODE (op0) == ADDR_EXPR | |
2787 | && (CONSTANT_CLASS_P (TREE_OPERAND (op0, 0)) | |
2788 | || decl_address_invariant_p (TREE_OPERAND (op0, 0)))); | |
2789 | } | |
2790 | ||
2791 | return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op); | |
b9c94ed7 | 2792 | } |
2793 | ||
2794 | /* Return true if T is a gimple invariant address at IPA level | |
2795 | (so addresses of variables on stack are not allowed). */ | |
2796 | ||
2797 | bool | |
2798 | is_gimple_ip_invariant_address (const_tree t) | |
2799 | { | |
2800 | const_tree op; | |
2801 | ||
2802 | if (TREE_CODE (t) != ADDR_EXPR) | |
2803 | return false; | |
2804 | ||
2805 | op = strip_invariant_refs (TREE_OPERAND (t, 0)); | |
2806 | ||
2807 | return op && (CONSTANT_CLASS_P (op) || decl_address_ip_invariant_p (op)); | |
75a70cf9 | 2808 | } |
2809 | ||
2810 | /* Return true if T is a GIMPLE minimal invariant. It's a restricted | |
2811 | form of function invariant. */ | |
2812 | ||
2813 | bool | |
2814 | is_gimple_min_invariant (const_tree t) | |
2815 | { | |
2816 | if (TREE_CODE (t) == ADDR_EXPR) | |
2817 | return is_gimple_invariant_address (t); | |
2818 | ||
2819 | return is_gimple_constant (t); | |
2820 | } | |
2821 | ||
b9c94ed7 | 2822 | /* Return true if T is a GIMPLE interprocedural invariant. It's a restricted |
2823 | form of gimple minimal invariant. */ | |
2824 | ||
2825 | bool | |
2826 | is_gimple_ip_invariant (const_tree t) | |
2827 | { | |
2828 | if (TREE_CODE (t) == ADDR_EXPR) | |
2829 | return is_gimple_ip_invariant_address (t); | |
2830 | ||
2831 | return is_gimple_constant (t); | |
2832 | } | |
2833 | ||
75a70cf9 | 2834 | /* Return true if T looks like a valid GIMPLE statement. */ |
2835 | ||
2836 | bool | |
2837 | is_gimple_stmt (tree t) | |
2838 | { | |
2839 | const enum tree_code code = TREE_CODE (t); | |
2840 | ||
2841 | switch (code) | |
2842 | { | |
2843 | case NOP_EXPR: | |
2844 | /* The only valid NOP_EXPR is the empty statement. */ | |
2845 | return IS_EMPTY_STMT (t); | |
2846 | ||
2847 | case BIND_EXPR: | |
2848 | case COND_EXPR: | |
2849 | /* These are only valid if they're void. */ | |
2850 | return TREE_TYPE (t) == NULL || VOID_TYPE_P (TREE_TYPE (t)); | |
2851 | ||
2852 | case SWITCH_EXPR: | |
2853 | case GOTO_EXPR: | |
2854 | case RETURN_EXPR: | |
2855 | case LABEL_EXPR: | |
2856 | case CASE_LABEL_EXPR: | |
2857 | case TRY_CATCH_EXPR: | |
2858 | case TRY_FINALLY_EXPR: | |
2859 | case EH_FILTER_EXPR: | |
2860 | case CATCH_EXPR: | |
75a70cf9 | 2861 | case ASM_EXPR: |
75a70cf9 | 2862 | case STATEMENT_LIST: |
2863 | case OMP_PARALLEL: | |
2864 | case OMP_FOR: | |
2865 | case OMP_SECTIONS: | |
2866 | case OMP_SECTION: | |
2867 | case OMP_SINGLE: | |
2868 | case OMP_MASTER: | |
2869 | case OMP_ORDERED: | |
2870 | case OMP_CRITICAL: | |
2871 | case OMP_TASK: | |
2872 | /* These are always void. */ | |
2873 | return true; | |
2874 | ||
2875 | case CALL_EXPR: | |
2876 | case MODIFY_EXPR: | |
2877 | case PREDICT_EXPR: | |
2878 | /* These are valid regardless of their type. */ | |
2879 | return true; | |
2880 | ||
2881 | default: | |
2882 | return false; | |
2883 | } | |
2884 | } | |
2885 | ||
2886 | /* Return true if T is a variable. */ | |
2887 | ||
2888 | bool | |
2889 | is_gimple_variable (tree t) | |
2890 | { | |
2891 | return (TREE_CODE (t) == VAR_DECL | |
2892 | || TREE_CODE (t) == PARM_DECL | |
2893 | || TREE_CODE (t) == RESULT_DECL | |
2894 | || TREE_CODE (t) == SSA_NAME); | |
2895 | } | |
2896 | ||
2897 | /* Return true if T is a GIMPLE identifier (something with an address). */ | |
2898 | ||
2899 | bool | |
2900 | is_gimple_id (tree t) | |
2901 | { | |
2902 | return (is_gimple_variable (t) | |
2903 | || TREE_CODE (t) == FUNCTION_DECL | |
2904 | || TREE_CODE (t) == LABEL_DECL | |
2905 | || TREE_CODE (t) == CONST_DECL | |
2906 | /* Allow string constants, since they are addressable. */ | |
2907 | || TREE_CODE (t) == STRING_CST); | |
2908 | } | |
2909 | ||
2910 | /* Return true if TYPE is a suitable type for a scalar register variable. */ | |
2911 | ||
2912 | bool | |
2913 | is_gimple_reg_type (tree type) | |
2914 | { | |
f09f132b | 2915 | return !AGGREGATE_TYPE_P (type); |
75a70cf9 | 2916 | } |
2917 | ||
2918 | /* Return true if T is a non-aggregate register variable. */ | |
2919 | ||
2920 | bool | |
2921 | is_gimple_reg (tree t) | |
2922 | { | |
2923 | if (TREE_CODE (t) == SSA_NAME) | |
2924 | t = SSA_NAME_VAR (t); | |
2925 | ||
75a70cf9 | 2926 | if (!is_gimple_variable (t)) |
2927 | return false; | |
2928 | ||
2929 | if (!is_gimple_reg_type (TREE_TYPE (t))) | |
2930 | return false; | |
2931 | ||
2932 | /* A volatile decl is not acceptable because we can't reuse it as | |
2933 | needed. We need to copy it into a temp first. */ | |
2934 | if (TREE_THIS_VOLATILE (t)) | |
2935 | return false; | |
2936 | ||
2937 | /* We define "registers" as things that can be renamed as needed, | |
2938 | which with our infrastructure does not apply to memory. */ | |
2939 | if (needs_to_live_in_memory (t)) | |
2940 | return false; | |
2941 | ||
2942 | /* Hard register variables are an interesting case. For those that | |
2943 | are call-clobbered, we don't know where all the calls are, since | |
2944 | we don't (want to) take into account which operations will turn | |
2945 | into libcalls at the rtl level. For those that are call-saved, | |
2946 | we don't currently model the fact that calls may in fact change | |
2947 | global hard registers, nor do we examine ASM_CLOBBERS at the tree | |
2948 | level, and so miss variable changes that might imply. All around, | |
2949 | it seems safest to not do too much optimization with these at the | |
2950 | tree level at all. We'll have to rely on the rtl optimizers to | |
2951 | clean this up, as there we've got all the appropriate bits exposed. */ | |
2952 | if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t)) | |
2953 | return false; | |
2954 | ||
f09f132b | 2955 | /* Complex and vector values must have been put into SSA-like form. |
2956 | That is, no assignments to the individual components. */ | |
2957 | if (TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE | |
2958 | || TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE) | |
2959 | return DECL_GIMPLE_REG_P (t); | |
2960 | ||
75a70cf9 | 2961 | return true; |
2962 | } | |
2963 | ||
2964 | ||
75a70cf9 | 2965 | /* Return true if T is a GIMPLE variable whose address is not needed. */ |
2966 | ||
2967 | bool | |
2968 | is_gimple_non_addressable (tree t) | |
2969 | { | |
2970 | if (TREE_CODE (t) == SSA_NAME) | |
2971 | t = SSA_NAME_VAR (t); | |
2972 | ||
2973 | return (is_gimple_variable (t) && ! needs_to_live_in_memory (t)); | |
2974 | } | |
2975 | ||
2976 | /* Return true if T is a GIMPLE rvalue, i.e. an identifier or a constant. */ | |
2977 | ||
2978 | bool | |
2979 | is_gimple_val (tree t) | |
2980 | { | |
2981 | /* Make loads from volatiles and memory vars explicit. */ | |
2982 | if (is_gimple_variable (t) | |
2983 | && is_gimple_reg_type (TREE_TYPE (t)) | |
2984 | && !is_gimple_reg (t)) | |
2985 | return false; | |
2986 | ||
75a70cf9 | 2987 | return (is_gimple_variable (t) || is_gimple_min_invariant (t)); |
2988 | } | |
2989 | ||
2990 | /* Similarly, but accept hard registers as inputs to asm statements. */ | |
2991 | ||
2992 | bool | |
2993 | is_gimple_asm_val (tree t) | |
2994 | { | |
2995 | if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t)) | |
2996 | return true; | |
2997 | ||
2998 | return is_gimple_val (t); | |
2999 | } | |
3000 | ||
3001 | /* Return true if T is a GIMPLE minimal lvalue. */ | |
3002 | ||
3003 | bool | |
3004 | is_gimple_min_lval (tree t) | |
3005 | { | |
47f11e84 | 3006 | if (!(t = CONST_CAST_TREE (strip_invariant_refs (t)))) |
3007 | return false; | |
182cf5a9 | 3008 | return (is_gimple_id (t) || TREE_CODE (t) == MEM_REF); |
75a70cf9 | 3009 | } |
3010 | ||
75a70cf9 | 3011 | /* Return true if T is a valid function operand of a CALL_EXPR. */ |
3012 | ||
3013 | bool | |
3014 | is_gimple_call_addr (tree t) | |
3015 | { | |
3016 | return (TREE_CODE (t) == OBJ_TYPE_REF || is_gimple_val (t)); | |
3017 | } | |
3018 | ||
182cf5a9 | 3019 | /* Return true if T is a valid address operand of a MEM_REF. */ |
3020 | ||
3021 | bool | |
3022 | is_gimple_mem_ref_addr (tree t) | |
3023 | { | |
3024 | return (is_gimple_reg (t) | |
3025 | || TREE_CODE (t) == INTEGER_CST | |
3026 | || (TREE_CODE (t) == ADDR_EXPR | |
3027 | && (CONSTANT_CLASS_P (TREE_OPERAND (t, 0)) | |
3028 | || decl_address_invariant_p (TREE_OPERAND (t, 0))))); | |
3029 | } | |
3030 | ||
75a70cf9 | 3031 | /* If T makes a function call, return the corresponding CALL_EXPR operand. |
3032 | Otherwise, return NULL_TREE. */ | |
3033 | ||
3034 | tree | |
3035 | get_call_expr_in (tree t) | |
3036 | { | |
3037 | if (TREE_CODE (t) == MODIFY_EXPR) | |
3038 | t = TREE_OPERAND (t, 1); | |
3039 | if (TREE_CODE (t) == WITH_SIZE_EXPR) | |
3040 | t = TREE_OPERAND (t, 0); | |
3041 | if (TREE_CODE (t) == CALL_EXPR) | |
3042 | return t; | |
3043 | return NULL_TREE; | |
3044 | } | |
3045 | ||
3046 | ||
3047 | /* Given a memory reference expression T, return its base address. | |
3048 | The base address of a memory reference expression is the main | |
3049 | object being referenced. For instance, the base address for | |
3050 | 'array[i].fld[j]' is 'array'. You can think of this as stripping | |
3051 | away the offset part from a memory address. | |
3052 | ||
3053 | This function calls handled_component_p to strip away all the inner | |
3054 | parts of the memory reference until it reaches the base object. */ | |
3055 | ||
3056 | tree | |
3057 | get_base_address (tree t) | |
3058 | { | |
3059 | while (handled_component_p (t)) | |
3060 | t = TREE_OPERAND (t, 0); | |
48e1416a | 3061 | |
28daba6f | 3062 | if ((TREE_CODE (t) == MEM_REF |
3063 | || TREE_CODE (t) == TARGET_MEM_REF) | |
182cf5a9 | 3064 | && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR) |
3065 | t = TREE_OPERAND (TREE_OPERAND (t, 0), 0); | |
3066 | ||
551732eb | 3067 | if (TREE_CODE (t) == SSA_NAME |
3068 | || DECL_P (t) | |
75a70cf9 | 3069 | || TREE_CODE (t) == STRING_CST |
3070 | || TREE_CODE (t) == CONSTRUCTOR | |
182cf5a9 | 3071 | || INDIRECT_REF_P (t) |
28daba6f | 3072 | || TREE_CODE (t) == MEM_REF |
3073 | || TREE_CODE (t) == TARGET_MEM_REF) | |
75a70cf9 | 3074 | return t; |
3075 | else | |
3076 | return NULL_TREE; | |
3077 | } | |
3078 | ||
3079 | void | |
3080 | recalculate_side_effects (tree t) | |
3081 | { | |
3082 | enum tree_code code = TREE_CODE (t); | |
3083 | int len = TREE_OPERAND_LENGTH (t); | |
3084 | int i; | |
3085 | ||
3086 | switch (TREE_CODE_CLASS (code)) | |
3087 | { | |
3088 | case tcc_expression: | |
3089 | switch (code) | |
3090 | { | |
3091 | case INIT_EXPR: | |
3092 | case MODIFY_EXPR: | |
3093 | case VA_ARG_EXPR: | |
3094 | case PREDECREMENT_EXPR: | |
3095 | case PREINCREMENT_EXPR: | |
3096 | case POSTDECREMENT_EXPR: | |
3097 | case POSTINCREMENT_EXPR: | |
3098 | /* All of these have side-effects, no matter what their | |
3099 | operands are. */ | |
3100 | return; | |
3101 | ||
3102 | default: | |
3103 | break; | |
3104 | } | |
3105 | /* Fall through. */ | |
3106 | ||
3107 | case tcc_comparison: /* a comparison expression */ | |
3108 | case tcc_unary: /* a unary arithmetic expression */ | |
3109 | case tcc_binary: /* a binary arithmetic expression */ | |
3110 | case tcc_reference: /* a reference */ | |
3111 | case tcc_vl_exp: /* a function call */ | |
3112 | TREE_SIDE_EFFECTS (t) = TREE_THIS_VOLATILE (t); | |
3113 | for (i = 0; i < len; ++i) | |
3114 | { | |
3115 | tree op = TREE_OPERAND (t, i); | |
3116 | if (op && TREE_SIDE_EFFECTS (op)) | |
3117 | TREE_SIDE_EFFECTS (t) = 1; | |
3118 | } | |
3119 | break; | |
3120 | ||
d2305bfa | 3121 | case tcc_constant: |
3122 | /* No side-effects. */ | |
3123 | return; | |
3124 | ||
75a70cf9 | 3125 | default: |
75a70cf9 | 3126 | gcc_unreachable (); |
3127 | } | |
3128 | } | |
3129 | ||
3130 | /* Canonicalize a tree T for use in a COND_EXPR as conditional. Returns | |
3131 | a canonicalized tree that is valid for a COND_EXPR or NULL_TREE, if | |
3132 | we failed to create one. */ | |
3133 | ||
3134 | tree | |
3135 | canonicalize_cond_expr_cond (tree t) | |
3136 | { | |
abd3c475 | 3137 | /* Strip conversions around boolean operations. */ |
3138 | if (CONVERT_EXPR_P (t) | |
3139 | && truth_value_p (TREE_CODE (TREE_OPERAND (t, 0)))) | |
3140 | t = TREE_OPERAND (t, 0); | |
3141 | ||
75a70cf9 | 3142 | /* For !x use x == 0. */ |
71b5c25e | 3143 | if (TREE_CODE (t) == TRUTH_NOT_EXPR) |
75a70cf9 | 3144 | { |
3145 | tree top0 = TREE_OPERAND (t, 0); | |
3146 | t = build2 (EQ_EXPR, TREE_TYPE (t), | |
3147 | top0, build_int_cst (TREE_TYPE (top0), 0)); | |
3148 | } | |
3149 | /* For cmp ? 1 : 0 use cmp. */ | |
3150 | else if (TREE_CODE (t) == COND_EXPR | |
3151 | && COMPARISON_CLASS_P (TREE_OPERAND (t, 0)) | |
3152 | && integer_onep (TREE_OPERAND (t, 1)) | |
3153 | && integer_zerop (TREE_OPERAND (t, 2))) | |
3154 | { | |
3155 | tree top0 = TREE_OPERAND (t, 0); | |
3156 | t = build2 (TREE_CODE (top0), TREE_TYPE (t), | |
3157 | TREE_OPERAND (top0, 0), TREE_OPERAND (top0, 1)); | |
3158 | } | |
3159 | ||
3160 | if (is_gimple_condexpr (t)) | |
3161 | return t; | |
3162 | ||
3163 | return NULL_TREE; | |
3164 | } | |
3165 | ||
09c20c11 | 3166 | /* Build a GIMPLE_CALL identical to STMT but skipping the arguments in |
3167 | the positions marked by the set ARGS_TO_SKIP. */ | |
3168 | ||
5afe38fe | 3169 | gimple |
74140efd | 3170 | gimple_call_copy_skip_args (gimple stmt, bitmap args_to_skip) |
5afe38fe | 3171 | { |
3172 | int i; | |
5afe38fe | 3173 | int nargs = gimple_call_num_args (stmt); |
3174 | VEC(tree, heap) *vargs = VEC_alloc (tree, heap, nargs); | |
3175 | gimple new_stmt; | |
3176 | ||
3177 | for (i = 0; i < nargs; i++) | |
3178 | if (!bitmap_bit_p (args_to_skip, i)) | |
3179 | VEC_quick_push (tree, vargs, gimple_call_arg (stmt, i)); | |
3180 | ||
fb049fba | 3181 | if (gimple_call_internal_p (stmt)) |
3182 | new_stmt = gimple_build_call_internal_vec (gimple_call_internal_fn (stmt), | |
3183 | vargs); | |
3184 | else | |
3185 | new_stmt = gimple_build_call_vec (gimple_call_fn (stmt), vargs); | |
5afe38fe | 3186 | VEC_free (tree, heap, vargs); |
3187 | if (gimple_call_lhs (stmt)) | |
3188 | gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt)); | |
3189 | ||
dd277d48 | 3190 | gimple_set_vuse (new_stmt, gimple_vuse (stmt)); |
3191 | gimple_set_vdef (new_stmt, gimple_vdef (stmt)); | |
3192 | ||
5afe38fe | 3193 | gimple_set_block (new_stmt, gimple_block (stmt)); |
3194 | if (gimple_has_location (stmt)) | |
3195 | gimple_set_location (new_stmt, gimple_location (stmt)); | |
91aba934 | 3196 | gimple_call_copy_flags (new_stmt, stmt); |
5afe38fe | 3197 | gimple_call_set_chain (new_stmt, gimple_call_chain (stmt)); |
dd277d48 | 3198 | |
3199 | gimple_set_modified (new_stmt, true); | |
3200 | ||
5afe38fe | 3201 | return new_stmt; |
3202 | } | |
3203 | ||
dd277d48 | 3204 | |
79e191db | 3205 | enum gtc_mode { GTC_MERGE = 0, GTC_DIAG = 1 }; |
3206 | ||
564cba5f | 3207 | static hashval_t gimple_type_hash (const void *); |
7bfefa9d | 3208 | |
3209 | /* Structure used to maintain a cache of some type pairs compared by | |
3210 | gimple_types_compatible_p when comparing aggregate types. There are | |
a9b8ddbe | 3211 | three possible values for SAME_P: |
7bfefa9d | 3212 | |
3213 | -2: The pair (T1, T2) has just been inserted in the table. | |
7bfefa9d | 3214 | 0: T1 and T2 are different types. |
3215 | 1: T1 and T2 are the same type. | |
3216 | ||
a9b8ddbe | 3217 | The two elements in the SAME_P array are indexed by the comparison |
3218 | mode gtc_mode. */ | |
3219 | ||
7bfefa9d | 3220 | struct type_pair_d |
3221 | { | |
1fc0af12 | 3222 | unsigned int uid1; |
3223 | unsigned int uid2; | |
a9b8ddbe | 3224 | signed char same_p[2]; |
7bfefa9d | 3225 | }; |
3226 | typedef struct type_pair_d *type_pair_t; | |
93f1467b | 3227 | DEF_VEC_P(type_pair_t); |
3228 | DEF_VEC_ALLOC_P(type_pair_t,heap); | |
3229 | ||
b2640e03 | 3230 | #define GIMPLE_TYPE_PAIR_SIZE 16381 |
3231 | struct type_pair_d *type_pair_cache; | |
7bfefa9d | 3232 | |
7bfefa9d | 3233 | |
3234 | /* Lookup the pair of types T1 and T2 in *VISITED_P. Insert a new | |
3235 | entry if none existed. */ | |
3236 | ||
b2640e03 | 3237 | static inline type_pair_t |
3238 | lookup_type_pair (tree t1, tree t2) | |
7bfefa9d | 3239 | { |
b2640e03 | 3240 | unsigned int index; |
3241 | unsigned int uid1, uid2; | |
7bfefa9d | 3242 | |
b2640e03 | 3243 | if (type_pair_cache == NULL) |
3244 | type_pair_cache = XCNEWVEC (struct type_pair_d, GIMPLE_TYPE_PAIR_SIZE); | |
7bfefa9d | 3245 | |
4075ce4a | 3246 | if (TYPE_UID (t1) < TYPE_UID (t2)) |
3247 | { | |
b2640e03 | 3248 | uid1 = TYPE_UID (t1); |
3249 | uid2 = TYPE_UID (t2); | |
4075ce4a | 3250 | } |
3251 | else | |
3252 | { | |
b2640e03 | 3253 | uid1 = TYPE_UID (t2); |
3254 | uid2 = TYPE_UID (t1); | |
4075ce4a | 3255 | } |
b2640e03 | 3256 | gcc_checking_assert (uid1 != uid2); |
7bfefa9d | 3257 | |
b2640e03 | 3258 | /* iterative_hash_hashval_t imply an function calls. |
3259 | We know that UIDS are in limited range. */ | |
3260 | index = ((((unsigned HOST_WIDE_INT)uid1 << HOST_BITS_PER_WIDE_INT / 2) + uid2) | |
3261 | % GIMPLE_TYPE_PAIR_SIZE); | |
3262 | if (type_pair_cache [index].uid1 == uid1 | |
3263 | && type_pair_cache [index].uid2 == uid2) | |
3264 | return &type_pair_cache[index]; | |
7bfefa9d | 3265 | |
b2640e03 | 3266 | type_pair_cache [index].uid1 = uid1; |
3267 | type_pair_cache [index].uid2 = uid2; | |
3268 | type_pair_cache [index].same_p[0] = -2; | |
3269 | type_pair_cache [index].same_p[1] = -2; | |
3270 | ||
3271 | return &type_pair_cache[index]; | |
7bfefa9d | 3272 | } |
3273 | ||
93f1467b | 3274 | /* Per pointer state for the SCC finding. The on_sccstack flag |
3275 | is not strictly required, it is true when there is no hash value | |
3276 | recorded for the type and false otherwise. But querying that | |
3277 | is slower. */ | |
3278 | ||
3279 | struct sccs | |
3280 | { | |
3281 | unsigned int dfsnum; | |
3282 | unsigned int low; | |
3283 | bool on_sccstack; | |
3284 | union { | |
3285 | hashval_t hash; | |
a9b8ddbe | 3286 | signed char same_p; |
93f1467b | 3287 | } u; |
3288 | }; | |
3289 | ||
3290 | static unsigned int next_dfs_num; | |
3291 | static unsigned int gtc_next_dfs_num; | |
7bfefa9d | 3292 | |
7a3ccc3b | 3293 | |
3294 | /* GIMPLE type merging cache. A direct-mapped cache based on TYPE_UID. */ | |
3295 | ||
3296 | typedef struct GTY(()) gimple_type_leader_entry_s { | |
3297 | tree type; | |
3298 | tree leader; | |
3299 | } gimple_type_leader_entry; | |
3300 | ||
3301 | #define GIMPLE_TYPE_LEADER_SIZE 16381 | |
5cd33168 | 3302 | static GTY((deletable, length("GIMPLE_TYPE_LEADER_SIZE"))) |
3303 | gimple_type_leader_entry *gimple_type_leader; | |
7a3ccc3b | 3304 | |
3305 | /* Lookup an existing leader for T and return it or NULL_TREE, if | |
3306 | there is none in the cache. */ | |
3307 | ||
4075ce4a | 3308 | static inline tree |
7a3ccc3b | 3309 | gimple_lookup_type_leader (tree t) |
3310 | { | |
3311 | gimple_type_leader_entry *leader; | |
3312 | ||
3313 | if (!gimple_type_leader) | |
3314 | return NULL_TREE; | |
3315 | ||
3316 | leader = &gimple_type_leader[TYPE_UID (t) % GIMPLE_TYPE_LEADER_SIZE]; | |
3317 | if (leader->type != t) | |
3318 | return NULL_TREE; | |
3319 | ||
3320 | return leader->leader; | |
3321 | } | |
3322 | ||
a9a597e0 | 3323 | /* Return true if T1 and T2 have the same name. If FOR_COMPLETION_P is |
3324 | true then if any type has no name return false, otherwise return | |
3325 | true if both types have no names. */ | |
7bfefa9d | 3326 | |
3327 | static bool | |
1ca0809c | 3328 | compare_type_names_p (tree t1, tree t2) |
7bfefa9d | 3329 | { |
3330 | tree name1 = TYPE_NAME (t1); | |
3331 | tree name2 = TYPE_NAME (t2); | |
3332 | ||
a9a597e0 | 3333 | if (name1 && TREE_CODE (name1) == TYPE_DECL) |
1ca0809c | 3334 | name1 = DECL_NAME (name1); |
3335 | gcc_checking_assert (!name1 || TREE_CODE (name1) == IDENTIFIER_NODE); | |
7bfefa9d | 3336 | |
a9a597e0 | 3337 | if (name2 && TREE_CODE (name2) == TYPE_DECL) |
1ca0809c | 3338 | name2 = DECL_NAME (name2); |
3339 | gcc_checking_assert (!name2 || TREE_CODE (name2) == IDENTIFIER_NODE); | |
7bfefa9d | 3340 | |
3341 | /* Identifiers can be compared with pointer equality rather | |
3342 | than a string comparison. */ | |
3343 | if (name1 == name2) | |
3344 | return true; | |
3345 | ||
3346 | return false; | |
3347 | } | |
3348 | ||
a1072234 | 3349 | /* Return true if the field decls F1 and F2 are at the same offset. |
3350 | ||
e7e718d0 | 3351 | This is intended to be used on GIMPLE types only. */ |
7bfefa9d | 3352 | |
67b18080 | 3353 | bool |
a1072234 | 3354 | gimple_compare_field_offset (tree f1, tree f2) |
7bfefa9d | 3355 | { |
3356 | if (DECL_OFFSET_ALIGN (f1) == DECL_OFFSET_ALIGN (f2)) | |
a1072234 | 3357 | { |
3358 | tree offset1 = DECL_FIELD_OFFSET (f1); | |
3359 | tree offset2 = DECL_FIELD_OFFSET (f2); | |
3360 | return ((offset1 == offset2 | |
3361 | /* Once gimplification is done, self-referential offsets are | |
3362 | instantiated as operand #2 of the COMPONENT_REF built for | |
3363 | each access and reset. Therefore, they are not relevant | |
3364 | anymore and fields are interchangeable provided that they | |
3365 | represent the same access. */ | |
3366 | || (TREE_CODE (offset1) == PLACEHOLDER_EXPR | |
3367 | && TREE_CODE (offset2) == PLACEHOLDER_EXPR | |
3368 | && (DECL_SIZE (f1) == DECL_SIZE (f2) | |
3369 | || (TREE_CODE (DECL_SIZE (f1)) == PLACEHOLDER_EXPR | |
3370 | && TREE_CODE (DECL_SIZE (f2)) == PLACEHOLDER_EXPR) | |
3371 | || operand_equal_p (DECL_SIZE (f1), DECL_SIZE (f2), 0)) | |
3372 | && DECL_ALIGN (f1) == DECL_ALIGN (f2)) | |
3373 | || operand_equal_p (offset1, offset2, 0)) | |
3374 | && tree_int_cst_equal (DECL_FIELD_BIT_OFFSET (f1), | |
3375 | DECL_FIELD_BIT_OFFSET (f2))); | |
3376 | } | |
7bfefa9d | 3377 | |
3378 | /* Fortran and C do not always agree on what DECL_OFFSET_ALIGN | |
3379 | should be, so handle differing ones specially by decomposing | |
3380 | the offset into a byte and bit offset manually. */ | |
3381 | if (host_integerp (DECL_FIELD_OFFSET (f1), 0) | |
3382 | && host_integerp (DECL_FIELD_OFFSET (f2), 0)) | |
3383 | { | |
3384 | unsigned HOST_WIDE_INT byte_offset1, byte_offset2; | |
3385 | unsigned HOST_WIDE_INT bit_offset1, bit_offset2; | |
3386 | bit_offset1 = TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f1)); | |
3387 | byte_offset1 = (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f1)) | |
3388 | + bit_offset1 / BITS_PER_UNIT); | |
3389 | bit_offset2 = TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f2)); | |
3390 | byte_offset2 = (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f2)) | |
3391 | + bit_offset2 / BITS_PER_UNIT); | |
3392 | if (byte_offset1 != byte_offset2) | |
3393 | return false; | |
3394 | return bit_offset1 % BITS_PER_UNIT == bit_offset2 % BITS_PER_UNIT; | |
3395 | } | |
3396 | ||
3397 | return false; | |
3398 | } | |
3399 | ||
93f1467b | 3400 | static bool |
564cba5f | 3401 | gimple_types_compatible_p_1 (tree, tree, type_pair_t, |
a9b8ddbe | 3402 | VEC(type_pair_t, heap) **, |
93f1467b | 3403 | struct pointer_map_t *, struct obstack *); |
7bfefa9d | 3404 | |
93f1467b | 3405 | /* DFS visit the edge from the callers type pair with state *STATE to |
3406 | the pair T1, T2 while operating in FOR_MERGING_P mode. | |
3407 | Update the merging status if it is not part of the SCC containing the | |
3408 | callers pair and return it. | |
3409 | SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */ | |
3410 | ||
3411 | static bool | |
564cba5f | 3412 | gtc_visit (tree t1, tree t2, |
93f1467b | 3413 | struct sccs *state, |
3414 | VEC(type_pair_t, heap) **sccstack, | |
3415 | struct pointer_map_t *sccstate, | |
3416 | struct obstack *sccstate_obstack) | |
7bfefa9d | 3417 | { |
93f1467b | 3418 | struct sccs *cstate = NULL; |
3419 | type_pair_t p; | |
3420 | void **slot; | |
564cba5f | 3421 | tree leader1, leader2; |
7bfefa9d | 3422 | |
3423 | /* Check first for the obvious case of pointer identity. */ | |
3424 | if (t1 == t2) | |
93f1467b | 3425 | return true; |
7bfefa9d | 3426 | |
3427 | /* Check that we have two types to compare. */ | |
3428 | if (t1 == NULL_TREE || t2 == NULL_TREE) | |
93f1467b | 3429 | return false; |
7bfefa9d | 3430 | |
3431 | /* Can't be the same type if the types don't have the same code. */ | |
3432 | if (TREE_CODE (t1) != TREE_CODE (t2)) | |
93f1467b | 3433 | return false; |
b612c537 | 3434 | |
3435 | /* Can't be the same type if they have different CV qualifiers. */ | |
3436 | if (TYPE_QUALS (t1) != TYPE_QUALS (t2)) | |
93f1467b | 3437 | return false; |
7bfefa9d | 3438 | |
488a4664 | 3439 | if (TREE_ADDRESSABLE (t1) != TREE_ADDRESSABLE (t2)) |
3440 | return false; | |
3441 | ||
3442 | /* Void types and nullptr types are always the same. */ | |
3443 | if (TREE_CODE (t1) == VOID_TYPE | |
3444 | || TREE_CODE (t1) == NULLPTR_TYPE) | |
93f1467b | 3445 | return true; |
7bfefa9d | 3446 | |
488a4664 | 3447 | /* Can't be the same type if they have different alignment or mode. */ |
3448 | if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2) | |
3449 | || TYPE_MODE (t1) != TYPE_MODE (t2)) | |
3450 | return false; | |
3451 | ||
895241b4 | 3452 | /* Do some simple checks before doing three hashtable queries. */ |
b612c537 | 3453 | if (INTEGRAL_TYPE_P (t1) |
3454 | || SCALAR_FLOAT_TYPE_P (t1) | |
3455 | || FIXED_POINT_TYPE_P (t1) | |
3456 | || TREE_CODE (t1) == VECTOR_TYPE | |
bc9c6c8a | 3457 | || TREE_CODE (t1) == COMPLEX_TYPE |
488a4664 | 3458 | || TREE_CODE (t1) == OFFSET_TYPE |
3459 | || POINTER_TYPE_P (t1)) | |
b612c537 | 3460 | { |
488a4664 | 3461 | /* Can't be the same type if they have different sign or precision. */ |
3462 | if (TYPE_PRECISION (t1) != TYPE_PRECISION (t2) | |
b612c537 | 3463 | || TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2)) |
93f1467b | 3464 | return false; |
b612c537 | 3465 | |
3466 | if (TREE_CODE (t1) == INTEGER_TYPE | |
3467 | && (TYPE_IS_SIZETYPE (t1) != TYPE_IS_SIZETYPE (t2) | |
3468 | || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2))) | |
93f1467b | 3469 | return false; |
b612c537 | 3470 | |
3471 | /* That's all we need to check for float and fixed-point types. */ | |
3472 | if (SCALAR_FLOAT_TYPE_P (t1) | |
3473 | || FIXED_POINT_TYPE_P (t1)) | |
93f1467b | 3474 | return true; |
b612c537 | 3475 | |
488a4664 | 3476 | /* For other types fall thru to more complex checks. */ |
b612c537 | 3477 | } |
7bfefa9d | 3478 | |
488a4664 | 3479 | /* If the types have been previously registered and found equal |
3480 | they still are. */ | |
3481 | leader1 = gimple_lookup_type_leader (t1); | |
3482 | leader2 = gimple_lookup_type_leader (t2); | |
3483 | if (leader1 == t2 | |
3484 | || t1 == leader2 | |
3485 | || (leader1 && leader1 == leader2)) | |
3486 | return true; | |
895241b4 | 3487 | |
7bfefa9d | 3488 | /* If the hash values of t1 and t2 are different the types can't |
3489 | possibly be the same. This helps keeping the type-pair hashtable | |
3490 | small, only tracking comparisons for hash collisions. */ | |
564cba5f | 3491 | if (gimple_type_hash (t1) != gimple_type_hash (t2)) |
93f1467b | 3492 | return false; |
7bfefa9d | 3493 | |
93f1467b | 3494 | /* Allocate a new cache entry for this comparison. */ |
b2640e03 | 3495 | p = lookup_type_pair (t1, t2); |
564cba5f | 3496 | if (p->same_p[GTC_MERGE] == 0 || p->same_p[GTC_MERGE] == 1) |
7bfefa9d | 3497 | { |
3498 | /* We have already decided whether T1 and T2 are the | |
3499 | same, return the cached result. */ | |
564cba5f | 3500 | return p->same_p[GTC_MERGE] == 1; |
7bfefa9d | 3501 | } |
93f1467b | 3502 | |
93f1467b | 3503 | if ((slot = pointer_map_contains (sccstate, p)) != NULL) |
3504 | cstate = (struct sccs *)*slot; | |
1171c3e4 | 3505 | /* Not yet visited. DFS recurse. */ |
93f1467b | 3506 | if (!cstate) |
7bfefa9d | 3507 | { |
564cba5f | 3508 | gimple_types_compatible_p_1 (t1, t2, p, |
1171c3e4 | 3509 | sccstack, sccstate, sccstate_obstack); |
3510 | cstate = (struct sccs *)* pointer_map_contains (sccstate, p); | |
93f1467b | 3511 | state->low = MIN (state->low, cstate->low); |
7bfefa9d | 3512 | } |
1171c3e4 | 3513 | /* If the type is still on the SCC stack adjust the parents low. */ |
93f1467b | 3514 | if (cstate->dfsnum < state->dfsnum |
3515 | && cstate->on_sccstack) | |
3516 | state->low = MIN (cstate->dfsnum, state->low); | |
7bfefa9d | 3517 | |
1171c3e4 | 3518 | /* Return the current lattice value. We start with an equality |
3519 | assumption so types part of a SCC will be optimistically | |
3520 | treated equal unless proven otherwise. */ | |
3521 | return cstate->u.same_p; | |
93f1467b | 3522 | } |
3523 | ||
3524 | /* Worker for gimple_types_compatible. | |
3525 | SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */ | |
3526 | ||
3527 | static bool | |
564cba5f | 3528 | gimple_types_compatible_p_1 (tree t1, tree t2, type_pair_t p, |
93f1467b | 3529 | VEC(type_pair_t, heap) **sccstack, |
3530 | struct pointer_map_t *sccstate, | |
3531 | struct obstack *sccstate_obstack) | |
3532 | { | |
93f1467b | 3533 | struct sccs *state; |
3534 | ||
564cba5f | 3535 | gcc_assert (p->same_p[GTC_MERGE] == -2); |
7bfefa9d | 3536 | |
93f1467b | 3537 | state = XOBNEW (sccstate_obstack, struct sccs); |
3538 | *pointer_map_insert (sccstate, p) = state; | |
3539 | ||
3540 | VEC_safe_push (type_pair_t, heap, *sccstack, p); | |
3541 | state->dfsnum = gtc_next_dfs_num++; | |
3542 | state->low = state->dfsnum; | |
3543 | state->on_sccstack = true; | |
1171c3e4 | 3544 | /* Start with an equality assumption. As we DFS recurse into child |
3545 | SCCs this assumption may get revisited. */ | |
3546 | state->u.same_p = 1; | |
7bfefa9d | 3547 | |
9c759c0a | 3548 | /* The struct tags shall compare equal. */ |
1ca0809c | 3549 | if (!compare_type_names_p (t1, t2)) |
9c759c0a | 3550 | goto different_types; |
3551 | ||
7bfefa9d | 3552 | /* If their attributes are not the same they can't be the same type. */ |
3553 | if (!attribute_list_equal (TYPE_ATTRIBUTES (t1), TYPE_ATTRIBUTES (t2))) | |
3554 | goto different_types; | |
3555 | ||
7bfefa9d | 3556 | /* Do type-specific comparisons. */ |
3557 | switch (TREE_CODE (t1)) | |
3558 | { | |
93f1467b | 3559 | case VECTOR_TYPE: |
3560 | case COMPLEX_TYPE: | |
564cba5f | 3561 | if (!gtc_visit (TREE_TYPE (t1), TREE_TYPE (t2), |
93f1467b | 3562 | state, sccstack, sccstate, sccstate_obstack)) |
3563 | goto different_types; | |
3564 | goto same_types; | |
3565 | ||
7bfefa9d | 3566 | case ARRAY_TYPE: |
3567 | /* Array types are the same if the element types are the same and | |
3568 | the number of elements are the same. */ | |
564cba5f | 3569 | if (!gtc_visit (TREE_TYPE (t1), TREE_TYPE (t2), |
93f1467b | 3570 | state, sccstack, sccstate, sccstate_obstack) |
b612c537 | 3571 | || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2) |
3572 | || TYPE_NONALIASED_COMPONENT (t1) != TYPE_NONALIASED_COMPONENT (t2)) | |
7bfefa9d | 3573 | goto different_types; |
3574 | else | |
3575 | { | |
3576 | tree i1 = TYPE_DOMAIN (t1); | |
3577 | tree i2 = TYPE_DOMAIN (t2); | |
3578 | ||
3579 | /* For an incomplete external array, the type domain can be | |
3580 | NULL_TREE. Check this condition also. */ | |
3581 | if (i1 == NULL_TREE && i2 == NULL_TREE) | |
3582 | goto same_types; | |
3583 | else if (i1 == NULL_TREE || i2 == NULL_TREE) | |
3584 | goto different_types; | |
3585 | /* If for a complete array type the possibly gimplified sizes | |
3586 | are different the types are different. */ | |
3587 | else if (((TYPE_SIZE (i1) != NULL) ^ (TYPE_SIZE (i2) != NULL)) | |
3588 | || (TYPE_SIZE (i1) | |
3589 | && TYPE_SIZE (i2) | |
3590 | && !operand_equal_p (TYPE_SIZE (i1), TYPE_SIZE (i2), 0))) | |
3591 | goto different_types; | |
3592 | else | |
3593 | { | |
3594 | tree min1 = TYPE_MIN_VALUE (i1); | |
3595 | tree min2 = TYPE_MIN_VALUE (i2); | |
3596 | tree max1 = TYPE_MAX_VALUE (i1); | |
3597 | tree max2 = TYPE_MAX_VALUE (i2); | |
3598 | ||
3599 | /* The minimum/maximum values have to be the same. */ | |
3600 | if ((min1 == min2 | |
c9d19f43 | 3601 | || (min1 && min2 |
3602 | && ((TREE_CODE (min1) == PLACEHOLDER_EXPR | |
3603 | && TREE_CODE (min2) == PLACEHOLDER_EXPR) | |
3604 | || operand_equal_p (min1, min2, 0)))) | |
7bfefa9d | 3605 | && (max1 == max2 |
c9d19f43 | 3606 | || (max1 && max2 |
3607 | && ((TREE_CODE (max1) == PLACEHOLDER_EXPR | |
3608 | && TREE_CODE (max2) == PLACEHOLDER_EXPR) | |
3609 | || operand_equal_p (max1, max2, 0))))) | |
7bfefa9d | 3610 | goto same_types; |
3611 | else | |
3612 | goto different_types; | |
3613 | } | |
3614 | } | |
3615 | ||
3616 | case METHOD_TYPE: | |
3617 | /* Method types should belong to the same class. */ | |
93f1467b | 3618 | if (!gtc_visit (TYPE_METHOD_BASETYPE (t1), TYPE_METHOD_BASETYPE (t2), |
564cba5f | 3619 | state, sccstack, sccstate, sccstate_obstack)) |
7bfefa9d | 3620 | goto different_types; |
3621 | ||
3622 | /* Fallthru */ | |
3623 | ||
3624 | case FUNCTION_TYPE: | |
3625 | /* Function types are the same if the return type and arguments types | |
3626 | are the same. */ | |
564cba5f | 3627 | if (!gtc_visit (TREE_TYPE (t1), TREE_TYPE (t2), |
3628 | state, sccstack, sccstate, sccstate_obstack)) | |
816ede17 | 3629 | goto different_types; |
3630 | ||
309303cf | 3631 | if (!comp_type_attributes (t1, t2)) |
7bfefa9d | 3632 | goto different_types; |
816ede17 | 3633 | |
3634 | if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2)) | |
3635 | goto same_types; | |
7bfefa9d | 3636 | else |
3637 | { | |
816ede17 | 3638 | tree parms1, parms2; |
7bfefa9d | 3639 | |
816ede17 | 3640 | for (parms1 = TYPE_ARG_TYPES (t1), parms2 = TYPE_ARG_TYPES (t2); |
3641 | parms1 && parms2; | |
3642 | parms1 = TREE_CHAIN (parms1), parms2 = TREE_CHAIN (parms2)) | |
7bfefa9d | 3643 | { |
564cba5f | 3644 | if (!gtc_visit (TREE_VALUE (parms1), TREE_VALUE (parms2), |
3645 | state, sccstack, sccstate, sccstate_obstack)) | |
7bfefa9d | 3646 | goto different_types; |
7bfefa9d | 3647 | } |
816ede17 | 3648 | |
3649 | if (parms1 || parms2) | |
3650 | goto different_types; | |
3651 | ||
3652 | goto same_types; | |
7bfefa9d | 3653 | } |
3654 | ||
bc9c6c8a | 3655 | case OFFSET_TYPE: |
3656 | { | |
564cba5f | 3657 | if (!gtc_visit (TREE_TYPE (t1), TREE_TYPE (t2), |
93f1467b | 3658 | state, sccstack, sccstate, sccstate_obstack) |
3659 | || !gtc_visit (TYPE_OFFSET_BASETYPE (t1), | |
564cba5f | 3660 | TYPE_OFFSET_BASETYPE (t2), |
93f1467b | 3661 | state, sccstack, sccstate, sccstate_obstack)) |
bc9c6c8a | 3662 | goto different_types; |
3663 | ||
3664 | goto same_types; | |
3665 | } | |
3666 | ||
7bfefa9d | 3667 | case POINTER_TYPE: |
3668 | case REFERENCE_TYPE: | |
66bd377c | 3669 | { |
3670 | /* If the two pointers have different ref-all attributes, | |
3671 | they can't be the same type. */ | |
3672 | if (TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2)) | |
3673 | goto different_types; | |
7bfefa9d | 3674 | |
66bd377c | 3675 | /* Otherwise, pointer and reference types are the same if the |
3676 | pointed-to types are the same. */ | |
564cba5f | 3677 | if (gtc_visit (TREE_TYPE (t1), TREE_TYPE (t2), |
93f1467b | 3678 | state, sccstack, sccstate, sccstate_obstack)) |
66bd377c | 3679 | goto same_types; |
3680 | ||
3681 | goto different_types; | |
3682 | } | |
7bfefa9d | 3683 | |
b612c537 | 3684 | case INTEGER_TYPE: |
3685 | case BOOLEAN_TYPE: | |
3686 | { | |
3687 | tree min1 = TYPE_MIN_VALUE (t1); | |
3688 | tree max1 = TYPE_MAX_VALUE (t1); | |
3689 | tree min2 = TYPE_MIN_VALUE (t2); | |
3690 | tree max2 = TYPE_MAX_VALUE (t2); | |
3691 | bool min_equal_p = false; | |
3692 | bool max_equal_p = false; | |
3693 | ||
3694 | /* If either type has a minimum value, the other type must | |
3695 | have the same. */ | |
3696 | if (min1 == NULL_TREE && min2 == NULL_TREE) | |
3697 | min_equal_p = true; | |
3698 | else if (min1 && min2 && operand_equal_p (min1, min2, 0)) | |
3699 | min_equal_p = true; | |
3700 | ||
3701 | /* Likewise, if either type has a maximum value, the other | |
3702 | type must have the same. */ | |
3703 | if (max1 == NULL_TREE && max2 == NULL_TREE) | |
3704 | max_equal_p = true; | |
3705 | else if (max1 && max2 && operand_equal_p (max1, max2, 0)) | |
3706 | max_equal_p = true; | |
3707 | ||
3708 | if (!min_equal_p || !max_equal_p) | |
3709 | goto different_types; | |
3710 | ||
3711 | goto same_types; | |
3712 | } | |
3713 | ||
7bfefa9d | 3714 | case ENUMERAL_TYPE: |
66bd377c | 3715 | { |
b612c537 | 3716 | /* FIXME lto, we cannot check bounds on enumeral types because |
3717 | different front ends will produce different values. | |
3718 | In C, enumeral types are integers, while in C++ each element | |
3719 | will have its own symbolic value. We should decide how enums | |
3720 | are to be represented in GIMPLE and have each front end lower | |
3721 | to that. */ | |
66bd377c | 3722 | tree v1, v2; |
7bfefa9d | 3723 | |
b612c537 | 3724 | /* For enumeral types, all the values must be the same. */ |
66bd377c | 3725 | if (TYPE_VALUES (t1) == TYPE_VALUES (t2)) |
3726 | goto same_types; | |
7bfefa9d | 3727 | |
66bd377c | 3728 | for (v1 = TYPE_VALUES (t1), v2 = TYPE_VALUES (t2); |
3729 | v1 && v2; | |
3730 | v1 = TREE_CHAIN (v1), v2 = TREE_CHAIN (v2)) | |
3731 | { | |
3732 | tree c1 = TREE_VALUE (v1); | |
3733 | tree c2 = TREE_VALUE (v2); | |
7bfefa9d | 3734 | |
66bd377c | 3735 | if (TREE_CODE (c1) == CONST_DECL) |
3736 | c1 = DECL_INITIAL (c1); | |
7bfefa9d | 3737 | |
66bd377c | 3738 | if (TREE_CODE (c2) == CONST_DECL) |
3739 | c2 = DECL_INITIAL (c2); | |
7bfefa9d | 3740 | |
66bd377c | 3741 | if (tree_int_cst_equal (c1, c2) != 1) |
3742 | goto different_types; | |
c693f407 | 3743 | |
564cba5f | 3744 | if (TREE_PURPOSE (v1) != TREE_PURPOSE (v2)) |
c693f407 | 3745 | goto different_types; |
66bd377c | 3746 | } |
7bfefa9d | 3747 | |
66bd377c | 3748 | /* If one enumeration has more values than the other, they |
3749 | are not the same. */ | |
3750 | if (v1 || v2) | |
3751 | goto different_types; | |
7bfefa9d | 3752 | |
66bd377c | 3753 | goto same_types; |
3754 | } | |
7bfefa9d | 3755 | |
3756 | case RECORD_TYPE: | |
3757 | case UNION_TYPE: | |
3758 | case QUAL_UNION_TYPE: | |
66bd377c | 3759 | { |
3760 | tree f1, f2; | |
7bfefa9d | 3761 | |
66bd377c | 3762 | /* For aggregate types, all the fields must be the same. */ |
3763 | for (f1 = TYPE_FIELDS (t1), f2 = TYPE_FIELDS (t2); | |
3764 | f1 && f2; | |
3765 | f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2)) | |
3766 | { | |
26256e53 | 3767 | /* Different field kinds are not compatible. */ |
3768 | if (TREE_CODE (f1) != TREE_CODE (f2)) | |
3769 | goto different_types; | |
3770 | /* Field decls must have the same name and offset. */ | |
3771 | if (TREE_CODE (f1) == FIELD_DECL | |
3772 | && (DECL_NONADDRESSABLE_P (f1) != DECL_NONADDRESSABLE_P (f2) | |
3773 | || !gimple_compare_field_offset (f1, f2))) | |
3774 | goto different_types; | |
3775 | /* All entities should have the same name and type. */ | |
564cba5f | 3776 | if (DECL_NAME (f1) != DECL_NAME (f2) |
564cba5f | 3777 | || !gtc_visit (TREE_TYPE (f1), TREE_TYPE (f2), |
93f1467b | 3778 | state, sccstack, sccstate, sccstate_obstack)) |
66bd377c | 3779 | goto different_types; |
3780 | } | |
7bfefa9d | 3781 | |
66bd377c | 3782 | /* If one aggregate has more fields than the other, they |
3783 | are not the same. */ | |
3784 | if (f1 || f2) | |
3785 | goto different_types; | |
7bfefa9d | 3786 | |
66bd377c | 3787 | goto same_types; |
3788 | } | |
7bfefa9d | 3789 | |
7bfefa9d | 3790 | default: |
b612c537 | 3791 | gcc_unreachable (); |
7bfefa9d | 3792 | } |
3793 | ||
3794 | /* Common exit path for types that are not compatible. */ | |
3795 | different_types: | |
93f1467b | 3796 | state->u.same_p = 0; |
3797 | goto pop; | |
7bfefa9d | 3798 | |
3799 | /* Common exit path for types that are compatible. */ | |
3800 | same_types: | |
1171c3e4 | 3801 | gcc_assert (state->u.same_p == 1); |
7bfefa9d | 3802 | |
93f1467b | 3803 | pop: |
3804 | if (state->low == state->dfsnum) | |
3805 | { | |
3806 | type_pair_t x; | |
7bfefa9d | 3807 | |
1171c3e4 | 3808 | /* Pop off the SCC and set its cache values to the final |
3809 | comparison result. */ | |
93f1467b | 3810 | do |
3811 | { | |
3812 | struct sccs *cstate; | |
3813 | x = VEC_pop (type_pair_t, *sccstack); | |
3814 | cstate = (struct sccs *)*pointer_map_contains (sccstate, x); | |
3815 | cstate->on_sccstack = false; | |
564cba5f | 3816 | x->same_p[GTC_MERGE] = state->u.same_p; |
93f1467b | 3817 | } |
3818 | while (x != p); | |
3819 | } | |
7bfefa9d | 3820 | |
93f1467b | 3821 | return state->u.same_p; |
3822 | } | |
7bfefa9d | 3823 | |
93f1467b | 3824 | /* Return true iff T1 and T2 are structurally identical. When |
3825 | FOR_MERGING_P is true the an incomplete type and a complete type | |
3826 | are considered different, otherwise they are considered compatible. */ | |
7bfefa9d | 3827 | |
79e191db | 3828 | static bool |
564cba5f | 3829 | gimple_types_compatible_p (tree t1, tree t2) |
7bfefa9d | 3830 | { |
93f1467b | 3831 | VEC(type_pair_t, heap) *sccstack = NULL; |
3832 | struct pointer_map_t *sccstate; | |
3833 | struct obstack sccstate_obstack; | |
3834 | type_pair_t p = NULL; | |
3835 | bool res; | |
564cba5f | 3836 | tree leader1, leader2; |
93f1467b | 3837 | |
3838 | /* Before starting to set up the SCC machinery handle simple cases. */ | |
3839 | ||
3840 | /* Check first for the obvious case of pointer identity. */ | |
3841 | if (t1 == t2) | |
3842 | return true; | |
3843 | ||
3844 | /* Check that we have two types to compare. */ | |
3845 | if (t1 == NULL_TREE || t2 == NULL_TREE) | |
3846 | return false; | |
3847 | ||
93f1467b | 3848 | /* Can't be the same type if the types don't have the same code. */ |
3849 | if (TREE_CODE (t1) != TREE_CODE (t2)) | |
3850 | return false; | |
3851 | ||
3852 | /* Can't be the same type if they have different CV qualifiers. */ | |
3853 | if (TYPE_QUALS (t1) != TYPE_QUALS (t2)) | |
3854 | return false; | |
3855 | ||
488a4664 | 3856 | if (TREE_ADDRESSABLE (t1) != TREE_ADDRESSABLE (t2)) |
3857 | return false; | |
3858 | ||
3859 | /* Void types and nullptr types are always the same. */ | |
3860 | if (TREE_CODE (t1) == VOID_TYPE | |
3861 | || TREE_CODE (t1) == NULLPTR_TYPE) | |
93f1467b | 3862 | return true; |
3863 | ||
488a4664 | 3864 | /* Can't be the same type if they have different alignment or mode. */ |
3865 | if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2) | |
3866 | || TYPE_MODE (t1) != TYPE_MODE (t2)) | |
3867 | return false; | |
3868 | ||
93f1467b | 3869 | /* Do some simple checks before doing three hashtable queries. */ |
3870 | if (INTEGRAL_TYPE_P (t1) | |
3871 | || SCALAR_FLOAT_TYPE_P (t1) | |
3872 | || FIXED_POINT_TYPE_P (t1) | |
3873 | || TREE_CODE (t1) == VECTOR_TYPE | |
3874 | || TREE_CODE (t1) == COMPLEX_TYPE | |
488a4664 | 3875 | || TREE_CODE (t1) == OFFSET_TYPE |
3876 | || POINTER_TYPE_P (t1)) | |
93f1467b | 3877 | { |
488a4664 | 3878 | /* Can't be the same type if they have different sign or precision. */ |
3879 | if (TYPE_PRECISION (t1) != TYPE_PRECISION (t2) | |
93f1467b | 3880 | || TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2)) |
3881 | return false; | |
3882 | ||
3883 | if (TREE_CODE (t1) == INTEGER_TYPE | |
3884 | && (TYPE_IS_SIZETYPE (t1) != TYPE_IS_SIZETYPE (t2) | |
3885 | || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2))) | |
3886 | return false; | |
3887 | ||
3888 | /* That's all we need to check for float and fixed-point types. */ | |
3889 | if (SCALAR_FLOAT_TYPE_P (t1) | |
3890 | || FIXED_POINT_TYPE_P (t1)) | |
3891 | return true; | |
3892 | ||
488a4664 | 3893 | /* For other types fall thru to more complex checks. */ |
93f1467b | 3894 | } |
3895 | ||
488a4664 | 3896 | /* If the types have been previously registered and found equal |
3897 | they still are. */ | |
3898 | leader1 = gimple_lookup_type_leader (t1); | |
3899 | leader2 = gimple_lookup_type_leader (t2); | |
3900 | if (leader1 == t2 | |
3901 | || t1 == leader2 | |
3902 | || (leader1 && leader1 == leader2)) | |
3903 | return true; | |
93f1467b | 3904 | |
3905 | /* If the hash values of t1 and t2 are different the types can't | |
3906 | possibly be the same. This helps keeping the type-pair hashtable | |
3907 | small, only tracking comparisons for hash collisions. */ | |
564cba5f | 3908 | if (gimple_type_hash (t1) != gimple_type_hash (t2)) |
93f1467b | 3909 | return false; |
3910 | ||
3911 | /* If we've visited this type pair before (in the case of aggregates | |
3912 | with self-referential types), and we made a decision, return it. */ | |
b2640e03 | 3913 | p = lookup_type_pair (t1, t2); |
564cba5f | 3914 | if (p->same_p[GTC_MERGE] == 0 || p->same_p[GTC_MERGE] == 1) |
93f1467b | 3915 | { |
3916 | /* We have already decided whether T1 and T2 are the | |
3917 | same, return the cached result. */ | |
564cba5f | 3918 | return p->same_p[GTC_MERGE] == 1; |
93f1467b | 3919 | } |
3920 | ||
3921 | /* Now set up the SCC machinery for the comparison. */ | |
3922 | gtc_next_dfs_num = 1; | |
3923 | sccstate = pointer_map_create (); | |
3924 | gcc_obstack_init (&sccstate_obstack); | |
564cba5f | 3925 | res = gimple_types_compatible_p_1 (t1, t2, p, |
93f1467b | 3926 | &sccstack, sccstate, &sccstate_obstack); |
3927 | VEC_free (type_pair_t, heap, sccstack); | |
3928 | pointer_map_destroy (sccstate); | |
3929 | obstack_free (&sccstate_obstack, NULL); | |
3930 | ||
3931 | return res; | |
3932 | } | |
7bfefa9d | 3933 | |
7bfefa9d | 3934 | |
3935 | static hashval_t | |
3936 | iterative_hash_gimple_type (tree, hashval_t, VEC(tree, heap) **, | |
564cba5f | 3937 | struct pointer_map_t *, struct obstack *); |
7bfefa9d | 3938 | |
3939 | /* DFS visit the edge from the callers type with state *STATE to T. | |
3940 | Update the callers type hash V with the hash for T if it is not part | |
3941 | of the SCC containing the callers type and return it. | |
3942 | SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */ | |
3943 | ||
3944 | static hashval_t | |
3945 | visit (tree t, struct sccs *state, hashval_t v, | |
3946 | VEC (tree, heap) **sccstack, | |
3947 | struct pointer_map_t *sccstate, | |
564cba5f | 3948 | struct obstack *sccstate_obstack) |
7bfefa9d | 3949 | { |
3950 | struct sccs *cstate = NULL; | |
7a52b640 | 3951 | struct tree_int_map m; |
7bfefa9d | 3952 | void **slot; |
3953 | ||
3954 | /* If there is a hash value recorded for this type then it can't | |
3955 | possibly be part of our parent SCC. Simply mix in its hash. */ | |
7a52b640 | 3956 | m.base.from = t; |
564cba5f | 3957 | if ((slot = htab_find_slot (type_hash_cache, &m, NO_INSERT)) |
7a52b640 | 3958 | && *slot) |
3959 | return iterative_hash_hashval_t (((struct tree_int_map *) *slot)->to, v); | |
7bfefa9d | 3960 | |
3961 | if ((slot = pointer_map_contains (sccstate, t)) != NULL) | |
3962 | cstate = (struct sccs *)*slot; | |
3963 | if (!cstate) | |
3964 | { | |
3965 | hashval_t tem; | |
3966 | /* Not yet visited. DFS recurse. */ | |
3967 | tem = iterative_hash_gimple_type (t, v, | |
564cba5f | 3968 | sccstack, sccstate, sccstate_obstack); |
7bfefa9d | 3969 | if (!cstate) |
3970 | cstate = (struct sccs *)* pointer_map_contains (sccstate, t); | |
3971 | state->low = MIN (state->low, cstate->low); | |
3972 | /* If the type is no longer on the SCC stack and thus is not part | |
3973 | of the parents SCC mix in its hash value. Otherwise we will | |
3974 | ignore the type for hashing purposes and return the unaltered | |
3975 | hash value. */ | |
3976 | if (!cstate->on_sccstack) | |
3977 | return tem; | |
3978 | } | |
3979 | if (cstate->dfsnum < state->dfsnum | |
3980 | && cstate->on_sccstack) | |
3981 | state->low = MIN (cstate->dfsnum, state->low); | |
3982 | ||
3983 | /* We are part of our parents SCC, skip this type during hashing | |
3984 | and return the unaltered hash value. */ | |
3985 | return v; | |
3986 | } | |
3987 | ||
a9a597e0 | 3988 | /* Hash NAME with the previous hash value V and return it. */ |
7bfefa9d | 3989 | |
3990 | static hashval_t | |
a9a597e0 | 3991 | iterative_hash_name (tree name, hashval_t v) |
7bfefa9d | 3992 | { |
7bfefa9d | 3993 | if (!name) |
3994 | return v; | |
3995 | if (TREE_CODE (name) == TYPE_DECL) | |
3996 | name = DECL_NAME (name); | |
3997 | if (!name) | |
3998 | return v; | |
3999 | gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE); | |
7bfefa9d | 4000 | return iterative_hash_object (IDENTIFIER_HASH_VALUE (name), v); |
4001 | } | |
4002 | ||
9532776c | 4003 | /* A type, hashvalue pair for sorting SCC members. */ |
4004 | ||
4005 | struct type_hash_pair { | |
4006 | tree type; | |
4007 | hashval_t hash; | |
4008 | }; | |
4009 | ||
4010 | /* Compare two type, hashvalue pairs. */ | |
4011 | ||
4012 | static int | |
4013 | type_hash_pair_compare (const void *p1_, const void *p2_) | |
4014 | { | |
4015 | const struct type_hash_pair *p1 = (const struct type_hash_pair *) p1_; | |
4016 | const struct type_hash_pair *p2 = (const struct type_hash_pair *) p2_; | |
e8dcede0 | 4017 | if (p1->hash < p2->hash) |
4018 | return -1; | |
4019 | else if (p1->hash > p2->hash) | |
4020 | return 1; | |
4021 | return 0; | |
9532776c | 4022 | } |
4023 | ||
7bfefa9d | 4024 | /* Returning a hash value for gimple type TYPE combined with VAL. |
4025 | SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. | |
4026 | ||
4027 | To hash a type we end up hashing in types that are reachable. | |
4028 | Through pointers we can end up with cycles which messes up the | |
4029 | required property that we need to compute the same hash value | |
4030 | for structurally equivalent types. To avoid this we have to | |
4031 | hash all types in a cycle (the SCC) in a commutative way. The | |
4032 | easiest way is to not mix in the hashes of the SCC members at | |
4033 | all. To make this work we have to delay setting the hash | |
4034 | values of the SCC until it is complete. */ | |
4035 | ||
4036 | static hashval_t | |
4037 | iterative_hash_gimple_type (tree type, hashval_t val, | |
4038 | VEC(tree, heap) **sccstack, | |
4039 | struct pointer_map_t *sccstate, | |
564cba5f | 4040 | struct obstack *sccstate_obstack) |
7bfefa9d | 4041 | { |
4042 | hashval_t v; | |
4043 | void **slot; | |
4044 | struct sccs *state; | |
4045 | ||
7a52b640 | 4046 | /* Not visited during this DFS walk. */ |
1b4345f7 | 4047 | gcc_checking_assert (!pointer_map_contains (sccstate, type)); |
7bfefa9d | 4048 | state = XOBNEW (sccstate_obstack, struct sccs); |
4049 | *pointer_map_insert (sccstate, type) = state; | |
4050 | ||
4051 | VEC_safe_push (tree, heap, *sccstack, type); | |
4052 | state->dfsnum = next_dfs_num++; | |
4053 | state->low = state->dfsnum; | |
4054 | state->on_sccstack = true; | |
4055 | ||
4056 | /* Combine a few common features of types so that types are grouped into | |
4057 | smaller sets; when searching for existing matching types to merge, | |
4058 | only existing types having the same features as the new type will be | |
4059 | checked. */ | |
9c759c0a | 4060 | v = iterative_hash_name (TYPE_NAME (type), 0); |
4061 | v = iterative_hash_hashval_t (TREE_CODE (type), v); | |
7bfefa9d | 4062 | v = iterative_hash_hashval_t (TYPE_QUALS (type), v); |
4063 | v = iterative_hash_hashval_t (TREE_ADDRESSABLE (type), v); | |
4064 | ||
4065 | /* Do not hash the types size as this will cause differences in | |
4066 | hash values for the complete vs. the incomplete type variant. */ | |
4067 | ||
4068 | /* Incorporate common features of numerical types. */ | |
4069 | if (INTEGRAL_TYPE_P (type) | |
4070 | || SCALAR_FLOAT_TYPE_P (type) | |
4071 | || FIXED_POINT_TYPE_P (type)) | |
4072 | { | |
4073 | v = iterative_hash_hashval_t (TYPE_PRECISION (type), v); | |
4074 | v = iterative_hash_hashval_t (TYPE_MODE (type), v); | |
4075 | v = iterative_hash_hashval_t (TYPE_UNSIGNED (type), v); | |
4076 | } | |
4077 | ||
4078 | /* For pointer and reference types, fold in information about the type | |
dc9aeee0 | 4079 | pointed to. */ |
7bfefa9d | 4080 | if (POINTER_TYPE_P (type)) |
dc9aeee0 | 4081 | v = visit (TREE_TYPE (type), state, v, |
4082 | sccstack, sccstate, sccstate_obstack); | |
7bfefa9d | 4083 | |
f9a5c96c | 4084 | /* For integer types hash the types min/max values and the string flag. */ |
4085 | if (TREE_CODE (type) == INTEGER_TYPE) | |
4086 | { | |
20b3ad9e | 4087 | /* OMP lowering can introduce error_mark_node in place of |
4088 | random local decls in types. */ | |
4089 | if (TYPE_MIN_VALUE (type) != error_mark_node) | |
4090 | v = iterative_hash_expr (TYPE_MIN_VALUE (type), v); | |
4091 | if (TYPE_MAX_VALUE (type) != error_mark_node) | |
4092 | v = iterative_hash_expr (TYPE_MAX_VALUE (type), v); | |
f9a5c96c | 4093 | v = iterative_hash_hashval_t (TYPE_STRING_FLAG (type), v); |
4094 | } | |
4095 | ||
4096 | /* For array types hash their domain and the string flag. */ | |
4097 | if (TREE_CODE (type) == ARRAY_TYPE | |
4098 | && TYPE_DOMAIN (type)) | |
4099 | { | |
4100 | v = iterative_hash_hashval_t (TYPE_STRING_FLAG (type), v); | |
4101 | v = visit (TYPE_DOMAIN (type), state, v, | |
564cba5f | 4102 | sccstack, sccstate, sccstate_obstack); |
f9a5c96c | 4103 | } |
4104 | ||
4105 | /* Recurse for aggregates with a single element type. */ | |
7bfefa9d | 4106 | if (TREE_CODE (type) == ARRAY_TYPE |
4107 | || TREE_CODE (type) == COMPLEX_TYPE | |
4108 | || TREE_CODE (type) == VECTOR_TYPE) | |
4109 | v = visit (TREE_TYPE (type), state, v, | |
564cba5f | 4110 | sccstack, sccstate, sccstate_obstack); |
7bfefa9d | 4111 | |
4112 | /* Incorporate function return and argument types. */ | |
4113 | if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) | |
4114 | { | |
4115 | unsigned na; | |
4116 | tree p; | |
4117 | ||
4118 | /* For method types also incorporate their parent class. */ | |
4119 | if (TREE_CODE (type) == METHOD_TYPE) | |
4120 | v = visit (TYPE_METHOD_BASETYPE (type), state, v, | |
564cba5f | 4121 | sccstack, sccstate, sccstate_obstack); |
7bfefa9d | 4122 | |
dc9aeee0 | 4123 | /* Check result and argument types. */ |
4124 | v = visit (TREE_TYPE (type), state, v, | |
4125 | sccstack, sccstate, sccstate_obstack); | |
7bfefa9d | 4126 | for (p = TYPE_ARG_TYPES (type), na = 0; p; p = TREE_CHAIN (p)) |
4127 | { | |
dc9aeee0 | 4128 | v = visit (TREE_VALUE (p), state, v, |
4129 | sccstack, sccstate, sccstate_obstack); | |
7bfefa9d | 4130 | na++; |
4131 | } | |
4132 | ||
4133 | v = iterative_hash_hashval_t (na, v); | |
4134 | } | |
4135 | ||
4136 | if (TREE_CODE (type) == RECORD_TYPE | |
4137 | || TREE_CODE (type) == UNION_TYPE | |
4138 | || TREE_CODE (type) == QUAL_UNION_TYPE) | |
4139 | { | |
4140 | unsigned nf; | |
4141 | tree f; | |
4142 | ||
7bfefa9d | 4143 | for (f = TYPE_FIELDS (type), nf = 0; f; f = TREE_CHAIN (f)) |
4144 | { | |
564cba5f | 4145 | v = iterative_hash_name (DECL_NAME (f), v); |
7bfefa9d | 4146 | v = visit (TREE_TYPE (f), state, v, |
564cba5f | 4147 | sccstack, sccstate, sccstate_obstack); |
7bfefa9d | 4148 | nf++; |
4149 | } | |
4150 | ||
4151 | v = iterative_hash_hashval_t (nf, v); | |
4152 | } | |
4153 | ||
4154 | /* Record hash for us. */ | |
93f1467b | 4155 | state->u.hash = v; |
7bfefa9d | 4156 | |
4157 | /* See if we found an SCC. */ | |
4158 | if (state->low == state->dfsnum) | |
4159 | { | |
4160 | tree x; | |
9532776c | 4161 | struct tree_int_map *m; |
7bfefa9d | 4162 | |
4163 | /* Pop off the SCC and set its hash values. */ | |
9532776c | 4164 | x = VEC_pop (tree, *sccstack); |
9532776c | 4165 | /* Optimize SCC size one. */ |
4166 | if (x == type) | |
7bfefa9d | 4167 | { |
f5e139e8 | 4168 | state->on_sccstack = false; |
9532776c | 4169 | m = ggc_alloc_cleared_tree_int_map (); |
7a52b640 | 4170 | m->base.from = x; |
f5e139e8 | 4171 | m->to = v; |
564cba5f | 4172 | slot = htab_find_slot (type_hash_cache, m, INSERT); |
7a52b640 | 4173 | gcc_assert (!*slot); |
4174 | *slot = (void *) m; | |
7bfefa9d | 4175 | } |
9532776c | 4176 | else |
4177 | { | |
f5e139e8 | 4178 | struct sccs *cstate; |
9532776c | 4179 | unsigned first, i, size, j; |
4180 | struct type_hash_pair *pairs; | |
4181 | /* Pop off the SCC and build an array of type, hash pairs. */ | |
4182 | first = VEC_length (tree, *sccstack) - 1; | |
4183 | while (VEC_index (tree, *sccstack, first) != type) | |
4184 | --first; | |
4185 | size = VEC_length (tree, *sccstack) - first + 1; | |
4186 | pairs = XALLOCAVEC (struct type_hash_pair, size); | |
4187 | i = 0; | |
f5e139e8 | 4188 | cstate = (struct sccs *)*pointer_map_contains (sccstate, x); |
4189 | cstate->on_sccstack = false; | |
9532776c | 4190 | pairs[i].type = x; |
4191 | pairs[i].hash = cstate->u.hash; | |
4192 | do | |
4193 | { | |
4194 | x = VEC_pop (tree, *sccstack); | |
4195 | cstate = (struct sccs *)*pointer_map_contains (sccstate, x); | |
4196 | cstate->on_sccstack = false; | |
4197 | ++i; | |
4198 | pairs[i].type = x; | |
4199 | pairs[i].hash = cstate->u.hash; | |
4200 | } | |
4201 | while (x != type); | |
4202 | gcc_assert (i + 1 == size); | |
4203 | /* Sort the arrays of type, hash pairs so that when we mix in | |
4204 | all members of the SCC the hash value becomes independent on | |
4205 | the order we visited the SCC. Disregard hashes equal to | |
4206 | the hash of the type we mix into because we cannot guarantee | |
4207 | a stable sort for those across different TUs. */ | |
4208 | qsort (pairs, size, sizeof (struct type_hash_pair), | |
4209 | type_hash_pair_compare); | |
4210 | for (i = 0; i < size; ++i) | |
4211 | { | |
4212 | hashval_t hash; | |
4213 | m = ggc_alloc_cleared_tree_int_map (); | |
4214 | m->base.from = pairs[i].type; | |
4215 | hash = pairs[i].hash; | |
4216 | /* Skip same hashes. */ | |
4217 | for (j = i + 1; j < size && pairs[j].hash == pairs[i].hash; ++j) | |
4218 | ; | |
4219 | for (; j < size; ++j) | |
4220 | hash = iterative_hash_hashval_t (pairs[j].hash, hash); | |
4221 | for (j = 0; pairs[j].hash != pairs[i].hash; ++j) | |
4222 | hash = iterative_hash_hashval_t (pairs[j].hash, hash); | |
4223 | m->to = hash; | |
f5e139e8 | 4224 | if (pairs[i].type == type) |
4225 | v = hash; | |
9532776c | 4226 | slot = htab_find_slot (type_hash_cache, m, INSERT); |
4227 | gcc_assert (!*slot); | |
4228 | *slot = (void *) m; | |
4229 | } | |
4230 | } | |
7bfefa9d | 4231 | } |
4232 | ||
4233 | return iterative_hash_hashval_t (v, val); | |
4234 | } | |
4235 | ||
4236 | ||
4237 | /* Returns a hash value for P (assumed to be a type). The hash value | |
4238 | is computed using some distinguishing features of the type. Note | |
4239 | that we cannot use pointer hashing here as we may be dealing with | |
4240 | two distinct instances of the same type. | |
4241 | ||
4242 | This function should produce the same hash value for two compatible | |
4243 | types according to gimple_types_compatible_p. */ | |
4244 | ||
4245 | static hashval_t | |
564cba5f | 4246 | gimple_type_hash (const void *p) |
7bfefa9d | 4247 | { |
90e70538 | 4248 | const_tree t = (const_tree) p; |
7bfefa9d | 4249 | VEC(tree, heap) *sccstack = NULL; |
4250 | struct pointer_map_t *sccstate; | |
4251 | struct obstack sccstate_obstack; | |
4252 | hashval_t val; | |
4253 | void **slot; | |
7a52b640 | 4254 | struct tree_int_map m; |
7bfefa9d | 4255 | |
564cba5f | 4256 | if (type_hash_cache == NULL) |
7a52b640 | 4257 | type_hash_cache = htab_create_ggc (512, tree_int_map_hash, |
4258 | tree_int_map_eq, NULL); | |
7bfefa9d | 4259 | |
7a52b640 | 4260 | m.base.from = CONST_CAST_TREE (t); |
564cba5f | 4261 | if ((slot = htab_find_slot (type_hash_cache, &m, NO_INSERT)) |
7a52b640 | 4262 | && *slot) |
4263 | return iterative_hash_hashval_t (((struct tree_int_map *) *slot)->to, 0); | |
7bfefa9d | 4264 | |
4265 | /* Perform a DFS walk and pre-hash all reachable types. */ | |
4266 | next_dfs_num = 1; | |
4267 | sccstate = pointer_map_create (); | |
4268 | gcc_obstack_init (&sccstate_obstack); | |
90e70538 | 4269 | val = iterative_hash_gimple_type (CONST_CAST_TREE (t), 0, |
564cba5f | 4270 | &sccstack, sccstate, &sccstate_obstack); |
7bfefa9d | 4271 | VEC_free (tree, heap, sccstack); |
4272 | pointer_map_destroy (sccstate); | |
4273 | obstack_free (&sccstate_obstack, NULL); | |
4274 | ||
4275 | return val; | |
4276 | } | |
4277 | ||
e27d9de9 | 4278 | /* Returning a hash value for gimple type TYPE combined with VAL. |
4279 | ||
4280 | The hash value returned is equal for types considered compatible | |
4281 | by gimple_canonical_types_compatible_p. */ | |
4282 | ||
4283 | static hashval_t | |
4284 | iterative_hash_canonical_type (tree type, hashval_t val) | |
4285 | { | |
4286 | hashval_t v; | |
4287 | void **slot; | |
4288 | struct tree_int_map *mp, m; | |
4289 | ||
4290 | m.base.from = type; | |
4291 | if ((slot = htab_find_slot (canonical_type_hash_cache, &m, INSERT)) | |
4292 | && *slot) | |
4088c72c | 4293 | return iterative_hash_hashval_t (((struct tree_int_map *) *slot)->to, val); |
e27d9de9 | 4294 | |
4295 | /* Combine a few common features of types so that types are grouped into | |
4296 | smaller sets; when searching for existing matching types to merge, | |
4297 | only existing types having the same features as the new type will be | |
4298 | checked. */ | |
4299 | v = iterative_hash_hashval_t (TREE_CODE (type), 0); | |
e27d9de9 | 4300 | v = iterative_hash_hashval_t (TREE_ADDRESSABLE (type), v); |
488a4664 | 4301 | v = iterative_hash_hashval_t (TYPE_ALIGN (type), v); |
4302 | v = iterative_hash_hashval_t (TYPE_MODE (type), v); | |
e27d9de9 | 4303 | |
4304 | /* Incorporate common features of numerical types. */ | |
4305 | if (INTEGRAL_TYPE_P (type) | |
4306 | || SCALAR_FLOAT_TYPE_P (type) | |
488a4664 | 4307 | || FIXED_POINT_TYPE_P (type) |
4308 | || TREE_CODE (type) == VECTOR_TYPE | |
4309 | || TREE_CODE (type) == COMPLEX_TYPE | |
4310 | || TREE_CODE (type) == OFFSET_TYPE | |
4311 | || POINTER_TYPE_P (type)) | |
e27d9de9 | 4312 | { |
4313 | v = iterative_hash_hashval_t (TYPE_PRECISION (type), v); | |
e27d9de9 | 4314 | v = iterative_hash_hashval_t (TYPE_UNSIGNED (type), v); |
4315 | } | |
4316 | ||
4317 | /* For pointer and reference types, fold in information about the type | |
4318 | pointed to but do not recurse to the pointed-to type. */ | |
4319 | if (POINTER_TYPE_P (type)) | |
4320 | { | |
4321 | v = iterative_hash_hashval_t (TYPE_REF_CAN_ALIAS_ALL (type), v); | |
488a4664 | 4322 | v = iterative_hash_hashval_t (TYPE_ADDR_SPACE (TREE_TYPE (type)), v); |
4323 | v = iterative_hash_hashval_t (TYPE_RESTRICT (type), v); | |
e27d9de9 | 4324 | v = iterative_hash_hashval_t (TREE_CODE (TREE_TYPE (type)), v); |
4325 | } | |
4326 | ||
4327 | /* For integer types hash the types min/max values and the string flag. */ | |
4328 | if (TREE_CODE (type) == INTEGER_TYPE) | |
4329 | { | |
e27d9de9 | 4330 | v = iterative_hash_hashval_t (TYPE_STRING_FLAG (type), v); |
488a4664 | 4331 | v = iterative_hash_hashval_t (TYPE_IS_SIZETYPE (type), v); |
e27d9de9 | 4332 | } |
4333 | ||
4334 | /* For array types hash their domain and the string flag. */ | |
4335 | if (TREE_CODE (type) == ARRAY_TYPE | |
4336 | && TYPE_DOMAIN (type)) | |
4337 | { | |
4338 | v = iterative_hash_hashval_t (TYPE_STRING_FLAG (type), v); | |
4339 | v = iterative_hash_canonical_type (TYPE_DOMAIN (type), v); | |
4340 | } | |
4341 | ||
4342 | /* Recurse for aggregates with a single element type. */ | |
4343 | if (TREE_CODE (type) == ARRAY_TYPE | |
4344 | || TREE_CODE (type) == COMPLEX_TYPE | |
4345 | || TREE_CODE (type) == VECTOR_TYPE) | |
4346 | v = iterative_hash_canonical_type (TREE_TYPE (type), v); | |
4347 | ||
4348 | /* Incorporate function return and argument types. */ | |
4349 | if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) | |
4350 | { | |
4351 | unsigned na; | |
4352 | tree p; | |
4353 | ||
4354 | /* For method types also incorporate their parent class. */ | |
4355 | if (TREE_CODE (type) == METHOD_TYPE) | |
4356 | v = iterative_hash_canonical_type (TYPE_METHOD_BASETYPE (type), v); | |
4357 | ||
1ca0809c | 4358 | v = iterative_hash_canonical_type (TREE_TYPE (type), v); |
e27d9de9 | 4359 | |
4360 | for (p = TYPE_ARG_TYPES (type), na = 0; p; p = TREE_CHAIN (p)) | |
4361 | { | |
1ca0809c | 4362 | v = iterative_hash_canonical_type (TREE_VALUE (p), v); |
e27d9de9 | 4363 | na++; |
4364 | } | |
4365 | ||
4366 | v = iterative_hash_hashval_t (na, v); | |
4367 | } | |
4368 | ||
4369 | if (TREE_CODE (type) == RECORD_TYPE | |
4370 | || TREE_CODE (type) == UNION_TYPE | |
4371 | || TREE_CODE (type) == QUAL_UNION_TYPE) | |
4372 | { | |
4373 | unsigned nf; | |
4374 | tree f; | |
4375 | ||
4376 | for (f = TYPE_FIELDS (type), nf = 0; f; f = TREE_CHAIN (f)) | |
ebb9e48b | 4377 | if (TREE_CODE (f) == FIELD_DECL) |
4378 | { | |
4379 | v = iterative_hash_canonical_type (TREE_TYPE (f), v); | |
4380 | nf++; | |
4381 | } | |
e27d9de9 | 4382 | |
4383 | v = iterative_hash_hashval_t (nf, v); | |
4384 | } | |
4385 | ||
4386 | /* Cache the just computed hash value. */ | |
4387 | mp = ggc_alloc_cleared_tree_int_map (); | |
4388 | mp->base.from = type; | |
4389 | mp->to = v; | |
4390 | *slot = (void *) mp; | |
4391 | ||
4392 | return iterative_hash_hashval_t (v, val); | |
4393 | } | |
4394 | ||
d1fb5d85 | 4395 | static hashval_t |
4396 | gimple_canonical_type_hash (const void *p) | |
4397 | { | |
e27d9de9 | 4398 | if (canonical_type_hash_cache == NULL) |
4399 | canonical_type_hash_cache = htab_create_ggc (512, tree_int_map_hash, | |
4400 | tree_int_map_eq, NULL); | |
4401 | ||
4402 | return iterative_hash_canonical_type (CONST_CAST_TREE ((const_tree) p), 0); | |
d1fb5d85 | 4403 | } |
4404 | ||
7bfefa9d | 4405 | |
4406 | /* Returns nonzero if P1 and P2 are equal. */ | |
4407 | ||
4408 | static int | |
4409 | gimple_type_eq (const void *p1, const void *p2) | |
4410 | { | |
4411 | const_tree t1 = (const_tree) p1; | |
4412 | const_tree t2 = (const_tree) p2; | |
003c7ce5 | 4413 | return gimple_types_compatible_p (CONST_CAST_TREE (t1), |
564cba5f | 4414 | CONST_CAST_TREE (t2)); |
7bfefa9d | 4415 | } |
4416 | ||
4417 | ||
ce89f696 | 4418 | /* Worker for gimple_register_type. |
4419 | Register type T in the global type table gimple_types. | |
4420 | When REGISTERING_MV is false first recurse for the main variant of T. */ | |
7bfefa9d | 4421 | |
ce89f696 | 4422 | static tree |
4423 | gimple_register_type_1 (tree t, bool registering_mv) | |
7bfefa9d | 4424 | { |
4425 | void **slot; | |
7a3ccc3b | 4426 | gimple_type_leader_entry *leader; |
7bfefa9d | 4427 | |
7a3ccc3b | 4428 | /* If we registered this type before return the cached result. */ |
4429 | leader = &gimple_type_leader[TYPE_UID (t) % GIMPLE_TYPE_LEADER_SIZE]; | |
4430 | if (leader->type == t) | |
4431 | return leader->leader; | |
09eb10ed | 4432 | |
b816f77f | 4433 | /* Always register the main variant first. This is important so we |
4434 | pick up the non-typedef variants as canonical, otherwise we'll end | |
ce89f696 | 4435 | up taking typedef ids for structure tags during comparison. |
4436 | It also makes sure that main variants will be merged to main variants. | |
4437 | As we are operating on a possibly partially fixed up type graph | |
4438 | do not bother to recurse more than once, otherwise we may end up | |
bddb3763 | 4439 | walking in circles. |
4440 | If we are registering a main variant it will either remain its | |
4441 | own main variant or it will be merged to something else in which | |
4442 | case we do not care for the main variant leader. */ | |
ce89f696 | 4443 | if (!registering_mv |
4444 | && TYPE_MAIN_VARIANT (t) != t) | |
4d83607a | 4445 | gimple_register_type_1 (TYPE_MAIN_VARIANT (t), true); |
7bfefa9d | 4446 | |
4d83607a | 4447 | /* See if we already have an equivalent type registered. */ |
7bfefa9d | 4448 | slot = htab_find_slot (gimple_types, t, INSERT); |
4449 | if (*slot | |
4450 | && *(tree *)slot != t) | |
4451 | { | |
4452 | tree new_type = (tree) *((tree *) slot); | |
7a3ccc3b | 4453 | leader->type = t; |
4454 | leader->leader = new_type; | |
4d83607a | 4455 | return new_type; |
7a3ccc3b | 4456 | } |
4457 | ||
4d83607a | 4458 | /* If not, insert it to the cache and the hash. */ |
4459 | leader->type = t; | |
4460 | leader->leader = t; | |
4461 | *slot = (void *) t; | |
7a3ccc3b | 4462 | return t; |
4463 | } | |
4464 | ||
ce89f696 | 4465 | /* Register type T in the global type table gimple_types. |
4466 | If another type T', compatible with T, already existed in | |
4467 | gimple_types then return T', otherwise return T. This is used by | |
4468 | LTO to merge identical types read from different TUs. */ | |
4469 | ||
4470 | tree | |
4471 | gimple_register_type (tree t) | |
4472 | { | |
4473 | gcc_assert (TYPE_P (t)); | |
4474 | ||
4475 | if (!gimple_type_leader) | |
4476 | gimple_type_leader = ggc_alloc_cleared_vec_gimple_type_leader_entry_s | |
4477 | (GIMPLE_TYPE_LEADER_SIZE); | |
4478 | ||
4479 | if (gimple_types == NULL) | |
4480 | gimple_types = htab_create_ggc (16381, gimple_type_hash, gimple_type_eq, 0); | |
4481 | ||
4482 | return gimple_register_type_1 (t, false); | |
4483 | } | |
7a3ccc3b | 4484 | |
e27d9de9 | 4485 | /* The TYPE_CANONICAL merging machinery. It should closely resemble |
4486 | the middle-end types_compatible_p function. It needs to avoid | |
4487 | claiming types are different for types that should be treated | |
4488 | the same with respect to TBAA. Canonical types are also used | |
4489 | for IL consistency checks via the useless_type_conversion_p | |
4490 | predicate which does not handle all type kinds itself but falls | |
4491 | back to pointer-comparison of TYPE_CANONICAL for aggregates | |
4492 | for example. */ | |
4493 | ||
4494 | /* Return true iff T1 and T2 are structurally identical for what | |
4495 | TBAA is concerned. */ | |
4496 | ||
4497 | static bool | |
4498 | gimple_canonical_types_compatible_p (tree t1, tree t2) | |
4499 | { | |
e27d9de9 | 4500 | /* Before starting to set up the SCC machinery handle simple cases. */ |
4501 | ||
4502 | /* Check first for the obvious case of pointer identity. */ | |
4503 | if (t1 == t2) | |
4504 | return true; | |
4505 | ||
4506 | /* Check that we have two types to compare. */ | |
4507 | if (t1 == NULL_TREE || t2 == NULL_TREE) | |
4508 | return false; | |
4509 | ||
4510 | /* If the types have been previously registered and found equal | |
4511 | they still are. */ | |
4512 | if (TYPE_CANONICAL (t1) | |
4513 | && TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2)) | |
4514 | return true; | |
4515 | ||
4516 | /* Can't be the same type if the types don't have the same code. */ | |
4517 | if (TREE_CODE (t1) != TREE_CODE (t2)) | |
4518 | return false; | |
4519 | ||
488a4664 | 4520 | if (TREE_ADDRESSABLE (t1) != TREE_ADDRESSABLE (t2)) |
e27d9de9 | 4521 | return false; |
4522 | ||
488a4664 | 4523 | /* Qualifiers do not matter for canonical type comparison purposes. */ |
4524 | ||
4525 | /* Void types and nullptr types are always the same. */ | |
4526 | if (TREE_CODE (t1) == VOID_TYPE | |
4527 | || TREE_CODE (t1) == NULLPTR_TYPE) | |
e27d9de9 | 4528 | return true; |
4529 | ||
488a4664 | 4530 | /* Can't be the same type if they have different alignment, or mode. */ |
4531 | if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2) | |
4532 | || TYPE_MODE (t1) != TYPE_MODE (t2)) | |
4533 | return false; | |
4534 | ||
4535 | /* Non-aggregate types can be handled cheaply. */ | |
e27d9de9 | 4536 | if (INTEGRAL_TYPE_P (t1) |
4537 | || SCALAR_FLOAT_TYPE_P (t1) | |
4538 | || FIXED_POINT_TYPE_P (t1) | |
4539 | || TREE_CODE (t1) == VECTOR_TYPE | |
4540 | || TREE_CODE (t1) == COMPLEX_TYPE | |
488a4664 | 4541 | || TREE_CODE (t1) == OFFSET_TYPE |
4542 | || POINTER_TYPE_P (t1)) | |
e27d9de9 | 4543 | { |
488a4664 | 4544 | /* Can't be the same type if they have different sign or precision. */ |
4545 | if (TYPE_PRECISION (t1) != TYPE_PRECISION (t2) | |
e27d9de9 | 4546 | || TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2)) |
4547 | return false; | |
4548 | ||
4549 | if (TREE_CODE (t1) == INTEGER_TYPE | |
4550 | && (TYPE_IS_SIZETYPE (t1) != TYPE_IS_SIZETYPE (t2) | |
4551 | || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2))) | |
4552 | return false; | |
4553 | ||
488a4664 | 4554 | /* For canonical type comparisons we do not want to build SCCs |
4555 | so we cannot compare pointed-to types. But we can, for now, | |
4556 | require the same pointed-to type kind and match what | |
4557 | useless_type_conversion_p would do. */ | |
4558 | if (POINTER_TYPE_P (t1)) | |
4559 | { | |
4560 | /* If the two pointers have different ref-all attributes, | |
4561 | they can't be the same type. */ | |
4562 | if (TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2)) | |
4563 | return false; | |
e27d9de9 | 4564 | |
488a4664 | 4565 | if (TYPE_ADDR_SPACE (TREE_TYPE (t1)) |
4566 | != TYPE_ADDR_SPACE (TREE_TYPE (t2))) | |
4567 | return false; | |
e27d9de9 | 4568 | |
488a4664 | 4569 | if (TYPE_RESTRICT (t1) != TYPE_RESTRICT (t2)) |
4570 | return false; | |
4571 | ||
4572 | if (TREE_CODE (TREE_TYPE (t1)) != TREE_CODE (TREE_TYPE (t2))) | |
4573 | return false; | |
4574 | } | |
4575 | ||
4576 | /* Tail-recurse to components. */ | |
4577 | if (TREE_CODE (t1) == VECTOR_TYPE | |
4578 | || TREE_CODE (t1) == COMPLEX_TYPE) | |
4579 | return gimple_canonical_types_compatible_p (TREE_TYPE (t1), | |
4580 | TREE_TYPE (t2)); | |
4581 | ||
4582 | return true; | |
e27d9de9 | 4583 | } |
4584 | ||
e27d9de9 | 4585 | /* If their attributes are not the same they can't be the same type. */ |
4586 | if (!attribute_list_equal (TYPE_ATTRIBUTES (t1), TYPE_ATTRIBUTES (t2))) | |
8b55830c | 4587 | return false; |
e27d9de9 | 4588 | |
4589 | /* Do type-specific comparisons. */ | |
4590 | switch (TREE_CODE (t1)) | |
4591 | { | |
e27d9de9 | 4592 | case ARRAY_TYPE: |
4593 | /* Array types are the same if the element types are the same and | |
4594 | the number of elements are the same. */ | |
4595 | if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2)) | |
4596 | || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2) | |
4597 | || TYPE_NONALIASED_COMPONENT (t1) != TYPE_NONALIASED_COMPONENT (t2)) | |
8b55830c | 4598 | return false; |
e27d9de9 | 4599 | else |
4600 | { | |
4601 | tree i1 = TYPE_DOMAIN (t1); | |
4602 | tree i2 = TYPE_DOMAIN (t2); | |
4603 | ||
4604 | /* For an incomplete external array, the type domain can be | |
4605 | NULL_TREE. Check this condition also. */ | |
4606 | if (i1 == NULL_TREE && i2 == NULL_TREE) | |
8b55830c | 4607 | return true; |
e27d9de9 | 4608 | else if (i1 == NULL_TREE || i2 == NULL_TREE) |
8b55830c | 4609 | return false; |
e27d9de9 | 4610 | /* If for a complete array type the possibly gimplified sizes |
4611 | are different the types are different. */ | |
4612 | else if (((TYPE_SIZE (i1) != NULL) ^ (TYPE_SIZE (i2) != NULL)) | |
4613 | || (TYPE_SIZE (i1) | |
4614 | && TYPE_SIZE (i2) | |
4615 | && !operand_equal_p (TYPE_SIZE (i1), TYPE_SIZE (i2), 0))) | |
8b55830c | 4616 | return false; |
e27d9de9 | 4617 | else |
4618 | { | |
4619 | tree min1 = TYPE_MIN_VALUE (i1); | |
4620 | tree min2 = TYPE_MIN_VALUE (i2); | |
4621 | tree max1 = TYPE_MAX_VALUE (i1); | |
4622 | tree max2 = TYPE_MAX_VALUE (i2); | |
4623 | ||
4624 | /* The minimum/maximum values have to be the same. */ | |
4625 | if ((min1 == min2 | |
4626 | || (min1 && min2 | |
4627 | && ((TREE_CODE (min1) == PLACEHOLDER_EXPR | |
4628 | && TREE_CODE (min2) == PLACEHOLDER_EXPR) | |
4629 | || operand_equal_p (min1, min2, 0)))) | |
4630 | && (max1 == max2 | |
4631 | || (max1 && max2 | |
4632 | && ((TREE_CODE (max1) == PLACEHOLDER_EXPR | |
4633 | && TREE_CODE (max2) == PLACEHOLDER_EXPR) | |
4634 | || operand_equal_p (max1, max2, 0))))) | |
8b55830c | 4635 | return true; |
e27d9de9 | 4636 | else |
8b55830c | 4637 | return false; |
e27d9de9 | 4638 | } |
4639 | } | |
4640 | ||
4641 | case METHOD_TYPE: | |
4642 | /* Method types should belong to the same class. */ | |
4643 | if (!gimple_canonical_types_compatible_p | |
4644 | (TYPE_METHOD_BASETYPE (t1), TYPE_METHOD_BASETYPE (t2))) | |
8b55830c | 4645 | return false; |
e27d9de9 | 4646 | |
4647 | /* Fallthru */ | |
4648 | ||
4649 | case FUNCTION_TYPE: | |
4650 | /* Function types are the same if the return type and arguments types | |
4651 | are the same. */ | |
1ca0809c | 4652 | if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2))) |
8b55830c | 4653 | return false; |
e27d9de9 | 4654 | |
4655 | if (!comp_type_attributes (t1, t2)) | |
8b55830c | 4656 | return false; |
e27d9de9 | 4657 | |
4658 | if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2)) | |
8b55830c | 4659 | return true; |
e27d9de9 | 4660 | else |
4661 | { | |
4662 | tree parms1, parms2; | |
4663 | ||
4664 | for (parms1 = TYPE_ARG_TYPES (t1), parms2 = TYPE_ARG_TYPES (t2); | |
4665 | parms1 && parms2; | |
4666 | parms1 = TREE_CHAIN (parms1), parms2 = TREE_CHAIN (parms2)) | |
4667 | { | |
1ca0809c | 4668 | if (!gimple_canonical_types_compatible_p |
4669 | (TREE_VALUE (parms1), TREE_VALUE (parms2))) | |
8b55830c | 4670 | return false; |
e27d9de9 | 4671 | } |
4672 | ||
4673 | if (parms1 || parms2) | |
8b55830c | 4674 | return false; |
e27d9de9 | 4675 | |
8b55830c | 4676 | return true; |
e27d9de9 | 4677 | } |
4678 | ||
e27d9de9 | 4679 | case RECORD_TYPE: |
4680 | case UNION_TYPE: | |
4681 | case QUAL_UNION_TYPE: | |
4682 | { | |
4683 | tree f1, f2; | |
4684 | ||
4685 | /* For aggregate types, all the fields must be the same. */ | |
4686 | for (f1 = TYPE_FIELDS (t1), f2 = TYPE_FIELDS (t2); | |
4687 | f1 && f2; | |
4688 | f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2)) | |
4689 | { | |
ebb9e48b | 4690 | /* Skip non-fields. */ |
4691 | while (f1 && TREE_CODE (f1) != FIELD_DECL) | |
4692 | f1 = TREE_CHAIN (f1); | |
4693 | while (f2 && TREE_CODE (f2) != FIELD_DECL) | |
4694 | f2 = TREE_CHAIN (f2); | |
4695 | if (!f1 || !f2) | |
4696 | break; | |
e27d9de9 | 4697 | /* The fields must have the same name, offset and type. */ |
4698 | if (DECL_NONADDRESSABLE_P (f1) != DECL_NONADDRESSABLE_P (f2) | |
4699 | || !gimple_compare_field_offset (f1, f2) | |
4700 | || !gimple_canonical_types_compatible_p | |
4701 | (TREE_TYPE (f1), TREE_TYPE (f2))) | |
8b55830c | 4702 | return false; |
e27d9de9 | 4703 | } |
4704 | ||
4705 | /* If one aggregate has more fields than the other, they | |
4706 | are not the same. */ | |
4707 | if (f1 || f2) | |
8b55830c | 4708 | return false; |
e27d9de9 | 4709 | |
8b55830c | 4710 | return true; |
e27d9de9 | 4711 | } |
4712 | ||
4713 | default: | |
4714 | gcc_unreachable (); | |
4715 | } | |
e27d9de9 | 4716 | } |
4717 | ||
4718 | ||
7a3ccc3b | 4719 | /* Returns nonzero if P1 and P2 are equal. */ |
4720 | ||
4721 | static int | |
4722 | gimple_canonical_type_eq (const void *p1, const void *p2) | |
4723 | { | |
4724 | const_tree t1 = (const_tree) p1; | |
4725 | const_tree t2 = (const_tree) p2; | |
e27d9de9 | 4726 | return gimple_canonical_types_compatible_p (CONST_CAST_TREE (t1), |
4727 | CONST_CAST_TREE (t2)); | |
7a3ccc3b | 4728 | } |
4729 | ||
4730 | /* Register type T in the global type table gimple_types. | |
4731 | If another type T', compatible with T, already existed in | |
4732 | gimple_types then return T', otherwise return T. This is used by | |
45014c84 | 4733 | LTO to merge identical types read from different TUs. |
4734 | ||
4735 | ??? This merging does not exactly match how the tree.c middle-end | |
4736 | functions will assign TYPE_CANONICAL when new types are created | |
4737 | during optimization (which at least happens for pointer and array | |
4738 | types). */ | |
7a3ccc3b | 4739 | |
4740 | tree | |
4741 | gimple_register_canonical_type (tree t) | |
4742 | { | |
4743 | void **slot; | |
4744 | ||
4745 | gcc_assert (TYPE_P (t)); | |
4746 | ||
488a4664 | 4747 | if (TYPE_CANONICAL (t)) |
4748 | return TYPE_CANONICAL (t); | |
4749 | ||
7a3ccc3b | 4750 | if (gimple_canonical_types == NULL) |
d1fb5d85 | 4751 | gimple_canonical_types = htab_create_ggc (16381, gimple_canonical_type_hash, |
7a3ccc3b | 4752 | gimple_canonical_type_eq, 0); |
4753 | ||
4754 | slot = htab_find_slot (gimple_canonical_types, t, INSERT); | |
4755 | if (*slot | |
4756 | && *(tree *)slot != t) | |
4757 | { | |
4758 | tree new_type = (tree) *((tree *) slot); | |
4759 | ||
4760 | TYPE_CANONICAL (t) = new_type; | |
4761 | t = new_type; | |
4762 | } | |
4763 | else | |
4764 | { | |
4765 | TYPE_CANONICAL (t) = t; | |
09eb10ed | 4766 | *slot = (void *) t; |
4767 | } | |
7bfefa9d | 4768 | |
4769 | return t; | |
4770 | } | |
4771 | ||
4772 | ||
4773 | /* Show statistics on references to the global type table gimple_types. */ | |
4774 | ||
4775 | void | |
4776 | print_gimple_types_stats (void) | |
4777 | { | |
4778 | if (gimple_types) | |
4779 | fprintf (stderr, "GIMPLE type table: size %ld, %ld elements, " | |
4780 | "%ld searches, %ld collisions (ratio: %f)\n", | |
4781 | (long) htab_size (gimple_types), | |
4782 | (long) htab_elements (gimple_types), | |
4783 | (long) gimple_types->searches, | |
4784 | (long) gimple_types->collisions, | |
4785 | htab_collisions (gimple_types)); | |
4786 | else | |
4787 | fprintf (stderr, "GIMPLE type table is empty\n"); | |
d1fb5d85 | 4788 | if (type_hash_cache) |
4789 | fprintf (stderr, "GIMPLE type hash table: size %ld, %ld elements, " | |
4790 | "%ld searches, %ld collisions (ratio: %f)\n", | |
4791 | (long) htab_size (type_hash_cache), | |
4792 | (long) htab_elements (type_hash_cache), | |
4793 | (long) type_hash_cache->searches, | |
4794 | (long) type_hash_cache->collisions, | |
4795 | htab_collisions (type_hash_cache)); | |
4796 | else | |
4797 | fprintf (stderr, "GIMPLE type hash table is empty\n"); | |
7a3ccc3b | 4798 | if (gimple_canonical_types) |
4799 | fprintf (stderr, "GIMPLE canonical type table: size %ld, %ld elements, " | |
4800 | "%ld searches, %ld collisions (ratio: %f)\n", | |
4801 | (long) htab_size (gimple_canonical_types), | |
4802 | (long) htab_elements (gimple_canonical_types), | |
4803 | (long) gimple_canonical_types->searches, | |
4804 | (long) gimple_canonical_types->collisions, | |
4805 | htab_collisions (gimple_canonical_types)); | |
4806 | else | |
4807 | fprintf (stderr, "GIMPLE canonical type table is empty\n"); | |
d1fb5d85 | 4808 | if (canonical_type_hash_cache) |
4809 | fprintf (stderr, "GIMPLE canonical type hash table: size %ld, %ld elements, " | |
7a52b640 | 4810 | "%ld searches, %ld collisions (ratio: %f)\n", |
d1fb5d85 | 4811 | (long) htab_size (canonical_type_hash_cache), |
4812 | (long) htab_elements (canonical_type_hash_cache), | |
4813 | (long) canonical_type_hash_cache->searches, | |
4814 | (long) canonical_type_hash_cache->collisions, | |
4815 | htab_collisions (canonical_type_hash_cache)); | |
7a52b640 | 4816 | else |
d1fb5d85 | 4817 | fprintf (stderr, "GIMPLE canonical type hash table is empty\n"); |
7bfefa9d | 4818 | } |
4819 | ||
7366cbe7 | 4820 | /* Free the gimple type hashtables used for LTO type merging. */ |
4821 | ||
4822 | void | |
4823 | free_gimple_type_tables (void) | |
4824 | { | |
4825 | /* Last chance to print stats for the tables. */ | |
4826 | if (flag_lto_report) | |
4827 | print_gimple_types_stats (); | |
4828 | ||
4829 | if (gimple_types) | |
4830 | { | |
4831 | htab_delete (gimple_types); | |
4832 | gimple_types = NULL; | |
4833 | } | |
7a3ccc3b | 4834 | if (gimple_canonical_types) |
4835 | { | |
4836 | htab_delete (gimple_canonical_types); | |
4837 | gimple_canonical_types = NULL; | |
4838 | } | |
7366cbe7 | 4839 | if (type_hash_cache) |
4840 | { | |
7a52b640 | 4841 | htab_delete (type_hash_cache); |
7366cbe7 | 4842 | type_hash_cache = NULL; |
4843 | } | |
d1fb5d85 | 4844 | if (canonical_type_hash_cache) |
4845 | { | |
4846 | htab_delete (canonical_type_hash_cache); | |
4847 | canonical_type_hash_cache = NULL; | |
4848 | } | |
b2640e03 | 4849 | if (type_pair_cache) |
7366cbe7 | 4850 | { |
b2640e03 | 4851 | free (type_pair_cache); |
4852 | type_pair_cache = NULL; | |
7366cbe7 | 4853 | } |
7a3ccc3b | 4854 | gimple_type_leader = NULL; |
7366cbe7 | 4855 | } |
4856 | ||
7bfefa9d | 4857 | |
4858 | /* Return a type the same as TYPE except unsigned or | |
4859 | signed according to UNSIGNEDP. */ | |
4860 | ||
4861 | static tree | |
4862 | gimple_signed_or_unsigned_type (bool unsignedp, tree type) | |
4863 | { | |
4864 | tree type1; | |
4865 | ||
4866 | type1 = TYPE_MAIN_VARIANT (type); | |
4867 | if (type1 == signed_char_type_node | |
4868 | || type1 == char_type_node | |
4869 | || type1 == unsigned_char_type_node) | |
4870 | return unsignedp ? unsigned_char_type_node : signed_char_type_node; | |
4871 | if (type1 == integer_type_node || type1 == unsigned_type_node) | |
4872 | return unsignedp ? unsigned_type_node : integer_type_node; | |
4873 | if (type1 == short_integer_type_node || type1 == short_unsigned_type_node) | |
4874 | return unsignedp ? short_unsigned_type_node : short_integer_type_node; | |
4875 | if (type1 == long_integer_type_node || type1 == long_unsigned_type_node) | |
4876 | return unsignedp ? long_unsigned_type_node : long_integer_type_node; | |
4877 | if (type1 == long_long_integer_type_node | |
4878 | || type1 == long_long_unsigned_type_node) | |
4879 | return unsignedp | |
4880 | ? long_long_unsigned_type_node | |
4881 | : long_long_integer_type_node; | |
6388cfe2 | 4882 | if (int128_integer_type_node && (type1 == int128_integer_type_node || type1 == int128_unsigned_type_node)) |
4883 | return unsignedp | |
4884 | ? int128_unsigned_type_node | |
4885 | : int128_integer_type_node; | |
7bfefa9d | 4886 | #if HOST_BITS_PER_WIDE_INT >= 64 |
4887 | if (type1 == intTI_type_node || type1 == unsigned_intTI_type_node) | |
4888 | return unsignedp ? unsigned_intTI_type_node : intTI_type_node; | |
4889 | #endif | |
4890 | if (type1 == intDI_type_node || type1 == unsigned_intDI_type_node) | |
4891 | return unsignedp ? unsigned_intDI_type_node : intDI_type_node; | |
4892 | if (type1 == intSI_type_node || type1 == unsigned_intSI_type_node) | |
4893 | return unsignedp ? unsigned_intSI_type_node : intSI_type_node; | |
4894 | if (type1 == intHI_type_node || type1 == unsigned_intHI_type_node) | |
4895 | return unsignedp ? unsigned_intHI_type_node : intHI_type_node; | |
4896 | if (type1 == intQI_type_node || type1 == unsigned_intQI_type_node) | |
4897 | return unsignedp ? unsigned_intQI_type_node : intQI_type_node; | |
4898 | ||
4899 | #define GIMPLE_FIXED_TYPES(NAME) \ | |
4900 | if (type1 == short_ ## NAME ## _type_node \ | |
4901 | || type1 == unsigned_short_ ## NAME ## _type_node) \ | |
4902 | return unsignedp ? unsigned_short_ ## NAME ## _type_node \ | |
4903 | : short_ ## NAME ## _type_node; \ | |
4904 | if (type1 == NAME ## _type_node \ | |
4905 | || type1 == unsigned_ ## NAME ## _type_node) \ | |
4906 | return unsignedp ? unsigned_ ## NAME ## _type_node \ | |
4907 | : NAME ## _type_node; \ | |
4908 | if (type1 == long_ ## NAME ## _type_node \ | |
4909 | || type1 == unsigned_long_ ## NAME ## _type_node) \ | |
4910 | return unsignedp ? unsigned_long_ ## NAME ## _type_node \ | |
4911 | : long_ ## NAME ## _type_node; \ | |
4912 | if (type1 == long_long_ ## NAME ## _type_node \ | |
4913 | || type1 == unsigned_long_long_ ## NAME ## _type_node) \ | |
4914 | return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \ | |
4915 | : long_long_ ## NAME ## _type_node; | |
4916 | ||
4917 | #define GIMPLE_FIXED_MODE_TYPES(NAME) \ | |
4918 | if (type1 == NAME ## _type_node \ | |
4919 | || type1 == u ## NAME ## _type_node) \ | |
4920 | return unsignedp ? u ## NAME ## _type_node \ | |
4921 | : NAME ## _type_node; | |
4922 | ||
4923 | #define GIMPLE_FIXED_TYPES_SAT(NAME) \ | |
4924 | if (type1 == sat_ ## short_ ## NAME ## _type_node \ | |
4925 | || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \ | |
4926 | return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \ | |
4927 | : sat_ ## short_ ## NAME ## _type_node; \ | |
4928 | if (type1 == sat_ ## NAME ## _type_node \ | |
4929 | || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \ | |
4930 | return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \ | |
4931 | : sat_ ## NAME ## _type_node; \ | |
4932 | if (type1 == sat_ ## long_ ## NAME ## _type_node \ | |
4933 | || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \ | |
4934 | return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \ | |
4935 | : sat_ ## long_ ## NAME ## _type_node; \ | |
4936 | if (type1 == sat_ ## long_long_ ## NAME ## _type_node \ | |
4937 | || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \ | |
4938 | return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \ | |
4939 | : sat_ ## long_long_ ## NAME ## _type_node; | |
4940 | ||
4941 | #define GIMPLE_FIXED_MODE_TYPES_SAT(NAME) \ | |
4942 | if (type1 == sat_ ## NAME ## _type_node \ | |
4943 | || type1 == sat_ ## u ## NAME ## _type_node) \ | |
4944 | return unsignedp ? sat_ ## u ## NAME ## _type_node \ | |
4945 | : sat_ ## NAME ## _type_node; | |
4946 | ||
4947 | GIMPLE_FIXED_TYPES (fract); | |
4948 | GIMPLE_FIXED_TYPES_SAT (fract); | |
4949 | GIMPLE_FIXED_TYPES (accum); | |
4950 | GIMPLE_FIXED_TYPES_SAT (accum); | |
4951 | ||
4952 | GIMPLE_FIXED_MODE_TYPES (qq); | |
4953 | GIMPLE_FIXED_MODE_TYPES (hq); | |
4954 | GIMPLE_FIXED_MODE_TYPES (sq); | |
4955 | GIMPLE_FIXED_MODE_TYPES (dq); | |
4956 | GIMPLE_FIXED_MODE_TYPES (tq); | |
4957 | GIMPLE_FIXED_MODE_TYPES_SAT (qq); | |
4958 | GIMPLE_FIXED_MODE_TYPES_SAT (hq); | |
4959 | GIMPLE_FIXED_MODE_TYPES_SAT (sq); | |
4960 | GIMPLE_FIXED_MODE_TYPES_SAT (dq); | |
4961 | GIMPLE_FIXED_MODE_TYPES_SAT (tq); | |
4962 | GIMPLE_FIXED_MODE_TYPES (ha); | |
4963 | GIMPLE_FIXED_MODE_TYPES (sa); | |
4964 | GIMPLE_FIXED_MODE_TYPES (da); | |
4965 | GIMPLE_FIXED_MODE_TYPES (ta); | |
4966 | GIMPLE_FIXED_MODE_TYPES_SAT (ha); | |
4967 | GIMPLE_FIXED_MODE_TYPES_SAT (sa); | |
4968 | GIMPLE_FIXED_MODE_TYPES_SAT (da); | |
4969 | GIMPLE_FIXED_MODE_TYPES_SAT (ta); | |
4970 | ||
4971 | /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not | |
4972 | the precision; they have precision set to match their range, but | |
4973 | may use a wider mode to match an ABI. If we change modes, we may | |
4974 | wind up with bad conversions. For INTEGER_TYPEs in C, must check | |
4975 | the precision as well, so as to yield correct results for | |
4976 | bit-field types. C++ does not have these separate bit-field | |
4977 | types, and producing a signed or unsigned variant of an | |
4978 | ENUMERAL_TYPE may cause other problems as well. */ | |
4979 | if (!INTEGRAL_TYPE_P (type) | |
4980 | || TYPE_UNSIGNED (type) == unsignedp) | |
4981 | return type; | |
4982 | ||
4983 | #define TYPE_OK(node) \ | |
4984 | (TYPE_MODE (type) == TYPE_MODE (node) \ | |
4985 | && TYPE_PRECISION (type) == TYPE_PRECISION (node)) | |
4986 | if (TYPE_OK (signed_char_type_node)) | |
4987 | return unsignedp ? unsigned_char_type_node : signed_char_type_node; | |
4988 | if (TYPE_OK (integer_type_node)) | |
4989 | return unsignedp ? unsigned_type_node : integer_type_node; | |
4990 | if (TYPE_OK (short_integer_type_node)) | |
4991 | return unsignedp ? short_unsigned_type_node : short_integer_type_node; | |
4992 | if (TYPE_OK (long_integer_type_node)) | |
4993 | return unsignedp ? long_unsigned_type_node : long_integer_type_node; | |
4994 | if (TYPE_OK (long_long_integer_type_node)) | |
4995 | return (unsignedp | |
4996 | ? long_long_unsigned_type_node | |
4997 | : long_long_integer_type_node); | |
6388cfe2 | 4998 | if (int128_integer_type_node && TYPE_OK (int128_integer_type_node)) |
4999 | return (unsignedp | |
5000 | ? int128_unsigned_type_node | |
5001 | : int128_integer_type_node); | |
7bfefa9d | 5002 | |
5003 | #if HOST_BITS_PER_WIDE_INT >= 64 | |
5004 | if (TYPE_OK (intTI_type_node)) | |
5005 | return unsignedp ? unsigned_intTI_type_node : intTI_type_node; | |
5006 | #endif | |
5007 | if (TYPE_OK (intDI_type_node)) | |
5008 | return unsignedp ? unsigned_intDI_type_node : intDI_type_node; | |
5009 | if (TYPE_OK (intSI_type_node)) | |
5010 | return unsignedp ? unsigned_intSI_type_node : intSI_type_node; | |
5011 | if (TYPE_OK (intHI_type_node)) | |
5012 | return unsignedp ? unsigned_intHI_type_node : intHI_type_node; | |
5013 | if (TYPE_OK (intQI_type_node)) | |
5014 | return unsignedp ? unsigned_intQI_type_node : intQI_type_node; | |
5015 | ||
5016 | #undef GIMPLE_FIXED_TYPES | |
5017 | #undef GIMPLE_FIXED_MODE_TYPES | |
5018 | #undef GIMPLE_FIXED_TYPES_SAT | |
5019 | #undef GIMPLE_FIXED_MODE_TYPES_SAT | |
5020 | #undef TYPE_OK | |
5021 | ||
5022 | return build_nonstandard_integer_type (TYPE_PRECISION (type), unsignedp); | |
5023 | } | |
5024 | ||
5025 | ||
5026 | /* Return an unsigned type the same as TYPE in other respects. */ | |
5027 | ||
5028 | tree | |
5029 | gimple_unsigned_type (tree type) | |
5030 | { | |
5031 | return gimple_signed_or_unsigned_type (true, type); | |
5032 | } | |
5033 | ||
5034 | ||
5035 | /* Return a signed type the same as TYPE in other respects. */ | |
5036 | ||
5037 | tree | |
5038 | gimple_signed_type (tree type) | |
5039 | { | |
5040 | return gimple_signed_or_unsigned_type (false, type); | |
5041 | } | |
5042 | ||
5043 | ||
5044 | /* Return the typed-based alias set for T, which may be an expression | |
5045 | or a type. Return -1 if we don't do anything special. */ | |
5046 | ||
5047 | alias_set_type | |
5048 | gimple_get_alias_set (tree t) | |
5049 | { | |
5050 | tree u; | |
5051 | ||
5052 | /* Permit type-punning when accessing a union, provided the access | |
5053 | is directly through the union. For example, this code does not | |
5054 | permit taking the address of a union member and then storing | |
5055 | through it. Even the type-punning allowed here is a GCC | |
5056 | extension, albeit a common and useful one; the C standard says | |
5057 | that such accesses have implementation-defined behavior. */ | |
5058 | for (u = t; | |
5059 | TREE_CODE (u) == COMPONENT_REF || TREE_CODE (u) == ARRAY_REF; | |
5060 | u = TREE_OPERAND (u, 0)) | |
5061 | if (TREE_CODE (u) == COMPONENT_REF | |
5062 | && TREE_CODE (TREE_TYPE (TREE_OPERAND (u, 0))) == UNION_TYPE) | |
5063 | return 0; | |
5064 | ||
5065 | /* That's all the expressions we handle specially. */ | |
5066 | if (!TYPE_P (t)) | |
5067 | return -1; | |
5068 | ||
5069 | /* For convenience, follow the C standard when dealing with | |
5070 | character types. Any object may be accessed via an lvalue that | |
5071 | has character type. */ | |
5072 | if (t == char_type_node | |
5073 | || t == signed_char_type_node | |
5074 | || t == unsigned_char_type_node) | |
5075 | return 0; | |
5076 | ||
5077 | /* Allow aliasing between signed and unsigned variants of the same | |
5078 | type. We treat the signed variant as canonical. */ | |
5079 | if (TREE_CODE (t) == INTEGER_TYPE && TYPE_UNSIGNED (t)) | |
5080 | { | |
5081 | tree t1 = gimple_signed_type (t); | |
5082 | ||
5083 | /* t1 == t can happen for boolean nodes which are always unsigned. */ | |
5084 | if (t1 != t) | |
5085 | return get_alias_set (t1); | |
5086 | } | |
7bfefa9d | 5087 | |
5088 | return -1; | |
5089 | } | |
5090 | ||
5091 | ||
dd277d48 | 5092 | /* Data structure used to count the number of dereferences to PTR |
5093 | inside an expression. */ | |
5094 | struct count_ptr_d | |
5095 | { | |
5096 | tree ptr; | |
5097 | unsigned num_stores; | |
5098 | unsigned num_loads; | |
5099 | }; | |
5100 | ||
5101 | /* Helper for count_uses_and_derefs. Called by walk_tree to look for | |
5102 | (ALIGN/MISALIGNED_)INDIRECT_REF nodes for the pointer passed in DATA. */ | |
5103 | ||
5104 | static tree | |
5105 | count_ptr_derefs (tree *tp, int *walk_subtrees, void *data) | |
5106 | { | |
5107 | struct walk_stmt_info *wi_p = (struct walk_stmt_info *) data; | |
5108 | struct count_ptr_d *count_p = (struct count_ptr_d *) wi_p->info; | |
5109 | ||
5110 | /* Do not walk inside ADDR_EXPR nodes. In the expression &ptr->fld, | |
5111 | pointer 'ptr' is *not* dereferenced, it is simply used to compute | |
5112 | the address of 'fld' as 'ptr + offsetof(fld)'. */ | |
5113 | if (TREE_CODE (*tp) == ADDR_EXPR) | |
5114 | { | |
5115 | *walk_subtrees = 0; | |
5116 | return NULL_TREE; | |
5117 | } | |
5118 | ||
182cf5a9 | 5119 | if (TREE_CODE (*tp) == MEM_REF && TREE_OPERAND (*tp, 0) == count_p->ptr) |
dd277d48 | 5120 | { |
5121 | if (wi_p->is_lhs) | |
5122 | count_p->num_stores++; | |
5123 | else | |
5124 | count_p->num_loads++; | |
5125 | } | |
5126 | ||
5127 | return NULL_TREE; | |
5128 | } | |
5129 | ||
5130 | /* Count the number of direct and indirect uses for pointer PTR in | |
5131 | statement STMT. The number of direct uses is stored in | |
5132 | *NUM_USES_P. Indirect references are counted separately depending | |
5133 | on whether they are store or load operations. The counts are | |
5134 | stored in *NUM_STORES_P and *NUM_LOADS_P. */ | |
5135 | ||
5136 | void | |
5137 | count_uses_and_derefs (tree ptr, gimple stmt, unsigned *num_uses_p, | |
5138 | unsigned *num_loads_p, unsigned *num_stores_p) | |
5139 | { | |
5140 | ssa_op_iter i; | |
5141 | tree use; | |
5142 | ||
5143 | *num_uses_p = 0; | |
5144 | *num_loads_p = 0; | |
5145 | *num_stores_p = 0; | |
5146 | ||
5147 | /* Find out the total number of uses of PTR in STMT. */ | |
5148 | FOR_EACH_SSA_TREE_OPERAND (use, stmt, i, SSA_OP_USE) | |
5149 | if (use == ptr) | |
5150 | (*num_uses_p)++; | |
5151 | ||
5152 | /* Now count the number of indirect references to PTR. This is | |
5153 | truly awful, but we don't have much choice. There are no parent | |
5154 | pointers inside INDIRECT_REFs, so an expression like | |
5155 | '*x_1 = foo (x_1, *x_1)' needs to be traversed piece by piece to | |
5156 | find all the indirect and direct uses of x_1 inside. The only | |
5157 | shortcut we can take is the fact that GIMPLE only allows | |
5158 | INDIRECT_REFs inside the expressions below. */ | |
5159 | if (is_gimple_assign (stmt) | |
5160 | || gimple_code (stmt) == GIMPLE_RETURN | |
5161 | || gimple_code (stmt) == GIMPLE_ASM | |
5162 | || is_gimple_call (stmt)) | |
5163 | { | |
5164 | struct walk_stmt_info wi; | |
5165 | struct count_ptr_d count; | |
5166 | ||
5167 | count.ptr = ptr; | |
5168 | count.num_stores = 0; | |
5169 | count.num_loads = 0; | |
5170 | ||
5171 | memset (&wi, 0, sizeof (wi)); | |
5172 | wi.info = &count; | |
5173 | walk_gimple_op (stmt, count_ptr_derefs, &wi); | |
5174 | ||
5175 | *num_stores_p = count.num_stores; | |
5176 | *num_loads_p = count.num_loads; | |
5177 | } | |
5178 | ||
5179 | gcc_assert (*num_uses_p >= *num_loads_p + *num_stores_p); | |
5180 | } | |
5181 | ||
5ed0b345 | 5182 | /* From a tree operand OP return the base of a load or store operation |
5183 | or NULL_TREE if OP is not a load or a store. */ | |
5184 | ||
5185 | static tree | |
5186 | get_base_loadstore (tree op) | |
5187 | { | |
5188 | while (handled_component_p (op)) | |
5189 | op = TREE_OPERAND (op, 0); | |
5190 | if (DECL_P (op) | |
5191 | || INDIRECT_REF_P (op) | |
182cf5a9 | 5192 | || TREE_CODE (op) == MEM_REF |
5ed0b345 | 5193 | || TREE_CODE (op) == TARGET_MEM_REF) |
5194 | return op; | |
5195 | return NULL_TREE; | |
5196 | } | |
5197 | ||
5198 | /* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE and | |
5199 | VISIT_ADDR if non-NULL on loads, store and address-taken operands | |
5200 | passing the STMT, the base of the operand and DATA to it. The base | |
5201 | will be either a decl, an indirect reference (including TARGET_MEM_REF) | |
5202 | or the argument of an address expression. | |
5203 | Returns the results of these callbacks or'ed. */ | |
5204 | ||
5205 | bool | |
5206 | walk_stmt_load_store_addr_ops (gimple stmt, void *data, | |
5207 | bool (*visit_load)(gimple, tree, void *), | |
5208 | bool (*visit_store)(gimple, tree, void *), | |
5209 | bool (*visit_addr)(gimple, tree, void *)) | |
5210 | { | |
5211 | bool ret = false; | |
5212 | unsigned i; | |
5213 | if (gimple_assign_single_p (stmt)) | |
5214 | { | |
5215 | tree lhs, rhs; | |
5216 | if (visit_store) | |
5217 | { | |
5218 | lhs = get_base_loadstore (gimple_assign_lhs (stmt)); | |
5219 | if (lhs) | |
5220 | ret |= visit_store (stmt, lhs, data); | |
5221 | } | |
5222 | rhs = gimple_assign_rhs1 (stmt); | |
be1b4133 | 5223 | while (handled_component_p (rhs)) |
5224 | rhs = TREE_OPERAND (rhs, 0); | |
5ed0b345 | 5225 | if (visit_addr) |
5226 | { | |
5227 | if (TREE_CODE (rhs) == ADDR_EXPR) | |
5228 | ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), data); | |
5229 | else if (TREE_CODE (rhs) == TARGET_MEM_REF | |
5230 | && TREE_CODE (TMR_BASE (rhs)) == ADDR_EXPR) | |
5231 | ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (rhs), 0), data); | |
5232 | else if (TREE_CODE (rhs) == OBJ_TYPE_REF | |
5233 | && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs)) == ADDR_EXPR) | |
5234 | ret |= visit_addr (stmt, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs), | |
5235 | 0), data); | |
d29f7fa8 | 5236 | lhs = gimple_assign_lhs (stmt); |
5237 | if (TREE_CODE (lhs) == TARGET_MEM_REF | |
d29f7fa8 | 5238 | && TREE_CODE (TMR_BASE (lhs)) == ADDR_EXPR) |
5239 | ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (lhs), 0), data); | |
5ed0b345 | 5240 | } |
5241 | if (visit_load) | |
5242 | { | |
5243 | rhs = get_base_loadstore (rhs); | |
5244 | if (rhs) | |
5245 | ret |= visit_load (stmt, rhs, data); | |
5246 | } | |
5247 | } | |
5248 | else if (visit_addr | |
5249 | && (is_gimple_assign (stmt) | |
2a3ebafa | 5250 | || gimple_code (stmt) == GIMPLE_COND)) |
5ed0b345 | 5251 | { |
5252 | for (i = 0; i < gimple_num_ops (stmt); ++i) | |
5253 | if (gimple_op (stmt, i) | |
5254 | && TREE_CODE (gimple_op (stmt, i)) == ADDR_EXPR) | |
5255 | ret |= visit_addr (stmt, TREE_OPERAND (gimple_op (stmt, i), 0), data); | |
5256 | } | |
5257 | else if (is_gimple_call (stmt)) | |
5258 | { | |
5259 | if (visit_store) | |
5260 | { | |
5261 | tree lhs = gimple_call_lhs (stmt); | |
5262 | if (lhs) | |
5263 | { | |
5264 | lhs = get_base_loadstore (lhs); | |
5265 | if (lhs) | |
5266 | ret |= visit_store (stmt, lhs, data); | |
5267 | } | |
5268 | } | |
5269 | if (visit_load || visit_addr) | |
5270 | for (i = 0; i < gimple_call_num_args (stmt); ++i) | |
5271 | { | |
5272 | tree rhs = gimple_call_arg (stmt, i); | |
5273 | if (visit_addr | |
5274 | && TREE_CODE (rhs) == ADDR_EXPR) | |
5275 | ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), data); | |
5276 | else if (visit_load) | |
5277 | { | |
5278 | rhs = get_base_loadstore (rhs); | |
5279 | if (rhs) | |
5280 | ret |= visit_load (stmt, rhs, data); | |
5281 | } | |
5282 | } | |
5283 | if (visit_addr | |
5284 | && gimple_call_chain (stmt) | |
5285 | && TREE_CODE (gimple_call_chain (stmt)) == ADDR_EXPR) | |
5286 | ret |= visit_addr (stmt, TREE_OPERAND (gimple_call_chain (stmt), 0), | |
5287 | data); | |
60b9b3ae | 5288 | if (visit_addr |
5289 | && gimple_call_return_slot_opt_p (stmt) | |
5290 | && gimple_call_lhs (stmt) != NULL_TREE | |
c7e30df8 | 5291 | && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (stmt)))) |
60b9b3ae | 5292 | ret |= visit_addr (stmt, gimple_call_lhs (stmt), data); |
5ed0b345 | 5293 | } |
5294 | else if (gimple_code (stmt) == GIMPLE_ASM) | |
5295 | { | |
5296 | unsigned noutputs; | |
5297 | const char *constraint; | |
5298 | const char **oconstraints; | |
5299 | bool allows_mem, allows_reg, is_inout; | |
5300 | noutputs = gimple_asm_noutputs (stmt); | |
5301 | oconstraints = XALLOCAVEC (const char *, noutputs); | |
5302 | if (visit_store || visit_addr) | |
5303 | for (i = 0; i < gimple_asm_noutputs (stmt); ++i) | |
5304 | { | |
5305 | tree link = gimple_asm_output_op (stmt, i); | |
5306 | tree op = get_base_loadstore (TREE_VALUE (link)); | |
5307 | if (op && visit_store) | |
5308 | ret |= visit_store (stmt, op, data); | |
5309 | if (visit_addr) | |
5310 | { | |
5311 | constraint = TREE_STRING_POINTER | |
5312 | (TREE_VALUE (TREE_PURPOSE (link))); | |
5313 | oconstraints[i] = constraint; | |
5314 | parse_output_constraint (&constraint, i, 0, 0, &allows_mem, | |
5315 | &allows_reg, &is_inout); | |
5316 | if (op && !allows_reg && allows_mem) | |
5317 | ret |= visit_addr (stmt, op, data); | |
5318 | } | |
5319 | } | |
5320 | if (visit_load || visit_addr) | |
5321 | for (i = 0; i < gimple_asm_ninputs (stmt); ++i) | |
5322 | { | |
5323 | tree link = gimple_asm_input_op (stmt, i); | |
5324 | tree op = TREE_VALUE (link); | |
5325 | if (visit_addr | |
5326 | && TREE_CODE (op) == ADDR_EXPR) | |
5327 | ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data); | |
5328 | else if (visit_load || visit_addr) | |
5329 | { | |
5330 | op = get_base_loadstore (op); | |
5331 | if (op) | |
5332 | { | |
5333 | if (visit_load) | |
5334 | ret |= visit_load (stmt, op, data); | |
5335 | if (visit_addr) | |
5336 | { | |
5337 | constraint = TREE_STRING_POINTER | |
5338 | (TREE_VALUE (TREE_PURPOSE (link))); | |
5339 | parse_input_constraint (&constraint, 0, 0, noutputs, | |
5340 | 0, oconstraints, | |
5341 | &allows_mem, &allows_reg); | |
5342 | if (!allows_reg && allows_mem) | |
5343 | ret |= visit_addr (stmt, op, data); | |
5344 | } | |
5345 | } | |
5346 | } | |
5347 | } | |
5348 | } | |
5349 | else if (gimple_code (stmt) == GIMPLE_RETURN) | |
5350 | { | |
5351 | tree op = gimple_return_retval (stmt); | |
5352 | if (op) | |
5353 | { | |
5354 | if (visit_addr | |
5355 | && TREE_CODE (op) == ADDR_EXPR) | |
5356 | ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data); | |
5357 | else if (visit_load) | |
5358 | { | |
5359 | op = get_base_loadstore (op); | |
5360 | if (op) | |
5361 | ret |= visit_load (stmt, op, data); | |
5362 | } | |
5363 | } | |
5364 | } | |
5365 | else if (visit_addr | |
5366 | && gimple_code (stmt) == GIMPLE_PHI) | |
5367 | { | |
5368 | for (i = 0; i < gimple_phi_num_args (stmt); ++i) | |
5369 | { | |
5370 | tree op = PHI_ARG_DEF (stmt, i); | |
5371 | if (TREE_CODE (op) == ADDR_EXPR) | |
5372 | ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data); | |
5373 | } | |
5374 | } | |
5375 | ||
5376 | return ret; | |
5377 | } | |
5378 | ||
5379 | /* Like walk_stmt_load_store_addr_ops but with NULL visit_addr. IPA-CP | |
5380 | should make a faster clone for this case. */ | |
5381 | ||
5382 | bool | |
5383 | walk_stmt_load_store_ops (gimple stmt, void *data, | |
5384 | bool (*visit_load)(gimple, tree, void *), | |
5385 | bool (*visit_store)(gimple, tree, void *)) | |
5386 | { | |
5387 | return walk_stmt_load_store_addr_ops (stmt, data, | |
5388 | visit_load, visit_store, NULL); | |
5389 | } | |
5390 | ||
6d5ec6f8 | 5391 | /* Helper for gimple_ior_addresses_taken_1. */ |
5392 | ||
5393 | static bool | |
5394 | gimple_ior_addresses_taken_1 (gimple stmt ATTRIBUTE_UNUSED, | |
5395 | tree addr, void *data) | |
5396 | { | |
5397 | bitmap addresses_taken = (bitmap)data; | |
7f2d9047 | 5398 | addr = get_base_address (addr); |
5399 | if (addr | |
5400 | && DECL_P (addr)) | |
6d5ec6f8 | 5401 | { |
5402 | bitmap_set_bit (addresses_taken, DECL_UID (addr)); | |
5403 | return true; | |
5404 | } | |
5405 | return false; | |
5406 | } | |
5407 | ||
5408 | /* Set the bit for the uid of all decls that have their address taken | |
5409 | in STMT in the ADDRESSES_TAKEN bitmap. Returns true if there | |
5410 | were any in this stmt. */ | |
5411 | ||
5412 | bool | |
5413 | gimple_ior_addresses_taken (bitmap addresses_taken, gimple stmt) | |
5414 | { | |
5415 | return walk_stmt_load_store_addr_ops (stmt, addresses_taken, NULL, NULL, | |
5416 | gimple_ior_addresses_taken_1); | |
5417 | } | |
5418 | ||
34e5cced | 5419 | |
5420 | /* Return a printable name for symbol DECL. */ | |
5421 | ||
5422 | const char * | |
5423 | gimple_decl_printable_name (tree decl, int verbosity) | |
5424 | { | |
60d62ca4 | 5425 | if (!DECL_NAME (decl)) |
5426 | return NULL; | |
34e5cced | 5427 | |
5428 | if (DECL_ASSEMBLER_NAME_SET_P (decl)) | |
5429 | { | |
5430 | const char *str, *mangled_str; | |
5431 | int dmgl_opts = DMGL_NO_OPTS; | |
5432 | ||
5433 | if (verbosity >= 2) | |
5434 | { | |
5435 | dmgl_opts = DMGL_VERBOSE | |
34e5cced | 5436 | | DMGL_ANSI |
5437 | | DMGL_GNU_V3 | |
5438 | | DMGL_RET_POSTFIX; | |
5439 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
5440 | dmgl_opts |= DMGL_PARAMS; | |
5441 | } | |
5442 | ||
5443 | mangled_str = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
5444 | str = cplus_demangle_v3 (mangled_str, dmgl_opts); | |
5445 | return (str) ? str : mangled_str; | |
5446 | } | |
5447 | ||
5448 | return IDENTIFIER_POINTER (DECL_NAME (decl)); | |
5449 | } | |
5450 | ||
3ea38c1f | 5451 | /* Return true when STMT is builtins call to CODE. */ |
5452 | ||
5453 | bool | |
5454 | gimple_call_builtin_p (gimple stmt, enum built_in_function code) | |
5455 | { | |
5456 | tree fndecl; | |
5457 | return (is_gimple_call (stmt) | |
5458 | && (fndecl = gimple_call_fndecl (stmt)) != NULL | |
5459 | && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL | |
5460 | && DECL_FUNCTION_CODE (fndecl) == code); | |
5461 | } | |
5462 | ||
97cf41ec | 5463 | /* Return true if STMT clobbers memory. STMT is required to be a |
5464 | GIMPLE_ASM. */ | |
5465 | ||
5466 | bool | |
5467 | gimple_asm_clobbers_memory_p (const_gimple stmt) | |
5468 | { | |
5469 | unsigned i; | |
5470 | ||
5471 | for (i = 0; i < gimple_asm_nclobbers (stmt); i++) | |
5472 | { | |
5473 | tree op = gimple_asm_clobber_op (stmt, i); | |
5474 | if (strcmp (TREE_STRING_POINTER (TREE_VALUE (op)), "memory") == 0) | |
5475 | return true; | |
5476 | } | |
5477 | ||
5478 | return false; | |
5479 | } | |
75a70cf9 | 5480 | #include "gt-gimple.h" |