Line data Source code
1 : /* Miscellaneous SSA utility functions.
2 : Copyright (C) 2001-2026 Free Software Foundation, Inc.
3 :
4 : This file is part of GCC.
5 :
6 : GCC is free software; you can redistribute it and/or modify
7 : it under the terms of the GNU General Public License as published by
8 : the Free Software Foundation; either version 3, or (at your option)
9 : any later version.
10 :
11 : GCC is distributed in the hope that it will be useful,
12 : but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : GNU General Public License for more details.
15 :
16 : You should have received a copy of the GNU General Public License
17 : along with GCC; see the file COPYING3. If not see
18 : <http://www.gnu.org/licenses/>. */
19 :
20 : #include "config.h"
21 : #include "system.h"
22 : #include "coretypes.h"
23 : #include "backend.h"
24 : #include "tree.h"
25 : #include "gimple.h"
26 : #include "cfghooks.h"
27 : #include "tree-pass.h"
28 : #include "ssa.h"
29 : #include "gimple-pretty-print.h"
30 : #include "diagnostic-core.h"
31 : #include "fold-const.h"
32 : #include "stor-layout.h"
33 : #include "gimple-iterator.h"
34 : #include "gimple-fold.h"
35 : #include "gimplify.h"
36 : #include "gimple-walk.h"
37 : #include "tree-ssa-loop-manip.h"
38 : #include "tree-into-ssa.h"
39 : #include "tree-ssa.h"
40 : #include "cfgloop.h"
41 : #include "cfgexpand.h"
42 : #include "tree-cfg.h"
43 : #include "tree-dfa.h"
44 : #include "stringpool.h"
45 : #include "attribs.h"
46 : #include "asan.h"
47 :
48 : /* Pointer map of variable mappings, keyed by edge. */
49 : static hash_map<edge, auto_vec<edge_var_map> > *edge_var_maps;
50 :
51 :
52 : /* Add a mapping with PHI RESULT and PHI DEF associated with edge E. */
53 :
54 : void
55 11967564 : redirect_edge_var_map_add (edge e, tree result, tree def, location_t locus)
56 : {
57 11967564 : edge_var_map new_node;
58 :
59 11967564 : if (edge_var_maps == NULL)
60 71916 : edge_var_maps = new hash_map<edge, auto_vec<edge_var_map> >;
61 :
62 11967564 : auto_vec<edge_var_map> &slot = edge_var_maps->get_or_insert (e);
63 11967564 : new_node.def = def;
64 11967564 : new_node.result = result;
65 11967564 : new_node.locus = locus;
66 :
67 11967564 : slot.safe_push (new_node);
68 11967564 : }
69 :
70 :
71 : /* Clear the var mappings in edge E. */
72 :
73 : void
74 148358692 : redirect_edge_var_map_clear (edge e)
75 : {
76 148358692 : if (!edge_var_maps)
77 : return;
78 :
79 132218147 : auto_vec<edge_var_map> *head = edge_var_maps->get (e);
80 :
81 132218147 : if (head)
82 10800839 : head->release ();
83 : }
84 :
85 :
86 : /* Duplicate the redirected var mappings in OLDE in NEWE.
87 :
88 : This assumes a hash_map can have multiple edges mapping to the same
89 : var_map (many to one mapping), since we don't remove the previous mappings.
90 : */
91 :
92 : void
93 453196 : redirect_edge_var_map_dup (edge newe, edge olde)
94 : {
95 453196 : if (!edge_var_maps)
96 : return;
97 :
98 422008 : auto_vec<edge_var_map> *new_head = &edge_var_maps->get_or_insert (newe);
99 422008 : auto_vec<edge_var_map> *old_head = edge_var_maps->get (olde);
100 422008 : if (!old_head)
101 : return;
102 :
103 8024 : new_head->safe_splice (*old_head);
104 : }
105 :
106 :
107 : /* Return the variable mappings for a given edge. If there is none, return
108 : NULL. */
109 :
110 : vec<edge_var_map> *
111 8276838 : redirect_edge_var_map_vector (edge e)
112 : {
113 : /* Hey, what kind of idiot would... you'd be surprised. */
114 8276838 : if (!edge_var_maps)
115 : return NULL;
116 :
117 8250865 : auto_vec<edge_var_map> *slot = edge_var_maps->get (e);
118 8250865 : if (!slot)
119 : return NULL;
120 :
121 : return slot;
122 : }
123 :
124 : /* Clear the edge variable mappings. */
125 :
126 : void
127 945555645 : redirect_edge_var_map_empty (void)
128 : {
129 945555645 : if (edge_var_maps)
130 252824977 : edge_var_maps->empty ();
131 945555645 : }
132 :
133 :
134 : /* Remove the corresponding arguments from the PHI nodes in E's
135 : destination block and redirect it to DEST. Return redirected edge.
136 : The list of removed arguments is stored in a vector accessed
137 : through edge_var_maps. */
138 :
139 : edge
140 67734767 : ssa_redirect_edge (edge e, basic_block dest)
141 : {
142 67734767 : gphi_iterator gsi;
143 67734767 : gphi *phi;
144 :
145 67734767 : redirect_edge_var_map_clear (e);
146 :
147 : /* Remove the appropriate PHI arguments in E's destination block.
148 : If we are redirecting a copied edge the destination has not
149 : got PHI argument space reserved nor an interesting argument. */
150 67734767 : if (! (e->dest->flags & BB_DUPLICATED))
151 78518737 : for (gsi = gsi_start_phis (e->dest); !gsi_end_p (gsi); gsi_next (&gsi))
152 : {
153 12805224 : tree def;
154 12805224 : location_t locus;
155 :
156 12805224 : phi = gsi.phi ();
157 12805224 : def = gimple_phi_arg_def (phi, e->dest_idx);
158 12805224 : locus = gimple_phi_arg_location (phi, e->dest_idx);
159 :
160 12805224 : if (def == NULL_TREE)
161 1758558 : continue;
162 :
163 11046666 : redirect_edge_var_map_add (e, gimple_phi_result (phi), def, locus);
164 : }
165 :
166 67734767 : e = redirect_edge_succ_nodup (e, dest);
167 :
168 67734767 : return e;
169 : }
170 :
171 :
172 : /* Add PHI arguments queued in PENDING_STMT list on edge E to edge
173 : E->dest. */
174 :
175 : void
176 3432469 : flush_pending_stmts (edge e)
177 : {
178 3432469 : gphi *phi;
179 3432469 : edge_var_map *vm;
180 3432469 : int i;
181 3432469 : gphi_iterator gsi;
182 :
183 3432469 : vec<edge_var_map> *v = redirect_edge_var_map_vector (e);
184 3432469 : if (!v)
185 350825 : return;
186 :
187 3081644 : for (gsi = gsi_start_phis (e->dest), i = 0;
188 8495598 : !gsi_end_p (gsi) && v->iterate (i, &vm);
189 5413954 : gsi_next (&gsi), i++)
190 : {
191 5413954 : tree def;
192 :
193 5413954 : phi = gsi.phi ();
194 5413954 : def = redirect_edge_var_map_def (vm);
195 5413954 : add_phi_arg (phi, def, e, redirect_edge_var_map_location (vm));
196 : }
197 :
198 3081644 : redirect_edge_var_map_clear (e);
199 : }
200 :
201 : /* Replace the LHS of STMT, an assignment, either a GIMPLE_ASSIGN or a
202 : GIMPLE_CALL, with NLHS, in preparation for modifying the RHS to an
203 : expression with a different value.
204 :
205 : This will update any annotations (say debug bind stmts) referring
206 : to the original LHS, so that they use the RHS instead. This is
207 : done even if NLHS and LHS are the same, for it is understood that
208 : the RHS will be modified afterwards, and NLHS will not be assigned
209 : an equivalent value.
210 :
211 : Adjusting any non-annotation uses of the LHS, if needed, is a
212 : responsibility of the caller.
213 :
214 : The effect of this call should be pretty much the same as that of
215 : inserting a copy of STMT before STMT, and then removing the
216 : original stmt, at which time gsi_remove() would have update
217 : annotations, but using this function saves all the inserting,
218 : copying and removing. */
219 :
220 : void
221 51 : gimple_replace_ssa_lhs (gimple *stmt, tree nlhs)
222 : {
223 51 : if (MAY_HAVE_DEBUG_BIND_STMTS)
224 : {
225 0 : tree lhs = gimple_get_lhs (stmt);
226 :
227 0 : gcc_assert (SSA_NAME_DEF_STMT (lhs) == stmt);
228 :
229 0 : insert_debug_temp_for_var_def (NULL, lhs);
230 : }
231 :
232 51 : gimple_set_lhs (stmt, nlhs);
233 51 : }
234 :
235 :
236 : /* Given a tree for an expression for which we might want to emit
237 : locations or values in debug information (generally a variable, but
238 : we might deal with other kinds of trees in the future), return the
239 : tree that should be used as the variable of a DEBUG_BIND STMT or
240 : VAR_LOCATION INSN or NOTE. Return NULL if VAR is not to be tracked. */
241 :
242 : tree
243 378482732 : target_for_debug_bind (tree var)
244 : {
245 378485324 : if (!MAY_HAVE_DEBUG_BIND_STMTS)
246 : return NULL_TREE;
247 :
248 356033029 : if (TREE_CODE (var) == SSA_NAME)
249 : {
250 16777453 : var = SSA_NAME_VAR (var);
251 : if (var == NULL_TREE)
252 : return NULL_TREE;
253 : }
254 :
255 302418109 : if ((!VAR_P (var) || VAR_DECL_IS_VIRTUAL_OPERAND (var))
256 365027148 : && TREE_CODE (var) != PARM_DECL)
257 : return NULL_TREE;
258 :
259 300400046 : if (DECL_HAS_VALUE_EXPR_P (var))
260 2592 : return target_for_debug_bind (DECL_VALUE_EXPR (var));
261 :
262 300397454 : if (DECL_IGNORED_P (var))
263 : return NULL_TREE;
264 :
265 : /* var-tracking only tracks registers. */
266 277432180 : if (!is_gimple_reg_type (TREE_TYPE (var)))
267 9386580 : return NULL_TREE;
268 :
269 : return var;
270 : }
271 :
272 : /* Called via walk_tree, look for SSA_NAMEs that have already been
273 : released. */
274 :
275 : tree
276 10318957 : find_released_ssa_name (tree *tp, int *walk_subtrees, void *data_)
277 : {
278 10318957 : struct walk_stmt_info *wi = (struct walk_stmt_info *) data_;
279 :
280 10318957 : if (wi && wi->is_lhs)
281 : return NULL_TREE;
282 :
283 10274534 : if (TREE_CODE (*tp) == SSA_NAME)
284 : {
285 1664837 : if (SSA_NAME_IN_FREE_LIST (*tp))
286 : return *tp;
287 :
288 1646068 : *walk_subtrees = 0;
289 : }
290 8609697 : else if (IS_TYPE_OR_DECL_P (*tp))
291 38926 : *walk_subtrees = 0;
292 :
293 : return NULL_TREE;
294 : }
295 :
296 : /* Insert a DEBUG BIND stmt before the DEF of VAR if VAR is referenced
297 : by other DEBUG stmts, and replace uses of the DEF with the
298 : newly-created debug temp. */
299 :
300 : void
301 92703513 : insert_debug_temp_for_var_def (gimple_stmt_iterator *gsi, tree var)
302 : {
303 92703513 : imm_use_iterator imm_iter;
304 92703513 : use_operand_p use_p;
305 92703513 : gimple *stmt;
306 92703513 : gimple *def_stmt = NULL;
307 92703513 : int usecount = 0;
308 92703513 : tree value = NULL;
309 :
310 92703513 : if (!MAY_HAVE_DEBUG_BIND_STMTS)
311 89200120 : return;
312 :
313 : /* If this name has already been registered for replacement, do nothing
314 : as anything that uses this name isn't in SSA form. */
315 92703513 : if (name_registered_for_update_p (var))
316 : return;
317 :
318 : /* Check whether there are debug stmts that reference this variable and,
319 : if there are, decide whether we should use a debug temp. */
320 102603408 : FOR_EACH_IMM_USE_FAST (use_p, imm_iter, var)
321 : {
322 11561024 : stmt = USE_STMT (use_p);
323 :
324 11561024 : if (!gimple_debug_bind_p (stmt))
325 7576150 : continue;
326 :
327 3984874 : if (usecount++)
328 : break;
329 :
330 3503393 : if (gimple_debug_bind_get_value (stmt) != var)
331 : {
332 : /* Count this as an additional use, so as to make sure we
333 : use a temp unless VAR's definition has a SINGLE_RHS that
334 : can be shared. */
335 724206 : usecount++;
336 724206 : break;
337 : }
338 92248071 : }
339 :
340 92248071 : if (!usecount)
341 : return;
342 :
343 3503393 : if (gsi)
344 3053507 : def_stmt = gsi_stmt (*gsi);
345 : else
346 449886 : def_stmt = SSA_NAME_DEF_STMT (var);
347 :
348 : /* If we didn't get an insertion point, and the stmt has already
349 : been removed, we won't be able to insert the debug bind stmt, so
350 : we'll have to drop debug information. */
351 3503393 : if (gimple_code (def_stmt) == GIMPLE_PHI)
352 : {
353 176246 : value = degenerate_phi_result (as_a <gphi *> (def_stmt));
354 176246 : if (value && walk_tree (&value, find_released_ssa_name, NULL, NULL))
355 78 : value = NULL;
356 : /* error_mark_node is what fixup_noreturn_call changes PHI arguments
357 : to. */
358 176168 : else if (value == error_mark_node)
359 0 : value = NULL;
360 : }
361 3327147 : else if (gimple_clobber_p (def_stmt))
362 : /* We can end up here when rewriting a decl into SSA and coming
363 : along a clobber for the original decl. Turn that into
364 : # DEBUG decl => NULL */
365 1295809 : value = NULL;
366 2031338 : else if (is_gimple_assign (def_stmt))
367 : {
368 1941797 : bool no_value = false;
369 :
370 1941797 : if (!dom_info_available_p (CDI_DOMINATORS))
371 : {
372 63114 : struct walk_stmt_info wi;
373 :
374 63114 : memset (&wi, 0, sizeof (wi));
375 :
376 : /* When removing blocks without following reverse dominance
377 : order, we may sometimes encounter SSA_NAMEs that have
378 : already been released, referenced in other SSA_DEFs that
379 : we're about to release. Consider:
380 :
381 : <bb X>:
382 : v_1 = foo;
383 :
384 : <bb Y>:
385 : w_2 = v_1 + bar;
386 : # DEBUG w => w_2
387 :
388 : If we deleted BB X first, propagating the value of w_2
389 : won't do us any good. It's too late to recover their
390 : original definition of v_1: when it was deleted, it was
391 : only referenced in other DEFs, it couldn't possibly know
392 : it should have been retained, and propagating every
393 : single DEF just in case it might have to be propagated
394 : into a DEBUG STMT would probably be too wasteful.
395 :
396 : When dominator information is not readily available, we
397 : check for and accept some loss of debug information. But
398 : if it is available, there's no excuse for us to remove
399 : blocks in the wrong order, so we don't even check for
400 : dead SSA NAMEs. SSA verification shall catch any
401 : errors. */
402 63087 : if ((!gsi && !gimple_bb (def_stmt))
403 126201 : || walk_gimple_op (def_stmt, find_released_ssa_name, &wi))
404 18691 : no_value = true;
405 : }
406 :
407 63114 : if (!no_value)
408 1923106 : value = gimple_assign_rhs_to_tree (def_stmt);
409 : }
410 :
411 3503393 : if (value)
412 : {
413 : /* If there's a single use of VAR, and VAR is the entire debug
414 : expression (usecount would have been incremented again
415 : otherwise), then we can propagate VALUE into this single use,
416 : avoiding the temp.
417 :
418 : We can also avoid using a temp if VALUE can be shared and
419 : propagated into all uses, without generating expressions that
420 : wouldn't be valid gimple RHSs.
421 :
422 : Other cases that would require unsharing or non-gimple RHSs
423 : are deferred to a debug temp, although we could avoid temps
424 : at the expense of duplication of expressions. */
425 :
426 1951867 : if (usecount == 1
427 1083778 : || gimple_code (def_stmt) == GIMPLE_PHI
428 1074389 : || CONSTANT_CLASS_P (value)
429 3023635 : || is_gimple_reg (value))
430 : ;
431 : else
432 : {
433 1069807 : gdebug *def_temp;
434 1069807 : tree vexpr = build_debug_expr_decl (TREE_TYPE (value));
435 :
436 1069807 : def_temp = gimple_build_debug_bind (vexpr,
437 : unshare_expr (value),
438 : def_stmt);
439 :
440 : /* FIXME: Is setting the mode really necessary? */
441 1069807 : if (DECL_P (value))
442 2845 : SET_DECL_MODE (vexpr, DECL_MODE (value));
443 : else
444 1066962 : SET_DECL_MODE (vexpr, TYPE_MODE (TREE_TYPE (value)));
445 :
446 1069807 : if (gsi)
447 844693 : gsi_insert_before (gsi, def_temp, GSI_SAME_STMT);
448 : else
449 : {
450 225114 : gimple_stmt_iterator ngsi = gsi_for_stmt (def_stmt);
451 225114 : gsi_insert_before (&ngsi, def_temp, GSI_SAME_STMT);
452 : }
453 :
454 1069807 : value = vexpr;
455 : }
456 : }
457 :
458 10031108 : FOR_EACH_IMM_USE_STMT (stmt, imm_iter, var)
459 : {
460 6527715 : if (!gimple_debug_bind_p (stmt))
461 872326 : continue;
462 :
463 5655389 : if (value)
464 : {
465 7881102 : FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
466 3940551 : SET_USE (use_p, unshare_expr (value));
467 : /* If we didn't replace uses with a debug decl fold the
468 : resulting expression. Otherwise we end up with invalid IL. */
469 3939200 : if (TREE_CODE (value) != DEBUG_EXPR_DECL)
470 : {
471 908720 : gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
472 908720 : fold_stmt_inplace (&gsi);
473 : }
474 : }
475 : else
476 1716189 : gimple_debug_bind_reset_value (stmt);
477 :
478 5655389 : update_stmt (stmt);
479 3503393 : }
480 : }
481 :
482 :
483 : /* Insert a DEBUG BIND stmt before STMT for each DEF referenced by
484 : other DEBUG stmts, and replace uses of the DEF with the
485 : newly-created debug temp. */
486 :
487 : void
488 172604670 : insert_debug_temps_for_defs (gimple_stmt_iterator *gsi)
489 : {
490 172604670 : gimple *stmt;
491 172604670 : ssa_op_iter op_iter;
492 172604670 : def_operand_p def_p;
493 :
494 172604670 : if (!MAY_HAVE_DEBUG_BIND_STMTS)
495 47040752 : return;
496 :
497 125563918 : stmt = gsi_stmt (*gsi);
498 :
499 287287942 : FOR_EACH_PHI_OR_STMT_DEF (def_p, stmt, op_iter, SSA_OP_DEF)
500 : {
501 36160106 : tree var = DEF_FROM_PTR (def_p);
502 :
503 36160106 : if (TREE_CODE (var) != SSA_NAME)
504 149575 : continue;
505 :
506 36010531 : insert_debug_temp_for_var_def (gsi, var);
507 : }
508 : }
509 :
510 : /* Reset all debug stmts that use SSA_NAME(s) defined in STMT. */
511 :
512 : void
513 8616 : reset_debug_uses (gimple *stmt)
514 : {
515 8616 : ssa_op_iter op_iter;
516 8616 : def_operand_p def_p;
517 8616 : imm_use_iterator imm_iter;
518 8616 : gimple *use_stmt;
519 :
520 8616 : if (!MAY_HAVE_DEBUG_BIND_STMTS)
521 259 : return;
522 :
523 22461 : FOR_EACH_PHI_OR_STMT_DEF (def_p, stmt, op_iter, SSA_OP_DEF)
524 : {
525 5747 : tree var = DEF_FROM_PTR (def_p);
526 :
527 5747 : if (TREE_CODE (var) != SSA_NAME)
528 0 : continue;
529 :
530 12960 : FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, var)
531 : {
532 7213 : if (!gimple_debug_bind_p (use_stmt))
533 7128 : continue;
534 :
535 85 : gimple_debug_bind_reset_value (use_stmt);
536 85 : update_stmt (use_stmt);
537 5747 : }
538 : }
539 : }
540 :
541 : /* Delete SSA DEFs for SSA versions in the TOREMOVE bitmap, removing
542 : dominated stmts before their dominators, so that release_ssa_defs
543 : stands a chance of propagating DEFs into debug bind stmts. */
544 :
545 : void
546 251559 : release_defs_bitset (bitmap toremove)
547 : {
548 251559 : unsigned j;
549 251559 : bitmap_iterator bi;
550 :
551 : /* Performing a topological sort is probably overkill, this will
552 : most likely run in slightly superlinear time, rather than the
553 : pathological quadratic worst case.
554 : But iterate from max SSA name version to min one because
555 : that mimics allocation order during code generation behavior best.
556 : Use an array for this which we compact on-the-fly with a NULL
557 : marker moving towards the end of the vector. */
558 251559 : auto_vec<tree, 16> names;
559 251559 : names.reserve (bitmap_count_bits (toremove) + 1);
560 251559 : names.quick_push (NULL_TREE);
561 2795499 : EXECUTE_IF_SET_IN_BITMAP (toremove, 0, j, bi)
562 2543940 : names.quick_push (ssa_name (j));
563 :
564 251559 : bitmap_tree_view (toremove);
565 774518 : while (!bitmap_empty_p (toremove))
566 : {
567 271400 : j = names.length () - 1;
568 3612687 : for (unsigned i = names.length () - 1; names[i];)
569 : {
570 3341287 : bool remove_now = true;
571 3341287 : tree var = names[i];
572 3341287 : gimple *stmt;
573 3341287 : imm_use_iterator uit;
574 :
575 4030604 : FOR_EACH_IMM_USE_STMT (stmt, uit, var)
576 : {
577 1486664 : ssa_op_iter dit;
578 1486664 : def_operand_p def_p;
579 :
580 : /* We can't propagate PHI nodes into debug stmts. */
581 1486664 : if (gimple_code (stmt) == GIMPLE_PHI
582 1486664 : || is_gimple_debug (stmt))
583 689317 : continue;
584 :
585 : /* If we find another definition to remove that uses
586 : the one we're looking at, defer the removal of this
587 : one, so that it can be propagated into debug stmts
588 : after the other is. */
589 797347 : FOR_EACH_SSA_DEF_OPERAND (def_p, stmt, dit, SSA_OP_DEF)
590 : {
591 797347 : tree odef = DEF_FROM_PTR (def_p);
592 :
593 797347 : if (bitmap_bit_p (toremove, SSA_NAME_VERSION (odef)))
594 : {
595 : remove_now = false;
596 : break;
597 : }
598 : }
599 :
600 797347 : if (!remove_now)
601 : break;
602 3341287 : }
603 :
604 3341287 : if (remove_now)
605 : {
606 2543940 : gimple *def = SSA_NAME_DEF_STMT (var);
607 2543940 : gimple_stmt_iterator gsi = gsi_for_stmt (def);
608 :
609 2543940 : if (gimple_code (def) == GIMPLE_PHI)
610 650289 : remove_phi_node (&gsi, true);
611 : else
612 : {
613 1893651 : gsi_remove (&gsi, true);
614 1893651 : release_defs (def);
615 : }
616 2543940 : bitmap_clear_bit (toremove, SSA_NAME_VERSION (var));
617 : }
618 : else
619 797347 : --i;
620 3341287 : if (--j != i)
621 3146458 : names[i] = names[j];
622 : }
623 : }
624 251559 : bitmap_list_view (toremove);
625 251559 : }
626 :
627 : /* Disable warnings about missing quoting in GCC diagnostics for
628 : the verification errors. Their format strings don't follow GCC
629 : diagnostic conventions and the calls are ultimately followed by
630 : one to internal_error. */
631 : #if __GNUC__ >= 10
632 : # pragma GCC diagnostic push
633 : # pragma GCC diagnostic ignored "-Wformat-diag"
634 : #endif
635 :
636 : /* Verify virtual SSA form. */
637 :
638 : bool
639 230235637 : verify_vssa (basic_block bb_start, tree current_vdef, sbitmap visited)
640 : {
641 230235637 : bool err = false;
642 :
643 230235637 : struct state_t {
644 : basic_block bb;
645 : tree vdef;
646 : } state;
647 :
648 230235637 : auto_vec<state_t, 3> worklist;
649 230235637 : state.bb = bb_start;
650 230235637 : state.vdef = current_vdef;
651 230235637 : worklist.safe_push (state);
652 :
653 2915717940 : while (!worklist.is_empty ())
654 : {
655 2455246666 : const auto &state = worklist.pop ();
656 2455246666 : const auto &bb = state.bb;
657 2455246666 : current_vdef = state.vdef;
658 :
659 2455246666 : if (!bitmap_set_bit (visited, bb->index))
660 114743306 : continue;
661 :
662 : /* Pick up the single virtual PHI def. */
663 2340503360 : gphi *phi = NULL;
664 3015759721 : for (gphi_iterator si = gsi_start_phis (bb); !gsi_end_p (si);
665 675256361 : gsi_next (&si))
666 : {
667 675256361 : tree res = gimple_phi_result (si.phi ());
668 1665695615 : if (virtual_operand_p (res))
669 : {
670 315182893 : if (phi)
671 : {
672 0 : error ("multiple virtual PHI nodes in BB %d", bb->index);
673 0 : print_gimple_stmt (stderr, phi, 0);
674 0 : print_gimple_stmt (stderr, si.phi (), 0);
675 0 : err = true;
676 : }
677 : else
678 : phi = si.phi ();
679 : }
680 : }
681 2340503360 : if (phi)
682 : {
683 315182893 : current_vdef = gimple_phi_result (phi);
684 315182893 : if (TREE_CODE (current_vdef) != SSA_NAME)
685 : {
686 0 : error ("virtual definition is not an SSA name");
687 0 : print_gimple_stmt (stderr, phi, 0);
688 0 : err = true;
689 : }
690 : }
691 :
692 : /* Verify stmts. */
693 17730414287 : for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
694 13049407567 : gsi_next (&gsi))
695 : {
696 13049407567 : gimple *stmt = gsi_stmt (gsi);
697 18507894381 : tree vuse = gimple_vuse (stmt);
698 5393337859 : if (vuse)
699 : {
700 3601580016 : if (vuse != current_vdef)
701 : {
702 0 : error ("stmt with wrong VUSE");
703 0 : print_gimple_stmt (stderr, stmt, 0, TDF_VOPS);
704 0 : fprintf (stderr, "expected ");
705 0 : print_generic_expr (stderr, current_vdef);
706 0 : fprintf (stderr, "\n");
707 0 : err = true;
708 : }
709 16650987583 : tree vdef = gimple_vdef (stmt);
710 3601580016 : if (vdef)
711 : {
712 2257528412 : current_vdef = vdef;
713 2257528412 : if (TREE_CODE (current_vdef) != SSA_NAME)
714 : {
715 0 : error ("virtual definition is not an SSA name");
716 0 : print_gimple_stmt (stderr, phi, 0);
717 0 : err = true;
718 : }
719 : }
720 : }
721 : }
722 :
723 : /* Verify destination PHI uses and add successors to worklist. */
724 2340503360 : edge_iterator ei;
725 2340503360 : edge e;
726 5178701330 : FOR_EACH_EDGE (e, ei, bb->succs)
727 : {
728 2838197970 : gphi *phi = get_virtual_phi (e->dest);
729 2838197970 : if (phi
730 2838197970 : && PHI_ARG_DEF_FROM_EDGE (phi, e) != current_vdef)
731 : {
732 0 : error ("PHI node with wrong VUSE on edge from BB %d",
733 0 : e->src->index);
734 0 : print_gimple_stmt (stderr, phi, 0, TDF_VOPS);
735 0 : fprintf (stderr, "expected ");
736 0 : print_generic_expr (stderr, current_vdef);
737 0 : fprintf (stderr, "\n");
738 0 : err = true;
739 : }
740 :
741 : /* Add successor BB along with current vdef to worklist. */
742 2838197970 : if (!bitmap_bit_p (visited, e->dest->index))
743 : {
744 2225011029 : state_t new_state;
745 2225011029 : new_state.bb = e->dest;
746 2225011029 : new_state.vdef = current_vdef;
747 :
748 2225011029 : worklist.safe_push (new_state);
749 : }
750 : }
751 : }
752 230235637 : return err;
753 230235637 : }
754 :
755 : /* Return true if SSA_NAME is malformed and mark it visited.
756 :
757 : IS_VIRTUAL is true if this SSA_NAME was found inside a virtual
758 : operand. */
759 :
760 : static bool
761 14174647942 : verify_ssa_name (tree ssa_name, bool is_virtual)
762 : {
763 14174647942 : if (TREE_CODE (ssa_name) != SSA_NAME)
764 : {
765 0 : error ("expected an SSA_NAME object");
766 0 : return true;
767 : }
768 :
769 14174647942 : if (SSA_NAME_IN_FREE_LIST (ssa_name))
770 : {
771 0 : error ("found an SSA_NAME that had been released into the free pool");
772 0 : return true;
773 : }
774 :
775 14174647942 : if (SSA_NAME_VAR (ssa_name) != NULL_TREE
776 8463595777 : && TREE_TYPE (ssa_name) != TREE_TYPE (SSA_NAME_VAR (ssa_name)))
777 : {
778 0 : error ("type mismatch between an SSA_NAME and its symbol");
779 0 : return true;
780 : }
781 :
782 14174647942 : if (is_virtual && !virtual_operand_p (ssa_name))
783 : {
784 0 : error ("found a virtual definition for a GIMPLE register");
785 0 : return true;
786 : }
787 :
788 14174647942 : if (is_virtual && SSA_NAME_VAR (ssa_name) != gimple_vop (cfun))
789 : {
790 0 : error ("virtual SSA name for non-VOP decl");
791 0 : return true;
792 : }
793 :
794 14174647942 : if (!is_virtual && virtual_operand_p (ssa_name))
795 : {
796 0 : error ("found a real definition for a non-register");
797 0 : return true;
798 : }
799 :
800 14174647942 : if (SSA_NAME_IS_DEFAULT_DEF (ssa_name)
801 14174647942 : && !gimple_nop_p (SSA_NAME_DEF_STMT (ssa_name)))
802 : {
803 0 : error ("found a default name with a non-empty defining statement");
804 0 : return true;
805 : }
806 :
807 : return false;
808 : }
809 :
810 :
811 : /* Return true if the definition of SSA_NAME at block BB is malformed.
812 :
813 : STMT is the statement where SSA_NAME is created.
814 :
815 : DEFINITION_BLOCK is an array of basic blocks indexed by SSA_NAME
816 : version numbers. If DEFINITION_BLOCK[SSA_NAME_VERSION] is set,
817 : it means that the block in that array slot contains the
818 : definition of SSA_NAME.
819 :
820 : IS_VIRTUAL is true if SSA_NAME is created by a VDEF. */
821 :
822 : static bool
823 6034396044 : verify_def (basic_block bb, basic_block *definition_block, tree ssa_name,
824 : gimple *stmt, bool is_virtual)
825 : {
826 6034396044 : if (verify_ssa_name (ssa_name, is_virtual))
827 0 : goto err;
828 :
829 6034396044 : if (SSA_NAME_VAR (ssa_name)
830 3310130381 : && TREE_CODE (SSA_NAME_VAR (ssa_name)) == RESULT_DECL
831 0 : && DECL_BY_REFERENCE (SSA_NAME_VAR (ssa_name)))
832 : {
833 0 : error ("RESULT_DECL should be read only when DECL_BY_REFERENCE is set");
834 0 : goto err;
835 : }
836 :
837 6034396044 : if (definition_block[SSA_NAME_VERSION (ssa_name)])
838 : {
839 0 : error ("SSA_NAME created in two different blocks %i and %i",
840 0 : definition_block[SSA_NAME_VERSION (ssa_name)]->index, bb->index);
841 0 : goto err;
842 : }
843 :
844 6034396044 : definition_block[SSA_NAME_VERSION (ssa_name)] = bb;
845 :
846 6034396044 : if (SSA_NAME_DEF_STMT (ssa_name) != stmt)
847 : {
848 0 : error ("SSA_NAME_DEF_STMT is wrong");
849 0 : fprintf (stderr, "Expected definition statement:\n");
850 0 : print_gimple_stmt (stderr, SSA_NAME_DEF_STMT (ssa_name), 4, TDF_VOPS);
851 0 : fprintf (stderr, "\nActual definition statement:\n");
852 0 : print_gimple_stmt (stderr, stmt, 4, TDF_VOPS);
853 0 : goto err;
854 : }
855 :
856 : return false;
857 :
858 0 : err:
859 0 : fprintf (stderr, "while verifying SSA_NAME ");
860 0 : print_generic_expr (stderr, ssa_name);
861 0 : fprintf (stderr, " in statement\n");
862 0 : print_gimple_stmt (stderr, stmt, 4, TDF_VOPS);
863 :
864 0 : return true;
865 : }
866 :
867 :
868 : /* Return true if the use of SSA_NAME at statement STMT in block BB is
869 : malformed.
870 :
871 : DEF_BB is the block where SSA_NAME was found to be created.
872 :
873 : IDOM contains immediate dominator information for the flowgraph.
874 :
875 : CHECK_ABNORMAL is true if the caller wants to check whether this use
876 : is flowing through an abnormal edge (only used when checking PHI
877 : arguments).
878 :
879 : If NAMES_DEFINED_IN_BB is not NULL, it contains a bitmap of ssa names
880 : that are defined before STMT in basic block BB. */
881 :
882 : static bool
883 11509131381 : verify_use (basic_block bb, basic_block def_bb, use_operand_p use_p,
884 : gimple *stmt, bool check_abnormal, bitmap names_defined_in_bb)
885 : {
886 11509131381 : bool err = false;
887 11509131381 : tree ssa_name = USE_FROM_PTR (use_p);
888 :
889 11509131381 : if (!TREE_VISITED (ssa_name))
890 6427864885 : if (verify_imm_links (stderr, ssa_name))
891 11509131381 : err = true;
892 :
893 11509131381 : TREE_VISITED (ssa_name) = 1;
894 :
895 11509131381 : if (gimple_nop_p (SSA_NAME_DEF_STMT (ssa_name))
896 11509131381 : && SSA_NAME_IS_DEFAULT_DEF (ssa_name))
897 : ; /* Default definitions have empty statements. Nothing to do. */
898 9894720566 : else if (!def_bb)
899 : {
900 0 : error ("missing definition");
901 0 : err = true;
902 : }
903 9894720566 : else if (bb != def_bb
904 9894720566 : && !dominated_by_p (CDI_DOMINATORS, bb, def_bb))
905 : {
906 0 : error ("definition in block %i does not dominate use in block %i",
907 : def_bb->index, bb->index);
908 0 : err = true;
909 : }
910 9894720566 : else if (bb == def_bb
911 9894720566 : && names_defined_in_bb != NULL
912 15824349419 : && !bitmap_bit_p (names_defined_in_bb, SSA_NAME_VERSION (ssa_name)))
913 : {
914 0 : error ("definition in block %i follows the use", def_bb->index);
915 0 : err = true;
916 : }
917 :
918 11509131381 : if (check_abnormal
919 11516932389 : && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name))
920 : {
921 0 : error ("SSA_NAME_OCCURS_IN_ABNORMAL_PHI should be set");
922 0 : err = true;
923 : }
924 :
925 : /* Make sure the use is in an appropriate list by checking the previous
926 : element to make sure it's the same. */
927 11509131381 : if (use_p->prev == NULL)
928 : {
929 0 : error ("no immediate_use list");
930 0 : err = true;
931 : }
932 : else
933 : {
934 11509131381 : tree listvar;
935 11509131381 : if (use_p->prev->use == NULL)
936 6427864885 : listvar = use_p->prev->loc.ssa_name;
937 : else
938 5081266496 : listvar = USE_FROM_PTR (use_p->prev);
939 11509131381 : if (listvar != ssa_name)
940 : {
941 0 : error ("wrong immediate use list");
942 0 : err = true;
943 : }
944 : }
945 :
946 11509131381 : if (err)
947 : {
948 0 : fprintf (stderr, "for SSA_NAME: ");
949 0 : print_generic_expr (stderr, ssa_name, TDF_VOPS);
950 0 : fprintf (stderr, " in statement:\n");
951 0 : print_gimple_stmt (stderr, stmt, 0, TDF_VOPS);
952 : }
953 :
954 11509131381 : return err;
955 : }
956 :
957 :
958 : /* Return true if any of the arguments for PHI node PHI at block BB is
959 : malformed.
960 :
961 : DEFINITION_BLOCK is an array of basic blocks indexed by SSA_NAME
962 : version numbers. If DEFINITION_BLOCK[SSA_NAME_VERSION] is set,
963 : it means that the block in that array slot contains the
964 : definition of SSA_NAME. */
965 :
966 : static bool
967 675268055 : verify_phi_args (gphi *phi, basic_block bb, basic_block *definition_block)
968 : {
969 675268055 : edge e;
970 675268055 : bool err = false;
971 675268055 : size_t i, phi_num_args = gimple_phi_num_args (phi);
972 :
973 1350536110 : if (EDGE_COUNT (bb->preds) != phi_num_args)
974 : {
975 0 : error ("incoming edge count does not match number of PHI arguments");
976 0 : err = true;
977 0 : goto error;
978 : }
979 :
980 2385336406 : for (i = 0; i < phi_num_args; i++)
981 : {
982 1710068351 : use_operand_p op_p = gimple_phi_arg_imm_use_ptr (phi, i);
983 1710068351 : tree op = USE_FROM_PTR (op_p);
984 :
985 1710068351 : e = EDGE_PRED (bb, i);
986 :
987 1710068351 : if (op == NULL_TREE)
988 : {
989 0 : error ("PHI argument is missing for edge %d->%d",
990 0 : e->src->index,
991 0 : e->dest->index);
992 0 : err = true;
993 0 : goto error;
994 : }
995 :
996 1710068351 : if (TREE_CODE (op) != SSA_NAME && !is_gimple_min_invariant (op))
997 : {
998 0 : error ("PHI argument is not SSA_NAME, or invariant");
999 0 : err = true;
1000 : }
1001 :
1002 1710068351 : if ((e->flags & EDGE_ABNORMAL) && TREE_CODE (op) != SSA_NAME)
1003 : {
1004 0 : error ("PHI argument on abnormal edge is not SSA_NAME");
1005 0 : err = true;
1006 : }
1007 :
1008 1710068351 : if (TREE_CODE (op) == SSA_NAME)
1009 : {
1010 2948881860 : err = verify_ssa_name (op, virtual_operand_p (gimple_phi_result (phi)));
1011 1474440930 : err |= verify_use (e->src, definition_block[SSA_NAME_VERSION (op)],
1012 1474440930 : op_p, phi, e->flags & EDGE_ABNORMAL, NULL);
1013 : }
1014 :
1015 1710068351 : if (TREE_CODE (op) == ADDR_EXPR)
1016 : {
1017 11908924 : tree base = TREE_OPERAND (op, 0);
1018 15903167 : while (handled_component_p (base))
1019 3994243 : base = TREE_OPERAND (base, 0);
1020 11908924 : if ((VAR_P (base)
1021 : || TREE_CODE (base) == PARM_DECL
1022 : || TREE_CODE (base) == RESULT_DECL)
1023 5485934 : && !TREE_ADDRESSABLE (base))
1024 : {
1025 0 : error ("address taken, but ADDRESSABLE bit not set");
1026 0 : err = true;
1027 : }
1028 : }
1029 :
1030 1710068351 : if (e->dest != bb)
1031 : {
1032 0 : error ("wrong edge %d->%d for PHI argument",
1033 0 : e->src->index, e->dest->index);
1034 0 : err = true;
1035 : }
1036 :
1037 1710068351 : if (err)
1038 : {
1039 0 : fprintf (stderr, "PHI argument\n");
1040 0 : print_generic_stmt (stderr, op, TDF_VOPS);
1041 0 : goto error;
1042 : }
1043 : }
1044 :
1045 675268055 : error:
1046 675268055 : if (err)
1047 : {
1048 0 : fprintf (stderr, "for PHI node\n");
1049 0 : print_gimple_stmt (stderr, phi, 0, TDF_VOPS|TDF_MEMSYMS);
1050 : }
1051 :
1052 :
1053 675268055 : return err;
1054 : }
1055 :
1056 :
1057 : /* Verify common invariants in the SSA web.
1058 : TODO: verify the variable annotations. */
1059 :
1060 : DEBUG_FUNCTION void
1061 230342055 : verify_ssa (bool check_modified_stmt, bool check_ssa_operands)
1062 : {
1063 230342055 : basic_block bb;
1064 460684110 : basic_block *definition_block = XCNEWVEC (basic_block, num_ssa_names);
1065 230342055 : ssa_op_iter iter;
1066 230342055 : tree op;
1067 230342055 : enum dom_state orig_dom_state = dom_info_state (CDI_DOMINATORS);
1068 230342055 : auto_bitmap names_defined_in_bb;
1069 :
1070 230342055 : gcc_assert (!need_ssa_update_p (cfun));
1071 :
1072 230342055 : timevar_push (TV_TREE_SSA_VERIFY);
1073 :
1074 230342055 : {
1075 : /* Keep track of SSA names present in the IL. */
1076 230342055 : size_t i;
1077 230342055 : tree name;
1078 230342055 : hash_map <const void *, tree> ssa_info;
1079 :
1080 9068489221 : FOR_EACH_SSA_NAME (i, name, cfun)
1081 : {
1082 6665810968 : gimple *stmt;
1083 6665810968 : TREE_VISITED (name) = 0;
1084 :
1085 13331621936 : verify_ssa_name (name, virtual_operand_p (name));
1086 :
1087 6665810968 : stmt = SSA_NAME_DEF_STMT (name);
1088 6665810968 : if (!gimple_nop_p (stmt))
1089 : {
1090 6034396044 : basic_block bb = gimple_bb (stmt);
1091 6034396044 : if (verify_def (bb, definition_block,
1092 : name, stmt, virtual_operand_p (name)))
1093 0 : goto err;
1094 : }
1095 :
1096 6665810968 : const pt_solution *pt_info = ssa_name_pt_solution (name);
1097 839232139 : if (pt_info)
1098 : {
1099 774680660 : bool existed;
1100 774680660 : tree &val = ssa_info.get_or_insert (pt_info, &existed);
1101 774680660 : if (existed)
1102 : {
1103 0 : error ("shared SSA name pt_solution info");
1104 0 : print_generic_expr (stderr, val);
1105 0 : fprintf (stderr, " and ");
1106 0 : print_generic_expr (stderr, name);
1107 0 : fprintf (stderr, "\n");
1108 0 : goto err;
1109 : }
1110 : else
1111 774680660 : val = name;
1112 : }
1113 6665810968 : const void *info = SSA_NAME_RANGE_INFO (name);
1114 6665810968 : if (info)
1115 : {
1116 1487819529 : bool existed;
1117 1487819529 : tree &val = ssa_info.get_or_insert (info, &existed);
1118 1487819529 : if (existed)
1119 : {
1120 0 : error ("shared SSA name info");
1121 0 : print_generic_expr (stderr, val);
1122 0 : fprintf (stderr, " and ");
1123 0 : print_generic_expr (stderr, name);
1124 0 : fprintf (stderr, "\n");
1125 0 : goto err;
1126 : }
1127 : else
1128 1487819529 : val = name;
1129 : }
1130 : }
1131 0 : }
1132 :
1133 230342055 : calculate_dominance_info (CDI_DOMINATORS);
1134 :
1135 : /* Now verify all the uses and make sure they agree with the definitions
1136 : found in the previous pass. */
1137 2114887495 : FOR_EACH_BB_FN (bb, cfun)
1138 : {
1139 1884545440 : edge e;
1140 1884545440 : edge_iterator ei;
1141 :
1142 : /* Make sure that all edges have a clear 'aux' field. */
1143 4496862498 : FOR_EACH_EDGE (e, ei, bb->preds)
1144 : {
1145 2612317058 : if (e->aux)
1146 : {
1147 0 : error ("AUX pointer initialized for edge %d->%d", e->src->index,
1148 0 : e->dest->index);
1149 0 : goto err;
1150 : }
1151 : }
1152 :
1153 : /* Verify the arguments for every PHI node in the block. */
1154 2559813495 : for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1155 : {
1156 675268055 : gphi *phi = gsi.phi ();
1157 675268055 : if (verify_phi_args (phi, bb, definition_block))
1158 0 : goto err;
1159 :
1160 675268055 : bitmap_set_bit (names_defined_in_bb,
1161 675268055 : SSA_NAME_VERSION (gimple_phi_result (phi)));
1162 : }
1163 :
1164 : /* Now verify all the uses and vuses in every statement of the block. */
1165 16818652384 : for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
1166 13049561504 : gsi_next (&gsi))
1167 : {
1168 13049561504 : gimple *stmt = gsi_stmt (gsi);
1169 13049561504 : use_operand_p use_p;
1170 :
1171 26024830174 : if (check_modified_stmt && gimple_modified_p (stmt))
1172 : {
1173 0 : error ("stmt (%p) marked modified after optimization pass: ",
1174 : (void *)stmt);
1175 0 : print_gimple_stmt (stderr, stmt, 0, TDF_VOPS);
1176 0 : goto err;
1177 : }
1178 :
1179 13049561504 : if (check_ssa_operands && verify_ssa_operands (cfun, stmt))
1180 : {
1181 0 : print_gimple_stmt (stderr, stmt, 0, TDF_VOPS);
1182 0 : goto err;
1183 : }
1184 :
1185 13049561504 : if (gimple_debug_bind_p (stmt)
1186 6743800797 : && !gimple_debug_bind_has_value_p (stmt))
1187 2240072706 : continue;
1188 :
1189 20844179249 : FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE|SSA_OP_VUSE)
1190 : {
1191 10034690451 : op = USE_FROM_PTR (use_p);
1192 10034690451 : if (verify_use (bb, definition_block[SSA_NAME_VERSION (op)],
1193 : use_p, stmt, false, names_defined_in_bb))
1194 0 : goto err;
1195 : }
1196 :
1197 16156749565 : FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_ALL_DEFS)
1198 : {
1199 5347260767 : if (SSA_NAME_DEF_STMT (op) != stmt)
1200 : {
1201 0 : error ("SSA_NAME_DEF_STMT is wrong");
1202 0 : fprintf (stderr, "Expected definition statement:\n");
1203 0 : print_gimple_stmt (stderr, stmt, 4, TDF_VOPS);
1204 0 : fprintf (stderr, "\nActual definition statement:\n");
1205 0 : print_gimple_stmt (stderr, SSA_NAME_DEF_STMT (op),
1206 : 4, TDF_VOPS);
1207 0 : goto err;
1208 : }
1209 5347260767 : bitmap_set_bit (names_defined_in_bb, SSA_NAME_VERSION (op));
1210 : }
1211 : }
1212 :
1213 1884545440 : bitmap_clear (names_defined_in_bb);
1214 : }
1215 :
1216 230342055 : free (definition_block);
1217 :
1218 230342055 : if (gimple_vop (cfun)
1219 230342055 : && ssa_default_def (cfun, gimple_vop (cfun)))
1220 : {
1221 230235637 : auto_sbitmap visited (last_basic_block_for_fn (cfun) + 1);
1222 230235637 : bitmap_clear (visited);
1223 230235637 : if (verify_vssa (ENTRY_BLOCK_PTR_FOR_FN (cfun),
1224 : ssa_default_def (cfun, gimple_vop (cfun)), visited))
1225 0 : goto err;
1226 230235637 : }
1227 :
1228 : /* Restore the dominance information to its prior known state, so
1229 : that we do not perturb the compiler's subsequent behavior. */
1230 230342055 : if (orig_dom_state == DOM_NONE)
1231 74767629 : free_dominance_info (CDI_DOMINATORS);
1232 : else
1233 155574426 : set_dom_info_availability (CDI_DOMINATORS, orig_dom_state);
1234 :
1235 230342055 : timevar_pop (TV_TREE_SSA_VERIFY);
1236 230342055 : return;
1237 :
1238 0 : err:
1239 0 : internal_error ("verify_ssa failed");
1240 230342055 : }
1241 :
1242 : #if __GNUC__ >= 10
1243 : # pragma GCC diagnostic pop
1244 : #endif
1245 :
1246 : /* Initialize global DFA and SSA structures.
1247 : If SIZE is non-zero allocated ssa names array of a given size. */
1248 :
1249 : void
1250 3436727 : init_tree_ssa (struct function *fn, int size)
1251 : {
1252 3436727 : fn->gimple_df = ggc_cleared_alloc<gimple_df> ();
1253 3436727 : fn->gimple_df->default_defs = hash_table<ssa_name_hasher>::create_ggc (20);
1254 3436727 : pt_solution_reset (&fn->gimple_df->escaped);
1255 3436727 : pt_solution_reset (&fn->gimple_df->escaped_return);
1256 3436727 : init_ssanames (fn, size);
1257 3436727 : }
1258 :
1259 : /* Deallocate memory associated with SSA data structures for FNDECL. */
1260 :
1261 : void
1262 3324820 : delete_tree_ssa (struct function *fn)
1263 : {
1264 3324820 : fini_ssanames (fn);
1265 :
1266 : /* We no longer maintain the SSA operand cache at this point. */
1267 3324820 : if (ssa_operands_active (fn))
1268 3300761 : fini_ssa_operands (fn);
1269 :
1270 3324820 : fn->gimple_df->default_defs->empty ();
1271 3324820 : fn->gimple_df->default_defs = NULL;
1272 3324820 : pt_solution_reset (&fn->gimple_df->escaped);
1273 3324820 : pt_solution_reset (&fn->gimple_df->escaped_return);
1274 3324820 : if (fn->gimple_df->decls_to_pointers != NULL)
1275 43515 : delete fn->gimple_df->decls_to_pointers;
1276 3324820 : fn->gimple_df->decls_to_pointers = NULL;
1277 3324820 : fn->gimple_df = NULL;
1278 :
1279 : /* We no longer need the edge variable maps. */
1280 3324820 : redirect_edge_var_map_empty ();
1281 3324820 : }
1282 :
1283 : /* Return true if EXPR is a useless type conversion, otherwise return
1284 : false. */
1285 :
1286 : bool
1287 1016129937 : tree_ssa_useless_type_conversion (tree expr)
1288 : {
1289 1016129937 : tree outer_type, inner_type;
1290 :
1291 : /* If we have an assignment that merely uses a NOP_EXPR to change
1292 : the top of the RHS to the type of the LHS and the type conversion
1293 : is "safe", then strip away the type conversion so that we can
1294 : enter LHS = RHS into the const_and_copies table. */
1295 1016129937 : if (!CONVERT_EXPR_P (expr)
1296 938842205 : && TREE_CODE (expr) != VIEW_CONVERT_EXPR
1297 937764882 : && TREE_CODE (expr) != NON_LVALUE_EXPR)
1298 : return false;
1299 :
1300 78936644 : outer_type = TREE_TYPE (expr);
1301 78936644 : inner_type = TREE_TYPE (TREE_OPERAND (expr, 0));
1302 :
1303 78936644 : if (inner_type == error_mark_node)
1304 : return false;
1305 :
1306 78936601 : return useless_type_conversion_p (outer_type, inner_type);
1307 : }
1308 :
1309 : /* Strip conversions from EXP according to
1310 : tree_ssa_useless_type_conversion and return the resulting
1311 : expression. */
1312 :
1313 : tree
1314 980335121 : tree_ssa_strip_useless_type_conversions (tree exp)
1315 : {
1316 1002645058 : while (tree_ssa_useless_type_conversion (exp))
1317 22309937 : exp = TREE_OPERAND (exp, 0);
1318 980335121 : return exp;
1319 : }
1320 :
1321 : /* Return true if T, as SSA_NAME, has an implicit default defined value. */
1322 :
1323 : bool
1324 394002960 : ssa_defined_default_def_p (tree t)
1325 : {
1326 394002960 : tree var = SSA_NAME_VAR (t);
1327 :
1328 151176365 : if (!var)
1329 : ;
1330 : /* Parameters get their initial value from the function entry. */
1331 151176365 : else if (TREE_CODE (var) == PARM_DECL)
1332 : return true;
1333 : /* When returning by reference the return address is actually a hidden
1334 : parameter. */
1335 119397911 : else if (TREE_CODE (var) == RESULT_DECL && DECL_BY_REFERENCE (var))
1336 : return true;
1337 : /* Hard register variables get their initial value from the ether. */
1338 119184603 : else if (VAR_P (var) && DECL_HARD_REGISTER (var))
1339 0 : return true;
1340 :
1341 : return false;
1342 : }
1343 :
1344 :
1345 : /* Return true if T, an SSA_NAME, has an undefined value. PARTIAL is what
1346 : should be returned if the value is only partially undefined. */
1347 :
1348 : bool
1349 393652401 : ssa_undefined_value_p (tree t, bool partial)
1350 : {
1351 393652401 : gimple *def_stmt;
1352 :
1353 787304802 : gcc_checking_assert (!virtual_operand_p (t));
1354 :
1355 393652401 : if (ssa_defined_default_def_p (t))
1356 : return false;
1357 :
1358 : /* The value is undefined iff its definition statement is empty. */
1359 361725531 : def_stmt = SSA_NAME_DEF_STMT (t);
1360 361725531 : if (gimple_nop_p (def_stmt))
1361 : return true;
1362 :
1363 : /* The value is undefined if the definition statement is a call
1364 : to .DEFERRED_INIT function. Except for AUTO_INIT_CXX26 which is
1365 : undefined but needs to have the same value in all uses. */
1366 351235137 : if (gimple_call_internal_p (def_stmt, IFN_DEFERRED_INIT))
1367 : {
1368 40588 : if (tree_to_uhwi (gimple_call_arg (def_stmt, 1)) & AUTO_INIT_CXX26)
1369 : return false;
1370 : else
1371 : return true;
1372 : }
1373 :
1374 : /* The value is partially undefined if the definition statement is
1375 : a REALPART_EXPR or IMAGPART_EXPR and its operand is defined by
1376 : the call to .DEFERRED_INIT function. This is for handling the
1377 : following case:
1378 :
1379 : 1 typedef _Complex float C;
1380 : 2 C foo (int cond)
1381 : 3 {
1382 : 4 C f;
1383 : 5 __imag__ f = 0;
1384 : 6 if (cond)
1385 : 7 {
1386 : 8 __real__ f = 1;
1387 : 9 return f;
1388 : 10 }
1389 : 11 return f;
1390 : 12 }
1391 :
1392 : with -ftrivial-auto-var-init, compiler will insert the following
1393 : artificial initialization:
1394 : f = .DEFERRED_INIT (f, 2);
1395 : _1 = REALPART_EXPR <f>;
1396 :
1397 : we should treat the definition _1 = REALPART_EXPR <f> as undefined. */
1398 351194549 : auto assign = dyn_cast<gassign *> (def_stmt);
1399 41307061 : if (assign && partial && is_gimple_assign (assign)
1400 392501610 : && (gimple_assign_rhs_code (assign) == REALPART_EXPR
1401 40983570 : || gimple_assign_rhs_code (assign) == IMAGPART_EXPR))
1402 : {
1403 688547 : tree real_imag_part = TREE_OPERAND (gimple_assign_rhs1 (assign), 0);
1404 688547 : if (TREE_CODE (real_imag_part) == SSA_NAME
1405 688547 : && gimple_call_internal_p (SSA_NAME_DEF_STMT (real_imag_part),
1406 : IFN_DEFERRED_INIT))
1407 : return true;
1408 : }
1409 :
1410 : /* Check if the complex was not only partially defined. */
1411 41306915 : if (assign && partial && is_gimple_assign (assign)
1412 392501318 : && gimple_assign_rhs_code (assign) == COMPLEX_EXPR)
1413 : {
1414 18371 : tree rhs1, rhs2;
1415 :
1416 18371 : rhs1 = gimple_assign_rhs1 (assign);
1417 18371 : rhs2 = gimple_assign_rhs2 (assign);
1418 18030 : return (TREE_CODE (rhs1) == SSA_NAME && ssa_undefined_value_p (rhs1))
1419 36358 : || (TREE_CODE (rhs2) == SSA_NAME && ssa_undefined_value_p (rhs2));
1420 : }
1421 : return false;
1422 : }
1423 :
1424 :
1425 : /* Return TRUE iff there are any non-PHI uses of VAR that dominate the
1426 : end of BB. If we return TRUE and BB is a loop header, then VAR we
1427 : be assumed to be defined within the loop, even if it is marked as
1428 : maybe-undefined. */
1429 :
1430 : bool
1431 351450 : ssa_name_any_use_dominates_bb_p (tree var, basic_block bb)
1432 : {
1433 351450 : imm_use_iterator iter;
1434 351450 : use_operand_p use_p;
1435 1153850 : FOR_EACH_IMM_USE_FAST (use_p, iter, var)
1436 : {
1437 826932 : if (is_a <gphi *> (USE_STMT (use_p))
1438 826932 : || is_gimple_debug (USE_STMT (use_p)))
1439 755428 : continue;
1440 71504 : basic_block dombb = gimple_bb (USE_STMT (use_p));
1441 71504 : if (dominated_by_p (CDI_DOMINATORS, bb, dombb))
1442 24532 : return true;
1443 24532 : }
1444 :
1445 326918 : return false;
1446 : }
1447 :
1448 : /* Mark as maybe_undef any SSA_NAMEs that are unsuitable as ivopts
1449 : candidates for potentially involving undefined behavior. */
1450 :
1451 : void
1452 12454681 : mark_ssa_maybe_undefs (void)
1453 : {
1454 12454681 : auto_vec<tree> queue;
1455 :
1456 : /* Scan all SSA_NAMEs, marking the definitely-undefined ones as
1457 : maybe-undefined and queuing them for propagation, while clearing
1458 : the mark on others. */
1459 12454681 : unsigned int i;
1460 12454681 : tree var;
1461 617449115 : FOR_EACH_SSA_NAME (i, var, cfun)
1462 : {
1463 408723393 : if (SSA_NAME_IS_VIRTUAL_OPERAND (var)
1464 408723393 : || !ssa_undefined_value_p (var, false))
1465 400392993 : ssa_name_set_maybe_undef (var, false);
1466 : else
1467 : {
1468 8330400 : ssa_name_set_maybe_undef (var);
1469 8330400 : queue.safe_push (var);
1470 8330400 : if (dump_file && (dump_flags & TDF_DETAILS))
1471 138 : fprintf (dump_file, "marking _%i as maybe-undef\n",
1472 69 : SSA_NAME_VERSION (var));
1473 : }
1474 : }
1475 :
1476 : /* Now propagate maybe-undefined from a DEF to any other PHI that
1477 : uses it, as long as there isn't any intervening use of DEF. */
1478 22332633 : while (!queue.is_empty ())
1479 : {
1480 8654156 : var = queue.pop ();
1481 8654156 : imm_use_iterator iter;
1482 8654156 : use_operand_p use_p;
1483 10247587 : FOR_EACH_IMM_USE_FAST (use_p, iter, var)
1484 : {
1485 : /* Any uses of VAR that aren't PHI args imply VAR must be
1486 : defined, otherwise undefined behavior would have been
1487 : definitely invoked. Only PHI args may hold
1488 : maybe-undefined values without invoking undefined
1489 : behavior for that reason alone. */
1490 1593431 : if (!is_a <gphi *> (USE_STMT (use_p)))
1491 1269675 : continue;
1492 584298 : gphi *phi = as_a <gphi *> (USE_STMT (use_p));
1493 :
1494 584298 : tree def = gimple_phi_result (phi);
1495 584298 : if (ssa_name_maybe_undef_p (def))
1496 241752 : continue;
1497 :
1498 : /* Look for any uses of the maybe-unused SSA_NAME that
1499 : dominates the block that reaches the incoming block
1500 : corresponding to the PHI arg in which it is mentioned.
1501 : That means we can assume the SSA_NAME is defined in that
1502 : path, so we only mark a PHI result as maybe-undef if we
1503 : find an unused reaching SSA_NAME. */
1504 342546 : int idx = phi_arg_index_from_use (use_p);
1505 342546 : basic_block bb = gimple_phi_arg_edge (phi, idx)->src;
1506 342546 : if (ssa_name_any_use_dominates_bb_p (var, bb))
1507 18790 : continue;
1508 :
1509 323756 : ssa_name_set_maybe_undef (def);
1510 323756 : queue.safe_push (def);
1511 323756 : if (dump_file && (dump_flags & TDF_DETAILS))
1512 0 : fprintf (dump_file, "marking _%i as maybe-undef because of _%i\n",
1513 0 : SSA_NAME_VERSION (def), SSA_NAME_VERSION (var));
1514 8654156 : }
1515 : }
1516 12454681 : }
1517 :
1518 :
1519 : /* If necessary, rewrite the base of the reference tree *TP from
1520 : a MEM_REF to a plain or converted symbol. */
1521 :
1522 : static void
1523 24212432 : maybe_rewrite_mem_ref_base (tree *tp, bitmap suitable_for_renaming)
1524 : {
1525 24212432 : tree sym;
1526 :
1527 27619885 : while (handled_component_p (*tp))
1528 3407453 : tp = &TREE_OPERAND (*tp, 0);
1529 24212432 : if (TREE_CODE (*tp) == MEM_REF
1530 1747404 : && TREE_CODE (TREE_OPERAND (*tp, 0)) == ADDR_EXPR
1531 314195 : && (sym = TREE_OPERAND (TREE_OPERAND (*tp, 0), 0))
1532 314195 : && DECL_P (sym)
1533 313779 : && !TREE_ADDRESSABLE (sym)
1534 183466 : && bitmap_bit_p (suitable_for_renaming, DECL_UID (sym))
1535 59698 : && is_gimple_reg_type (TREE_TYPE (*tp))
1536 24272120 : && ! VOID_TYPE_P (TREE_TYPE (*tp)))
1537 : {
1538 59688 : if (VECTOR_TYPE_P (TREE_TYPE (sym))
1539 1516 : && useless_type_conversion_p (TREE_TYPE (*tp),
1540 1516 : TREE_TYPE (TREE_TYPE (sym)))
1541 60068 : && multiple_p (mem_ref_offset (*tp),
1542 380 : wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (*tp)))))
1543 : {
1544 758 : *tp = build3 (BIT_FIELD_REF, TREE_TYPE (*tp), sym,
1545 379 : TYPE_SIZE (TREE_TYPE (*tp)),
1546 : int_const_binop (MULT_EXPR,
1547 758 : bitsize_int (BITS_PER_UNIT),
1548 379 : TREE_OPERAND (*tp, 1)));
1549 : }
1550 59309 : else if (TREE_CODE (TREE_TYPE (sym)) == COMPLEX_TYPE
1551 1074 : && useless_type_conversion_p (TREE_TYPE (*tp),
1552 1074 : TREE_TYPE (TREE_TYPE (sym)))
1553 59314 : && (integer_zerop (TREE_OPERAND (*tp, 1))
1554 3 : || tree_int_cst_equal (TREE_OPERAND (*tp, 1),
1555 3 : TYPE_SIZE_UNIT (TREE_TYPE (*tp)))))
1556 : {
1557 6 : *tp = build1 (integer_zerop (TREE_OPERAND (*tp, 1))
1558 : ? REALPART_EXPR : IMAGPART_EXPR,
1559 4 : TREE_TYPE (*tp), sym);
1560 : }
1561 59305 : else if (integer_zerop (TREE_OPERAND (*tp, 1))
1562 59305 : && DECL_SIZE (sym) == TYPE_SIZE (TREE_TYPE (*tp)))
1563 : {
1564 58863 : if (!useless_type_conversion_p (TREE_TYPE (*tp),
1565 58863 : TREE_TYPE (sym)))
1566 13001 : *tp = build1 (VIEW_CONVERT_EXPR,
1567 13001 : TREE_TYPE (*tp), sym);
1568 : else
1569 45862 : *tp = sym;
1570 : }
1571 442 : else if (DECL_SIZE (sym)
1572 442 : && TREE_CODE (DECL_SIZE (sym)) == INTEGER_CST
1573 442 : && (known_subrange_p
1574 442 : (mem_ref_offset (*tp),
1575 442 : wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (*tp))),
1576 442 : 0, wi::to_offset (DECL_SIZE_UNIT (sym))))
1577 442 : && (! INTEGRAL_TYPE_P (TREE_TYPE (*tp))
1578 425 : || (wi::to_offset (TYPE_SIZE (TREE_TYPE (*tp)))
1579 850 : == TYPE_PRECISION (TREE_TYPE (*tp))))
1580 442 : && (! INTEGRAL_TYPE_P (TREE_TYPE (sym))
1581 169 : || type_has_mode_precision_p (TREE_TYPE (sym)))
1582 884 : && wi::umod_trunc (wi::to_offset (TYPE_SIZE (TREE_TYPE (*tp))),
1583 884 : BITS_PER_UNIT) == 0)
1584 : {
1585 884 : *tp = build3 (BIT_FIELD_REF, TREE_TYPE (*tp), sym,
1586 442 : TYPE_SIZE (TREE_TYPE (*tp)),
1587 : wide_int_to_tree (bitsizetype,
1588 442 : mem_ref_offset (*tp)
1589 884 : << LOG2_BITS_PER_UNIT));
1590 : }
1591 : }
1592 24212432 : }
1593 :
1594 : /* For a tree REF return its base if it is the base of a MEM_REF
1595 : that cannot be rewritten into SSA form. Otherwise return NULL_TREE. */
1596 :
1597 : static tree
1598 308729591 : non_rewritable_mem_ref_base (tree ref)
1599 : {
1600 308729591 : tree base;
1601 :
1602 : /* A plain decl does not need it set. */
1603 308729591 : if (DECL_P (ref))
1604 : return NULL_TREE;
1605 :
1606 277802855 : switch (TREE_CODE (ref))
1607 : {
1608 3001104 : case REALPART_EXPR:
1609 3001104 : case IMAGPART_EXPR:
1610 3001104 : case BIT_FIELD_REF:
1611 3001104 : if (DECL_P (TREE_OPERAND (ref, 0)))
1612 : return NULL_TREE;
1613 : break;
1614 2510795 : case VIEW_CONVERT_EXPR:
1615 2510795 : if (DECL_P (TREE_OPERAND (ref, 0)))
1616 : {
1617 1091510 : if (TYPE_SIZE (TREE_TYPE (ref))
1618 1091510 : != TYPE_SIZE (TREE_TYPE (TREE_OPERAND (ref, 0))))
1619 817 : return TREE_OPERAND (ref, 0);
1620 : return NULL_TREE;
1621 : }
1622 : break;
1623 : /* We would need to rewrite ARRAY_REFs or COMPONENT_REFs and even
1624 : more so multiple levels of handled components. */
1625 276209409 : default:;
1626 : }
1627 :
1628 276209409 : base = ref;
1629 :
1630 : /* But watch out for MEM_REFs we cannot lower to a
1631 : VIEW_CONVERT_EXPR or a BIT_FIELD_REF. */
1632 276209409 : if (TREE_CODE (base) == MEM_REF
1633 276209409 : && TREE_CODE (TREE_OPERAND (base, 0)) == ADDR_EXPR)
1634 : {
1635 6466923 : tree decl = TREE_OPERAND (TREE_OPERAND (base, 0), 0);
1636 6466923 : if (! DECL_P (decl))
1637 : return NULL_TREE;
1638 6419775 : if (! is_gimple_reg_type (TREE_TYPE (base))
1639 6229175 : || VOID_TYPE_P (TREE_TYPE (base))
1640 12648950 : || TREE_THIS_VOLATILE (decl) != TREE_THIS_VOLATILE (base))
1641 : return decl;
1642 6227928 : if ((VECTOR_TYPE_P (TREE_TYPE (decl))
1643 6224871 : || TREE_CODE (TREE_TYPE (decl)) == COMPLEX_TYPE)
1644 4533 : && useless_type_conversion_p (TREE_TYPE (base),
1645 4533 : TREE_TYPE (TREE_TYPE (decl)))
1646 1115 : && known_ge (mem_ref_offset (base), 0)
1647 1068 : && known_gt (wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (decl))),
1648 : mem_ref_offset (base))
1649 6228990 : && multiple_p (mem_ref_offset (base),
1650 1062 : wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (base)))))
1651 1060 : return NULL_TREE;
1652 : /* For same sizes and zero offset we can use a VIEW_CONVERT_EXPR. */
1653 6226868 : if (integer_zerop (TREE_OPERAND (base, 1))
1654 6226868 : && DECL_SIZE (decl) == TYPE_SIZE (TREE_TYPE (base)))
1655 : return NULL_TREE;
1656 : /* For integral typed extracts we can use a BIT_FIELD_REF. */
1657 5560184 : if (DECL_SIZE (decl)
1658 5557130 : && TREE_CODE (DECL_SIZE_UNIT (decl)) == INTEGER_CST
1659 5557130 : && (known_subrange_p
1660 5557130 : (mem_ref_offset (base),
1661 5557130 : wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (base))),
1662 5557130 : 0, wi::to_poly_offset (DECL_SIZE_UNIT (decl))))
1663 : /* ??? We can't handle bitfield precision extracts without
1664 : either using an alternate type for the BIT_FIELD_REF and
1665 : then doing a conversion or possibly adjusting the offset
1666 : according to endianness. */
1667 5554650 : && (! INTEGRAL_TYPE_P (TREE_TYPE (base))
1668 2968256 : || (wi::to_offset (TYPE_SIZE (TREE_TYPE (base)))
1669 5936512 : == TYPE_PRECISION (TREE_TYPE (base))))
1670 : /* ??? Likewise for extracts from bitfields, we'd have
1671 : to pun the base object to a size precision mode first. */
1672 5548240 : && (! INTEGRAL_TYPE_P (TREE_TYPE (decl))
1673 44434 : || type_has_mode_precision_p (TREE_TYPE (decl)))
1674 11070458 : && wi::umod_trunc (wi::to_offset (TYPE_SIZE (TREE_TYPE (base))),
1675 11020548 : BITS_PER_UNIT) == 0)
1676 5510274 : return NULL_TREE;
1677 49910 : return decl;
1678 : }
1679 :
1680 : /* We cannot rewrite a decl in the base. */
1681 269742486 : base = get_base_address (ref);
1682 269742486 : if (DECL_P (base))
1683 : return base;
1684 :
1685 : /* We cannot rewrite TARGET_MEM_REFs. */
1686 249256678 : else if (TREE_CODE (base) == TARGET_MEM_REF
1687 249256678 : && TREE_CODE (TREE_OPERAND (base, 0)) == ADDR_EXPR)
1688 : {
1689 0 : tree decl = TREE_OPERAND (TREE_OPERAND (base, 0), 0);
1690 0 : if (! DECL_P (decl))
1691 : return NULL_TREE;
1692 0 : return decl;
1693 : }
1694 :
1695 : return NULL_TREE;
1696 : }
1697 :
1698 : /* For an lvalue tree LHS return true if it cannot be rewritten into SSA form.
1699 : Otherwise return true. */
1700 :
1701 : static bool
1702 109169343 : non_rewritable_lvalue_p (tree lhs)
1703 : {
1704 : /* A plain decl is always rewritable. */
1705 109169343 : if (DECL_P (lhs))
1706 : return false;
1707 :
1708 : /* We can re-write REALPART_EXPR and IMAGPART_EXPR sets in
1709 : a reasonably efficient manner... */
1710 63678767 : if ((TREE_CODE (lhs) == REALPART_EXPR
1711 63678767 : || TREE_CODE (lhs) == IMAGPART_EXPR)
1712 63678767 : && DECL_P (TREE_OPERAND (lhs, 0)))
1713 : return false;
1714 :
1715 : /* ??? The following could be relaxed allowing component
1716 : references that do not change the access size. */
1717 63646843 : if (TREE_CODE (lhs) == MEM_REF
1718 63646843 : && TREE_CODE (TREE_OPERAND (lhs, 0)) == ADDR_EXPR)
1719 : {
1720 7562481 : tree decl = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0);
1721 :
1722 : /* A decl that is wrapped inside a MEM-REF that covers
1723 : it full is also rewritable. */
1724 7562481 : if (integer_zerop (TREE_OPERAND (lhs, 1))
1725 2211547 : && DECL_P (decl)
1726 2211487 : && DECL_SIZE (decl) == TYPE_SIZE (TREE_TYPE (lhs))
1727 : /* If the dynamic type of the decl has larger precision than
1728 : the decl itself we can't use the decls type for SSA rewriting. */
1729 577391 : && ((! INTEGRAL_TYPE_P (TREE_TYPE (decl))
1730 15999 : || compare_tree_int (DECL_SIZE (decl),
1731 15999 : TYPE_PRECISION (TREE_TYPE (decl))) == 0)
1732 1876 : || (INTEGRAL_TYPE_P (TREE_TYPE (lhs))
1733 1800 : && (TYPE_PRECISION (TREE_TYPE (decl))
1734 1800 : >= TYPE_PRECISION (TREE_TYPE (lhs)))))
1735 : /* Make sure we are not re-writing non-float copying into float
1736 : copying as that can incur normalization. */
1737 577180 : && (! FLOAT_TYPE_P (TREE_TYPE (decl))
1738 5128 : || types_compatible_p (TREE_TYPE (lhs), TREE_TYPE (decl)))
1739 8135136 : && (TREE_THIS_VOLATILE (decl) == TREE_THIS_VOLATILE (lhs)))
1740 : return false;
1741 :
1742 : /* A vector-insert using a MEM_REF or ARRAY_REF is rewritable
1743 : using a BIT_INSERT_EXPR. */
1744 6990312 : if (DECL_P (decl)
1745 6990246 : && VECTOR_TYPE_P (TREE_TYPE (decl))
1746 3012 : && TYPE_MODE (TREE_TYPE (decl)) != BLKmode
1747 296 : && known_ge (mem_ref_offset (lhs), 0)
1748 261 : && known_gt (wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (decl))),
1749 : mem_ref_offset (lhs))
1750 261 : && multiple_p (mem_ref_offset (lhs),
1751 261 : wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (lhs))))
1752 13980558 : && known_ge (wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (decl))),
1753 : wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (lhs)))))
1754 : {
1755 260 : poly_uint64 lhs_bits, nelts;
1756 260 : if (poly_int_tree_p (TYPE_SIZE (TREE_TYPE (lhs)), &lhs_bits)
1757 262 : && multiple_p (lhs_bits,
1758 : tree_to_uhwi
1759 260 : (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl)))),
1760 : &nelts)
1761 280 : && valid_vector_subparts_p (nelts))
1762 : {
1763 240 : if (known_eq (nelts, 1u))
1764 240 : return false;
1765 : /* For sub-vector inserts the insert vector mode has to be
1766 : supported. */
1767 175 : tree vtype = build_vector_type (TREE_TYPE (TREE_TYPE (decl)),
1768 175 : nelts);
1769 175 : if (TYPE_MODE (vtype) != BLKmode)
1770 : return false;
1771 : }
1772 : }
1773 : }
1774 :
1775 : /* A vector-insert using a BIT_FIELD_REF is rewritable using
1776 : BIT_INSERT_EXPR. */
1777 63074434 : if (TREE_CODE (lhs) == BIT_FIELD_REF
1778 22750 : && DECL_P (TREE_OPERAND (lhs, 0))
1779 16935 : && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (lhs, 0)))
1780 16935 : && TYPE_MODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) != BLKmode
1781 4324 : && operand_equal_p (TYPE_SIZE_UNIT (TREE_TYPE (lhs)),
1782 4324 : TYPE_SIZE_UNIT
1783 : (TREE_TYPE (TREE_TYPE (TREE_OPERAND (lhs, 0)))), 0)
1784 63078757 : && (tree_to_uhwi (TREE_OPERAND (lhs, 2))
1785 4323 : % tree_to_uhwi (TYPE_SIZE (TREE_TYPE (lhs)))) == 0)
1786 4323 : return false;
1787 :
1788 : return true;
1789 : }
1790 :
1791 : /* When possible, clear TREE_ADDRESSABLE bit, set or clear DECL_NOT_GIMPLE_REG_P
1792 : and mark the variable VAR for conversion into SSA. Return true when updating
1793 : stmts is required. */
1794 :
1795 : static void
1796 110729478 : maybe_optimize_var (tree var, bitmap addresses_taken, bitmap not_reg_needs,
1797 : bitmap suitable_for_renaming)
1798 : {
1799 : /* Global Variables, result decls cannot be changed. */
1800 110729478 : if (is_global_var (var)
1801 109062036 : || TREE_CODE (var) == RESULT_DECL
1802 219791514 : || bitmap_bit_p (addresses_taken, DECL_UID (var)))
1803 : return;
1804 :
1805 99667045 : bool maybe_reg = false;
1806 99667045 : if (TREE_ADDRESSABLE (var))
1807 : {
1808 1595108 : TREE_ADDRESSABLE (var) = 0;
1809 1595108 : maybe_reg = true;
1810 1595108 : if (dump_file)
1811 : {
1812 145 : fprintf (dump_file, "No longer having address taken: ");
1813 145 : print_generic_expr (dump_file, var);
1814 145 : fprintf (dump_file, "\n");
1815 : }
1816 : }
1817 :
1818 : /* For register type decls if we do not have any partial defs
1819 : we cannot express in SSA form mark them as DECL_NOT_GIMPLE_REG_P
1820 : as to avoid SSA rewrite. For the others go ahead and mark
1821 : them for renaming. */
1822 99667045 : if (is_gimple_reg_type (TREE_TYPE (var)))
1823 : {
1824 83043387 : if (bitmap_bit_p (not_reg_needs, DECL_UID (var)))
1825 : {
1826 38022 : DECL_NOT_GIMPLE_REG_P (var) = 1;
1827 38022 : if (dump_file)
1828 : {
1829 4 : fprintf (dump_file, "Has partial defs: ");
1830 4 : print_generic_expr (dump_file, var);
1831 4 : fprintf (dump_file, "\n");
1832 : }
1833 : }
1834 165959558 : else if (BITINT_TYPE_P (TREE_TYPE (var))
1835 51193 : && (cfun->curr_properties & PROP_gimple_lbitint) != 0
1836 83038675 : && TYPE_PRECISION (TREE_TYPE (var)) > MAX_FIXED_MODE_SIZE)
1837 : {
1838 : /* Don't rewrite large/huge _BitInt vars after _BitInt lowering
1839 : into SSA form. */
1840 5988 : DECL_NOT_GIMPLE_REG_P (var) = 1;
1841 5988 : if (dump_file)
1842 : {
1843 0 : fprintf (dump_file, "_BitInt var after its lowering: ");
1844 0 : print_generic_expr (dump_file, var);
1845 0 : fprintf (dump_file, "\n");
1846 : }
1847 : }
1848 82999377 : else if (DECL_NOT_GIMPLE_REG_P (var))
1849 : {
1850 9128 : maybe_reg = true;
1851 9128 : DECL_NOT_GIMPLE_REG_P (var) = 0;
1852 : }
1853 83043387 : if (maybe_reg)
1854 : {
1855 544597 : if (is_gimple_reg (var))
1856 : {
1857 536306 : if (dump_file)
1858 : {
1859 43 : fprintf (dump_file, "Now a gimple register: ");
1860 43 : print_generic_expr (dump_file, var);
1861 43 : fprintf (dump_file, "\n");
1862 : }
1863 536306 : bitmap_set_bit (suitable_for_renaming, DECL_UID (var));
1864 : }
1865 : else
1866 8291 : DECL_NOT_GIMPLE_REG_P (var) = 1;
1867 : }
1868 : }
1869 : }
1870 :
1871 : /* Return true when STMT is ASAN mark where second argument is an address
1872 : of a local variable. */
1873 :
1874 : static bool
1875 61280389 : is_asan_mark_p (gimple *stmt)
1876 : {
1877 61280389 : if (!gimple_call_internal_p (stmt, IFN_ASAN_MARK))
1878 : return false;
1879 :
1880 57787 : tree addr = get_base_address (gimple_call_arg (stmt, 1));
1881 57787 : if (TREE_CODE (addr) == ADDR_EXPR
1882 57787 : && VAR_P (TREE_OPERAND (addr, 0)))
1883 : {
1884 57583 : tree var = TREE_OPERAND (addr, 0);
1885 57583 : if (lookup_attribute (ASAN_USE_AFTER_SCOPE_ATTRIBUTE,
1886 57583 : DECL_ATTRIBUTES (var)))
1887 : return false;
1888 :
1889 52564 : unsigned addressable = TREE_ADDRESSABLE (var);
1890 52564 : TREE_ADDRESSABLE (var) = 0;
1891 52564 : bool r = is_gimple_reg (var);
1892 52564 : TREE_ADDRESSABLE (var) = addressable;
1893 52564 : return r;
1894 : }
1895 :
1896 : return false;
1897 : }
1898 :
1899 : /* Helper for set_addresses_taken. If the base of ADDR is a DECL,
1900 : set the bit for its uid in the bitmap passed as DATA and return
1901 : true; otherwise return false. */
1902 :
1903 : static bool
1904 56194038 : set_addresses_taken_1 (gimple *, tree addr, tree, void *data)
1905 : {
1906 56194038 : bitmap addresses_taken = (bitmap)data;
1907 56194038 : addr = get_base_address (addr);
1908 56194038 : if (addr && DECL_P (addr))
1909 : {
1910 35744247 : bitmap_set_bit (addresses_taken, DECL_UID (addr));
1911 35744247 : return true;
1912 : }
1913 : return false;
1914 : }
1915 :
1916 : /* Set the bit for the uid of all DECLs that have their address taken in
1917 : STMT in the ADDRESSES_TAKEN bitmap. Return true if there are any. */
1918 :
1919 : static bool
1920 887649360 : set_addresses_taken (gimple *stmt, bitmap addresses_taken)
1921 : {
1922 887649360 : return walk_stmt_load_store_addr_ops (stmt, addresses_taken, NULL, NULL,
1923 887649360 : set_addresses_taken_1);
1924 : }
1925 :
1926 : /* Compute TREE_ADDRESSABLE and whether we have unhandled partial defs
1927 : for local variables. */
1928 :
1929 : void
1930 12933076 : execute_update_addresses_taken (void)
1931 : {
1932 12933076 : basic_block bb;
1933 12933076 : auto_bitmap addresses_taken;
1934 12933076 : auto_bitmap not_reg_needs;
1935 12933076 : auto_bitmap suitable_for_renaming;
1936 12933076 : bool optimistic_not_addressable = false;
1937 12933076 : tree var;
1938 12933076 : unsigned i;
1939 :
1940 12933076 : timevar_push (TV_ADDRESS_TAKEN);
1941 :
1942 : /* Collect into ADDRESSES_TAKEN all variables whose address is taken within
1943 : the function body. */
1944 128777529 : FOR_EACH_BB_FN (bb, cfun)
1945 : {
1946 1119360066 : for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
1947 887671160 : gsi_next (&gsi))
1948 : {
1949 887671160 : gimple *stmt = gsi_stmt (gsi);
1950 887671160 : enum gimple_code code = gimple_code (stmt);
1951 887671160 : tree decl;
1952 :
1953 887671160 : if (code == GIMPLE_CALL)
1954 : {
1955 58824072 : if (optimize_atomic_compare_exchange_p (stmt))
1956 : {
1957 : /* For __atomic_compare_exchange_N if the second argument
1958 : is &var, don't mark var addressable;
1959 : if it becomes non-addressable, we'll rewrite it into
1960 : ATOMIC_COMPARE_EXCHANGE call. */
1961 5830 : tree arg = gimple_call_arg (stmt, 1);
1962 5830 : gimple_call_set_arg (stmt, 1, null_pointer_node);
1963 5830 : set_addresses_taken (stmt, addresses_taken);
1964 5830 : gimple_call_set_arg (stmt, 1, arg);
1965 : /* Remember we have to check again below. */
1966 5830 : optimistic_not_addressable = true;
1967 : }
1968 58818242 : else if (is_asan_mark_p (stmt)
1969 58818242 : || gimple_call_internal_p (stmt, IFN_GOMP_SIMT_ENTER))
1970 : ;
1971 58798167 : else if (gimple_call_internal_p (stmt, IFN_ASSUME))
1972 : {
1973 : /* An address-taken arguments are not relevant for aliasing
1974 : and we never expand the call (and need the address).
1975 : But we can't use a register. */
1976 4058 : for (unsigned i = 1; i < gimple_call_num_args (stmt); ++i)
1977 : {
1978 2333 : tree arg = gimple_call_arg (stmt, i);
1979 2333 : if (TREE_CODE (arg) == ADDR_EXPR)
1980 16 : bitmap_set_bit (not_reg_needs,
1981 8 : DECL_UID (get_base_address
1982 : (TREE_OPERAND (arg, 0))));
1983 : }
1984 : }
1985 : else
1986 58796442 : set_addresses_taken (stmt, addresses_taken);
1987 : }
1988 : else
1989 : /* Note all addresses taken by the stmt. */
1990 828847088 : set_addresses_taken (stmt, addresses_taken);
1991 :
1992 : /* If we have a call or an assignment, see if the lhs contains
1993 : a local decl that requires not to be a gimple register. */
1994 887671160 : if (code == GIMPLE_ASSIGN || code == GIMPLE_CALL)
1995 : {
1996 332601739 : tree lhs = gimple_get_lhs (stmt);
1997 332601739 : if (lhs
1998 297245897 : && TREE_CODE (lhs) != SSA_NAME
1999 441780282 : && ((code == GIMPLE_CALL && ! DECL_P (lhs))
2000 109061779 : || non_rewritable_lvalue_p (lhs)))
2001 : {
2002 63176634 : decl = get_base_address (lhs);
2003 63176634 : if (DECL_P (decl))
2004 44132658 : bitmap_set_bit (not_reg_needs, DECL_UID (decl));
2005 : }
2006 : }
2007 :
2008 887671160 : if (gimple_assign_single_p (stmt))
2009 : {
2010 184856727 : tree rhs = gimple_assign_rhs1 (stmt);
2011 184856727 : if ((decl = non_rewritable_mem_ref_base (rhs)))
2012 20514528 : bitmap_set_bit (not_reg_needs, DECL_UID (decl));
2013 : }
2014 :
2015 702814433 : else if (code == GIMPLE_CALL)
2016 : {
2017 175065463 : for (i = 0; i < gimple_call_num_args (stmt); ++i)
2018 : {
2019 116241391 : tree arg = gimple_call_arg (stmt, i);
2020 116241391 : if ((decl = non_rewritable_mem_ref_base (arg)))
2021 173154 : bitmap_set_bit (not_reg_needs, DECL_UID (decl));
2022 : }
2023 : }
2024 :
2025 643990361 : else if (code == GIMPLE_ASM)
2026 : {
2027 689558 : gasm *asm_stmt = as_a <gasm *> (stmt);
2028 2076412 : for (i = 0; i < gimple_asm_noutputs (asm_stmt); ++i)
2029 : {
2030 697296 : tree link = gimple_asm_output_op (asm_stmt, i);
2031 697296 : tree lhs = TREE_VALUE (link);
2032 697296 : if (TREE_CODE (lhs) != SSA_NAME)
2033 : {
2034 181850 : decl = get_base_address (lhs);
2035 181850 : if (DECL_P (decl)
2036 181850 : && (non_rewritable_lvalue_p (lhs)
2037 : /* We cannot move required conversions from
2038 : the lhs to the rhs in asm statements, so
2039 : require we do not need any. */
2040 97323 : || !useless_type_conversion_p
2041 97323 : (TREE_TYPE (lhs), TREE_TYPE (decl))))
2042 10851 : bitmap_set_bit (not_reg_needs, DECL_UID (decl));
2043 : }
2044 : }
2045 1152647 : for (i = 0; i < gimple_asm_ninputs (asm_stmt); ++i)
2046 : {
2047 463089 : tree link = gimple_asm_input_op (asm_stmt, i);
2048 463089 : if ((decl = non_rewritable_mem_ref_base (TREE_VALUE (link))))
2049 1323 : bitmap_set_bit (not_reg_needs, DECL_UID (decl));
2050 : }
2051 : }
2052 : }
2053 :
2054 154736248 : for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
2055 38891795 : gsi_next (&gsi))
2056 : {
2057 38891795 : gphi *phi = gsi.phi ();
2058 :
2059 178162999 : for (i = 0; i < gimple_phi_num_args (phi); i++)
2060 : {
2061 100379409 : tree op = PHI_ARG_DEF (phi, i);
2062 100379409 : if (TREE_CODE (op) == ADDR_EXPR)
2063 776859 : set_addresses_taken_1 (phi, TREE_OPERAND (op, 0), op,
2064 776859 : (void *)addresses_taken);
2065 : }
2066 : }
2067 : }
2068 :
2069 : /* We cannot iterate over all referenced vars because that can contain
2070 : unused vars from BLOCK trees, which causes code generation differences
2071 : for -g vs. -g0. */
2072 39934862 : for (var = DECL_ARGUMENTS (cfun->decl); var; var = DECL_CHAIN (var))
2073 27001786 : maybe_optimize_var (var, addresses_taken, not_reg_needs,
2074 : suitable_for_renaming);
2075 :
2076 96660768 : FOR_EACH_VEC_SAFE_ELT (cfun->local_decls, i, var)
2077 83727692 : maybe_optimize_var (var, addresses_taken, not_reg_needs,
2078 : suitable_for_renaming);
2079 :
2080 : /* Operand caches need to be recomputed for operands referencing the updated
2081 : variables and operands need to be rewritten to expose bare symbols. */
2082 12933076 : if (!bitmap_empty_p (suitable_for_renaming)
2083 12933076 : || optimistic_not_addressable)
2084 : {
2085 5727802 : FOR_EACH_BB_FN (bb, cfun)
2086 48580597 : for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
2087 : {
2088 37572425 : gimple *stmt = gsi_stmt (gsi);
2089 :
2090 : /* Re-write TARGET_MEM_REFs of symbols we want to
2091 : rewrite into SSA form. */
2092 37572425 : if (gimple_assign_single_p (stmt))
2093 : {
2094 12546283 : tree lhs = gimple_assign_lhs (stmt);
2095 12546283 : tree rhs, *rhsp = gimple_assign_rhs1_ptr (stmt);
2096 12546283 : tree sym;
2097 :
2098 : /* Rewrite LHS IMAG/REALPART_EXPR similar to
2099 : gimplify_modify_expr_complex_part. */
2100 12546283 : if ((TREE_CODE (lhs) == IMAGPART_EXPR
2101 12546283 : || TREE_CODE (lhs) == REALPART_EXPR)
2102 3645 : && DECL_P (TREE_OPERAND (lhs, 0))
2103 12548885 : && bitmap_bit_p (suitable_for_renaming,
2104 2602 : DECL_UID (TREE_OPERAND (lhs, 0))))
2105 : {
2106 2524 : tree other = make_ssa_name (TREE_TYPE (lhs));
2107 3795 : tree lrhs = build1 (TREE_CODE (lhs) == IMAGPART_EXPR
2108 : ? REALPART_EXPR : IMAGPART_EXPR,
2109 2524 : TREE_TYPE (other),
2110 2524 : TREE_OPERAND (lhs, 0));
2111 2524 : suppress_warning (lrhs);
2112 2524 : gimple *load = gimple_build_assign (other, lrhs);
2113 2524 : location_t loc = gimple_location (stmt);
2114 2524 : gimple_set_location (load, loc);
2115 5048 : gimple_set_vuse (load, gimple_vuse (stmt));
2116 2524 : gsi_insert_before (&gsi, load, GSI_SAME_STMT);
2117 2524 : gimple_assign_set_lhs (stmt, TREE_OPERAND (lhs, 0));
2118 2524 : gimple_assign_set_rhs_with_ops
2119 3795 : (&gsi, COMPLEX_EXPR,
2120 : TREE_CODE (lhs) == IMAGPART_EXPR
2121 1271 : ? other : gimple_assign_rhs1 (stmt),
2122 2524 : TREE_CODE (lhs) == IMAGPART_EXPR
2123 1253 : ? gimple_assign_rhs1 (stmt) : other, NULL_TREE);
2124 2524 : stmt = gsi_stmt (gsi);
2125 2524 : unlink_stmt_vdef (stmt);
2126 2524 : update_stmt (stmt);
2127 2524 : continue;
2128 2524 : }
2129 :
2130 : /* Rewrite a vector insert via a BIT_FIELD_REF on the LHS
2131 : into a BIT_INSERT_EXPR. */
2132 12543759 : if (TREE_CODE (lhs) == BIT_FIELD_REF
2133 942 : && DECL_P (TREE_OPERAND (lhs, 0))
2134 884 : && bitmap_bit_p (suitable_for_renaming,
2135 884 : DECL_UID (TREE_OPERAND (lhs, 0)))
2136 740 : && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (lhs, 0)))
2137 740 : && TYPE_MODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) != BLKmode
2138 740 : && operand_equal_p (TYPE_SIZE_UNIT (TREE_TYPE (lhs)),
2139 740 : TYPE_SIZE_UNIT (TREE_TYPE
2140 : (TREE_TYPE (TREE_OPERAND (lhs, 0)))),
2141 : 0)
2142 12544499 : && (tree_to_uhwi (TREE_OPERAND (lhs, 2))
2143 740 : % tree_to_uhwi (TYPE_SIZE (TREE_TYPE (lhs))) == 0))
2144 : {
2145 740 : tree var = TREE_OPERAND (lhs, 0);
2146 740 : tree val = gimple_assign_rhs1 (stmt);
2147 740 : if (! types_compatible_p (TREE_TYPE (TREE_TYPE (var)),
2148 740 : TREE_TYPE (val)))
2149 : {
2150 0 : tree tem = make_ssa_name (TREE_TYPE (TREE_TYPE (var)));
2151 0 : gimple *pun
2152 0 : = gimple_build_assign (tem,
2153 : build1 (VIEW_CONVERT_EXPR,
2154 0 : TREE_TYPE (tem), val));
2155 0 : gsi_insert_before (&gsi, pun, GSI_SAME_STMT);
2156 0 : val = tem;
2157 : }
2158 740 : tree bitpos = TREE_OPERAND (lhs, 2);
2159 740 : gimple_assign_set_lhs (stmt, var);
2160 740 : gimple_assign_set_rhs_with_ops
2161 740 : (&gsi, BIT_INSERT_EXPR, var, val, bitpos);
2162 740 : stmt = gsi_stmt (gsi);
2163 740 : unlink_stmt_vdef (stmt);
2164 740 : update_stmt (stmt);
2165 740 : continue;
2166 740 : }
2167 :
2168 : /* Rewrite a vector insert using a MEM_REF on the LHS
2169 : into a BIT_INSERT_EXPR. */
2170 12543019 : if (TREE_CODE (lhs) == MEM_REF
2171 475672 : && TREE_CODE (TREE_OPERAND (lhs, 0)) == ADDR_EXPR
2172 113396 : && (sym = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0))
2173 113396 : && DECL_P (sym)
2174 113396 : && bitmap_bit_p (suitable_for_renaming, DECL_UID (sym))
2175 9262 : && VECTOR_TYPE_P (TREE_TYPE (sym))
2176 183 : && TYPE_MODE (TREE_TYPE (sym)) != BLKmode
2177 : /* If it is a full replacement we can do better below. */
2178 177 : && maybe_ne (wi::to_poly_offset
2179 177 : (TYPE_SIZE_UNIT (TREE_TYPE (lhs))),
2180 : wi::to_poly_offset
2181 177 : (TYPE_SIZE_UNIT (TREE_TYPE (sym))))
2182 79 : && known_ge (mem_ref_offset (lhs), 0)
2183 79 : && known_gt (wi::to_poly_offset
2184 : (TYPE_SIZE_UNIT (TREE_TYPE (sym))),
2185 : mem_ref_offset (lhs))
2186 12543098 : && multiple_p (mem_ref_offset (lhs),
2187 : wi::to_poly_offset
2188 12543019 : (TYPE_SIZE_UNIT (TREE_TYPE (lhs)))))
2189 : {
2190 79 : tree val = gimple_assign_rhs1 (stmt);
2191 79 : if (! types_compatible_p (TREE_TYPE (val),
2192 79 : TREE_TYPE (TREE_TYPE (sym))))
2193 : {
2194 58 : poly_uint64 lhs_bits, nelts;
2195 58 : tree temtype = TREE_TYPE (TREE_TYPE (sym));
2196 58 : if (poly_int_tree_p (TYPE_SIZE (TREE_TYPE (lhs)),
2197 : &lhs_bits)
2198 174 : && multiple_p (lhs_bits,
2199 : tree_to_uhwi
2200 58 : (TYPE_SIZE (TREE_TYPE
2201 : (TREE_TYPE (sym)))),
2202 : &nelts)
2203 58 : && maybe_ne (nelts, 1u)
2204 148 : && valid_vector_subparts_p (nelts))
2205 32 : temtype = build_vector_type (temtype, nelts);
2206 58 : tree tem = make_ssa_name (temtype);
2207 58 : gimple *pun
2208 58 : = gimple_build_assign (tem,
2209 : build1 (VIEW_CONVERT_EXPR,
2210 58 : TREE_TYPE (tem), val));
2211 58 : gsi_insert_before (&gsi, pun, GSI_SAME_STMT);
2212 58 : val = tem;
2213 : }
2214 79 : tree bitpos
2215 79 : = wide_int_to_tree (bitsizetype,
2216 79 : mem_ref_offset (lhs) * BITS_PER_UNIT);
2217 79 : gimple_assign_set_lhs (stmt, sym);
2218 79 : gimple_assign_set_rhs_with_ops
2219 79 : (&gsi, BIT_INSERT_EXPR, sym, val, bitpos);
2220 79 : stmt = gsi_stmt (gsi);
2221 79 : unlink_stmt_vdef (stmt);
2222 79 : update_stmt (stmt);
2223 79 : continue;
2224 79 : }
2225 :
2226 : /* We shouldn't have any fancy wrapping of
2227 : component-refs on the LHS, but look through
2228 : VIEW_CONVERT_EXPRs as that is easy. */
2229 12542945 : while (TREE_CODE (lhs) == VIEW_CONVERT_EXPR)
2230 5 : lhs = TREE_OPERAND (lhs, 0);
2231 12542940 : if (TREE_CODE (lhs) == MEM_REF
2232 475598 : && TREE_CODE (TREE_OPERAND (lhs, 0)) == ADDR_EXPR
2233 113317 : && integer_zerop (TREE_OPERAND (lhs, 1))
2234 50252 : && (sym = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0))
2235 50252 : && DECL_P (sym)
2236 50252 : && !TREE_ADDRESSABLE (sym)
2237 12573600 : && bitmap_bit_p (suitable_for_renaming, DECL_UID (sym)))
2238 : lhs = sym;
2239 : else
2240 12533757 : lhs = gimple_assign_lhs (stmt);
2241 :
2242 : /* Rewrite the RHS and make sure the resulting assignment
2243 : is validly typed. */
2244 12542940 : maybe_rewrite_mem_ref_base (rhsp, suitable_for_renaming);
2245 12542940 : rhs = gimple_assign_rhs1 (stmt);
2246 12542940 : if (gimple_assign_lhs (stmt) != lhs
2247 12552123 : && !useless_type_conversion_p (TREE_TYPE (lhs),
2248 9183 : TREE_TYPE (rhs)))
2249 : {
2250 4389 : if (gimple_clobber_p (stmt))
2251 : {
2252 11 : rhs = build_constructor (TREE_TYPE (lhs), NULL);
2253 11 : TREE_THIS_VOLATILE (rhs) = 1;
2254 : }
2255 : else
2256 4378 : rhs = fold_build1 (VIEW_CONVERT_EXPR,
2257 : TREE_TYPE (lhs), rhs);
2258 : }
2259 12542940 : if (gimple_assign_lhs (stmt) != lhs)
2260 9183 : gimple_assign_set_lhs (stmt, lhs);
2261 :
2262 12542940 : if (gimple_assign_rhs1 (stmt) != rhs)
2263 : {
2264 4389 : gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
2265 4389 : gimple_assign_set_rhs_from_tree (&gsi, rhs);
2266 : }
2267 : }
2268 :
2269 25026142 : else if (gimple_code (stmt) == GIMPLE_CALL)
2270 : {
2271 2467977 : unsigned i;
2272 2467977 : if (optimize_atomic_compare_exchange_p (stmt))
2273 : {
2274 5830 : tree expected = gimple_call_arg (stmt, 1);
2275 5830 : tree decl = TREE_OPERAND (expected, 0);
2276 5830 : if (bitmap_bit_p (suitable_for_renaming, DECL_UID (decl)))
2277 : {
2278 5787 : fold_builtin_atomic_compare_exchange (&gsi);
2279 5787 : continue;
2280 : }
2281 43 : else if (!TREE_ADDRESSABLE (decl))
2282 : /* If there are partial defs of the decl we may
2283 : have cleared the addressable bit but set
2284 : DECL_NOT_GIMPLE_REG_P. We have to restore
2285 : TREE_ADDRESSABLE here. */
2286 27 : TREE_ADDRESSABLE (decl) = 1;
2287 : }
2288 2462147 : else if (is_asan_mark_p (stmt))
2289 : {
2290 392 : tree var = TREE_OPERAND (gimple_call_arg (stmt, 1), 0);
2291 392 : if (bitmap_bit_p (suitable_for_renaming, DECL_UID (var)))
2292 : {
2293 344 : unlink_stmt_vdef (stmt);
2294 344 : if (asan_mark_p (stmt, ASAN_MARK_POISON))
2295 : {
2296 177 : gcall *call
2297 177 : = gimple_build_call_internal (IFN_ASAN_POISON, 0);
2298 177 : gimple_call_set_lhs (call, var);
2299 177 : gsi_replace (&gsi, call, true);
2300 : }
2301 : else
2302 : {
2303 : /* In ASAN_MARK (UNPOISON, &b, ...) the variable
2304 : is uninitialized. Avoid dependencies on
2305 : previous out of scope value. */
2306 167 : tree clobber = build_clobber (TREE_TYPE (var));
2307 167 : gimple *g = gimple_build_assign (var, clobber);
2308 167 : gsi_replace (&gsi, g, true);
2309 : }
2310 344 : continue;
2311 344 : }
2312 : }
2313 2461755 : else if (gimple_call_internal_p (stmt, IFN_GOMP_SIMT_ENTER))
2314 0 : for (i = 1; i < gimple_call_num_args (stmt); i++)
2315 : {
2316 0 : tree *argp = gimple_call_arg_ptr (stmt, i);
2317 0 : if (*argp == null_pointer_node)
2318 0 : continue;
2319 0 : gcc_assert (TREE_CODE (*argp) == ADDR_EXPR
2320 : && VAR_P (TREE_OPERAND (*argp, 0)));
2321 0 : tree var = TREE_OPERAND (*argp, 0);
2322 0 : if (bitmap_bit_p (suitable_for_renaming, DECL_UID (var)))
2323 0 : *argp = null_pointer_node;
2324 : }
2325 6908143 : for (i = 0; i < gimple_call_num_args (stmt); ++i)
2326 : {
2327 4446297 : tree *argp = gimple_call_arg_ptr (stmt, i);
2328 4446297 : maybe_rewrite_mem_ref_base (argp, suitable_for_renaming);
2329 : }
2330 : }
2331 :
2332 22558165 : else if (gimple_code (stmt) == GIMPLE_ASM)
2333 : {
2334 11854 : gasm *asm_stmt = as_a <gasm *> (stmt);
2335 11854 : unsigned i;
2336 63002 : for (i = 0; i < gimple_asm_noutputs (asm_stmt); ++i)
2337 : {
2338 39294 : tree link = gimple_asm_output_op (asm_stmt, i);
2339 39294 : maybe_rewrite_mem_ref_base (&TREE_VALUE (link),
2340 : suitable_for_renaming);
2341 : }
2342 27371 : for (i = 0; i < gimple_asm_ninputs (asm_stmt); ++i)
2343 : {
2344 15517 : tree link = gimple_asm_input_op (asm_stmt, i);
2345 15517 : maybe_rewrite_mem_ref_base (&TREE_VALUE (link),
2346 : suitable_for_renaming);
2347 : }
2348 : }
2349 :
2350 22546311 : else if (gimple_debug_bind_p (stmt)
2351 16674738 : && gimple_debug_bind_has_value_p (stmt))
2352 : {
2353 7168384 : tree *valuep = gimple_debug_bind_get_value_ptr (stmt);
2354 7168384 : tree decl;
2355 7168384 : maybe_rewrite_mem_ref_base (valuep, suitable_for_renaming);
2356 7168384 : decl = non_rewritable_mem_ref_base (*valuep);
2357 7168384 : if (decl
2358 7168384 : && bitmap_bit_p (suitable_for_renaming, DECL_UID (decl)))
2359 10 : gimple_debug_bind_reset_value (stmt);
2360 : }
2361 :
2362 51321814 : if (gimple_references_memory_p (stmt)
2363 32592885 : || is_gimple_debug (stmt))
2364 21644804 : update_stmt (stmt);
2365 :
2366 37562951 : gsi_next (&gsi);
2367 : }
2368 :
2369 : /* Update SSA form here, we are called as non-pass as well. */
2370 223716 : if (number_of_loops (cfun) > 1
2371 223716 : && loops_state_satisfies_p (LOOP_CLOSED_SSA))
2372 148 : rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa);
2373 : else
2374 223568 : update_ssa (TODO_update_ssa);
2375 : }
2376 :
2377 12933076 : timevar_pop (TV_ADDRESS_TAKEN);
2378 12933076 : }
2379 :
2380 : namespace {
2381 :
2382 : const pass_data pass_data_update_address_taken =
2383 : {
2384 : GIMPLE_PASS, /* type */
2385 : "addressables", /* name */
2386 : OPTGROUP_NONE, /* optinfo_flags */
2387 : TV_ADDRESS_TAKEN, /* tv_id */
2388 : PROP_ssa, /* properties_required */
2389 : 0, /* properties_provided */
2390 : 0, /* properties_destroyed */
2391 : 0, /* todo_flags_start */
2392 : TODO_update_address_taken, /* todo_flags_finish */
2393 : };
2394 :
2395 : class pass_update_address_taken : public gimple_opt_pass
2396 : {
2397 : public:
2398 0 : pass_update_address_taken (gcc::context *ctxt)
2399 0 : : gimple_opt_pass (pass_data_update_address_taken, ctxt)
2400 : {}
2401 :
2402 : /* opt_pass methods: */
2403 :
2404 : }; // class pass_update_address_taken
2405 :
2406 : } // anon namespace
2407 :
2408 : gimple_opt_pass *
2409 0 : make_pass_update_address_taken (gcc::context *ctxt)
2410 : {
2411 0 : return new pass_update_address_taken (ctxt);
2412 : }
|