GCC Middle and Back End API Reference
ssa-iterators.h
Go to the documentation of this file.
1/* Header file for SSA iterators.
2 Copyright (C) 2013-2025 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#ifndef GCC_SSA_ITERATORS_H
21#define GCC_SSA_ITERATORS_H
22
23/* Immediate use lists are used to directly access all uses for an SSA
24 name and get pointers to the statement for each use.
25
26 The structure ssa_use_operand_t consists of PREV and NEXT pointers
27 to maintain the list. A USE pointer, which points to address where
28 the use is located and a LOC pointer which can point to the
29 statement where the use is located, or, in the case of the root
30 node, it points to the SSA name itself.
31
32 The list is anchored by an occurrence of ssa_operand_d *in* the
33 ssa_name node itself (named 'imm_uses'). This node is uniquely
34 identified by having a NULL USE pointer. and the LOC pointer
35 pointing back to the ssa_name node itself. This node forms the
36 base for a circular list, and initially this is the only node in
37 the list.
38
39 Fast iteration via FOR_EACH_IMM_USE_FAST allows each use to be
40 examined, but does not allow any modifications to the uses or stmts.
41
42 Safe iteration via FOR_EACH_IMM_USE_STMT and FOR_EACH_IMM_USE_ON_STMT
43 allows insertion, deletion, and modification of SSA operands within
44 the current stmt iterated. The iterator manages this by re-sorting
45 the immediate uses to batch uses on a single stmt after each other.
46 If using an inner FOR_EACH_IMM_USE_ON_STMT iteration only the active
47 use may be manipulated. Safety relies on new immediate uses being
48 inserted at the front of immediate use lists. */
49
51{
52 /* This is the current use the iterator is processing. */
54 /* This marks the last use in the list (use node from SSA_NAME) */
56 /* This is the next ssa_name to visit in an outer FOR_EACH_IMM_USE_STMT.
57 Also used for fast imm use iterator checking. */
59 /* This is the next ssa_name to visit. IMM_USE may get removed before
60 the next one is traversed to, so it must be cached early. */
62 /* This is the SSA name iterated over. */
64};
65
66
67/* Use this iterator when simply looking at stmts. Adding, deleting or
68 modifying stmts will cause this iterator to malfunction. */
69
70#if ! defined ENABLE_GIMPLE_CHECKING
71#define FOR_EACH_IMM_USE_FAST(DEST, ITER, SSAVAR) \
72 for ((DEST) = first_readonly_imm_use (&(ITER), (SSAVAR)); \
73 !end_readonly_imm_use_p (&(ITER)); \
74 (void) ((DEST) = next_readonly_imm_use (&(ITER))))
75#else
76
77/* arrange to automatically call, upon descruction, with a given pointer
78 to imm_use_iterator. */
79struct auto_end_imm_use_fast_traverse
80{
82 auto_end_imm_use_fast_traverse (imm_use_iterator *imm)
83 : imm (imm) {}
84 ~auto_end_imm_use_fast_traverse ()
85 { imm->name->ssa_name.fast_iteration_depth--; }
86};
87
88#define FOR_EACH_IMM_USE_FAST(DEST, ITER, SSAVAR) \
89 for (struct auto_end_imm_use_fast_traverse \
90 auto_end_imm_use_fast_traverse \
91 ((((DEST) = first_readonly_imm_use (&(ITER), (SSAVAR))), \
92 &(ITER))); \
93 !end_readonly_imm_use_p (&(ITER)); \
94 (void) ((DEST) = next_readonly_imm_use (&(ITER))))
95#endif
96
97/* Forward declare for use in the class below. */
99
100/* arrange to automatically call, upon descruction, end_imm_use_stmt_traverse
101 with a given pointer to imm_use_iterator. */
110
111/* Use this iterator to visit each stmt which has a use of SSAVAR. The
112 destructor of the auto_end_imm_use_stmt_traverse object deals with removing
113 ITER from SSAVAR's IMM_USE list even when leaving the scope early. */
114
115#define FOR_EACH_IMM_USE_STMT(STMT, ITER, SSAVAR) \
116 for (struct auto_end_imm_use_stmt_traverse \
117 auto_end_imm_use_stmt_traverse \
118 ((((STMT) = first_imm_use_stmt (&(ITER), (SSAVAR))), \
119 &(ITER))); \
120 !end_imm_use_stmt_p (&(ITER)); \
121 (void) ((STMT) = next_imm_use_stmt (&(ITER))))
122
123/* Use this iterator in combination with FOR_EACH_IMM_USE_STMT to
124 get access to each occurrence of ssavar on the stmt returned by
125 that iterator.. for instance:
126
127 FOR_EACH_IMM_USE_STMT (stmt, iter, ssavar)
128 {
129 FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
130 {
131 SET_USE (use_p, blah);
132 }
133 update_stmt (stmt);
134 } */
135
136#define FOR_EACH_IMM_USE_ON_STMT(DEST, ITER) \
137 for ((DEST) = first_imm_use_on_stmt (&(ITER)); \
138 !end_imm_use_on_stmt_p (&(ITER)); \
139 (void) ((DEST) = next_imm_use_on_stmt (&(ITER))))
140
141
142/* Use this to get a vector of all gimple stmts using SSAVAR without
143 duplicates. It's cheaper than FOR_EACH_IMM_USE_STMT and has no
144 constraints on what you are allowed to do inside an iteration
145 over the vector. */
147
148extern bool single_imm_use_1 (const ssa_use_operand_t *head,
149 use_operand_p *use_p, gimple **stmt);
150
151
158
159/* This structure is used in the operand iterator loops. It contains the
160 items required to determine which operand is retrieved next. During
161 optimization, this structure is scalarized, and any unused fields are
162 optimized away, resulting in little overhead. */
163
174
175/* NOTE: Keep these in sync with doc/tree-ssa.texi. */
176/* These flags are used to determine which operands are returned during
177 execution of the loop. */
178#define SSA_OP_USE 0x01 /* Real USE operands. */
179#define SSA_OP_DEF 0x02 /* Real DEF operands. */
180#define SSA_OP_VUSE 0x04 /* VUSE operands. */
181#define SSA_OP_VDEF 0x08 /* VDEF operands. */
182/* These are commonly grouped operand flags. */
183#define SSA_OP_VIRTUAL_USES (SSA_OP_VUSE)
184#define SSA_OP_VIRTUAL_DEFS (SSA_OP_VDEF)
185#define SSA_OP_ALL_VIRTUALS (SSA_OP_VIRTUAL_USES | SSA_OP_VIRTUAL_DEFS)
186#define SSA_OP_ALL_USES (SSA_OP_VIRTUAL_USES | SSA_OP_USE)
187#define SSA_OP_ALL_DEFS (SSA_OP_VIRTUAL_DEFS | SSA_OP_DEF)
188#define SSA_OP_ALL_OPERANDS (SSA_OP_ALL_USES | SSA_OP_ALL_DEFS)
189
190/* This macro executes a loop over the operands of STMT specified in FLAG,
191 returning each operand as a 'tree' in the variable TREEVAR. ITER is an
192 ssa_op_iter structure used to control the loop. */
193#define FOR_EACH_SSA_TREE_OPERAND(TREEVAR, STMT, ITER, FLAGS) \
194 for (TREEVAR = op_iter_init_tree (&(ITER), STMT, FLAGS); \
195 !op_iter_done (&(ITER)); \
196 (void) (TREEVAR = op_iter_next_tree (&(ITER))))
197
198/* This macro executes a loop over the operands of STMT specified in FLAG,
199 returning each operand as a 'use_operand_p' in the variable USEVAR.
200 ITER is an ssa_op_iter structure used to control the loop. */
201#define FOR_EACH_SSA_USE_OPERAND(USEVAR, STMT, ITER, FLAGS) \
202 for (USEVAR = op_iter_init_use (&(ITER), STMT, FLAGS); \
203 !op_iter_done (&(ITER)); \
204 USEVAR = op_iter_next_use (&(ITER)))
205
206/* This macro executes a loop over the operands of STMT specified in FLAG,
207 returning each operand as a 'def_operand_p' in the variable DEFVAR.
208 ITER is an ssa_op_iter structure used to control the loop. */
209#define FOR_EACH_SSA_DEF_OPERAND(DEFVAR, STMT, ITER, FLAGS) \
210 for (DEFVAR = op_iter_init_def (&(ITER), STMT, FLAGS); \
211 !op_iter_done (&(ITER)); \
212 DEFVAR = op_iter_next_def (&(ITER)))
213
214/* This macro will execute a loop over all the arguments of a PHI which
215 match FLAGS. A use_operand_p is always returned via USEVAR. FLAGS
216 can be either SSA_OP_USE or SSA_OP_VIRTUAL_USES or SSA_OP_ALL_USES. */
217#define FOR_EACH_PHI_ARG(USEVAR, STMT, ITER, FLAGS) \
218 for ((USEVAR) = op_iter_init_phiuse (&(ITER), STMT, FLAGS); \
219 !op_iter_done (&(ITER)); \
220 (USEVAR) = op_iter_next_use (&(ITER)))
221
222
223/* This macro will execute a loop over a stmt, regardless of whether it is
224 a real stmt or a PHI node, looking at the USE nodes matching FLAGS. */
225#define FOR_EACH_PHI_OR_STMT_USE(USEVAR, STMT, ITER, FLAGS) \
226 for ((USEVAR) = (gimple_code (STMT) == GIMPLE_PHI \
227 ? op_iter_init_phiuse (&(ITER), \
228 as_a <gphi *> (STMT), \
229 FLAGS) \
230 : op_iter_init_use (&(ITER), STMT, FLAGS)); \
231 !op_iter_done (&(ITER)); \
232 (USEVAR) = op_iter_next_use (&(ITER)))
233
234/* This macro will execute a loop over a stmt, regardless of whether it is
235 a real stmt or a PHI node, looking at the DEF nodes matching FLAGS. */
236#define FOR_EACH_PHI_OR_STMT_DEF(DEFVAR, STMT, ITER, FLAGS) \
237 for ((DEFVAR) = (gimple_code (STMT) == GIMPLE_PHI \
238 ? op_iter_init_phidef (&(ITER), \
239 as_a <gphi *> (STMT), \
240 FLAGS) \
241 : op_iter_init_def (&(ITER), STMT, FLAGS)); \
242 !op_iter_done (&(ITER)); \
243 (DEFVAR) = op_iter_next_def (&(ITER)))
244
245/* This macro returns an operand in STMT as a tree if it is the ONLY
246 operand matching FLAGS. If there are 0 or more than 1 operand matching
247 FLAGS, then NULL_TREE is returned. */
248#define SINGLE_SSA_TREE_OPERAND(STMT, FLAGS) \
249 single_ssa_tree_operand (STMT, FLAGS)
250
251/* This macro returns an operand in STMT as a use_operand_p if it is the ONLY
252 operand matching FLAGS. If there are 0 or more than 1 operand matching
253 FLAGS, then NULL_USE_OPERAND_P is returned. */
254#define SINGLE_SSA_USE_OPERAND(STMT, FLAGS) \
255 single_ssa_use_operand (STMT, FLAGS)
256
257/* This macro returns an operand in STMT as a def_operand_p if it is the ONLY
258 operand matching FLAGS. If there are 0 or more than 1 operand matching
259 FLAGS, then NULL_DEF_OPERAND_P is returned. */
260#define SINGLE_SSA_DEF_OPERAND(STMT, FLAGS) \
261 single_ssa_def_operand (STMT, FLAGS)
262
263/* This macro returns TRUE if there are no operands matching FLAGS in STMT. */
264#define ZERO_SSA_OPERANDS(STMT, FLAGS) zero_ssa_operands (STMT, FLAGS)
265
266/* This macro counts the number of operands in STMT matching FLAGS. */
267#define NUM_SSA_OPERANDS(STMT, FLAGS) num_ssa_operands (STMT, FLAGS)
268
269
270/* Delink an immediate_uses node from its chain. */
271inline void
273{
274 /* Return if this node is not in a list. */
275 if (linknode->prev == NULL)
276 return;
277
278#if defined ENABLE_GIMPLE_CHECKING
279 if (linknode->loc.stmt
280 /* update_stmt on constant/removed uses. */
281 && USE_FROM_PTR (linknode)
282 && TREE_CODE (USE_FROM_PTR (linknode)) == SSA_NAME)
283 {
284 tree var = USE_FROM_PTR (linknode);
285 gcc_assert (var->ssa_name.fast_iteration_depth == 0
286 && (var->ssa_name.active_iterated_stmt == NULL
287 || (var->ssa_name.active_iterated_stmt
288 == linknode->loc.stmt)));
289 }
290#endif
291
292 linknode->prev->next = linknode->next;
293 linknode->next->prev = linknode->prev;
294 linknode->prev = NULL;
295 linknode->next = NULL;
296}
297
298/* Link ssa_imm_use node LINKNODE into the chain for LIST. */
299inline void
301{
302 /* Link the new node at the head of the list. If we are in the process of
303 traversing the list, we won't visit any new nodes added to it. */
304 linknode->prev = list;
305 linknode->next = list->next;
306 list->next->prev = linknode;
307 list->next = linknode;
308}
309
310/* Link ssa_imm_use node LINKNODE into the chain for DEF. */
311inline void
313{
314 ssa_use_operand_t *root;
315
316 if (!def || TREE_CODE (def) != SSA_NAME)
317 linknode->prev = NULL;
318 else
319 {
320 root = &(SSA_NAME_IMM_USE_NODE (def));
321 if (linknode->use)
322 gcc_checking_assert (*(linknode->use) == def);
323 link_imm_use_to_list (linknode, root);
324 }
325}
326
327/* Set the value of a use pointed to by USE to VAL. */
328inline void
330{
332 *(use->use) = val;
333 link_imm_use (use, val);
334}
335
336/* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
337 in STMT. */
338inline void
340{
341 if (stmt)
342 link_imm_use (linknode, def);
343 else
344 link_imm_use (linknode, NULL);
345 linknode->loc.stmt = stmt;
346}
347
348/* Relink a new node in place of an old node in the list. */
349inline void
351{
352 /* The node one had better be in the same list. */
353 gcc_checking_assert (*(old->use) == *(node->use));
354 node->prev = old->prev;
355 node->next = old->next;
356 if (old->prev)
357 {
358 old->prev->next = node;
359 old->next->prev = node;
360 /* Remove the old node from the list. */
361 old->prev = NULL;
362 }
363}
364
365/* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
366 in STMT. */
367inline void
369 gimple *stmt)
370{
371 if (stmt)
372 relink_imm_use (linknode, old);
373 else
374 link_imm_use (linknode, NULL);
375 linknode->loc.stmt = stmt;
376}
377
378
379/* Return true is IMM has reached the end of the immediate use list. */
380inline bool
382{
383 return (imm->imm_use == imm->end_p);
384}
385
386/* Initialize iterator IMM to process the list for VAR. */
387inline use_operand_p
389{
390#if defined ENABLE_GIMPLE_CHECKING
391 var->ssa_name.fast_iteration_depth++;
392#endif
393 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
394 imm->imm_use = imm->end_p->next;
395 imm->next_stmt_use = imm->imm_use->next;
396 imm->name = var;
397 if (end_readonly_imm_use_p (imm))
398 return NULL_USE_OPERAND_P;
399 return imm->imm_use;
400}
401
402/* Bump IMM to the next use in the list. */
403inline use_operand_p
405{
406 use_operand_p old = imm->imm_use;
407
408 /* If this assertion fails, it indicates the 'next' pointer has changed
409 since the last bump. This indicates that the list is being modified
410 via stmt changes, or SET_USE, or somesuch thing, and you need to be
411 using the SAFE version of the iterator. */
412 if (flag_checking)
413 {
414 gcc_assert (imm->next_stmt_use == old->next);
415 imm->next_stmt_use = old->next->next;
416 }
417
418 imm->imm_use = old->next;
419 if (end_readonly_imm_use_p (imm))
420 return NULL_USE_OPERAND_P;
421 return imm->imm_use;
422}
423
424
425/* Return true if VAR has no nondebug uses. */
426inline bool
428{
429 const ssa_use_operand_t *const head = &(SSA_NAME_IMM_USE_NODE (var));
430 const ssa_use_operand_t *ptr;
431
432 for (ptr = head->next; ptr != head; ptr = ptr->next)
433 if (USE_STMT (ptr) && !is_gimple_debug (USE_STMT (ptr)))
434 return false;
435
436 return true;
437}
438
439/* Return true if VAR has a single nondebug use. */
440inline bool
442{
443 const ssa_use_operand_t *const head = &(SSA_NAME_IMM_USE_NODE (var));
444 const ssa_use_operand_t *ptr;
445 bool single = false;
446
447 for (ptr = head->next; ptr != head; ptr = ptr->next)
448 if (USE_STMT(ptr) && !is_gimple_debug (USE_STMT (ptr)))
449 {
450 if (single)
451 return false;
452 else
453 single = true;
454 }
455
456 return single;
457}
458
459/* If VAR has only a single immediate nondebug use, return true, and
460 set USE_P and STMT to the use pointer and stmt of occurrence. */
461inline bool
463{
464 const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
465
466 /* If there aren't any uses whatsoever, we're done. */
467 if (ptr == ptr->next)
468 {
470 *use_p = NULL_USE_OPERAND_P;
471 *stmt = NULL;
472 return false;
473 }
474
475 /* If there's a single use, check that it's not a debug stmt. */
476 if (ptr == ptr->next->next)
477 {
478 if (USE_STMT (ptr->next) && !is_gimple_debug (USE_STMT (ptr->next)))
479 {
480 *use_p = ptr->next;
481 *stmt = ptr->next->loc.stmt;
482 return true;
483 }
484 else
485 goto return_false;
486 }
487
488 return single_imm_use_1 (ptr, use_p, stmt);
489}
490
491/* Return the number of nondebug immediate uses of VAR. */
492inline unsigned int
494{
495 const ssa_use_operand_t *const start = &(SSA_NAME_IMM_USE_NODE (var));
496 const ssa_use_operand_t *ptr;
497 unsigned int num = 0;
498
500 {
501 for (ptr = start->next; ptr != start; ptr = ptr->next)
502 if (USE_STMT (ptr))
503 num++;
504 }
505 else
506 for (ptr = start->next; ptr != start; ptr = ptr->next)
507 if (USE_STMT (ptr) && !is_gimple_debug (USE_STMT (ptr)))
508 num++;
509
510 return num;
511}
512
513/* ----------------------------------------------------------------------- */
514
515/* The following set of routines are used to iterator over various type of
516 SSA operands. */
517
518/* Return true if PTR is finished iterating. */
519inline bool
521{
522 return ptr->done;
523}
524
525/* Get the next iterator use value for PTR. */
526inline use_operand_p
528{
529 use_operand_p use_p;
531 if (ptr->uses)
532 {
533 use_p = USE_OP_PTR (ptr->uses);
534 ptr->uses = ptr->uses->next;
535 return use_p;
536 }
537 if (ptr->i < ptr->numops)
538 {
539 return PHI_ARG_DEF_PTR (ptr->stmt, (ptr->i)++);
540 }
541 ptr->done = true;
542 return NULL_USE_OPERAND_P;
543}
544
545/* Get the next iterator def value for PTR. */
546inline def_operand_p
548{
550 if (ptr->flags & SSA_OP_VDEF)
551 {
552 tree *p;
553 ptr->flags &= ~SSA_OP_VDEF;
554 p = gimple_vdef_ptr (ptr->stmt);
555 if (p && *p)
556 return p;
557 }
558 if (ptr->flags & SSA_OP_DEF)
559 {
560 while (ptr->i < ptr->numops)
561 {
562 tree *val = gimple_op_ptr (ptr->stmt, ptr->i);
563 ptr->i++;
564 if (*val)
565 {
566 if (TREE_CODE (*val) == TREE_LIST)
567 val = &TREE_VALUE (*val);
568 if (TREE_CODE (*val) == SSA_NAME
569 || is_gimple_reg (*val))
570 return val;
571 }
572 }
573 ptr->flags &= ~SSA_OP_DEF;
574 }
575
576 ptr->done = true;
577 return NULL_DEF_OPERAND_P;
578}
579
580/* Get the next iterator tree value for PTR. */
581inline tree
583{
584 tree val;
586 if (ptr->uses)
587 {
588 val = USE_OP (ptr->uses);
589 ptr->uses = ptr->uses->next;
590 return val;
591 }
592 if (ptr->flags & SSA_OP_VDEF)
593 {
594 ptr->flags &= ~SSA_OP_VDEF;
595 if ((val = gimple_vdef (ptr->stmt)))
596 return val;
597 }
598 if (ptr->flags & SSA_OP_DEF)
599 {
600 while (ptr->i < ptr->numops)
601 {
602 val = gimple_op (ptr->stmt, ptr->i);
603 ptr->i++;
604 if (val)
605 {
606 if (TREE_CODE (val) == TREE_LIST)
607 val = TREE_VALUE (val);
608 if (TREE_CODE (val) == SSA_NAME
609 || is_gimple_reg (val))
610 return val;
611 }
612 }
613 ptr->flags &= ~SSA_OP_DEF;
614 }
615
616 ptr->done = true;
617 return NULL_TREE;
618}
619
620
621/* This functions clears the iterator PTR, and marks it done. This is normally
622 used to prevent warnings in the compile about might be uninitialized
623 components. */
624
625inline void
627{
628 ptr->i = 0;
629 ptr->numops = 0;
630 ptr->uses = NULL;
632 ptr->stmt = NULL;
633 ptr->done = true;
634 ptr->flags = 0;
635}
636
637/* Initialize the iterator PTR to the virtual defs in STMT. */
638inline void
639op_iter_init (ssa_op_iter *ptr, gimple *stmt, int flags)
640{
641 /* PHI nodes require a different iterator initialization path. We
642 do not support iterating over virtual defs or uses without
643 iterating over defs or uses at the same time. */
644 gcc_checking_assert (gimple_code (stmt) != GIMPLE_PHI
645 && (!(flags & SSA_OP_VDEF) || (flags & SSA_OP_DEF))
646 && (!(flags & SSA_OP_VUSE) || (flags & SSA_OP_USE)));
647 ptr->numops = 0;
648 if (flags & (SSA_OP_DEF | SSA_OP_VDEF))
649 {
650 switch (gimple_code (stmt))
651 {
652 case GIMPLE_ASSIGN:
653 case GIMPLE_CALL:
654 ptr->numops = 1;
655 break;
656 case GIMPLE_ASM:
658 break;
659 case GIMPLE_TRANSACTION:
660 ptr->numops = 0;
661 flags &= ~SSA_OP_DEF;
662 break;
663 default:
664 ptr->numops = 0;
665 flags &= ~(SSA_OP_DEF | SSA_OP_VDEF);
666 break;
667 }
668 }
669 ptr->uses = (flags & (SSA_OP_USE|SSA_OP_VUSE)) ? gimple_use_ops (stmt) : NULL;
670 if (!(flags & SSA_OP_VUSE)
671 && ptr->uses
672 && gimple_vuse (stmt) != NULL_TREE)
673 ptr->uses = ptr->uses->next;
674 ptr->done = false;
675 ptr->i = 0;
676
677 ptr->stmt = stmt;
678 ptr->flags = flags;
679}
680
681/* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
682 the first use. */
683inline use_operand_p
684op_iter_init_use (ssa_op_iter *ptr, gimple *stmt, int flags)
685{
687 && (flags & SSA_OP_USE));
688 op_iter_init (ptr, stmt, flags);
690 return op_iter_next_use (ptr);
691}
692
693/* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
694 the first def. */
695inline def_operand_p
696op_iter_init_def (ssa_op_iter *ptr, gimple *stmt, int flags)
697{
699 && (flags & SSA_OP_DEF));
700 op_iter_init (ptr, stmt, flags);
702 return op_iter_next_def (ptr);
703}
704
705/* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
706 the first operand as a tree. */
707inline tree
708op_iter_init_tree (ssa_op_iter *ptr, gimple *stmt, int flags)
709{
710 op_iter_init (ptr, stmt, flags);
712 return op_iter_next_tree (ptr);
713}
714
715
716/* If there is a single operand in STMT matching FLAGS, return it. Otherwise
717 return NULL. */
718inline tree
720{
721 tree var;
722 ssa_op_iter iter;
723
724 var = op_iter_init_tree (&iter, stmt, flags);
725 if (op_iter_done (&iter))
726 return NULL_TREE;
727 op_iter_next_tree (&iter);
728 if (op_iter_done (&iter))
729 return var;
730 return NULL_TREE;
731}
732
733
734/* If there is a single operand in STMT matching FLAGS, return it. Otherwise
735 return NULL. */
736inline use_operand_p
738{
739 use_operand_p var;
740 ssa_op_iter iter;
741
742 var = op_iter_init_use (&iter, stmt, flags);
743 if (op_iter_done (&iter))
744 return NULL_USE_OPERAND_P;
745 op_iter_next_use (&iter);
746 if (op_iter_done (&iter))
747 return var;
748 return NULL_USE_OPERAND_P;
749}
750
751/* Return the single virtual use operand in STMT if present. Otherwise
752 return NULL. */
753inline use_operand_p
755{
756 if (! gimple_vuse (stmt))
757 return NULL_USE_OPERAND_P;
758 return USE_OP_PTR (gimple_use_ops (stmt));
759}
760
761
762/* If there is a single operand in STMT matching FLAGS, return it. Otherwise
763 return NULL. */
764inline def_operand_p
766{
767 def_operand_p var;
768 ssa_op_iter iter;
769
770 var = op_iter_init_def (&iter, stmt, flags);
771 if (op_iter_done (&iter))
772 return NULL_DEF_OPERAND_P;
773 op_iter_next_def (&iter);
774 if (op_iter_done (&iter))
775 return var;
776 return NULL_DEF_OPERAND_P;
777}
778
779
780/* Return true if there are zero operands in STMT matching the type
781 given in FLAGS. */
782inline bool
783zero_ssa_operands (gimple *stmt, int flags)
784{
785 ssa_op_iter iter;
786
787 op_iter_init_tree (&iter, stmt, flags);
788 return op_iter_done (&iter);
789}
790
791
792/* Return the number of operands matching FLAGS in STMT. */
793inline int
794num_ssa_operands (gimple *stmt, int flags)
795{
796 ssa_op_iter iter;
797 tree t;
798 int num = 0;
799
800 gcc_checking_assert (gimple_code (stmt) != GIMPLE_PHI);
801 FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
802 num++;
803 return num;
804}
805
806/* If there is a single DEF in the PHI node which matches FLAG, return it.
807 Otherwise return NULL_DEF_OPERAND_P. */
808inline tree
809single_phi_def (gphi *stmt, int flags)
810{
811 tree def = gimple_phi_result (stmt);
812 if ((flags & SSA_OP_DEF) && is_gimple_reg (def))
813 return def;
814 if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
815 return def;
816 return NULL_TREE;
817}
818
819/* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
820 be either SSA_OP_USES or SSA_OP_VIRTUAL_USES. */
821inline use_operand_p
822op_iter_init_phiuse (ssa_op_iter *ptr, gphi *phi, int flags)
823{
824 tree phi_def = gimple_phi_result (phi);
825 int comp;
826
828 ptr->done = false;
829
831
833
834 /* If the PHI node doesn't the operand type we care about, we're done. */
835 if ((flags & comp) == 0)
836 {
837 ptr->done = true;
838 return NULL_USE_OPERAND_P;
839 }
840
841 ptr->stmt = phi;
842 ptr->numops = gimple_phi_num_args (phi);
844 ptr->flags = flags;
845 return op_iter_next_use (ptr);
846}
847
848
849/* Start an iterator for a PHI definition. */
850
851inline def_operand_p
852op_iter_init_phidef (ssa_op_iter *ptr, gphi *phi, int flags)
853{
854 tree phi_def = gimple_phi_result (phi);
855 int comp;
856
858 ptr->done = false;
859
861
863
864 /* If the PHI node doesn't have the operand type we care about,
865 we're done. */
866 if ((flags & comp) == 0)
867 {
868 ptr->done = true;
869 return NULL_DEF_OPERAND_P;
870 }
871
873 /* The first call to op_iter_next_def will terminate the iterator since
874 all the fields are NULL. Simply return the result here as the first and
875 therefore only result. */
876 return gimple_phi_result_ptr (phi);
877}
878
879/* Return true is IMM has reached the end of the immediate use stmt list. */
880
881inline bool
883{
884 return (imm->imm_use == imm->end_p);
885}
886
887/* Finished the traverse of an immediate use stmt list IMM by removing the
888 placeholder node from the list. */
889
890inline void
892{
893#if defined ENABLE_GIMPLE_CHECKING
894 imm->name->ssa_name.active_iterated_stmt = NULL;
895#endif
896}
897
898/* Immediate use traversal of uses within a stmt require that all the
899 uses on a stmt be sequentially listed. This routine is used to build up
900 this sequential list by adding USE_P to the end of the current list
901 currently delimited by HEAD and LAST_P. The new LAST_P value is
902 returned. */
903
904inline use_operand_p
906 use_operand_p last_p)
907{
909 /* Skip head when we find it. */
910 if (use_p != head)
911 {
912 /* If use_p is already linked in after last_p, continue. */
913 if (last_p->next == use_p)
914 last_p = use_p;
915 else
916 {
917 /* Delink from current location, and link in at last_p. */
918 delink_imm_use (use_p);
919 link_imm_use_to_list (use_p, last_p);
920 last_p = use_p;
921 }
922 }
923 return last_p;
924}
925
926
927/* This routine will relink all uses with the same stmt as HEAD into the list
928 immediately following HEAD for iterator IMM and returns the last use on
929 that stmt. */
930
931inline use_operand_p
933{
934 use_operand_p use_p;
935 use_operand_p last_p = head;
936 gimple *head_stmt = USE_STMT (head);
938 ssa_op_iter op_iter;
939 int flag;
940
941 /* Only look at virtual or real uses, depending on the type of HEAD. */
943
944 if (gphi *phi = dyn_cast <gphi *> (head_stmt))
945 {
946 FOR_EACH_PHI_ARG (use_p, phi, op_iter, flag)
947 if (USE_FROM_PTR (use_p) == use)
948 last_p = move_use_after_head (use_p, head, last_p);
949 }
950 else
951 {
952 if (flag == SSA_OP_USE)
953 {
954 FOR_EACH_SSA_USE_OPERAND (use_p, head_stmt, op_iter, flag)
955 if (USE_FROM_PTR (use_p) == use)
956 last_p = move_use_after_head (use_p, head, last_p);
957 }
958 else if ((use_p = gimple_vuse_op (head_stmt)) != NULL_USE_OPERAND_P)
959 {
960 if (USE_FROM_PTR (use_p) == use)
961 last_p = move_use_after_head (use_p, head, last_p);
962 }
963 }
964 return last_p;
965}
966
967/* Initialize IMM to traverse over uses of VAR. Return the first statement. */
968inline gimple *
970{
971#if defined ENABLE_GIMPLE_CHECKING
972 gcc_assert (var->ssa_name.active_iterated_stmt == NULL
973 && var->ssa_name.fast_iteration_depth == 0);
974#endif
975 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
976 imm->imm_use = imm->end_p->next;
978
979 /* next_stmt_use is used to point to the immediate use node after
980 the set of uses for the current stmt. */
982 imm->name = var;
983
984 if (end_imm_use_stmt_p (imm))
985 return NULL;
986
988
989#if defined ENABLE_GIMPLE_CHECKING
990 var->ssa_name.active_iterated_stmt = USE_STMT (imm->imm_use);
991#endif
992 return USE_STMT (imm->imm_use);
993}
994
995/* Bump IMM to the next stmt which has a use of var. */
996
997inline gimple *
999{
1000 imm->imm_use = imm->next_stmt_use;
1001 if (end_imm_use_stmt_p (imm))
1002 return NULL;
1003
1004#if defined ENABLE_GIMPLE_CHECKING
1005 imm->name->ssa_name.active_iterated_stmt = USE_STMT (imm->imm_use);
1006#endif
1007 imm->next_stmt_use = link_use_stmts_after (imm->imm_use, imm)->next;
1008 return USE_STMT (imm->imm_use);
1009}
1010
1011/* This routine will return the first use on the stmt IMM currently refers
1012 to. */
1013
1014inline use_operand_p
1016{
1017 imm->next_imm_name = imm->imm_use->next;
1018 return imm->imm_use;
1019}
1020
1021/* Return TRUE if the last use on the stmt IMM refers to has been visited. */
1022
1023inline bool
1025{
1026 return (imm->imm_use == imm->next_stmt_use);
1027}
1028
1029/* Bump to the next use on the stmt IMM refers to, return NULL if done. */
1030
1031inline use_operand_p
1033{
1034 imm->imm_use = imm->next_imm_name;
1035 if (end_imm_use_on_stmt_p (imm))
1036 return NULL_USE_OPERAND_P;
1037 else
1038 {
1039 imm->next_imm_name = imm->imm_use->next;
1040 return imm->imm_use;
1041 }
1042}
1043
1044/* Delink all immediate_use information for STMT. */
1045inline void
1047{
1048 ssa_op_iter iter;
1049 use_operand_p use_p;
1050
1052 FOR_EACH_PHI_OR_STMT_USE (use_p, stmt, iter, SSA_OP_ALL_USES)
1053 delink_imm_use (use_p);
1054}
1055
1056#endif /* GCC_TREE_SSA_ITERATORS_H */
Definition vec.h:1667
const union tree_node * const_tree
Definition coretypes.h:98
union tree_node * tree
Definition coretypes.h:97
#define cfun
Definition function.h:480
static sbitmap * comp
Definition gcse.cc:1732
bool is_gimple_reg(tree t)
Definition gimple-expr.cc:790
use_operand_p gimple_vuse_op(const gimple *g)
Definition gimple-ssa.h:141
tree * gimple_op_ptr(gimple *gs, unsigned i)
Definition gimple.h:2571
tree * gimple_vdef_ptr(gimple *g)
Definition gimple.h:2218
tree gimple_op(const gimple *gs, unsigned i)
Definition gimple.h:2557
tree gimple_vdef(const gimple *g)
Definition gimple.h:2194
gimple_code
Definition gimple.h:30
unsigned gimple_asm_noutputs(const gasm *asm_stmt)
Definition gimple.h:4068
tree gimple_phi_result(const gphi *gs)
Definition gimple.h:4599
struct use_optype_d * gimple_use_ops(const gimple *g)
Definition gimple.h:2158
bool is_gimple_debug(const gimple *gs)
Definition gimple.h:4950
tree * gimple_phi_result_ptr(gphi *gs)
Definition gimple.h:4614
tree gimple_vuse(const gimple *g)
Definition gimple.h:2182
unsigned gimple_phi_num_args(const gimple *gs)
Definition gimple.h:4589
#define return_false()
Definition ipa-icf-gimple.h:57
T as_a(U *p)
Definition is-a.h:253
T dyn_cast(U *p)
Definition is-a.h:280
Definition custom-sarif-properties/state-graphs.h:33
def_operand_p op_iter_next_def(ssa_op_iter *ptr)
Definition ssa-iterators.h:547
use_operand_p first_imm_use_on_stmt(imm_use_iterator *imm)
Definition ssa-iterators.h:1015
#define SSA_OP_USE
Definition ssa-iterators.h:178
#define SSA_OP_VUSE
Definition ssa-iterators.h:180
void link_imm_use_stmt(ssa_use_operand_t *linknode, tree def, gimple *stmt)
Definition ssa-iterators.h:339
void end_imm_use_stmt_traverse(imm_use_iterator *)
use_operand_p first_readonly_imm_use(imm_use_iterator *imm, tree var)
Definition ssa-iterators.h:388
void delink_stmt_imm_use(gimple *stmt)
Definition ssa-iterators.h:1046
bool single_imm_use(const_tree var, use_operand_p *use_p, gimple **stmt)
Definition ssa-iterators.h:462
gimple * first_imm_use_stmt(imm_use_iterator *imm, tree var)
Definition ssa-iterators.h:969
void clear_and_done_ssa_iter(ssa_op_iter *ptr)
Definition ssa-iterators.h:626
#define SSA_OP_VIRTUAL_DEFS
Definition ssa-iterators.h:184
bool has_zero_uses(const_tree var)
Definition ssa-iterators.h:427
#define SSA_OP_VDEF
Definition ssa-iterators.h:181
use_operand_p op_iter_init_phiuse(ssa_op_iter *ptr, gphi *phi, int flags)
Definition ssa-iterators.h:822
use_operand_p next_imm_use_on_stmt(imm_use_iterator *imm)
Definition ssa-iterators.h:1032
void relink_imm_use(ssa_use_operand_t *node, ssa_use_operand_t *old)
Definition ssa-iterators.h:350
#define SSA_OP_VIRTUAL_USES
Definition ssa-iterators.h:183
use_operand_p op_iter_next_use(ssa_op_iter *ptr)
Definition ssa-iterators.h:527
ssa_op_iter_type
Definition ssa-iterators.h:152
@ ssa_op_iter_none
Definition ssa-iterators.h:153
@ ssa_op_iter_use
Definition ssa-iterators.h:155
@ ssa_op_iter_tree
Definition ssa-iterators.h:154
@ ssa_op_iter_def
Definition ssa-iterators.h:156
use_operand_p single_ssa_use_operand(gimple *stmt, int flags)
Definition ssa-iterators.h:737
tree op_iter_init_tree(ssa_op_iter *ptr, gimple *stmt, int flags)
Definition ssa-iterators.h:708
use_operand_p move_use_after_head(use_operand_p use_p, use_operand_p head, use_operand_p last_p)
Definition ssa-iterators.h:905
bool end_imm_use_on_stmt_p(const imm_use_iterator *imm)
Definition ssa-iterators.h:1024
#define FOR_EACH_SSA_USE_OPERAND(USEVAR, STMT, ITER, FLAGS)
Definition ssa-iterators.h:201
bool zero_ssa_operands(gimple *stmt, int flags)
Definition ssa-iterators.h:783
#define FOR_EACH_SSA_TREE_OPERAND(TREEVAR, STMT, ITER, FLAGS)
Definition ssa-iterators.h:193
gimple * next_imm_use_stmt(imm_use_iterator *imm)
Definition ssa-iterators.h:998
#define FOR_EACH_PHI_ARG(USEVAR, STMT, ITER, FLAGS)
Definition ssa-iterators.h:217
tree single_phi_def(gphi *stmt, int flags)
Definition ssa-iterators.h:809
def_operand_p op_iter_init_def(ssa_op_iter *ptr, gimple *stmt, int flags)
Definition ssa-iterators.h:696
use_operand_p next_readonly_imm_use(imm_use_iterator *imm)
Definition ssa-iterators.h:404
use_operand_p ssa_vuse_operand(gimple *stmt)
Definition ssa-iterators.h:754
void op_iter_init(ssa_op_iter *ptr, gimple *stmt, int flags)
Definition ssa-iterators.h:639
unsigned int num_imm_uses(const_tree var)
Definition ssa-iterators.h:493
void relink_imm_use_stmt(ssa_use_operand_t *linknode, ssa_use_operand_t *old, gimple *stmt)
Definition ssa-iterators.h:368
void set_ssa_use_from_ptr(use_operand_p use, tree val)
Definition ssa-iterators.h:329
use_operand_p op_iter_init_use(ssa_op_iter *ptr, gimple *stmt, int flags)
Definition ssa-iterators.h:684
void link_imm_use(ssa_use_operand_t *linknode, tree def)
Definition ssa-iterators.h:312
#define SSA_OP_ALL_DEFS
Definition ssa-iterators.h:187
void link_imm_use_to_list(ssa_use_operand_t *linknode, ssa_use_operand_t *list)
Definition ssa-iterators.h:300
bool has_single_use(const_tree var)
Definition ssa-iterators.h:441
#define SSA_OP_ALL_USES
Definition ssa-iterators.h:186
bool end_readonly_imm_use_p(const imm_use_iterator *imm)
Definition ssa-iterators.h:381
def_operand_p single_ssa_def_operand(gimple *stmt, int flags)
Definition ssa-iterators.h:765
def_operand_p op_iter_init_phidef(ssa_op_iter *ptr, gphi *phi, int flags)
Definition ssa-iterators.h:852
#define SSA_OP_DEF
Definition ssa-iterators.h:179
void delink_imm_use(ssa_use_operand_t *linknode)
Definition ssa-iterators.h:272
#define FOR_EACH_PHI_OR_STMT_USE(USEVAR, STMT, ITER, FLAGS)
Definition ssa-iterators.h:225
bool end_imm_use_stmt_p(const imm_use_iterator *imm)
Definition ssa-iterators.h:882
use_operand_p link_use_stmts_after(use_operand_p head, imm_use_iterator *)
Definition ssa-iterators.h:932
bool single_imm_use_1(const ssa_use_operand_t *head, use_operand_p *use_p, gimple **stmt)
Definition tree-ssa-operands.cc:1394
tree op_iter_next_tree(ssa_op_iter *ptr)
Definition ssa-iterators.h:582
tree single_ssa_tree_operand(gimple *stmt, int flags)
Definition ssa-iterators.h:719
auto_vec< gimple *, 2 > gather_imm_use_stmts(tree ssavar)
Definition tree-ssa-operands.cc:1422
bool op_iter_done(const ssa_op_iter *ptr)
Definition ssa-iterators.h:520
int num_ssa_operands(gimple *stmt, int flags)
Definition ssa-iterators.h:794
~auto_end_imm_use_stmt_traverse()
Definition ssa-iterators.h:107
auto_end_imm_use_stmt_traverse(imm_use_iterator *imm)
Definition ssa-iterators.h:105
imm_use_iterator * imm
Definition ssa-iterators.h:104
Definition loop-invariant.cc:88
Definition gimple.h:221
Definition gimple.h:461
Definition collect2.cc:175
Definition ssa-iterators.h:51
ssa_use_operand_t * next_stmt_use
Definition ssa-iterators.h:58
ssa_use_operand_t * end_p
Definition ssa-iterators.h:55
ssa_use_operand_t * imm_use
Definition ssa-iterators.h:53
ssa_use_operand_t * next_imm_name
Definition ssa-iterators.h:61
tree name
Definition ssa-iterators.h:63
Definition ssa-iterators.h:165
unsigned numops
Definition ssa-iterators.h:170
unsigned i
Definition ssa-iterators.h:169
bool done
Definition ssa-iterators.h:167
int flags
Definition ssa-iterators.h:168
gimple * stmt
Definition ssa-iterators.h:172
use_optype_p uses
Definition ssa-iterators.h:171
enum ssa_op_iter_type iter_type
Definition ssa-iterators.h:166
Definition tree-core.h:1687
union ssa_use_operand_t::@367230375271135120343303147343174306203144124205 loc
gimple * stmt
Definition tree-core.h:1695
tree ssa_name
Definition tree-core.h:1695
tree * use
Definition tree-core.h:1696
struct ssa_use_operand_t * prev
Definition tree-core.h:1688
struct ssa_use_operand_t * next
Definition tree-core.h:1689
struct use_optype_d * next
Definition tree-ssa-operands.h:39
Definition loop-invariant.cc:78
#define NULL
Definition system.h:50
#define gcc_assert(EXPR)
Definition system.h:814
#define gcc_checking_assert(EXPR)
Definition system.h:821
bool ssa_operands_active(struct function *fun)
Definition tree-ssa-operands.cc:219
tree * def_operand_p
Definition tree-ssa-operands.h:27
struct use_optype_d * use_optype_p
Definition tree-ssa-operands.h:42
#define USE_FROM_PTR(PTR)
Definition tree-ssa-operands.h:65
#define USE_STMT(USE)
Definition tree-ssa-operands.h:70
ssa_use_operand_t * use_operand_p
Definition tree-ssa-operands.h:30
#define USE_OP(OP)
Definition tree-ssa-operands.h:73
#define USE_OP_PTR(OP)
Definition tree-ssa-operands.h:72
#define PHI_ARG_DEF_PTR(PHI, I)
Definition tree-ssa-operands.h:77
#define NULL_USE_OPERAND_P
Definition tree-ssa-operands.h:33
#define NULL_DEF_OPERAND_P
Definition tree-ssa-operands.h:34
#define TREE_VALUE(NODE)
Definition tree.h:1241
#define MAY_HAVE_DEBUG_BIND_STMTS
Definition tree.h:1333
#define SSA_NAME_IMM_USE_NODE(NODE)
Definition tree.h:2248
#define TREE_CODE(NODE)
Definition tree.h:325
#define NULL_TREE
Definition tree.h:318