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 : 313783258 : gimple_set_code (gimple *g, enum gimple_code code)
134 : : {
135 : 313783258 : 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 : 380853114 : gimple_size (enum gimple_code code, unsigned num_ops)
143 : : {
144 : 380853114 : size_t size = gsstruct_code_size[gss_for_code (code)];
145 : 380853114 : if (num_ops > 0)
146 : 262628881 : size += (sizeof (tree) * (num_ops - 1));
147 : 380853114 : return size;
148 : : }
149 : :
150 : : /* Initialize GIMPLE statement G with CODE and NUM_OPS. */
151 : :
152 : : void
153 : 313783258 : gimple_init (gimple *g, enum gimple_code code, unsigned num_ops)
154 : : {
155 : 313783258 : gimple_set_code (g, code);
156 : 313783258 : 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 : 313783258 : g->modified = 1;
161 : 313783258 : gimple_init_singleton (g);
162 : 313783258 : }
163 : :
164 : : /* Allocate memory for a GIMPLE statement with code CODE and NUM_OPS
165 : : operands. */
166 : :
167 : : gimple *
168 : 311940250 : gimple_alloc (enum gimple_code code, unsigned num_ops MEM_STAT_DECL)
169 : : {
170 : 311940250 : size_t size;
171 : 311940250 : gimple *stmt;
172 : :
173 : 311940250 : size = gimple_size (code, num_ops);
174 : 311940250 : 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 : 311940250 : stmt = ggc_alloc_cleared_gimple_statement_stat (size PASS_MEM_STAT);
182 : 311940250 : gimple_init (stmt, code, num_ops);
183 : 311940250 : return stmt;
184 : : }
185 : :
186 : : /* Set SUBCODE to be the code of the expression computed by statement G. */
187 : :
188 : : static inline void
189 : 225098515 : 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 : 225098515 : gcc_assert (subcode < (1 << 16));
194 : 225098515 : g->subcode = subcode;
195 : 225098515 : }
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 : 214757458 : 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 : 214757458 : gimple_set_subcode (s, subcode);
212 : :
213 : 214757458 : return s;
214 : : }
215 : :
216 : :
217 : : /* Build a GIMPLE_RETURN statement returning RETVAL. */
218 : :
219 : : greturn *
220 : 3598791 : gimple_build_return (tree retval)
221 : : {
222 : 3598791 : greturn *s
223 : 3598791 : = as_a <greturn *> (gimple_build_with_ops (GIMPLE_RETURN, ERROR_MARK,
224 : : 2));
225 : 3598791 : if (retval)
226 : 2185518 : gimple_return_set_retval (s, retval);
227 : 3598791 : return s;
228 : : }
229 : :
230 : : /* Reset alias information on call S. */
231 : :
232 : : void
233 : 17655933 : gimple_call_reset_alias_info (gcall *s)
234 : : {
235 : 17655933 : if (gimple_call_flags (s) & ECF_CONST)
236 : 2177252 : memset (gimple_call_use_set (s), 0, sizeof (struct pt_solution));
237 : : else
238 : 15478681 : pt_solution_reset (gimple_call_use_set (s));
239 : 17655933 : if (gimple_call_flags (s) & (ECF_CONST|ECF_PURE|ECF_NOVOPS))
240 : 3376457 : memset (gimple_call_clobber_set (s), 0, sizeof (struct pt_solution));
241 : : else
242 : 14279476 : pt_solution_reset (gimple_call_clobber_set (s));
243 : 17655933 : }
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 : 11835705 : gimple_build_call_1 (tree fn, unsigned nargs)
252 : : {
253 : 11835705 : gcall *s
254 : 23671410 : = as_a <gcall *> (gimple_build_with_ops (GIMPLE_CALL, ERROR_MARK,
255 : : nargs + 3));
256 : 11835705 : if (TREE_CODE (fn) == FUNCTION_DECL)
257 : 11624741 : fn = build_fold_addr_expr (fn);
258 : 11835705 : gimple_set_op (s, 1, fn);
259 : 11835705 : gimple_call_set_fntype (s, TREE_TYPE (TREE_TYPE (fn)));
260 : 11835705 : gimple_call_reset_alias_info (s);
261 : 11835705 : 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 : 583090 : gimple_build_call_vec (tree fn, const vec<tree> &args)
270 : : {
271 : 583090 : unsigned i;
272 : 583090 : unsigned nargs = args.length ();
273 : 583090 : gcall *call = gimple_build_call_1 (fn, nargs);
274 : :
275 : 2621631 : for (i = 0; i < nargs; i++)
276 : 1455451 : gimple_call_set_arg (call, i, args[i]);
277 : :
278 : 583090 : 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 : 603259 : gimple_build_call (tree fn, unsigned nargs, ...)
287 : : {
288 : 603259 : va_list ap;
289 : 603259 : gcall *call;
290 : 603259 : unsigned i;
291 : :
292 : 603259 : gcc_assert (TREE_CODE (fn) == FUNCTION_DECL || is_gimple_call_addr (fn));
293 : :
294 : 603259 : call = gimple_build_call_1 (fn, nargs);
295 : :
296 : 603259 : va_start (ap, nargs);
297 : 1261825 : for (i = 0; i < nargs; i++)
298 : 658566 : gimple_call_set_arg (call, i, va_arg (ap, tree));
299 : 603259 : va_end (ap);
300 : :
301 : 603259 : 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 : 2427 : gimple_build_call_valist (tree fn, unsigned nargs, va_list ap)
310 : : {
311 : 2427 : gcall *call;
312 : 2427 : unsigned i;
313 : :
314 : 2427 : gcc_assert (TREE_CODE (fn) == FUNCTION_DECL || is_gimple_call_addr (fn));
315 : :
316 : 2427 : call = gimple_build_call_1 (fn, nargs);
317 : :
318 : 11792 : for (i = 0; i < nargs; i++)
319 : 6938 : gimple_call_set_arg (call, i, va_arg (ap, tree));
320 : :
321 : 2427 : 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 : 860603 : gimple_build_call_internal_1 (enum internal_fn fn, unsigned nargs)
331 : : {
332 : 860603 : gcall *s
333 : 1721206 : = as_a <gcall *> (gimple_build_with_ops (GIMPLE_CALL, ERROR_MARK,
334 : : nargs + 3));
335 : 860603 : s->subcode |= GF_CALL_INTERNAL;
336 : 860603 : gimple_call_set_internal_fn (s, fn);
337 : 860603 : gimple_call_reset_alias_info (s);
338 : 860603 : 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 : 472851 : gimple_build_call_internal (enum internal_fn fn, unsigned nargs, ...)
347 : : {
348 : 472851 : va_list ap;
349 : 472851 : gcall *call;
350 : 472851 : unsigned i;
351 : :
352 : 472851 : call = gimple_build_call_internal_1 (fn, nargs);
353 : 472851 : va_start (ap, nargs);
354 : 1901981 : for (i = 0; i < nargs; i++)
355 : 1429130 : gimple_call_set_arg (call, i, va_arg (ap, tree));
356 : 472851 : va_end (ap);
357 : :
358 : 472851 : 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 : 387749 : gimple_build_call_internal_vec (enum internal_fn fn, const vec<tree> &args)
367 : : {
368 : 387749 : unsigned i, nargs;
369 : 387749 : gcall *call;
370 : :
371 : 387749 : nargs = args.length ();
372 : 387749 : call = gimple_build_call_internal_1 (fn, nargs);
373 : 1928587 : for (i = 0; i < nargs; i++)
374 : 1153089 : gimple_call_set_arg (call, i, args[i]);
375 : :
376 : 387749 : 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 : 10646932 : gimple_build_call_from_tree (tree t, tree fnptrtype)
386 : : {
387 : 10646932 : unsigned i, nargs;
388 : 10646932 : gcall *call;
389 : :
390 : 10646932 : gcc_assert (TREE_CODE (t) == CALL_EXPR);
391 : :
392 : 10646932 : nargs = call_expr_nargs (t);
393 : :
394 : 10646932 : tree fndecl = NULL_TREE;
395 : 10646932 : if (CALL_EXPR_FN (t) == NULL_TREE)
396 : 3 : call = gimple_build_call_internal_1 (CALL_EXPR_IFN (t), nargs);
397 : : else
398 : : {
399 : 10646929 : fndecl = get_callee_fndecl (t);
400 : 10808937 : call = gimple_build_call_1 (fndecl ? fndecl : CALL_EXPR_FN (t), nargs);
401 : : }
402 : :
403 : 29646258 : for (i = 0; i < nargs; i++)
404 : 18999326 : gimple_call_set_arg (call, i, CALL_EXPR_ARG (t, i));
405 : :
406 : 10646932 : gimple_set_block (call, TREE_BLOCK (t));
407 : 10646932 : gimple_set_location (call, EXPR_LOCATION (t));
408 : :
409 : : /* Carry all the CALL_EXPR flags to the new GIMPLE_CALL. */
410 : 10646932 : gimple_call_set_chain (call, CALL_EXPR_STATIC_CHAIN (t));
411 : 10646932 : gimple_call_set_tail (call, CALL_EXPR_TAILCALL (t));
412 : 10646932 : gimple_call_set_must_tail (call, CALL_EXPR_MUST_TAIL_CALL (t));
413 : 10646932 : gimple_call_set_return_slot_opt (call, CALL_EXPR_RETURN_SLOT_OPT (t));
414 : 10646932 : if (fndecl
415 : 10484921 : && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
416 : 12919279 : && ALLOCA_FUNCTION_CODE_P (DECL_FUNCTION_CODE (fndecl)))
417 : 41489 : gimple_call_set_alloca_for_var (call, CALL_ALLOCA_FOR_VAR_P (t));
418 : 10605443 : else if (fndecl
419 : 21048875 : && (DECL_IS_OPERATOR_NEW_P (fndecl)
420 : 10391451 : || DECL_IS_OPERATOR_DELETE_P (fndecl)))
421 : 128183 : gimple_call_set_from_new_or_delete (call, CALL_FROM_NEW_OR_DELETE_P (t));
422 : : else
423 : 10477260 : gimple_call_set_from_thunk (call, CALL_FROM_THUNK_P (t));
424 : 10646932 : gimple_call_set_va_arg_pack (call, CALL_EXPR_VA_ARG_PACK (t));
425 : 10646932 : gimple_call_set_nothrow (call, TREE_NOTHROW (t));
426 : 10646932 : if (fndecl)
427 : 31616774 : gimple_call_set_expected_throw (call,
428 : 10484921 : flags_from_decl_or_type (fndecl)
429 : 10484921 : & ECF_XTHROW);
430 : 10646932 : gimple_call_set_by_descriptor (call, CALL_EXPR_BY_DESCRIPTOR (t));
431 : 10646932 : copy_warning (call, t);
432 : :
433 : 10646932 : if (fnptrtype)
434 : : {
435 : 10646817 : 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 : 10646817 : if (!fndecl)
441 : : {
442 : 161896 : gcc_assert (POINTER_TYPE_P (fnptrtype));
443 : 161896 : tree fntype = TREE_TYPE (fnptrtype);
444 : :
445 : 161896 : if (lookup_attribute ("nocf_check", TYPE_ATTRIBUTES (fntype)))
446 : 21 : gimple_call_set_nocf_check (call, true);
447 : : }
448 : : }
449 : :
450 : 10646932 : return call;
451 : : }
452 : :
453 : : /* Build a gcall to __builtin_unreachable as rewritten by
454 : : -fsanitize=unreachable. */
455 : :
456 : : gcall *
457 : 170774 : gimple_build_builtin_unreachable (location_t loc)
458 : : {
459 : 170774 : tree data = NULL_TREE;
460 : 170774 : tree fn = sanitize_unreachable_fn (&data, loc);
461 : 170774 : gcall *g = gimple_build_call (fn, data != NULL_TREE, data);
462 : 170774 : gimple_call_set_ctrl_altering (g, true);
463 : 170774 : gimple_set_location (g, loc);
464 : 170774 : 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 : 87190968 : gimple_build_assign (tree lhs, tree rhs MEM_STAT_DECL)
474 : : {
475 : 87190968 : enum tree_code subcode;
476 : 87190968 : tree op1, op2, op3;
477 : :
478 : 87190968 : extract_ops_from_tree (rhs, &subcode, &op1, &op2, &op3);
479 : 87190968 : 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 : 93052140 : gimple_build_assign_1 (tree lhs, enum tree_code subcode, tree op1,
488 : : tree op2, tree op3 MEM_STAT_DECL)
489 : : {
490 : 93052140 : unsigned num_ops;
491 : 93052140 : gassign *p;
492 : :
493 : : /* Need 1 operand for LHS and 1 or 2 for the RHS (depending on the
494 : : code). */
495 : 93052140 : num_ops = get_gimple_rhs_num_ops (subcode) + 1;
496 : :
497 : 186104280 : p = as_a <gassign *> (
498 : : gimple_build_with_ops_stat (GIMPLE_ASSIGN, (unsigned)subcode, num_ops
499 : : PASS_MEM_STAT));
500 : 93052140 : gimple_assign_set_lhs (p, lhs);
501 : : /* For COND_EXPR, op1 should not be a comparison. */
502 : 93052140 : if (op1 && subcode == COND_EXPR)
503 : 243194 : gcc_assert (!COMPARISON_CLASS_P (op1));
504 : 93052140 : gimple_assign_set_rhs1 (p, op1);
505 : 93052140 : if (op2)
506 : : {
507 : 14425045 : gcc_assert (num_ops > 2);
508 : 14425045 : gimple_assign_set_rhs2 (p, op2);
509 : : }
510 : :
511 : 93052140 : if (op3)
512 : : {
513 : 353320 : gcc_assert (num_ops > 3);
514 : 353320 : gimple_assign_set_rhs3 (p, op3);
515 : : }
516 : :
517 : 93052140 : return p;
518 : : }
519 : :
520 : : /* Build a GIMPLE_ASSIGN statement with subcode SUBCODE and operands
521 : : OP1, OP2 and OP3. */
522 : :
523 : : gassign *
524 : 88474227 : gimple_build_assign (tree lhs, enum tree_code subcode, tree op1,
525 : : tree op2, tree op3 MEM_STAT_DECL)
526 : : {
527 : 88474227 : 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 : 3249451 : gimple_build_assign (tree lhs, enum tree_code subcode, tree op1,
535 : : tree op2 MEM_STAT_DECL)
536 : : {
537 : 3249451 : return gimple_build_assign_1 (lhs, subcode, op1, op2, NULL_TREE
538 : 3249451 : PASS_MEM_STAT);
539 : : }
540 : :
541 : : /* Build a GIMPLE_ASSIGN statement with subcode SUBCODE and operand OP1. */
542 : :
543 : : gassign *
544 : 1328462 : gimple_build_assign (tree lhs, enum tree_code subcode, tree op1 MEM_STAT_DECL)
545 : : {
546 : 1328462 : return gimple_build_assign_1 (lhs, subcode, op1, NULL_TREE, NULL_TREE
547 : 1328462 : 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 : 10578220 : gimple_build_cond (enum tree_code pred_code, tree lhs, tree rhs,
559 : : tree t_label, tree f_label)
560 : : {
561 : 10578220 : gcond *p;
562 : :
563 : 10578220 : gcc_assert (TREE_CODE_CLASS (pred_code) == tcc_comparison);
564 : 21156440 : p = as_a <gcond *> (gimple_build_with_ops (GIMPLE_COND, pred_code, 4));
565 : 10578220 : gimple_cond_set_lhs (p, lhs);
566 : 10578220 : gimple_cond_set_rhs (p, rhs);
567 : 10578220 : gimple_cond_set_true_label (p, t_label);
568 : 10578220 : gimple_cond_set_false_label (p, f_label);
569 : 10578220 : 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 : 99659 : gimple_build_cond_from_tree (tree cond, tree t_label, tree f_label)
577 : : {
578 : 99659 : enum tree_code code;
579 : 99659 : tree lhs, rhs;
580 : :
581 : 99659 : gimple_cond_get_ops_from_tree (cond, &code, &lhs, &rhs);
582 : 99659 : 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 : 416681 : gimple_cond_set_condition_from_tree (gcond *stmt, tree cond)
590 : : {
591 : 416681 : enum tree_code code;
592 : 416681 : tree lhs, rhs;
593 : :
594 : 416681 : gimple_cond_get_ops_from_tree (cond, &code, &lhs, &rhs);
595 : 416681 : gimple_cond_set_condition (stmt, code, lhs, rhs);
596 : 416681 : }
597 : :
598 : : /* Build a GIMPLE_LABEL statement for LABEL. */
599 : :
600 : : glabel *
601 : 19400924 : gimple_build_label (tree label)
602 : : {
603 : 19400924 : glabel *p
604 : 19400924 : = as_a <glabel *> (gimple_build_with_ops (GIMPLE_LABEL, ERROR_MARK, 1));
605 : 19400924 : gimple_label_set_label (p, label);
606 : 19400924 : return p;
607 : : }
608 : :
609 : : /* Build a GIMPLE_GOTO statement to label DEST. */
610 : :
611 : : ggoto *
612 : 7049971 : gimple_build_goto (tree dest)
613 : : {
614 : 7049971 : ggoto *p
615 : 7049971 : = as_a <ggoto *> (gimple_build_with_ops (GIMPLE_GOTO, ERROR_MARK, 1));
616 : 7049971 : gimple_goto_set_dest (p, dest);
617 : 7049971 : return p;
618 : : }
619 : :
620 : :
621 : : /* Build a GIMPLE_NOP statement. */
622 : :
623 : : gimple *
624 : 15271960 : gimple_build_nop (void)
625 : : {
626 : 15271960 : 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 : 7434467 : gimple_build_bind (tree vars, gimple_seq body, tree block)
636 : : {
637 : 7434467 : gbind *p = as_a <gbind *> (gimple_alloc (GIMPLE_BIND, 0));
638 : 7434467 : gimple_bind_set_vars (p, vars);
639 : 7434467 : if (body)
640 : 1326393 : gimple_bind_set_body (p, body);
641 : 7434467 : if (block)
642 : 5963073 : gimple_bind_set_block (p, block);
643 : 7434467 : 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 : 101304 : gimple_build_asm_1 (const char *string, unsigned ninputs, unsigned noutputs,
656 : : unsigned nclobbers, unsigned nlabels)
657 : : {
658 : 101304 : gasm *p;
659 : 101304 : int size = strlen (string);
660 : :
661 : 101304 : p = as_a <gasm *> (
662 : 101304 : gimple_build_with_ops (GIMPLE_ASM, ERROR_MARK,
663 : : ninputs + noutputs + nclobbers + nlabels));
664 : :
665 : 101304 : p->ni = ninputs;
666 : 101304 : p->no = noutputs;
667 : 101304 : p->nc = nclobbers;
668 : 101304 : p->nl = nlabels;
669 : 101304 : p->string = ggc_alloc_string (string, size);
670 : :
671 : 101304 : if (GATHER_STATISTICS)
672 : : gimple_alloc_sizes[(int) gimple_alloc_kind (GIMPLE_ASM)] += size;
673 : :
674 : 101304 : 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 : 101304 : 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 : 101304 : gasm *p;
694 : 101304 : unsigned i;
695 : :
696 : 198876 : 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 : 326854 : for (i = 0; i < vec_safe_length (inputs); i++)
703 : 45719 : gimple_asm_set_input_op (p, i, (*inputs)[i]);
704 : :
705 : 259357 : for (i = 0; i < vec_safe_length (outputs); i++)
706 : 64116 : gimple_asm_set_output_op (p, i, (*outputs)[i]);
707 : :
708 : 357527 : for (i = 0; i < vec_safe_length (clobbers); i++)
709 : 94478 : gimple_asm_set_clobber_op (p, i, (*clobbers)[i]);
710 : :
711 : 102101 : for (i = 0; i < vec_safe_length (labels); i++)
712 : 797 : gimple_asm_set_label_op (p, i, (*labels)[i]);
713 : :
714 : 101304 : 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 : 39603 : gimple_build_catch (tree types, gimple_seq handler)
724 : : {
725 : 39603 : gcatch *p = as_a <gcatch *> (gimple_alloc (GIMPLE_CATCH, 0));
726 : 39603 : gimple_catch_set_types (p, types);
727 : 39603 : if (handler)
728 : 39591 : gimple_catch_set_handler (p, handler);
729 : :
730 : 39603 : 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 : 4632 : gimple_build_eh_filter (tree types, gimple_seq failure)
740 : : {
741 : 4632 : geh_filter *p = as_a <geh_filter *> (gimple_alloc (GIMPLE_EH_FILTER, 0));
742 : 4632 : gimple_eh_filter_set_types (p, types);
743 : 4632 : if (failure)
744 : 4632 : gimple_eh_filter_set_failure (p, failure);
745 : :
746 : 4632 : return p;
747 : : }
748 : :
749 : : /* Build a GIMPLE_EH_MUST_NOT_THROW statement. */
750 : :
751 : : geh_mnt *
752 : 1309876 : gimple_build_eh_must_not_throw (tree decl)
753 : : {
754 : 1309876 : geh_mnt *p = as_a <geh_mnt *> (gimple_alloc (GIMPLE_EH_MUST_NOT_THROW, 0));
755 : :
756 : 1309876 : gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
757 : 1309876 : gcc_assert (flags_from_decl_or_type (decl) & ECF_NORETURN);
758 : 1309876 : gimple_eh_must_not_throw_set_fndecl (p, decl);
759 : :
760 : 1309876 : return p;
761 : : }
762 : :
763 : : /* Build a GIMPLE_EH_ELSE statement. */
764 : :
765 : : geh_else *
766 : 363 : gimple_build_eh_else (gimple_seq n_body, gimple_seq e_body)
767 : : {
768 : 363 : geh_else *p = as_a <geh_else *> (gimple_alloc (GIMPLE_EH_ELSE, 0));
769 : 363 : gimple_eh_else_set_n_body (p, n_body);
770 : 363 : gimple_eh_else_set_e_body (p, e_body);
771 : 363 : 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 : 3173346 : gimple_build_try (gimple_seq eval, gimple_seq cleanup,
783 : : enum gimple_try_flags kind)
784 : : {
785 : 3173346 : gtry *p;
786 : :
787 : 3173346 : gcc_assert (kind == GIMPLE_TRY_CATCH || kind == GIMPLE_TRY_FINALLY);
788 : 3173346 : p = as_a <gtry *> (gimple_alloc (GIMPLE_TRY, 0));
789 : 3173346 : gimple_set_subcode (p, kind);
790 : 3173346 : if (eval)
791 : 3055896 : gimple_try_set_eval (p, eval);
792 : 3173346 : if (cleanup)
793 : 3173346 : gimple_try_set_cleanup (p, cleanup);
794 : :
795 : 3173346 : return p;
796 : : }
797 : :
798 : : /* Construct a GIMPLE_WITH_CLEANUP_EXPR statement.
799 : :
800 : : CLEANUP is the cleanup expression. */
801 : :
802 : : gimple *
803 : 612207 : gimple_build_wce (gimple_seq cleanup)
804 : : {
805 : 612207 : gimple *p = gimple_alloc (GIMPLE_WITH_CLEANUP_EXPR, 0);
806 : 612207 : if (cleanup)
807 : 612207 : gimple_wce_set_cleanup (p, cleanup);
808 : :
809 : 612207 : return p;
810 : : }
811 : :
812 : :
813 : : /* Build a GIMPLE_RESX statement. */
814 : :
815 : : gresx *
816 : 885797 : gimple_build_resx (int region)
817 : : {
818 : 885797 : gresx *p
819 : 885797 : = as_a <gresx *> (gimple_build_with_ops (GIMPLE_RESX, ERROR_MARK, 0));
820 : 885797 : p->region = region;
821 : 885797 : 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 : 71209 : gimple_build_switch_nlabels (unsigned nlabels, tree index, tree default_label)
832 : : {
833 : : /* nlabels + 1 default label + 1 index. */
834 : 71209 : gcc_checking_assert (default_label);
835 : 142418 : gswitch *p = as_a <gswitch *> (gimple_build_with_ops (GIMPLE_SWITCH,
836 : : ERROR_MARK,
837 : : 1 + 1 + nlabels));
838 : 71209 : gimple_switch_set_index (p, index);
839 : 71209 : gimple_switch_set_default_label (p, default_label);
840 : 71209 : 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 : 71209 : gimple_build_switch (tree index, tree default_label, const vec<tree> &args)
851 : : {
852 : 71209 : unsigned i, nlabels = args.length ();
853 : :
854 : 71209 : gswitch *p = gimple_build_switch_nlabels (nlabels, index, default_label);
855 : :
856 : : /* Copy the labels from the vector to the switch statement. */
857 : 1276239 : for (i = 0; i < nlabels; i++)
858 : 1133821 : gimple_switch_set_label (p, i + 1, args[i]);
859 : :
860 : 71209 : return p;
861 : : }
862 : :
863 : : /* Build a GIMPLE_EH_DISPATCH statement. */
864 : :
865 : : geh_dispatch *
866 : 41648 : gimple_build_eh_dispatch (int region)
867 : : {
868 : 41648 : geh_dispatch *p
869 : 41648 : = as_a <geh_dispatch *> (
870 : : gimple_build_with_ops (GIMPLE_EH_DISPATCH, ERROR_MARK, 0));
871 : 41648 : p->region = region;
872 : 41648 : 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 : 60300527 : gimple_build_debug_bind (tree var, tree value, gimple *stmt MEM_STAT_DECL)
881 : : {
882 : 60300527 : gdebug *p
883 : 60300527 : = as_a <gdebug *> (gimple_build_with_ops_stat (GIMPLE_DEBUG,
884 : : (unsigned)GIMPLE_DEBUG_BIND, 2
885 : : PASS_MEM_STAT));
886 : 60300527 : gimple_debug_bind_set_var (p, var);
887 : 60300527 : gimple_debug_bind_set_value (p, value);
888 : 60300527 : if (stmt)
889 : 59253351 : gimple_set_location (p, gimple_location (stmt));
890 : :
891 : 60300527 : 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 : 605965 : gimple_build_debug_source_bind (tree var, tree value,
901 : : gimple *stmt MEM_STAT_DECL)
902 : : {
903 : 605965 : gdebug *p
904 : 605965 : = as_a <gdebug *> (
905 : : gimple_build_with_ops_stat (GIMPLE_DEBUG,
906 : : (unsigned)GIMPLE_DEBUG_SOURCE_BIND, 2
907 : : PASS_MEM_STAT));
908 : :
909 : 605965 : gimple_debug_source_bind_set_var (p, var);
910 : 605965 : gimple_debug_source_bind_set_value (p, value);
911 : 605965 : if (stmt)
912 : 467861 : gimple_set_location (p, gimple_location (stmt));
913 : :
914 : 605965 : return p;
915 : : }
916 : :
917 : :
918 : : /* Build a new GIMPLE_DEBUG_BEGIN_STMT statement in BLOCK at
919 : : LOCATION. */
920 : :
921 : : gdebug *
922 : 2428491 : gimple_build_debug_begin_stmt (tree block, location_t location
923 : : MEM_STAT_DECL)
924 : : {
925 : 2428491 : gdebug *p
926 : 2428491 : = as_a <gdebug *> (
927 : : gimple_build_with_ops_stat (GIMPLE_DEBUG,
928 : : (unsigned)GIMPLE_DEBUG_BEGIN_STMT, 0
929 : : PASS_MEM_STAT));
930 : :
931 : 2428491 : gimple_set_location (p, location);
932 : 2428491 : gimple_set_block (p, block);
933 : 2428491 : cfun->debug_marker_count++;
934 : :
935 : 2428491 : 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 : 3946163 : gimple_build_debug_inline_entry (tree block, location_t location
944 : : MEM_STAT_DECL)
945 : : {
946 : 3946163 : gdebug *p
947 : 3946163 : = as_a <gdebug *> (
948 : : gimple_build_with_ops_stat (GIMPLE_DEBUG,
949 : : (unsigned)GIMPLE_DEBUG_INLINE_ENTRY, 0
950 : : PASS_MEM_STAT));
951 : :
952 : 3946163 : gimple_set_location (p, location);
953 : 3946163 : gimple_set_block (p, block);
954 : 3946163 : cfun->debug_marker_count++;
955 : :
956 : 3946163 : 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 : 53332 : gimple_build_omp_for (gimple_seq body, int kind, tree clauses, size_t collapse,
989 : : gimple_seq pre_body)
990 : : {
991 : 53332 : gomp_for *p = as_a <gomp_for *> (gimple_alloc (GIMPLE_OMP_FOR, 0));
992 : 53332 : if (body)
993 : 49480 : gimple_omp_set_body (p, body);
994 : 53332 : gimple_omp_for_set_clauses (p, clauses);
995 : 53332 : gimple_omp_for_set_kind (p, kind);
996 : 53332 : p->collapse = collapse;
997 : 53332 : p->iter = ggc_cleared_vec_alloc<gimple_omp_for_iter> (collapse);
998 : :
999 : 53332 : if (pre_body)
1000 : 3561 : gimple_omp_for_set_pre_body (p, pre_body);
1001 : :
1002 : 53332 : 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 : 18353 : gimple_build_omp_parallel (gimple_seq body, tree clauses, tree child_fn,
1015 : : tree data_arg)
1016 : : {
1017 : 18353 : gomp_parallel *p
1018 : 18353 : = as_a <gomp_parallel *> (gimple_alloc (GIMPLE_OMP_PARALLEL, 0));
1019 : 18353 : if (body)
1020 : 18156 : gimple_omp_set_body (p, body);
1021 : 18353 : gimple_omp_parallel_set_clauses (p, clauses);
1022 : 18353 : gimple_omp_parallel_set_child_fn (p, child_fn);
1023 : 18353 : gimple_omp_parallel_set_data_arg (p, data_arg);
1024 : :
1025 : 18353 : 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 : 5423 : 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 : 5423 : gomp_task *p = as_a <gomp_task *> (gimple_alloc (GIMPLE_OMP_TASK, 0));
1044 : 5423 : if (body)
1045 : 5333 : gimple_omp_set_body (p, body);
1046 : 5423 : gimple_omp_task_set_clauses (p, clauses);
1047 : 5423 : gimple_omp_task_set_child_fn (p, child_fn);
1048 : 5423 : gimple_omp_task_set_data_arg (p, data_arg);
1049 : 5423 : gimple_omp_task_set_copy_fn (p, copy_fn);
1050 : 5423 : gimple_omp_task_set_arg_size (p, arg_size);
1051 : 5423 : gimple_omp_task_set_arg_align (p, arg_align);
1052 : :
1053 : 5423 : 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 : 791 : gimple_build_omp_structured_block (gimple_seq body)
1078 : : {
1079 : 791 : gimple *p = gimple_alloc (GIMPLE_OMP_STRUCTURED_BLOCK, 0);
1080 : 791 : if (body)
1081 : 791 : gimple_omp_set_body (p, body);
1082 : :
1083 : 791 : 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 : 51793 : gimple_build_omp_continue (tree control_def, tree control_use)
1141 : : {
1142 : 51793 : gomp_continue *p
1143 : 51793 : = as_a <gomp_continue *> (gimple_alloc (GIMPLE_OMP_CONTINUE, 0));
1144 : 51793 : gimple_omp_continue_set_control_def (p, control_def);
1145 : 51793 : gimple_omp_continue_set_control_use (p, control_use);
1146 : 51793 : 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 : 100848 : gimple_build_omp_return (bool wait_p)
1173 : : {
1174 : 100848 : gimple *p = gimple_alloc (GIMPLE_OMP_RETURN, 0);
1175 : 100848 : if (wait_p)
1176 : 37661 : gimple_omp_return_set_nowait (p);
1177 : :
1178 : 100848 : 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 : 1274 : gimple_build_omp_single (gimple_seq body, tree clauses)
1237 : : {
1238 : 1274 : gomp_single *p
1239 : 1274 : = as_a <gomp_single *> (gimple_alloc (GIMPLE_OMP_SINGLE, 0));
1240 : 1274 : if (body)
1241 : 1165 : gimple_omp_set_body (p, body);
1242 : 1274 : gimple_omp_single_set_clauses (p, clauses);
1243 : :
1244 : 1274 : 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 : 846 : gimple_build_omp_dispatch (gimple_seq body, tree clauses)
1272 : : {
1273 : 846 : gimple *p = gimple_alloc (GIMPLE_OMP_DISPATCH, 0);
1274 : 846 : gimple_omp_dispatch_set_clauses (p, clauses);
1275 : 846 : if (body)
1276 : 846 : gimple_omp_set_body (p, body);
1277 : :
1278 : 846 : return p;
1279 : : }
1280 : :
1281 : : /* Build a GIMPLE_OMP_INTEROP statement.
1282 : :
1283 : : CLAUSES are any of the OMP interop construct's clauses. */
1284 : :
1285 : : gimple *
1286 : 612 : gimple_build_omp_interop (tree clauses)
1287 : : {
1288 : 612 : gimple *p = gimple_alloc (GIMPLE_OMP_INTEROP, 0);
1289 : 612 : gimple_omp_interop_set_clauses (p, clauses);
1290 : :
1291 : 612 : return p;
1292 : : }
1293 : :
1294 : : /* Build a GIMPLE_OMP_TARGET statement.
1295 : :
1296 : : BODY is the sequence of statements that will be executed.
1297 : : KIND is the kind of the region.
1298 : : CLAUSES are any of the construct's clauses.
1299 : : ITERATOR_LOOPS is an optional sequence containing constructed loops
1300 : : for OpenMP iterators. */
1301 : :
1302 : : gomp_target *
1303 : 41797 : gimple_build_omp_target (gimple_seq body, int kind, tree clauses,
1304 : : gimple_seq iterator_loops)
1305 : : {
1306 : 41797 : gomp_target *p
1307 : 41797 : = as_a <gomp_target *> (gimple_alloc (GIMPLE_OMP_TARGET, 0));
1308 : 41797 : if (body)
1309 : 28432 : gimple_omp_set_body (p, body);
1310 : 41797 : gimple_omp_target_set_clauses (p, clauses);
1311 : 41797 : gimple_omp_target_set_kind (p, kind);
1312 : 41797 : gimple_omp_target_set_iterator_loops (p, iterator_loops);
1313 : :
1314 : 41797 : return p;
1315 : : }
1316 : :
1317 : :
1318 : : /* Build a GIMPLE_OMP_TEAMS statement.
1319 : :
1320 : : BODY is the sequence of statements that will be executed.
1321 : : CLAUSES are any of the OMP teams construct's clauses. */
1322 : :
1323 : : gomp_teams *
1324 : 8774 : gimple_build_omp_teams (gimple_seq body, tree clauses)
1325 : : {
1326 : 8774 : gomp_teams *p = as_a <gomp_teams *> (gimple_alloc (GIMPLE_OMP_TEAMS, 0));
1327 : 8774 : if (body)
1328 : 8774 : gimple_omp_set_body (p, body);
1329 : 8774 : gimple_omp_teams_set_clauses (p, clauses);
1330 : :
1331 : 8774 : return p;
1332 : : }
1333 : :
1334 : :
1335 : : /* Build a GIMPLE_OMP_ATOMIC_LOAD statement. */
1336 : :
1337 : : gomp_atomic_load *
1338 : 10306 : gimple_build_omp_atomic_load (tree lhs, tree rhs, enum omp_memory_order mo)
1339 : : {
1340 : 10306 : gomp_atomic_load *p
1341 : 10306 : = as_a <gomp_atomic_load *> (gimple_alloc (GIMPLE_OMP_ATOMIC_LOAD, 0));
1342 : 10306 : gimple_omp_atomic_load_set_lhs (p, lhs);
1343 : 10306 : gimple_omp_atomic_load_set_rhs (p, rhs);
1344 : 10306 : gimple_omp_atomic_set_memory_order (p, mo);
1345 : 10306 : return p;
1346 : : }
1347 : :
1348 : : /* Build a GIMPLE_OMP_ATOMIC_STORE statement.
1349 : :
1350 : : VAL is the value we are storing. */
1351 : :
1352 : : gomp_atomic_store *
1353 : 10306 : gimple_build_omp_atomic_store (tree val, enum omp_memory_order mo)
1354 : : {
1355 : 10306 : gomp_atomic_store *p
1356 : 10306 : = as_a <gomp_atomic_store *> (gimple_alloc (GIMPLE_OMP_ATOMIC_STORE, 0));
1357 : 10306 : gimple_omp_atomic_store_set_val (p, val);
1358 : 10306 : gimple_omp_atomic_set_memory_order (p, mo);
1359 : 10306 : return p;
1360 : : }
1361 : :
1362 : : /* Build a GIMPLE_ASSUME statement. */
1363 : :
1364 : : gimple *
1365 : 124 : gimple_build_assume (tree guard, gimple_seq body)
1366 : : {
1367 : 124 : gimple_statement_assume *p
1368 : 124 : = as_a <gimple_statement_assume *> (gimple_alloc (GIMPLE_ASSUME, 0));
1369 : 124 : gimple_assume_set_guard (p, guard);
1370 : 124 : *gimple_assume_body_ptr (p) = body;
1371 : 124 : return p;
1372 : : }
1373 : :
1374 : : /* Build a GIMPLE_TRANSACTION statement. */
1375 : :
1376 : : gtransaction *
1377 : 545 : gimple_build_transaction (gimple_seq body)
1378 : : {
1379 : 545 : gtransaction *p
1380 : 545 : = as_a <gtransaction *> (gimple_alloc (GIMPLE_TRANSACTION, 0));
1381 : 545 : gimple_transaction_set_body (p, body);
1382 : 545 : gimple_transaction_set_label_norm (p, 0);
1383 : 545 : gimple_transaction_set_label_uninst (p, 0);
1384 : 545 : gimple_transaction_set_label_over (p, 0);
1385 : 545 : return p;
1386 : : }
1387 : :
1388 : : #if defined ENABLE_GIMPLE_CHECKING
1389 : : /* Complain of a gimple type mismatch and die. */
1390 : :
1391 : : void
1392 : 0 : gimple_check_failed (const gimple *gs, const char *file, int line,
1393 : : const char *function, enum gimple_code code,
1394 : : enum tree_code subcode)
1395 : : {
1396 : 0 : internal_error ("gimple check: expected %s(%s), have %s(%s) in %s, at %s:%d",
1397 : 0 : gimple_code_name[code],
1398 : : get_tree_code_name (subcode),
1399 : 0 : gimple_code_name[gimple_code (gs)],
1400 : 0 : gs->subcode > 0
1401 : 0 : ? get_tree_code_name ((enum tree_code) gs->subcode)
1402 : : : "",
1403 : : function, trim_filename (file), line);
1404 : : }
1405 : : #endif /* ENABLE_GIMPLE_CHECKING */
1406 : :
1407 : :
1408 : : /* Link gimple statement GS to the end of the sequence *SEQ_P. If
1409 : : *SEQ_P is NULL, a new sequence is allocated. */
1410 : :
1411 : : void
1412 : 47112623 : gimple_seq_add_stmt (gimple_seq *seq_p, gimple *gs)
1413 : : {
1414 : 47112623 : gimple_stmt_iterator si;
1415 : 47112623 : if (gs == NULL)
1416 : 0 : return;
1417 : :
1418 : 47112623 : si = gsi_last (*seq_p);
1419 : 47112623 : gsi_insert_after (&si, gs, GSI_NEW_STMT);
1420 : : }
1421 : :
1422 : : /* Link gimple statement GS to the end of the sequence *SEQ_P. If
1423 : : *SEQ_P is NULL, a new sequence is allocated. This function is
1424 : : similar to gimple_seq_add_stmt, but does not scan the operands.
1425 : : During gimplification, we need to manipulate statement sequences
1426 : : before the def/use vectors have been constructed. */
1427 : :
1428 : : void
1429 : 181449592 : gimple_seq_add_stmt_without_update (gimple_seq *seq_p, gimple *gs)
1430 : : {
1431 : 181449592 : gimple_stmt_iterator si;
1432 : :
1433 : 181449592 : if (gs == NULL)
1434 : 0 : return;
1435 : :
1436 : 181449592 : si = gsi_last (*seq_p);
1437 : 181449592 : gsi_insert_after_without_update (&si, gs, GSI_NEW_STMT);
1438 : : }
1439 : :
1440 : : /* Append sequence SRC to the end of sequence *DST_P. If *DST_P is
1441 : : NULL, a new sequence is allocated. */
1442 : :
1443 : : void
1444 : 15984721 : gimple_seq_add_seq (gimple_seq *dst_p, gimple_seq src)
1445 : : {
1446 : 15984721 : gimple_stmt_iterator si;
1447 : 15984721 : if (src == NULL)
1448 : 4546407 : return;
1449 : :
1450 : 11438314 : si = gsi_last (*dst_p);
1451 : 11438314 : gsi_insert_seq_after (&si, src, GSI_NEW_STMT);
1452 : : }
1453 : :
1454 : : /* Append sequence SRC to the end of sequence *DST_P. If *DST_P is
1455 : : NULL, a new sequence is allocated. This function is
1456 : : similar to gimple_seq_add_seq, but does not scan the operands. */
1457 : :
1458 : : void
1459 : 268036 : gimple_seq_add_seq_without_update (gimple_seq *dst_p, gimple_seq src)
1460 : : {
1461 : 268036 : gimple_stmt_iterator si;
1462 : 268036 : if (src == NULL)
1463 : 96056 : return;
1464 : :
1465 : 171980 : si = gsi_last (*dst_p);
1466 : 171980 : gsi_insert_seq_after_without_update (&si, src, GSI_NEW_STMT);
1467 : : }
1468 : :
1469 : : /* Determine whether to assign a location to the statement GS. */
1470 : :
1471 : : static bool
1472 : 267029283 : should_carry_location_p (gimple *gs)
1473 : : {
1474 : : /* Don't emit a line note for a label. We particularly don't want to
1475 : : emit one for the break label, since it doesn't actually correspond
1476 : : to the beginning of the loop/switch. */
1477 : 267029283 : if (gimple_code (gs) == GIMPLE_LABEL)
1478 : 0 : return false;
1479 : :
1480 : : return true;
1481 : : }
1482 : :
1483 : : /* Set the location for gimple statement GS to LOCATION. */
1484 : :
1485 : : static void
1486 : 674182256 : annotate_one_with_location (gimple *gs, location_t location)
1487 : : {
1488 : 674182256 : if (!gimple_has_location (gs)
1489 : 336580492 : && !gimple_do_not_emit_location_p (gs)
1490 : 674182256 : && should_carry_location_p (gs))
1491 : 25765772 : gimple_set_location (gs, location);
1492 : 674182256 : }
1493 : :
1494 : : /* Set LOCATION for all the statements after iterator GSI in sequence
1495 : : SEQ. If GSI is pointing to the end of the sequence, start with the
1496 : : first statement in SEQ. */
1497 : :
1498 : : void
1499 : 98653932 : annotate_all_with_location_after (gimple_seq seq, gimple_stmt_iterator gsi,
1500 : : location_t location)
1501 : : {
1502 : 98653932 : if (gsi_end_p (gsi))
1503 : 34219750 : gsi = gsi_start (seq);
1504 : : else
1505 : 64434182 : gsi_next (&gsi);
1506 : :
1507 : 772502888 : for (; !gsi_end_p (gsi); gsi_next (&gsi))
1508 : 673848956 : annotate_one_with_location (gsi_stmt (gsi), location);
1509 : 98653932 : }
1510 : :
1511 : : /* Set the location for all the statements in a sequence STMT_P to LOCATION. */
1512 : :
1513 : : void
1514 : 213735 : annotate_all_with_location (gimple_seq stmt_p, location_t location)
1515 : : {
1516 : 213735 : gimple_stmt_iterator i;
1517 : :
1518 : 213735 : if (gimple_seq_empty_p (stmt_p))
1519 : 213735 : return;
1520 : :
1521 : 539370 : for (i = gsi_start (stmt_p); !gsi_end_p (i); gsi_next (&i))
1522 : : {
1523 : 333300 : gimple *gs = gsi_stmt (i);
1524 : 333300 : annotate_one_with_location (gs, location);
1525 : : }
1526 : : }
1527 : :
1528 : : /* Helper function of empty_body_p. Return true if STMT is an empty
1529 : : statement. */
1530 : :
1531 : : static bool
1532 : 36454 : empty_stmt_p (gimple *stmt)
1533 : : {
1534 : 36454 : if (gimple_code (stmt) == GIMPLE_NOP)
1535 : : return true;
1536 : 36452 : if (gbind *bind_stmt = dyn_cast <gbind *> (stmt))
1537 : 21533 : return empty_body_p (gimple_bind_body (bind_stmt));
1538 : : return false;
1539 : : }
1540 : :
1541 : :
1542 : : /* Return true if BODY contains nothing but empty statements. */
1543 : :
1544 : : bool
1545 : 36527 : empty_body_p (gimple_seq body)
1546 : : {
1547 : 36527 : gimple_stmt_iterator i;
1548 : :
1549 : 36527 : if (gimple_seq_empty_p (body))
1550 : : return true;
1551 : 36631 : for (i = gsi_start (body); !gsi_end_p (i); gsi_next (&i))
1552 : 36454 : if (!empty_stmt_p (gsi_stmt (i))
1553 : 36454 : && !is_gimple_debug (gsi_stmt (i)))
1554 : : return false;
1555 : :
1556 : : return true;
1557 : : }
1558 : :
1559 : :
1560 : : /* Perform a deep copy of sequence SRC and return the result. */
1561 : :
1562 : : gimple_seq
1563 : 1804298 : gimple_seq_copy (gimple_seq src)
1564 : : {
1565 : 1804298 : gimple_stmt_iterator gsi;
1566 : 1804298 : gimple_seq new_seq = NULL;
1567 : 1804298 : gimple *stmt;
1568 : :
1569 : 4066648 : for (gsi = gsi_start (src); !gsi_end_p (gsi); gsi_next (&gsi))
1570 : : {
1571 : 2262350 : stmt = gimple_copy (gsi_stmt (gsi));
1572 : 2262350 : gimple_seq_add_stmt (&new_seq, stmt);
1573 : : }
1574 : :
1575 : 1804298 : return new_seq;
1576 : : }
1577 : :
1578 : :
1579 : :
1580 : : /* Return true if calls C1 and C2 are known to go to the same function. */
1581 : :
1582 : : bool
1583 : 1003056 : gimple_call_same_target_p (const gimple *c1, const gimple *c2)
1584 : : {
1585 : 1003056 : if (gimple_call_internal_p (c1))
1586 : 4736 : return (gimple_call_internal_p (c2)
1587 : 4736 : && gimple_call_internal_fn (c1) == gimple_call_internal_fn (c2)
1588 : 9472 : && (!gimple_call_internal_unique_p (as_a <const gcall *> (c1))
1589 : 0 : || c1 == c2));
1590 : : else
1591 : 998320 : return (gimple_call_fn (c1) == gimple_call_fn (c2)
1592 : 998320 : || (gimple_call_fndecl (c1)
1593 : 997755 : && gimple_call_fndecl (c1) == gimple_call_fndecl (c2)));
1594 : : }
1595 : :
1596 : : /* Detect flags from a GIMPLE_CALL. This is just like
1597 : : call_expr_flags, but for gimple tuples. */
1598 : :
1599 : : int
1600 : 4224315060 : gimple_call_flags (const gimple *stmt)
1601 : : {
1602 : 4224315060 : int flags = 0;
1603 : :
1604 : 4224315060 : if (gimple_call_internal_p (stmt))
1605 : 125493769 : flags = internal_fn_flags (gimple_call_internal_fn (stmt));
1606 : : else
1607 : : {
1608 : 4098821291 : tree decl = gimple_call_fndecl (stmt);
1609 : 4098821291 : if (decl)
1610 : 3967430554 : flags = flags_from_decl_or_type (decl);
1611 : 4098821291 : flags |= flags_from_decl_or_type (gimple_call_fntype (stmt));
1612 : : }
1613 : :
1614 : 4224315060 : if (stmt->subcode & GF_CALL_NOTHROW)
1615 : 724246158 : flags |= ECF_NOTHROW;
1616 : 4224315060 : if (stmt->subcode & GF_CALL_XTHROW)
1617 : 11172100 : flags |= ECF_XTHROW;
1618 : :
1619 : 4224315060 : if (stmt->subcode & GF_CALL_BY_DESCRIPTOR)
1620 : 0 : flags |= ECF_BY_DESCRIPTOR;
1621 : :
1622 : 4224315060 : return flags;
1623 : : }
1624 : :
1625 : : /* Return the "fn spec" string for call STMT. */
1626 : :
1627 : : attr_fnspec
1628 : 433609871 : gimple_call_fnspec (const gcall *stmt)
1629 : : {
1630 : 433609871 : tree type, attr;
1631 : :
1632 : 433609871 : if (gimple_call_internal_p (stmt))
1633 : : {
1634 : 9630846 : const_tree spec = internal_fn_fnspec (gimple_call_internal_fn (stmt));
1635 : 9630846 : if (spec)
1636 : 320456 : return spec;
1637 : : else
1638 : 9310390 : return "";
1639 : : }
1640 : :
1641 : 423979025 : type = gimple_call_fntype (stmt);
1642 : 423979025 : if (type)
1643 : : {
1644 : 423979025 : attr = lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type));
1645 : 423979025 : if (attr)
1646 : 58967065 : return TREE_VALUE (TREE_VALUE (attr));
1647 : : }
1648 : 365011960 : if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
1649 : 110279418 : return builtin_fnspec (gimple_call_fndecl (stmt));
1650 : 254732542 : tree fndecl = gimple_call_fndecl (stmt);
1651 : : /* If the call is to a replaceable operator delete and results
1652 : : from a delete expression as opposed to a direct call to
1653 : : such operator, then we can treat it as free. */
1654 : 254732542 : if (fndecl
1655 : 240271663 : && DECL_IS_OPERATOR_DELETE_P (fndecl)
1656 : 6139326 : && DECL_IS_REPLACEABLE_OPERATOR (fndecl)
1657 : 260867403 : && gimple_call_from_new_or_delete (stmt))
1658 : : {
1659 : 6082516 : if (flag_assume_sane_operators_new_delete)
1660 : 6081236 : return ".co ";
1661 : : else
1662 : 1280 : return ". o ";
1663 : : }
1664 : : /* Similarly operator new can be treated as malloc. */
1665 : 248650026 : if (fndecl
1666 : 234189147 : && DECL_IS_REPLACEABLE_OPERATOR_NEW_P (fndecl)
1667 : 250625516 : && gimple_call_from_new_or_delete (stmt))
1668 : : {
1669 : 1941114 : if (flag_assume_sane_operators_new_delete)
1670 : 1940191 : return "mC";
1671 : : else
1672 : 923 : return "m ";
1673 : : }
1674 : 246708912 : return "";
1675 : : }
1676 : :
1677 : : /* Detects argument flags for argument number ARG on call STMT. */
1678 : :
1679 : : int
1680 : 119758010 : gimple_call_arg_flags (const gcall *stmt, unsigned arg)
1681 : : {
1682 : 119758010 : attr_fnspec fnspec = gimple_call_fnspec (stmt);
1683 : 119758010 : int flags = 0;
1684 : :
1685 : 119758010 : if (fnspec.known_p ())
1686 : 22105780 : flags = fnspec.arg_eaf_flags (arg);
1687 : 119758010 : tree callee = gimple_call_fndecl (stmt);
1688 : 119758010 : if (callee)
1689 : : {
1690 : 111648023 : cgraph_node *node = cgraph_node::get (callee);
1691 : 111648023 : modref_summary *summary = node ? get_modref_function_summary (node)
1692 : : : NULL;
1693 : :
1694 : 111448839 : if (summary && summary->arg_flags.length () > arg)
1695 : : {
1696 : 21030882 : int modref_flags = summary->arg_flags[arg];
1697 : :
1698 : : /* We have possibly optimized out load. Be conservative here. */
1699 : 21030882 : if (!node->binds_to_current_def_p ())
1700 : 9934791 : modref_flags = interposable_eaf_flags (modref_flags, flags);
1701 : 21030882 : if (dbg_cnt (ipa_mod_ref_pta))
1702 : 21030882 : flags |= modref_flags;
1703 : : }
1704 : : }
1705 : 119758010 : return flags;
1706 : : }
1707 : :
1708 : : /* Detects argument flags for return slot on call STMT. */
1709 : :
1710 : : int
1711 : 104376 : gimple_call_retslot_flags (const gcall *stmt)
1712 : : {
1713 : 104376 : int flags = implicit_retslot_eaf_flags;
1714 : :
1715 : 104376 : tree callee = gimple_call_fndecl (stmt);
1716 : 104376 : if (callee)
1717 : : {
1718 : 92357 : cgraph_node *node = cgraph_node::get (callee);
1719 : 92357 : modref_summary *summary = node ? get_modref_function_summary (node)
1720 : : : NULL;
1721 : :
1722 : 92357 : if (summary)
1723 : : {
1724 : 59417 : int modref_flags = summary->retslot_flags;
1725 : :
1726 : : /* We have possibly optimized out load. Be conservative here. */
1727 : 59417 : if (!node->binds_to_current_def_p ())
1728 : 51417 : modref_flags = interposable_eaf_flags (modref_flags, flags);
1729 : 59417 : if (dbg_cnt (ipa_mod_ref_pta))
1730 : 59417 : flags |= modref_flags;
1731 : : }
1732 : : }
1733 : 104376 : return flags;
1734 : : }
1735 : :
1736 : : /* Detects argument flags for static chain on call STMT. */
1737 : :
1738 : : int
1739 : 180028 : gimple_call_static_chain_flags (const gcall *stmt)
1740 : : {
1741 : 180028 : int flags = 0;
1742 : :
1743 : 180028 : tree callee = gimple_call_fndecl (stmt);
1744 : 180028 : if (callee)
1745 : : {
1746 : 27564 : cgraph_node *node = cgraph_node::get (callee);
1747 : 27564 : modref_summary *summary = node ? get_modref_function_summary (node)
1748 : : : NULL;
1749 : :
1750 : : /* Nested functions should always bind to current def since
1751 : : there is no public ABI for them. */
1752 : 27564 : gcc_checking_assert (node->binds_to_current_def_p ());
1753 : 27564 : if (summary)
1754 : : {
1755 : 25792 : int modref_flags = summary->static_chain_flags;
1756 : :
1757 : 25792 : if (dbg_cnt (ipa_mod_ref_pta))
1758 : 180028 : flags |= modref_flags;
1759 : : }
1760 : : }
1761 : 180028 : return flags;
1762 : : }
1763 : :
1764 : : /* Detects return flags for the call STMT. */
1765 : :
1766 : : int
1767 : 48079431 : gimple_call_return_flags (const gcall *stmt)
1768 : : {
1769 : 48079431 : if (gimple_call_flags (stmt) & ECF_MALLOC)
1770 : : return ERF_NOALIAS;
1771 : :
1772 : 46462514 : attr_fnspec fnspec = gimple_call_fnspec (stmt);
1773 : :
1774 : 46462514 : unsigned int arg_no;
1775 : 46462514 : if (fnspec.returns_arg (&arg_no))
1776 : 983348 : return ERF_RETURNS_ARG | arg_no;
1777 : :
1778 : 45479166 : if (fnspec.returns_noalias_p ())
1779 : : return ERF_NOALIAS;
1780 : : return 0;
1781 : : }
1782 : :
1783 : :
1784 : : /* Return true if call STMT is known to return a non-zero result. */
1785 : :
1786 : : bool
1787 : 12966106 : gimple_call_nonnull_result_p (gcall *call)
1788 : : {
1789 : 12966106 : tree fndecl = gimple_call_fndecl (call);
1790 : 12966106 : if (!fndecl)
1791 : : return false;
1792 : 11765737 : if (flag_delete_null_pointer_checks && !flag_check_new
1793 : 11765682 : && DECL_IS_OPERATOR_NEW_P (fndecl)
1794 : 12084781 : && !TREE_NOTHROW (fndecl))
1795 : : return true;
1796 : :
1797 : : /* References are always non-NULL. */
1798 : 11461849 : if (flag_delete_null_pointer_checks
1799 : 11461849 : && TREE_CODE (TREE_TYPE (fndecl)) == REFERENCE_TYPE)
1800 : : return true;
1801 : :
1802 : 11461849 : if (flag_delete_null_pointer_checks
1803 : 22917433 : && lookup_attribute ("returns_nonnull",
1804 : 11455584 : TYPE_ATTRIBUTES (gimple_call_fntype (call))))
1805 : : return true;
1806 : 11396152 : return gimple_alloca_call_p (call);
1807 : : }
1808 : :
1809 : :
1810 : : /* If CALL returns a non-null result in an argument, return that arg. */
1811 : :
1812 : : tree
1813 : 12526173 : gimple_call_nonnull_arg (gcall *call)
1814 : : {
1815 : 12526173 : tree fndecl = gimple_call_fndecl (call);
1816 : 12526173 : if (!fndecl)
1817 : : return NULL_TREE;
1818 : :
1819 : 11332069 : unsigned rf = gimple_call_return_flags (call);
1820 : 11332069 : if (rf & ERF_RETURNS_ARG)
1821 : : {
1822 : 0 : unsigned argnum = rf & ERF_RETURN_ARG_MASK;
1823 : 0 : if (argnum < gimple_call_num_args (call))
1824 : : {
1825 : 0 : tree arg = gimple_call_arg (call, argnum);
1826 : 0 : if (SSA_VAR_P (arg)
1827 : 0 : && infer_nonnull_range_by_attribute (call, arg))
1828 : : return arg;
1829 : : }
1830 : : }
1831 : : return NULL_TREE;
1832 : : }
1833 : :
1834 : :
1835 : : /* Return true if GS is a copy assignment. */
1836 : :
1837 : : bool
1838 : 198186747 : gimple_assign_copy_p (gimple *gs)
1839 : : {
1840 : 198186747 : return (gimple_assign_single_p (gs)
1841 : 198186747 : && is_gimple_val (gimple_op (gs, 1)));
1842 : : }
1843 : :
1844 : :
1845 : : /* Return true if GS is a SSA_NAME copy assignment. */
1846 : :
1847 : : bool
1848 : 40030202 : gimple_assign_ssa_name_copy_p (gimple *gs)
1849 : : {
1850 : 40030202 : return (gimple_assign_single_p (gs)
1851 : 22774485 : && TREE_CODE (gimple_assign_lhs (gs)) == SSA_NAME
1852 : 53301283 : && TREE_CODE (gimple_assign_rhs1 (gs)) == SSA_NAME);
1853 : : }
1854 : :
1855 : :
1856 : : /* Return true if GS is an assignment with a unary RHS, but the
1857 : : operator has no effect on the assigned value. The logic is adapted
1858 : : from STRIP_NOPS. This predicate is intended to be used in tuplifying
1859 : : instances in which STRIP_NOPS was previously applied to the RHS of
1860 : : an assignment.
1861 : :
1862 : : NOTE: In the use cases that led to the creation of this function
1863 : : and of gimple_assign_single_p, it is typical to test for either
1864 : : condition and to proceed in the same manner. In each case, the
1865 : : assigned value is represented by the single RHS operand of the
1866 : : assignment. I suspect there may be cases where gimple_assign_copy_p,
1867 : : gimple_assign_single_p, or equivalent logic is used where a similar
1868 : : treatment of unary NOPs is appropriate. */
1869 : :
1870 : : bool
1871 : 48947 : gimple_assign_unary_nop_p (gimple *gs)
1872 : : {
1873 : 48947 : return (is_gimple_assign (gs)
1874 : 48947 : && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs))
1875 : 43634 : || gimple_assign_rhs_code (gs) == NON_LVALUE_EXPR)
1876 : 5313 : && gimple_assign_rhs1 (gs) != error_mark_node
1877 : 59573 : && (TYPE_MODE (TREE_TYPE (gimple_assign_lhs (gs)))
1878 : 5313 : == TYPE_MODE (TREE_TYPE (gimple_assign_rhs1 (gs)))));
1879 : : }
1880 : :
1881 : : /* Return true if GS is an assignment that loads from its rhs1. */
1882 : :
1883 : : bool
1884 : 571789270 : gimple_assign_load_p (const gimple *gs)
1885 : : {
1886 : 571789270 : tree rhs;
1887 : 571789270 : if (!gimple_assign_single_p (gs))
1888 : : return false;
1889 : 338925291 : rhs = gimple_assign_rhs1 (gs);
1890 : 338925291 : if (TREE_CODE (rhs) == WITH_SIZE_EXPR)
1891 : : return true;
1892 : 338925287 : if (handled_component_p (rhs))
1893 : 92750791 : rhs = TREE_OPERAND (rhs, 0);
1894 : 338925287 : return (handled_component_p (rhs)
1895 : 312710503 : || DECL_P (rhs)
1896 : 252557970 : || TREE_CODE (rhs) == MEM_REF
1897 : 184687337 : || TREE_CODE (rhs) == TARGET_MEM_REF);
1898 : : }
1899 : :
1900 : :
1901 : : /* Set BB to be the basic block holding G. */
1902 : :
1903 : : void
1904 : 697096400 : gimple_set_bb (gimple *stmt, basic_block bb)
1905 : : {
1906 : 697096400 : stmt->bb = bb;
1907 : :
1908 : 697096400 : if (gimple_code (stmt) != GIMPLE_LABEL)
1909 : : return;
1910 : :
1911 : : /* If the statement is a label, add the label to block-to-labels map
1912 : : so that we can speed up edge creation for GIMPLE_GOTOs. */
1913 : 38719188 : if (cfun->cfg)
1914 : : {
1915 : 38719074 : tree t;
1916 : 38719074 : int uid;
1917 : :
1918 : 38719074 : t = gimple_label_label (as_a <glabel *> (stmt));
1919 : 38719074 : uid = LABEL_DECL_UID (t);
1920 : 38719074 : if (uid == -1)
1921 : : {
1922 : 19745203 : unsigned old_len =
1923 : 19745203 : vec_safe_length (label_to_block_map_for_fn (cfun));
1924 : 19745203 : LABEL_DECL_UID (t) = uid = cfun->cfg->last_label_uid++;
1925 : 19745203 : if (old_len <= (unsigned) uid)
1926 : 9565914 : vec_safe_grow_cleared (label_to_block_map_for_fn (cfun), uid + 1);
1927 : : }
1928 : :
1929 : 38719074 : (*label_to_block_map_for_fn (cfun))[uid] = bb;
1930 : : }
1931 : : }
1932 : :
1933 : :
1934 : : /* Modify the RHS of the assignment pointed-to by GSI using the
1935 : : operands in the expression tree EXPR.
1936 : :
1937 : : NOTE: The statement pointed-to by GSI may be reallocated if it
1938 : : did not have enough operand slots.
1939 : :
1940 : : This function is useful to convert an existing tree expression into
1941 : : the flat representation used for the RHS of a GIMPLE assignment.
1942 : : It will reallocate memory as needed to expand or shrink the number
1943 : : of operand slots needed to represent EXPR.
1944 : :
1945 : : NOTE: If you find yourself building a tree and then calling this
1946 : : function, you are most certainly doing it the slow way. It is much
1947 : : better to build a new assignment or to use the function
1948 : : gimple_assign_set_rhs_with_ops, which does not require an
1949 : : expression tree to be built. */
1950 : :
1951 : : void
1952 : 4724633 : gimple_assign_set_rhs_from_tree (gimple_stmt_iterator *gsi, tree expr)
1953 : : {
1954 : 4724633 : enum tree_code subcode;
1955 : 4724633 : tree op1, op2, op3;
1956 : :
1957 : 4724633 : extract_ops_from_tree (expr, &subcode, &op1, &op2, &op3);
1958 : 4724633 : gimple_assign_set_rhs_with_ops (gsi, subcode, op1, op2, op3);
1959 : 4724633 : }
1960 : :
1961 : :
1962 : : /* Set the RHS of assignment statement pointed-to by GSI to CODE with
1963 : : operands OP1, OP2 and OP3.
1964 : :
1965 : : NOTE: The statement pointed-to by GSI may be reallocated if it
1966 : : did not have enough operand slots. */
1967 : :
1968 : : void
1969 : 7167711 : gimple_assign_set_rhs_with_ops (gimple_stmt_iterator *gsi, enum tree_code code,
1970 : : tree op1, tree op2, tree op3)
1971 : : {
1972 : 7167711 : unsigned new_rhs_ops = get_gimple_rhs_num_ops (code);
1973 : 7167711 : gimple *stmt = gsi_stmt (*gsi);
1974 : 7167711 : gimple *old_stmt = stmt;
1975 : :
1976 : : /* If the new CODE needs more operands, allocate a new statement. */
1977 : 7167711 : if (gimple_num_ops (stmt) < new_rhs_ops + 1)
1978 : : {
1979 : 188294 : tree lhs = gimple_assign_lhs (old_stmt);
1980 : 188294 : stmt = gimple_alloc (gimple_code (old_stmt), new_rhs_ops + 1);
1981 : 188294 : memcpy (stmt, old_stmt, gimple_size (gimple_code (old_stmt)));
1982 : 188294 : gimple_init_singleton (stmt);
1983 : :
1984 : : /* The LHS needs to be reset as this also changes the SSA name
1985 : : on the LHS. */
1986 : 188294 : gimple_assign_set_lhs (stmt, lhs);
1987 : : }
1988 : :
1989 : 7167711 : gimple_set_num_ops (stmt, new_rhs_ops + 1);
1990 : 7167711 : gimple_set_subcode (stmt, code);
1991 : 7167711 : gimple_assign_set_rhs1 (stmt, op1);
1992 : 7167711 : if (new_rhs_ops > 1)
1993 : 1086420 : gimple_assign_set_rhs2 (stmt, op2);
1994 : 1086420 : if (new_rhs_ops > 2)
1995 : 34178 : gimple_assign_set_rhs3 (stmt, op3);
1996 : 7167711 : if (stmt != old_stmt)
1997 : 188294 : gsi_replace (gsi, stmt, false);
1998 : 7167711 : }
1999 : :
2000 : :
2001 : : /* Return the LHS of a statement that performs an assignment,
2002 : : either a GIMPLE_ASSIGN or a GIMPLE_CALL. Returns NULL_TREE
2003 : : for a call to a function that returns no value, or for a
2004 : : statement other than an assignment or a call. */
2005 : :
2006 : : tree
2007 : 6647883710 : gimple_get_lhs (const gimple *stmt)
2008 : : {
2009 : 6647883710 : enum gimple_code code = gimple_code (stmt);
2010 : :
2011 : 6647883710 : if (code == GIMPLE_ASSIGN)
2012 : 4278989269 : return gimple_assign_lhs (stmt);
2013 : 2368894441 : else if (code == GIMPLE_CALL)
2014 : 474994110 : return gimple_call_lhs (stmt);
2015 : 1893900331 : else if (code == GIMPLE_PHI)
2016 : 150054454 : return gimple_phi_result (stmt);
2017 : : else
2018 : : return NULL_TREE;
2019 : : }
2020 : :
2021 : :
2022 : : /* Set the LHS of a statement that performs an assignment,
2023 : : either a GIMPLE_ASSIGN or a GIMPLE_CALL. */
2024 : :
2025 : : void
2026 : 2167326 : gimple_set_lhs (gimple *stmt, tree lhs)
2027 : : {
2028 : 2167326 : enum gimple_code code = gimple_code (stmt);
2029 : :
2030 : 2167326 : if (code == GIMPLE_ASSIGN)
2031 : 1011358 : gimple_assign_set_lhs (stmt, lhs);
2032 : 1155968 : else if (code == GIMPLE_CALL)
2033 : 1155968 : gimple_call_set_lhs (stmt, lhs);
2034 : : else
2035 : 0 : gcc_unreachable ();
2036 : 2167326 : }
2037 : :
2038 : :
2039 : : /* Return a deep copy of statement STMT. All the operands from STMT
2040 : : are reallocated and copied using unshare_expr. The DEF, USE, VDEF
2041 : : and VUSE operand arrays are set to empty in the new copy. The new
2042 : : copy isn't part of any sequence. */
2043 : :
2044 : : gimple *
2045 : 66881562 : gimple_copy (gimple *stmt)
2046 : : {
2047 : 66881562 : enum gimple_code code = gimple_code (stmt);
2048 : 66881562 : unsigned num_ops = gimple_num_ops (stmt);
2049 : 66881562 : gimple *copy = gimple_alloc (code, num_ops);
2050 : 66881562 : unsigned i;
2051 : :
2052 : : /* Shallow copy all the fields from STMT. */
2053 : 66881562 : memcpy (copy, stmt, gimple_size (code));
2054 : 66881562 : gimple_init_singleton (copy);
2055 : :
2056 : : /* If STMT has sub-statements, deep-copy them as well. */
2057 : 66881562 : if (gimple_has_substatements (stmt))
2058 : : {
2059 : 42320 : gimple_seq new_seq;
2060 : 42320 : tree t;
2061 : :
2062 : 42320 : switch (gimple_code (stmt))
2063 : : {
2064 : 349 : case GIMPLE_BIND:
2065 : 349 : {
2066 : 349 : gbind *bind_stmt = as_a <gbind *> (stmt);
2067 : 349 : gbind *bind_copy = as_a <gbind *> (copy);
2068 : 349 : new_seq = gimple_seq_copy (gimple_bind_body (bind_stmt));
2069 : 349 : gimple_bind_set_body (bind_copy, new_seq);
2070 : 349 : gimple_bind_set_vars (bind_copy,
2071 : : unshare_expr (gimple_bind_vars (bind_stmt)));
2072 : 349 : gimple_bind_set_block (bind_copy, gimple_bind_block (bind_stmt));
2073 : : }
2074 : 349 : break;
2075 : :
2076 : 17498 : case GIMPLE_CATCH:
2077 : 17498 : {
2078 : 17498 : gcatch *catch_stmt = as_a <gcatch *> (stmt);
2079 : 17498 : gcatch *catch_copy = as_a <gcatch *> (copy);
2080 : 17498 : new_seq = gimple_seq_copy (gimple_catch_handler (catch_stmt));
2081 : 17498 : gimple_catch_set_handler (catch_copy, new_seq);
2082 : 17498 : t = unshare_expr (gimple_catch_types (catch_stmt));
2083 : 17498 : gimple_catch_set_types (catch_copy, t);
2084 : : }
2085 : 17498 : break;
2086 : :
2087 : 0 : case GIMPLE_EH_FILTER:
2088 : 0 : {
2089 : 0 : geh_filter *eh_filter_stmt = as_a <geh_filter *> (stmt);
2090 : 0 : geh_filter *eh_filter_copy = as_a <geh_filter *> (copy);
2091 : 0 : new_seq
2092 : 0 : = gimple_seq_copy (gimple_eh_filter_failure (eh_filter_stmt));
2093 : 0 : gimple_eh_filter_set_failure (eh_filter_copy, new_seq);
2094 : 0 : t = unshare_expr (gimple_eh_filter_types (eh_filter_stmt));
2095 : 0 : gimple_eh_filter_set_types (eh_filter_copy, t);
2096 : : }
2097 : 0 : break;
2098 : :
2099 : 273 : case GIMPLE_EH_ELSE:
2100 : 273 : {
2101 : 273 : geh_else *eh_else_stmt = as_a <geh_else *> (stmt);
2102 : 273 : geh_else *eh_else_copy = as_a <geh_else *> (copy);
2103 : 273 : new_seq = gimple_seq_copy (gimple_eh_else_n_body (eh_else_stmt));
2104 : 273 : gimple_eh_else_set_n_body (eh_else_copy, new_seq);
2105 : 273 : new_seq = gimple_seq_copy (gimple_eh_else_e_body (eh_else_stmt));
2106 : 273 : gimple_eh_else_set_e_body (eh_else_copy, new_seq);
2107 : : }
2108 : 273 : break;
2109 : :
2110 : 23938 : case GIMPLE_TRY:
2111 : 23938 : {
2112 : 23938 : gtry *try_stmt = as_a <gtry *> (stmt);
2113 : 23938 : gtry *try_copy = as_a <gtry *> (copy);
2114 : 23938 : new_seq = gimple_seq_copy (gimple_try_eval (try_stmt));
2115 : 23938 : gimple_try_set_eval (try_copy, new_seq);
2116 : 23938 : new_seq = gimple_seq_copy (gimple_try_cleanup (try_stmt));
2117 : 23938 : gimple_try_set_cleanup (try_copy, new_seq);
2118 : : }
2119 : 23938 : break;
2120 : :
2121 : 256 : case GIMPLE_OMP_FOR:
2122 : 256 : new_seq = gimple_seq_copy (gimple_omp_for_pre_body (stmt));
2123 : 256 : gimple_omp_for_set_pre_body (copy, new_seq);
2124 : 256 : t = unshare_expr (gimple_omp_for_clauses (stmt));
2125 : 256 : gimple_omp_for_set_clauses (copy, t);
2126 : 256 : {
2127 : 256 : gomp_for *omp_for_copy = as_a <gomp_for *> (copy);
2128 : 256 : omp_for_copy->iter = ggc_vec_alloc<gimple_omp_for_iter>
2129 : 256 : ( gimple_omp_for_collapse (stmt));
2130 : : }
2131 : 524 : for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
2132 : : {
2133 : 268 : gimple_omp_for_set_cond (copy, i,
2134 : : gimple_omp_for_cond (stmt, i));
2135 : 268 : gimple_omp_for_set_index (copy, i,
2136 : : gimple_omp_for_index (stmt, i));
2137 : 268 : t = unshare_expr (gimple_omp_for_initial (stmt, i));
2138 : 268 : gimple_omp_for_set_initial (copy, i, t);
2139 : 268 : t = unshare_expr (gimple_omp_for_final (stmt, i));
2140 : 268 : gimple_omp_for_set_final (copy, i, t);
2141 : 268 : t = unshare_expr (gimple_omp_for_incr (stmt, i));
2142 : 268 : gimple_omp_for_set_incr (copy, i, t);
2143 : : }
2144 : 256 : goto copy_omp_body;
2145 : :
2146 : 0 : case GIMPLE_OMP_PARALLEL:
2147 : 0 : {
2148 : 0 : gomp_parallel *omp_par_stmt = as_a <gomp_parallel *> (stmt);
2149 : 0 : gomp_parallel *omp_par_copy = as_a <gomp_parallel *> (copy);
2150 : 0 : t = unshare_expr (gimple_omp_parallel_clauses (omp_par_stmt));
2151 : 0 : gimple_omp_parallel_set_clauses (omp_par_copy, t);
2152 : 0 : t = unshare_expr (gimple_omp_parallel_child_fn (omp_par_stmt));
2153 : 0 : gimple_omp_parallel_set_child_fn (omp_par_copy, t);
2154 : 0 : t = unshare_expr (gimple_omp_parallel_data_arg (omp_par_stmt));
2155 : 0 : gimple_omp_parallel_set_data_arg (omp_par_copy, t);
2156 : : }
2157 : 0 : goto copy_omp_body;
2158 : :
2159 : 0 : case GIMPLE_OMP_TASK:
2160 : 0 : t = unshare_expr (gimple_omp_task_clauses (stmt));
2161 : 0 : gimple_omp_task_set_clauses (copy, t);
2162 : 0 : t = unshare_expr (gimple_omp_task_child_fn (stmt));
2163 : 0 : gimple_omp_task_set_child_fn (copy, t);
2164 : 0 : t = unshare_expr (gimple_omp_task_data_arg (stmt));
2165 : 0 : gimple_omp_task_set_data_arg (copy, t);
2166 : 0 : t = unshare_expr (gimple_omp_task_copy_fn (stmt));
2167 : 0 : gimple_omp_task_set_copy_fn (copy, t);
2168 : 0 : t = unshare_expr (gimple_omp_task_arg_size (stmt));
2169 : 0 : gimple_omp_task_set_arg_size (copy, t);
2170 : 0 : t = unshare_expr (gimple_omp_task_arg_align (stmt));
2171 : 0 : gimple_omp_task_set_arg_align (copy, t);
2172 : 0 : goto copy_omp_body;
2173 : :
2174 : 0 : case GIMPLE_OMP_CRITICAL:
2175 : 0 : t = unshare_expr (gimple_omp_critical_name
2176 : 0 : (as_a <gomp_critical *> (stmt)));
2177 : 0 : gimple_omp_critical_set_name (as_a <gomp_critical *> (copy), t);
2178 : 0 : t = unshare_expr (gimple_omp_critical_clauses
2179 : 0 : (as_a <gomp_critical *> (stmt)));
2180 : 0 : gimple_omp_critical_set_clauses (as_a <gomp_critical *> (copy), t);
2181 : 0 : goto copy_omp_body;
2182 : :
2183 : 0 : case GIMPLE_OMP_ORDERED:
2184 : 0 : t = unshare_expr (gimple_omp_ordered_clauses
2185 : 0 : (as_a <gomp_ordered *> (stmt)));
2186 : 0 : gimple_omp_ordered_set_clauses (as_a <gomp_ordered *> (copy), t);
2187 : 0 : goto copy_omp_body;
2188 : :
2189 : 0 : case GIMPLE_OMP_SCAN:
2190 : 0 : t = gimple_omp_scan_clauses (as_a <gomp_scan *> (stmt));
2191 : 0 : t = unshare_expr (t);
2192 : 0 : gimple_omp_scan_set_clauses (as_a <gomp_scan *> (copy), t);
2193 : 0 : goto copy_omp_body;
2194 : :
2195 : 0 : case GIMPLE_OMP_TASKGROUP:
2196 : 0 : t = unshare_expr (gimple_omp_taskgroup_clauses (stmt));
2197 : 0 : gimple_omp_taskgroup_set_clauses (copy, t);
2198 : 0 : goto copy_omp_body;
2199 : :
2200 : 0 : case GIMPLE_OMP_SECTIONS:
2201 : 0 : t = unshare_expr (gimple_omp_sections_clauses (stmt));
2202 : 0 : gimple_omp_sections_set_clauses (copy, t);
2203 : 0 : t = unshare_expr (gimple_omp_sections_control (stmt));
2204 : 0 : gimple_omp_sections_set_control (copy, t);
2205 : 0 : goto copy_omp_body;
2206 : :
2207 : 0 : case GIMPLE_OMP_SINGLE:
2208 : 0 : {
2209 : 0 : gomp_single *omp_single_copy = as_a <gomp_single *> (copy);
2210 : 0 : t = unshare_expr (gimple_omp_single_clauses (stmt));
2211 : 0 : gimple_omp_single_set_clauses (omp_single_copy, t);
2212 : : }
2213 : 0 : goto copy_omp_body;
2214 : :
2215 : 0 : case GIMPLE_OMP_SCOPE:
2216 : 0 : t = unshare_expr (gimple_omp_scope_clauses (stmt));
2217 : 0 : gimple_omp_scope_set_clauses (copy, t);
2218 : 0 : goto copy_omp_body;
2219 : :
2220 : 0 : case GIMPLE_OMP_DISPATCH:
2221 : 0 : t = unshare_expr (gimple_omp_dispatch_clauses (stmt));
2222 : 0 : gimple_omp_dispatch_set_clauses (copy, t);
2223 : 0 : goto copy_omp_body;
2224 : :
2225 : 0 : case GIMPLE_OMP_INTEROP:
2226 : 0 : t = unshare_expr (gimple_omp_interop_clauses (stmt));
2227 : 0 : gimple_omp_interop_set_clauses (copy, t);
2228 : 0 : break;
2229 : :
2230 : 0 : case GIMPLE_OMP_TARGET:
2231 : 0 : {
2232 : 0 : gomp_target *omp_target_stmt = as_a <gomp_target *> (stmt);
2233 : 0 : gomp_target *omp_target_copy = as_a <gomp_target *> (copy);
2234 : 0 : t = unshare_expr (gimple_omp_target_clauses (omp_target_stmt));
2235 : 0 : gimple_omp_target_set_clauses (omp_target_copy, t);
2236 : 0 : t = unshare_expr (gimple_omp_target_data_arg (omp_target_stmt));
2237 : 0 : gimple_omp_target_set_data_arg (omp_target_copy, t);
2238 : : }
2239 : 0 : goto copy_omp_body;
2240 : :
2241 : 0 : case GIMPLE_OMP_TEAMS:
2242 : 0 : {
2243 : 0 : gomp_teams *omp_teams_copy = as_a <gomp_teams *> (copy);
2244 : 0 : t = unshare_expr (gimple_omp_teams_clauses (stmt));
2245 : 0 : gimple_omp_teams_set_clauses (omp_teams_copy, t);
2246 : : }
2247 : : /* FALLTHRU */
2248 : :
2249 : 256 : case GIMPLE_OMP_SECTION:
2250 : 256 : case GIMPLE_OMP_MASTER:
2251 : 256 : case GIMPLE_OMP_STRUCTURED_BLOCK:
2252 : 256 : copy_omp_body:
2253 : 256 : new_seq = gimple_seq_copy (gimple_omp_body (stmt));
2254 : 256 : gimple_omp_set_body (copy, new_seq);
2255 : 256 : break;
2256 : :
2257 : 0 : case GIMPLE_OMP_MASKED:
2258 : 0 : t = unshare_expr (gimple_omp_masked_clauses (stmt));
2259 : 0 : gimple_omp_masked_set_clauses (copy, t);
2260 : 0 : goto copy_omp_body;
2261 : :
2262 : 0 : case GIMPLE_ASSUME:
2263 : 0 : new_seq = gimple_seq_copy (gimple_assume_body (stmt));
2264 : 0 : *gimple_assume_body_ptr (copy) = new_seq;
2265 : 0 : gimple_assume_set_guard (copy,
2266 : : unshare_expr (gimple_assume_guard (stmt)));
2267 : 0 : break;
2268 : :
2269 : 6 : case GIMPLE_TRANSACTION:
2270 : 6 : new_seq = gimple_seq_copy (gimple_transaction_body (
2271 : 6 : as_a <gtransaction *> (stmt)));
2272 : 6 : gimple_transaction_set_body (as_a <gtransaction *> (copy),
2273 : : new_seq);
2274 : 6 : break;
2275 : :
2276 : 0 : case GIMPLE_WITH_CLEANUP_EXPR:
2277 : 0 : new_seq = gimple_seq_copy (gimple_wce_cleanup (stmt));
2278 : 0 : gimple_wce_set_cleanup (copy, new_seq);
2279 : 0 : break;
2280 : :
2281 : 0 : default:
2282 : 0 : gcc_unreachable ();
2283 : : }
2284 : : }
2285 : :
2286 : 66881562 : switch (gimple_code (stmt))
2287 : : {
2288 : 0 : case GIMPLE_OMP_ATOMIC_LOAD:
2289 : 0 : {
2290 : 0 : gomp_atomic_load *g = as_a <gomp_atomic_load *> (copy);
2291 : 0 : gimple_omp_atomic_load_set_lhs (g,
2292 : : unshare_expr (gimple_omp_atomic_load_lhs (g)));
2293 : 0 : gimple_omp_atomic_load_set_rhs (g,
2294 : : unshare_expr (gimple_omp_atomic_load_rhs (g)));
2295 : 0 : break;
2296 : : }
2297 : 0 : case GIMPLE_OMP_ATOMIC_STORE:
2298 : 0 : {
2299 : 0 : gomp_atomic_store *g = as_a <gomp_atomic_store *> (copy);
2300 : 0 : gimple_omp_atomic_store_set_val (g,
2301 : : unshare_expr (gimple_omp_atomic_store_val (g)));
2302 : 0 : break;
2303 : : }
2304 : : default:
2305 : : break;
2306 : : }
2307 : :
2308 : : /* Make copy of operands. */
2309 : 204959049 : for (i = 0; i < num_ops; i++)
2310 : 138077487 : gimple_set_op (copy, i, unshare_expr (gimple_op (stmt, i)));
2311 : :
2312 : 66881562 : if (gimple_has_mem_ops (stmt))
2313 : : {
2314 : 31695727 : gimple_set_vdef (copy, gimple_vdef (stmt));
2315 : 31695727 : gimple_set_vuse (copy, gimple_vuse (stmt));
2316 : : }
2317 : :
2318 : : /* Clear out SSA operand vectors on COPY. */
2319 : 66881562 : if (gimple_has_ops (stmt))
2320 : : {
2321 : 66427812 : gimple_set_use_ops (copy, NULL);
2322 : :
2323 : : /* SSA operands need to be updated. */
2324 : 66427812 : gimple_set_modified (copy, true);
2325 : : }
2326 : :
2327 : 66881562 : if (gimple_debug_nonbind_marker_p (stmt))
2328 : 14630664 : cfun->debug_marker_count++;
2329 : :
2330 : 66881562 : return copy;
2331 : : }
2332 : :
2333 : : /* Move OLD_STMT's vuse and vdef operands to NEW_STMT, on the assumption
2334 : : that OLD_STMT is about to be removed. */
2335 : :
2336 : : void
2337 : 556871 : gimple_move_vops (gimple *new_stmt, gimple *old_stmt)
2338 : : {
2339 : 556871 : tree vdef = gimple_vdef (old_stmt);
2340 : 1113742 : gimple_set_vuse (new_stmt, gimple_vuse (old_stmt));
2341 : 556871 : gimple_set_vdef (new_stmt, vdef);
2342 : 556871 : if (vdef && TREE_CODE (vdef) == SSA_NAME)
2343 : 185889 : SSA_NAME_DEF_STMT (vdef) = new_stmt;
2344 : 556871 : }
2345 : :
2346 : : /* Return true if statement S has side-effects. We consider a
2347 : : statement to have side effects if:
2348 : :
2349 : : - It is a GIMPLE_CALL not marked with ECF_PURE or ECF_CONST.
2350 : : - Any of its operands are marked TREE_THIS_VOLATILE or TREE_SIDE_EFFECTS. */
2351 : :
2352 : : bool
2353 : 1305894392 : gimple_has_side_effects (const gimple *s)
2354 : : {
2355 : 1305894392 : if (is_gimple_debug (s))
2356 : : return false;
2357 : :
2358 : : /* We don't have to scan the arguments to check for
2359 : : volatile arguments, though, at present, we still
2360 : : do a scan to check for TREE_SIDE_EFFECTS. */
2361 : 2204792087 : if (gimple_has_volatile_ops (s))
2362 : : return true;
2363 : :
2364 : 1106653897 : if (gimple_code (s) == GIMPLE_ASM
2365 : 1106653897 : && gimple_asm_volatile_p (as_a <const gasm *> (s)))
2366 : : return true;
2367 : :
2368 : 1106081786 : if (is_gimple_call (s))
2369 : : {
2370 : 94917004 : int flags = gimple_call_flags (s);
2371 : :
2372 : : /* An infinite loop is considered a side effect. */
2373 : 94917004 : if (!(flags & (ECF_CONST | ECF_PURE))
2374 : 19940758 : || (flags & ECF_LOOPING_CONST_OR_PURE))
2375 : : return true;
2376 : :
2377 : : return false;
2378 : : }
2379 : :
2380 : : return false;
2381 : : }
2382 : :
2383 : : /* Helper for gimple_could_trap_p and gimple_assign_rhs_could_trap_p.
2384 : : Return true if S can trap. When INCLUDE_MEM is true, check whether
2385 : : the memory operations could trap. When INCLUDE_STORES is true and
2386 : : S is a GIMPLE_ASSIGN, the LHS of the assignment is also checked. */
2387 : :
2388 : : bool
2389 : 57291299 : gimple_could_trap_p_1 (const gimple *s, bool include_mem, bool include_stores)
2390 : : {
2391 : 57291299 : tree t, div = NULL_TREE;
2392 : 57291299 : enum tree_code op;
2393 : :
2394 : 57291299 : if (include_mem)
2395 : : {
2396 : 32305320 : unsigned i, start = (is_gimple_assign (s) && !include_stores) ? 1 : 0;
2397 : :
2398 : 111605172 : for (i = start; i < gimple_num_ops (s); i++)
2399 : 83594510 : if (tree_could_trap_p (gimple_op (s, i)))
2400 : : return true;
2401 : : }
2402 : :
2403 : 52996641 : switch (gimple_code (s))
2404 : : {
2405 : 8856 : case GIMPLE_ASM:
2406 : 8856 : return gimple_asm_volatile_p (as_a <const gasm *> (s));
2407 : :
2408 : 1344573 : case GIMPLE_CALL:
2409 : 1344573 : if (gimple_call_internal_p (s))
2410 : : return false;
2411 : 1193728 : t = gimple_call_fndecl (s);
2412 : : /* Assume that indirect and calls to weak functions may trap. */
2413 : 1193728 : if (!t || !DECL_P (t) || DECL_WEAK (t))
2414 : : return true;
2415 : : return false;
2416 : :
2417 : 40457218 : case GIMPLE_ASSIGN:
2418 : 40457218 : op = gimple_assign_rhs_code (s);
2419 : :
2420 : : /* For COND_EXPR only the condition may trap. */
2421 : 40457218 : if (op == COND_EXPR)
2422 : 20571 : return tree_could_trap_p (gimple_assign_rhs1 (s));
2423 : :
2424 : : /* For comparisons we need to check rhs operand types instead of lhs type
2425 : : (which is BOOLEAN_TYPE). */
2426 : 40436647 : if (TREE_CODE_CLASS (op) == tcc_comparison)
2427 : 1411122 : t = TREE_TYPE (gimple_assign_rhs1 (s));
2428 : : else
2429 : 39025525 : t = TREE_TYPE (gimple_assign_lhs (s));
2430 : :
2431 : 40436647 : if (get_gimple_rhs_class (op) == GIMPLE_BINARY_RHS)
2432 : 22622284 : div = gimple_assign_rhs2 (s);
2433 : :
2434 : 42826654 : return (operation_could_trap_p (op, FLOAT_TYPE_P (t),
2435 : 40436647 : (INTEGRAL_TYPE_P (t)
2436 : 40436647 : && TYPE_OVERFLOW_TRAPS (t)),
2437 : 40436647 : div));
2438 : :
2439 : 7196211 : case GIMPLE_COND:
2440 : 7196211 : t = TREE_TYPE (gimple_cond_lhs (s));
2441 : 7196211 : return operation_could_trap_p (gimple_cond_code (s),
2442 : 14392422 : FLOAT_TYPE_P (t), false, NULL_TREE);
2443 : :
2444 : : default:
2445 : : break;
2446 : : }
2447 : :
2448 : : return false;
2449 : : }
2450 : :
2451 : : /* Return true if statement S can trap. */
2452 : :
2453 : : bool
2454 : 29286686 : gimple_could_trap_p (const gimple *s)
2455 : : {
2456 : 29286686 : return gimple_could_trap_p_1 (s, true, true);
2457 : : }
2458 : :
2459 : : /* Return true if RHS of a GIMPLE_ASSIGN S can trap. */
2460 : :
2461 : : bool
2462 : 3018634 : gimple_assign_rhs_could_trap_p (gimple *s)
2463 : : {
2464 : 3018634 : gcc_assert (is_gimple_assign (s));
2465 : 3018634 : return gimple_could_trap_p_1 (s, true, false);
2466 : : }
2467 : :
2468 : :
2469 : : /* Print debugging information for gimple stmts generated. */
2470 : :
2471 : : void
2472 : 0 : dump_gimple_statistics (void)
2473 : : {
2474 : 0 : int i;
2475 : 0 : uint64_t total_tuples = 0, total_bytes = 0;
2476 : :
2477 : 0 : if (! GATHER_STATISTICS)
2478 : : {
2479 : 0 : fprintf (stderr, "No GIMPLE statistics\n");
2480 : 0 : return;
2481 : : }
2482 : :
2483 : : fprintf (stderr, "\nGIMPLE statements\n");
2484 : : fprintf (stderr, "Kind Stmts Bytes\n");
2485 : : fprintf (stderr, "---------------------------------------\n");
2486 : : for (i = 0; i < (int) gimple_alloc_kind_all; ++i)
2487 : : {
2488 : : fprintf (stderr, "%-20s %7" PRIu64 "%c %10" PRIu64 "%c\n",
2489 : : gimple_alloc_kind_names[i],
2490 : : SIZE_AMOUNT (gimple_alloc_counts[i]),
2491 : : SIZE_AMOUNT (gimple_alloc_sizes[i]));
2492 : : total_tuples += gimple_alloc_counts[i];
2493 : : total_bytes += gimple_alloc_sizes[i];
2494 : : }
2495 : : fprintf (stderr, "---------------------------------------\n");
2496 : : fprintf (stderr, "%-20s %7" PRIu64 "%c %10" PRIu64 "%c\n", "Total",
2497 : : SIZE_AMOUNT (total_tuples), SIZE_AMOUNT (total_bytes));
2498 : : fprintf (stderr, "---------------------------------------\n");
2499 : : }
2500 : :
2501 : :
2502 : : /* Return the number of operands needed on the RHS of a GIMPLE
2503 : : assignment for an expression with tree code CODE. */
2504 : :
2505 : : unsigned
2506 : 100523903 : get_gimple_rhs_num_ops (enum tree_code code)
2507 : : {
2508 : 100523903 : switch (get_gimple_rhs_class (code))
2509 : : {
2510 : : case GIMPLE_UNARY_RHS:
2511 : : case GIMPLE_SINGLE_RHS:
2512 : : return 1;
2513 : : case GIMPLE_BINARY_RHS:
2514 : : return 2;
2515 : : case GIMPLE_TERNARY_RHS:
2516 : : return 3;
2517 : 0 : default:
2518 : 0 : gcc_unreachable ();
2519 : : }
2520 : : }
2521 : :
2522 : : #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \
2523 : : (unsigned char) \
2524 : : ((TYPE) == tcc_unary ? GIMPLE_UNARY_RHS \
2525 : : : ((TYPE) == tcc_binary \
2526 : : || (TYPE) == tcc_comparison) ? GIMPLE_BINARY_RHS \
2527 : : : ((TYPE) == tcc_constant \
2528 : : || (TYPE) == tcc_declaration \
2529 : : || (TYPE) == tcc_reference) ? GIMPLE_SINGLE_RHS \
2530 : : : ((SYM) == TRUTH_AND_EXPR \
2531 : : || (SYM) == TRUTH_OR_EXPR \
2532 : : || (SYM) == TRUTH_XOR_EXPR) ? GIMPLE_BINARY_RHS \
2533 : : : (SYM) == TRUTH_NOT_EXPR ? GIMPLE_UNARY_RHS \
2534 : : : ((SYM) == COND_EXPR \
2535 : : || (SYM) == WIDEN_MULT_PLUS_EXPR \
2536 : : || (SYM) == WIDEN_MULT_MINUS_EXPR \
2537 : : || (SYM) == DOT_PROD_EXPR \
2538 : : || (SYM) == SAD_EXPR \
2539 : : || (SYM) == REALIGN_LOAD_EXPR \
2540 : : || (SYM) == VEC_COND_EXPR \
2541 : : || (SYM) == VEC_PERM_EXPR \
2542 : : || (SYM) == BIT_INSERT_EXPR) ? GIMPLE_TERNARY_RHS \
2543 : : : ((SYM) == CONSTRUCTOR \
2544 : : || (SYM) == OBJ_TYPE_REF \
2545 : : || (SYM) == ADDR_EXPR \
2546 : : || (SYM) == WITH_SIZE_EXPR \
2547 : : || (SYM) == SSA_NAME \
2548 : : || (SYM) == OMP_NEXT_VARIANT \
2549 : : || (SYM) == OMP_TARGET_DEVICE_MATCHES) ? GIMPLE_SINGLE_RHS \
2550 : : : GIMPLE_INVALID_RHS),
2551 : : #define END_OF_BASE_TREE_CODES (unsigned char) GIMPLE_INVALID_RHS,
2552 : :
2553 : : const unsigned char gimple_rhs_class_table[] = {
2554 : : #include "all-tree.def"
2555 : : };
2556 : :
2557 : : #undef DEFTREECODE
2558 : : #undef END_OF_BASE_TREE_CODES
2559 : :
2560 : : /* Build a GIMPLE_CALL identical to STMT but skipping the arguments in
2561 : : the positions marked by the set ARGS_TO_SKIP. */
2562 : :
2563 : : gcall *
2564 : 0 : gimple_call_copy_skip_args (gcall *stmt, bitmap args_to_skip)
2565 : : {
2566 : 0 : int i;
2567 : 0 : int nargs = gimple_call_num_args (stmt);
2568 : 0 : auto_vec<tree> vargs (nargs);
2569 : 0 : gcall *new_stmt;
2570 : :
2571 : 0 : for (i = 0; i < nargs; i++)
2572 : 0 : if (!bitmap_bit_p (args_to_skip, i))
2573 : 0 : vargs.quick_push (gimple_call_arg (stmt, i));
2574 : :
2575 : 0 : if (gimple_call_internal_p (stmt))
2576 : 0 : new_stmt = gimple_build_call_internal_vec (gimple_call_internal_fn (stmt),
2577 : : vargs);
2578 : : else
2579 : 0 : new_stmt = gimple_build_call_vec (gimple_call_fn (stmt), vargs);
2580 : :
2581 : 0 : if (gimple_call_lhs (stmt))
2582 : 0 : gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt));
2583 : :
2584 : 0 : gimple_set_vuse (new_stmt, gimple_vuse (stmt));
2585 : 0 : gimple_set_vdef (new_stmt, gimple_vdef (stmt));
2586 : :
2587 : 0 : if (gimple_has_location (stmt))
2588 : 0 : gimple_set_location (new_stmt, gimple_location (stmt));
2589 : 0 : gimple_call_copy_flags (new_stmt, stmt);
2590 : 0 : gimple_call_set_chain (new_stmt, gimple_call_chain (stmt));
2591 : :
2592 : 0 : gimple_set_modified (new_stmt, true);
2593 : :
2594 : 0 : return new_stmt;
2595 : 0 : }
2596 : :
2597 : :
2598 : :
2599 : : /* Return true if the field decls F1 and F2 are at the same offset.
2600 : :
2601 : : This is intended to be used on GIMPLE types only. */
2602 : :
2603 : : bool
2604 : 52946418 : gimple_compare_field_offset (tree f1, tree f2)
2605 : : {
2606 : 52946418 : if (DECL_OFFSET_ALIGN (f1) == DECL_OFFSET_ALIGN (f2))
2607 : : {
2608 : 52946355 : tree offset1 = DECL_FIELD_OFFSET (f1);
2609 : 52946355 : tree offset2 = DECL_FIELD_OFFSET (f2);
2610 : 52946355 : return ((offset1 == offset2
2611 : : /* Once gimplification is done, self-referential offsets are
2612 : : instantiated as operand #2 of the COMPONENT_REF built for
2613 : : each access and reset. Therefore, they are not relevant
2614 : : anymore and fields are interchangeable provided that they
2615 : : represent the same access. */
2616 : 0 : || (TREE_CODE (offset1) == PLACEHOLDER_EXPR
2617 : 0 : && TREE_CODE (offset2) == PLACEHOLDER_EXPR
2618 : 0 : && (DECL_SIZE (f1) == DECL_SIZE (f2)
2619 : 0 : || (TREE_CODE (DECL_SIZE (f1)) == PLACEHOLDER_EXPR
2620 : 0 : && TREE_CODE (DECL_SIZE (f2)) == PLACEHOLDER_EXPR)
2621 : 0 : || operand_equal_p (DECL_SIZE (f1), DECL_SIZE (f2), 0))
2622 : 0 : && DECL_ALIGN (f1) == DECL_ALIGN (f2))
2623 : 0 : || operand_equal_p (offset1, offset2, 0))
2624 : 105892710 : && tree_int_cst_equal (DECL_FIELD_BIT_OFFSET (f1),
2625 : 52946355 : DECL_FIELD_BIT_OFFSET (f2)));
2626 : : }
2627 : :
2628 : : /* Fortran and C do not always agree on what DECL_OFFSET_ALIGN
2629 : : should be, so handle differing ones specially by decomposing
2630 : : the offset into a byte and bit offset manually. */
2631 : 63 : if (tree_fits_shwi_p (DECL_FIELD_OFFSET (f1))
2632 : 63 : && tree_fits_shwi_p (DECL_FIELD_OFFSET (f2)))
2633 : : {
2634 : 63 : unsigned HOST_WIDE_INT byte_offset1, byte_offset2;
2635 : 63 : unsigned HOST_WIDE_INT bit_offset1, bit_offset2;
2636 : 63 : bit_offset1 = TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f1));
2637 : 63 : byte_offset1 = (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f1))
2638 : 63 : + bit_offset1 / BITS_PER_UNIT);
2639 : 63 : bit_offset2 = TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f2));
2640 : 63 : byte_offset2 = (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f2))
2641 : 63 : + bit_offset2 / BITS_PER_UNIT);
2642 : 63 : if (byte_offset1 != byte_offset2)
2643 : : return false;
2644 : 63 : return bit_offset1 % BITS_PER_UNIT == bit_offset2 % BITS_PER_UNIT;
2645 : : }
2646 : :
2647 : : return false;
2648 : : }
2649 : :
2650 : :
2651 : : /* Return a type the same as TYPE except unsigned or
2652 : : signed according to UNSIGNEDP. */
2653 : :
2654 : : static tree
2655 : 554721 : gimple_signed_or_unsigned_type (bool unsignedp, tree type)
2656 : : {
2657 : 554721 : tree type1;
2658 : 554721 : int i;
2659 : :
2660 : 554721 : type1 = TYPE_MAIN_VARIANT (type);
2661 : 554721 : if (type1 == signed_char_type_node
2662 : 554721 : || type1 == char_type_node
2663 : 554721 : || type1 == unsigned_char_type_node)
2664 : 4 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2665 : 554717 : if (type1 == integer_type_node || type1 == unsigned_type_node)
2666 : 320624 : return unsignedp ? unsigned_type_node : integer_type_node;
2667 : 234093 : if (type1 == short_integer_type_node || type1 == short_unsigned_type_node)
2668 : 213162 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2669 : 20931 : if (type1 == long_integer_type_node || type1 == long_unsigned_type_node)
2670 : 30 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2671 : 20901 : if (type1 == long_long_integer_type_node
2672 : 20813 : || type1 == long_long_unsigned_type_node)
2673 : 88 : return unsignedp
2674 : 88 : ? long_long_unsigned_type_node
2675 : 0 : : long_long_integer_type_node;
2676 : :
2677 : 34735 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
2678 : 20813 : if (int_n_enabled_p[i]
2679 : 20813 : && (type1 == int_n_trees[i].unsigned_type
2680 : 14294 : || type1 == int_n_trees[i].signed_type))
2681 : 6891 : return unsignedp
2682 : 6891 : ? int_n_trees[i].unsigned_type
2683 : 6891 : : int_n_trees[i].signed_type;
2684 : :
2685 : : #if HOST_BITS_PER_WIDE_INT >= 64
2686 : 13922 : if (type1 == intTI_type_node || type1 == unsigned_intTI_type_node)
2687 : 0 : return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
2688 : : #endif
2689 : 13922 : if (type1 == intDI_type_node || type1 == unsigned_intDI_type_node)
2690 : 0 : return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
2691 : 13922 : if (type1 == intSI_type_node || type1 == unsigned_intSI_type_node)
2692 : 0 : return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
2693 : 13922 : if (type1 == intHI_type_node || type1 == unsigned_intHI_type_node)
2694 : 0 : return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
2695 : 13922 : if (type1 == intQI_type_node || type1 == unsigned_intQI_type_node)
2696 : 0 : return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
2697 : :
2698 : : #define GIMPLE_FIXED_TYPES(NAME) \
2699 : : if (type1 == short_ ## NAME ## _type_node \
2700 : : || type1 == unsigned_short_ ## NAME ## _type_node) \
2701 : : return unsignedp ? unsigned_short_ ## NAME ## _type_node \
2702 : : : short_ ## NAME ## _type_node; \
2703 : : if (type1 == NAME ## _type_node \
2704 : : || type1 == unsigned_ ## NAME ## _type_node) \
2705 : : return unsignedp ? unsigned_ ## NAME ## _type_node \
2706 : : : NAME ## _type_node; \
2707 : : if (type1 == long_ ## NAME ## _type_node \
2708 : : || type1 == unsigned_long_ ## NAME ## _type_node) \
2709 : : return unsignedp ? unsigned_long_ ## NAME ## _type_node \
2710 : : : long_ ## NAME ## _type_node; \
2711 : : if (type1 == long_long_ ## NAME ## _type_node \
2712 : : || type1 == unsigned_long_long_ ## NAME ## _type_node) \
2713 : : return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
2714 : : : long_long_ ## NAME ## _type_node;
2715 : :
2716 : : #define GIMPLE_FIXED_MODE_TYPES(NAME) \
2717 : : if (type1 == NAME ## _type_node \
2718 : : || type1 == u ## NAME ## _type_node) \
2719 : : return unsignedp ? u ## NAME ## _type_node \
2720 : : : NAME ## _type_node;
2721 : :
2722 : : #define GIMPLE_FIXED_TYPES_SAT(NAME) \
2723 : : if (type1 == sat_ ## short_ ## NAME ## _type_node \
2724 : : || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
2725 : : return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
2726 : : : sat_ ## short_ ## NAME ## _type_node; \
2727 : : if (type1 == sat_ ## NAME ## _type_node \
2728 : : || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
2729 : : return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
2730 : : : sat_ ## NAME ## _type_node; \
2731 : : if (type1 == sat_ ## long_ ## NAME ## _type_node \
2732 : : || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
2733 : : return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
2734 : : : sat_ ## long_ ## NAME ## _type_node; \
2735 : : if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
2736 : : || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
2737 : : return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
2738 : : : sat_ ## long_long_ ## NAME ## _type_node;
2739 : :
2740 : : #define GIMPLE_FIXED_MODE_TYPES_SAT(NAME) \
2741 : : if (type1 == sat_ ## NAME ## _type_node \
2742 : : || type1 == sat_ ## u ## NAME ## _type_node) \
2743 : : return unsignedp ? sat_ ## u ## NAME ## _type_node \
2744 : : : sat_ ## NAME ## _type_node;
2745 : :
2746 : 13922 : GIMPLE_FIXED_TYPES (fract);
2747 : 13922 : GIMPLE_FIXED_TYPES_SAT (fract);
2748 : 13922 : GIMPLE_FIXED_TYPES (accum);
2749 : 13922 : GIMPLE_FIXED_TYPES_SAT (accum);
2750 : :
2751 : 13922 : GIMPLE_FIXED_MODE_TYPES (qq);
2752 : 13922 : GIMPLE_FIXED_MODE_TYPES (hq);
2753 : 13922 : GIMPLE_FIXED_MODE_TYPES (sq);
2754 : 13922 : GIMPLE_FIXED_MODE_TYPES (dq);
2755 : 13922 : GIMPLE_FIXED_MODE_TYPES (tq);
2756 : 13922 : GIMPLE_FIXED_MODE_TYPES_SAT (qq);
2757 : 13922 : GIMPLE_FIXED_MODE_TYPES_SAT (hq);
2758 : 13922 : GIMPLE_FIXED_MODE_TYPES_SAT (sq);
2759 : 13922 : GIMPLE_FIXED_MODE_TYPES_SAT (dq);
2760 : 13922 : GIMPLE_FIXED_MODE_TYPES_SAT (tq);
2761 : 13922 : GIMPLE_FIXED_MODE_TYPES (ha);
2762 : 13922 : GIMPLE_FIXED_MODE_TYPES (sa);
2763 : 13922 : GIMPLE_FIXED_MODE_TYPES (da);
2764 : 13922 : GIMPLE_FIXED_MODE_TYPES (ta);
2765 : 13922 : GIMPLE_FIXED_MODE_TYPES_SAT (ha);
2766 : 13922 : GIMPLE_FIXED_MODE_TYPES_SAT (sa);
2767 : 13922 : GIMPLE_FIXED_MODE_TYPES_SAT (da);
2768 : 13922 : GIMPLE_FIXED_MODE_TYPES_SAT (ta);
2769 : :
2770 : : /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
2771 : : the precision; they have precision set to match their range, but
2772 : : may use a wider mode to match an ABI. If we change modes, we may
2773 : : wind up with bad conversions. For INTEGER_TYPEs in C, must check
2774 : : the precision as well, so as to yield correct results for
2775 : : bit-field types. C++ does not have these separate bit-field
2776 : : types, and producing a signed or unsigned variant of an
2777 : : ENUMERAL_TYPE may cause other problems as well. */
2778 : 13922 : if (!INTEGRAL_TYPE_P (type)
2779 : 13922 : || TYPE_UNSIGNED (type) == unsignedp)
2780 : : return type;
2781 : :
2782 : : #define TYPE_OK(node) \
2783 : : (TYPE_MODE (type) == TYPE_MODE (node) \
2784 : : && TYPE_PRECISION (type) == TYPE_PRECISION (node))
2785 : 13922 : if (TYPE_OK (signed_char_type_node))
2786 : 479 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2787 : 13443 : if (TYPE_OK (integer_type_node))
2788 : 3512 : return unsignedp ? unsigned_type_node : integer_type_node;
2789 : 9931 : if (TYPE_OK (short_integer_type_node))
2790 : 4747 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2791 : 5184 : if (TYPE_OK (long_integer_type_node))
2792 : 0 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2793 : 5184 : if (TYPE_OK (long_long_integer_type_node))
2794 : 0 : return (unsignedp
2795 : 0 : ? long_long_unsigned_type_node
2796 : 0 : : long_long_integer_type_node);
2797 : :
2798 : 10340 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
2799 : 5184 : if (int_n_enabled_p[i]
2800 : 5184 : && TYPE_MODE (type) == int_n_data[i].m
2801 : 5212 : && TYPE_PRECISION (type) == int_n_data[i].bitsize)
2802 : 28 : return unsignedp
2803 : 28 : ? int_n_trees[i].unsigned_type
2804 : 28 : : int_n_trees[i].signed_type;
2805 : :
2806 : : #if HOST_BITS_PER_WIDE_INT >= 64
2807 : 5156 : if (TYPE_OK (intTI_type_node))
2808 : 0 : return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
2809 : : #endif
2810 : 5156 : if (TYPE_OK (intDI_type_node))
2811 : 0 : return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
2812 : 5156 : if (TYPE_OK (intSI_type_node))
2813 : 0 : return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
2814 : 5156 : if (TYPE_OK (intHI_type_node))
2815 : 0 : return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
2816 : 5156 : if (TYPE_OK (intQI_type_node))
2817 : 0 : return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
2818 : :
2819 : : #undef GIMPLE_FIXED_TYPES
2820 : : #undef GIMPLE_FIXED_MODE_TYPES
2821 : : #undef GIMPLE_FIXED_TYPES_SAT
2822 : : #undef GIMPLE_FIXED_MODE_TYPES_SAT
2823 : : #undef TYPE_OK
2824 : :
2825 : 5156 : return build_nonstandard_integer_type (TYPE_PRECISION (type), unsignedp);
2826 : : }
2827 : :
2828 : :
2829 : : /* Return an unsigned type the same as TYPE in other respects. */
2830 : :
2831 : : tree
2832 : 0 : gimple_unsigned_type (tree type)
2833 : : {
2834 : 0 : return gimple_signed_or_unsigned_type (true, type);
2835 : : }
2836 : :
2837 : :
2838 : : /* Return a signed type the same as TYPE in other respects. */
2839 : :
2840 : : tree
2841 : 554721 : gimple_signed_type (tree type)
2842 : : {
2843 : 554721 : return gimple_signed_or_unsigned_type (false, type);
2844 : : }
2845 : :
2846 : :
2847 : : /* Return the typed-based alias set for T, which may be an expression
2848 : : or a type. Return -1 if we don't do anything special. */
2849 : :
2850 : : alias_set_type
2851 : 8166309 : gimple_get_alias_set (tree t)
2852 : : {
2853 : : /* That's all the expressions we handle specially. */
2854 : 8166309 : if (!TYPE_P (t))
2855 : : return -1;
2856 : :
2857 : : /* For convenience, follow the C standard when dealing with
2858 : : character types. Any object may be accessed via an lvalue that
2859 : : has character type. */
2860 : 2349001 : if (t == char_type_node
2861 : 1843118 : || t == signed_char_type_node
2862 : 1843118 : || t == unsigned_char_type_node)
2863 : : return 0;
2864 : :
2865 : : /* Allow aliasing between signed and unsigned variants of the same
2866 : : type. We treat the signed variant as canonical. */
2867 : 1843118 : if (TREE_CODE (t) == INTEGER_TYPE && TYPE_UNSIGNED (t))
2868 : : {
2869 : 553815 : tree t1 = gimple_signed_type (t);
2870 : :
2871 : : /* t1 == t can happen for boolean nodes which are always unsigned. */
2872 : 553815 : if (t1 != t)
2873 : 553815 : return get_alias_set (t1);
2874 : : }
2875 : :
2876 : : /* Allow aliasing between enumeral types and the underlying
2877 : : integer type. This is required for C since those are
2878 : : compatible types. */
2879 : 1289303 : else if (TREE_CODE (t) == ENUMERAL_TYPE)
2880 : : {
2881 : 0 : tree t1 = lang_hooks.types.type_for_size (tree_to_uhwi (TYPE_SIZE (t)),
2882 : : false /* short-cut above */);
2883 : 0 : return get_alias_set (t1);
2884 : : }
2885 : :
2886 : : return -1;
2887 : : }
2888 : :
2889 : :
2890 : : /* Helper for gimple_ior_addresses_taken_1. */
2891 : :
2892 : : static bool
2893 : 53679935 : gimple_ior_addresses_taken_1 (gimple *, tree addr, tree, void *data)
2894 : : {
2895 : 53679935 : bitmap addresses_taken = (bitmap)data;
2896 : 53679935 : addr = get_base_address (addr);
2897 : 53679935 : if (addr
2898 : 53679935 : && DECL_P (addr))
2899 : : {
2900 : 34022012 : bitmap_set_bit (addresses_taken, DECL_UID (addr));
2901 : 34022012 : return true;
2902 : : }
2903 : : return false;
2904 : : }
2905 : :
2906 : : /* Set the bit for the uid of all decls that have their address taken
2907 : : in STMT in the ADDRESSES_TAKEN bitmap. Returns true if there
2908 : : were any in this stmt. */
2909 : :
2910 : : bool
2911 : 833137819 : gimple_ior_addresses_taken (bitmap addresses_taken, gimple *stmt)
2912 : : {
2913 : 833137819 : return walk_stmt_load_store_addr_ops (stmt, addresses_taken, NULL, NULL,
2914 : 833137819 : gimple_ior_addresses_taken_1);
2915 : : }
2916 : :
2917 : :
2918 : : /* Return true when STMTs arguments and return value match those of FNDECL,
2919 : : a decl of a builtin function. */
2920 : :
2921 : : bool
2922 : 283031001 : gimple_builtin_call_types_compatible_p (const gimple *stmt, tree fndecl)
2923 : : {
2924 : 283031001 : gcc_checking_assert (DECL_BUILT_IN_CLASS (fndecl) != NOT_BUILT_IN);
2925 : :
2926 : 283031001 : if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
2927 : 280875596 : if (tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl)))
2928 : 283031001 : fndecl = decl;
2929 : :
2930 : 283031001 : tree ret = gimple_call_lhs (stmt);
2931 : 283031001 : if (ret
2932 : 455646593 : && !useless_type_conversion_p (TREE_TYPE (ret),
2933 : 172615592 : TREE_TYPE (TREE_TYPE (fndecl))))
2934 : : return false;
2935 : :
2936 : 283009378 : tree targs = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
2937 : 283009378 : unsigned nargs = gimple_call_num_args (stmt);
2938 : 855647801 : for (unsigned i = 0; i < nargs; ++i)
2939 : : {
2940 : : /* Variadic args follow. */
2941 : 601641741 : if (!targs)
2942 : : return true;
2943 : 577566275 : tree arg = gimple_call_arg (stmt, i);
2944 : 577566275 : tree type = TREE_VALUE (targs);
2945 : 577566275 : if (!useless_type_conversion_p (type, TREE_TYPE (arg)))
2946 : : return false;
2947 : 572638423 : targs = TREE_CHAIN (targs);
2948 : : }
2949 : 507277740 : if (targs && !VOID_TYPE_P (TREE_VALUE (targs)))
2950 : : return false;
2951 : : return true;
2952 : : }
2953 : :
2954 : : /* Return true when STMT is operator a replaceable delete call. */
2955 : :
2956 : : bool
2957 : 2176292 : gimple_call_operator_delete_p (const gcall *stmt)
2958 : : {
2959 : 2176292 : tree fndecl;
2960 : :
2961 : 2176292 : if ((fndecl = gimple_call_fndecl (stmt)) != NULL_TREE)
2962 : 2176292 : return DECL_IS_OPERATOR_DELETE_P (fndecl);
2963 : : return false;
2964 : : }
2965 : :
2966 : : /* Return true when STMT is builtins call. */
2967 : :
2968 : : bool
2969 : 67903806 : gimple_call_builtin_p (const gimple *stmt)
2970 : : {
2971 : 67903806 : tree fndecl;
2972 : 67903806 : if (is_gimple_call (stmt)
2973 : 20474231 : && (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE
2974 : 87119199 : && DECL_BUILT_IN_CLASS (fndecl) != NOT_BUILT_IN)
2975 : 3892197 : return gimple_builtin_call_types_compatible_p (stmt, fndecl);
2976 : : return false;
2977 : : }
2978 : :
2979 : : /* Return true when STMT is builtins call to CLASS. */
2980 : :
2981 : : bool
2982 : 998273680 : gimple_call_builtin_p (const gimple *stmt, enum built_in_class klass)
2983 : : {
2984 : 998273680 : tree fndecl;
2985 : 998273680 : if (is_gimple_call (stmt)
2986 : 753634279 : && (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE
2987 : 1714777915 : && DECL_BUILT_IN_CLASS (fndecl) == klass)
2988 : 189131656 : return gimple_builtin_call_types_compatible_p (stmt, fndecl);
2989 : : return false;
2990 : : }
2991 : :
2992 : : /* Return true when STMT is builtins call to CODE of CLASS. */
2993 : :
2994 : : bool
2995 : 2984489148 : gimple_call_builtin_p (const gimple *stmt, enum built_in_function code)
2996 : : {
2997 : 2984489148 : tree fndecl;
2998 : 2984489148 : if (is_gimple_call (stmt)
2999 : 876919002 : && (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE
3000 : 3816077589 : && fndecl_built_in_p (fndecl, code))
3001 : 2974078 : return gimple_builtin_call_types_compatible_p (stmt, fndecl);
3002 : : return false;
3003 : : }
3004 : :
3005 : : /* If CALL is a call to a combined_fn (i.e. an internal function or
3006 : : a normal built-in function), return its code, otherwise return
3007 : : CFN_LAST. */
3008 : :
3009 : : combined_fn
3010 : 187439550 : gimple_call_combined_fn (const gimple *stmt)
3011 : : {
3012 : 187439550 : if (const gcall *call = dyn_cast <const gcall *> (stmt))
3013 : : {
3014 : 185517902 : if (gimple_call_internal_p (call))
3015 : 9162267 : return as_combined_fn (gimple_call_internal_fn (call));
3016 : :
3017 : 176355635 : tree fndecl = gimple_call_fndecl (stmt);
3018 : 176355635 : if (fndecl
3019 : 169539667 : && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
3020 : 247065317 : && gimple_builtin_call_types_compatible_p (stmt, fndecl))
3021 : 70156083 : return as_combined_fn (DECL_FUNCTION_CODE (fndecl));
3022 : : }
3023 : : return CFN_LAST;
3024 : : }
3025 : :
3026 : : /* Return true if STMT clobbers memory. STMT is required to be a
3027 : : GIMPLE_ASM. */
3028 : :
3029 : : bool
3030 : 11433624 : gimple_asm_clobbers_memory_p (const gasm *stmt)
3031 : : {
3032 : 11433624 : unsigned i;
3033 : :
3034 : 16701647 : for (i = 0; i < gimple_asm_nclobbers (stmt); i++)
3035 : : {
3036 : 9465505 : tree op = gimple_asm_clobber_op (stmt, i);
3037 : 9465505 : if (strcmp (TREE_STRING_POINTER (TREE_VALUE (op)), "memory") == 0)
3038 : : return true;
3039 : : }
3040 : :
3041 : : /* Non-empty basic ASM implicitly clobbers memory. */
3042 : 7236142 : if (gimple_asm_basic_p (stmt) && strlen (gimple_asm_string (stmt)) != 0)
3043 : 97307 : return true;
3044 : :
3045 : : return false;
3046 : : }
3047 : :
3048 : : /* Dump bitmap SET (assumed to contain VAR_DECLs) to FILE. */
3049 : :
3050 : : void
3051 : 5294 : dump_decl_set (FILE *file, bitmap set)
3052 : : {
3053 : 5294 : if (set)
3054 : : {
3055 : 5294 : bitmap_iterator bi;
3056 : 5294 : unsigned i;
3057 : :
3058 : 5294 : fprintf (file, "{ ");
3059 : :
3060 : 22140 : EXECUTE_IF_SET_IN_BITMAP (set, 0, i, bi)
3061 : : {
3062 : 16846 : fprintf (file, "D.%u", i);
3063 : 16846 : fprintf (file, " ");
3064 : : }
3065 : :
3066 : 5294 : fprintf (file, "}");
3067 : : }
3068 : : else
3069 : 0 : fprintf (file, "NIL");
3070 : 5294 : }
3071 : :
3072 : : /* Return true when CALL is a call stmt that definitely doesn't
3073 : : free any memory or makes it unavailable otherwise. */
3074 : : bool
3075 : 9845679 : nonfreeing_call_p (gimple *call)
3076 : : {
3077 : 9845679 : if (gimple_call_builtin_p (call, BUILT_IN_NORMAL)
3078 : 9845679 : && gimple_call_flags (call) & ECF_LEAF)
3079 : 4267086 : switch (DECL_FUNCTION_CODE (gimple_call_fndecl (call)))
3080 : : {
3081 : : /* Just in case these become ECF_LEAF in the future. */
3082 : : case BUILT_IN_FREE:
3083 : : case BUILT_IN_TM_FREE:
3084 : : case BUILT_IN_REALLOC:
3085 : : case BUILT_IN_STACK_RESTORE:
3086 : : case BUILT_IN_GOMP_FREE:
3087 : : case BUILT_IN_GOMP_REALLOC:
3088 : : return false;
3089 : : default:
3090 : : return true;
3091 : : }
3092 : 5578593 : else if (gimple_call_internal_p (call))
3093 : 769474 : switch (gimple_call_internal_fn (call))
3094 : : {
3095 : : case IFN_ABNORMAL_DISPATCHER:
3096 : : return true;
3097 : 33719 : case IFN_ASAN_MARK:
3098 : 33719 : return tree_to_uhwi (gimple_call_arg (call, 0)) == ASAN_MARK_UNPOISON;
3099 : 729924 : default:
3100 : 729924 : if (gimple_call_flags (call) & ECF_LEAF)
3101 : : return true;
3102 : : return false;
3103 : : }
3104 : :
3105 : 4809119 : tree fndecl = gimple_call_fndecl (call);
3106 : 4809119 : if (!fndecl)
3107 : : return false;
3108 : 4639700 : struct cgraph_node *n = cgraph_node::get (fndecl);
3109 : 4639700 : if (!n)
3110 : : return false;
3111 : 4638321 : enum availability availability;
3112 : 4638321 : n = n->function_symbol (&availability);
3113 : 4638321 : if (!n || availability <= AVAIL_INTERPOSABLE)
3114 : : return false;
3115 : 1151384 : return n->nonfreeing_fn;
3116 : : }
3117 : :
3118 : : /* Return true when CALL is a call stmt that definitely need not
3119 : : be considered to be a memory barrier. */
3120 : : bool
3121 : 1645022 : nonbarrier_call_p (gimple *call)
3122 : : {
3123 : 1645022 : if (gimple_call_flags (call) & (ECF_PURE | ECF_CONST))
3124 : 648573 : return true;
3125 : : /* Should extend this to have a nonbarrier_fn flag, just as above in
3126 : : the nonfreeing case. */
3127 : : return false;
3128 : : }
3129 : :
3130 : : /* Callback for walk_stmt_load_store_ops.
3131 : :
3132 : : Return TRUE if OP will dereference the tree stored in DATA, FALSE
3133 : : otherwise.
3134 : :
3135 : : This routine only makes a superficial check for a dereference. Thus
3136 : : it must only be used if it is safe to return a false negative. */
3137 : : static bool
3138 : 76913151 : check_loadstore (gimple *, tree op, tree, void *data)
3139 : : {
3140 : 76913151 : if (TREE_CODE (op) == MEM_REF || TREE_CODE (op) == TARGET_MEM_REF)
3141 : : {
3142 : : /* Some address spaces may legitimately dereference zero. */
3143 : 39689255 : addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (op));
3144 : 39689255 : if (targetm.addr_space.zero_address_valid (as))
3145 : : return false;
3146 : :
3147 : 39688142 : return operand_equal_p (TREE_OPERAND (op, 0), (tree)data, 0);
3148 : : }
3149 : : return false;
3150 : : }
3151 : :
3152 : :
3153 : : /* Return true if OP can be inferred to be non-NULL after STMT executes,
3154 : : either by using a pointer dereference or attributes. */
3155 : : bool
3156 : 0 : infer_nonnull_range (gimple *stmt, tree op)
3157 : : {
3158 : 0 : return (infer_nonnull_range_by_dereference (stmt, op)
3159 : 0 : || infer_nonnull_range_by_attribute (stmt, op));
3160 : : }
3161 : :
3162 : : /* Return true if OP can be inferred to be non-NULL after STMT
3163 : : executes by using a pointer dereference. */
3164 : : bool
3165 : 330556690 : infer_nonnull_range_by_dereference (gimple *stmt, tree op)
3166 : : {
3167 : : /* We can only assume that a pointer dereference will yield
3168 : : non-NULL if -fdelete-null-pointer-checks is enabled. */
3169 : 330556690 : if (!flag_delete_null_pointer_checks
3170 : 330342325 : || !POINTER_TYPE_P (TREE_TYPE (op))
3171 : 330342325 : || gimple_code (stmt) == GIMPLE_ASM
3172 : 660448707 : || gimple_clobber_p (stmt))
3173 : : return false;
3174 : :
3175 : 322942021 : if (walk_stmt_load_store_ops (stmt, (void *)op,
3176 : : check_loadstore, check_loadstore))
3177 : : return true;
3178 : :
3179 : : return false;
3180 : : }
3181 : :
3182 : : /* Return true if OP can be inferred to be a non-NULL after STMT
3183 : : executes by using attributes. If OP2 and OP3 are non-NULL and
3184 : : nonnull_if_nonzero is the only attribute implying OP being non-NULL
3185 : : and the corresponding argument(s) aren't non-zero INTEGER_CST, set *OP2
3186 : : and *OP3 to the corresponding arguments and return true (in that case
3187 : : returning true doesn't mean OP can be unconditionally inferred to be
3188 : : non-NULL, but conditionally). */
3189 : : bool
3190 : 73814975 : infer_nonnull_range_by_attribute (gimple *stmt, tree op, tree *op2, tree *op3)
3191 : : {
3192 : 73814975 : if (op2)
3193 : : {
3194 : 3900 : *op2 = NULL_TREE;
3195 : 3900 : *op3 = NULL_TREE;
3196 : : }
3197 : :
3198 : : /* We can only assume that a pointer dereference will yield
3199 : : non-NULL if -fdelete-null-pointer-checks is enabled. */
3200 : 73814975 : if (!flag_delete_null_pointer_checks
3201 : 73787492 : || !POINTER_TYPE_P (TREE_TYPE (op))
3202 : 147602467 : || gimple_code (stmt) == GIMPLE_ASM)
3203 : : return false;
3204 : :
3205 : 73732751 : if (is_gimple_call (stmt) && !gimple_call_internal_p (stmt))
3206 : : {
3207 : 4383755 : tree fntype = gimple_call_fntype (stmt);
3208 : 4383755 : tree attrs = TYPE_ATTRIBUTES (fntype);
3209 : 4480405 : for (; attrs; attrs = TREE_CHAIN (attrs))
3210 : : {
3211 : 1122950 : attrs = lookup_attribute ("nonnull", attrs);
3212 : :
3213 : : /* If "nonnull" wasn't specified, we know nothing about
3214 : : the argument, unless "nonnull_if_nonzero" attribute is
3215 : : present. */
3216 : 1122950 : if (attrs == NULL_TREE)
3217 : : break;
3218 : :
3219 : : /* If "nonnull" applies to all the arguments, then ARG
3220 : : is non-null if it's in the argument list. */
3221 : 255063 : if (TREE_VALUE (attrs) == NULL_TREE)
3222 : : {
3223 : 460736 : for (unsigned int i = 0; i < gimple_call_num_args (stmt); i++)
3224 : : {
3225 : 311240 : if (POINTER_TYPE_P (TREE_TYPE (gimple_call_arg (stmt, i)))
3226 : 303465 : && operand_equal_p (op, gimple_call_arg (stmt, i), 0))
3227 : : return true;
3228 : : }
3229 : : return false;
3230 : : }
3231 : :
3232 : : /* Now see if op appears in the nonnull list. */
3233 : 245867 : for (tree t = TREE_VALUE (attrs); t; t = TREE_CHAIN (t))
3234 : : {
3235 : 149217 : unsigned int idx = TREE_INT_CST_LOW (TREE_VALUE (t)) - 1;
3236 : 149217 : if (idx < gimple_call_num_args (stmt))
3237 : : {
3238 : 149216 : tree arg = gimple_call_arg (stmt, idx);
3239 : 149216 : if (operand_equal_p (op, arg, 0))
3240 : : return true;
3241 : : }
3242 : : }
3243 : : }
3244 : :
3245 : 4225342 : for (attrs = TYPE_ATTRIBUTES (fntype);
3246 : 4402400 : (attrs = lookup_attribute ("nonnull_if_nonzero", attrs));
3247 : 177058 : attrs = TREE_CHAIN (attrs))
3248 : : {
3249 : 177693 : tree args = TREE_VALUE (attrs);
3250 : 177693 : unsigned int idx = TREE_INT_CST_LOW (TREE_VALUE (args)) - 1;
3251 : 177693 : unsigned int idx2
3252 : 177693 : = TREE_INT_CST_LOW (TREE_VALUE (TREE_CHAIN (args))) - 1;
3253 : 177693 : unsigned int idx3 = idx2;
3254 : 177693 : if (tree chain2 = TREE_CHAIN (TREE_CHAIN (args)))
3255 : 4288 : idx3 = TREE_INT_CST_LOW (TREE_VALUE (chain2)) - 1;
3256 : 177693 : if (idx < gimple_call_num_args (stmt)
3257 : 177681 : && idx2 < gimple_call_num_args (stmt)
3258 : 177670 : && idx3 < gimple_call_num_args (stmt)
3259 : 355363 : && operand_equal_p (op, gimple_call_arg (stmt, idx), 0))
3260 : : {
3261 : 635 : tree arg2 = gimple_call_arg (stmt, idx2);
3262 : 635 : tree arg3 = gimple_call_arg (stmt, idx3);
3263 : 1270 : if (!INTEGRAL_TYPE_P (TREE_TYPE (arg2))
3264 : 1270 : || !INTEGRAL_TYPE_P (TREE_TYPE (arg3)))
3265 : : return false;
3266 : 635 : if (integer_nonzerop (arg2) && integer_nonzerop (arg3))
3267 : : return true;
3268 : 413 : if (integer_zerop (arg2) || integer_zerop (arg3))
3269 : 90 : return false;
3270 : 323 : if (op2)
3271 : : {
3272 : : /* This case is meant for ubsan instrumentation.
3273 : : The caller can check at runtime if *OP2 and *OP3 are
3274 : : non-zero and OP is null. */
3275 : 132 : *op2 = arg2;
3276 : 132 : *op3 = arg3;
3277 : 132 : return true;
3278 : : }
3279 : 191 : return tree_expr_nonzero_p (arg2) && tree_expr_nonzero_p (arg3);
3280 : : }
3281 : : }
3282 : : }
3283 : :
3284 : : /* If this function is marked as returning non-null, then we can
3285 : : infer OP is non-null if it is used in the return statement. */
3286 : 73573703 : if (greturn *return_stmt = dyn_cast <greturn *> (stmt))
3287 : 946925 : if (gimple_return_retval (return_stmt)
3288 : 547368 : && operand_equal_p (gimple_return_retval (return_stmt), op, 0)
3289 : 1037040 : && lookup_attribute ("returns_nonnull",
3290 : 90115 : TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))
3291 : : return true;
3292 : :
3293 : : return false;
3294 : : }
3295 : :
3296 : : /* Compare two case labels. Because the front end should already have
3297 : : made sure that case ranges do not overlap, it is enough to only compare
3298 : : the CASE_LOW values of each case label. */
3299 : :
3300 : : static int
3301 : 44229770 : compare_case_labels (const void *p1, const void *p2)
3302 : : {
3303 : 44229770 : const_tree const case1 = *(const_tree const*)p1;
3304 : 44229770 : const_tree const case2 = *(const_tree const*)p2;
3305 : :
3306 : : /* The 'default' case label always goes first. */
3307 : 44229770 : if (!CASE_LOW (case1))
3308 : : return -1;
3309 : 44229770 : else if (!CASE_LOW (case2))
3310 : : return 1;
3311 : : else
3312 : 44229770 : return tree_int_cst_compare (CASE_LOW (case1), CASE_LOW (case2));
3313 : : }
3314 : :
3315 : : /* Sort the case labels in LABEL_VEC in place in ascending order. */
3316 : :
3317 : : void
3318 : 71433 : sort_case_labels (vec<tree> &label_vec)
3319 : : {
3320 : 71433 : label_vec.qsort (compare_case_labels);
3321 : 71433 : }
3322 : :
3323 : : /* Prepare a vector of case labels to be used in a GIMPLE_SWITCH statement.
3324 : :
3325 : : LABELS is a vector that contains all case labels to look at.
3326 : :
3327 : : INDEX_TYPE is the type of the switch index expression. Case labels
3328 : : in LABELS are discarded if their values are not in the value range
3329 : : covered by INDEX_TYPE. The remaining case label values are folded
3330 : : to INDEX_TYPE.
3331 : :
3332 : : If a default case exists in LABELS, it is removed from LABELS and
3333 : : returned in DEFAULT_CASEP. If no default case exists, but the
3334 : : case labels already cover the whole range of INDEX_TYPE, a default
3335 : : case is returned pointing to one of the existing case labels.
3336 : : Otherwise DEFAULT_CASEP is set to NULL_TREE.
3337 : :
3338 : : DEFAULT_CASEP may be NULL, in which case the above comment doesn't
3339 : : apply and no action is taken regardless of whether a default case is
3340 : : found or not. */
3341 : :
3342 : : void
3343 : 63991 : preprocess_case_label_vec_for_gimple (vec<tree> &labels,
3344 : : tree index_type,
3345 : : tree *default_casep)
3346 : : {
3347 : 63991 : tree min_value, max_value;
3348 : 63991 : tree default_case = NULL_TREE;
3349 : 63991 : size_t i, len;
3350 : :
3351 : 63991 : i = 0;
3352 : 63991 : min_value = TYPE_MIN_VALUE (index_type);
3353 : 63991 : max_value = TYPE_MAX_VALUE (index_type);
3354 : 1183388 : while (i < labels.length ())
3355 : : {
3356 : 1119397 : tree elt = labels[i];
3357 : 1119397 : tree low = CASE_LOW (elt);
3358 : 1119397 : tree high = CASE_HIGH (elt);
3359 : 1119397 : bool remove_element = false;
3360 : :
3361 : 1119397 : if (low)
3362 : : {
3363 : 1081929 : gcc_checking_assert (TREE_CODE (low) == INTEGER_CST);
3364 : 1081929 : gcc_checking_assert (!high || TREE_CODE (high) == INTEGER_CST);
3365 : :
3366 : : /* This is a non-default case label, i.e. it has a value.
3367 : :
3368 : : See if the case label is reachable within the range of
3369 : : the index type. Remove out-of-range case values. Turn
3370 : : case ranges into a canonical form (high > low strictly)
3371 : : and convert the case label values to the index type.
3372 : :
3373 : : NB: The type of gimple_switch_index() may be the promoted
3374 : : type, but the case labels retain the original type. */
3375 : :
3376 : 13143 : if (high)
3377 : : {
3378 : : /* This is a case range. Discard empty ranges.
3379 : : If the bounds or the range are equal, turn this
3380 : : into a simple (one-value) case. */
3381 : 13143 : int cmp = tree_int_cst_compare (high, low);
3382 : 13143 : if (cmp < 0)
3383 : : remove_element = true;
3384 : 13143 : else if (cmp == 0)
3385 : : high = NULL_TREE;
3386 : : }
3387 : :
3388 : 1070785 : if (! high)
3389 : : {
3390 : : /* If the simple case value is unreachable, ignore it. */
3391 : 1079930 : if ((TREE_CODE (min_value) == INTEGER_CST
3392 : 1079930 : && tree_int_cst_compare (low, min_value) < 0)
3393 : 2159817 : || (TREE_CODE (max_value) == INTEGER_CST
3394 : 1079887 : && tree_int_cst_compare (low, max_value) > 0))
3395 : : remove_element = true;
3396 : : else
3397 : 1079769 : low = fold_convert (index_type, low);
3398 : : }
3399 : : else
3400 : : {
3401 : : /* If the entire case range is unreachable, ignore it. */
3402 : 1999 : if ((TREE_CODE (min_value) == INTEGER_CST
3403 : 1999 : && tree_int_cst_compare (high, min_value) < 0)
3404 : 3986 : || (TREE_CODE (max_value) == INTEGER_CST
3405 : 1987 : && tree_int_cst_compare (low, max_value) > 0))
3406 : : remove_element = true;
3407 : : else
3408 : : {
3409 : : /* If the lower bound is less than the index type's
3410 : : minimum value, truncate the range bounds. */
3411 : 1987 : if (TREE_CODE (min_value) == INTEGER_CST
3412 : 1987 : && tree_int_cst_compare (low, min_value) < 0)
3413 : : low = min_value;
3414 : 1987 : low = fold_convert (index_type, low);
3415 : :
3416 : : /* If the upper bound is greater than the index type's
3417 : : maximum value, truncate the range bounds. */
3418 : 1987 : if (TREE_CODE (max_value) == INTEGER_CST
3419 : 1987 : && tree_int_cst_compare (high, max_value) > 0)
3420 : : high = max_value;
3421 : 1987 : high = fold_convert (index_type, high);
3422 : :
3423 : : /* We may have folded a case range to a one-value case. */
3424 : 1987 : if (tree_int_cst_equal (low, high))
3425 : 0 : high = NULL_TREE;
3426 : : }
3427 : : }
3428 : :
3429 : 1081929 : CASE_LOW (elt) = low;
3430 : 1081929 : CASE_HIGH (elt) = high;
3431 : : }
3432 : : else
3433 : : {
3434 : 37468 : gcc_assert (!default_case);
3435 : 37468 : default_case = elt;
3436 : : /* The default case must be passed separately to the
3437 : : gimple_build_switch routine. But if DEFAULT_CASEP
3438 : : is NULL, we do not remove the default case (it would
3439 : : be completely lost). */
3440 : 37468 : if (default_casep)
3441 : : remove_element = true;
3442 : : }
3443 : :
3444 : 1081929 : if (remove_element)
3445 : 37641 : labels.ordered_remove (i);
3446 : : else
3447 : 1081756 : i++;
3448 : : }
3449 : 63991 : len = i;
3450 : :
3451 : 63991 : if (!labels.is_empty ())
3452 : 63150 : sort_case_labels (labels);
3453 : :
3454 : 63991 : if (default_casep && !default_case)
3455 : : {
3456 : : /* If the switch has no default label, add one, so that we jump
3457 : : around the switch body. If the labels already cover the whole
3458 : : range of the switch index_type, add the default label pointing
3459 : : to one of the existing labels. */
3460 : 14720 : if (len
3461 : 14242 : && TYPE_MIN_VALUE (index_type)
3462 : 14242 : && TYPE_MAX_VALUE (index_type)
3463 : 28962 : && tree_int_cst_equal (CASE_LOW (labels[0]),
3464 : 14242 : TYPE_MIN_VALUE (index_type)))
3465 : : {
3466 : 4387 : tree low, high = CASE_HIGH (labels[len - 1]);
3467 : 4387 : if (!high)
3468 : 4344 : high = CASE_LOW (labels[len - 1]);
3469 : 4387 : if (tree_int_cst_equal (high, TYPE_MAX_VALUE (index_type)))
3470 : : {
3471 : 61 : tree widest_label = labels[0];
3472 : 129 : for (i = 1; i < len; i++)
3473 : : {
3474 : 82 : high = CASE_LOW (labels[i]);
3475 : 82 : low = CASE_HIGH (labels[i - 1]);
3476 : 82 : if (!low)
3477 : 52 : low = CASE_LOW (labels[i - 1]);
3478 : :
3479 : 82 : if (CASE_HIGH (labels[i]) != NULL_TREE
3480 : 113 : && (CASE_HIGH (widest_label) == NULL_TREE
3481 : 26 : || (wi::gtu_p
3482 : 52 : (wi::to_wide (CASE_HIGH (labels[i]))
3483 : 78 : - wi::to_wide (CASE_LOW (labels[i])),
3484 : 26 : wi::to_wide (CASE_HIGH (widest_label))
3485 : 160 : - wi::to_wide (CASE_LOW (widest_label))))))
3486 : 17 : widest_label = labels[i];
3487 : :
3488 : 82 : if (wi::to_wide (low) + 1 != wi::to_wide (high))
3489 : : break;
3490 : : }
3491 : 61 : if (i == len)
3492 : : {
3493 : : /* Designate the label with the widest range to be the
3494 : : default label. */
3495 : 47 : tree label = CASE_LABEL (widest_label);
3496 : 47 : default_case = build_case_label (NULL_TREE, NULL_TREE,
3497 : : label);
3498 : : }
3499 : : }
3500 : : }
3501 : : }
3502 : :
3503 : 63991 : if (default_casep)
3504 : 52188 : *default_casep = default_case;
3505 : 63991 : }
3506 : :
3507 : : /* Set the location of all statements in SEQ to LOC. */
3508 : :
3509 : : void
3510 : 1005886 : gimple_seq_set_location (gimple_seq seq, location_t loc)
3511 : : {
3512 : 2031691 : for (gimple_stmt_iterator i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
3513 : 1025805 : gimple_set_location (gsi_stmt (i), loc);
3514 : 1005886 : }
3515 : :
3516 : : /* Release SSA_NAMEs in SEQ as well as the GIMPLE statements. */
3517 : :
3518 : : void
3519 : 5425723 : gimple_seq_discard (gimple_seq seq)
3520 : : {
3521 : 5425723 : gimple_stmt_iterator gsi;
3522 : :
3523 : 5969291 : for (gsi = gsi_start (seq); !gsi_end_p (gsi); )
3524 : : {
3525 : 366874 : gimple *stmt = gsi_stmt (gsi);
3526 : 366874 : gsi_remove (&gsi, true);
3527 : 366874 : release_defs (stmt);
3528 : 366874 : ggc_free (stmt);
3529 : : }
3530 : 5425723 : }
3531 : :
3532 : : /* See if STMT now calls function that takes no parameters and if so, drop
3533 : : call arguments. This is used when devirtualization machinery redirects
3534 : : to __builtin_unreachable or __cxa_pure_virtual. */
3535 : :
3536 : : void
3537 : 953260 : maybe_remove_unused_call_args (struct function *fn, gimple *stmt)
3538 : : {
3539 : 953260 : tree decl = gimple_call_fndecl (stmt);
3540 : 953260 : if (TYPE_ARG_TYPES (TREE_TYPE (decl))
3541 : 952414 : && TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))) == void_type_node
3542 : 1134928 : && gimple_call_num_args (stmt))
3543 : : {
3544 : 104333 : gimple_set_num_ops (stmt, 3);
3545 : 104333 : update_stmt_fn (fn, stmt);
3546 : : }
3547 : 953260 : }
3548 : :
3549 : : /* Return false if STMT will likely expand to real function call. */
3550 : :
3551 : : bool
3552 : 3278128 : gimple_inexpensive_call_p (gcall *stmt)
3553 : : {
3554 : 3278128 : if (gimple_call_internal_p (stmt))
3555 : : return true;
3556 : 3219818 : tree decl = gimple_call_fndecl (stmt);
3557 : 3219818 : if (decl && is_inexpensive_builtin (decl))
3558 : : return true;
3559 : : return false;
3560 : : }
3561 : :
3562 : : /* Return a non-artificial location for STMT. If STMT does not have
3563 : : location information, get the location from EXPR. */
3564 : :
3565 : : location_t
3566 : 127784 : gimple_or_expr_nonartificial_location (gimple *stmt, tree expr)
3567 : : {
3568 : 127784 : location_t loc = gimple_nonartificial_location (stmt);
3569 : 127784 : if (loc == UNKNOWN_LOCATION && EXPR_HAS_LOCATION (expr))
3570 : 52 : loc = tree_nonartificial_location (expr);
3571 : 127784 : return expansion_point_location_if_in_system_header (loc);
3572 : : }
3573 : :
3574 : :
3575 : : #if CHECKING_P
3576 : :
3577 : : namespace selftest {
3578 : :
3579 : : /* Selftests for core gimple structures. */
3580 : :
3581 : : /* Verify that STMT is pretty-printed as EXPECTED.
3582 : : Helper function for selftests. */
3583 : :
3584 : : static void
3585 : 20 : verify_gimple_pp (const char *expected, gimple *stmt)
3586 : : {
3587 : 20 : pretty_printer pp;
3588 : 20 : pp_gimple_stmt_1 (&pp, stmt, 0 /* spc */, TDF_NONE /* flags */);
3589 : 20 : ASSERT_STREQ (expected, pp_formatted_text (&pp));
3590 : 20 : }
3591 : :
3592 : : /* Build a GIMPLE_ASSIGN equivalent to
3593 : : tmp = 5;
3594 : : and verify various properties of it. */
3595 : :
3596 : : static void
3597 : 4 : test_assign_single ()
3598 : : {
3599 : 4 : tree type = integer_type_node;
3600 : 4 : tree lhs = build_decl (UNKNOWN_LOCATION, VAR_DECL,
3601 : : get_identifier ("tmp"),
3602 : : type);
3603 : 4 : tree rhs = build_int_cst (type, 5);
3604 : 4 : gassign *stmt = gimple_build_assign (lhs, rhs);
3605 : 4 : verify_gimple_pp ("tmp = 5;", stmt);
3606 : :
3607 : 4 : ASSERT_TRUE (is_gimple_assign (stmt));
3608 : 4 : ASSERT_EQ (lhs, gimple_assign_lhs (stmt));
3609 : 4 : ASSERT_EQ (lhs, gimple_get_lhs (stmt));
3610 : 4 : ASSERT_EQ (rhs, gimple_assign_rhs1 (stmt));
3611 : 4 : ASSERT_EQ (NULL, gimple_assign_rhs2 (stmt));
3612 : 4 : ASSERT_EQ (NULL, gimple_assign_rhs3 (stmt));
3613 : 4 : ASSERT_TRUE (gimple_assign_single_p (stmt));
3614 : 8 : ASSERT_EQ (INTEGER_CST, gimple_assign_rhs_code (stmt));
3615 : 4 : }
3616 : :
3617 : : /* Build a GIMPLE_ASSIGN equivalent to
3618 : : tmp = a * b;
3619 : : and verify various properties of it. */
3620 : :
3621 : : static void
3622 : 4 : test_assign_binop ()
3623 : : {
3624 : 4 : tree type = integer_type_node;
3625 : 4 : tree lhs = build_decl (UNKNOWN_LOCATION, VAR_DECL,
3626 : : get_identifier ("tmp"),
3627 : : type);
3628 : 4 : tree a = build_decl (UNKNOWN_LOCATION, VAR_DECL,
3629 : : get_identifier ("a"),
3630 : : type);
3631 : 4 : tree b = build_decl (UNKNOWN_LOCATION, VAR_DECL,
3632 : : get_identifier ("b"),
3633 : : type);
3634 : 4 : gassign *stmt = gimple_build_assign (lhs, MULT_EXPR, a, b);
3635 : 4 : verify_gimple_pp ("tmp = a * b;", stmt);
3636 : :
3637 : 4 : ASSERT_TRUE (is_gimple_assign (stmt));
3638 : 4 : ASSERT_EQ (lhs, gimple_assign_lhs (stmt));
3639 : 4 : ASSERT_EQ (lhs, gimple_get_lhs (stmt));
3640 : 4 : ASSERT_EQ (a, gimple_assign_rhs1 (stmt));
3641 : 8 : ASSERT_EQ (b, gimple_assign_rhs2 (stmt));
3642 : 4 : ASSERT_EQ (NULL, gimple_assign_rhs3 (stmt));
3643 : 4 : ASSERT_FALSE (gimple_assign_single_p (stmt));
3644 : 4 : ASSERT_EQ (MULT_EXPR, gimple_assign_rhs_code (stmt));
3645 : 4 : }
3646 : :
3647 : : /* Build a GIMPLE_NOP and verify various properties of it. */
3648 : :
3649 : : static void
3650 : 4 : test_nop_stmt ()
3651 : : {
3652 : 4 : gimple *stmt = gimple_build_nop ();
3653 : 4 : verify_gimple_pp ("GIMPLE_NOP", stmt);
3654 : 4 : ASSERT_EQ (GIMPLE_NOP, gimple_code (stmt));
3655 : 4 : ASSERT_EQ (NULL, gimple_get_lhs (stmt));
3656 : 4 : ASSERT_FALSE (gimple_assign_single_p (stmt));
3657 : 4 : }
3658 : :
3659 : : /* Build a GIMPLE_RETURN equivalent to
3660 : : return 7;
3661 : : and verify various properties of it. */
3662 : :
3663 : : static void
3664 : 4 : test_return_stmt ()
3665 : : {
3666 : 4 : tree type = integer_type_node;
3667 : 4 : tree val = build_int_cst (type, 7);
3668 : 4 : greturn *stmt = gimple_build_return (val);
3669 : 4 : verify_gimple_pp ("return 7;", stmt);
3670 : :
3671 : 4 : ASSERT_EQ (GIMPLE_RETURN, gimple_code (stmt));
3672 : 4 : ASSERT_EQ (NULL, gimple_get_lhs (stmt));
3673 : 4 : ASSERT_EQ (val, gimple_return_retval (stmt));
3674 : 4 : ASSERT_FALSE (gimple_assign_single_p (stmt));
3675 : 4 : }
3676 : :
3677 : : /* Build a GIMPLE_RETURN equivalent to
3678 : : return;
3679 : : and verify various properties of it. */
3680 : :
3681 : : static void
3682 : 4 : test_return_without_value ()
3683 : : {
3684 : 4 : greturn *stmt = gimple_build_return (NULL);
3685 : 4 : verify_gimple_pp ("return;", stmt);
3686 : :
3687 : 4 : ASSERT_EQ (GIMPLE_RETURN, gimple_code (stmt));
3688 : 4 : ASSERT_EQ (NULL, gimple_get_lhs (stmt));
3689 : 4 : ASSERT_EQ (NULL, gimple_return_retval (stmt));
3690 : 4 : ASSERT_FALSE (gimple_assign_single_p (stmt));
3691 : 4 : }
3692 : :
3693 : : /* Run all of the selftests within this file. */
3694 : :
3695 : : void
3696 : 4 : gimple_cc_tests ()
3697 : : {
3698 : 4 : test_assign_single ();
3699 : 4 : test_assign_binop ();
3700 : 4 : test_nop_stmt ();
3701 : 4 : test_return_stmt ();
3702 : 4 : test_return_without_value ();
3703 : 4 : }
3704 : :
3705 : : } // namespace selftest
3706 : :
3707 : :
3708 : : #endif /* CHECKING_P */
|