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