Branch data Line data Source code
1 : : /* Control flow functions for trees.
2 : : Copyright (C) 2001-2024 Free Software Foundation, Inc.
3 : : Contributed by Diego Novillo <dnovillo@redhat.com>
4 : :
5 : : This file is part of GCC.
6 : :
7 : : GCC is free software; you can redistribute it and/or modify
8 : : it under the terms of the GNU General Public License as published by
9 : : the Free Software Foundation; either version 3, or (at your option)
10 : : any later version.
11 : :
12 : : GCC is distributed in the hope that it will be useful,
13 : : but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : : GNU General Public License for more details.
16 : :
17 : : You should have received a copy of the GNU General Public License
18 : : along with GCC; see the file COPYING3. If not see
19 : : <http://www.gnu.org/licenses/>. */
20 : :
21 : : #include "config.h"
22 : : #include "system.h"
23 : : #include "coretypes.h"
24 : : #include "backend.h"
25 : : #include "target.h"
26 : : #include "rtl.h"
27 : : #include "tree.h"
28 : : #include "gimple.h"
29 : : #include "cfghooks.h"
30 : : #include "tree-pass.h"
31 : : #include "ssa.h"
32 : : #include "cgraph.h"
33 : : #include "gimple-pretty-print.h"
34 : : #include "diagnostic-core.h"
35 : : #include "fold-const.h"
36 : : #include "trans-mem.h"
37 : : #include "stor-layout.h"
38 : : #include "print-tree.h"
39 : : #include "cfganal.h"
40 : : #include "gimple-iterator.h"
41 : : #include "gimple-fold.h"
42 : : #include "tree-eh.h"
43 : : #include "gimplify-me.h"
44 : : #include "gimple-walk.h"
45 : : #include "tree-cfg.h"
46 : : #include "tree-ssa-loop-manip.h"
47 : : #include "tree-ssa-loop-niter.h"
48 : : #include "tree-into-ssa.h"
49 : : #include "tree-dfa.h"
50 : : #include "tree-ssa.h"
51 : : #include "except.h"
52 : : #include "cfgloop.h"
53 : : #include "tree-ssa-propagate.h"
54 : : #include "value-prof.h"
55 : : #include "tree-inline.h"
56 : : #include "tree-ssa-live.h"
57 : : #include "tree-ssa-dce.h"
58 : : #include "omp-general.h"
59 : : #include "omp-expand.h"
60 : : #include "tree-cfgcleanup.h"
61 : : #include "gimplify.h"
62 : : #include "attribs.h"
63 : : #include "selftest.h"
64 : : #include "opts.h"
65 : : #include "asan.h"
66 : : #include "profile.h"
67 : : #include "sreal.h"
68 : :
69 : : /* This file contains functions for building the Control Flow Graph (CFG)
70 : : for a function tree. */
71 : :
72 : : /* Local declarations. */
73 : :
74 : : /* Initial capacity for the basic block array. */
75 : : static const int initial_cfg_capacity = 20;
76 : :
77 : : /* This hash table allows us to efficiently lookup all CASE_LABEL_EXPRs
78 : : which use a particular edge. The CASE_LABEL_EXPRs are chained together
79 : : via their CASE_CHAIN field, which we clear after we're done with the
80 : : hash table to prevent problems with duplication of GIMPLE_SWITCHes.
81 : :
82 : : Access to this list of CASE_LABEL_EXPRs allows us to efficiently
83 : : update the case vector in response to edge redirections.
84 : :
85 : : Right now this table is set up and torn down at key points in the
86 : : compilation process. It would be nice if we could make the table
87 : : more persistent. The key is getting notification of changes to
88 : : the CFG (particularly edge removal, creation and redirection). */
89 : :
90 : : static hash_map<edge, tree> *edge_to_cases;
91 : :
92 : : /* If we record edge_to_cases, this bitmap will hold indexes
93 : : of basic blocks that end in a GIMPLE_SWITCH which we touched
94 : : due to edge manipulations. */
95 : :
96 : : static bitmap touched_switch_bbs;
97 : :
98 : : /* OpenMP region idxs for blocks during cfg pass. */
99 : : static vec<int> bb_to_omp_idx;
100 : :
101 : : /* CFG statistics. */
102 : : struct cfg_stats_d
103 : : {
104 : : long num_merged_labels;
105 : : };
106 : :
107 : : static struct cfg_stats_d cfg_stats;
108 : :
109 : : /* Data to pass to replace_block_vars_by_duplicates_1. */
110 : : struct replace_decls_d
111 : : {
112 : : hash_map<tree, tree> *vars_map;
113 : : tree to_context;
114 : : };
115 : :
116 : : /* Hash table to store last discriminator assigned for each locus. */
117 : : struct locus_discrim_map
118 : : {
119 : : int location_line;
120 : : int discriminator;
121 : : };
122 : :
123 : : /* Hashtable helpers. */
124 : :
125 : : struct locus_discrim_hasher : free_ptr_hash <locus_discrim_map>
126 : : {
127 : : static inline hashval_t hash (const locus_discrim_map *);
128 : : static inline bool equal (const locus_discrim_map *,
129 : : const locus_discrim_map *);
130 : : };
131 : :
132 : : /* Trivial hash function for a location_t. ITEM is a pointer to
133 : : a hash table entry that maps a location_t to a discriminator. */
134 : :
135 : : inline hashval_t
136 : 78534647 : locus_discrim_hasher::hash (const locus_discrim_map *item)
137 : : {
138 : 78534647 : return item->location_line;
139 : : }
140 : :
141 : : /* Equality function for the locus-to-discriminator map. A and B
142 : : point to the two hash table entries to compare. */
143 : :
144 : : inline bool
145 : 86703131 : locus_discrim_hasher::equal (const locus_discrim_map *a,
146 : : const locus_discrim_map *b)
147 : : {
148 : 86703131 : return a->location_line == b->location_line;
149 : : }
150 : :
151 : : static hash_table<locus_discrim_hasher> *discriminator_per_locus;
152 : :
153 : : /* Basic blocks and flowgraphs. */
154 : : static void make_blocks (gimple_seq);
155 : :
156 : : /* Edges. */
157 : : static void make_edges (void);
158 : : static void assign_discriminators (void);
159 : : static void make_cond_expr_edges (basic_block);
160 : : static void make_gimple_switch_edges (gswitch *, basic_block);
161 : : static bool make_goto_expr_edges (basic_block);
162 : : static void make_gimple_asm_edges (basic_block);
163 : : static edge gimple_redirect_edge_and_branch (edge, basic_block);
164 : : static edge gimple_try_redirect_by_replacing_jump (edge, basic_block);
165 : :
166 : : /* Various helpers. */
167 : : static inline bool stmt_starts_bb_p (gimple *, gimple *);
168 : : static bool gimple_verify_flow_info (void);
169 : : static void gimple_make_forwarder_block (edge);
170 : : static gimple *first_non_label_stmt (basic_block);
171 : : static bool verify_gimple_transaction (gtransaction *);
172 : : static bool call_can_make_abnormal_goto (gimple *);
173 : :
174 : : /* Flowgraph optimization and cleanup. */
175 : : static void gimple_merge_blocks (basic_block, basic_block);
176 : : static bool gimple_can_merge_blocks_p (basic_block, basic_block);
177 : : static void remove_bb (basic_block);
178 : : static edge find_taken_edge_computed_goto (basic_block, tree);
179 : : static edge find_taken_edge_cond_expr (const gcond *, tree);
180 : :
181 : : void
182 : 3032382 : init_empty_tree_cfg_for_function (struct function *fn)
183 : : {
184 : : /* Initialize the basic block array. */
185 : 3032382 : init_flow (fn);
186 : 3032382 : profile_status_for_fn (fn) = PROFILE_ABSENT;
187 : 3032382 : n_basic_blocks_for_fn (fn) = NUM_FIXED_BLOCKS;
188 : 3032382 : last_basic_block_for_fn (fn) = NUM_FIXED_BLOCKS;
189 : 3032382 : vec_safe_grow_cleared (basic_block_info_for_fn (fn),
190 : : initial_cfg_capacity, true);
191 : :
192 : : /* Build a mapping of labels to their associated blocks. */
193 : 3032382 : vec_safe_grow_cleared (label_to_block_map_for_fn (fn),
194 : : initial_cfg_capacity, true);
195 : :
196 : 3032382 : SET_BASIC_BLOCK_FOR_FN (fn, ENTRY_BLOCK, ENTRY_BLOCK_PTR_FOR_FN (fn));
197 : 3032382 : SET_BASIC_BLOCK_FOR_FN (fn, EXIT_BLOCK, EXIT_BLOCK_PTR_FOR_FN (fn));
198 : :
199 : 3032382 : ENTRY_BLOCK_PTR_FOR_FN (fn)->next_bb
200 : 3032382 : = EXIT_BLOCK_PTR_FOR_FN (fn);
201 : 3032382 : EXIT_BLOCK_PTR_FOR_FN (fn)->prev_bb
202 : 3032382 : = ENTRY_BLOCK_PTR_FOR_FN (fn);
203 : 3032382 : }
204 : :
205 : : void
206 : 2951163 : init_empty_tree_cfg (void)
207 : : {
208 : 2951163 : init_empty_tree_cfg_for_function (cfun);
209 : 2951163 : }
210 : :
211 : : /*---------------------------------------------------------------------------
212 : : Create basic blocks
213 : : ---------------------------------------------------------------------------*/
214 : :
215 : : /* Entry point to the CFG builder for trees. SEQ is the sequence of
216 : : statements to be added to the flowgraph. */
217 : :
218 : : static void
219 : 2688918 : build_gimple_cfg (gimple_seq seq)
220 : : {
221 : : /* Register specific gimple functions. */
222 : 2688918 : gimple_register_cfg_hooks ();
223 : :
224 : 2688918 : memset ((void *) &cfg_stats, 0, sizeof (cfg_stats));
225 : :
226 : 2688918 : init_empty_tree_cfg ();
227 : :
228 : 2688918 : make_blocks (seq);
229 : :
230 : : /* Make sure there is always at least one block, even if it's empty. */
231 : 2688918 : if (n_basic_blocks_for_fn (cfun) == NUM_FIXED_BLOCKS)
232 : 0 : create_empty_bb (ENTRY_BLOCK_PTR_FOR_FN (cfun));
233 : :
234 : : /* Adjust the size of the array. */
235 : 2688918 : if (basic_block_info_for_fn (cfun)->length ()
236 : 2688918 : < (size_t) n_basic_blocks_for_fn (cfun))
237 : 0 : vec_safe_grow_cleared (basic_block_info_for_fn (cfun),
238 : : n_basic_blocks_for_fn (cfun));
239 : :
240 : : /* To speed up statement iterator walks, we first purge dead labels. */
241 : 2688918 : cleanup_dead_labels ();
242 : :
243 : : /* Group case nodes to reduce the number of edges.
244 : : We do this after cleaning up dead labels because otherwise we miss
245 : : a lot of obvious case merging opportunities. */
246 : 2688918 : group_case_labels ();
247 : :
248 : : /* Create the edges of the flowgraph. */
249 : 2688918 : discriminator_per_locus = new hash_table<locus_discrim_hasher> (13);
250 : 2688918 : make_edges ();
251 : 2688918 : assign_discriminators ();
252 : 2688918 : cleanup_dead_labels ();
253 : 2688918 : delete discriminator_per_locus;
254 : 2688918 : discriminator_per_locus = NULL;
255 : 2688918 : }
256 : :
257 : : /* Look for ANNOTATE calls with loop annotation kind in BB; if found, remove
258 : : them and propagate the information to LOOP. We assume that the annotations
259 : : come immediately before the condition in BB, if any. */
260 : :
261 : : static void
262 : 1443489 : replace_loop_annotate_in_block (basic_block bb, class loop *loop)
263 : : {
264 : 1443489 : gimple_stmt_iterator gsi = gsi_last_bb (bb);
265 : 1443489 : gimple *stmt = gsi_stmt (gsi);
266 : :
267 : 1443489 : if (!(stmt && gimple_code (stmt) == GIMPLE_COND))
268 : 566995 : return;
269 : :
270 : 883152 : for (gsi_prev_nondebug (&gsi); !gsi_end_p (gsi); gsi_prev (&gsi))
271 : : {
272 : 490627 : stmt = gsi_stmt (gsi);
273 : 490627 : if (gimple_code (stmt) != GIMPLE_CALL)
274 : : break;
275 : 58244 : if (!gimple_call_internal_p (stmt)
276 : 58244 : || gimple_call_internal_fn (stmt) != IFN_ANNOTATE)
277 : : break;
278 : :
279 : 3329 : switch ((annot_expr_kind) tree_to_shwi (gimple_call_arg (stmt, 1)))
280 : : {
281 : 257 : case annot_expr_ivdep_kind:
282 : 257 : loop->safelen = INT_MAX;
283 : 257 : break;
284 : 446 : case annot_expr_unroll_kind:
285 : 446 : loop->unroll
286 : 446 : = (unsigned short) tree_to_shwi (gimple_call_arg (stmt, 2));
287 : 446 : cfun->has_unroll = true;
288 : 446 : break;
289 : 2559 : case annot_expr_no_vector_kind:
290 : 2559 : loop->dont_vectorize = true;
291 : 2559 : break;
292 : 3 : case annot_expr_vector_kind:
293 : 3 : loop->force_vectorize = true;
294 : 3 : cfun->has_force_vectorize_loops = true;
295 : 3 : break;
296 : 0 : case annot_expr_parallel_kind:
297 : 0 : loop->can_be_parallel = true;
298 : 0 : loop->safelen = INT_MAX;
299 : 0 : break;
300 : 64 : case annot_expr_maybe_infinite_kind:
301 : 64 : loop->finite_p = false;
302 : 64 : break;
303 : 0 : default:
304 : 0 : gcc_unreachable ();
305 : : }
306 : :
307 : 3329 : stmt = gimple_build_assign (gimple_call_lhs (stmt),
308 : : gimple_call_arg (stmt, 0));
309 : 3329 : gsi_replace (&gsi, stmt, true);
310 : : }
311 : : }
312 : :
313 : : /* Look for ANNOTATE calls with loop annotation kind; if found, remove
314 : : them and propagate the information to the loop. We assume that the
315 : : annotations come immediately before the condition of the loop. */
316 : :
317 : : static void
318 : 2688918 : replace_loop_annotate (void)
319 : : {
320 : 2688918 : basic_block bb;
321 : 2688918 : gimple_stmt_iterator gsi;
322 : 2688918 : gimple *stmt;
323 : :
324 : 8607509 : for (auto loop : loops_list (cfun, 0))
325 : : {
326 : : /* Push the global flag_finite_loops state down to individual loops. */
327 : 540755 : loop->finite_p = flag_finite_loops;
328 : :
329 : : /* Check all exit source blocks for annotations. */
330 : 3057128 : for (auto e : get_loop_exit_edges (loop))
331 : 1984244 : replace_loop_annotate_in_block (e->src, loop);
332 : 2688918 : }
333 : :
334 : : /* Remove IFN_ANNOTATE. Safeguard for the case loop->latch == NULL. */
335 : 19002105 : FOR_EACH_BB_FN (bb, cfun)
336 : : {
337 : 155572852 : for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi_prev (&gsi))
338 : : {
339 : 61473239 : stmt = gsi_stmt (gsi);
340 : 61473239 : if (gimple_code (stmt) != GIMPLE_CALL)
341 : 52110303 : continue;
342 : 9362936 : if (!gimple_call_internal_p (stmt)
343 : 9362936 : || gimple_call_internal_fn (stmt) != IFN_ANNOTATE)
344 : 9362936 : continue;
345 : :
346 : 0 : switch ((annot_expr_kind) tree_to_shwi (gimple_call_arg (stmt, 1)))
347 : : {
348 : 0 : case annot_expr_ivdep_kind:
349 : 0 : case annot_expr_unroll_kind:
350 : 0 : case annot_expr_no_vector_kind:
351 : 0 : case annot_expr_vector_kind:
352 : 0 : case annot_expr_parallel_kind:
353 : 0 : case annot_expr_maybe_infinite_kind:
354 : 0 : break;
355 : 0 : default:
356 : 0 : gcc_unreachable ();
357 : : }
358 : :
359 : 0 : warning_at (gimple_location (stmt), 0, "ignoring loop annotation");
360 : 0 : stmt = gimple_build_assign (gimple_call_lhs (stmt),
361 : : gimple_call_arg (stmt, 0));
362 : 0 : gsi_replace (&gsi, stmt, true);
363 : : }
364 : : }
365 : 2688918 : }
366 : :
367 : : static unsigned int
368 : 2688918 : execute_build_cfg (void)
369 : : {
370 : 2688918 : gimple_seq body = gimple_body (current_function_decl);
371 : :
372 : 2688918 : build_gimple_cfg (body);
373 : 2688918 : gimple_set_body (current_function_decl, NULL);
374 : 2688918 : if (dump_file && (dump_flags & TDF_DETAILS))
375 : : {
376 : 2 : fprintf (dump_file, "Scope blocks:\n");
377 : 2 : dump_scope_blocks (dump_file, dump_flags);
378 : : }
379 : 2688918 : cleanup_tree_cfg ();
380 : :
381 : 2688918 : bb_to_omp_idx.release ();
382 : :
383 : 2688918 : loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
384 : 2688918 : replace_loop_annotate ();
385 : 2688918 : return 0;
386 : : }
387 : :
388 : : namespace {
389 : :
390 : : const pass_data pass_data_build_cfg =
391 : : {
392 : : GIMPLE_PASS, /* type */
393 : : "cfg", /* name */
394 : : OPTGROUP_NONE, /* optinfo_flags */
395 : : TV_TREE_CFG, /* tv_id */
396 : : PROP_gimple_leh, /* properties_required */
397 : : ( PROP_cfg | PROP_loops ), /* properties_provided */
398 : : 0, /* properties_destroyed */
399 : : 0, /* todo_flags_start */
400 : : 0, /* todo_flags_finish */
401 : : };
402 : :
403 : : class pass_build_cfg : public gimple_opt_pass
404 : : {
405 : : public:
406 : 281930 : pass_build_cfg (gcc::context *ctxt)
407 : 563860 : : gimple_opt_pass (pass_data_build_cfg, ctxt)
408 : : {}
409 : :
410 : : /* opt_pass methods: */
411 : 2688918 : unsigned int execute (function *) final override
412 : : {
413 : 2688918 : return execute_build_cfg ();
414 : : }
415 : :
416 : : }; // class pass_build_cfg
417 : :
418 : : } // anon namespace
419 : :
420 : : gimple_opt_pass *
421 : 281930 : make_pass_build_cfg (gcc::context *ctxt)
422 : : {
423 : 281930 : return new pass_build_cfg (ctxt);
424 : : }
425 : :
426 : :
427 : : /* Return true if T is a computed goto. */
428 : :
429 : : bool
430 : 538728806 : computed_goto_p (gimple *t)
431 : : {
432 : 538728806 : return (gimple_code (t) == GIMPLE_GOTO
433 : 538728806 : && TREE_CODE (gimple_goto_dest (t)) != LABEL_DECL);
434 : : }
435 : :
436 : : /* Returns true if the sequence of statements STMTS only contains
437 : : a call to __builtin_unreachable (). */
438 : :
439 : : bool
440 : 3283592 : gimple_seq_unreachable_p (gimple_seq stmts)
441 : : {
442 : 3283592 : if (stmts == NULL
443 : : /* Return false if -fsanitize=unreachable, we don't want to
444 : : optimize away those calls, but rather turn them into
445 : : __ubsan_handle_builtin_unreachable () or __builtin_trap ()
446 : : later. */
447 : 3283592 : || sanitize_flags_p (SANITIZE_UNREACHABLE))
448 : 3219 : return false;
449 : :
450 : 3280373 : gimple_stmt_iterator gsi = gsi_last (stmts);
451 : :
452 : 3280373 : if (!gimple_call_builtin_p (gsi_stmt (gsi), BUILT_IN_UNREACHABLE))
453 : : return false;
454 : :
455 : 409900 : for (gsi_prev (&gsi); !gsi_end_p (gsi); gsi_prev (&gsi))
456 : : {
457 : 11035 : gimple *stmt = gsi_stmt (gsi);
458 : 11035 : if (gimple_code (stmt) != GIMPLE_LABEL
459 : 5504 : && !is_gimple_debug (stmt)
460 : 11997 : && !gimple_clobber_p (stmt))
461 : : return false;
462 : : }
463 : : return true;
464 : : }
465 : :
466 : : /* Returns true for edge E where e->src ends with a GIMPLE_COND and
467 : : the other edge points to a bb with just __builtin_unreachable ().
468 : : I.e. return true for C->M edge in:
469 : : <bb C>:
470 : : ...
471 : : if (something)
472 : : goto <bb N>;
473 : : else
474 : : goto <bb M>;
475 : : <bb N>:
476 : : __builtin_unreachable ();
477 : : <bb M>: */
478 : :
479 : : bool
480 : 10613507 : assert_unreachable_fallthru_edge_p (edge e)
481 : : {
482 : 10613507 : basic_block pred_bb = e->src;
483 : 30350449 : if (safe_is_a <gcond *> (*gsi_last_bb (pred_bb)))
484 : : {
485 : 10613507 : basic_block other_bb = EDGE_SUCC (pred_bb, 0)->dest;
486 : 10613507 : if (other_bb == e->dest)
487 : 5618435 : other_bb = EDGE_SUCC (pred_bb, 1)->dest;
488 : 10613507 : if (EDGE_COUNT (other_bb->succs) == 0)
489 : 2980144 : return gimple_seq_unreachable_p (bb_seq (other_bb));
490 : : }
491 : : return false;
492 : : }
493 : :
494 : :
495 : : /* Initialize GF_CALL_CTRL_ALTERING flag, which indicates the call
496 : : could alter control flow except via eh. We initialize the flag at
497 : : CFG build time and only ever clear it later. */
498 : :
499 : : static void
500 : 9947735 : gimple_call_initialize_ctrl_altering (gimple *stmt)
501 : : {
502 : 9947735 : int flags = gimple_call_flags (stmt);
503 : :
504 : : /* A call alters control flow if it can make an abnormal goto. */
505 : 9947735 : if (call_can_make_abnormal_goto (stmt)
506 : : /* A call also alters control flow if it does not return. */
507 : 9941152 : || flags & ECF_NORETURN
508 : : /* TM ending statements have backedges out of the transaction.
509 : : Return true so we split the basic block containing them.
510 : : Note that the TM_BUILTIN test is merely an optimization. */
511 : 8472200 : || ((flags & ECF_TM_BUILTIN)
512 : 1157 : && is_tm_ending_fndecl (gimple_call_fndecl (stmt)))
513 : : /* BUILT_IN_RETURN call is same as return statement. */
514 : 8471050 : || gimple_call_builtin_p (stmt, BUILT_IN_RETURN)
515 : : /* IFN_UNIQUE should be the last insn, to make checking for it
516 : : as cheap as possible. */
517 : 18418785 : || (gimple_call_internal_p (stmt)
518 : 322110 : && gimple_call_internal_unique_p (stmt)))
519 : 1553883 : gimple_call_set_ctrl_altering (stmt, true);
520 : : else
521 : 8393852 : gimple_call_set_ctrl_altering (stmt, false);
522 : 9947735 : }
523 : :
524 : :
525 : : /* Insert SEQ after BB and build a flowgraph. */
526 : :
527 : : static basic_block
528 : 2740825 : make_blocks_1 (gimple_seq seq, basic_block bb)
529 : : {
530 : 2740825 : gimple_stmt_iterator i = gsi_start (seq);
531 : 2740825 : gimple *stmt = NULL;
532 : 2740825 : gimple *prev_stmt = NULL;
533 : 2740825 : bool start_new_block = true;
534 : 2740825 : bool first_stmt_of_seq = true;
535 : :
536 : 86880808 : while (!gsi_end_p (i))
537 : : {
538 : : /* PREV_STMT should only be set to a debug stmt if the debug
539 : : stmt is before nondebug stmts. Once stmt reaches a nondebug
540 : : nonlabel, prev_stmt will be set to it, so that
541 : : stmt_starts_bb_p will know to start a new block if a label is
542 : : found. However, if stmt was a label after debug stmts only,
543 : : keep the label in prev_stmt even if we find further debug
544 : : stmts, for there may be other labels after them, and they
545 : : should land in the same block. */
546 : 84139983 : if (!prev_stmt || !stmt || !is_gimple_debug (stmt))
547 : : prev_stmt = stmt;
548 : 84139983 : stmt = gsi_stmt (i);
549 : :
550 : 84139983 : if (stmt && is_gimple_call (stmt))
551 : 9947735 : gimple_call_initialize_ctrl_altering (stmt);
552 : :
553 : : /* If the statement starts a new basic block or if we have determined
554 : : in a previous pass that we need to create a new block for STMT, do
555 : : so now. */
556 : 84139983 : if (start_new_block || stmt_starts_bb_p (stmt, prev_stmt))
557 : : {
558 : 19900502 : if (!first_stmt_of_seq)
559 : 17159677 : gsi_split_seq_before (&i, &seq);
560 : 19900502 : bb = create_basic_block (seq, bb);
561 : 19900502 : start_new_block = false;
562 : 19900502 : prev_stmt = NULL;
563 : : }
564 : :
565 : : /* Now add STMT to BB and create the subgraphs for special statement
566 : : codes. */
567 : 84139983 : gimple_set_bb (stmt, bb);
568 : :
569 : : /* If STMT is a basic block terminator, set START_NEW_BLOCK for the
570 : : next iteration. */
571 : 84139983 : if (stmt_ends_bb_p (stmt))
572 : : {
573 : : /* If the stmt can make abnormal goto use a new temporary
574 : : for the assignment to the LHS. This makes sure the old value
575 : : of the LHS is available on the abnormal edge. Otherwise
576 : : we will end up with overlapping life-ranges for abnormal
577 : : SSA names. */
578 : 18106328 : if (gimple_has_lhs (stmt)
579 : 1532540 : && stmt_can_make_abnormal_goto (stmt)
580 : 3152781 : && is_gimple_reg_type (TREE_TYPE (gimple_get_lhs (stmt))))
581 : : {
582 : 2310 : tree lhs = gimple_get_lhs (stmt);
583 : 2310 : tree tmp = create_tmp_var (TREE_TYPE (lhs));
584 : 2310 : gimple *s = gimple_build_assign (lhs, tmp);
585 : 2310 : gimple_set_location (s, gimple_location (stmt));
586 : 2310 : gimple_set_block (s, gimple_block (stmt));
587 : 2310 : gimple_set_lhs (stmt, tmp);
588 : 2310 : gsi_insert_after (&i, s, GSI_SAME_STMT);
589 : : }
590 : : start_new_block = true;
591 : : }
592 : :
593 : 84139983 : gsi_next (&i);
594 : 84139983 : first_stmt_of_seq = false;
595 : : }
596 : 2740825 : return bb;
597 : : }
598 : :
599 : : /* Build a flowgraph for the sequence of stmts SEQ. */
600 : :
601 : : static void
602 : 2688918 : make_blocks (gimple_seq seq)
603 : : {
604 : : /* Look for debug markers right before labels, and move the debug
605 : : stmts after the labels. Accepting labels among debug markers
606 : : adds no value, just complexity; if we wanted to annotate labels
607 : : with view numbers (so sequencing among markers would matter) or
608 : : somesuch, we're probably better off still moving the labels, but
609 : : adding other debug annotations in their original positions or
610 : : emitting nonbind or bind markers associated with the labels in
611 : : the original position of the labels.
612 : :
613 : : Moving labels would probably be simpler, but we can't do that:
614 : : moving labels assigns label ids to them, and doing so because of
615 : : debug markers makes for -fcompare-debug and possibly even codegen
616 : : differences. So, we have to move the debug stmts instead. To
617 : : that end, we scan SEQ backwards, marking the position of the
618 : : latest (earliest we find) label, and moving debug stmts that are
619 : : not separated from it by nondebug nonlabel stmts after the
620 : : label. */
621 : 2688918 : if (MAY_HAVE_DEBUG_MARKER_STMTS)
622 : : {
623 : 1622059 : gimple_stmt_iterator label = gsi_none ();
624 : :
625 : 93358052 : for (gimple_stmt_iterator i = gsi_last (seq); !gsi_end_p (i); gsi_prev (&i))
626 : : {
627 : 45056967 : gimple *stmt = gsi_stmt (i);
628 : :
629 : : /* If this is the first label we encounter (latest in SEQ)
630 : : before nondebug stmts, record its position. */
631 : 45056967 : if (is_a <glabel *> (stmt))
632 : : {
633 : 8265355 : if (gsi_end_p (label))
634 : 7690074 : label = i;
635 : 8265355 : continue;
636 : : }
637 : :
638 : : /* Without a recorded label position to move debug stmts to,
639 : : there's nothing to do. */
640 : 36791612 : if (gsi_end_p (label))
641 : 29083346 : continue;
642 : :
643 : : /* Move the debug stmt at I after LABEL. */
644 : 7708266 : if (is_gimple_debug (stmt))
645 : : {
646 : 22244 : gcc_assert (gimple_debug_nonbind_marker_p (stmt));
647 : : /* As STMT is removed, I advances to the stmt after
648 : : STMT, so the gsi_prev in the for "increment"
649 : : expression gets us to the stmt we're to visit after
650 : : STMT. LABEL, however, would advance to the moved
651 : : stmt if we passed it to gsi_move_after, so pass it a
652 : : copy instead, so as to keep LABEL pointing to the
653 : : LABEL. */
654 : 22244 : gimple_stmt_iterator copy = label;
655 : 22244 : gsi_move_after (&i, ©);
656 : 22244 : continue;
657 : 22244 : }
658 : :
659 : : /* There aren't any (more?) debug stmts before label, so
660 : : there isn't anything else to move after it. */
661 : : label = gsi_none ();
662 : : }
663 : : }
664 : :
665 : 2688918 : make_blocks_1 (seq, ENTRY_BLOCK_PTR_FOR_FN (cfun));
666 : 2688918 : }
667 : :
668 : : /* Create and return a new empty basic block after bb AFTER. */
669 : :
670 : : static basic_block
671 : 61150226 : create_bb (void *h, void *e, basic_block after)
672 : : {
673 : 61150226 : basic_block bb;
674 : :
675 : 61150226 : gcc_assert (!e);
676 : :
677 : : /* Create and initialize a new basic block. Since alloc_block uses
678 : : GC allocation that clears memory to allocate a basic block, we do
679 : : not have to clear the newly allocated basic block here. */
680 : 61150226 : bb = alloc_block ();
681 : :
682 : 61150226 : bb->index = last_basic_block_for_fn (cfun);
683 : 61150226 : bb->flags = BB_NEW;
684 : 61150226 : set_bb_seq (bb, h ? (gimple_seq) h : NULL);
685 : :
686 : : /* Add the new block to the linked list of blocks. */
687 : 61150226 : link_block (bb, after);
688 : :
689 : : /* Grow the basic block array if needed. */
690 : 61150226 : if ((size_t) last_basic_block_for_fn (cfun)
691 : 61150226 : == basic_block_info_for_fn (cfun)->length ())
692 : 17752711 : vec_safe_grow_cleared (basic_block_info_for_fn (cfun),
693 : 17752711 : last_basic_block_for_fn (cfun) + 1);
694 : :
695 : : /* Add the newly created block to the array. */
696 : 61150226 : SET_BASIC_BLOCK_FOR_FN (cfun, last_basic_block_for_fn (cfun), bb);
697 : :
698 : 61150226 : n_basic_blocks_for_fn (cfun)++;
699 : 61150226 : last_basic_block_for_fn (cfun)++;
700 : :
701 : 61150226 : return bb;
702 : : }
703 : :
704 : :
705 : : /*---------------------------------------------------------------------------
706 : : Edge creation
707 : : ---------------------------------------------------------------------------*/
708 : :
709 : : /* If basic block BB has an abnormal edge to a basic block
710 : : containing IFN_ABNORMAL_DISPATCHER internal call, return
711 : : that the dispatcher's basic block, otherwise return NULL. */
712 : :
713 : : basic_block
714 : 411 : get_abnormal_succ_dispatcher (basic_block bb)
715 : : {
716 : 411 : edge e;
717 : 411 : edge_iterator ei;
718 : :
719 : 788 : FOR_EACH_EDGE (e, ei, bb->succs)
720 : 581 : if ((e->flags & (EDGE_ABNORMAL | EDGE_EH)) == EDGE_ABNORMAL)
721 : : {
722 : 204 : gimple_stmt_iterator gsi
723 : 204 : = gsi_start_nondebug_after_labels_bb (e->dest);
724 : 204 : gimple *g = gsi_stmt (gsi);
725 : 204 : if (g && gimple_call_internal_p (g, IFN_ABNORMAL_DISPATCHER))
726 : 204 : return e->dest;
727 : : }
728 : : return NULL;
729 : : }
730 : :
731 : : /* Helper function for make_edges. Create a basic block with
732 : : with ABNORMAL_DISPATCHER internal call in it if needed, and
733 : : create abnormal edges from BBS to it and from it to FOR_BB
734 : : if COMPUTED_GOTO is false, otherwise factor the computed gotos. */
735 : :
736 : : static void
737 : 5005 : handle_abnormal_edges (basic_block *dispatcher_bbs, basic_block for_bb,
738 : : auto_vec<basic_block> *bbs, bool computed_goto)
739 : : {
740 : 5005 : basic_block *dispatcher = dispatcher_bbs + (computed_goto ? 1 : 0);
741 : 5005 : unsigned int idx = 0;
742 : 5005 : basic_block bb;
743 : 5005 : bool inner = false;
744 : :
745 : 5005 : if (!bb_to_omp_idx.is_empty ())
746 : : {
747 : 13 : dispatcher = dispatcher_bbs + 2 * bb_to_omp_idx[for_bb->index];
748 : 13 : if (bb_to_omp_idx[for_bb->index] != 0)
749 : 7 : inner = true;
750 : : }
751 : :
752 : : /* If the dispatcher has been created already, then there are basic
753 : : blocks with abnormal edges to it, so just make a new edge to
754 : : for_bb. */
755 : 5005 : if (*dispatcher == NULL)
756 : : {
757 : : /* Check if there are any basic blocks that need to have
758 : : abnormal edges to this dispatcher. If there are none, return
759 : : early. */
760 : 3256 : if (bb_to_omp_idx.is_empty ())
761 : : {
762 : 3243 : if (bbs->is_empty ())
763 : 5005 : return;
764 : : }
765 : : else
766 : : {
767 : 21 : FOR_EACH_VEC_ELT (*bbs, idx, bb)
768 : 21 : if (bb_to_omp_idx[bb->index] == bb_to_omp_idx[for_bb->index])
769 : : break;
770 : 13 : if (bb == NULL)
771 : : return;
772 : : }
773 : :
774 : : /* Create the dispatcher bb. */
775 : 2450 : *dispatcher = create_basic_block (NULL, for_bb);
776 : 2450 : if (computed_goto)
777 : : {
778 : : /* Factor computed gotos into a common computed goto site. Also
779 : : record the location of that site so that we can un-factor the
780 : : gotos after we have converted back to normal form. */
781 : 551 : gimple_stmt_iterator gsi = gsi_start_bb (*dispatcher);
782 : :
783 : : /* Create the destination of the factored goto. Each original
784 : : computed goto will put its desired destination into this
785 : : variable and jump to the label we create immediately below. */
786 : 551 : tree var = create_tmp_var (ptr_type_node, "gotovar");
787 : :
788 : : /* Build a label for the new block which will contain the
789 : : factored computed goto. */
790 : 551 : tree factored_label_decl
791 : 551 : = create_artificial_label (UNKNOWN_LOCATION);
792 : 551 : gimple *factored_computed_goto_label
793 : 551 : = gimple_build_label (factored_label_decl);
794 : 551 : gsi_insert_after (&gsi, factored_computed_goto_label, GSI_NEW_STMT);
795 : :
796 : : /* Build our new computed goto. */
797 : 551 : gimple *factored_computed_goto = gimple_build_goto (var);
798 : 551 : gsi_insert_after (&gsi, factored_computed_goto, GSI_NEW_STMT);
799 : :
800 : 2127 : FOR_EACH_VEC_ELT (*bbs, idx, bb)
801 : : {
802 : 1025 : if (!bb_to_omp_idx.is_empty ()
803 : 0 : && bb_to_omp_idx[bb->index] != bb_to_omp_idx[for_bb->index])
804 : 0 : continue;
805 : :
806 : 1025 : gsi = gsi_last_bb (bb);
807 : 1025 : gimple *last = gsi_stmt (gsi);
808 : :
809 : 1025 : gcc_assert (computed_goto_p (last));
810 : :
811 : : /* Copy the original computed goto's destination into VAR. */
812 : 1025 : gimple *assignment
813 : 1025 : = gimple_build_assign (var, gimple_goto_dest (last));
814 : 1025 : gsi_insert_before (&gsi, assignment, GSI_SAME_STMT);
815 : :
816 : 1025 : edge e = make_edge (bb, *dispatcher, EDGE_FALLTHRU);
817 : 1025 : e->goto_locus = gimple_location (last);
818 : 1025 : gsi_remove (&gsi, true);
819 : : }
820 : : }
821 : : else
822 : : {
823 : 1899 : tree arg = inner ? boolean_true_node : boolean_false_node;
824 : 1899 : gcall *g = gimple_build_call_internal (IFN_ABNORMAL_DISPATCHER,
825 : : 1, arg);
826 : 1899 : gimple_call_set_ctrl_altering (g, true);
827 : 1899 : gimple_stmt_iterator gsi = gsi_after_labels (*dispatcher);
828 : 1899 : gsi_insert_after (&gsi, g, GSI_NEW_STMT);
829 : :
830 : : /* Create predecessor edges of the dispatcher. */
831 : 12288 : FOR_EACH_VEC_ELT (*bbs, idx, bb)
832 : : {
833 : 6591 : if (!bb_to_omp_idx.is_empty ()
834 : 52 : && bb_to_omp_idx[bb->index] != bb_to_omp_idx[for_bb->index])
835 : 23 : continue;
836 : 6568 : make_edge (bb, *dispatcher, EDGE_ABNORMAL);
837 : : }
838 : : }
839 : : }
840 : :
841 : 4199 : make_edge (*dispatcher, for_bb, EDGE_ABNORMAL);
842 : : }
843 : :
844 : : /* Creates outgoing edges for BB. Returns 1 when it ends with an
845 : : computed goto, returns 2 when it ends with a statement that
846 : : might return to this function via an nonlocal goto, otherwise
847 : : return 0. Updates *PCUR_REGION with the OMP region this BB is in. */
848 : :
849 : : static int
850 : 19900502 : make_edges_bb (basic_block bb, struct omp_region **pcur_region, int *pomp_index)
851 : : {
852 : 19900502 : gimple *last = *gsi_last_bb (bb);
853 : 19900502 : bool fallthru = false;
854 : 19900502 : int ret = 0;
855 : :
856 : 19900502 : if (!last)
857 : : return ret;
858 : :
859 : 19900502 : switch (gimple_code (last))
860 : : {
861 : 5521130 : case GIMPLE_GOTO:
862 : 5521130 : if (make_goto_expr_edges (bb))
863 : 19900502 : ret = 1;
864 : : fallthru = false;
865 : : break;
866 : 2677838 : case GIMPLE_RETURN:
867 : 2677838 : {
868 : 2677838 : edge e = make_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun), 0);
869 : 2677838 : e->goto_locus = gimple_location (last);
870 : 2677838 : fallthru = false;
871 : : }
872 : 2677838 : break;
873 : 5006462 : case GIMPLE_COND:
874 : 5006462 : make_cond_expr_edges (bb);
875 : 5006462 : fallthru = false;
876 : 5006462 : break;
877 : 51749 : case GIMPLE_SWITCH:
878 : 51749 : make_gimple_switch_edges (as_a <gswitch *> (last), bb);
879 : 51749 : fallthru = false;
880 : 51749 : break;
881 : 747666 : case GIMPLE_RESX:
882 : 747666 : make_eh_edge (last);
883 : 747666 : fallthru = false;
884 : 747666 : break;
885 : 42673 : case GIMPLE_EH_DISPATCH:
886 : 42673 : fallthru = make_eh_dispatch_edges (as_a <geh_dispatch *> (last));
887 : 42673 : break;
888 : :
889 : 3476440 : case GIMPLE_CALL:
890 : : /* If this function receives a nonlocal goto, then we need to
891 : : make edges from this call site to all the nonlocal goto
892 : : handlers. */
893 : 3476440 : if (stmt_can_make_abnormal_goto (last))
894 : 6583 : ret = 2;
895 : :
896 : : /* If this statement has reachable exception handlers, then
897 : : create abnormal edges to them. */
898 : 3476440 : make_eh_edge (last);
899 : :
900 : : /* BUILTIN_RETURN is really a return statement. */
901 : 3476440 : if (gimple_call_builtin_p (last, BUILT_IN_RETURN))
902 : : {
903 : 367 : make_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun), 0);
904 : 367 : fallthru = false;
905 : : }
906 : : /* Some calls are known not to return. */
907 : : else
908 : 3476073 : fallthru = !gimple_call_noreturn_p (last);
909 : : break;
910 : :
911 : 2069959 : case GIMPLE_ASSIGN:
912 : : /* A GIMPLE_ASSIGN may throw internally and thus be considered
913 : : control-altering. */
914 : 2069959 : if (is_ctrl_altering_stmt (last))
915 : 618472 : make_eh_edge (last);
916 : : fallthru = true;
917 : : break;
918 : :
919 : 2227 : case GIMPLE_ASM:
920 : 2227 : make_gimple_asm_edges (bb);
921 : 2227 : fallthru = true;
922 : 2227 : break;
923 : :
924 : 288984 : CASE_GIMPLE_OMP:
925 : 288984 : fallthru = omp_make_gimple_edges (bb, pcur_region, pomp_index);
926 : 288984 : break;
927 : :
928 : 469 : case GIMPLE_TRANSACTION:
929 : 469 : {
930 : 469 : gtransaction *txn = as_a <gtransaction *> (last);
931 : 469 : tree label1 = gimple_transaction_label_norm (txn);
932 : 469 : tree label2 = gimple_transaction_label_uninst (txn);
933 : :
934 : 469 : if (label1)
935 : 459 : make_edge (bb, label_to_block (cfun, label1), EDGE_FALLTHRU);
936 : 469 : if (label2)
937 : 454 : make_edge (bb, label_to_block (cfun, label2),
938 : 454 : EDGE_TM_UNINSTRUMENTED | (label1 ? 0 : EDGE_FALLTHRU));
939 : :
940 : 469 : tree label3 = gimple_transaction_label_over (txn);
941 : 469 : if (gimple_transaction_subcode (txn)
942 : : & (GTMA_HAVE_ABORT | GTMA_IS_OUTER))
943 : 72 : make_edge (bb, label_to_block (cfun, label3), EDGE_TM_ABORT);
944 : :
945 : : fallthru = false;
946 : : }
947 : : break;
948 : :
949 : 14905 : default:
950 : 14905 : gcc_assert (!stmt_ends_bb_p (last));
951 : : fallthru = true;
952 : : break;
953 : : }
954 : :
955 : 12294039 : if (fallthru)
956 : 4337671 : make_edge (bb, bb->next_bb, EDGE_FALLTHRU);
957 : :
958 : : return ret;
959 : : }
960 : :
961 : : /* Join all the blocks in the flowgraph. */
962 : :
963 : : static void
964 : 2688918 : make_edges (void)
965 : : {
966 : 2688918 : basic_block bb;
967 : 2688918 : struct omp_region *cur_region = NULL;
968 : 2688918 : auto_vec<basic_block> ab_edge_goto;
969 : 2688918 : auto_vec<basic_block> ab_edge_call;
970 : 2688918 : int cur_omp_region_idx = 0;
971 : :
972 : : /* Create an edge from entry to the first block with executable
973 : : statements in it. */
974 : 2688918 : make_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun),
975 : 2688918 : BASIC_BLOCK_FOR_FN (cfun, NUM_FIXED_BLOCKS),
976 : : EDGE_FALLTHRU);
977 : :
978 : : /* Traverse the basic block array placing edges. */
979 : 22451634 : FOR_EACH_BB_FN (bb, cfun)
980 : : {
981 : 19762716 : int mer;
982 : :
983 : 19762716 : if (!bb_to_omp_idx.is_empty ())
984 : 691216 : bb_to_omp_idx[bb->index] = cur_omp_region_idx;
985 : :
986 : 19762716 : mer = make_edges_bb (bb, &cur_region, &cur_omp_region_idx);
987 : 19762716 : if (mer == 1)
988 : 1099 : ab_edge_goto.safe_push (bb);
989 : 19761617 : else if (mer == 2)
990 : 6583 : ab_edge_call.safe_push (bb);
991 : :
992 : 20276856 : if (cur_region && bb_to_omp_idx.is_empty ())
993 : 21173 : bb_to_omp_idx.safe_grow_cleared (n_basic_blocks_for_fn (cfun), true);
994 : : }
995 : :
996 : : /* Computed gotos are hell to deal with, especially if there are
997 : : lots of them with a large number of destinations. So we factor
998 : : them to a common computed goto location before we build the
999 : : edge list. After we convert back to normal form, we will un-factor
1000 : : the computed gotos since factoring introduces an unwanted jump.
1001 : : For non-local gotos and abnormal edges from calls to calls that return
1002 : : twice or forced labels, factor the abnormal edges too, by having all
1003 : : abnormal edges from the calls go to a common artificial basic block
1004 : : with ABNORMAL_DISPATCHER internal call and abnormal edges from that
1005 : : basic block to all forced labels and calls returning twice.
1006 : : We do this per-OpenMP structured block, because those regions
1007 : : are guaranteed to be single entry single exit by the standard,
1008 : : so it is not allowed to enter or exit such regions abnormally this way,
1009 : : thus all computed gotos, non-local gotos and setjmp/longjmp calls
1010 : : must not transfer control across SESE region boundaries. */
1011 : 2688918 : if (!ab_edge_goto.is_empty () || !ab_edge_call.is_empty ())
1012 : : {
1013 : 2483 : gimple_stmt_iterator gsi;
1014 : 2483 : basic_block dispatcher_bb_array[2] = { NULL, NULL };
1015 : 2483 : basic_block *dispatcher_bbs = dispatcher_bb_array;
1016 : 2483 : int count = n_basic_blocks_for_fn (cfun);
1017 : :
1018 : 2483 : if (!bb_to_omp_idx.is_empty ())
1019 : 11 : dispatcher_bbs = XCNEWVEC (basic_block, 2 * count);
1020 : :
1021 : 28490 : FOR_EACH_BB_FN (bb, cfun)
1022 : : {
1023 : 65982 : for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1024 : : {
1025 : 38523 : glabel *label_stmt = dyn_cast <glabel *> (gsi_stmt (gsi));
1026 : 14444 : tree target;
1027 : :
1028 : 14444 : if (!label_stmt)
1029 : : break;
1030 : :
1031 : 14444 : target = gimple_label_label (label_stmt);
1032 : :
1033 : : /* Make an edge to every label block that has been marked as a
1034 : : potential target for a computed goto or a non-local goto. */
1035 : 14444 : if (FORCED_LABEL (target))
1036 : 2388 : handle_abnormal_edges (dispatcher_bbs, bb, &ab_edge_goto,
1037 : : true);
1038 : 14444 : if (DECL_NONLOCAL (target))
1039 : : {
1040 : 476 : handle_abnormal_edges (dispatcher_bbs, bb, &ab_edge_call,
1041 : : false);
1042 : 476 : break;
1043 : : }
1044 : : }
1045 : :
1046 : 26007 : if (!gsi_end_p (gsi) && is_gimple_debug (gsi_stmt (gsi)))
1047 : 1994 : gsi_next_nondebug (&gsi);
1048 : 26007 : if (!gsi_end_p (gsi))
1049 : : {
1050 : : /* Make an edge to every setjmp-like call. */
1051 : 24452 : gimple *call_stmt = gsi_stmt (gsi);
1052 : 24452 : if (is_gimple_call (call_stmt)
1053 : 24452 : && ((gimple_call_flags (call_stmt) & ECF_RETURNS_TWICE)
1054 : 7760 : || gimple_call_builtin_p (call_stmt,
1055 : : BUILT_IN_SETJMP_RECEIVER)))
1056 : 2141 : handle_abnormal_edges (dispatcher_bbs, bb, &ab_edge_call,
1057 : : false);
1058 : : }
1059 : : }
1060 : :
1061 : 2494 : if (!bb_to_omp_idx.is_empty ())
1062 : 11 : XDELETE (dispatcher_bbs);
1063 : : }
1064 : :
1065 : 2688918 : omp_free_regions ();
1066 : 2688918 : }
1067 : :
1068 : : /* Add SEQ after GSI. Start new bb after GSI, and created further bbs as
1069 : : needed. Returns true if new bbs were created.
1070 : : Note: This is transitional code, and should not be used for new code. We
1071 : : should be able to get rid of this by rewriting all target va-arg
1072 : : gimplification hooks to use an interface gimple_build_cond_value as described
1073 : : in https://gcc.gnu.org/ml/gcc-patches/2015-02/msg01194.html. */
1074 : :
1075 : : bool
1076 : 51907 : gimple_find_sub_bbs (gimple_seq seq, gimple_stmt_iterator *gsi)
1077 : : {
1078 : 51907 : gimple *stmt = gsi_stmt (*gsi);
1079 : 51907 : basic_block bb = gimple_bb (stmt);
1080 : 51907 : basic_block lastbb, afterbb;
1081 : 51907 : int old_num_bbs = n_basic_blocks_for_fn (cfun);
1082 : 51907 : edge e;
1083 : 51907 : lastbb = make_blocks_1 (seq, bb);
1084 : 51907 : if (old_num_bbs == n_basic_blocks_for_fn (cfun))
1085 : : return false;
1086 : 51907 : e = split_block (bb, stmt);
1087 : : /* Move e->dest to come after the new basic blocks. */
1088 : 51907 : afterbb = e->dest;
1089 : 51907 : unlink_block (afterbb);
1090 : 51907 : link_block (afterbb, lastbb);
1091 : 51907 : redirect_edge_succ (e, bb->next_bb);
1092 : 51907 : bb = bb->next_bb;
1093 : 189693 : while (bb != afterbb)
1094 : : {
1095 : 137786 : struct omp_region *cur_region = NULL;
1096 : 137786 : profile_count cnt = profile_count::zero ();
1097 : 137786 : bool all = true;
1098 : :
1099 : 137786 : int cur_omp_region_idx = 0;
1100 : 137786 : int mer = make_edges_bb (bb, &cur_region, &cur_omp_region_idx);
1101 : 137786 : gcc_assert (!mer && !cur_region);
1102 : 137786 : add_bb_to_loop (bb, afterbb->loop_father);
1103 : :
1104 : 137786 : edge e;
1105 : 137786 : edge_iterator ei;
1106 : 304447 : FOR_EACH_EDGE (e, ei, bb->preds)
1107 : : {
1108 : 166661 : if (e->count ().initialized_p ())
1109 : 21235 : cnt += e->count ();
1110 : : else
1111 : : all = false;
1112 : : }
1113 : 137786 : tree_guess_outgoing_edge_probabilities (bb);
1114 : 137786 : if (all || profile_status_for_fn (cfun) == PROFILE_READ)
1115 : 17058 : bb->count = cnt;
1116 : :
1117 : 137786 : bb = bb->next_bb;
1118 : : }
1119 : : return true;
1120 : : }
1121 : :
1122 : : /* Find the next available discriminator value for LOCUS. The
1123 : : discriminator distinguishes among several basic blocks that
1124 : : share a common locus, allowing for more accurate sample-based
1125 : : profiling. */
1126 : :
1127 : : static int
1128 : 22159258 : next_discriminator_for_locus (int line)
1129 : : {
1130 : 22159258 : struct locus_discrim_map item;
1131 : 22159258 : struct locus_discrim_map **slot;
1132 : :
1133 : 22159258 : item.location_line = line;
1134 : 22159258 : item.discriminator = 0;
1135 : 22159258 : slot = discriminator_per_locus->find_slot_with_hash (&item, line, INSERT);
1136 : 22159258 : gcc_assert (slot);
1137 : 22159258 : if (*slot == HTAB_EMPTY_ENTRY)
1138 : : {
1139 : 11447233 : *slot = XNEW (struct locus_discrim_map);
1140 : 11447233 : gcc_assert (*slot);
1141 : 11447233 : (*slot)->location_line = line;
1142 : 11447233 : (*slot)->discriminator = 0;
1143 : : }
1144 : 22159258 : (*slot)->discriminator++;
1145 : 22159258 : return (*slot)->discriminator;
1146 : : }
1147 : :
1148 : : /* Return TRUE if LOCUS1 and LOCUS2 refer to the same source line. */
1149 : :
1150 : : static bool
1151 : 129835720 : same_line_p (location_t locus1, expanded_location *from, location_t locus2)
1152 : : {
1153 : 129835720 : expanded_location to;
1154 : :
1155 : 129835720 : if (locus1 == locus2)
1156 : : return true;
1157 : :
1158 : 104790935 : to = expand_location (locus2);
1159 : :
1160 : 104790935 : if (from->line != to.line)
1161 : : return false;
1162 : 54211885 : if (from->file == to.file)
1163 : : return true;
1164 : 747426 : return (from->file != NULL
1165 : 509957 : && to.file != NULL
1166 : 749771 : && filename_cmp (from->file, to.file) == 0);
1167 : : }
1168 : :
1169 : : /* Assign a unique discriminator value to all statements in block bb that
1170 : : have the same line number as locus. */
1171 : :
1172 : : static void
1173 : 12209733 : assign_discriminator (location_t locus, basic_block bb)
1174 : : {
1175 : 12209733 : gimple_stmt_iterator gsi;
1176 : 12209733 : int discriminator;
1177 : :
1178 : 12209733 : if (locus == UNKNOWN_LOCATION)
1179 : 0 : return;
1180 : :
1181 : 12209733 : expanded_location locus_e = expand_location (locus);
1182 : :
1183 : 12209733 : discriminator = next_discriminator_for_locus (locus_e.line);
1184 : :
1185 : 69981430 : for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1186 : : {
1187 : 45561964 : gimple *stmt = gsi_stmt (gsi);
1188 : 45561964 : location_t stmt_locus = gimple_location (stmt);
1189 : 45561964 : if (same_line_p (locus, &locus_e, stmt_locus))
1190 : 61394136 : gimple_set_location (stmt,
1191 : : location_with_discriminator (stmt_locus, discriminator));
1192 : : }
1193 : : }
1194 : :
1195 : : /* Assign discriminators to statement locations. */
1196 : :
1197 : : static void
1198 : 2688918 : assign_discriminators (void)
1199 : : {
1200 : 2688918 : basic_block bb;
1201 : :
1202 : 22454084 : FOR_EACH_BB_FN (bb, cfun)
1203 : : {
1204 : 19765166 : edge e;
1205 : 19765166 : edge_iterator ei;
1206 : 19765166 : gimple_stmt_iterator gsi;
1207 : 19765166 : location_t curr_locus = UNKNOWN_LOCATION;
1208 : 19765166 : expanded_location curr_locus_e = {};
1209 : 19765166 : int curr_discr = 0;
1210 : :
1211 : : /* Traverse the basic block, if two function calls within a basic block
1212 : : are mapped to the same line, assign a new discriminator because a call
1213 : : stmt could be a split point of a basic block. */
1214 : 115437017 : for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1215 : : {
1216 : 75906685 : gimple *stmt = gsi_stmt (gsi);
1217 : :
1218 : : /* Don't allow debug stmts to affect discriminators, but
1219 : : allow them to take discriminators when they're on the
1220 : : same line as the preceding nondebug stmt. */
1221 : 75906685 : if (is_gimple_debug (stmt))
1222 : : {
1223 : 2544733 : if (curr_locus != UNKNOWN_LOCATION
1224 : 2544733 : && same_line_p (curr_locus, &curr_locus_e,
1225 : : gimple_location (stmt)))
1226 : : {
1227 : 286426 : location_t loc = gimple_location (stmt);
1228 : 286426 : location_t dloc = location_with_discriminator (loc,
1229 : : curr_discr);
1230 : 572852 : gimple_set_location (stmt, dloc);
1231 : : }
1232 : 2544733 : continue;
1233 : 2544733 : }
1234 : 73361952 : if (curr_locus == UNKNOWN_LOCATION)
1235 : : {
1236 : 22533688 : curr_locus = gimple_location (stmt);
1237 : 22533688 : curr_locus_e = expand_location (curr_locus);
1238 : : }
1239 : 50828264 : else if (!same_line_p (curr_locus, &curr_locus_e, gimple_location (stmt)))
1240 : : {
1241 : 15602847 : curr_locus = gimple_location (stmt);
1242 : 15602847 : curr_locus_e = expand_location (curr_locus);
1243 : 15602847 : curr_discr = 0;
1244 : : }
1245 : 35225417 : else if (curr_discr != 0)
1246 : : {
1247 : 7374569 : location_t loc = gimple_location (stmt);
1248 : 7374569 : location_t dloc = location_with_discriminator (loc, curr_discr);
1249 : 14748110 : gimple_set_location (stmt, dloc);
1250 : : }
1251 : : /* Allocate a new discriminator for CALL stmt. */
1252 : 73361952 : if (gimple_code (stmt) == GIMPLE_CALL)
1253 : 9949525 : curr_discr = next_discriminator_for_locus (curr_locus);
1254 : : }
1255 : :
1256 : 19765166 : gimple *last = last_nondebug_stmt (bb);
1257 : 19765166 : location_t locus = last ? gimple_location (last) : UNKNOWN_LOCATION;
1258 : 19560098 : if (locus == UNKNOWN_LOCATION)
1259 : 1415341 : continue;
1260 : :
1261 : 18349825 : expanded_location locus_e = expand_location (locus);
1262 : :
1263 : 42961439 : FOR_EACH_EDGE (e, ei, bb->succs)
1264 : : {
1265 : 24611614 : gimple *first = first_non_label_stmt (e->dest);
1266 : 24611614 : gimple *last = last_nondebug_stmt (e->dest);
1267 : :
1268 : 24611614 : gimple *stmt_on_same_line = NULL;
1269 : 24611614 : if (first && same_line_p (locus, &locus_e,
1270 : : gimple_location (first)))
1271 : : stmt_on_same_line = first;
1272 : 12636225 : else if (last && same_line_p (locus, &locus_e,
1273 : : gimple_location (last)))
1274 : : stmt_on_same_line = last;
1275 : :
1276 : 12209733 : if (stmt_on_same_line)
1277 : : {
1278 : 12209733 : if (has_discriminator (gimple_location (stmt_on_same_line))
1279 : 12209733 : && !has_discriminator (locus))
1280 : 265302 : assign_discriminator (locus, bb);
1281 : : else
1282 : 11944431 : assign_discriminator (locus, e->dest);
1283 : : }
1284 : : }
1285 : : }
1286 : 2688918 : }
1287 : :
1288 : : /* Create the edges for a GIMPLE_COND starting at block BB. */
1289 : :
1290 : : static void
1291 : 5006462 : make_cond_expr_edges (basic_block bb)
1292 : : {
1293 : 10012924 : gcond *entry = as_a <gcond *> (*gsi_last_bb (bb));
1294 : 5006462 : gimple *then_stmt, *else_stmt;
1295 : 5006462 : basic_block then_bb, else_bb;
1296 : 5006462 : tree then_label, else_label;
1297 : 5006462 : edge e;
1298 : :
1299 : 5006462 : gcc_assert (entry);
1300 : :
1301 : : /* Entry basic blocks for each component. */
1302 : 5006462 : then_label = gimple_cond_true_label (entry);
1303 : 5006462 : else_label = gimple_cond_false_label (entry);
1304 : 5006462 : then_bb = label_to_block (cfun, then_label);
1305 : 5006462 : else_bb = label_to_block (cfun, else_label);
1306 : 5006462 : then_stmt = first_stmt (then_bb);
1307 : 5006462 : else_stmt = first_stmt (else_bb);
1308 : :
1309 : 5006462 : e = make_edge (bb, then_bb, EDGE_TRUE_VALUE);
1310 : 5006462 : e->goto_locus = gimple_location (then_stmt);
1311 : 5006462 : e = make_edge (bb, else_bb, EDGE_FALSE_VALUE);
1312 : 5006462 : if (e)
1313 : 5002138 : e->goto_locus = gimple_location (else_stmt);
1314 : :
1315 : : /* We do not need the labels anymore. */
1316 : 5006462 : gimple_cond_set_true_label (entry, NULL_TREE);
1317 : 5006462 : gimple_cond_set_false_label (entry, NULL_TREE);
1318 : 5006462 : }
1319 : :
1320 : :
1321 : : /* Called for each element in the hash table (P) as we delete the
1322 : : edge to cases hash table.
1323 : :
1324 : : Clear all the CASE_CHAINs to prevent problems with copying of
1325 : : SWITCH_EXPRs and structure sharing rules, then free the hash table
1326 : : element. */
1327 : :
1328 : : bool
1329 : 1001717 : edge_to_cases_cleanup (edge const &, tree const &value, void *)
1330 : : {
1331 : 1001717 : tree t, next;
1332 : :
1333 : 2158617 : for (t = value; t; t = next)
1334 : : {
1335 : 1156900 : next = CASE_CHAIN (t);
1336 : 1156900 : CASE_CHAIN (t) = NULL;
1337 : : }
1338 : :
1339 : 1001717 : return true;
1340 : : }
1341 : :
1342 : : /* Start recording information mapping edges to case labels. */
1343 : :
1344 : : void
1345 : 30632180 : start_recording_case_labels (void)
1346 : : {
1347 : 30632180 : gcc_assert (edge_to_cases == NULL);
1348 : 30632180 : edge_to_cases = new hash_map<edge, tree>;
1349 : 30632180 : touched_switch_bbs = BITMAP_ALLOC (NULL);
1350 : 30632180 : }
1351 : :
1352 : : /* Return nonzero if we are recording information for case labels. */
1353 : :
1354 : : static bool
1355 : 365800 : recording_case_labels_p (void)
1356 : : {
1357 : 365800 : return (edge_to_cases != NULL);
1358 : : }
1359 : :
1360 : : /* Stop recording information mapping edges to case labels and
1361 : : remove any information we have recorded. */
1362 : : void
1363 : 30632180 : end_recording_case_labels (void)
1364 : : {
1365 : 30632180 : bitmap_iterator bi;
1366 : 30632180 : unsigned i;
1367 : 30632180 : edge_to_cases->traverse<void *, edge_to_cases_cleanup> (NULL);
1368 : 61264360 : delete edge_to_cases;
1369 : 30632180 : edge_to_cases = NULL;
1370 : 30777671 : EXECUTE_IF_SET_IN_BITMAP (touched_switch_bbs, 0, i, bi)
1371 : : {
1372 : 145491 : basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
1373 : 145491 : if (bb)
1374 : : {
1375 : 432847 : if (gswitch *stmt = safe_dyn_cast <gswitch *> (*gsi_last_bb (bb)))
1376 : 143477 : group_case_labels_stmt (stmt);
1377 : : }
1378 : : }
1379 : 30632180 : BITMAP_FREE (touched_switch_bbs);
1380 : 30632180 : }
1381 : :
1382 : : /* If we are inside a {start,end}_recording_cases block, then return
1383 : : a chain of CASE_LABEL_EXPRs from T which reference E.
1384 : :
1385 : : Otherwise return NULL. */
1386 : :
1387 : : tree
1388 : 365800 : get_cases_for_edge (edge e, gswitch *t)
1389 : : {
1390 : 365800 : tree *slot;
1391 : 365800 : size_t i, n;
1392 : :
1393 : : /* If we are not recording cases, then we do not have CASE_LABEL_EXPR
1394 : : chains available. Return NULL so the caller can detect this case. */
1395 : 365800 : if (!recording_case_labels_p ())
1396 : : return NULL;
1397 : :
1398 : 321888 : slot = edge_to_cases->get (e);
1399 : 321888 : if (slot)
1400 : 176431 : return *slot;
1401 : :
1402 : : /* If we did not find E in the hash table, then this must be the first
1403 : : time we have been queried for information about E & T. Add all the
1404 : : elements from T to the hash table then perform the query again. */
1405 : :
1406 : 145457 : n = gimple_switch_num_labels (t);
1407 : 1293963 : for (i = 0; i < n; i++)
1408 : : {
1409 : 1148506 : tree elt = gimple_switch_label (t, i);
1410 : 1148506 : tree lab = CASE_LABEL (elt);
1411 : 1148506 : basic_block label_bb = label_to_block (cfun, lab);
1412 : 1148506 : edge this_edge = find_edge (e->src, label_bb);
1413 : :
1414 : : /* Add it to the chain of CASE_LABEL_EXPRs referencing E, or create
1415 : : a new chain. */
1416 : 1148506 : tree &s = edge_to_cases->get_or_insert (this_edge);
1417 : 1148506 : CASE_CHAIN (elt) = s;
1418 : 1148506 : s = elt;
1419 : : }
1420 : :
1421 : 145457 : return *edge_to_cases->get (e);
1422 : : }
1423 : :
1424 : : /* Create the edges for a GIMPLE_SWITCH starting at block BB. */
1425 : :
1426 : : static void
1427 : 51749 : make_gimple_switch_edges (gswitch *entry, basic_block bb)
1428 : : {
1429 : 51749 : size_t i, n;
1430 : :
1431 : 51749 : n = gimple_switch_num_labels (entry);
1432 : :
1433 : 371622 : for (i = 0; i < n; ++i)
1434 : : {
1435 : 319873 : basic_block label_bb = gimple_switch_label_bb (cfun, entry, i);
1436 : 319873 : make_edge (bb, label_bb, 0);
1437 : : }
1438 : 51749 : }
1439 : :
1440 : :
1441 : : /* Return the basic block holding label DEST. */
1442 : :
1443 : : basic_block
1444 : 444030575 : label_to_block (struct function *ifun, tree dest)
1445 : : {
1446 : 444030575 : int uid = LABEL_DECL_UID (dest);
1447 : :
1448 : : /* We would die hard when faced by an undefined label. Emit a label to
1449 : : the very first basic block. This will hopefully make even the dataflow
1450 : : and undefined variable warnings quite right. */
1451 : 444030575 : if (seen_error () && uid < 0)
1452 : : {
1453 : 97 : gimple_stmt_iterator gsi =
1454 : 97 : gsi_start_bb (BASIC_BLOCK_FOR_FN (cfun, NUM_FIXED_BLOCKS));
1455 : 97 : gimple *stmt;
1456 : :
1457 : 97 : stmt = gimple_build_label (dest);
1458 : 97 : gsi_insert_before (&gsi, stmt, GSI_NEW_STMT);
1459 : 97 : uid = LABEL_DECL_UID (dest);
1460 : : }
1461 : 888061150 : if (vec_safe_length (ifun->cfg->x_label_to_block_map) <= (unsigned int) uid)
1462 : : return NULL;
1463 : 444030575 : return (*ifun->cfg->x_label_to_block_map)[uid];
1464 : : }
1465 : :
1466 : : /* Create edges for a goto statement at block BB. Returns true
1467 : : if abnormal edges should be created. */
1468 : :
1469 : : static bool
1470 : 5521130 : make_goto_expr_edges (basic_block bb)
1471 : : {
1472 : 5521130 : gimple_stmt_iterator last = gsi_last_bb (bb);
1473 : 5521130 : gimple *goto_t = gsi_stmt (last);
1474 : :
1475 : : /* A simple GOTO creates normal edges. */
1476 : 5521130 : if (simple_goto_p (goto_t))
1477 : : {
1478 : 5520031 : tree dest = gimple_goto_dest (goto_t);
1479 : 5520031 : basic_block label_bb = label_to_block (cfun, dest);
1480 : 5520031 : edge e = make_edge (bb, label_bb, EDGE_FALLTHRU);
1481 : 5520031 : e->goto_locus = gimple_location (goto_t);
1482 : 5520031 : gsi_remove (&last, true);
1483 : 5520031 : return false;
1484 : : }
1485 : :
1486 : : /* A computed GOTO creates abnormal edges. */
1487 : : return true;
1488 : : }
1489 : :
1490 : : /* Create edges for an asm statement with labels at block BB. */
1491 : :
1492 : : static void
1493 : 2227 : make_gimple_asm_edges (basic_block bb)
1494 : : {
1495 : 4454 : gasm *stmt = as_a <gasm *> (*gsi_last_bb (bb));
1496 : 2227 : int i, n = gimple_asm_nlabels (stmt);
1497 : :
1498 : 3018 : for (i = 0; i < n; ++i)
1499 : : {
1500 : 791 : tree label = TREE_VALUE (gimple_asm_label_op (stmt, i));
1501 : 791 : basic_block label_bb = label_to_block (cfun, label);
1502 : 791 : make_edge (bb, label_bb, 0);
1503 : : }
1504 : 2227 : }
1505 : :
1506 : : /*---------------------------------------------------------------------------
1507 : : Flowgraph analysis
1508 : : ---------------------------------------------------------------------------*/
1509 : :
1510 : : /* Cleanup useless labels in basic blocks. This is something we wish
1511 : : to do early because it allows us to group case labels before creating
1512 : : the edges for the CFG, and it speeds up block statement iterators in
1513 : : all passes later on.
1514 : : We rerun this pass after CFG is created, to get rid of the labels that
1515 : : are no longer referenced. After then we do not run it any more, since
1516 : : (almost) no new labels should be created. */
1517 : :
1518 : : /* A map from basic block index to the leading label of that block. */
1519 : : struct label_record
1520 : : {
1521 : : /* The label. */
1522 : : tree label;
1523 : :
1524 : : /* True if the label is referenced from somewhere. */
1525 : : bool used;
1526 : : };
1527 : :
1528 : : /* Given LABEL return the first label in the same basic block. */
1529 : :
1530 : : static tree
1531 : 18790150 : main_block_label (tree label, label_record *label_for_bb)
1532 : : {
1533 : 18790150 : basic_block bb = label_to_block (cfun, label);
1534 : 18790150 : tree main_label = label_for_bb[bb->index].label;
1535 : :
1536 : : /* label_to_block possibly inserted undefined label into the chain. */
1537 : 18790150 : if (!main_label)
1538 : : {
1539 : 87 : label_for_bb[bb->index].label = label;
1540 : 87 : main_label = label;
1541 : : }
1542 : :
1543 : 18790150 : label_for_bb[bb->index].used = true;
1544 : 18790150 : return main_label;
1545 : : }
1546 : :
1547 : : /* Clean up redundant labels within the exception tree. */
1548 : :
1549 : : static void
1550 : 6805206 : cleanup_dead_labels_eh (label_record *label_for_bb)
1551 : : {
1552 : 6805206 : eh_landing_pad lp;
1553 : 6805206 : eh_region r;
1554 : 6805206 : tree lab;
1555 : 6805206 : int i;
1556 : :
1557 : 6805206 : if (cfun->eh == NULL)
1558 : 6805206 : return;
1559 : :
1560 : 9788869 : for (i = 1; vec_safe_iterate (cfun->eh->lp_array, i, &lp); ++i)
1561 : 2983663 : if (lp && lp->post_landing_pad)
1562 : : {
1563 : 1692082 : lab = main_block_label (lp->post_landing_pad, label_for_bb);
1564 : 1692082 : if (lab != lp->post_landing_pad)
1565 : : {
1566 : 0 : EH_LANDING_PAD_NR (lp->post_landing_pad) = 0;
1567 : 0 : lp->post_landing_pad = lab;
1568 : 0 : EH_LANDING_PAD_NR (lab) = lp->index;
1569 : : }
1570 : : }
1571 : :
1572 : 11481169 : FOR_ALL_EH_REGION (r)
1573 : 4675963 : switch (r->type)
1574 : : {
1575 : : case ERT_CLEANUP:
1576 : : case ERT_MUST_NOT_THROW:
1577 : : break;
1578 : :
1579 : 134355 : case ERT_TRY:
1580 : 134355 : {
1581 : 134355 : eh_catch c;
1582 : 268264 : for (c = r->u.eh_try.first_catch; c ; c = c->next_catch)
1583 : : {
1584 : 133909 : lab = c->label;
1585 : 133909 : if (lab)
1586 : 90342 : c->label = main_block_label (lab, label_for_bb);
1587 : : }
1588 : : }
1589 : : break;
1590 : :
1591 : 10940 : case ERT_ALLOWED_EXCEPTIONS:
1592 : 10940 : lab = r->u.allowed.label;
1593 : 10940 : if (lab)
1594 : 1108 : r->u.allowed.label = main_block_label (lab, label_for_bb);
1595 : : break;
1596 : : }
1597 : : }
1598 : :
1599 : :
1600 : : /* Cleanup redundant labels. This is a three-step process:
1601 : : 1) Find the leading label for each block.
1602 : : 2) Redirect all references to labels to the leading labels.
1603 : : 3) Cleanup all useless labels. */
1604 : :
1605 : : void
1606 : 6805206 : cleanup_dead_labels (void)
1607 : : {
1608 : 6805206 : basic_block bb;
1609 : 6805206 : label_record *label_for_bb = XCNEWVEC (struct label_record,
1610 : : last_basic_block_for_fn (cfun));
1611 : :
1612 : : /* Find a suitable label for each block. We use the first user-defined
1613 : : label if there is one, or otherwise just the first label we see. */
1614 : 57845920 : FOR_EACH_BB_FN (bb, cfun)
1615 : : {
1616 : 51040714 : gimple_stmt_iterator i;
1617 : :
1618 : 133313982 : for (i = gsi_start_bb (bb); !gsi_end_p (i); gsi_next (&i))
1619 : : {
1620 : 81105752 : tree label;
1621 : 82282685 : glabel *label_stmt = dyn_cast <glabel *> (gsi_stmt (i));
1622 : :
1623 : 31241971 : if (!label_stmt)
1624 : : break;
1625 : :
1626 : 31241971 : label = gimple_label_label (label_stmt);
1627 : :
1628 : : /* If we have not yet seen a label for the current block,
1629 : : remember this one and see if there are more labels. */
1630 : 31241971 : if (!label_for_bb[bb->index].label)
1631 : : {
1632 : 29204281 : label_for_bb[bb->index].label = label;
1633 : 29204281 : continue;
1634 : : }
1635 : :
1636 : : /* If we did see a label for the current block already, but it
1637 : : is an artificially created label, replace it if the current
1638 : : label is a user defined label. */
1639 : 2037690 : if (!DECL_ARTIFICIAL (label)
1640 : 2037690 : && DECL_ARTIFICIAL (label_for_bb[bb->index].label))
1641 : : {
1642 : 9417 : label_for_bb[bb->index].label = label;
1643 : 9417 : break;
1644 : : }
1645 : : }
1646 : : }
1647 : :
1648 : : /* Now redirect all jumps/branches to the selected label.
1649 : : First do so for each block ending in a control statement. */
1650 : 57845920 : FOR_EACH_BB_FN (bb, cfun)
1651 : : {
1652 : 51040714 : gimple *stmt = *gsi_last_bb (bb);
1653 : 51040714 : tree label, new_label;
1654 : :
1655 : 51040714 : if (!stmt)
1656 : 496540 : continue;
1657 : :
1658 : 50544174 : switch (gimple_code (stmt))
1659 : : {
1660 : 14956586 : case GIMPLE_COND:
1661 : 14956586 : {
1662 : 14956586 : gcond *cond_stmt = as_a <gcond *> (stmt);
1663 : 14956586 : label = gimple_cond_true_label (cond_stmt);
1664 : 14956586 : if (label)
1665 : : {
1666 : 4977587 : new_label = main_block_label (label, label_for_bb);
1667 : 4977587 : if (new_label != label)
1668 : 7574 : gimple_cond_set_true_label (cond_stmt, new_label);
1669 : : }
1670 : :
1671 : 14956586 : label = gimple_cond_false_label (cond_stmt);
1672 : 14956586 : if (label)
1673 : : {
1674 : 4977587 : new_label = main_block_label (label, label_for_bb);
1675 : 4977587 : if (new_label != label)
1676 : 97384 : gimple_cond_set_false_label (cond_stmt, new_label);
1677 : : }
1678 : : }
1679 : : break;
1680 : :
1681 : 119930 : case GIMPLE_SWITCH:
1682 : 119930 : {
1683 : 119930 : gswitch *switch_stmt = as_a <gswitch *> (stmt);
1684 : 119930 : size_t i, n = gimple_switch_num_labels (switch_stmt);
1685 : :
1686 : : /* Replace all destination labels. */
1687 : 1674757 : for (i = 0; i < n; ++i)
1688 : : {
1689 : 1554827 : tree case_label = gimple_switch_label (switch_stmt, i);
1690 : 1554827 : label = CASE_LABEL (case_label);
1691 : 1554827 : new_label = main_block_label (label, label_for_bb);
1692 : 1554827 : if (new_label != label)
1693 : 789396 : CASE_LABEL (case_label) = new_label;
1694 : : }
1695 : : break;
1696 : : }
1697 : :
1698 : 7687 : case GIMPLE_ASM:
1699 : 7687 : {
1700 : 7687 : gasm *asm_stmt = as_a <gasm *> (stmt);
1701 : 7687 : int i, n = gimple_asm_nlabels (asm_stmt);
1702 : :
1703 : 10012 : for (i = 0; i < n; ++i)
1704 : : {
1705 : 2325 : tree cons = gimple_asm_label_op (asm_stmt, i);
1706 : 2325 : tree label = main_block_label (TREE_VALUE (cons), label_for_bb);
1707 : 2325 : TREE_VALUE (cons) = label;
1708 : : }
1709 : : break;
1710 : : }
1711 : :
1712 : : /* We have to handle gotos until they're removed, and we don't
1713 : : remove them until after we've created the CFG edges. */
1714 : 5493669 : case GIMPLE_GOTO:
1715 : 5493669 : if (!computed_goto_p (stmt))
1716 : : {
1717 : 5491536 : ggoto *goto_stmt = as_a <ggoto *> (stmt);
1718 : 5491536 : label = gimple_goto_dest (goto_stmt);
1719 : 5491536 : new_label = main_block_label (label, label_for_bb);
1720 : 5491536 : if (new_label != label)
1721 : 958995 : gimple_goto_set_dest (goto_stmt, new_label);
1722 : : }
1723 : : break;
1724 : :
1725 : 938 : case GIMPLE_TRANSACTION:
1726 : 938 : {
1727 : 938 : gtransaction *txn = as_a <gtransaction *> (stmt);
1728 : :
1729 : 938 : label = gimple_transaction_label_norm (txn);
1730 : 938 : if (label)
1731 : : {
1732 : 918 : new_label = main_block_label (label, label_for_bb);
1733 : 918 : if (new_label != label)
1734 : 0 : gimple_transaction_set_label_norm (txn, new_label);
1735 : : }
1736 : :
1737 : 938 : label = gimple_transaction_label_uninst (txn);
1738 : 938 : if (label)
1739 : : {
1740 : 908 : new_label = main_block_label (label, label_for_bb);
1741 : 908 : if (new_label != label)
1742 : 0 : gimple_transaction_set_label_uninst (txn, new_label);
1743 : : }
1744 : :
1745 : 938 : label = gimple_transaction_label_over (txn);
1746 : 938 : if (label)
1747 : : {
1748 : 930 : new_label = main_block_label (label, label_for_bb);
1749 : 930 : if (new_label != label)
1750 : 9 : gimple_transaction_set_label_over (txn, new_label);
1751 : : }
1752 : : }
1753 : : break;
1754 : :
1755 : : default:
1756 : : break;
1757 : : }
1758 : : }
1759 : :
1760 : : /* Do the same for the exception region tree labels. */
1761 : 6805206 : cleanup_dead_labels_eh (label_for_bb);
1762 : :
1763 : : /* Finally, purge dead labels. All user-defined labels and labels that
1764 : : can be the target of non-local gotos and labels which have their
1765 : : address taken are preserved. */
1766 : 57845920 : FOR_EACH_BB_FN (bb, cfun)
1767 : : {
1768 : 51040714 : gimple_stmt_iterator i;
1769 : 51040714 : tree label_for_this_bb = label_for_bb[bb->index].label;
1770 : :
1771 : 51040714 : if (!label_for_this_bb)
1772 : 21836346 : continue;
1773 : :
1774 : : /* If the main label of the block is unused, we may still remove it. */
1775 : 29204368 : if (!label_for_bb[bb->index].used)
1776 : 13641984 : label_for_this_bb = NULL;
1777 : :
1778 : 89650804 : for (i = gsi_start_bb (bb); !gsi_end_p (i); )
1779 : : {
1780 : 59775011 : tree label;
1781 : 60446436 : glabel *label_stmt = dyn_cast <glabel *> (gsi_stmt (i));
1782 : :
1783 : 31242068 : if (!label_stmt)
1784 : : break;
1785 : :
1786 : 31242068 : label = gimple_label_label (label_stmt);
1787 : :
1788 : 31242068 : if (label == label_for_this_bb
1789 : 15679684 : || !DECL_ARTIFICIAL (label)
1790 : 15012671 : || DECL_NONLOCAL (label)
1791 : 46253286 : || FORCED_LABEL (label))
1792 : 16243523 : gsi_next (&i);
1793 : : else
1794 : : {
1795 : 14998545 : gcc_checking_assert (EH_LANDING_PAD_NR (label) == 0);
1796 : 14998545 : gsi_remove (&i, true);
1797 : : }
1798 : : }
1799 : : }
1800 : :
1801 : 6805206 : free (label_for_bb);
1802 : 6805206 : }
1803 : :
1804 : : /* Scan the sorted vector of cases in STMT (a GIMPLE_SWITCH) and combine
1805 : : the ones jumping to the same label.
1806 : : Eg. three separate entries 1: 2: 3: become one entry 1..3: */
1807 : :
1808 : : bool
1809 : 265196 : group_case_labels_stmt (gswitch *stmt)
1810 : : {
1811 : 265196 : int old_size = gimple_switch_num_labels (stmt);
1812 : 265196 : int i, next_index, new_size;
1813 : 265196 : basic_block default_bb = NULL;
1814 : 265196 : hash_set<tree> *removed_labels = NULL;
1815 : :
1816 : 265196 : default_bb = gimple_switch_default_bb (cfun, stmt);
1817 : :
1818 : : /* Look for possible opportunities to merge cases. */
1819 : 265196 : new_size = i = 1;
1820 : 2229140 : while (i < old_size)
1821 : : {
1822 : 1698748 : tree base_case, base_high;
1823 : 1698748 : basic_block base_bb;
1824 : :
1825 : 1698748 : base_case = gimple_switch_label (stmt, i);
1826 : :
1827 : 1698748 : gcc_assert (base_case);
1828 : 1698748 : base_bb = label_to_block (cfun, CASE_LABEL (base_case));
1829 : :
1830 : : /* Discard cases that have the same destination as the default case or
1831 : : whose destination blocks have already been removed as unreachable. */
1832 : 1703402 : if (base_bb == NULL
1833 : 1698748 : || base_bb == default_bb
1834 : 1698748 : || (removed_labels
1835 : 1 : && removed_labels->contains (CASE_LABEL (base_case))))
1836 : : {
1837 : 4654 : i++;
1838 : 4654 : continue;
1839 : : }
1840 : :
1841 : 1694094 : base_high = CASE_HIGH (base_case)
1842 : 3388188 : ? CASE_HIGH (base_case)
1843 : 1572534 : : CASE_LOW (base_case);
1844 : 1694094 : next_index = i + 1;
1845 : :
1846 : : /* Try to merge case labels. Break out when we reach the end
1847 : : of the label vector or when we cannot merge the next case
1848 : : label with the current one. */
1849 : 2441876 : while (next_index < old_size)
1850 : : {
1851 : 2178488 : tree merge_case = gimple_switch_label (stmt, next_index);
1852 : 2178488 : basic_block merge_bb = label_to_block (cfun, CASE_LABEL (merge_case));
1853 : 2178488 : wide_int bhp1 = wi::to_wide (base_high) + 1;
1854 : :
1855 : : /* Merge the cases if they jump to the same place,
1856 : : and their ranges are consecutive. */
1857 : 2178488 : if (merge_bb == base_bb
1858 : 841098 : && (removed_labels == NULL
1859 : 0 : || !removed_labels->contains (CASE_LABEL (merge_case)))
1860 : 3019586 : && wi::to_wide (CASE_LOW (merge_case)) == bhp1)
1861 : : {
1862 : 747782 : base_high
1863 : 747782 : = (CASE_HIGH (merge_case)
1864 : 747782 : ? CASE_HIGH (merge_case) : CASE_LOW (merge_case));
1865 : 747782 : CASE_HIGH (base_case) = base_high;
1866 : 747782 : next_index++;
1867 : : }
1868 : : else
1869 : : break;
1870 : 2178488 : }
1871 : :
1872 : : /* Discard cases that have an unreachable destination block. */
1873 : 1703782 : if (EDGE_COUNT (base_bb->succs) == 0
1874 : 287178 : && gimple_seq_unreachable_p (bb_seq (base_bb))
1875 : : /* Don't optimize this if __builtin_unreachable () is the
1876 : : implicitly added one by the C++ FE too early, before
1877 : : -Wreturn-type can be diagnosed. We'll optimize it later
1878 : : during switchconv pass or any other cfg cleanup. */
1879 : 1417531 : && (gimple_in_ssa_p (cfun)
1880 : 907 : || (LOCATION_LOCUS (gimple_location (last_nondebug_stmt (base_bb)))
1881 : : != BUILTINS_LOCATION)))
1882 : : {
1883 : 926 : edge base_edge = find_edge (gimple_bb (stmt), base_bb);
1884 : 926 : if (base_edge != NULL)
1885 : : {
1886 : 38 : for (gimple_stmt_iterator gsi = gsi_start_bb (base_bb);
1887 : 38 : !gsi_end_p (gsi); gsi_next (&gsi))
1888 : 38 : if (glabel *stmt = dyn_cast <glabel *> (gsi_stmt (gsi)))
1889 : : {
1890 : 19 : if (FORCED_LABEL (gimple_label_label (stmt))
1891 : 19 : || DECL_NONLOCAL (gimple_label_label (stmt)))
1892 : : {
1893 : : /* Forced/non-local labels aren't going to be removed,
1894 : : but they will be moved to some neighbouring basic
1895 : : block. If some later case label refers to one of
1896 : : those labels, we should throw that case away rather
1897 : : than keeping it around and refering to some random
1898 : : other basic block without an edge to it. */
1899 : 1 : if (removed_labels == NULL)
1900 : 1 : removed_labels = new hash_set<tree>;
1901 : 1 : removed_labels->add (gimple_label_label (stmt));
1902 : : }
1903 : : }
1904 : : else
1905 : : break;
1906 : 19 : remove_edge_and_dominated_blocks (base_edge);
1907 : : }
1908 : 926 : i = next_index;
1909 : 926 : continue;
1910 : 926 : }
1911 : :
1912 : 1693168 : if (new_size < i)
1913 : 77270 : gimple_switch_set_label (stmt, new_size,
1914 : : gimple_switch_label (stmt, i));
1915 : 1693168 : i = next_index;
1916 : 1693168 : new_size++;
1917 : : }
1918 : :
1919 : 265196 : gcc_assert (new_size <= old_size);
1920 : :
1921 : 265196 : if (new_size < old_size)
1922 : 19626 : gimple_switch_set_num_labels (stmt, new_size);
1923 : :
1924 : 265197 : delete removed_labels;
1925 : 265196 : return new_size < old_size;
1926 : : }
1927 : :
1928 : : /* Look for blocks ending in a multiway branch (a GIMPLE_SWITCH),
1929 : : and scan the sorted vector of cases. Combine the ones jumping to the
1930 : : same label. */
1931 : :
1932 : : bool
1933 : 4116288 : group_case_labels (void)
1934 : : {
1935 : 4116288 : basic_block bb;
1936 : 4116288 : bool changed = false;
1937 : :
1938 : 35391836 : FOR_EACH_BB_FN (bb, cfun)
1939 : : {
1940 : 93455565 : if (gswitch *stmt = safe_dyn_cast <gswitch *> (*gsi_last_bb (bb)))
1941 : 68181 : changed |= group_case_labels_stmt (stmt);
1942 : : }
1943 : :
1944 : 4116288 : return changed;
1945 : : }
1946 : :
1947 : : /* Checks whether we can merge block B into block A. */
1948 : :
1949 : : static bool
1950 : 386170774 : gimple_can_merge_blocks_p (basic_block a, basic_block b)
1951 : : {
1952 : 386170774 : gimple *stmt;
1953 : :
1954 : 772341548 : if (!single_succ_p (a))
1955 : : return false;
1956 : :
1957 : 187892321 : if (single_succ_edge (a)->flags & EDGE_COMPLEX)
1958 : : return false;
1959 : :
1960 : 177136592 : if (single_succ (a) != b)
1961 : : return false;
1962 : :
1963 : 354273184 : if (!single_pred_p (b))
1964 : : return false;
1965 : :
1966 : 84403185 : if (a == ENTRY_BLOCK_PTR_FOR_FN (cfun)
1967 : 52466896 : || b == EXIT_BLOCK_PTR_FOR_FN (cfun))
1968 : : return false;
1969 : :
1970 : : /* If A ends by a statement causing exceptions or something similar, we
1971 : : cannot merge the blocks. */
1972 : 25165276 : stmt = *gsi_last_bb (a);
1973 : 25165276 : if (stmt && stmt_ends_bb_p (stmt))
1974 : : return false;
1975 : :
1976 : : /* Examine the labels at the beginning of B. */
1977 : 46787775 : for (gimple_stmt_iterator gsi = gsi_start_bb (b); !gsi_end_p (gsi);
1978 : 147461 : gsi_next (&gsi))
1979 : : {
1980 : 22128676 : tree lab;
1981 : 22128676 : glabel *label_stmt = dyn_cast <glabel *> (gsi_stmt (gsi));
1982 : 1717223 : if (!label_stmt)
1983 : : break;
1984 : 1717223 : lab = gimple_label_label (label_stmt);
1985 : :
1986 : : /* Do not remove user forced labels or for -O0 any user labels. */
1987 : 1759698 : if (!DECL_ARTIFICIAL (lab) && (!optimize || FORCED_LABEL (lab)))
1988 : 365178556 : return false;
1989 : : }
1990 : :
1991 : : /* Protect simple loop latches. We only want to avoid merging
1992 : : the latch with the loop header or with a block in another
1993 : : loop in this case. */
1994 : 21750395 : if (current_loops
1995 : 19419848 : && b->loop_father->latch == b
1996 : 340059 : && loops_state_satisfies_p (LOOPS_HAVE_SIMPLE_LATCHES)
1997 : 21779142 : && (b->loop_father->header == a
1998 : 17916 : || b->loop_father != a->loop_father))
1999 : : return false;
2000 : :
2001 : : /* It must be possible to eliminate all phi nodes in B. If ssa form
2002 : : is not up-to-date and a name-mapping is registered, we cannot eliminate
2003 : : any phis. Symbols marked for renaming are never a problem though. */
2004 : 26961165 : for (gphi_iterator gsi = gsi_start_phis (b); !gsi_end_p (gsi);
2005 : 5221745 : gsi_next (&gsi))
2006 : : {
2007 : 5221745 : gphi *phi = gsi.phi ();
2008 : : /* Technically only new names matter. */
2009 : 5221745 : if (name_registered_for_update_p (PHI_RESULT (phi)))
2010 : 0 : return false;
2011 : : }
2012 : :
2013 : : /* When not optimizing, don't merge if we'd lose goto_locus. */
2014 : 21739420 : if (!optimize
2015 : 21739420 : && single_succ_edge (a)->goto_locus != UNKNOWN_LOCATION)
2016 : : {
2017 : 782972 : location_t goto_locus = single_succ_edge (a)->goto_locus;
2018 : 782972 : gimple_stmt_iterator prev, next;
2019 : 782972 : prev = gsi_last_nondebug_bb (a);
2020 : 782972 : next = gsi_after_labels (b);
2021 : 782972 : if (!gsi_end_p (next) && is_gimple_debug (gsi_stmt (next)))
2022 : 6 : gsi_next_nondebug (&next);
2023 : 782972 : if ((gsi_end_p (prev)
2024 : 674443 : || gimple_location (gsi_stmt (prev)) != goto_locus)
2025 : 1434207 : && (gsi_end_p (next)
2026 : 720449 : || gimple_location (gsi_stmt (next)) != goto_locus))
2027 : 747202 : return false;
2028 : : }
2029 : :
2030 : : return true;
2031 : : }
2032 : :
2033 : : /* Replaces all uses of NAME by VAL. */
2034 : :
2035 : : void
2036 : 3207598 : replace_uses_by (tree name, tree val)
2037 : : {
2038 : 3207598 : imm_use_iterator imm_iter;
2039 : 3207598 : use_operand_p use;
2040 : 3207598 : gimple *stmt;
2041 : 3207598 : edge e;
2042 : :
2043 : 8746257 : FOR_EACH_IMM_USE_STMT (stmt, imm_iter, name)
2044 : : {
2045 : : /* Mark the block if we change the last stmt in it. */
2046 : 5538659 : if (cfgcleanup_altered_bbs
2047 : 5538659 : && stmt_ends_bb_p (stmt))
2048 : 693959 : bitmap_set_bit (cfgcleanup_altered_bbs, gimple_bb (stmt)->index);
2049 : :
2050 : 16898613 : FOR_EACH_IMM_USE_ON_STMT (use, imm_iter)
2051 : : {
2052 : 5679977 : replace_exp (use, val);
2053 : :
2054 : 5679977 : if (gimple_code (stmt) == GIMPLE_PHI)
2055 : : {
2056 : 2096891 : e = gimple_phi_arg_edge (as_a <gphi *> (stmt),
2057 : 2096891 : PHI_ARG_INDEX_FROM_USE (use));
2058 : 2096891 : if (e->flags & EDGE_ABNORMAL
2059 : 2096891 : && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (val))
2060 : : {
2061 : : /* This can only occur for virtual operands, since
2062 : : for the real ones SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name))
2063 : : would prevent replacement. */
2064 : 0 : gcc_checking_assert (virtual_operand_p (name));
2065 : 0 : SSA_NAME_OCCURS_IN_ABNORMAL_PHI (val) = 1;
2066 : : }
2067 : : }
2068 : : }
2069 : :
2070 : 5538659 : if (gimple_code (stmt) != GIMPLE_PHI)
2071 : : {
2072 : 3577250 : gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
2073 : 3577250 : gimple *orig_stmt = stmt;
2074 : 3577250 : size_t i;
2075 : :
2076 : : /* FIXME. It shouldn't be required to keep TREE_CONSTANT
2077 : : on ADDR_EXPRs up-to-date on GIMPLE. Propagation will
2078 : : only change sth from non-invariant to invariant, and only
2079 : : when propagating constants. */
2080 : 3577250 : if (is_gimple_min_invariant (val))
2081 : 1504004 : for (i = 0; i < gimple_num_ops (stmt); i++)
2082 : : {
2083 : 1091346 : tree op = gimple_op (stmt, i);
2084 : : /* Operands may be empty here. For example, the labels
2085 : : of a GIMPLE_COND are nulled out following the creation
2086 : : of the corresponding CFG edges. */
2087 : 1091346 : if (op && TREE_CODE (op) == ADDR_EXPR)
2088 : 54863 : recompute_tree_invariant_for_addr_expr (op);
2089 : : }
2090 : :
2091 : 3577250 : if (fold_stmt (&gsi))
2092 : 583249 : stmt = gsi_stmt (gsi);
2093 : :
2094 : 3577250 : if (maybe_clean_or_replace_eh_stmt (orig_stmt, stmt))
2095 : 114 : gimple_purge_dead_eh_edges (gimple_bb (stmt));
2096 : :
2097 : 3577250 : update_stmt (stmt);
2098 : : }
2099 : 3207598 : }
2100 : :
2101 : 3207598 : gcc_checking_assert (has_zero_uses (name));
2102 : :
2103 : : /* Also update the trees stored in loop structures. */
2104 : 3207598 : if (current_loops)
2105 : : {
2106 : 75509372 : for (auto loop : loops_list (cfun, 0))
2107 : 69094176 : substitute_in_loop_info (loop, name, val);
2108 : : }
2109 : 3207598 : }
2110 : :
2111 : : /* Merge block B into block A. */
2112 : :
2113 : : static void
2114 : 13183485 : gimple_merge_blocks (basic_block a, basic_block b)
2115 : : {
2116 : 13183485 : gimple_stmt_iterator last, gsi;
2117 : 13183485 : gphi_iterator psi;
2118 : :
2119 : 13183485 : if (dump_file)
2120 : 18539 : fprintf (dump_file, "Merging blocks %d and %d\n", a->index, b->index);
2121 : :
2122 : : /* Remove all single-valued PHI nodes from block B of the form
2123 : : V_i = PHI <V_j> by propagating V_j to all the uses of V_i. */
2124 : 13183485 : gsi = gsi_last_bb (a);
2125 : 16896839 : for (psi = gsi_start_phis (b); !gsi_end_p (psi); )
2126 : : {
2127 : 3713354 : gimple *phi = gsi_stmt (psi);
2128 : 3713354 : tree def = gimple_phi_result (phi), use = gimple_phi_arg_def (phi, 0);
2129 : 3713354 : gimple *copy;
2130 : 3713354 : bool may_replace_uses = (virtual_operand_p (def)
2131 : 3713354 : || may_propagate_copy (def, use));
2132 : :
2133 : : /* In case we maintain loop closed ssa form, do not propagate arguments
2134 : : of loop exit phi nodes. */
2135 : 3713354 : if (current_loops
2136 : 3713354 : && loops_state_satisfies_p (LOOP_CLOSED_SSA)
2137 : 512452 : && !virtual_operand_p (def)
2138 : 364345 : && TREE_CODE (use) == SSA_NAME
2139 : 3988396 : && a->loop_father != b->loop_father)
2140 : : may_replace_uses = false;
2141 : :
2142 : 3712765 : if (!may_replace_uses)
2143 : : {
2144 : 1592 : gcc_assert (!virtual_operand_p (def));
2145 : :
2146 : : /* Note that just emitting the copies is fine -- there is no problem
2147 : : with ordering of phi nodes. This is because A is the single
2148 : : predecessor of B, therefore results of the phi nodes cannot
2149 : : appear as arguments of the phi nodes. */
2150 : 796 : copy = gimple_build_assign (def, use);
2151 : 796 : gsi_insert_after (&gsi, copy, GSI_NEW_STMT);
2152 : 796 : remove_phi_node (&psi, false);
2153 : : }
2154 : : else
2155 : : {
2156 : : /* If we deal with a PHI for virtual operands, we can simply
2157 : : propagate these without fussing with folding or updating
2158 : : the stmt. */
2159 : 7425116 : if (virtual_operand_p (def))
2160 : : {
2161 : 1496704 : imm_use_iterator iter;
2162 : 1496704 : use_operand_p use_p;
2163 : 1496704 : gimple *stmt;
2164 : :
2165 : 4230160 : FOR_EACH_IMM_USE_STMT (stmt, iter, def)
2166 : 8255710 : FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
2167 : 4257831 : SET_USE (use_p, use);
2168 : :
2169 : 1496704 : if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (def))
2170 : 287 : SSA_NAME_OCCURS_IN_ABNORMAL_PHI (use) = 1;
2171 : : }
2172 : : else
2173 : 2215854 : replace_uses_by (def, use);
2174 : :
2175 : 3712558 : remove_phi_node (&psi, true);
2176 : : }
2177 : : }
2178 : :
2179 : : /* Ensure that B follows A. */
2180 : 13183485 : move_block_after (b, a);
2181 : :
2182 : 13183485 : gcc_assert (single_succ_edge (a)->flags & EDGE_FALLTHRU);
2183 : 26366970 : gcc_assert (!*gsi_last_bb (a)
2184 : : || !stmt_ends_bb_p (*gsi_last_bb (a)));
2185 : :
2186 : : /* Remove labels from B and set gimple_bb to A for other statements. */
2187 : 99727130 : for (gsi = gsi_start_bb (b); !gsi_end_p (gsi);)
2188 : : {
2189 : 73360160 : gimple *stmt = gsi_stmt (gsi);
2190 : 73360160 : if (glabel *label_stmt = dyn_cast <glabel *> (stmt))
2191 : : {
2192 : 105022 : tree label = gimple_label_label (label_stmt);
2193 : 105022 : int lp_nr;
2194 : :
2195 : 105022 : gsi_remove (&gsi, false);
2196 : :
2197 : : /* Now that we can thread computed gotos, we might have
2198 : : a situation where we have a forced label in block B
2199 : : However, the label at the start of block B might still be
2200 : : used in other ways (think about the runtime checking for
2201 : : Fortran assigned gotos). So we cannot just delete the
2202 : : label. Instead we move the label to the start of block A. */
2203 : 105022 : if (FORCED_LABEL (label))
2204 : : {
2205 : 1543 : gimple_stmt_iterator dest_gsi = gsi_start_bb (a);
2206 : 1543 : tree first_label = NULL_TREE;
2207 : 1543 : if (!gsi_end_p (dest_gsi))
2208 : 1529 : if (glabel *first_label_stmt
2209 : 1529 : = dyn_cast <glabel *> (gsi_stmt (dest_gsi)))
2210 : 1000 : first_label = gimple_label_label (first_label_stmt);
2211 : 1000 : if (first_label
2212 : 1000 : && (DECL_NONLOCAL (first_label)
2213 : 1000 : || EH_LANDING_PAD_NR (first_label) != 0))
2214 : 4 : gsi_insert_after (&dest_gsi, stmt, GSI_NEW_STMT);
2215 : : else
2216 : 1539 : gsi_insert_before (&dest_gsi, stmt, GSI_NEW_STMT);
2217 : : }
2218 : : /* Other user labels keep around in a form of a debug stmt. */
2219 : 103479 : else if (!DECL_ARTIFICIAL (label) && MAY_HAVE_DEBUG_BIND_STMTS)
2220 : : {
2221 : 7767 : gimple *dbg = gimple_build_debug_bind (label,
2222 : : integer_zero_node,
2223 : : stmt);
2224 : 7767 : gimple_debug_bind_reset_value (dbg);
2225 : 7767 : gsi_insert_before (&gsi, dbg, GSI_SAME_STMT);
2226 : : }
2227 : :
2228 : 105022 : lp_nr = EH_LANDING_PAD_NR (label);
2229 : 105022 : if (lp_nr)
2230 : : {
2231 : 9850 : eh_landing_pad lp = get_eh_landing_pad_from_number (lp_nr);
2232 : 9850 : lp->post_landing_pad = NULL;
2233 : : }
2234 : : }
2235 : : else
2236 : : {
2237 : 73255138 : gimple_set_bb (stmt, a);
2238 : 73255138 : gsi_next (&gsi);
2239 : : }
2240 : : }
2241 : :
2242 : : /* When merging two BBs, if their counts are different, the larger count
2243 : : is selected as the new bb count. This is to handle inconsistent
2244 : : profiles. */
2245 : 13183485 : if (a->loop_father == b->loop_father)
2246 : : {
2247 : 13123437 : a->count = a->count.merge (b->count);
2248 : : }
2249 : :
2250 : : /* Merge the sequences. */
2251 : 13183485 : last = gsi_last_bb (a);
2252 : 26366970 : gsi_insert_seq_after (&last, bb_seq (b), GSI_NEW_STMT);
2253 : 13183485 : set_bb_seq (b, NULL);
2254 : :
2255 : 13183485 : if (cfgcleanup_altered_bbs)
2256 : 13162943 : bitmap_set_bit (cfgcleanup_altered_bbs, a->index);
2257 : 13183485 : }
2258 : :
2259 : :
2260 : : /* Return the one of two successors of BB that is not reachable by a
2261 : : complex edge, if there is one. Else, return BB. We use
2262 : : this in optimizations that use post-dominators for their heuristics,
2263 : : to catch the cases in C++ where function calls are involved. */
2264 : :
2265 : : basic_block
2266 : 8 : single_noncomplex_succ (basic_block bb)
2267 : : {
2268 : 8 : edge e0, e1;
2269 : 8 : if (EDGE_COUNT (bb->succs) != 2)
2270 : : return bb;
2271 : :
2272 : 8 : e0 = EDGE_SUCC (bb, 0);
2273 : 8 : e1 = EDGE_SUCC (bb, 1);
2274 : 8 : if (e0->flags & EDGE_COMPLEX)
2275 : 8 : return e1->dest;
2276 : 0 : if (e1->flags & EDGE_COMPLEX)
2277 : 0 : return e0->dest;
2278 : :
2279 : : return bb;
2280 : : }
2281 : :
2282 : : /* T is CALL_EXPR. Set current_function_calls_* flags. */
2283 : :
2284 : : void
2285 : 48382187 : notice_special_calls (gcall *call)
2286 : : {
2287 : 48382187 : int flags = gimple_call_flags (call);
2288 : :
2289 : 48382187 : if (flags & ECF_MAY_BE_ALLOCA)
2290 : 145129 : cfun->calls_alloca = true;
2291 : 48382187 : if (flags & ECF_RETURNS_TWICE)
2292 : 6766 : cfun->calls_setjmp = true;
2293 : 48382187 : }
2294 : :
2295 : :
2296 : : /* Clear flags set by notice_special_calls. Used by dead code removal
2297 : : to update the flags. */
2298 : :
2299 : : void
2300 : 7563479 : clear_special_calls (void)
2301 : : {
2302 : 7563479 : cfun->calls_alloca = false;
2303 : 7563479 : cfun->calls_setjmp = false;
2304 : 7563479 : }
2305 : :
2306 : : /* Remove PHI nodes associated with basic block BB and all edges out of BB. */
2307 : :
2308 : : static void
2309 : 32044219 : remove_phi_nodes_and_edges_for_unreachable_block (basic_block bb)
2310 : : {
2311 : : /* Since this block is no longer reachable, we can just delete all
2312 : : of its PHI nodes. */
2313 : 32044219 : remove_phi_nodes (bb);
2314 : :
2315 : : /* Remove edges to BB's successors. */
2316 : 94296512 : while (EDGE_COUNT (bb->succs) > 0)
2317 : 30208074 : remove_edge (EDGE_SUCC (bb, 0));
2318 : 32044219 : }
2319 : :
2320 : :
2321 : : /* Remove statements of basic block BB. */
2322 : :
2323 : : static void
2324 : 32044219 : remove_bb (basic_block bb)
2325 : : {
2326 : 32044219 : gimple_stmt_iterator i;
2327 : :
2328 : 32044219 : if (dump_file)
2329 : : {
2330 : 39329 : fprintf (dump_file, "Removing basic block %d\n", bb->index);
2331 : 39329 : if (dump_flags & TDF_DETAILS)
2332 : : {
2333 : 26656 : dump_bb (dump_file, bb, 0, TDF_BLOCKS);
2334 : 26656 : fprintf (dump_file, "\n");
2335 : : }
2336 : : }
2337 : :
2338 : 32044219 : if (current_loops)
2339 : : {
2340 : 30372208 : class loop *loop = bb->loop_father;
2341 : :
2342 : : /* If a loop gets removed, clean up the information associated
2343 : : with it. */
2344 : 30372208 : if (loop->latch == bb
2345 : 30193977 : || loop->header == bb)
2346 : 211236 : free_numbers_of_iterations_estimates (loop);
2347 : : }
2348 : :
2349 : : /* Remove all the instructions in the block. */
2350 : 32044219 : if (bb_seq (bb) != NULL)
2351 : : {
2352 : : /* Walk backwards so as to get a chance to substitute all
2353 : : released DEFs into debug stmts. See
2354 : : eliminate_unnecessary_stmts() in tree-ssa-dce.cc for more
2355 : : details. */
2356 : 5715856 : for (i = gsi_last_bb (bb); !gsi_end_p (i);)
2357 : : {
2358 : 15259166 : gimple *stmt = gsi_stmt (i);
2359 : 15259166 : glabel *label_stmt = dyn_cast <glabel *> (stmt);
2360 : 1919965 : if (label_stmt
2361 : 1919965 : && (FORCED_LABEL (gimple_label_label (label_stmt))
2362 : 1919538 : || DECL_NONLOCAL (gimple_label_label (label_stmt))))
2363 : : {
2364 : 429 : basic_block new_bb;
2365 : 429 : gimple_stmt_iterator new_gsi;
2366 : :
2367 : : /* A non-reachable non-local label may still be referenced.
2368 : : But it no longer needs to carry the extra semantics of
2369 : : non-locality. */
2370 : 429 : if (DECL_NONLOCAL (gimple_label_label (label_stmt)))
2371 : : {
2372 : 2 : DECL_NONLOCAL (gimple_label_label (label_stmt)) = 0;
2373 : 2 : FORCED_LABEL (gimple_label_label (label_stmt)) = 1;
2374 : : }
2375 : :
2376 : 429 : new_bb = bb->prev_bb;
2377 : : /* Don't move any labels into ENTRY block. */
2378 : 429 : if (new_bb == ENTRY_BLOCK_PTR_FOR_FN (cfun))
2379 : : {
2380 : 0 : new_bb = single_succ (new_bb);
2381 : 0 : gcc_assert (new_bb != bb);
2382 : : }
2383 : 429 : if ((unsigned) bb->index < bb_to_omp_idx.length ()
2384 : 10 : && ((unsigned) new_bb->index >= bb_to_omp_idx.length ()
2385 : 10 : || (bb_to_omp_idx[bb->index]
2386 : 10 : != bb_to_omp_idx[new_bb->index])))
2387 : : {
2388 : : /* During cfg pass make sure to put orphaned labels
2389 : : into the right OMP region. */
2390 : : unsigned int i;
2391 : : int idx;
2392 : 30 : new_bb = NULL;
2393 : 30 : FOR_EACH_VEC_ELT (bb_to_omp_idx, i, idx)
2394 : 30 : if (i >= NUM_FIXED_BLOCKS
2395 : 10 : && idx == bb_to_omp_idx[bb->index]
2396 : 40 : && i != (unsigned) bb->index)
2397 : : {
2398 : 10 : new_bb = BASIC_BLOCK_FOR_FN (cfun, i);
2399 : 10 : break;
2400 : : }
2401 : 10 : if (new_bb == NULL)
2402 : : {
2403 : 0 : new_bb = single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun));
2404 : 0 : gcc_assert (new_bb != bb);
2405 : : }
2406 : : }
2407 : 429 : new_gsi = gsi_after_labels (new_bb);
2408 : 429 : gsi_remove (&i, false);
2409 : 429 : gsi_insert_before (&new_gsi, stmt, GSI_NEW_STMT);
2410 : : }
2411 : : else
2412 : : {
2413 : : /* Release SSA definitions. */
2414 : 15258737 : release_defs (stmt);
2415 : 15258737 : gsi_remove (&i, true);
2416 : : }
2417 : :
2418 : 15259166 : if (gsi_end_p (i))
2419 : 30518332 : i = gsi_last_bb (bb);
2420 : : else
2421 : 20975022 : gsi_prev (&i);
2422 : : }
2423 : : }
2424 : :
2425 : 32066623 : if ((unsigned) bb->index < bb_to_omp_idx.length ())
2426 : 22404 : bb_to_omp_idx[bb->index] = -1;
2427 : 32044219 : remove_phi_nodes_and_edges_for_unreachable_block (bb);
2428 : 32044219 : bb->il.gimple.seq = NULL;
2429 : 32044219 : bb->il.gimple.phi_nodes = NULL;
2430 : 32044219 : }
2431 : :
2432 : :
2433 : : /* Given a basic block BB and a value VAL for use in the final statement
2434 : : of the block (if a GIMPLE_COND, GIMPLE_SWITCH, or computed goto), return
2435 : : the edge that will be taken out of the block.
2436 : : If VAL is NULL_TREE, then the current value of the final statement's
2437 : : predicate or index is used.
2438 : : If the value does not match a unique edge, NULL is returned. */
2439 : :
2440 : : edge
2441 : 215328100 : find_taken_edge (basic_block bb, tree val)
2442 : : {
2443 : 215328100 : gimple *stmt;
2444 : :
2445 : 215328100 : stmt = *gsi_last_bb (bb);
2446 : :
2447 : : /* Handle ENTRY and EXIT. */
2448 : 215328100 : if (!stmt)
2449 : : ;
2450 : :
2451 : 212117099 : else if (gimple_code (stmt) == GIMPLE_COND)
2452 : 172467866 : return find_taken_edge_cond_expr (as_a <gcond *> (stmt), val);
2453 : :
2454 : 39649233 : else if (gimple_code (stmt) == GIMPLE_SWITCH)
2455 : 1021453 : return find_taken_edge_switch_expr (as_a <gswitch *> (stmt), val);
2456 : :
2457 : 38627780 : else if (computed_goto_p (stmt))
2458 : : {
2459 : : /* Only optimize if the argument is a label, if the argument is
2460 : : not a label then we cannot construct a proper CFG.
2461 : :
2462 : : It may be the case that we only need to allow the LABEL_REF to
2463 : : appear inside an ADDR_EXPR, but we also allow the LABEL_REF to
2464 : : appear inside a LABEL_EXPR just to be safe. */
2465 : 2805 : if (val
2466 : 1531 : && (TREE_CODE (val) == ADDR_EXPR || TREE_CODE (val) == LABEL_EXPR)
2467 : 3051 : && TREE_CODE (TREE_OPERAND (val, 0)) == LABEL_DECL)
2468 : 182 : return find_taken_edge_computed_goto (bb, TREE_OPERAND (val, 0));
2469 : : }
2470 : :
2471 : : /* Otherwise we only know the taken successor edge if it's unique. */
2472 : 41838599 : return single_succ_p (bb) ? single_succ_edge (bb) : NULL;
2473 : : }
2474 : :
2475 : : /* Given a constant value VAL and the entry block BB to a GOTO_EXPR
2476 : : statement, determine which of the outgoing edges will be taken out of the
2477 : : block. Return NULL if either edge may be taken. */
2478 : :
2479 : : static edge
2480 : 182 : find_taken_edge_computed_goto (basic_block bb, tree val)
2481 : : {
2482 : 182 : basic_block dest;
2483 : 182 : edge e = NULL;
2484 : :
2485 : 182 : dest = label_to_block (cfun, val);
2486 : 182 : if (dest)
2487 : 178 : e = find_edge (bb, dest);
2488 : :
2489 : : /* It's possible for find_edge to return NULL here on invalid code
2490 : : that abuses the labels-as-values extension (e.g. code that attempts to
2491 : : jump *between* functions via stored labels-as-values; PR 84136).
2492 : : If so, then we simply return that NULL for the edge.
2493 : : We don't currently have a way of detecting such invalid code, so we
2494 : : can't assert that it was the case when a NULL edge occurs here. */
2495 : :
2496 : 182 : return e;
2497 : : }
2498 : :
2499 : : /* Given COND_STMT and a constant value VAL for use as the predicate,
2500 : : determine which of the two edges will be taken out of
2501 : : the statement's block. Return NULL if either edge may be taken.
2502 : : If VAL is NULL_TREE, then the current value of COND_STMT's predicate
2503 : : is used. */
2504 : :
2505 : : static edge
2506 : 172467866 : find_taken_edge_cond_expr (const gcond *cond_stmt, tree val)
2507 : : {
2508 : 172467866 : edge true_edge, false_edge;
2509 : :
2510 : 172467866 : if (val == NULL_TREE)
2511 : : {
2512 : : /* Use the current value of the predicate. */
2513 : 160555983 : if (gimple_cond_true_p (cond_stmt))
2514 : 61478 : val = integer_one_node;
2515 : 160494505 : else if (gimple_cond_false_p (cond_stmt))
2516 : 149010 : val = integer_zero_node;
2517 : : else
2518 : : return NULL;
2519 : : }
2520 : 11911883 : else if (TREE_CODE (val) != INTEGER_CST)
2521 : : return NULL;
2522 : :
2523 : 10756691 : extract_true_false_edges_from_block (gimple_bb (cond_stmt),
2524 : : &true_edge, &false_edge);
2525 : :
2526 : 10756691 : return (integer_zerop (val) ? false_edge : true_edge);
2527 : : }
2528 : :
2529 : : /* Given SWITCH_STMT and an INTEGER_CST VAL for use as the index, determine
2530 : : which edge will be taken out of the statement's block. Return NULL if any
2531 : : edge may be taken.
2532 : : If VAL is NULL_TREE, then the current value of SWITCH_STMT's index
2533 : : is used. */
2534 : :
2535 : : edge
2536 : 1021458 : find_taken_edge_switch_expr (const gswitch *switch_stmt, tree val)
2537 : : {
2538 : 1021458 : basic_block dest_bb;
2539 : 1021458 : edge e;
2540 : 1021458 : tree taken_case;
2541 : :
2542 : 1021458 : if (gimple_switch_num_labels (switch_stmt) == 1)
2543 : 1 : taken_case = gimple_switch_default_label (switch_stmt);
2544 : : else
2545 : : {
2546 : 1021457 : if (val == NULL_TREE)
2547 : 140504 : val = gimple_switch_index (switch_stmt);
2548 : 1021457 : if (TREE_CODE (val) != INTEGER_CST)
2549 : : return NULL;
2550 : : else
2551 : 22331 : taken_case = find_case_label_for_value (switch_stmt, val);
2552 : : }
2553 : 22332 : dest_bb = label_to_block (cfun, CASE_LABEL (taken_case));
2554 : :
2555 : 22332 : e = find_edge (gimple_bb (switch_stmt), dest_bb);
2556 : 22332 : gcc_assert (e);
2557 : : return e;
2558 : : }
2559 : :
2560 : :
2561 : : /* Return the CASE_LABEL_EXPR that SWITCH_STMT will take for VAL.
2562 : : We can make optimal use here of the fact that the case labels are
2563 : : sorted: We can do a binary search for a case matching VAL. */
2564 : :
2565 : : tree
2566 : 22331 : find_case_label_for_value (const gswitch *switch_stmt, tree val)
2567 : : {
2568 : 22331 : size_t low, high, n = gimple_switch_num_labels (switch_stmt);
2569 : 22331 : tree default_case = gimple_switch_default_label (switch_stmt);
2570 : :
2571 : 45911 : for (low = 0, high = n; high - low > 1; )
2572 : : {
2573 : 43201 : size_t i = (high + low) / 2;
2574 : 43201 : tree t = gimple_switch_label (switch_stmt, i);
2575 : 43201 : int cmp;
2576 : :
2577 : : /* Cache the result of comparing CASE_LOW and val. */
2578 : 43201 : cmp = tree_int_cst_compare (CASE_LOW (t), val);
2579 : :
2580 : 43201 : if (cmp > 0)
2581 : : high = i;
2582 : : else
2583 : 31873 : low = i;
2584 : :
2585 : 43201 : if (CASE_HIGH (t) == NULL)
2586 : : {
2587 : : /* A singe-valued case label. */
2588 : 42180 : if (cmp == 0)
2589 : 19095 : return t;
2590 : : }
2591 : : else
2592 : : {
2593 : : /* A case range. We can only handle integer ranges. */
2594 : 1021 : if (cmp <= 0 && tree_int_cst_compare (CASE_HIGH (t), val) >= 0)
2595 : 526 : return t;
2596 : : }
2597 : : }
2598 : :
2599 : : return default_case;
2600 : : }
2601 : :
2602 : :
2603 : : /* Dump a basic block on stderr. */
2604 : :
2605 : : void
2606 : 0 : gimple_debug_bb (basic_block bb)
2607 : : {
2608 : 0 : dump_bb (stderr, bb, 0, TDF_VOPS|TDF_MEMSYMS|TDF_BLOCKS);
2609 : 0 : }
2610 : :
2611 : :
2612 : : /* Dump basic block with index N on stderr. */
2613 : :
2614 : : basic_block
2615 : 0 : gimple_debug_bb_n (int n)
2616 : : {
2617 : 0 : gimple_debug_bb (BASIC_BLOCK_FOR_FN (cfun, n));
2618 : 0 : return BASIC_BLOCK_FOR_FN (cfun, n);
2619 : : }
2620 : :
2621 : :
2622 : : /* Dump the CFG on stderr.
2623 : :
2624 : : FLAGS are the same used by the tree dumping functions
2625 : : (see TDF_* in dumpfile.h). */
2626 : :
2627 : : void
2628 : 0 : gimple_debug_cfg (dump_flags_t flags)
2629 : : {
2630 : 0 : gimple_dump_cfg (stderr, flags);
2631 : 0 : }
2632 : :
2633 : :
2634 : : /* Dump the program showing basic block boundaries on the given FILE.
2635 : :
2636 : : FLAGS are the same used by the tree dumping functions (see TDF_* in
2637 : : tree.h). */
2638 : :
2639 : : void
2640 : 118 : gimple_dump_cfg (FILE *file, dump_flags_t flags)
2641 : : {
2642 : 118 : if (flags & TDF_DETAILS)
2643 : : {
2644 : 2 : dump_function_header (file, current_function_decl, flags);
2645 : 2 : fprintf (file, ";; \n%d basic blocks, %d edges, last basic block %d.\n\n",
2646 : : n_basic_blocks_for_fn (cfun), n_edges_for_fn (cfun),
2647 : 2 : last_basic_block_for_fn (cfun));
2648 : :
2649 : 2 : brief_dump_cfg (file, flags);
2650 : 2 : fprintf (file, "\n");
2651 : : }
2652 : :
2653 : 118 : if (flags & TDF_STATS)
2654 : 9 : dump_cfg_stats (file);
2655 : :
2656 : 118 : dump_function_to_file (current_function_decl, file, flags | TDF_BLOCKS);
2657 : 118 : }
2658 : :
2659 : :
2660 : : /* Dump CFG statistics on FILE. */
2661 : :
2662 : : void
2663 : 9 : dump_cfg_stats (FILE *file)
2664 : : {
2665 : 9 : static long max_num_merged_labels = 0;
2666 : 9 : unsigned long size, total = 0;
2667 : 9 : long num_edges;
2668 : 9 : basic_block bb;
2669 : 9 : const char * const fmt_str = "%-30s%-13s%12s\n";
2670 : 9 : const char * const fmt_str_1 = "%-30s%13d" PRsa (11) "\n";
2671 : 9 : const char * const fmt_str_2 = "%-30s%13ld" PRsa (11) "\n";
2672 : 9 : const char * const fmt_str_3 = "%-43s" PRsa (11) "\n";
2673 : 9 : const char *funcname = current_function_name ();
2674 : :
2675 : 9 : fprintf (file, "\nCFG Statistics for %s\n\n", funcname);
2676 : :
2677 : 9 : fprintf (file, "---------------------------------------------------------\n");
2678 : 9 : fprintf (file, fmt_str, "", " Number of ", "Memory");
2679 : 9 : fprintf (file, fmt_str, "", " instances ", "used ");
2680 : 9 : fprintf (file, "---------------------------------------------------------\n");
2681 : :
2682 : 9 : size = n_basic_blocks_for_fn (cfun) * sizeof (struct basic_block_def);
2683 : 9 : total += size;
2684 : 9 : fprintf (file, fmt_str_1, "Basic blocks", n_basic_blocks_for_fn (cfun),
2685 : 0 : SIZE_AMOUNT (size));
2686 : :
2687 : 9 : num_edges = 0;
2688 : 20 : FOR_EACH_BB_FN (bb, cfun)
2689 : 22 : num_edges += EDGE_COUNT (bb->succs);
2690 : 9 : size = num_edges * sizeof (class edge_def);
2691 : 9 : total += size;
2692 : 9 : fprintf (file, fmt_str_2, "Edges", num_edges, SIZE_AMOUNT (size));
2693 : :
2694 : 9 : fprintf (file, "---------------------------------------------------------\n");
2695 : 9 : fprintf (file, fmt_str_3, "Total memory used by CFG data",
2696 : 0 : SIZE_AMOUNT (total));
2697 : 9 : fprintf (file, "---------------------------------------------------------\n");
2698 : 9 : fprintf (file, "\n");
2699 : :
2700 : 9 : if (cfg_stats.num_merged_labels > max_num_merged_labels)
2701 : 0 : max_num_merged_labels = cfg_stats.num_merged_labels;
2702 : :
2703 : 9 : fprintf (file, "Coalesced label blocks: %ld (Max so far: %ld)\n",
2704 : : cfg_stats.num_merged_labels, max_num_merged_labels);
2705 : :
2706 : 9 : fprintf (file, "\n");
2707 : 9 : }
2708 : :
2709 : :
2710 : : /* Dump CFG statistics on stderr. Keep extern so that it's always
2711 : : linked in the final executable. */
2712 : :
2713 : : DEBUG_FUNCTION void
2714 : 0 : debug_cfg_stats (void)
2715 : : {
2716 : 0 : dump_cfg_stats (stderr);
2717 : 0 : }
2718 : :
2719 : : /*---------------------------------------------------------------------------
2720 : : Miscellaneous helpers
2721 : : ---------------------------------------------------------------------------*/
2722 : :
2723 : : /* Return true if T, a GIMPLE_CALL, can make an abnormal transfer of control
2724 : : flow. Transfers of control flow associated with EH are excluded. */
2725 : :
2726 : : static bool
2727 : 125568035 : call_can_make_abnormal_goto (gimple *t)
2728 : : {
2729 : : /* If the function has no non-local labels, then a call cannot make an
2730 : : abnormal transfer of control. */
2731 : 125568035 : if (!cfun->has_nonlocal_label
2732 : 125568035 : && !cfun->calls_setjmp)
2733 : : return false;
2734 : :
2735 : : /* Likewise if the call has no side effects. */
2736 : 207568 : if (!gimple_has_side_effects (t))
2737 : : return false;
2738 : :
2739 : : /* Likewise if the called function is leaf. */
2740 : 201146 : if (gimple_call_flags (t) & ECF_LEAF)
2741 : : return false;
2742 : :
2743 : : return true;
2744 : : }
2745 : :
2746 : :
2747 : : /* Return true if T can make an abnormal transfer of control flow.
2748 : : Transfers of control flow associated with EH are excluded. */
2749 : :
2750 : : bool
2751 : 494606071 : stmt_can_make_abnormal_goto (gimple *t)
2752 : : {
2753 : 494606071 : if (computed_goto_p (t))
2754 : : return true;
2755 : 494602178 : if (is_gimple_call (t))
2756 : 115620300 : return call_can_make_abnormal_goto (t);
2757 : : return false;
2758 : : }
2759 : :
2760 : :
2761 : : /* Return true if T represents a stmt that always transfers control. */
2762 : :
2763 : : bool
2764 : 14164492243 : is_ctrl_stmt (gimple *t)
2765 : : {
2766 : 14164492243 : switch (gimple_code (t))
2767 : : {
2768 : : case GIMPLE_COND:
2769 : : case GIMPLE_SWITCH:
2770 : : case GIMPLE_GOTO:
2771 : : case GIMPLE_RETURN:
2772 : : case GIMPLE_RESX:
2773 : : return true;
2774 : 12210006635 : default:
2775 : 12210006635 : return false;
2776 : : }
2777 : : }
2778 : :
2779 : :
2780 : : /* Return true if T is a statement that may alter the flow of control
2781 : : (e.g., a call to a non-returning function). */
2782 : :
2783 : : bool
2784 : 11654685682 : is_ctrl_altering_stmt (gimple *t)
2785 : : {
2786 : 11654685682 : gcc_assert (t);
2787 : :
2788 : 11654685682 : switch (gimple_code (t))
2789 : : {
2790 : 1002107447 : case GIMPLE_CALL:
2791 : : /* Per stmt call flag indicates whether the call could alter
2792 : : controlflow. */
2793 : 1002107447 : if (gimple_call_ctrl_altering_p (t))
2794 : : return true;
2795 : : break;
2796 : :
2797 : : case GIMPLE_EH_DISPATCH:
2798 : : /* EH_DISPATCH branches to the individual catch handlers at
2799 : : this level of a try or allowed-exceptions region. It can
2800 : : fallthru to the next statement as well. */
2801 : : return true;
2802 : :
2803 : 15252240 : case GIMPLE_ASM:
2804 : 15252240 : if (gimple_asm_nlabels (as_a <gasm *> (t)) > 0)
2805 : : return true;
2806 : : break;
2807 : :
2808 : : CASE_GIMPLE_OMP:
2809 : : /* OpenMP directives alter control flow. */
2810 : : return true;
2811 : :
2812 : : case GIMPLE_TRANSACTION:
2813 : : /* A transaction start alters control flow. */
2814 : : return true;
2815 : :
2816 : : default:
2817 : : break;
2818 : : }
2819 : :
2820 : : /* If a statement can throw, it alters control flow. */
2821 : 11511222357 : return stmt_can_throw_internal (cfun, t);
2822 : : }
2823 : :
2824 : :
2825 : : /* Return true if T is a simple local goto. */
2826 : :
2827 : : bool
2828 : 5573059 : simple_goto_p (gimple *t)
2829 : : {
2830 : 5573059 : return (gimple_code (t) == GIMPLE_GOTO
2831 : 5573059 : && TREE_CODE (gimple_goto_dest (t)) == LABEL_DECL);
2832 : : }
2833 : :
2834 : :
2835 : : /* Return true if STMT should start a new basic block. PREV_STMT is
2836 : : the statement preceding STMT. It is used when STMT is a label or a
2837 : : case label. Labels should only start a new basic block if their
2838 : : previous statement wasn't a label. Otherwise, sequence of labels
2839 : : would generate unnecessary basic blocks that only contain a single
2840 : : label. */
2841 : :
2842 : : static inline bool
2843 : 65981767 : stmt_starts_bb_p (gimple *stmt, gimple *prev_stmt)
2844 : : {
2845 : 65981767 : if (stmt == NULL)
2846 : : return false;
2847 : :
2848 : : /* PREV_STMT is only set to a debug stmt if the debug stmt is before
2849 : : any nondebug stmts in the block. We don't want to start another
2850 : : block in this case: the debug stmt will already have started the
2851 : : one STMT would start if we weren't outputting debug stmts. */
2852 : 65981767 : if (prev_stmt && is_gimple_debug (prev_stmt))
2853 : : return false;
2854 : :
2855 : : /* Labels start a new basic block only if the preceding statement
2856 : : wasn't a label of the same type. This prevents the creation of
2857 : : consecutive blocks that have nothing but a single label. */
2858 : 65500235 : if (glabel *label_stmt = dyn_cast <glabel *> (stmt))
2859 : : {
2860 : : /* Nonlocal and computed GOTO targets always start a new block. */
2861 : 3771133 : if (DECL_NONLOCAL (gimple_label_label (label_stmt))
2862 : 3771133 : || FORCED_LABEL (gimple_label_label (label_stmt)))
2863 : : return true;
2864 : :
2865 : 5500608 : if (glabel *plabel = safe_dyn_cast <glabel *> (prev_stmt))
2866 : : {
2867 : 2040363 : if (DECL_NONLOCAL (gimple_label_label (plabel))
2868 : 2040363 : || !DECL_ARTIFICIAL (gimple_label_label (plabel)))
2869 : : return true;
2870 : :
2871 : 2029871 : cfg_stats.num_merged_labels++;
2872 : 2029871 : return false;
2873 : : }
2874 : : else
2875 : : return true;
2876 : : }
2877 : 61729102 : else if (gimple_code (stmt) == GIMPLE_CALL)
2878 : : {
2879 : 8439159 : if (gimple_call_flags (stmt) & ECF_RETURNS_TWICE)
2880 : : /* setjmp acts similar to a nonlocal GOTO target and thus should
2881 : : start a new block. */
2882 : : return true;
2883 : 8438135 : if (gimple_call_internal_p (stmt, IFN_PHI)
2884 : 0 : && prev_stmt
2885 : 0 : && gimple_code (prev_stmt) != GIMPLE_LABEL
2886 : 8438135 : && (gimple_code (prev_stmt) != GIMPLE_CALL
2887 : 0 : || ! gimple_call_internal_p (prev_stmt, IFN_PHI)))
2888 : : /* PHI nodes start a new block unless preceeded by a label
2889 : : or another PHI. */
2890 : : return true;
2891 : : }
2892 : :
2893 : : return false;
2894 : : }
2895 : :
2896 : :
2897 : : /* Return true if T should end a basic block. */
2898 : :
2899 : : bool
2900 : 12497394192 : stmt_ends_bb_p (gimple *t)
2901 : : {
2902 : 12497394192 : return is_ctrl_stmt (t) || is_ctrl_altering_stmt (t);
2903 : : }
2904 : :
2905 : : /* Remove block annotations and other data structures. */
2906 : :
2907 : : void
2908 : 2929286 : delete_tree_cfg_annotations (struct function *fn)
2909 : : {
2910 : 2929286 : vec_free (label_to_block_map_for_fn (fn));
2911 : 2929286 : }
2912 : :
2913 : : /* Return the virtual phi in BB. */
2914 : :
2915 : : gphi *
2916 : 2477134898 : get_virtual_phi (basic_block bb)
2917 : : {
2918 : 2477134898 : for (gphi_iterator gsi = gsi_start_phis (bb);
2919 : 3034975985 : !gsi_end_p (gsi);
2920 : 557841087 : gsi_next (&gsi))
2921 : : {
2922 : 1319168550 : gphi *phi = gsi.phi ();
2923 : :
2924 : 2638337100 : if (virtual_operand_p (PHI_RESULT (phi)))
2925 : 761327463 : return phi;
2926 : : }
2927 : :
2928 : 1715807435 : return NULL;
2929 : : }
2930 : :
2931 : : /* Return the first statement in basic block BB. */
2932 : :
2933 : : gimple *
2934 : 40200253 : first_stmt (basic_block bb)
2935 : : {
2936 : 40200253 : gimple_stmt_iterator i = gsi_start_bb (bb);
2937 : 40200253 : gimple *stmt = NULL;
2938 : :
2939 : 115040292 : while (!gsi_end_p (i) && is_gimple_debug ((stmt = gsi_stmt (i))))
2940 : : {
2941 : 74840039 : gsi_next (&i);
2942 : 74840039 : stmt = NULL;
2943 : : }
2944 : 40200253 : return stmt;
2945 : : }
2946 : :
2947 : : /* Return the first non-label statement in basic block BB. */
2948 : :
2949 : : static gimple *
2950 : 24611614 : first_non_label_stmt (basic_block bb)
2951 : : {
2952 : 24611614 : gimple_stmt_iterator i = gsi_start_bb (bb);
2953 : 44379362 : while (!gsi_end_p (i) && gimple_code (gsi_stmt (i)) == GIMPLE_LABEL)
2954 : 19767748 : gsi_next (&i);
2955 : 24611614 : return !gsi_end_p (i) ? gsi_stmt (i) : NULL;
2956 : : }
2957 : :
2958 : : /* Return the last statement in basic block BB. */
2959 : :
2960 : : gimple *
2961 : 193075155 : last_nondebug_stmt (basic_block bb)
2962 : : {
2963 : 193075155 : gimple_stmt_iterator i = gsi_last_bb (bb);
2964 : : gimple *stmt = NULL;
2965 : :
2966 : 204226797 : while (!gsi_end_p (i) && is_gimple_debug ((stmt = gsi_stmt (i))))
2967 : : {
2968 : 265248637 : gsi_prev (&i);
2969 : : stmt = NULL;
2970 : : }
2971 : 193075155 : return stmt;
2972 : : }
2973 : :
2974 : : /* Return the last statement of an otherwise empty block. Return NULL
2975 : : if the block is totally empty, or if it contains more than one
2976 : : statement. */
2977 : :
2978 : : gimple *
2979 : 8901714 : last_and_only_stmt (basic_block bb)
2980 : : {
2981 : 8901714 : gimple_stmt_iterator i = gsi_last_nondebug_bb (bb);
2982 : 8901714 : gimple *last, *prev;
2983 : :
2984 : 8901714 : if (gsi_end_p (i))
2985 : : return NULL;
2986 : :
2987 : 8182811 : last = gsi_stmt (i);
2988 : 8182811 : gsi_prev_nondebug (&i);
2989 : 8182811 : if (gsi_end_p (i))
2990 : : return last;
2991 : :
2992 : : /* Empty statements should no longer appear in the instruction stream.
2993 : : Everything that might have appeared before should be deleted by
2994 : : remove_useless_stmts, and the optimizers should just gsi_remove
2995 : : instead of smashing with build_empty_stmt.
2996 : :
2997 : : Thus the only thing that should appear here in a block containing
2998 : : one executable statement is a label. */
2999 : 6730256 : prev = gsi_stmt (i);
3000 : 6730256 : if (gimple_code (prev) == GIMPLE_LABEL)
3001 : : return last;
3002 : : else
3003 : : return NULL;
3004 : : }
3005 : :
3006 : : /* Returns the basic block after which the new basic block created
3007 : : by splitting edge EDGE_IN should be placed. Tries to keep the new block
3008 : : near its "logical" location. This is of most help to humans looking
3009 : : at debugging dumps. */
3010 : :
3011 : : basic_block
3012 : 23780761 : split_edge_bb_loc (edge edge_in)
3013 : : {
3014 : 23780761 : basic_block dest = edge_in->dest;
3015 : 23780761 : basic_block dest_prev = dest->prev_bb;
3016 : :
3017 : 23780761 : if (dest_prev)
3018 : : {
3019 : 23780761 : edge e = find_edge (dest_prev, dest);
3020 : 23780761 : if (e && !(e->flags & EDGE_COMPLEX))
3021 : 20089675 : return edge_in->src;
3022 : : }
3023 : : return dest_prev;
3024 : : }
3025 : :
3026 : : /* Split a (typically critical) edge EDGE_IN. Return the new block.
3027 : : Abort on abnormal edges. */
3028 : :
3029 : : static basic_block
3030 : 22341096 : gimple_split_edge (edge edge_in)
3031 : : {
3032 : 22341096 : basic_block new_bb, after_bb, dest;
3033 : 22341096 : edge new_edge, e;
3034 : :
3035 : : /* Abnormal edges cannot be split. */
3036 : 22341096 : gcc_assert (!(edge_in->flags & EDGE_ABNORMAL));
3037 : :
3038 : 22341096 : dest = edge_in->dest;
3039 : :
3040 : 22341096 : after_bb = split_edge_bb_loc (edge_in);
3041 : :
3042 : 22341096 : new_bb = create_empty_bb (after_bb);
3043 : 22341096 : new_bb->count = edge_in->count ();
3044 : :
3045 : : /* We want to avoid re-allocating PHIs when we first
3046 : : add the fallthru edge from new_bb to dest but we also
3047 : : want to avoid changing PHI argument order when
3048 : : first redirecting edge_in away from dest. The former
3049 : : avoids changing PHI argument order by adding them
3050 : : last and then the redirection swapping it back into
3051 : : place by means of unordered remove.
3052 : : So hack around things by temporarily removing all PHIs
3053 : : from the destination during the edge redirection and then
3054 : : making sure the edges stay in order. */
3055 : 22341096 : gimple_seq saved_phis = phi_nodes (dest);
3056 : 22341096 : unsigned old_dest_idx = edge_in->dest_idx;
3057 : 22341096 : set_phi_nodes (dest, NULL);
3058 : 22341096 : new_edge = make_single_succ_edge (new_bb, dest, EDGE_FALLTHRU);
3059 : 22341096 : e = redirect_edge_and_branch (edge_in, new_bb);
3060 : 22341096 : gcc_assert (e == edge_in && new_edge->dest_idx == old_dest_idx);
3061 : : /* set_phi_nodes sets the BB of the PHI nodes, so do it manually here. */
3062 : 22341096 : dest->il.gimple.phi_nodes = saved_phis;
3063 : :
3064 : 22341096 : return new_bb;
3065 : : }
3066 : :
3067 : :
3068 : : /* Verify properties of the address expression T whose base should be
3069 : : TREE_ADDRESSABLE if VERIFY_ADDRESSABLE is true. */
3070 : :
3071 : : static bool
3072 : 519488536 : verify_address (tree t, bool verify_addressable)
3073 : : {
3074 : 519488536 : bool old_constant;
3075 : 519488536 : bool old_side_effects;
3076 : 519488536 : bool new_constant;
3077 : 519488536 : bool new_side_effects;
3078 : :
3079 : 519488536 : old_constant = TREE_CONSTANT (t);
3080 : 519488536 : old_side_effects = TREE_SIDE_EFFECTS (t);
3081 : :
3082 : 519488536 : recompute_tree_invariant_for_addr_expr (t);
3083 : 519488536 : new_side_effects = TREE_SIDE_EFFECTS (t);
3084 : 519488536 : new_constant = TREE_CONSTANT (t);
3085 : :
3086 : 519488536 : if (old_constant != new_constant)
3087 : : {
3088 : 0 : error ("constant not recomputed when %<ADDR_EXPR%> changed");
3089 : 0 : return true;
3090 : : }
3091 : 519488536 : if (old_side_effects != new_side_effects)
3092 : : {
3093 : 0 : error ("side effects not recomputed when %<ADDR_EXPR%> changed");
3094 : 0 : return true;
3095 : : }
3096 : :
3097 : 519488536 : tree base = TREE_OPERAND (t, 0);
3098 : 652368904 : while (handled_component_p (base))
3099 : 132880368 : base = TREE_OPERAND (base, 0);
3100 : :
3101 : 519488536 : if (!(VAR_P (base)
3102 : : || TREE_CODE (base) == PARM_DECL
3103 : : || TREE_CODE (base) == RESULT_DECL))
3104 : : return false;
3105 : :
3106 : 368887105 : if (verify_addressable && !TREE_ADDRESSABLE (base))
3107 : : {
3108 : 0 : error ("address taken but %<TREE_ADDRESSABLE%> bit not set");
3109 : 0 : return true;
3110 : : }
3111 : :
3112 : : return false;
3113 : : }
3114 : :
3115 : :
3116 : : /* Verify if EXPR is a valid GIMPLE reference expression. If
3117 : : REQUIRE_LVALUE is true verifies it is an lvalue. Returns true
3118 : : if there is an error, otherwise false. */
3119 : :
3120 : : static bool
3121 : 3372679050 : verify_types_in_gimple_reference (tree expr, bool require_lvalue)
3122 : : {
3123 : 3372679050 : const char *code_name = get_tree_code_name (TREE_CODE (expr));
3124 : :
3125 : 3372679050 : if (TREE_CODE (expr) == REALPART_EXPR
3126 : 3372679050 : || TREE_CODE (expr) == IMAGPART_EXPR
3127 : 3340537744 : || TREE_CODE (expr) == BIT_FIELD_REF
3128 : 3329241652 : || TREE_CODE (expr) == VIEW_CONVERT_EXPR)
3129 : : {
3130 : 85066977 : tree op = TREE_OPERAND (expr, 0);
3131 : 85066977 : if (TREE_CODE (expr) != VIEW_CONVERT_EXPR
3132 : 85066977 : && !is_gimple_reg_type (TREE_TYPE (expr)))
3133 : : {
3134 : 0 : error ("non-scalar %qs", code_name);
3135 : 0 : return true;
3136 : : }
3137 : :
3138 : 85066977 : if (TREE_CODE (expr) == BIT_FIELD_REF)
3139 : : {
3140 : 11296092 : tree t1 = TREE_OPERAND (expr, 1);
3141 : 11296092 : tree t2 = TREE_OPERAND (expr, 2);
3142 : 11296092 : poly_uint64 size, bitpos;
3143 : 11296092 : if (!poly_int_tree_p (t1, &size)
3144 : 11296092 : || !poly_int_tree_p (t2, &bitpos)
3145 : 11296092 : || !types_compatible_p (bitsizetype, TREE_TYPE (t1))
3146 : 22592184 : || !types_compatible_p (bitsizetype, TREE_TYPE (t2)))
3147 : : {
3148 : 0 : error ("invalid position or size operand to %qs", code_name);
3149 : 0 : return true;
3150 : : }
3151 : 22554166 : if (INTEGRAL_TYPE_P (TREE_TYPE (expr))
3152 : 20772967 : && maybe_ne (TYPE_PRECISION (TREE_TYPE (expr)), size))
3153 : : {
3154 : 0 : error ("integral result type precision does not match "
3155 : : "field size of %qs", code_name);
3156 : 0 : return true;
3157 : : }
3158 : 11296092 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
3159 : 1781199 : && TYPE_MODE (TREE_TYPE (expr)) != BLKmode
3160 : 3562140 : && maybe_ne (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr))),
3161 : : size))
3162 : : {
3163 : 0 : error ("mode size of non-integral result does not "
3164 : : "match field size of %qs",
3165 : : code_name);
3166 : 0 : return true;
3167 : : }
3168 : 22591486 : if (INTEGRAL_TYPE_P (TREE_TYPE (op))
3169 : 11509008 : && !type_has_mode_precision_p (TREE_TYPE (op)))
3170 : : {
3171 : 0 : error ("%qs of non-mode-precision operand", code_name);
3172 : 0 : return true;
3173 : : }
3174 : 11296092 : if (!AGGREGATE_TYPE_P (TREE_TYPE (op))
3175 : 11296092 : && maybe_gt (size + bitpos,
3176 : : tree_to_poly_uint64 (TYPE_SIZE (TREE_TYPE (op)))))
3177 : : {
3178 : 0 : error ("position plus size exceeds size of referenced object in "
3179 : : "%qs", code_name);
3180 : 0 : return true;
3181 : : }
3182 : : }
3183 : :
3184 : 85066977 : if ((TREE_CODE (expr) == REALPART_EXPR
3185 : 85066977 : || TREE_CODE (expr) == IMAGPART_EXPR)
3186 : 117208283 : && !useless_type_conversion_p (TREE_TYPE (expr),
3187 : 32141306 : TREE_TYPE (TREE_TYPE (op))))
3188 : : {
3189 : 0 : error ("type mismatch in %qs reference", code_name);
3190 : 0 : debug_generic_stmt (TREE_TYPE (expr));
3191 : 0 : debug_generic_stmt (TREE_TYPE (TREE_TYPE (op)));
3192 : 0 : return true;
3193 : : }
3194 : :
3195 : 85066977 : if (TREE_CODE (expr) == VIEW_CONVERT_EXPR)
3196 : : {
3197 : : /* For VIEW_CONVERT_EXPRs which are allowed here too, we only check
3198 : : that their operand is not a register an invariant when
3199 : : requiring an lvalue (this usually means there is a SRA or IPA-SRA
3200 : : bug). Otherwise there is nothing to verify, gross mismatches at
3201 : : most invoke undefined behavior. */
3202 : 41629579 : if (require_lvalue
3203 : 41629579 : && (is_gimple_reg (op) || is_gimple_min_invariant (op)))
3204 : : {
3205 : 0 : error ("conversion of %qs on the left hand side of %qs",
3206 : 0 : get_tree_code_name (TREE_CODE (op)), code_name);
3207 : 0 : debug_generic_stmt (expr);
3208 : 0 : return true;
3209 : : }
3210 : 41629579 : else if (is_gimple_reg (op)
3211 : 41629579 : && TYPE_SIZE (TREE_TYPE (expr)) != TYPE_SIZE (TREE_TYPE (op)))
3212 : : {
3213 : 0 : error ("conversion of register to a different size in %qs",
3214 : : code_name);
3215 : 0 : debug_generic_stmt (expr);
3216 : 0 : return true;
3217 : : }
3218 : : }
3219 : :
3220 : : expr = op;
3221 : : }
3222 : :
3223 : : bool require_non_reg = false;
3224 : 5549184812 : while (handled_component_p (expr))
3225 : : {
3226 : 2176505762 : require_non_reg = true;
3227 : 2176505762 : code_name = get_tree_code_name (TREE_CODE (expr));
3228 : :
3229 : 2176505762 : if (TREE_CODE (expr) == REALPART_EXPR
3230 : 2176505762 : || TREE_CODE (expr) == IMAGPART_EXPR
3231 : 2176505762 : || TREE_CODE (expr) == BIT_FIELD_REF)
3232 : : {
3233 : 0 : error ("non-top-level %qs", code_name);
3234 : 0 : return true;
3235 : : }
3236 : :
3237 : 2176505762 : tree op = TREE_OPERAND (expr, 0);
3238 : :
3239 : 2176505762 : if (TREE_CODE (expr) == ARRAY_REF
3240 : 2176505762 : || TREE_CODE (expr) == ARRAY_RANGE_REF)
3241 : : {
3242 : 395484120 : if (!is_gimple_val (TREE_OPERAND (expr, 1))
3243 : 395484120 : || (TREE_OPERAND (expr, 2)
3244 : 2846815 : && !is_gimple_val (TREE_OPERAND (expr, 2)))
3245 : 790968240 : || (TREE_OPERAND (expr, 3)
3246 : 689871 : && !is_gimple_val (TREE_OPERAND (expr, 3))))
3247 : : {
3248 : 0 : error ("invalid operands to %qs", code_name);
3249 : 0 : debug_generic_stmt (expr);
3250 : 0 : return true;
3251 : : }
3252 : : }
3253 : :
3254 : : /* Verify if the reference array element types are compatible. */
3255 : 2176505762 : if (TREE_CODE (expr) == ARRAY_REF
3256 : 2571762063 : && !useless_type_conversion_p (TREE_TYPE (expr),
3257 : 395256301 : TREE_TYPE (TREE_TYPE (op))))
3258 : : {
3259 : 0 : error ("type mismatch in %qs", code_name);
3260 : 0 : debug_generic_stmt (TREE_TYPE (expr));
3261 : 0 : debug_generic_stmt (TREE_TYPE (TREE_TYPE (op)));
3262 : 0 : return true;
3263 : : }
3264 : 2176505762 : if (TREE_CODE (expr) == ARRAY_RANGE_REF
3265 : 2176733581 : && !useless_type_conversion_p (TREE_TYPE (TREE_TYPE (expr)),
3266 : 227819 : TREE_TYPE (TREE_TYPE (op))))
3267 : : {
3268 : 0 : error ("type mismatch in %qs", code_name);
3269 : 0 : debug_generic_stmt (TREE_TYPE (TREE_TYPE (expr)));
3270 : 0 : debug_generic_stmt (TREE_TYPE (TREE_TYPE (op)));
3271 : 0 : return true;
3272 : : }
3273 : :
3274 : 2176505762 : if (TREE_CODE (expr) == COMPONENT_REF)
3275 : : {
3276 : 1778749544 : if (TREE_OPERAND (expr, 2)
3277 : 1778749544 : && !is_gimple_val (TREE_OPERAND (expr, 2)))
3278 : : {
3279 : 0 : error ("invalid %qs offset operator", code_name);
3280 : 0 : return true;
3281 : : }
3282 : 1778749544 : if (!useless_type_conversion_p (TREE_TYPE (expr),
3283 : 1778749544 : TREE_TYPE (TREE_OPERAND (expr, 1))))
3284 : : {
3285 : 0 : error ("type mismatch in %qs", code_name);
3286 : 0 : debug_generic_stmt (TREE_TYPE (expr));
3287 : 0 : debug_generic_stmt (TREE_TYPE (TREE_OPERAND (expr, 1)));
3288 : 0 : return true;
3289 : : }
3290 : : }
3291 : :
3292 : : expr = op;
3293 : : }
3294 : :
3295 : 3372679050 : code_name = get_tree_code_name (TREE_CODE (expr));
3296 : :
3297 : 3372679050 : if (TREE_CODE (expr) == MEM_REF)
3298 : : {
3299 : 1116507720 : if (!is_gimple_mem_ref_addr (TREE_OPERAND (expr, 0))
3300 : 1116507720 : || (TREE_CODE (TREE_OPERAND (expr, 0)) == ADDR_EXPR
3301 : 275716995 : && verify_address (TREE_OPERAND (expr, 0), false)))
3302 : : {
3303 : 0 : error ("invalid address operand in %qs", code_name);
3304 : 0 : debug_generic_stmt (expr);
3305 : 0 : return true;
3306 : : }
3307 : 1116507720 : if (!poly_int_tree_p (TREE_OPERAND (expr, 1))
3308 : 1116507720 : || !POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (expr, 1))))
3309 : : {
3310 : 0 : error ("invalid offset operand in %qs", code_name);
3311 : 0 : debug_generic_stmt (expr);
3312 : 0 : return true;
3313 : : }
3314 : 1116507720 : if (MR_DEPENDENCE_CLIQUE (expr) != 0
3315 : 1116507720 : && MR_DEPENDENCE_CLIQUE (expr) > cfun->last_clique)
3316 : : {
3317 : 0 : error ("invalid clique in %qs", code_name);
3318 : 0 : debug_generic_stmt (expr);
3319 : 0 : return true;
3320 : : }
3321 : : }
3322 : 2256171330 : else if (TREE_CODE (expr) == TARGET_MEM_REF)
3323 : : {
3324 : 26439259 : if (!TMR_BASE (expr)
3325 : 26439259 : || !is_gimple_mem_ref_addr (TMR_BASE (expr))
3326 : 52878518 : || (TREE_CODE (TMR_BASE (expr)) == ADDR_EXPR
3327 : 6518153 : && verify_address (TMR_BASE (expr), false)))
3328 : : {
3329 : 0 : error ("invalid address operand in %qs", code_name);
3330 : 0 : return true;
3331 : : }
3332 : 26439259 : if (!TMR_OFFSET (expr)
3333 : 26439259 : || !poly_int_tree_p (TMR_OFFSET (expr))
3334 : 52878518 : || !POINTER_TYPE_P (TREE_TYPE (TMR_OFFSET (expr))))
3335 : : {
3336 : 0 : error ("invalid offset operand in %qs", code_name);
3337 : 0 : debug_generic_stmt (expr);
3338 : 0 : return true;
3339 : : }
3340 : 26439259 : if (MR_DEPENDENCE_CLIQUE (expr) != 0
3341 : 26439259 : && MR_DEPENDENCE_CLIQUE (expr) > cfun->last_clique)
3342 : : {
3343 : 0 : error ("invalid clique in %qs", code_name);
3344 : 0 : debug_generic_stmt (expr);
3345 : 0 : return true;
3346 : : }
3347 : : }
3348 : 2229732071 : else if (INDIRECT_REF_P (expr))
3349 : : {
3350 : 0 : error ("%qs in gimple IL", code_name);
3351 : 0 : debug_generic_stmt (expr);
3352 : 0 : return true;
3353 : : }
3354 : 2229732071 : else if (require_non_reg
3355 : 2229732071 : && (is_gimple_reg (expr)
3356 : 869651793 : || (is_gimple_min_invariant (expr)
3357 : : /* STRING_CSTs are representatives of the string table
3358 : : entry which lives in memory. */
3359 : 8414256 : && TREE_CODE (expr) != STRING_CST)))
3360 : : {
3361 : 0 : error ("%qs as base where non-register is required", code_name);
3362 : 0 : debug_generic_stmt (expr);
3363 : 0 : return true;
3364 : : }
3365 : :
3366 : 3372679050 : if (!require_lvalue
3367 : 3372679050 : && (is_gimple_reg (expr) || is_gimple_min_invariant (expr)))
3368 : 1060205390 : return false;
3369 : :
3370 : 2312473660 : if (TREE_CODE (expr) != SSA_NAME && is_gimple_id (expr))
3371 : : return false;
3372 : :
3373 : 1142946979 : if (TREE_CODE (expr) != TARGET_MEM_REF
3374 : 1142946979 : && TREE_CODE (expr) != MEM_REF)
3375 : : {
3376 : 0 : error ("invalid expression for min lvalue");
3377 : 0 : return true;
3378 : : }
3379 : :
3380 : : return false;
3381 : : }
3382 : :
3383 : : /* Returns true if there is one pointer type in TYPE_POINTER_TO (SRC_OBJ)
3384 : : list of pointer-to types that is trivially convertible to DEST. */
3385 : :
3386 : : static bool
3387 : 94 : one_pointer_to_useless_type_conversion_p (tree dest, tree src_obj)
3388 : : {
3389 : 94 : tree src;
3390 : :
3391 : 94 : if (!TYPE_POINTER_TO (src_obj))
3392 : : return true;
3393 : :
3394 : 94 : for (src = TYPE_POINTER_TO (src_obj); src; src = TYPE_NEXT_PTR_TO (src))
3395 : 94 : if (useless_type_conversion_p (dest, src))
3396 : : return true;
3397 : :
3398 : : return false;
3399 : : }
3400 : :
3401 : : /* Return true if TYPE1 is a fixed-point type and if conversions to and
3402 : : from TYPE2 can be handled by FIXED_CONVERT_EXPR. */
3403 : :
3404 : : static bool
3405 : 0 : valid_fixed_convert_types_p (tree type1, tree type2)
3406 : : {
3407 : 0 : return (FIXED_POINT_TYPE_P (type1)
3408 : 0 : && (INTEGRAL_TYPE_P (type2)
3409 : 0 : || SCALAR_FLOAT_TYPE_P (type2)
3410 : 0 : || FIXED_POINT_TYPE_P (type2)));
3411 : : }
3412 : :
3413 : : /* Verify the contents of a GIMPLE_CALL STMT. Returns true when there
3414 : : is a problem, otherwise false. */
3415 : :
3416 : : static bool
3417 : 963151006 : verify_gimple_call (gcall *stmt)
3418 : : {
3419 : 963151006 : tree fn = gimple_call_fn (stmt);
3420 : 963151006 : tree fntype, fndecl;
3421 : 963151006 : unsigned i;
3422 : :
3423 : 963151006 : if (gimple_call_internal_p (stmt))
3424 : : {
3425 : 28303425 : if (fn)
3426 : : {
3427 : 0 : error ("gimple call has two targets");
3428 : 0 : debug_generic_stmt (fn);
3429 : 0 : return true;
3430 : : }
3431 : : }
3432 : : else
3433 : : {
3434 : 934847581 : if (!fn)
3435 : : {
3436 : 0 : error ("gimple call has no target");
3437 : 0 : return true;
3438 : : }
3439 : : }
3440 : :
3441 : 934847581 : if (fn && !is_gimple_call_addr (fn))
3442 : : {
3443 : 0 : error ("invalid function in gimple call");
3444 : 0 : debug_generic_stmt (fn);
3445 : 0 : return true;
3446 : : }
3447 : :
3448 : 963151006 : if (fn
3449 : 963151006 : && (!POINTER_TYPE_P (TREE_TYPE (fn))
3450 : 934847581 : || (TREE_CODE (TREE_TYPE (TREE_TYPE (fn))) != FUNCTION_TYPE
3451 : 150750520 : && TREE_CODE (TREE_TYPE (TREE_TYPE (fn))) != METHOD_TYPE)))
3452 : : {
3453 : 0 : error ("non-function in gimple call");
3454 : 0 : return true;
3455 : : }
3456 : :
3457 : 963151006 : fndecl = gimple_call_fndecl (stmt);
3458 : 963151006 : if (fndecl
3459 : 909485675 : && TREE_CODE (fndecl) == FUNCTION_DECL
3460 : 909485675 : && DECL_LOOPING_CONST_OR_PURE_P (fndecl)
3461 : 5667731 : && !DECL_PURE_P (fndecl)
3462 : 963552297 : && !TREE_READONLY (fndecl))
3463 : : {
3464 : 0 : error ("invalid pure const state for function");
3465 : 0 : return true;
3466 : : }
3467 : :
3468 : 963151006 : tree lhs = gimple_call_lhs (stmt);
3469 : 963151006 : if (lhs
3470 : 963151006 : && (!is_gimple_reg (lhs)
3471 : 60967594 : && (!is_gimple_lvalue (lhs)
3472 : 60967594 : || verify_types_in_gimple_reference
3473 : 60967594 : (TREE_CODE (lhs) == WITH_SIZE_EXPR
3474 : 0 : ? TREE_OPERAND (lhs, 0) : lhs, true))))
3475 : : {
3476 : 0 : error ("invalid LHS in gimple call");
3477 : 0 : return true;
3478 : : }
3479 : :
3480 : 963151006 : if (gimple_call_ctrl_altering_p (stmt)
3481 : 123388330 : && gimple_call_noreturn_p (stmt)
3482 : 1082099078 : && should_remove_lhs_p (lhs))
3483 : : {
3484 : 0 : error ("LHS in %<noreturn%> call");
3485 : 0 : return true;
3486 : : }
3487 : :
3488 : 963151006 : fntype = gimple_call_fntype (stmt);
3489 : 963151006 : if (fntype
3490 : 963151006 : && lhs
3491 : 360716749 : && !useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (fntype))
3492 : : /* ??? At least C++ misses conversions at assignments from
3493 : : void * call results.
3494 : : For now simply allow arbitrary pointer type conversions. */
3495 : 963151006 : && !(POINTER_TYPE_P (TREE_TYPE (lhs))
3496 : 0 : && POINTER_TYPE_P (TREE_TYPE (fntype))))
3497 : : {
3498 : 0 : error ("invalid conversion in gimple call");
3499 : 0 : debug_generic_stmt (TREE_TYPE (lhs));
3500 : 0 : debug_generic_stmt (TREE_TYPE (fntype));
3501 : 0 : return true;
3502 : : }
3503 : :
3504 : 963151006 : if (gimple_call_chain (stmt)
3505 : 963151006 : && !is_gimple_val (gimple_call_chain (stmt)))
3506 : : {
3507 : 0 : error ("invalid static chain in gimple call");
3508 : 0 : debug_generic_stmt (gimple_call_chain (stmt));
3509 : 0 : return true;
3510 : : }
3511 : :
3512 : : /* If there is a static chain argument, the call should either be
3513 : : indirect, or the decl should have DECL_STATIC_CHAIN set. */
3514 : 963151006 : if (gimple_call_chain (stmt)
3515 : 4882090 : && fndecl
3516 : 964574070 : && !DECL_STATIC_CHAIN (fndecl))
3517 : : {
3518 : 0 : error ("static chain with function that doesn%'t use one");
3519 : 0 : return true;
3520 : : }
3521 : :
3522 : 963151006 : if (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
3523 : : {
3524 : 218238945 : switch (DECL_FUNCTION_CODE (fndecl))
3525 : : {
3526 : 13267026 : case BUILT_IN_UNREACHABLE:
3527 : 13267026 : case BUILT_IN_UNREACHABLE_TRAP:
3528 : 13267026 : case BUILT_IN_TRAP:
3529 : 13267026 : if (gimple_call_num_args (stmt) > 0)
3530 : : {
3531 : : /* Built-in unreachable with parameters might not be caught by
3532 : : undefined behavior sanitizer. Front-ends do check users do not
3533 : : call them that way but we also produce calls to
3534 : : __builtin_unreachable internally, for example when IPA figures
3535 : : out a call cannot happen in a legal program. In such cases,
3536 : : we must make sure arguments are stripped off. */
3537 : 0 : error ("%<__builtin_unreachable%> or %<__builtin_trap%> call "
3538 : : "with arguments");
3539 : 0 : return true;
3540 : : }
3541 : : break;
3542 : : default:
3543 : : break;
3544 : : }
3545 : : }
3546 : :
3547 : : /* For a call to .DEFERRED_INIT,
3548 : : LHS = DEFERRED_INIT (SIZE of the DECL, INIT_TYPE, NAME of the DECL)
3549 : : we should guarantee that when the 1st argument is a constant, it should
3550 : : be the same as the size of the LHS. */
3551 : :
3552 : 963151006 : if (gimple_call_internal_p (stmt, IFN_DEFERRED_INIT))
3553 : : {
3554 : 46604 : tree size_of_arg0 = gimple_call_arg (stmt, 0);
3555 : 46604 : tree size_of_lhs = TYPE_SIZE_UNIT (TREE_TYPE (lhs));
3556 : :
3557 : 46604 : if (TREE_CODE (lhs) == SSA_NAME)
3558 : 46604 : lhs = SSA_NAME_VAR (lhs);
3559 : :
3560 : 46604 : poly_uint64 size_from_arg0, size_from_lhs;
3561 : 46604 : bool is_constant_size_arg0 = poly_int_tree_p (size_of_arg0,
3562 : : &size_from_arg0);
3563 : 46604 : bool is_constant_size_lhs = poly_int_tree_p (size_of_lhs,
3564 : : &size_from_lhs);
3565 : 46604 : if (is_constant_size_arg0 && is_constant_size_lhs)
3566 : 43873 : if (maybe_ne (size_from_arg0, size_from_lhs))
3567 : : {
3568 : 0 : error ("%<DEFERRED_INIT%> calls should have same "
3569 : : "constant size for the first argument and LHS");
3570 : 0 : return true;
3571 : : }
3572 : : }
3573 : :
3574 : : /* ??? The C frontend passes unpromoted arguments in case it
3575 : : didn't see a function declaration before the call. So for now
3576 : : leave the call arguments mostly unverified. Once we gimplify
3577 : : unit-at-a-time we have a chance to fix this. */
3578 : 2877843079 : for (i = 0; i < gimple_call_num_args (stmt); ++i)
3579 : : {
3580 : 1914692074 : tree arg = gimple_call_arg (stmt, i);
3581 : 1914692074 : if ((is_gimple_reg_type (TREE_TYPE (arg))
3582 : 1806261253 : && !is_gimple_val (arg))
3583 : 3720953326 : || (!is_gimple_reg_type (TREE_TYPE (arg))
3584 : 108430821 : && !is_gimple_lvalue (arg)))
3585 : : {
3586 : 1 : error ("invalid argument to gimple call");
3587 : 1 : debug_generic_expr (arg);
3588 : 1 : return true;
3589 : : }
3590 : 1914692073 : if (!is_gimple_reg (arg))
3591 : : {
3592 : 1116936451 : if (TREE_CODE (arg) == WITH_SIZE_EXPR)
3593 : 22108 : arg = TREE_OPERAND (arg, 0);
3594 : 1116936451 : if (verify_types_in_gimple_reference (arg, false))
3595 : : return true;
3596 : : }
3597 : : }
3598 : :
3599 : : return false;
3600 : : }
3601 : :
3602 : : /* Verifies the gimple comparison with the result type TYPE and
3603 : : the operands OP0 and OP1, comparison code is CODE. */
3604 : :
3605 : : static bool
3606 : 736773623 : verify_gimple_comparison (tree type, tree op0, tree op1, enum tree_code code)
3607 : : {
3608 : 736773623 : tree op0_type = TREE_TYPE (op0);
3609 : 736773623 : tree op1_type = TREE_TYPE (op1);
3610 : :
3611 : 736773623 : if (!is_gimple_val (op0) || !is_gimple_val (op1))
3612 : : {
3613 : 0 : error ("invalid operands in gimple comparison");
3614 : 0 : return true;
3615 : : }
3616 : :
3617 : : /* For comparisons we do not have the operations type as the
3618 : : effective type the comparison is carried out in. Instead
3619 : : we require that either the first operand is trivially
3620 : : convertible into the second, or the other way around. */
3621 : 736773623 : if (!useless_type_conversion_p (op0_type, op1_type)
3622 : 736773623 : && !useless_type_conversion_p (op1_type, op0_type))
3623 : : {
3624 : 0 : error ("mismatching comparison operand types");
3625 : 0 : debug_generic_expr (op0_type);
3626 : 0 : debug_generic_expr (op1_type);
3627 : 0 : return true;
3628 : : }
3629 : :
3630 : : /* The resulting type of a comparison may be an effective boolean type. */
3631 : 736773623 : if (INTEGRAL_TYPE_P (type)
3632 : 736773623 : && (TREE_CODE (type) == BOOLEAN_TYPE
3633 : 724 : || TYPE_PRECISION (type) == 1))
3634 : : {
3635 : 735671062 : if ((VECTOR_TYPE_P (op0_type)
3636 : 735561864 : || VECTOR_TYPE_P (op1_type))
3637 : 109198 : && code != EQ_EXPR && code != NE_EXPR
3638 : 0 : && !VECTOR_BOOLEAN_TYPE_P (op0_type)
3639 : 735671062 : && !VECTOR_INTEGER_TYPE_P (op0_type))
3640 : : {
3641 : 0 : error ("unsupported operation or type for vector comparison"
3642 : : " returning a boolean");
3643 : 0 : debug_generic_expr (op0_type);
3644 : 0 : debug_generic_expr (op1_type);
3645 : 0 : return true;
3646 : : }
3647 : : }
3648 : : /* Or a boolean vector type with the same element count
3649 : : as the comparison operand types. */
3650 : 1102561 : else if (VECTOR_TYPE_P (type)
3651 : 1102561 : && TREE_CODE (TREE_TYPE (type)) == BOOLEAN_TYPE)
3652 : : {
3653 : 1102561 : if (TREE_CODE (op0_type) != VECTOR_TYPE
3654 : 1102561 : || TREE_CODE (op1_type) != VECTOR_TYPE)
3655 : : {
3656 : 0 : error ("non-vector operands in vector comparison");
3657 : 0 : debug_generic_expr (op0_type);
3658 : 0 : debug_generic_expr (op1_type);
3659 : 0 : return true;
3660 : : }
3661 : :
3662 : 1102561 : if (maybe_ne (TYPE_VECTOR_SUBPARTS (type),
3663 : 2205122 : TYPE_VECTOR_SUBPARTS (op0_type)))
3664 : : {
3665 : 0 : error ("invalid vector comparison resulting type");
3666 : 0 : debug_generic_expr (type);
3667 : 0 : return true;
3668 : : }
3669 : : }
3670 : : else
3671 : : {
3672 : 0 : error ("bogus comparison result type");
3673 : 0 : debug_generic_expr (type);
3674 : 0 : return true;
3675 : : }
3676 : :
3677 : : return false;
3678 : : }
3679 : :
3680 : : /* Verify a gimple assignment statement STMT with an unary rhs.
3681 : : Returns true if anything is wrong. */
3682 : :
3683 : : static bool
3684 : 389952433 : verify_gimple_assign_unary (gassign *stmt)
3685 : : {
3686 : 389952433 : enum tree_code rhs_code = gimple_assign_rhs_code (stmt);
3687 : 389952433 : tree lhs = gimple_assign_lhs (stmt);
3688 : 389952433 : tree lhs_type = TREE_TYPE (lhs);
3689 : 389952433 : tree rhs1 = gimple_assign_rhs1 (stmt);
3690 : 389952433 : tree rhs1_type = TREE_TYPE (rhs1);
3691 : :
3692 : 389952433 : if (!is_gimple_reg (lhs))
3693 : : {
3694 : 0 : error ("non-register as LHS of unary operation");
3695 : 0 : return true;
3696 : : }
3697 : :
3698 : 389952433 : if (!is_gimple_val (rhs1))
3699 : : {
3700 : 0 : error ("invalid operand in unary operation");
3701 : 0 : return true;
3702 : : }
3703 : :
3704 : 389952433 : const char* const code_name = get_tree_code_name (rhs_code);
3705 : :
3706 : : /* First handle conversions. */
3707 : 389952433 : switch (rhs_code)
3708 : : {
3709 : 346537193 : CASE_CONVERT:
3710 : 346537193 : {
3711 : : /* Allow conversions between vectors with the same number of elements,
3712 : : provided that the conversion is OK for the element types too. */
3713 : 346537193 : if (VECTOR_TYPE_P (lhs_type)
3714 : 191990 : && VECTOR_TYPE_P (rhs1_type)
3715 : 346729183 : && known_eq (TYPE_VECTOR_SUBPARTS (lhs_type),
3716 : : TYPE_VECTOR_SUBPARTS (rhs1_type)))
3717 : : {
3718 : 191990 : lhs_type = TREE_TYPE (lhs_type);
3719 : 191990 : rhs1_type = TREE_TYPE (rhs1_type);
3720 : : }
3721 : 346345203 : else if (VECTOR_TYPE_P (lhs_type) || VECTOR_TYPE_P (rhs1_type))
3722 : : {
3723 : 0 : error ("invalid vector types in nop conversion");
3724 : 0 : debug_generic_expr (lhs_type);
3725 : 0 : debug_generic_expr (rhs1_type);
3726 : 0 : return true;
3727 : : }
3728 : :
3729 : : /* Allow conversions from pointer type to integral type only if
3730 : : there is no sign or zero extension involved.
3731 : : For targets were the precision of ptrofftype doesn't match that
3732 : : of pointers we allow conversions to types where
3733 : : POINTERS_EXTEND_UNSIGNED specifies how that works. */
3734 : 346537193 : if ((POINTER_TYPE_P (lhs_type)
3735 : 19860623 : && INTEGRAL_TYPE_P (rhs1_type))
3736 : 350478643 : || (POINTER_TYPE_P (rhs1_type)
3737 : 44726988 : && INTEGRAL_TYPE_P (lhs_type)
3738 : 40785538 : && (TYPE_PRECISION (rhs1_type) >= TYPE_PRECISION (lhs_type)
3739 : : #if defined(POINTERS_EXTEND_UNSIGNED)
3740 : 0 : || (TYPE_MODE (rhs1_type) == ptr_mode
3741 : 0 : && (TYPE_PRECISION (lhs_type)
3742 : 0 : == BITS_PER_WORD /* word_mode */
3743 : 0 : || (TYPE_PRECISION (lhs_type)
3744 : 0 : == GET_MODE_PRECISION (Pmode))))
3745 : : #endif
3746 : : )))
3747 : 56704711 : return false;
3748 : :
3749 : : /* Allow conversion from integral to offset type and vice versa. */
3750 : 289832482 : if ((TREE_CODE (lhs_type) == OFFSET_TYPE
3751 : 5968 : && INTEGRAL_TYPE_P (rhs1_type))
3752 : 289831012 : || (INTEGRAL_TYPE_P (lhs_type)
3753 : 266364218 : && TREE_CODE (rhs1_type) == OFFSET_TYPE))
3754 : : return false;
3755 : :
3756 : : /* Otherwise assert we are converting between types of the
3757 : : same kind. */
3758 : 289788861 : if (INTEGRAL_TYPE_P (lhs_type) != INTEGRAL_TYPE_P (rhs1_type))
3759 : : {
3760 : 0 : error ("invalid types in nop conversion");
3761 : 0 : debug_generic_expr (lhs_type);
3762 : 0 : debug_generic_expr (rhs1_type);
3763 : 0 : return true;
3764 : : }
3765 : :
3766 : : return false;
3767 : : }
3768 : :
3769 : 0 : case ADDR_SPACE_CONVERT_EXPR:
3770 : 0 : {
3771 : 0 : if (!POINTER_TYPE_P (rhs1_type) || !POINTER_TYPE_P (lhs_type)
3772 : 0 : || (TYPE_ADDR_SPACE (TREE_TYPE (rhs1_type))
3773 : 0 : == TYPE_ADDR_SPACE (TREE_TYPE (lhs_type))))
3774 : : {
3775 : 0 : error ("invalid types in address space conversion");
3776 : 0 : debug_generic_expr (lhs_type);
3777 : 0 : debug_generic_expr (rhs1_type);
3778 : 0 : return true;
3779 : : }
3780 : :
3781 : : return false;
3782 : : }
3783 : :
3784 : 0 : case FIXED_CONVERT_EXPR:
3785 : 0 : {
3786 : 0 : if (!valid_fixed_convert_types_p (lhs_type, rhs1_type)
3787 : 0 : && !valid_fixed_convert_types_p (rhs1_type, lhs_type))
3788 : : {
3789 : 0 : error ("invalid types in fixed-point conversion");
3790 : 0 : debug_generic_expr (lhs_type);
3791 : 0 : debug_generic_expr (rhs1_type);
3792 : 0 : return true;
3793 : : }
3794 : :
3795 : : return false;
3796 : : }
3797 : :
3798 : 15778524 : case FLOAT_EXPR:
3799 : 15778524 : {
3800 : 15712639 : if ((!INTEGRAL_TYPE_P (rhs1_type) || !SCALAR_FLOAT_TYPE_P (lhs_type))
3801 : 15778524 : && (!VECTOR_INTEGER_TYPE_P (rhs1_type)
3802 : 65885 : || !VECTOR_FLOAT_TYPE_P (lhs_type)))
3803 : : {
3804 : 0 : error ("invalid types in conversion to floating-point");
3805 : 0 : debug_generic_expr (lhs_type);
3806 : 0 : debug_generic_expr (rhs1_type);
3807 : 0 : return true;
3808 : : }
3809 : :
3810 : : return false;
3811 : : }
3812 : :
3813 : 4976487 : case FIX_TRUNC_EXPR:
3814 : 4976487 : {
3815 : 4956502 : if ((!INTEGRAL_TYPE_P (lhs_type) || !SCALAR_FLOAT_TYPE_P (rhs1_type))
3816 : 4976487 : && (!VECTOR_INTEGER_TYPE_P (lhs_type)
3817 : 19985 : || !VECTOR_FLOAT_TYPE_P (rhs1_type)))
3818 : : {
3819 : 0 : error ("invalid types in conversion to integer");
3820 : 0 : debug_generic_expr (lhs_type);
3821 : 0 : debug_generic_expr (rhs1_type);
3822 : 0 : return true;
3823 : : }
3824 : :
3825 : : return false;
3826 : : }
3827 : :
3828 : 579314 : case VEC_UNPACK_HI_EXPR:
3829 : 579314 : case VEC_UNPACK_LO_EXPR:
3830 : 579314 : case VEC_UNPACK_FLOAT_HI_EXPR:
3831 : 579314 : case VEC_UNPACK_FLOAT_LO_EXPR:
3832 : 579314 : case VEC_UNPACK_FIX_TRUNC_HI_EXPR:
3833 : 579314 : case VEC_UNPACK_FIX_TRUNC_LO_EXPR:
3834 : 579314 : if (TREE_CODE (rhs1_type) != VECTOR_TYPE
3835 : 579314 : || TREE_CODE (lhs_type) != VECTOR_TYPE
3836 : 579314 : || (!INTEGRAL_TYPE_P (TREE_TYPE (lhs_type))
3837 : 105054 : && !SCALAR_FLOAT_TYPE_P (TREE_TYPE (lhs_type)))
3838 : 579314 : || (!INTEGRAL_TYPE_P (TREE_TYPE (rhs1_type))
3839 : 36118 : && !SCALAR_FLOAT_TYPE_P (TREE_TYPE (rhs1_type)))
3840 : 579314 : || ((rhs_code == VEC_UNPACK_HI_EXPR
3841 : 579314 : || rhs_code == VEC_UNPACK_LO_EXPR)
3842 : 1012084 : && (INTEGRAL_TYPE_P (TREE_TYPE (lhs_type))
3843 : 506042 : != INTEGRAL_TYPE_P (TREE_TYPE (rhs1_type))))
3844 : 579314 : || ((rhs_code == VEC_UNPACK_FLOAT_HI_EXPR
3845 : 579314 : || rhs_code == VEC_UNPACK_FLOAT_LO_EXPR)
3846 : 71104 : && (INTEGRAL_TYPE_P (TREE_TYPE (lhs_type))
3847 : 71104 : || SCALAR_FLOAT_TYPE_P (TREE_TYPE (rhs1_type))))
3848 : 579314 : || ((rhs_code == VEC_UNPACK_FIX_TRUNC_HI_EXPR
3849 : 579314 : || rhs_code == VEC_UNPACK_FIX_TRUNC_LO_EXPR)
3850 : 2168 : && (INTEGRAL_TYPE_P (TREE_TYPE (rhs1_type))
3851 : 2168 : || SCALAR_FLOAT_TYPE_P (TREE_TYPE (lhs_type))))
3852 : 1158628 : || (maybe_ne (GET_MODE_SIZE (element_mode (lhs_type)),
3853 : 1158628 : 2 * GET_MODE_SIZE (element_mode (rhs1_type)))
3854 : 46684 : && (!VECTOR_BOOLEAN_TYPE_P (lhs_type)
3855 : 46684 : || !VECTOR_BOOLEAN_TYPE_P (rhs1_type)))
3856 : 1158628 : || maybe_ne (2 * TYPE_VECTOR_SUBPARTS (lhs_type),
3857 : 1158628 : TYPE_VECTOR_SUBPARTS (rhs1_type)))
3858 : : {
3859 : 0 : error ("type mismatch in %qs expression", code_name);
3860 : 0 : debug_generic_expr (lhs_type);
3861 : 0 : debug_generic_expr (rhs1_type);
3862 : 0 : return true;
3863 : : }
3864 : :
3865 : : return false;
3866 : :
3867 : 21972569 : case NEGATE_EXPR:
3868 : 21972569 : case ABS_EXPR:
3869 : 21972569 : case BIT_NOT_EXPR:
3870 : 21972569 : case PAREN_EXPR:
3871 : 21972569 : case CONJ_EXPR:
3872 : : /* Disallow pointer and offset types for many of the unary gimple. */
3873 : 21972569 : if (POINTER_TYPE_P (lhs_type)
3874 : 21972569 : || TREE_CODE (lhs_type) == OFFSET_TYPE)
3875 : : {
3876 : 0 : error ("invalid types for %qs", code_name);
3877 : 0 : debug_generic_expr (lhs_type);
3878 : 0 : debug_generic_expr (rhs1_type);
3879 : 0 : return true;
3880 : : }
3881 : 21972569 : break;
3882 : :
3883 : 108346 : case ABSU_EXPR:
3884 : 31091 : if (!ANY_INTEGRAL_TYPE_P (lhs_type)
3885 : 108346 : || !TYPE_UNSIGNED (lhs_type)
3886 : 108346 : || !ANY_INTEGRAL_TYPE_P (rhs1_type)
3887 : 108346 : || TYPE_UNSIGNED (rhs1_type)
3888 : 216692 : || element_precision (lhs_type) != element_precision (rhs1_type))
3889 : : {
3890 : 0 : error ("invalid types for %qs", code_name);
3891 : 0 : debug_generic_expr (lhs_type);
3892 : 0 : debug_generic_expr (rhs1_type);
3893 : 0 : return true;
3894 : : }
3895 : : return false;
3896 : :
3897 : 0 : case VEC_DUPLICATE_EXPR:
3898 : 0 : if (TREE_CODE (lhs_type) != VECTOR_TYPE
3899 : 0 : || !useless_type_conversion_p (TREE_TYPE (lhs_type), rhs1_type))
3900 : : {
3901 : 0 : error ("%qs should be from a scalar to a like vector", code_name);
3902 : 0 : debug_generic_expr (lhs_type);
3903 : 0 : debug_generic_expr (rhs1_type);
3904 : 0 : return true;
3905 : : }
3906 : : return false;
3907 : :
3908 : 0 : default:
3909 : 0 : gcc_unreachable ();
3910 : : }
3911 : :
3912 : : /* For the remaining codes assert there is no conversion involved. */
3913 : 21972569 : if (!useless_type_conversion_p (lhs_type, rhs1_type))
3914 : : {
3915 : 0 : error ("non-trivial conversion in unary operation");
3916 : 0 : debug_generic_expr (lhs_type);
3917 : 0 : debug_generic_expr (rhs1_type);
3918 : 0 : return true;
3919 : : }
3920 : :
3921 : : return false;
3922 : : }
3923 : :
3924 : : /* Verify a gimple assignment statement STMT with a binary rhs.
3925 : : Returns true if anything is wrong. */
3926 : :
3927 : : static bool
3928 : 902204991 : verify_gimple_assign_binary (gassign *stmt)
3929 : : {
3930 : 902204991 : enum tree_code rhs_code = gimple_assign_rhs_code (stmt);
3931 : 902204991 : tree lhs = gimple_assign_lhs (stmt);
3932 : 902204991 : tree lhs_type = TREE_TYPE (lhs);
3933 : 902204991 : tree rhs1 = gimple_assign_rhs1 (stmt);
3934 : 902204991 : tree rhs1_type = TREE_TYPE (rhs1);
3935 : 902204991 : tree rhs2 = gimple_assign_rhs2 (stmt);
3936 : 902204991 : tree rhs2_type = TREE_TYPE (rhs2);
3937 : :
3938 : 902204991 : if (!is_gimple_reg (lhs))
3939 : : {
3940 : 0 : error ("non-register as LHS of binary operation");
3941 : 0 : return true;
3942 : : }
3943 : :
3944 : 902204991 : if (!is_gimple_val (rhs1)
3945 : 902204991 : || !is_gimple_val (rhs2))
3946 : : {
3947 : 0 : error ("invalid operands in binary operation");
3948 : 0 : return true;
3949 : : }
3950 : :
3951 : 902204991 : const char* const code_name = get_tree_code_name (rhs_code);
3952 : :
3953 : : /* First handle operations that involve different types. */
3954 : 902204991 : switch (rhs_code)
3955 : : {
3956 : 2558309 : case COMPLEX_EXPR:
3957 : 2558309 : {
3958 : 2558309 : if (TREE_CODE (lhs_type) != COMPLEX_TYPE
3959 : 2558309 : || !(INTEGRAL_TYPE_P (rhs1_type)
3960 : : || SCALAR_FLOAT_TYPE_P (rhs1_type))
3961 : 2558309 : || !(INTEGRAL_TYPE_P (rhs2_type)
3962 : : || SCALAR_FLOAT_TYPE_P (rhs2_type)))
3963 : : {
3964 : 0 : error ("type mismatch in %qs", code_name);
3965 : 0 : debug_generic_expr (lhs_type);
3966 : 0 : debug_generic_expr (rhs1_type);
3967 : 0 : debug_generic_expr (rhs2_type);
3968 : 0 : return true;
3969 : : }
3970 : :
3971 : : return false;
3972 : : }
3973 : :
3974 : 29043293 : case LSHIFT_EXPR:
3975 : 29043293 : case RSHIFT_EXPR:
3976 : 29043293 : case LROTATE_EXPR:
3977 : 29043293 : case RROTATE_EXPR:
3978 : 29043293 : {
3979 : : /* Shifts and rotates are ok on integral types, fixed point
3980 : : types and integer vector types. */
3981 : 29043293 : if ((!INTEGRAL_TYPE_P (rhs1_type)
3982 : 458223 : && !FIXED_POINT_TYPE_P (rhs1_type)
3983 : 458223 : && ! (VECTOR_TYPE_P (rhs1_type)
3984 : 458223 : && INTEGRAL_TYPE_P (TREE_TYPE (rhs1_type))))
3985 : 29043293 : || (!INTEGRAL_TYPE_P (rhs2_type)
3986 : : /* Vector shifts of vectors are also ok. */
3987 : 93620 : && ! (VECTOR_TYPE_P (rhs1_type)
3988 : 93620 : && INTEGRAL_TYPE_P (TREE_TYPE (rhs1_type))
3989 : 93620 : && VECTOR_TYPE_P (rhs2_type)
3990 : 93620 : && INTEGRAL_TYPE_P (TREE_TYPE (rhs2_type))))
3991 : 58086586 : || !useless_type_conversion_p (lhs_type, rhs1_type))
3992 : : {
3993 : 0 : error ("type mismatch in %qs", code_name);
3994 : 0 : debug_generic_expr (lhs_type);
3995 : 0 : debug_generic_expr (rhs1_type);
3996 : 0 : debug_generic_expr (rhs2_type);
3997 : 0 : return true;
3998 : : }
3999 : :
4000 : : return false;
4001 : : }
4002 : :
4003 : 0 : case WIDEN_LSHIFT_EXPR:
4004 : 0 : {
4005 : 0 : if (!INTEGRAL_TYPE_P (lhs_type)
4006 : 0 : || !INTEGRAL_TYPE_P (rhs1_type)
4007 : 0 : || TREE_CODE (rhs2) != INTEGER_CST
4008 : 0 : || (2 * TYPE_PRECISION (rhs1_type) > TYPE_PRECISION (lhs_type)))
4009 : : {
4010 : 0 : error ("type mismatch in %qs", code_name);
4011 : 0 : debug_generic_expr (lhs_type);
4012 : 0 : debug_generic_expr (rhs1_type);
4013 : 0 : debug_generic_expr (rhs2_type);
4014 : 0 : return true;
4015 : : }
4016 : :
4017 : : return false;
4018 : : }
4019 : :
4020 : 0 : case VEC_WIDEN_LSHIFT_HI_EXPR:
4021 : 0 : case VEC_WIDEN_LSHIFT_LO_EXPR:
4022 : 0 : {
4023 : 0 : if (TREE_CODE (rhs1_type) != VECTOR_TYPE
4024 : 0 : || TREE_CODE (lhs_type) != VECTOR_TYPE
4025 : 0 : || !INTEGRAL_TYPE_P (TREE_TYPE (rhs1_type))
4026 : 0 : || !INTEGRAL_TYPE_P (TREE_TYPE (lhs_type))
4027 : 0 : || TREE_CODE (rhs2) != INTEGER_CST
4028 : 0 : || (2 * TYPE_PRECISION (TREE_TYPE (rhs1_type))
4029 : 0 : > TYPE_PRECISION (TREE_TYPE (lhs_type))))
4030 : : {
4031 : 0 : error ("type mismatch in %qs", code_name);
4032 : 0 : debug_generic_expr (lhs_type);
4033 : 0 : debug_generic_expr (rhs1_type);
4034 : 0 : debug_generic_expr (rhs2_type);
4035 : 0 : return true;
4036 : : }
4037 : :
4038 : : return false;
4039 : : }
4040 : :
4041 : 402388827 : case PLUS_EXPR:
4042 : 402388827 : case MINUS_EXPR:
4043 : 402388827 : {
4044 : 402388827 : tree lhs_etype = lhs_type;
4045 : 402388827 : tree rhs1_etype = rhs1_type;
4046 : 402388827 : tree rhs2_etype = rhs2_type;
4047 : 402388827 : if (VECTOR_TYPE_P (lhs_type))
4048 : : {
4049 : 3737061 : if (TREE_CODE (rhs1_type) != VECTOR_TYPE
4050 : 3737061 : || TREE_CODE (rhs2_type) != VECTOR_TYPE)
4051 : : {
4052 : 0 : error ("invalid non-vector operands to %qs", code_name);
4053 : 0 : return true;
4054 : : }
4055 : 3737061 : lhs_etype = TREE_TYPE (lhs_type);
4056 : 3737061 : rhs1_etype = TREE_TYPE (rhs1_type);
4057 : 3737061 : rhs2_etype = TREE_TYPE (rhs2_type);
4058 : : }
4059 : 402388827 : if (POINTER_TYPE_P (lhs_etype)
4060 : 402388827 : || POINTER_TYPE_P (rhs1_etype)
4061 : 402388827 : || POINTER_TYPE_P (rhs2_etype))
4062 : : {
4063 : 0 : error ("invalid (pointer) operands %qs", code_name);
4064 : 0 : return true;
4065 : : }
4066 : :
4067 : : /* Continue with generic binary expression handling. */
4068 : : break;
4069 : : }
4070 : :
4071 : 136706178 : case POINTER_PLUS_EXPR:
4072 : 136706178 : {
4073 : 136706178 : if (!POINTER_TYPE_P (rhs1_type)
4074 : 136706178 : || !useless_type_conversion_p (lhs_type, rhs1_type)
4075 : 273412356 : || !ptrofftype_p (rhs2_type))
4076 : : {
4077 : 0 : error ("type mismatch in %qs", code_name);
4078 : 0 : debug_generic_stmt (lhs_type);
4079 : 0 : debug_generic_stmt (rhs1_type);
4080 : 0 : debug_generic_stmt (rhs2_type);
4081 : 0 : return true;
4082 : : }
4083 : :
4084 : : return false;
4085 : : }
4086 : :
4087 : 12743640 : case POINTER_DIFF_EXPR:
4088 : 12743640 : {
4089 : 12743640 : if (!POINTER_TYPE_P (rhs1_type)
4090 : 12743640 : || !POINTER_TYPE_P (rhs2_type)
4091 : : /* Because we special-case pointers to void we allow difference
4092 : : of arbitrary pointers with the same mode. */
4093 : 12743640 : || TYPE_MODE (rhs1_type) != TYPE_MODE (rhs2_type)
4094 : 12743640 : || !INTEGRAL_TYPE_P (lhs_type)
4095 : 12743640 : || TYPE_UNSIGNED (lhs_type)
4096 : 25487280 : || TYPE_PRECISION (lhs_type) != TYPE_PRECISION (rhs1_type))
4097 : : {
4098 : 0 : error ("type mismatch in %qs", code_name);
4099 : 0 : debug_generic_stmt (lhs_type);
4100 : 0 : debug_generic_stmt (rhs1_type);
4101 : 0 : debug_generic_stmt (rhs2_type);
4102 : 0 : return true;
4103 : : }
4104 : :
4105 : : return false;
4106 : : }
4107 : :
4108 : 0 : case TRUTH_ANDIF_EXPR:
4109 : 0 : case TRUTH_ORIF_EXPR:
4110 : 0 : case TRUTH_AND_EXPR:
4111 : 0 : case TRUTH_OR_EXPR:
4112 : 0 : case TRUTH_XOR_EXPR:
4113 : :
4114 : 0 : gcc_unreachable ();
4115 : :
4116 : 77738298 : case LT_EXPR:
4117 : 77738298 : case LE_EXPR:
4118 : 77738298 : case GT_EXPR:
4119 : 77738298 : case GE_EXPR:
4120 : 77738298 : case EQ_EXPR:
4121 : 77738298 : case NE_EXPR:
4122 : 77738298 : case UNORDERED_EXPR:
4123 : 77738298 : case ORDERED_EXPR:
4124 : 77738298 : case UNLT_EXPR:
4125 : 77738298 : case UNLE_EXPR:
4126 : 77738298 : case UNGT_EXPR:
4127 : 77738298 : case UNGE_EXPR:
4128 : 77738298 : case UNEQ_EXPR:
4129 : 77738298 : case LTGT_EXPR:
4130 : : /* Comparisons are also binary, but the result type is not
4131 : : connected to the operand types. */
4132 : 77738298 : return verify_gimple_comparison (lhs_type, rhs1, rhs2, rhs_code);
4133 : :
4134 : 129099 : case WIDEN_MULT_EXPR:
4135 : 129099 : if (TREE_CODE (lhs_type) != INTEGER_TYPE)
4136 : : return true;
4137 : 129099 : return ((2 * TYPE_PRECISION (rhs1_type) > TYPE_PRECISION (lhs_type))
4138 : 129099 : || (TYPE_PRECISION (rhs1_type) != TYPE_PRECISION (rhs2_type)));
4139 : :
4140 : 0 : case WIDEN_SUM_EXPR:
4141 : 0 : {
4142 : 0 : if (((TREE_CODE (rhs1_type) != VECTOR_TYPE
4143 : 0 : || TREE_CODE (lhs_type) != VECTOR_TYPE)
4144 : 0 : && ((!INTEGRAL_TYPE_P (rhs1_type)
4145 : 0 : && !SCALAR_FLOAT_TYPE_P (rhs1_type))
4146 : 0 : || (!INTEGRAL_TYPE_P (lhs_type)
4147 : 0 : && !SCALAR_FLOAT_TYPE_P (lhs_type))))
4148 : 0 : || !useless_type_conversion_p (lhs_type, rhs2_type)
4149 : 0 : || maybe_lt (GET_MODE_SIZE (element_mode (rhs2_type)),
4150 : 0 : 2 * GET_MODE_SIZE (element_mode (rhs1_type))))
4151 : : {
4152 : 0 : error ("type mismatch in %qs", code_name);
4153 : 0 : debug_generic_expr (lhs_type);
4154 : 0 : debug_generic_expr (rhs1_type);
4155 : 0 : debug_generic_expr (rhs2_type);
4156 : 0 : return true;
4157 : : }
4158 : : return false;
4159 : : }
4160 : :
4161 : 37472 : case VEC_WIDEN_MULT_HI_EXPR:
4162 : 37472 : case VEC_WIDEN_MULT_LO_EXPR:
4163 : 37472 : case VEC_WIDEN_MULT_EVEN_EXPR:
4164 : 37472 : case VEC_WIDEN_MULT_ODD_EXPR:
4165 : 37472 : {
4166 : 37472 : if (TREE_CODE (rhs1_type) != VECTOR_TYPE
4167 : 37472 : || TREE_CODE (lhs_type) != VECTOR_TYPE
4168 : 37472 : || !types_compatible_p (rhs1_type, rhs2_type)
4169 : 112416 : || maybe_ne (GET_MODE_SIZE (element_mode (lhs_type)),
4170 : 112416 : 2 * GET_MODE_SIZE (element_mode (rhs1_type))))
4171 : : {
4172 : 0 : error ("type mismatch in %qs", code_name);
4173 : 0 : debug_generic_expr (lhs_type);
4174 : 0 : debug_generic_expr (rhs1_type);
4175 : 0 : debug_generic_expr (rhs2_type);
4176 : 0 : return true;
4177 : : }
4178 : : return false;
4179 : : }
4180 : :
4181 : 336002 : case VEC_PACK_TRUNC_EXPR:
4182 : : /* ??? We currently use VEC_PACK_TRUNC_EXPR to simply concat
4183 : : vector boolean types. */
4184 : 336002 : if (VECTOR_BOOLEAN_TYPE_P (lhs_type)
4185 : 39371 : && VECTOR_BOOLEAN_TYPE_P (rhs1_type)
4186 : 39371 : && types_compatible_p (rhs1_type, rhs2_type)
4187 : 672004 : && known_eq (TYPE_VECTOR_SUBPARTS (lhs_type),
4188 : : 2 * TYPE_VECTOR_SUBPARTS (rhs1_type)))
4189 : 39371 : return false;
4190 : :
4191 : : /* Fallthru. */
4192 : 305049 : case VEC_PACK_SAT_EXPR:
4193 : 305049 : case VEC_PACK_FIX_TRUNC_EXPR:
4194 : 305049 : {
4195 : 305049 : if (TREE_CODE (rhs1_type) != VECTOR_TYPE
4196 : 305049 : || TREE_CODE (lhs_type) != VECTOR_TYPE
4197 : 601680 : || !((rhs_code == VEC_PACK_FIX_TRUNC_EXPR
4198 : 8418 : && SCALAR_FLOAT_TYPE_P (TREE_TYPE (rhs1_type))
4199 : 8418 : && INTEGRAL_TYPE_P (TREE_TYPE (lhs_type)))
4200 : 296631 : || (INTEGRAL_TYPE_P (TREE_TYPE (rhs1_type))
4201 : 296631 : == INTEGRAL_TYPE_P (TREE_TYPE (lhs_type))))
4202 : 305049 : || !types_compatible_p (rhs1_type, rhs2_type)
4203 : 610098 : || maybe_ne (GET_MODE_SIZE (element_mode (rhs1_type)),
4204 : 610098 : 2 * GET_MODE_SIZE (element_mode (lhs_type)))
4205 : 610098 : || maybe_ne (2 * TYPE_VECTOR_SUBPARTS (rhs1_type),
4206 : 610098 : TYPE_VECTOR_SUBPARTS (lhs_type)))
4207 : : {
4208 : 0 : error ("type mismatch in %qs", code_name);
4209 : 0 : debug_generic_expr (lhs_type);
4210 : 0 : debug_generic_expr (rhs1_type);
4211 : 0 : debug_generic_expr (rhs2_type);
4212 : 0 : return true;
4213 : : }
4214 : :
4215 : : return false;
4216 : : }
4217 : :
4218 : 883 : case VEC_PACK_FLOAT_EXPR:
4219 : 883 : if (TREE_CODE (rhs1_type) != VECTOR_TYPE
4220 : 883 : || TREE_CODE (lhs_type) != VECTOR_TYPE
4221 : 883 : || !INTEGRAL_TYPE_P (TREE_TYPE (rhs1_type))
4222 : 883 : || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (lhs_type))
4223 : 883 : || !types_compatible_p (rhs1_type, rhs2_type)
4224 : 1766 : || maybe_ne (GET_MODE_SIZE (element_mode (rhs1_type)),
4225 : 1766 : 2 * GET_MODE_SIZE (element_mode (lhs_type)))
4226 : 1766 : || maybe_ne (2 * TYPE_VECTOR_SUBPARTS (rhs1_type),
4227 : 1766 : TYPE_VECTOR_SUBPARTS (lhs_type)))
4228 : : {
4229 : 0 : error ("type mismatch in %qs", code_name);
4230 : 0 : debug_generic_expr (lhs_type);
4231 : 0 : debug_generic_expr (rhs1_type);
4232 : 0 : debug_generic_expr (rhs2_type);
4233 : 0 : return true;
4234 : : }
4235 : :
4236 : : return false;
4237 : :
4238 : 180597362 : case MULT_EXPR:
4239 : 180597362 : case MULT_HIGHPART_EXPR:
4240 : 180597362 : case TRUNC_DIV_EXPR:
4241 : 180597362 : case CEIL_DIV_EXPR:
4242 : 180597362 : case FLOOR_DIV_EXPR:
4243 : 180597362 : case ROUND_DIV_EXPR:
4244 : 180597362 : case TRUNC_MOD_EXPR:
4245 : 180597362 : case CEIL_MOD_EXPR:
4246 : 180597362 : case FLOOR_MOD_EXPR:
4247 : 180597362 : case ROUND_MOD_EXPR:
4248 : 180597362 : case RDIV_EXPR:
4249 : 180597362 : case EXACT_DIV_EXPR:
4250 : 180597362 : case BIT_IOR_EXPR:
4251 : 180597362 : case BIT_XOR_EXPR:
4252 : : /* Disallow pointer and offset types for many of the binary gimple. */
4253 : 180597362 : if (POINTER_TYPE_P (lhs_type)
4254 : 180597362 : || TREE_CODE (lhs_type) == OFFSET_TYPE)
4255 : : {
4256 : 0 : error ("invalid types for %qs", code_name);
4257 : 0 : debug_generic_expr (lhs_type);
4258 : 0 : debug_generic_expr (rhs1_type);
4259 : 0 : debug_generic_expr (rhs2_type);
4260 : 0 : return true;
4261 : : }
4262 : : /* Continue with generic binary expression handling. */
4263 : : break;
4264 : :
4265 : : case MIN_EXPR:
4266 : : case MAX_EXPR:
4267 : : /* Continue with generic binary expression handling. */
4268 : : break;
4269 : :
4270 : 48447048 : case BIT_AND_EXPR:
4271 : 48447048 : if (POINTER_TYPE_P (lhs_type)
4272 : 173642 : && TREE_CODE (rhs2) == INTEGER_CST)
4273 : : break;
4274 : : /* Disallow pointer and offset types for many of the binary gimple. */
4275 : 48273406 : if (POINTER_TYPE_P (lhs_type)
4276 : 48273406 : || TREE_CODE (lhs_type) == OFFSET_TYPE)
4277 : : {
4278 : 0 : error ("invalid types for %qs", code_name);
4279 : 0 : debug_generic_expr (lhs_type);
4280 : 0 : debug_generic_expr (rhs1_type);
4281 : 0 : debug_generic_expr (rhs2_type);
4282 : 0 : return true;
4283 : : }
4284 : : /* Continue with generic binary expression handling. */
4285 : : break;
4286 : :
4287 : 0 : case VEC_SERIES_EXPR:
4288 : 0 : if (!useless_type_conversion_p (rhs1_type, rhs2_type))
4289 : : {
4290 : 0 : error ("type mismatch in %qs", code_name);
4291 : 0 : debug_generic_expr (rhs1_type);
4292 : 0 : debug_generic_expr (rhs2_type);
4293 : 0 : return true;
4294 : : }
4295 : 0 : if (TREE_CODE (lhs_type) != VECTOR_TYPE
4296 : 0 : || !useless_type_conversion_p (TREE_TYPE (lhs_type), rhs1_type))
4297 : : {
4298 : 0 : error ("vector type expected in %qs", code_name);
4299 : 0 : debug_generic_expr (lhs_type);
4300 : 0 : return true;
4301 : : }
4302 : : return false;
4303 : :
4304 : 0 : default:
4305 : 0 : gcc_unreachable ();
4306 : : }
4307 : :
4308 : 642903399 : if (!useless_type_conversion_p (lhs_type, rhs1_type)
4309 : 642903399 : || !useless_type_conversion_p (lhs_type, rhs2_type))
4310 : : {
4311 : 0 : error ("type mismatch in binary expression");
4312 : 0 : debug_generic_stmt (lhs_type);
4313 : 0 : debug_generic_stmt (rhs1_type);
4314 : 0 : debug_generic_stmt (rhs2_type);
4315 : 0 : return true;
4316 : : }
4317 : :
4318 : : return false;
4319 : : }
4320 : :
4321 : : /* Verify a gimple assignment statement STMT with a ternary rhs.
4322 : : Returns true if anything is wrong. */
4323 : :
4324 : : static bool
4325 : 7584237 : verify_gimple_assign_ternary (gassign *stmt)
4326 : : {
4327 : 7584237 : enum tree_code rhs_code = gimple_assign_rhs_code (stmt);
4328 : 7584237 : tree lhs = gimple_assign_lhs (stmt);
4329 : 7584237 : tree lhs_type = TREE_TYPE (lhs);
4330 : 7584237 : tree rhs1 = gimple_assign_rhs1 (stmt);
4331 : 7584237 : tree rhs1_type = TREE_TYPE (rhs1);
4332 : 7584237 : tree rhs2 = gimple_assign_rhs2 (stmt);
4333 : 7584237 : tree rhs2_type = TREE_TYPE (rhs2);
4334 : 7584237 : tree rhs3 = gimple_assign_rhs3 (stmt);
4335 : 7584237 : tree rhs3_type = TREE_TYPE (rhs3);
4336 : :
4337 : 7584237 : if (!is_gimple_reg (lhs))
4338 : : {
4339 : 0 : error ("non-register as LHS of ternary operation");
4340 : 0 : return true;
4341 : : }
4342 : :
4343 : 7584237 : if (!is_gimple_val (rhs1)
4344 : 7584237 : || !is_gimple_val (rhs2)
4345 : 15168474 : || !is_gimple_val (rhs3))
4346 : : {
4347 : 0 : error ("invalid operands in ternary operation");
4348 : 0 : return true;
4349 : : }
4350 : :
4351 : 7584237 : const char* const code_name = get_tree_code_name (rhs_code);
4352 : :
4353 : : /* First handle operations that involve different types. */
4354 : 7584237 : switch (rhs_code)
4355 : : {
4356 : 0 : case WIDEN_MULT_PLUS_EXPR:
4357 : 0 : case WIDEN_MULT_MINUS_EXPR:
4358 : 0 : if ((!INTEGRAL_TYPE_P (rhs1_type)
4359 : 0 : && !FIXED_POINT_TYPE_P (rhs1_type))
4360 : 0 : || !useless_type_conversion_p (rhs1_type, rhs2_type)
4361 : 0 : || !useless_type_conversion_p (lhs_type, rhs3_type)
4362 : 0 : || 2 * TYPE_PRECISION (rhs1_type) > TYPE_PRECISION (lhs_type)
4363 : 0 : || TYPE_PRECISION (rhs1_type) != TYPE_PRECISION (rhs2_type))
4364 : : {
4365 : 0 : error ("type mismatch in %qs", code_name);
4366 : 0 : debug_generic_expr (lhs_type);
4367 : 0 : debug_generic_expr (rhs1_type);
4368 : 0 : debug_generic_expr (rhs2_type);
4369 : 0 : debug_generic_expr (rhs3_type);
4370 : 0 : return true;
4371 : : }
4372 : : break;
4373 : :
4374 : 935272 : case VEC_COND_EXPR:
4375 : 935272 : if (!VECTOR_BOOLEAN_TYPE_P (rhs1_type)
4376 : 1870544 : || maybe_ne (TYPE_VECTOR_SUBPARTS (rhs1_type),
4377 : 1870544 : TYPE_VECTOR_SUBPARTS (lhs_type)))
4378 : : {
4379 : 0 : error ("the first argument of a %qs must be of a "
4380 : : "boolean vector type of the same number of elements "
4381 : : "as the result", code_name);
4382 : 0 : debug_generic_expr (lhs_type);
4383 : 0 : debug_generic_expr (rhs1_type);
4384 : 0 : return true;
4385 : : }
4386 : : /* Fallthrough. */
4387 : 1780506 : case COND_EXPR:
4388 : 1780506 : if (!useless_type_conversion_p (lhs_type, rhs2_type)
4389 : 1780506 : || !useless_type_conversion_p (lhs_type, rhs3_type))
4390 : : {
4391 : 0 : error ("type mismatch in %qs", code_name);
4392 : 0 : debug_generic_expr (lhs_type);
4393 : 0 : debug_generic_expr (rhs2_type);
4394 : 0 : debug_generic_expr (rhs3_type);
4395 : 0 : return true;
4396 : : }
4397 : : break;
4398 : :
4399 : 5712842 : case VEC_PERM_EXPR:
4400 : : /* If permute is constant, then we allow for lhs and rhs
4401 : : to have different vector types, provided:
4402 : : (1) lhs, rhs1, rhs2 have same element type.
4403 : : (2) rhs3 vector is constant and has integer element type.
4404 : : (3) len(lhs) == len(rhs3) && len(rhs1) == len(rhs2). */
4405 : :
4406 : 5712842 : if (TREE_CODE (lhs_type) != VECTOR_TYPE
4407 : 5712842 : || TREE_CODE (rhs1_type) != VECTOR_TYPE
4408 : 5712842 : || TREE_CODE (rhs2_type) != VECTOR_TYPE
4409 : 5712842 : || TREE_CODE (rhs3_type) != VECTOR_TYPE)
4410 : : {
4411 : 0 : error ("vector types expected in %qs", code_name);
4412 : 0 : debug_generic_expr (lhs_type);
4413 : 0 : debug_generic_expr (rhs1_type);
4414 : 0 : debug_generic_expr (rhs2_type);
4415 : 0 : debug_generic_expr (rhs3_type);
4416 : 0 : return true;
4417 : : }
4418 : :
4419 : : /* If rhs3 is constant, we allow lhs, rhs1 and rhs2 to be different vector types,
4420 : : as long as lhs, rhs1 and rhs2 have same element type. */
4421 : 5712842 : if (TREE_CONSTANT (rhs3)
4422 : 5712842 : ? (!useless_type_conversion_p (TREE_TYPE (lhs_type), TREE_TYPE (rhs1_type))
4423 : 5599885 : || !useless_type_conversion_p (TREE_TYPE (lhs_type), TREE_TYPE (rhs2_type)))
4424 : 112957 : : (!useless_type_conversion_p (lhs_type, rhs1_type)
4425 : 112957 : || !useless_type_conversion_p (lhs_type, rhs2_type)))
4426 : : {
4427 : 0 : error ("type mismatch in %qs", code_name);
4428 : 0 : debug_generic_expr (lhs_type);
4429 : 0 : debug_generic_expr (rhs1_type);
4430 : 0 : debug_generic_expr (rhs2_type);
4431 : 0 : debug_generic_expr (rhs3_type);
4432 : 0 : return true;
4433 : : }
4434 : :
4435 : : /* If rhs3 is constant, relax the check len(rhs2) == len(rhs3). */
4436 : 5712842 : if (maybe_ne (TYPE_VECTOR_SUBPARTS (rhs1_type),
4437 : 5712842 : TYPE_VECTOR_SUBPARTS (rhs2_type))
4438 : 5712842 : || (!TREE_CONSTANT(rhs3)
4439 : 112957 : && maybe_ne (TYPE_VECTOR_SUBPARTS (rhs2_type),
4440 : 112957 : TYPE_VECTOR_SUBPARTS (rhs3_type)))
4441 : 11425684 : || maybe_ne (TYPE_VECTOR_SUBPARTS (rhs3_type),
4442 : 5712842 : TYPE_VECTOR_SUBPARTS (lhs_type)))
4443 : : {
4444 : 0 : error ("vectors with different element number found in %qs",
4445 : : code_name);
4446 : 0 : debug_generic_expr (lhs_type);
4447 : 0 : debug_generic_expr (rhs1_type);
4448 : 0 : debug_generic_expr (rhs2_type);
4449 : 0 : debug_generic_expr (rhs3_type);
4450 : 0 : return true;
4451 : : }
4452 : :
4453 : 5712842 : if (TREE_CODE (TREE_TYPE (rhs3_type)) != INTEGER_TYPE
4454 : 5712842 : || (TREE_CODE (rhs3) != VECTOR_CST
4455 : 112957 : && (GET_MODE_BITSIZE (SCALAR_INT_TYPE_MODE
4456 : : (TREE_TYPE (rhs3_type)))
4457 : 5825799 : != GET_MODE_BITSIZE (SCALAR_TYPE_MODE
4458 : : (TREE_TYPE (rhs1_type))))))
4459 : : {
4460 : 0 : error ("invalid mask type in %qs", code_name);
4461 : 0 : debug_generic_expr (lhs_type);
4462 : 0 : debug_generic_expr (rhs1_type);
4463 : 0 : debug_generic_expr (rhs2_type);
4464 : 0 : debug_generic_expr (rhs3_type);
4465 : 0 : return true;
4466 : : }
4467 : :
4468 : : return false;
4469 : :
4470 : 4123 : case SAD_EXPR:
4471 : 4123 : if (!useless_type_conversion_p (rhs1_type, rhs2_type)
4472 : 4123 : || !useless_type_conversion_p (lhs_type, rhs3_type)
4473 : 8246 : || 2 * GET_MODE_UNIT_BITSIZE (TYPE_MODE (TREE_TYPE (rhs1_type)))
4474 : 8246 : > GET_MODE_UNIT_BITSIZE (TYPE_MODE (TREE_TYPE (lhs_type))))
4475 : : {
4476 : 0 : error ("type mismatch in %qs", code_name);
4477 : 0 : debug_generic_expr (lhs_type);
4478 : 0 : debug_generic_expr (rhs1_type);
4479 : 0 : debug_generic_expr (rhs2_type);
4480 : 0 : debug_generic_expr (rhs3_type);
4481 : 0 : return true;
4482 : : }
4483 : :
4484 : 4123 : if (TREE_CODE (rhs1_type) != VECTOR_TYPE
4485 : 4123 : || TREE_CODE (rhs2_type) != VECTOR_TYPE
4486 : 4123 : || TREE_CODE (rhs3_type) != VECTOR_TYPE)
4487 : : {
4488 : 0 : error ("vector types expected in %qs", code_name);
4489 : 0 : debug_generic_expr (lhs_type);
4490 : 0 : debug_generic_expr (rhs1_type);
4491 : 0 : debug_generic_expr (rhs2_type);
4492 : 0 : debug_generic_expr (rhs3_type);
4493 : 0 : return true;
4494 : : }
4495 : :
4496 : : return false;
4497 : :
4498 : 80983 : case BIT_INSERT_EXPR:
4499 : 80983 : if (! useless_type_conversion_p (lhs_type, rhs1_type))
4500 : : {
4501 : 0 : error ("type mismatch in %qs", code_name);
4502 : 0 : debug_generic_expr (lhs_type);
4503 : 0 : debug_generic_expr (rhs1_type);
4504 : 0 : return true;
4505 : : }
4506 : 80983 : if (! ((INTEGRAL_TYPE_P (rhs1_type)
4507 : 3260 : && INTEGRAL_TYPE_P (rhs2_type))
4508 : : /* Vector element insert. */
4509 : 77723 : || (VECTOR_TYPE_P (rhs1_type)
4510 : 77723 : && types_compatible_p (TREE_TYPE (rhs1_type), rhs2_type))
4511 : : /* Aligned sub-vector insert. */
4512 : 4290 : || (VECTOR_TYPE_P (rhs1_type)
4513 : 4290 : && VECTOR_TYPE_P (rhs2_type)
4514 : 4290 : && types_compatible_p (TREE_TYPE (rhs1_type),
4515 : 4290 : TREE_TYPE (rhs2_type))
4516 : 4290 : && multiple_p (TYPE_VECTOR_SUBPARTS (rhs1_type),
4517 : 4290 : TYPE_VECTOR_SUBPARTS (rhs2_type))
4518 : 4290 : && multiple_p (wi::to_poly_offset (rhs3),
4519 : 4290 : wi::to_poly_offset (TYPE_SIZE (rhs2_type))))))
4520 : : {
4521 : 0 : error ("not allowed type combination in %qs", code_name);
4522 : 0 : debug_generic_expr (rhs1_type);
4523 : 0 : debug_generic_expr (rhs2_type);
4524 : 0 : return true;
4525 : : }
4526 : 80983 : if (! tree_fits_uhwi_p (rhs3)
4527 : 80983 : || ! types_compatible_p (bitsizetype, TREE_TYPE (rhs3))
4528 : 161966 : || ! tree_fits_uhwi_p (TYPE_SIZE (rhs2_type)))
4529 : : {
4530 : 0 : error ("invalid position or size in %qs", code_name);
4531 : 0 : return true;
4532 : : }
4533 : 80983 : if (INTEGRAL_TYPE_P (rhs1_type)
4534 : 80983 : && !type_has_mode_precision_p (rhs1_type))
4535 : : {
4536 : 0 : error ("%qs into non-mode-precision operand", code_name);
4537 : 0 : return true;
4538 : : }
4539 : 80983 : if (INTEGRAL_TYPE_P (rhs1_type))
4540 : : {
4541 : 3260 : unsigned HOST_WIDE_INT bitpos = tree_to_uhwi (rhs3);
4542 : 3260 : if (bitpos >= TYPE_PRECISION (rhs1_type)
4543 : 3260 : || (bitpos + TYPE_PRECISION (rhs2_type)
4544 : 3260 : > TYPE_PRECISION (rhs1_type)))
4545 : : {
4546 : 0 : error ("insertion out of range in %qs", code_name);
4547 : 0 : return true;
4548 : : }
4549 : : }
4550 : 77723 : else if (VECTOR_TYPE_P (rhs1_type))
4551 : : {
4552 : 77723 : unsigned HOST_WIDE_INT bitpos = tree_to_uhwi (rhs3);
4553 : 77723 : unsigned HOST_WIDE_INT bitsize = tree_to_uhwi (TYPE_SIZE (rhs2_type));
4554 : 77723 : if (bitpos % bitsize != 0)
4555 : : {
4556 : 0 : error ("%qs not at element boundary", code_name);
4557 : 0 : return true;
4558 : : }
4559 : : }
4560 : : return false;
4561 : :
4562 : 5783 : case DOT_PROD_EXPR:
4563 : 5783 : {
4564 : 5783 : if (((TREE_CODE (rhs1_type) != VECTOR_TYPE
4565 : 5783 : || TREE_CODE (lhs_type) != VECTOR_TYPE)
4566 : 0 : && ((!INTEGRAL_TYPE_P (rhs1_type)
4567 : 0 : && !SCALAR_FLOAT_TYPE_P (rhs1_type))
4568 : 0 : || (!INTEGRAL_TYPE_P (lhs_type)
4569 : 0 : && !SCALAR_FLOAT_TYPE_P (lhs_type))))
4570 : : /* rhs1_type and rhs2_type may differ in sign. */
4571 : 5783 : || !tree_nop_conversion_p (rhs1_type, rhs2_type)
4572 : 5783 : || !useless_type_conversion_p (lhs_type, rhs3_type)
4573 : 17349 : || maybe_lt (GET_MODE_SIZE (element_mode (rhs3_type)),
4574 : 17349 : 2 * GET_MODE_SIZE (element_mode (rhs1_type))))
4575 : : {
4576 : 0 : error ("type mismatch in %qs", code_name);
4577 : 0 : debug_generic_expr (lhs_type);
4578 : 0 : debug_generic_expr (rhs1_type);
4579 : 0 : debug_generic_expr (rhs2_type);
4580 : 0 : return true;
4581 : : }
4582 : : return false;
4583 : : }
4584 : :
4585 : : case REALIGN_LOAD_EXPR:
4586 : : /* FIXME. */
4587 : : return false;
4588 : :
4589 : 0 : default:
4590 : 0 : gcc_unreachable ();
4591 : : }
4592 : : return false;
4593 : : }
4594 : :
4595 : : /* Verify a gimple assignment statement STMT with a single rhs.
4596 : : Returns true if anything is wrong. */
4597 : :
4598 : : static bool
4599 : 2826434929 : verify_gimple_assign_single (gassign *stmt)
4600 : : {
4601 : 2826434929 : enum tree_code rhs_code = gimple_assign_rhs_code (stmt);
4602 : 2826434929 : tree lhs = gimple_assign_lhs (stmt);
4603 : 2826434929 : tree lhs_type = TREE_TYPE (lhs);
4604 : 2826434929 : tree rhs1 = gimple_assign_rhs1 (stmt);
4605 : 2826434929 : tree rhs1_type = TREE_TYPE (rhs1);
4606 : 2826434929 : bool res = false;
4607 : :
4608 : 2826434929 : const char* const code_name = get_tree_code_name (rhs_code);
4609 : :
4610 : 2826434929 : if (!useless_type_conversion_p (lhs_type, rhs1_type))
4611 : : {
4612 : 0 : error ("non-trivial conversion in %qs", code_name);
4613 : 0 : debug_generic_expr (lhs_type);
4614 : 0 : debug_generic_expr (rhs1_type);
4615 : 0 : return true;
4616 : : }
4617 : :
4618 : 2826434929 : if (gimple_clobber_p (stmt)
4619 : 2826434929 : && !(DECL_P (lhs) || TREE_CODE (lhs) == MEM_REF))
4620 : : {
4621 : 0 : error ("%qs LHS in clobber statement",
4622 : : get_tree_code_name (TREE_CODE (lhs)));
4623 : 0 : debug_generic_expr (lhs);
4624 : 0 : return true;
4625 : : }
4626 : :
4627 : 2826434929 : if (TREE_CODE (lhs) == WITH_SIZE_EXPR)
4628 : : {
4629 : 0 : error ("%qs LHS in assignment statement",
4630 : : get_tree_code_name (TREE_CODE (lhs)));
4631 : 0 : debug_generic_expr (lhs);
4632 : 0 : return true;
4633 : : }
4634 : :
4635 : 2826434929 : if (handled_component_p (lhs)
4636 : 2079060297 : || TREE_CODE (lhs) == MEM_REF
4637 : 1848241036 : || TREE_CODE (lhs) == TARGET_MEM_REF)
4638 : 986023695 : res |= verify_types_in_gimple_reference (lhs, true);
4639 : :
4640 : : /* Special codes we cannot handle via their class. */
4641 : 2826434929 : switch (rhs_code)
4642 : : {
4643 : 237253388 : case ADDR_EXPR:
4644 : 237253388 : {
4645 : 237253388 : tree op = TREE_OPERAND (rhs1, 0);
4646 : 237253388 : if (!is_gimple_addressable (op))
4647 : : {
4648 : 0 : error ("invalid operand in %qs", code_name);
4649 : 0 : return true;
4650 : : }
4651 : :
4652 : : /* Technically there is no longer a need for matching types, but
4653 : : gimple hygiene asks for this check. In LTO we can end up
4654 : : combining incompatible units and thus end up with addresses
4655 : : of globals that change their type to a common one. */
4656 : 237253388 : if (!in_lto_p
4657 : 236858685 : && !types_compatible_p (TREE_TYPE (op),
4658 : 236858685 : TREE_TYPE (TREE_TYPE (rhs1)))
4659 : 237253482 : && !one_pointer_to_useless_type_conversion_p (TREE_TYPE (rhs1),
4660 : 94 : TREE_TYPE (op)))
4661 : : {
4662 : 0 : error ("type mismatch in %qs", code_name);
4663 : 0 : debug_generic_stmt (TREE_TYPE (rhs1));
4664 : 0 : debug_generic_stmt (TREE_TYPE (op));
4665 : 0 : return true;
4666 : : }
4667 : :
4668 : 237253388 : return (verify_address (rhs1, true)
4669 : 237253388 : || verify_types_in_gimple_reference (op, true));
4670 : : }
4671 : :
4672 : : /* tcc_reference */
4673 : 0 : case INDIRECT_REF:
4674 : 0 : error ("%qs in gimple IL", code_name);
4675 : 0 : return true;
4676 : :
4677 : 45 : case WITH_SIZE_EXPR:
4678 : 45 : if (!is_gimple_val (TREE_OPERAND (rhs1, 1)))
4679 : : {
4680 : 0 : error ("invalid %qs size argument in load", code_name);
4681 : 0 : debug_generic_stmt (lhs);
4682 : 0 : debug_generic_stmt (rhs1);
4683 : 0 : return true;
4684 : : }
4685 : 45 : rhs1 = TREE_OPERAND (rhs1, 0);
4686 : : /* Fallthru. */
4687 : 971497922 : case COMPONENT_REF:
4688 : 971497922 : case BIT_FIELD_REF:
4689 : 971497922 : case ARRAY_REF:
4690 : 971497922 : case ARRAY_RANGE_REF:
4691 : 971497922 : case VIEW_CONVERT_EXPR:
4692 : 971497922 : case REALPART_EXPR:
4693 : 971497922 : case IMAGPART_EXPR:
4694 : 971497922 : case TARGET_MEM_REF:
4695 : 971497922 : case MEM_REF:
4696 : 971497922 : if (!is_gimple_reg (lhs)
4697 : 971497922 : && is_gimple_reg_type (TREE_TYPE (lhs)))
4698 : : {
4699 : 0 : error ("invalid RHS for gimple memory store: %qs", code_name);
4700 : 0 : debug_generic_stmt (lhs);
4701 : 0 : debug_generic_stmt (rhs1);
4702 : 0 : return true;
4703 : : }
4704 : 971497922 : return res || verify_types_in_gimple_reference (rhs1, false);
4705 : :
4706 : : /* tcc_constant */
4707 : : case SSA_NAME:
4708 : : case INTEGER_CST:
4709 : : case REAL_CST:
4710 : : case FIXED_CST:
4711 : : case COMPLEX_CST:
4712 : : case VECTOR_CST:
4713 : : case STRING_CST:
4714 : : return res;
4715 : :
4716 : : /* tcc_declaration */
4717 : : case CONST_DECL:
4718 : : return res;
4719 : 306009262 : case VAR_DECL:
4720 : 306009262 : case PARM_DECL:
4721 : 306009262 : if (!is_gimple_reg (lhs)
4722 : 83596269 : && !is_gimple_reg (rhs1)
4723 : 378700375 : && is_gimple_reg_type (TREE_TYPE (lhs)))
4724 : : {
4725 : 0 : error ("invalid RHS for gimple memory store: %qs", code_name);
4726 : 0 : debug_generic_stmt (lhs);
4727 : 0 : debug_generic_stmt (rhs1);
4728 : 0 : return true;
4729 : : }
4730 : : return res;
4731 : :
4732 : 295444018 : case CONSTRUCTOR:
4733 : 295444018 : if (VECTOR_TYPE_P (rhs1_type))
4734 : : {
4735 : 7185821 : unsigned int i;
4736 : 7185821 : tree elt_i, elt_v, elt_t = NULL_TREE;
4737 : :
4738 : 1624262677 : if (CONSTRUCTOR_NELTS (rhs1) == 0)
4739 : : return res;
4740 : : /* For vector CONSTRUCTORs we require that either it is empty
4741 : : CONSTRUCTOR, or it is a CONSTRUCTOR of smaller vector elements
4742 : : (then the element count must be correct to cover the whole
4743 : : outer vector and index must be NULL on all elements, or it is
4744 : : a CONSTRUCTOR of scalar elements, where we as an exception allow
4745 : : smaller number of elements (assuming zero filling) and
4746 : : consecutive indexes as compared to NULL indexes (such
4747 : : CONSTRUCTORs can appear in the IL from FEs). */
4748 : 27903462 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (rhs1), i, elt_i, elt_v)
4749 : : {
4750 : 21324404 : if (elt_t == NULL_TREE)
4751 : : {
4752 : 6579058 : elt_t = TREE_TYPE (elt_v);
4753 : 6579058 : if (VECTOR_TYPE_P (elt_t))
4754 : : {
4755 : 42681 : tree elt_t = TREE_TYPE (elt_v);
4756 : 42681 : if (!useless_type_conversion_p (TREE_TYPE (rhs1_type),
4757 : 42681 : TREE_TYPE (elt_t)))
4758 : : {
4759 : 0 : error ("incorrect type of vector %qs elements",
4760 : : code_name);
4761 : 0 : debug_generic_stmt (rhs1);
4762 : 0 : return true;
4763 : : }
4764 : 85362 : else if (maybe_ne (CONSTRUCTOR_NELTS (rhs1)
4765 : 85362 : * TYPE_VECTOR_SUBPARTS (elt_t),
4766 : 85362 : TYPE_VECTOR_SUBPARTS (rhs1_type)))
4767 : : {
4768 : 0 : error ("incorrect number of vector %qs elements",
4769 : : code_name);
4770 : 0 : debug_generic_stmt (rhs1);
4771 : 0 : return true;
4772 : : }
4773 : : }
4774 : 6536377 : else if (!useless_type_conversion_p (TREE_TYPE (rhs1_type),
4775 : : elt_t))
4776 : : {
4777 : 0 : error ("incorrect type of vector %qs elements",
4778 : : code_name);
4779 : 0 : debug_generic_stmt (rhs1);
4780 : 0 : return true;
4781 : : }
4782 : 13072754 : else if (maybe_gt (CONSTRUCTOR_NELTS (rhs1),
4783 : : TYPE_VECTOR_SUBPARTS (rhs1_type)))
4784 : : {
4785 : 0 : error ("incorrect number of vector %qs elements",
4786 : : code_name);
4787 : 0 : debug_generic_stmt (rhs1);
4788 : 0 : return true;
4789 : : }
4790 : : }
4791 : 14745346 : else if (!useless_type_conversion_p (elt_t, TREE_TYPE (elt_v)))
4792 : : {
4793 : 0 : error ("incorrect type of vector CONSTRUCTOR elements");
4794 : 0 : debug_generic_stmt (rhs1);
4795 : 0 : return true;
4796 : : }
4797 : 21324404 : if (elt_i != NULL_TREE
4798 : 21324404 : && (VECTOR_TYPE_P (elt_t)
4799 : 5688736 : || TREE_CODE (elt_i) != INTEGER_CST
4800 : 5688736 : || compare_tree_int (elt_i, i) != 0))
4801 : : {
4802 : 0 : error ("vector %qs with non-NULL element index",
4803 : : code_name);
4804 : 0 : debug_generic_stmt (rhs1);
4805 : 0 : return true;
4806 : : }
4807 : 21324404 : if (!is_gimple_val (elt_v))
4808 : : {
4809 : 0 : error ("vector %qs element is not a GIMPLE value",
4810 : : code_name);
4811 : 0 : debug_generic_stmt (rhs1);
4812 : 0 : return true;
4813 : : }
4814 : : }
4815 : : }
4816 : 288258197 : else if (CONSTRUCTOR_NELTS (rhs1) != 0)
4817 : : {
4818 : 0 : error ("non-vector %qs with elements", code_name);
4819 : 0 : debug_generic_stmt (rhs1);
4820 : 0 : return true;
4821 : : }
4822 : : return res;
4823 : :
4824 : : case OBJ_TYPE_REF:
4825 : : /* FIXME. */
4826 : : return res;
4827 : :
4828 : : default:;
4829 : : }
4830 : :
4831 : : return res;
4832 : : }
4833 : :
4834 : : /* Verify the contents of a GIMPLE_ASSIGN STMT. Returns true when there
4835 : : is a problem, otherwise false. */
4836 : :
4837 : : static bool
4838 : 4126176590 : verify_gimple_assign (gassign *stmt)
4839 : : {
4840 : 4126176590 : switch (gimple_assign_rhs_class (stmt))
4841 : : {
4842 : 2826434929 : case GIMPLE_SINGLE_RHS:
4843 : 2826434929 : return verify_gimple_assign_single (stmt);
4844 : :
4845 : 389952433 : case GIMPLE_UNARY_RHS:
4846 : 389952433 : return verify_gimple_assign_unary (stmt);
4847 : :
4848 : 902204991 : case GIMPLE_BINARY_RHS:
4849 : 902204991 : return verify_gimple_assign_binary (stmt);
4850 : :
4851 : 7584237 : case GIMPLE_TERNARY_RHS:
4852 : 7584237 : return verify_gimple_assign_ternary (stmt);
4853 : :
4854 : 0 : default:
4855 : 0 : gcc_unreachable ();
4856 : : }
4857 : : }
4858 : :
4859 : : /* Verify the contents of a GIMPLE_RETURN STMT. Returns true when there
4860 : : is a problem, otherwise false. */
4861 : :
4862 : : static bool
4863 : 235664323 : verify_gimple_return (greturn *stmt)
4864 : : {
4865 : 235664323 : tree op = gimple_return_retval (stmt);
4866 : 235664323 : tree restype = TREE_TYPE (TREE_TYPE (cfun->decl));
4867 : :
4868 : : /* We cannot test for present return values as we do not fix up missing
4869 : : return values from the original source. */
4870 : 235664323 : if (op == NULL)
4871 : : return false;
4872 : :
4873 : 130915676 : if (!is_gimple_val (op)
4874 : 130915676 : && TREE_CODE (op) != RESULT_DECL)
4875 : : {
4876 : 0 : error ("invalid operand in return statement");
4877 : 0 : debug_generic_stmt (op);
4878 : 0 : return true;
4879 : : }
4880 : :
4881 : 130915676 : if ((TREE_CODE (op) == RESULT_DECL
4882 : 9388039 : && DECL_BY_REFERENCE (op))
4883 : 139790347 : || (TREE_CODE (op) == SSA_NAME
4884 : 79199431 : && SSA_NAME_VAR (op)
4885 : 12637563 : && TREE_CODE (SSA_NAME_VAR (op)) == RESULT_DECL
4886 : 2117014 : && DECL_BY_REFERENCE (SSA_NAME_VAR (op))))
4887 : 2630382 : op = TREE_TYPE (op);
4888 : :
4889 : 130915676 : if (!useless_type_conversion_p (restype, TREE_TYPE (op)))
4890 : : {
4891 : 0 : error ("invalid conversion in return statement");
4892 : 0 : debug_generic_stmt (restype);
4893 : 0 : debug_generic_stmt (TREE_TYPE (op));
4894 : 0 : return true;
4895 : : }
4896 : :
4897 : : return false;
4898 : : }
4899 : :
4900 : :
4901 : : /* Verify the contents of a GIMPLE_GOTO STMT. Returns true when there
4902 : : is a problem, otherwise false. */
4903 : :
4904 : : static bool
4905 : 21435954 : verify_gimple_goto (ggoto *stmt)
4906 : : {
4907 : 21435954 : tree dest = gimple_goto_dest (stmt);
4908 : :
4909 : : /* ??? We have two canonical forms of direct goto destinations, a
4910 : : bare LABEL_DECL and an ADDR_EXPR of a LABEL_DECL. */
4911 : 21435954 : if (TREE_CODE (dest) != LABEL_DECL
4912 : 21435954 : && (!is_gimple_val (dest)
4913 : 58638 : || !POINTER_TYPE_P (TREE_TYPE (dest))))
4914 : : {
4915 : 0 : error ("goto destination is neither a label nor a pointer");
4916 : 0 : return true;
4917 : : }
4918 : :
4919 : : return false;
4920 : : }
4921 : :
4922 : : /* Verify the contents of a GIMPLE_SWITCH STMT. Returns true when there
4923 : : is a problem, otherwise false. */
4924 : :
4925 : : static bool
4926 : 4402476 : verify_gimple_switch (gswitch *stmt)
4927 : : {
4928 : 4402476 : unsigned int i, n;
4929 : 4402476 : tree elt, prev_upper_bound = NULL_TREE;
4930 : 4402476 : tree index_type, elt_type = NULL_TREE;
4931 : :
4932 : 4402476 : if (!is_gimple_val (gimple_switch_index (stmt)))
4933 : : {
4934 : 0 : error ("invalid operand to switch statement");
4935 : 0 : debug_generic_stmt (gimple_switch_index (stmt));
4936 : 0 : return true;
4937 : : }
4938 : :
4939 : 4402476 : index_type = TREE_TYPE (gimple_switch_index (stmt));
4940 : 4402476 : if (! INTEGRAL_TYPE_P (index_type))
4941 : : {
4942 : 0 : error ("non-integral type switch statement");
4943 : 0 : debug_generic_expr (index_type);
4944 : 0 : return true;
4945 : : }
4946 : :
4947 : 4402476 : elt = gimple_switch_label (stmt, 0);
4948 : 4402476 : if (CASE_LOW (elt) != NULL_TREE
4949 : 4402476 : || CASE_HIGH (elt) != NULL_TREE
4950 : 8804952 : || CASE_CHAIN (elt) != NULL_TREE)
4951 : : {
4952 : 0 : error ("invalid default case label in switch statement");
4953 : 0 : debug_generic_expr (elt);
4954 : 0 : return true;
4955 : : }
4956 : :
4957 : 4402476 : n = gimple_switch_num_labels (stmt);
4958 : 38958048 : for (i = 1; i < n; i++)
4959 : : {
4960 : 30153096 : elt = gimple_switch_label (stmt, i);
4961 : :
4962 : 30153096 : if (CASE_CHAIN (elt))
4963 : : {
4964 : 0 : error ("invalid %<CASE_CHAIN%>");
4965 : 0 : debug_generic_expr (elt);
4966 : 0 : return true;
4967 : : }
4968 : 30153096 : if (! CASE_LOW (elt))
4969 : : {
4970 : 0 : error ("invalid case label in switch statement");
4971 : 0 : debug_generic_expr (elt);
4972 : 0 : return true;
4973 : : }
4974 : 30153096 : if (CASE_HIGH (elt)
4975 : 30153096 : && ! tree_int_cst_lt (CASE_LOW (elt), CASE_HIGH (elt)))
4976 : : {
4977 : 0 : error ("invalid case range in switch statement");
4978 : 0 : debug_generic_expr (elt);
4979 : 0 : return true;
4980 : : }
4981 : :
4982 : 30153096 : if (! elt_type)
4983 : : {
4984 : 4399368 : elt_type = TREE_TYPE (CASE_LOW (elt));
4985 : 4399368 : if (TYPE_PRECISION (index_type) < TYPE_PRECISION (elt_type))
4986 : : {
4987 : 0 : error ("type precision mismatch in switch statement");
4988 : 0 : return true;
4989 : : }
4990 : : }
4991 : 30153096 : if (TREE_TYPE (CASE_LOW (elt)) != elt_type
4992 : 30153096 : || (CASE_HIGH (elt) && TREE_TYPE (CASE_HIGH (elt)) != elt_type))
4993 : : {
4994 : 0 : error ("type mismatch for case label in switch statement");
4995 : 0 : debug_generic_expr (elt);
4996 : 0 : return true;
4997 : : }
4998 : :
4999 : 30153096 : if (prev_upper_bound)
5000 : : {
5001 : 25753728 : if (! tree_int_cst_lt (prev_upper_bound, CASE_LOW (elt)))
5002 : : {
5003 : 0 : error ("case labels not sorted in switch statement");
5004 : 0 : return true;
5005 : : }
5006 : : }
5007 : :
5008 : 30153096 : prev_upper_bound = CASE_HIGH (elt);
5009 : 30153096 : if (! prev_upper_bound)
5010 : 27823849 : prev_upper_bound = CASE_LOW (elt);
5011 : : }
5012 : :
5013 : : return false;
5014 : : }
5015 : :
5016 : : /* Verify a gimple debug statement STMT.
5017 : : Returns true if anything is wrong. */
5018 : :
5019 : : static bool
5020 : 0 : verify_gimple_debug (gimple *stmt ATTRIBUTE_UNUSED)
5021 : : {
5022 : : /* There isn't much that could be wrong in a gimple debug stmt. A
5023 : : gimple debug bind stmt, for example, maps a tree, that's usually
5024 : : a VAR_DECL or a PARM_DECL, but that could also be some scalarized
5025 : : component or member of an aggregate type, to another tree, that
5026 : : can be an arbitrary expression. These stmts expand into debug
5027 : : insns, and are converted to debug notes by var-tracking.cc. */
5028 : 0 : return false;
5029 : : }
5030 : :
5031 : : /* Verify a gimple label statement STMT.
5032 : : Returns true if anything is wrong. */
5033 : :
5034 : : static bool
5035 : 204538188 : verify_gimple_label (glabel *stmt)
5036 : : {
5037 : 204538188 : tree decl = gimple_label_label (stmt);
5038 : 204538188 : int uid;
5039 : 204538188 : bool err = false;
5040 : :
5041 : 204538188 : if (TREE_CODE (decl) != LABEL_DECL)
5042 : : return true;
5043 : 409019621 : if (!DECL_NONLOCAL (decl) && !FORCED_LABEL (decl)
5044 : 407072175 : && DECL_CONTEXT (decl) != current_function_decl)
5045 : : {
5046 : 0 : error ("label context is not the current function declaration");
5047 : 0 : err |= true;
5048 : : }
5049 : :
5050 : 204538188 : uid = LABEL_DECL_UID (decl);
5051 : 204538188 : if (cfun->cfg
5052 : 204538188 : && (uid == -1
5053 : 129593111 : || (*label_to_block_map_for_fn (cfun))[uid] != gimple_bb (stmt)))
5054 : : {
5055 : 0 : error ("incorrect entry in %<label_to_block_map%>");
5056 : 0 : err |= true;
5057 : : }
5058 : :
5059 : 204538188 : uid = EH_LANDING_PAD_NR (decl);
5060 : 204538188 : if (uid)
5061 : : {
5062 : 72723944 : eh_landing_pad lp = get_eh_landing_pad_from_number (uid);
5063 : 72723944 : if (decl != lp->post_landing_pad)
5064 : : {
5065 : 0 : error ("incorrect setting of landing pad number");
5066 : 0 : err |= true;
5067 : : }
5068 : : }
5069 : :
5070 : : return err;
5071 : : }
5072 : :
5073 : : /* Verify a gimple cond statement STMT.
5074 : : Returns true if anything is wrong. */
5075 : :
5076 : : static bool
5077 : 659035325 : verify_gimple_cond (gcond *stmt)
5078 : : {
5079 : 659035325 : if (TREE_CODE_CLASS (gimple_cond_code (stmt)) != tcc_comparison)
5080 : : {
5081 : 0 : error ("invalid comparison code in gimple cond");
5082 : 0 : return true;
5083 : : }
5084 : 659035325 : if (!(!gimple_cond_true_label (stmt)
5085 : 25800541 : || TREE_CODE (gimple_cond_true_label (stmt)) == LABEL_DECL)
5086 : 684835866 : || !(!gimple_cond_false_label (stmt)
5087 : 25800541 : || TREE_CODE (gimple_cond_false_label (stmt)) == LABEL_DECL))
5088 : : {
5089 : 0 : error ("invalid labels in gimple cond");
5090 : 0 : return true;
5091 : : }
5092 : :
5093 : 659035325 : return verify_gimple_comparison (boolean_type_node,
5094 : : gimple_cond_lhs (stmt),
5095 : : gimple_cond_rhs (stmt),
5096 : 659035325 : gimple_cond_code (stmt));
5097 : : }
5098 : :
5099 : : /* Verify the GIMPLE statement STMT. Returns true if there is an
5100 : : error, otherwise false. */
5101 : :
5102 : : static bool
5103 : 11189757902 : verify_gimple_stmt (gimple *stmt)
5104 : : {
5105 : 11189757902 : switch (gimple_code (stmt))
5106 : : {
5107 : 4126176590 : case GIMPLE_ASSIGN:
5108 : 4126176590 : return verify_gimple_assign (as_a <gassign *> (stmt));
5109 : :
5110 : 204538188 : case GIMPLE_LABEL:
5111 : 204538188 : return verify_gimple_label (as_a <glabel *> (stmt));
5112 : :
5113 : 963151006 : case GIMPLE_CALL:
5114 : 963151006 : return verify_gimple_call (as_a <gcall *> (stmt));
5115 : :
5116 : 659035325 : case GIMPLE_COND:
5117 : 659035325 : return verify_gimple_cond (as_a <gcond *> (stmt));
5118 : :
5119 : 21435954 : case GIMPLE_GOTO:
5120 : 21435954 : return verify_gimple_goto (as_a <ggoto *> (stmt));
5121 : :
5122 : 4402476 : case GIMPLE_SWITCH:
5123 : 4402476 : return verify_gimple_switch (as_a <gswitch *> (stmt));
5124 : :
5125 : 235664323 : case GIMPLE_RETURN:
5126 : 235664323 : return verify_gimple_return (as_a <greturn *> (stmt));
5127 : :
5128 : : case GIMPLE_ASM:
5129 : : return false;
5130 : :
5131 : 34652 : case GIMPLE_TRANSACTION:
5132 : 34652 : return verify_gimple_transaction (as_a <gtransaction *> (stmt));
5133 : :
5134 : : /* Tuples that do not have tree operands. */
5135 : : case GIMPLE_NOP:
5136 : : case GIMPLE_PREDICT:
5137 : : case GIMPLE_RESX:
5138 : : case GIMPLE_EH_DISPATCH:
5139 : : case GIMPLE_EH_MUST_NOT_THROW:
5140 : : return false;
5141 : :
5142 : : CASE_GIMPLE_OMP:
5143 : : /* OpenMP directives are validated by the FE and never operated
5144 : : on by the optimizers. Furthermore, GIMPLE_OMP_FOR may contain
5145 : : non-gimple expressions when the main index variable has had
5146 : : its address taken. This does not affect the loop itself
5147 : : because the header of an GIMPLE_OMP_FOR is merely used to determine
5148 : : how to setup the parallel iteration. */
5149 : : return false;
5150 : :
5151 : : case GIMPLE_ASSUME:
5152 : : return false;
5153 : :
5154 : : case GIMPLE_DEBUG:
5155 : : return verify_gimple_debug (stmt);
5156 : :
5157 : 0 : default:
5158 : 0 : gcc_unreachable ();
5159 : : }
5160 : : }
5161 : :
5162 : : /* Verify the contents of a GIMPLE_PHI. Returns true if there is a problem,
5163 : : and false otherwise. */
5164 : :
5165 : : static bool
5166 : 592851858 : verify_gimple_phi (gphi *phi)
5167 : : {
5168 : 592851858 : bool err = false;
5169 : 592851858 : unsigned i;
5170 : 592851858 : tree phi_result = gimple_phi_result (phi);
5171 : 592851858 : bool virtual_p;
5172 : :
5173 : 592851858 : if (!phi_result)
5174 : : {
5175 : 0 : error ("invalid %<PHI%> result");
5176 : 0 : return true;
5177 : : }
5178 : :
5179 : 592851858 : virtual_p = virtual_operand_p (phi_result);
5180 : 592851858 : if (TREE_CODE (phi_result) != SSA_NAME
5181 : 592851858 : || (virtual_p
5182 : 289340240 : && SSA_NAME_VAR (phi_result) != gimple_vop (cfun)))
5183 : : {
5184 : 0 : error ("invalid %<PHI%> result");
5185 : 0 : err = true;
5186 : : }
5187 : :
5188 : 2066435428 : for (i = 0; i < gimple_phi_num_args (phi); i++)
5189 : : {
5190 : 1473583570 : tree t = gimple_phi_arg_def (phi, i);
5191 : :
5192 : 1473583570 : if (!t)
5193 : : {
5194 : 0 : error ("missing %<PHI%> def");
5195 : 0 : err |= true;
5196 : 0 : continue;
5197 : : }
5198 : : /* Addressable variables do have SSA_NAMEs but they
5199 : : are not considered gimple values. */
5200 : 1473583570 : else if ((TREE_CODE (t) == SSA_NAME
5201 : 1281650993 : && virtual_p != virtual_operand_p (t))
5202 : 1473583570 : || (virtual_p
5203 : 754356454 : && (TREE_CODE (t) != SSA_NAME
5204 : 754356454 : || SSA_NAME_VAR (t) != gimple_vop (cfun)))
5205 : 1473583570 : || (!virtual_p
5206 : 719227116 : && !is_gimple_val (t)))
5207 : : {
5208 : 0 : error ("invalid %<PHI%> argument");
5209 : 0 : debug_generic_expr (t);
5210 : 0 : err |= true;
5211 : : }
5212 : : #ifdef ENABLE_TYPES_CHECKING
5213 : 1473583570 : if (!useless_type_conversion_p (TREE_TYPE (phi_result), TREE_TYPE (t)))
5214 : : {
5215 : 0 : error ("incompatible types in %<PHI%> argument %u", i);
5216 : 0 : debug_generic_stmt (TREE_TYPE (phi_result));
5217 : 0 : debug_generic_stmt (TREE_TYPE (t));
5218 : 0 : err |= true;
5219 : : }
5220 : : #endif
5221 : : }
5222 : :
5223 : : return err;
5224 : : }
5225 : :
5226 : : /* Verify the GIMPLE statements inside the sequence STMTS. */
5227 : :
5228 : : static bool
5229 : 49528619 : verify_gimple_in_seq_2 (gimple_seq stmts)
5230 : : {
5231 : 49528619 : gimple_stmt_iterator ittr;
5232 : 49528619 : bool err = false;
5233 : :
5234 : 475232322 : for (ittr = gsi_start (stmts); !gsi_end_p (ittr); gsi_next (&ittr))
5235 : : {
5236 : 425703703 : gimple *stmt = gsi_stmt (ittr);
5237 : :
5238 : 425703703 : switch (gimple_code (stmt))
5239 : : {
5240 : 14119027 : case GIMPLE_BIND:
5241 : 14119027 : err |= verify_gimple_in_seq_2 (
5242 : 14119027 : gimple_bind_body (as_a <gbind *> (stmt)));
5243 : 14119027 : break;
5244 : :
5245 : 10054228 : case GIMPLE_TRY:
5246 : 10054228 : err |= verify_gimple_in_seq_2 (gimple_try_eval (stmt));
5247 : 10054228 : err |= verify_gimple_in_seq_2 (gimple_try_cleanup (stmt));
5248 : 10054228 : break;
5249 : :
5250 : 26192 : case GIMPLE_EH_FILTER:
5251 : 26192 : err |= verify_gimple_in_seq_2 (gimple_eh_filter_failure (stmt));
5252 : 26192 : break;
5253 : :
5254 : 1145 : case GIMPLE_EH_ELSE:
5255 : 1145 : {
5256 : 1145 : geh_else *eh_else = as_a <geh_else *> (stmt);
5257 : 1145 : err |= verify_gimple_in_seq_2 (gimple_eh_else_n_body (eh_else));
5258 : 1145 : err |= verify_gimple_in_seq_2 (gimple_eh_else_e_body (eh_else));
5259 : : }
5260 : 1145 : break;
5261 : :
5262 : 184142 : case GIMPLE_CATCH:
5263 : 184142 : err |= verify_gimple_in_seq_2 (gimple_catch_handler (
5264 : 184142 : as_a <gcatch *> (stmt)));
5265 : 184142 : break;
5266 : :
5267 : 309 : case GIMPLE_ASSUME:
5268 : 309 : err |= verify_gimple_in_seq_2 (gimple_assume_body (stmt));
5269 : 309 : break;
5270 : :
5271 : 3374 : case GIMPLE_TRANSACTION:
5272 : 3374 : err |= verify_gimple_transaction (as_a <gtransaction *> (stmt));
5273 : 3374 : break;
5274 : :
5275 : 401315286 : default:
5276 : 401315286 : {
5277 : 401315286 : bool err2 = verify_gimple_stmt (stmt);
5278 : 401315286 : if (err2)
5279 : 1 : debug_gimple_stmt (stmt);
5280 : 401315286 : err |= err2;
5281 : : }
5282 : : }
5283 : : }
5284 : :
5285 : 49528619 : return err;
5286 : : }
5287 : :
5288 : : /* Verify the contents of a GIMPLE_TRANSACTION. Returns true if there
5289 : : is a problem, otherwise false. */
5290 : :
5291 : : static bool
5292 : 38026 : verify_gimple_transaction (gtransaction *stmt)
5293 : : {
5294 : 38026 : tree lab;
5295 : :
5296 : 38026 : lab = gimple_transaction_label_norm (stmt);
5297 : 38026 : if (lab != NULL && TREE_CODE (lab) != LABEL_DECL)
5298 : : return true;
5299 : 38026 : lab = gimple_transaction_label_uninst (stmt);
5300 : 38026 : if (lab != NULL && TREE_CODE (lab) != LABEL_DECL)
5301 : : return true;
5302 : 38026 : lab = gimple_transaction_label_over (stmt);
5303 : 38026 : if (lab != NULL && TREE_CODE (lab) != LABEL_DECL)
5304 : : return true;
5305 : :
5306 : 38026 : return verify_gimple_in_seq_2 (gimple_transaction_body (stmt));
5307 : : }
5308 : :
5309 : :
5310 : : /* Verify the GIMPLE statements inside the statement list STMTS. */
5311 : :
5312 : : DEBUG_FUNCTION bool
5313 : 15050177 : verify_gimple_in_seq (gimple_seq stmts, bool ice)
5314 : : {
5315 : 15050177 : timevar_push (TV_TREE_STMT_VERIFY);
5316 : 15050177 : bool res = verify_gimple_in_seq_2 (stmts);
5317 : 15050177 : if (res && ice)
5318 : 0 : internal_error ("%<verify_gimple%> failed");
5319 : 15050177 : timevar_pop (TV_TREE_STMT_VERIFY);
5320 : 15050177 : return res;
5321 : : }
5322 : :
5323 : : /* Return true when the T can be shared. */
5324 : :
5325 : : static bool
5326 : 27957494513 : tree_node_can_be_shared (tree t)
5327 : : {
5328 : 27957494513 : if (IS_TYPE_OR_DECL_P (t)
5329 : 20003873802 : || TREE_CODE (t) == SSA_NAME
5330 : 10335187543 : || TREE_CODE (t) == IDENTIFIER_NODE
5331 : 10335187353 : || TREE_CODE (t) == CASE_LABEL_EXPR
5332 : 38263636705 : || is_gimple_min_invariant (t))
5333 : 23839041907 : return true;
5334 : :
5335 : 4118452606 : if (t == error_mark_node)
5336 : : return true;
5337 : :
5338 : : return false;
5339 : : }
5340 : :
5341 : : /* Called via walk_tree. Verify tree sharing. */
5342 : :
5343 : : static tree
5344 : 27957494513 : verify_node_sharing_1 (tree *tp, int *walk_subtrees, void *data)
5345 : : {
5346 : 27957494513 : hash_set<void *> *visited = (hash_set<void *> *) data;
5347 : :
5348 : 27957494513 : if (tree_node_can_be_shared (*tp))
5349 : : {
5350 : 23839041907 : *walk_subtrees = false;
5351 : 23839041907 : return NULL;
5352 : : }
5353 : :
5354 : 4118452606 : if (visited->add (*tp))
5355 : 0 : return *tp;
5356 : :
5357 : : return NULL;
5358 : : }
5359 : :
5360 : : /* Called via walk_gimple_stmt. Verify tree sharing. */
5361 : :
5362 : : static tree
5363 : 26483910943 : verify_node_sharing (tree *tp, int *walk_subtrees, void *data)
5364 : : {
5365 : 26483910943 : struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
5366 : 26483910943 : return verify_node_sharing_1 (tp, walk_subtrees, wi->info);
5367 : : }
5368 : :
5369 : : static bool eh_error_found;
5370 : : bool
5371 : 189518347 : verify_eh_throw_stmt_node (gimple *const &stmt, const int &,
5372 : : hash_set<gimple *> *visited)
5373 : : {
5374 : 189518347 : if (!visited->contains (stmt))
5375 : : {
5376 : 0 : error ("dead statement in EH table");
5377 : 0 : debug_gimple_stmt (stmt);
5378 : 0 : eh_error_found = true;
5379 : : }
5380 : 189518347 : return true;
5381 : : }
5382 : :
5383 : : /* Verify if the location LOCs block is in BLOCKS. */
5384 : :
5385 : : static bool
5386 : 20460868774 : verify_location (hash_set<tree> *blocks, location_t loc)
5387 : : {
5388 : 33679921404 : tree block = LOCATION_BLOCK (loc);
5389 : 33679921404 : if (block != NULL_TREE
5390 : 33679921404 : && !blocks->contains (block))
5391 : : {
5392 : 0 : error ("location references block not in block tree");
5393 : 0 : return true;
5394 : : }
5395 : 33679921404 : if (block != NULL_TREE)
5396 : 13219052630 : return verify_location (blocks, BLOCK_SOURCE_LOCATION (block));
5397 : : return false;
5398 : : }
5399 : :
5400 : : /* Called via walk_tree. Verify that expressions have no blocks. */
5401 : :
5402 : : static tree
5403 : 1354391773 : verify_expr_no_block (tree *tp, int *walk_subtrees, void *)
5404 : : {
5405 : 1354391773 : if (!EXPR_P (*tp))
5406 : : {
5407 : 836664426 : *walk_subtrees = false;
5408 : 836664426 : return NULL;
5409 : : }
5410 : :
5411 : 517727347 : location_t loc = EXPR_LOCATION (*tp);
5412 : 517727347 : if (LOCATION_BLOCK (loc) != NULL)
5413 : 0 : return *tp;
5414 : :
5415 : : return NULL;
5416 : : }
5417 : :
5418 : : /* Called via walk_tree. Verify locations of expressions. */
5419 : :
5420 : : static tree
5421 : 31072417782 : verify_expr_location_1 (tree *tp, int *walk_subtrees, void *data)
5422 : : {
5423 : 31072417782 : hash_set<tree> *blocks = (hash_set<tree> *) data;
5424 : 31072417782 : tree t = *tp;
5425 : :
5426 : : /* ??? This doesn't really belong here but there's no good place to
5427 : : stick this remainder of old verify_expr. */
5428 : : /* ??? This barfs on debug stmts which contain binds to vars with
5429 : : different function context. */
5430 : : #if 0
5431 : : if (VAR_P (t)
5432 : : || TREE_CODE (t) == PARM_DECL
5433 : : || TREE_CODE (t) == RESULT_DECL)
5434 : : {
5435 : : tree context = decl_function_context (t);
5436 : : if (context != cfun->decl
5437 : : && !SCOPE_FILE_SCOPE_P (context)
5438 : : && !TREE_STATIC (t)
5439 : : && !DECL_EXTERNAL (t))
5440 : : {
5441 : : error ("local declaration from a different function");
5442 : : return t;
5443 : : }
5444 : : }
5445 : : #endif
5446 : :
5447 : 31072417782 : if (VAR_P (t) && DECL_HAS_DEBUG_EXPR_P (t))
5448 : : {
5449 : 378647888 : tree x = DECL_DEBUG_EXPR (t);
5450 : 378647888 : tree addr = walk_tree (&x, verify_expr_no_block, NULL, NULL);
5451 : 378647888 : if (addr)
5452 : 0 : return addr;
5453 : : }
5454 : 31072417782 : if ((VAR_P (t)
5455 : : || TREE_CODE (t) == PARM_DECL
5456 : : || TREE_CODE (t) == RESULT_DECL)
5457 : 6472662650 : && DECL_HAS_VALUE_EXPR_P (t))
5458 : : {
5459 : 1622 : tree x = DECL_VALUE_EXPR (t);
5460 : 1622 : tree addr = walk_tree (&x, verify_expr_no_block, NULL, NULL);
5461 : 1622 : if (addr)
5462 : 0 : return addr;
5463 : : }
5464 : :
5465 : 31072417782 : if (!EXPR_P (t))
5466 : : {
5467 : 24474771737 : *walk_subtrees = false;
5468 : 24474771737 : return NULL;
5469 : : }
5470 : :
5471 : 6597646045 : location_t loc = EXPR_LOCATION (t);
5472 : 6597646045 : if (verify_location (blocks, loc))
5473 : : return t;
5474 : :
5475 : : return NULL;
5476 : : }
5477 : :
5478 : : /* Called via walk_gimple_op. Verify locations of expressions. */
5479 : :
5480 : : static tree
5481 : 29573073939 : verify_expr_location (tree *tp, int *walk_subtrees, void *data)
5482 : : {
5483 : 29573073939 : struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
5484 : 29573073939 : return verify_expr_location_1 (tp, walk_subtrees, wi->info);
5485 : : }
5486 : :
5487 : : /* Insert all subblocks of BLOCK into BLOCKS and recurse. */
5488 : :
5489 : : static void
5490 : 2081736736 : collect_subblocks (hash_set<tree> *blocks, tree block)
5491 : : {
5492 : 2081736736 : tree t;
5493 : 3936819304 : for (t = BLOCK_SUBBLOCKS (block); t; t = BLOCK_CHAIN (t))
5494 : : {
5495 : 1855082568 : blocks->add (t);
5496 : 1855082568 : collect_subblocks (blocks, t);
5497 : : }
5498 : 2081736736 : }
5499 : :
5500 : : /* Disable warnings about missing quoting in GCC diagnostics for
5501 : : the verification errors. Their format strings don't follow
5502 : : GCC diagnostic conventions and trigger an ICE in the end. */
5503 : : #if __GNUC__ >= 10
5504 : : # pragma GCC diagnostic push
5505 : : # pragma GCC diagnostic ignored "-Wformat-diag"
5506 : : #endif
5507 : :
5508 : : /* Verify the GIMPLE statements in the CFG of FN. */
5509 : :
5510 : : DEBUG_FUNCTION bool
5511 : 226654168 : verify_gimple_in_cfg (struct function *fn, bool verify_nothrow, bool ice)
5512 : : {
5513 : 226654168 : basic_block bb;
5514 : 226654168 : bool err = false;
5515 : :
5516 : 226654168 : timevar_push (TV_TREE_STMT_VERIFY);
5517 : 226654168 : hash_set<void *> visited;
5518 : 226654168 : hash_set<gimple *> visited_throwing_stmts;
5519 : :
5520 : : /* Collect all BLOCKs referenced by the BLOCK tree of FN. */
5521 : 226654168 : hash_set<tree> blocks;
5522 : 226654168 : if (DECL_INITIAL (fn->decl))
5523 : : {
5524 : 226654168 : blocks.add (DECL_INITIAL (fn->decl));
5525 : 226654168 : collect_subblocks (&blocks, DECL_INITIAL (fn->decl));
5526 : : }
5527 : :
5528 : 1984311374 : FOR_EACH_BB_FN (bb, fn)
5529 : : {
5530 : 1757657206 : gimple_stmt_iterator gsi;
5531 : 1757657206 : edge_iterator ei;
5532 : 1757657206 : edge e;
5533 : :
5534 : 1757657206 : for (gphi_iterator gpi = gsi_start_phis (bb);
5535 : 2350509064 : !gsi_end_p (gpi);
5536 : 592851858 : gsi_next (&gpi))
5537 : : {
5538 : 592851858 : gphi *phi = gpi.phi ();
5539 : 592851858 : bool err2 = false;
5540 : 592851858 : unsigned i;
5541 : :
5542 : 592851858 : if (gimple_bb (phi) != bb)
5543 : : {
5544 : 0 : error ("gimple_bb (phi) is set to a wrong basic block");
5545 : 0 : err2 = true;
5546 : : }
5547 : :
5548 : 592851858 : err2 |= verify_gimple_phi (phi);
5549 : :
5550 : : /* Only PHI arguments have locations. */
5551 : 592851858 : if (gimple_location (phi) != UNKNOWN_LOCATION)
5552 : : {
5553 : 0 : error ("PHI node with location");
5554 : 0 : err2 = true;
5555 : : }
5556 : :
5557 : 2066435428 : for (i = 0; i < gimple_phi_num_args (phi); i++)
5558 : : {
5559 : 1473583570 : tree arg = gimple_phi_arg_def (phi, i);
5560 : 1473583570 : tree addr = walk_tree (&arg, verify_node_sharing_1,
5561 : : &visited, NULL);
5562 : 1473583570 : if (addr)
5563 : : {
5564 : 0 : error ("incorrect sharing of tree nodes");
5565 : 0 : debug_generic_expr (addr);
5566 : 0 : err2 |= true;
5567 : : }
5568 : 1473583570 : location_t loc = gimple_phi_arg_location (phi, i);
5569 : 1473583570 : if (virtual_operand_p (gimple_phi_result (phi))
5570 : 1473583570 : && loc != UNKNOWN_LOCATION)
5571 : : {
5572 : 0 : error ("virtual PHI with argument locations");
5573 : 0 : err2 = true;
5574 : : }
5575 : 1473583570 : addr = walk_tree (&arg, verify_expr_location_1, &blocks, NULL);
5576 : 1473583570 : if (addr)
5577 : : {
5578 : 0 : debug_generic_expr (addr);
5579 : 0 : err2 = true;
5580 : : }
5581 : 1473583570 : err2 |= verify_location (&blocks, loc);
5582 : : }
5583 : :
5584 : 592851858 : if (err2)
5585 : 0 : debug_gimple_stmt (phi);
5586 : 592851858 : err |= err2;
5587 : : }
5588 : :
5589 : 14303757028 : for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
5590 : : {
5591 : 10788442616 : gimple *stmt = gsi_stmt (gsi);
5592 : 10788442616 : bool err2 = false;
5593 : 10788442616 : struct walk_stmt_info wi;
5594 : 10788442616 : tree addr;
5595 : 10788442616 : int lp_nr;
5596 : :
5597 : 10788442616 : if (gimple_bb (stmt) != bb)
5598 : : {
5599 : 0 : error ("gimple_bb (stmt) is set to a wrong basic block");
5600 : 0 : err2 = true;
5601 : : }
5602 : :
5603 : 10788442616 : err2 |= verify_gimple_stmt (stmt);
5604 : 10788442616 : err2 |= verify_location (&blocks, gimple_location (stmt));
5605 : :
5606 : 10788442616 : memset (&wi, 0, sizeof (wi));
5607 : 10788442616 : wi.info = (void *) &visited;
5608 : 10788442616 : addr = walk_gimple_op (stmt, verify_node_sharing, &wi);
5609 : 10788442616 : if (addr)
5610 : : {
5611 : 0 : error ("incorrect sharing of tree nodes");
5612 : 0 : debug_generic_expr (addr);
5613 : 0 : err2 |= true;
5614 : : }
5615 : :
5616 : 10788442616 : memset (&wi, 0, sizeof (wi));
5617 : 10788442616 : wi.info = (void *) &blocks;
5618 : 10788442616 : addr = walk_gimple_op (stmt, verify_expr_location, &wi);
5619 : 10788442616 : if (addr)
5620 : : {
5621 : 0 : debug_generic_expr (addr);
5622 : 0 : err2 |= true;
5623 : : }
5624 : :
5625 : : /* If the statement is marked as part of an EH region, then it is
5626 : : expected that the statement could throw. Verify that when we
5627 : : have optimizations that simplify statements such that we prove
5628 : : that they cannot throw, that we update other data structures
5629 : : to match. */
5630 : 10788442616 : lp_nr = lookup_stmt_eh_lp (stmt);
5631 : 10788442616 : if (lp_nr != 0)
5632 : 189518347 : visited_throwing_stmts.add (stmt);
5633 : 189518347 : if (lp_nr > 0)
5634 : : {
5635 : 182788179 : if (!stmt_could_throw_p (cfun, stmt))
5636 : : {
5637 : 19 : if (verify_nothrow)
5638 : : {
5639 : 0 : error ("statement marked for throw, but doesn%'t");
5640 : 0 : err2 |= true;
5641 : : }
5642 : : }
5643 : 182788160 : else if (!gsi_one_before_end_p (gsi))
5644 : : {
5645 : 0 : error ("statement marked for throw in middle of block");
5646 : 0 : err2 |= true;
5647 : : }
5648 : : }
5649 : :
5650 : 10788442616 : if (err2)
5651 : 0 : debug_gimple_stmt (stmt);
5652 : 10788442616 : err |= err2;
5653 : : }
5654 : :
5655 : 4195468589 : FOR_EACH_EDGE (e, ei, bb->succs)
5656 : 2437811383 : if (e->goto_locus != UNKNOWN_LOCATION)
5657 : 1601196543 : err |= verify_location (&blocks, e->goto_locus);
5658 : : }
5659 : :
5660 : 226654168 : hash_map<gimple *, int> *eh_table = get_eh_throw_stmt_table (cfun);
5661 : 226654168 : eh_error_found = false;
5662 : 226654168 : if (eh_table)
5663 : 32307261 : eh_table->traverse<hash_set<gimple *> *, verify_eh_throw_stmt_node>
5664 : 32307261 : (&visited_throwing_stmts);
5665 : :
5666 : 226654168 : if (ice && (err || eh_error_found))
5667 : 0 : internal_error ("verify_gimple failed");
5668 : :
5669 : 226654168 : verify_histograms ();
5670 : 226654168 : timevar_pop (TV_TREE_STMT_VERIFY);
5671 : :
5672 : 226654168 : return (err || eh_error_found);
5673 : 226654168 : }
5674 : :
5675 : :
5676 : : /* Verifies that the flow information is OK. */
5677 : :
5678 : : static bool
5679 : 217269426 : gimple_verify_flow_info (void)
5680 : : {
5681 : 217269426 : bool err = false;
5682 : 217269426 : basic_block bb;
5683 : 217269426 : gimple_stmt_iterator gsi;
5684 : 217269426 : gimple *stmt;
5685 : 217269426 : edge e;
5686 : 217269426 : edge_iterator ei;
5687 : :
5688 : 217269426 : if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->il.gimple.seq
5689 : 217269426 : || ENTRY_BLOCK_PTR_FOR_FN (cfun)->il.gimple.phi_nodes)
5690 : : {
5691 : 0 : error ("ENTRY_BLOCK has IL associated with it");
5692 : 0 : err = true;
5693 : : }
5694 : :
5695 : 217269426 : if (EXIT_BLOCK_PTR_FOR_FN (cfun)->il.gimple.seq
5696 : 217269426 : || EXIT_BLOCK_PTR_FOR_FN (cfun)->il.gimple.phi_nodes)
5697 : : {
5698 : 0 : error ("EXIT_BLOCK has IL associated with it");
5699 : 0 : err = true;
5700 : : }
5701 : :
5702 : 430691071 : FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
5703 : 213421645 : if (e->flags & EDGE_FALLTHRU)
5704 : : {
5705 : 0 : error ("fallthru to exit from bb %d", e->src->index);
5706 : 0 : err = true;
5707 : : }
5708 : 217269426 : if (cfun->cfg->full_profile
5709 : 217269426 : && !ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.initialized_p ())
5710 : : {
5711 : 0 : error ("entry block count not initialized");
5712 : 0 : err = true;
5713 : : }
5714 : 217269426 : if (cfun->cfg->full_profile
5715 : 217269426 : && !EXIT_BLOCK_PTR_FOR_FN (cfun)->count.initialized_p ())
5716 : : {
5717 : 0 : error ("exit block count not initialized");
5718 : 0 : err = true;
5719 : : }
5720 : 217269426 : if (cfun->cfg->full_profile
5721 : 328748374 : && !single_succ_edge
5722 : 111478948 : (ENTRY_BLOCK_PTR_FOR_FN (cfun))->probability.initialized_p ())
5723 : : {
5724 : 0 : error ("probability of edge from entry block not initialized");
5725 : 0 : err = true;
5726 : : }
5727 : :
5728 : :
5729 : 2013332124 : FOR_EACH_BB_FN (bb, cfun)
5730 : : {
5731 : 1796062698 : bool found_ctrl_stmt = false;
5732 : :
5733 : 1796062698 : stmt = NULL;
5734 : :
5735 : 1796062698 : if (cfun->cfg->full_profile)
5736 : : {
5737 : 1167073522 : if (!bb->count.initialized_p ())
5738 : : {
5739 : 0 : error ("count of bb %d not initialized", bb->index);
5740 : 0 : err = true;
5741 : : }
5742 : 2814381003 : FOR_EACH_EDGE (e, ei, bb->succs)
5743 : 1647307481 : if (!e->probability.initialized_p ())
5744 : : {
5745 : 0 : error ("probability of edge %d->%d not initialized",
5746 : 0 : bb->index, e->dest->index);
5747 : 0 : err = true;
5748 : : }
5749 : : }
5750 : :
5751 : : /* Skip labels on the start of basic block. */
5752 : 3728814873 : for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
5753 : : {
5754 : 1782553377 : tree label;
5755 : 1782553377 : gimple *prev_stmt = stmt;
5756 : :
5757 : 1782553377 : stmt = gsi_stmt (gsi);
5758 : :
5759 : 1782553377 : if (gimple_code (stmt) != GIMPLE_LABEL)
5760 : : break;
5761 : :
5762 : 136689477 : label = gimple_label_label (as_a <glabel *> (stmt));
5763 : 136689477 : if (prev_stmt && DECL_NONLOCAL (label))
5764 : : {
5765 : 0 : error ("nonlocal label %qD is not first in a sequence "
5766 : : "of labels in bb %d", label, bb->index);
5767 : 0 : err = true;
5768 : : }
5769 : :
5770 : 137799290 : if (prev_stmt && EH_LANDING_PAD_NR (label) != 0)
5771 : : {
5772 : 0 : error ("EH landing pad label %qD is not first in a sequence "
5773 : : "of labels in bb %d", label, bb->index);
5774 : 0 : err = true;
5775 : : }
5776 : :
5777 : 136689477 : if (label_to_block (cfun, label) != bb)
5778 : : {
5779 : 0 : error ("label %qD to block does not match in bb %d",
5780 : : label, bb->index);
5781 : 0 : err = true;
5782 : : }
5783 : :
5784 : 136689477 : if (decl_function_context (label) != current_function_decl)
5785 : : {
5786 : 0 : error ("label %qD has incorrect context in bb %d",
5787 : : label, bb->index);
5788 : 0 : err = true;
5789 : : }
5790 : : }
5791 : :
5792 : : /* Verify that body of basic block BB is free of control flow. */
5793 : : bool seen_nondebug_stmt = false;
5794 : 13370596901 : for (; !gsi_end_p (gsi); gsi_next (&gsi))
5795 : : {
5796 : 11574534203 : gimple *stmt = gsi_stmt (gsi);
5797 : :
5798 : : /* Do NOT disregard debug stmts after found_ctrl_stmt. */
5799 : 11574534203 : if (found_ctrl_stmt)
5800 : : {
5801 : 0 : error ("control flow in the middle of basic block %d",
5802 : : bb->index);
5803 : 0 : err = true;
5804 : : }
5805 : :
5806 : 11574534203 : if (stmt_ends_bb_p (stmt))
5807 : 1203119205 : found_ctrl_stmt = true;
5808 : :
5809 : 11574534203 : if (glabel *label_stmt = dyn_cast <glabel *> (stmt))
5810 : : {
5811 : 0 : error ("label %qD in the middle of basic block %d",
5812 : : gimple_label_label (label_stmt), bb->index);
5813 : 0 : err = true;
5814 : : }
5815 : :
5816 : : /* Check that no statements appear between a returns_twice call
5817 : : and its associated abnormal edge. */
5818 : 11574534203 : if (gimple_code (stmt) == GIMPLE_CALL
5819 : 11574534203 : && gimple_call_flags (stmt) & ECF_RETURNS_TWICE)
5820 : : {
5821 : 126995 : bool misplaced = false;
5822 : : /* TM is an exception: it points abnormal edges just after the
5823 : : call that starts a transaction, i.e. it must end the BB. */
5824 : 126995 : if (gimple_call_builtin_p (stmt, BUILT_IN_TM_START))
5825 : : {
5826 : 4320 : if (single_succ_p (bb)
5827 : 3406 : && bb_has_abnormal_pred (single_succ (bb))
5828 : 6987 : && !gsi_one_nondebug_before_end_p (gsi))
5829 : : {
5830 : 0 : error ("returns_twice call is not last in basic block "
5831 : : "%d", bb->index);
5832 : 0 : misplaced = true;
5833 : : }
5834 : : }
5835 : : else
5836 : : {
5837 : 122675 : if (seen_nondebug_stmt && bb_has_abnormal_pred (bb))
5838 : : {
5839 : 0 : error ("returns_twice call is not first in basic block "
5840 : : "%d", bb->index);
5841 : 0 : misplaced = true;
5842 : : }
5843 : : }
5844 : 0 : if (misplaced)
5845 : : {
5846 : 0 : print_gimple_stmt (stderr, stmt, 0, TDF_SLIM);
5847 : 0 : err = true;
5848 : : }
5849 : : }
5850 : 11574534203 : if (!is_gimple_debug (stmt))
5851 : 5927258373 : seen_nondebug_stmt = true;
5852 : : }
5853 : :
5854 : 1796062698 : gsi = gsi_last_nondebug_bb (bb);
5855 : 1796062698 : if (gsi_end_p (gsi))
5856 : 121203319 : continue;
5857 : :
5858 : 1674859379 : stmt = gsi_stmt (gsi);
5859 : :
5860 : 1674859379 : if (gimple_code (stmt) == GIMPLE_LABEL)
5861 : 41958027 : continue;
5862 : :
5863 : 1632901352 : if (verify_eh_edges (stmt))
5864 : 0 : err = true;
5865 : :
5866 : 1632901352 : if (is_ctrl_stmt (stmt))
5867 : : {
5868 : 2507721844 : FOR_EACH_EDGE (e, ei, bb->succs)
5869 : 1586344031 : if (e->flags & EDGE_FALLTHRU)
5870 : : {
5871 : 0 : error ("fallthru edge after a control statement in bb %d",
5872 : : bb->index);
5873 : 0 : err = true;
5874 : : }
5875 : : }
5876 : :
5877 : 1632901352 : if (gimple_code (stmt) != GIMPLE_COND)
5878 : : {
5879 : : /* Verify that there are no edges with EDGE_TRUE/FALSE_FLAG set
5880 : : after anything else but if statement. */
5881 : 1996386311 : FOR_EACH_EDGE (e, ei, bb->succs)
5882 : 1025580625 : if (e->flags & (EDGE_TRUE_VALUE | EDGE_FALSE_VALUE))
5883 : : {
5884 : 0 : error ("true/false edge after a non-GIMPLE_COND in bb %d",
5885 : : bb->index);
5886 : 0 : err = true;
5887 : : }
5888 : : }
5889 : :
5890 : 1632901352 : switch (gimple_code (stmt))
5891 : : {
5892 : 662095666 : case GIMPLE_COND:
5893 : 662095666 : {
5894 : 662095666 : edge true_edge;
5895 : 662095666 : edge false_edge;
5896 : :
5897 : 662095666 : extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
5898 : :
5899 : 662095666 : if (!true_edge
5900 : 662095666 : || !false_edge
5901 : 662095666 : || !(true_edge->flags & EDGE_TRUE_VALUE)
5902 : 662095666 : || !(false_edge->flags & EDGE_FALSE_VALUE)
5903 : 662095666 : || (true_edge->flags & (EDGE_FALLTHRU | EDGE_ABNORMAL))
5904 : 662095666 : || (false_edge->flags & (EDGE_FALLTHRU | EDGE_ABNORMAL))
5905 : 1324191332 : || EDGE_COUNT (bb->succs) >= 3)
5906 : : {
5907 : 0 : error ("wrong outgoing edge flags at end of bb %d",
5908 : : bb->index);
5909 : 0 : err = true;
5910 : : }
5911 : : }
5912 : 662095666 : break;
5913 : :
5914 : 50052 : case GIMPLE_GOTO:
5915 : 50052 : if (simple_goto_p (stmt))
5916 : : {
5917 : 0 : error ("explicit goto at end of bb %d", bb->index);
5918 : 0 : err = true;
5919 : : }
5920 : : else
5921 : : {
5922 : : /* FIXME. We should double check that the labels in the
5923 : : destination blocks have their address taken. */
5924 : 180497 : FOR_EACH_EDGE (e, ei, bb->succs)
5925 : 130445 : if ((e->flags & (EDGE_FALLTHRU | EDGE_TRUE_VALUE
5926 : : | EDGE_FALSE_VALUE))
5927 : 130445 : || !(e->flags & EDGE_ABNORMAL))
5928 : : {
5929 : 0 : error ("wrong outgoing edge flags at end of bb %d",
5930 : : bb->index);
5931 : 0 : err = true;
5932 : : }
5933 : : }
5934 : : break;
5935 : :
5936 : 349486915 : case GIMPLE_CALL:
5937 : 349486915 : if (!gimple_call_builtin_p (stmt, BUILT_IN_RETURN))
5938 : : break;
5939 : : /* fallthru */
5940 : 213418589 : case GIMPLE_RETURN:
5941 : 213418589 : if (!single_succ_p (bb)
5942 : 213418589 : || (single_succ_edge (bb)->flags
5943 : 213418589 : & (EDGE_FALLTHRU | EDGE_ABNORMAL
5944 : : | EDGE_TRUE_VALUE | EDGE_FALSE_VALUE)))
5945 : : {
5946 : 0 : error ("wrong outgoing edge flags at end of bb %d", bb->index);
5947 : 0 : err = true;
5948 : : }
5949 : 213418589 : if (single_succ (bb) != EXIT_BLOCK_PTR_FOR_FN (cfun))
5950 : : {
5951 : 0 : error ("return edge does not point to exit in bb %d",
5952 : : bb->index);
5953 : 0 : err = true;
5954 : : }
5955 : : break;
5956 : :
5957 : 4017890 : case GIMPLE_SWITCH:
5958 : 4017890 : {
5959 : 4017890 : gswitch *switch_stmt = as_a <gswitch *> (stmt);
5960 : 4017890 : tree prev;
5961 : 4017890 : edge e;
5962 : 4017890 : size_t i, n;
5963 : :
5964 : 4017890 : n = gimple_switch_num_labels (switch_stmt);
5965 : :
5966 : : /* Mark all the destination basic blocks. */
5967 : 32482580 : for (i = 0; i < n; ++i)
5968 : : {
5969 : 28464690 : basic_block label_bb = gimple_switch_label_bb (cfun, switch_stmt, i);
5970 : 28464690 : gcc_assert (!label_bb->aux || label_bb->aux == (void *)1);
5971 : 28464690 : label_bb->aux = (void *)1;
5972 : : }
5973 : :
5974 : : /* Verify that the case labels are sorted. */
5975 : 4017890 : prev = gimple_switch_label (switch_stmt, 0);
5976 : 28464690 : for (i = 1; i < n; ++i)
5977 : : {
5978 : 24446800 : tree c = gimple_switch_label (switch_stmt, i);
5979 : 24446800 : if (!CASE_LOW (c))
5980 : : {
5981 : 0 : error ("found default case not at the start of "
5982 : : "case vector");
5983 : 0 : err = true;
5984 : 0 : continue;
5985 : : }
5986 : 24446800 : if (CASE_LOW (prev)
5987 : 24446800 : && !tree_int_cst_lt (CASE_LOW (prev), CASE_LOW (c)))
5988 : : {
5989 : 0 : error ("case labels not sorted: ");
5990 : 0 : print_generic_expr (stderr, prev);
5991 : 0 : fprintf (stderr," is greater than ");
5992 : 0 : print_generic_expr (stderr, c);
5993 : 0 : fprintf (stderr," but comes before it.\n");
5994 : 0 : err = true;
5995 : : }
5996 : : prev = c;
5997 : : }
5998 : : /* VRP will remove the default case if it can prove it will
5999 : : never be executed. So do not verify there always exists
6000 : : a default case here. */
6001 : :
6002 : 28795508 : FOR_EACH_EDGE (e, ei, bb->succs)
6003 : : {
6004 : 24777618 : if (!e->dest->aux)
6005 : : {
6006 : 0 : error ("extra outgoing edge %d->%d",
6007 : : bb->index, e->dest->index);
6008 : 0 : err = true;
6009 : : }
6010 : :
6011 : 24777618 : e->dest->aux = (void *)2;
6012 : 24777618 : if ((e->flags & (EDGE_FALLTHRU | EDGE_ABNORMAL
6013 : : | EDGE_TRUE_VALUE | EDGE_FALSE_VALUE)))
6014 : : {
6015 : 0 : error ("wrong outgoing edge flags at end of bb %d",
6016 : : bb->index);
6017 : 0 : err = true;
6018 : : }
6019 : : }
6020 : :
6021 : : /* Check that we have all of them. */
6022 : 32482580 : for (i = 0; i < n; ++i)
6023 : : {
6024 : 28464690 : basic_block label_bb = gimple_switch_label_bb (cfun,
6025 : : switch_stmt, i);
6026 : :
6027 : 28464690 : if (label_bb->aux != (void *)2)
6028 : : {
6029 : 0 : error ("missing edge %i->%i", bb->index, label_bb->index);
6030 : 0 : err = true;
6031 : : }
6032 : : }
6033 : :
6034 : 28795508 : FOR_EACH_EDGE (e, ei, bb->succs)
6035 : 24777618 : e->dest->aux = (void *)0;
6036 : : }
6037 : 4017890 : break;
6038 : :
6039 : 1897912 : case GIMPLE_EH_DISPATCH:
6040 : 1897912 : if (verify_eh_dispatch_edge (as_a <geh_dispatch *> (stmt)))
6041 : 0 : err = true;
6042 : : break;
6043 : :
6044 : : default:
6045 : : break;
6046 : : }
6047 : : }
6048 : :
6049 : 217269426 : if (dom_info_state (CDI_DOMINATORS) >= DOM_NO_FAST_QUERY)
6050 : 176084767 : verify_dominators (CDI_DOMINATORS);
6051 : :
6052 : 217269426 : return err;
6053 : : }
6054 : :
6055 : : #if __GNUC__ >= 10
6056 : : # pragma GCC diagnostic pop
6057 : : #endif
6058 : :
6059 : : /* Updates phi nodes after creating a forwarder block joined
6060 : : by edge FALLTHRU. */
6061 : :
6062 : : static void
6063 : 185658 : gimple_make_forwarder_block (edge fallthru)
6064 : : {
6065 : 185658 : edge e;
6066 : 185658 : edge_iterator ei;
6067 : 185658 : basic_block dummy, bb;
6068 : 185658 : tree var;
6069 : 185658 : gphi_iterator gsi;
6070 : 185658 : bool forward_location_p;
6071 : :
6072 : 185658 : dummy = fallthru->src;
6073 : 185658 : bb = fallthru->dest;
6074 : :
6075 : 185658 : if (single_pred_p (bb))
6076 : 129 : return;
6077 : :
6078 : : /* We can forward location info if we have only one predecessor. */
6079 : 185529 : forward_location_p = single_pred_p (dummy);
6080 : :
6081 : : /* If we redirected a branch we must create new PHI nodes at the
6082 : : start of BB. */
6083 : 635885 : for (gsi = gsi_start_phis (dummy); !gsi_end_p (gsi); gsi_next (&gsi))
6084 : : {
6085 : 450356 : gphi *phi, *new_phi;
6086 : :
6087 : 450356 : phi = gsi.phi ();
6088 : 450356 : var = gimple_phi_result (phi);
6089 : 450356 : new_phi = create_phi_node (var, bb);
6090 : 450356 : gimple_phi_set_result (phi, copy_ssa_name (var, phi));
6091 : 450408 : add_phi_arg (new_phi, gimple_phi_result (phi), fallthru,
6092 : : forward_location_p
6093 : 52 : ? gimple_phi_arg_location (phi, 0) : UNKNOWN_LOCATION);
6094 : : }
6095 : :
6096 : : /* Add the arguments we have stored on edges. */
6097 : 564887 : FOR_EACH_EDGE (e, ei, bb->preds)
6098 : : {
6099 : 379358 : if (e == fallthru)
6100 : 185529 : continue;
6101 : :
6102 : 193829 : flush_pending_stmts (e);
6103 : : }
6104 : : }
6105 : :
6106 : :
6107 : : /* Return a non-special label in the head of basic block BLOCK.
6108 : : Create one if it doesn't exist. */
6109 : :
6110 : : tree
6111 : 5910650 : gimple_block_label (basic_block bb)
6112 : : {
6113 : 5910650 : gimple_stmt_iterator i, s = gsi_start_bb (bb);
6114 : 5910650 : bool first = true;
6115 : 5910650 : tree label;
6116 : 5910650 : glabel *stmt;
6117 : :
6118 : 5910650 : for (i = s; !gsi_end_p (i); first = false, gsi_next (&i))
6119 : : {
6120 : 4725060 : stmt = dyn_cast <glabel *> (gsi_stmt (i));
6121 : 4636435 : if (!stmt)
6122 : : break;
6123 : 4636435 : label = gimple_label_label (stmt);
6124 : 4636435 : if (!DECL_NONLOCAL (label))
6125 : : {
6126 : 4636435 : if (!first)
6127 : 0 : gsi_move_before (&i, &s);
6128 : 4636435 : return label;
6129 : : }
6130 : : }
6131 : :
6132 : 1274215 : label = create_artificial_label (UNKNOWN_LOCATION);
6133 : 1274215 : stmt = gimple_build_label (label);
6134 : 1274215 : gsi_insert_before (&s, stmt, GSI_NEW_STMT);
6135 : 1274215 : return label;
6136 : : }
6137 : :
6138 : :
6139 : : /* Attempt to perform edge redirection by replacing a possibly complex
6140 : : jump instruction by a goto or by removing the jump completely.
6141 : : This can apply only if all edges now point to the same block. The
6142 : : parameters and return values are equivalent to
6143 : : redirect_edge_and_branch. */
6144 : :
6145 : : static edge
6146 : 53981599 : gimple_try_redirect_by_replacing_jump (edge e, basic_block target)
6147 : : {
6148 : 53981599 : basic_block src = e->src;
6149 : 53981599 : gimple_stmt_iterator i;
6150 : 53981599 : gimple *stmt;
6151 : :
6152 : : /* We can replace or remove a complex jump only when we have exactly
6153 : : two edges. */
6154 : 107673233 : if (EDGE_COUNT (src->succs) != 2
6155 : : /* Verify that all targets will be TARGET. Specifically, the
6156 : : edge that is not E must also go to TARGET. */
6157 : 53981599 : || EDGE_SUCC (src, EDGE_SUCC (src, 0) == e)->dest != target)
6158 : : return NULL;
6159 : :
6160 : 289995 : i = gsi_last_bb (src);
6161 : 289995 : if (gsi_end_p (i))
6162 : : return NULL;
6163 : :
6164 : 289995 : stmt = gsi_stmt (i);
6165 : :
6166 : 289995 : if (gimple_code (stmt) == GIMPLE_COND || gimple_code (stmt) == GIMPLE_SWITCH)
6167 : : {
6168 : 289965 : gsi_remove (&i, true);
6169 : 289965 : e = ssa_redirect_edge (e, target);
6170 : 289965 : e->flags = EDGE_FALLTHRU;
6171 : 289965 : return e;
6172 : : }
6173 : :
6174 : : return NULL;
6175 : : }
6176 : :
6177 : :
6178 : : /* Redirect E to DEST. Return NULL on failure. Otherwise, return the
6179 : : edge representing the redirected branch. */
6180 : :
6181 : : static edge
6182 : 55266441 : gimple_redirect_edge_and_branch (edge e, basic_block dest)
6183 : : {
6184 : 55266441 : basic_block bb = e->src;
6185 : 55266441 : gimple_stmt_iterator gsi;
6186 : 55266441 : edge ret;
6187 : 55266441 : gimple *stmt;
6188 : :
6189 : 55266441 : if (e->flags & EDGE_ABNORMAL)
6190 : : return NULL;
6191 : :
6192 : 55266441 : if (e->dest == dest)
6193 : : return NULL;
6194 : :
6195 : 55245500 : if (e->flags & EDGE_EH)
6196 : 1056907 : return redirect_eh_edge (e, dest);
6197 : :
6198 : 54188593 : if (e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun))
6199 : : {
6200 : 53981599 : ret = gimple_try_redirect_by_replacing_jump (e, dest);
6201 : 53981599 : if (ret)
6202 : : return ret;
6203 : : }
6204 : :
6205 : 53898628 : gsi = gsi_last_nondebug_bb (bb);
6206 : 53898628 : stmt = gsi_end_p (gsi) ? NULL : gsi_stmt (gsi);
6207 : :
6208 : 53898628 : switch (stmt ? gimple_code (stmt) : GIMPLE_ERROR_MARK)
6209 : : {
6210 : : case GIMPLE_COND:
6211 : : /* For COND_EXPR, we only need to redirect the edge. */
6212 : : break;
6213 : :
6214 : 0 : case GIMPLE_GOTO:
6215 : : /* No non-abnormal edges should lead from a non-simple goto, and
6216 : : simple ones should be represented implicitly. */
6217 : 0 : gcc_unreachable ();
6218 : :
6219 : 357383 : case GIMPLE_SWITCH:
6220 : 357383 : {
6221 : 357383 : gswitch *switch_stmt = as_a <gswitch *> (stmt);
6222 : 357383 : tree label = gimple_block_label (dest);
6223 : 357383 : tree cases = get_cases_for_edge (e, switch_stmt);
6224 : :
6225 : : /* If we have a list of cases associated with E, then use it
6226 : : as it's a lot faster than walking the entire case vector. */
6227 : 357383 : if (cases)
6228 : : {
6229 : 313471 : edge e2 = find_edge (e->src, dest);
6230 : 313471 : tree last, first;
6231 : :
6232 : 313471 : first = cases;
6233 : 996739 : while (cases)
6234 : : {
6235 : 369797 : last = cases;
6236 : 369797 : CASE_LABEL (cases) = label;
6237 : 369797 : cases = CASE_CHAIN (cases);
6238 : : }
6239 : :
6240 : : /* If there was already an edge in the CFG, then we need
6241 : : to move all the cases associated with E to E2. */
6242 : 313471 : if (e2)
6243 : : {
6244 : 8394 : tree cases2 = get_cases_for_edge (e2, switch_stmt);
6245 : :
6246 : 8394 : CASE_CHAIN (last) = CASE_CHAIN (cases2);
6247 : 8394 : CASE_CHAIN (cases2) = first;
6248 : : }
6249 : 313471 : bitmap_set_bit (touched_switch_bbs, gimple_bb (stmt)->index);
6250 : : }
6251 : : else
6252 : : {
6253 : 43912 : size_t i, n = gimple_switch_num_labels (switch_stmt);
6254 : :
6255 : 4545689 : for (i = 0; i < n; i++)
6256 : : {
6257 : 4501777 : tree elt = gimple_switch_label (switch_stmt, i);
6258 : 4501777 : if (label_to_block (cfun, CASE_LABEL (elt)) == e->dest)
6259 : 49988 : CASE_LABEL (elt) = label;
6260 : : }
6261 : : }
6262 : : }
6263 : : break;
6264 : :
6265 : 12154 : case GIMPLE_ASM:
6266 : 12154 : {
6267 : 12154 : gasm *asm_stmt = as_a <gasm *> (stmt);
6268 : 12154 : int i, n = gimple_asm_nlabels (asm_stmt);
6269 : 12154 : tree label = NULL;
6270 : :
6271 : 15773 : for (i = 0; i < n; ++i)
6272 : : {
6273 : 3619 : tree cons = gimple_asm_label_op (asm_stmt, i);
6274 : 3619 : if (label_to_block (cfun, TREE_VALUE (cons)) == e->dest)
6275 : : {
6276 : 1744 : if (!label)
6277 : 1718 : label = gimple_block_label (dest);
6278 : 1744 : TREE_VALUE (cons) = label;
6279 : : }
6280 : : }
6281 : :
6282 : : /* If we didn't find any label matching the former edge in the
6283 : : asm labels, we must be redirecting the fallthrough
6284 : : edge. */
6285 : 12154 : gcc_assert (label || (e->flags & EDGE_FALLTHRU));
6286 : : }
6287 : : break;
6288 : :
6289 : 241 : case GIMPLE_RETURN:
6290 : 241 : gsi_remove (&gsi, true);
6291 : 241 : e->flags |= EDGE_FALLTHRU;
6292 : 241 : break;
6293 : :
6294 : : case GIMPLE_OMP_RETURN:
6295 : : case GIMPLE_OMP_CONTINUE:
6296 : : case GIMPLE_OMP_SECTIONS_SWITCH:
6297 : : case GIMPLE_OMP_FOR:
6298 : : /* The edges from OMP constructs can be simply redirected. */
6299 : : break;
6300 : :
6301 : 0 : case GIMPLE_EH_DISPATCH:
6302 : 0 : if (!(e->flags & EDGE_FALLTHRU))
6303 : 0 : redirect_eh_dispatch_edge (as_a <geh_dispatch *> (stmt), e, dest);
6304 : : break;
6305 : :
6306 : 393 : case GIMPLE_TRANSACTION:
6307 : 393 : if (e->flags & EDGE_TM_ABORT)
6308 : 81 : gimple_transaction_set_label_over (as_a <gtransaction *> (stmt),
6309 : : gimple_block_label (dest));
6310 : 312 : else if (e->flags & EDGE_TM_UNINSTRUMENTED)
6311 : 153 : gimple_transaction_set_label_uninst (as_a <gtransaction *> (stmt),
6312 : : gimple_block_label (dest));
6313 : : else
6314 : 159 : gimple_transaction_set_label_norm (as_a <gtransaction *> (stmt),
6315 : : gimple_block_label (dest));
6316 : : break;
6317 : :
6318 : 7614704 : default:
6319 : : /* Otherwise it must be a fallthru edge, and we don't need to
6320 : : do anything besides redirecting it. */
6321 : 7614704 : gcc_assert (e->flags & EDGE_FALLTHRU);
6322 : : break;
6323 : : }
6324 : :
6325 : : /* Update/insert PHI nodes as necessary. */
6326 : :
6327 : : /* Now update the edges in the CFG. */
6328 : 53898628 : e = ssa_redirect_edge (e, dest);
6329 : :
6330 : 53898628 : return e;
6331 : : }
6332 : :
6333 : : /* Returns true if it is possible to remove edge E by redirecting
6334 : : it to the destination of the other edge from E->src. */
6335 : :
6336 : : static bool
6337 : 223821 : gimple_can_remove_branch_p (const_edge e)
6338 : : {
6339 : 223821 : if (e->flags & (EDGE_ABNORMAL | EDGE_EH))
6340 : 0 : return false;
6341 : :
6342 : : return true;
6343 : : }
6344 : :
6345 : : /* Simple wrapper, as we can always redirect fallthru edges. */
6346 : :
6347 : : static basic_block
6348 : 2729472 : gimple_redirect_edge_and_branch_force (edge e, basic_block dest)
6349 : : {
6350 : 2729472 : e = gimple_redirect_edge_and_branch (e, dest);
6351 : 2729472 : gcc_assert (e);
6352 : :
6353 : 2729472 : return NULL;
6354 : : }
6355 : :
6356 : :
6357 : : /* Splits basic block BB after statement STMT (but at least after the
6358 : : labels). If STMT is NULL, BB is split just after the labels. */
6359 : :
6360 : : static basic_block
6361 : 4651150 : gimple_split_block (basic_block bb, void *stmt)
6362 : : {
6363 : 4651150 : gimple_stmt_iterator gsi;
6364 : 4651150 : gimple_stmt_iterator gsi_tgt;
6365 : 4651150 : gimple_seq list;
6366 : 4651150 : basic_block new_bb;
6367 : 4651150 : edge e;
6368 : 4651150 : edge_iterator ei;
6369 : :
6370 : 4651150 : new_bb = create_empty_bb (bb);
6371 : :
6372 : : /* Redirect the outgoing edges. */
6373 : 4651150 : new_bb->succs = bb->succs;
6374 : 4651150 : bb->succs = NULL;
6375 : 10855406 : FOR_EACH_EDGE (e, ei, new_bb->succs)
6376 : 6204256 : e->src = new_bb;
6377 : :
6378 : : /* Get a stmt iterator pointing to the first stmt to move. */
6379 : 4651150 : if (!stmt || gimple_code ((gimple *) stmt) == GIMPLE_LABEL)
6380 : 1371306 : gsi = gsi_after_labels (bb);
6381 : : else
6382 : : {
6383 : 3279844 : gsi = gsi_for_stmt ((gimple *) stmt);
6384 : 3279844 : gsi_next (&gsi);
6385 : : }
6386 : :
6387 : : /* Move everything from GSI to the new basic block. */
6388 : 4651150 : if (gsi_end_p (gsi))
6389 : : return new_bb;
6390 : :
6391 : : /* Split the statement list - avoid re-creating new containers as this
6392 : : brings ugly quadratic memory consumption in the inliner.
6393 : : (We are still quadratic since we need to update stmt BB pointers,
6394 : : sadly.) */
6395 : 4397508 : gsi_split_seq_before (&gsi, &list);
6396 : 4397508 : set_bb_seq (new_bb, list);
6397 : 4397508 : for (gsi_tgt = gsi_start (list);
6398 : 25347217 : !gsi_end_p (gsi_tgt); gsi_next (&gsi_tgt))
6399 : 20949709 : gimple_set_bb (gsi_stmt (gsi_tgt), new_bb);
6400 : :
6401 : : return new_bb;
6402 : : }
6403 : :
6404 : :
6405 : : /* Moves basic block BB after block AFTER. */
6406 : :
6407 : : static bool
6408 : 17984332 : gimple_move_block_after (basic_block bb, basic_block after)
6409 : : {
6410 : 17984332 : if (bb->prev_bb == after)
6411 : : return true;
6412 : :
6413 : 4466457 : unlink_block (bb);
6414 : 4466457 : link_block (bb, after);
6415 : :
6416 : 4466457 : return true;
6417 : : }
6418 : :
6419 : :
6420 : : /* Return TRUE if block BB has no executable statements, otherwise return
6421 : : FALSE. */
6422 : :
6423 : : static bool
6424 : 11099793 : gimple_empty_block_p (basic_block bb)
6425 : : {
6426 : : /* BB must have no executable statements. */
6427 : 11099793 : gimple_stmt_iterator gsi = gsi_after_labels (bb);
6428 : 11099793 : if (phi_nodes (bb))
6429 : : return false;
6430 : 13225125 : while (!gsi_end_p (gsi))
6431 : : {
6432 : 5424803 : gimple *stmt = gsi_stmt (gsi);
6433 : 5424803 : if (is_gimple_debug (stmt))
6434 : : ;
6435 : 2549996 : else if (gimple_code (stmt) == GIMPLE_NOP
6436 : 2549996 : || gimple_code (stmt) == GIMPLE_PREDICT)
6437 : : ;
6438 : : else
6439 : : return false;
6440 : 2924940 : gsi_next (&gsi);
6441 : : }
6442 : : return true;
6443 : : }
6444 : :
6445 : :
6446 : : /* Split a basic block if it ends with a conditional branch and if the
6447 : : other part of the block is not empty. */
6448 : :
6449 : : static basic_block
6450 : 604 : gimple_split_block_before_cond_jump (basic_block bb)
6451 : : {
6452 : 604 : gimple *last, *split_point;
6453 : 604 : gimple_stmt_iterator gsi = gsi_last_nondebug_bb (bb);
6454 : 604 : if (gsi_end_p (gsi))
6455 : : return NULL;
6456 : 604 : last = gsi_stmt (gsi);
6457 : 604 : if (gimple_code (last) != GIMPLE_COND
6458 : 604 : && gimple_code (last) != GIMPLE_SWITCH)
6459 : : return NULL;
6460 : 604 : gsi_prev (&gsi);
6461 : 604 : split_point = gsi_stmt (gsi);
6462 : 604 : return split_block (bb, split_point)->dest;
6463 : : }
6464 : :
6465 : :
6466 : : /* Return true if basic_block can be duplicated. */
6467 : :
6468 : : static bool
6469 : 7056067 : gimple_can_duplicate_bb_p (const_basic_block bb)
6470 : : {
6471 : 7056067 : gimple *last = last_nondebug_stmt (CONST_CAST_BB (bb));
6472 : :
6473 : : /* Do checks that can only fail for the last stmt, to minimize the work in the
6474 : : stmt loop. */
6475 : 7056067 : if (last) {
6476 : : /* A transaction is a single entry multiple exit region. It
6477 : : must be duplicated in its entirety or not at all. */
6478 : 6068686 : if (gimple_code (last) == GIMPLE_TRANSACTION)
6479 : : return false;
6480 : :
6481 : : /* An IFN_UNIQUE call must be duplicated as part of its group,
6482 : : or not at all. */
6483 : 6068685 : if (is_gimple_call (last)
6484 : 57264 : && gimple_call_internal_p (last)
6485 : 6068957 : && gimple_call_internal_unique_p (last))
6486 : : return false;
6487 : : }
6488 : :
6489 : 14112132 : for (gimple_stmt_iterator gsi = gsi_start_bb (CONST_CAST_BB (bb));
6490 : 43044386 : !gsi_end_p (gsi); gsi_next (&gsi))
6491 : : {
6492 : 35988421 : gimple *g = gsi_stmt (gsi);
6493 : :
6494 : : /* Prohibit duplication of returns_twice calls, otherwise associated
6495 : : abnormal edges also need to be duplicated properly.
6496 : : An IFN_GOMP_SIMT_ENTER_ALLOC/IFN_GOMP_SIMT_EXIT call must be
6497 : : duplicated as part of its group, or not at all.
6498 : : The IFN_GOMP_SIMT_VOTE_ANY and IFN_GOMP_SIMT_XCHG_* are part of such a
6499 : : group, so the same holds there. */
6500 : 35988421 : if (is_gimple_call (g)
6501 : 35988421 : && (gimple_call_flags (g) & ECF_RETURNS_TWICE
6502 : 417576 : || gimple_call_internal_p (g, IFN_GOMP_SIMT_ENTER_ALLOC)
6503 : 417576 : || gimple_call_internal_p (g, IFN_GOMP_SIMT_EXIT)
6504 : 417576 : || gimple_call_internal_p (g, IFN_GOMP_SIMT_VOTE_ANY)
6505 : 417576 : || gimple_call_internal_p (g, IFN_GOMP_SIMT_XCHG_BFLY)
6506 : 417576 : || gimple_call_internal_p (g, IFN_GOMP_SIMT_XCHG_IDX)))
6507 : 102 : return false;
6508 : : }
6509 : :
6510 : : return true;
6511 : : }
6512 : :
6513 : : /* Create a duplicate of the basic block BB. NOTE: This does not
6514 : : preserve SSA form. */
6515 : :
6516 : : static basic_block
6517 : 3003711 : gimple_duplicate_bb (basic_block bb, copy_bb_data *id)
6518 : : {
6519 : 3003711 : basic_block new_bb;
6520 : 3003711 : gimple_stmt_iterator gsi_tgt;
6521 : :
6522 : 3003711 : new_bb = create_empty_bb (EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb);
6523 : :
6524 : : /* Copy the PHI nodes. We ignore PHI node arguments here because
6525 : : the incoming edges have not been setup yet. */
6526 : 3003711 : for (gphi_iterator gpi = gsi_start_phis (bb);
6527 : 7133132 : !gsi_end_p (gpi);
6528 : 4129421 : gsi_next (&gpi))
6529 : : {
6530 : 4129421 : gphi *phi, *copy;
6531 : 4129421 : phi = gpi.phi ();
6532 : 4129421 : copy = create_phi_node (NULL_TREE, new_bb);
6533 : 4129421 : create_new_def_for (gimple_phi_result (phi), copy,
6534 : : gimple_phi_result_ptr (copy));
6535 : 4129421 : gimple_set_uid (copy, gimple_uid (phi));
6536 : : }
6537 : :
6538 : 3003711 : gsi_tgt = gsi_start_bb (new_bb);
6539 : 6007422 : for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
6540 : 17330291 : !gsi_end_p (gsi);
6541 : 14326580 : gsi_next (&gsi))
6542 : : {
6543 : 14326580 : def_operand_p def_p;
6544 : 14326580 : ssa_op_iter op_iter;
6545 : 14326580 : tree lhs;
6546 : 14326580 : gimple *stmt, *copy;
6547 : :
6548 : 14326580 : stmt = gsi_stmt (gsi);
6549 : 14326580 : if (gimple_code (stmt) == GIMPLE_LABEL)
6550 : 57970 : continue;
6551 : :
6552 : : /* Don't duplicate label debug stmts. */
6553 : 14270044 : if (gimple_debug_bind_p (stmt)
6554 : 7882727 : && TREE_CODE (gimple_debug_bind_get_var (stmt))
6555 : : == LABEL_DECL)
6556 : 1434 : continue;
6557 : :
6558 : : /* Create a new copy of STMT and duplicate STMT's virtual
6559 : : operands. */
6560 : 14268610 : copy = gimple_copy (stmt);
6561 : 14268610 : gsi_insert_after (&gsi_tgt, copy, GSI_NEW_STMT);
6562 : :
6563 : 14268610 : maybe_duplicate_eh_stmt (copy, stmt);
6564 : 14268610 : gimple_duplicate_stmt_histograms (cfun, copy, cfun, stmt);
6565 : :
6566 : : /* When copying around a stmt writing into a local non-user
6567 : : aggregate, make sure it won't share stack slot with other
6568 : : vars. */
6569 : 14268610 : lhs = gimple_get_lhs (stmt);
6570 : 14268610 : if (lhs && TREE_CODE (lhs) != SSA_NAME)
6571 : : {
6572 : 621006 : tree base = get_base_address (lhs);
6573 : 621006 : if (base
6574 : 621006 : && (VAR_P (base) || TREE_CODE (base) == RESULT_DECL)
6575 : 420032 : && DECL_IGNORED_P (base)
6576 : 166297 : && !TREE_STATIC (base)
6577 : 165208 : && !DECL_EXTERNAL (base)
6578 : 786210 : && (!VAR_P (base) || !DECL_HAS_VALUE_EXPR_P (base)))
6579 : 165204 : DECL_NONSHAREABLE (base) = 1;
6580 : : }
6581 : :
6582 : : /* If requested remap dependence info of cliques brought in
6583 : : via inlining. */
6584 : 14268610 : if (id)
6585 : 40157767 : for (unsigned i = 0; i < gimple_num_ops (copy); ++i)
6586 : : {
6587 : 28067112 : tree op = gimple_op (copy, i);
6588 : 28067112 : if (!op)
6589 : 7092602 : continue;
6590 : 20974510 : if (TREE_CODE (op) == ADDR_EXPR
6591 : 20269808 : || TREE_CODE (op) == WITH_SIZE_EXPR)
6592 : 704702 : op = TREE_OPERAND (op, 0);
6593 : 22377276 : while (handled_component_p (op))
6594 : 1402766 : op = TREE_OPERAND (op, 0);
6595 : 20974510 : if ((TREE_CODE (op) == MEM_REF
6596 : 20974510 : || TREE_CODE (op) == TARGET_MEM_REF)
6597 : 753518 : && MR_DEPENDENCE_CLIQUE (op) > 1
6598 : 21028032 : && MR_DEPENDENCE_CLIQUE (op) != bb->loop_father->owned_clique)
6599 : : {
6600 : 23310 : if (!id->dependence_map)
6601 : 9723 : id->dependence_map = new hash_map<dependence_hash,
6602 : : unsigned short>;
6603 : 23310 : bool existed;
6604 : 23310 : unsigned short &newc = id->dependence_map->get_or_insert
6605 : 23310 : (MR_DEPENDENCE_CLIQUE (op), &existed);
6606 : 23310 : if (!existed)
6607 : : {
6608 : 14414 : gcc_assert (MR_DEPENDENCE_CLIQUE (op) <= cfun->last_clique);
6609 : 28828 : newc = get_new_clique (cfun);
6610 : : }
6611 : 23310 : MR_DEPENDENCE_CLIQUE (op) = newc;
6612 : : }
6613 : : }
6614 : :
6615 : : /* Create new names for all the definitions created by COPY and
6616 : : add replacement mappings for each new name. */
6617 : 18266404 : FOR_EACH_SSA_DEF_OPERAND (def_p, copy, op_iter, SSA_OP_ALL_DEFS)
6618 : 3997794 : create_new_def_for (DEF_FROM_PTR (def_p), copy, def_p);
6619 : : }
6620 : :
6621 : 3003711 : return new_bb;
6622 : : }
6623 : :
6624 : : /* Adds phi node arguments for edge E_COPY after basic block duplication. */
6625 : :
6626 : : static void
6627 : 3965021 : add_phi_args_after_copy_edge (edge e_copy)
6628 : : {
6629 : 3965021 : basic_block bb, bb_copy = e_copy->src, dest;
6630 : 3965021 : edge e;
6631 : 3965021 : edge_iterator ei;
6632 : 3965021 : gphi *phi, *phi_copy;
6633 : 3965021 : tree def;
6634 : 3965021 : gphi_iterator psi, psi_copy;
6635 : :
6636 : 3965021 : if (gimple_seq_empty_p (phi_nodes (e_copy->dest)))
6637 : 2537207 : return;
6638 : :
6639 : 1427814 : bb = bb_copy->flags & BB_DUPLICATED ? get_bb_original (bb_copy) : bb_copy;
6640 : :
6641 : 1427814 : if (e_copy->dest->flags & BB_DUPLICATED)
6642 : 580767 : dest = get_bb_original (e_copy->dest);
6643 : : else
6644 : : dest = e_copy->dest;
6645 : :
6646 : 1427814 : e = find_edge (bb, dest);
6647 : 1427814 : if (!e)
6648 : : {
6649 : : /* During loop unrolling the target of the latch edge is copied.
6650 : : In this case we are not looking for edge to dest, but to
6651 : : duplicated block whose original was dest. */
6652 : 941 : FOR_EACH_EDGE (e, ei, bb->succs)
6653 : : {
6654 : 941 : if ((e->dest->flags & BB_DUPLICATED)
6655 : 941 : && get_bb_original (e->dest) == dest)
6656 : : break;
6657 : : }
6658 : :
6659 : 941 : gcc_assert (e != NULL);
6660 : : }
6661 : :
6662 : 1427814 : for (psi = gsi_start_phis (e->dest),
6663 : 1427814 : psi_copy = gsi_start_phis (e_copy->dest);
6664 : 4143548 : !gsi_end_p (psi);
6665 : 2715734 : gsi_next (&psi), gsi_next (&psi_copy))
6666 : : {
6667 : 2715734 : phi = psi.phi ();
6668 : 2715734 : phi_copy = psi_copy.phi ();
6669 : 2715734 : def = PHI_ARG_DEF_FROM_EDGE (phi, e);
6670 : 2715734 : add_phi_arg (phi_copy, def, e_copy,
6671 : : gimple_phi_arg_location_from_edge (phi, e));
6672 : : }
6673 : : }
6674 : :
6675 : :
6676 : : /* Basic block BB_COPY was created by code duplication. Add phi node
6677 : : arguments for edges going out of BB_COPY. The blocks that were
6678 : : duplicated have BB_DUPLICATED set. */
6679 : :
6680 : : void
6681 : 2759706 : add_phi_args_after_copy_bb (basic_block bb_copy)
6682 : : {
6683 : 2759706 : edge e_copy;
6684 : 2759706 : edge_iterator ei;
6685 : :
6686 : 6724703 : FOR_EACH_EDGE (e_copy, ei, bb_copy->succs)
6687 : : {
6688 : 3964997 : add_phi_args_after_copy_edge (e_copy);
6689 : : }
6690 : 2759706 : }
6691 : :
6692 : : /* Blocks in REGION_COPY array of length N_REGION were created by
6693 : : duplication of basic blocks. Add phi node arguments for edges
6694 : : going from these blocks. If E_COPY is not NULL, also add
6695 : : phi node arguments for its destination.*/
6696 : :
6697 : : void
6698 : 1473112 : add_phi_args_after_copy (basic_block *region_copy, unsigned n_region,
6699 : : edge e_copy)
6700 : : {
6701 : 1473112 : unsigned i;
6702 : :
6703 : 3418543 : for (i = 0; i < n_region; i++)
6704 : 1945431 : region_copy[i]->flags |= BB_DUPLICATED;
6705 : :
6706 : 3418543 : for (i = 0; i < n_region; i++)
6707 : 1945431 : add_phi_args_after_copy_bb (region_copy[i]);
6708 : 1473112 : if (e_copy)
6709 : 24 : add_phi_args_after_copy_edge (e_copy);
6710 : :
6711 : 3418543 : for (i = 0; i < n_region; i++)
6712 : 1945431 : region_copy[i]->flags &= ~BB_DUPLICATED;
6713 : 1473112 : }
6714 : :
6715 : : /* Duplicates a REGION (set of N_REGION basic blocks) with just a single
6716 : : important exit edge EXIT. By important we mean that no SSA name defined
6717 : : inside region is live over the other exit edges of the region. All entry
6718 : : edges to the region must go to ENTRY->dest. The edge ENTRY is redirected
6719 : : to the duplicate of the region. Dominance and loop information is
6720 : : updated if UPDATE_DOMINANCE is true, but not the SSA web. If
6721 : : UPDATE_DOMINANCE is false then we assume that the caller will update the
6722 : : dominance information after calling this function. The new basic
6723 : : blocks are stored to REGION_COPY in the same order as they had in REGION,
6724 : : provided that REGION_COPY is not NULL.
6725 : : The function returns false if it is unable to copy the region,
6726 : : true otherwise.
6727 : :
6728 : : It is callers responsibility to update profile. */
6729 : :
6730 : : bool
6731 : 472256 : gimple_duplicate_seme_region (edge entry, edge exit,
6732 : : basic_block *region, unsigned n_region,
6733 : : basic_block *region_copy,
6734 : : bool update_dominance)
6735 : : {
6736 : 472256 : unsigned i;
6737 : 472256 : bool free_region_copy = false, copying_header = false;
6738 : 472256 : class loop *loop = entry->dest->loop_father;
6739 : 472256 : edge exit_copy;
6740 : 472256 : edge redirected;
6741 : :
6742 : 472256 : if (!can_copy_bbs_p (region, n_region))
6743 : : return false;
6744 : :
6745 : : /* Some sanity checking. Note that we do not check for all possible
6746 : : missuses of the functions. I.e. if you ask to copy something weird,
6747 : : it will work, but the state of structures probably will not be
6748 : : correct. */
6749 : 950698 : for (i = 0; i < n_region; i++)
6750 : : {
6751 : : /* We do not handle subloops, i.e. all the blocks must belong to the
6752 : : same loop. */
6753 : 478442 : if (region[i]->loop_father != loop)
6754 : : return false;
6755 : :
6756 : 478442 : if (region[i] != entry->dest
6757 : 6186 : && region[i] == loop->header)
6758 : : return false;
6759 : : }
6760 : :
6761 : : /* In case the function is used for loop header copying (which is the primary
6762 : : use), ensure that EXIT and its copy will be new latch and entry edges. */
6763 : 472256 : if (loop->header == entry->dest)
6764 : : {
6765 : 472256 : copying_header = true;
6766 : :
6767 : 472256 : if (!dominated_by_p (CDI_DOMINATORS, loop->latch, exit->src))
6768 : : return false;
6769 : :
6770 : 950698 : for (i = 0; i < n_region; i++)
6771 : 478442 : if (region[i] != exit->src
6772 : 478442 : && dominated_by_p (CDI_DOMINATORS, region[i], exit->src))
6773 : : return false;
6774 : : }
6775 : :
6776 : 472256 : initialize_original_copy_tables ();
6777 : :
6778 : 472256 : if (copying_header)
6779 : 472256 : set_loop_copy (loop, loop_outer (loop));
6780 : : else
6781 : 0 : set_loop_copy (loop, loop);
6782 : :
6783 : 472256 : if (!region_copy)
6784 : : {
6785 : 0 : region_copy = XNEWVEC (basic_block, n_region);
6786 : 0 : free_region_copy = true;
6787 : : }
6788 : :
6789 : : /* Record blocks outside the region that are dominated by something
6790 : : inside. */
6791 : 472256 : auto_vec<basic_block> doms;
6792 : 472256 : if (update_dominance)
6793 : 472256 : doms = get_dominated_by_region (CDI_DOMINATORS, region, n_region);
6794 : :
6795 : 472256 : copy_bbs (region, n_region, region_copy, &exit, 1, &exit_copy, loop,
6796 : : split_edge_bb_loc (entry), update_dominance);
6797 : :
6798 : 472256 : if (copying_header)
6799 : : {
6800 : 472256 : loop->header = exit->dest;
6801 : 472256 : loop->latch = exit->src;
6802 : : }
6803 : :
6804 : : /* Redirect the entry and add the phi node arguments. */
6805 : 472256 : redirected = redirect_edge_and_branch (entry, get_bb_copy (entry->dest));
6806 : 472256 : gcc_assert (redirected != NULL);
6807 : 472256 : flush_pending_stmts (entry);
6808 : :
6809 : : /* Concerning updating of dominators: We must recount dominators
6810 : : for entry block and its copy. Anything that is outside of the
6811 : : region, but was dominated by something inside needs recounting as
6812 : : well. */
6813 : 472256 : if (update_dominance)
6814 : : {
6815 : 472256 : set_immediate_dominator (CDI_DOMINATORS, entry->dest, entry->src);
6816 : 472256 : doms.safe_push (get_bb_original (entry->dest));
6817 : 472256 : iterate_fix_dominators (CDI_DOMINATORS, doms, false);
6818 : : }
6819 : :
6820 : : /* Add the other PHI node arguments. */
6821 : 472256 : add_phi_args_after_copy (region_copy, n_region, NULL);
6822 : :
6823 : 472256 : if (free_region_copy)
6824 : 0 : free (region_copy);
6825 : :
6826 : 472256 : free_original_copy_tables ();
6827 : 472256 : return true;
6828 : 472256 : }
6829 : :
6830 : : /* Checks if BB is part of the region defined by N_REGION BBS. */
6831 : : static bool
6832 : 0 : bb_part_of_region_p (basic_block bb, basic_block* bbs, unsigned n_region)
6833 : : {
6834 : 0 : unsigned int n;
6835 : :
6836 : 0 : for (n = 0; n < n_region; n++)
6837 : : {
6838 : 0 : if (bb == bbs[n])
6839 : : return true;
6840 : : }
6841 : : return false;
6842 : : }
6843 : :
6844 : :
6845 : : /* For each PHI in BB, copy the argument associated with SRC_E to TGT_E.
6846 : : Assuming the argument exists, just does not have a value. */
6847 : :
6848 : : void
6849 : 25950256 : copy_phi_arg_into_existing_phi (edge src_e, edge tgt_e)
6850 : : {
6851 : 25950256 : int src_idx = src_e->dest_idx;
6852 : 25950256 : int tgt_idx = tgt_e->dest_idx;
6853 : :
6854 : : /* Iterate over each PHI in e->dest. */
6855 : 25950256 : for (gphi_iterator gsi = gsi_start_phis (src_e->dest),
6856 : 25950256 : gsi2 = gsi_start_phis (tgt_e->dest);
6857 : 63538151 : !gsi_end_p (gsi);
6858 : 37587895 : gsi_next (&gsi), gsi_next (&gsi2))
6859 : : {
6860 : 37587895 : gphi *src_phi = gsi.phi ();
6861 : 37587895 : gphi *dest_phi = gsi2.phi ();
6862 : 37587895 : tree val = gimple_phi_arg_def (src_phi, src_idx);
6863 : 37587895 : location_t locus = gimple_phi_arg_location (src_phi, src_idx);
6864 : :
6865 : 37587895 : SET_PHI_ARG_DEF (dest_phi, tgt_idx, val);
6866 : 37587895 : gimple_phi_arg_set_location (dest_phi, tgt_idx, locus);
6867 : : }
6868 : 25950256 : }
6869 : :
6870 : : /* Duplicates REGION consisting of N_REGION blocks. The new blocks
6871 : : are stored to REGION_COPY in the same order in that they appear
6872 : : in REGION, if REGION_COPY is not NULL. ENTRY is the entry to
6873 : : the region, EXIT an exit from it. The condition guarding EXIT
6874 : : is moved to ENTRY. Returns true if duplication succeeds, false
6875 : : otherwise.
6876 : :
6877 : : For example,
6878 : :
6879 : : some_code;
6880 : : if (cond)
6881 : : A;
6882 : : else
6883 : : B;
6884 : :
6885 : : is transformed to
6886 : :
6887 : : if (cond)
6888 : : {
6889 : : some_code;
6890 : : A;
6891 : : }
6892 : : else
6893 : : {
6894 : : some_code;
6895 : : B;
6896 : : }
6897 : : */
6898 : :
6899 : : bool
6900 : 24 : gimple_duplicate_sese_tail (edge entry, edge exit,
6901 : : basic_block *region, unsigned n_region,
6902 : : basic_block *region_copy)
6903 : : {
6904 : 24 : unsigned i;
6905 : 24 : bool free_region_copy = false;
6906 : 24 : class loop *loop = exit->dest->loop_father;
6907 : 24 : class loop *orig_loop = entry->dest->loop_father;
6908 : 24 : basic_block switch_bb, entry_bb, nentry_bb;
6909 : 24 : profile_count total_count = profile_count::uninitialized (),
6910 : 24 : exit_count = profile_count::uninitialized ();
6911 : 24 : edge exits[2], nexits[2], e;
6912 : 24 : gimple_stmt_iterator gsi;
6913 : 24 : edge sorig, snew;
6914 : 24 : basic_block exit_bb;
6915 : 24 : class loop *target, *aloop, *cloop;
6916 : :
6917 : 24 : gcc_assert (EDGE_COUNT (exit->src->succs) == 2);
6918 : 24 : exits[0] = exit;
6919 : 24 : exits[1] = EDGE_SUCC (exit->src, EDGE_SUCC (exit->src, 0) == exit);
6920 : :
6921 : 24 : if (!can_copy_bbs_p (region, n_region))
6922 : : return false;
6923 : :
6924 : 24 : initialize_original_copy_tables ();
6925 : 24 : set_loop_copy (orig_loop, loop);
6926 : :
6927 : 24 : target= loop;
6928 : 24 : for (aloop = orig_loop->inner; aloop; aloop = aloop->next)
6929 : : {
6930 : 0 : if (bb_part_of_region_p (aloop->header, region, n_region))
6931 : : {
6932 : 0 : cloop = duplicate_loop (aloop, target);
6933 : 0 : duplicate_subloops (aloop, cloop);
6934 : : }
6935 : : }
6936 : :
6937 : 24 : if (!region_copy)
6938 : : {
6939 : 0 : region_copy = XNEWVEC (basic_block, n_region);
6940 : 0 : free_region_copy = true;
6941 : : }
6942 : :
6943 : 24 : gcc_assert (!need_ssa_update_p (cfun));
6944 : :
6945 : : /* Record blocks outside the region that are dominated by something
6946 : : inside. */
6947 : 24 : auto_vec<basic_block> doms = get_dominated_by_region (CDI_DOMINATORS, region,
6948 : 24 : n_region);
6949 : :
6950 : 24 : total_count = exit->src->count;
6951 : 24 : exit_count = exit->count ();
6952 : : /* Fix up corner cases, to avoid division by zero or creation of negative
6953 : : frequencies. */
6954 : 24 : if (exit_count > total_count)
6955 : 0 : exit_count = total_count;
6956 : :
6957 : 24 : copy_bbs (region, n_region, region_copy, exits, 2, nexits, orig_loop,
6958 : : split_edge_bb_loc (exit), true);
6959 : 24 : if (total_count.initialized_p () && exit_count.initialized_p ())
6960 : : {
6961 : 24 : scale_bbs_frequencies_profile_count (region, n_region,
6962 : : total_count - exit_count,
6963 : : total_count);
6964 : 24 : scale_bbs_frequencies_profile_count (region_copy, n_region, exit_count,
6965 : : total_count);
6966 : : }
6967 : :
6968 : : /* Create the switch block, and put the exit condition to it. */
6969 : 24 : entry_bb = entry->dest;
6970 : 24 : nentry_bb = get_bb_copy (entry_bb);
6971 : 24 : if (!*gsi_last_bb (entry->src)
6972 : 24 : || !stmt_ends_bb_p (*gsi_last_bb (entry->src)))
6973 : 24 : switch_bb = entry->src;
6974 : : else
6975 : 0 : switch_bb = split_edge (entry);
6976 : 24 : set_immediate_dominator (CDI_DOMINATORS, nentry_bb, switch_bb);
6977 : :
6978 : 48 : gcond *cond_stmt = as_a <gcond *> (*gsi_last_bb (exit->src));
6979 : 24 : cond_stmt = as_a <gcond *> (gimple_copy (cond_stmt));
6980 : :
6981 : 24 : gsi = gsi_last_bb (switch_bb);
6982 : 24 : gsi_insert_after (&gsi, cond_stmt, GSI_NEW_STMT);
6983 : :
6984 : 24 : sorig = single_succ_edge (switch_bb);
6985 : 24 : sorig->flags = exits[1]->flags;
6986 : 24 : sorig->probability = exits[1]->probability;
6987 : 24 : snew = make_edge (switch_bb, nentry_bb, exits[0]->flags);
6988 : 24 : snew->probability = exits[0]->probability;
6989 : :
6990 : :
6991 : : /* Register the new edge from SWITCH_BB in loop exit lists. */
6992 : 24 : rescan_loop_exit (snew, true, false);
6993 : :
6994 : : /* Add the PHI node arguments. */
6995 : 24 : add_phi_args_after_copy (region_copy, n_region, snew);
6996 : :
6997 : : /* Get rid of now superfluous conditions and associated edges (and phi node
6998 : : arguments). */
6999 : 24 : exit_bb = exit->dest;
7000 : :
7001 : 24 : e = redirect_edge_and_branch (exits[0], exits[1]->dest);
7002 : 24 : PENDING_STMT (e) = NULL;
7003 : :
7004 : : /* The latch of ORIG_LOOP was copied, and so was the backedge
7005 : : to the original header. We redirect this backedge to EXIT_BB. */
7006 : 50 : for (i = 0; i < n_region; i++)
7007 : 26 : if (get_bb_original (region_copy[i]) == orig_loop->latch)
7008 : : {
7009 : 0 : gcc_assert (single_succ_edge (region_copy[i]));
7010 : 0 : e = redirect_edge_and_branch (single_succ_edge (region_copy[i]), exit_bb);
7011 : 0 : PENDING_STMT (e) = NULL;
7012 : 0 : copy_phi_arg_into_existing_phi (nexits[0], e);
7013 : : }
7014 : 24 : e = redirect_edge_and_branch (nexits[1], nexits[0]->dest);
7015 : 24 : PENDING_STMT (e) = NULL;
7016 : :
7017 : : /* Anything that is outside of the region, but was dominated by something
7018 : : inside needs to update dominance info. */
7019 : 24 : iterate_fix_dominators (CDI_DOMINATORS, doms, false);
7020 : :
7021 : 24 : if (free_region_copy)
7022 : 0 : free (region_copy);
7023 : :
7024 : 24 : free_original_copy_tables ();
7025 : 24 : return true;
7026 : 24 : }
7027 : :
7028 : : /* Add all the blocks dominated by ENTRY to the array BBS_P. Stop
7029 : : adding blocks when the dominator traversal reaches EXIT. This
7030 : : function silently assumes that ENTRY strictly dominates EXIT. */
7031 : :
7032 : : void
7033 : 567494 : gather_blocks_in_sese_region (basic_block entry, basic_block exit,
7034 : : vec<basic_block> *bbs_p)
7035 : : {
7036 : 567494 : basic_block son;
7037 : :
7038 : 567494 : for (son = first_dom_son (CDI_DOMINATORS, entry);
7039 : 1134866 : son;
7040 : 567372 : son = next_dom_son (CDI_DOMINATORS, son))
7041 : : {
7042 : 567372 : bbs_p->safe_push (son);
7043 : 567372 : if (son != exit)
7044 : 524811 : gather_blocks_in_sese_region (son, exit, bbs_p);
7045 : : }
7046 : 567494 : }
7047 : :
7048 : : /* Replaces *TP with a duplicate (belonging to function TO_CONTEXT).
7049 : : The duplicates are recorded in VARS_MAP. */
7050 : :
7051 : : static void
7052 : 4207662 : replace_by_duplicate_decl (tree *tp, hash_map<tree, tree> *vars_map,
7053 : : tree to_context)
7054 : : {
7055 : 4207662 : tree t = *tp, new_t;
7056 : 4207662 : struct function *f = DECL_STRUCT_FUNCTION (to_context);
7057 : :
7058 : 4207662 : if (DECL_CONTEXT (t) == to_context)
7059 : 33304 : return;
7060 : :
7061 : 4174358 : bool existed;
7062 : 4174358 : tree &loc = vars_map->get_or_insert (t, &existed);
7063 : :
7064 : 4174358 : if (!existed)
7065 : : {
7066 : 1244827 : if (SSA_VAR_P (t))
7067 : : {
7068 : 1234270 : new_t = copy_var_decl (t, DECL_NAME (t), TREE_TYPE (t));
7069 : 1234270 : add_local_decl (f, new_t);
7070 : : }
7071 : : else
7072 : : {
7073 : 10557 : gcc_assert (TREE_CODE (t) == CONST_DECL);
7074 : 10557 : new_t = copy_node (t);
7075 : : }
7076 : 1244827 : DECL_CONTEXT (new_t) = to_context;
7077 : :
7078 : 1244827 : loc = new_t;
7079 : : }
7080 : : else
7081 : 2929531 : new_t = loc;
7082 : :
7083 : 4174358 : *tp = new_t;
7084 : : }
7085 : :
7086 : :
7087 : : /* Creates an ssa name in TO_CONTEXT equivalent to NAME.
7088 : : VARS_MAP maps old ssa names and var_decls to the new ones. */
7089 : :
7090 : : static tree
7091 : 13453 : replace_ssa_name (tree name, hash_map<tree, tree> *vars_map,
7092 : : tree to_context)
7093 : : {
7094 : 13453 : tree new_name;
7095 : :
7096 : 26906 : gcc_assert (!virtual_operand_p (name));
7097 : :
7098 : 13453 : tree *loc = vars_map->get (name);
7099 : :
7100 : 13453 : if (!loc)
7101 : : {
7102 : 5507 : tree decl = SSA_NAME_VAR (name);
7103 : 5507 : if (decl)
7104 : : {
7105 : 1323 : gcc_assert (!SSA_NAME_IS_DEFAULT_DEF (name));
7106 : 1323 : replace_by_duplicate_decl (&decl, vars_map, to_context);
7107 : 1323 : new_name = make_ssa_name_fn (DECL_STRUCT_FUNCTION (to_context),
7108 : 1323 : decl, SSA_NAME_DEF_STMT (name));
7109 : : }
7110 : : else
7111 : 4184 : new_name = copy_ssa_name_fn (DECL_STRUCT_FUNCTION (to_context),
7112 : 4184 : name, SSA_NAME_DEF_STMT (name));
7113 : :
7114 : : /* Now that we've used the def stmt to define new_name, make sure it
7115 : : doesn't define name anymore. */
7116 : 5507 : SSA_NAME_DEF_STMT (name) = NULL;
7117 : :
7118 : 5507 : vars_map->put (name, new_name);
7119 : : }
7120 : : else
7121 : 7946 : new_name = *loc;
7122 : :
7123 : 13453 : return new_name;
7124 : : }
7125 : :
7126 : : struct move_stmt_d
7127 : : {
7128 : : tree orig_block;
7129 : : tree new_block;
7130 : : tree from_context;
7131 : : tree to_context;
7132 : : hash_map<tree, tree> *vars_map;
7133 : : htab_t new_label_map;
7134 : : hash_map<void *, void *> *eh_map;
7135 : : bool remap_decls_p;
7136 : : };
7137 : :
7138 : : /* Helper for move_block_to_fn. Set TREE_BLOCK in every expression
7139 : : contained in *TP if it has been ORIG_BLOCK previously and change the
7140 : : DECL_CONTEXT of every local variable referenced in *TP. */
7141 : :
7142 : : static tree
7143 : 6878400 : move_stmt_op (tree *tp, int *walk_subtrees, void *data)
7144 : : {
7145 : 6878400 : struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
7146 : 6878400 : struct move_stmt_d *p = (struct move_stmt_d *) wi->info;
7147 : 6878400 : tree t = *tp;
7148 : :
7149 : 6878400 : if (EXPR_P (t))
7150 : : {
7151 : 1074829 : tree block = TREE_BLOCK (t);
7152 : 1074829 : if (block == NULL_TREE)
7153 : : ;
7154 : 28535 : else if (block == p->orig_block
7155 : 26332 : || p->orig_block == NULL_TREE)
7156 : : {
7157 : : /* tree_node_can_be_shared says we can share invariant
7158 : : addresses but unshare_expr copies them anyways. Make sure
7159 : : to unshare before adjusting the block in place - we do not
7160 : : always see a copy here. */
7161 : 2212 : if (TREE_CODE (t) == ADDR_EXPR
7162 : 2212 : && is_gimple_min_invariant (t))
7163 : 2203 : *tp = t = unshare_expr (t);
7164 : 2212 : TREE_SET_BLOCK (t, p->new_block);
7165 : : }
7166 : 26323 : else if (flag_checking)
7167 : : {
7168 : 93855 : while (block && TREE_CODE (block) == BLOCK && block != p->orig_block)
7169 : 67532 : block = BLOCK_SUPERCONTEXT (block);
7170 : 26323 : gcc_assert (block == p->orig_block);
7171 : : }
7172 : : }
7173 : 5803571 : else if (DECL_P (t) || TREE_CODE (t) == SSA_NAME)
7174 : : {
7175 : 4253162 : if (TREE_CODE (t) == SSA_NAME)
7176 : 11754 : *tp = replace_ssa_name (t, p->vars_map, p->to_context);
7177 : 4241408 : else if (TREE_CODE (t) == PARM_DECL
7178 : 4241408 : && gimple_in_ssa_p (cfun))
7179 : 194 : *tp = *(p->vars_map->get (t));
7180 : 4241214 : else if (TREE_CODE (t) == LABEL_DECL)
7181 : : {
7182 : 3015 : if (p->new_label_map)
7183 : : {
7184 : 512 : struct tree_map in, *out;
7185 : 512 : in.base.from = t;
7186 : 512 : out = (struct tree_map *)
7187 : 512 : htab_find_with_hash (p->new_label_map, &in, DECL_UID (t));
7188 : 512 : if (out)
7189 : 0 : *tp = t = out->to;
7190 : : }
7191 : :
7192 : : /* For FORCED_LABELs we can end up with references from other
7193 : : functions if some SESE regions are outlined. It is UB to
7194 : : jump in between them, but they could be used just for printing
7195 : : addresses etc. In that case, DECL_CONTEXT on the label should
7196 : : be the function containing the glabel stmt with that LABEL_DECL,
7197 : : rather than whatever function a reference to the label was seen
7198 : : last time. */
7199 : 3015 : if (!FORCED_LABEL (t) && !DECL_NONLOCAL (t))
7200 : 3008 : DECL_CONTEXT (t) = p->to_context;
7201 : : }
7202 : 4238199 : else if (p->remap_decls_p)
7203 : : {
7204 : : /* Replace T with its duplicate. T should no longer appear in the
7205 : : parent function, so this looks wasteful; however, it may appear
7206 : : in referenced_vars, and more importantly, as virtual operands of
7207 : : statements, and in alias lists of other variables. It would be
7208 : : quite difficult to expunge it from all those places. ??? It might
7209 : : suffice to do this for addressable variables. */
7210 : 3566101 : if ((VAR_P (t) && !is_global_var (t))
7211 : 4278817 : || TREE_CODE (t) == CONST_DECL)
7212 : 3536037 : replace_by_duplicate_decl (tp, p->vars_map, p->to_context);
7213 : : }
7214 : 4253162 : *walk_subtrees = 0;
7215 : 4253162 : }
7216 : 1550409 : else if (TYPE_P (t))
7217 : 0 : *walk_subtrees = 0;
7218 : :
7219 : 6878400 : return NULL_TREE;
7220 : : }
7221 : :
7222 : : /* Helper for move_stmt_r. Given an EH region number for the source
7223 : : function, map that to the duplicate EH regio number in the dest. */
7224 : :
7225 : : static int
7226 : 0 : move_stmt_eh_region_nr (int old_nr, struct move_stmt_d *p)
7227 : : {
7228 : 0 : eh_region old_r, new_r;
7229 : :
7230 : 0 : old_r = get_eh_region_from_number (old_nr);
7231 : 0 : new_r = static_cast<eh_region> (*p->eh_map->get (old_r));
7232 : :
7233 : 0 : return new_r->index;
7234 : : }
7235 : :
7236 : : /* Similar, but operate on INTEGER_CSTs. */
7237 : :
7238 : : static tree
7239 : 0 : move_stmt_eh_region_tree_nr (tree old_t_nr, struct move_stmt_d *p)
7240 : : {
7241 : 0 : int old_nr, new_nr;
7242 : :
7243 : 0 : old_nr = tree_to_shwi (old_t_nr);
7244 : 0 : new_nr = move_stmt_eh_region_nr (old_nr, p);
7245 : :
7246 : 0 : return build_int_cst (integer_type_node, new_nr);
7247 : : }
7248 : :
7249 : : /* Like move_stmt_op, but for gimple statements.
7250 : :
7251 : : Helper for move_block_to_fn. Set GIMPLE_BLOCK in every expression
7252 : : contained in the current statement in *GSI_P and change the
7253 : : DECL_CONTEXT of every local variable referenced in the current
7254 : : statement. */
7255 : :
7256 : : static tree
7257 : 1958884 : move_stmt_r (gimple_stmt_iterator *gsi_p, bool *handled_ops_p,
7258 : : struct walk_stmt_info *wi)
7259 : : {
7260 : 1958884 : struct move_stmt_d *p = (struct move_stmt_d *) wi->info;
7261 : 1958884 : gimple *stmt = gsi_stmt (*gsi_p);
7262 : 1958884 : tree block = gimple_block (stmt);
7263 : :
7264 : 1958884 : if (block == p->orig_block
7265 : 1720556 : || (p->orig_block == NULL_TREE
7266 : 1050 : && block != NULL_TREE))
7267 : 239378 : gimple_set_block (stmt, p->new_block);
7268 : :
7269 : 1958884 : switch (gimple_code (stmt))
7270 : : {
7271 : 266124 : case GIMPLE_CALL:
7272 : : /* Remap the region numbers for __builtin_eh_{pointer,filter}. */
7273 : 266124 : {
7274 : 266124 : tree r, fndecl = gimple_call_fndecl (stmt);
7275 : 266124 : if (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
7276 : 95605 : switch (DECL_FUNCTION_CODE (fndecl))
7277 : : {
7278 : 0 : case BUILT_IN_EH_COPY_VALUES:
7279 : 0 : r = gimple_call_arg (stmt, 1);
7280 : 0 : r = move_stmt_eh_region_tree_nr (r, p);
7281 : 0 : gimple_call_set_arg (stmt, 1, r);
7282 : : /* FALLTHRU */
7283 : :
7284 : 0 : case BUILT_IN_EH_POINTER:
7285 : 0 : case BUILT_IN_EH_FILTER:
7286 : 0 : r = gimple_call_arg (stmt, 0);
7287 : 0 : r = move_stmt_eh_region_tree_nr (r, p);
7288 : 0 : gimple_call_set_arg (stmt, 0, r);
7289 : 0 : break;
7290 : :
7291 : : default:
7292 : : break;
7293 : : }
7294 : : }
7295 : : break;
7296 : :
7297 : 0 : case GIMPLE_RESX:
7298 : 0 : {
7299 : 0 : gresx *resx_stmt = as_a <gresx *> (stmt);
7300 : 0 : int r = gimple_resx_region (resx_stmt);
7301 : 0 : r = move_stmt_eh_region_nr (r, p);
7302 : 0 : gimple_resx_set_region (resx_stmt, r);
7303 : : }
7304 : 0 : break;
7305 : :
7306 : 0 : case GIMPLE_EH_DISPATCH:
7307 : 0 : {
7308 : 0 : geh_dispatch *eh_dispatch_stmt = as_a <geh_dispatch *> (stmt);
7309 : 0 : int r = gimple_eh_dispatch_region (eh_dispatch_stmt);
7310 : 0 : r = move_stmt_eh_region_nr (r, p);
7311 : 0 : gimple_eh_dispatch_set_region (eh_dispatch_stmt, r);
7312 : : }
7313 : 0 : break;
7314 : :
7315 : : case GIMPLE_OMP_RETURN:
7316 : : case GIMPLE_OMP_CONTINUE:
7317 : : break;
7318 : :
7319 : 1512 : case GIMPLE_LABEL:
7320 : 1512 : {
7321 : : /* For FORCED_LABEL, move_stmt_op doesn't adjust DECL_CONTEXT,
7322 : : so that such labels can be referenced from other regions.
7323 : : Make sure to update it when seeing a GIMPLE_LABEL though,
7324 : : that is the owner of the label. */
7325 : 1512 : walk_gimple_op (stmt, move_stmt_op, wi);
7326 : 1512 : *handled_ops_p = true;
7327 : 1512 : tree label = gimple_label_label (as_a <glabel *> (stmt));
7328 : 1512 : if (FORCED_LABEL (label) || DECL_NONLOCAL (label))
7329 : 5 : DECL_CONTEXT (label) = p->to_context;
7330 : : }
7331 : : break;
7332 : :
7333 : 1691248 : default:
7334 : 1691248 : if (is_gimple_omp (stmt))
7335 : : {
7336 : : /* Do not remap variables inside OMP directives. Variables
7337 : : referenced in clauses and directive header belong to the
7338 : : parent function and should not be moved into the child
7339 : : function. */
7340 : 0 : bool save_remap_decls_p = p->remap_decls_p;
7341 : 0 : p->remap_decls_p = false;
7342 : 0 : *handled_ops_p = true;
7343 : :
7344 : 0 : walk_gimple_seq_mod (gimple_omp_body_ptr (stmt), move_stmt_r,
7345 : : move_stmt_op, wi);
7346 : :
7347 : 0 : p->remap_decls_p = save_remap_decls_p;
7348 : : }
7349 : : break;
7350 : : }
7351 : :
7352 : 1958884 : return NULL_TREE;
7353 : : }
7354 : :
7355 : : /* Move basic block BB from function CFUN to function DEST_FN. The
7356 : : block is moved out of the original linked list and placed after
7357 : : block AFTER in the new list. Also, the block is removed from the
7358 : : original array of blocks and placed in DEST_FN's array of blocks.
7359 : : If UPDATE_EDGE_COUNT_P is true, the edge counts on both CFGs is
7360 : : updated to reflect the moved edges.
7361 : :
7362 : : The local variables are remapped to new instances, VARS_MAP is used
7363 : : to record the mapping. */
7364 : :
7365 : : static void
7366 : 607755 : move_block_to_fn (struct function *dest_cfun, basic_block bb,
7367 : : basic_block after, bool update_edge_count_p,
7368 : : struct move_stmt_d *d)
7369 : : {
7370 : 607755 : struct control_flow_graph *cfg;
7371 : 607755 : edge_iterator ei;
7372 : 607755 : edge e;
7373 : 607755 : gimple_stmt_iterator si;
7374 : 607755 : unsigned old_len;
7375 : :
7376 : : /* Remove BB from dominance structures. */
7377 : 607755 : delete_from_dominance_info (CDI_DOMINATORS, bb);
7378 : :
7379 : : /* Move BB from its current loop to the copy in the new function. */
7380 : 607755 : if (current_loops)
7381 : : {
7382 : 607755 : class loop *new_loop = (class loop *)bb->loop_father->aux;
7383 : 607755 : if (new_loop)
7384 : 349494 : bb->loop_father = new_loop;
7385 : : }
7386 : :
7387 : : /* Link BB to the new linked list. */
7388 : 607755 : move_block_after (bb, after);
7389 : :
7390 : : /* Update the edge count in the corresponding flowgraphs. */
7391 : 607755 : if (update_edge_count_p)
7392 : 1303134 : FOR_EACH_EDGE (e, ei, bb->succs)
7393 : : {
7394 : 737528 : cfun->cfg->x_n_edges--;
7395 : 737528 : dest_cfun->cfg->x_n_edges++;
7396 : : }
7397 : :
7398 : : /* Remove BB from the original basic block array. */
7399 : 607755 : (*cfun->cfg->x_basic_block_info)[bb->index] = NULL;
7400 : 607755 : cfun->cfg->x_n_basic_blocks--;
7401 : :
7402 : : /* Grow DEST_CFUN's basic block array if needed. */
7403 : 607755 : cfg = dest_cfun->cfg;
7404 : 607755 : cfg->x_n_basic_blocks++;
7405 : 607755 : if (bb->index >= cfg->x_last_basic_block)
7406 : 42271 : cfg->x_last_basic_block = bb->index + 1;
7407 : :
7408 : 607755 : old_len = vec_safe_length (cfg->x_basic_block_info);
7409 : 607755 : if ((unsigned) cfg->x_last_basic_block >= old_len)
7410 : 34199 : vec_safe_grow_cleared (cfg->x_basic_block_info,
7411 : 34199 : cfg->x_last_basic_block + 1);
7412 : :
7413 : 607755 : (*cfg->x_basic_block_info)[bb->index] = bb;
7414 : :
7415 : : /* Remap the variables in phi nodes. */
7416 : 607755 : for (gphi_iterator psi = gsi_start_phis (bb);
7417 : 609032 : !gsi_end_p (psi); )
7418 : : {
7419 : 1277 : gphi *phi = psi.phi ();
7420 : 1277 : use_operand_p use;
7421 : 1277 : tree op = PHI_RESULT (phi);
7422 : 1277 : ssa_op_iter oi;
7423 : 1277 : unsigned i;
7424 : :
7425 : 2554 : if (virtual_operand_p (op))
7426 : : {
7427 : : /* Remove the phi nodes for virtual operands (alias analysis will be
7428 : : run for the new function, anyway). But replace all uses that
7429 : : might be outside of the region we move. */
7430 : 567 : use_operand_p use_p;
7431 : 567 : imm_use_iterator iter;
7432 : 567 : gimple *use_stmt;
7433 : 1127 : FOR_EACH_IMM_USE_STMT (use_stmt, iter, op)
7434 : 1680 : FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
7435 : 1127 : SET_USE (use_p, SSA_NAME_VAR (op));
7436 : 567 : remove_phi_node (&psi, true);
7437 : 567 : continue;
7438 : 567 : }
7439 : :
7440 : 710 : SET_PHI_RESULT (phi,
7441 : : replace_ssa_name (op, d->vars_map, dest_cfun->decl));
7442 : 1871 : FOR_EACH_PHI_ARG (use, phi, oi, SSA_OP_USE)
7443 : : {
7444 : 1161 : op = USE_FROM_PTR (use);
7445 : 1161 : if (TREE_CODE (op) == SSA_NAME)
7446 : 989 : SET_USE (use, replace_ssa_name (op, d->vars_map, dest_cfun->decl));
7447 : : }
7448 : :
7449 : 3742 : for (i = 0; i < EDGE_COUNT (bb->preds); i++)
7450 : : {
7451 : 1161 : location_t locus = gimple_phi_arg_location (phi, i);
7452 : 1161 : tree block = LOCATION_BLOCK (locus);
7453 : :
7454 : 1161 : if (locus == UNKNOWN_LOCATION)
7455 : 967 : continue;
7456 : 194 : if (d->orig_block == NULL_TREE || block == d->orig_block)
7457 : : {
7458 : 194 : locus = set_block (locus, d->new_block);
7459 : 194 : gimple_phi_arg_set_location (phi, i, locus);
7460 : : }
7461 : : }
7462 : :
7463 : 710 : gsi_next (&psi);
7464 : : }
7465 : :
7466 : 3174394 : for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
7467 : : {
7468 : 1958884 : gimple *stmt = gsi_stmt (si);
7469 : 1958884 : struct walk_stmt_info wi;
7470 : :
7471 : 1958884 : memset (&wi, 0, sizeof (wi));
7472 : 1958884 : wi.info = d;
7473 : 1958884 : walk_gimple_stmt (&si, move_stmt_r, move_stmt_op, &wi);
7474 : :
7475 : 1958884 : if (glabel *label_stmt = dyn_cast <glabel *> (stmt))
7476 : : {
7477 : 1512 : tree label = gimple_label_label (label_stmt);
7478 : 1512 : int uid = LABEL_DECL_UID (label);
7479 : :
7480 : 1512 : gcc_assert (uid > -1);
7481 : :
7482 : 1512 : old_len = vec_safe_length (cfg->x_label_to_block_map);
7483 : 1512 : if (old_len <= (unsigned) uid)
7484 : 189 : vec_safe_grow_cleared (cfg->x_label_to_block_map, uid + 1);
7485 : :
7486 : 1512 : (*cfg->x_label_to_block_map)[uid] = bb;
7487 : 1512 : (*cfun->cfg->x_label_to_block_map)[uid] = NULL;
7488 : :
7489 : 1512 : gcc_assert (DECL_CONTEXT (label) == dest_cfun->decl);
7490 : :
7491 : 1512 : if (uid >= dest_cfun->cfg->last_label_uid)
7492 : 352 : dest_cfun->cfg->last_label_uid = uid + 1;
7493 : : }
7494 : :
7495 : 1958884 : maybe_duplicate_eh_stmt_fn (dest_cfun, stmt, cfun, stmt, d->eh_map, 0);
7496 : 1958884 : remove_stmt_from_eh_lp_fn (cfun, stmt);
7497 : :
7498 : 1958884 : gimple_duplicate_stmt_histograms (dest_cfun, stmt, cfun, stmt);
7499 : 1958884 : gimple_remove_stmt_histograms (cfun, stmt);
7500 : :
7501 : : /* We cannot leave any operands allocated from the operand caches of
7502 : : the current function. */
7503 : 1958884 : free_stmt_operands (cfun, stmt);
7504 : 1958884 : push_cfun (dest_cfun);
7505 : 1958884 : update_stmt (stmt);
7506 : 1958884 : if (is_gimple_call (stmt))
7507 : 266124 : notice_special_calls (as_a <gcall *> (stmt));
7508 : 1958884 : pop_cfun ();
7509 : : }
7510 : :
7511 : 1345283 : FOR_EACH_EDGE (e, ei, bb->succs)
7512 : 737528 : if (e->goto_locus != UNKNOWN_LOCATION)
7513 : : {
7514 : 209816 : tree block = LOCATION_BLOCK (e->goto_locus);
7515 : 209816 : if (d->orig_block == NULL_TREE
7516 : 209616 : || block == d->orig_block)
7517 : 25124 : e->goto_locus = set_block (e->goto_locus, d->new_block);
7518 : : }
7519 : 607755 : }
7520 : :
7521 : : /* Examine the statements in BB (which is in SRC_CFUN); find and return
7522 : : the outermost EH region. Use REGION as the incoming base EH region.
7523 : : If there is no single outermost region, return NULL and set *ALL to
7524 : : true. */
7525 : :
7526 : : static eh_region
7527 : 607750 : find_outermost_region_in_block (struct function *src_cfun,
7528 : : basic_block bb, eh_region region,
7529 : : bool *all)
7530 : : {
7531 : 607750 : gimple_stmt_iterator si;
7532 : :
7533 : 3174372 : for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
7534 : : {
7535 : 1958873 : gimple *stmt = gsi_stmt (si);
7536 : 1958873 : eh_region stmt_region;
7537 : 1958873 : int lp_nr;
7538 : :
7539 : 1958873 : lp_nr = lookup_stmt_eh_lp_fn (src_cfun, stmt);
7540 : 1958873 : stmt_region = get_eh_region_from_lp_number_fn (src_cfun, lp_nr);
7541 : 1958873 : if (stmt_region)
7542 : : {
7543 : 3258 : if (region == NULL)
7544 : : region = stmt_region;
7545 : 1240 : else if (stmt_region != region)
7546 : : {
7547 : 204 : region = eh_region_outermost (src_cfun, stmt_region, region);
7548 : 204 : if (region == NULL)
7549 : : {
7550 : 1 : *all = true;
7551 : 1 : return NULL;
7552 : : }
7553 : : }
7554 : : }
7555 : : }
7556 : :
7557 : : return region;
7558 : : }
7559 : :
7560 : : static tree
7561 : 0 : new_label_mapper (tree decl, void *data)
7562 : : {
7563 : 0 : htab_t hash = (htab_t) data;
7564 : 0 : struct tree_map *m;
7565 : 0 : void **slot;
7566 : :
7567 : 0 : gcc_assert (TREE_CODE (decl) == LABEL_DECL);
7568 : :
7569 : 0 : m = XNEW (struct tree_map);
7570 : 0 : m->hash = DECL_UID (decl);
7571 : 0 : m->base.from = decl;
7572 : 0 : m->to = create_artificial_label (UNKNOWN_LOCATION);
7573 : 0 : LABEL_DECL_UID (m->to) = LABEL_DECL_UID (decl);
7574 : 0 : if (LABEL_DECL_UID (m->to) >= cfun->cfg->last_label_uid)
7575 : 0 : cfun->cfg->last_label_uid = LABEL_DECL_UID (m->to) + 1;
7576 : :
7577 : 0 : slot = htab_find_slot_with_hash (hash, m, m->hash, INSERT);
7578 : 0 : gcc_assert (*slot == NULL);
7579 : :
7580 : 0 : *slot = m;
7581 : :
7582 : 0 : return m->to;
7583 : : }
7584 : :
7585 : : /* Tree walker to replace the decls used inside value expressions by
7586 : : duplicates. */
7587 : :
7588 : : static tree
7589 : 250462 : replace_block_vars_by_duplicates_1 (tree *tp, int *walk_subtrees, void *data)
7590 : : {
7591 : 250462 : struct replace_decls_d *rd = (struct replace_decls_d *)data;
7592 : :
7593 : 250462 : switch (TREE_CODE (*tp))
7594 : : {
7595 : 47951 : case VAR_DECL:
7596 : 47951 : case PARM_DECL:
7597 : 47951 : case RESULT_DECL:
7598 : 47951 : replace_by_duplicate_decl (tp, rd->vars_map, rd->to_context);
7599 : 47951 : break;
7600 : : default:
7601 : : break;
7602 : : }
7603 : :
7604 : 250462 : if (IS_TYPE_OR_DECL_P (*tp))
7605 : 81270 : *walk_subtrees = false;
7606 : :
7607 : 250462 : return NULL;
7608 : : }
7609 : :
7610 : : /* Change DECL_CONTEXT of all BLOCK_VARS in block, including
7611 : : subblocks. */
7612 : :
7613 : : static void
7614 : 163281 : replace_block_vars_by_duplicates (tree block, hash_map<tree, tree> *vars_map,
7615 : : tree to_context)
7616 : : {
7617 : 163281 : tree *tp, t;
7618 : :
7619 : 790404 : for (tp = &BLOCK_VARS (block); *tp; tp = &DECL_CHAIN (*tp))
7620 : : {
7621 : 627123 : t = *tp;
7622 : 627123 : if (!VAR_P (t) && TREE_CODE (t) != CONST_DECL)
7623 : 7239 : continue;
7624 : 619884 : replace_by_duplicate_decl (&t, vars_map, to_context);
7625 : 619884 : if (t != *tp)
7626 : : {
7627 : 619884 : if (VAR_P (*tp) && DECL_HAS_VALUE_EXPR_P (*tp))
7628 : : {
7629 : 43057 : tree x = DECL_VALUE_EXPR (*tp);
7630 : 43057 : struct replace_decls_d rd = { vars_map, to_context };
7631 : 43057 : unshare_expr (x);
7632 : 43057 : walk_tree (&x, replace_block_vars_by_duplicates_1, &rd, NULL);
7633 : 43057 : SET_DECL_VALUE_EXPR (t, x);
7634 : 43057 : DECL_HAS_VALUE_EXPR_P (t) = 1;
7635 : : }
7636 : 619884 : DECL_CHAIN (t) = DECL_CHAIN (*tp);
7637 : 619884 : *tp = t;
7638 : : }
7639 : : }
7640 : :
7641 : 284291 : for (block = BLOCK_SUBBLOCKS (block); block; block = BLOCK_CHAIN (block))
7642 : 121010 : replace_block_vars_by_duplicates (block, vars_map, to_context);
7643 : 163281 : }
7644 : :
7645 : : /* Fixup the loop arrays and numbers after moving LOOP and its subloops
7646 : : from FN1 to FN2. */
7647 : :
7648 : : static void
7649 : 67154 : fixup_loop_arrays_after_move (struct function *fn1, struct function *fn2,
7650 : : class loop *loop)
7651 : : {
7652 : : /* Discard it from the old loop array. */
7653 : 134308 : (*get_loops (fn1))[loop->num] = NULL;
7654 : :
7655 : : /* Place it in the new loop array, assigning it a new number. */
7656 : 67154 : loop->num = number_of_loops (fn2);
7657 : 67154 : vec_safe_push (loops_for_fn (fn2)->larray, loop);
7658 : :
7659 : : /* Recurse to children. */
7660 : 94816 : for (loop = loop->inner; loop; loop = loop->next)
7661 : 27662 : fixup_loop_arrays_after_move (fn1, fn2, loop);
7662 : 67154 : }
7663 : :
7664 : : /* Verify that the blocks in BBS_P are a single-entry, single-exit region
7665 : : delimited by ENTRY_BB and EXIT_BB, possibly containing noreturn blocks. */
7666 : :
7667 : : DEBUG_FUNCTION void
7668 : 42271 : verify_sese (basic_block entry, basic_block exit, vec<basic_block> *bbs_p)
7669 : : {
7670 : 42271 : basic_block bb;
7671 : 42271 : edge_iterator ei;
7672 : 42271 : edge e;
7673 : 42271 : bitmap bbs = BITMAP_ALLOC (NULL);
7674 : 42271 : int i;
7675 : :
7676 : 42271 : gcc_assert (entry != NULL);
7677 : 42271 : gcc_assert (entry != exit);
7678 : 42271 : gcc_assert (bbs_p != NULL);
7679 : :
7680 : 42271 : gcc_assert (bbs_p->length () > 0);
7681 : :
7682 : 650026 : FOR_EACH_VEC_ELT (*bbs_p, i, bb)
7683 : 607755 : bitmap_set_bit (bbs, bb->index);
7684 : :
7685 : 42271 : gcc_assert (bitmap_bit_p (bbs, entry->index));
7686 : 42271 : gcc_assert (exit == NULL || bitmap_bit_p (bbs, exit->index));
7687 : :
7688 : 650026 : FOR_EACH_VEC_ELT (*bbs_p, i, bb)
7689 : : {
7690 : 607755 : if (bb == entry)
7691 : : {
7692 : 84542 : gcc_assert (single_pred_p (entry));
7693 : 42271 : gcc_assert (!bitmap_bit_p (bbs, single_pred (entry)->index));
7694 : : }
7695 : : else
7696 : 1303012 : for (ei = ei_start (bb->preds); !ei_end_p (ei); ei_next (&ei))
7697 : : {
7698 : 737528 : e = ei_edge (ei);
7699 : 737528 : gcc_assert (bitmap_bit_p (bbs, e->src->index));
7700 : : }
7701 : :
7702 : 607755 : if (bb == exit)
7703 : : {
7704 : 84298 : gcc_assert (single_succ_p (exit));
7705 : 42149 : gcc_assert (!bitmap_bit_p (bbs, single_succ (exit)->index));
7706 : : }
7707 : : else
7708 : 1303134 : for (ei = ei_start (bb->succs); !ei_end_p (ei); ei_next (&ei))
7709 : : {
7710 : 737528 : e = ei_edge (ei);
7711 : 737528 : gcc_assert (bitmap_bit_p (bbs, e->dest->index));
7712 : : }
7713 : : }
7714 : :
7715 : 42271 : BITMAP_FREE (bbs);
7716 : 42271 : }
7717 : :
7718 : : /* If FROM is an SSA_NAME, mark the version in bitmap DATA. */
7719 : :
7720 : : bool
7721 : 1250540 : gather_ssa_name_hash_map_from (tree const &from, tree const &, void *data)
7722 : : {
7723 : 1250540 : bitmap release_names = (bitmap)data;
7724 : :
7725 : 1250540 : if (TREE_CODE (from) != SSA_NAME)
7726 : : return true;
7727 : :
7728 : 5507 : bitmap_set_bit (release_names, SSA_NAME_VERSION (from));
7729 : 5507 : return true;
7730 : : }
7731 : :
7732 : : /* Return LOOP_DIST_ALIAS call if present in BB. */
7733 : :
7734 : : static gimple *
7735 : 113 : find_loop_dist_alias (basic_block bb)
7736 : : {
7737 : 113 : gimple_stmt_iterator gsi = gsi_last_bb (bb);
7738 : 142 : if (!safe_is_a <gcond *> (*gsi))
7739 : : return NULL;
7740 : :
7741 : 30 : gsi_prev (&gsi);
7742 : 30 : if (gsi_end_p (gsi))
7743 : : return NULL;
7744 : :
7745 : 22 : gimple *g = gsi_stmt (gsi);
7746 : 22 : if (gimple_call_internal_p (g, IFN_LOOP_DIST_ALIAS))
7747 : : return g;
7748 : : return NULL;
7749 : : }
7750 : :
7751 : : /* Fold loop internal call G like IFN_LOOP_VECTORIZED/IFN_LOOP_DIST_ALIAS
7752 : : to VALUE and update any immediate uses of it's LHS. */
7753 : :
7754 : : void
7755 : 20749 : fold_loop_internal_call (gimple *g, tree value)
7756 : : {
7757 : 20749 : tree lhs = gimple_call_lhs (g);
7758 : 20749 : use_operand_p use_p;
7759 : 20749 : imm_use_iterator iter;
7760 : 20749 : gimple *use_stmt;
7761 : 20749 : gimple_stmt_iterator gsi = gsi_for_stmt (g);
7762 : :
7763 : 20749 : replace_call_with_value (&gsi, value);
7764 : 41433 : FOR_EACH_IMM_USE_STMT (use_stmt, iter, lhs)
7765 : : {
7766 : 62052 : FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
7767 : 20684 : SET_USE (use_p, value);
7768 : 20684 : update_stmt (use_stmt);
7769 : : /* If we turn conditional to constant, scale profile counts.
7770 : : We know that the conditional was created by loop distribution
7771 : : and all basic blocks dominated by the taken edge are part of
7772 : : the loop distributed. */
7773 : 20684 : if (gimple_code (use_stmt) == GIMPLE_COND)
7774 : : {
7775 : 20684 : edge true_edge, false_edge;
7776 : 20684 : extract_true_false_edges_from_block (gimple_bb (use_stmt),
7777 : : &true_edge, &false_edge);
7778 : 20684 : edge taken_edge = NULL, other_edge = NULL;
7779 : 20684 : if (gimple_cond_true_p (as_a <gcond *>(use_stmt)))
7780 : : {
7781 : 4057 : taken_edge = true_edge;
7782 : 4057 : other_edge = false_edge;
7783 : : }
7784 : 16627 : else if (gimple_cond_false_p (as_a <gcond *>(use_stmt)))
7785 : : {
7786 : 16618 : taken_edge = false_edge;
7787 : 16618 : other_edge = true_edge;
7788 : : }
7789 : 20675 : if (taken_edge
7790 : 41359 : && !(taken_edge->probability == profile_probability::always ()))
7791 : : {
7792 : 16 : profile_count old_count = taken_edge->count ();
7793 : 16 : profile_count new_count = taken_edge->src->count;
7794 : 16 : taken_edge->probability = profile_probability::always ();
7795 : 16 : other_edge->probability = profile_probability::never ();
7796 : : /* If we have multiple predecessors, we can't use the dominance
7797 : : test. This should not happen as the guarded code should
7798 : : start with pre-header. */
7799 : 16 : gcc_assert (single_pred_edge (taken_edge->dest));
7800 : 32 : if (old_count.nonzero_p ())
7801 : : {
7802 : 14 : taken_edge->dest->count
7803 : 14 : = taken_edge->dest->count.apply_scale (new_count,
7804 : : old_count);
7805 : 14 : scale_strictly_dominated_blocks (taken_edge->dest,
7806 : : new_count, old_count);
7807 : : }
7808 : : }
7809 : : }
7810 : 20749 : }
7811 : 20749 : }
7812 : :
7813 : : /* Move a single-entry, single-exit region delimited by ENTRY_BB and
7814 : : EXIT_BB to function DEST_CFUN. The whole region is replaced by a
7815 : : single basic block in the original CFG and the new basic block is
7816 : : returned. DEST_CFUN must not have a CFG yet.
7817 : :
7818 : : Note that the region need not be a pure SESE region. Blocks inside
7819 : : the region may contain calls to abort/exit. The only restriction
7820 : : is that ENTRY_BB should be the only entry point and it must
7821 : : dominate EXIT_BB.
7822 : :
7823 : : Change TREE_BLOCK of all statements in ORIG_BLOCK to the new
7824 : : functions outermost BLOCK, move all subblocks of ORIG_BLOCK
7825 : : to the new function.
7826 : :
7827 : : All local variables referenced in the region are assumed to be in
7828 : : the corresponding BLOCK_VARS and unexpanded variable lists
7829 : : associated with DEST_CFUN.
7830 : :
7831 : : TODO: investigate whether we can reuse gimple_duplicate_sese_region to
7832 : : reimplement move_sese_region_to_fn by duplicating the region rather than
7833 : : moving it. */
7834 : :
7835 : : basic_block
7836 : 42271 : move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb,
7837 : : basic_block exit_bb, tree orig_block)
7838 : : {
7839 : 42271 : vec<basic_block> bbs;
7840 : 42271 : basic_block dom_entry = get_immediate_dominator (CDI_DOMINATORS, entry_bb);
7841 : 42271 : basic_block after, bb, *entry_pred, *exit_succ, abb;
7842 : 42271 : struct function *saved_cfun = cfun;
7843 : 42271 : int *entry_flag, *exit_flag;
7844 : 42271 : profile_probability *entry_prob, *exit_prob;
7845 : 42271 : unsigned i, num_entry_edges, num_exit_edges, num_nodes;
7846 : 42271 : edge e;
7847 : 42271 : edge_iterator ei;
7848 : 42271 : htab_t new_label_map;
7849 : 42271 : hash_map<void *, void *> *eh_map;
7850 : 42271 : class loop *loop = entry_bb->loop_father;
7851 : 42271 : class loop *loop0 = get_loop (saved_cfun, 0);
7852 : 42271 : struct move_stmt_d d;
7853 : :
7854 : : /* If ENTRY does not strictly dominate EXIT, this cannot be an SESE
7855 : : region. */
7856 : 42271 : gcc_assert (entry_bb != exit_bb
7857 : : && (!exit_bb
7858 : : || dominated_by_p (CDI_DOMINATORS, exit_bb, entry_bb)));
7859 : :
7860 : : /* Collect all the blocks in the region. Manually add ENTRY_BB
7861 : : because it won't be added by dfs_enumerate_from. */
7862 : 42271 : bbs.create (0);
7863 : 42271 : bbs.safe_push (entry_bb);
7864 : 42271 : gather_blocks_in_sese_region (entry_bb, exit_bb, &bbs);
7865 : :
7866 : 42271 : if (flag_checking)
7867 : 42271 : verify_sese (entry_bb, exit_bb, &bbs);
7868 : :
7869 : : /* The blocks that used to be dominated by something in BBS will now be
7870 : : dominated by the new block. */
7871 : 42271 : auto_vec<basic_block> dom_bbs = get_dominated_by_region (CDI_DOMINATORS,
7872 : : bbs.address (),
7873 : 84542 : bbs.length ());
7874 : :
7875 : : /* Detach ENTRY_BB and EXIT_BB from CFUN->CFG. We need to remember
7876 : : the predecessor edges to ENTRY_BB and the successor edges to
7877 : : EXIT_BB so that we can re-attach them to the new basic block that
7878 : : will replace the region. */
7879 : 42271 : num_entry_edges = EDGE_COUNT (entry_bb->preds);
7880 : 42271 : entry_pred = XNEWVEC (basic_block, num_entry_edges);
7881 : 42271 : entry_flag = XNEWVEC (int, num_entry_edges);
7882 : 42271 : entry_prob = XNEWVEC (profile_probability, num_entry_edges);
7883 : 42271 : i = 0;
7884 : 84542 : for (ei = ei_start (entry_bb->preds); (e = ei_safe_edge (ei)) != NULL;)
7885 : : {
7886 : 42271 : entry_prob[i] = e->probability;
7887 : 42271 : entry_flag[i] = e->flags;
7888 : 42271 : entry_pred[i++] = e->src;
7889 : 42271 : remove_edge (e);
7890 : : }
7891 : :
7892 : 42271 : if (exit_bb)
7893 : : {
7894 : 42149 : num_exit_edges = EDGE_COUNT (exit_bb->succs);
7895 : 42149 : exit_succ = XNEWVEC (basic_block, num_exit_edges);
7896 : 42149 : exit_flag = XNEWVEC (int, num_exit_edges);
7897 : 42149 : exit_prob = XNEWVEC (profile_probability, num_exit_edges);
7898 : 42149 : i = 0;
7899 : 84298 : for (ei = ei_start (exit_bb->succs); (e = ei_safe_edge (ei)) != NULL;)
7900 : : {
7901 : 42149 : exit_prob[i] = e->probability;
7902 : 42149 : exit_flag[i] = e->flags;
7903 : 42149 : exit_succ[i++] = e->dest;
7904 : 42149 : remove_edge (e);
7905 : : }
7906 : : }
7907 : : else
7908 : : {
7909 : : num_exit_edges = 0;
7910 : : exit_succ = NULL;
7911 : : exit_flag = NULL;
7912 : : exit_prob = NULL;
7913 : : }
7914 : :
7915 : : /* Switch context to the child function to initialize DEST_FN's CFG. */
7916 : 42271 : gcc_assert (dest_cfun->cfg == NULL);
7917 : 42271 : push_cfun (dest_cfun);
7918 : :
7919 : 42271 : init_empty_tree_cfg ();
7920 : :
7921 : : /* Initialize EH information for the new function. */
7922 : 42271 : eh_map = NULL;
7923 : 42271 : new_label_map = NULL;
7924 : 42271 : if (saved_cfun->eh)
7925 : : {
7926 : 42271 : eh_region region = NULL;
7927 : 42271 : bool all = false;
7928 : :
7929 : 650020 : FOR_EACH_VEC_ELT (bbs, i, bb)
7930 : : {
7931 : 607750 : region = find_outermost_region_in_block (saved_cfun, bb, region, &all);
7932 : 607750 : if (all)
7933 : : break;
7934 : : }
7935 : :
7936 : 42271 : init_eh_for_function ();
7937 : 42271 : if (region != NULL || all)
7938 : : {
7939 : 2018 : new_label_map = htab_create (17, tree_map_hash, tree_map_eq, free);
7940 : 2018 : eh_map = duplicate_eh_regions (saved_cfun, region, 0,
7941 : : new_label_mapper, new_label_map);
7942 : : }
7943 : : }
7944 : :
7945 : : /* Initialize an empty loop tree. */
7946 : 42271 : struct loops *loops = ggc_cleared_alloc<struct loops> ();
7947 : 42271 : init_loops_structure (dest_cfun, loops, 1);
7948 : 42271 : loops->state = LOOPS_MAY_HAVE_MULTIPLE_LATCHES;
7949 : 42271 : set_loops_for_fn (dest_cfun, loops);
7950 : :
7951 : 84542 : vec<loop_p, va_gc> *larray = get_loops (saved_cfun)->copy ();
7952 : :
7953 : : /* Move the outlined loop tree part. */
7954 : 42271 : num_nodes = bbs.length ();
7955 : 650026 : FOR_EACH_VEC_ELT (bbs, i, bb)
7956 : : {
7957 : 607755 : if (bb->loop_father->header == bb)
7958 : : {
7959 : 67154 : class loop *this_loop = bb->loop_father;
7960 : : /* Avoid the need to remap SSA names used in nb_iterations. */
7961 : 67154 : free_numbers_of_iterations_estimates (this_loop);
7962 : 67154 : class loop *outer = loop_outer (this_loop);
7963 : 67154 : if (outer == loop
7964 : : /* If the SESE region contains some bbs ending with
7965 : : a noreturn call, those are considered to belong
7966 : : to the outermost loop in saved_cfun, rather than
7967 : : the entry_bb's loop_father. */
7968 : 67154 : || outer == loop0)
7969 : : {
7970 : 39492 : if (outer != loop)
7971 : 10 : num_nodes -= this_loop->num_nodes;
7972 : 39492 : flow_loop_tree_node_remove (bb->loop_father);
7973 : 39492 : flow_loop_tree_node_add (get_loop (dest_cfun, 0), this_loop);
7974 : 39492 : fixup_loop_arrays_after_move (saved_cfun, cfun, this_loop);
7975 : : }
7976 : : }
7977 : 540601 : else if (bb->loop_father == loop0 && loop0 != loop)
7978 : 1229 : num_nodes--;
7979 : :
7980 : : /* Remove loop exits from the outlined region. */
7981 : 607755 : if (loops_for_fn (saved_cfun)->exits)
7982 : 5991 : FOR_EACH_EDGE (e, ei, bb->succs)
7983 : : {
7984 : 3252 : struct loops *l = loops_for_fn (saved_cfun);
7985 : 3252 : loop_exit **slot
7986 : 3252 : = l->exits->find_slot_with_hash (e, htab_hash_pointer (e),
7987 : : NO_INSERT);
7988 : 3252 : if (slot)
7989 : 312 : l->exits->clear_slot (slot);
7990 : : }
7991 : : }
7992 : :
7993 : : /* Adjust the number of blocks in the tree root of the outlined part. */
7994 : 84542 : get_loop (dest_cfun, 0)->num_nodes = bbs.length () + 2;
7995 : :
7996 : : /* Setup a mapping to be used by move_block_to_fn. */
7997 : 42271 : loop->aux = current_loops->tree_root;
7998 : 42271 : loop0->aux = current_loops->tree_root;
7999 : :
8000 : : /* Fix up orig_loop_num. If the block referenced in it has been moved
8001 : : to dest_cfun, update orig_loop_num field, otherwise clear it. */
8002 : 42271 : signed char *moved_orig_loop_num = NULL;
8003 : 193967 : for (auto dloop : loops_list (dest_cfun, 0))
8004 : 67154 : if (dloop->orig_loop_num)
8005 : : {
8006 : 2 : if (moved_orig_loop_num == NULL)
8007 : 2 : moved_orig_loop_num
8008 : 2 : = XCNEWVEC (signed char, vec_safe_length (larray));
8009 : 2 : if ((*larray)[dloop->orig_loop_num] != NULL
8010 : 2 : && get_loop (saved_cfun, dloop->orig_loop_num) == NULL)
8011 : : {
8012 : 0 : if (moved_orig_loop_num[dloop->orig_loop_num] >= 0
8013 : 0 : && moved_orig_loop_num[dloop->orig_loop_num] < 2)
8014 : 0 : moved_orig_loop_num[dloop->orig_loop_num]++;
8015 : 0 : dloop->orig_loop_num = (*larray)[dloop->orig_loop_num]->num;
8016 : : }
8017 : : else
8018 : : {
8019 : 2 : moved_orig_loop_num[dloop->orig_loop_num] = -1;
8020 : 2 : dloop->orig_loop_num = 0;
8021 : : }
8022 : 42271 : }
8023 : 42271 : pop_cfun ();
8024 : :
8025 : 42271 : if (moved_orig_loop_num)
8026 : : {
8027 : 29 : FOR_EACH_VEC_ELT (bbs, i, bb)
8028 : : {
8029 : 27 : gimple *g = find_loop_dist_alias (bb);
8030 : 27 : if (g == NULL)
8031 : 27 : continue;
8032 : :
8033 : 0 : int orig_loop_num = tree_to_shwi (gimple_call_arg (g, 0));
8034 : 0 : gcc_assert (orig_loop_num
8035 : : && (unsigned) orig_loop_num < vec_safe_length (larray));
8036 : 0 : if (moved_orig_loop_num[orig_loop_num] == 2)
8037 : : {
8038 : : /* If we have moved both loops with this orig_loop_num into
8039 : : dest_cfun and the LOOP_DIST_ALIAS call is being moved there
8040 : : too, update the first argument. */
8041 : 0 : gcc_assert ((*larray)[orig_loop_num] != NULL
8042 : : && (get_loop (saved_cfun, orig_loop_num) == NULL));
8043 : 0 : tree t = build_int_cst (integer_type_node,
8044 : 0 : (*larray)[orig_loop_num]->num);
8045 : 0 : gimple_call_set_arg (g, 0, t);
8046 : 0 : update_stmt (g);
8047 : : /* Make sure the following loop will not update it. */
8048 : 0 : moved_orig_loop_num[orig_loop_num] = 0;
8049 : : }
8050 : : else
8051 : : /* Otherwise at least one of the loops stayed in saved_cfun.
8052 : : Remove the LOOP_DIST_ALIAS call. */
8053 : 0 : fold_loop_internal_call (g, gimple_call_arg (g, 1));
8054 : : }
8055 : 88 : FOR_EACH_BB_FN (bb, saved_cfun)
8056 : : {
8057 : 86 : gimple *g = find_loop_dist_alias (bb);
8058 : 86 : if (g == NULL)
8059 : 85 : continue;
8060 : 1 : int orig_loop_num = tree_to_shwi (gimple_call_arg (g, 0));
8061 : 2 : gcc_assert (orig_loop_num
8062 : : && (unsigned) orig_loop_num < vec_safe_length (larray));
8063 : 1 : if (moved_orig_loop_num[orig_loop_num])
8064 : : /* LOOP_DIST_ALIAS call remained in saved_cfun, if at least one
8065 : : of the corresponding loops was moved, remove it. */
8066 : 1 : fold_loop_internal_call (g, gimple_call_arg (g, 1));
8067 : : }
8068 : 2 : XDELETEVEC (moved_orig_loop_num);
8069 : : }
8070 : 42271 : ggc_free (larray);
8071 : :
8072 : : /* Move blocks from BBS into DEST_CFUN. */
8073 : 42271 : gcc_assert (bbs.length () >= 2);
8074 : 42271 : after = dest_cfun->cfg->x_entry_block_ptr;
8075 : 42271 : hash_map<tree, tree> vars_map;
8076 : :
8077 : 42271 : memset (&d, 0, sizeof (d));
8078 : 42271 : d.orig_block = orig_block;
8079 : 42271 : d.new_block = DECL_INITIAL (dest_cfun->decl);
8080 : 42271 : d.from_context = cfun->decl;
8081 : 42271 : d.to_context = dest_cfun->decl;
8082 : 42271 : d.vars_map = &vars_map;
8083 : 42271 : d.new_label_map = new_label_map;
8084 : 42271 : d.eh_map = eh_map;
8085 : 42271 : d.remap_decls_p = true;
8086 : :
8087 : 42271 : if (gimple_in_ssa_p (cfun))
8088 : 412 : for (tree arg = DECL_ARGUMENTS (d.to_context); arg; arg = DECL_CHAIN (arg))
8089 : : {
8090 : 206 : tree narg = make_ssa_name_fn (dest_cfun, arg, gimple_build_nop ());
8091 : 206 : set_ssa_default_def (dest_cfun, arg, narg);
8092 : 206 : vars_map.put (arg, narg);
8093 : : }
8094 : :
8095 : 650026 : FOR_EACH_VEC_ELT (bbs, i, bb)
8096 : : {
8097 : : /* No need to update edge counts on the last block. It has
8098 : : already been updated earlier when we detached the region from
8099 : : the original CFG. */
8100 : 607755 : move_block_to_fn (dest_cfun, bb, after, bb != exit_bb, &d);
8101 : 607755 : after = bb;
8102 : : }
8103 : :
8104 : : /* Adjust the maximum clique used. */
8105 : 42271 : dest_cfun->last_clique = saved_cfun->last_clique;
8106 : :
8107 : 42271 : loop->aux = NULL;
8108 : 42271 : loop0->aux = NULL;
8109 : : /* Loop sizes are no longer correct, fix them up. */
8110 : 42271 : loop->num_nodes -= num_nodes;
8111 : 42271 : for (class loop *outer = loop_outer (loop);
8112 : 46331 : outer; outer = loop_outer (outer))
8113 : 4060 : outer->num_nodes -= num_nodes;
8114 : 42271 : loop0->num_nodes -= bbs.length () - num_nodes;
8115 : :
8116 : 42271 : if (saved_cfun->has_simduid_loops || saved_cfun->has_force_vectorize_loops)
8117 : : {
8118 : 9695 : class loop *aloop;
8119 : 32416 : for (i = 0; vec_safe_iterate (loops->larray, i, &aloop); i++)
8120 : 22721 : if (aloop != NULL)
8121 : : {
8122 : 22721 : if (aloop->simduid)
8123 : : {
8124 : 2467 : replace_by_duplicate_decl (&aloop->simduid, d.vars_map,
8125 : : d.to_context);
8126 : 2467 : dest_cfun->has_simduid_loops = true;
8127 : : }
8128 : 22721 : if (aloop->force_vectorize)
8129 : 4335 : dest_cfun->has_force_vectorize_loops = true;
8130 : : }
8131 : : }
8132 : :
8133 : : /* Rewire BLOCK_SUBBLOCKS of orig_block. */
8134 : 42271 : if (orig_block)
8135 : : {
8136 : 42065 : tree block;
8137 : 42065 : gcc_assert (BLOCK_SUBBLOCKS (DECL_INITIAL (dest_cfun->decl))
8138 : : == NULL_TREE);
8139 : 84130 : BLOCK_SUBBLOCKS (DECL_INITIAL (dest_cfun->decl))
8140 : 42065 : = BLOCK_SUBBLOCKS (orig_block);
8141 : 42065 : for (block = BLOCK_SUBBLOCKS (orig_block);
8142 : 80865 : block; block = BLOCK_CHAIN (block))
8143 : 38800 : BLOCK_SUPERCONTEXT (block) = DECL_INITIAL (dest_cfun->decl);
8144 : 42065 : BLOCK_SUBBLOCKS (orig_block) = NULL_TREE;
8145 : : }
8146 : :
8147 : 42271 : replace_block_vars_by_duplicates (DECL_INITIAL (dest_cfun->decl),
8148 : : &vars_map, dest_cfun->decl);
8149 : :
8150 : 42271 : if (new_label_map)
8151 : 2018 : htab_delete (new_label_map);
8152 : 42271 : if (eh_map)
8153 : 2018 : delete eh_map;
8154 : :
8155 : : /* We need to release ssa-names in a defined order, so first find them,
8156 : : and then iterate in ascending version order. */
8157 : 42271 : bitmap release_names = BITMAP_ALLOC (NULL);
8158 : 42271 : vars_map.traverse<void *, gather_ssa_name_hash_map_from> (release_names);
8159 : 42271 : bitmap_iterator bi;
8160 : 47778 : EXECUTE_IF_SET_IN_BITMAP (release_names, 0, i, bi)
8161 : 5507 : release_ssa_name (ssa_name (i));
8162 : 42271 : BITMAP_FREE (release_names);
8163 : :
8164 : : /* Rewire the entry and exit blocks. The successor to the entry
8165 : : block turns into the successor of DEST_FN's ENTRY_BLOCK_PTR in
8166 : : the child function. Similarly, the predecessor of DEST_FN's
8167 : : EXIT_BLOCK_PTR turns into the predecessor of EXIT_BLOCK_PTR. We
8168 : : need to switch CFUN between DEST_CFUN and SAVED_CFUN so that the
8169 : : various CFG manipulation function get to the right CFG.
8170 : :
8171 : : FIXME, this is silly. The CFG ought to become a parameter to
8172 : : these helpers. */
8173 : 42271 : push_cfun (dest_cfun);
8174 : 42271 : ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = entry_bb->count;
8175 : 42271 : make_single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun), entry_bb, EDGE_FALLTHRU);
8176 : 42271 : if (exit_bb)
8177 : : {
8178 : 42149 : make_single_succ_edge (exit_bb, EXIT_BLOCK_PTR_FOR_FN (cfun), 0);
8179 : 42149 : EXIT_BLOCK_PTR_FOR_FN (cfun)->count = exit_bb->count;
8180 : : }
8181 : : else
8182 : 122 : EXIT_BLOCK_PTR_FOR_FN (cfun)->count = profile_count::zero ();
8183 : 42271 : pop_cfun ();
8184 : :
8185 : : /* Back in the original function, the SESE region has disappeared,
8186 : : create a new basic block in its place. */
8187 : 42271 : bb = create_empty_bb (entry_pred[0]);
8188 : 42271 : if (current_loops)
8189 : 42271 : add_bb_to_loop (bb, loop);
8190 : 42271 : profile_count count = profile_count::zero ();
8191 : 84542 : for (i = 0; i < num_entry_edges; i++)
8192 : : {
8193 : 42271 : e = make_edge (entry_pred[i], bb, entry_flag[i]);
8194 : 42271 : e->probability = entry_prob[i];
8195 : 42271 : count += e->count ();
8196 : : }
8197 : 42271 : bb->count = count;
8198 : :
8199 : 84420 : for (i = 0; i < num_exit_edges; i++)
8200 : : {
8201 : 42149 : e = make_edge (bb, exit_succ[i], exit_flag[i]);
8202 : 42149 : e->probability = exit_prob[i];
8203 : : }
8204 : :
8205 : 42271 : set_immediate_dominator (CDI_DOMINATORS, bb, dom_entry);
8206 : 80345 : FOR_EACH_VEC_ELT (dom_bbs, i, abb)
8207 : 38074 : set_immediate_dominator (CDI_DOMINATORS, abb, bb);
8208 : :
8209 : 42271 : if (exit_bb)
8210 : : {
8211 : 42149 : free (exit_prob);
8212 : 42149 : free (exit_flag);
8213 : 42149 : free (exit_succ);
8214 : : }
8215 : 42271 : free (entry_prob);
8216 : 42271 : free (entry_flag);
8217 : 42271 : free (entry_pred);
8218 : 42271 : bbs.release ();
8219 : :
8220 : 42271 : return bb;
8221 : 42271 : }
8222 : :
8223 : : /* Dump default def DEF to file FILE using FLAGS and indentation
8224 : : SPC. */
8225 : :
8226 : : static void
8227 : 571 : dump_default_def (FILE *file, tree def, int spc, dump_flags_t flags)
8228 : : {
8229 : 1713 : for (int i = 0; i < spc; ++i)
8230 : 1142 : fprintf (file, " ");
8231 : 571 : dump_ssaname_info_to_file (file, def, spc);
8232 : :
8233 : 571 : print_generic_expr (file, TREE_TYPE (def), flags);
8234 : 571 : fprintf (file, " ");
8235 : 571 : print_generic_expr (file, def, flags);
8236 : 571 : fprintf (file, " = ");
8237 : 571 : print_generic_expr (file, SSA_NAME_VAR (def), flags);
8238 : 571 : fprintf (file, ";\n");
8239 : 571 : }
8240 : :
8241 : : /* Print no_sanitize attribute to FILE for a given attribute VALUE. */
8242 : :
8243 : : static void
8244 : 70 : print_no_sanitize_attr_value (FILE *file, tree value)
8245 : : {
8246 : 70 : unsigned int flags = tree_to_uhwi (value);
8247 : 70 : bool first = true;
8248 : 2380 : for (int i = 0; sanitizer_opts[i].name != NULL; ++i)
8249 : : {
8250 : 2310 : if ((sanitizer_opts[i].flag & flags) == sanitizer_opts[i].flag)
8251 : : {
8252 : 312 : if (!first)
8253 : 242 : fprintf (file, " | ");
8254 : 312 : fprintf (file, "%s", sanitizer_opts[i].name);
8255 : 312 : first = false;
8256 : : }
8257 : : }
8258 : 70 : }
8259 : :
8260 : : /* Dump FUNCTION_DECL FN to file FILE using FLAGS (see TDF_* in dumpfile.h)
8261 : : */
8262 : :
8263 : : void
8264 : 55518 : dump_function_to_file (tree fndecl, FILE *file, dump_flags_t flags)
8265 : : {
8266 : 55518 : tree arg, var, old_current_fndecl = current_function_decl;
8267 : 55518 : struct function *dsf;
8268 : 55518 : bool ignore_topmost_bind = false, any_var = false;
8269 : 55518 : basic_block bb;
8270 : 55518 : tree chain;
8271 : 55518 : bool tmclone = (TREE_CODE (fndecl) == FUNCTION_DECL
8272 : 106330 : && decl_is_tm_clone (fndecl));
8273 : 55518 : struct function *fun = DECL_STRUCT_FUNCTION (fndecl);
8274 : :
8275 : 55518 : tree fntype = TREE_TYPE (fndecl);
8276 : 55518 : tree attrs[] = { DECL_ATTRIBUTES (fndecl), TYPE_ATTRIBUTES (fntype) };
8277 : :
8278 : 166554 : for (int i = 0; i != 2; ++i)
8279 : : {
8280 : 111036 : if (!attrs[i])
8281 : 90108 : continue;
8282 : :
8283 : 20928 : fprintf (file, "__attribute__((");
8284 : :
8285 : 20928 : bool first = true;
8286 : 20928 : tree chain;
8287 : 58299 : for (chain = attrs[i]; chain; first = false, chain = TREE_CHAIN (chain))
8288 : : {
8289 : 37371 : if (!first)
8290 : 16443 : fprintf (file, ", ");
8291 : :
8292 : 37371 : tree name = get_attribute_name (chain);
8293 : 37371 : print_generic_expr (file, name, dump_flags);
8294 : 37371 : if (TREE_VALUE (chain) != NULL_TREE)
8295 : : {
8296 : 9931 : fprintf (file, " (");
8297 : :
8298 : 9931 : if (strstr (IDENTIFIER_POINTER (name), "no_sanitize"))
8299 : 70 : print_no_sanitize_attr_value (file, TREE_VALUE (chain));
8300 : 9861 : else if (!strcmp (IDENTIFIER_POINTER (name),
8301 : : "omp declare variant base"))
8302 : : {
8303 : 95 : tree a = TREE_VALUE (chain);
8304 : 95 : print_generic_expr (file, TREE_PURPOSE (a), dump_flags);
8305 : 95 : fprintf (file, " match ");
8306 : 95 : print_omp_context_selector (file, TREE_VALUE (a),
8307 : : dump_flags);
8308 : : }
8309 : : else
8310 : 9766 : print_generic_expr (file, TREE_VALUE (chain), dump_flags);
8311 : 9931 : fprintf (file, ")");
8312 : : }
8313 : : }
8314 : :
8315 : 20928 : fprintf (file, "))\n");
8316 : : }
8317 : :
8318 : 55518 : current_function_decl = fndecl;
8319 : 55518 : if (flags & TDF_GIMPLE)
8320 : : {
8321 : 41 : static bool hotness_bb_param_printed = false;
8322 : 41 : if (profile_info != NULL
8323 : 0 : && !hotness_bb_param_printed)
8324 : : {
8325 : 0 : hotness_bb_param_printed = true;
8326 : 0 : fprintf (file,
8327 : : "/* --param=gimple-fe-computed-hot-bb-threshold=%" PRId64
8328 : : " */\n", get_hot_bb_threshold ());
8329 : : }
8330 : :
8331 : 41 : print_generic_expr (file, TREE_TYPE (TREE_TYPE (fndecl)),
8332 : : dump_flags | TDF_SLIM);
8333 : 41 : fprintf (file, " __GIMPLE (%s",
8334 : 41 : (fun->curr_properties & PROP_ssa) ? "ssa"
8335 : 9 : : (fun->curr_properties & PROP_cfg) ? "cfg"
8336 : : : "");
8337 : :
8338 : 41 : if (fun && fun->cfg)
8339 : : {
8340 : 37 : basic_block bb = ENTRY_BLOCK_PTR_FOR_FN (fun);
8341 : 37 : if (bb->count.initialized_p ())
8342 : 0 : fprintf (file, ",%s(%" PRIu64 ")",
8343 : : profile_quality_as_string (bb->count.quality ()),
8344 : : bb->count.value ());
8345 : 37 : if (dump_flags & TDF_UID)
8346 : 0 : fprintf (file, ")\n%sD_%u (", function_name (fun),
8347 : 0 : DECL_UID (fndecl));
8348 : : else
8349 : 37 : fprintf (file, ")\n%s (", function_name (fun));
8350 : : }
8351 : : }
8352 : : else
8353 : : {
8354 : 55477 : print_generic_expr (file, TREE_TYPE (fntype), dump_flags);
8355 : 55477 : if (dump_flags & TDF_UID)
8356 : 1352 : fprintf (file, " %sD.%u %s(", function_name (fun), DECL_UID (fndecl),
8357 : : tmclone ? "[tm-clone] " : "");
8358 : : else
8359 : 109558 : fprintf (file, " %s %s(", function_name (fun),
8360 : : tmclone ? "[tm-clone] " : "");
8361 : : }
8362 : :
8363 : 55518 : arg = DECL_ARGUMENTS (fndecl);
8364 : 130226 : while (arg)
8365 : : {
8366 : 74708 : print_generic_expr (file, TREE_TYPE (arg), dump_flags);
8367 : 74708 : fprintf (file, " ");
8368 : 74708 : print_generic_expr (file, arg, dump_flags);
8369 : 74708 : if (DECL_CHAIN (arg))
8370 : 38165 : fprintf (file, ", ");
8371 : 74708 : arg = DECL_CHAIN (arg);
8372 : : }
8373 : 55518 : fprintf (file, ")\n");
8374 : :
8375 : 55518 : dsf = DECL_STRUCT_FUNCTION (fndecl);
8376 : 55518 : if (dsf && (flags & TDF_EH))
8377 : 663 : dump_eh_tree (file, dsf);
8378 : :
8379 : 55518 : if (flags & TDF_RAW && !gimple_has_body_p (fndecl))
8380 : : {
8381 : 0 : dump_node (fndecl, TDF_SLIM | flags, file);
8382 : 0 : current_function_decl = old_current_fndecl;
8383 : 0 : return;
8384 : : }
8385 : :
8386 : : /* When GIMPLE is lowered, the variables are no longer available in
8387 : : BIND_EXPRs, so display them separately. */
8388 : 55518 : if (fun && fun->decl == fndecl && (fun->curr_properties & PROP_gimple_lcf))
8389 : : {
8390 : 46804 : unsigned ix;
8391 : 46804 : ignore_topmost_bind = true;
8392 : :
8393 : 46804 : fprintf (file, "{\n");
8394 : 92596 : if (gimple_in_ssa_p (fun)
8395 : 45792 : && (flags & TDF_ALIAS))
8396 : : {
8397 : 1253 : for (arg = DECL_ARGUMENTS (fndecl); arg != NULL;
8398 : 597 : arg = DECL_CHAIN (arg))
8399 : : {
8400 : 597 : tree def = ssa_default_def (fun, arg);
8401 : 597 : if (def)
8402 : 571 : dump_default_def (file, def, 2, flags);
8403 : : }
8404 : :
8405 : 656 : tree res = DECL_RESULT (fun->decl);
8406 : 656 : if (res != NULL_TREE
8407 : 656 : && DECL_BY_REFERENCE (res))
8408 : : {
8409 : 0 : tree def = ssa_default_def (fun, res);
8410 : 0 : if (def)
8411 : 0 : dump_default_def (file, def, 2, flags);
8412 : : }
8413 : :
8414 : 656 : tree static_chain = fun->static_chain_decl;
8415 : 656 : if (static_chain != NULL_TREE)
8416 : : {
8417 : 0 : tree def = ssa_default_def (fun, static_chain);
8418 : 0 : if (def)
8419 : 0 : dump_default_def (file, def, 2, flags);
8420 : : }
8421 : : }
8422 : :
8423 : 46804 : if (!vec_safe_is_empty (fun->local_decls))
8424 : 253231 : FOR_EACH_LOCAL_DECL (fun, ix, var)
8425 : : {
8426 : 226157 : print_generic_decl (file, var, flags);
8427 : 226157 : fprintf (file, "\n");
8428 : :
8429 : 226157 : any_var = true;
8430 : : }
8431 : :
8432 : 46804 : tree name;
8433 : :
8434 : 46804 : if (gimple_in_ssa_p (fun))
8435 : 1589977 : FOR_EACH_SSA_NAME (ix, name, fun)
8436 : : {
8437 : 1157828 : if (!SSA_NAME_VAR (name)
8438 : : /* SSA name with decls without a name still get
8439 : : dumped as _N, list those explicitely as well even
8440 : : though we've dumped the decl declaration as D.xxx
8441 : : above. */
8442 : 665342 : || !SSA_NAME_IDENTIFIER (name))
8443 : : {
8444 : 495360 : fprintf (file, " ");
8445 : 495360 : print_generic_expr (file, TREE_TYPE (name), flags);
8446 : 495360 : fprintf (file, " ");
8447 : 495360 : print_generic_expr (file, name, flags);
8448 : 495360 : fprintf (file, ";\n");
8449 : :
8450 : 495360 : any_var = true;
8451 : : }
8452 : : }
8453 : : }
8454 : :
8455 : 55518 : if (fun && fun->decl == fndecl
8456 : 55518 : && fun->cfg
8457 : 46546 : && basic_block_info_for_fn (fun))
8458 : : {
8459 : : /* If the CFG has been built, emit a CFG-based dump. */
8460 : 46546 : if (!ignore_topmost_bind)
8461 : 0 : fprintf (file, "{\n");
8462 : :
8463 : 46546 : if (any_var && n_basic_blocks_for_fn (fun))
8464 : 40714 : fprintf (file, "\n");
8465 : :
8466 : 285684 : FOR_EACH_BB_FN (bb, fun)
8467 : 239138 : dump_bb (file, bb, 2, flags);
8468 : :
8469 : 46546 : fprintf (file, "}\n");
8470 : : }
8471 : 8972 : else if (fun && (fun->curr_properties & PROP_gimple_any))
8472 : : {
8473 : : /* The function is now in GIMPLE form but the CFG has not been
8474 : : built yet. Emit the single sequence of GIMPLE statements
8475 : : that make up its body. */
8476 : 3840 : gimple_seq body = gimple_body (fndecl);
8477 : :
8478 : 3840 : if (gimple_seq_first_stmt (body)
8479 : 3840 : && gimple_seq_first_stmt (body) == gimple_seq_last_stmt (body)
8480 : 7422 : && gimple_code (gimple_seq_first_stmt (body)) == GIMPLE_BIND)
8481 : 3582 : print_gimple_seq (file, body, 0, flags);
8482 : : else
8483 : : {
8484 : 258 : if (!ignore_topmost_bind)
8485 : 0 : fprintf (file, "{\n");
8486 : :
8487 : 258 : if (any_var)
8488 : 187 : fprintf (file, "\n");
8489 : :
8490 : 258 : print_gimple_seq (file, body, 2, flags);
8491 : 258 : fprintf (file, "}\n");
8492 : : }
8493 : : }
8494 : : else
8495 : : {
8496 : 5132 : int indent;
8497 : :
8498 : : /* Make a tree based dump. */
8499 : 5132 : chain = DECL_SAVED_TREE (fndecl);
8500 : 5132 : if (chain && TREE_CODE (chain) == BIND_EXPR)
8501 : : {
8502 : 5132 : if (ignore_topmost_bind)
8503 : : {
8504 : 0 : chain = BIND_EXPR_BODY (chain);
8505 : 0 : indent = 2;
8506 : : }
8507 : : else
8508 : : indent = 0;
8509 : : }
8510 : : else
8511 : : {
8512 : 0 : if (!ignore_topmost_bind)
8513 : : {
8514 : 0 : fprintf (file, "{\n");
8515 : : /* No topmost bind, pretend it's ignored for later. */
8516 : 0 : ignore_topmost_bind = true;
8517 : : }
8518 : : indent = 2;
8519 : : }
8520 : :
8521 : 5132 : if (any_var)
8522 : 0 : fprintf (file, "\n");
8523 : :
8524 : 5132 : print_generic_stmt_indented (file, chain, flags, indent);
8525 : 5132 : if (ignore_topmost_bind)
8526 : 0 : fprintf (file, "}\n");
8527 : : }
8528 : :
8529 : 55518 : if (flags & TDF_ENUMERATE_LOCALS)
8530 : 38 : dump_enumerated_decls (file, flags);
8531 : 55518 : fprintf (file, "\n\n");
8532 : :
8533 : 55518 : current_function_decl = old_current_fndecl;
8534 : : }
8535 : :
8536 : : /* Dump FUNCTION_DECL FN to stderr using FLAGS (see TDF_* in tree.h) */
8537 : :
8538 : : DEBUG_FUNCTION void
8539 : 0 : debug_function (tree fn, dump_flags_t flags)
8540 : : {
8541 : 0 : dump_function_to_file (fn, stderr, flags);
8542 : 0 : }
8543 : :
8544 : :
8545 : : /* Print on FILE the indexes for the predecessors of basic_block BB. */
8546 : :
8547 : : static void
8548 : 5276 : print_pred_bbs (FILE *file, basic_block bb)
8549 : : {
8550 : 5276 : edge e;
8551 : 5276 : edge_iterator ei;
8552 : :
8553 : 11941 : FOR_EACH_EDGE (e, ei, bb->preds)
8554 : 6665 : fprintf (file, "bb_%d ", e->src->index);
8555 : 5276 : }
8556 : :
8557 : :
8558 : : /* Print on FILE the indexes for the successors of basic_block BB. */
8559 : :
8560 : : static void
8561 : 5276 : print_succ_bbs (FILE *file, basic_block bb)
8562 : : {
8563 : 5276 : edge e;
8564 : 5276 : edge_iterator ei;
8565 : :
8566 : 12034 : FOR_EACH_EDGE (e, ei, bb->succs)
8567 : 6758 : fprintf (file, "bb_%d ", e->dest->index);
8568 : 5276 : }
8569 : :
8570 : : /* Print to FILE the basic block BB following the VERBOSITY level. */
8571 : :
8572 : : void
8573 : 5276 : print_loops_bb (FILE *file, basic_block bb, int indent, int verbosity)
8574 : : {
8575 : 5276 : char *s_indent = (char *) alloca ((size_t) indent + 1);
8576 : 5276 : memset ((void *) s_indent, ' ', (size_t) indent);
8577 : 5276 : s_indent[indent] = '\0';
8578 : :
8579 : : /* Print basic_block's header. */
8580 : 5276 : if (verbosity >= 2)
8581 : : {
8582 : 5276 : fprintf (file, "%s bb_%d (preds = {", s_indent, bb->index);
8583 : 5276 : print_pred_bbs (file, bb);
8584 : 5276 : fprintf (file, "}, succs = {");
8585 : 5276 : print_succ_bbs (file, bb);
8586 : 5276 : fprintf (file, "})\n");
8587 : : }
8588 : :
8589 : : /* Print basic_block's body. */
8590 : 5276 : if (verbosity >= 3)
8591 : : {
8592 : 2883 : fprintf (file, "%s {\n", s_indent);
8593 : 2883 : dump_bb (file, bb, indent + 4, TDF_VOPS|TDF_MEMSYMS);
8594 : 2883 : fprintf (file, "%s }\n", s_indent);
8595 : : }
8596 : 5276 : }
8597 : :
8598 : : /* Print loop information. */
8599 : :
8600 : : void
8601 : 8494 : print_loop_info (FILE *file, const class loop *loop, const char *prefix)
8602 : : {
8603 : 8494 : if (loop->can_be_parallel)
8604 : 0 : fprintf (file, ", can_be_parallel");
8605 : 8494 : if (loop->warned_aggressive_loop_optimizations)
8606 : 0 : fprintf (file, ", warned_aggressive_loop_optimizations");
8607 : 8494 : if (loop->dont_vectorize)
8608 : 5 : fprintf (file, ", dont_vectorize");
8609 : 8494 : if (loop->force_vectorize)
8610 : 0 : fprintf (file, ", force_vectorize");
8611 : 8494 : if (loop->in_oacc_kernels_region)
8612 : 220 : fprintf (file, ", in_oacc_kernels_region");
8613 : 8494 : if (loop->finite_p)
8614 : 1950 : fprintf (file, ", finite_p");
8615 : 8494 : if (loop->unroll)
8616 : 77 : fprintf (file, "\n%sunroll %d", prefix, loop->unroll);
8617 : 8494 : if (loop->nb_iterations)
8618 : : {
8619 : 76 : fprintf (file, "\n%sniter ", prefix);
8620 : 76 : print_generic_expr (file, loop->nb_iterations);
8621 : : }
8622 : :
8623 : 8494 : if (loop->any_upper_bound)
8624 : : {
8625 : 1899 : fprintf (file, "\n%supper_bound ", prefix);
8626 : 1899 : print_decu (loop->nb_iterations_upper_bound, file);
8627 : : }
8628 : 8494 : if (loop->any_likely_upper_bound)
8629 : : {
8630 : 1899 : fprintf (file, "\n%slikely_upper_bound ", prefix);
8631 : 1899 : print_decu (loop->nb_iterations_likely_upper_bound, file);
8632 : : }
8633 : :
8634 : 8494 : if (loop->any_estimate)
8635 : : {
8636 : 963 : fprintf (file, "\n%sestimate ", prefix);
8637 : 963 : print_decu (loop->nb_iterations_estimate, file);
8638 : : }
8639 : 8494 : bool reliable;
8640 : 8494 : sreal iterations;
8641 : 8494 : if (loop->num && expected_loop_iterations_by_profile (loop, &iterations, &reliable))
8642 : : {
8643 : 4904 : fprintf (file, "\n%siterations by profile: %f (%s%s) entry count:", prefix,
8644 : : iterations.to_double (), reliable ? "reliable" : "unreliable",
8645 : 2229 : maybe_flat_loop_profile (loop) ? ", maybe flat" : "");
8646 : 2229 : loop_count_in (loop).dump (file, cfun);
8647 : : }
8648 : :
8649 : 8494 : }
8650 : :
8651 : : static void print_loop_and_siblings (FILE *, class loop *, int, int);
8652 : :
8653 : : /* Pretty print LOOP on FILE, indented INDENT spaces. Following
8654 : : VERBOSITY level this outputs the contents of the loop, or just its
8655 : : structure. */
8656 : :
8657 : : static void
8658 : 1248 : print_loop (FILE *file, class loop *loop, int indent, int verbosity)
8659 : : {
8660 : 1248 : char *s_indent;
8661 : 1248 : basic_block bb;
8662 : :
8663 : 1248 : if (loop == NULL)
8664 : : return;
8665 : :
8666 : 1248 : s_indent = (char *) alloca ((size_t) indent + 1);
8667 : 1248 : memset ((void *) s_indent, ' ', (size_t) indent);
8668 : 1248 : s_indent[indent] = '\0';
8669 : :
8670 : : /* Print loop's header. */
8671 : 1248 : fprintf (file, "%sloop_%d (", s_indent, loop->num);
8672 : 1248 : if (loop->header)
8673 : 1248 : fprintf (file, "header = %d", loop->header->index);
8674 : : else
8675 : : {
8676 : 0 : fprintf (file, "deleted)\n");
8677 : 0 : return;
8678 : : }
8679 : 1248 : if (loop->latch)
8680 : 1248 : fprintf (file, ", latch = %d", loop->latch->index);
8681 : : else
8682 : 0 : fprintf (file, ", multiple latches");
8683 : 1248 : print_loop_info (file, loop, s_indent);
8684 : 1248 : fprintf (file, ")\n");
8685 : :
8686 : : /* Print loop's body. */
8687 : 1248 : if (verbosity >= 1)
8688 : : {
8689 : 1248 : fprintf (file, "%s{\n", s_indent);
8690 : 21034 : FOR_EACH_BB_FN (bb, cfun)
8691 : 19786 : if (bb->loop_father == loop)
8692 : 4786 : print_loops_bb (file, bb, indent, verbosity);
8693 : :
8694 : 1248 : print_loop_and_siblings (file, loop->inner, indent + 2, verbosity);
8695 : 1248 : fprintf (file, "%s}\n", s_indent);
8696 : : }
8697 : : }
8698 : :
8699 : : /* Print the LOOP and its sibling loops on FILE, indented INDENT
8700 : : spaces. Following VERBOSITY level this outputs the contents of the
8701 : : loop, or just its structure. */
8702 : :
8703 : : static void
8704 : 1248 : print_loop_and_siblings (FILE *file, class loop *loop, int indent,
8705 : : int verbosity)
8706 : : {
8707 : 2120 : if (loop == NULL)
8708 : 1248 : return;
8709 : :
8710 : 1248 : print_loop (file, loop, indent, verbosity);
8711 : 376 : print_loop_and_siblings (file, loop->next, indent, verbosity);
8712 : : }
8713 : :
8714 : : /* Follow a CFG edge from the entry point of the program, and on entry
8715 : : of a loop, pretty print the loop structure on FILE. */
8716 : :
8717 : : void
8718 : 376 : print_loops (FILE *file, int verbosity)
8719 : : {
8720 : 376 : basic_block bb;
8721 : :
8722 : 376 : bb = ENTRY_BLOCK_PTR_FOR_FN (cfun);
8723 : 376 : fprintf (file, "\nLoops in function: %s\n", current_function_name ());
8724 : 376 : if (bb && bb->loop_father)
8725 : 752 : print_loop_and_siblings (file, bb->loop_father, 0, verbosity);
8726 : 376 : }
8727 : :
8728 : : /* Dump a loop. */
8729 : :
8730 : : DEBUG_FUNCTION void
8731 : 0 : debug (class loop &ref)
8732 : : {
8733 : 0 : print_loop (stderr, &ref, 0, /*verbosity*/0);
8734 : 0 : }
8735 : :
8736 : : DEBUG_FUNCTION void
8737 : 0 : debug (class loop *ptr)
8738 : : {
8739 : 0 : if (ptr)
8740 : 0 : debug (*ptr);
8741 : : else
8742 : 0 : fprintf (stderr, "<nil>\n");
8743 : 0 : }
8744 : :
8745 : : /* Dump a loop verbosely. */
8746 : :
8747 : : DEBUG_FUNCTION void
8748 : 0 : debug_verbose (class loop &ref)
8749 : : {
8750 : 0 : print_loop (stderr, &ref, 0, /*verbosity*/3);
8751 : 0 : }
8752 : :
8753 : : DEBUG_FUNCTION void
8754 : 0 : debug_verbose (class loop *ptr)
8755 : : {
8756 : 0 : if (ptr)
8757 : 0 : debug (*ptr);
8758 : : else
8759 : 0 : fprintf (stderr, "<nil>\n");
8760 : 0 : }
8761 : :
8762 : :
8763 : : /* Debugging loops structure at tree level, at some VERBOSITY level. */
8764 : :
8765 : : DEBUG_FUNCTION void
8766 : 0 : debug_loops (int verbosity)
8767 : : {
8768 : 0 : print_loops (stderr, verbosity);
8769 : 0 : }
8770 : :
8771 : : /* Print on stderr the code of LOOP, at some VERBOSITY level. */
8772 : :
8773 : : DEBUG_FUNCTION void
8774 : 0 : debug_loop (class loop *loop, int verbosity)
8775 : : {
8776 : 0 : print_loop (stderr, loop, 0, verbosity);
8777 : 0 : }
8778 : :
8779 : : /* Print on stderr the code of loop number NUM, at some VERBOSITY
8780 : : level. */
8781 : :
8782 : : DEBUG_FUNCTION void
8783 : 0 : debug_loop_num (unsigned num, int verbosity)
8784 : : {
8785 : 0 : debug_loop (get_loop (cfun, num), verbosity);
8786 : 0 : }
8787 : :
8788 : : /* Return true if BB ends with a call, possibly followed by some
8789 : : instructions that must stay with the call. Return false,
8790 : : otherwise. */
8791 : :
8792 : : static bool
8793 : 3 : gimple_block_ends_with_call_p (basic_block bb)
8794 : : {
8795 : 3 : gimple_stmt_iterator gsi = gsi_last_nondebug_bb (bb);
8796 : 3 : return !gsi_end_p (gsi) && is_gimple_call (gsi_stmt (gsi));
8797 : : }
8798 : :
8799 : :
8800 : : /* Return true if BB ends with a conditional branch. Return false,
8801 : : otherwise. */
8802 : :
8803 : : static bool
8804 : 1716 : gimple_block_ends_with_condjump_p (const_basic_block bb)
8805 : : {
8806 : 3432 : return safe_is_a <gcond *> (*gsi_last_bb (const_cast <basic_block> (bb)));
8807 : : }
8808 : :
8809 : :
8810 : : /* Return true if statement T may terminate execution of BB in ways not
8811 : : explicitly represtented in the CFG. */
8812 : :
8813 : : bool
8814 : 311451086 : stmt_can_terminate_bb_p (gimple *t)
8815 : : {
8816 : 311451086 : tree fndecl = NULL_TREE;
8817 : 311451086 : int call_flags = 0;
8818 : :
8819 : : /* Eh exception not handled internally terminates execution of the whole
8820 : : function. */
8821 : 311451086 : if (stmt_can_throw_external (cfun, t))
8822 : : return true;
8823 : :
8824 : : /* NORETURN and LONGJMP calls already have an edge to exit.
8825 : : CONST and PURE calls do not need one.
8826 : : We don't currently check for CONST and PURE here, although
8827 : : it would be a good idea, because those attributes are
8828 : : figured out from the RTL in mark_constant_function, and
8829 : : the counter incrementation code from -fprofile-arcs
8830 : : leads to different results from -fbranch-probabilities. */
8831 : 305625528 : if (is_gimple_call (t))
8832 : : {
8833 : 10171102 : fndecl = gimple_call_fndecl (t);
8834 : 10171102 : call_flags = gimple_call_flags (t);
8835 : : }
8836 : :
8837 : 305625528 : if (is_gimple_call (t)
8838 : 10171102 : && fndecl
8839 : 8818065 : && fndecl_built_in_p (fndecl)
8840 : : && (call_flags & ECF_NOTHROW)
8841 : 3541128 : && !(call_flags & ECF_RETURNS_TWICE)
8842 : : /* fork() doesn't really return twice, but the effect of
8843 : : wrapping it in __gcov_fork() which calls __gcov_dump() and
8844 : : __gcov_reset() and clears the counters before forking has the same
8845 : : effect as returning twice. Force a fake edge. */
8846 : 308829277 : && !fndecl_built_in_p (fndecl, BUILT_IN_FORK))
8847 : : return false;
8848 : :
8849 : 302421907 : if (is_gimple_call (t))
8850 : : {
8851 : 6967481 : edge_iterator ei;
8852 : 6967481 : edge e;
8853 : 6967481 : basic_block bb;
8854 : :
8855 : 6967481 : if (call_flags & (ECF_PURE | ECF_CONST)
8856 : 1401934 : && !(call_flags & ECF_LOOPING_CONST_OR_PURE))
8857 : 6247458 : return false;
8858 : :
8859 : : /* Function call may do longjmp, terminate program or do other things.
8860 : : Special case noreturn that have non-abnormal edges out as in this case
8861 : : the fact is sufficiently represented by lack of edges out of T. */
8862 : 5655466 : if (!(call_flags & ECF_NORETURN))
8863 : : return true;
8864 : :
8865 : 800314 : bb = gimple_bb (t);
8866 : 1520294 : FOR_EACH_EDGE (e, ei, bb->succs)
8867 : 800271 : if ((e->flags & EDGE_FAKE) == 0)
8868 : : return true;
8869 : : }
8870 : :
8871 : 296174449 : if (gasm *asm_stmt = dyn_cast <gasm *> (t))
8872 : 263351 : if (gimple_asm_volatile_p (asm_stmt) || gimple_asm_input_p (asm_stmt))
8873 : : return true;
8874 : :
8875 : : return false;
8876 : : }
8877 : :
8878 : :
8879 : : /* Add fake edges to the function exit for any non constant and non
8880 : : noreturn calls (or noreturn calls with EH/abnormal edges),
8881 : : volatile inline assembly in the bitmap of blocks specified by BLOCKS
8882 : : or to the whole CFG if BLOCKS is zero. Return the number of blocks
8883 : : that were split.
8884 : :
8885 : : The goal is to expose cases in which entering a basic block does
8886 : : not imply that all subsequent instructions must be executed. */
8887 : :
8888 : : static int
8889 : 2276 : gimple_flow_call_edges_add (sbitmap blocks)
8890 : : {
8891 : 2276 : int i;
8892 : 2276 : int blocks_split = 0;
8893 : 2276 : int last_bb = last_basic_block_for_fn (cfun);
8894 : 2276 : bool check_last_block = false;
8895 : :
8896 : 2276 : if (n_basic_blocks_for_fn (cfun) == NUM_FIXED_BLOCKS)
8897 : : return 0;
8898 : :
8899 : 2276 : if (! blocks)
8900 : : check_last_block = true;
8901 : : else
8902 : 0 : check_last_block = bitmap_bit_p (blocks,
8903 : 0 : EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb->index);
8904 : :
8905 : : /* In the last basic block, before epilogue generation, there will be
8906 : : a fallthru edge to EXIT. Special care is required if the last insn
8907 : : of the last basic block is a call because make_edge folds duplicate
8908 : : edges, which would result in the fallthru edge also being marked
8909 : : fake, which would result in the fallthru edge being removed by
8910 : : remove_fake_edges, which would result in an invalid CFG.
8911 : :
8912 : : Moreover, we can't elide the outgoing fake edge, since the block
8913 : : profiler needs to take this into account in order to solve the minimal
8914 : : spanning tree in the case that the call doesn't return.
8915 : :
8916 : : Handle this by adding a dummy instruction in a new last basic block. */
8917 : 0 : if (check_last_block)
8918 : : {
8919 : 2276 : basic_block bb = EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb;
8920 : 2276 : gimple_stmt_iterator gsi = gsi_last_nondebug_bb (bb);
8921 : 2276 : gimple *t = NULL;
8922 : :
8923 : 2276 : if (!gsi_end_p (gsi))
8924 : 2271 : t = gsi_stmt (gsi);
8925 : :
8926 : 2271 : if (t && stmt_can_terminate_bb_p (t))
8927 : : {
8928 : 140 : edge e;
8929 : :
8930 : 140 : e = find_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun));
8931 : 140 : if (e)
8932 : : {
8933 : 0 : gsi_insert_on_edge (e, gimple_build_nop ());
8934 : 0 : gsi_commit_edge_inserts ();
8935 : : }
8936 : : }
8937 : : }
8938 : :
8939 : : /* Now add fake edges to the function exit for any non constant
8940 : : calls since there is no way that we can determine if they will
8941 : : return or not... */
8942 : 16363 : for (i = 0; i < last_bb; i++)
8943 : : {
8944 : 14087 : basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
8945 : 14087 : gimple_stmt_iterator gsi;
8946 : 14087 : gimple *stmt, *last_stmt;
8947 : :
8948 : 14087 : if (!bb)
8949 : 8 : continue;
8950 : :
8951 : 14079 : if (blocks && !bitmap_bit_p (blocks, i))
8952 : 0 : continue;
8953 : :
8954 : 14079 : gsi = gsi_last_nondebug_bb (bb);
8955 : 14079 : if (!gsi_end_p (gsi))
8956 : : {
8957 : 21969 : last_stmt = gsi_stmt (gsi);
8958 : 21969 : do
8959 : : {
8960 : 21969 : stmt = gsi_stmt (gsi);
8961 : 21969 : if (stmt_can_terminate_bb_p (stmt))
8962 : : {
8963 : 3321 : edge e;
8964 : :
8965 : : /* The handling above of the final block before the
8966 : : epilogue should be enough to verify that there is
8967 : : no edge to the exit block in CFG already.
8968 : : Calling make_edge in such case would cause us to
8969 : : mark that edge as fake and remove it later. */
8970 : 3321 : if (flag_checking && stmt == last_stmt)
8971 : : {
8972 : 939 : e = find_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun));
8973 : 939 : gcc_assert (e == NULL);
8974 : : }
8975 : :
8976 : : /* Note that the following may create a new basic block
8977 : : and renumber the existing basic blocks. */
8978 : 3321 : if (stmt != last_stmt)
8979 : : {
8980 : 2382 : e = split_block (bb, stmt);
8981 : 2382 : if (e)
8982 : 2382 : blocks_split++;
8983 : : }
8984 : 3321 : e = make_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun), EDGE_FAKE);
8985 : 3321 : e->probability = profile_probability::guessed_never ();
8986 : : }
8987 : 21969 : gsi_prev (&gsi);
8988 : : }
8989 : 21969 : while (!gsi_end_p (gsi));
8990 : : }
8991 : : }
8992 : :
8993 : 2276 : if (blocks_split)
8994 : 1019 : checking_verify_flow_info ();
8995 : :
8996 : : return blocks_split;
8997 : : }
8998 : :
8999 : : /* Removes edge E and all the blocks dominated by it, and updates dominance
9000 : : information. The IL in E->src needs to be updated separately.
9001 : : If dominance info is not available, only the edge E is removed.*/
9002 : :
9003 : : void
9004 : 2750229 : remove_edge_and_dominated_blocks (edge e)
9005 : : {
9006 : 2750229 : vec<basic_block> bbs_to_fix_dom = vNULL;
9007 : 2750229 : edge f;
9008 : 2750229 : edge_iterator ei;
9009 : 2750229 : bool none_removed = false;
9010 : 2750229 : unsigned i;
9011 : 2750229 : basic_block bb, dbb;
9012 : 2750229 : bitmap_iterator bi;
9013 : :
9014 : : /* If we are removing a path inside a non-root loop that may change
9015 : : loop ownership of blocks or remove loops. Mark loops for fixup. */
9016 : 2750229 : if (current_loops
9017 : 2525456 : && loop_outer (e->src->loop_father) != NULL
9018 : 3272103 : && e->src->loop_father == e->dest->loop_father)
9019 : 205710 : loops_state_set (LOOPS_NEED_FIXUP);
9020 : :
9021 : 2750229 : if (!dom_info_available_p (CDI_DOMINATORS))
9022 : : {
9023 : 2547945 : remove_edge (e);
9024 : 5095890 : return;
9025 : : }
9026 : :
9027 : : /* No updating is needed for edges to exit. */
9028 : 202284 : if (e->dest == EXIT_BLOCK_PTR_FOR_FN (cfun))
9029 : : {
9030 : 0 : if (cfgcleanup_altered_bbs)
9031 : 0 : bitmap_set_bit (cfgcleanup_altered_bbs, e->src->index);
9032 : 0 : remove_edge (e);
9033 : 0 : return;
9034 : : }
9035 : :
9036 : : /* First, we find the basic blocks to remove. If E->dest has a predecessor
9037 : : that is not dominated by E->dest, then this set is empty. Otherwise,
9038 : : all the basic blocks dominated by E->dest are removed.
9039 : :
9040 : : Also, to DF_IDOM we store the immediate dominators of the blocks in
9041 : : the dominance frontier of E (i.e., of the successors of the
9042 : : removed blocks, if there are any, and of E->dest otherwise). */
9043 : 216727 : FOR_EACH_EDGE (f, ei, e->dest->preds)
9044 : : {
9045 : 212624 : if (f == e)
9046 : 14410 : continue;
9047 : :
9048 : 198214 : if (!dominated_by_p (CDI_DOMINATORS, f->src, e->dest))
9049 : : {
9050 : : none_removed = true;
9051 : : break;
9052 : : }
9053 : : }
9054 : :
9055 : 202284 : auto_bitmap df, df_idom;
9056 : 202284 : auto_vec<basic_block> bbs_to_remove;
9057 : 202284 : if (none_removed)
9058 : 198181 : bitmap_set_bit (df_idom,
9059 : 198181 : get_immediate_dominator (CDI_DOMINATORS, e->dest)->index);
9060 : : else
9061 : : {
9062 : 4103 : bbs_to_remove = get_all_dominated_blocks (CDI_DOMINATORS, e->dest);
9063 : 9755 : FOR_EACH_VEC_ELT (bbs_to_remove, i, bb)
9064 : : {
9065 : 11549 : FOR_EACH_EDGE (f, ei, bb->succs)
9066 : : {
9067 : 5897 : if (f->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
9068 : 5895 : bitmap_set_bit (df, f->dest->index);
9069 : : }
9070 : : }
9071 : 9755 : FOR_EACH_VEC_ELT (bbs_to_remove, i, bb)
9072 : 5652 : bitmap_clear_bit (df, bb->index);
9073 : :
9074 : 8028 : EXECUTE_IF_SET_IN_BITMAP (df, 0, i, bi)
9075 : : {
9076 : 3925 : bb = BASIC_BLOCK_FOR_FN (cfun, i);
9077 : 3925 : bitmap_set_bit (df_idom,
9078 : 3925 : get_immediate_dominator (CDI_DOMINATORS, bb)->index);
9079 : : }
9080 : : }
9081 : :
9082 : 202284 : if (cfgcleanup_altered_bbs)
9083 : : {
9084 : : /* Record the set of the altered basic blocks. */
9085 : 19629 : bitmap_set_bit (cfgcleanup_altered_bbs, e->src->index);
9086 : 19629 : bitmap_ior_into (cfgcleanup_altered_bbs, df);
9087 : : }
9088 : :
9089 : : /* Remove E and the cancelled blocks. */
9090 : 202284 : if (none_removed)
9091 : 198181 : remove_edge (e);
9092 : : else
9093 : : {
9094 : : /* Walk backwards so as to get a chance to substitute all
9095 : : released DEFs into debug stmts. See
9096 : : eliminate_unnecessary_stmts() in tree-ssa-dce.cc for more
9097 : : details. */
9098 : 13858 : for (i = bbs_to_remove.length (); i-- > 0; )
9099 : 5652 : delete_basic_block (bbs_to_remove[i]);
9100 : : }
9101 : :
9102 : : /* Update the dominance information. The immediate dominator may change only
9103 : : for blocks whose immediate dominator belongs to DF_IDOM:
9104 : :
9105 : : Suppose that idom(X) = Y before removal of E and idom(X) != Y after the
9106 : : removal. Let Z the arbitrary block such that idom(Z) = Y and
9107 : : Z dominates X after the removal. Before removal, there exists a path P
9108 : : from Y to X that avoids Z. Let F be the last edge on P that is
9109 : : removed, and let W = F->dest. Before removal, idom(W) = Y (since Y
9110 : : dominates W, and because of P, Z does not dominate W), and W belongs to
9111 : : the dominance frontier of E. Therefore, Y belongs to DF_IDOM. */
9112 : 403790 : EXECUTE_IF_SET_IN_BITMAP (df_idom, 0, i, bi)
9113 : : {
9114 : 201506 : bb = BASIC_BLOCK_FOR_FN (cfun, i);
9115 : 201506 : for (dbb = first_dom_son (CDI_DOMINATORS, bb);
9116 : 710725 : dbb;
9117 : 509219 : dbb = next_dom_son (CDI_DOMINATORS, dbb))
9118 : 509219 : bbs_to_fix_dom.safe_push (dbb);
9119 : : }
9120 : :
9121 : 202284 : iterate_fix_dominators (CDI_DOMINATORS, bbs_to_fix_dom, true);
9122 : :
9123 : 202284 : bbs_to_fix_dom.release ();
9124 : 202284 : }
9125 : :
9126 : : /* Purge dead EH edges from basic block BB. */
9127 : :
9128 : : bool
9129 : 389534639 : gimple_purge_dead_eh_edges (basic_block bb)
9130 : : {
9131 : 389534639 : bool changed = false;
9132 : 389534639 : edge e;
9133 : 389534639 : edge_iterator ei;
9134 : 389534639 : gimple *stmt = *gsi_last_bb (bb);
9135 : :
9136 : 389534639 : if (stmt && stmt_can_throw_internal (cfun, stmt))
9137 : : return false;
9138 : :
9139 : 832468530 : for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
9140 : : {
9141 : 483049934 : if (e->flags & EDGE_EH)
9142 : : {
9143 : 714046 : remove_edge_and_dominated_blocks (e);
9144 : 714046 : changed = true;
9145 : : }
9146 : : else
9147 : 482335888 : ei_next (&ei);
9148 : : }
9149 : :
9150 : : return changed;
9151 : : }
9152 : :
9153 : : /* Purge dead EH edges from basic block listed in BLOCKS. */
9154 : :
9155 : : bool
9156 : 6575714 : gimple_purge_all_dead_eh_edges (const_bitmap blocks)
9157 : : {
9158 : 6575714 : bool changed = false;
9159 : 6575714 : unsigned i;
9160 : 6575714 : bitmap_iterator bi;
9161 : :
9162 : 6761680 : EXECUTE_IF_SET_IN_BITMAP (blocks, 0, i, bi)
9163 : : {
9164 : 185966 : basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
9165 : :
9166 : : /* Earlier gimple_purge_dead_eh_edges could have removed
9167 : : this basic block already. */
9168 : 185966 : gcc_assert (bb || changed);
9169 : 185966 : if (bb != NULL)
9170 : 185965 : changed |= gimple_purge_dead_eh_edges (bb);
9171 : : }
9172 : :
9173 : 6575714 : return changed;
9174 : : }
9175 : :
9176 : : /* Purge dead abnormal call edges from basic block BB. */
9177 : :
9178 : : bool
9179 : 75466342 : gimple_purge_dead_abnormal_call_edges (basic_block bb)
9180 : : {
9181 : 75466342 : bool changed = false;
9182 : 75466342 : edge e;
9183 : 75466342 : edge_iterator ei;
9184 : 75466342 : gimple *stmt = *gsi_last_bb (bb);
9185 : :
9186 : 75466342 : if (stmt && stmt_can_make_abnormal_goto (stmt))
9187 : : return false;
9188 : :
9189 : 178695858 : for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
9190 : : {
9191 : 103272533 : if (e->flags & EDGE_ABNORMAL)
9192 : : {
9193 : 1394 : if (e->flags & EDGE_FALLTHRU)
9194 : 0 : e->flags &= ~EDGE_ABNORMAL;
9195 : : else
9196 : 1394 : remove_edge_and_dominated_blocks (e);
9197 : : changed = true;
9198 : : }
9199 : : else
9200 : 103271139 : ei_next (&ei);
9201 : : }
9202 : :
9203 : : return changed;
9204 : : }
9205 : :
9206 : : /* Purge dead abnormal call edges from basic block listed in BLOCKS. */
9207 : :
9208 : : bool
9209 : 5179164 : gimple_purge_all_dead_abnormal_call_edges (const_bitmap blocks)
9210 : : {
9211 : 5179164 : bool changed = false;
9212 : 5179164 : unsigned i;
9213 : 5179164 : bitmap_iterator bi;
9214 : :
9215 : 5179178 : EXECUTE_IF_SET_IN_BITMAP (blocks, 0, i, bi)
9216 : : {
9217 : 14 : basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
9218 : :
9219 : : /* Earlier gimple_purge_dead_abnormal_call_edges could have removed
9220 : : this basic block already. */
9221 : 14 : gcc_assert (bb || changed);
9222 : 14 : if (bb != NULL)
9223 : 14 : changed |= gimple_purge_dead_abnormal_call_edges (bb);
9224 : : }
9225 : :
9226 : 5179164 : return changed;
9227 : : }
9228 : :
9229 : : /* This function is called whenever a new edge is created or
9230 : : redirected. */
9231 : :
9232 : : static void
9233 : 137838600 : gimple_execute_on_growing_pred (edge e)
9234 : : {
9235 : 137838600 : basic_block bb = e->dest;
9236 : :
9237 : 137838600 : if (!gimple_seq_empty_p (phi_nodes (bb)))
9238 : 26168338 : reserve_phi_args_for_new_edge (bb);
9239 : 137838600 : }
9240 : :
9241 : : /* This function is called immediately before edge E is removed from
9242 : : the edge vector E->dest->preds. */
9243 : :
9244 : : static void
9245 : 112082611 : gimple_execute_on_shrinking_pred (edge e)
9246 : : {
9247 : 112082611 : if (!gimple_seq_empty_p (phi_nodes (e->dest)))
9248 : 28725930 : remove_phi_args (e);
9249 : 112082611 : }
9250 : :
9251 : : /*---------------------------------------------------------------------------
9252 : : Helper functions for Loop versioning
9253 : : ---------------------------------------------------------------------------*/
9254 : :
9255 : : /* Adjust phi nodes for 'first' basic block. 'second' basic block is a copy
9256 : : of 'first'. Both of them are dominated by 'new_head' basic block. When
9257 : : 'new_head' was created by 'second's incoming edge it received phi arguments
9258 : : on the edge by split_edge(). Later, additional edge 'e' was created to
9259 : : connect 'new_head' and 'first'. Now this routine adds phi args on this
9260 : : additional edge 'e' that new_head to second edge received as part of edge
9261 : : splitting. */
9262 : :
9263 : : static void
9264 : 28813 : gimple_lv_adjust_loop_header_phi (basic_block first, basic_block second,
9265 : : basic_block new_head, edge e)
9266 : : {
9267 : 28813 : gphi *phi1, *phi2;
9268 : 28813 : gphi_iterator psi1, psi2;
9269 : 28813 : tree def;
9270 : 28813 : edge e2 = find_edge (new_head, second);
9271 : :
9272 : : /* Because NEW_HEAD has been created by splitting SECOND's incoming
9273 : : edge, we should always have an edge from NEW_HEAD to SECOND. */
9274 : 28813 : gcc_assert (e2 != NULL);
9275 : :
9276 : : /* Browse all 'second' basic block phi nodes and add phi args to
9277 : : edge 'e' for 'first' head. PHI args are always in correct order. */
9278 : :
9279 : 28813 : for (psi2 = gsi_start_phis (second),
9280 : 28813 : psi1 = gsi_start_phis (first);
9281 : 109320 : !gsi_end_p (psi2) && !gsi_end_p (psi1);
9282 : 80507 : gsi_next (&psi2), gsi_next (&psi1))
9283 : : {
9284 : 80507 : phi1 = psi1.phi ();
9285 : 80507 : phi2 = psi2.phi ();
9286 : 80507 : def = PHI_ARG_DEF (phi2, e2->dest_idx);
9287 : 80507 : add_phi_arg (phi1, def, e, gimple_phi_arg_location_from_edge (phi2, e2));
9288 : : }
9289 : 28813 : }
9290 : :
9291 : :
9292 : : /* Adds a if else statement to COND_BB with condition COND_EXPR.
9293 : : SECOND_HEAD is the destination of the THEN and FIRST_HEAD is
9294 : : the destination of the ELSE part. */
9295 : :
9296 : : static void
9297 : 28813 : gimple_lv_add_condition_to_bb (basic_block first_head ATTRIBUTE_UNUSED,
9298 : : basic_block second_head ATTRIBUTE_UNUSED,
9299 : : basic_block cond_bb, void *cond_e)
9300 : : {
9301 : 28813 : gimple_stmt_iterator gsi;
9302 : 28813 : gimple *new_cond_expr;
9303 : 28813 : tree cond_expr = (tree) cond_e;
9304 : 28813 : edge e0;
9305 : :
9306 : : /* Build new conditional expr */
9307 : 28813 : gsi = gsi_last_bb (cond_bb);
9308 : :
9309 : 28813 : cond_expr = force_gimple_operand_gsi_1 (&gsi, cond_expr,
9310 : : is_gimple_condexpr_for_cond,
9311 : : NULL_TREE, false,
9312 : : GSI_CONTINUE_LINKING);
9313 : 28813 : new_cond_expr = gimple_build_cond_from_tree (cond_expr,
9314 : : NULL_TREE, NULL_TREE);
9315 : :
9316 : : /* Add new cond in cond_bb. */
9317 : 28813 : gsi_insert_after (&gsi, new_cond_expr, GSI_NEW_STMT);
9318 : :
9319 : : /* Adjust edges appropriately to connect new head with first head
9320 : : as well as second head. */
9321 : 28813 : e0 = single_succ_edge (cond_bb);
9322 : 28813 : e0->flags &= ~EDGE_FALLTHRU;
9323 : 28813 : e0->flags |= EDGE_FALSE_VALUE;
9324 : 28813 : }
9325 : :
9326 : :
9327 : : /* Do book-keeping of basic block BB for the profile consistency checker.
9328 : : Store the counting in RECORD. */
9329 : : static void
9330 : 0 : gimple_account_profile_record (basic_block bb,
9331 : : struct profile_record *record)
9332 : : {
9333 : 0 : gimple_stmt_iterator i;
9334 : 0 : for (i = gsi_start_nondebug_after_labels_bb (bb); !gsi_end_p (i);
9335 : 0 : gsi_next_nondebug (&i))
9336 : : {
9337 : 0 : record->size
9338 : 0 : += estimate_num_insns (gsi_stmt (i), &eni_size_weights);
9339 : 0 : if (profile_info)
9340 : : {
9341 : 0 : if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa ().initialized_p ()
9342 : 0 : && ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa ().nonzero_p ()
9343 : 0 : && bb->count.ipa ().initialized_p ())
9344 : 0 : record->time
9345 : 0 : += estimate_num_insns (gsi_stmt (i),
9346 : : &eni_time_weights)
9347 : 0 : * bb->count.ipa ().to_gcov_type ();
9348 : : }
9349 : 0 : else if (bb->count.initialized_p ()
9350 : 0 : && ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.initialized_p ())
9351 : 0 : record->time
9352 : 0 : += estimate_num_insns
9353 : 0 : (gsi_stmt (i),
9354 : : &eni_time_weights)
9355 : 0 : * bb->count.to_sreal_scale
9356 : 0 : (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count).to_double ();
9357 : : else
9358 : 0 : record->time
9359 : 0 : += estimate_num_insns (gsi_stmt (i), &eni_time_weights);
9360 : : }
9361 : 0 : }
9362 : :
9363 : : struct cfg_hooks gimple_cfg_hooks = {
9364 : : "gimple",
9365 : : gimple_verify_flow_info,
9366 : : gimple_dump_bb, /* dump_bb */
9367 : : gimple_dump_bb_for_graph, /* dump_bb_for_graph */
9368 : : create_bb, /* create_basic_block */
9369 : : gimple_redirect_edge_and_branch, /* redirect_edge_and_branch */
9370 : : gimple_redirect_edge_and_branch_force, /* redirect_edge_and_branch_force */
9371 : : gimple_can_remove_branch_p, /* can_remove_branch_p */
9372 : : remove_bb, /* delete_basic_block */
9373 : : gimple_split_block, /* split_block */
9374 : : gimple_move_block_after, /* move_block_after */
9375 : : gimple_can_merge_blocks_p, /* can_merge_blocks_p */
9376 : : gimple_merge_blocks, /* merge_blocks */
9377 : : gimple_predict_edge, /* predict_edge */
9378 : : gimple_predicted_by_p, /* predicted_by_p */
9379 : : gimple_can_duplicate_bb_p, /* can_duplicate_block_p */
9380 : : gimple_duplicate_bb, /* duplicate_block */
9381 : : gimple_split_edge, /* split_edge */
9382 : : gimple_make_forwarder_block, /* make_forward_block */
9383 : : NULL, /* tidy_fallthru_edge */
9384 : : NULL, /* force_nonfallthru */
9385 : : gimple_block_ends_with_call_p,/* block_ends_with_call_p */
9386 : : gimple_block_ends_with_condjump_p, /* block_ends_with_condjump_p */
9387 : : gimple_flow_call_edges_add, /* flow_call_edges_add */
9388 : : gimple_execute_on_growing_pred, /* execute_on_growing_pred */
9389 : : gimple_execute_on_shrinking_pred, /* execute_on_shrinking_pred */
9390 : : gimple_duplicate_loop_body_to_header_edge, /* duplicate loop for trees */
9391 : : gimple_lv_add_condition_to_bb, /* lv_add_condition_to_bb */
9392 : : gimple_lv_adjust_loop_header_phi, /* lv_adjust_loop_header_phi*/
9393 : : extract_true_false_edges_from_block, /* extract_cond_bb_edges */
9394 : : flush_pending_stmts, /* flush_pending_stmts */
9395 : : gimple_empty_block_p, /* block_empty_p */
9396 : : gimple_split_block_before_cond_jump, /* split_block_before_cond_jump */
9397 : : gimple_account_profile_record,
9398 : : };
9399 : :
9400 : :
9401 : : /* Split all critical edges. Split some extra (not necessarily critical) edges
9402 : : if FOR_EDGE_INSERTION_P is true. */
9403 : :
9404 : : unsigned int
9405 : 4001334 : split_critical_edges (bool for_edge_insertion_p /* = false */)
9406 : : {
9407 : 4001334 : basic_block bb;
9408 : 4001334 : edge e;
9409 : 4001334 : edge_iterator ei;
9410 : :
9411 : : /* split_edge can redirect edges out of SWITCH_EXPRs, which can get
9412 : : expensive. So we want to enable recording of edge to CASE_LABEL_EXPR
9413 : : mappings around the calls to split_edge. */
9414 : 4001334 : start_recording_case_labels ();
9415 : 68172314 : FOR_ALL_BB_FN (bb, cfun)
9416 : : {
9417 : 142207481 : FOR_EACH_EDGE (e, ei, bb->succs)
9418 : : {
9419 : 78036501 : if (EDGE_CRITICAL_P (e) && !(e->flags & EDGE_ABNORMAL))
9420 : 13717506 : split_edge (e);
9421 : : /* PRE inserts statements to edges and expects that
9422 : : since split_critical_edges was done beforehand, committing edge
9423 : : insertions will not split more edges. In addition to critical
9424 : : edges we must split edges that have multiple successors and
9425 : : end by control flow statements, such as RESX.
9426 : : Go ahead and split them too. This matches the logic in
9427 : : gimple_find_edge_insert_loc. */
9428 : 64318995 : else if (for_edge_insertion_p
9429 : 101182418 : && (!single_pred_p (e->dest)
9430 : 28293804 : || !gimple_seq_empty_p (phi_nodes (e->dest))
9431 : 28065197 : || e->dest == EXIT_BLOCK_PTR_FOR_FN (cfun))
9432 : 25461571 : && e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun)
9433 : 89780209 : && !(e->flags & EDGE_ABNORMAL))
9434 : : {
9435 : 25446907 : gimple_stmt_iterator gsi;
9436 : :
9437 : 25446907 : gsi = gsi_last_bb (e->src);
9438 : 25446907 : if (!gsi_end_p (gsi)
9439 : 12844085 : && stmt_ends_bb_p (gsi_stmt (gsi))
9440 : 28595265 : && (gimple_code (gsi_stmt (gsi)) != GIMPLE_RETURN
9441 : 206149 : && !gimple_call_builtin_p (gsi_stmt (gsi),
9442 : : BUILT_IN_RETURN)))
9443 : 205101 : split_edge (e);
9444 : : }
9445 : : }
9446 : : }
9447 : 4001334 : end_recording_case_labels ();
9448 : 4001334 : return 0;
9449 : : }
9450 : :
9451 : : namespace {
9452 : :
9453 : : const pass_data pass_data_split_crit_edges =
9454 : : {
9455 : : GIMPLE_PASS, /* type */
9456 : : "crited", /* name */
9457 : : OPTGROUP_NONE, /* optinfo_flags */
9458 : : TV_TREE_SPLIT_EDGES, /* tv_id */
9459 : : PROP_cfg, /* properties_required */
9460 : : PROP_no_crit_edges, /* properties_provided */
9461 : : 0, /* properties_destroyed */
9462 : : 0, /* todo_flags_start */
9463 : : 0, /* todo_flags_finish */
9464 : : };
9465 : :
9466 : : class pass_split_crit_edges : public gimple_opt_pass
9467 : : {
9468 : : public:
9469 : 563828 : pass_split_crit_edges (gcc::context *ctxt)
9470 : 1127656 : : gimple_opt_pass (pass_data_split_crit_edges, ctxt)
9471 : : {}
9472 : :
9473 : : /* opt_pass methods: */
9474 : 988045 : unsigned int execute (function *) final override
9475 : : {
9476 : 988045 : return split_critical_edges ();
9477 : : }
9478 : :
9479 : 281914 : opt_pass * clone () final override
9480 : : {
9481 : 281914 : return new pass_split_crit_edges (m_ctxt);
9482 : : }
9483 : : }; // class pass_split_crit_edges
9484 : :
9485 : : } // anon namespace
9486 : :
9487 : : gimple_opt_pass *
9488 : 281914 : make_pass_split_crit_edges (gcc::context *ctxt)
9489 : : {
9490 : 281914 : return new pass_split_crit_edges (ctxt);
9491 : : }
9492 : :
9493 : :
9494 : : /* Insert COND expression which is GIMPLE_COND after STMT
9495 : : in basic block BB with appropriate basic block split
9496 : : and creation of a new conditionally executed basic block.
9497 : : Update profile so the new bb is visited with probability PROB.
9498 : : Return created basic block. */
9499 : : basic_block
9500 : 2213 : insert_cond_bb (basic_block bb, gimple *stmt, gimple *cond,
9501 : : profile_probability prob)
9502 : : {
9503 : 2213 : edge fall = split_block (bb, stmt);
9504 : 2213 : gimple_stmt_iterator iter = gsi_last_bb (bb);
9505 : 2213 : basic_block new_bb;
9506 : :
9507 : : /* Insert cond statement. */
9508 : 2213 : gcc_assert (gimple_code (cond) == GIMPLE_COND);
9509 : 2213 : if (gsi_end_p (iter))
9510 : 0 : gsi_insert_before (&iter, cond, GSI_CONTINUE_LINKING);
9511 : : else
9512 : 2213 : gsi_insert_after (&iter, cond, GSI_CONTINUE_LINKING);
9513 : :
9514 : : /* Create conditionally executed block. */
9515 : 2213 : new_bb = create_empty_bb (bb);
9516 : 2213 : edge e = make_edge (bb, new_bb, EDGE_TRUE_VALUE);
9517 : 2213 : e->probability = prob;
9518 : 2213 : new_bb->count = e->count ();
9519 : 2213 : make_single_succ_edge (new_bb, fall->dest, EDGE_FALLTHRU);
9520 : :
9521 : : /* Fix edge for split bb. */
9522 : 2213 : fall->flags = EDGE_FALSE_VALUE;
9523 : 2213 : fall->probability -= e->probability;
9524 : :
9525 : : /* Update dominance info. */
9526 : 2213 : if (dom_info_available_p (CDI_DOMINATORS))
9527 : : {
9528 : 2213 : set_immediate_dominator (CDI_DOMINATORS, new_bb, bb);
9529 : 2213 : set_immediate_dominator (CDI_DOMINATORS, fall->dest, bb);
9530 : : }
9531 : :
9532 : : /* Update loop info. */
9533 : 2213 : if (current_loops)
9534 : 2213 : add_bb_to_loop (new_bb, bb->loop_father);
9535 : :
9536 : 2213 : return new_bb;
9537 : : }
9538 : :
9539 : :
9540 : :
9541 : : /* Given a basic block B which ends with a conditional and has
9542 : : precisely two successors, determine which of the edges is taken if
9543 : : the conditional is true and which is taken if the conditional is
9544 : : false. Set TRUE_EDGE and FALSE_EDGE appropriately. */
9545 : :
9546 : : void
9547 : 731945689 : extract_true_false_edges_from_block (basic_block b,
9548 : : edge *true_edge,
9549 : : edge *false_edge)
9550 : : {
9551 : 731945689 : edge e = EDGE_SUCC (b, 0);
9552 : :
9553 : 731945689 : if (e->flags & EDGE_TRUE_VALUE)
9554 : : {
9555 : 700218299 : *true_edge = e;
9556 : 700218299 : *false_edge = EDGE_SUCC (b, 1);
9557 : : }
9558 : : else
9559 : : {
9560 : 31727390 : *false_edge = e;
9561 : 31727390 : *true_edge = EDGE_SUCC (b, 1);
9562 : : }
9563 : 731945689 : }
9564 : :
9565 : :
9566 : : /* From a controlling predicate in the immediate dominator DOM of
9567 : : PHIBLOCK determine the edges into PHIBLOCK that are chosen if the
9568 : : predicate evaluates to true and false and store them to
9569 : : *TRUE_CONTROLLED_EDGE and *FALSE_CONTROLLED_EDGE if
9570 : : they are non-NULL. Returns true if the edges can be determined,
9571 : : else return false. */
9572 : :
9573 : : bool
9574 : 139188 : extract_true_false_controlled_edges (basic_block dom, basic_block phiblock,
9575 : : edge *true_controlled_edge,
9576 : : edge *false_controlled_edge)
9577 : : {
9578 : 139188 : basic_block bb = phiblock;
9579 : 139188 : edge true_edge, false_edge, tem;
9580 : 139188 : edge e0 = NULL, e1 = NULL;
9581 : :
9582 : : /* We have to verify that one edge into the PHI node is dominated
9583 : : by the true edge of the predicate block and the other edge
9584 : : dominated by the false edge. This ensures that the PHI argument
9585 : : we are going to take is completely determined by the path we
9586 : : take from the predicate block.
9587 : : We can only use BB dominance checks below if the destination of
9588 : : the true/false edges are dominated by their edge, thus only
9589 : : have a single predecessor. */
9590 : 139188 : extract_true_false_edges_from_block (dom, &true_edge, &false_edge);
9591 : 139188 : tem = EDGE_PRED (bb, 0);
9592 : 139188 : if (tem == true_edge
9593 : 139188 : || (single_pred_p (true_edge->dest)
9594 : 104996 : && (tem->src == true_edge->dest
9595 : 75354 : || dominated_by_p (CDI_DOMINATORS,
9596 : : tem->src, true_edge->dest))))
9597 : : e0 = tem;
9598 : 56634 : else if (tem == false_edge
9599 : 56634 : || (single_pred_p (false_edge->dest)
9600 : 45573 : && (tem->src == false_edge->dest
9601 : 34553 : || dominated_by_p (CDI_DOMINATORS,
9602 : : tem->src, false_edge->dest))))
9603 : : e1 = tem;
9604 : : else
9605 : 23782 : return false;
9606 : 115406 : tem = EDGE_PRED (bb, 1);
9607 : 115406 : if (tem == true_edge
9608 : 115406 : || (single_pred_p (true_edge->dest)
9609 : 85599 : && (tem->src == true_edge->dest
9610 : 70738 : || dominated_by_p (CDI_DOMINATORS,
9611 : : tem->src, true_edge->dest))))
9612 : : e0 = tem;
9613 : 86419 : else if (tem == false_edge
9614 : 86419 : || (single_pred_p (false_edge->dest)
9615 : 64914 : && (tem->src == false_edge->dest
9616 : 21408 : || dominated_by_p (CDI_DOMINATORS,
9617 : : tem->src, false_edge->dest))))
9618 : : e1 = tem;
9619 : : else
9620 : 15832 : return false;
9621 : 99574 : if (!e0 || !e1)
9622 : : return false;
9623 : :
9624 : 99574 : if (true_controlled_edge)
9625 : 99574 : *true_controlled_edge = e0;
9626 : 99574 : if (false_controlled_edge)
9627 : 99574 : *false_controlled_edge = e1;
9628 : :
9629 : : return true;
9630 : : }
9631 : :
9632 : : /* Generate a range test LHS CODE RHS that determines whether INDEX is in the
9633 : : range [low, high]. Place associated stmts before *GSI. */
9634 : :
9635 : : void
9636 : 5386 : generate_range_test (basic_block bb, tree index, tree low, tree high,
9637 : : tree *lhs, tree *rhs)
9638 : : {
9639 : 5386 : tree type = TREE_TYPE (index);
9640 : 5386 : tree utype = range_check_type (type);
9641 : :
9642 : 5386 : low = fold_convert (utype, low);
9643 : 5386 : high = fold_convert (utype, high);
9644 : :
9645 : 5386 : gimple_seq seq = NULL;
9646 : 5386 : index = gimple_convert (&seq, utype, index);
9647 : 5386 : *lhs = gimple_build (&seq, MINUS_EXPR, utype, index, low);
9648 : 5386 : *rhs = const_binop (MINUS_EXPR, utype, high, low);
9649 : :
9650 : 5386 : gimple_stmt_iterator gsi = gsi_last_bb (bb);
9651 : 5386 : gsi_insert_seq_before (&gsi, seq, GSI_SAME_STMT);
9652 : 5386 : }
9653 : :
9654 : : /* Return the basic block that belongs to label numbered INDEX
9655 : : of a switch statement. */
9656 : :
9657 : : basic_block
9658 : 58696684 : gimple_switch_label_bb (function *ifun, gswitch *gs, unsigned index)
9659 : : {
9660 : 58696684 : return label_to_block (ifun, CASE_LABEL (gimple_switch_label (gs, index)));
9661 : : }
9662 : :
9663 : : /* Return the default basic block of a switch statement. */
9664 : :
9665 : : basic_block
9666 : 318765 : gimple_switch_default_bb (function *ifun, gswitch *gs)
9667 : : {
9668 : 318765 : return gimple_switch_label_bb (ifun, gs, 0);
9669 : : }
9670 : :
9671 : : /* Return the edge that belongs to label numbered INDEX
9672 : : of a switch statement. */
9673 : :
9674 : : edge
9675 : 1128561 : gimple_switch_edge (function *ifun, gswitch *gs, unsigned index)
9676 : : {
9677 : 1128561 : return find_edge (gimple_bb (gs), gimple_switch_label_bb (ifun, gs, index));
9678 : : }
9679 : :
9680 : : /* Return the default edge of a switch statement. */
9681 : :
9682 : : edge
9683 : 144366 : gimple_switch_default_edge (function *ifun, gswitch *gs)
9684 : : {
9685 : 144366 : return gimple_switch_edge (ifun, gs, 0);
9686 : : }
9687 : :
9688 : : /* Return true if the only executable statement in BB is a GIMPLE_COND. */
9689 : :
9690 : : bool
9691 : 1564 : cond_only_block_p (basic_block bb)
9692 : : {
9693 : : /* BB must have no executable statements. */
9694 : 1564 : gimple_stmt_iterator gsi = gsi_after_labels (bb);
9695 : 1564 : if (phi_nodes (bb))
9696 : : return false;
9697 : 3271 : while (!gsi_end_p (gsi))
9698 : : {
9699 : 1723 : gimple *stmt = gsi_stmt (gsi);
9700 : 1723 : if (is_gimple_debug (stmt))
9701 : : ;
9702 : 1564 : else if (gimple_code (stmt) == GIMPLE_NOP
9703 : : || gimple_code (stmt) == GIMPLE_PREDICT
9704 : : || gimple_code (stmt) == GIMPLE_COND)
9705 : : ;
9706 : : else
9707 : : return false;
9708 : 1707 : gsi_next (&gsi);
9709 : : }
9710 : : return true;
9711 : : }
9712 : :
9713 : :
9714 : : /* Emit return warnings. */
9715 : :
9716 : : namespace {
9717 : :
9718 : : const pass_data pass_data_warn_function_return =
9719 : : {
9720 : : GIMPLE_PASS, /* type */
9721 : : "*warn_function_return", /* name */
9722 : : OPTGROUP_NONE, /* optinfo_flags */
9723 : : TV_NONE, /* tv_id */
9724 : : PROP_cfg, /* properties_required */
9725 : : 0, /* properties_provided */
9726 : : 0, /* properties_destroyed */
9727 : : 0, /* todo_flags_start */
9728 : : 0, /* todo_flags_finish */
9729 : : };
9730 : :
9731 : : class pass_warn_function_return : public gimple_opt_pass
9732 : : {
9733 : : public:
9734 : 281914 : pass_warn_function_return (gcc::context *ctxt)
9735 : 563828 : : gimple_opt_pass (pass_data_warn_function_return, ctxt)
9736 : : {}
9737 : :
9738 : : /* opt_pass methods: */
9739 : : unsigned int execute (function *) final override;
9740 : :
9741 : : }; // class pass_warn_function_return
9742 : :
9743 : : unsigned int
9744 : 2688896 : pass_warn_function_return::execute (function *fun)
9745 : : {
9746 : 2688896 : location_t location;
9747 : 2688896 : gimple *last;
9748 : 2688896 : edge e;
9749 : 2688896 : edge_iterator ei;
9750 : :
9751 : 2688896 : if (!targetm.warn_func_return (fun->decl))
9752 : : return 0;
9753 : :
9754 : : /* If we have a path to EXIT, then we do return. */
9755 : 2688821 : if (TREE_THIS_VOLATILE (fun->decl)
9756 : 2688821 : && EDGE_COUNT (EXIT_BLOCK_PTR_FOR_FN (fun)->preds) > 0)
9757 : : {
9758 : 79 : location = UNKNOWN_LOCATION;
9759 : 79 : for (ei = ei_start (EXIT_BLOCK_PTR_FOR_FN (fun)->preds);
9760 : 124 : (e = ei_safe_edge (ei)); )
9761 : : {
9762 : 79 : last = *gsi_last_bb (e->src);
9763 : 79 : if ((gimple_code (last) == GIMPLE_RETURN
9764 : 0 : || gimple_call_builtin_p (last, BUILT_IN_RETURN))
9765 : 79 : && location == UNKNOWN_LOCATION
9766 : 79 : && ((location = LOCATION_LOCUS (gimple_location (last)))
9767 : : != UNKNOWN_LOCATION)
9768 : 156 : && !optimize)
9769 : : break;
9770 : : /* When optimizing, replace return stmts in noreturn functions
9771 : : with __builtin_unreachable () call. */
9772 : 45 : if (optimize && gimple_code (last) == GIMPLE_RETURN)
9773 : : {
9774 : 45 : location_t loc = gimple_location (last);
9775 : 45 : gimple *new_stmt = gimple_build_builtin_unreachable (loc);
9776 : 45 : gimple_stmt_iterator gsi = gsi_for_stmt (last);
9777 : 45 : gsi_replace (&gsi, new_stmt, true);
9778 : 45 : remove_edge (e);
9779 : : }
9780 : : else
9781 : 0 : ei_next (&ei);
9782 : : }
9783 : 79 : if (location == UNKNOWN_LOCATION)
9784 : 2 : location = cfun->function_end_locus;
9785 : 79 : warning_at (location, 0, "%<noreturn%> function does return");
9786 : : }
9787 : :
9788 : : /* If we see "return;" in some basic block, then we do reach the end
9789 : : without returning a value. */
9790 : 2688742 : else if (warn_return_type > 0
9791 : 1770041 : && !warning_suppressed_p (fun->decl, OPT_Wreturn_type)
9792 : 4455741 : && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (fun->decl))))
9793 : : {
9794 : 1825370 : FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (fun)->preds)
9795 : : {
9796 : 2730016 : greturn *return_stmt = dyn_cast <greturn *> (*gsi_last_bb (e->src));
9797 : 909921 : if (return_stmt
9798 : 909921 : && gimple_return_retval (return_stmt) == NULL
9799 : 41 : && !warning_suppressed_p (return_stmt, OPT_Wreturn_type))
9800 : : {
9801 : 19 : location = gimple_location (return_stmt);
9802 : 19 : if (LOCATION_LOCUS (location) == UNKNOWN_LOCATION)
9803 : 0 : location = fun->function_end_locus;
9804 : 19 : if (warning_at (location, OPT_Wreturn_type,
9805 : : "control reaches end of non-void function"))
9806 : 17 : suppress_warning (fun->decl, OPT_Wreturn_type);
9807 : : break;
9808 : : }
9809 : : }
9810 : : /* The C++ FE turns fallthrough from the end of non-void function
9811 : : into __builtin_unreachable () call with BUILTINS_LOCATION.
9812 : : Recognize those as well as calls from ubsan_instrument_return. */
9813 : 915332 : basic_block bb;
9814 : 915332 : if (!warning_suppressed_p (fun->decl, OPT_Wreturn_type))
9815 : 4500605 : FOR_EACH_BB_FN (bb, fun)
9816 : 3585865 : if (EDGE_COUNT (bb->succs) == 0)
9817 : : {
9818 : 160269 : gimple *last = *gsi_last_bb (bb);
9819 : 160269 : const enum built_in_function ubsan_missing_ret
9820 : : = BUILT_IN_UBSAN_HANDLE_MISSING_RETURN;
9821 : 160269 : if (last
9822 : 160269 : && ((LOCATION_LOCUS (gimple_location (last))
9823 : : == BUILTINS_LOCATION
9824 : 555 : && (gimple_call_builtin_p (last, BUILT_IN_UNREACHABLE)
9825 : 226 : || gimple_call_builtin_p (last,
9826 : : BUILT_IN_UNREACHABLE_TRAP)
9827 : 4 : || gimple_call_builtin_p (last, BUILT_IN_TRAP)))
9828 : 159714 : || gimple_call_builtin_p (last, ubsan_missing_ret)))
9829 : : {
9830 : 575 : gimple_stmt_iterator gsi = gsi_for_stmt (last);
9831 : 575 : gsi_prev_nondebug (&gsi);
9832 : 575 : gimple *prev = gsi_stmt (gsi);
9833 : 575 : if (prev == NULL)
9834 : : location = UNKNOWN_LOCATION;
9835 : : else
9836 : 191 : location = gimple_location (prev);
9837 : 575 : if (LOCATION_LOCUS (location) == UNKNOWN_LOCATION)
9838 : 413 : location = fun->function_end_locus;
9839 : 575 : if (warning_at (location, OPT_Wreturn_type,
9840 : : "control reaches end of non-void function"))
9841 : 139 : suppress_warning (fun->decl, OPT_Wreturn_type);
9842 : 575 : break;
9843 : : }
9844 : : }
9845 : : }
9846 : : return 0;
9847 : : }
9848 : :
9849 : : } // anon namespace
9850 : :
9851 : : gimple_opt_pass *
9852 : 281914 : make_pass_warn_function_return (gcc::context *ctxt)
9853 : : {
9854 : 281914 : return new pass_warn_function_return (ctxt);
9855 : : }
9856 : :
9857 : : /* Walk a gimplified function and warn for functions whose return value is
9858 : : ignored and attribute((warn_unused_result)) is set. This is done before
9859 : : inlining, so we don't have to worry about that. */
9860 : :
9861 : : static void
9862 : 9092731 : do_warn_unused_result (gimple_seq seq)
9863 : : {
9864 : 9092731 : tree fdecl, ftype;
9865 : 9092731 : gimple_stmt_iterator i;
9866 : :
9867 : 57885716 : for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
9868 : : {
9869 : 48792985 : gimple *g = gsi_stmt (i);
9870 : :
9871 : 48792985 : switch (gimple_code (g))
9872 : : {
9873 : 3320343 : case GIMPLE_BIND:
9874 : 3320343 : do_warn_unused_result (gimple_bind_body (as_a <gbind *>(g)));
9875 : 3320343 : break;
9876 : 1778067 : case GIMPLE_TRY:
9877 : 1778067 : do_warn_unused_result (gimple_try_eval (g));
9878 : 1778067 : do_warn_unused_result (gimple_try_cleanup (g));
9879 : 1778067 : break;
9880 : 21793 : case GIMPLE_CATCH:
9881 : 43586 : do_warn_unused_result (gimple_catch_handler (
9882 : 21793 : as_a <gcatch *> (g)));
9883 : 21793 : break;
9884 : 5324 : case GIMPLE_EH_FILTER:
9885 : 5324 : do_warn_unused_result (gimple_eh_filter_failure (g));
9886 : 5324 : break;
9887 : :
9888 : 6962165 : case GIMPLE_CALL:
9889 : 6962165 : if (gimple_call_lhs (g))
9890 : : break;
9891 : 3981202 : if (gimple_call_internal_p (g))
9892 : : break;
9893 : :
9894 : : /* This is a naked call, as opposed to a GIMPLE_CALL with an
9895 : : LHS. All calls whose value is ignored should be
9896 : : represented like this. Look for the attribute. */
9897 : 3962517 : fdecl = gimple_call_fndecl (g);
9898 : 3962517 : ftype = gimple_call_fntype (g);
9899 : :
9900 : 3962517 : if (lookup_attribute ("warn_unused_result", TYPE_ATTRIBUTES (ftype)))
9901 : : {
9902 : 222 : location_t loc = gimple_location (g);
9903 : :
9904 : 222 : if (fdecl)
9905 : 132 : warning_at (loc, OPT_Wunused_result,
9906 : : "ignoring return value of %qD "
9907 : : "declared with attribute %<warn_unused_result%>",
9908 : : fdecl);
9909 : : else
9910 : 90 : warning_at (loc, OPT_Wunused_result,
9911 : : "ignoring return value of function "
9912 : : "declared with attribute %<warn_unused_result%>");
9913 : : }
9914 : : break;
9915 : :
9916 : : default:
9917 : : /* Not a container, not a call, or a call whose value is used. */
9918 : : break;
9919 : : }
9920 : : }
9921 : 9092731 : }
9922 : :
9923 : : namespace {
9924 : :
9925 : : const pass_data pass_data_warn_unused_result =
9926 : : {
9927 : : GIMPLE_PASS, /* type */
9928 : : "*warn_unused_result", /* name */
9929 : : OPTGROUP_NONE, /* optinfo_flags */
9930 : : TV_NONE, /* tv_id */
9931 : : PROP_gimple_any, /* properties_required */
9932 : : 0, /* properties_provided */
9933 : : 0, /* properties_destroyed */
9934 : : 0, /* todo_flags_start */
9935 : : 0, /* todo_flags_finish */
9936 : : };
9937 : :
9938 : : class pass_warn_unused_result : public gimple_opt_pass
9939 : : {
9940 : : public:
9941 : 281914 : pass_warn_unused_result (gcc::context *ctxt)
9942 : 563828 : : gimple_opt_pass (pass_data_warn_unused_result, ctxt)
9943 : : {}
9944 : :
9945 : : /* opt_pass methods: */
9946 : 2688925 : bool gate (function *) final override { return flag_warn_unused_result; }
9947 : 2189137 : unsigned int execute (function *) final override
9948 : : {
9949 : 2189137 : do_warn_unused_result (gimple_body (current_function_decl));
9950 : 2189137 : return 0;
9951 : : }
9952 : :
9953 : : }; // class pass_warn_unused_result
9954 : :
9955 : : } // anon namespace
9956 : :
9957 : : gimple_opt_pass *
9958 : 281914 : make_pass_warn_unused_result (gcc::context *ctxt)
9959 : : {
9960 : 281914 : return new pass_warn_unused_result (ctxt);
9961 : : }
9962 : :
9963 : : /* Maybe Remove stores to variables we marked write-only.
9964 : : Return true if a store was removed. */
9965 : : static bool
9966 : 391345407 : maybe_remove_writeonly_store (gimple_stmt_iterator &gsi, gimple *stmt,
9967 : : bitmap dce_ssa_names)
9968 : : {
9969 : : /* Keep access when store has side effect, i.e. in case when source
9970 : : is volatile. */
9971 : 391345407 : if (!gimple_store_p (stmt)
9972 : 56669806 : || gimple_has_side_effects (stmt)
9973 : 436872740 : || optimize_debug)
9974 : 345870248 : return false;
9975 : :
9976 : 45475159 : tree lhs = get_base_address (gimple_get_lhs (stmt));
9977 : :
9978 : 45475159 : if (!VAR_P (lhs)
9979 : 35499702 : || (!TREE_STATIC (lhs) && !DECL_EXTERNAL (lhs))
9980 : 52209807 : || !varpool_node::get (lhs)->writeonly)
9981 : : return false;
9982 : :
9983 : 28988 : if (dump_file && (dump_flags & TDF_DETAILS))
9984 : : {
9985 : 0 : fprintf (dump_file, "Removing statement, writes"
9986 : : " to write only var:\n");
9987 : 0 : print_gimple_stmt (dump_file, stmt, 0,
9988 : : TDF_VOPS|TDF_MEMSYMS);
9989 : : }
9990 : :
9991 : : /* Mark ssa name defining to be checked for simple dce. */
9992 : 28988 : if (gimple_assign_single_p (stmt))
9993 : : {
9994 : 28988 : tree rhs = gimple_assign_rhs1 (stmt);
9995 : 28988 : if (TREE_CODE (rhs) == SSA_NAME
9996 : 28988 : && !SSA_NAME_IS_DEFAULT_DEF (rhs))
9997 : 9190 : bitmap_set_bit (dce_ssa_names, SSA_NAME_VERSION (rhs));
9998 : : }
9999 : 28988 : unlink_stmt_vdef (stmt);
10000 : 28988 : gsi_remove (&gsi, true);
10001 : 28988 : release_defs (stmt);
10002 : 28988 : return true;
10003 : : }
10004 : :
10005 : : /* IPA passes, compilation of earlier functions or inlining
10006 : : might have changed some properties, such as marked functions nothrow,
10007 : : pure, const or noreturn.
10008 : : Remove redundant edges and basic blocks, and create new ones if necessary. */
10009 : :
10010 : : unsigned int
10011 : 10438851 : execute_fixup_cfg (void)
10012 : : {
10013 : 10438851 : basic_block bb;
10014 : 10438851 : gimple_stmt_iterator gsi;
10015 : 10438851 : int todo = 0;
10016 : 10438851 : cgraph_node *node = cgraph_node::get (current_function_decl);
10017 : : /* Same scaling is also done by ipa_merge_profiles. */
10018 : 10438851 : profile_count num = node->count;
10019 : 10438851 : profile_count den = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
10020 : 10438851 : bool scale = num.initialized_p () && !(num == den);
10021 : 10438851 : auto_bitmap dce_ssa_names;
10022 : :
10023 : 10438851 : if (scale)
10024 : : {
10025 : 21675 : profile_count::adjust_for_ipa_scaling (&num, &den);
10026 : 21675 : ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = node->count;
10027 : 21675 : EXIT_BLOCK_PTR_FOR_FN (cfun)->count
10028 : 21675 : = EXIT_BLOCK_PTR_FOR_FN (cfun)->count.apply_scale (num, den);
10029 : : }
10030 : :
10031 : 90530678 : FOR_EACH_BB_FN (bb, cfun)
10032 : : {
10033 : 80091827 : if (scale)
10034 : 935295 : bb->count = bb->count.apply_scale (num, den);
10035 : 551529061 : for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
10036 : : {
10037 : 391345407 : gimple *stmt = gsi_stmt (gsi);
10038 : 391345407 : tree decl = is_gimple_call (stmt)
10039 : 391345407 : ? gimple_call_fndecl (stmt)
10040 : 431557251 : : NULL;
10041 : 40211844 : if (decl)
10042 : : {
10043 : 37721197 : int flags = gimple_call_flags (stmt);
10044 : 37721197 : if (flags & (ECF_CONST | ECF_PURE | ECF_LOOPING_CONST_OR_PURE))
10045 : : {
10046 : 5606039 : if (gimple_in_ssa_p (cfun))
10047 : : {
10048 : 4960731 : todo |= TODO_update_ssa | TODO_cleanup_cfg;
10049 : 4960731 : update_stmt (stmt);
10050 : : }
10051 : : }
10052 : 37721197 : if (flags & ECF_NORETURN
10053 : 37721197 : && fixup_noreturn_call (stmt))
10054 : 71780 : todo |= TODO_cleanup_cfg;
10055 : : }
10056 : :
10057 : : /* Remove stores to variables we marked write-only. */
10058 : 391345407 : if (maybe_remove_writeonly_store (gsi, stmt, dce_ssa_names))
10059 : : {
10060 : 28988 : todo |= TODO_update_ssa | TODO_cleanup_cfg;
10061 : 28988 : continue;
10062 : : }
10063 : :
10064 : : /* For calls we can simply remove LHS when it is known
10065 : : to be write-only. */
10066 : 391316419 : if (is_gimple_call (stmt)
10067 : 391316419 : && gimple_get_lhs (stmt))
10068 : : {
10069 : 16328349 : tree lhs = get_base_address (gimple_get_lhs (stmt));
10070 : :
10071 : 16328349 : if (VAR_P (lhs)
10072 : 4124852 : && (TREE_STATIC (lhs) || DECL_EXTERNAL (lhs))
10073 : 16337609 : && varpool_node::get (lhs)->writeonly)
10074 : : {
10075 : 2 : gimple_call_set_lhs (stmt, NULL);
10076 : 2 : update_stmt (stmt);
10077 : 2 : todo |= TODO_update_ssa | TODO_cleanup_cfg;
10078 : : }
10079 : : }
10080 : :
10081 : 391316419 : gsi_next (&gsi);
10082 : : }
10083 : 160183654 : if (gimple *last = *gsi_last_bb (bb))
10084 : : {
10085 : 74596811 : if (maybe_clean_eh_stmt (last)
10086 : 74596811 : && gimple_purge_dead_eh_edges (bb))
10087 : 147963 : todo |= TODO_cleanup_cfg;
10088 : 74596811 : if (gimple_purge_dead_abnormal_call_edges (bb))
10089 : 1169 : todo |= TODO_cleanup_cfg;
10090 : : }
10091 : :
10092 : : /* If we have a basic block with no successors that does not
10093 : : end with a control statement or a noreturn call end it with
10094 : : a call to __builtin_unreachable. This situation can occur
10095 : : when inlining a noreturn call that does in fact return. */
10096 : 80091827 : if (EDGE_COUNT (bb->succs) == 0)
10097 : : {
10098 : 5331021 : gimple *stmt = last_nondebug_stmt (bb);
10099 : 5331021 : if (!stmt
10100 : 5331021 : || (!is_ctrl_stmt (stmt)
10101 : 4582772 : && (!is_gimple_call (stmt)
10102 : 4582750 : || !gimple_call_noreturn_p (stmt))))
10103 : : {
10104 : 144 : if (stmt && is_gimple_call (stmt))
10105 : 105 : gimple_call_set_ctrl_altering (stmt, false);
10106 : 144 : stmt = gimple_build_builtin_unreachable (UNKNOWN_LOCATION);
10107 : 144 : gimple_stmt_iterator gsi = gsi_last_bb (bb);
10108 : 144 : gsi_insert_after (&gsi, stmt, GSI_NEW_STMT);
10109 : 144 : if (!cfun->after_inlining)
10110 : 116 : if (tree fndecl = gimple_call_fndecl (stmt))
10111 : : {
10112 : 116 : gcall *call_stmt = dyn_cast <gcall *> (stmt);
10113 : 116 : node->create_edge (cgraph_node::get_create (fndecl),
10114 : : call_stmt, bb->count);
10115 : : }
10116 : : }
10117 : : }
10118 : : }
10119 : 10438851 : if (scale)
10120 : : {
10121 : 21675 : update_max_bb_count ();
10122 : 21675 : compute_function_frequency ();
10123 : : }
10124 : :
10125 : 10438851 : if (current_loops
10126 : 10438851 : && (todo & TODO_cleanup_cfg))
10127 : 1714055 : loops_state_set (LOOPS_NEED_FIXUP);
10128 : :
10129 : 10438851 : simple_dce_from_worklist (dce_ssa_names);
10130 : :
10131 : 10438851 : return todo;
10132 : 10438851 : }
10133 : :
10134 : : namespace {
10135 : :
10136 : : const pass_data pass_data_fixup_cfg =
10137 : : {
10138 : : GIMPLE_PASS, /* type */
10139 : : "fixup_cfg", /* name */
10140 : : OPTGROUP_NONE, /* optinfo_flags */
10141 : : TV_NONE, /* tv_id */
10142 : : PROP_cfg, /* properties_required */
10143 : : 0, /* properties_provided */
10144 : : 0, /* properties_destroyed */
10145 : : 0, /* todo_flags_start */
10146 : : 0, /* todo_flags_finish */
10147 : : };
10148 : :
10149 : : class pass_fixup_cfg : public gimple_opt_pass
10150 : : {
10151 : : public:
10152 : 845742 : pass_fixup_cfg (gcc::context *ctxt)
10153 : 1691484 : : gimple_opt_pass (pass_data_fixup_cfg, ctxt)
10154 : : {}
10155 : :
10156 : : /* opt_pass methods: */
10157 : 563828 : opt_pass * clone () final override { return new pass_fixup_cfg (m_ctxt); }
10158 : 6767202 : unsigned int execute (function *) final override
10159 : : {
10160 : 6767202 : return execute_fixup_cfg ();
10161 : : }
10162 : :
10163 : : }; // class pass_fixup_cfg
10164 : :
10165 : : } // anon namespace
10166 : :
10167 : : gimple_opt_pass *
10168 : 281914 : make_pass_fixup_cfg (gcc::context *ctxt)
10169 : : {
10170 : 281914 : return new pass_fixup_cfg (ctxt);
10171 : : }
10172 : :
10173 : : /* Garbage collection support for edge_def. */
10174 : :
10175 : : extern void gt_ggc_mx (tree&);
10176 : : extern void gt_ggc_mx (gimple *&);
10177 : : extern void gt_ggc_mx (rtx&);
10178 : : extern void gt_ggc_mx (basic_block&);
10179 : :
10180 : : static void
10181 : 37680681 : gt_ggc_mx (rtx_insn *& x)
10182 : : {
10183 : 0 : if (x)
10184 : 0 : gt_ggc_mx_rtx_def ((void *) x);
10185 : 0 : }
10186 : :
10187 : : void
10188 : 115716709 : gt_ggc_mx (edge_def *e)
10189 : : {
10190 : 115716709 : tree block = LOCATION_BLOCK (e->goto_locus);
10191 : 115716709 : gt_ggc_mx (e->src);
10192 : 115716709 : gt_ggc_mx (e->dest);
10193 : 115716709 : if (current_ir_type () == IR_GIMPLE)
10194 : 78036028 : gt_ggc_mx (e->insns.g);
10195 : : else
10196 : 37680681 : gt_ggc_mx (e->insns.r);
10197 : 115716709 : gt_ggc_mx (block);
10198 : 115716709 : }
10199 : :
10200 : : /* PCH support for edge_def. */
10201 : :
10202 : : extern void gt_pch_nx (tree&);
10203 : : extern void gt_pch_nx (gimple *&);
10204 : : extern void gt_pch_nx (rtx&);
10205 : : extern void gt_pch_nx (basic_block&);
10206 : :
10207 : : static void
10208 : 0 : gt_pch_nx (rtx_insn *& x)
10209 : : {
10210 : 0 : if (x)
10211 : 0 : gt_pch_nx_rtx_def ((void *) x);
10212 : 0 : }
10213 : :
10214 : : void
10215 : 0 : gt_pch_nx (edge_def *e)
10216 : : {
10217 : 0 : tree block = LOCATION_BLOCK (e->goto_locus);
10218 : 0 : gt_pch_nx (e->src);
10219 : 0 : gt_pch_nx (e->dest);
10220 : 0 : if (current_ir_type () == IR_GIMPLE)
10221 : 0 : gt_pch_nx (e->insns.g);
10222 : : else
10223 : 0 : gt_pch_nx (e->insns.r);
10224 : 0 : gt_pch_nx (block);
10225 : 0 : }
10226 : :
10227 : : void
10228 : 0 : gt_pch_nx (edge_def *e, gt_pointer_operator op, void *cookie)
10229 : : {
10230 : 0 : tree block = LOCATION_BLOCK (e->goto_locus);
10231 : 0 : op (&(e->src), NULL, cookie);
10232 : 0 : op (&(e->dest), NULL, cookie);
10233 : 0 : if (current_ir_type () == IR_GIMPLE)
10234 : 0 : op (&(e->insns.g), NULL, cookie);
10235 : : else
10236 : 0 : op (&(e->insns.r), NULL, cookie);
10237 : 0 : op (&(block), &(block), cookie);
10238 : 0 : }
10239 : :
10240 : : #if CHECKING_P
10241 : :
10242 : : namespace selftest {
10243 : :
10244 : : /* Helper function for CFG selftests: create a dummy function decl
10245 : : and push it as cfun. */
10246 : :
10247 : : static tree
10248 : 12 : push_fndecl (const char *name)
10249 : : {
10250 : 12 : tree fn_type = build_function_type_array (integer_type_node, 0, NULL);
10251 : : /* FIXME: this uses input_location: */
10252 : 12 : tree fndecl = build_fn_decl (name, fn_type);
10253 : 12 : tree retval = build_decl (UNKNOWN_LOCATION, RESULT_DECL,
10254 : : NULL_TREE, integer_type_node);
10255 : 12 : DECL_RESULT (fndecl) = retval;
10256 : 12 : push_struct_function (fndecl);
10257 : 12 : function *fun = DECL_STRUCT_FUNCTION (fndecl);
10258 : 12 : ASSERT_TRUE (fun != NULL);
10259 : 12 : init_empty_tree_cfg_for_function (fun);
10260 : 12 : ASSERT_EQ (2, n_basic_blocks_for_fn (fun));
10261 : 12 : ASSERT_EQ (0, n_edges_for_fn (fun));
10262 : 12 : return fndecl;
10263 : : }
10264 : :
10265 : : /* These tests directly create CFGs.
10266 : : Compare with the static fns within tree-cfg.cc:
10267 : : - build_gimple_cfg
10268 : : - make_blocks: calls create_basic_block (seq, bb);
10269 : : - make_edges. */
10270 : :
10271 : : /* Verify a simple cfg of the form:
10272 : : ENTRY -> A -> B -> C -> EXIT. */
10273 : :
10274 : : static void
10275 : 4 : test_linear_chain ()
10276 : : {
10277 : 4 : gimple_register_cfg_hooks ();
10278 : :
10279 : 4 : tree fndecl = push_fndecl ("cfg_test_linear_chain");
10280 : 4 : function *fun = DECL_STRUCT_FUNCTION (fndecl);
10281 : :
10282 : : /* Create some empty blocks. */
10283 : 4 : basic_block bb_a = create_empty_bb (ENTRY_BLOCK_PTR_FOR_FN (fun));
10284 : 4 : basic_block bb_b = create_empty_bb (bb_a);
10285 : 4 : basic_block bb_c = create_empty_bb (bb_b);
10286 : :
10287 : 4 : ASSERT_EQ (5, n_basic_blocks_for_fn (fun));
10288 : 4 : ASSERT_EQ (0, n_edges_for_fn (fun));
10289 : :
10290 : : /* Create some edges: a simple linear chain of BBs. */
10291 : 4 : make_edge (ENTRY_BLOCK_PTR_FOR_FN (fun), bb_a, EDGE_FALLTHRU);
10292 : 4 : make_edge (bb_a, bb_b, 0);
10293 : 4 : make_edge (bb_b, bb_c, 0);
10294 : 4 : make_edge (bb_c, EXIT_BLOCK_PTR_FOR_FN (fun), 0);
10295 : :
10296 : : /* Verify the edges. */
10297 : 4 : ASSERT_EQ (4, n_edges_for_fn (fun));
10298 : 4 : ASSERT_EQ (NULL, ENTRY_BLOCK_PTR_FOR_FN (fun)->preds);
10299 : 4 : ASSERT_EQ (1, ENTRY_BLOCK_PTR_FOR_FN (fun)->succs->length ());
10300 : 4 : ASSERT_EQ (1, bb_a->preds->length ());
10301 : 4 : ASSERT_EQ (1, bb_a->succs->length ());
10302 : 4 : ASSERT_EQ (1, bb_b->preds->length ());
10303 : 4 : ASSERT_EQ (1, bb_b->succs->length ());
10304 : 4 : ASSERT_EQ (1, bb_c->preds->length ());
10305 : 4 : ASSERT_EQ (1, bb_c->succs->length ());
10306 : 4 : ASSERT_EQ (1, EXIT_BLOCK_PTR_FOR_FN (fun)->preds->length ());
10307 : 4 : ASSERT_EQ (NULL, EXIT_BLOCK_PTR_FOR_FN (fun)->succs);
10308 : :
10309 : : /* Verify the dominance information
10310 : : Each BB in our simple chain should be dominated by the one before
10311 : : it. */
10312 : 4 : calculate_dominance_info (CDI_DOMINATORS);
10313 : 4 : ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_b));
10314 : 4 : ASSERT_EQ (bb_b, get_immediate_dominator (CDI_DOMINATORS, bb_c));
10315 : 4 : auto_vec<basic_block> dom_by_b = get_dominated_by (CDI_DOMINATORS, bb_b);
10316 : 4 : ASSERT_EQ (1, dom_by_b.length ());
10317 : 4 : ASSERT_EQ (bb_c, dom_by_b[0]);
10318 : 4 : free_dominance_info (CDI_DOMINATORS);
10319 : :
10320 : : /* Similarly for post-dominance: each BB in our chain is post-dominated
10321 : : by the one after it. */
10322 : 4 : calculate_dominance_info (CDI_POST_DOMINATORS);
10323 : 4 : ASSERT_EQ (bb_b, get_immediate_dominator (CDI_POST_DOMINATORS, bb_a));
10324 : 4 : ASSERT_EQ (bb_c, get_immediate_dominator (CDI_POST_DOMINATORS, bb_b));
10325 : 4 : auto_vec<basic_block> postdom_by_b = get_dominated_by (CDI_POST_DOMINATORS, bb_b);
10326 : 4 : ASSERT_EQ (1, postdom_by_b.length ());
10327 : 4 : ASSERT_EQ (bb_a, postdom_by_b[0]);
10328 : 4 : free_dominance_info (CDI_POST_DOMINATORS);
10329 : :
10330 : 4 : pop_cfun ();
10331 : 4 : }
10332 : :
10333 : : /* Verify a simple CFG of the form:
10334 : : ENTRY
10335 : : |
10336 : : A
10337 : : / \
10338 : : /t \f
10339 : : B C
10340 : : \ /
10341 : : \ /
10342 : : D
10343 : : |
10344 : : EXIT. */
10345 : :
10346 : : static void
10347 : 4 : test_diamond ()
10348 : : {
10349 : 4 : gimple_register_cfg_hooks ();
10350 : :
10351 : 4 : tree fndecl = push_fndecl ("cfg_test_diamond");
10352 : 4 : function *fun = DECL_STRUCT_FUNCTION (fndecl);
10353 : :
10354 : : /* Create some empty blocks. */
10355 : 4 : basic_block bb_a = create_empty_bb (ENTRY_BLOCK_PTR_FOR_FN (fun));
10356 : 4 : basic_block bb_b = create_empty_bb (bb_a);
10357 : 4 : basic_block bb_c = create_empty_bb (bb_a);
10358 : 4 : basic_block bb_d = create_empty_bb (bb_b);
10359 : :
10360 : 4 : ASSERT_EQ (6, n_basic_blocks_for_fn (fun));
10361 : 4 : ASSERT_EQ (0, n_edges_for_fn (fun));
10362 : :
10363 : : /* Create the edges. */
10364 : 4 : make_edge (ENTRY_BLOCK_PTR_FOR_FN (fun), bb_a, EDGE_FALLTHRU);
10365 : 4 : make_edge (bb_a, bb_b, EDGE_TRUE_VALUE);
10366 : 4 : make_edge (bb_a, bb_c, EDGE_FALSE_VALUE);
10367 : 4 : make_edge (bb_b, bb_d, 0);
10368 : 4 : make_edge (bb_c, bb_d, 0);
10369 : 4 : make_edge (bb_d, EXIT_BLOCK_PTR_FOR_FN (fun), 0);
10370 : :
10371 : : /* Verify the edges. */
10372 : 4 : ASSERT_EQ (6, n_edges_for_fn (fun));
10373 : 4 : ASSERT_EQ (1, bb_a->preds->length ());
10374 : 4 : ASSERT_EQ (2, bb_a->succs->length ());
10375 : 4 : ASSERT_EQ (1, bb_b->preds->length ());
10376 : 4 : ASSERT_EQ (1, bb_b->succs->length ());
10377 : 4 : ASSERT_EQ (1, bb_c->preds->length ());
10378 : 4 : ASSERT_EQ (1, bb_c->succs->length ());
10379 : 4 : ASSERT_EQ (2, bb_d->preds->length ());
10380 : 4 : ASSERT_EQ (1, bb_d->succs->length ());
10381 : :
10382 : : /* Verify the dominance information. */
10383 : 4 : calculate_dominance_info (CDI_DOMINATORS);
10384 : 4 : ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_b));
10385 : 4 : ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_c));
10386 : 4 : ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_d));
10387 : 4 : auto_vec<basic_block> dom_by_a = get_dominated_by (CDI_DOMINATORS, bb_a);
10388 : 4 : ASSERT_EQ (3, dom_by_a.length ()); /* B, C, D, in some order. */
10389 : 4 : dom_by_a.release ();
10390 : 4 : auto_vec<basic_block> dom_by_b = get_dominated_by (CDI_DOMINATORS, bb_b);
10391 : 4 : ASSERT_EQ (0, dom_by_b.length ());
10392 : 4 : dom_by_b.release ();
10393 : 4 : free_dominance_info (CDI_DOMINATORS);
10394 : :
10395 : : /* Similarly for post-dominance. */
10396 : 4 : calculate_dominance_info (CDI_POST_DOMINATORS);
10397 : 4 : ASSERT_EQ (bb_d, get_immediate_dominator (CDI_POST_DOMINATORS, bb_a));
10398 : 4 : ASSERT_EQ (bb_d, get_immediate_dominator (CDI_POST_DOMINATORS, bb_b));
10399 : 4 : ASSERT_EQ (bb_d, get_immediate_dominator (CDI_POST_DOMINATORS, bb_c));
10400 : 4 : auto_vec<basic_block> postdom_by_d = get_dominated_by (CDI_POST_DOMINATORS, bb_d);
10401 : 4 : ASSERT_EQ (3, postdom_by_d.length ()); /* A, B, C in some order. */
10402 : 4 : postdom_by_d.release ();
10403 : 4 : auto_vec<basic_block> postdom_by_b = get_dominated_by (CDI_POST_DOMINATORS, bb_b);
10404 : 4 : ASSERT_EQ (0, postdom_by_b.length ());
10405 : 4 : postdom_by_b.release ();
10406 : 4 : free_dominance_info (CDI_POST_DOMINATORS);
10407 : :
10408 : 4 : pop_cfun ();
10409 : 4 : }
10410 : :
10411 : : /* Verify that we can handle a CFG containing a "complete" aka
10412 : : fully-connected subgraph (where A B C D below all have edges
10413 : : pointing to each other node, also to themselves).
10414 : : e.g.:
10415 : : ENTRY EXIT
10416 : : | ^
10417 : : | /
10418 : : | /
10419 : : | /
10420 : : V/
10421 : : A<--->B
10422 : : ^^ ^^
10423 : : | \ / |
10424 : : | X |
10425 : : | / \ |
10426 : : VV VV
10427 : : C<--->D
10428 : : */
10429 : :
10430 : : static void
10431 : 4 : test_fully_connected ()
10432 : : {
10433 : 4 : gimple_register_cfg_hooks ();
10434 : :
10435 : 4 : tree fndecl = push_fndecl ("cfg_fully_connected");
10436 : 4 : function *fun = DECL_STRUCT_FUNCTION (fndecl);
10437 : :
10438 : 4 : const int n = 4;
10439 : :
10440 : : /* Create some empty blocks. */
10441 : 4 : auto_vec <basic_block> subgraph_nodes;
10442 : 20 : for (int i = 0; i < n; i++)
10443 : 16 : subgraph_nodes.safe_push (create_empty_bb (ENTRY_BLOCK_PTR_FOR_FN (fun)));
10444 : :
10445 : 4 : ASSERT_EQ (n + 2, n_basic_blocks_for_fn (fun));
10446 : 4 : ASSERT_EQ (0, n_edges_for_fn (fun));
10447 : :
10448 : : /* Create the edges. */
10449 : 4 : make_edge (ENTRY_BLOCK_PTR_FOR_FN (fun), subgraph_nodes[0], EDGE_FALLTHRU);
10450 : 4 : make_edge (subgraph_nodes[0], EXIT_BLOCK_PTR_FOR_FN (fun), 0);
10451 : 20 : for (int i = 0; i < n; i++)
10452 : 80 : for (int j = 0; j < n; j++)
10453 : 64 : make_edge (subgraph_nodes[i], subgraph_nodes[j], 0);
10454 : :
10455 : : /* Verify the edges. */
10456 : 4 : ASSERT_EQ (2 + (n * n), n_edges_for_fn (fun));
10457 : : /* The first one is linked to ENTRY/EXIT as well as itself and
10458 : : everything else. */
10459 : 4 : ASSERT_EQ (n + 1, subgraph_nodes[0]->preds->length ());
10460 : 4 : ASSERT_EQ (n + 1, subgraph_nodes[0]->succs->length ());
10461 : : /* The other ones in the subgraph are linked to everything in
10462 : : the subgraph (including themselves). */
10463 : 16 : for (int i = 1; i < n; i++)
10464 : : {
10465 : 12 : ASSERT_EQ (n, subgraph_nodes[i]->preds->length ());
10466 : 12 : ASSERT_EQ (n, subgraph_nodes[i]->succs->length ());
10467 : : }
10468 : :
10469 : : /* Verify the dominance information. */
10470 : 4 : calculate_dominance_info (CDI_DOMINATORS);
10471 : : /* The initial block in the subgraph should be dominated by ENTRY. */
10472 : 4 : ASSERT_EQ (ENTRY_BLOCK_PTR_FOR_FN (fun),
10473 : : get_immediate_dominator (CDI_DOMINATORS,
10474 : : subgraph_nodes[0]));
10475 : : /* Every other block in the subgraph should be dominated by the
10476 : : initial block. */
10477 : 16 : for (int i = 1; i < n; i++)
10478 : 12 : ASSERT_EQ (subgraph_nodes[0],
10479 : : get_immediate_dominator (CDI_DOMINATORS,
10480 : : subgraph_nodes[i]));
10481 : 4 : free_dominance_info (CDI_DOMINATORS);
10482 : :
10483 : : /* Similarly for post-dominance. */
10484 : 4 : calculate_dominance_info (CDI_POST_DOMINATORS);
10485 : : /* The initial block in the subgraph should be postdominated by EXIT. */
10486 : 4 : ASSERT_EQ (EXIT_BLOCK_PTR_FOR_FN (fun),
10487 : : get_immediate_dominator (CDI_POST_DOMINATORS,
10488 : : subgraph_nodes[0]));
10489 : : /* Every other block in the subgraph should be postdominated by the
10490 : : initial block, since that leads to EXIT. */
10491 : 16 : for (int i = 1; i < n; i++)
10492 : 12 : ASSERT_EQ (subgraph_nodes[0],
10493 : : get_immediate_dominator (CDI_POST_DOMINATORS,
10494 : : subgraph_nodes[i]));
10495 : 4 : free_dominance_info (CDI_POST_DOMINATORS);
10496 : :
10497 : 4 : pop_cfun ();
10498 : 4 : }
10499 : :
10500 : : /* Run all of the selftests within this file. */
10501 : :
10502 : : void
10503 : 4 : tree_cfg_cc_tests ()
10504 : : {
10505 : 4 : test_linear_chain ();
10506 : 4 : test_diamond ();
10507 : 4 : test_fully_connected ();
10508 : 4 : }
10509 : :
10510 : : } // namespace selftest
10511 : :
10512 : : /* TODO: test the dominator/postdominator logic with various graphs/nodes:
10513 : : - loop
10514 : : - nested loops
10515 : : - switch statement (a block with many out-edges)
10516 : : - something that jumps to itself
10517 : : - etc */
10518 : :
10519 : : #endif /* CHECKING_P */
|