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