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