Merged r158907 through r159238 into branch.
[official-gcc.git] / gcc / tree-flow-inline.h
blobf7609ea7911cc51e7108586bbe3ccb283c4f9610
1 /* Inline functions for tree-flow.h
2 Copyright (C) 2001, 2003, 2005, 2006, 2007, 2008, 2010
3 Free Software Foundation, Inc.
4 Contributed by Diego Novillo <dnovillo@redhat.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #ifndef _TREE_FLOW_INLINE_H
23 #define _TREE_FLOW_INLINE_H 1
25 /* Inline functions for manipulating various data structures defined in
26 tree-flow.h. See tree-flow.h for documentation. */
28 /* Return true when gimple SSA form was built.
29 gimple_in_ssa_p is queried by gimplifier in various early stages before SSA
30 infrastructure is initialized. Check for presence of the datastructures
31 at first place. */
32 static inline bool
33 gimple_in_ssa_p (const struct function *fun)
35 return fun && fun->gimple_df && fun->gimple_df->in_ssa_p;
38 /* Array of all variables referenced in the function. */
39 static inline htab_t
40 gimple_referenced_vars (const struct function *fun)
42 if (!fun->gimple_df)
43 return NULL;
44 return fun->gimple_df->referenced_vars;
47 /* Artificial variable used for the virtual operand FUD chain. */
48 static inline tree
49 gimple_vop (const struct function *fun)
51 gcc_assert (fun && fun->gimple_df);
52 return fun->gimple_df->vop;
55 /* Initialize the hashtable iterator HTI to point to hashtable TABLE */
57 static inline void *
58 first_htab_element (htab_iterator *hti, htab_t table)
60 hti->htab = table;
61 hti->slot = table->entries;
62 hti->limit = hti->slot + htab_size (table);
65 PTR x = *(hti->slot);
66 if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
67 break;
68 } while (++(hti->slot) < hti->limit);
70 if (hti->slot < hti->limit)
71 return *(hti->slot);
72 return NULL;
75 /* Return current non-empty/deleted slot of the hashtable pointed to by HTI,
76 or NULL if we have reached the end. */
78 static inline bool
79 end_htab_p (const htab_iterator *hti)
81 if (hti->slot >= hti->limit)
82 return true;
83 return false;
86 /* Advance the hashtable iterator pointed to by HTI to the next element of the
87 hashtable. */
89 static inline void *
90 next_htab_element (htab_iterator *hti)
92 while (++(hti->slot) < hti->limit)
94 PTR x = *(hti->slot);
95 if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
96 return x;
98 return NULL;
101 /* Initialize ITER to point to the first referenced variable in the
102 referenced_vars hashtable, and return that variable. */
104 static inline tree
105 first_referenced_var (referenced_var_iterator *iter)
107 return (tree) first_htab_element (&iter->hti,
108 gimple_referenced_vars (cfun));
111 /* Return true if we have hit the end of the referenced variables ITER is
112 iterating through. */
114 static inline bool
115 end_referenced_vars_p (const referenced_var_iterator *iter)
117 return end_htab_p (&iter->hti);
120 /* Make ITER point to the next referenced_var in the referenced_var hashtable,
121 and return that variable. */
123 static inline tree
124 next_referenced_var (referenced_var_iterator *iter)
126 return (tree) next_htab_element (&iter->hti);
129 /* Return the variable annotation for T, which must be a _DECL node.
130 Return NULL if the variable annotation doesn't already exist. */
131 static inline var_ann_t
132 var_ann (const_tree t)
134 const var_ann_t *p = DECL_VAR_ANN_PTR (t);
135 return p ? *p : NULL;
138 /* Return the variable annotation for T, which must be a _DECL node.
139 Create the variable annotation if it doesn't exist. */
140 static inline var_ann_t
141 get_var_ann (tree var)
143 var_ann_t *p = DECL_VAR_ANN_PTR (var);
144 gcc_assert (p);
145 return *p ? *p : create_var_ann (var);
148 /* Get the number of the next statement uid to be allocated. */
149 static inline unsigned int
150 gimple_stmt_max_uid (struct function *fn)
152 return fn->last_stmt_uid;
155 /* Set the number of the next statement uid to be allocated. */
156 static inline void
157 set_gimple_stmt_max_uid (struct function *fn, unsigned int maxid)
159 fn->last_stmt_uid = maxid;
162 /* Set the number of the next statement uid to be allocated. */
163 static inline unsigned int
164 inc_gimple_stmt_max_uid (struct function *fn)
166 return fn->last_stmt_uid++;
169 /* Return the line number for EXPR, or return -1 if we have no line
170 number information for it. */
171 static inline int
172 get_lineno (const_gimple stmt)
174 location_t loc;
176 if (!stmt)
177 return -1;
179 loc = gimple_location (stmt);
180 if (loc == UNKNOWN_LOCATION)
181 return -1;
183 return LOCATION_LINE (loc);
186 /* Delink an immediate_uses node from its chain. */
187 static inline void
188 delink_imm_use (ssa_use_operand_t *linknode)
190 /* Return if this node is not in a list. */
191 if (linknode->prev == NULL)
192 return;
194 linknode->prev->next = linknode->next;
195 linknode->next->prev = linknode->prev;
196 linknode->prev = NULL;
197 linknode->next = NULL;
200 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
201 static inline void
202 link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
204 /* Link the new node at the head of the list. If we are in the process of
205 traversing the list, we won't visit any new nodes added to it. */
206 linknode->prev = list;
207 linknode->next = list->next;
208 list->next->prev = linknode;
209 list->next = linknode;
212 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
213 static inline void
214 link_imm_use (ssa_use_operand_t *linknode, tree def)
216 ssa_use_operand_t *root;
218 if (!def || TREE_CODE (def) != SSA_NAME)
219 linknode->prev = NULL;
220 else
222 root = &(SSA_NAME_IMM_USE_NODE (def));
223 #ifdef ENABLE_CHECKING
224 if (linknode->use)
225 gcc_assert (*(linknode->use) == def);
226 #endif
227 link_imm_use_to_list (linknode, root);
231 /* Set the value of a use pointed to by USE to VAL. */
232 static inline void
233 set_ssa_use_from_ptr (use_operand_p use, tree val)
235 delink_imm_use (use);
236 *(use->use) = val;
237 link_imm_use (use, val);
240 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
241 in STMT. */
242 static inline void
243 link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, gimple stmt)
245 if (stmt)
246 link_imm_use (linknode, def);
247 else
248 link_imm_use (linknode, NULL);
249 linknode->loc.stmt = stmt;
252 /* Relink a new node in place of an old node in the list. */
253 static inline void
254 relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
256 /* The node one had better be in the same list. */
257 gcc_assert (*(old->use) == *(node->use));
258 node->prev = old->prev;
259 node->next = old->next;
260 if (old->prev)
262 old->prev->next = node;
263 old->next->prev = node;
264 /* Remove the old node from the list. */
265 old->prev = NULL;
269 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
270 in STMT. */
271 static inline void
272 relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old,
273 gimple stmt)
275 if (stmt)
276 relink_imm_use (linknode, old);
277 else
278 link_imm_use (linknode, NULL);
279 linknode->loc.stmt = stmt;
283 /* Return true is IMM has reached the end of the immediate use list. */
284 static inline bool
285 end_readonly_imm_use_p (const imm_use_iterator *imm)
287 return (imm->imm_use == imm->end_p);
290 /* Initialize iterator IMM to process the list for VAR. */
291 static inline use_operand_p
292 first_readonly_imm_use (imm_use_iterator *imm, tree var)
294 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
295 imm->imm_use = imm->end_p->next;
296 #ifdef ENABLE_CHECKING
297 imm->iter_node.next = imm->imm_use->next;
298 #endif
299 if (end_readonly_imm_use_p (imm))
300 return NULL_USE_OPERAND_P;
301 return imm->imm_use;
304 /* Bump IMM to the next use in the list. */
305 static inline use_operand_p
306 next_readonly_imm_use (imm_use_iterator *imm)
308 use_operand_p old = imm->imm_use;
310 #ifdef ENABLE_CHECKING
311 /* If this assertion fails, it indicates the 'next' pointer has changed
312 since the last bump. This indicates that the list is being modified
313 via stmt changes, or SET_USE, or somesuch thing, and you need to be
314 using the SAFE version of the iterator. */
315 gcc_assert (imm->iter_node.next == old->next);
316 imm->iter_node.next = old->next->next;
317 #endif
319 imm->imm_use = old->next;
320 if (end_readonly_imm_use_p (imm))
321 return NULL_USE_OPERAND_P;
322 return imm->imm_use;
325 /* tree-cfg.c */
326 extern bool has_zero_uses_1 (const ssa_use_operand_t *head);
327 extern bool single_imm_use_1 (const ssa_use_operand_t *head,
328 use_operand_p *use_p, gimple *stmt);
330 /* Return true if VAR has no nondebug uses. */
331 static inline bool
332 has_zero_uses (const_tree var)
334 const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
336 /* A single use_operand means there is no items in the list. */
337 if (ptr == ptr->next)
338 return true;
340 /* If there are debug stmts, we have to look at each use and see
341 whether there are any nondebug uses. */
342 if (!MAY_HAVE_DEBUG_STMTS)
343 return false;
345 return has_zero_uses_1 (ptr);
348 /* Return true if VAR has a single nondebug use. */
349 static inline bool
350 has_single_use (const_tree var)
352 const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
354 /* If there aren't any uses whatsoever, we're done. */
355 if (ptr == ptr->next)
356 return false;
358 /* If there's a single use, check that it's not a debug stmt. */
359 if (ptr == ptr->next->next)
360 return !is_gimple_debug (USE_STMT (ptr->next));
362 /* If there are debug stmts, we have to look at each of them. */
363 if (!MAY_HAVE_DEBUG_STMTS)
364 return false;
366 return single_imm_use_1 (ptr, NULL, NULL);
370 /* If VAR has only a single immediate nondebug use, return true, and
371 set USE_P and STMT to the use pointer and stmt of occurrence. */
372 static inline bool
373 single_imm_use (const_tree var, use_operand_p *use_p, gimple *stmt)
375 const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
377 /* If there aren't any uses whatsoever, we're done. */
378 if (ptr == ptr->next)
380 return_false:
381 *use_p = NULL_USE_OPERAND_P;
382 *stmt = NULL;
383 return false;
386 /* If there's a single use, check that it's not a debug stmt. */
387 if (ptr == ptr->next->next)
389 if (!is_gimple_debug (USE_STMT (ptr->next)))
391 *use_p = ptr->next;
392 *stmt = ptr->next->loc.stmt;
393 return true;
395 else
396 goto return_false;
399 /* If there are debug stmts, we have to look at each of them. */
400 if (!MAY_HAVE_DEBUG_STMTS)
401 goto return_false;
403 return single_imm_use_1 (ptr, use_p, stmt);
406 /* Return the number of nondebug immediate uses of VAR. */
407 static inline unsigned int
408 num_imm_uses (const_tree var)
410 const ssa_use_operand_t *const start = &(SSA_NAME_IMM_USE_NODE (var));
411 const ssa_use_operand_t *ptr;
412 unsigned int num = 0;
414 if (!MAY_HAVE_DEBUG_STMTS)
415 for (ptr = start->next; ptr != start; ptr = ptr->next)
416 num++;
417 else
418 for (ptr = start->next; ptr != start; ptr = ptr->next)
419 if (!is_gimple_debug (USE_STMT (ptr)))
420 num++;
422 return num;
425 /* Return the tree pointed-to by USE. */
426 static inline tree
427 get_use_from_ptr (use_operand_p use)
429 return *(use->use);
432 /* Return the tree pointed-to by DEF. */
433 static inline tree
434 get_def_from_ptr (def_operand_p def)
436 return *def;
439 /* Return a use_operand_p pointer for argument I of PHI node GS. */
441 static inline use_operand_p
442 gimple_phi_arg_imm_use_ptr (gimple gs, int i)
444 return &gimple_phi_arg (gs, i)->imm_use;
447 /* Return the tree operand for argument I of PHI node GS. */
449 static inline tree
450 gimple_phi_arg_def (gimple gs, size_t index)
452 struct phi_arg_d *pd = gimple_phi_arg (gs, index);
453 return get_use_from_ptr (&pd->imm_use);
456 /* Return a pointer to the tree operand for argument I of PHI node GS. */
458 static inline tree *
459 gimple_phi_arg_def_ptr (gimple gs, size_t index)
461 return &gimple_phi_arg (gs, index)->def;
464 /* Return the edge associated with argument I of phi node GS. */
466 static inline edge
467 gimple_phi_arg_edge (gimple gs, size_t i)
469 return EDGE_PRED (gimple_bb (gs), i);
472 /* Return the source location of gimple argument I of phi node GS. */
474 static inline source_location
475 gimple_phi_arg_location (gimple gs, size_t i)
477 return gimple_phi_arg (gs, i)->locus;
480 /* Return the source location of the argument on edge E of phi node GS. */
482 static inline source_location
483 gimple_phi_arg_location_from_edge (gimple gs, edge e)
485 return gimple_phi_arg (gs, e->dest_idx)->locus;
488 /* Set the source location of gimple argument I of phi node GS to LOC. */
490 static inline void
491 gimple_phi_arg_set_location (gimple gs, size_t i, source_location loc)
493 gimple_phi_arg (gs, i)->locus = loc;
496 /* Return TRUE if argument I of phi node GS has a location record. */
498 static inline bool
499 gimple_phi_arg_has_location (gimple gs, size_t i)
501 return gimple_phi_arg_location (gs, i) != UNKNOWN_LOCATION;
505 /* Return the PHI nodes for basic block BB, or NULL if there are no
506 PHI nodes. */
507 static inline gimple_seq
508 phi_nodes (const_basic_block bb)
510 gcc_assert (!(bb->flags & BB_RTL));
511 if (!bb->il.gimple)
512 return NULL;
513 return bb->il.gimple->phi_nodes;
516 /* Set PHI nodes of a basic block BB to SEQ. */
518 static inline void
519 set_phi_nodes (basic_block bb, gimple_seq seq)
521 gimple_stmt_iterator i;
523 gcc_assert (!(bb->flags & BB_RTL));
524 bb->il.gimple->phi_nodes = seq;
525 if (seq)
526 for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
527 gimple_set_bb (gsi_stmt (i), bb);
530 /* Return the phi argument which contains the specified use. */
532 static inline int
533 phi_arg_index_from_use (use_operand_p use)
535 struct phi_arg_d *element, *root;
536 size_t index;
537 gimple phi;
539 /* Since the use is the first thing in a PHI argument element, we can
540 calculate its index based on casting it to an argument, and performing
541 pointer arithmetic. */
543 phi = USE_STMT (use);
544 gcc_assert (gimple_code (phi) == GIMPLE_PHI);
546 element = (struct phi_arg_d *)use;
547 root = gimple_phi_arg (phi, 0);
548 index = element - root;
550 #ifdef ENABLE_CHECKING
551 /* Make sure the calculation doesn't have any leftover bytes. If it does,
552 then imm_use is likely not the first element in phi_arg_d. */
553 gcc_assert ((((char *)element - (char *)root)
554 % sizeof (struct phi_arg_d)) == 0
555 && index < gimple_phi_capacity (phi));
556 #endif
558 return index;
561 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
563 static inline void
564 set_is_used (tree var)
566 var_ann_t ann = get_var_ann (var);
567 ann->used = 1;
571 /* Return true if T (assumed to be a DECL) is a global variable.
572 A variable is considered global if its storage is not automatic. */
574 static inline bool
575 is_global_var (const_tree t)
577 return (TREE_STATIC (t) || DECL_EXTERNAL (t));
581 /* Return true if VAR may be aliased. A variable is considered as
582 maybe aliased if it has its address taken by the local TU
583 or possibly by another TU and might be modified through a pointer. */
585 static inline bool
586 may_be_aliased (const_tree var)
588 return (TREE_CODE (var) != CONST_DECL
589 && !((TREE_STATIC (var) || TREE_PUBLIC (var) || DECL_EXTERNAL (var))
590 && TREE_READONLY (var)
591 && !TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (var)))
592 && (TREE_PUBLIC (var)
593 || DECL_EXTERNAL (var)
594 || TREE_ADDRESSABLE (var)));
598 /* PHI nodes should contain only ssa_names and invariants. A test
599 for ssa_name is definitely simpler; don't let invalid contents
600 slip in in the meantime. */
602 static inline bool
603 phi_ssa_name_p (const_tree t)
605 if (TREE_CODE (t) == SSA_NAME)
606 return true;
607 #ifdef ENABLE_CHECKING
608 gcc_assert (is_gimple_min_invariant (t));
609 #endif
610 return false;
614 /* Returns the loop of the statement STMT. */
616 static inline struct loop *
617 loop_containing_stmt (gimple stmt)
619 basic_block bb = gimple_bb (stmt);
620 if (!bb)
621 return NULL;
623 return bb->loop_father;
627 /* ----------------------------------------------------------------------- */
629 /* The following set of routines are used to iterator over various type of
630 SSA operands. */
632 /* Return true if PTR is finished iterating. */
633 static inline bool
634 op_iter_done (const ssa_op_iter *ptr)
636 return ptr->done;
639 /* Get the next iterator use value for PTR. */
640 static inline use_operand_p
641 op_iter_next_use (ssa_op_iter *ptr)
643 use_operand_p use_p;
644 #ifdef ENABLE_CHECKING
645 gcc_assert (ptr->iter_type == ssa_op_iter_use);
646 #endif
647 if (ptr->uses)
649 use_p = USE_OP_PTR (ptr->uses);
650 ptr->uses = ptr->uses->next;
651 return use_p;
653 if (ptr->phi_i < ptr->num_phi)
655 return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
657 ptr->done = true;
658 return NULL_USE_OPERAND_P;
661 /* Get the next iterator def value for PTR. */
662 static inline def_operand_p
663 op_iter_next_def (ssa_op_iter *ptr)
665 def_operand_p def_p;
666 #ifdef ENABLE_CHECKING
667 gcc_assert (ptr->iter_type == ssa_op_iter_def);
668 #endif
669 if (ptr->defs)
671 def_p = DEF_OP_PTR (ptr->defs);
672 ptr->defs = ptr->defs->next;
673 return def_p;
675 ptr->done = true;
676 return NULL_DEF_OPERAND_P;
679 /* Get the next iterator tree value for PTR. */
680 static inline tree
681 op_iter_next_tree (ssa_op_iter *ptr)
683 tree val;
684 #ifdef ENABLE_CHECKING
685 gcc_assert (ptr->iter_type == ssa_op_iter_tree);
686 #endif
687 if (ptr->uses)
689 val = USE_OP (ptr->uses);
690 ptr->uses = ptr->uses->next;
691 return val;
693 if (ptr->defs)
695 val = DEF_OP (ptr->defs);
696 ptr->defs = ptr->defs->next;
697 return val;
700 ptr->done = true;
701 return NULL_TREE;
706 /* This functions clears the iterator PTR, and marks it done. This is normally
707 used to prevent warnings in the compile about might be uninitialized
708 components. */
710 static inline void
711 clear_and_done_ssa_iter (ssa_op_iter *ptr)
713 ptr->defs = NULL;
714 ptr->uses = NULL;
715 ptr->iter_type = ssa_op_iter_none;
716 ptr->phi_i = 0;
717 ptr->num_phi = 0;
718 ptr->phi_stmt = NULL;
719 ptr->done = true;
722 /* Initialize the iterator PTR to the virtual defs in STMT. */
723 static inline void
724 op_iter_init (ssa_op_iter *ptr, gimple stmt, int flags)
726 /* We do not support iterating over virtual defs or uses without
727 iterating over defs or uses at the same time. */
728 gcc_assert ((!(flags & SSA_OP_VDEF) || (flags & SSA_OP_DEF))
729 && (!(flags & SSA_OP_VUSE) || (flags & SSA_OP_USE)));
730 ptr->defs = (flags & (SSA_OP_DEF|SSA_OP_VDEF)) ? gimple_def_ops (stmt) : NULL;
731 if (!(flags & SSA_OP_VDEF)
732 && ptr->defs
733 && gimple_vdef (stmt) != NULL_TREE)
734 ptr->defs = ptr->defs->next;
735 ptr->uses = (flags & (SSA_OP_USE|SSA_OP_VUSE)) ? gimple_use_ops (stmt) : NULL;
736 if (!(flags & SSA_OP_VUSE)
737 && ptr->uses
738 && gimple_vuse (stmt) != NULL_TREE)
739 ptr->uses = ptr->uses->next;
740 ptr->done = false;
742 ptr->phi_i = 0;
743 ptr->num_phi = 0;
744 ptr->phi_stmt = NULL;
747 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
748 the first use. */
749 static inline use_operand_p
750 op_iter_init_use (ssa_op_iter *ptr, gimple stmt, int flags)
752 gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0
753 && (flags & SSA_OP_USE));
754 op_iter_init (ptr, stmt, flags);
755 ptr->iter_type = ssa_op_iter_use;
756 return op_iter_next_use (ptr);
759 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
760 the first def. */
761 static inline def_operand_p
762 op_iter_init_def (ssa_op_iter *ptr, gimple stmt, int flags)
764 gcc_assert ((flags & SSA_OP_ALL_USES) == 0
765 && (flags & SSA_OP_DEF));
766 op_iter_init (ptr, stmt, flags);
767 ptr->iter_type = ssa_op_iter_def;
768 return op_iter_next_def (ptr);
771 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
772 the first operand as a tree. */
773 static inline tree
774 op_iter_init_tree (ssa_op_iter *ptr, gimple stmt, int flags)
776 op_iter_init (ptr, stmt, flags);
777 ptr->iter_type = ssa_op_iter_tree;
778 return op_iter_next_tree (ptr);
782 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
783 return NULL. */
784 static inline tree
785 single_ssa_tree_operand (gimple stmt, int flags)
787 tree var;
788 ssa_op_iter iter;
790 var = op_iter_init_tree (&iter, stmt, flags);
791 if (op_iter_done (&iter))
792 return NULL_TREE;
793 op_iter_next_tree (&iter);
794 if (op_iter_done (&iter))
795 return var;
796 return NULL_TREE;
800 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
801 return NULL. */
802 static inline use_operand_p
803 single_ssa_use_operand (gimple stmt, int flags)
805 use_operand_p var;
806 ssa_op_iter iter;
808 var = op_iter_init_use (&iter, stmt, flags);
809 if (op_iter_done (&iter))
810 return NULL_USE_OPERAND_P;
811 op_iter_next_use (&iter);
812 if (op_iter_done (&iter))
813 return var;
814 return NULL_USE_OPERAND_P;
819 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
820 return NULL. */
821 static inline def_operand_p
822 single_ssa_def_operand (gimple stmt, int flags)
824 def_operand_p var;
825 ssa_op_iter iter;
827 var = op_iter_init_def (&iter, stmt, flags);
828 if (op_iter_done (&iter))
829 return NULL_DEF_OPERAND_P;
830 op_iter_next_def (&iter);
831 if (op_iter_done (&iter))
832 return var;
833 return NULL_DEF_OPERAND_P;
837 /* Return true if there are zero operands in STMT matching the type
838 given in FLAGS. */
839 static inline bool
840 zero_ssa_operands (gimple stmt, int flags)
842 ssa_op_iter iter;
844 op_iter_init_tree (&iter, stmt, flags);
845 return op_iter_done (&iter);
849 /* Return the number of operands matching FLAGS in STMT. */
850 static inline int
851 num_ssa_operands (gimple stmt, int flags)
853 ssa_op_iter iter;
854 tree t;
855 int num = 0;
857 FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
858 num++;
859 return num;
863 /* Delink all immediate_use information for STMT. */
864 static inline void
865 delink_stmt_imm_use (gimple stmt)
867 ssa_op_iter iter;
868 use_operand_p use_p;
870 if (ssa_operands_active ())
871 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_ALL_USES)
872 delink_imm_use (use_p);
876 /* If there is a single DEF in the PHI node which matches FLAG, return it.
877 Otherwise return NULL_DEF_OPERAND_P. */
878 static inline tree
879 single_phi_def (gimple stmt, int flags)
881 tree def = PHI_RESULT (stmt);
882 if ((flags & SSA_OP_DEF) && is_gimple_reg (def))
883 return def;
884 if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
885 return def;
886 return NULL_TREE;
889 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
890 be either SSA_OP_USES or SSA_OP_VIRTUAL_USES. */
891 static inline use_operand_p
892 op_iter_init_phiuse (ssa_op_iter *ptr, gimple phi, int flags)
894 tree phi_def = gimple_phi_result (phi);
895 int comp;
897 clear_and_done_ssa_iter (ptr);
898 ptr->done = false;
900 gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
902 comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
904 /* If the PHI node doesn't the operand type we care about, we're done. */
905 if ((flags & comp) == 0)
907 ptr->done = true;
908 return NULL_USE_OPERAND_P;
911 ptr->phi_stmt = phi;
912 ptr->num_phi = gimple_phi_num_args (phi);
913 ptr->iter_type = ssa_op_iter_use;
914 return op_iter_next_use (ptr);
918 /* Start an iterator for a PHI definition. */
920 static inline def_operand_p
921 op_iter_init_phidef (ssa_op_iter *ptr, gimple phi, int flags)
923 tree phi_def = PHI_RESULT (phi);
924 int comp;
926 clear_and_done_ssa_iter (ptr);
927 ptr->done = false;
929 gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
931 comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
933 /* If the PHI node doesn't have the operand type we care about,
934 we're done. */
935 if ((flags & comp) == 0)
937 ptr->done = true;
938 return NULL_DEF_OPERAND_P;
941 ptr->iter_type = ssa_op_iter_def;
942 /* The first call to op_iter_next_def will terminate the iterator since
943 all the fields are NULL. Simply return the result here as the first and
944 therefore only result. */
945 return PHI_RESULT_PTR (phi);
948 /* Return true is IMM has reached the end of the immediate use stmt list. */
950 static inline bool
951 end_imm_use_stmt_p (const imm_use_iterator *imm)
953 return (imm->imm_use == imm->end_p);
956 /* Finished the traverse of an immediate use stmt list IMM by removing the
957 placeholder node from the list. */
959 static inline void
960 end_imm_use_stmt_traverse (imm_use_iterator *imm)
962 delink_imm_use (&(imm->iter_node));
965 /* Immediate use traversal of uses within a stmt require that all the
966 uses on a stmt be sequentially listed. This routine is used to build up
967 this sequential list by adding USE_P to the end of the current list
968 currently delimited by HEAD and LAST_P. The new LAST_P value is
969 returned. */
971 static inline use_operand_p
972 move_use_after_head (use_operand_p use_p, use_operand_p head,
973 use_operand_p last_p)
975 #ifdef ENABLE_CHECKING
976 gcc_assert (USE_FROM_PTR (use_p) == USE_FROM_PTR (head));
977 #endif
978 /* Skip head when we find it. */
979 if (use_p != head)
981 /* If use_p is already linked in after last_p, continue. */
982 if (last_p->next == use_p)
983 last_p = use_p;
984 else
986 /* Delink from current location, and link in at last_p. */
987 delink_imm_use (use_p);
988 link_imm_use_to_list (use_p, last_p);
989 last_p = use_p;
992 return last_p;
996 /* This routine will relink all uses with the same stmt as HEAD into the list
997 immediately following HEAD for iterator IMM. */
999 static inline void
1000 link_use_stmts_after (use_operand_p head, imm_use_iterator *imm)
1002 use_operand_p use_p;
1003 use_operand_p last_p = head;
1004 gimple head_stmt = USE_STMT (head);
1005 tree use = USE_FROM_PTR (head);
1006 ssa_op_iter op_iter;
1007 int flag;
1009 /* Only look at virtual or real uses, depending on the type of HEAD. */
1010 flag = (is_gimple_reg (use) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1012 if (gimple_code (head_stmt) == GIMPLE_PHI)
1014 FOR_EACH_PHI_ARG (use_p, head_stmt, op_iter, flag)
1015 if (USE_FROM_PTR (use_p) == use)
1016 last_p = move_use_after_head (use_p, head, last_p);
1018 else
1020 if (flag == SSA_OP_USE)
1022 FOR_EACH_SSA_USE_OPERAND (use_p, head_stmt, op_iter, flag)
1023 if (USE_FROM_PTR (use_p) == use)
1024 last_p = move_use_after_head (use_p, head, last_p);
1026 else if ((use_p = gimple_vuse_op (head_stmt)) != NULL_USE_OPERAND_P)
1028 if (USE_FROM_PTR (use_p) == use)
1029 last_p = move_use_after_head (use_p, head, last_p);
1032 /* Link iter node in after last_p. */
1033 if (imm->iter_node.prev != NULL)
1034 delink_imm_use (&imm->iter_node);
1035 link_imm_use_to_list (&(imm->iter_node), last_p);
1038 /* Initialize IMM to traverse over uses of VAR. Return the first statement. */
1039 static inline gimple
1040 first_imm_use_stmt (imm_use_iterator *imm, tree var)
1042 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
1043 imm->imm_use = imm->end_p->next;
1044 imm->next_imm_name = NULL_USE_OPERAND_P;
1046 /* iter_node is used as a marker within the immediate use list to indicate
1047 where the end of the current stmt's uses are. Initialize it to NULL
1048 stmt and use, which indicates a marker node. */
1049 imm->iter_node.prev = NULL_USE_OPERAND_P;
1050 imm->iter_node.next = NULL_USE_OPERAND_P;
1051 imm->iter_node.loc.stmt = NULL;
1052 imm->iter_node.use = NULL;
1054 if (end_imm_use_stmt_p (imm))
1055 return NULL;
1057 link_use_stmts_after (imm->imm_use, imm);
1059 return USE_STMT (imm->imm_use);
1062 /* Bump IMM to the next stmt which has a use of var. */
1064 static inline gimple
1065 next_imm_use_stmt (imm_use_iterator *imm)
1067 imm->imm_use = imm->iter_node.next;
1068 if (end_imm_use_stmt_p (imm))
1070 if (imm->iter_node.prev != NULL)
1071 delink_imm_use (&imm->iter_node);
1072 return NULL;
1075 link_use_stmts_after (imm->imm_use, imm);
1076 return USE_STMT (imm->imm_use);
1079 /* This routine will return the first use on the stmt IMM currently refers
1080 to. */
1082 static inline use_operand_p
1083 first_imm_use_on_stmt (imm_use_iterator *imm)
1085 imm->next_imm_name = imm->imm_use->next;
1086 return imm->imm_use;
1089 /* Return TRUE if the last use on the stmt IMM refers to has been visited. */
1091 static inline bool
1092 end_imm_use_on_stmt_p (const imm_use_iterator *imm)
1094 return (imm->imm_use == &(imm->iter_node));
1097 /* Bump to the next use on the stmt IMM refers to, return NULL if done. */
1099 static inline use_operand_p
1100 next_imm_use_on_stmt (imm_use_iterator *imm)
1102 imm->imm_use = imm->next_imm_name;
1103 if (end_imm_use_on_stmt_p (imm))
1104 return NULL_USE_OPERAND_P;
1105 else
1107 imm->next_imm_name = imm->imm_use->next;
1108 return imm->imm_use;
1112 /* Return true if VAR cannot be modified by the program. */
1114 static inline bool
1115 unmodifiable_var_p (const_tree var)
1117 if (TREE_CODE (var) == SSA_NAME)
1118 var = SSA_NAME_VAR (var);
1120 return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1123 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it. */
1125 static inline bool
1126 array_ref_contains_indirect_ref (const_tree ref)
1128 gcc_assert (TREE_CODE (ref) == ARRAY_REF);
1130 do {
1131 ref = TREE_OPERAND (ref, 0);
1132 } while (handled_component_p (ref));
1134 return TREE_CODE (ref) == INDIRECT_REF;
1137 /* Return true if REF, a handled component reference, has an ARRAY_REF
1138 somewhere in it. */
1140 static inline bool
1141 ref_contains_array_ref (const_tree ref)
1143 gcc_assert (handled_component_p (ref));
1145 do {
1146 if (TREE_CODE (ref) == ARRAY_REF)
1147 return true;
1148 ref = TREE_OPERAND (ref, 0);
1149 } while (handled_component_p (ref));
1151 return false;
1154 /* Return true if REF has an VIEW_CONVERT_EXPR somewhere in it. */
1156 static inline bool
1157 contains_view_convert_expr_p (const_tree ref)
1159 while (handled_component_p (ref))
1161 if (TREE_CODE (ref) == VIEW_CONVERT_EXPR)
1162 return true;
1163 ref = TREE_OPERAND (ref, 0);
1166 return false;
1169 /* Return true, if the two ranges [POS1, SIZE1] and [POS2, SIZE2]
1170 overlap. SIZE1 and/or SIZE2 can be (unsigned)-1 in which case the
1171 range is open-ended. Otherwise return false. */
1173 static inline bool
1174 ranges_overlap_p (unsigned HOST_WIDE_INT pos1,
1175 unsigned HOST_WIDE_INT size1,
1176 unsigned HOST_WIDE_INT pos2,
1177 unsigned HOST_WIDE_INT size2)
1179 if (pos1 >= pos2
1180 && (size2 == (unsigned HOST_WIDE_INT)-1
1181 || pos1 < (pos2 + size2)))
1182 return true;
1183 if (pos2 >= pos1
1184 && (size1 == (unsigned HOST_WIDE_INT)-1
1185 || pos2 < (pos1 + size1)))
1186 return true;
1188 return false;
1191 /* Accessor to tree-ssa-operands.c caches. */
1192 static inline struct ssa_operands *
1193 gimple_ssa_operands (const struct function *fun)
1195 return &fun->gimple_df->ssa_operands;
1198 /* Given an edge_var_map V, return the PHI arg definition. */
1200 static inline tree
1201 redirect_edge_var_map_def (edge_var_map *v)
1203 return v->def;
1206 /* Given an edge_var_map V, return the PHI result. */
1208 static inline tree
1209 redirect_edge_var_map_result (edge_var_map *v)
1211 return v->result;
1214 /* Given an edge_var_map V, return the PHI arg location. */
1216 static inline source_location
1217 redirect_edge_var_map_location (edge_var_map *v)
1219 return v->locus;
1223 /* Return an SSA_NAME node for variable VAR defined in statement STMT
1224 in function cfun. */
1226 static inline tree
1227 make_ssa_name (tree var, gimple stmt)
1229 return make_ssa_name_fn (cfun, var, stmt);
1232 #endif /* _TREE_FLOW_INLINE_H */