]>
Commit | Line | Data |
---|---|---|
726a989a RB |
1 | /* Gimple IR support functions. |
2 | ||
cbe34bb5 | 3 | Copyright (C) 2007-2017 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" | |
c7131fb2 AM |
25 | #include "backend.h" |
26 | #include "tree.h" | |
27 | #include "gimple.h" | |
c7131fb2 | 28 | #include "ssa.h" |
957060b5 AM |
29 | #include "cgraph.h" |
30 | #include "diagnostic.h" | |
40e23961 | 31 | #include "alias.h" |
40e23961 | 32 | #include "fold-const.h" |
d8a2d370 | 33 | #include "calls.h" |
d8a2d370 | 34 | #include "stor-layout.h" |
2fb9a547 AM |
35 | #include "internal-fn.h" |
36 | #include "tree-eh.h" | |
5be5c238 AM |
37 | #include "gimple-iterator.h" |
38 | #include "gimple-walk.h" | |
45b0be94 | 39 | #include "gimplify.h" |
6626f970 | 40 | #include "target.h" |
ce120587 | 41 | #include "builtins.h" |
d9b950dd DM |
42 | #include "selftest.h" |
43 | #include "gimple-pretty-print.h" | |
6dc4a604 | 44 | #include "asan.h" |
726a989a | 45 | |
d7f09764 | 46 | |
f2c4a81c | 47 | /* All the tuples have their operand vector (if present) at the very bottom |
726a989a RB |
48 | of the structure. Therefore, the offset required to find the |
49 | operands vector the size of the structure minus the size of the 1 | |
50 | element tree array at the end (see gimple_ops). */ | |
f2c4a81c RH |
51 | #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) \ |
52 | (HAS_TREE_OP ? sizeof (struct STRUCT) - sizeof (tree) : 0), | |
6bc7bc14 | 53 | EXPORTED_CONST size_t gimple_ops_offset_[] = { |
f2c4a81c RH |
54 | #include "gsstruct.def" |
55 | }; | |
56 | #undef DEFGSSTRUCT | |
57 | ||
c3284718 | 58 | #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) sizeof (struct STRUCT), |
f2c4a81c RH |
59 | static const size_t gsstruct_code_size[] = { |
60 | #include "gsstruct.def" | |
61 | }; | |
62 | #undef DEFGSSTRUCT | |
63 | ||
64 | #define DEFGSCODE(SYM, NAME, GSSCODE) NAME, | |
65 | const char *const gimple_code_name[] = { | |
66 | #include "gimple.def" | |
67 | }; | |
68 | #undef DEFGSCODE | |
69 | ||
70 | #define DEFGSCODE(SYM, NAME, GSSCODE) GSSCODE, | |
71 | EXPORTED_CONST enum gimple_statement_structure_enum gss_for_code_[] = { | |
726a989a RB |
72 | #include "gimple.def" |
73 | }; | |
74 | #undef DEFGSCODE | |
75 | ||
726a989a RB |
76 | /* Gimple stats. */ |
77 | ||
78 | int gimple_alloc_counts[(int) gimple_alloc_kind_all]; | |
79 | int gimple_alloc_sizes[(int) gimple_alloc_kind_all]; | |
80 | ||
81 | /* Keep in sync with gimple.h:enum gimple_alloc_kind. */ | |
82 | static const char * const gimple_alloc_kind_names[] = { | |
83 | "assignments", | |
84 | "phi nodes", | |
85 | "conditionals", | |
726a989a RB |
86 | "everything else" |
87 | }; | |
88 | ||
bde351d5 RB |
89 | /* Static gimple tuple members. */ |
90 | const enum gimple_code gassign::code_; | |
003b40ae RB |
91 | const enum gimple_code gcall::code_; |
92 | const enum gimple_code gcond::code_; | |
bde351d5 RB |
93 | |
94 | ||
726a989a RB |
95 | /* Gimple tuple constructors. |
96 | Note: Any constructor taking a ``gimple_seq'' as a parameter, can | |
97 | be passed a NULL to start with an empty sequence. */ | |
98 | ||
99 | /* Set the code for statement G to CODE. */ | |
100 | ||
101 | static inline void | |
355fe088 | 102 | gimple_set_code (gimple *g, enum gimple_code code) |
726a989a | 103 | { |
daa6e488 | 104 | g->code = code; |
726a989a RB |
105 | } |
106 | ||
726a989a RB |
107 | /* Return the number of bytes needed to hold a GIMPLE statement with |
108 | code CODE. */ | |
109 | ||
f2c4a81c | 110 | static inline size_t |
726a989a RB |
111 | gimple_size (enum gimple_code code) |
112 | { | |
f2c4a81c | 113 | return gsstruct_code_size[gss_for_code (code)]; |
726a989a RB |
114 | } |
115 | ||
726a989a RB |
116 | /* Allocate memory for a GIMPLE statement with code CODE and NUM_OPS |
117 | operands. */ | |
118 | ||
355fe088 | 119 | gimple * |
726a989a RB |
120 | gimple_alloc_stat (enum gimple_code code, unsigned num_ops MEM_STAT_DECL) |
121 | { | |
122 | size_t size; | |
355fe088 | 123 | gimple *stmt; |
726a989a RB |
124 | |
125 | size = gimple_size (code); | |
126 | if (num_ops > 0) | |
127 | size += sizeof (tree) * (num_ops - 1); | |
128 | ||
7aa6d18a SB |
129 | if (GATHER_STATISTICS) |
130 | { | |
131 | enum gimple_alloc_kind kind = gimple_alloc_kind (code); | |
132 | gimple_alloc_counts[(int) kind]++; | |
133 | gimple_alloc_sizes[(int) kind] += size; | |
134 | } | |
726a989a | 135 | |
daa6e488 | 136 | stmt = ggc_alloc_cleared_gimple_statement_stat (size PASS_MEM_STAT); |
726a989a RB |
137 | gimple_set_code (stmt, code); |
138 | gimple_set_num_ops (stmt, num_ops); | |
139 | ||
140 | /* Do not call gimple_set_modified here as it has other side | |
141 | effects and this tuple is still not completely built. */ | |
daa6e488 | 142 | stmt->modified = 1; |
355a7673 | 143 | gimple_init_singleton (stmt); |
726a989a RB |
144 | |
145 | return stmt; | |
146 | } | |
147 | ||
148 | /* Set SUBCODE to be the code of the expression computed by statement G. */ | |
149 | ||
150 | static inline void | |
355fe088 | 151 | gimple_set_subcode (gimple *g, unsigned subcode) |
726a989a RB |
152 | { |
153 | /* We only have 16 bits for the RHS code. Assert that we are not | |
154 | overflowing it. */ | |
155 | gcc_assert (subcode < (1 << 16)); | |
daa6e488 | 156 | g->subcode = subcode; |
726a989a RB |
157 | } |
158 | ||
159 | ||
160 | ||
161 | /* Build a tuple with operands. CODE is the statement to build (which | |
7d05cebb | 162 | must be one of the GIMPLE_WITH_OPS tuples). SUBCODE is the subcode |
b8698a0f | 163 | for the new tuple. NUM_OPS is the number of operands to allocate. */ |
726a989a RB |
164 | |
165 | #define gimple_build_with_ops(c, s, n) \ | |
166 | gimple_build_with_ops_stat (c, s, n MEM_STAT_INFO) | |
167 | ||
355fe088 | 168 | static gimple * |
b5b8b0ac | 169 | gimple_build_with_ops_stat (enum gimple_code code, unsigned subcode, |
726a989a RB |
170 | unsigned num_ops MEM_STAT_DECL) |
171 | { | |
355fe088 | 172 | gimple *s = gimple_alloc_stat (code, num_ops PASS_MEM_STAT); |
726a989a RB |
173 | gimple_set_subcode (s, subcode); |
174 | ||
175 | return s; | |
176 | } | |
177 | ||
178 | ||
179 | /* Build a GIMPLE_RETURN statement returning RETVAL. */ | |
180 | ||
538dd0b7 | 181 | greturn * |
726a989a RB |
182 | gimple_build_return (tree retval) |
183 | { | |
538dd0b7 DM |
184 | greturn *s |
185 | = as_a <greturn *> (gimple_build_with_ops (GIMPLE_RETURN, ERROR_MARK, | |
186 | 2)); | |
726a989a RB |
187 | if (retval) |
188 | gimple_return_set_retval (s, retval); | |
189 | return s; | |
190 | } | |
191 | ||
d086d311 RG |
192 | /* Reset alias information on call S. */ |
193 | ||
194 | void | |
538dd0b7 | 195 | gimple_call_reset_alias_info (gcall *s) |
d086d311 RG |
196 | { |
197 | if (gimple_call_flags (s) & ECF_CONST) | |
198 | memset (gimple_call_use_set (s), 0, sizeof (struct pt_solution)); | |
199 | else | |
200 | pt_solution_reset (gimple_call_use_set (s)); | |
201 | if (gimple_call_flags (s) & (ECF_CONST|ECF_PURE|ECF_NOVOPS)) | |
202 | memset (gimple_call_clobber_set (s), 0, sizeof (struct pt_solution)); | |
203 | else | |
204 | pt_solution_reset (gimple_call_clobber_set (s)); | |
205 | } | |
206 | ||
21860814 JJ |
207 | /* Helper for gimple_build_call, gimple_build_call_valist, |
208 | gimple_build_call_vec and gimple_build_call_from_tree. Build the basic | |
209 | components of a GIMPLE_CALL statement to function FN with NARGS | |
210 | arguments. */ | |
726a989a | 211 | |
538dd0b7 | 212 | static inline gcall * |
726a989a RB |
213 | gimple_build_call_1 (tree fn, unsigned nargs) |
214 | { | |
538dd0b7 DM |
215 | gcall *s |
216 | = as_a <gcall *> (gimple_build_with_ops (GIMPLE_CALL, ERROR_MARK, | |
217 | nargs + 3)); | |
7c9577be RG |
218 | if (TREE_CODE (fn) == FUNCTION_DECL) |
219 | fn = build_fold_addr_expr (fn); | |
726a989a | 220 | gimple_set_op (s, 1, fn); |
f20ca725 | 221 | gimple_call_set_fntype (s, TREE_TYPE (TREE_TYPE (fn))); |
d086d311 | 222 | gimple_call_reset_alias_info (s); |
726a989a RB |
223 | return s; |
224 | } | |
225 | ||
226 | ||
227 | /* Build a GIMPLE_CALL statement to function FN with the arguments | |
228 | specified in vector ARGS. */ | |
229 | ||
538dd0b7 | 230 | gcall * |
9771b263 | 231 | gimple_build_call_vec (tree fn, vec<tree> args) |
726a989a RB |
232 | { |
233 | unsigned i; | |
9771b263 | 234 | unsigned nargs = args.length (); |
538dd0b7 | 235 | gcall *call = gimple_build_call_1 (fn, nargs); |
726a989a RB |
236 | |
237 | for (i = 0; i < nargs; i++) | |
9771b263 | 238 | gimple_call_set_arg (call, i, args[i]); |
726a989a RB |
239 | |
240 | return call; | |
241 | } | |
242 | ||
243 | ||
244 | /* Build a GIMPLE_CALL statement to function FN. NARGS is the number of | |
245 | arguments. The ... are the arguments. */ | |
246 | ||
538dd0b7 | 247 | gcall * |
726a989a RB |
248 | gimple_build_call (tree fn, unsigned nargs, ...) |
249 | { | |
250 | va_list ap; | |
538dd0b7 | 251 | gcall *call; |
726a989a RB |
252 | unsigned i; |
253 | ||
254 | gcc_assert (TREE_CODE (fn) == FUNCTION_DECL || is_gimple_call_addr (fn)); | |
255 | ||
256 | call = gimple_build_call_1 (fn, nargs); | |
257 | ||
258 | va_start (ap, nargs); | |
259 | for (i = 0; i < nargs; i++) | |
260 | gimple_call_set_arg (call, i, va_arg (ap, tree)); | |
261 | va_end (ap); | |
262 | ||
263 | return call; | |
264 | } | |
265 | ||
266 | ||
21860814 JJ |
267 | /* Build a GIMPLE_CALL statement to function FN. NARGS is the number of |
268 | arguments. AP contains the arguments. */ | |
269 | ||
538dd0b7 | 270 | gcall * |
21860814 JJ |
271 | gimple_build_call_valist (tree fn, unsigned nargs, va_list ap) |
272 | { | |
538dd0b7 | 273 | gcall *call; |
21860814 JJ |
274 | unsigned i; |
275 | ||
276 | gcc_assert (TREE_CODE (fn) == FUNCTION_DECL || is_gimple_call_addr (fn)); | |
277 | ||
278 | call = gimple_build_call_1 (fn, nargs); | |
279 | ||
280 | for (i = 0; i < nargs; i++) | |
281 | gimple_call_set_arg (call, i, va_arg (ap, tree)); | |
282 | ||
283 | return call; | |
284 | } | |
285 | ||
286 | ||
25583c4f RS |
287 | /* Helper for gimple_build_call_internal and gimple_build_call_internal_vec. |
288 | Build the basic components of a GIMPLE_CALL statement to internal | |
289 | function FN with NARGS arguments. */ | |
290 | ||
538dd0b7 | 291 | static inline gcall * |
25583c4f RS |
292 | gimple_build_call_internal_1 (enum internal_fn fn, unsigned nargs) |
293 | { | |
538dd0b7 DM |
294 | gcall *s |
295 | = as_a <gcall *> (gimple_build_with_ops (GIMPLE_CALL, ERROR_MARK, | |
296 | nargs + 3)); | |
daa6e488 | 297 | s->subcode |= GF_CALL_INTERNAL; |
25583c4f RS |
298 | gimple_call_set_internal_fn (s, fn); |
299 | gimple_call_reset_alias_info (s); | |
300 | return s; | |
301 | } | |
302 | ||
303 | ||
304 | /* Build a GIMPLE_CALL statement to internal function FN. NARGS is | |
305 | the number of arguments. The ... are the arguments. */ | |
306 | ||
538dd0b7 | 307 | gcall * |
25583c4f RS |
308 | gimple_build_call_internal (enum internal_fn fn, unsigned nargs, ...) |
309 | { | |
310 | va_list ap; | |
538dd0b7 | 311 | gcall *call; |
25583c4f RS |
312 | unsigned i; |
313 | ||
314 | call = gimple_build_call_internal_1 (fn, nargs); | |
315 | va_start (ap, nargs); | |
316 | for (i = 0; i < nargs; i++) | |
317 | gimple_call_set_arg (call, i, va_arg (ap, tree)); | |
318 | va_end (ap); | |
319 | ||
320 | return call; | |
321 | } | |
322 | ||
323 | ||
324 | /* Build a GIMPLE_CALL statement to internal function FN with the arguments | |
325 | specified in vector ARGS. */ | |
326 | ||
538dd0b7 | 327 | gcall * |
9771b263 | 328 | gimple_build_call_internal_vec (enum internal_fn fn, vec<tree> args) |
25583c4f RS |
329 | { |
330 | unsigned i, nargs; | |
538dd0b7 | 331 | gcall *call; |
25583c4f | 332 | |
9771b263 | 333 | nargs = args.length (); |
25583c4f RS |
334 | call = gimple_build_call_internal_1 (fn, nargs); |
335 | for (i = 0; i < nargs; i++) | |
9771b263 | 336 | gimple_call_set_arg (call, i, args[i]); |
25583c4f RS |
337 | |
338 | return call; | |
339 | } | |
340 | ||
341 | ||
726a989a RB |
342 | /* Build a GIMPLE_CALL statement from CALL_EXPR T. Note that T is |
343 | assumed to be in GIMPLE form already. Minimal checking is done of | |
344 | this fact. */ | |
345 | ||
538dd0b7 | 346 | gcall * |
726a989a RB |
347 | gimple_build_call_from_tree (tree t) |
348 | { | |
349 | unsigned i, nargs; | |
538dd0b7 | 350 | gcall *call; |
726a989a RB |
351 | tree fndecl = get_callee_fndecl (t); |
352 | ||
353 | gcc_assert (TREE_CODE (t) == CALL_EXPR); | |
354 | ||
355 | nargs = call_expr_nargs (t); | |
356 | call = gimple_build_call_1 (fndecl ? fndecl : CALL_EXPR_FN (t), nargs); | |
357 | ||
358 | for (i = 0; i < nargs; i++) | |
359 | gimple_call_set_arg (call, i, CALL_EXPR_ARG (t, i)); | |
360 | ||
361 | gimple_set_block (call, TREE_BLOCK (t)); | |
362 | ||
363 | /* Carry all the CALL_EXPR flags to the new GIMPLE_CALL. */ | |
364 | gimple_call_set_chain (call, CALL_EXPR_STATIC_CHAIN (t)); | |
365 | gimple_call_set_tail (call, CALL_EXPR_TAILCALL (t)); | |
9a385c2d | 366 | gimple_call_set_must_tail (call, CALL_EXPR_MUST_TAIL_CALL (t)); |
726a989a | 367 | gimple_call_set_return_slot_opt (call, CALL_EXPR_RETURN_SLOT_OPT (t)); |
63d2a353 MM |
368 | if (fndecl |
369 | && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL | |
13e49da9 TV |
370 | && (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA |
371 | || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA_WITH_ALIGN)) | |
63d2a353 MM |
372 | gimple_call_set_alloca_for_var (call, CALL_ALLOCA_FOR_VAR_P (t)); |
373 | else | |
374 | gimple_call_set_from_thunk (call, CALL_FROM_THUNK_P (t)); | |
726a989a | 375 | gimple_call_set_va_arg_pack (call, CALL_EXPR_VA_ARG_PACK (t)); |
9bb1a81b | 376 | gimple_call_set_nothrow (call, TREE_NOTHROW (t)); |
4c640e26 | 377 | gimple_call_set_by_descriptor (call, CALL_EXPR_BY_DESCRIPTOR (t)); |
d665b6e5 | 378 | gimple_set_no_warning (call, TREE_NO_WARNING (t)); |
d5e254e1 | 379 | gimple_call_set_with_bounds (call, CALL_WITH_BOUNDS_P (t)); |
726a989a RB |
380 | |
381 | return call; | |
382 | } | |
383 | ||
384 | ||
726a989a RB |
385 | /* Build a GIMPLE_ASSIGN statement. |
386 | ||
387 | LHS of the assignment. | |
388 | RHS of the assignment which can be unary or binary. */ | |
389 | ||
538dd0b7 | 390 | gassign * |
0d0e4a03 | 391 | gimple_build_assign (tree lhs, tree rhs MEM_STAT_DECL) |
726a989a RB |
392 | { |
393 | enum tree_code subcode; | |
0354c0c7 | 394 | tree op1, op2, op3; |
726a989a | 395 | |
d1e2bb2d | 396 | extract_ops_from_tree (rhs, &subcode, &op1, &op2, &op3); |
0d0e4a03 | 397 | return gimple_build_assign (lhs, subcode, op1, op2, op3 PASS_MEM_STAT); |
726a989a RB |
398 | } |
399 | ||
400 | ||
7d05cebb | 401 | /* Build a GIMPLE_ASSIGN statement with subcode SUBCODE and operands |
0d0e4a03 | 402 | OP1, OP2 and OP3. */ |
726a989a | 403 | |
0d0e4a03 JJ |
404 | static inline gassign * |
405 | gimple_build_assign_1 (tree lhs, enum tree_code subcode, tree op1, | |
406 | tree op2, tree op3 MEM_STAT_DECL) | |
726a989a RB |
407 | { |
408 | unsigned num_ops; | |
538dd0b7 | 409 | gassign *p; |
726a989a RB |
410 | |
411 | /* Need 1 operand for LHS and 1 or 2 for the RHS (depending on the | |
412 | code). */ | |
413 | num_ops = get_gimple_rhs_num_ops (subcode) + 1; | |
b8698a0f | 414 | |
538dd0b7 DM |
415 | p = as_a <gassign *> ( |
416 | gimple_build_with_ops_stat (GIMPLE_ASSIGN, (unsigned)subcode, num_ops | |
417 | PASS_MEM_STAT)); | |
726a989a RB |
418 | gimple_assign_set_lhs (p, lhs); |
419 | gimple_assign_set_rhs1 (p, op1); | |
420 | if (op2) | |
421 | { | |
422 | gcc_assert (num_ops > 2); | |
423 | gimple_assign_set_rhs2 (p, op2); | |
424 | } | |
425 | ||
0354c0c7 BS |
426 | if (op3) |
427 | { | |
428 | gcc_assert (num_ops > 3); | |
429 | gimple_assign_set_rhs3 (p, op3); | |
430 | } | |
431 | ||
726a989a RB |
432 | return p; |
433 | } | |
434 | ||
0d0e4a03 JJ |
435 | /* Build a GIMPLE_ASSIGN statement with subcode SUBCODE and operands |
436 | OP1, OP2 and OP3. */ | |
437 | ||
438 | gassign * | |
439 | gimple_build_assign (tree lhs, enum tree_code subcode, tree op1, | |
440 | tree op2, tree op3 MEM_STAT_DECL) | |
441 | { | |
442 | return gimple_build_assign_1 (lhs, subcode, op1, op2, op3 PASS_MEM_STAT); | |
443 | } | |
444 | ||
445 | /* Build a GIMPLE_ASSIGN statement with subcode SUBCODE and operands | |
446 | OP1 and OP2. */ | |
447 | ||
538dd0b7 | 448 | gassign * |
0d0e4a03 JJ |
449 | gimple_build_assign (tree lhs, enum tree_code subcode, tree op1, |
450 | tree op2 MEM_STAT_DECL) | |
73804b12 | 451 | { |
0d0e4a03 JJ |
452 | return gimple_build_assign_1 (lhs, subcode, op1, op2, NULL_TREE |
453 | PASS_MEM_STAT); | |
73804b12 RG |
454 | } |
455 | ||
0d0e4a03 JJ |
456 | /* Build a GIMPLE_ASSIGN statement with subcode SUBCODE and operand OP1. */ |
457 | ||
538dd0b7 | 458 | gassign * |
0d0e4a03 | 459 | gimple_build_assign (tree lhs, enum tree_code subcode, tree op1 MEM_STAT_DECL) |
00d66391 | 460 | { |
0d0e4a03 JJ |
461 | return gimple_build_assign_1 (lhs, subcode, op1, NULL_TREE, NULL_TREE |
462 | PASS_MEM_STAT); | |
00d66391 JJ |
463 | } |
464 | ||
726a989a | 465 | |
726a989a RB |
466 | /* Build a GIMPLE_COND statement. |
467 | ||
468 | PRED is the condition used to compare LHS and the RHS. | |
469 | T_LABEL is the label to jump to if the condition is true. | |
470 | F_LABEL is the label to jump to otherwise. */ | |
471 | ||
538dd0b7 | 472 | gcond * |
726a989a RB |
473 | gimple_build_cond (enum tree_code pred_code, tree lhs, tree rhs, |
474 | tree t_label, tree f_label) | |
475 | { | |
538dd0b7 | 476 | gcond *p; |
726a989a RB |
477 | |
478 | gcc_assert (TREE_CODE_CLASS (pred_code) == tcc_comparison); | |
538dd0b7 | 479 | p = as_a <gcond *> (gimple_build_with_ops (GIMPLE_COND, pred_code, 4)); |
726a989a RB |
480 | gimple_cond_set_lhs (p, lhs); |
481 | gimple_cond_set_rhs (p, rhs); | |
482 | gimple_cond_set_true_label (p, t_label); | |
483 | gimple_cond_set_false_label (p, f_label); | |
484 | return p; | |
485 | } | |
486 | ||
726a989a RB |
487 | /* Build a GIMPLE_COND statement from the conditional expression tree |
488 | COND. T_LABEL and F_LABEL are as in gimple_build_cond. */ | |
489 | ||
538dd0b7 | 490 | gcond * |
726a989a RB |
491 | gimple_build_cond_from_tree (tree cond, tree t_label, tree f_label) |
492 | { | |
493 | enum tree_code code; | |
494 | tree lhs, rhs; | |
495 | ||
496 | gimple_cond_get_ops_from_tree (cond, &code, &lhs, &rhs); | |
497 | return gimple_build_cond (code, lhs, rhs, t_label, f_label); | |
498 | } | |
499 | ||
500 | /* Set code, lhs, and rhs of a GIMPLE_COND from a suitable | |
501 | boolean expression tree COND. */ | |
502 | ||
503 | void | |
538dd0b7 | 504 | gimple_cond_set_condition_from_tree (gcond *stmt, tree cond) |
726a989a RB |
505 | { |
506 | enum tree_code code; | |
507 | tree lhs, rhs; | |
508 | ||
509 | gimple_cond_get_ops_from_tree (cond, &code, &lhs, &rhs); | |
510 | gimple_cond_set_condition (stmt, code, lhs, rhs); | |
511 | } | |
512 | ||
513 | /* Build a GIMPLE_LABEL statement for LABEL. */ | |
514 | ||
538dd0b7 | 515 | glabel * |
726a989a RB |
516 | gimple_build_label (tree label) |
517 | { | |
538dd0b7 DM |
518 | glabel *p |
519 | = as_a <glabel *> (gimple_build_with_ops (GIMPLE_LABEL, ERROR_MARK, 1)); | |
726a989a RB |
520 | gimple_label_set_label (p, label); |
521 | return p; | |
522 | } | |
523 | ||
524 | /* Build a GIMPLE_GOTO statement to label DEST. */ | |
525 | ||
538dd0b7 | 526 | ggoto * |
726a989a RB |
527 | gimple_build_goto (tree dest) |
528 | { | |
538dd0b7 DM |
529 | ggoto *p |
530 | = as_a <ggoto *> (gimple_build_with_ops (GIMPLE_GOTO, ERROR_MARK, 1)); | |
726a989a RB |
531 | gimple_goto_set_dest (p, dest); |
532 | return p; | |
533 | } | |
534 | ||
535 | ||
536 | /* Build a GIMPLE_NOP statement. */ | |
537 | ||
355fe088 | 538 | gimple * |
726a989a RB |
539 | gimple_build_nop (void) |
540 | { | |
541 | return gimple_alloc (GIMPLE_NOP, 0); | |
542 | } | |
543 | ||
544 | ||
545 | /* Build a GIMPLE_BIND statement. | |
546 | VARS are the variables in BODY. | |
547 | BLOCK is the containing block. */ | |
548 | ||
538dd0b7 | 549 | gbind * |
726a989a RB |
550 | gimple_build_bind (tree vars, gimple_seq body, tree block) |
551 | { | |
538dd0b7 | 552 | gbind *p = as_a <gbind *> (gimple_alloc (GIMPLE_BIND, 0)); |
726a989a RB |
553 | gimple_bind_set_vars (p, vars); |
554 | if (body) | |
555 | gimple_bind_set_body (p, body); | |
556 | if (block) | |
557 | gimple_bind_set_block (p, block); | |
558 | return p; | |
559 | } | |
560 | ||
561 | /* Helper function to set the simple fields of a asm stmt. | |
562 | ||
563 | STRING is a pointer to a string that is the asm blocks assembly code. | |
564 | NINPUT is the number of register inputs. | |
565 | NOUTPUT is the number of register outputs. | |
566 | NCLOBBERS is the number of clobbered registers. | |
567 | */ | |
568 | ||
538dd0b7 | 569 | static inline gasm * |
b8698a0f | 570 | gimple_build_asm_1 (const char *string, unsigned ninputs, unsigned noutputs, |
1c384bf1 | 571 | unsigned nclobbers, unsigned nlabels) |
726a989a | 572 | { |
538dd0b7 | 573 | gasm *p; |
726a989a RB |
574 | int size = strlen (string); |
575 | ||
1c384bf1 RH |
576 | /* ASMs with labels cannot have outputs. This should have been |
577 | enforced by the front end. */ | |
578 | gcc_assert (nlabels == 0 || noutputs == 0); | |
579 | ||
538dd0b7 | 580 | p = as_a <gasm *> ( |
daa6e488 DM |
581 | gimple_build_with_ops (GIMPLE_ASM, ERROR_MARK, |
582 | ninputs + noutputs + nclobbers + nlabels)); | |
726a989a | 583 | |
daa6e488 DM |
584 | p->ni = ninputs; |
585 | p->no = noutputs; | |
586 | p->nc = nclobbers; | |
587 | p->nl = nlabels; | |
588 | p->string = ggc_alloc_string (string, size); | |
726a989a | 589 | |
7aa6d18a SB |
590 | if (GATHER_STATISTICS) |
591 | gimple_alloc_sizes[(int) gimple_alloc_kind (GIMPLE_ASM)] += size; | |
b8698a0f | 592 | |
726a989a RB |
593 | return p; |
594 | } | |
595 | ||
596 | /* Build a GIMPLE_ASM statement. | |
597 | ||
598 | STRING is the assembly code. | |
599 | NINPUT is the number of register inputs. | |
600 | NOUTPUT is the number of register outputs. | |
601 | NCLOBBERS is the number of clobbered registers. | |
602 | INPUTS is a vector of the input register parameters. | |
603 | OUTPUTS is a vector of the output register parameters. | |
1c384bf1 RH |
604 | CLOBBERS is a vector of the clobbered register parameters. |
605 | LABELS is a vector of destination labels. */ | |
726a989a | 606 | |
538dd0b7 | 607 | gasm * |
9771b263 DN |
608 | gimple_build_asm_vec (const char *string, vec<tree, va_gc> *inputs, |
609 | vec<tree, va_gc> *outputs, vec<tree, va_gc> *clobbers, | |
610 | vec<tree, va_gc> *labels) | |
726a989a | 611 | { |
538dd0b7 | 612 | gasm *p; |
726a989a RB |
613 | unsigned i; |
614 | ||
615 | p = gimple_build_asm_1 (string, | |
9771b263 DN |
616 | vec_safe_length (inputs), |
617 | vec_safe_length (outputs), | |
618 | vec_safe_length (clobbers), | |
619 | vec_safe_length (labels)); | |
b8698a0f | 620 | |
9771b263 DN |
621 | for (i = 0; i < vec_safe_length (inputs); i++) |
622 | gimple_asm_set_input_op (p, i, (*inputs)[i]); | |
726a989a | 623 | |
9771b263 DN |
624 | for (i = 0; i < vec_safe_length (outputs); i++) |
625 | gimple_asm_set_output_op (p, i, (*outputs)[i]); | |
726a989a | 626 | |
9771b263 DN |
627 | for (i = 0; i < vec_safe_length (clobbers); i++) |
628 | gimple_asm_set_clobber_op (p, i, (*clobbers)[i]); | |
b8698a0f | 629 | |
9771b263 DN |
630 | for (i = 0; i < vec_safe_length (labels); i++) |
631 | gimple_asm_set_label_op (p, i, (*labels)[i]); | |
b8698a0f | 632 | |
726a989a RB |
633 | return p; |
634 | } | |
635 | ||
636 | /* Build a GIMPLE_CATCH statement. | |
637 | ||
638 | TYPES are the catch types. | |
639 | HANDLER is the exception handler. */ | |
640 | ||
538dd0b7 | 641 | gcatch * |
726a989a RB |
642 | gimple_build_catch (tree types, gimple_seq handler) |
643 | { | |
538dd0b7 | 644 | gcatch *p = as_a <gcatch *> (gimple_alloc (GIMPLE_CATCH, 0)); |
726a989a RB |
645 | gimple_catch_set_types (p, types); |
646 | if (handler) | |
647 | gimple_catch_set_handler (p, handler); | |
648 | ||
649 | return p; | |
650 | } | |
651 | ||
652 | /* Build a GIMPLE_EH_FILTER statement. | |
653 | ||
654 | TYPES are the filter's types. | |
655 | FAILURE is the filter's failure action. */ | |
656 | ||
538dd0b7 | 657 | geh_filter * |
726a989a RB |
658 | gimple_build_eh_filter (tree types, gimple_seq failure) |
659 | { | |
538dd0b7 | 660 | geh_filter *p = as_a <geh_filter *> (gimple_alloc (GIMPLE_EH_FILTER, 0)); |
726a989a RB |
661 | gimple_eh_filter_set_types (p, types); |
662 | if (failure) | |
663 | gimple_eh_filter_set_failure (p, failure); | |
664 | ||
665 | return p; | |
666 | } | |
667 | ||
1d65f45c RH |
668 | /* Build a GIMPLE_EH_MUST_NOT_THROW statement. */ |
669 | ||
538dd0b7 | 670 | geh_mnt * |
1d65f45c RH |
671 | gimple_build_eh_must_not_throw (tree decl) |
672 | { | |
538dd0b7 | 673 | geh_mnt *p = as_a <geh_mnt *> (gimple_alloc (GIMPLE_EH_MUST_NOT_THROW, 0)); |
1d65f45c RH |
674 | |
675 | gcc_assert (TREE_CODE (decl) == FUNCTION_DECL); | |
676 | gcc_assert (flags_from_decl_or_type (decl) & ECF_NORETURN); | |
d7f09764 | 677 | gimple_eh_must_not_throw_set_fndecl (p, decl); |
1d65f45c RH |
678 | |
679 | return p; | |
680 | } | |
681 | ||
0a35513e AH |
682 | /* Build a GIMPLE_EH_ELSE statement. */ |
683 | ||
538dd0b7 | 684 | geh_else * |
0a35513e AH |
685 | gimple_build_eh_else (gimple_seq n_body, gimple_seq e_body) |
686 | { | |
538dd0b7 | 687 | geh_else *p = as_a <geh_else *> (gimple_alloc (GIMPLE_EH_ELSE, 0)); |
0a35513e AH |
688 | gimple_eh_else_set_n_body (p, n_body); |
689 | gimple_eh_else_set_e_body (p, e_body); | |
690 | return p; | |
691 | } | |
692 | ||
726a989a RB |
693 | /* Build a GIMPLE_TRY statement. |
694 | ||
695 | EVAL is the expression to evaluate. | |
696 | CLEANUP is the cleanup expression. | |
697 | KIND is either GIMPLE_TRY_CATCH or GIMPLE_TRY_FINALLY depending on | |
698 | whether this is a try/catch or a try/finally respectively. */ | |
699 | ||
538dd0b7 | 700 | gtry * |
726a989a RB |
701 | gimple_build_try (gimple_seq eval, gimple_seq cleanup, |
702 | enum gimple_try_flags kind) | |
703 | { | |
538dd0b7 | 704 | gtry *p; |
726a989a RB |
705 | |
706 | gcc_assert (kind == GIMPLE_TRY_CATCH || kind == GIMPLE_TRY_FINALLY); | |
538dd0b7 | 707 | p = as_a <gtry *> (gimple_alloc (GIMPLE_TRY, 0)); |
726a989a RB |
708 | gimple_set_subcode (p, kind); |
709 | if (eval) | |
710 | gimple_try_set_eval (p, eval); | |
711 | if (cleanup) | |
712 | gimple_try_set_cleanup (p, cleanup); | |
713 | ||
714 | return p; | |
715 | } | |
716 | ||
717 | /* Construct a GIMPLE_WITH_CLEANUP_EXPR statement. | |
718 | ||
719 | CLEANUP is the cleanup expression. */ | |
720 | ||
355fe088 | 721 | gimple * |
726a989a RB |
722 | gimple_build_wce (gimple_seq cleanup) |
723 | { | |
355fe088 | 724 | gimple *p = gimple_alloc (GIMPLE_WITH_CLEANUP_EXPR, 0); |
726a989a RB |
725 | if (cleanup) |
726 | gimple_wce_set_cleanup (p, cleanup); | |
727 | ||
728 | return p; | |
729 | } | |
730 | ||
731 | ||
1d65f45c | 732 | /* Build a GIMPLE_RESX statement. */ |
726a989a | 733 | |
538dd0b7 | 734 | gresx * |
726a989a RB |
735 | gimple_build_resx (int region) |
736 | { | |
538dd0b7 DM |
737 | gresx *p |
738 | = as_a <gresx *> (gimple_build_with_ops (GIMPLE_RESX, ERROR_MARK, 0)); | |
daa6e488 | 739 | p->region = region; |
726a989a RB |
740 | return p; |
741 | } | |
742 | ||
743 | ||
744 | /* The helper for constructing a gimple switch statement. | |
745 | INDEX is the switch's index. | |
746 | NLABELS is the number of labels in the switch excluding the default. | |
747 | DEFAULT_LABEL is the default label for the switch statement. */ | |
748 | ||
538dd0b7 | 749 | gswitch * |
1d65f45c | 750 | gimple_build_switch_nlabels (unsigned nlabels, tree index, tree default_label) |
726a989a RB |
751 | { |
752 | /* nlabels + 1 default label + 1 index. */ | |
fd8d363e | 753 | gcc_checking_assert (default_label); |
538dd0b7 DM |
754 | gswitch *p = as_a <gswitch *> (gimple_build_with_ops (GIMPLE_SWITCH, |
755 | ERROR_MARK, | |
756 | 1 + 1 + nlabels)); | |
726a989a | 757 | gimple_switch_set_index (p, index); |
fd8d363e | 758 | gimple_switch_set_default_label (p, default_label); |
726a989a RB |
759 | return p; |
760 | } | |
761 | ||
726a989a RB |
762 | /* Build a GIMPLE_SWITCH statement. |
763 | ||
764 | INDEX is the switch's index. | |
765 | DEFAULT_LABEL is the default label | |
766 | ARGS is a vector of labels excluding the default. */ | |
767 | ||
538dd0b7 | 768 | gswitch * |
9771b263 | 769 | gimple_build_switch (tree index, tree default_label, vec<tree> args) |
726a989a | 770 | { |
9771b263 | 771 | unsigned i, nlabels = args.length (); |
fd8d363e | 772 | |
538dd0b7 | 773 | gswitch *p = gimple_build_switch_nlabels (nlabels, index, default_label); |
726a989a | 774 | |
1d65f45c | 775 | /* Copy the labels from the vector to the switch statement. */ |
1d65f45c | 776 | for (i = 0; i < nlabels; i++) |
9771b263 | 777 | gimple_switch_set_label (p, i + 1, args[i]); |
726a989a RB |
778 | |
779 | return p; | |
780 | } | |
781 | ||
1d65f45c RH |
782 | /* Build a GIMPLE_EH_DISPATCH statement. */ |
783 | ||
538dd0b7 | 784 | geh_dispatch * |
1d65f45c RH |
785 | gimple_build_eh_dispatch (int region) |
786 | { | |
538dd0b7 DM |
787 | geh_dispatch *p |
788 | = as_a <geh_dispatch *> ( | |
789 | gimple_build_with_ops (GIMPLE_EH_DISPATCH, ERROR_MARK, 0)); | |
daa6e488 | 790 | p->region = region; |
1d65f45c RH |
791 | return p; |
792 | } | |
726a989a | 793 | |
b5b8b0ac AO |
794 | /* Build a new GIMPLE_DEBUG_BIND statement. |
795 | ||
796 | VAR is bound to VALUE; block and location are taken from STMT. */ | |
797 | ||
538dd0b7 | 798 | gdebug * |
355fe088 | 799 | gimple_build_debug_bind_stat (tree var, tree value, gimple *stmt MEM_STAT_DECL) |
b5b8b0ac | 800 | { |
538dd0b7 DM |
801 | gdebug *p |
802 | = as_a <gdebug *> (gimple_build_with_ops_stat (GIMPLE_DEBUG, | |
803 | (unsigned)GIMPLE_DEBUG_BIND, 2 | |
804 | PASS_MEM_STAT)); | |
b5b8b0ac AO |
805 | gimple_debug_bind_set_var (p, var); |
806 | gimple_debug_bind_set_value (p, value); | |
807 | if (stmt) | |
5368224f | 808 | gimple_set_location (p, gimple_location (stmt)); |
b5b8b0ac AO |
809 | |
810 | return p; | |
811 | } | |
812 | ||
813 | ||
ddb555ed JJ |
814 | /* Build a new GIMPLE_DEBUG_SOURCE_BIND statement. |
815 | ||
816 | VAR is bound to VALUE; block and location are taken from STMT. */ | |
817 | ||
538dd0b7 | 818 | gdebug * |
ddb555ed | 819 | gimple_build_debug_source_bind_stat (tree var, tree value, |
355fe088 | 820 | gimple *stmt MEM_STAT_DECL) |
ddb555ed | 821 | { |
538dd0b7 DM |
822 | gdebug *p |
823 | = as_a <gdebug *> ( | |
824 | gimple_build_with_ops_stat (GIMPLE_DEBUG, | |
825 | (unsigned)GIMPLE_DEBUG_SOURCE_BIND, 2 | |
826 | PASS_MEM_STAT)); | |
ddb555ed JJ |
827 | |
828 | gimple_debug_source_bind_set_var (p, var); | |
829 | gimple_debug_source_bind_set_value (p, value); | |
830 | if (stmt) | |
5368224f | 831 | gimple_set_location (p, gimple_location (stmt)); |
ddb555ed JJ |
832 | |
833 | return p; | |
834 | } | |
835 | ||
836 | ||
726a989a RB |
837 | /* Build a GIMPLE_OMP_CRITICAL statement. |
838 | ||
839 | BODY is the sequence of statements for which only one thread can execute. | |
d9a6bd32 JJ |
840 | NAME is optional identifier for this critical block. |
841 | CLAUSES are clauses for this critical block. */ | |
726a989a | 842 | |
538dd0b7 | 843 | gomp_critical * |
d9a6bd32 | 844 | gimple_build_omp_critical (gimple_seq body, tree name, tree clauses) |
726a989a | 845 | { |
538dd0b7 DM |
846 | gomp_critical *p |
847 | = as_a <gomp_critical *> (gimple_alloc (GIMPLE_OMP_CRITICAL, 0)); | |
726a989a | 848 | gimple_omp_critical_set_name (p, name); |
d9a6bd32 | 849 | gimple_omp_critical_set_clauses (p, clauses); |
726a989a RB |
850 | if (body) |
851 | gimple_omp_set_body (p, body); | |
852 | ||
853 | return p; | |
854 | } | |
855 | ||
856 | /* Build a GIMPLE_OMP_FOR statement. | |
857 | ||
858 | BODY is sequence of statements inside the for loop. | |
74bf76ed | 859 | KIND is the `for' variant. |
41dbbb37 | 860 | CLAUSES, are any of the construct's clauses. |
726a989a RB |
861 | COLLAPSE is the collapse count. |
862 | PRE_BODY is the sequence of statements that are loop invariant. */ | |
863 | ||
538dd0b7 | 864 | gomp_for * |
74bf76ed | 865 | gimple_build_omp_for (gimple_seq body, int kind, tree clauses, size_t collapse, |
726a989a RB |
866 | gimple_seq pre_body) |
867 | { | |
538dd0b7 | 868 | gomp_for *p = as_a <gomp_for *> (gimple_alloc (GIMPLE_OMP_FOR, 0)); |
726a989a RB |
869 | if (body) |
870 | gimple_omp_set_body (p, body); | |
871 | gimple_omp_for_set_clauses (p, clauses); | |
74bf76ed | 872 | gimple_omp_for_set_kind (p, kind); |
daa6e488 | 873 | p->collapse = collapse; |
766090c2 | 874 | p->iter = ggc_cleared_vec_alloc<gimple_omp_for_iter> (collapse); |
daa6e488 | 875 | |
726a989a RB |
876 | if (pre_body) |
877 | gimple_omp_for_set_pre_body (p, pre_body); | |
878 | ||
879 | return p; | |
880 | } | |
881 | ||
882 | ||
883 | /* Build a GIMPLE_OMP_PARALLEL statement. | |
884 | ||
885 | BODY is sequence of statements which are executed in parallel. | |
886 | CLAUSES, are the OMP parallel construct's clauses. | |
887 | CHILD_FN is the function created for the parallel threads to execute. | |
888 | DATA_ARG are the shared data argument(s). */ | |
889 | ||
538dd0b7 | 890 | gomp_parallel * |
b8698a0f | 891 | gimple_build_omp_parallel (gimple_seq body, tree clauses, tree child_fn, |
726a989a RB |
892 | tree data_arg) |
893 | { | |
538dd0b7 DM |
894 | gomp_parallel *p |
895 | = as_a <gomp_parallel *> (gimple_alloc (GIMPLE_OMP_PARALLEL, 0)); | |
726a989a RB |
896 | if (body) |
897 | gimple_omp_set_body (p, body); | |
898 | gimple_omp_parallel_set_clauses (p, clauses); | |
899 | gimple_omp_parallel_set_child_fn (p, child_fn); | |
900 | gimple_omp_parallel_set_data_arg (p, data_arg); | |
901 | ||
902 | return p; | |
903 | } | |
904 | ||
905 | ||
906 | /* Build a GIMPLE_OMP_TASK statement. | |
907 | ||
908 | BODY is sequence of statements which are executed by the explicit task. | |
909 | CLAUSES, are the OMP parallel construct's clauses. | |
910 | CHILD_FN is the function created for the parallel threads to execute. | |
911 | DATA_ARG are the shared data argument(s). | |
912 | COPY_FN is the optional function for firstprivate initialization. | |
913 | ARG_SIZE and ARG_ALIGN are size and alignment of the data block. */ | |
914 | ||
538dd0b7 | 915 | gomp_task * |
726a989a RB |
916 | gimple_build_omp_task (gimple_seq body, tree clauses, tree child_fn, |
917 | tree data_arg, tree copy_fn, tree arg_size, | |
918 | tree arg_align) | |
919 | { | |
538dd0b7 | 920 | gomp_task *p = as_a <gomp_task *> (gimple_alloc (GIMPLE_OMP_TASK, 0)); |
726a989a RB |
921 | if (body) |
922 | gimple_omp_set_body (p, body); | |
923 | gimple_omp_task_set_clauses (p, clauses); | |
924 | gimple_omp_task_set_child_fn (p, child_fn); | |
925 | gimple_omp_task_set_data_arg (p, data_arg); | |
926 | gimple_omp_task_set_copy_fn (p, copy_fn); | |
927 | gimple_omp_task_set_arg_size (p, arg_size); | |
928 | gimple_omp_task_set_arg_align (p, arg_align); | |
929 | ||
930 | return p; | |
931 | } | |
932 | ||
933 | ||
934 | /* Build a GIMPLE_OMP_SECTION statement for a sections statement. | |
935 | ||
936 | BODY is the sequence of statements in the section. */ | |
937 | ||
355fe088 | 938 | gimple * |
726a989a RB |
939 | gimple_build_omp_section (gimple_seq body) |
940 | { | |
355fe088 | 941 | gimple *p = gimple_alloc (GIMPLE_OMP_SECTION, 0); |
726a989a RB |
942 | if (body) |
943 | gimple_omp_set_body (p, body); | |
944 | ||
945 | return p; | |
946 | } | |
947 | ||
948 | ||
949 | /* Build a GIMPLE_OMP_MASTER statement. | |
950 | ||
951 | BODY is the sequence of statements to be executed by just the master. */ | |
952 | ||
355fe088 | 953 | gimple * |
726a989a RB |
954 | gimple_build_omp_master (gimple_seq body) |
955 | { | |
355fe088 | 956 | gimple *p = gimple_alloc (GIMPLE_OMP_MASTER, 0); |
726a989a RB |
957 | if (body) |
958 | gimple_omp_set_body (p, body); | |
959 | ||
960 | return p; | |
961 | } | |
962 | ||
b2b40051 MJ |
963 | /* Build a GIMPLE_OMP_GRID_BODY statement. |
964 | ||
965 | BODY is the sequence of statements to be executed by the kernel. */ | |
966 | ||
967 | gimple * | |
968 | gimple_build_omp_grid_body (gimple_seq body) | |
969 | { | |
970 | gimple *p = gimple_alloc (GIMPLE_OMP_GRID_BODY, 0); | |
971 | if (body) | |
972 | gimple_omp_set_body (p, body); | |
973 | ||
974 | return p; | |
975 | } | |
726a989a | 976 | |
acf0174b JJ |
977 | /* Build a GIMPLE_OMP_TASKGROUP statement. |
978 | ||
979 | BODY is the sequence of statements to be executed by the taskgroup | |
980 | construct. */ | |
981 | ||
355fe088 | 982 | gimple * |
acf0174b JJ |
983 | gimple_build_omp_taskgroup (gimple_seq body) |
984 | { | |
355fe088 | 985 | gimple *p = gimple_alloc (GIMPLE_OMP_TASKGROUP, 0); |
acf0174b JJ |
986 | if (body) |
987 | gimple_omp_set_body (p, body); | |
988 | ||
989 | return p; | |
990 | } | |
991 | ||
992 | ||
726a989a RB |
993 | /* Build a GIMPLE_OMP_CONTINUE statement. |
994 | ||
995 | CONTROL_DEF is the definition of the control variable. | |
996 | CONTROL_USE is the use of the control variable. */ | |
997 | ||
538dd0b7 | 998 | gomp_continue * |
726a989a RB |
999 | gimple_build_omp_continue (tree control_def, tree control_use) |
1000 | { | |
538dd0b7 DM |
1001 | gomp_continue *p |
1002 | = as_a <gomp_continue *> (gimple_alloc (GIMPLE_OMP_CONTINUE, 0)); | |
726a989a RB |
1003 | gimple_omp_continue_set_control_def (p, control_def); |
1004 | gimple_omp_continue_set_control_use (p, control_use); | |
1005 | return p; | |
1006 | } | |
1007 | ||
1008 | /* Build a GIMPLE_OMP_ORDERED statement. | |
1009 | ||
1010 | BODY is the sequence of statements inside a loop that will executed in | |
d9a6bd32 JJ |
1011 | sequence. |
1012 | CLAUSES are clauses for this statement. */ | |
726a989a | 1013 | |
d9a6bd32 JJ |
1014 | gomp_ordered * |
1015 | gimple_build_omp_ordered (gimple_seq body, tree clauses) | |
726a989a | 1016 | { |
d9a6bd32 JJ |
1017 | gomp_ordered *p |
1018 | = as_a <gomp_ordered *> (gimple_alloc (GIMPLE_OMP_ORDERED, 0)); | |
1019 | gimple_omp_ordered_set_clauses (p, clauses); | |
726a989a RB |
1020 | if (body) |
1021 | gimple_omp_set_body (p, body); | |
1022 | ||
1023 | return p; | |
1024 | } | |
1025 | ||
1026 | ||
1027 | /* Build a GIMPLE_OMP_RETURN statement. | |
1028 | WAIT_P is true if this is a non-waiting return. */ | |
1029 | ||
355fe088 | 1030 | gimple * |
726a989a RB |
1031 | gimple_build_omp_return (bool wait_p) |
1032 | { | |
355fe088 | 1033 | gimple *p = gimple_alloc (GIMPLE_OMP_RETURN, 0); |
726a989a RB |
1034 | if (wait_p) |
1035 | gimple_omp_return_set_nowait (p); | |
1036 | ||
1037 | return p; | |
1038 | } | |
1039 | ||
1040 | ||
1041 | /* Build a GIMPLE_OMP_SECTIONS statement. | |
1042 | ||
1043 | BODY is a sequence of section statements. | |
1044 | CLAUSES are any of the OMP sections contsruct's clauses: private, | |
1045 | firstprivate, lastprivate, reduction, and nowait. */ | |
1046 | ||
538dd0b7 | 1047 | gomp_sections * |
726a989a RB |
1048 | gimple_build_omp_sections (gimple_seq body, tree clauses) |
1049 | { | |
538dd0b7 DM |
1050 | gomp_sections *p |
1051 | = as_a <gomp_sections *> (gimple_alloc (GIMPLE_OMP_SECTIONS, 0)); | |
726a989a RB |
1052 | if (body) |
1053 | gimple_omp_set_body (p, body); | |
1054 | gimple_omp_sections_set_clauses (p, clauses); | |
1055 | ||
1056 | return p; | |
1057 | } | |
1058 | ||
1059 | ||
1060 | /* Build a GIMPLE_OMP_SECTIONS_SWITCH. */ | |
1061 | ||
355fe088 | 1062 | gimple * |
726a989a RB |
1063 | gimple_build_omp_sections_switch (void) |
1064 | { | |
1065 | return gimple_alloc (GIMPLE_OMP_SECTIONS_SWITCH, 0); | |
1066 | } | |
1067 | ||
1068 | ||
1069 | /* Build a GIMPLE_OMP_SINGLE statement. | |
1070 | ||
1071 | BODY is the sequence of statements that will be executed once. | |
1072 | CLAUSES are any of the OMP single construct's clauses: private, firstprivate, | |
1073 | copyprivate, nowait. */ | |
1074 | ||
538dd0b7 | 1075 | gomp_single * |
726a989a RB |
1076 | gimple_build_omp_single (gimple_seq body, tree clauses) |
1077 | { | |
538dd0b7 DM |
1078 | gomp_single *p |
1079 | = as_a <gomp_single *> (gimple_alloc (GIMPLE_OMP_SINGLE, 0)); | |
726a989a RB |
1080 | if (body) |
1081 | gimple_omp_set_body (p, body); | |
1082 | gimple_omp_single_set_clauses (p, clauses); | |
1083 | ||
1084 | return p; | |
1085 | } | |
1086 | ||
1087 | ||
acf0174b JJ |
1088 | /* Build a GIMPLE_OMP_TARGET statement. |
1089 | ||
1090 | BODY is the sequence of statements that will be executed. | |
41dbbb37 TS |
1091 | KIND is the kind of the region. |
1092 | CLAUSES are any of the construct's clauses. */ | |
acf0174b | 1093 | |
538dd0b7 | 1094 | gomp_target * |
acf0174b JJ |
1095 | gimple_build_omp_target (gimple_seq body, int kind, tree clauses) |
1096 | { | |
538dd0b7 DM |
1097 | gomp_target *p |
1098 | = as_a <gomp_target *> (gimple_alloc (GIMPLE_OMP_TARGET, 0)); | |
acf0174b JJ |
1099 | if (body) |
1100 | gimple_omp_set_body (p, body); | |
1101 | gimple_omp_target_set_clauses (p, clauses); | |
1102 | gimple_omp_target_set_kind (p, kind); | |
1103 | ||
1104 | return p; | |
1105 | } | |
1106 | ||
1107 | ||
1108 | /* Build a GIMPLE_OMP_TEAMS statement. | |
1109 | ||
1110 | BODY is the sequence of statements that will be executed. | |
1111 | CLAUSES are any of the OMP teams construct's clauses. */ | |
1112 | ||
538dd0b7 | 1113 | gomp_teams * |
acf0174b JJ |
1114 | gimple_build_omp_teams (gimple_seq body, tree clauses) |
1115 | { | |
538dd0b7 | 1116 | gomp_teams *p = as_a <gomp_teams *> (gimple_alloc (GIMPLE_OMP_TEAMS, 0)); |
acf0174b JJ |
1117 | if (body) |
1118 | gimple_omp_set_body (p, body); | |
1119 | gimple_omp_teams_set_clauses (p, clauses); | |
1120 | ||
1121 | return p; | |
1122 | } | |
1123 | ||
1124 | ||
726a989a RB |
1125 | /* Build a GIMPLE_OMP_ATOMIC_LOAD statement. */ |
1126 | ||
538dd0b7 | 1127 | gomp_atomic_load * |
726a989a RB |
1128 | gimple_build_omp_atomic_load (tree lhs, tree rhs) |
1129 | { | |
538dd0b7 DM |
1130 | gomp_atomic_load *p |
1131 | = as_a <gomp_atomic_load *> (gimple_alloc (GIMPLE_OMP_ATOMIC_LOAD, 0)); | |
726a989a RB |
1132 | gimple_omp_atomic_load_set_lhs (p, lhs); |
1133 | gimple_omp_atomic_load_set_rhs (p, rhs); | |
1134 | return p; | |
1135 | } | |
1136 | ||
1137 | /* Build a GIMPLE_OMP_ATOMIC_STORE statement. | |
1138 | ||
1139 | VAL is the value we are storing. */ | |
1140 | ||
538dd0b7 | 1141 | gomp_atomic_store * |
726a989a RB |
1142 | gimple_build_omp_atomic_store (tree val) |
1143 | { | |
538dd0b7 DM |
1144 | gomp_atomic_store *p |
1145 | = as_a <gomp_atomic_store *> (gimple_alloc (GIMPLE_OMP_ATOMIC_STORE, 0)); | |
726a989a RB |
1146 | gimple_omp_atomic_store_set_val (p, val); |
1147 | return p; | |
1148 | } | |
1149 | ||
0a35513e AH |
1150 | /* Build a GIMPLE_TRANSACTION statement. */ |
1151 | ||
538dd0b7 | 1152 | gtransaction * |
7c11b0fe | 1153 | gimple_build_transaction (gimple_seq body) |
0a35513e | 1154 | { |
538dd0b7 DM |
1155 | gtransaction *p |
1156 | = as_a <gtransaction *> (gimple_alloc (GIMPLE_TRANSACTION, 0)); | |
0a35513e | 1157 | gimple_transaction_set_body (p, body); |
7c11b0fe RH |
1158 | gimple_transaction_set_label_norm (p, 0); |
1159 | gimple_transaction_set_label_uninst (p, 0); | |
1160 | gimple_transaction_set_label_over (p, 0); | |
0a35513e AH |
1161 | return p; |
1162 | } | |
1163 | ||
cea094ed | 1164 | #if defined ENABLE_GIMPLE_CHECKING |
726a989a RB |
1165 | /* Complain of a gimple type mismatch and die. */ |
1166 | ||
1167 | void | |
355fe088 | 1168 | gimple_check_failed (const gimple *gs, const char *file, int line, |
726a989a RB |
1169 | const char *function, enum gimple_code code, |
1170 | enum tree_code subcode) | |
1171 | { | |
1172 | internal_error ("gimple check: expected %s(%s), have %s(%s) in %s, at %s:%d", | |
1173 | gimple_code_name[code], | |
5806f481 | 1174 | get_tree_code_name (subcode), |
726a989a | 1175 | gimple_code_name[gimple_code (gs)], |
daa6e488 DM |
1176 | gs->subcode > 0 |
1177 | ? get_tree_code_name ((enum tree_code) gs->subcode) | |
726a989a RB |
1178 | : "", |
1179 | function, trim_filename (file), line); | |
1180 | } | |
726a989a RB |
1181 | #endif /* ENABLE_GIMPLE_CHECKING */ |
1182 | ||
1183 | ||
726a989a RB |
1184 | /* Link gimple statement GS to the end of the sequence *SEQ_P. If |
1185 | *SEQ_P is NULL, a new sequence is allocated. */ | |
1186 | ||
1187 | void | |
355fe088 | 1188 | gimple_seq_add_stmt (gimple_seq *seq_p, gimple *gs) |
726a989a RB |
1189 | { |
1190 | gimple_stmt_iterator si; | |
726a989a RB |
1191 | if (gs == NULL) |
1192 | return; | |
1193 | ||
726a989a RB |
1194 | si = gsi_last (*seq_p); |
1195 | gsi_insert_after (&si, gs, GSI_NEW_STMT); | |
1196 | } | |
1197 | ||
45b0be94 AM |
1198 | /* Link gimple statement GS to the end of the sequence *SEQ_P. If |
1199 | *SEQ_P is NULL, a new sequence is allocated. This function is | |
1200 | similar to gimple_seq_add_stmt, but does not scan the operands. | |
1201 | During gimplification, we need to manipulate statement sequences | |
1202 | before the def/use vectors have been constructed. */ | |
1203 | ||
1204 | void | |
355fe088 | 1205 | gimple_seq_add_stmt_without_update (gimple_seq *seq_p, gimple *gs) |
45b0be94 AM |
1206 | { |
1207 | gimple_stmt_iterator si; | |
1208 | ||
1209 | if (gs == NULL) | |
1210 | return; | |
1211 | ||
1212 | si = gsi_last (*seq_p); | |
1213 | gsi_insert_after_without_update (&si, gs, GSI_NEW_STMT); | |
1214 | } | |
726a989a RB |
1215 | |
1216 | /* Append sequence SRC to the end of sequence *DST_P. If *DST_P is | |
1217 | NULL, a new sequence is allocated. */ | |
1218 | ||
1219 | void | |
1220 | gimple_seq_add_seq (gimple_seq *dst_p, gimple_seq src) | |
1221 | { | |
1222 | gimple_stmt_iterator si; | |
726a989a RB |
1223 | if (src == NULL) |
1224 | return; | |
1225 | ||
726a989a RB |
1226 | si = gsi_last (*dst_p); |
1227 | gsi_insert_seq_after (&si, src, GSI_NEW_STMT); | |
1228 | } | |
1229 | ||
fef5a0d9 RB |
1230 | /* Append sequence SRC to the end of sequence *DST_P. If *DST_P is |
1231 | NULL, a new sequence is allocated. This function is | |
1232 | similar to gimple_seq_add_seq, but does not scan the operands. */ | |
1233 | ||
1234 | void | |
1235 | gimple_seq_add_seq_without_update (gimple_seq *dst_p, gimple_seq src) | |
1236 | { | |
1237 | gimple_stmt_iterator si; | |
1238 | if (src == NULL) | |
1239 | return; | |
1240 | ||
1241 | si = gsi_last (*dst_p); | |
1242 | gsi_insert_seq_after_without_update (&si, src, GSI_NEW_STMT); | |
1243 | } | |
1244 | ||
45b0be94 AM |
1245 | /* Determine whether to assign a location to the statement GS. */ |
1246 | ||
1247 | static bool | |
355fe088 | 1248 | should_carry_location_p (gimple *gs) |
45b0be94 AM |
1249 | { |
1250 | /* Don't emit a line note for a label. We particularly don't want to | |
1251 | emit one for the break label, since it doesn't actually correspond | |
1252 | to the beginning of the loop/switch. */ | |
1253 | if (gimple_code (gs) == GIMPLE_LABEL) | |
1254 | return false; | |
1255 | ||
1256 | return true; | |
1257 | } | |
1258 | ||
1259 | /* Set the location for gimple statement GS to LOCATION. */ | |
1260 | ||
1261 | static void | |
355fe088 | 1262 | annotate_one_with_location (gimple *gs, location_t location) |
45b0be94 AM |
1263 | { |
1264 | if (!gimple_has_location (gs) | |
1265 | && !gimple_do_not_emit_location_p (gs) | |
1266 | && should_carry_location_p (gs)) | |
1267 | gimple_set_location (gs, location); | |
1268 | } | |
1269 | ||
1270 | /* Set LOCATION for all the statements after iterator GSI in sequence | |
1271 | SEQ. If GSI is pointing to the end of the sequence, start with the | |
1272 | first statement in SEQ. */ | |
1273 | ||
1274 | void | |
1275 | annotate_all_with_location_after (gimple_seq seq, gimple_stmt_iterator gsi, | |
1276 | location_t location) | |
1277 | { | |
1278 | if (gsi_end_p (gsi)) | |
1279 | gsi = gsi_start (seq); | |
1280 | else | |
1281 | gsi_next (&gsi); | |
1282 | ||
1283 | for (; !gsi_end_p (gsi); gsi_next (&gsi)) | |
1284 | annotate_one_with_location (gsi_stmt (gsi), location); | |
1285 | } | |
1286 | ||
1287 | /* Set the location for all the statements in a sequence STMT_P to LOCATION. */ | |
1288 | ||
1289 | void | |
1290 | annotate_all_with_location (gimple_seq stmt_p, location_t location) | |
1291 | { | |
1292 | gimple_stmt_iterator i; | |
1293 | ||
1294 | if (gimple_seq_empty_p (stmt_p)) | |
1295 | return; | |
1296 | ||
1297 | for (i = gsi_start (stmt_p); !gsi_end_p (i); gsi_next (&i)) | |
1298 | { | |
355fe088 | 1299 | gimple *gs = gsi_stmt (i); |
45b0be94 AM |
1300 | annotate_one_with_location (gs, location); |
1301 | } | |
1302 | } | |
726a989a RB |
1303 | |
1304 | /* Helper function of empty_body_p. Return true if STMT is an empty | |
1305 | statement. */ | |
1306 | ||
1307 | static bool | |
355fe088 | 1308 | empty_stmt_p (gimple *stmt) |
726a989a RB |
1309 | { |
1310 | if (gimple_code (stmt) == GIMPLE_NOP) | |
1311 | return true; | |
538dd0b7 DM |
1312 | if (gbind *bind_stmt = dyn_cast <gbind *> (stmt)) |
1313 | return empty_body_p (gimple_bind_body (bind_stmt)); | |
726a989a RB |
1314 | return false; |
1315 | } | |
1316 | ||
1317 | ||
1318 | /* Return true if BODY contains nothing but empty statements. */ | |
1319 | ||
1320 | bool | |
1321 | empty_body_p (gimple_seq body) | |
1322 | { | |
1323 | gimple_stmt_iterator i; | |
1324 | ||
726a989a RB |
1325 | if (gimple_seq_empty_p (body)) |
1326 | return true; | |
1327 | for (i = gsi_start (body); !gsi_end_p (i); gsi_next (&i)) | |
b5b8b0ac AO |
1328 | if (!empty_stmt_p (gsi_stmt (i)) |
1329 | && !is_gimple_debug (gsi_stmt (i))) | |
726a989a RB |
1330 | return false; |
1331 | ||
1332 | return true; | |
1333 | } | |
1334 | ||
1335 | ||
1336 | /* Perform a deep copy of sequence SRC and return the result. */ | |
1337 | ||
1338 | gimple_seq | |
1339 | gimple_seq_copy (gimple_seq src) | |
1340 | { | |
1341 | gimple_stmt_iterator gsi; | |
355a7673 | 1342 | gimple_seq new_seq = NULL; |
355fe088 | 1343 | gimple *stmt; |
726a989a RB |
1344 | |
1345 | for (gsi = gsi_start (src); !gsi_end_p (gsi); gsi_next (&gsi)) | |
1346 | { | |
1347 | stmt = gimple_copy (gsi_stmt (gsi)); | |
82d6e6fc | 1348 | gimple_seq_add_stmt (&new_seq, stmt); |
726a989a RB |
1349 | } |
1350 | ||
82d6e6fc | 1351 | return new_seq; |
726a989a RB |
1352 | } |
1353 | ||
1354 | ||
726a989a | 1355 | |
25583c4f RS |
1356 | /* Return true if calls C1 and C2 are known to go to the same function. */ |
1357 | ||
1358 | bool | |
355fe088 | 1359 | gimple_call_same_target_p (const gimple *c1, const gimple *c2) |
25583c4f RS |
1360 | { |
1361 | if (gimple_call_internal_p (c1)) | |
1362 | return (gimple_call_internal_p (c2) | |
8ab78162 | 1363 | && gimple_call_internal_fn (c1) == gimple_call_internal_fn (c2) |
3433ee35 NS |
1364 | && (!gimple_call_internal_unique_p (as_a <const gcall *> (c1)) |
1365 | || c1 == c2)); | |
25583c4f RS |
1366 | else |
1367 | return (gimple_call_fn (c1) == gimple_call_fn (c2) | |
1368 | || (gimple_call_fndecl (c1) | |
1369 | && gimple_call_fndecl (c1) == gimple_call_fndecl (c2))); | |
1370 | } | |
1371 | ||
726a989a RB |
1372 | /* Detect flags from a GIMPLE_CALL. This is just like |
1373 | call_expr_flags, but for gimple tuples. */ | |
1374 | ||
1375 | int | |
355fe088 | 1376 | gimple_call_flags (const gimple *stmt) |
726a989a RB |
1377 | { |
1378 | int flags; | |
1379 | tree decl = gimple_call_fndecl (stmt); | |
726a989a RB |
1380 | |
1381 | if (decl) | |
1382 | flags = flags_from_decl_or_type (decl); | |
25583c4f RS |
1383 | else if (gimple_call_internal_p (stmt)) |
1384 | flags = internal_fn_flags (gimple_call_internal_fn (stmt)); | |
726a989a | 1385 | else |
97e03fa1 | 1386 | flags = flags_from_decl_or_type (gimple_call_fntype (stmt)); |
726a989a | 1387 | |
daa6e488 | 1388 | if (stmt->subcode & GF_CALL_NOTHROW) |
9bb1a81b JM |
1389 | flags |= ECF_NOTHROW; |
1390 | ||
4c640e26 EB |
1391 | if (stmt->subcode & GF_CALL_BY_DESCRIPTOR) |
1392 | flags |= ECF_BY_DESCRIPTOR; | |
1393 | ||
726a989a RB |
1394 | return flags; |
1395 | } | |
1396 | ||
25583c4f RS |
1397 | /* Return the "fn spec" string for call STMT. */ |
1398 | ||
b78475cf | 1399 | static const_tree |
538dd0b7 | 1400 | gimple_call_fnspec (const gcall *stmt) |
25583c4f RS |
1401 | { |
1402 | tree type, attr; | |
1403 | ||
b78475cf YG |
1404 | if (gimple_call_internal_p (stmt)) |
1405 | return internal_fn_fnspec (gimple_call_internal_fn (stmt)); | |
1406 | ||
25583c4f RS |
1407 | type = gimple_call_fntype (stmt); |
1408 | if (!type) | |
1409 | return NULL_TREE; | |
1410 | ||
1411 | attr = lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type)); | |
1412 | if (!attr) | |
1413 | return NULL_TREE; | |
1414 | ||
1415 | return TREE_VALUE (TREE_VALUE (attr)); | |
1416 | } | |
1417 | ||
0b7b376d RG |
1418 | /* Detects argument flags for argument number ARG on call STMT. */ |
1419 | ||
1420 | int | |
538dd0b7 | 1421 | gimple_call_arg_flags (const gcall *stmt, unsigned arg) |
0b7b376d | 1422 | { |
b78475cf | 1423 | const_tree attr = gimple_call_fnspec (stmt); |
0b7b376d | 1424 | |
25583c4f | 1425 | if (!attr || 1 + arg >= (unsigned) TREE_STRING_LENGTH (attr)) |
0b7b376d RG |
1426 | return 0; |
1427 | ||
1428 | switch (TREE_STRING_POINTER (attr)[1 + arg]) | |
1429 | { | |
1430 | case 'x': | |
1431 | case 'X': | |
1432 | return EAF_UNUSED; | |
1433 | ||
1434 | case 'R': | |
1435 | return EAF_DIRECT | EAF_NOCLOBBER | EAF_NOESCAPE; | |
1436 | ||
1437 | case 'r': | |
1438 | return EAF_NOCLOBBER | EAF_NOESCAPE; | |
1439 | ||
1440 | case 'W': | |
1441 | return EAF_DIRECT | EAF_NOESCAPE; | |
1442 | ||
1443 | case 'w': | |
1444 | return EAF_NOESCAPE; | |
1445 | ||
1446 | case '.': | |
1447 | default: | |
1448 | return 0; | |
1449 | } | |
1450 | } | |
1451 | ||
1452 | /* Detects return flags for the call STMT. */ | |
1453 | ||
1454 | int | |
538dd0b7 | 1455 | gimple_call_return_flags (const gcall *stmt) |
0b7b376d | 1456 | { |
b78475cf | 1457 | const_tree attr; |
0b7b376d RG |
1458 | |
1459 | if (gimple_call_flags (stmt) & ECF_MALLOC) | |
1460 | return ERF_NOALIAS; | |
1461 | ||
25583c4f RS |
1462 | attr = gimple_call_fnspec (stmt); |
1463 | if (!attr || TREE_STRING_LENGTH (attr) < 1) | |
0b7b376d RG |
1464 | return 0; |
1465 | ||
1466 | switch (TREE_STRING_POINTER (attr)[0]) | |
1467 | { | |
1468 | case '1': | |
1469 | case '2': | |
1470 | case '3': | |
1471 | case '4': | |
1472 | return ERF_RETURNS_ARG | (TREE_STRING_POINTER (attr)[0] - '1'); | |
1473 | ||
1474 | case 'm': | |
1475 | return ERF_NOALIAS; | |
1476 | ||
1477 | case '.': | |
1478 | default: | |
1479 | return 0; | |
1480 | } | |
1481 | } | |
726a989a | 1482 | |
3dbe9454 | 1483 | |
726a989a RB |
1484 | /* Return true if GS is a copy assignment. */ |
1485 | ||
1486 | bool | |
355fe088 | 1487 | gimple_assign_copy_p (gimple *gs) |
726a989a | 1488 | { |
3dbe9454 RG |
1489 | return (gimple_assign_single_p (gs) |
1490 | && is_gimple_val (gimple_op (gs, 1))); | |
726a989a RB |
1491 | } |
1492 | ||
1493 | ||
1494 | /* Return true if GS is a SSA_NAME copy assignment. */ | |
1495 | ||
1496 | bool | |
355fe088 | 1497 | gimple_assign_ssa_name_copy_p (gimple *gs) |
726a989a | 1498 | { |
3dbe9454 | 1499 | return (gimple_assign_single_p (gs) |
726a989a RB |
1500 | && TREE_CODE (gimple_assign_lhs (gs)) == SSA_NAME |
1501 | && TREE_CODE (gimple_assign_rhs1 (gs)) == SSA_NAME); | |
1502 | } | |
1503 | ||
1504 | ||
726a989a RB |
1505 | /* Return true if GS is an assignment with a unary RHS, but the |
1506 | operator has no effect on the assigned value. The logic is adapted | |
1507 | from STRIP_NOPS. This predicate is intended to be used in tuplifying | |
1508 | instances in which STRIP_NOPS was previously applied to the RHS of | |
1509 | an assignment. | |
1510 | ||
1511 | NOTE: In the use cases that led to the creation of this function | |
1512 | and of gimple_assign_single_p, it is typical to test for either | |
1513 | condition and to proceed in the same manner. In each case, the | |
1514 | assigned value is represented by the single RHS operand of the | |
1515 | assignment. I suspect there may be cases where gimple_assign_copy_p, | |
1516 | gimple_assign_single_p, or equivalent logic is used where a similar | |
1517 | treatment of unary NOPs is appropriate. */ | |
b8698a0f | 1518 | |
726a989a | 1519 | bool |
355fe088 | 1520 | gimple_assign_unary_nop_p (gimple *gs) |
726a989a | 1521 | { |
3dbe9454 | 1522 | return (is_gimple_assign (gs) |
1a87cf0c | 1523 | && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs)) |
726a989a RB |
1524 | || gimple_assign_rhs_code (gs) == NON_LVALUE_EXPR) |
1525 | && gimple_assign_rhs1 (gs) != error_mark_node | |
1526 | && (TYPE_MODE (TREE_TYPE (gimple_assign_lhs (gs))) | |
1527 | == TYPE_MODE (TREE_TYPE (gimple_assign_rhs1 (gs))))); | |
1528 | } | |
1529 | ||
1530 | /* Set BB to be the basic block holding G. */ | |
1531 | ||
1532 | void | |
355fe088 | 1533 | gimple_set_bb (gimple *stmt, basic_block bb) |
726a989a | 1534 | { |
daa6e488 | 1535 | stmt->bb = bb; |
726a989a | 1536 | |
45b62594 RB |
1537 | if (gimple_code (stmt) != GIMPLE_LABEL) |
1538 | return; | |
1539 | ||
726a989a RB |
1540 | /* If the statement is a label, add the label to block-to-labels map |
1541 | so that we can speed up edge creation for GIMPLE_GOTOs. */ | |
45b62594 | 1542 | if (cfun->cfg) |
726a989a RB |
1543 | { |
1544 | tree t; | |
1545 | int uid; | |
1546 | ||
538dd0b7 | 1547 | t = gimple_label_label (as_a <glabel *> (stmt)); |
726a989a RB |
1548 | uid = LABEL_DECL_UID (t); |
1549 | if (uid == -1) | |
1550 | { | |
99729d91 DM |
1551 | unsigned old_len = |
1552 | vec_safe_length (label_to_block_map_for_fn (cfun)); | |
726a989a RB |
1553 | LABEL_DECL_UID (t) = uid = cfun->cfg->last_label_uid++; |
1554 | if (old_len <= (unsigned) uid) | |
1555 | { | |
5006671f | 1556 | unsigned new_len = 3 * uid / 2 + 1; |
726a989a | 1557 | |
99729d91 DM |
1558 | vec_safe_grow_cleared (label_to_block_map_for_fn (cfun), |
1559 | new_len); | |
726a989a RB |
1560 | } |
1561 | } | |
1562 | ||
99729d91 | 1563 | (*label_to_block_map_for_fn (cfun))[uid] = bb; |
726a989a RB |
1564 | } |
1565 | } | |
1566 | ||
1567 | ||
726a989a RB |
1568 | /* Modify the RHS of the assignment pointed-to by GSI using the |
1569 | operands in the expression tree EXPR. | |
1570 | ||
1571 | NOTE: The statement pointed-to by GSI may be reallocated if it | |
1572 | did not have enough operand slots. | |
1573 | ||
1574 | This function is useful to convert an existing tree expression into | |
1575 | the flat representation used for the RHS of a GIMPLE assignment. | |
1576 | It will reallocate memory as needed to expand or shrink the number | |
1577 | of operand slots needed to represent EXPR. | |
1578 | ||
1579 | NOTE: If you find yourself building a tree and then calling this | |
1580 | function, you are most certainly doing it the slow way. It is much | |
1581 | better to build a new assignment or to use the function | |
1582 | gimple_assign_set_rhs_with_ops, which does not require an | |
1583 | expression tree to be built. */ | |
1584 | ||
1585 | void | |
1586 | gimple_assign_set_rhs_from_tree (gimple_stmt_iterator *gsi, tree expr) | |
1587 | { | |
1588 | enum tree_code subcode; | |
0354c0c7 | 1589 | tree op1, op2, op3; |
726a989a | 1590 | |
d1e2bb2d | 1591 | extract_ops_from_tree (expr, &subcode, &op1, &op2, &op3); |
00d66391 | 1592 | gimple_assign_set_rhs_with_ops (gsi, subcode, op1, op2, op3); |
726a989a RB |
1593 | } |
1594 | ||
1595 | ||
1596 | /* Set the RHS of assignment statement pointed-to by GSI to CODE with | |
0354c0c7 | 1597 | operands OP1, OP2 and OP3. |
726a989a RB |
1598 | |
1599 | NOTE: The statement pointed-to by GSI may be reallocated if it | |
1600 | did not have enough operand slots. */ | |
1601 | ||
1602 | void | |
00d66391 JJ |
1603 | gimple_assign_set_rhs_with_ops (gimple_stmt_iterator *gsi, enum tree_code code, |
1604 | tree op1, tree op2, tree op3) | |
726a989a RB |
1605 | { |
1606 | unsigned new_rhs_ops = get_gimple_rhs_num_ops (code); | |
355fe088 | 1607 | gimple *stmt = gsi_stmt (*gsi); |
726a989a RB |
1608 | |
1609 | /* If the new CODE needs more operands, allocate a new statement. */ | |
1610 | if (gimple_num_ops (stmt) < new_rhs_ops + 1) | |
1611 | { | |
1612 | tree lhs = gimple_assign_lhs (stmt); | |
355fe088 | 1613 | gimple *new_stmt = gimple_alloc (gimple_code (stmt), new_rhs_ops + 1); |
726a989a | 1614 | memcpy (new_stmt, stmt, gimple_size (gimple_code (stmt))); |
355a7673 | 1615 | gimple_init_singleton (new_stmt); |
a8697b27 | 1616 | gsi_replace (gsi, new_stmt, false); |
726a989a RB |
1617 | stmt = new_stmt; |
1618 | ||
1619 | /* The LHS needs to be reset as this also changes the SSA name | |
1620 | on the LHS. */ | |
1621 | gimple_assign_set_lhs (stmt, lhs); | |
1622 | } | |
1623 | ||
1624 | gimple_set_num_ops (stmt, new_rhs_ops + 1); | |
1625 | gimple_set_subcode (stmt, code); | |
1626 | gimple_assign_set_rhs1 (stmt, op1); | |
1627 | if (new_rhs_ops > 1) | |
1628 | gimple_assign_set_rhs2 (stmt, op2); | |
0354c0c7 BS |
1629 | if (new_rhs_ops > 2) |
1630 | gimple_assign_set_rhs3 (stmt, op3); | |
726a989a RB |
1631 | } |
1632 | ||
1633 | ||
1634 | /* Return the LHS of a statement that performs an assignment, | |
1635 | either a GIMPLE_ASSIGN or a GIMPLE_CALL. Returns NULL_TREE | |
1636 | for a call to a function that returns no value, or for a | |
1637 | statement other than an assignment or a call. */ | |
1638 | ||
1639 | tree | |
355fe088 | 1640 | gimple_get_lhs (const gimple *stmt) |
726a989a | 1641 | { |
e0c68ce9 | 1642 | enum gimple_code code = gimple_code (stmt); |
726a989a RB |
1643 | |
1644 | if (code == GIMPLE_ASSIGN) | |
1645 | return gimple_assign_lhs (stmt); | |
1646 | else if (code == GIMPLE_CALL) | |
1647 | return gimple_call_lhs (stmt); | |
1648 | else | |
1649 | return NULL_TREE; | |
1650 | } | |
1651 | ||
1652 | ||
1653 | /* Set the LHS of a statement that performs an assignment, | |
1654 | either a GIMPLE_ASSIGN or a GIMPLE_CALL. */ | |
1655 | ||
1656 | void | |
355fe088 | 1657 | gimple_set_lhs (gimple *stmt, tree lhs) |
726a989a | 1658 | { |
e0c68ce9 | 1659 | enum gimple_code code = gimple_code (stmt); |
726a989a RB |
1660 | |
1661 | if (code == GIMPLE_ASSIGN) | |
1662 | gimple_assign_set_lhs (stmt, lhs); | |
1663 | else if (code == GIMPLE_CALL) | |
1664 | gimple_call_set_lhs (stmt, lhs); | |
1665 | else | |
c3284718 | 1666 | gcc_unreachable (); |
726a989a RB |
1667 | } |
1668 | ||
1669 | ||
1670 | /* Return a deep copy of statement STMT. All the operands from STMT | |
1671 | are reallocated and copied using unshare_expr. The DEF, USE, VDEF | |
355a7673 MM |
1672 | and VUSE operand arrays are set to empty in the new copy. The new |
1673 | copy isn't part of any sequence. */ | |
726a989a | 1674 | |
355fe088 TS |
1675 | gimple * |
1676 | gimple_copy (gimple *stmt) | |
726a989a RB |
1677 | { |
1678 | enum gimple_code code = gimple_code (stmt); | |
1679 | unsigned num_ops = gimple_num_ops (stmt); | |
355fe088 | 1680 | gimple *copy = gimple_alloc (code, num_ops); |
726a989a RB |
1681 | unsigned i; |
1682 | ||
1683 | /* Shallow copy all the fields from STMT. */ | |
1684 | memcpy (copy, stmt, gimple_size (code)); | |
355a7673 | 1685 | gimple_init_singleton (copy); |
726a989a RB |
1686 | |
1687 | /* If STMT has sub-statements, deep-copy them as well. */ | |
1688 | if (gimple_has_substatements (stmt)) | |
1689 | { | |
1690 | gimple_seq new_seq; | |
1691 | tree t; | |
1692 | ||
1693 | switch (gimple_code (stmt)) | |
1694 | { | |
1695 | case GIMPLE_BIND: | |
538dd0b7 DM |
1696 | { |
1697 | gbind *bind_stmt = as_a <gbind *> (stmt); | |
1698 | gbind *bind_copy = as_a <gbind *> (copy); | |
1699 | new_seq = gimple_seq_copy (gimple_bind_body (bind_stmt)); | |
1700 | gimple_bind_set_body (bind_copy, new_seq); | |
1701 | gimple_bind_set_vars (bind_copy, | |
1702 | unshare_expr (gimple_bind_vars (bind_stmt))); | |
1703 | gimple_bind_set_block (bind_copy, gimple_bind_block (bind_stmt)); | |
1704 | } | |
726a989a RB |
1705 | break; |
1706 | ||
1707 | case GIMPLE_CATCH: | |
538dd0b7 DM |
1708 | { |
1709 | gcatch *catch_stmt = as_a <gcatch *> (stmt); | |
1710 | gcatch *catch_copy = as_a <gcatch *> (copy); | |
1711 | new_seq = gimple_seq_copy (gimple_catch_handler (catch_stmt)); | |
1712 | gimple_catch_set_handler (catch_copy, new_seq); | |
1713 | t = unshare_expr (gimple_catch_types (catch_stmt)); | |
1714 | gimple_catch_set_types (catch_copy, t); | |
1715 | } | |
726a989a RB |
1716 | break; |
1717 | ||
1718 | case GIMPLE_EH_FILTER: | |
538dd0b7 DM |
1719 | { |
1720 | geh_filter *eh_filter_stmt = as_a <geh_filter *> (stmt); | |
1721 | geh_filter *eh_filter_copy = as_a <geh_filter *> (copy); | |
1722 | new_seq | |
1723 | = gimple_seq_copy (gimple_eh_filter_failure (eh_filter_stmt)); | |
1724 | gimple_eh_filter_set_failure (eh_filter_copy, new_seq); | |
1725 | t = unshare_expr (gimple_eh_filter_types (eh_filter_stmt)); | |
1726 | gimple_eh_filter_set_types (eh_filter_copy, t); | |
1727 | } | |
726a989a RB |
1728 | break; |
1729 | ||
0a35513e | 1730 | case GIMPLE_EH_ELSE: |
538dd0b7 DM |
1731 | { |
1732 | geh_else *eh_else_stmt = as_a <geh_else *> (stmt); | |
1733 | geh_else *eh_else_copy = as_a <geh_else *> (copy); | |
1734 | new_seq = gimple_seq_copy (gimple_eh_else_n_body (eh_else_stmt)); | |
1735 | gimple_eh_else_set_n_body (eh_else_copy, new_seq); | |
1736 | new_seq = gimple_seq_copy (gimple_eh_else_e_body (eh_else_stmt)); | |
1737 | gimple_eh_else_set_e_body (eh_else_copy, new_seq); | |
1738 | } | |
0a35513e AH |
1739 | break; |
1740 | ||
726a989a | 1741 | case GIMPLE_TRY: |
538dd0b7 DM |
1742 | { |
1743 | gtry *try_stmt = as_a <gtry *> (stmt); | |
1744 | gtry *try_copy = as_a <gtry *> (copy); | |
1745 | new_seq = gimple_seq_copy (gimple_try_eval (try_stmt)); | |
1746 | gimple_try_set_eval (try_copy, new_seq); | |
1747 | new_seq = gimple_seq_copy (gimple_try_cleanup (try_stmt)); | |
1748 | gimple_try_set_cleanup (try_copy, new_seq); | |
1749 | } | |
726a989a RB |
1750 | break; |
1751 | ||
1752 | case GIMPLE_OMP_FOR: | |
1753 | new_seq = gimple_seq_copy (gimple_omp_for_pre_body (stmt)); | |
1754 | gimple_omp_for_set_pre_body (copy, new_seq); | |
1755 | t = unshare_expr (gimple_omp_for_clauses (stmt)); | |
1756 | gimple_omp_for_set_clauses (copy, t); | |
daa6e488 | 1757 | { |
538dd0b7 | 1758 | gomp_for *omp_for_copy = as_a <gomp_for *> (copy); |
766090c2 TS |
1759 | omp_for_copy->iter = ggc_vec_alloc<gimple_omp_for_iter> |
1760 | ( gimple_omp_for_collapse (stmt)); | |
daa6e488 | 1761 | } |
726a989a RB |
1762 | for (i = 0; i < gimple_omp_for_collapse (stmt); i++) |
1763 | { | |
1764 | gimple_omp_for_set_cond (copy, i, | |
1765 | gimple_omp_for_cond (stmt, i)); | |
1766 | gimple_omp_for_set_index (copy, i, | |
1767 | gimple_omp_for_index (stmt, i)); | |
1768 | t = unshare_expr (gimple_omp_for_initial (stmt, i)); | |
1769 | gimple_omp_for_set_initial (copy, i, t); | |
1770 | t = unshare_expr (gimple_omp_for_final (stmt, i)); | |
1771 | gimple_omp_for_set_final (copy, i, t); | |
1772 | t = unshare_expr (gimple_omp_for_incr (stmt, i)); | |
1773 | gimple_omp_for_set_incr (copy, i, t); | |
1774 | } | |
1775 | goto copy_omp_body; | |
1776 | ||
1777 | case GIMPLE_OMP_PARALLEL: | |
538dd0b7 DM |
1778 | { |
1779 | gomp_parallel *omp_par_stmt = as_a <gomp_parallel *> (stmt); | |
1780 | gomp_parallel *omp_par_copy = as_a <gomp_parallel *> (copy); | |
1781 | t = unshare_expr (gimple_omp_parallel_clauses (omp_par_stmt)); | |
1782 | gimple_omp_parallel_set_clauses (omp_par_copy, t); | |
1783 | t = unshare_expr (gimple_omp_parallel_child_fn (omp_par_stmt)); | |
1784 | gimple_omp_parallel_set_child_fn (omp_par_copy, t); | |
1785 | t = unshare_expr (gimple_omp_parallel_data_arg (omp_par_stmt)); | |
1786 | gimple_omp_parallel_set_data_arg (omp_par_copy, t); | |
1787 | } | |
726a989a RB |
1788 | goto copy_omp_body; |
1789 | ||
1790 | case GIMPLE_OMP_TASK: | |
1791 | t = unshare_expr (gimple_omp_task_clauses (stmt)); | |
1792 | gimple_omp_task_set_clauses (copy, t); | |
1793 | t = unshare_expr (gimple_omp_task_child_fn (stmt)); | |
1794 | gimple_omp_task_set_child_fn (copy, t); | |
1795 | t = unshare_expr (gimple_omp_task_data_arg (stmt)); | |
1796 | gimple_omp_task_set_data_arg (copy, t); | |
1797 | t = unshare_expr (gimple_omp_task_copy_fn (stmt)); | |
1798 | gimple_omp_task_set_copy_fn (copy, t); | |
1799 | t = unshare_expr (gimple_omp_task_arg_size (stmt)); | |
1800 | gimple_omp_task_set_arg_size (copy, t); | |
1801 | t = unshare_expr (gimple_omp_task_arg_align (stmt)); | |
1802 | gimple_omp_task_set_arg_align (copy, t); | |
1803 | goto copy_omp_body; | |
1804 | ||
1805 | case GIMPLE_OMP_CRITICAL: | |
d9a6bd32 JJ |
1806 | t = unshare_expr (gimple_omp_critical_name |
1807 | (as_a <gomp_critical *> (stmt))); | |
538dd0b7 | 1808 | gimple_omp_critical_set_name (as_a <gomp_critical *> (copy), t); |
d9a6bd32 JJ |
1809 | t = unshare_expr (gimple_omp_critical_clauses |
1810 | (as_a <gomp_critical *> (stmt))); | |
1811 | gimple_omp_critical_set_clauses (as_a <gomp_critical *> (copy), t); | |
1812 | goto copy_omp_body; | |
1813 | ||
1814 | case GIMPLE_OMP_ORDERED: | |
1815 | t = unshare_expr (gimple_omp_ordered_clauses | |
1816 | (as_a <gomp_ordered *> (stmt))); | |
1817 | gimple_omp_ordered_set_clauses (as_a <gomp_ordered *> (copy), t); | |
726a989a RB |
1818 | goto copy_omp_body; |
1819 | ||
1820 | case GIMPLE_OMP_SECTIONS: | |
1821 | t = unshare_expr (gimple_omp_sections_clauses (stmt)); | |
1822 | gimple_omp_sections_set_clauses (copy, t); | |
1823 | t = unshare_expr (gimple_omp_sections_control (stmt)); | |
1824 | gimple_omp_sections_set_control (copy, t); | |
1825 | /* FALLTHRU */ | |
1826 | ||
1827 | case GIMPLE_OMP_SINGLE: | |
acf0174b JJ |
1828 | case GIMPLE_OMP_TARGET: |
1829 | case GIMPLE_OMP_TEAMS: | |
726a989a RB |
1830 | case GIMPLE_OMP_SECTION: |
1831 | case GIMPLE_OMP_MASTER: | |
acf0174b | 1832 | case GIMPLE_OMP_TASKGROUP: |
b2b40051 | 1833 | case GIMPLE_OMP_GRID_BODY: |
726a989a RB |
1834 | copy_omp_body: |
1835 | new_seq = gimple_seq_copy (gimple_omp_body (stmt)); | |
1836 | gimple_omp_set_body (copy, new_seq); | |
1837 | break; | |
1838 | ||
0a35513e | 1839 | case GIMPLE_TRANSACTION: |
538dd0b7 DM |
1840 | new_seq = gimple_seq_copy (gimple_transaction_body ( |
1841 | as_a <gtransaction *> (stmt))); | |
1842 | gimple_transaction_set_body (as_a <gtransaction *> (copy), | |
1843 | new_seq); | |
0a35513e AH |
1844 | break; |
1845 | ||
726a989a RB |
1846 | case GIMPLE_WITH_CLEANUP_EXPR: |
1847 | new_seq = gimple_seq_copy (gimple_wce_cleanup (stmt)); | |
1848 | gimple_wce_set_cleanup (copy, new_seq); | |
1849 | break; | |
1850 | ||
1851 | default: | |
1852 | gcc_unreachable (); | |
1853 | } | |
1854 | } | |
1855 | ||
1856 | /* Make copy of operands. */ | |
483ef49f RG |
1857 | for (i = 0; i < num_ops; i++) |
1858 | gimple_set_op (copy, i, unshare_expr (gimple_op (stmt, i))); | |
726a989a | 1859 | |
483ef49f RG |
1860 | if (gimple_has_mem_ops (stmt)) |
1861 | { | |
1862 | gimple_set_vdef (copy, gimple_vdef (stmt)); | |
1863 | gimple_set_vuse (copy, gimple_vuse (stmt)); | |
1864 | } | |
726a989a | 1865 | |
483ef49f RG |
1866 | /* Clear out SSA operand vectors on COPY. */ |
1867 | if (gimple_has_ops (stmt)) | |
1868 | { | |
483ef49f | 1869 | gimple_set_use_ops (copy, NULL); |
726a989a | 1870 | |
5006671f RG |
1871 | /* SSA operands need to be updated. */ |
1872 | gimple_set_modified (copy, true); | |
726a989a RB |
1873 | } |
1874 | ||
1875 | return copy; | |
1876 | } | |
1877 | ||
1878 | ||
726a989a RB |
1879 | /* Return true if statement S has side-effects. We consider a |
1880 | statement to have side effects if: | |
1881 | ||
1882 | - It is a GIMPLE_CALL not marked with ECF_PURE or ECF_CONST. | |
1883 | - Any of its operands are marked TREE_THIS_VOLATILE or TREE_SIDE_EFFECTS. */ | |
1884 | ||
1885 | bool | |
355fe088 | 1886 | gimple_has_side_effects (const gimple *s) |
726a989a | 1887 | { |
b5b8b0ac AO |
1888 | if (is_gimple_debug (s)) |
1889 | return false; | |
1890 | ||
726a989a RB |
1891 | /* We don't have to scan the arguments to check for |
1892 | volatile arguments, though, at present, we still | |
1893 | do a scan to check for TREE_SIDE_EFFECTS. */ | |
1894 | if (gimple_has_volatile_ops (s)) | |
1895 | return true; | |
1896 | ||
179184e3 | 1897 | if (gimple_code (s) == GIMPLE_ASM |
538dd0b7 | 1898 | && gimple_asm_volatile_p (as_a <const gasm *> (s))) |
179184e3 RG |
1899 | return true; |
1900 | ||
726a989a RB |
1901 | if (is_gimple_call (s)) |
1902 | { | |
723afc44 | 1903 | int flags = gimple_call_flags (s); |
726a989a | 1904 | |
723afc44 RG |
1905 | /* An infinite loop is considered a side effect. */ |
1906 | if (!(flags & (ECF_CONST | ECF_PURE)) | |
1907 | || (flags & ECF_LOOPING_CONST_OR_PURE)) | |
726a989a RB |
1908 | return true; |
1909 | ||
726a989a RB |
1910 | return false; |
1911 | } | |
726a989a RB |
1912 | |
1913 | return false; | |
1914 | } | |
1915 | ||
726a989a | 1916 | /* Helper for gimple_could_trap_p and gimple_assign_rhs_could_trap_p. |
e1fd038a SP |
1917 | Return true if S can trap. When INCLUDE_MEM is true, check whether |
1918 | the memory operations could trap. When INCLUDE_STORES is true and | |
1919 | S is a GIMPLE_ASSIGN, the LHS of the assignment is also checked. */ | |
726a989a | 1920 | |
e1fd038a | 1921 | bool |
355fe088 | 1922 | gimple_could_trap_p_1 (gimple *s, bool include_mem, bool include_stores) |
726a989a | 1923 | { |
726a989a RB |
1924 | tree t, div = NULL_TREE; |
1925 | enum tree_code op; | |
1926 | ||
e1fd038a SP |
1927 | if (include_mem) |
1928 | { | |
1929 | unsigned i, start = (is_gimple_assign (s) && !include_stores) ? 1 : 0; | |
726a989a | 1930 | |
e1fd038a SP |
1931 | for (i = start; i < gimple_num_ops (s); i++) |
1932 | if (tree_could_trap_p (gimple_op (s, i))) | |
1933 | return true; | |
1934 | } | |
726a989a RB |
1935 | |
1936 | switch (gimple_code (s)) | |
1937 | { | |
1938 | case GIMPLE_ASM: | |
538dd0b7 | 1939 | return gimple_asm_volatile_p (as_a <gasm *> (s)); |
726a989a RB |
1940 | |
1941 | case GIMPLE_CALL: | |
1942 | t = gimple_call_fndecl (s); | |
1943 | /* Assume that calls to weak functions may trap. */ | |
1944 | if (!t || !DECL_P (t) || DECL_WEAK (t)) | |
1945 | return true; | |
1946 | return false; | |
1947 | ||
1948 | case GIMPLE_ASSIGN: | |
1949 | t = gimple_expr_type (s); | |
1950 | op = gimple_assign_rhs_code (s); | |
1951 | if (get_gimple_rhs_class (op) == GIMPLE_BINARY_RHS) | |
1952 | div = gimple_assign_rhs2 (s); | |
1953 | return (operation_could_trap_p (op, FLOAT_TYPE_P (t), | |
1954 | (INTEGRAL_TYPE_P (t) | |
1955 | && TYPE_OVERFLOW_TRAPS (t)), | |
1956 | div)); | |
1957 | ||
46ec7a06 RB |
1958 | case GIMPLE_COND: |
1959 | t = TREE_TYPE (gimple_cond_lhs (s)); | |
1960 | return operation_could_trap_p (gimple_cond_code (s), | |
1961 | FLOAT_TYPE_P (t), false, NULL_TREE); | |
1962 | ||
726a989a RB |
1963 | default: |
1964 | break; | |
1965 | } | |
1966 | ||
1967 | return false; | |
726a989a RB |
1968 | } |
1969 | ||
726a989a RB |
1970 | /* Return true if statement S can trap. */ |
1971 | ||
1972 | bool | |
355fe088 | 1973 | gimple_could_trap_p (gimple *s) |
726a989a | 1974 | { |
e1fd038a | 1975 | return gimple_could_trap_p_1 (s, true, true); |
726a989a RB |
1976 | } |
1977 | ||
726a989a RB |
1978 | /* Return true if RHS of a GIMPLE_ASSIGN S can trap. */ |
1979 | ||
1980 | bool | |
355fe088 | 1981 | gimple_assign_rhs_could_trap_p (gimple *s) |
726a989a RB |
1982 | { |
1983 | gcc_assert (is_gimple_assign (s)); | |
e1fd038a | 1984 | return gimple_could_trap_p_1 (s, true, false); |
726a989a RB |
1985 | } |
1986 | ||
1987 | ||
1988 | /* Print debugging information for gimple stmts generated. */ | |
1989 | ||
1990 | void | |
1991 | dump_gimple_statistics (void) | |
1992 | { | |
726a989a RB |
1993 | int i, total_tuples = 0, total_bytes = 0; |
1994 | ||
7aa6d18a SB |
1995 | if (! GATHER_STATISTICS) |
1996 | { | |
1997 | fprintf (stderr, "No gimple statistics\n"); | |
1998 | return; | |
1999 | } | |
2000 | ||
726a989a RB |
2001 | fprintf (stderr, "\nGIMPLE statements\n"); |
2002 | fprintf (stderr, "Kind Stmts Bytes\n"); | |
2003 | fprintf (stderr, "---------------------------------------\n"); | |
2004 | for (i = 0; i < (int) gimple_alloc_kind_all; ++i) | |
2005 | { | |
2006 | fprintf (stderr, "%-20s %7d %10d\n", gimple_alloc_kind_names[i], | |
2007 | gimple_alloc_counts[i], gimple_alloc_sizes[i]); | |
2008 | total_tuples += gimple_alloc_counts[i]; | |
2009 | total_bytes += gimple_alloc_sizes[i]; | |
2010 | } | |
2011 | fprintf (stderr, "---------------------------------------\n"); | |
2012 | fprintf (stderr, "%-20s %7d %10d\n", "Total", total_tuples, total_bytes); | |
2013 | fprintf (stderr, "---------------------------------------\n"); | |
726a989a RB |
2014 | } |
2015 | ||
2016 | ||
726a989a RB |
2017 | /* Return the number of operands needed on the RHS of a GIMPLE |
2018 | assignment for an expression with tree code CODE. */ | |
2019 | ||
2020 | unsigned | |
2021 | get_gimple_rhs_num_ops (enum tree_code code) | |
2022 | { | |
2023 | enum gimple_rhs_class rhs_class = get_gimple_rhs_class (code); | |
2024 | ||
2025 | if (rhs_class == GIMPLE_UNARY_RHS || rhs_class == GIMPLE_SINGLE_RHS) | |
2026 | return 1; | |
2027 | else if (rhs_class == GIMPLE_BINARY_RHS) | |
2028 | return 2; | |
0354c0c7 BS |
2029 | else if (rhs_class == GIMPLE_TERNARY_RHS) |
2030 | return 3; | |
726a989a RB |
2031 | else |
2032 | gcc_unreachable (); | |
2033 | } | |
2034 | ||
2035 | #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \ | |
2036 | (unsigned char) \ | |
2037 | ((TYPE) == tcc_unary ? GIMPLE_UNARY_RHS \ | |
2038 | : ((TYPE) == tcc_binary \ | |
2039 | || (TYPE) == tcc_comparison) ? GIMPLE_BINARY_RHS \ | |
2040 | : ((TYPE) == tcc_constant \ | |
2041 | || (TYPE) == tcc_declaration \ | |
2042 | || (TYPE) == tcc_reference) ? GIMPLE_SINGLE_RHS \ | |
2043 | : ((SYM) == TRUTH_AND_EXPR \ | |
2044 | || (SYM) == TRUTH_OR_EXPR \ | |
2045 | || (SYM) == TRUTH_XOR_EXPR) ? GIMPLE_BINARY_RHS \ | |
2046 | : (SYM) == TRUTH_NOT_EXPR ? GIMPLE_UNARY_RHS \ | |
4e71066d RG |
2047 | : ((SYM) == COND_EXPR \ |
2048 | || (SYM) == WIDEN_MULT_PLUS_EXPR \ | |
16949072 | 2049 | || (SYM) == WIDEN_MULT_MINUS_EXPR \ |
f471fe72 | 2050 | || (SYM) == DOT_PROD_EXPR \ |
79d652a5 | 2051 | || (SYM) == SAD_EXPR \ |
f471fe72 | 2052 | || (SYM) == REALIGN_LOAD_EXPR \ |
4e71066d | 2053 | || (SYM) == VEC_COND_EXPR \ |
2205ed25 | 2054 | || (SYM) == VEC_PERM_EXPR \ |
483c6429 | 2055 | || (SYM) == BIT_INSERT_EXPR \ |
16949072 | 2056 | || (SYM) == FMA_EXPR) ? GIMPLE_TERNARY_RHS \ |
4e71066d | 2057 | : ((SYM) == CONSTRUCTOR \ |
726a989a RB |
2058 | || (SYM) == OBJ_TYPE_REF \ |
2059 | || (SYM) == ASSERT_EXPR \ | |
2060 | || (SYM) == ADDR_EXPR \ | |
2061 | || (SYM) == WITH_SIZE_EXPR \ | |
4e71066d | 2062 | || (SYM) == SSA_NAME) ? GIMPLE_SINGLE_RHS \ |
726a989a RB |
2063 | : GIMPLE_INVALID_RHS), |
2064 | #define END_OF_BASE_TREE_CODES (unsigned char) GIMPLE_INVALID_RHS, | |
2065 | ||
2066 | const unsigned char gimple_rhs_class_table[] = { | |
2067 | #include "all-tree.def" | |
2068 | }; | |
2069 | ||
2070 | #undef DEFTREECODE | |
2071 | #undef END_OF_BASE_TREE_CODES | |
2072 | ||
726a989a RB |
2073 | /* Canonicalize a tree T for use in a COND_EXPR as conditional. Returns |
2074 | a canonicalized tree that is valid for a COND_EXPR or NULL_TREE, if | |
2075 | we failed to create one. */ | |
2076 | ||
2077 | tree | |
2078 | canonicalize_cond_expr_cond (tree t) | |
2079 | { | |
b66a1bac RG |
2080 | /* Strip conversions around boolean operations. */ |
2081 | if (CONVERT_EXPR_P (t) | |
9b80d091 KT |
2082 | && (truth_value_p (TREE_CODE (TREE_OPERAND (t, 0))) |
2083 | || TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) | |
2084 | == BOOLEAN_TYPE)) | |
b66a1bac RG |
2085 | t = TREE_OPERAND (t, 0); |
2086 | ||
726a989a | 2087 | /* For !x use x == 0. */ |
12430896 | 2088 | if (TREE_CODE (t) == TRUTH_NOT_EXPR) |
726a989a RB |
2089 | { |
2090 | tree top0 = TREE_OPERAND (t, 0); | |
2091 | t = build2 (EQ_EXPR, TREE_TYPE (t), | |
2092 | top0, build_int_cst (TREE_TYPE (top0), 0)); | |
2093 | } | |
2094 | /* For cmp ? 1 : 0 use cmp. */ | |
2095 | else if (TREE_CODE (t) == COND_EXPR | |
2096 | && COMPARISON_CLASS_P (TREE_OPERAND (t, 0)) | |
2097 | && integer_onep (TREE_OPERAND (t, 1)) | |
2098 | && integer_zerop (TREE_OPERAND (t, 2))) | |
2099 | { | |
2100 | tree top0 = TREE_OPERAND (t, 0); | |
2101 | t = build2 (TREE_CODE (top0), TREE_TYPE (t), | |
2102 | TREE_OPERAND (top0, 0), TREE_OPERAND (top0, 1)); | |
2103 | } | |
4481581f JL |
2104 | /* For x ^ y use x != y. */ |
2105 | else if (TREE_CODE (t) == BIT_XOR_EXPR) | |
2106 | t = build2 (NE_EXPR, TREE_TYPE (t), | |
2107 | TREE_OPERAND (t, 0), TREE_OPERAND (t, 1)); | |
2108 | ||
726a989a RB |
2109 | if (is_gimple_condexpr (t)) |
2110 | return t; | |
2111 | ||
2112 | return NULL_TREE; | |
2113 | } | |
2114 | ||
e6c99067 DN |
2115 | /* Build a GIMPLE_CALL identical to STMT but skipping the arguments in |
2116 | the positions marked by the set ARGS_TO_SKIP. */ | |
2117 | ||
538dd0b7 DM |
2118 | gcall * |
2119 | gimple_call_copy_skip_args (gcall *stmt, bitmap args_to_skip) | |
c6f7cfc1 JH |
2120 | { |
2121 | int i; | |
c6f7cfc1 | 2122 | int nargs = gimple_call_num_args (stmt); |
ef062b13 | 2123 | auto_vec<tree> vargs (nargs); |
538dd0b7 | 2124 | gcall *new_stmt; |
c6f7cfc1 JH |
2125 | |
2126 | for (i = 0; i < nargs; i++) | |
2127 | if (!bitmap_bit_p (args_to_skip, i)) | |
9771b263 | 2128 | vargs.quick_push (gimple_call_arg (stmt, i)); |
c6f7cfc1 | 2129 | |
25583c4f RS |
2130 | if (gimple_call_internal_p (stmt)) |
2131 | new_stmt = gimple_build_call_internal_vec (gimple_call_internal_fn (stmt), | |
2132 | vargs); | |
2133 | else | |
2134 | new_stmt = gimple_build_call_vec (gimple_call_fn (stmt), vargs); | |
ef062b13 | 2135 | |
c6f7cfc1 JH |
2136 | if (gimple_call_lhs (stmt)) |
2137 | gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt)); | |
2138 | ||
5006671f RG |
2139 | gimple_set_vuse (new_stmt, gimple_vuse (stmt)); |
2140 | gimple_set_vdef (new_stmt, gimple_vdef (stmt)); | |
2141 | ||
c6f7cfc1 JH |
2142 | if (gimple_has_location (stmt)) |
2143 | gimple_set_location (new_stmt, gimple_location (stmt)); | |
8d2adc24 | 2144 | gimple_call_copy_flags (new_stmt, stmt); |
c6f7cfc1 | 2145 | gimple_call_set_chain (new_stmt, gimple_call_chain (stmt)); |
5006671f RG |
2146 | |
2147 | gimple_set_modified (new_stmt, true); | |
2148 | ||
c6f7cfc1 JH |
2149 | return new_stmt; |
2150 | } | |
2151 | ||
5006671f | 2152 | |
d7f09764 | 2153 | |
d025732d EB |
2154 | /* Return true if the field decls F1 and F2 are at the same offset. |
2155 | ||
91f2fae8 | 2156 | This is intended to be used on GIMPLE types only. */ |
d7f09764 | 2157 | |
1e4bc4eb | 2158 | bool |
d025732d | 2159 | gimple_compare_field_offset (tree f1, tree f2) |
d7f09764 DN |
2160 | { |
2161 | if (DECL_OFFSET_ALIGN (f1) == DECL_OFFSET_ALIGN (f2)) | |
d025732d EB |
2162 | { |
2163 | tree offset1 = DECL_FIELD_OFFSET (f1); | |
2164 | tree offset2 = DECL_FIELD_OFFSET (f2); | |
2165 | return ((offset1 == offset2 | |
2166 | /* Once gimplification is done, self-referential offsets are | |
2167 | instantiated as operand #2 of the COMPONENT_REF built for | |
2168 | each access and reset. Therefore, they are not relevant | |
2169 | anymore and fields are interchangeable provided that they | |
2170 | represent the same access. */ | |
2171 | || (TREE_CODE (offset1) == PLACEHOLDER_EXPR | |
2172 | && TREE_CODE (offset2) == PLACEHOLDER_EXPR | |
2173 | && (DECL_SIZE (f1) == DECL_SIZE (f2) | |
2174 | || (TREE_CODE (DECL_SIZE (f1)) == PLACEHOLDER_EXPR | |
2175 | && TREE_CODE (DECL_SIZE (f2)) == PLACEHOLDER_EXPR) | |
2176 | || operand_equal_p (DECL_SIZE (f1), DECL_SIZE (f2), 0)) | |
2177 | && DECL_ALIGN (f1) == DECL_ALIGN (f2)) | |
2178 | || operand_equal_p (offset1, offset2, 0)) | |
2179 | && tree_int_cst_equal (DECL_FIELD_BIT_OFFSET (f1), | |
2180 | DECL_FIELD_BIT_OFFSET (f2))); | |
2181 | } | |
d7f09764 DN |
2182 | |
2183 | /* Fortran and C do not always agree on what DECL_OFFSET_ALIGN | |
2184 | should be, so handle differing ones specially by decomposing | |
2185 | the offset into a byte and bit offset manually. */ | |
9541ffee RS |
2186 | if (tree_fits_shwi_p (DECL_FIELD_OFFSET (f1)) |
2187 | && tree_fits_shwi_p (DECL_FIELD_OFFSET (f2))) | |
d7f09764 DN |
2188 | { |
2189 | unsigned HOST_WIDE_INT byte_offset1, byte_offset2; | |
2190 | unsigned HOST_WIDE_INT bit_offset1, bit_offset2; | |
2191 | bit_offset1 = TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f1)); | |
2192 | byte_offset1 = (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f1)) | |
2193 | + bit_offset1 / BITS_PER_UNIT); | |
2194 | bit_offset2 = TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f2)); | |
2195 | byte_offset2 = (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f2)) | |
2196 | + bit_offset2 / BITS_PER_UNIT); | |
2197 | if (byte_offset1 != byte_offset2) | |
2198 | return false; | |
2199 | return bit_offset1 % BITS_PER_UNIT == bit_offset2 % BITS_PER_UNIT; | |
2200 | } | |
2201 | ||
2202 | return false; | |
2203 | } | |
2204 | ||
d7f09764 DN |
2205 | |
2206 | /* Return a type the same as TYPE except unsigned or | |
2207 | signed according to UNSIGNEDP. */ | |
2208 | ||
2209 | static tree | |
2210 | gimple_signed_or_unsigned_type (bool unsignedp, tree type) | |
2211 | { | |
2212 | tree type1; | |
78a7c317 | 2213 | int i; |
d7f09764 DN |
2214 | |
2215 | type1 = TYPE_MAIN_VARIANT (type); | |
2216 | if (type1 == signed_char_type_node | |
2217 | || type1 == char_type_node | |
2218 | || type1 == unsigned_char_type_node) | |
2219 | return unsignedp ? unsigned_char_type_node : signed_char_type_node; | |
2220 | if (type1 == integer_type_node || type1 == unsigned_type_node) | |
2221 | return unsignedp ? unsigned_type_node : integer_type_node; | |
2222 | if (type1 == short_integer_type_node || type1 == short_unsigned_type_node) | |
2223 | return unsignedp ? short_unsigned_type_node : short_integer_type_node; | |
2224 | if (type1 == long_integer_type_node || type1 == long_unsigned_type_node) | |
2225 | return unsignedp ? long_unsigned_type_node : long_integer_type_node; | |
2226 | if (type1 == long_long_integer_type_node | |
2227 | || type1 == long_long_unsigned_type_node) | |
2228 | return unsignedp | |
2229 | ? long_long_unsigned_type_node | |
2230 | : long_long_integer_type_node; | |
78a7c317 DD |
2231 | |
2232 | for (i = 0; i < NUM_INT_N_ENTS; i ++) | |
2233 | if (int_n_enabled_p[i] | |
2234 | && (type1 == int_n_trees[i].unsigned_type | |
2235 | || type1 == int_n_trees[i].signed_type)) | |
2236 | return unsignedp | |
2237 | ? int_n_trees[i].unsigned_type | |
2238 | : int_n_trees[i].signed_type; | |
2239 | ||
d7f09764 DN |
2240 | #if HOST_BITS_PER_WIDE_INT >= 64 |
2241 | if (type1 == intTI_type_node || type1 == unsigned_intTI_type_node) | |
2242 | return unsignedp ? unsigned_intTI_type_node : intTI_type_node; | |
2243 | #endif | |
2244 | if (type1 == intDI_type_node || type1 == unsigned_intDI_type_node) | |
2245 | return unsignedp ? unsigned_intDI_type_node : intDI_type_node; | |
2246 | if (type1 == intSI_type_node || type1 == unsigned_intSI_type_node) | |
2247 | return unsignedp ? unsigned_intSI_type_node : intSI_type_node; | |
2248 | if (type1 == intHI_type_node || type1 == unsigned_intHI_type_node) | |
2249 | return unsignedp ? unsigned_intHI_type_node : intHI_type_node; | |
2250 | if (type1 == intQI_type_node || type1 == unsigned_intQI_type_node) | |
2251 | return unsignedp ? unsigned_intQI_type_node : intQI_type_node; | |
2252 | ||
2253 | #define GIMPLE_FIXED_TYPES(NAME) \ | |
2254 | if (type1 == short_ ## NAME ## _type_node \ | |
2255 | || type1 == unsigned_short_ ## NAME ## _type_node) \ | |
2256 | return unsignedp ? unsigned_short_ ## NAME ## _type_node \ | |
2257 | : short_ ## NAME ## _type_node; \ | |
2258 | if (type1 == NAME ## _type_node \ | |
2259 | || type1 == unsigned_ ## NAME ## _type_node) \ | |
2260 | return unsignedp ? unsigned_ ## NAME ## _type_node \ | |
2261 | : NAME ## _type_node; \ | |
2262 | if (type1 == long_ ## NAME ## _type_node \ | |
2263 | || type1 == unsigned_long_ ## NAME ## _type_node) \ | |
2264 | return unsignedp ? unsigned_long_ ## NAME ## _type_node \ | |
2265 | : long_ ## NAME ## _type_node; \ | |
2266 | if (type1 == long_long_ ## NAME ## _type_node \ | |
2267 | || type1 == unsigned_long_long_ ## NAME ## _type_node) \ | |
2268 | return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \ | |
2269 | : long_long_ ## NAME ## _type_node; | |
2270 | ||
2271 | #define GIMPLE_FIXED_MODE_TYPES(NAME) \ | |
2272 | if (type1 == NAME ## _type_node \ | |
2273 | || type1 == u ## NAME ## _type_node) \ | |
2274 | return unsignedp ? u ## NAME ## _type_node \ | |
2275 | : NAME ## _type_node; | |
2276 | ||
2277 | #define GIMPLE_FIXED_TYPES_SAT(NAME) \ | |
2278 | if (type1 == sat_ ## short_ ## NAME ## _type_node \ | |
2279 | || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \ | |
2280 | return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \ | |
2281 | : sat_ ## short_ ## NAME ## _type_node; \ | |
2282 | if (type1 == sat_ ## NAME ## _type_node \ | |
2283 | || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \ | |
2284 | return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \ | |
2285 | : sat_ ## NAME ## _type_node; \ | |
2286 | if (type1 == sat_ ## long_ ## NAME ## _type_node \ | |
2287 | || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \ | |
2288 | return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \ | |
2289 | : sat_ ## long_ ## NAME ## _type_node; \ | |
2290 | if (type1 == sat_ ## long_long_ ## NAME ## _type_node \ | |
2291 | || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \ | |
2292 | return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \ | |
2293 | : sat_ ## long_long_ ## NAME ## _type_node; | |
2294 | ||
2295 | #define GIMPLE_FIXED_MODE_TYPES_SAT(NAME) \ | |
2296 | if (type1 == sat_ ## NAME ## _type_node \ | |
2297 | || type1 == sat_ ## u ## NAME ## _type_node) \ | |
2298 | return unsignedp ? sat_ ## u ## NAME ## _type_node \ | |
2299 | : sat_ ## NAME ## _type_node; | |
2300 | ||
2301 | GIMPLE_FIXED_TYPES (fract); | |
2302 | GIMPLE_FIXED_TYPES_SAT (fract); | |
2303 | GIMPLE_FIXED_TYPES (accum); | |
2304 | GIMPLE_FIXED_TYPES_SAT (accum); | |
2305 | ||
2306 | GIMPLE_FIXED_MODE_TYPES (qq); | |
2307 | GIMPLE_FIXED_MODE_TYPES (hq); | |
2308 | GIMPLE_FIXED_MODE_TYPES (sq); | |
2309 | GIMPLE_FIXED_MODE_TYPES (dq); | |
2310 | GIMPLE_FIXED_MODE_TYPES (tq); | |
2311 | GIMPLE_FIXED_MODE_TYPES_SAT (qq); | |
2312 | GIMPLE_FIXED_MODE_TYPES_SAT (hq); | |
2313 | GIMPLE_FIXED_MODE_TYPES_SAT (sq); | |
2314 | GIMPLE_FIXED_MODE_TYPES_SAT (dq); | |
2315 | GIMPLE_FIXED_MODE_TYPES_SAT (tq); | |
2316 | GIMPLE_FIXED_MODE_TYPES (ha); | |
2317 | GIMPLE_FIXED_MODE_TYPES (sa); | |
2318 | GIMPLE_FIXED_MODE_TYPES (da); | |
2319 | GIMPLE_FIXED_MODE_TYPES (ta); | |
2320 | GIMPLE_FIXED_MODE_TYPES_SAT (ha); | |
2321 | GIMPLE_FIXED_MODE_TYPES_SAT (sa); | |
2322 | GIMPLE_FIXED_MODE_TYPES_SAT (da); | |
2323 | GIMPLE_FIXED_MODE_TYPES_SAT (ta); | |
2324 | ||
2325 | /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not | |
2326 | the precision; they have precision set to match their range, but | |
2327 | may use a wider mode to match an ABI. If we change modes, we may | |
2328 | wind up with bad conversions. For INTEGER_TYPEs in C, must check | |
2329 | the precision as well, so as to yield correct results for | |
2330 | bit-field types. C++ does not have these separate bit-field | |
2331 | types, and producing a signed or unsigned variant of an | |
2332 | ENUMERAL_TYPE may cause other problems as well. */ | |
2333 | if (!INTEGRAL_TYPE_P (type) | |
2334 | || TYPE_UNSIGNED (type) == unsignedp) | |
2335 | return type; | |
2336 | ||
2337 | #define TYPE_OK(node) \ | |
2338 | (TYPE_MODE (type) == TYPE_MODE (node) \ | |
2339 | && TYPE_PRECISION (type) == TYPE_PRECISION (node)) | |
2340 | if (TYPE_OK (signed_char_type_node)) | |
2341 | return unsignedp ? unsigned_char_type_node : signed_char_type_node; | |
2342 | if (TYPE_OK (integer_type_node)) | |
2343 | return unsignedp ? unsigned_type_node : integer_type_node; | |
2344 | if (TYPE_OK (short_integer_type_node)) | |
2345 | return unsignedp ? short_unsigned_type_node : short_integer_type_node; | |
2346 | if (TYPE_OK (long_integer_type_node)) | |
2347 | return unsignedp ? long_unsigned_type_node : long_integer_type_node; | |
2348 | if (TYPE_OK (long_long_integer_type_node)) | |
2349 | return (unsignedp | |
2350 | ? long_long_unsigned_type_node | |
2351 | : long_long_integer_type_node); | |
78a7c317 DD |
2352 | |
2353 | for (i = 0; i < NUM_INT_N_ENTS; i ++) | |
2354 | if (int_n_enabled_p[i] | |
2355 | && TYPE_MODE (type) == int_n_data[i].m | |
2356 | && TYPE_PRECISION (type) == int_n_data[i].bitsize) | |
2357 | return unsignedp | |
2358 | ? int_n_trees[i].unsigned_type | |
2359 | : int_n_trees[i].signed_type; | |
d7f09764 DN |
2360 | |
2361 | #if HOST_BITS_PER_WIDE_INT >= 64 | |
2362 | if (TYPE_OK (intTI_type_node)) | |
2363 | return unsignedp ? unsigned_intTI_type_node : intTI_type_node; | |
2364 | #endif | |
2365 | if (TYPE_OK (intDI_type_node)) | |
2366 | return unsignedp ? unsigned_intDI_type_node : intDI_type_node; | |
2367 | if (TYPE_OK (intSI_type_node)) | |
2368 | return unsignedp ? unsigned_intSI_type_node : intSI_type_node; | |
2369 | if (TYPE_OK (intHI_type_node)) | |
2370 | return unsignedp ? unsigned_intHI_type_node : intHI_type_node; | |
2371 | if (TYPE_OK (intQI_type_node)) | |
2372 | return unsignedp ? unsigned_intQI_type_node : intQI_type_node; | |
2373 | ||
2374 | #undef GIMPLE_FIXED_TYPES | |
2375 | #undef GIMPLE_FIXED_MODE_TYPES | |
2376 | #undef GIMPLE_FIXED_TYPES_SAT | |
2377 | #undef GIMPLE_FIXED_MODE_TYPES_SAT | |
2378 | #undef TYPE_OK | |
2379 | ||
2380 | return build_nonstandard_integer_type (TYPE_PRECISION (type), unsignedp); | |
2381 | } | |
2382 | ||
2383 | ||
2384 | /* Return an unsigned type the same as TYPE in other respects. */ | |
2385 | ||
2386 | tree | |
2387 | gimple_unsigned_type (tree type) | |
2388 | { | |
2389 | return gimple_signed_or_unsigned_type (true, type); | |
2390 | } | |
2391 | ||
2392 | ||
2393 | /* Return a signed type the same as TYPE in other respects. */ | |
2394 | ||
2395 | tree | |
2396 | gimple_signed_type (tree type) | |
2397 | { | |
2398 | return gimple_signed_or_unsigned_type (false, type); | |
2399 | } | |
2400 | ||
2401 | ||
2402 | /* Return the typed-based alias set for T, which may be an expression | |
2403 | or a type. Return -1 if we don't do anything special. */ | |
2404 | ||
2405 | alias_set_type | |
2406 | gimple_get_alias_set (tree t) | |
2407 | { | |
d7f09764 DN |
2408 | /* That's all the expressions we handle specially. */ |
2409 | if (!TYPE_P (t)) | |
2410 | return -1; | |
2411 | ||
2412 | /* For convenience, follow the C standard when dealing with | |
2413 | character types. Any object may be accessed via an lvalue that | |
2414 | has character type. */ | |
2415 | if (t == char_type_node | |
2416 | || t == signed_char_type_node | |
2417 | || t == unsigned_char_type_node) | |
2418 | return 0; | |
2419 | ||
2420 | /* Allow aliasing between signed and unsigned variants of the same | |
2421 | type. We treat the signed variant as canonical. */ | |
2422 | if (TREE_CODE (t) == INTEGER_TYPE && TYPE_UNSIGNED (t)) | |
2423 | { | |
2424 | tree t1 = gimple_signed_type (t); | |
2425 | ||
2426 | /* t1 == t can happen for boolean nodes which are always unsigned. */ | |
2427 | if (t1 != t) | |
2428 | return get_alias_set (t1); | |
2429 | } | |
d7f09764 DN |
2430 | |
2431 | return -1; | |
2432 | } | |
2433 | ||
2434 | ||
ccacdf06 RG |
2435 | /* Helper for gimple_ior_addresses_taken_1. */ |
2436 | ||
2437 | static bool | |
355fe088 | 2438 | gimple_ior_addresses_taken_1 (gimple *, tree addr, tree, void *data) |
ccacdf06 RG |
2439 | { |
2440 | bitmap addresses_taken = (bitmap)data; | |
2ea9dc64 RG |
2441 | addr = get_base_address (addr); |
2442 | if (addr | |
2443 | && DECL_P (addr)) | |
ccacdf06 RG |
2444 | { |
2445 | bitmap_set_bit (addresses_taken, DECL_UID (addr)); | |
2446 | return true; | |
2447 | } | |
2448 | return false; | |
2449 | } | |
2450 | ||
2451 | /* Set the bit for the uid of all decls that have their address taken | |
2452 | in STMT in the ADDRESSES_TAKEN bitmap. Returns true if there | |
2453 | were any in this stmt. */ | |
2454 | ||
2455 | bool | |
355fe088 | 2456 | gimple_ior_addresses_taken (bitmap addresses_taken, gimple *stmt) |
ccacdf06 RG |
2457 | { |
2458 | return walk_stmt_load_store_addr_ops (stmt, addresses_taken, NULL, NULL, | |
2459 | gimple_ior_addresses_taken_1); | |
2460 | } | |
2461 | ||
4537ec0c | 2462 | |
5c944c6c RB |
2463 | /* Return true when STMTs arguments and return value match those of FNDECL, |
2464 | a decl of a builtin function. */ | |
3626621a | 2465 | |
5c944c6c | 2466 | bool |
355fe088 | 2467 | gimple_builtin_call_types_compatible_p (const gimple *stmt, tree fndecl) |
3626621a | 2468 | { |
5c944c6c RB |
2469 | gcc_checking_assert (DECL_BUILT_IN_CLASS (fndecl) != NOT_BUILT_IN); |
2470 | ||
2471 | tree ret = gimple_call_lhs (stmt); | |
2472 | if (ret | |
2ad3adf1 JJ |
2473 | && !useless_type_conversion_p (TREE_TYPE (ret), |
2474 | TREE_TYPE (TREE_TYPE (fndecl)))) | |
5c944c6c RB |
2475 | return false; |
2476 | ||
3626621a RB |
2477 | tree targs = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); |
2478 | unsigned nargs = gimple_call_num_args (stmt); | |
2479 | for (unsigned i = 0; i < nargs; ++i) | |
2480 | { | |
2481 | /* Variadic args follow. */ | |
2482 | if (!targs) | |
2483 | return true; | |
2484 | tree arg = gimple_call_arg (stmt, i); | |
fd39794a JJ |
2485 | tree type = TREE_VALUE (targs); |
2486 | if (!useless_type_conversion_p (type, TREE_TYPE (arg)) | |
2487 | /* char/short integral arguments are promoted to int | |
2488 | by several frontends if targetm.calls.promote_prototypes | |
2489 | is true. Allow such promotion too. */ | |
2490 | && !(INTEGRAL_TYPE_P (type) | |
2491 | && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node) | |
2492 | && targetm.calls.promote_prototypes (TREE_TYPE (fndecl)) | |
2493 | && useless_type_conversion_p (integer_type_node, | |
2494 | TREE_TYPE (arg)))) | |
3626621a RB |
2495 | return false; |
2496 | targs = TREE_CHAIN (targs); | |
2497 | } | |
2498 | if (targs && !VOID_TYPE_P (TREE_VALUE (targs))) | |
2499 | return false; | |
2500 | return true; | |
2501 | } | |
2502 | ||
5c944c6c RB |
2503 | /* Return true when STMT is builtins call. */ |
2504 | ||
2505 | bool | |
355fe088 | 2506 | gimple_call_builtin_p (const gimple *stmt) |
5c944c6c RB |
2507 | { |
2508 | tree fndecl; | |
2509 | if (is_gimple_call (stmt) | |
2510 | && (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE | |
2511 | && DECL_BUILT_IN_CLASS (fndecl) != NOT_BUILT_IN) | |
2512 | return gimple_builtin_call_types_compatible_p (stmt, fndecl); | |
2513 | return false; | |
2514 | } | |
2515 | ||
3626621a RB |
2516 | /* Return true when STMT is builtins call to CLASS. */ |
2517 | ||
2518 | bool | |
355fe088 | 2519 | gimple_call_builtin_p (const gimple *stmt, enum built_in_class klass) |
3626621a RB |
2520 | { |
2521 | tree fndecl; | |
2522 | if (is_gimple_call (stmt) | |
2523 | && (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE | |
2524 | && DECL_BUILT_IN_CLASS (fndecl) == klass) | |
5c944c6c | 2525 | return gimple_builtin_call_types_compatible_p (stmt, fndecl); |
3626621a RB |
2526 | return false; |
2527 | } | |
2528 | ||
2529 | /* Return true when STMT is builtins call to CODE of CLASS. */ | |
c54c785d JH |
2530 | |
2531 | bool | |
355fe088 | 2532 | gimple_call_builtin_p (const gimple *stmt, enum built_in_function code) |
c54c785d JH |
2533 | { |
2534 | tree fndecl; | |
3626621a RB |
2535 | if (is_gimple_call (stmt) |
2536 | && (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE | |
2537 | && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL | |
2538 | && DECL_FUNCTION_CODE (fndecl) == code) | |
5c944c6c | 2539 | return gimple_builtin_call_types_compatible_p (stmt, fndecl); |
3626621a | 2540 | return false; |
c54c785d JH |
2541 | } |
2542 | ||
00175cb2 RS |
2543 | /* If CALL is a call to a combined_fn (i.e. an internal function or |
2544 | a normal built-in function), return its code, otherwise return | |
2545 | CFN_LAST. */ | |
2546 | ||
2547 | combined_fn | |
2548 | gimple_call_combined_fn (const gimple *stmt) | |
2549 | { | |
2550 | if (const gcall *call = dyn_cast <const gcall *> (stmt)) | |
2551 | { | |
2552 | if (gimple_call_internal_p (call)) | |
2553 | return as_combined_fn (gimple_call_internal_fn (call)); | |
2554 | ||
2555 | tree fndecl = gimple_call_fndecl (stmt); | |
2556 | if (fndecl | |
2557 | && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL | |
2558 | && gimple_builtin_call_types_compatible_p (stmt, fndecl)) | |
2559 | return as_combined_fn (DECL_FUNCTION_CODE (fndecl)); | |
2560 | } | |
2561 | return CFN_LAST; | |
2562 | } | |
2563 | ||
edcdea5b NF |
2564 | /* Return true if STMT clobbers memory. STMT is required to be a |
2565 | GIMPLE_ASM. */ | |
2566 | ||
2567 | bool | |
538dd0b7 | 2568 | gimple_asm_clobbers_memory_p (const gasm *stmt) |
edcdea5b NF |
2569 | { |
2570 | unsigned i; | |
2571 | ||
2572 | for (i = 0; i < gimple_asm_nclobbers (stmt); i++) | |
2573 | { | |
2574 | tree op = gimple_asm_clobber_op (stmt, i); | |
2575 | if (strcmp (TREE_STRING_POINTER (TREE_VALUE (op)), "memory") == 0) | |
2576 | return true; | |
2577 | } | |
2578 | ||
93671519 BE |
2579 | /* Non-empty basic ASM implicitly clobbers memory. */ |
2580 | if (gimple_asm_input_p (stmt) && strlen (gimple_asm_string (stmt)) != 0) | |
2581 | return true; | |
2582 | ||
edcdea5b NF |
2583 | return false; |
2584 | } | |
475b8f37 | 2585 | |
80560f95 AM |
2586 | /* Dump bitmap SET (assumed to contain VAR_DECLs) to FILE. */ |
2587 | ||
2588 | void | |
2589 | dump_decl_set (FILE *file, bitmap set) | |
2590 | { | |
2591 | if (set) | |
2592 | { | |
2593 | bitmap_iterator bi; | |
2594 | unsigned i; | |
2595 | ||
2596 | fprintf (file, "{ "); | |
2597 | ||
2598 | EXECUTE_IF_SET_IN_BITMAP (set, 0, i, bi) | |
2599 | { | |
2600 | fprintf (file, "D.%u", i); | |
2601 | fprintf (file, " "); | |
2602 | } | |
2603 | ||
2604 | fprintf (file, "}"); | |
2605 | } | |
2606 | else | |
2607 | fprintf (file, "NIL"); | |
2608 | } | |
7a300452 | 2609 | |
3d9c733e AM |
2610 | /* Return true when CALL is a call stmt that definitely doesn't |
2611 | free any memory or makes it unavailable otherwise. */ | |
2612 | bool | |
355fe088 | 2613 | nonfreeing_call_p (gimple *call) |
3d9c733e AM |
2614 | { |
2615 | if (gimple_call_builtin_p (call, BUILT_IN_NORMAL) | |
2616 | && gimple_call_flags (call) & ECF_LEAF) | |
2617 | switch (DECL_FUNCTION_CODE (gimple_call_fndecl (call))) | |
2618 | { | |
2619 | /* Just in case these become ECF_LEAF in the future. */ | |
2620 | case BUILT_IN_FREE: | |
2621 | case BUILT_IN_TM_FREE: | |
2622 | case BUILT_IN_REALLOC: | |
2623 | case BUILT_IN_STACK_RESTORE: | |
2624 | return false; | |
2625 | default: | |
2626 | return true; | |
2627 | } | |
8413ca87 JJ |
2628 | else if (gimple_call_internal_p (call)) |
2629 | switch (gimple_call_internal_fn (call)) | |
2630 | { | |
2631 | case IFN_ABNORMAL_DISPATCHER: | |
2632 | return true; | |
6dc4a604 | 2633 | case IFN_ASAN_MARK: |
56b7aede | 2634 | return tree_to_uhwi (gimple_call_arg (call, 0)) == ASAN_MARK_UNPOISON; |
8413ca87 JJ |
2635 | default: |
2636 | if (gimple_call_flags (call) & ECF_LEAF) | |
2637 | return true; | |
2638 | return false; | |
2639 | } | |
3d9c733e | 2640 | |
8413ca87 JJ |
2641 | tree fndecl = gimple_call_fndecl (call); |
2642 | if (!fndecl) | |
2643 | return false; | |
2644 | struct cgraph_node *n = cgraph_node::get (fndecl); | |
2645 | if (!n) | |
2646 | return false; | |
2647 | enum availability availability; | |
2648 | n = n->function_symbol (&availability); | |
2649 | if (!n || availability <= AVAIL_INTERPOSABLE) | |
2650 | return false; | |
2651 | return n->nonfreeing_fn; | |
3d9c733e | 2652 | } |
8fdc414d | 2653 | |
c000cd7c BS |
2654 | /* Return true when CALL is a call stmt that definitely need not |
2655 | be considered to be a memory barrier. */ | |
2656 | bool | |
2657 | nonbarrier_call_p (gimple *call) | |
2658 | { | |
2659 | if (gimple_call_flags (call) & (ECF_PURE | ECF_CONST)) | |
2660 | return true; | |
2661 | /* Should extend this to have a nonbarrier_fn flag, just as above in | |
2662 | the nonfreeing case. */ | |
2663 | return false; | |
2664 | } | |
2665 | ||
8fdc414d JL |
2666 | /* Callback for walk_stmt_load_store_ops. |
2667 | ||
2668 | Return TRUE if OP will dereference the tree stored in DATA, FALSE | |
2669 | otherwise. | |
2670 | ||
2671 | This routine only makes a superficial check for a dereference. Thus | |
2672 | it must only be used if it is safe to return a false negative. */ | |
2673 | static bool | |
355fe088 | 2674 | check_loadstore (gimple *, tree op, tree, void *data) |
8fdc414d | 2675 | { |
6626f970 RH |
2676 | if (TREE_CODE (op) == MEM_REF || TREE_CODE (op) == TARGET_MEM_REF) |
2677 | { | |
2678 | /* Some address spaces may legitimately dereference zero. */ | |
2679 | addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (op)); | |
2680 | if (targetm.addr_space.zero_address_valid (as)) | |
2681 | return false; | |
2682 | ||
2683 | return operand_equal_p (TREE_OPERAND (op, 0), (tree)data, 0); | |
2684 | } | |
8fdc414d JL |
2685 | return false; |
2686 | } | |
2687 | ||
ae93744d | 2688 | |
76787f70 MLI |
2689 | /* Return true if OP can be inferred to be non-NULL after STMT executes, |
2690 | either by using a pointer dereference or attributes. */ | |
2691 | bool | |
355fe088 | 2692 | infer_nonnull_range (gimple *stmt, tree op) |
76787f70 MLI |
2693 | { |
2694 | return infer_nonnull_range_by_dereference (stmt, op) | |
2695 | || infer_nonnull_range_by_attribute (stmt, op); | |
2696 | } | |
8fdc414d | 2697 | |
76787f70 MLI |
2698 | /* Return true if OP can be inferred to be non-NULL after STMT |
2699 | executes by using a pointer dereference. */ | |
8fdc414d | 2700 | bool |
355fe088 | 2701 | infer_nonnull_range_by_dereference (gimple *stmt, tree op) |
8fdc414d JL |
2702 | { |
2703 | /* We can only assume that a pointer dereference will yield | |
2704 | non-NULL if -fdelete-null-pointer-checks is enabled. */ | |
2705 | if (!flag_delete_null_pointer_checks | |
2706 | || !POINTER_TYPE_P (TREE_TYPE (op)) | |
2707 | || gimple_code (stmt) == GIMPLE_ASM) | |
2708 | return false; | |
2709 | ||
76787f70 MLI |
2710 | if (walk_stmt_load_store_ops (stmt, (void *)op, |
2711 | check_loadstore, check_loadstore)) | |
8fdc414d JL |
2712 | return true; |
2713 | ||
76787f70 MLI |
2714 | return false; |
2715 | } | |
2716 | ||
2717 | /* Return true if OP can be inferred to be a non-NULL after STMT | |
2718 | executes by using attributes. */ | |
2719 | bool | |
355fe088 | 2720 | infer_nonnull_range_by_attribute (gimple *stmt, tree op) |
76787f70 MLI |
2721 | { |
2722 | /* We can only assume that a pointer dereference will yield | |
2723 | non-NULL if -fdelete-null-pointer-checks is enabled. */ | |
2724 | if (!flag_delete_null_pointer_checks | |
2725 | || !POINTER_TYPE_P (TREE_TYPE (op)) | |
2726 | || gimple_code (stmt) == GIMPLE_ASM) | |
2727 | return false; | |
2728 | ||
2729 | if (is_gimple_call (stmt) && !gimple_call_internal_p (stmt)) | |
8fdc414d JL |
2730 | { |
2731 | tree fntype = gimple_call_fntype (stmt); | |
2732 | tree attrs = TYPE_ATTRIBUTES (fntype); | |
2733 | for (; attrs; attrs = TREE_CHAIN (attrs)) | |
2734 | { | |
2735 | attrs = lookup_attribute ("nonnull", attrs); | |
2736 | ||
2737 | /* If "nonnull" wasn't specified, we know nothing about | |
2738 | the argument. */ | |
2739 | if (attrs == NULL_TREE) | |
2740 | return false; | |
2741 | ||
2742 | /* If "nonnull" applies to all the arguments, then ARG | |
2743 | is non-null if it's in the argument list. */ | |
2744 | if (TREE_VALUE (attrs) == NULL_TREE) | |
2745 | { | |
2746 | for (unsigned int i = 0; i < gimple_call_num_args (stmt); i++) | |
2747 | { | |
36f291f7 PP |
2748 | if (POINTER_TYPE_P (TREE_TYPE (gimple_call_arg (stmt, i))) |
2749 | && operand_equal_p (op, gimple_call_arg (stmt, i), 0)) | |
8fdc414d JL |
2750 | return true; |
2751 | } | |
2752 | return false; | |
2753 | } | |
2754 | ||
2755 | /* Now see if op appears in the nonnull list. */ | |
2756 | for (tree t = TREE_VALUE (attrs); t; t = TREE_CHAIN (t)) | |
2757 | { | |
e37dcf45 MP |
2758 | unsigned int idx = TREE_INT_CST_LOW (TREE_VALUE (t)) - 1; |
2759 | if (idx < gimple_call_num_args (stmt)) | |
2760 | { | |
2761 | tree arg = gimple_call_arg (stmt, idx); | |
2762 | if (operand_equal_p (op, arg, 0)) | |
2763 | return true; | |
2764 | } | |
8fdc414d JL |
2765 | } |
2766 | } | |
2767 | } | |
2768 | ||
2769 | /* If this function is marked as returning non-null, then we can | |
2770 | infer OP is non-null if it is used in the return statement. */ | |
76787f70 MLI |
2771 | if (greturn *return_stmt = dyn_cast <greturn *> (stmt)) |
2772 | if (gimple_return_retval (return_stmt) | |
2773 | && operand_equal_p (gimple_return_retval (return_stmt), op, 0) | |
2774 | && lookup_attribute ("returns_nonnull", | |
2775 | TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl)))) | |
2776 | return true; | |
8fdc414d JL |
2777 | |
2778 | return false; | |
2779 | } | |
45b0be94 AM |
2780 | |
2781 | /* Compare two case labels. Because the front end should already have | |
2782 | made sure that case ranges do not overlap, it is enough to only compare | |
2783 | the CASE_LOW values of each case label. */ | |
2784 | ||
2785 | static int | |
2786 | compare_case_labels (const void *p1, const void *p2) | |
2787 | { | |
2788 | const_tree const case1 = *(const_tree const*)p1; | |
2789 | const_tree const case2 = *(const_tree const*)p2; | |
2790 | ||
2791 | /* The 'default' case label always goes first. */ | |
2792 | if (!CASE_LOW (case1)) | |
2793 | return -1; | |
2794 | else if (!CASE_LOW (case2)) | |
2795 | return 1; | |
2796 | else | |
2797 | return tree_int_cst_compare (CASE_LOW (case1), CASE_LOW (case2)); | |
2798 | } | |
2799 | ||
2800 | /* Sort the case labels in LABEL_VEC in place in ascending order. */ | |
2801 | ||
2802 | void | |
2803 | sort_case_labels (vec<tree> label_vec) | |
2804 | { | |
2805 | label_vec.qsort (compare_case_labels); | |
2806 | } | |
2807 | \f | |
2808 | /* Prepare a vector of case labels to be used in a GIMPLE_SWITCH statement. | |
2809 | ||
2810 | LABELS is a vector that contains all case labels to look at. | |
2811 | ||
2812 | INDEX_TYPE is the type of the switch index expression. Case labels | |
2813 | in LABELS are discarded if their values are not in the value range | |
2814 | covered by INDEX_TYPE. The remaining case label values are folded | |
2815 | to INDEX_TYPE. | |
2816 | ||
2817 | If a default case exists in LABELS, it is removed from LABELS and | |
2818 | returned in DEFAULT_CASEP. If no default case exists, but the | |
2819 | case labels already cover the whole range of INDEX_TYPE, a default | |
2820 | case is returned pointing to one of the existing case labels. | |
2821 | Otherwise DEFAULT_CASEP is set to NULL_TREE. | |
2822 | ||
2823 | DEFAULT_CASEP may be NULL, in which case the above comment doesn't | |
2824 | apply and no action is taken regardless of whether a default case is | |
2825 | found or not. */ | |
2826 | ||
2827 | void | |
2828 | preprocess_case_label_vec_for_gimple (vec<tree> labels, | |
2829 | tree index_type, | |
2830 | tree *default_casep) | |
2831 | { | |
2832 | tree min_value, max_value; | |
2833 | tree default_case = NULL_TREE; | |
2834 | size_t i, len; | |
2835 | ||
2836 | i = 0; | |
2837 | min_value = TYPE_MIN_VALUE (index_type); | |
2838 | max_value = TYPE_MAX_VALUE (index_type); | |
2839 | while (i < labels.length ()) | |
2840 | { | |
2841 | tree elt = labels[i]; | |
2842 | tree low = CASE_LOW (elt); | |
2843 | tree high = CASE_HIGH (elt); | |
2844 | bool remove_element = FALSE; | |
2845 | ||
2846 | if (low) | |
2847 | { | |
2848 | gcc_checking_assert (TREE_CODE (low) == INTEGER_CST); | |
2849 | gcc_checking_assert (!high || TREE_CODE (high) == INTEGER_CST); | |
2850 | ||
2851 | /* This is a non-default case label, i.e. it has a value. | |
2852 | ||
2853 | See if the case label is reachable within the range of | |
2854 | the index type. Remove out-of-range case values. Turn | |
2855 | case ranges into a canonical form (high > low strictly) | |
2856 | and convert the case label values to the index type. | |
2857 | ||
2858 | NB: The type of gimple_switch_index() may be the promoted | |
2859 | type, but the case labels retain the original type. */ | |
2860 | ||
2861 | if (high) | |
2862 | { | |
2863 | /* This is a case range. Discard empty ranges. | |
2864 | If the bounds or the range are equal, turn this | |
2865 | into a simple (one-value) case. */ | |
2866 | int cmp = tree_int_cst_compare (high, low); | |
2867 | if (cmp < 0) | |
2868 | remove_element = TRUE; | |
2869 | else if (cmp == 0) | |
2870 | high = NULL_TREE; | |
2871 | } | |
2872 | ||
2873 | if (! high) | |
2874 | { | |
2875 | /* If the simple case value is unreachable, ignore it. */ | |
2876 | if ((TREE_CODE (min_value) == INTEGER_CST | |
2877 | && tree_int_cst_compare (low, min_value) < 0) | |
2878 | || (TREE_CODE (max_value) == INTEGER_CST | |
2879 | && tree_int_cst_compare (low, max_value) > 0)) | |
2880 | remove_element = TRUE; | |
2881 | else | |
2882 | low = fold_convert (index_type, low); | |
2883 | } | |
2884 | else | |
2885 | { | |
2886 | /* If the entire case range is unreachable, ignore it. */ | |
2887 | if ((TREE_CODE (min_value) == INTEGER_CST | |
2888 | && tree_int_cst_compare (high, min_value) < 0) | |
2889 | || (TREE_CODE (max_value) == INTEGER_CST | |
2890 | && tree_int_cst_compare (low, max_value) > 0)) | |
2891 | remove_element = TRUE; | |
2892 | else | |
2893 | { | |
2894 | /* If the lower bound is less than the index type's | |
2895 | minimum value, truncate the range bounds. */ | |
2896 | if (TREE_CODE (min_value) == INTEGER_CST | |
2897 | && tree_int_cst_compare (low, min_value) < 0) | |
2898 | low = min_value; | |
2899 | low = fold_convert (index_type, low); | |
2900 | ||
2901 | /* If the upper bound is greater than the index type's | |
2902 | maximum value, truncate the range bounds. */ | |
2903 | if (TREE_CODE (max_value) == INTEGER_CST | |
2904 | && tree_int_cst_compare (high, max_value) > 0) | |
2905 | high = max_value; | |
2906 | high = fold_convert (index_type, high); | |
2907 | ||
2908 | /* We may have folded a case range to a one-value case. */ | |
2909 | if (tree_int_cst_equal (low, high)) | |
2910 | high = NULL_TREE; | |
2911 | } | |
2912 | } | |
2913 | ||
2914 | CASE_LOW (elt) = low; | |
2915 | CASE_HIGH (elt) = high; | |
2916 | } | |
2917 | else | |
2918 | { | |
2919 | gcc_assert (!default_case); | |
2920 | default_case = elt; | |
2921 | /* The default case must be passed separately to the | |
2922 | gimple_build_switch routine. But if DEFAULT_CASEP | |
2923 | is NULL, we do not remove the default case (it would | |
2924 | be completely lost). */ | |
2925 | if (default_casep) | |
2926 | remove_element = TRUE; | |
2927 | } | |
2928 | ||
2929 | if (remove_element) | |
2930 | labels.ordered_remove (i); | |
2931 | else | |
2932 | i++; | |
2933 | } | |
2934 | len = i; | |
2935 | ||
2936 | if (!labels.is_empty ()) | |
2937 | sort_case_labels (labels); | |
2938 | ||
2939 | if (default_casep && !default_case) | |
2940 | { | |
2941 | /* If the switch has no default label, add one, so that we jump | |
2942 | around the switch body. If the labels already cover the whole | |
2943 | range of the switch index_type, add the default label pointing | |
2944 | to one of the existing labels. */ | |
2945 | if (len | |
2946 | && TYPE_MIN_VALUE (index_type) | |
2947 | && TYPE_MAX_VALUE (index_type) | |
2948 | && tree_int_cst_equal (CASE_LOW (labels[0]), | |
2949 | TYPE_MIN_VALUE (index_type))) | |
2950 | { | |
2951 | tree low, high = CASE_HIGH (labels[len - 1]); | |
2952 | if (!high) | |
2953 | high = CASE_LOW (labels[len - 1]); | |
2954 | if (tree_int_cst_equal (high, TYPE_MAX_VALUE (index_type))) | |
2955 | { | |
938da3a5 | 2956 | tree widest_label = labels[0]; |
45b0be94 AM |
2957 | for (i = 1; i < len; i++) |
2958 | { | |
2959 | high = CASE_LOW (labels[i]); | |
2960 | low = CASE_HIGH (labels[i - 1]); | |
2961 | if (!low) | |
2962 | low = CASE_LOW (labels[i - 1]); | |
938da3a5 PP |
2963 | |
2964 | if (CASE_HIGH (labels[i]) != NULL_TREE | |
2965 | && (CASE_HIGH (widest_label) == NULL_TREE | |
2966 | || wi::gtu_p (wi::sub (CASE_HIGH (labels[i]), | |
2967 | CASE_LOW (labels[i])), | |
2968 | wi::sub (CASE_HIGH (widest_label), | |
2969 | CASE_LOW (widest_label))))) | |
2970 | widest_label = labels[i]; | |
2971 | ||
807e902e | 2972 | if (wi::add (low, 1) != high) |
45b0be94 AM |
2973 | break; |
2974 | } | |
2975 | if (i == len) | |
2976 | { | |
938da3a5 PP |
2977 | /* Designate the label with the widest range to be the |
2978 | default label. */ | |
2979 | tree label = CASE_LABEL (widest_label); | |
45b0be94 AM |
2980 | default_case = build_case_label (NULL_TREE, NULL_TREE, |
2981 | label); | |
2982 | } | |
2983 | } | |
2984 | } | |
2985 | } | |
2986 | ||
2987 | if (default_casep) | |
2988 | *default_casep = default_case; | |
2989 | } | |
5be5c238 AM |
2990 | |
2991 | /* Set the location of all statements in SEQ to LOC. */ | |
2992 | ||
2993 | void | |
2994 | gimple_seq_set_location (gimple_seq seq, location_t loc) | |
2995 | { | |
2996 | for (gimple_stmt_iterator i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i)) | |
2997 | gimple_set_location (gsi_stmt (i), loc); | |
2998 | } | |
73049af5 JJ |
2999 | |
3000 | /* Release SSA_NAMEs in SEQ as well as the GIMPLE statements. */ | |
3001 | ||
3002 | void | |
3003 | gimple_seq_discard (gimple_seq seq) | |
3004 | { | |
3005 | gimple_stmt_iterator gsi; | |
3006 | ||
3007 | for (gsi = gsi_start (seq); !gsi_end_p (gsi); ) | |
3008 | { | |
355fe088 | 3009 | gimple *stmt = gsi_stmt (gsi); |
73049af5 JJ |
3010 | gsi_remove (&gsi, true); |
3011 | release_defs (stmt); | |
3012 | ggc_free (stmt); | |
3013 | } | |
3014 | } | |
0b986c6a JH |
3015 | |
3016 | /* See if STMT now calls function that takes no parameters and if so, drop | |
3017 | call arguments. This is used when devirtualization machinery redirects | |
538374e1 | 3018 | to __builtin_unreachable or __cxa_pure_virtual. */ |
0b986c6a JH |
3019 | |
3020 | void | |
355fe088 | 3021 | maybe_remove_unused_call_args (struct function *fn, gimple *stmt) |
0b986c6a JH |
3022 | { |
3023 | tree decl = gimple_call_fndecl (stmt); | |
3024 | if (TYPE_ARG_TYPES (TREE_TYPE (decl)) | |
3025 | && TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))) == void_type_node | |
3026 | && gimple_call_num_args (stmt)) | |
3027 | { | |
3028 | gimple_set_num_ops (stmt, 3); | |
3029 | update_stmt_fn (fn, stmt); | |
3030 | } | |
3031 | } | |
d9b950dd | 3032 | |
ce120587 JH |
3033 | /* Return false if STMT will likely expand to real function call. */ |
3034 | ||
3035 | bool | |
3036 | gimple_inexpensive_call_p (gcall *stmt) | |
3037 | { | |
3038 | if (gimple_call_internal_p (stmt)) | |
3039 | return true; | |
3040 | tree decl = gimple_call_fndecl (stmt); | |
3041 | if (decl && is_inexpensive_builtin (decl)) | |
3042 | return true; | |
3043 | return false; | |
3044 | } | |
3045 | ||
d9b950dd DM |
3046 | #if CHECKING_P |
3047 | ||
3048 | namespace selftest { | |
3049 | ||
3050 | /* Selftests for core gimple structures. */ | |
3051 | ||
3052 | /* Verify that STMT is pretty-printed as EXPECTED. | |
3053 | Helper function for selftests. */ | |
3054 | ||
3055 | static void | |
3056 | verify_gimple_pp (const char *expected, gimple *stmt) | |
3057 | { | |
3058 | pretty_printer pp; | |
3059 | pp_gimple_stmt_1 (&pp, stmt, 0 /* spc */, 0 /* flags */); | |
3060 | ASSERT_STREQ (expected, pp_formatted_text (&pp)); | |
3061 | } | |
3062 | ||
3063 | /* Build a GIMPLE_ASSIGN equivalent to | |
3064 | tmp = 5; | |
3065 | and verify various properties of it. */ | |
3066 | ||
3067 | static void | |
3068 | test_assign_single () | |
3069 | { | |
3070 | tree type = integer_type_node; | |
3071 | tree lhs = build_decl (UNKNOWN_LOCATION, VAR_DECL, | |
3072 | get_identifier ("tmp"), | |
3073 | type); | |
3074 | tree rhs = build_int_cst (type, 5); | |
3075 | gassign *stmt = gimple_build_assign (lhs, rhs); | |
3076 | verify_gimple_pp ("tmp = 5;", stmt); | |
3077 | ||
3078 | ASSERT_TRUE (is_gimple_assign (stmt)); | |
3079 | ASSERT_EQ (lhs, gimple_assign_lhs (stmt)); | |
3080 | ASSERT_EQ (lhs, gimple_get_lhs (stmt)); | |
3081 | ASSERT_EQ (rhs, gimple_assign_rhs1 (stmt)); | |
3082 | ASSERT_EQ (NULL, gimple_assign_rhs2 (stmt)); | |
3083 | ASSERT_EQ (NULL, gimple_assign_rhs3 (stmt)); | |
3084 | ASSERT_TRUE (gimple_assign_single_p (stmt)); | |
3085 | ASSERT_EQ (INTEGER_CST, gimple_assign_rhs_code (stmt)); | |
3086 | } | |
3087 | ||
3088 | /* Build a GIMPLE_ASSIGN equivalent to | |
3089 | tmp = a * b; | |
3090 | and verify various properties of it. */ | |
3091 | ||
3092 | static void | |
3093 | test_assign_binop () | |
3094 | { | |
3095 | tree type = integer_type_node; | |
3096 | tree lhs = build_decl (UNKNOWN_LOCATION, VAR_DECL, | |
3097 | get_identifier ("tmp"), | |
3098 | type); | |
3099 | tree a = build_decl (UNKNOWN_LOCATION, VAR_DECL, | |
3100 | get_identifier ("a"), | |
3101 | type); | |
3102 | tree b = build_decl (UNKNOWN_LOCATION, VAR_DECL, | |
3103 | get_identifier ("b"), | |
3104 | type); | |
3105 | gassign *stmt = gimple_build_assign (lhs, MULT_EXPR, a, b); | |
3106 | verify_gimple_pp ("tmp = a * b;", stmt); | |
3107 | ||
3108 | ASSERT_TRUE (is_gimple_assign (stmt)); | |
3109 | ASSERT_EQ (lhs, gimple_assign_lhs (stmt)); | |
3110 | ASSERT_EQ (lhs, gimple_get_lhs (stmt)); | |
3111 | ASSERT_EQ (a, gimple_assign_rhs1 (stmt)); | |
3112 | ASSERT_EQ (b, gimple_assign_rhs2 (stmt)); | |
3113 | ASSERT_EQ (NULL, gimple_assign_rhs3 (stmt)); | |
3114 | ASSERT_FALSE (gimple_assign_single_p (stmt)); | |
3115 | ASSERT_EQ (MULT_EXPR, gimple_assign_rhs_code (stmt)); | |
3116 | } | |
3117 | ||
3118 | /* Build a GIMPLE_NOP and verify various properties of it. */ | |
3119 | ||
3120 | static void | |
3121 | test_nop_stmt () | |
3122 | { | |
3123 | gimple *stmt = gimple_build_nop (); | |
3124 | verify_gimple_pp ("GIMPLE_NOP", stmt); | |
3125 | ASSERT_EQ (GIMPLE_NOP, gimple_code (stmt)); | |
3126 | ASSERT_EQ (NULL, gimple_get_lhs (stmt)); | |
3127 | ASSERT_FALSE (gimple_assign_single_p (stmt)); | |
3128 | } | |
3129 | ||
3130 | /* Build a GIMPLE_RETURN equivalent to | |
3131 | return 7; | |
3132 | and verify various properties of it. */ | |
3133 | ||
3134 | static void | |
3135 | test_return_stmt () | |
3136 | { | |
3137 | tree type = integer_type_node; | |
3138 | tree val = build_int_cst (type, 7); | |
3139 | greturn *stmt = gimple_build_return (val); | |
3140 | verify_gimple_pp ("return 7;", stmt); | |
3141 | ||
3142 | ASSERT_EQ (GIMPLE_RETURN, gimple_code (stmt)); | |
3143 | ASSERT_EQ (NULL, gimple_get_lhs (stmt)); | |
3144 | ASSERT_EQ (val, gimple_return_retval (stmt)); | |
3145 | ASSERT_FALSE (gimple_assign_single_p (stmt)); | |
3146 | } | |
3147 | ||
3148 | /* Build a GIMPLE_RETURN equivalent to | |
3149 | return; | |
3150 | and verify various properties of it. */ | |
3151 | ||
3152 | static void | |
3153 | test_return_without_value () | |
3154 | { | |
3155 | greturn *stmt = gimple_build_return (NULL); | |
3156 | verify_gimple_pp ("return;", stmt); | |
3157 | ||
3158 | ASSERT_EQ (GIMPLE_RETURN, gimple_code (stmt)); | |
3159 | ASSERT_EQ (NULL, gimple_get_lhs (stmt)); | |
3160 | ASSERT_EQ (NULL, gimple_return_retval (stmt)); | |
3161 | ASSERT_FALSE (gimple_assign_single_p (stmt)); | |
3162 | } | |
3163 | ||
3164 | /* Run all of the selftests within this file. */ | |
3165 | ||
3166 | void | |
3167 | gimple_c_tests () | |
3168 | { | |
3169 | test_assign_single (); | |
3170 | test_assign_binop (); | |
3171 | test_nop_stmt (); | |
3172 | test_return_stmt (); | |
3173 | test_return_without_value (); | |
3174 | } | |
3175 | ||
3176 | } // namespace selftest | |
3177 | ||
3178 | ||
3179 | #endif /* CHECKING_P */ |