Branch data Line data Source code
1 : : /* Gimple IR support functions.
2 : :
3 : : Copyright (C) 2007-2025 Free Software Foundation, Inc.
4 : : Contributed by Aldy Hernandez <aldyh@redhat.com>
5 : :
6 : : This file is part of GCC.
7 : :
8 : : GCC is free software; you can redistribute it and/or modify it under
9 : : the terms of the GNU General Public License as published by the Free
10 : : Software Foundation; either version 3, or (at your option) any later
11 : : version.
12 : :
13 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 : : for more details.
17 : :
18 : : You should have received a copy of the GNU General Public License
19 : : along with GCC; see the file COPYING3. If not see
20 : : <http://www.gnu.org/licenses/>. */
21 : :
22 : : #include "config.h"
23 : : #include "system.h"
24 : : #include "coretypes.h"
25 : : #include "backend.h"
26 : : #include "tree.h"
27 : : #include "gimple.h"
28 : : #include "ssa.h"
29 : : #include "cgraph.h"
30 : : #include "diagnostic.h"
31 : : #include "alias.h"
32 : : #include "fold-const.h"
33 : : #include "calls.h"
34 : : #include "stor-layout.h"
35 : : #include "internal-fn.h"
36 : : #include "tree-eh.h"
37 : : #include "gimple-iterator.h"
38 : : #include "gimple-walk.h"
39 : : #include "gimplify.h"
40 : : #include "target.h"
41 : : #include "builtins.h"
42 : : #include "selftest.h"
43 : : #include "gimple-pretty-print.h"
44 : : #include "stringpool.h"
45 : : #include "attribs.h"
46 : : #include "asan.h"
47 : : #include "ubsan.h"
48 : : #include "langhooks.h"
49 : : #include "attr-fnspec.h"
50 : : #include "ipa-modref-tree.h"
51 : : #include "ipa-modref.h"
52 : : #include "dbgcnt.h"
53 : :
54 : : /* All the tuples have their operand vector (if present) at the very bottom of
55 : : the structure. Therefore, the offset required to find the operands vector is
56 : : the size of the structure minus the size of the 1-element tree array at the
57 : : end (see gimple_ops). An adjustment may be required if there is tail
58 : : padding, as may happen on a host (e.g. sparc) where a pointer has 4-byte
59 : : alignment while a uint64_t has 8-byte alignment.
60 : :
61 : : Unfortunately, we can't use offsetof to do this computation 100%
62 : : straightforwardly, because these structs use inheritance and so are not
63 : : standard layout types. However, the fact that they are not standard layout
64 : : types also means that tail padding will be reused in inheritance, which makes
65 : : it possible to check for the problematic case with the following logic
66 : : instead. If tail padding is detected, the offset should be decreased
67 : : accordingly. */
68 : :
69 : : template<typename G>
70 : : static constexpr size_t
71 : : get_tail_padding_adjustment ()
72 : : {
73 : : struct padding_check : G
74 : : {
75 : : tree t;
76 : : };
77 : : return sizeof (padding_check) == sizeof (G) ? sizeof (tree) : 0;
78 : : }
79 : :
80 : : #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) \
81 : : (HAS_TREE_OP \
82 : : ? sizeof (STRUCT) - sizeof (tree) - get_tail_padding_adjustment<STRUCT> () \
83 : : : 0),
84 : : EXPORTED_CONST size_t gimple_ops_offset_[] = {
85 : : #include "gsstruct.def"
86 : : };
87 : : #undef DEFGSSTRUCT
88 : :
89 : : #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) sizeof (struct STRUCT),
90 : : static const size_t gsstruct_code_size[] = {
91 : : #include "gsstruct.def"
92 : : };
93 : : #undef DEFGSSTRUCT
94 : :
95 : : #define DEFGSCODE(SYM, NAME, GSSCODE) NAME,
96 : : const char *const gimple_code_name[] = {
97 : : #include "gimple.def"
98 : : };
99 : : #undef DEFGSCODE
100 : :
101 : : #define DEFGSCODE(SYM, NAME, GSSCODE) GSSCODE,
102 : : EXPORTED_CONST enum gimple_statement_structure_enum gss_for_code_[] = {
103 : : #include "gimple.def"
104 : : };
105 : : #undef DEFGSCODE
106 : :
107 : : /* Gimple stats. */
108 : :
109 : : uint64_t gimple_alloc_counts[(int) gimple_alloc_kind_all];
110 : : uint64_t gimple_alloc_sizes[(int) gimple_alloc_kind_all];
111 : :
112 : : /* Keep in sync with gimple.h:enum gimple_alloc_kind. */
113 : : static const char * const gimple_alloc_kind_names[] = {
114 : : "assignments",
115 : : "phi nodes",
116 : : "conditionals",
117 : : "everything else"
118 : : };
119 : :
120 : : /* Static gimple tuple members. */
121 : : const enum gimple_code gassign::code_;
122 : : const enum gimple_code gcall::code_;
123 : : const enum gimple_code gcond::code_;
124 : :
125 : :
126 : : /* Gimple tuple constructors.
127 : : Note: Any constructor taking a ``gimple_seq'' as a parameter, can
128 : : be passed a NULL to start with an empty sequence. */
129 : :
130 : : /* Set the code for statement G to CODE. */
131 : :
132 : : static inline void
133 : 278269098 : gimple_set_code (gimple *g, enum gimple_code code)
134 : : {
135 : 278269098 : g->code = code;
136 : : }
137 : :
138 : : /* Return the number of bytes needed to hold a GIMPLE statement with
139 : : code CODE. */
140 : :
141 : : size_t
142 : 333755241 : gimple_size (enum gimple_code code, unsigned num_ops)
143 : : {
144 : 333755241 : size_t size = gsstruct_code_size[gss_for_code (code)];
145 : 333755241 : if (num_ops > 0)
146 : 232478802 : size += (sizeof (tree) * (num_ops - 1));
147 : 333755241 : return size;
148 : : }
149 : :
150 : : /* Initialize GIMPLE statement G with CODE and NUM_OPS. */
151 : :
152 : : void
153 : 278269098 : gimple_init (gimple *g, enum gimple_code code, unsigned num_ops)
154 : : {
155 : 278269098 : gimple_set_code (g, code);
156 : 278269098 : gimple_set_num_ops (g, num_ops);
157 : :
158 : : /* Do not call gimple_set_modified here as it has other side
159 : : effects and this tuple is still not completely built. */
160 : 278269098 : g->modified = 1;
161 : 278269098 : gimple_init_singleton (g);
162 : 278269098 : }
163 : :
164 : : /* Allocate memory for a GIMPLE statement with code CODE and NUM_OPS
165 : : operands. */
166 : :
167 : : gimple *
168 : 276449728 : gimple_alloc (enum gimple_code code, unsigned num_ops MEM_STAT_DECL)
169 : : {
170 : 276449728 : size_t size;
171 : 276449728 : gimple *stmt;
172 : :
173 : 276449728 : size = gimple_size (code, num_ops);
174 : 276449728 : if (GATHER_STATISTICS)
175 : : {
176 : : enum gimple_alloc_kind kind = gimple_alloc_kind (code);
177 : : gimple_alloc_counts[(int) kind]++;
178 : : gimple_alloc_sizes[(int) kind] += size;
179 : : }
180 : :
181 : 276449728 : stmt = ggc_alloc_cleared_gimple_statement_stat (size PASS_MEM_STAT);
182 : 276449728 : gimple_init (stmt, code, num_ops);
183 : 276449728 : return stmt;
184 : : }
185 : :
186 : : /* Set SUBCODE to be the code of the expression computed by statement G. */
187 : :
188 : : static inline void
189 : 201861286 : gimple_set_subcode (gimple *g, unsigned subcode)
190 : : {
191 : : /* We only have 16 bits for the RHS code. Assert that we are not
192 : : overflowing it. */
193 : 201861286 : gcc_assert (subcode < (1 << 16));
194 : 201861286 : g->subcode = subcode;
195 : 201861286 : }
196 : :
197 : :
198 : :
199 : : /* Build a tuple with operands. CODE is the statement to build (which
200 : : must be one of the GIMPLE_WITH_OPS tuples). SUBCODE is the subcode
201 : : for the new tuple. NUM_OPS is the number of operands to allocate. */
202 : :
203 : : #define gimple_build_with_ops(c, s, n) \
204 : : gimple_build_with_ops_stat (c, s, n MEM_STAT_INFO)
205 : :
206 : : static gimple *
207 : 192719501 : gimple_build_with_ops_stat (enum gimple_code code, unsigned subcode,
208 : : unsigned num_ops MEM_STAT_DECL)
209 : : {
210 : 0 : gimple *s = gimple_alloc (code, num_ops PASS_MEM_STAT);
211 : 192719501 : gimple_set_subcode (s, subcode);
212 : :
213 : 192719501 : return s;
214 : : }
215 : :
216 : :
217 : : /* Build a GIMPLE_RETURN statement returning RETVAL. */
218 : :
219 : : greturn *
220 : 3318502 : gimple_build_return (tree retval)
221 : : {
222 : 3318502 : greturn *s
223 : 3318502 : = as_a <greturn *> (gimple_build_with_ops (GIMPLE_RETURN, ERROR_MARK,
224 : : 2));
225 : 3318502 : if (retval)
226 : 2003140 : gimple_return_set_retval (s, retval);
227 : 3318502 : return s;
228 : : }
229 : :
230 : : /* Reset alias information on call S. */
231 : :
232 : : void
233 : 15911439 : gimple_call_reset_alias_info (gcall *s)
234 : : {
235 : 15911439 : if (gimple_call_flags (s) & ECF_CONST)
236 : 1709276 : memset (gimple_call_use_set (s), 0, sizeof (struct pt_solution));
237 : : else
238 : 14202163 : pt_solution_reset (gimple_call_use_set (s));
239 : 15911439 : if (gimple_call_flags (s) & (ECF_CONST|ECF_PURE|ECF_NOVOPS))
240 : 2819580 : memset (gimple_call_clobber_set (s), 0, sizeof (struct pt_solution));
241 : : else
242 : 13091859 : pt_solution_reset (gimple_call_clobber_set (s));
243 : 15911439 : }
244 : :
245 : : /* Helper for gimple_build_call, gimple_build_call_valist,
246 : : gimple_build_call_vec and gimple_build_call_from_tree. Build the basic
247 : : components of a GIMPLE_CALL statement to function FN with NARGS
248 : : arguments. */
249 : :
250 : : static inline gcall *
251 : 10944383 : gimple_build_call_1 (tree fn, unsigned nargs)
252 : : {
253 : 10944383 : gcall *s
254 : 21888766 : = as_a <gcall *> (gimple_build_with_ops (GIMPLE_CALL, ERROR_MARK,
255 : : nargs + 3));
256 : 10944383 : if (TREE_CODE (fn) == FUNCTION_DECL)
257 : 10739409 : fn = build_fold_addr_expr (fn);
258 : 10944383 : gimple_set_op (s, 1, fn);
259 : 10944383 : gimple_call_set_fntype (s, TREE_TYPE (TREE_TYPE (fn)));
260 : 10944383 : gimple_call_reset_alias_info (s);
261 : 10944383 : return s;
262 : : }
263 : :
264 : :
265 : : /* Build a GIMPLE_CALL statement to function FN with the arguments
266 : : specified in vector ARGS. */
267 : :
268 : : gcall *
269 : 498290 : gimple_build_call_vec (tree fn, const vec<tree> &args)
270 : : {
271 : 498290 : unsigned i;
272 : 498290 : unsigned nargs = args.length ();
273 : 498290 : gcall *call = gimple_build_call_1 (fn, nargs);
274 : :
275 : 2276433 : for (i = 0; i < nargs; i++)
276 : 1279853 : gimple_call_set_arg (call, i, args[i]);
277 : :
278 : 498290 : return call;
279 : : }
280 : :
281 : :
282 : : /* Build a GIMPLE_CALL statement to function FN. NARGS is the number of
283 : : arguments. The ... are the arguments. */
284 : :
285 : : gcall *
286 : 559648 : gimple_build_call (tree fn, unsigned nargs, ...)
287 : : {
288 : 559648 : va_list ap;
289 : 559648 : gcall *call;
290 : 559648 : unsigned i;
291 : :
292 : 559648 : gcc_assert (TREE_CODE (fn) == FUNCTION_DECL || is_gimple_call_addr (fn));
293 : :
294 : 559648 : call = gimple_build_call_1 (fn, nargs);
295 : :
296 : 559648 : va_start (ap, nargs);
297 : 1172684 : for (i = 0; i < nargs; i++)
298 : 613036 : gimple_call_set_arg (call, i, va_arg (ap, tree));
299 : 559648 : va_end (ap);
300 : :
301 : 559648 : return call;
302 : : }
303 : :
304 : :
305 : : /* Build a GIMPLE_CALL statement to function FN. NARGS is the number of
306 : : arguments. AP contains the arguments. */
307 : :
308 : : gcall *
309 : 2270 : gimple_build_call_valist (tree fn, unsigned nargs, va_list ap)
310 : : {
311 : 2270 : gcall *call;
312 : 2270 : unsigned i;
313 : :
314 : 2270 : gcc_assert (TREE_CODE (fn) == FUNCTION_DECL || is_gimple_call_addr (fn));
315 : :
316 : 2270 : call = gimple_build_call_1 (fn, nargs);
317 : :
318 : 10978 : for (i = 0; i < nargs; i++)
319 : 6438 : gimple_call_set_arg (call, i, va_arg (ap, tree));
320 : :
321 : 2270 : return call;
322 : : }
323 : :
324 : :
325 : : /* Helper for gimple_build_call_internal and gimple_build_call_internal_vec.
326 : : Build the basic components of a GIMPLE_CALL statement to internal
327 : : function FN with NARGS arguments. */
328 : :
329 : : static inline gcall *
330 : 601991 : gimple_build_call_internal_1 (enum internal_fn fn, unsigned nargs)
331 : : {
332 : 601991 : gcall *s
333 : 1203982 : = as_a <gcall *> (gimple_build_with_ops (GIMPLE_CALL, ERROR_MARK,
334 : : nargs + 3));
335 : 601991 : s->subcode |= GF_CALL_INTERNAL;
336 : 601991 : gimple_call_set_internal_fn (s, fn);
337 : 601991 : gimple_call_reset_alias_info (s);
338 : 601991 : return s;
339 : : }
340 : :
341 : :
342 : : /* Build a GIMPLE_CALL statement to internal function FN. NARGS is
343 : : the number of arguments. The ... are the arguments. */
344 : :
345 : : gcall *
346 : 388982 : gimple_build_call_internal (enum internal_fn fn, unsigned nargs, ...)
347 : : {
348 : 388982 : va_list ap;
349 : 388982 : gcall *call;
350 : 388982 : unsigned i;
351 : :
352 : 388982 : call = gimple_build_call_internal_1 (fn, nargs);
353 : 388982 : va_start (ap, nargs);
354 : 1568547 : for (i = 0; i < nargs; i++)
355 : 1179565 : gimple_call_set_arg (call, i, va_arg (ap, tree));
356 : 388982 : va_end (ap);
357 : :
358 : 388982 : return call;
359 : : }
360 : :
361 : :
362 : : /* Build a GIMPLE_CALL statement to internal function FN with the arguments
363 : : specified in vector ARGS. */
364 : :
365 : : gcall *
366 : 213006 : gimple_build_call_internal_vec (enum internal_fn fn, const vec<tree> &args)
367 : : {
368 : 213006 : unsigned i, nargs;
369 : 213006 : gcall *call;
370 : :
371 : 213006 : nargs = args.length ();
372 : 213006 : call = gimple_build_call_internal_1 (fn, nargs);
373 : 1063287 : for (i = 0; i < nargs; i++)
374 : 637275 : gimple_call_set_arg (call, i, args[i]);
375 : :
376 : 213006 : return call;
377 : : }
378 : :
379 : :
380 : : /* Build a GIMPLE_CALL statement from CALL_EXPR T. Note that T is
381 : : assumed to be in GIMPLE form already. Minimal checking is done of
382 : : this fact. */
383 : :
384 : : gcall *
385 : 9884178 : gimple_build_call_from_tree (tree t, tree fnptrtype)
386 : : {
387 : 9884178 : unsigned i, nargs;
388 : 9884178 : gcall *call;
389 : :
390 : 9884178 : gcc_assert (TREE_CODE (t) == CALL_EXPR);
391 : :
392 : 9884178 : nargs = call_expr_nargs (t);
393 : :
394 : 9884178 : tree fndecl = NULL_TREE;
395 : 9884178 : if (CALL_EXPR_FN (t) == NULL_TREE)
396 : 3 : call = gimple_build_call_internal_1 (CALL_EXPR_IFN (t), nargs);
397 : : else
398 : : {
399 : 9884175 : fndecl = get_callee_fndecl (t);
400 : 10043120 : call = gimple_build_call_1 (fndecl ? fndecl : CALL_EXPR_FN (t), nargs);
401 : : }
402 : :
403 : 27577257 : for (i = 0; i < nargs; i++)
404 : 17693079 : gimple_call_set_arg (call, i, CALL_EXPR_ARG (t, i));
405 : :
406 : 9884178 : gimple_set_block (call, TREE_BLOCK (t));
407 : 9884178 : gimple_set_location (call, EXPR_LOCATION (t));
408 : :
409 : : /* Carry all the CALL_EXPR flags to the new GIMPLE_CALL. */
410 : 9884178 : gimple_call_set_chain (call, CALL_EXPR_STATIC_CHAIN (t));
411 : 9884178 : gimple_call_set_tail (call, CALL_EXPR_TAILCALL (t));
412 : 9884178 : gimple_call_set_must_tail (call, CALL_EXPR_MUST_TAIL_CALL (t));
413 : 9884178 : gimple_call_set_return_slot_opt (call, CALL_EXPR_RETURN_SLOT_OPT (t));
414 : 9884178 : if (fndecl
415 : 9725230 : && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
416 : 12005799 : && ALLOCA_FUNCTION_CODE_P (DECL_FUNCTION_CODE (fndecl)))
417 : 37384 : gimple_call_set_alloca_for_var (call, CALL_ALLOCA_FOR_VAR_P (t));
418 : 9846794 : else if (fndecl
419 : 19534640 : && (DECL_IS_OPERATOR_NEW_P (fndecl)
420 : 9640132 : || DECL_IS_OPERATOR_DELETE_P (fndecl)))
421 : 118738 : gimple_call_set_from_new_or_delete (call, CALL_FROM_NEW_OR_DELETE_P (t));
422 : : else
423 : 9728056 : gimple_call_set_from_thunk (call, CALL_FROM_THUNK_P (t));
424 : 9884178 : gimple_call_set_va_arg_pack (call, CALL_EXPR_VA_ARG_PACK (t));
425 : 9884178 : gimple_call_set_nothrow (call, TREE_NOTHROW (t));
426 : 9884178 : if (fndecl)
427 : 29334638 : gimple_call_set_expected_throw (call,
428 : 9725230 : flags_from_decl_or_type (fndecl)
429 : 9725230 : & ECF_XTHROW);
430 : 9884178 : gimple_call_set_by_descriptor (call, CALL_EXPR_BY_DESCRIPTOR (t));
431 : 9884178 : copy_warning (call, t);
432 : :
433 : 9884178 : if (fnptrtype)
434 : : {
435 : 9884075 : gimple_call_set_fntype (call, TREE_TYPE (fnptrtype));
436 : :
437 : : /* Check if it's an indirect CALL and the type has the
438 : : nocf_check attribute. In that case propagate the information
439 : : to the gimple CALL insn. */
440 : 9884075 : if (!fndecl)
441 : : {
442 : 158845 : gcc_assert (POINTER_TYPE_P (fnptrtype));
443 : 158845 : tree fntype = TREE_TYPE (fnptrtype);
444 : :
445 : 158845 : if (lookup_attribute ("nocf_check", TYPE_ATTRIBUTES (fntype)))
446 : 21 : gimple_call_set_nocf_check (call, true);
447 : : }
448 : : }
449 : :
450 : 9884178 : return call;
451 : : }
452 : :
453 : : /* Build a gcall to __builtin_unreachable as rewritten by
454 : : -fsanitize=unreachable. */
455 : :
456 : : gcall *
457 : 158045 : gimple_build_builtin_unreachable (location_t loc)
458 : : {
459 : 158045 : tree data = NULL_TREE;
460 : 158045 : tree fn = sanitize_unreachable_fn (&data, loc);
461 : 158045 : gcall *g = gimple_build_call (fn, data != NULL_TREE, data);
462 : 158045 : gimple_call_set_ctrl_altering (g, true);
463 : 158045 : gimple_set_location (g, loc);
464 : 158045 : return g;
465 : : }
466 : :
467 : : /* Build a GIMPLE_ASSIGN statement.
468 : :
469 : : LHS of the assignment.
470 : : RHS of the assignment which can be unary or binary. */
471 : :
472 : : gassign *
473 : 82190257 : gimple_build_assign (tree lhs, tree rhs MEM_STAT_DECL)
474 : : {
475 : 82190257 : enum tree_code subcode;
476 : 82190257 : tree op1, op2, op3;
477 : :
478 : 82190257 : extract_ops_from_tree (rhs, &subcode, &op1, &op2, &op3);
479 : 82190257 : return gimple_build_assign (lhs, subcode, op1, op2, op3 PASS_MEM_STAT);
480 : : }
481 : :
482 : :
483 : : /* Build a GIMPLE_ASSIGN statement with subcode SUBCODE and operands
484 : : OP1, OP2 and OP3. */
485 : :
486 : : static inline gassign *
487 : 87485569 : gimple_build_assign_1 (tree lhs, enum tree_code subcode, tree op1,
488 : : tree op2, tree op3 MEM_STAT_DECL)
489 : : {
490 : 87485569 : unsigned num_ops;
491 : 87485569 : gassign *p;
492 : :
493 : : /* Need 1 operand for LHS and 1 or 2 for the RHS (depending on the
494 : : code). */
495 : 87485569 : num_ops = get_gimple_rhs_num_ops (subcode) + 1;
496 : :
497 : 174971138 : p = as_a <gassign *> (
498 : : gimple_build_with_ops_stat (GIMPLE_ASSIGN, (unsigned)subcode, num_ops
499 : : PASS_MEM_STAT));
500 : 87485569 : gimple_assign_set_lhs (p, lhs);
501 : : /* For COND_EXPR, op1 should not be a comparison. */
502 : 87485569 : if (op1 && subcode == COND_EXPR)
503 : 221537 : gcc_assert (!COMPARISON_CLASS_P (op1));
504 : 87485569 : gimple_assign_set_rhs1 (p, op1);
505 : 87485569 : if (op2)
506 : : {
507 : 13630971 : gcc_assert (num_ops > 2);
508 : 13630971 : gimple_assign_set_rhs2 (p, op2);
509 : : }
510 : :
511 : 87485569 : if (op3)
512 : : {
513 : 318548 : gcc_assert (num_ops > 3);
514 : 318548 : gimple_assign_set_rhs3 (p, op3);
515 : : }
516 : :
517 : 87485569 : return p;
518 : : }
519 : :
520 : : /* Build a GIMPLE_ASSIGN statement with subcode SUBCODE and operands
521 : : OP1, OP2 and OP3. */
522 : :
523 : : gassign *
524 : 83478283 : gimple_build_assign (tree lhs, enum tree_code subcode, tree op1,
525 : : tree op2, tree op3 MEM_STAT_DECL)
526 : : {
527 : 83478283 : return gimple_build_assign_1 (lhs, subcode, op1, op2, op3 PASS_MEM_STAT);
528 : : }
529 : :
530 : : /* Build a GIMPLE_ASSIGN statement with subcode SUBCODE and operands
531 : : OP1 and OP2. */
532 : :
533 : : gassign *
534 : 2838687 : gimple_build_assign (tree lhs, enum tree_code subcode, tree op1,
535 : : tree op2 MEM_STAT_DECL)
536 : : {
537 : 2838687 : return gimple_build_assign_1 (lhs, subcode, op1, op2, NULL_TREE
538 : 2838687 : PASS_MEM_STAT);
539 : : }
540 : :
541 : : /* Build a GIMPLE_ASSIGN statement with subcode SUBCODE and operand OP1. */
542 : :
543 : : gassign *
544 : 1168599 : gimple_build_assign (tree lhs, enum tree_code subcode, tree op1 MEM_STAT_DECL)
545 : : {
546 : 1168599 : return gimple_build_assign_1 (lhs, subcode, op1, NULL_TREE, NULL_TREE
547 : 1168599 : PASS_MEM_STAT);
548 : : }
549 : :
550 : :
551 : : /* Build a GIMPLE_COND statement.
552 : :
553 : : PRED is the condition used to compare LHS and the RHS.
554 : : T_LABEL is the label to jump to if the condition is true.
555 : : F_LABEL is the label to jump to otherwise. */
556 : :
557 : : gcond *
558 : 10086929 : gimple_build_cond (enum tree_code pred_code, tree lhs, tree rhs,
559 : : tree t_label, tree f_label)
560 : : {
561 : 10086929 : gcond *p;
562 : :
563 : 10086929 : gcc_assert (TREE_CODE_CLASS (pred_code) == tcc_comparison);
564 : 20173858 : p = as_a <gcond *> (gimple_build_with_ops (GIMPLE_COND, pred_code, 4));
565 : 10086929 : gimple_cond_set_lhs (p, lhs);
566 : 10086929 : gimple_cond_set_rhs (p, rhs);
567 : 10086929 : gimple_cond_set_true_label (p, t_label);
568 : 10086929 : gimple_cond_set_false_label (p, f_label);
569 : 10086929 : return p;
570 : : }
571 : :
572 : : /* Build a GIMPLE_COND statement from the conditional expression tree
573 : : COND. T_LABEL and F_LABEL are as in gimple_build_cond. */
574 : :
575 : : gcond *
576 : 90881 : gimple_build_cond_from_tree (tree cond, tree t_label, tree f_label)
577 : : {
578 : 90881 : enum tree_code code;
579 : 90881 : tree lhs, rhs;
580 : :
581 : 90881 : gimple_cond_get_ops_from_tree (cond, &code, &lhs, &rhs);
582 : 90881 : return gimple_build_cond (code, lhs, rhs, t_label, f_label);
583 : : }
584 : :
585 : : /* Set code, lhs, and rhs of a GIMPLE_COND from a suitable
586 : : boolean expression tree COND. */
587 : :
588 : : void
589 : 365057 : gimple_cond_set_condition_from_tree (gcond *stmt, tree cond)
590 : : {
591 : 365057 : enum tree_code code;
592 : 365057 : tree lhs, rhs;
593 : :
594 : 365057 : gimple_cond_get_ops_from_tree (cond, &code, &lhs, &rhs);
595 : 365057 : gimple_cond_set_condition (stmt, code, lhs, rhs);
596 : 365057 : }
597 : :
598 : : /* Build a GIMPLE_LABEL statement for LABEL. */
599 : :
600 : : glabel *
601 : 18266811 : gimple_build_label (tree label)
602 : : {
603 : 18266811 : glabel *p
604 : 18266811 : = as_a <glabel *> (gimple_build_with_ops (GIMPLE_LABEL, ERROR_MARK, 1));
605 : 18266811 : gimple_label_set_label (p, label);
606 : 18266811 : return p;
607 : : }
608 : :
609 : : /* Build a GIMPLE_GOTO statement to label DEST. */
610 : :
611 : : ggoto *
612 : 6535786 : gimple_build_goto (tree dest)
613 : : {
614 : 6535786 : ggoto *p
615 : 6535786 : = as_a <ggoto *> (gimple_build_with_ops (GIMPLE_GOTO, ERROR_MARK, 1));
616 : 6535786 : gimple_goto_set_dest (p, dest);
617 : 6535786 : return p;
618 : : }
619 : :
620 : :
621 : : /* Build a GIMPLE_NOP statement. */
622 : :
623 : : gimple *
624 : 14360555 : gimple_build_nop (void)
625 : : {
626 : 14360555 : return gimple_alloc (GIMPLE_NOP, 0);
627 : : }
628 : :
629 : :
630 : : /* Build a GIMPLE_BIND statement.
631 : : VARS are the variables in BODY.
632 : : BLOCK is the containing block. */
633 : :
634 : : gbind *
635 : 7171955 : gimple_build_bind (tree vars, gimple_seq body, tree block)
636 : : {
637 : 7171955 : gbind *p = as_a <gbind *> (gimple_alloc (GIMPLE_BIND, 0));
638 : 7171955 : gimple_bind_set_vars (p, vars);
639 : 7171955 : if (body)
640 : 1303672 : gimple_bind_set_body (p, body);
641 : 7171955 : if (block)
642 : 5725333 : gimple_bind_set_block (p, block);
643 : 7171955 : return p;
644 : : }
645 : :
646 : : /* Helper function to set the simple fields of a asm stmt.
647 : :
648 : : STRING is a pointer to a string that is the asm blocks assembly code.
649 : : NINPUT is the number of register inputs.
650 : : NOUTPUT is the number of register outputs.
651 : : NCLOBBERS is the number of clobbered registers.
652 : : */
653 : :
654 : : static inline gasm *
655 : 99685 : gimple_build_asm_1 (const char *string, unsigned ninputs, unsigned noutputs,
656 : : unsigned nclobbers, unsigned nlabels)
657 : : {
658 : 99685 : gasm *p;
659 : 99685 : int size = strlen (string);
660 : :
661 : 99685 : p = as_a <gasm *> (
662 : 99685 : gimple_build_with_ops (GIMPLE_ASM, ERROR_MARK,
663 : : ninputs + noutputs + nclobbers + nlabels));
664 : :
665 : 99685 : p->ni = ninputs;
666 : 99685 : p->no = noutputs;
667 : 99685 : p->nc = nclobbers;
668 : 99685 : p->nl = nlabels;
669 : 99685 : p->string = ggc_alloc_string (string, size);
670 : :
671 : 99685 : if (GATHER_STATISTICS)
672 : : gimple_alloc_sizes[(int) gimple_alloc_kind (GIMPLE_ASM)] += size;
673 : :
674 : 99685 : return p;
675 : : }
676 : :
677 : : /* Build a GIMPLE_ASM statement.
678 : :
679 : : STRING is the assembly code.
680 : : NINPUT is the number of register inputs.
681 : : NOUTPUT is the number of register outputs.
682 : : NCLOBBERS is the number of clobbered registers.
683 : : INPUTS is a vector of the input register parameters.
684 : : OUTPUTS is a vector of the output register parameters.
685 : : CLOBBERS is a vector of the clobbered register parameters.
686 : : LABELS is a vector of destination labels. */
687 : :
688 : : gasm *
689 : 99685 : gimple_build_asm_vec (const char *string, vec<tree, va_gc> *inputs,
690 : : vec<tree, va_gc> *outputs, vec<tree, va_gc> *clobbers,
691 : : vec<tree, va_gc> *labels)
692 : : {
693 : 99685 : gasm *p;
694 : 99685 : unsigned i;
695 : :
696 : 196151 : p = gimple_build_asm_1 (string,
697 : : vec_safe_length (inputs),
698 : : vec_safe_length (outputs),
699 : : vec_safe_length (clobbers),
700 : : vec_safe_length (labels));
701 : :
702 : 319480 : for (i = 0; i < vec_safe_length (inputs); i++)
703 : 44162 : gimple_asm_set_input_op (p, i, (*inputs)[i]);
704 : :
705 : 252904 : for (i = 0; i < vec_safe_length (outputs); i++)
706 : 62164 : gimple_asm_set_output_op (p, i, (*outputs)[i]);
707 : :
708 : 355418 : for (i = 0; i < vec_safe_length (clobbers); i++)
709 : 94304 : gimple_asm_set_clobber_op (p, i, (*clobbers)[i]);
710 : :
711 : 100448 : for (i = 0; i < vec_safe_length (labels); i++)
712 : 763 : gimple_asm_set_label_op (p, i, (*labels)[i]);
713 : :
714 : 99685 : return p;
715 : : }
716 : :
717 : : /* Build a GIMPLE_CATCH statement.
718 : :
719 : : TYPES are the catch types.
720 : : HANDLER is the exception handler. */
721 : :
722 : : gcatch *
723 : 38431 : gimple_build_catch (tree types, gimple_seq handler)
724 : : {
725 : 38431 : gcatch *p = as_a <gcatch *> (gimple_alloc (GIMPLE_CATCH, 0));
726 : 38431 : gimple_catch_set_types (p, types);
727 : 38431 : if (handler)
728 : 38419 : gimple_catch_set_handler (p, handler);
729 : :
730 : 38431 : return p;
731 : : }
732 : :
733 : : /* Build a GIMPLE_EH_FILTER statement.
734 : :
735 : : TYPES are the filter's types.
736 : : FAILURE is the filter's failure action. */
737 : :
738 : : geh_filter *
739 : 4227 : gimple_build_eh_filter (tree types, gimple_seq failure)
740 : : {
741 : 4227 : geh_filter *p = as_a <geh_filter *> (gimple_alloc (GIMPLE_EH_FILTER, 0));
742 : 4227 : gimple_eh_filter_set_types (p, types);
743 : 4227 : if (failure)
744 : 4227 : gimple_eh_filter_set_failure (p, failure);
745 : :
746 : 4227 : return p;
747 : : }
748 : :
749 : : /* Build a GIMPLE_EH_MUST_NOT_THROW statement. */
750 : :
751 : : geh_mnt *
752 : 1120291 : gimple_build_eh_must_not_throw (tree decl)
753 : : {
754 : 1120291 : geh_mnt *p = as_a <geh_mnt *> (gimple_alloc (GIMPLE_EH_MUST_NOT_THROW, 0));
755 : :
756 : 1120291 : gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
757 : 1120291 : gcc_assert (flags_from_decl_or_type (decl) & ECF_NORETURN);
758 : 1120291 : gimple_eh_must_not_throw_set_fndecl (p, decl);
759 : :
760 : 1120291 : return p;
761 : : }
762 : :
763 : : /* Build a GIMPLE_EH_ELSE statement. */
764 : :
765 : : geh_else *
766 : 361 : gimple_build_eh_else (gimple_seq n_body, gimple_seq e_body)
767 : : {
768 : 361 : geh_else *p = as_a <geh_else *> (gimple_alloc (GIMPLE_EH_ELSE, 0));
769 : 361 : gimple_eh_else_set_n_body (p, n_body);
770 : 361 : gimple_eh_else_set_e_body (p, e_body);
771 : 361 : return p;
772 : : }
773 : :
774 : : /* Build a GIMPLE_TRY statement.
775 : :
776 : : EVAL is the expression to evaluate.
777 : : CLEANUP is the cleanup expression.
778 : : KIND is either GIMPLE_TRY_CATCH or GIMPLE_TRY_FINALLY depending on
779 : : whether this is a try/catch or a try/finally respectively. */
780 : :
781 : : gtry *
782 : 2814786 : gimple_build_try (gimple_seq eval, gimple_seq cleanup,
783 : : enum gimple_try_flags kind)
784 : : {
785 : 2814786 : gtry *p;
786 : :
787 : 2814786 : gcc_assert (kind == GIMPLE_TRY_CATCH || kind == GIMPLE_TRY_FINALLY);
788 : 2814786 : p = as_a <gtry *> (gimple_alloc (GIMPLE_TRY, 0));
789 : 2814786 : gimple_set_subcode (p, kind);
790 : 2814786 : if (eval)
791 : 2703881 : gimple_try_set_eval (p, eval);
792 : 2814786 : if (cleanup)
793 : 2814786 : gimple_try_set_cleanup (p, cleanup);
794 : :
795 : 2814786 : return p;
796 : : }
797 : :
798 : : /* Construct a GIMPLE_WITH_CLEANUP_EXPR statement.
799 : :
800 : : CLEANUP is the cleanup expression. */
801 : :
802 : : gimple *
803 : 510154 : gimple_build_wce (gimple_seq cleanup)
804 : : {
805 : 510154 : gimple *p = gimple_alloc (GIMPLE_WITH_CLEANUP_EXPR, 0);
806 : 510154 : if (cleanup)
807 : 510154 : gimple_wce_set_cleanup (p, cleanup);
808 : :
809 : 510154 : return p;
810 : : }
811 : :
812 : :
813 : : /* Build a GIMPLE_RESX statement. */
814 : :
815 : : gresx *
816 : 766906 : gimple_build_resx (int region)
817 : : {
818 : 766906 : gresx *p
819 : 766906 : = as_a <gresx *> (gimple_build_with_ops (GIMPLE_RESX, ERROR_MARK, 0));
820 : 766906 : p->region = region;
821 : 766906 : return p;
822 : : }
823 : :
824 : :
825 : : /* The helper for constructing a gimple switch statement.
826 : : INDEX is the switch's index.
827 : : NLABELS is the number of labels in the switch excluding the default.
828 : : DEFAULT_LABEL is the default label for the switch statement. */
829 : :
830 : : gswitch *
831 : 64094 : gimple_build_switch_nlabels (unsigned nlabels, tree index, tree default_label)
832 : : {
833 : : /* nlabels + 1 default label + 1 index. */
834 : 64094 : gcc_checking_assert (default_label);
835 : 128188 : gswitch *p = as_a <gswitch *> (gimple_build_with_ops (GIMPLE_SWITCH,
836 : : ERROR_MARK,
837 : : 1 + 1 + nlabels));
838 : 64094 : gimple_switch_set_index (p, index);
839 : 64094 : gimple_switch_set_default_label (p, default_label);
840 : 64094 : return p;
841 : : }
842 : :
843 : : /* Build a GIMPLE_SWITCH statement.
844 : :
845 : : INDEX is the switch's index.
846 : : DEFAULT_LABEL is the default label
847 : : ARGS is a vector of labels excluding the default. */
848 : :
849 : : gswitch *
850 : 64094 : gimple_build_switch (tree index, tree default_label, const vec<tree> &args)
851 : : {
852 : 64094 : unsigned i, nlabels = args.length ();
853 : :
854 : 64094 : gswitch *p = gimple_build_switch_nlabels (nlabels, index, default_label);
855 : :
856 : : /* Copy the labels from the vector to the switch statement. */
857 : 1231150 : for (i = 0; i < nlabels; i++)
858 : 1102962 : gimple_switch_set_label (p, i + 1, args[i]);
859 : :
860 : 64094 : return p;
861 : : }
862 : :
863 : : /* Build a GIMPLE_EH_DISPATCH statement. */
864 : :
865 : : geh_dispatch *
866 : 40879 : gimple_build_eh_dispatch (int region)
867 : : {
868 : 40879 : geh_dispatch *p
869 : 40879 : = as_a <geh_dispatch *> (
870 : : gimple_build_with_ops (GIMPLE_EH_DISPATCH, ERROR_MARK, 0));
871 : 40879 : p->region = region;
872 : 40879 : return p;
873 : : }
874 : :
875 : : /* Build a new GIMPLE_DEBUG_BIND statement.
876 : :
877 : : VAR is bound to VALUE; block and location are taken from STMT. */
878 : :
879 : : gdebug *
880 : 48121212 : gimple_build_debug_bind (tree var, tree value, gimple *stmt MEM_STAT_DECL)
881 : : {
882 : 48121212 : gdebug *p
883 : 48121212 : = as_a <gdebug *> (gimple_build_with_ops_stat (GIMPLE_DEBUG,
884 : : (unsigned)GIMPLE_DEBUG_BIND, 2
885 : : PASS_MEM_STAT));
886 : 48121212 : gimple_debug_bind_set_var (p, var);
887 : 48121212 : gimple_debug_bind_set_value (p, value);
888 : 48121212 : if (stmt)
889 : 47254926 : gimple_set_location (p, gimple_location (stmt));
890 : :
891 : 48121212 : return p;
892 : : }
893 : :
894 : :
895 : : /* Build a new GIMPLE_DEBUG_SOURCE_BIND statement.
896 : :
897 : : VAR is bound to VALUE; block and location are taken from STMT. */
898 : :
899 : : gdebug *
900 : 511604 : gimple_build_debug_source_bind (tree var, tree value,
901 : : gimple *stmt MEM_STAT_DECL)
902 : : {
903 : 511604 : gdebug *p
904 : 511604 : = as_a <gdebug *> (
905 : : gimple_build_with_ops_stat (GIMPLE_DEBUG,
906 : : (unsigned)GIMPLE_DEBUG_SOURCE_BIND, 2
907 : : PASS_MEM_STAT));
908 : :
909 : 511604 : gimple_debug_source_bind_set_var (p, var);
910 : 511604 : gimple_debug_source_bind_set_value (p, value);
911 : 511604 : if (stmt)
912 : 392688 : gimple_set_location (p, gimple_location (stmt));
913 : :
914 : 511604 : return p;
915 : : }
916 : :
917 : :
918 : : /* Build a new GIMPLE_DEBUG_BEGIN_STMT statement in BLOCK at
919 : : LOCATION. */
920 : :
921 : : gdebug *
922 : 2578850 : gimple_build_debug_begin_stmt (tree block, location_t location
923 : : MEM_STAT_DECL)
924 : : {
925 : 2578850 : gdebug *p
926 : 2578850 : = as_a <gdebug *> (
927 : : gimple_build_with_ops_stat (GIMPLE_DEBUG,
928 : : (unsigned)GIMPLE_DEBUG_BEGIN_STMT, 0
929 : : PASS_MEM_STAT));
930 : :
931 : 2578850 : gimple_set_location (p, location);
932 : 2578850 : gimple_set_block (p, block);
933 : 2578850 : cfun->debug_marker_count++;
934 : :
935 : 2578850 : return p;
936 : : }
937 : :
938 : :
939 : : /* Build a new GIMPLE_DEBUG_INLINE_ENTRY statement in BLOCK at
940 : : LOCATION. The BLOCK links to the inlined function. */
941 : :
942 : : gdebug *
943 : 3296300 : gimple_build_debug_inline_entry (tree block, location_t location
944 : : MEM_STAT_DECL)
945 : : {
946 : 3296300 : gdebug *p
947 : 3296300 : = as_a <gdebug *> (
948 : : gimple_build_with_ops_stat (GIMPLE_DEBUG,
949 : : (unsigned)GIMPLE_DEBUG_INLINE_ENTRY, 0
950 : : PASS_MEM_STAT));
951 : :
952 : 3296300 : gimple_set_location (p, location);
953 : 3296300 : gimple_set_block (p, block);
954 : 3296300 : cfun->debug_marker_count++;
955 : :
956 : 3296300 : return p;
957 : : }
958 : :
959 : :
960 : : /* Build a GIMPLE_OMP_CRITICAL statement.
961 : :
962 : : BODY is the sequence of statements for which only one thread can execute.
963 : : NAME is optional identifier for this critical block.
964 : : CLAUSES are clauses for this critical block. */
965 : :
966 : : gomp_critical *
967 : 546 : gimple_build_omp_critical (gimple_seq body, tree name, tree clauses)
968 : : {
969 : 546 : gomp_critical *p
970 : 546 : = as_a <gomp_critical *> (gimple_alloc (GIMPLE_OMP_CRITICAL, 0));
971 : 546 : gimple_omp_critical_set_name (p, name);
972 : 546 : gimple_omp_critical_set_clauses (p, clauses);
973 : 546 : if (body)
974 : 456 : gimple_omp_set_body (p, body);
975 : :
976 : 546 : return p;
977 : : }
978 : :
979 : : /* Build a GIMPLE_OMP_FOR statement.
980 : :
981 : : BODY is sequence of statements inside the for loop.
982 : : KIND is the `for' variant.
983 : : CLAUSES are any of the construct's clauses.
984 : : COLLAPSE is the collapse count.
985 : : PRE_BODY is the sequence of statements that are loop invariant. */
986 : :
987 : : gomp_for *
988 : 53381 : gimple_build_omp_for (gimple_seq body, int kind, tree clauses, size_t collapse,
989 : : gimple_seq pre_body)
990 : : {
991 : 53381 : gomp_for *p = as_a <gomp_for *> (gimple_alloc (GIMPLE_OMP_FOR, 0));
992 : 53381 : if (body)
993 : 49520 : gimple_omp_set_body (p, body);
994 : 53381 : gimple_omp_for_set_clauses (p, clauses);
995 : 53381 : gimple_omp_for_set_kind (p, kind);
996 : 53381 : p->collapse = collapse;
997 : 53381 : p->iter = ggc_cleared_vec_alloc<gimple_omp_for_iter> (collapse);
998 : :
999 : 53381 : if (pre_body)
1000 : 2446 : gimple_omp_for_set_pre_body (p, pre_body);
1001 : :
1002 : 53381 : return p;
1003 : : }
1004 : :
1005 : :
1006 : : /* Build a GIMPLE_OMP_PARALLEL statement.
1007 : :
1008 : : BODY is sequence of statements which are executed in parallel.
1009 : : CLAUSES are the OMP parallel construct's clauses.
1010 : : CHILD_FN is the function created for the parallel threads to execute.
1011 : : DATA_ARG are the shared data argument(s). */
1012 : :
1013 : : gomp_parallel *
1014 : 18402 : gimple_build_omp_parallel (gimple_seq body, tree clauses, tree child_fn,
1015 : : tree data_arg)
1016 : : {
1017 : 18402 : gomp_parallel *p
1018 : 18402 : = as_a <gomp_parallel *> (gimple_alloc (GIMPLE_OMP_PARALLEL, 0));
1019 : 18402 : if (body)
1020 : 18198 : gimple_omp_set_body (p, body);
1021 : 18402 : gimple_omp_parallel_set_clauses (p, clauses);
1022 : 18402 : gimple_omp_parallel_set_child_fn (p, child_fn);
1023 : 18402 : gimple_omp_parallel_set_data_arg (p, data_arg);
1024 : :
1025 : 18402 : return p;
1026 : : }
1027 : :
1028 : :
1029 : : /* Build a GIMPLE_OMP_TASK statement.
1030 : :
1031 : : BODY is sequence of statements which are executed by the explicit task.
1032 : : CLAUSES are the OMP task construct's clauses.
1033 : : CHILD_FN is the function created for the parallel threads to execute.
1034 : : DATA_ARG are the shared data argument(s).
1035 : : COPY_FN is the optional function for firstprivate initialization.
1036 : : ARG_SIZE and ARG_ALIGN are size and alignment of the data block. */
1037 : :
1038 : : gomp_task *
1039 : 5605 : gimple_build_omp_task (gimple_seq body, tree clauses, tree child_fn,
1040 : : tree data_arg, tree copy_fn, tree arg_size,
1041 : : tree arg_align)
1042 : : {
1043 : 5605 : gomp_task *p = as_a <gomp_task *> (gimple_alloc (GIMPLE_OMP_TASK, 0));
1044 : 5605 : if (body)
1045 : 5518 : gimple_omp_set_body (p, body);
1046 : 5605 : gimple_omp_task_set_clauses (p, clauses);
1047 : 5605 : gimple_omp_task_set_child_fn (p, child_fn);
1048 : 5605 : gimple_omp_task_set_data_arg (p, data_arg);
1049 : 5605 : gimple_omp_task_set_copy_fn (p, copy_fn);
1050 : 5605 : gimple_omp_task_set_arg_size (p, arg_size);
1051 : 5605 : gimple_omp_task_set_arg_align (p, arg_align);
1052 : :
1053 : 5605 : return p;
1054 : : }
1055 : :
1056 : :
1057 : : /* Build a GIMPLE_OMP_SECTION statement for a sections statement.
1058 : :
1059 : : BODY is the sequence of statements in the section. */
1060 : :
1061 : : gimple *
1062 : 1271 : gimple_build_omp_section (gimple_seq body)
1063 : : {
1064 : 1271 : gimple *p = gimple_alloc (GIMPLE_OMP_SECTION, 0);
1065 : 1271 : if (body)
1066 : 1079 : gimple_omp_set_body (p, body);
1067 : :
1068 : 1271 : return p;
1069 : : }
1070 : :
1071 : :
1072 : : /* Build a GIMPLE_OMP_STRUCTURED_BLOCK statement.
1073 : :
1074 : : BODY is the structured block sequence. */
1075 : :
1076 : : gimple *
1077 : 774 : gimple_build_omp_structured_block (gimple_seq body)
1078 : : {
1079 : 774 : gimple *p = gimple_alloc (GIMPLE_OMP_STRUCTURED_BLOCK, 0);
1080 : 774 : if (body)
1081 : 774 : gimple_omp_set_body (p, body);
1082 : :
1083 : 774 : return p;
1084 : : }
1085 : :
1086 : :
1087 : : /* Build a GIMPLE_OMP_MASTER statement.
1088 : :
1089 : : BODY is the sequence of statements to be executed by just the master. */
1090 : :
1091 : : gimple *
1092 : 886 : gimple_build_omp_master (gimple_seq body)
1093 : : {
1094 : 886 : gimple *p = gimple_alloc (GIMPLE_OMP_MASTER, 0);
1095 : 886 : if (body)
1096 : 793 : gimple_omp_set_body (p, body);
1097 : :
1098 : 886 : return p;
1099 : : }
1100 : :
1101 : : /* Build a GIMPLE_OMP_MASKED statement.
1102 : :
1103 : : BODY is the sequence of statements to be executed by the selected thread(s). */
1104 : :
1105 : : gimple *
1106 : 446 : gimple_build_omp_masked (gimple_seq body, tree clauses)
1107 : : {
1108 : 446 : gimple *p = gimple_alloc (GIMPLE_OMP_MASKED, 0);
1109 : 446 : gimple_omp_masked_set_clauses (p, clauses);
1110 : 446 : if (body)
1111 : 386 : gimple_omp_set_body (p, body);
1112 : :
1113 : 446 : return p;
1114 : : }
1115 : :
1116 : : /* Build a GIMPLE_OMP_TASKGROUP statement.
1117 : :
1118 : : BODY is the sequence of statements to be executed by the taskgroup
1119 : : construct.
1120 : : CLAUSES are any of the construct's clauses. */
1121 : :
1122 : : gimple *
1123 : 611 : gimple_build_omp_taskgroup (gimple_seq body, tree clauses)
1124 : : {
1125 : 611 : gimple *p = gimple_alloc (GIMPLE_OMP_TASKGROUP, 0);
1126 : 611 : gimple_omp_taskgroup_set_clauses (p, clauses);
1127 : 611 : if (body)
1128 : 611 : gimple_omp_set_body (p, body);
1129 : :
1130 : 611 : return p;
1131 : : }
1132 : :
1133 : :
1134 : : /* Build a GIMPLE_OMP_CONTINUE statement.
1135 : :
1136 : : CONTROL_DEF is the definition of the control variable.
1137 : : CONTROL_USE is the use of the control variable. */
1138 : :
1139 : : gomp_continue *
1140 : 51868 : gimple_build_omp_continue (tree control_def, tree control_use)
1141 : : {
1142 : 51868 : gomp_continue *p
1143 : 51868 : = as_a <gomp_continue *> (gimple_alloc (GIMPLE_OMP_CONTINUE, 0));
1144 : 51868 : gimple_omp_continue_set_control_def (p, control_def);
1145 : 51868 : gimple_omp_continue_set_control_use (p, control_use);
1146 : 51868 : return p;
1147 : : }
1148 : :
1149 : : /* Build a GIMPLE_OMP_ORDERED statement.
1150 : :
1151 : : BODY is the sequence of statements inside a loop that will executed in
1152 : : sequence.
1153 : : CLAUSES are clauses for this statement. */
1154 : :
1155 : : gomp_ordered *
1156 : 1838 : gimple_build_omp_ordered (gimple_seq body, tree clauses)
1157 : : {
1158 : 1838 : gomp_ordered *p
1159 : 1838 : = as_a <gomp_ordered *> (gimple_alloc (GIMPLE_OMP_ORDERED, 0));
1160 : 1838 : gimple_omp_ordered_set_clauses (p, clauses);
1161 : 1838 : if (body)
1162 : 501 : gimple_omp_set_body (p, body);
1163 : :
1164 : 1838 : return p;
1165 : : }
1166 : :
1167 : :
1168 : : /* Build a GIMPLE_OMP_RETURN statement.
1169 : : WAIT_P is true if this is a non-waiting return. */
1170 : :
1171 : : gimple *
1172 : 100349 : gimple_build_omp_return (bool wait_p)
1173 : : {
1174 : 100349 : gimple *p = gimple_alloc (GIMPLE_OMP_RETURN, 0);
1175 : 100349 : if (wait_p)
1176 : 37632 : gimple_omp_return_set_nowait (p);
1177 : :
1178 : 100349 : return p;
1179 : : }
1180 : :
1181 : :
1182 : : /* Build a GIMPLE_OMP_SCAN statement.
1183 : :
1184 : : BODY is the sequence of statements to be executed by the scan
1185 : : construct.
1186 : : CLAUSES are any of the construct's clauses. */
1187 : :
1188 : : gomp_scan *
1189 : 1284 : gimple_build_omp_scan (gimple_seq body, tree clauses)
1190 : : {
1191 : 1284 : gomp_scan *p
1192 : 1284 : = as_a <gomp_scan *> (gimple_alloc (GIMPLE_OMP_SCAN, 0));
1193 : 1284 : gimple_omp_scan_set_clauses (p, clauses);
1194 : 1284 : if (body)
1195 : 1070 : gimple_omp_set_body (p, body);
1196 : :
1197 : 1284 : return p;
1198 : : }
1199 : :
1200 : :
1201 : : /* Build a GIMPLE_OMP_SECTIONS statement.
1202 : :
1203 : : BODY is a sequence of section statements.
1204 : : CLAUSES are any of the OMP sections contsruct's clauses: private,
1205 : : firstprivate, lastprivate, reduction, and nowait. */
1206 : :
1207 : : gomp_sections *
1208 : 626 : gimple_build_omp_sections (gimple_seq body, tree clauses)
1209 : : {
1210 : 626 : gomp_sections *p
1211 : 626 : = as_a <gomp_sections *> (gimple_alloc (GIMPLE_OMP_SECTIONS, 0));
1212 : 626 : if (body)
1213 : 626 : gimple_omp_set_body (p, body);
1214 : 626 : gimple_omp_sections_set_clauses (p, clauses);
1215 : :
1216 : 626 : return p;
1217 : : }
1218 : :
1219 : :
1220 : : /* Build a GIMPLE_OMP_SECTIONS_SWITCH. */
1221 : :
1222 : : gimple *
1223 : 378 : gimple_build_omp_sections_switch (void)
1224 : : {
1225 : 378 : return gimple_alloc (GIMPLE_OMP_SECTIONS_SWITCH, 0);
1226 : : }
1227 : :
1228 : :
1229 : : /* Build a GIMPLE_OMP_SINGLE statement.
1230 : :
1231 : : BODY is the sequence of statements that will be executed once.
1232 : : CLAUSES are any of the OMP single construct's clauses: private, firstprivate,
1233 : : copyprivate, nowait. */
1234 : :
1235 : : gomp_single *
1236 : 1284 : gimple_build_omp_single (gimple_seq body, tree clauses)
1237 : : {
1238 : 1284 : gomp_single *p
1239 : 1284 : = as_a <gomp_single *> (gimple_alloc (GIMPLE_OMP_SINGLE, 0));
1240 : 1284 : if (body)
1241 : 1175 : gimple_omp_set_body (p, body);
1242 : 1284 : gimple_omp_single_set_clauses (p, clauses);
1243 : :
1244 : 1284 : return p;
1245 : : }
1246 : :
1247 : :
1248 : : /* Build a GIMPLE_OMP_SCOPE statement.
1249 : :
1250 : : BODY is the sequence of statements that will be executed once.
1251 : : CLAUSES are any of the OMP scope construct's clauses: private, reduction,
1252 : : nowait. */
1253 : :
1254 : : gimple *
1255 : 214 : gimple_build_omp_scope (gimple_seq body, tree clauses)
1256 : : {
1257 : 214 : gimple *p = gimple_alloc (GIMPLE_OMP_SCOPE, 0);
1258 : 214 : gimple_omp_scope_set_clauses (p, clauses);
1259 : 214 : if (body)
1260 : 156 : gimple_omp_set_body (p, body);
1261 : :
1262 : 214 : return p;
1263 : : }
1264 : :
1265 : : /* Build a GIMPLE_OMP_DISPATCH statement.
1266 : :
1267 : : BODY is the target function call to be dispatched.
1268 : : CLAUSES are any of the OMP dispatch construct's clauses. */
1269 : :
1270 : : gimple *
1271 : 819 : gimple_build_omp_dispatch (gimple_seq body, tree clauses)
1272 : : {
1273 : 819 : gimple *p = gimple_alloc (GIMPLE_OMP_DISPATCH, 0);
1274 : 819 : gimple_omp_dispatch_set_clauses (p, clauses);
1275 : 819 : if (body)
1276 : 819 : gimple_omp_set_body (p, body);
1277 : :
1278 : 819 : return p;
1279 : : }
1280 : :
1281 : : /* Build a GIMPLE_OMP_TARGET statement.
1282 : :
1283 : : BODY is the sequence of statements that will be executed.
1284 : : KIND is the kind of the region.
1285 : : CLAUSES are any of the construct's clauses. */
1286 : :
1287 : : gomp_target *
1288 : 40988 : gimple_build_omp_target (gimple_seq body, int kind, tree clauses)
1289 : : {
1290 : 40988 : gomp_target *p
1291 : 40988 : = as_a <gomp_target *> (gimple_alloc (GIMPLE_OMP_TARGET, 0));
1292 : 40988 : if (body)
1293 : 27774 : gimple_omp_set_body (p, body);
1294 : 40988 : gimple_omp_target_set_clauses (p, clauses);
1295 : 40988 : gimple_omp_target_set_kind (p, kind);
1296 : :
1297 : 40988 : return p;
1298 : : }
1299 : :
1300 : :
1301 : : /* Build a GIMPLE_OMP_TEAMS statement.
1302 : :
1303 : : BODY is the sequence of statements that will be executed.
1304 : : CLAUSES are any of the OMP teams construct's clauses. */
1305 : :
1306 : : gomp_teams *
1307 : 8779 : gimple_build_omp_teams (gimple_seq body, tree clauses)
1308 : : {
1309 : 8779 : gomp_teams *p = as_a <gomp_teams *> (gimple_alloc (GIMPLE_OMP_TEAMS, 0));
1310 : 8779 : if (body)
1311 : 8779 : gimple_omp_set_body (p, body);
1312 : 8779 : gimple_omp_teams_set_clauses (p, clauses);
1313 : :
1314 : 8779 : return p;
1315 : : }
1316 : :
1317 : :
1318 : : /* Build a GIMPLE_OMP_ATOMIC_LOAD statement. */
1319 : :
1320 : : gomp_atomic_load *
1321 : 10310 : gimple_build_omp_atomic_load (tree lhs, tree rhs, enum omp_memory_order mo)
1322 : : {
1323 : 10310 : gomp_atomic_load *p
1324 : 10310 : = as_a <gomp_atomic_load *> (gimple_alloc (GIMPLE_OMP_ATOMIC_LOAD, 0));
1325 : 10310 : gimple_omp_atomic_load_set_lhs (p, lhs);
1326 : 10310 : gimple_omp_atomic_load_set_rhs (p, rhs);
1327 : 10310 : gimple_omp_atomic_set_memory_order (p, mo);
1328 : 10310 : return p;
1329 : : }
1330 : :
1331 : : /* Build a GIMPLE_OMP_ATOMIC_STORE statement.
1332 : :
1333 : : VAL is the value we are storing. */
1334 : :
1335 : : gomp_atomic_store *
1336 : 10310 : gimple_build_omp_atomic_store (tree val, enum omp_memory_order mo)
1337 : : {
1338 : 10310 : gomp_atomic_store *p
1339 : 10310 : = as_a <gomp_atomic_store *> (gimple_alloc (GIMPLE_OMP_ATOMIC_STORE, 0));
1340 : 10310 : gimple_omp_atomic_store_set_val (p, val);
1341 : 10310 : gimple_omp_atomic_set_memory_order (p, mo);
1342 : 10310 : return p;
1343 : : }
1344 : :
1345 : : /* Build a GIMPLE_ASSUME statement. */
1346 : :
1347 : : gimple *
1348 : 108 : gimple_build_assume (tree guard, gimple_seq body)
1349 : : {
1350 : 108 : gimple_statement_assume *p
1351 : 108 : = as_a <gimple_statement_assume *> (gimple_alloc (GIMPLE_ASSUME, 0));
1352 : 108 : gimple_assume_set_guard (p, guard);
1353 : 108 : *gimple_assume_body_ptr (p) = body;
1354 : 108 : return p;
1355 : : }
1356 : :
1357 : : /* Build a GIMPLE_TRANSACTION statement. */
1358 : :
1359 : : gtransaction *
1360 : 545 : gimple_build_transaction (gimple_seq body)
1361 : : {
1362 : 545 : gtransaction *p
1363 : 545 : = as_a <gtransaction *> (gimple_alloc (GIMPLE_TRANSACTION, 0));
1364 : 545 : gimple_transaction_set_body (p, body);
1365 : 545 : gimple_transaction_set_label_norm (p, 0);
1366 : 545 : gimple_transaction_set_label_uninst (p, 0);
1367 : 545 : gimple_transaction_set_label_over (p, 0);
1368 : 545 : return p;
1369 : : }
1370 : :
1371 : : #if defined ENABLE_GIMPLE_CHECKING
1372 : : /* Complain of a gimple type mismatch and die. */
1373 : :
1374 : : void
1375 : 0 : gimple_check_failed (const gimple *gs, const char *file, int line,
1376 : : const char *function, enum gimple_code code,
1377 : : enum tree_code subcode)
1378 : : {
1379 : 0 : internal_error ("gimple check: expected %s(%s), have %s(%s) in %s, at %s:%d",
1380 : 0 : gimple_code_name[code],
1381 : : get_tree_code_name (subcode),
1382 : 0 : gimple_code_name[gimple_code (gs)],
1383 : 0 : gs->subcode > 0
1384 : 0 : ? get_tree_code_name ((enum tree_code) gs->subcode)
1385 : : : "",
1386 : : function, trim_filename (file), line);
1387 : : }
1388 : : #endif /* ENABLE_GIMPLE_CHECKING */
1389 : :
1390 : :
1391 : : /* Link gimple statement GS to the end of the sequence *SEQ_P. If
1392 : : *SEQ_P is NULL, a new sequence is allocated. */
1393 : :
1394 : : void
1395 : 41575913 : gimple_seq_add_stmt (gimple_seq *seq_p, gimple *gs)
1396 : : {
1397 : 41575913 : gimple_stmt_iterator si;
1398 : 41575913 : if (gs == NULL)
1399 : 0 : return;
1400 : :
1401 : 41575913 : si = gsi_last (*seq_p);
1402 : 41575913 : gsi_insert_after (&si, gs, GSI_NEW_STMT);
1403 : : }
1404 : :
1405 : : /* Link gimple statement GS to the end of the sequence *SEQ_P. If
1406 : : *SEQ_P is NULL, a new sequence is allocated. This function is
1407 : : similar to gimple_seq_add_stmt, but does not scan the operands.
1408 : : During gimplification, we need to manipulate statement sequences
1409 : : before the def/use vectors have been constructed. */
1410 : :
1411 : : void
1412 : 160681838 : gimple_seq_add_stmt_without_update (gimple_seq *seq_p, gimple *gs)
1413 : : {
1414 : 160681838 : gimple_stmt_iterator si;
1415 : :
1416 : 160681838 : if (gs == NULL)
1417 : 0 : return;
1418 : :
1419 : 160681838 : si = gsi_last (*seq_p);
1420 : 160681838 : gsi_insert_after_without_update (&si, gs, GSI_NEW_STMT);
1421 : : }
1422 : :
1423 : : /* Append sequence SRC to the end of sequence *DST_P. If *DST_P is
1424 : : NULL, a new sequence is allocated. */
1425 : :
1426 : : void
1427 : 14899924 : gimple_seq_add_seq (gimple_seq *dst_p, gimple_seq src)
1428 : : {
1429 : 14899924 : gimple_stmt_iterator si;
1430 : 14899924 : if (src == NULL)
1431 : 4284475 : return;
1432 : :
1433 : 10615449 : si = gsi_last (*dst_p);
1434 : 10615449 : gsi_insert_seq_after (&si, src, GSI_NEW_STMT);
1435 : : }
1436 : :
1437 : : /* Append sequence SRC to the end of sequence *DST_P. If *DST_P is
1438 : : NULL, a new sequence is allocated. This function is
1439 : : similar to gimple_seq_add_seq, but does not scan the operands. */
1440 : :
1441 : : void
1442 : 238928 : gimple_seq_add_seq_without_update (gimple_seq *dst_p, gimple_seq src)
1443 : : {
1444 : 238928 : gimple_stmt_iterator si;
1445 : 238928 : if (src == NULL)
1446 : 82362 : return;
1447 : :
1448 : 156566 : si = gsi_last (*dst_p);
1449 : 156566 : gsi_insert_seq_after_without_update (&si, src, GSI_NEW_STMT);
1450 : : }
1451 : :
1452 : : /* Determine whether to assign a location to the statement GS. */
1453 : :
1454 : : static bool
1455 : 263839751 : should_carry_location_p (gimple *gs)
1456 : : {
1457 : : /* Don't emit a line note for a label. We particularly don't want to
1458 : : emit one for the break label, since it doesn't actually correspond
1459 : : to the beginning of the loop/switch. */
1460 : 263839751 : if (gimple_code (gs) == GIMPLE_LABEL)
1461 : 0 : return false;
1462 : :
1463 : : return true;
1464 : : }
1465 : :
1466 : : /* Set the location for gimple statement GS to LOCATION. */
1467 : :
1468 : : static void
1469 : 662435844 : annotate_one_with_location (gimple *gs, location_t location)
1470 : : {
1471 : 662435844 : if (!gimple_has_location (gs)
1472 : 332980555 : && !gimple_do_not_emit_location_p (gs)
1473 : 662435844 : && should_carry_location_p (gs))
1474 : 24386822 : gimple_set_location (gs, location);
1475 : 662435844 : }
1476 : :
1477 : : /* Set LOCATION for all the statements after iterator GSI in sequence
1478 : : SEQ. If GSI is pointing to the end of the sequence, start with the
1479 : : first statement in SEQ. */
1480 : :
1481 : : void
1482 : 94568364 : annotate_all_with_location_after (gimple_seq seq, gimple_stmt_iterator gsi,
1483 : : location_t location)
1484 : : {
1485 : 94568364 : if (gsi_end_p (gsi))
1486 : 32458801 : gsi = gsi_start (seq);
1487 : : else
1488 : 62109563 : gsi_next (&gsi);
1489 : :
1490 : 756740504 : for (; !gsi_end_p (gsi); gsi_next (&gsi))
1491 : 662172140 : annotate_one_with_location (gsi_stmt (gsi), location);
1492 : 94568364 : }
1493 : :
1494 : : /* Set the location for all the statements in a sequence STMT_P to LOCATION. */
1495 : :
1496 : : void
1497 : 173379 : annotate_all_with_location (gimple_seq stmt_p, location_t location)
1498 : : {
1499 : 173379 : gimple_stmt_iterator i;
1500 : :
1501 : 173379 : if (gimple_seq_empty_p (stmt_p))
1502 : 173379 : return;
1503 : :
1504 : 430028 : for (i = gsi_start (stmt_p); !gsi_end_p (i); gsi_next (&i))
1505 : : {
1506 : 263704 : gimple *gs = gsi_stmt (i);
1507 : 263704 : annotate_one_with_location (gs, location);
1508 : : }
1509 : : }
1510 : :
1511 : : /* Helper function of empty_body_p. Return true if STMT is an empty
1512 : : statement. */
1513 : :
1514 : : static bool
1515 : 36419 : empty_stmt_p (gimple *stmt)
1516 : : {
1517 : 36419 : if (gimple_code (stmt) == GIMPLE_NOP)
1518 : : return true;
1519 : 36417 : if (gbind *bind_stmt = dyn_cast <gbind *> (stmt))
1520 : 21514 : return empty_body_p (gimple_bind_body (bind_stmt));
1521 : : return false;
1522 : : }
1523 : :
1524 : :
1525 : : /* Return true if BODY contains nothing but empty statements. */
1526 : :
1527 : : bool
1528 : 36492 : empty_body_p (gimple_seq body)
1529 : : {
1530 : 36492 : gimple_stmt_iterator i;
1531 : :
1532 : 36492 : if (gimple_seq_empty_p (body))
1533 : : return true;
1534 : 36596 : for (i = gsi_start (body); !gsi_end_p (i); gsi_next (&i))
1535 : 36419 : if (!empty_stmt_p (gsi_stmt (i))
1536 : 36419 : && !is_gimple_debug (gsi_stmt (i)))
1537 : : return false;
1538 : :
1539 : : return true;
1540 : : }
1541 : :
1542 : :
1543 : : /* Perform a deep copy of sequence SRC and return the result. */
1544 : :
1545 : : gimple_seq
1546 : 1647899 : gimple_seq_copy (gimple_seq src)
1547 : : {
1548 : 1647899 : gimple_stmt_iterator gsi;
1549 : 1647899 : gimple_seq new_seq = NULL;
1550 : 1647899 : gimple *stmt;
1551 : :
1552 : 3704760 : for (gsi = gsi_start (src); !gsi_end_p (gsi); gsi_next (&gsi))
1553 : : {
1554 : 2056861 : stmt = gimple_copy (gsi_stmt (gsi));
1555 : 2056861 : gimple_seq_add_stmt (&new_seq, stmt);
1556 : : }
1557 : :
1558 : 1647899 : return new_seq;
1559 : : }
1560 : :
1561 : :
1562 : :
1563 : : /* Return true if calls C1 and C2 are known to go to the same function. */
1564 : :
1565 : : bool
1566 : 928018 : gimple_call_same_target_p (const gimple *c1, const gimple *c2)
1567 : : {
1568 : 928018 : if (gimple_call_internal_p (c1))
1569 : 378 : return (gimple_call_internal_p (c2)
1570 : 378 : && gimple_call_internal_fn (c1) == gimple_call_internal_fn (c2)
1571 : 756 : && (!gimple_call_internal_unique_p (as_a <const gcall *> (c1))
1572 : 0 : || c1 == c2));
1573 : : else
1574 : 927640 : return (gimple_call_fn (c1) == gimple_call_fn (c2)
1575 : 927640 : || (gimple_call_fndecl (c1)
1576 : 927217 : && gimple_call_fndecl (c1) == gimple_call_fndecl (c2)));
1577 : : }
1578 : :
1579 : : /* Detect flags from a GIMPLE_CALL. This is just like
1580 : : call_expr_flags, but for gimple tuples. */
1581 : :
1582 : : int
1583 : 3930781973 : gimple_call_flags (const gimple *stmt)
1584 : : {
1585 : 3930781973 : int flags = 0;
1586 : :
1587 : 3930781973 : if (gimple_call_internal_p (stmt))
1588 : 80112361 : flags = internal_fn_flags (gimple_call_internal_fn (stmt));
1589 : : else
1590 : : {
1591 : 3850669612 : tree decl = gimple_call_fndecl (stmt);
1592 : 3850669612 : if (decl)
1593 : 3729259009 : flags = flags_from_decl_or_type (decl);
1594 : 3850669612 : flags |= flags_from_decl_or_type (gimple_call_fntype (stmt));
1595 : : }
1596 : :
1597 : 3930781973 : if (stmt->subcode & GF_CALL_NOTHROW)
1598 : 640322696 : flags |= ECF_NOTHROW;
1599 : 3930781973 : if (stmt->subcode & GF_CALL_XTHROW)
1600 : 10141424 : flags |= ECF_XTHROW;
1601 : :
1602 : 3930781973 : if (stmt->subcode & GF_CALL_BY_DESCRIPTOR)
1603 : 0 : flags |= ECF_BY_DESCRIPTOR;
1604 : :
1605 : 3930781973 : return flags;
1606 : : }
1607 : :
1608 : : /* Return the "fn spec" string for call STMT. */
1609 : :
1610 : : attr_fnspec
1611 : 386037588 : gimple_call_fnspec (const gcall *stmt)
1612 : : {
1613 : 386037588 : tree type, attr;
1614 : :
1615 : 386037588 : if (gimple_call_internal_p (stmt))
1616 : : {
1617 : 7269218 : const_tree spec = internal_fn_fnspec (gimple_call_internal_fn (stmt));
1618 : 7269218 : if (spec)
1619 : 298227 : return spec;
1620 : : else
1621 : 6970991 : return "";
1622 : : }
1623 : :
1624 : 378768370 : type = gimple_call_fntype (stmt);
1625 : 378768370 : if (type)
1626 : : {
1627 : 378768370 : attr = lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type));
1628 : 378768370 : if (attr)
1629 : 54520101 : return TREE_VALUE (TREE_VALUE (attr));
1630 : : }
1631 : 324248269 : if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
1632 : 99968848 : return builtin_fnspec (gimple_call_fndecl (stmt));
1633 : 224279421 : tree fndecl = gimple_call_fndecl (stmt);
1634 : : /* If the call is to a replaceable operator delete and results
1635 : : from a delete expression as opposed to a direct call to
1636 : : such operator, then we can treat it as free. */
1637 : 224279421 : if (fndecl
1638 : 211587649 : && DECL_IS_OPERATOR_DELETE_P (fndecl)
1639 : 5133893 : && DECL_IS_REPLACEABLE_OPERATOR (fndecl)
1640 : 229410633 : && gimple_call_from_new_or_delete (stmt))
1641 : : {
1642 : 5061618 : if (flag_assume_sane_operators_new_delete)
1643 : 5060718 : return ".co ";
1644 : : else
1645 : 900 : return ". o ";
1646 : : }
1647 : : /* Similarly operator new can be treated as malloc. */
1648 : 219217803 : if (fndecl
1649 : 206526031 : && DECL_IS_REPLACEABLE_OPERATOR_NEW_P (fndecl)
1650 : 220872621 : && gimple_call_from_new_or_delete (stmt))
1651 : : {
1652 : 1609967 : if (flag_assume_sane_operators_new_delete)
1653 : 1609249 : return "mC";
1654 : : else
1655 : 718 : return "m ";
1656 : : }
1657 : 217607836 : return "";
1658 : : }
1659 : :
1660 : : /* Detects argument flags for argument number ARG on call STMT. */
1661 : :
1662 : : int
1663 : 100629371 : gimple_call_arg_flags (const gcall *stmt, unsigned arg)
1664 : : {
1665 : 100629371 : attr_fnspec fnspec = gimple_call_fnspec (stmt);
1666 : 100629371 : int flags = 0;
1667 : :
1668 : 100629371 : if (fnspec.known_p ())
1669 : 19475652 : flags = fnspec.arg_eaf_flags (arg);
1670 : 100629371 : tree callee = gimple_call_fndecl (stmt);
1671 : 100629371 : if (callee)
1672 : : {
1673 : 94666925 : cgraph_node *node = cgraph_node::get (callee);
1674 : 94666925 : modref_summary *summary = node ? get_modref_function_summary (node)
1675 : 195110733 : : NULL;
1676 : :
1677 : 94481362 : if (summary && summary->arg_flags.length () > arg)
1678 : : {
1679 : 17543490 : int modref_flags = summary->arg_flags[arg];
1680 : :
1681 : : /* We have possibly optimized out load. Be conservative here. */
1682 : 17543490 : if (!node->binds_to_current_def_p ())
1683 : 7400334 : modref_flags = interposable_eaf_flags (modref_flags, flags);
1684 : 17543490 : if (dbg_cnt (ipa_mod_ref_pta))
1685 : 17543490 : flags |= modref_flags;
1686 : : }
1687 : : }
1688 : 100629371 : return flags;
1689 : : }
1690 : :
1691 : : /* Detects argument flags for return slot on call STMT. */
1692 : :
1693 : : int
1694 : 91699 : gimple_call_retslot_flags (const gcall *stmt)
1695 : : {
1696 : 91699 : int flags = implicit_retslot_eaf_flags;
1697 : :
1698 : 91699 : tree callee = gimple_call_fndecl (stmt);
1699 : 91699 : if (callee)
1700 : : {
1701 : 80922 : cgraph_node *node = cgraph_node::get (callee);
1702 : 80922 : modref_summary *summary = node ? get_modref_function_summary (node)
1703 : 172621 : : NULL;
1704 : :
1705 : 80922 : if (summary)
1706 : : {
1707 : 47854 : int modref_flags = summary->retslot_flags;
1708 : :
1709 : : /* We have possibly optimized out load. Be conservative here. */
1710 : 47854 : if (!node->binds_to_current_def_p ())
1711 : 41117 : modref_flags = interposable_eaf_flags (modref_flags, flags);
1712 : 47854 : if (dbg_cnt (ipa_mod_ref_pta))
1713 : 47854 : flags |= modref_flags;
1714 : : }
1715 : : }
1716 : 91699 : return flags;
1717 : : }
1718 : :
1719 : : /* Detects argument flags for static chain on call STMT. */
1720 : :
1721 : : int
1722 : 180257 : gimple_call_static_chain_flags (const gcall *stmt)
1723 : : {
1724 : 180257 : int flags = 0;
1725 : :
1726 : 180257 : tree callee = gimple_call_fndecl (stmt);
1727 : 180257 : if (callee)
1728 : : {
1729 : 27904 : cgraph_node *node = cgraph_node::get (callee);
1730 : 27904 : modref_summary *summary = node ? get_modref_function_summary (node)
1731 : 27904 : : NULL;
1732 : :
1733 : : /* Nested functions should always bind to current def since
1734 : : there is no public ABI for them. */
1735 : 27904 : gcc_checking_assert (node->binds_to_current_def_p ());
1736 : 27904 : if (summary)
1737 : : {
1738 : 26159 : int modref_flags = summary->static_chain_flags;
1739 : :
1740 : 26159 : if (dbg_cnt (ipa_mod_ref_pta))
1741 : 180257 : flags |= modref_flags;
1742 : : }
1743 : : }
1744 : 180257 : return flags;
1745 : : }
1746 : :
1747 : : /* Detects return flags for the call STMT. */
1748 : :
1749 : : int
1750 : 45183950 : gimple_call_return_flags (const gcall *stmt)
1751 : : {
1752 : 45183950 : if (gimple_call_flags (stmt) & ECF_MALLOC)
1753 : : return ERF_NOALIAS;
1754 : :
1755 : 43703625 : attr_fnspec fnspec = gimple_call_fnspec (stmt);
1756 : :
1757 : 43703625 : unsigned int arg_no;
1758 : 43703625 : if (fnspec.returns_arg (&arg_no))
1759 : 906086 : return ERF_RETURNS_ARG | arg_no;
1760 : :
1761 : 42797539 : if (fnspec.returns_noalias_p ())
1762 : : return ERF_NOALIAS;
1763 : : return 0;
1764 : : }
1765 : :
1766 : :
1767 : : /* Return true if call STMT is known to return a non-zero result. */
1768 : :
1769 : : bool
1770 : 11898107 : gimple_call_nonnull_result_p (gcall *call)
1771 : : {
1772 : 11898107 : tree fndecl = gimple_call_fndecl (call);
1773 : 11898107 : if (!fndecl)
1774 : : return false;
1775 : 10988534 : if (flag_delete_null_pointer_checks && !flag_check_new
1776 : 10988485 : && DECL_IS_OPERATOR_NEW_P (fndecl)
1777 : 11285818 : && !TREE_NOTHROW (fndecl))
1778 : : return true;
1779 : :
1780 : : /* References are always non-NULL. */
1781 : 10705946 : if (flag_delete_null_pointer_checks
1782 : 10705946 : && TREE_CODE (TREE_TYPE (fndecl)) == REFERENCE_TYPE)
1783 : : return true;
1784 : :
1785 : 10705946 : if (flag_delete_null_pointer_checks
1786 : 21405667 : && lookup_attribute ("returns_nonnull",
1787 : 10699721 : TYPE_ATTRIBUTES (gimple_call_fntype (call))))
1788 : : return true;
1789 : 10643182 : return gimple_alloca_call_p (call);
1790 : : }
1791 : :
1792 : :
1793 : : /* If CALL returns a non-null result in an argument, return that arg. */
1794 : :
1795 : : tree
1796 : 11485421 : gimple_call_nonnull_arg (gcall *call)
1797 : : {
1798 : 11485421 : tree fndecl = gimple_call_fndecl (call);
1799 : 11485421 : if (!fndecl)
1800 : : return NULL_TREE;
1801 : :
1802 : 10582073 : unsigned rf = gimple_call_return_flags (call);
1803 : 10582073 : if (rf & ERF_RETURNS_ARG)
1804 : : {
1805 : 0 : unsigned argnum = rf & ERF_RETURN_ARG_MASK;
1806 : 0 : if (argnum < gimple_call_num_args (call))
1807 : : {
1808 : 0 : tree arg = gimple_call_arg (call, argnum);
1809 : 0 : if (SSA_VAR_P (arg)
1810 : 0 : && infer_nonnull_range_by_attribute (call, arg))
1811 : : return arg;
1812 : : }
1813 : : }
1814 : : return NULL_TREE;
1815 : : }
1816 : :
1817 : :
1818 : : /* Return true if GS is a copy assignment. */
1819 : :
1820 : : bool
1821 : 185071989 : gimple_assign_copy_p (gimple *gs)
1822 : : {
1823 : 185071989 : return (gimple_assign_single_p (gs)
1824 : 185071989 : && is_gimple_val (gimple_op (gs, 1)));
1825 : : }
1826 : :
1827 : :
1828 : : /* Return true if GS is a SSA_NAME copy assignment. */
1829 : :
1830 : : bool
1831 : 38004704 : gimple_assign_ssa_name_copy_p (gimple *gs)
1832 : : {
1833 : 38004704 : return (gimple_assign_single_p (gs)
1834 : 21571759 : && TREE_CODE (gimple_assign_lhs (gs)) == SSA_NAME
1835 : 50601607 : && TREE_CODE (gimple_assign_rhs1 (gs)) == SSA_NAME);
1836 : : }
1837 : :
1838 : :
1839 : : /* Return true if GS is an assignment with a unary RHS, but the
1840 : : operator has no effect on the assigned value. The logic is adapted
1841 : : from STRIP_NOPS. This predicate is intended to be used in tuplifying
1842 : : instances in which STRIP_NOPS was previously applied to the RHS of
1843 : : an assignment.
1844 : :
1845 : : NOTE: In the use cases that led to the creation of this function
1846 : : and of gimple_assign_single_p, it is typical to test for either
1847 : : condition and to proceed in the same manner. In each case, the
1848 : : assigned value is represented by the single RHS operand of the
1849 : : assignment. I suspect there may be cases where gimple_assign_copy_p,
1850 : : gimple_assign_single_p, or equivalent logic is used where a similar
1851 : : treatment of unary NOPs is appropriate. */
1852 : :
1853 : : bool
1854 : 54467 : gimple_assign_unary_nop_p (gimple *gs)
1855 : : {
1856 : 54467 : return (is_gimple_assign (gs)
1857 : 54467 : && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs))
1858 : 45638 : || gimple_assign_rhs_code (gs) == NON_LVALUE_EXPR)
1859 : 8829 : && gimple_assign_rhs1 (gs) != error_mark_node
1860 : 72125 : && (TYPE_MODE (TREE_TYPE (gimple_assign_lhs (gs)))
1861 : 8829 : == TYPE_MODE (TREE_TYPE (gimple_assign_rhs1 (gs)))));
1862 : : }
1863 : :
1864 : : /* Return true if GS is an assignment that loads from its rhs1. */
1865 : :
1866 : : bool
1867 : 706351780 : gimple_assign_load_p (const gimple *gs)
1868 : : {
1869 : 706351780 : tree rhs;
1870 : 706351780 : if (!gimple_assign_single_p (gs))
1871 : : return false;
1872 : 418279348 : rhs = gimple_assign_rhs1 (gs);
1873 : 418279348 : if (TREE_CODE (rhs) == WITH_SIZE_EXPR)
1874 : : return true;
1875 : 418279343 : if (handled_component_p (rhs))
1876 : 123382120 : rhs = TREE_OPERAND (rhs, 0);
1877 : 418279343 : return (handled_component_p (rhs)
1878 : 382603461 : || DECL_P (rhs)
1879 : 302986630 : || TREE_CODE (rhs) == MEM_REF
1880 : 218374354 : || TREE_CODE (rhs) == TARGET_MEM_REF);
1881 : : }
1882 : :
1883 : :
1884 : : /* Set BB to be the basic block holding G. */
1885 : :
1886 : : void
1887 : 614366303 : gimple_set_bb (gimple *stmt, basic_block bb)
1888 : : {
1889 : 614366303 : stmt->bb = bb;
1890 : :
1891 : 614366303 : if (gimple_code (stmt) != GIMPLE_LABEL)
1892 : : return;
1893 : :
1894 : : /* If the statement is a label, add the label to block-to-labels map
1895 : : so that we can speed up edge creation for GIMPLE_GOTOs. */
1896 : 36378083 : if (cfun->cfg)
1897 : : {
1898 : 36377863 : tree t;
1899 : 36377863 : int uid;
1900 : :
1901 : 36377863 : t = gimple_label_label (as_a <glabel *> (stmt));
1902 : 36377863 : uid = LABEL_DECL_UID (t);
1903 : 36377863 : if (uid == -1)
1904 : : {
1905 : 18556222 : unsigned old_len =
1906 : 18556222 : vec_safe_length (label_to_block_map_for_fn (cfun));
1907 : 18556222 : LABEL_DECL_UID (t) = uid = cfun->cfg->last_label_uid++;
1908 : 18556222 : if (old_len <= (unsigned) uid)
1909 : 9052434 : vec_safe_grow_cleared (label_to_block_map_for_fn (cfun), uid + 1);
1910 : : }
1911 : :
1912 : 36377863 : (*label_to_block_map_for_fn (cfun))[uid] = bb;
1913 : : }
1914 : : }
1915 : :
1916 : :
1917 : : /* Modify the RHS of the assignment pointed-to by GSI using the
1918 : : operands in the expression tree EXPR.
1919 : :
1920 : : NOTE: The statement pointed-to by GSI may be reallocated if it
1921 : : did not have enough operand slots.
1922 : :
1923 : : This function is useful to convert an existing tree expression into
1924 : : the flat representation used for the RHS of a GIMPLE assignment.
1925 : : It will reallocate memory as needed to expand or shrink the number
1926 : : of operand slots needed to represent EXPR.
1927 : :
1928 : : NOTE: If you find yourself building a tree and then calling this
1929 : : function, you are most certainly doing it the slow way. It is much
1930 : : better to build a new assignment or to use the function
1931 : : gimple_assign_set_rhs_with_ops, which does not require an
1932 : : expression tree to be built. */
1933 : :
1934 : : void
1935 : 4051917 : gimple_assign_set_rhs_from_tree (gimple_stmt_iterator *gsi, tree expr)
1936 : : {
1937 : 4051917 : enum tree_code subcode;
1938 : 4051917 : tree op1, op2, op3;
1939 : :
1940 : 4051917 : extract_ops_from_tree (expr, &subcode, &op1, &op2, &op3);
1941 : 4051917 : gimple_assign_set_rhs_with_ops (gsi, subcode, op1, op2, op3);
1942 : 4051917 : }
1943 : :
1944 : :
1945 : : /* Set the RHS of assignment statement pointed-to by GSI to CODE with
1946 : : operands OP1, OP2 and OP3.
1947 : :
1948 : : NOTE: The statement pointed-to by GSI may be reallocated if it
1949 : : did not have enough operand slots. */
1950 : :
1951 : : void
1952 : 6326999 : gimple_assign_set_rhs_with_ops (gimple_stmt_iterator *gsi, enum tree_code code,
1953 : : tree op1, tree op2, tree op3)
1954 : : {
1955 : 6326999 : unsigned new_rhs_ops = get_gimple_rhs_num_ops (code);
1956 : 6326999 : gimple *stmt = gsi_stmt (*gsi);
1957 : 6326999 : gimple *old_stmt = stmt;
1958 : :
1959 : : /* If the new CODE needs more operands, allocate a new statement. */
1960 : 6326999 : if (gimple_num_ops (stmt) < new_rhs_ops + 1)
1961 : : {
1962 : 159972 : tree lhs = gimple_assign_lhs (old_stmt);
1963 : 159972 : stmt = gimple_alloc (gimple_code (old_stmt), new_rhs_ops + 1);
1964 : 159972 : memcpy (stmt, old_stmt, gimple_size (gimple_code (old_stmt)));
1965 : 159972 : gimple_init_singleton (stmt);
1966 : :
1967 : : /* The LHS needs to be reset as this also changes the SSA name
1968 : : on the LHS. */
1969 : 159972 : gimple_assign_set_lhs (stmt, lhs);
1970 : : }
1971 : :
1972 : 6326999 : gimple_set_num_ops (stmt, new_rhs_ops + 1);
1973 : 6326999 : gimple_set_subcode (stmt, code);
1974 : 6326999 : gimple_assign_set_rhs1 (stmt, op1);
1975 : 6326999 : if (new_rhs_ops > 1)
1976 : 950364 : gimple_assign_set_rhs2 (stmt, op2);
1977 : 950364 : if (new_rhs_ops > 2)
1978 : 32717 : gimple_assign_set_rhs3 (stmt, op3);
1979 : 6326999 : if (stmt != old_stmt)
1980 : 159972 : gsi_replace (gsi, stmt, false);
1981 : 6326999 : }
1982 : :
1983 : :
1984 : : /* Return the LHS of a statement that performs an assignment,
1985 : : either a GIMPLE_ASSIGN or a GIMPLE_CALL. Returns NULL_TREE
1986 : : for a call to a function that returns no value, or for a
1987 : : statement other than an assignment or a call. */
1988 : :
1989 : : tree
1990 : 5954226759 : gimple_get_lhs (const gimple *stmt)
1991 : : {
1992 : 5954226759 : enum gimple_code code = gimple_code (stmt);
1993 : :
1994 : 5954226759 : if (code == GIMPLE_ASSIGN)
1995 : 3908897761 : return gimple_assign_lhs (stmt);
1996 : 2045328998 : else if (code == GIMPLE_CALL)
1997 : 442283915 : return gimple_call_lhs (stmt);
1998 : 1603045083 : else if (code == GIMPLE_PHI)
1999 : 130064151 : return gimple_phi_result (stmt);
2000 : : else
2001 : : return NULL_TREE;
2002 : : }
2003 : :
2004 : :
2005 : : /* Set the LHS of a statement that performs an assignment,
2006 : : either a GIMPLE_ASSIGN or a GIMPLE_CALL. */
2007 : :
2008 : : void
2009 : 2066381 : gimple_set_lhs (gimple *stmt, tree lhs)
2010 : : {
2011 : 2066381 : enum gimple_code code = gimple_code (stmt);
2012 : :
2013 : 2066381 : if (code == GIMPLE_ASSIGN)
2014 : 1004462 : gimple_assign_set_lhs (stmt, lhs);
2015 : 1061919 : else if (code == GIMPLE_CALL)
2016 : 1061919 : gimple_call_set_lhs (stmt, lhs);
2017 : : else
2018 : 0 : gcc_unreachable ();
2019 : 2066381 : }
2020 : :
2021 : :
2022 : : /* Return a deep copy of statement STMT. All the operands from STMT
2023 : : are reallocated and copied using unshare_expr. The DEF, USE, VDEF
2024 : : and VUSE operand arrays are set to empty in the new copy. The new
2025 : : copy isn't part of any sequence. */
2026 : :
2027 : : gimple *
2028 : 55326171 : gimple_copy (gimple *stmt)
2029 : : {
2030 : 55326171 : enum gimple_code code = gimple_code (stmt);
2031 : 55326171 : unsigned num_ops = gimple_num_ops (stmt);
2032 : 55326171 : gimple *copy = gimple_alloc (code, num_ops);
2033 : 55326171 : unsigned i;
2034 : :
2035 : : /* Shallow copy all the fields from STMT. */
2036 : 55326171 : memcpy (copy, stmt, gimple_size (code));
2037 : 55326171 : gimple_init_singleton (copy);
2038 : :
2039 : : /* If STMT has sub-statements, deep-copy them as well. */
2040 : 55326171 : if (gimple_has_substatements (stmt))
2041 : : {
2042 : 42318 : gimple_seq new_seq;
2043 : 42318 : tree t;
2044 : :
2045 : 42318 : switch (gimple_code (stmt))
2046 : : {
2047 : 349 : case GIMPLE_BIND:
2048 : 349 : {
2049 : 349 : gbind *bind_stmt = as_a <gbind *> (stmt);
2050 : 349 : gbind *bind_copy = as_a <gbind *> (copy);
2051 : 349 : new_seq = gimple_seq_copy (gimple_bind_body (bind_stmt));
2052 : 349 : gimple_bind_set_body (bind_copy, new_seq);
2053 : 349 : gimple_bind_set_vars (bind_copy,
2054 : : unshare_expr (gimple_bind_vars (bind_stmt)));
2055 : 349 : gimple_bind_set_block (bind_copy, gimple_bind_block (bind_stmt));
2056 : : }
2057 : 349 : break;
2058 : :
2059 : 17498 : case GIMPLE_CATCH:
2060 : 17498 : {
2061 : 17498 : gcatch *catch_stmt = as_a <gcatch *> (stmt);
2062 : 17498 : gcatch *catch_copy = as_a <gcatch *> (copy);
2063 : 17498 : new_seq = gimple_seq_copy (gimple_catch_handler (catch_stmt));
2064 : 17498 : gimple_catch_set_handler (catch_copy, new_seq);
2065 : 17498 : t = unshare_expr (gimple_catch_types (catch_stmt));
2066 : 17498 : gimple_catch_set_types (catch_copy, t);
2067 : : }
2068 : 17498 : break;
2069 : :
2070 : 0 : case GIMPLE_EH_FILTER:
2071 : 0 : {
2072 : 0 : geh_filter *eh_filter_stmt = as_a <geh_filter *> (stmt);
2073 : 0 : geh_filter *eh_filter_copy = as_a <geh_filter *> (copy);
2074 : 0 : new_seq
2075 : 0 : = gimple_seq_copy (gimple_eh_filter_failure (eh_filter_stmt));
2076 : 0 : gimple_eh_filter_set_failure (eh_filter_copy, new_seq);
2077 : 0 : t = unshare_expr (gimple_eh_filter_types (eh_filter_stmt));
2078 : 0 : gimple_eh_filter_set_types (eh_filter_copy, t);
2079 : : }
2080 : 0 : break;
2081 : :
2082 : 273 : case GIMPLE_EH_ELSE:
2083 : 273 : {
2084 : 273 : geh_else *eh_else_stmt = as_a <geh_else *> (stmt);
2085 : 273 : geh_else *eh_else_copy = as_a <geh_else *> (copy);
2086 : 273 : new_seq = gimple_seq_copy (gimple_eh_else_n_body (eh_else_stmt));
2087 : 273 : gimple_eh_else_set_n_body (eh_else_copy, new_seq);
2088 : 273 : new_seq = gimple_seq_copy (gimple_eh_else_e_body (eh_else_stmt));
2089 : 273 : gimple_eh_else_set_e_body (eh_else_copy, new_seq);
2090 : : }
2091 : 273 : break;
2092 : :
2093 : 23936 : case GIMPLE_TRY:
2094 : 23936 : {
2095 : 23936 : gtry *try_stmt = as_a <gtry *> (stmt);
2096 : 23936 : gtry *try_copy = as_a <gtry *> (copy);
2097 : 23936 : new_seq = gimple_seq_copy (gimple_try_eval (try_stmt));
2098 : 23936 : gimple_try_set_eval (try_copy, new_seq);
2099 : 23936 : new_seq = gimple_seq_copy (gimple_try_cleanup (try_stmt));
2100 : 23936 : gimple_try_set_cleanup (try_copy, new_seq);
2101 : : }
2102 : 23936 : break;
2103 : :
2104 : 256 : case GIMPLE_OMP_FOR:
2105 : 256 : new_seq = gimple_seq_copy (gimple_omp_for_pre_body (stmt));
2106 : 256 : gimple_omp_for_set_pre_body (copy, new_seq);
2107 : 256 : t = unshare_expr (gimple_omp_for_clauses (stmt));
2108 : 256 : gimple_omp_for_set_clauses (copy, t);
2109 : 256 : {
2110 : 256 : gomp_for *omp_for_copy = as_a <gomp_for *> (copy);
2111 : 256 : omp_for_copy->iter = ggc_vec_alloc<gimple_omp_for_iter>
2112 : 256 : ( gimple_omp_for_collapse (stmt));
2113 : : }
2114 : 524 : for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
2115 : : {
2116 : 268 : gimple_omp_for_set_cond (copy, i,
2117 : : gimple_omp_for_cond (stmt, i));
2118 : 268 : gimple_omp_for_set_index (copy, i,
2119 : : gimple_omp_for_index (stmt, i));
2120 : 268 : t = unshare_expr (gimple_omp_for_initial (stmt, i));
2121 : 268 : gimple_omp_for_set_initial (copy, i, t);
2122 : 268 : t = unshare_expr (gimple_omp_for_final (stmt, i));
2123 : 268 : gimple_omp_for_set_final (copy, i, t);
2124 : 268 : t = unshare_expr (gimple_omp_for_incr (stmt, i));
2125 : 268 : gimple_omp_for_set_incr (copy, i, t);
2126 : : }
2127 : 256 : goto copy_omp_body;
2128 : :
2129 : 0 : case GIMPLE_OMP_PARALLEL:
2130 : 0 : {
2131 : 0 : gomp_parallel *omp_par_stmt = as_a <gomp_parallel *> (stmt);
2132 : 0 : gomp_parallel *omp_par_copy = as_a <gomp_parallel *> (copy);
2133 : 0 : t = unshare_expr (gimple_omp_parallel_clauses (omp_par_stmt));
2134 : 0 : gimple_omp_parallel_set_clauses (omp_par_copy, t);
2135 : 0 : t = unshare_expr (gimple_omp_parallel_child_fn (omp_par_stmt));
2136 : 0 : gimple_omp_parallel_set_child_fn (omp_par_copy, t);
2137 : 0 : t = unshare_expr (gimple_omp_parallel_data_arg (omp_par_stmt));
2138 : 0 : gimple_omp_parallel_set_data_arg (omp_par_copy, t);
2139 : : }
2140 : 0 : goto copy_omp_body;
2141 : :
2142 : 0 : case GIMPLE_OMP_TASK:
2143 : 0 : t = unshare_expr (gimple_omp_task_clauses (stmt));
2144 : 0 : gimple_omp_task_set_clauses (copy, t);
2145 : 0 : t = unshare_expr (gimple_omp_task_child_fn (stmt));
2146 : 0 : gimple_omp_task_set_child_fn (copy, t);
2147 : 0 : t = unshare_expr (gimple_omp_task_data_arg (stmt));
2148 : 0 : gimple_omp_task_set_data_arg (copy, t);
2149 : 0 : t = unshare_expr (gimple_omp_task_copy_fn (stmt));
2150 : 0 : gimple_omp_task_set_copy_fn (copy, t);
2151 : 0 : t = unshare_expr (gimple_omp_task_arg_size (stmt));
2152 : 0 : gimple_omp_task_set_arg_size (copy, t);
2153 : 0 : t = unshare_expr (gimple_omp_task_arg_align (stmt));
2154 : 0 : gimple_omp_task_set_arg_align (copy, t);
2155 : 0 : goto copy_omp_body;
2156 : :
2157 : 0 : case GIMPLE_OMP_CRITICAL:
2158 : 0 : t = unshare_expr (gimple_omp_critical_name
2159 : 0 : (as_a <gomp_critical *> (stmt)));
2160 : 0 : gimple_omp_critical_set_name (as_a <gomp_critical *> (copy), t);
2161 : 0 : t = unshare_expr (gimple_omp_critical_clauses
2162 : 0 : (as_a <gomp_critical *> (stmt)));
2163 : 0 : gimple_omp_critical_set_clauses (as_a <gomp_critical *> (copy), t);
2164 : 0 : goto copy_omp_body;
2165 : :
2166 : 0 : case GIMPLE_OMP_ORDERED:
2167 : 0 : t = unshare_expr (gimple_omp_ordered_clauses
2168 : 0 : (as_a <gomp_ordered *> (stmt)));
2169 : 0 : gimple_omp_ordered_set_clauses (as_a <gomp_ordered *> (copy), t);
2170 : 0 : goto copy_omp_body;
2171 : :
2172 : 0 : case GIMPLE_OMP_SCAN:
2173 : 0 : t = gimple_omp_scan_clauses (as_a <gomp_scan *> (stmt));
2174 : 0 : t = unshare_expr (t);
2175 : 0 : gimple_omp_scan_set_clauses (as_a <gomp_scan *> (copy), t);
2176 : 0 : goto copy_omp_body;
2177 : :
2178 : 0 : case GIMPLE_OMP_TASKGROUP:
2179 : 0 : t = unshare_expr (gimple_omp_taskgroup_clauses (stmt));
2180 : 0 : gimple_omp_taskgroup_set_clauses (copy, t);
2181 : 0 : goto copy_omp_body;
2182 : :
2183 : 0 : case GIMPLE_OMP_SECTIONS:
2184 : 0 : t = unshare_expr (gimple_omp_sections_clauses (stmt));
2185 : 0 : gimple_omp_sections_set_clauses (copy, t);
2186 : 0 : t = unshare_expr (gimple_omp_sections_control (stmt));
2187 : 0 : gimple_omp_sections_set_control (copy, t);
2188 : 0 : goto copy_omp_body;
2189 : :
2190 : 0 : case GIMPLE_OMP_SINGLE:
2191 : 0 : {
2192 : 0 : gomp_single *omp_single_copy = as_a <gomp_single *> (copy);
2193 : 0 : t = unshare_expr (gimple_omp_single_clauses (stmt));
2194 : 0 : gimple_omp_single_set_clauses (omp_single_copy, t);
2195 : : }
2196 : 0 : goto copy_omp_body;
2197 : :
2198 : 0 : case GIMPLE_OMP_SCOPE:
2199 : 0 : t = unshare_expr (gimple_omp_scope_clauses (stmt));
2200 : 0 : gimple_omp_scope_set_clauses (copy, t);
2201 : 0 : goto copy_omp_body;
2202 : :
2203 : 0 : case GIMPLE_OMP_DISPATCH:
2204 : 0 : t = unshare_expr (gimple_omp_dispatch_clauses (stmt));
2205 : 0 : gimple_omp_dispatch_set_clauses (copy, t);
2206 : 0 : goto copy_omp_body;
2207 : :
2208 : 0 : case GIMPLE_OMP_TARGET:
2209 : 0 : {
2210 : 0 : gomp_target *omp_target_stmt = as_a <gomp_target *> (stmt);
2211 : 0 : gomp_target *omp_target_copy = as_a <gomp_target *> (copy);
2212 : 0 : t = unshare_expr (gimple_omp_target_clauses (omp_target_stmt));
2213 : 0 : gimple_omp_target_set_clauses (omp_target_copy, t);
2214 : 0 : t = unshare_expr (gimple_omp_target_data_arg (omp_target_stmt));
2215 : 0 : gimple_omp_target_set_data_arg (omp_target_copy, t);
2216 : : }
2217 : 0 : goto copy_omp_body;
2218 : :
2219 : 0 : case GIMPLE_OMP_TEAMS:
2220 : 0 : {
2221 : 0 : gomp_teams *omp_teams_copy = as_a <gomp_teams *> (copy);
2222 : 0 : t = unshare_expr (gimple_omp_teams_clauses (stmt));
2223 : 0 : gimple_omp_teams_set_clauses (omp_teams_copy, t);
2224 : : }
2225 : : /* FALLTHRU */
2226 : :
2227 : 256 : case GIMPLE_OMP_SECTION:
2228 : 256 : case GIMPLE_OMP_MASTER:
2229 : 256 : case GIMPLE_OMP_STRUCTURED_BLOCK:
2230 : 256 : copy_omp_body:
2231 : 256 : new_seq = gimple_seq_copy (gimple_omp_body (stmt));
2232 : 256 : gimple_omp_set_body (copy, new_seq);
2233 : 256 : break;
2234 : :
2235 : 0 : case GIMPLE_OMP_MASKED:
2236 : 0 : t = unshare_expr (gimple_omp_masked_clauses (stmt));
2237 : 0 : gimple_omp_masked_set_clauses (copy, t);
2238 : 0 : goto copy_omp_body;
2239 : :
2240 : 0 : case GIMPLE_ASSUME:
2241 : 0 : new_seq = gimple_seq_copy (gimple_assume_body (stmt));
2242 : 0 : *gimple_assume_body_ptr (copy) = new_seq;
2243 : 0 : gimple_assume_set_guard (copy,
2244 : : unshare_expr (gimple_assume_guard (stmt)));
2245 : 0 : break;
2246 : :
2247 : 6 : case GIMPLE_TRANSACTION:
2248 : 6 : new_seq = gimple_seq_copy (gimple_transaction_body (
2249 : 6 : as_a <gtransaction *> (stmt)));
2250 : 6 : gimple_transaction_set_body (as_a <gtransaction *> (copy),
2251 : : new_seq);
2252 : 6 : break;
2253 : :
2254 : 0 : case GIMPLE_WITH_CLEANUP_EXPR:
2255 : 0 : new_seq = gimple_seq_copy (gimple_wce_cleanup (stmt));
2256 : 0 : gimple_wce_set_cleanup (copy, new_seq);
2257 : 0 : break;
2258 : :
2259 : 0 : default:
2260 : 0 : gcc_unreachable ();
2261 : : }
2262 : : }
2263 : :
2264 : : /* Make copy of operands. */
2265 : 171177238 : for (i = 0; i < num_ops; i++)
2266 : 115851067 : gimple_set_op (copy, i, unshare_expr (gimple_op (stmt, i)));
2267 : :
2268 : 55326171 : if (gimple_has_mem_ops (stmt))
2269 : : {
2270 : 27608249 : gimple_set_vdef (copy, gimple_vdef (stmt));
2271 : 27608249 : gimple_set_vuse (copy, gimple_vuse (stmt));
2272 : : }
2273 : :
2274 : : /* Clear out SSA operand vectors on COPY. */
2275 : 55326171 : if (gimple_has_ops (stmt))
2276 : : {
2277 : 54899381 : gimple_set_use_ops (copy, NULL);
2278 : :
2279 : : /* SSA operands need to be updated. */
2280 : 54899381 : gimple_set_modified (copy, true);
2281 : : }
2282 : :
2283 : 55326171 : if (gimple_debug_nonbind_marker_p (stmt))
2284 : 11768188 : cfun->debug_marker_count++;
2285 : :
2286 : 55326171 : return copy;
2287 : : }
2288 : :
2289 : : /* Move OLD_STMT's vuse and vdef operands to NEW_STMT, on the assumption
2290 : : that OLD_STMT is about to be removed. */
2291 : :
2292 : : void
2293 : 479022 : gimple_move_vops (gimple *new_stmt, gimple *old_stmt)
2294 : : {
2295 : 479022 : tree vdef = gimple_vdef (old_stmt);
2296 : 958044 : gimple_set_vuse (new_stmt, gimple_vuse (old_stmt));
2297 : 479022 : gimple_set_vdef (new_stmt, vdef);
2298 : 479022 : if (vdef && TREE_CODE (vdef) == SSA_NAME)
2299 : 163031 : SSA_NAME_DEF_STMT (vdef) = new_stmt;
2300 : 479022 : }
2301 : :
2302 : : /* Return true if statement S has side-effects. We consider a
2303 : : statement to have side effects if:
2304 : :
2305 : : - It is a GIMPLE_CALL not marked with ECF_PURE or ECF_CONST.
2306 : : - Any of its operands are marked TREE_THIS_VOLATILE or TREE_SIDE_EFFECTS. */
2307 : :
2308 : : bool
2309 : 1195503690 : gimple_has_side_effects (const gimple *s)
2310 : : {
2311 : 1195503690 : if (is_gimple_debug (s))
2312 : : return false;
2313 : :
2314 : : /* We don't have to scan the arguments to check for
2315 : : volatile arguments, though, at present, we still
2316 : : do a scan to check for TREE_SIDE_EFFECTS. */
2317 : 2044969627 : if (gimple_has_volatile_ops (s))
2318 : : return true;
2319 : :
2320 : 1024117547 : if (gimple_code (s) == GIMPLE_ASM
2321 : 1024117547 : && gimple_asm_volatile_p (as_a <const gasm *> (s)))
2322 : : return true;
2323 : :
2324 : 1023558468 : if (is_gimple_call (s))
2325 : : {
2326 : 91506620 : int flags = gimple_call_flags (s);
2327 : :
2328 : : /* An infinite loop is considered a side effect. */
2329 : 91506620 : if (!(flags & (ECF_CONST | ECF_PURE))
2330 : 17962815 : || (flags & ECF_LOOPING_CONST_OR_PURE))
2331 : : return true;
2332 : :
2333 : : return false;
2334 : : }
2335 : :
2336 : : return false;
2337 : : }
2338 : :
2339 : : /* Helper for gimple_could_trap_p and gimple_assign_rhs_could_trap_p.
2340 : : Return true if S can trap. When INCLUDE_MEM is true, check whether
2341 : : the memory operations could trap. When INCLUDE_STORES is true and
2342 : : S is a GIMPLE_ASSIGN, the LHS of the assignment is also checked. */
2343 : :
2344 : : bool
2345 : 53598747 : gimple_could_trap_p_1 (const gimple *s, bool include_mem, bool include_stores)
2346 : : {
2347 : 53598747 : tree t, div = NULL_TREE;
2348 : 53598747 : enum tree_code op;
2349 : :
2350 : 53598747 : if (include_mem)
2351 : : {
2352 : 30398500 : unsigned i, start = (is_gimple_assign (s) && !include_stores) ? 1 : 0;
2353 : :
2354 : 105073000 : for (i = start; i < gimple_num_ops (s); i++)
2355 : 78836980 : if (tree_could_trap_p (gimple_op (s, i)))
2356 : : return true;
2357 : : }
2358 : :
2359 : 49436267 : switch (gimple_code (s))
2360 : : {
2361 : 8626 : case GIMPLE_ASM:
2362 : 8626 : return gimple_asm_volatile_p (as_a <const gasm *> (s));
2363 : :
2364 : 1320694 : case GIMPLE_CALL:
2365 : 1320694 : if (gimple_call_internal_p (s))
2366 : : return false;
2367 : 1182247 : t = gimple_call_fndecl (s);
2368 : : /* Assume that indirect and calls to weak functions may trap. */
2369 : 1182247 : if (!t || !DECL_P (t) || DECL_WEAK (t))
2370 : : return true;
2371 : : return false;
2372 : :
2373 : 37874582 : case GIMPLE_ASSIGN:
2374 : 37874582 : op = gimple_assign_rhs_code (s);
2375 : :
2376 : : /* For COND_EXPR only the condition may trap. */
2377 : 37874582 : if (op == COND_EXPR)
2378 : 19837 : return tree_could_trap_p (gimple_assign_rhs1 (s));
2379 : :
2380 : : /* For comparisons we need to check rhs operand types instead of lhs type
2381 : : (which is BOOLEAN_TYPE). */
2382 : 37854745 : if (TREE_CODE_CLASS (op) == tcc_comparison)
2383 : 1352481 : t = TREE_TYPE (gimple_assign_rhs1 (s));
2384 : : else
2385 : 36502264 : t = TREE_TYPE (gimple_assign_lhs (s));
2386 : :
2387 : 37854745 : if (get_gimple_rhs_class (op) == GIMPLE_BINARY_RHS)
2388 : 21401426 : div = gimple_assign_rhs2 (s);
2389 : :
2390 : 40134236 : return (operation_could_trap_p (op, FLOAT_TYPE_P (t),
2391 : 37854745 : (INTEGRAL_TYPE_P (t)
2392 : 37854745 : && TYPE_OVERFLOW_TRAPS (t)),
2393 : 37854745 : div));
2394 : :
2395 : 6531286 : case GIMPLE_COND:
2396 : 6531286 : t = TREE_TYPE (gimple_cond_lhs (s));
2397 : 6531286 : return operation_could_trap_p (gimple_cond_code (s),
2398 : 13062572 : FLOAT_TYPE_P (t), false, NULL_TREE);
2399 : :
2400 : : default:
2401 : : break;
2402 : : }
2403 : :
2404 : : return false;
2405 : : }
2406 : :
2407 : : /* Return true if statement S can trap. */
2408 : :
2409 : : bool
2410 : 27685213 : gimple_could_trap_p (const gimple *s)
2411 : : {
2412 : 27685213 : return gimple_could_trap_p_1 (s, true, true);
2413 : : }
2414 : :
2415 : : /* Return true if RHS of a GIMPLE_ASSIGN S can trap. */
2416 : :
2417 : : bool
2418 : 2713287 : gimple_assign_rhs_could_trap_p (gimple *s)
2419 : : {
2420 : 2713287 : gcc_assert (is_gimple_assign (s));
2421 : 2713287 : return gimple_could_trap_p_1 (s, true, false);
2422 : : }
2423 : :
2424 : :
2425 : : /* Print debugging information for gimple stmts generated. */
2426 : :
2427 : : void
2428 : 0 : dump_gimple_statistics (void)
2429 : : {
2430 : 0 : int i;
2431 : 0 : uint64_t total_tuples = 0, total_bytes = 0;
2432 : :
2433 : 0 : if (! GATHER_STATISTICS)
2434 : : {
2435 : 0 : fprintf (stderr, "No GIMPLE statistics\n");
2436 : 0 : return;
2437 : : }
2438 : :
2439 : : fprintf (stderr, "\nGIMPLE statements\n");
2440 : : fprintf (stderr, "Kind Stmts Bytes\n");
2441 : : fprintf (stderr, "---------------------------------------\n");
2442 : : for (i = 0; i < (int) gimple_alloc_kind_all; ++i)
2443 : : {
2444 : : fprintf (stderr, "%-20s %7" PRIu64 "%c %10" PRIu64 "%c\n",
2445 : : gimple_alloc_kind_names[i],
2446 : : SIZE_AMOUNT (gimple_alloc_counts[i]),
2447 : : SIZE_AMOUNT (gimple_alloc_sizes[i]));
2448 : : total_tuples += gimple_alloc_counts[i];
2449 : : total_bytes += gimple_alloc_sizes[i];
2450 : : }
2451 : : fprintf (stderr, "---------------------------------------\n");
2452 : : fprintf (stderr, "%-20s %7" PRIu64 "%c %10" PRIu64 "%c\n", "Total",
2453 : : SIZE_AMOUNT (total_tuples), SIZE_AMOUNT (total_bytes));
2454 : : fprintf (stderr, "---------------------------------------\n");
2455 : : }
2456 : :
2457 : :
2458 : : /* Return the number of operands needed on the RHS of a GIMPLE
2459 : : assignment for an expression with tree code CODE. */
2460 : :
2461 : : unsigned
2462 : 94098376 : get_gimple_rhs_num_ops (enum tree_code code)
2463 : : {
2464 : 94098376 : switch (get_gimple_rhs_class (code))
2465 : : {
2466 : : case GIMPLE_UNARY_RHS:
2467 : : case GIMPLE_SINGLE_RHS:
2468 : : return 1;
2469 : : case GIMPLE_BINARY_RHS:
2470 : : return 2;
2471 : : case GIMPLE_TERNARY_RHS:
2472 : : return 3;
2473 : 0 : default:
2474 : 0 : gcc_unreachable ();
2475 : : }
2476 : : }
2477 : :
2478 : : #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \
2479 : : (unsigned char) \
2480 : : ((TYPE) == tcc_unary ? GIMPLE_UNARY_RHS \
2481 : : : ((TYPE) == tcc_binary \
2482 : : || (TYPE) == tcc_comparison) ? GIMPLE_BINARY_RHS \
2483 : : : ((TYPE) == tcc_constant \
2484 : : || (TYPE) == tcc_declaration \
2485 : : || (TYPE) == tcc_reference) ? GIMPLE_SINGLE_RHS \
2486 : : : ((SYM) == TRUTH_AND_EXPR \
2487 : : || (SYM) == TRUTH_OR_EXPR \
2488 : : || (SYM) == TRUTH_XOR_EXPR) ? GIMPLE_BINARY_RHS \
2489 : : : (SYM) == TRUTH_NOT_EXPR ? GIMPLE_UNARY_RHS \
2490 : : : ((SYM) == COND_EXPR \
2491 : : || (SYM) == WIDEN_MULT_PLUS_EXPR \
2492 : : || (SYM) == WIDEN_MULT_MINUS_EXPR \
2493 : : || (SYM) == DOT_PROD_EXPR \
2494 : : || (SYM) == SAD_EXPR \
2495 : : || (SYM) == REALIGN_LOAD_EXPR \
2496 : : || (SYM) == VEC_COND_EXPR \
2497 : : || (SYM) == VEC_PERM_EXPR \
2498 : : || (SYM) == BIT_INSERT_EXPR) ? GIMPLE_TERNARY_RHS \
2499 : : : ((SYM) == CONSTRUCTOR \
2500 : : || (SYM) == OBJ_TYPE_REF \
2501 : : || (SYM) == ADDR_EXPR \
2502 : : || (SYM) == WITH_SIZE_EXPR \
2503 : : || (SYM) == SSA_NAME \
2504 : : || (SYM) == OMP_NEXT_VARIANT \
2505 : : || (SYM) == OMP_TARGET_DEVICE_MATCHES) ? GIMPLE_SINGLE_RHS \
2506 : : : GIMPLE_INVALID_RHS),
2507 : : #define END_OF_BASE_TREE_CODES (unsigned char) GIMPLE_INVALID_RHS,
2508 : :
2509 : : const unsigned char gimple_rhs_class_table[] = {
2510 : : #include "all-tree.def"
2511 : : };
2512 : :
2513 : : #undef DEFTREECODE
2514 : : #undef END_OF_BASE_TREE_CODES
2515 : :
2516 : : /* Build a GIMPLE_CALL identical to STMT but skipping the arguments in
2517 : : the positions marked by the set ARGS_TO_SKIP. */
2518 : :
2519 : : gcall *
2520 : 0 : gimple_call_copy_skip_args (gcall *stmt, bitmap args_to_skip)
2521 : : {
2522 : 0 : int i;
2523 : 0 : int nargs = gimple_call_num_args (stmt);
2524 : 0 : auto_vec<tree> vargs (nargs);
2525 : 0 : gcall *new_stmt;
2526 : :
2527 : 0 : for (i = 0; i < nargs; i++)
2528 : 0 : if (!bitmap_bit_p (args_to_skip, i))
2529 : 0 : vargs.quick_push (gimple_call_arg (stmt, i));
2530 : :
2531 : 0 : if (gimple_call_internal_p (stmt))
2532 : 0 : new_stmt = gimple_build_call_internal_vec (gimple_call_internal_fn (stmt),
2533 : : vargs);
2534 : : else
2535 : 0 : new_stmt = gimple_build_call_vec (gimple_call_fn (stmt), vargs);
2536 : :
2537 : 0 : if (gimple_call_lhs (stmt))
2538 : 0 : gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt));
2539 : :
2540 : 0 : gimple_set_vuse (new_stmt, gimple_vuse (stmt));
2541 : 0 : gimple_set_vdef (new_stmt, gimple_vdef (stmt));
2542 : :
2543 : 0 : if (gimple_has_location (stmt))
2544 : 0 : gimple_set_location (new_stmt, gimple_location (stmt));
2545 : 0 : gimple_call_copy_flags (new_stmt, stmt);
2546 : 0 : gimple_call_set_chain (new_stmt, gimple_call_chain (stmt));
2547 : :
2548 : 0 : gimple_set_modified (new_stmt, true);
2549 : :
2550 : 0 : return new_stmt;
2551 : 0 : }
2552 : :
2553 : :
2554 : :
2555 : : /* Return true if the field decls F1 and F2 are at the same offset.
2556 : :
2557 : : This is intended to be used on GIMPLE types only. */
2558 : :
2559 : : bool
2560 : 48387451 : gimple_compare_field_offset (tree f1, tree f2)
2561 : : {
2562 : 48387451 : if (DECL_OFFSET_ALIGN (f1) == DECL_OFFSET_ALIGN (f2))
2563 : : {
2564 : 48387388 : tree offset1 = DECL_FIELD_OFFSET (f1);
2565 : 48387388 : tree offset2 = DECL_FIELD_OFFSET (f2);
2566 : 48387388 : return ((offset1 == offset2
2567 : : /* Once gimplification is done, self-referential offsets are
2568 : : instantiated as operand #2 of the COMPONENT_REF built for
2569 : : each access and reset. Therefore, they are not relevant
2570 : : anymore and fields are interchangeable provided that they
2571 : : represent the same access. */
2572 : 0 : || (TREE_CODE (offset1) == PLACEHOLDER_EXPR
2573 : 0 : && TREE_CODE (offset2) == PLACEHOLDER_EXPR
2574 : 0 : && (DECL_SIZE (f1) == DECL_SIZE (f2)
2575 : 0 : || (TREE_CODE (DECL_SIZE (f1)) == PLACEHOLDER_EXPR
2576 : 0 : && TREE_CODE (DECL_SIZE (f2)) == PLACEHOLDER_EXPR)
2577 : 0 : || operand_equal_p (DECL_SIZE (f1), DECL_SIZE (f2), 0))
2578 : 0 : && DECL_ALIGN (f1) == DECL_ALIGN (f2))
2579 : 0 : || operand_equal_p (offset1, offset2, 0))
2580 : 96774776 : && tree_int_cst_equal (DECL_FIELD_BIT_OFFSET (f1),
2581 : 48387388 : DECL_FIELD_BIT_OFFSET (f2)));
2582 : : }
2583 : :
2584 : : /* Fortran and C do not always agree on what DECL_OFFSET_ALIGN
2585 : : should be, so handle differing ones specially by decomposing
2586 : : the offset into a byte and bit offset manually. */
2587 : 63 : if (tree_fits_shwi_p (DECL_FIELD_OFFSET (f1))
2588 : 63 : && tree_fits_shwi_p (DECL_FIELD_OFFSET (f2)))
2589 : : {
2590 : 63 : unsigned HOST_WIDE_INT byte_offset1, byte_offset2;
2591 : 63 : unsigned HOST_WIDE_INT bit_offset1, bit_offset2;
2592 : 63 : bit_offset1 = TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f1));
2593 : 63 : byte_offset1 = (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f1))
2594 : 63 : + bit_offset1 / BITS_PER_UNIT);
2595 : 63 : bit_offset2 = TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f2));
2596 : 63 : byte_offset2 = (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f2))
2597 : 63 : + bit_offset2 / BITS_PER_UNIT);
2598 : 63 : if (byte_offset1 != byte_offset2)
2599 : : return false;
2600 : 63 : return bit_offset1 % BITS_PER_UNIT == bit_offset2 % BITS_PER_UNIT;
2601 : : }
2602 : :
2603 : : return false;
2604 : : }
2605 : :
2606 : :
2607 : : /* Return a type the same as TYPE except unsigned or
2608 : : signed according to UNSIGNEDP. */
2609 : :
2610 : : static tree
2611 : 484184 : gimple_signed_or_unsigned_type (bool unsignedp, tree type)
2612 : : {
2613 : 484184 : tree type1;
2614 : 484184 : int i;
2615 : :
2616 : 484184 : type1 = TYPE_MAIN_VARIANT (type);
2617 : 484184 : if (type1 == signed_char_type_node
2618 : 484184 : || type1 == char_type_node
2619 : 484184 : || type1 == unsigned_char_type_node)
2620 : 4 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2621 : 484180 : if (type1 == integer_type_node || type1 == unsigned_type_node)
2622 : 309503 : return unsignedp ? unsigned_type_node : integer_type_node;
2623 : 174677 : if (type1 == short_integer_type_node || type1 == short_unsigned_type_node)
2624 : 153687 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2625 : 20990 : if (type1 == long_integer_type_node || type1 == long_unsigned_type_node)
2626 : 39 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2627 : 20951 : if (type1 == long_long_integer_type_node
2628 : 20863 : || type1 == long_long_unsigned_type_node)
2629 : 88 : return unsignedp
2630 : 88 : ? long_long_unsigned_type_node
2631 : 88 : : long_long_integer_type_node;
2632 : :
2633 : 34921 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
2634 : 20863 : if (int_n_enabled_p[i]
2635 : 20863 : && (type1 == int_n_trees[i].unsigned_type
2636 : 14400 : || type1 == int_n_trees[i].signed_type))
2637 : 6805 : return unsignedp
2638 : 6805 : ? int_n_trees[i].unsigned_type
2639 : 6805 : : int_n_trees[i].signed_type;
2640 : :
2641 : : #if HOST_BITS_PER_WIDE_INT >= 64
2642 : 14058 : if (type1 == intTI_type_node || type1 == unsigned_intTI_type_node)
2643 : 0 : return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
2644 : : #endif
2645 : 14058 : if (type1 == intDI_type_node || type1 == unsigned_intDI_type_node)
2646 : 0 : return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
2647 : 14058 : if (type1 == intSI_type_node || type1 == unsigned_intSI_type_node)
2648 : 0 : return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
2649 : 14058 : if (type1 == intHI_type_node || type1 == unsigned_intHI_type_node)
2650 : 0 : return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
2651 : 14058 : if (type1 == intQI_type_node || type1 == unsigned_intQI_type_node)
2652 : 0 : return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
2653 : :
2654 : : #define GIMPLE_FIXED_TYPES(NAME) \
2655 : : if (type1 == short_ ## NAME ## _type_node \
2656 : : || type1 == unsigned_short_ ## NAME ## _type_node) \
2657 : : return unsignedp ? unsigned_short_ ## NAME ## _type_node \
2658 : : : short_ ## NAME ## _type_node; \
2659 : : if (type1 == NAME ## _type_node \
2660 : : || type1 == unsigned_ ## NAME ## _type_node) \
2661 : : return unsignedp ? unsigned_ ## NAME ## _type_node \
2662 : : : NAME ## _type_node; \
2663 : : if (type1 == long_ ## NAME ## _type_node \
2664 : : || type1 == unsigned_long_ ## NAME ## _type_node) \
2665 : : return unsignedp ? unsigned_long_ ## NAME ## _type_node \
2666 : : : long_ ## NAME ## _type_node; \
2667 : : if (type1 == long_long_ ## NAME ## _type_node \
2668 : : || type1 == unsigned_long_long_ ## NAME ## _type_node) \
2669 : : return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
2670 : : : long_long_ ## NAME ## _type_node;
2671 : :
2672 : : #define GIMPLE_FIXED_MODE_TYPES(NAME) \
2673 : : if (type1 == NAME ## _type_node \
2674 : : || type1 == u ## NAME ## _type_node) \
2675 : : return unsignedp ? u ## NAME ## _type_node \
2676 : : : NAME ## _type_node;
2677 : :
2678 : : #define GIMPLE_FIXED_TYPES_SAT(NAME) \
2679 : : if (type1 == sat_ ## short_ ## NAME ## _type_node \
2680 : : || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
2681 : : return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
2682 : : : sat_ ## short_ ## NAME ## _type_node; \
2683 : : if (type1 == sat_ ## NAME ## _type_node \
2684 : : || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
2685 : : return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
2686 : : : sat_ ## NAME ## _type_node; \
2687 : : if (type1 == sat_ ## long_ ## NAME ## _type_node \
2688 : : || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
2689 : : return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
2690 : : : sat_ ## long_ ## NAME ## _type_node; \
2691 : : if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
2692 : : || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
2693 : : return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
2694 : : : sat_ ## long_long_ ## NAME ## _type_node;
2695 : :
2696 : : #define GIMPLE_FIXED_MODE_TYPES_SAT(NAME) \
2697 : : if (type1 == sat_ ## NAME ## _type_node \
2698 : : || type1 == sat_ ## u ## NAME ## _type_node) \
2699 : : return unsignedp ? sat_ ## u ## NAME ## _type_node \
2700 : : : sat_ ## NAME ## _type_node;
2701 : :
2702 : 14058 : GIMPLE_FIXED_TYPES (fract);
2703 : 14058 : GIMPLE_FIXED_TYPES_SAT (fract);
2704 : 14058 : GIMPLE_FIXED_TYPES (accum);
2705 : 14058 : GIMPLE_FIXED_TYPES_SAT (accum);
2706 : :
2707 : 14058 : GIMPLE_FIXED_MODE_TYPES (qq);
2708 : 14058 : GIMPLE_FIXED_MODE_TYPES (hq);
2709 : 14058 : GIMPLE_FIXED_MODE_TYPES (sq);
2710 : 14058 : GIMPLE_FIXED_MODE_TYPES (dq);
2711 : 14058 : GIMPLE_FIXED_MODE_TYPES (tq);
2712 : 14058 : GIMPLE_FIXED_MODE_TYPES_SAT (qq);
2713 : 14058 : GIMPLE_FIXED_MODE_TYPES_SAT (hq);
2714 : 14058 : GIMPLE_FIXED_MODE_TYPES_SAT (sq);
2715 : 14058 : GIMPLE_FIXED_MODE_TYPES_SAT (dq);
2716 : 14058 : GIMPLE_FIXED_MODE_TYPES_SAT (tq);
2717 : 14058 : GIMPLE_FIXED_MODE_TYPES (ha);
2718 : 14058 : GIMPLE_FIXED_MODE_TYPES (sa);
2719 : 14058 : GIMPLE_FIXED_MODE_TYPES (da);
2720 : 14058 : GIMPLE_FIXED_MODE_TYPES (ta);
2721 : 14058 : GIMPLE_FIXED_MODE_TYPES_SAT (ha);
2722 : 14058 : GIMPLE_FIXED_MODE_TYPES_SAT (sa);
2723 : 14058 : GIMPLE_FIXED_MODE_TYPES_SAT (da);
2724 : 14058 : GIMPLE_FIXED_MODE_TYPES_SAT (ta);
2725 : :
2726 : : /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
2727 : : the precision; they have precision set to match their range, but
2728 : : may use a wider mode to match an ABI. If we change modes, we may
2729 : : wind up with bad conversions. For INTEGER_TYPEs in C, must check
2730 : : the precision as well, so as to yield correct results for
2731 : : bit-field types. C++ does not have these separate bit-field
2732 : : types, and producing a signed or unsigned variant of an
2733 : : ENUMERAL_TYPE may cause other problems as well. */
2734 : 14058 : if (!INTEGRAL_TYPE_P (type)
2735 : 14058 : || TYPE_UNSIGNED (type) == unsignedp)
2736 : : return type;
2737 : :
2738 : : #define TYPE_OK(node) \
2739 : : (TYPE_MODE (type) == TYPE_MODE (node) \
2740 : : && TYPE_PRECISION (type) == TYPE_PRECISION (node))
2741 : 14058 : if (TYPE_OK (signed_char_type_node))
2742 : 610 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2743 : 13448 : if (TYPE_OK (integer_type_node))
2744 : 3504 : return unsignedp ? unsigned_type_node : integer_type_node;
2745 : 9944 : if (TYPE_OK (short_integer_type_node))
2746 : 4736 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2747 : 5208 : if (TYPE_OK (long_integer_type_node))
2748 : 0 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2749 : 5208 : if (TYPE_OK (long_long_integer_type_node))
2750 : 0 : return (unsignedp
2751 : 0 : ? long_long_unsigned_type_node
2752 : 0 : : long_long_integer_type_node);
2753 : :
2754 : 10380 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
2755 : 5208 : if (int_n_enabled_p[i]
2756 : 5208 : && TYPE_MODE (type) == int_n_data[i].m
2757 : 5244 : && TYPE_PRECISION (type) == int_n_data[i].bitsize)
2758 : 36 : return unsignedp
2759 : 36 : ? int_n_trees[i].unsigned_type
2760 : 36 : : int_n_trees[i].signed_type;
2761 : :
2762 : : #if HOST_BITS_PER_WIDE_INT >= 64
2763 : 5172 : if (TYPE_OK (intTI_type_node))
2764 : 0 : return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
2765 : : #endif
2766 : 5172 : if (TYPE_OK (intDI_type_node))
2767 : 0 : return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
2768 : 5172 : if (TYPE_OK (intSI_type_node))
2769 : 0 : return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
2770 : 5172 : if (TYPE_OK (intHI_type_node))
2771 : 0 : return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
2772 : 5172 : if (TYPE_OK (intQI_type_node))
2773 : 0 : return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
2774 : :
2775 : : #undef GIMPLE_FIXED_TYPES
2776 : : #undef GIMPLE_FIXED_MODE_TYPES
2777 : : #undef GIMPLE_FIXED_TYPES_SAT
2778 : : #undef GIMPLE_FIXED_MODE_TYPES_SAT
2779 : : #undef TYPE_OK
2780 : :
2781 : 5172 : return build_nonstandard_integer_type (TYPE_PRECISION (type), unsignedp);
2782 : : }
2783 : :
2784 : :
2785 : : /* Return an unsigned type the same as TYPE in other respects. */
2786 : :
2787 : : tree
2788 : 0 : gimple_unsigned_type (tree type)
2789 : : {
2790 : 0 : return gimple_signed_or_unsigned_type (true, type);
2791 : : }
2792 : :
2793 : :
2794 : : /* Return a signed type the same as TYPE in other respects. */
2795 : :
2796 : : tree
2797 : 484184 : gimple_signed_type (tree type)
2798 : : {
2799 : 484184 : return gimple_signed_or_unsigned_type (false, type);
2800 : : }
2801 : :
2802 : :
2803 : : /* Return the typed-based alias set for T, which may be an expression
2804 : : or a type. Return -1 if we don't do anything special. */
2805 : :
2806 : : alias_set_type
2807 : 7472029 : gimple_get_alias_set (tree t)
2808 : : {
2809 : : /* That's all the expressions we handle specially. */
2810 : 7472029 : if (!TYPE_P (t))
2811 : : return -1;
2812 : :
2813 : : /* For convenience, follow the C standard when dealing with
2814 : : character types. Any object may be accessed via an lvalue that
2815 : : has character type. */
2816 : 2164054 : if (t == char_type_node
2817 : 1673069 : || t == signed_char_type_node
2818 : 1673069 : || t == unsigned_char_type_node)
2819 : : return 0;
2820 : :
2821 : : /* Allow aliasing between signed and unsigned variants of the same
2822 : : type. We treat the signed variant as canonical. */
2823 : 1673069 : if (TREE_CODE (t) == INTEGER_TYPE && TYPE_UNSIGNED (t))
2824 : : {
2825 : 483293 : tree t1 = gimple_signed_type (t);
2826 : :
2827 : : /* t1 == t can happen for boolean nodes which are always unsigned. */
2828 : 483293 : if (t1 != t)
2829 : 483293 : return get_alias_set (t1);
2830 : : }
2831 : :
2832 : : /* Allow aliasing between enumeral types and the underlying
2833 : : integer type. This is required for C since those are
2834 : : compatible types. */
2835 : 1189776 : else if (TREE_CODE (t) == ENUMERAL_TYPE)
2836 : : {
2837 : 0 : tree t1 = lang_hooks.types.type_for_size (tree_to_uhwi (TYPE_SIZE (t)),
2838 : : false /* short-cut above */);
2839 : 0 : return get_alias_set (t1);
2840 : : }
2841 : :
2842 : : return -1;
2843 : : }
2844 : :
2845 : :
2846 : : /* Helper for gimple_ior_addresses_taken_1. */
2847 : :
2848 : : static bool
2849 : 48805782 : gimple_ior_addresses_taken_1 (gimple *, tree addr, tree, void *data)
2850 : : {
2851 : 48805782 : bitmap addresses_taken = (bitmap)data;
2852 : 48805782 : addr = get_base_address (addr);
2853 : 48805782 : if (addr
2854 : 48805782 : && DECL_P (addr))
2855 : : {
2856 : 31693758 : bitmap_set_bit (addresses_taken, DECL_UID (addr));
2857 : 31693758 : return true;
2858 : : }
2859 : : return false;
2860 : : }
2861 : :
2862 : : /* Set the bit for the uid of all decls that have their address taken
2863 : : in STMT in the ADDRESSES_TAKEN bitmap. Returns true if there
2864 : : were any in this stmt. */
2865 : :
2866 : : bool
2867 : 722643529 : gimple_ior_addresses_taken (bitmap addresses_taken, gimple *stmt)
2868 : : {
2869 : 722643529 : return walk_stmt_load_store_addr_ops (stmt, addresses_taken, NULL, NULL,
2870 : 722643529 : gimple_ior_addresses_taken_1);
2871 : : }
2872 : :
2873 : :
2874 : : /* Return true when STMTs arguments and return value match those of FNDECL,
2875 : : a decl of a builtin function. */
2876 : :
2877 : : bool
2878 : 262110420 : gimple_builtin_call_types_compatible_p (const gimple *stmt, tree fndecl)
2879 : : {
2880 : 262110420 : gcc_checking_assert (DECL_BUILT_IN_CLASS (fndecl) != NOT_BUILT_IN);
2881 : :
2882 : 262110420 : if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
2883 : 259951218 : if (tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl)))
2884 : 262110420 : fndecl = decl;
2885 : :
2886 : 262110420 : tree ret = gimple_call_lhs (stmt);
2887 : 262110420 : if (ret
2888 : 427315831 : && !useless_type_conversion_p (TREE_TYPE (ret),
2889 : 165205411 : TREE_TYPE (TREE_TYPE (fndecl))))
2890 : : return false;
2891 : :
2892 : 262088793 : tree targs = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
2893 : 262088793 : unsigned nargs = gimple_call_num_args (stmt);
2894 : 797940168 : for (unsigned i = 0; i < nargs; ++i)
2895 : : {
2896 : : /* Variadic args follow. */
2897 : 560219221 : if (!targs)
2898 : : return true;
2899 : 540187685 : tree arg = gimple_call_arg (stmt, i);
2900 : 540187685 : tree type = TREE_VALUE (targs);
2901 : 540187685 : if (!useless_type_conversion_p (type, TREE_TYPE (arg))
2902 : : /* char/short integral arguments are promoted to int
2903 : : by several frontends if targetm.calls.promote_prototypes
2904 : : is true. Allow such promotion too. */
2905 : 545613066 : && !(INTEGRAL_TYPE_P (type)
2906 : 8550394 : && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)
2907 : 5425381 : && targetm.calls.promote_prototypes (TREE_TYPE (fndecl))
2908 : 5425381 : && useless_type_conversion_p (integer_type_node,
2909 : 5425381 : TREE_TYPE (arg))))
2910 : 4336310 : return false;
2911 : 535851375 : targs = TREE_CHAIN (targs);
2912 : : }
2913 : 474715797 : if (targs && !VOID_TYPE_P (TREE_VALUE (targs)))
2914 : : return false;
2915 : : return true;
2916 : : }
2917 : :
2918 : : /* Return true when STMT is operator a replaceable delete call. */
2919 : :
2920 : : bool
2921 : 1877824 : gimple_call_operator_delete_p (const gcall *stmt)
2922 : : {
2923 : 1877824 : tree fndecl;
2924 : :
2925 : 1877824 : if ((fndecl = gimple_call_fndecl (stmt)) != NULL_TREE)
2926 : 1877824 : return DECL_IS_OPERATOR_DELETE_P (fndecl);
2927 : : return false;
2928 : : }
2929 : :
2930 : : /* Return true when STMT is builtins call. */
2931 : :
2932 : : bool
2933 : 64387097 : gimple_call_builtin_p (const gimple *stmt)
2934 : : {
2935 : 64387097 : tree fndecl;
2936 : 64387097 : if (is_gimple_call (stmt)
2937 : 18731827 : && (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE
2938 : 82216633 : && DECL_BUILT_IN_CLASS (fndecl) != NOT_BUILT_IN)
2939 : 3696938 : return gimple_builtin_call_types_compatible_p (stmt, fndecl);
2940 : : return false;
2941 : : }
2942 : :
2943 : : /* Return true when STMT is builtins call to CLASS. */
2944 : :
2945 : : bool
2946 : 896556204 : gimple_call_builtin_p (const gimple *stmt, enum built_in_class klass)
2947 : : {
2948 : 896556204 : tree fndecl;
2949 : 896556204 : if (is_gimple_call (stmt)
2950 : 671017482 : && (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE
2951 : 1537020915 : && DECL_BUILT_IN_CLASS (fndecl) == klass)
2952 : 172549749 : return gimple_builtin_call_types_compatible_p (stmt, fndecl);
2953 : : return false;
2954 : : }
2955 : :
2956 : : /* Return true when STMT is builtins call to CODE of CLASS. */
2957 : :
2958 : : bool
2959 : 2601446917 : gimple_call_builtin_p (const gimple *stmt, enum built_in_function code)
2960 : : {
2961 : 2601446917 : tree fndecl;
2962 : 2601446917 : if (is_gimple_call (stmt)
2963 : 780470327 : && (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE
2964 : 3346621372 : && fndecl_built_in_p (fndecl, code))
2965 : 1889494 : return gimple_builtin_call_types_compatible_p (stmt, fndecl);
2966 : : return false;
2967 : : }
2968 : :
2969 : : /* If CALL is a call to a combined_fn (i.e. an internal function or
2970 : : a normal built-in function), return its code, otherwise return
2971 : : CFN_LAST. */
2972 : :
2973 : : combined_fn
2974 : 173616504 : gimple_call_combined_fn (const gimple *stmt)
2975 : : {
2976 : 173616504 : if (const gcall *call = dyn_cast <const gcall *> (stmt))
2977 : : {
2978 : 171866103 : if (gimple_call_internal_p (call))
2979 : 6993123 : return as_combined_fn (gimple_call_internal_fn (call));
2980 : :
2981 : 164872980 : tree fndecl = gimple_call_fndecl (stmt);
2982 : 164872980 : if (fndecl
2983 : 158494506 : && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
2984 : 232421792 : && gimple_builtin_call_types_compatible_p (stmt, fndecl))
2985 : 67036240 : return as_combined_fn (DECL_FUNCTION_CODE (fndecl));
2986 : : }
2987 : : return CFN_LAST;
2988 : : }
2989 : :
2990 : : /* Return true if STMT clobbers memory. STMT is required to be a
2991 : : GIMPLE_ASM. */
2992 : :
2993 : : bool
2994 : 11269608 : gimple_asm_clobbers_memory_p (const gasm *stmt)
2995 : : {
2996 : 11269608 : unsigned i;
2997 : :
2998 : 16563867 : for (i = 0; i < gimple_asm_nclobbers (stmt); i++)
2999 : : {
3000 : 9517387 : tree op = gimple_asm_clobber_op (stmt, i);
3001 : 9517387 : if (strcmp (TREE_STRING_POINTER (TREE_VALUE (op)), "memory") == 0)
3002 : : return true;
3003 : : }
3004 : :
3005 : : /* Non-empty basic ASM implicitly clobbers memory. */
3006 : 7046480 : if (gimple_asm_basic_p (stmt) && strlen (gimple_asm_string (stmt)) != 0)
3007 : 95681 : return true;
3008 : :
3009 : : return false;
3010 : : }
3011 : :
3012 : : /* Dump bitmap SET (assumed to contain VAR_DECLs) to FILE. */
3013 : :
3014 : : void
3015 : 5209 : dump_decl_set (FILE *file, bitmap set)
3016 : : {
3017 : 5209 : if (set)
3018 : : {
3019 : 5209 : bitmap_iterator bi;
3020 : 5209 : unsigned i;
3021 : :
3022 : 5209 : fprintf (file, "{ ");
3023 : :
3024 : 21923 : EXECUTE_IF_SET_IN_BITMAP (set, 0, i, bi)
3025 : : {
3026 : 16714 : fprintf (file, "D.%u", i);
3027 : 16714 : fprintf (file, " ");
3028 : : }
3029 : :
3030 : 5209 : fprintf (file, "}");
3031 : : }
3032 : : else
3033 : 0 : fprintf (file, "NIL");
3034 : 5209 : }
3035 : :
3036 : : /* Return true when CALL is a call stmt that definitely doesn't
3037 : : free any memory or makes it unavailable otherwise. */
3038 : : bool
3039 : 9228021 : nonfreeing_call_p (gimple *call)
3040 : : {
3041 : 9228021 : if (gimple_call_builtin_p (call, BUILT_IN_NORMAL)
3042 : 9228021 : && gimple_call_flags (call) & ECF_LEAF)
3043 : 4057932 : switch (DECL_FUNCTION_CODE (gimple_call_fndecl (call)))
3044 : : {
3045 : : /* Just in case these become ECF_LEAF in the future. */
3046 : : case BUILT_IN_FREE:
3047 : : case BUILT_IN_TM_FREE:
3048 : : case BUILT_IN_REALLOC:
3049 : : case BUILT_IN_STACK_RESTORE:
3050 : : case BUILT_IN_GOMP_FREE:
3051 : : case BUILT_IN_GOMP_REALLOC:
3052 : : return false;
3053 : : default:
3054 : : return true;
3055 : : }
3056 : 5170089 : else if (gimple_call_internal_p (call))
3057 : 632756 : switch (gimple_call_internal_fn (call))
3058 : : {
3059 : : case IFN_ABNORMAL_DISPATCHER:
3060 : : return true;
3061 : 27372 : case IFN_ASAN_MARK:
3062 : 27372 : return tree_to_uhwi (gimple_call_arg (call, 0)) == ASAN_MARK_UNPOISON;
3063 : 599605 : default:
3064 : 599605 : if (gimple_call_flags (call) & ECF_LEAF)
3065 : : return true;
3066 : : return false;
3067 : : }
3068 : :
3069 : 4537333 : tree fndecl = gimple_call_fndecl (call);
3070 : 4537333 : if (!fndecl)
3071 : : return false;
3072 : 4382834 : struct cgraph_node *n = cgraph_node::get (fndecl);
3073 : 4382834 : if (!n)
3074 : : return false;
3075 : 4381442 : enum availability availability;
3076 : 4381442 : n = n->function_symbol (&availability);
3077 : 4381442 : if (!n || availability <= AVAIL_INTERPOSABLE)
3078 : : return false;
3079 : 1042094 : return n->nonfreeing_fn;
3080 : : }
3081 : :
3082 : : /* Return true when CALL is a call stmt that definitely need not
3083 : : be considered to be a memory barrier. */
3084 : : bool
3085 : 1524763 : nonbarrier_call_p (gimple *call)
3086 : : {
3087 : 1524763 : if (gimple_call_flags (call) & (ECF_PURE | ECF_CONST))
3088 : 573548 : return true;
3089 : : /* Should extend this to have a nonbarrier_fn flag, just as above in
3090 : : the nonfreeing case. */
3091 : : return false;
3092 : : }
3093 : :
3094 : : /* Callback for walk_stmt_load_store_ops.
3095 : :
3096 : : Return TRUE if OP will dereference the tree stored in DATA, FALSE
3097 : : otherwise.
3098 : :
3099 : : This routine only makes a superficial check for a dereference. Thus
3100 : : it must only be used if it is safe to return a false negative. */
3101 : : static bool
3102 : 71086055 : check_loadstore (gimple *, tree op, tree, void *data)
3103 : : {
3104 : 71086055 : if (TREE_CODE (op) == MEM_REF || TREE_CODE (op) == TARGET_MEM_REF)
3105 : : {
3106 : : /* Some address spaces may legitimately dereference zero. */
3107 : 34090403 : addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (op));
3108 : 34090403 : if (targetm.addr_space.zero_address_valid (as))
3109 : : return false;
3110 : :
3111 : 34089292 : return operand_equal_p (TREE_OPERAND (op, 0), (tree)data, 0);
3112 : : }
3113 : : return false;
3114 : : }
3115 : :
3116 : :
3117 : : /* Return true if OP can be inferred to be non-NULL after STMT executes,
3118 : : either by using a pointer dereference or attributes. */
3119 : : bool
3120 : 0 : infer_nonnull_range (gimple *stmt, tree op)
3121 : : {
3122 : 0 : return (infer_nonnull_range_by_dereference (stmt, op)
3123 : 0 : || infer_nonnull_range_by_attribute (stmt, op));
3124 : : }
3125 : :
3126 : : /* Return true if OP can be inferred to be non-NULL after STMT
3127 : : executes by using a pointer dereference. */
3128 : : bool
3129 : 294201229 : infer_nonnull_range_by_dereference (gimple *stmt, tree op)
3130 : : {
3131 : : /* We can only assume that a pointer dereference will yield
3132 : : non-NULL if -fdelete-null-pointer-checks is enabled. */
3133 : 294201229 : if (!flag_delete_null_pointer_checks
3134 : 293990872 : || !POINTER_TYPE_P (TREE_TYPE (op))
3135 : 293990872 : || gimple_code (stmt) == GIMPLE_ASM
3136 : 587751449 : || gimple_clobber_p (stmt))
3137 : : return false;
3138 : :
3139 : 286277886 : if (walk_stmt_load_store_ops (stmt, (void *)op,
3140 : : check_loadstore, check_loadstore))
3141 : : return true;
3142 : :
3143 : : return false;
3144 : : }
3145 : :
3146 : : /* Return true if OP can be inferred to be a non-NULL after STMT
3147 : : executes by using attributes. If OP2 is non-NULL and nonnull_if_nonzero
3148 : : is the only attribute implying OP being non-NULL and the corresponding
3149 : : argument isn't non-zero INTEGER_CST, set *OP2 to the corresponding
3150 : : argument and return true (in that case returning true doesn't mean
3151 : : OP can be unconditionally inferred to be non-NULL, but conditionally). */
3152 : : bool
3153 : 63761711 : infer_nonnull_range_by_attribute (gimple *stmt, tree op, tree *op2)
3154 : : {
3155 : 63761711 : if (op2)
3156 : 3422 : *op2 = NULL_TREE;
3157 : :
3158 : : /* We can only assume that a pointer dereference will yield
3159 : : non-NULL if -fdelete-null-pointer-checks is enabled. */
3160 : 63761711 : if (!flag_delete_null_pointer_checks
3161 : 63735440 : || !POINTER_TYPE_P (TREE_TYPE (op))
3162 : 127497151 : || gimple_code (stmt) == GIMPLE_ASM)
3163 : : return false;
3164 : :
3165 : 63682326 : if (is_gimple_call (stmt) && !gimple_call_internal_p (stmt))
3166 : : {
3167 : 4141997 : tree fntype = gimple_call_fntype (stmt);
3168 : 4141997 : tree attrs = TYPE_ATTRIBUTES (fntype);
3169 : 4234198 : for (; attrs; attrs = TREE_CHAIN (attrs))
3170 : : {
3171 : 1064753 : attrs = lookup_attribute ("nonnull", attrs);
3172 : :
3173 : : /* If "nonnull" wasn't specified, we know nothing about
3174 : : the argument, unless "nonnull_if_nonzero" attribute is
3175 : : present. */
3176 : 1064753 : if (attrs == NULL_TREE)
3177 : : break;
3178 : :
3179 : : /* If "nonnull" applies to all the arguments, then ARG
3180 : : is non-null if it's in the argument list. */
3181 : 252131 : if (TREE_VALUE (attrs) == NULL_TREE)
3182 : : {
3183 : 473345 : for (unsigned int i = 0; i < gimple_call_num_args (stmt); i++)
3184 : : {
3185 : 328294 : if (POINTER_TYPE_P (TREE_TYPE (gimple_call_arg (stmt, i)))
3186 : 314462 : && operand_equal_p (op, gimple_call_arg (stmt, i), 0))
3187 : : return true;
3188 : : }
3189 : : return false;
3190 : : }
3191 : :
3192 : : /* Now see if op appears in the nonnull list. */
3193 : 238162 : for (tree t = TREE_VALUE (attrs); t; t = TREE_CHAIN (t))
3194 : : {
3195 : 145961 : unsigned int idx = TREE_INT_CST_LOW (TREE_VALUE (t)) - 1;
3196 : 145961 : if (idx < gimple_call_num_args (stmt))
3197 : : {
3198 : 145960 : tree arg = gimple_call_arg (stmt, idx);
3199 : 145960 : if (operand_equal_p (op, arg, 0))
3200 : : return true;
3201 : : }
3202 : : }
3203 : : }
3204 : :
3205 : 3982067 : for (attrs = TYPE_ATTRIBUTES (fntype);
3206 : 4137474 : (attrs = lookup_attribute ("nonnull_if_nonzero", attrs));
3207 : 155407 : attrs = TREE_CHAIN (attrs))
3208 : : {
3209 : 155775 : tree args = TREE_VALUE (attrs);
3210 : 155775 : unsigned int idx = TREE_INT_CST_LOW (TREE_VALUE (args)) - 1;
3211 : 155775 : unsigned int idx2
3212 : 155775 : = TREE_INT_CST_LOW (TREE_VALUE (TREE_CHAIN (args))) - 1;
3213 : 155775 : if (idx < gimple_call_num_args (stmt)
3214 : 155763 : && idx2 < gimple_call_num_args (stmt)
3215 : 311527 : && operand_equal_p (op, gimple_call_arg (stmt, idx), 0))
3216 : : {
3217 : 368 : tree arg2 = gimple_call_arg (stmt, idx2);
3218 : 368 : if (!INTEGRAL_TYPE_P (TREE_TYPE (arg2)))
3219 : : return false;
3220 : 368 : if (integer_nonzerop (arg2))
3221 : : return true;
3222 : 268 : if (integer_zerop (arg2))
3223 : : return false;
3224 : 243 : if (op2)
3225 : : {
3226 : : /* This case is meant for ubsan instrumentation.
3227 : : The caller can check at runtime if *OP2 is
3228 : : non-zero and OP is null. */
3229 : 92 : *op2 = arg2;
3230 : 92 : return true;
3231 : : }
3232 : 151 : return tree_expr_nonzero_p (arg2);
3233 : : }
3234 : : }
3235 : : }
3236 : :
3237 : : /* If this function is marked as returning non-null, then we can
3238 : : infer OP is non-null if it is used in the return statement. */
3239 : 63522028 : if (greturn *return_stmt = dyn_cast <greturn *> (stmt))
3240 : 913200 : if (gimple_return_retval (return_stmt)
3241 : 531632 : && operand_equal_p (gimple_return_retval (return_stmt), op, 0)
3242 : 1000282 : && lookup_attribute ("returns_nonnull",
3243 : 87082 : TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))
3244 : : return true;
3245 : :
3246 : : return false;
3247 : : }
3248 : :
3249 : : /* Compare two case labels. Because the front end should already have
3250 : : made sure that case ranges do not overlap, it is enough to only compare
3251 : : the CASE_LOW values of each case label. */
3252 : :
3253 : : static int
3254 : 44602963 : compare_case_labels (const void *p1, const void *p2)
3255 : : {
3256 : 44602963 : const_tree const case1 = *(const_tree const*)p1;
3257 : 44602963 : const_tree const case2 = *(const_tree const*)p2;
3258 : :
3259 : : /* The 'default' case label always goes first. */
3260 : 44602963 : if (!CASE_LOW (case1))
3261 : : return -1;
3262 : 44602963 : else if (!CASE_LOW (case2))
3263 : : return 1;
3264 : : else
3265 : 44602963 : return tree_int_cst_compare (CASE_LOW (case1), CASE_LOW (case2));
3266 : : }
3267 : :
3268 : : /* Sort the case labels in LABEL_VEC in place in ascending order. */
3269 : :
3270 : : void
3271 : 68530 : sort_case_labels (vec<tree> &label_vec)
3272 : : {
3273 : 68530 : label_vec.qsort (compare_case_labels);
3274 : 68530 : }
3275 : :
3276 : : /* Prepare a vector of case labels to be used in a GIMPLE_SWITCH statement.
3277 : :
3278 : : LABELS is a vector that contains all case labels to look at.
3279 : :
3280 : : INDEX_TYPE is the type of the switch index expression. Case labels
3281 : : in LABELS are discarded if their values are not in the value range
3282 : : covered by INDEX_TYPE. The remaining case label values are folded
3283 : : to INDEX_TYPE.
3284 : :
3285 : : If a default case exists in LABELS, it is removed from LABELS and
3286 : : returned in DEFAULT_CASEP. If no default case exists, but the
3287 : : case labels already cover the whole range of INDEX_TYPE, a default
3288 : : case is returned pointing to one of the existing case labels.
3289 : : Otherwise DEFAULT_CASEP is set to NULL_TREE.
3290 : :
3291 : : DEFAULT_CASEP may be NULL, in which case the above comment doesn't
3292 : : apply and no action is taken regardless of whether a default case is
3293 : : found or not. */
3294 : :
3295 : : void
3296 : 61557 : preprocess_case_label_vec_for_gimple (vec<tree> &labels,
3297 : : tree index_type,
3298 : : tree *default_casep)
3299 : : {
3300 : 61557 : tree min_value, max_value;
3301 : 61557 : tree default_case = NULL_TREE;
3302 : 61557 : size_t i, len;
3303 : :
3304 : 61557 : i = 0;
3305 : 61557 : min_value = TYPE_MIN_VALUE (index_type);
3306 : 61557 : max_value = TYPE_MAX_VALUE (index_type);
3307 : 1180391 : while (i < labels.length ())
3308 : : {
3309 : 1118834 : tree elt = labels[i];
3310 : 1118834 : tree low = CASE_LOW (elt);
3311 : 1118834 : tree high = CASE_HIGH (elt);
3312 : 1118834 : bool remove_element = false;
3313 : :
3314 : 1118834 : if (low)
3315 : : {
3316 : 1084586 : gcc_checking_assert (TREE_CODE (low) == INTEGER_CST);
3317 : 1084586 : gcc_checking_assert (!high || TREE_CODE (high) == INTEGER_CST);
3318 : :
3319 : : /* This is a non-default case label, i.e. it has a value.
3320 : :
3321 : : See if the case label is reachable within the range of
3322 : : the index type. Remove out-of-range case values. Turn
3323 : : case ranges into a canonical form (high > low strictly)
3324 : : and convert the case label values to the index type.
3325 : :
3326 : : NB: The type of gimple_switch_index() may be the promoted
3327 : : type, but the case labels retain the original type. */
3328 : :
3329 : 16404 : if (high)
3330 : : {
3331 : : /* This is a case range. Discard empty ranges.
3332 : : If the bounds or the range are equal, turn this
3333 : : into a simple (one-value) case. */
3334 : 16404 : int cmp = tree_int_cst_compare (high, low);
3335 : 16404 : if (cmp < 0)
3336 : : remove_element = true;
3337 : 16404 : else if (cmp == 0)
3338 : : high = NULL_TREE;
3339 : : }
3340 : :
3341 : 1073442 : if (! high)
3342 : : {
3343 : : /* If the simple case value is unreachable, ignore it. */
3344 : 1079326 : if ((TREE_CODE (min_value) == INTEGER_CST
3345 : 1079326 : && tree_int_cst_compare (low, min_value) < 0)
3346 : 2158609 : || (TREE_CODE (max_value) == INTEGER_CST
3347 : 1079283 : && tree_int_cst_compare (low, max_value) > 0))
3348 : : remove_element = true;
3349 : : else
3350 : 1079165 : low = fold_convert (index_type, low);
3351 : : }
3352 : : else
3353 : : {
3354 : : /* If the entire case range is unreachable, ignore it. */
3355 : 5260 : if ((TREE_CODE (min_value) == INTEGER_CST
3356 : 5260 : && tree_int_cst_compare (high, min_value) < 0)
3357 : 10508 : || (TREE_CODE (max_value) == INTEGER_CST
3358 : 5248 : && tree_int_cst_compare (low, max_value) > 0))
3359 : : remove_element = true;
3360 : : else
3361 : : {
3362 : : /* If the lower bound is less than the index type's
3363 : : minimum value, truncate the range bounds. */
3364 : 5248 : if (TREE_CODE (min_value) == INTEGER_CST
3365 : 5248 : && tree_int_cst_compare (low, min_value) < 0)
3366 : : low = min_value;
3367 : 5248 : low = fold_convert (index_type, low);
3368 : :
3369 : : /* If the upper bound is greater than the index type's
3370 : : maximum value, truncate the range bounds. */
3371 : 5248 : if (TREE_CODE (max_value) == INTEGER_CST
3372 : 5248 : && tree_int_cst_compare (high, max_value) > 0)
3373 : : high = max_value;
3374 : 5248 : high = fold_convert (index_type, high);
3375 : :
3376 : : /* We may have folded a case range to a one-value case. */
3377 : 5248 : if (tree_int_cst_equal (low, high))
3378 : 0 : high = NULL_TREE;
3379 : : }
3380 : : }
3381 : :
3382 : 1084586 : CASE_LOW (elt) = low;
3383 : 1084586 : CASE_HIGH (elt) = high;
3384 : : }
3385 : : else
3386 : : {
3387 : 34248 : gcc_assert (!default_case);
3388 : 34248 : default_case = elt;
3389 : : /* The default case must be passed separately to the
3390 : : gimple_build_switch routine. But if DEFAULT_CASEP
3391 : : is NULL, we do not remove the default case (it would
3392 : : be completely lost). */
3393 : 34248 : if (default_casep)
3394 : : remove_element = true;
3395 : : }
3396 : :
3397 : 1084586 : if (remove_element)
3398 : 34421 : labels.ordered_remove (i);
3399 : : else
3400 : 1084413 : i++;
3401 : : }
3402 : 61557 : len = i;
3403 : :
3404 : 61557 : if (!labels.is_empty ())
3405 : 60732 : sort_case_labels (labels);
3406 : :
3407 : 61557 : if (default_casep && !default_case)
3408 : : {
3409 : : /* If the switch has no default label, add one, so that we jump
3410 : : around the switch body. If the labels already cover the whole
3411 : : range of the switch index_type, add the default label pointing
3412 : : to one of the existing labels. */
3413 : 14389 : if (len
3414 : 13925 : && TYPE_MIN_VALUE (index_type)
3415 : 13925 : && TYPE_MAX_VALUE (index_type)
3416 : 28314 : && tree_int_cst_equal (CASE_LOW (labels[0]),
3417 : 13925 : TYPE_MIN_VALUE (index_type)))
3418 : : {
3419 : 4142 : tree low, high = CASE_HIGH (labels[len - 1]);
3420 : 4142 : if (!high)
3421 : 4099 : high = CASE_LOW (labels[len - 1]);
3422 : 4142 : if (tree_int_cst_equal (high, TYPE_MAX_VALUE (index_type)))
3423 : : {
3424 : 64 : tree widest_label = labels[0];
3425 : 132 : for (i = 1; i < len; i++)
3426 : : {
3427 : 85 : high = CASE_LOW (labels[i]);
3428 : 85 : low = CASE_HIGH (labels[i - 1]);
3429 : 85 : if (!low)
3430 : 55 : low = CASE_LOW (labels[i - 1]);
3431 : :
3432 : 85 : if (CASE_HIGH (labels[i]) != NULL_TREE
3433 : 116 : && (CASE_HIGH (widest_label) == NULL_TREE
3434 : 26 : || (wi::gtu_p
3435 : 52 : (wi::to_wide (CASE_HIGH (labels[i]))
3436 : 78 : - wi::to_wide (CASE_LOW (labels[i])),
3437 : 26 : wi::to_wide (CASE_HIGH (widest_label))
3438 : 163 : - wi::to_wide (CASE_LOW (widest_label))))))
3439 : 17 : widest_label = labels[i];
3440 : :
3441 : 85 : if (wi::to_wide (low) + 1 != wi::to_wide (high))
3442 : : break;
3443 : : }
3444 : 64 : if (i == len)
3445 : : {
3446 : : /* Designate the label with the widest range to be the
3447 : : default label. */
3448 : 47 : tree label = CASE_LABEL (widest_label);
3449 : 47 : default_case = build_case_label (NULL_TREE, NULL_TREE,
3450 : : label);
3451 : : }
3452 : : }
3453 : : }
3454 : : }
3455 : :
3456 : 61557 : if (default_casep)
3457 : 48637 : *default_casep = default_case;
3458 : 61557 : }
3459 : :
3460 : : /* Set the location of all statements in SEQ to LOC. */
3461 : :
3462 : : void
3463 : 936996 : gimple_seq_set_location (gimple_seq seq, location_t loc)
3464 : : {
3465 : 1890351 : for (gimple_stmt_iterator i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
3466 : 953355 : gimple_set_location (gsi_stmt (i), loc);
3467 : 936996 : }
3468 : :
3469 : : /* Release SSA_NAMEs in SEQ as well as the GIMPLE statements. */
3470 : :
3471 : : void
3472 : 838848 : gimple_seq_discard (gimple_seq seq)
3473 : : {
3474 : 838848 : gimple_stmt_iterator gsi;
3475 : :
3476 : 1317142 : for (gsi = gsi_start (seq); !gsi_end_p (gsi); )
3477 : : {
3478 : 323815 : gimple *stmt = gsi_stmt (gsi);
3479 : 323815 : gsi_remove (&gsi, true);
3480 : 323815 : release_defs (stmt);
3481 : 323815 : ggc_free (stmt);
3482 : : }
3483 : 838848 : }
3484 : :
3485 : : /* See if STMT now calls function that takes no parameters and if so, drop
3486 : : call arguments. This is used when devirtualization machinery redirects
3487 : : to __builtin_unreachable or __cxa_pure_virtual. */
3488 : :
3489 : : void
3490 : 784065 : maybe_remove_unused_call_args (struct function *fn, gimple *stmt)
3491 : : {
3492 : 784065 : tree decl = gimple_call_fndecl (stmt);
3493 : 784065 : if (TYPE_ARG_TYPES (TREE_TYPE (decl))
3494 : 783248 : && TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))) == void_type_node
3495 : 933307 : && gimple_call_num_args (stmt))
3496 : : {
3497 : 78303 : gimple_set_num_ops (stmt, 3);
3498 : 78303 : update_stmt_fn (fn, stmt);
3499 : : }
3500 : 784065 : }
3501 : :
3502 : : /* Return false if STMT will likely expand to real function call. */
3503 : :
3504 : : bool
3505 : 3064295 : gimple_inexpensive_call_p (gcall *stmt)
3506 : : {
3507 : 3064295 : if (gimple_call_internal_p (stmt))
3508 : : return true;
3509 : 3025311 : tree decl = gimple_call_fndecl (stmt);
3510 : 3025311 : if (decl && is_inexpensive_builtin (decl))
3511 : : return true;
3512 : : return false;
3513 : : }
3514 : :
3515 : : /* Return a non-artificial location for STMT. If STMT does not have
3516 : : location information, get the location from EXPR. */
3517 : :
3518 : : location_t
3519 : 111522 : gimple_or_expr_nonartificial_location (gimple *stmt, tree expr)
3520 : : {
3521 : 111522 : location_t loc = gimple_nonartificial_location (stmt);
3522 : 111522 : if (loc == UNKNOWN_LOCATION && EXPR_HAS_LOCATION (expr))
3523 : 125 : loc = tree_nonartificial_location (expr);
3524 : 111522 : return expansion_point_location_if_in_system_header (loc);
3525 : : }
3526 : :
3527 : :
3528 : : #if CHECKING_P
3529 : :
3530 : : namespace selftest {
3531 : :
3532 : : /* Selftests for core gimple structures. */
3533 : :
3534 : : /* Verify that STMT is pretty-printed as EXPECTED.
3535 : : Helper function for selftests. */
3536 : :
3537 : : static void
3538 : 20 : verify_gimple_pp (const char *expected, gimple *stmt)
3539 : : {
3540 : 20 : pretty_printer pp;
3541 : 20 : pp_gimple_stmt_1 (&pp, stmt, 0 /* spc */, TDF_NONE /* flags */);
3542 : 20 : ASSERT_STREQ (expected, pp_formatted_text (&pp));
3543 : 20 : }
3544 : :
3545 : : /* Build a GIMPLE_ASSIGN equivalent to
3546 : : tmp = 5;
3547 : : and verify various properties of it. */
3548 : :
3549 : : static void
3550 : 4 : test_assign_single ()
3551 : : {
3552 : 4 : tree type = integer_type_node;
3553 : 4 : tree lhs = build_decl (UNKNOWN_LOCATION, VAR_DECL,
3554 : : get_identifier ("tmp"),
3555 : : type);
3556 : 4 : tree rhs = build_int_cst (type, 5);
3557 : 4 : gassign *stmt = gimple_build_assign (lhs, rhs);
3558 : 4 : verify_gimple_pp ("tmp = 5;", stmt);
3559 : :
3560 : 4 : ASSERT_TRUE (is_gimple_assign (stmt));
3561 : 4 : ASSERT_EQ (lhs, gimple_assign_lhs (stmt));
3562 : 4 : ASSERT_EQ (lhs, gimple_get_lhs (stmt));
3563 : 4 : ASSERT_EQ (rhs, gimple_assign_rhs1 (stmt));
3564 : 4 : ASSERT_EQ (NULL, gimple_assign_rhs2 (stmt));
3565 : 4 : ASSERT_EQ (NULL, gimple_assign_rhs3 (stmt));
3566 : 4 : ASSERT_TRUE (gimple_assign_single_p (stmt));
3567 : 8 : ASSERT_EQ (INTEGER_CST, gimple_assign_rhs_code (stmt));
3568 : 4 : }
3569 : :
3570 : : /* Build a GIMPLE_ASSIGN equivalent to
3571 : : tmp = a * b;
3572 : : and verify various properties of it. */
3573 : :
3574 : : static void
3575 : 4 : test_assign_binop ()
3576 : : {
3577 : 4 : tree type = integer_type_node;
3578 : 4 : tree lhs = build_decl (UNKNOWN_LOCATION, VAR_DECL,
3579 : : get_identifier ("tmp"),
3580 : : type);
3581 : 4 : tree a = build_decl (UNKNOWN_LOCATION, VAR_DECL,
3582 : : get_identifier ("a"),
3583 : : type);
3584 : 4 : tree b = build_decl (UNKNOWN_LOCATION, VAR_DECL,
3585 : : get_identifier ("b"),
3586 : : type);
3587 : 4 : gassign *stmt = gimple_build_assign (lhs, MULT_EXPR, a, b);
3588 : 4 : verify_gimple_pp ("tmp = a * b;", stmt);
3589 : :
3590 : 4 : ASSERT_TRUE (is_gimple_assign (stmt));
3591 : 4 : ASSERT_EQ (lhs, gimple_assign_lhs (stmt));
3592 : 4 : ASSERT_EQ (lhs, gimple_get_lhs (stmt));
3593 : 4 : ASSERT_EQ (a, gimple_assign_rhs1 (stmt));
3594 : 8 : ASSERT_EQ (b, gimple_assign_rhs2 (stmt));
3595 : 4 : ASSERT_EQ (NULL, gimple_assign_rhs3 (stmt));
3596 : 4 : ASSERT_FALSE (gimple_assign_single_p (stmt));
3597 : 4 : ASSERT_EQ (MULT_EXPR, gimple_assign_rhs_code (stmt));
3598 : 4 : }
3599 : :
3600 : : /* Build a GIMPLE_NOP and verify various properties of it. */
3601 : :
3602 : : static void
3603 : 4 : test_nop_stmt ()
3604 : : {
3605 : 4 : gimple *stmt = gimple_build_nop ();
3606 : 4 : verify_gimple_pp ("GIMPLE_NOP", stmt);
3607 : 4 : ASSERT_EQ (GIMPLE_NOP, gimple_code (stmt));
3608 : 4 : ASSERT_EQ (NULL, gimple_get_lhs (stmt));
3609 : 4 : ASSERT_FALSE (gimple_assign_single_p (stmt));
3610 : 4 : }
3611 : :
3612 : : /* Build a GIMPLE_RETURN equivalent to
3613 : : return 7;
3614 : : and verify various properties of it. */
3615 : :
3616 : : static void
3617 : 4 : test_return_stmt ()
3618 : : {
3619 : 4 : tree type = integer_type_node;
3620 : 4 : tree val = build_int_cst (type, 7);
3621 : 4 : greturn *stmt = gimple_build_return (val);
3622 : 4 : verify_gimple_pp ("return 7;", stmt);
3623 : :
3624 : 4 : ASSERT_EQ (GIMPLE_RETURN, gimple_code (stmt));
3625 : 4 : ASSERT_EQ (NULL, gimple_get_lhs (stmt));
3626 : 4 : ASSERT_EQ (val, gimple_return_retval (stmt));
3627 : 4 : ASSERT_FALSE (gimple_assign_single_p (stmt));
3628 : 4 : }
3629 : :
3630 : : /* Build a GIMPLE_RETURN equivalent to
3631 : : return;
3632 : : and verify various properties of it. */
3633 : :
3634 : : static void
3635 : 4 : test_return_without_value ()
3636 : : {
3637 : 4 : greturn *stmt = gimple_build_return (NULL);
3638 : 4 : verify_gimple_pp ("return;", stmt);
3639 : :
3640 : 4 : ASSERT_EQ (GIMPLE_RETURN, gimple_code (stmt));
3641 : 4 : ASSERT_EQ (NULL, gimple_get_lhs (stmt));
3642 : 4 : ASSERT_EQ (NULL, gimple_return_retval (stmt));
3643 : 4 : ASSERT_FALSE (gimple_assign_single_p (stmt));
3644 : 4 : }
3645 : :
3646 : : /* Run all of the selftests within this file. */
3647 : :
3648 : : void
3649 : 4 : gimple_cc_tests ()
3650 : : {
3651 : 4 : test_assign_single ();
3652 : 4 : test_assign_binop ();
3653 : 4 : test_nop_stmt ();
3654 : 4 : test_return_stmt ();
3655 : 4 : test_return_without_value ();
3656 : 4 : }
3657 : :
3658 : : } // namespace selftest
3659 : :
3660 : :
3661 : : #endif /* CHECKING_P */
|