* cgraph.h (cgraph_node_ptr): New type for vector functions.
[official-gcc.git] / gcc / tree-flow-inline.h
blob536a111bb44197af5df80e7d4c3f973ef8385de8
1 /* Inline functions for tree-flow.h
2 Copyright (C) 2001, 2003, 2005, 2006, 2007, 2008 Free Software
3 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 to model the effects of nonlocal
48 variables. */
49 static inline tree
50 gimple_nonlocal_all (const struct function *fun)
52 gcc_assert (fun && fun->gimple_df);
53 return fun->gimple_df->nonlocal_all;
56 /* Artificial variable used for the virtual operand FUD chain. */
57 static inline tree
58 gimple_vop (const struct function *fun)
60 gcc_assert (fun && fun->gimple_df);
61 return fun->gimple_df->vop;
64 /* Initialize the hashtable iterator HTI to point to hashtable TABLE */
66 static inline void *
67 first_htab_element (htab_iterator *hti, htab_t table)
69 hti->htab = table;
70 hti->slot = table->entries;
71 hti->limit = hti->slot + htab_size (table);
74 PTR x = *(hti->slot);
75 if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
76 break;
77 } while (++(hti->slot) < hti->limit);
79 if (hti->slot < hti->limit)
80 return *(hti->slot);
81 return NULL;
84 /* Return current non-empty/deleted slot of the hashtable pointed to by HTI,
85 or NULL if we have reached the end. */
87 static inline bool
88 end_htab_p (const htab_iterator *hti)
90 if (hti->slot >= hti->limit)
91 return true;
92 return false;
95 /* Advance the hashtable iterator pointed to by HTI to the next element of the
96 hashtable. */
98 static inline void *
99 next_htab_element (htab_iterator *hti)
101 while (++(hti->slot) < hti->limit)
103 PTR x = *(hti->slot);
104 if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
105 return x;
107 return NULL;
110 /* Initialize ITER to point to the first referenced variable in the
111 referenced_vars hashtable, and return that variable. */
113 static inline tree
114 first_referenced_var (referenced_var_iterator *iter)
116 return (tree) first_htab_element (&iter->hti,
117 gimple_referenced_vars (cfun));
120 /* Return true if we have hit the end of the referenced variables ITER is
121 iterating through. */
123 static inline bool
124 end_referenced_vars_p (const referenced_var_iterator *iter)
126 return end_htab_p (&iter->hti);
129 /* Make ITER point to the next referenced_var in the referenced_var hashtable,
130 and return that variable. */
132 static inline tree
133 next_referenced_var (referenced_var_iterator *iter)
135 return (tree) next_htab_element (&iter->hti);
138 /* Fill up VEC with the variables in the referenced vars hashtable. */
140 static inline void
141 fill_referenced_var_vec (VEC (tree, heap) **vec)
143 referenced_var_iterator rvi;
144 tree var;
145 *vec = NULL;
146 FOR_EACH_REFERENCED_VAR (var, rvi)
147 VEC_safe_push (tree, heap, *vec, var);
150 /* Return the variable annotation for T, which must be a _DECL node.
151 Return NULL if the variable annotation doesn't already exist. */
152 static inline var_ann_t
153 var_ann (const_tree t)
155 var_ann_t ann;
157 if (!t->base.ann)
158 return NULL;
159 ann = (var_ann_t) t->base.ann;
161 gcc_assert (ann->common.type == VAR_ANN);
163 return ann;
166 /* Return the variable annotation for T, which must be a _DECL node.
167 Create the variable annotation if it doesn't exist. */
168 static inline var_ann_t
169 get_var_ann (tree var)
171 var_ann_t ann = var_ann (var);
172 return (ann) ? ann : create_var_ann (var);
175 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
176 Return NULL if the function annotation doesn't already exist. */
177 static inline function_ann_t
178 function_ann (const_tree t)
180 gcc_assert (t);
181 gcc_assert (TREE_CODE (t) == FUNCTION_DECL);
182 gcc_assert (!t->base.ann
183 || t->base.ann->common.type == FUNCTION_ANN);
185 return (function_ann_t) t->base.ann;
188 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
189 Create the function annotation if it doesn't exist. */
190 static inline function_ann_t
191 get_function_ann (tree var)
193 function_ann_t ann = function_ann (var);
194 gcc_assert (!var->base.ann || var->base.ann->common.type == FUNCTION_ANN);
195 return (ann) ? ann : create_function_ann (var);
198 /* Get the number of the next statement uid to be allocated. */
199 static inline unsigned int
200 gimple_stmt_max_uid (struct function *fn)
202 return fn->last_stmt_uid;
205 /* Set the number of the next statement uid to be allocated. */
206 static inline void
207 set_gimple_stmt_max_uid (struct function *fn, unsigned int maxid)
209 fn->last_stmt_uid = maxid;
212 /* Set the number of the next statement uid to be allocated. */
213 static inline unsigned int
214 inc_gimple_stmt_max_uid (struct function *fn)
216 return fn->last_stmt_uid++;
219 /* Return the annotation type for annotation ANN. */
220 static inline enum tree_ann_type
221 ann_type (tree_ann_t ann)
223 return ann->common.type;
226 /* Return the line number for EXPR, or return -1 if we have no line
227 number information for it. */
228 static inline int
229 get_lineno (const_gimple stmt)
231 location_t loc;
233 if (!stmt)
234 return -1;
236 loc = gimple_location (stmt);
237 if (loc == UNKNOWN_LOCATION)
238 return -1;
240 return LOCATION_LINE (loc);
243 /* Delink an immediate_uses node from its chain. */
244 static inline void
245 delink_imm_use (ssa_use_operand_t *linknode)
247 /* Return if this node is not in a list. */
248 if (linknode->prev == NULL)
249 return;
251 linknode->prev->next = linknode->next;
252 linknode->next->prev = linknode->prev;
253 linknode->prev = NULL;
254 linknode->next = NULL;
257 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
258 static inline void
259 link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
261 /* Link the new node at the head of the list. If we are in the process of
262 traversing the list, we won't visit any new nodes added to it. */
263 linknode->prev = list;
264 linknode->next = list->next;
265 list->next->prev = linknode;
266 list->next = linknode;
269 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
270 static inline void
271 link_imm_use (ssa_use_operand_t *linknode, tree def)
273 ssa_use_operand_t *root;
275 if (!def || TREE_CODE (def) != SSA_NAME)
276 linknode->prev = NULL;
277 else
279 root = &(SSA_NAME_IMM_USE_NODE (def));
280 #ifdef ENABLE_CHECKING
281 if (linknode->use)
282 gcc_assert (*(linknode->use) == def);
283 #endif
284 link_imm_use_to_list (linknode, root);
288 /* Set the value of a use pointed to by USE to VAL. */
289 static inline void
290 set_ssa_use_from_ptr (use_operand_p use, tree val)
292 delink_imm_use (use);
293 *(use->use) = val;
294 link_imm_use (use, val);
297 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
298 in STMT. */
299 static inline void
300 link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, gimple stmt)
302 if (stmt)
303 link_imm_use (linknode, def);
304 else
305 link_imm_use (linknode, NULL);
306 linknode->loc.stmt = stmt;
309 /* Relink a new node in place of an old node in the list. */
310 static inline void
311 relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
313 /* The node one had better be in the same list. */
314 gcc_assert (*(old->use) == *(node->use));
315 node->prev = old->prev;
316 node->next = old->next;
317 if (old->prev)
319 old->prev->next = node;
320 old->next->prev = node;
321 /* Remove the old node from the list. */
322 old->prev = NULL;
326 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
327 in STMT. */
328 static inline void
329 relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old,
330 gimple stmt)
332 if (stmt)
333 relink_imm_use (linknode, old);
334 else
335 link_imm_use (linknode, NULL);
336 linknode->loc.stmt = stmt;
340 /* Return true is IMM has reached the end of the immediate use list. */
341 static inline bool
342 end_readonly_imm_use_p (const imm_use_iterator *imm)
344 return (imm->imm_use == imm->end_p);
347 /* Initialize iterator IMM to process the list for VAR. */
348 static inline use_operand_p
349 first_readonly_imm_use (imm_use_iterator *imm, tree var)
351 gcc_assert (TREE_CODE (var) == SSA_NAME);
353 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
354 imm->imm_use = imm->end_p->next;
355 #ifdef ENABLE_CHECKING
356 imm->iter_node.next = imm->imm_use->next;
357 #endif
358 if (end_readonly_imm_use_p (imm))
359 return NULL_USE_OPERAND_P;
360 return imm->imm_use;
363 /* Bump IMM to the next use in the list. */
364 static inline use_operand_p
365 next_readonly_imm_use (imm_use_iterator *imm)
367 use_operand_p old = imm->imm_use;
369 #ifdef ENABLE_CHECKING
370 /* If this assertion fails, it indicates the 'next' pointer has changed
371 since the last bump. This indicates that the list is being modified
372 via stmt changes, or SET_USE, or somesuch thing, and you need to be
373 using the SAFE version of the iterator. */
374 gcc_assert (imm->iter_node.next == old->next);
375 imm->iter_node.next = old->next->next;
376 #endif
378 imm->imm_use = old->next;
379 if (end_readonly_imm_use_p (imm))
380 return NULL_USE_OPERAND_P;
381 return imm->imm_use;
384 /* Return true if VAR has no uses. */
385 static inline bool
386 has_zero_uses (const_tree var)
388 const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
389 /* A single use means there is no items in the list. */
390 return (ptr == ptr->next);
393 /* Return true if VAR has a single use. */
394 static inline bool
395 has_single_use (const_tree var)
397 const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
398 /* A single use means there is one item in the list. */
399 return (ptr != ptr->next && ptr == ptr->next->next);
403 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
404 to the use pointer and stmt of occurrence. */
405 static inline bool
406 single_imm_use (const_tree var, use_operand_p *use_p, gimple *stmt)
408 const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
409 if (ptr != ptr->next && ptr == ptr->next->next)
411 *use_p = ptr->next;
412 *stmt = ptr->next->loc.stmt;
413 return true;
415 *use_p = NULL_USE_OPERAND_P;
416 *stmt = NULL;
417 return false;
420 /* Return the number of immediate uses of VAR. */
421 static inline unsigned int
422 num_imm_uses (const_tree var)
424 const ssa_use_operand_t *const start = &(SSA_NAME_IMM_USE_NODE (var));
425 const ssa_use_operand_t *ptr;
426 unsigned int num = 0;
428 for (ptr = start->next; ptr != start; ptr = ptr->next)
429 num++;
431 return num;
434 /* Return the tree pointed-to by USE. */
435 static inline tree
436 get_use_from_ptr (use_operand_p use)
438 return *(use->use);
441 /* Return the tree pointed-to by DEF. */
442 static inline tree
443 get_def_from_ptr (def_operand_p def)
445 return *def;
448 /* Return a use_operand_p pointer for argument I of PHI node GS. */
450 static inline use_operand_p
451 gimple_phi_arg_imm_use_ptr (gimple gs, int i)
453 return &gimple_phi_arg (gs, i)->imm_use;
456 /* Return the tree operand for argument I of PHI node GS. */
458 static inline tree
459 gimple_phi_arg_def (gimple gs, size_t index)
461 struct phi_arg_d *pd = gimple_phi_arg (gs, index);
462 return get_use_from_ptr (&pd->imm_use);
465 /* Return a pointer to the tree operand for argument I of PHI node GS. */
467 static inline tree *
468 gimple_phi_arg_def_ptr (gimple gs, size_t index)
470 return &gimple_phi_arg (gs, index)->def;
473 /* Return the edge associated with argument I of phi node GS. */
475 static inline edge
476 gimple_phi_arg_edge (gimple gs, size_t i)
478 return EDGE_PRED (gimple_bb (gs), i);
481 /* Return the PHI nodes for basic block BB, or NULL if there are no
482 PHI nodes. */
483 static inline gimple_seq
484 phi_nodes (const_basic_block bb)
486 gcc_assert (!(bb->flags & BB_RTL));
487 if (!bb->il.gimple)
488 return NULL;
489 return bb->il.gimple->phi_nodes;
492 /* Set PHI nodes of a basic block BB to SEQ. */
494 static inline void
495 set_phi_nodes (basic_block bb, gimple_seq seq)
497 gimple_stmt_iterator i;
499 gcc_assert (!(bb->flags & BB_RTL));
500 bb->il.gimple->phi_nodes = seq;
501 if (seq)
502 for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
503 gimple_set_bb (gsi_stmt (i), bb);
506 /* Return the phi argument which contains the specified use. */
508 static inline int
509 phi_arg_index_from_use (use_operand_p use)
511 struct phi_arg_d *element, *root;
512 size_t index;
513 gimple phi;
515 /* Since the use is the first thing in a PHI argument element, we can
516 calculate its index based on casting it to an argument, and performing
517 pointer arithmetic. */
519 phi = USE_STMT (use);
520 gcc_assert (gimple_code (phi) == GIMPLE_PHI);
522 element = (struct phi_arg_d *)use;
523 root = gimple_phi_arg (phi, 0);
524 index = element - root;
526 #ifdef ENABLE_CHECKING
527 /* Make sure the calculation doesn't have any leftover bytes. If it does,
528 then imm_use is likely not the first element in phi_arg_d. */
529 gcc_assert (
530 (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
531 gcc_assert (index < gimple_phi_capacity (phi));
532 #endif
534 return index;
537 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
539 static inline void
540 set_is_used (tree var)
542 var_ann_t ann = get_var_ann (var);
543 ann->used = 1;
547 /* Return true if T (assumed to be a DECL) is a global variable.
548 A variable is considered global if its storage is not automatic. */
550 static inline bool
551 is_global_var (const_tree t)
553 return (TREE_STATIC (t) || DECL_EXTERNAL (t));
557 /* Return true if VAR may be aliased. A variable is considered as
558 maybe aliased if it has its address taken by the local TU
559 or possibly by another TU. */
561 static inline bool
562 may_be_aliased (const_tree var)
564 return (TREE_PUBLIC (var) || DECL_EXTERNAL (var) || TREE_ADDRESSABLE (var));
568 /* PHI nodes should contain only ssa_names and invariants. A test
569 for ssa_name is definitely simpler; don't let invalid contents
570 slip in in the meantime. */
572 static inline bool
573 phi_ssa_name_p (const_tree t)
575 if (TREE_CODE (t) == SSA_NAME)
576 return true;
577 #ifdef ENABLE_CHECKING
578 gcc_assert (is_gimple_min_invariant (t));
579 #endif
580 return false;
584 /* Returns the loop of the statement STMT. */
586 static inline struct loop *
587 loop_containing_stmt (gimple stmt)
589 basic_block bb = gimple_bb (stmt);
590 if (!bb)
591 return NULL;
593 return bb->loop_father;
597 /* Return true if VAR is clobbered by function calls. */
598 static inline bool
599 is_call_clobbered (const_tree var)
601 return (is_global_var (var)
602 || (may_be_aliased (var)
603 && pt_solution_includes (&cfun->gimple_df->escaped, var)));
606 /* Return true if VAR is used by function calls. */
607 static inline bool
608 is_call_used (const_tree var)
610 return (is_call_clobbered (var)
611 || (may_be_aliased (var)
612 && pt_solution_includes (&cfun->gimple_df->callused, var)));
615 /* Return the common annotation for T. Return NULL if the annotation
616 doesn't already exist. */
617 static inline tree_ann_common_t
618 tree_common_ann (const_tree t)
620 /* Watch out static variables with unshared annotations. */
621 if (DECL_P (t) && TREE_CODE (t) == VAR_DECL)
622 return &var_ann (t)->common;
623 return &t->base.ann->common;
626 /* Return a common annotation for T. Create the constant annotation if it
627 doesn't exist. */
628 static inline tree_ann_common_t
629 get_tree_common_ann (tree t)
631 tree_ann_common_t ann = tree_common_ann (t);
632 return (ann) ? ann : create_tree_common_ann (t);
635 /* ----------------------------------------------------------------------- */
637 /* The following set of routines are used to iterator over various type of
638 SSA operands. */
640 /* Return true if PTR is finished iterating. */
641 static inline bool
642 op_iter_done (const ssa_op_iter *ptr)
644 return ptr->done;
647 /* Get the next iterator use value for PTR. */
648 static inline use_operand_p
649 op_iter_next_use (ssa_op_iter *ptr)
651 use_operand_p use_p;
652 #ifdef ENABLE_CHECKING
653 gcc_assert (ptr->iter_type == ssa_op_iter_use);
654 #endif
655 if (ptr->uses)
657 use_p = USE_OP_PTR (ptr->uses);
658 ptr->uses = ptr->uses->next;
659 return use_p;
661 if (ptr->phi_i < ptr->num_phi)
663 return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
665 ptr->done = true;
666 return NULL_USE_OPERAND_P;
669 /* Get the next iterator def value for PTR. */
670 static inline def_operand_p
671 op_iter_next_def (ssa_op_iter *ptr)
673 def_operand_p def_p;
674 #ifdef ENABLE_CHECKING
675 gcc_assert (ptr->iter_type == ssa_op_iter_def);
676 #endif
677 if (ptr->defs)
679 def_p = DEF_OP_PTR (ptr->defs);
680 ptr->defs = ptr->defs->next;
681 return def_p;
683 ptr->done = true;
684 return NULL_DEF_OPERAND_P;
687 /* Get the next iterator tree value for PTR. */
688 static inline tree
689 op_iter_next_tree (ssa_op_iter *ptr)
691 tree val;
692 #ifdef ENABLE_CHECKING
693 gcc_assert (ptr->iter_type == ssa_op_iter_tree);
694 #endif
695 if (ptr->uses)
697 val = USE_OP (ptr->uses);
698 ptr->uses = ptr->uses->next;
699 return val;
701 if (ptr->defs)
703 val = DEF_OP (ptr->defs);
704 ptr->defs = ptr->defs->next;
705 return val;
708 ptr->done = true;
709 return NULL_TREE;
714 /* This functions clears the iterator PTR, and marks it done. This is normally
715 used to prevent warnings in the compile about might be uninitialized
716 components. */
718 static inline void
719 clear_and_done_ssa_iter (ssa_op_iter *ptr)
721 ptr->defs = NULL;
722 ptr->uses = NULL;
723 ptr->iter_type = ssa_op_iter_none;
724 ptr->phi_i = 0;
725 ptr->num_phi = 0;
726 ptr->phi_stmt = NULL;
727 ptr->done = true;
730 /* Initialize the iterator PTR to the virtual defs in STMT. */
731 static inline void
732 op_iter_init (ssa_op_iter *ptr, gimple stmt, int flags)
734 /* We do not support iterating over virtual defs or uses without
735 iterating over defs or uses at the same time. */
736 gcc_assert ((!(flags & SSA_OP_VDEF) || (flags & SSA_OP_DEF))
737 && (!(flags & SSA_OP_VUSE) || (flags & SSA_OP_USE)));
738 ptr->defs = (flags & (SSA_OP_DEF|SSA_OP_VDEF)) ? gimple_def_ops (stmt) : NULL;
739 if (!(flags & SSA_OP_VDEF)
740 && ptr->defs
741 && gimple_vdef (stmt) != NULL_TREE)
742 ptr->defs = ptr->defs->next;
743 ptr->uses = (flags & (SSA_OP_USE|SSA_OP_VUSE)) ? gimple_use_ops (stmt) : NULL;
744 if (!(flags & SSA_OP_VUSE)
745 && ptr->uses
746 && gimple_vuse (stmt) != NULL_TREE)
747 ptr->uses = ptr->uses->next;
748 ptr->done = false;
750 ptr->phi_i = 0;
751 ptr->num_phi = 0;
752 ptr->phi_stmt = NULL;
755 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
756 the first use. */
757 static inline use_operand_p
758 op_iter_init_use (ssa_op_iter *ptr, gimple stmt, int flags)
760 gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0
761 && (flags & SSA_OP_USE));
762 op_iter_init (ptr, stmt, flags);
763 ptr->iter_type = ssa_op_iter_use;
764 return op_iter_next_use (ptr);
767 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
768 the first def. */
769 static inline def_operand_p
770 op_iter_init_def (ssa_op_iter *ptr, gimple stmt, int flags)
772 gcc_assert ((flags & SSA_OP_ALL_USES) == 0
773 && (flags & SSA_OP_DEF));
774 op_iter_init (ptr, stmt, flags);
775 ptr->iter_type = ssa_op_iter_def;
776 return op_iter_next_def (ptr);
779 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
780 the first operand as a tree. */
781 static inline tree
782 op_iter_init_tree (ssa_op_iter *ptr, gimple stmt, int flags)
784 op_iter_init (ptr, stmt, flags);
785 ptr->iter_type = ssa_op_iter_tree;
786 return op_iter_next_tree (ptr);
790 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
791 return NULL. */
792 static inline tree
793 single_ssa_tree_operand (gimple stmt, int flags)
795 tree var;
796 ssa_op_iter iter;
798 var = op_iter_init_tree (&iter, stmt, flags);
799 if (op_iter_done (&iter))
800 return NULL_TREE;
801 op_iter_next_tree (&iter);
802 if (op_iter_done (&iter))
803 return var;
804 return NULL_TREE;
808 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
809 return NULL. */
810 static inline use_operand_p
811 single_ssa_use_operand (gimple stmt, int flags)
813 use_operand_p var;
814 ssa_op_iter iter;
816 var = op_iter_init_use (&iter, stmt, flags);
817 if (op_iter_done (&iter))
818 return NULL_USE_OPERAND_P;
819 op_iter_next_use (&iter);
820 if (op_iter_done (&iter))
821 return var;
822 return NULL_USE_OPERAND_P;
827 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
828 return NULL. */
829 static inline def_operand_p
830 single_ssa_def_operand (gimple stmt, int flags)
832 def_operand_p var;
833 ssa_op_iter iter;
835 var = op_iter_init_def (&iter, stmt, flags);
836 if (op_iter_done (&iter))
837 return NULL_DEF_OPERAND_P;
838 op_iter_next_def (&iter);
839 if (op_iter_done (&iter))
840 return var;
841 return NULL_DEF_OPERAND_P;
845 /* Return true if there are zero operands in STMT matching the type
846 given in FLAGS. */
847 static inline bool
848 zero_ssa_operands (gimple stmt, int flags)
850 ssa_op_iter iter;
852 op_iter_init_tree (&iter, stmt, flags);
853 return op_iter_done (&iter);
857 /* Return the number of operands matching FLAGS in STMT. */
858 static inline int
859 num_ssa_operands (gimple stmt, int flags)
861 ssa_op_iter iter;
862 tree t;
863 int num = 0;
865 FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
866 num++;
867 return num;
871 /* Delink all immediate_use information for STMT. */
872 static inline void
873 delink_stmt_imm_use (gimple stmt)
875 ssa_op_iter iter;
876 use_operand_p use_p;
878 if (ssa_operands_active ())
879 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_ALL_USES)
880 delink_imm_use (use_p);
884 /* If there is a single DEF in the PHI node which matches FLAG, return it.
885 Otherwise return NULL_DEF_OPERAND_P. */
886 static inline tree
887 single_phi_def (gimple stmt, int flags)
889 tree def = PHI_RESULT (stmt);
890 if ((flags & SSA_OP_DEF) && is_gimple_reg (def))
891 return def;
892 if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
893 return def;
894 return NULL_TREE;
897 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
898 be either SSA_OP_USES or SSA_OP_VIRTUAL_USES. */
899 static inline use_operand_p
900 op_iter_init_phiuse (ssa_op_iter *ptr, gimple phi, int flags)
902 tree phi_def = gimple_phi_result (phi);
903 int comp;
905 clear_and_done_ssa_iter (ptr);
906 ptr->done = false;
908 gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
910 comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
912 /* If the PHI node doesn't the operand type we care about, we're done. */
913 if ((flags & comp) == 0)
915 ptr->done = true;
916 return NULL_USE_OPERAND_P;
919 ptr->phi_stmt = phi;
920 ptr->num_phi = gimple_phi_num_args (phi);
921 ptr->iter_type = ssa_op_iter_use;
922 return op_iter_next_use (ptr);
926 /* Start an iterator for a PHI definition. */
928 static inline def_operand_p
929 op_iter_init_phidef (ssa_op_iter *ptr, gimple phi, int flags)
931 tree phi_def = PHI_RESULT (phi);
932 int comp;
934 clear_and_done_ssa_iter (ptr);
935 ptr->done = false;
937 gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
939 comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
941 /* If the PHI node doesn't have the operand type we care about,
942 we're done. */
943 if ((flags & comp) == 0)
945 ptr->done = true;
946 return NULL_DEF_OPERAND_P;
949 ptr->iter_type = ssa_op_iter_def;
950 /* The first call to op_iter_next_def will terminate the iterator since
951 all the fields are NULL. Simply return the result here as the first and
952 therefore only result. */
953 return PHI_RESULT_PTR (phi);
956 /* Return true is IMM has reached the end of the immediate use stmt list. */
958 static inline bool
959 end_imm_use_stmt_p (const imm_use_iterator *imm)
961 return (imm->imm_use == imm->end_p);
964 /* Finished the traverse of an immediate use stmt list IMM by removing the
965 placeholder node from the list. */
967 static inline void
968 end_imm_use_stmt_traverse (imm_use_iterator *imm)
970 delink_imm_use (&(imm->iter_node));
973 /* Immediate use traversal of uses within a stmt require that all the
974 uses on a stmt be sequentially listed. This routine is used to build up
975 this sequential list by adding USE_P to the end of the current list
976 currently delimited by HEAD and LAST_P. The new LAST_P value is
977 returned. */
979 static inline use_operand_p
980 move_use_after_head (use_operand_p use_p, use_operand_p head,
981 use_operand_p last_p)
983 gcc_assert (USE_FROM_PTR (use_p) == USE_FROM_PTR (head));
984 /* Skip head when we find it. */
985 if (use_p != head)
987 /* If use_p is already linked in after last_p, continue. */
988 if (last_p->next == use_p)
989 last_p = use_p;
990 else
992 /* Delink from current location, and link in at last_p. */
993 delink_imm_use (use_p);
994 link_imm_use_to_list (use_p, last_p);
995 last_p = use_p;
998 return last_p;
1002 /* This routine will relink all uses with the same stmt as HEAD into the list
1003 immediately following HEAD for iterator IMM. */
1005 static inline void
1006 link_use_stmts_after (use_operand_p head, imm_use_iterator *imm)
1008 use_operand_p use_p;
1009 use_operand_p last_p = head;
1010 gimple head_stmt = USE_STMT (head);
1011 tree use = USE_FROM_PTR (head);
1012 ssa_op_iter op_iter;
1013 int flag;
1015 /* Only look at virtual or real uses, depending on the type of HEAD. */
1016 flag = (is_gimple_reg (use) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1018 if (gimple_code (head_stmt) == GIMPLE_PHI)
1020 FOR_EACH_PHI_ARG (use_p, head_stmt, op_iter, flag)
1021 if (USE_FROM_PTR (use_p) == use)
1022 last_p = move_use_after_head (use_p, head, last_p);
1024 else
1026 if (flag == SSA_OP_USE)
1028 FOR_EACH_SSA_USE_OPERAND (use_p, head_stmt, op_iter, flag)
1029 if (USE_FROM_PTR (use_p) == use)
1030 last_p = move_use_after_head (use_p, head, last_p);
1032 else if ((use_p = gimple_vuse_op (head_stmt)) != NULL_USE_OPERAND_P)
1034 if (USE_FROM_PTR (use_p) == use)
1035 last_p = move_use_after_head (use_p, head, last_p);
1038 /* Link iter node in after last_p. */
1039 if (imm->iter_node.prev != NULL)
1040 delink_imm_use (&imm->iter_node);
1041 link_imm_use_to_list (&(imm->iter_node), last_p);
1044 /* Initialize IMM to traverse over uses of VAR. Return the first statement. */
1045 static inline gimple
1046 first_imm_use_stmt (imm_use_iterator *imm, tree var)
1048 gcc_assert (TREE_CODE (var) == SSA_NAME);
1050 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
1051 imm->imm_use = imm->end_p->next;
1052 imm->next_imm_name = NULL_USE_OPERAND_P;
1054 /* iter_node is used as a marker within the immediate use list to indicate
1055 where the end of the current stmt's uses are. Initialize it to NULL
1056 stmt and use, which indicates a marker node. */
1057 imm->iter_node.prev = NULL_USE_OPERAND_P;
1058 imm->iter_node.next = NULL_USE_OPERAND_P;
1059 imm->iter_node.loc.stmt = NULL;
1060 imm->iter_node.use = NULL;
1062 if (end_imm_use_stmt_p (imm))
1063 return NULL;
1065 link_use_stmts_after (imm->imm_use, imm);
1067 return USE_STMT (imm->imm_use);
1070 /* Bump IMM to the next stmt which has a use of var. */
1072 static inline gimple
1073 next_imm_use_stmt (imm_use_iterator *imm)
1075 imm->imm_use = imm->iter_node.next;
1076 if (end_imm_use_stmt_p (imm))
1078 if (imm->iter_node.prev != NULL)
1079 delink_imm_use (&imm->iter_node);
1080 return NULL;
1083 link_use_stmts_after (imm->imm_use, imm);
1084 return USE_STMT (imm->imm_use);
1087 /* This routine will return the first use on the stmt IMM currently refers
1088 to. */
1090 static inline use_operand_p
1091 first_imm_use_on_stmt (imm_use_iterator *imm)
1093 imm->next_imm_name = imm->imm_use->next;
1094 return imm->imm_use;
1097 /* Return TRUE if the last use on the stmt IMM refers to has been visited. */
1099 static inline bool
1100 end_imm_use_on_stmt_p (const imm_use_iterator *imm)
1102 return (imm->imm_use == &(imm->iter_node));
1105 /* Bump to the next use on the stmt IMM refers to, return NULL if done. */
1107 static inline use_operand_p
1108 next_imm_use_on_stmt (imm_use_iterator *imm)
1110 imm->imm_use = imm->next_imm_name;
1111 if (end_imm_use_on_stmt_p (imm))
1112 return NULL_USE_OPERAND_P;
1113 else
1115 imm->next_imm_name = imm->imm_use->next;
1116 return imm->imm_use;
1120 /* Return true if VAR cannot be modified by the program. */
1122 static inline bool
1123 unmodifiable_var_p (const_tree var)
1125 if (TREE_CODE (var) == SSA_NAME)
1126 var = SSA_NAME_VAR (var);
1128 return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1131 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it. */
1133 static inline bool
1134 array_ref_contains_indirect_ref (const_tree ref)
1136 gcc_assert (TREE_CODE (ref) == ARRAY_REF);
1138 do {
1139 ref = TREE_OPERAND (ref, 0);
1140 } while (handled_component_p (ref));
1142 return TREE_CODE (ref) == INDIRECT_REF;
1145 /* Return true if REF, a handled component reference, has an ARRAY_REF
1146 somewhere in it. */
1148 static inline bool
1149 ref_contains_array_ref (const_tree ref)
1151 gcc_assert (handled_component_p (ref));
1153 do {
1154 if (TREE_CODE (ref) == ARRAY_REF)
1155 return true;
1156 ref = TREE_OPERAND (ref, 0);
1157 } while (handled_component_p (ref));
1159 return false;
1162 /* Return true, if the two ranges [POS1, SIZE1] and [POS2, SIZE2]
1163 overlap. SIZE1 and/or SIZE2 can be (unsigned)-1 in which case the
1164 range is open-ended. Otherwise return false. */
1166 static inline bool
1167 ranges_overlap_p (unsigned HOST_WIDE_INT pos1,
1168 unsigned HOST_WIDE_INT size1,
1169 unsigned HOST_WIDE_INT pos2,
1170 unsigned HOST_WIDE_INT size2)
1172 if (pos1 >= pos2
1173 && (size2 == (unsigned HOST_WIDE_INT)-1
1174 || pos1 < (pos2 + size2)))
1175 return true;
1176 if (pos2 >= pos1
1177 && (size1 == (unsigned HOST_WIDE_INT)-1
1178 || pos2 < (pos1 + size1)))
1179 return true;
1181 return false;
1184 /* Accessor to tree-ssa-operands.c caches. */
1185 static inline struct ssa_operands *
1186 gimple_ssa_operands (const struct function *fun)
1188 return &fun->gimple_df->ssa_operands;
1191 /* Given an edge_var_map V, return the PHI arg definition. */
1193 static inline tree
1194 redirect_edge_var_map_def (edge_var_map *v)
1196 return v->def;
1199 /* Given an edge_var_map V, return the PHI result. */
1201 static inline tree
1202 redirect_edge_var_map_result (edge_var_map *v)
1204 return v->result;
1208 /* Return an SSA_NAME node for variable VAR defined in statement STMT
1209 in function cfun. */
1211 static inline tree
1212 make_ssa_name (tree var, gimple stmt)
1214 return make_ssa_name_fn (cfun, var, stmt);
1217 #endif /* _TREE_FLOW_INLINE_H */