Fix typo in ChangeLog entry date.
[official-gcc.git] / gcc / tree-flow-inline.h
blobe6de3772c3c004872e3b03b8e3eb521021de436c
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 /* Get the number of the next statement uid to be allocated. */
176 static inline unsigned int
177 gimple_stmt_max_uid (struct function *fn)
179 return fn->last_stmt_uid;
182 /* Set the number of the next statement uid to be allocated. */
183 static inline void
184 set_gimple_stmt_max_uid (struct function *fn, unsigned int maxid)
186 fn->last_stmt_uid = maxid;
189 /* Set the number of the next statement uid to be allocated. */
190 static inline unsigned int
191 inc_gimple_stmt_max_uid (struct function *fn)
193 return fn->last_stmt_uid++;
196 /* Return the annotation type for annotation ANN. */
197 static inline enum tree_ann_type
198 ann_type (tree_ann_t ann)
200 return ann->common.type;
203 /* Return the line number for EXPR, or return -1 if we have no line
204 number information for it. */
205 static inline int
206 get_lineno (const_gimple stmt)
208 location_t loc;
210 if (!stmt)
211 return -1;
213 loc = gimple_location (stmt);
214 if (loc == UNKNOWN_LOCATION)
215 return -1;
217 return LOCATION_LINE (loc);
220 /* Delink an immediate_uses node from its chain. */
221 static inline void
222 delink_imm_use (ssa_use_operand_t *linknode)
224 /* Return if this node is not in a list. */
225 if (linknode->prev == NULL)
226 return;
228 linknode->prev->next = linknode->next;
229 linknode->next->prev = linknode->prev;
230 linknode->prev = NULL;
231 linknode->next = NULL;
234 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
235 static inline void
236 link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
238 /* Link the new node at the head of the list. If we are in the process of
239 traversing the list, we won't visit any new nodes added to it. */
240 linknode->prev = list;
241 linknode->next = list->next;
242 list->next->prev = linknode;
243 list->next = linknode;
246 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
247 static inline void
248 link_imm_use (ssa_use_operand_t *linknode, tree def)
250 ssa_use_operand_t *root;
252 if (!def || TREE_CODE (def) != SSA_NAME)
253 linknode->prev = NULL;
254 else
256 root = &(SSA_NAME_IMM_USE_NODE (def));
257 #ifdef ENABLE_CHECKING
258 if (linknode->use)
259 gcc_assert (*(linknode->use) == def);
260 #endif
261 link_imm_use_to_list (linknode, root);
265 /* Set the value of a use pointed to by USE to VAL. */
266 static inline void
267 set_ssa_use_from_ptr (use_operand_p use, tree val)
269 delink_imm_use (use);
270 *(use->use) = val;
271 link_imm_use (use, val);
274 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
275 in STMT. */
276 static inline void
277 link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, gimple stmt)
279 if (stmt)
280 link_imm_use (linknode, def);
281 else
282 link_imm_use (linknode, NULL);
283 linknode->loc.stmt = stmt;
286 /* Relink a new node in place of an old node in the list. */
287 static inline void
288 relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
290 /* The node one had better be in the same list. */
291 gcc_assert (*(old->use) == *(node->use));
292 node->prev = old->prev;
293 node->next = old->next;
294 if (old->prev)
296 old->prev->next = node;
297 old->next->prev = node;
298 /* Remove the old node from the list. */
299 old->prev = NULL;
303 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
304 in STMT. */
305 static inline void
306 relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old,
307 gimple stmt)
309 if (stmt)
310 relink_imm_use (linknode, old);
311 else
312 link_imm_use (linknode, NULL);
313 linknode->loc.stmt = stmt;
317 /* Return true is IMM has reached the end of the immediate use list. */
318 static inline bool
319 end_readonly_imm_use_p (const imm_use_iterator *imm)
321 return (imm->imm_use == imm->end_p);
324 /* Initialize iterator IMM to process the list for VAR. */
325 static inline use_operand_p
326 first_readonly_imm_use (imm_use_iterator *imm, tree var)
328 gcc_assert (TREE_CODE (var) == SSA_NAME);
330 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
331 imm->imm_use = imm->end_p->next;
332 #ifdef ENABLE_CHECKING
333 imm->iter_node.next = imm->imm_use->next;
334 #endif
335 if (end_readonly_imm_use_p (imm))
336 return NULL_USE_OPERAND_P;
337 return imm->imm_use;
340 /* Bump IMM to the next use in the list. */
341 static inline use_operand_p
342 next_readonly_imm_use (imm_use_iterator *imm)
344 use_operand_p old = imm->imm_use;
346 #ifdef ENABLE_CHECKING
347 /* If this assertion fails, it indicates the 'next' pointer has changed
348 since the last bump. This indicates that the list is being modified
349 via stmt changes, or SET_USE, or somesuch thing, and you need to be
350 using the SAFE version of the iterator. */
351 gcc_assert (imm->iter_node.next == old->next);
352 imm->iter_node.next = old->next->next;
353 #endif
355 imm->imm_use = old->next;
356 if (end_readonly_imm_use_p (imm))
357 return NULL_USE_OPERAND_P;
358 return imm->imm_use;
361 /* Return true if VAR has no uses. */
362 static inline bool
363 has_zero_uses (const_tree var)
365 const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
366 /* A single use means there is no items in the list. */
367 return (ptr == ptr->next);
370 /* Return true if VAR has a single use. */
371 static inline bool
372 has_single_use (const_tree var)
374 const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
375 /* A single use means there is one item in the list. */
376 return (ptr != ptr->next && ptr == ptr->next->next);
380 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
381 to the use pointer and stmt of occurrence. */
382 static inline bool
383 single_imm_use (const_tree var, use_operand_p *use_p, gimple *stmt)
385 const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
386 if (ptr != ptr->next && ptr == ptr->next->next)
388 *use_p = ptr->next;
389 *stmt = ptr->next->loc.stmt;
390 return true;
392 *use_p = NULL_USE_OPERAND_P;
393 *stmt = NULL;
394 return false;
397 /* Return the number of immediate uses of VAR. */
398 static inline unsigned int
399 num_imm_uses (const_tree var)
401 const ssa_use_operand_t *const start = &(SSA_NAME_IMM_USE_NODE (var));
402 const ssa_use_operand_t *ptr;
403 unsigned int num = 0;
405 for (ptr = start->next; ptr != start; ptr = ptr->next)
406 num++;
408 return num;
411 /* Return the tree pointed-to by USE. */
412 static inline tree
413 get_use_from_ptr (use_operand_p use)
415 return *(use->use);
418 /* Return the tree pointed-to by DEF. */
419 static inline tree
420 get_def_from_ptr (def_operand_p def)
422 return *def;
425 /* Return a use_operand_p pointer for argument I of PHI node GS. */
427 static inline use_operand_p
428 gimple_phi_arg_imm_use_ptr (gimple gs, int i)
430 return &gimple_phi_arg (gs, i)->imm_use;
433 /* Return the tree operand for argument I of PHI node GS. */
435 static inline tree
436 gimple_phi_arg_def (gimple gs, size_t index)
438 struct phi_arg_d *pd = gimple_phi_arg (gs, index);
439 return get_use_from_ptr (&pd->imm_use);
442 /* Return a pointer to the tree operand for argument I of PHI node GS. */
444 static inline tree *
445 gimple_phi_arg_def_ptr (gimple gs, size_t index)
447 return &gimple_phi_arg (gs, index)->def;
450 /* Return the edge associated with argument I of phi node GS. */
452 static inline edge
453 gimple_phi_arg_edge (gimple gs, size_t i)
455 return EDGE_PRED (gimple_bb (gs), i);
458 /* Return the PHI nodes for basic block BB, or NULL if there are no
459 PHI nodes. */
460 static inline gimple_seq
461 phi_nodes (const_basic_block bb)
463 gcc_assert (!(bb->flags & BB_RTL));
464 if (!bb->il.gimple)
465 return NULL;
466 return bb->il.gimple->phi_nodes;
469 /* Set PHI nodes of a basic block BB to SEQ. */
471 static inline void
472 set_phi_nodes (basic_block bb, gimple_seq seq)
474 gimple_stmt_iterator i;
476 gcc_assert (!(bb->flags & BB_RTL));
477 bb->il.gimple->phi_nodes = seq;
478 if (seq)
479 for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
480 gimple_set_bb (gsi_stmt (i), bb);
483 /* Return the phi argument which contains the specified use. */
485 static inline int
486 phi_arg_index_from_use (use_operand_p use)
488 struct phi_arg_d *element, *root;
489 size_t index;
490 gimple phi;
492 /* Since the use is the first thing in a PHI argument element, we can
493 calculate its index based on casting it to an argument, and performing
494 pointer arithmetic. */
496 phi = USE_STMT (use);
497 gcc_assert (gimple_code (phi) == GIMPLE_PHI);
499 element = (struct phi_arg_d *)use;
500 root = gimple_phi_arg (phi, 0);
501 index = element - root;
503 #ifdef ENABLE_CHECKING
504 /* Make sure the calculation doesn't have any leftover bytes. If it does,
505 then imm_use is likely not the first element in phi_arg_d. */
506 gcc_assert (
507 (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
508 gcc_assert (index < gimple_phi_capacity (phi));
509 #endif
511 return index;
514 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
516 static inline void
517 set_is_used (tree var)
519 var_ann_t ann = get_var_ann (var);
520 ann->used = 1;
524 /* Return true if T (assumed to be a DECL) is a global variable.
525 A variable is considered global if its storage is not automatic. */
527 static inline bool
528 is_global_var (const_tree t)
530 return (TREE_STATIC (t) || DECL_EXTERNAL (t));
534 /* Return true if VAR may be aliased. A variable is considered as
535 maybe aliased if it has its address taken by the local TU
536 or possibly by another TU. */
538 static inline bool
539 may_be_aliased (const_tree var)
541 return (TREE_PUBLIC (var) || DECL_EXTERNAL (var) || TREE_ADDRESSABLE (var));
545 /* PHI nodes should contain only ssa_names and invariants. A test
546 for ssa_name is definitely simpler; don't let invalid contents
547 slip in in the meantime. */
549 static inline bool
550 phi_ssa_name_p (const_tree t)
552 if (TREE_CODE (t) == SSA_NAME)
553 return true;
554 #ifdef ENABLE_CHECKING
555 gcc_assert (is_gimple_min_invariant (t));
556 #endif
557 return false;
561 /* Returns the loop of the statement STMT. */
563 static inline struct loop *
564 loop_containing_stmt (gimple stmt)
566 basic_block bb = gimple_bb (stmt);
567 if (!bb)
568 return NULL;
570 return bb->loop_father;
574 /* Return true if VAR is clobbered by function calls. */
575 static inline bool
576 is_call_clobbered (const_tree var)
578 return (is_global_var (var)
579 || (may_be_aliased (var)
580 && pt_solution_includes (&cfun->gimple_df->escaped, var)));
583 /* Return true if VAR is used by function calls. */
584 static inline bool
585 is_call_used (const_tree var)
587 return (is_call_clobbered (var)
588 || (may_be_aliased (var)
589 && pt_solution_includes (&cfun->gimple_df->callused, var)));
592 /* Return the common annotation for T. Return NULL if the annotation
593 doesn't already exist. */
594 static inline tree_ann_common_t
595 tree_common_ann (const_tree t)
597 /* Watch out static variables with unshared annotations. */
598 if (DECL_P (t) && TREE_CODE (t) == VAR_DECL)
599 return &var_ann (t)->common;
600 return &t->base.ann->common;
603 /* Return a common annotation for T. Create the constant annotation if it
604 doesn't exist. */
605 static inline tree_ann_common_t
606 get_tree_common_ann (tree t)
608 tree_ann_common_t ann = tree_common_ann (t);
609 return (ann) ? ann : create_tree_common_ann (t);
612 /* ----------------------------------------------------------------------- */
614 /* The following set of routines are used to iterator over various type of
615 SSA operands. */
617 /* Return true if PTR is finished iterating. */
618 static inline bool
619 op_iter_done (const ssa_op_iter *ptr)
621 return ptr->done;
624 /* Get the next iterator use value for PTR. */
625 static inline use_operand_p
626 op_iter_next_use (ssa_op_iter *ptr)
628 use_operand_p use_p;
629 #ifdef ENABLE_CHECKING
630 gcc_assert (ptr->iter_type == ssa_op_iter_use);
631 #endif
632 if (ptr->uses)
634 use_p = USE_OP_PTR (ptr->uses);
635 ptr->uses = ptr->uses->next;
636 return use_p;
638 if (ptr->phi_i < ptr->num_phi)
640 return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
642 ptr->done = true;
643 return NULL_USE_OPERAND_P;
646 /* Get the next iterator def value for PTR. */
647 static inline def_operand_p
648 op_iter_next_def (ssa_op_iter *ptr)
650 def_operand_p def_p;
651 #ifdef ENABLE_CHECKING
652 gcc_assert (ptr->iter_type == ssa_op_iter_def);
653 #endif
654 if (ptr->defs)
656 def_p = DEF_OP_PTR (ptr->defs);
657 ptr->defs = ptr->defs->next;
658 return def_p;
660 ptr->done = true;
661 return NULL_DEF_OPERAND_P;
664 /* Get the next iterator tree value for PTR. */
665 static inline tree
666 op_iter_next_tree (ssa_op_iter *ptr)
668 tree val;
669 #ifdef ENABLE_CHECKING
670 gcc_assert (ptr->iter_type == ssa_op_iter_tree);
671 #endif
672 if (ptr->uses)
674 val = USE_OP (ptr->uses);
675 ptr->uses = ptr->uses->next;
676 return val;
678 if (ptr->defs)
680 val = DEF_OP (ptr->defs);
681 ptr->defs = ptr->defs->next;
682 return val;
685 ptr->done = true;
686 return NULL_TREE;
691 /* This functions clears the iterator PTR, and marks it done. This is normally
692 used to prevent warnings in the compile about might be uninitialized
693 components. */
695 static inline void
696 clear_and_done_ssa_iter (ssa_op_iter *ptr)
698 ptr->defs = NULL;
699 ptr->uses = NULL;
700 ptr->iter_type = ssa_op_iter_none;
701 ptr->phi_i = 0;
702 ptr->num_phi = 0;
703 ptr->phi_stmt = NULL;
704 ptr->done = true;
707 /* Initialize the iterator PTR to the virtual defs in STMT. */
708 static inline void
709 op_iter_init (ssa_op_iter *ptr, gimple stmt, int flags)
711 /* We do not support iterating over virtual defs or uses without
712 iterating over defs or uses at the same time. */
713 gcc_assert ((!(flags & SSA_OP_VDEF) || (flags & SSA_OP_DEF))
714 && (!(flags & SSA_OP_VUSE) || (flags & SSA_OP_USE)));
715 ptr->defs = (flags & (SSA_OP_DEF|SSA_OP_VDEF)) ? gimple_def_ops (stmt) : NULL;
716 if (!(flags & SSA_OP_VDEF)
717 && ptr->defs
718 && gimple_vdef (stmt) != NULL_TREE)
719 ptr->defs = ptr->defs->next;
720 ptr->uses = (flags & (SSA_OP_USE|SSA_OP_VUSE)) ? gimple_use_ops (stmt) : NULL;
721 if (!(flags & SSA_OP_VUSE)
722 && ptr->uses
723 && gimple_vuse (stmt) != NULL_TREE)
724 ptr->uses = ptr->uses->next;
725 ptr->done = false;
727 ptr->phi_i = 0;
728 ptr->num_phi = 0;
729 ptr->phi_stmt = NULL;
732 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
733 the first use. */
734 static inline use_operand_p
735 op_iter_init_use (ssa_op_iter *ptr, gimple stmt, int flags)
737 gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0
738 && (flags & SSA_OP_USE));
739 op_iter_init (ptr, stmt, flags);
740 ptr->iter_type = ssa_op_iter_use;
741 return op_iter_next_use (ptr);
744 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
745 the first def. */
746 static inline def_operand_p
747 op_iter_init_def (ssa_op_iter *ptr, gimple stmt, int flags)
749 gcc_assert ((flags & SSA_OP_ALL_USES) == 0
750 && (flags & SSA_OP_DEF));
751 op_iter_init (ptr, stmt, flags);
752 ptr->iter_type = ssa_op_iter_def;
753 return op_iter_next_def (ptr);
756 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
757 the first operand as a tree. */
758 static inline tree
759 op_iter_init_tree (ssa_op_iter *ptr, gimple stmt, int flags)
761 op_iter_init (ptr, stmt, flags);
762 ptr->iter_type = ssa_op_iter_tree;
763 return op_iter_next_tree (ptr);
767 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
768 return NULL. */
769 static inline tree
770 single_ssa_tree_operand (gimple stmt, int flags)
772 tree var;
773 ssa_op_iter iter;
775 var = op_iter_init_tree (&iter, stmt, flags);
776 if (op_iter_done (&iter))
777 return NULL_TREE;
778 op_iter_next_tree (&iter);
779 if (op_iter_done (&iter))
780 return var;
781 return NULL_TREE;
785 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
786 return NULL. */
787 static inline use_operand_p
788 single_ssa_use_operand (gimple stmt, int flags)
790 use_operand_p var;
791 ssa_op_iter iter;
793 var = op_iter_init_use (&iter, stmt, flags);
794 if (op_iter_done (&iter))
795 return NULL_USE_OPERAND_P;
796 op_iter_next_use (&iter);
797 if (op_iter_done (&iter))
798 return var;
799 return NULL_USE_OPERAND_P;
804 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
805 return NULL. */
806 static inline def_operand_p
807 single_ssa_def_operand (gimple stmt, int flags)
809 def_operand_p var;
810 ssa_op_iter iter;
812 var = op_iter_init_def (&iter, stmt, flags);
813 if (op_iter_done (&iter))
814 return NULL_DEF_OPERAND_P;
815 op_iter_next_def (&iter);
816 if (op_iter_done (&iter))
817 return var;
818 return NULL_DEF_OPERAND_P;
822 /* Return true if there are zero operands in STMT matching the type
823 given in FLAGS. */
824 static inline bool
825 zero_ssa_operands (gimple stmt, int flags)
827 ssa_op_iter iter;
829 op_iter_init_tree (&iter, stmt, flags);
830 return op_iter_done (&iter);
834 /* Return the number of operands matching FLAGS in STMT. */
835 static inline int
836 num_ssa_operands (gimple stmt, int flags)
838 ssa_op_iter iter;
839 tree t;
840 int num = 0;
842 FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
843 num++;
844 return num;
848 /* Delink all immediate_use information for STMT. */
849 static inline void
850 delink_stmt_imm_use (gimple stmt)
852 ssa_op_iter iter;
853 use_operand_p use_p;
855 if (ssa_operands_active ())
856 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_ALL_USES)
857 delink_imm_use (use_p);
861 /* If there is a single DEF in the PHI node which matches FLAG, return it.
862 Otherwise return NULL_DEF_OPERAND_P. */
863 static inline tree
864 single_phi_def (gimple stmt, int flags)
866 tree def = PHI_RESULT (stmt);
867 if ((flags & SSA_OP_DEF) && is_gimple_reg (def))
868 return def;
869 if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
870 return def;
871 return NULL_TREE;
874 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
875 be either SSA_OP_USES or SSA_OP_VIRTUAL_USES. */
876 static inline use_operand_p
877 op_iter_init_phiuse (ssa_op_iter *ptr, gimple phi, int flags)
879 tree phi_def = gimple_phi_result (phi);
880 int comp;
882 clear_and_done_ssa_iter (ptr);
883 ptr->done = false;
885 gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
887 comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
889 /* If the PHI node doesn't the operand type we care about, we're done. */
890 if ((flags & comp) == 0)
892 ptr->done = true;
893 return NULL_USE_OPERAND_P;
896 ptr->phi_stmt = phi;
897 ptr->num_phi = gimple_phi_num_args (phi);
898 ptr->iter_type = ssa_op_iter_use;
899 return op_iter_next_use (ptr);
903 /* Start an iterator for a PHI definition. */
905 static inline def_operand_p
906 op_iter_init_phidef (ssa_op_iter *ptr, gimple phi, int flags)
908 tree phi_def = PHI_RESULT (phi);
909 int comp;
911 clear_and_done_ssa_iter (ptr);
912 ptr->done = false;
914 gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
916 comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
918 /* If the PHI node doesn't have the operand type we care about,
919 we're done. */
920 if ((flags & comp) == 0)
922 ptr->done = true;
923 return NULL_DEF_OPERAND_P;
926 ptr->iter_type = ssa_op_iter_def;
927 /* The first call to op_iter_next_def will terminate the iterator since
928 all the fields are NULL. Simply return the result here as the first and
929 therefore only result. */
930 return PHI_RESULT_PTR (phi);
933 /* Return true is IMM has reached the end of the immediate use stmt list. */
935 static inline bool
936 end_imm_use_stmt_p (const imm_use_iterator *imm)
938 return (imm->imm_use == imm->end_p);
941 /* Finished the traverse of an immediate use stmt list IMM by removing the
942 placeholder node from the list. */
944 static inline void
945 end_imm_use_stmt_traverse (imm_use_iterator *imm)
947 delink_imm_use (&(imm->iter_node));
950 /* Immediate use traversal of uses within a stmt require that all the
951 uses on a stmt be sequentially listed. This routine is used to build up
952 this sequential list by adding USE_P to the end of the current list
953 currently delimited by HEAD and LAST_P. The new LAST_P value is
954 returned. */
956 static inline use_operand_p
957 move_use_after_head (use_operand_p use_p, use_operand_p head,
958 use_operand_p last_p)
960 gcc_assert (USE_FROM_PTR (use_p) == USE_FROM_PTR (head));
961 /* Skip head when we find it. */
962 if (use_p != head)
964 /* If use_p is already linked in after last_p, continue. */
965 if (last_p->next == use_p)
966 last_p = use_p;
967 else
969 /* Delink from current location, and link in at last_p. */
970 delink_imm_use (use_p);
971 link_imm_use_to_list (use_p, last_p);
972 last_p = use_p;
975 return last_p;
979 /* This routine will relink all uses with the same stmt as HEAD into the list
980 immediately following HEAD for iterator IMM. */
982 static inline void
983 link_use_stmts_after (use_operand_p head, imm_use_iterator *imm)
985 use_operand_p use_p;
986 use_operand_p last_p = head;
987 gimple head_stmt = USE_STMT (head);
988 tree use = USE_FROM_PTR (head);
989 ssa_op_iter op_iter;
990 int flag;
992 /* Only look at virtual or real uses, depending on the type of HEAD. */
993 flag = (is_gimple_reg (use) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
995 if (gimple_code (head_stmt) == GIMPLE_PHI)
997 FOR_EACH_PHI_ARG (use_p, head_stmt, op_iter, flag)
998 if (USE_FROM_PTR (use_p) == use)
999 last_p = move_use_after_head (use_p, head, last_p);
1001 else
1003 if (flag == SSA_OP_USE)
1005 FOR_EACH_SSA_USE_OPERAND (use_p, head_stmt, op_iter, flag)
1006 if (USE_FROM_PTR (use_p) == use)
1007 last_p = move_use_after_head (use_p, head, last_p);
1009 else if ((use_p = gimple_vuse_op (head_stmt)) != NULL_USE_OPERAND_P)
1011 if (USE_FROM_PTR (use_p) == use)
1012 last_p = move_use_after_head (use_p, head, last_p);
1015 /* Link iter node in after last_p. */
1016 if (imm->iter_node.prev != NULL)
1017 delink_imm_use (&imm->iter_node);
1018 link_imm_use_to_list (&(imm->iter_node), last_p);
1021 /* Initialize IMM to traverse over uses of VAR. Return the first statement. */
1022 static inline gimple
1023 first_imm_use_stmt (imm_use_iterator *imm, tree var)
1025 gcc_assert (TREE_CODE (var) == SSA_NAME);
1027 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
1028 imm->imm_use = imm->end_p->next;
1029 imm->next_imm_name = NULL_USE_OPERAND_P;
1031 /* iter_node is used as a marker within the immediate use list to indicate
1032 where the end of the current stmt's uses are. Initialize it to NULL
1033 stmt and use, which indicates a marker node. */
1034 imm->iter_node.prev = NULL_USE_OPERAND_P;
1035 imm->iter_node.next = NULL_USE_OPERAND_P;
1036 imm->iter_node.loc.stmt = NULL;
1037 imm->iter_node.use = NULL;
1039 if (end_imm_use_stmt_p (imm))
1040 return NULL;
1042 link_use_stmts_after (imm->imm_use, imm);
1044 return USE_STMT (imm->imm_use);
1047 /* Bump IMM to the next stmt which has a use of var. */
1049 static inline gimple
1050 next_imm_use_stmt (imm_use_iterator *imm)
1052 imm->imm_use = imm->iter_node.next;
1053 if (end_imm_use_stmt_p (imm))
1055 if (imm->iter_node.prev != NULL)
1056 delink_imm_use (&imm->iter_node);
1057 return NULL;
1060 link_use_stmts_after (imm->imm_use, imm);
1061 return USE_STMT (imm->imm_use);
1064 /* This routine will return the first use on the stmt IMM currently refers
1065 to. */
1067 static inline use_operand_p
1068 first_imm_use_on_stmt (imm_use_iterator *imm)
1070 imm->next_imm_name = imm->imm_use->next;
1071 return imm->imm_use;
1074 /* Return TRUE if the last use on the stmt IMM refers to has been visited. */
1076 static inline bool
1077 end_imm_use_on_stmt_p (const imm_use_iterator *imm)
1079 return (imm->imm_use == &(imm->iter_node));
1082 /* Bump to the next use on the stmt IMM refers to, return NULL if done. */
1084 static inline use_operand_p
1085 next_imm_use_on_stmt (imm_use_iterator *imm)
1087 imm->imm_use = imm->next_imm_name;
1088 if (end_imm_use_on_stmt_p (imm))
1089 return NULL_USE_OPERAND_P;
1090 else
1092 imm->next_imm_name = imm->imm_use->next;
1093 return imm->imm_use;
1097 /* Return true if VAR cannot be modified by the program. */
1099 static inline bool
1100 unmodifiable_var_p (const_tree var)
1102 if (TREE_CODE (var) == SSA_NAME)
1103 var = SSA_NAME_VAR (var);
1105 return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1108 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it. */
1110 static inline bool
1111 array_ref_contains_indirect_ref (const_tree ref)
1113 gcc_assert (TREE_CODE (ref) == ARRAY_REF);
1115 do {
1116 ref = TREE_OPERAND (ref, 0);
1117 } while (handled_component_p (ref));
1119 return TREE_CODE (ref) == INDIRECT_REF;
1122 /* Return true if REF, a handled component reference, has an ARRAY_REF
1123 somewhere in it. */
1125 static inline bool
1126 ref_contains_array_ref (const_tree ref)
1128 gcc_assert (handled_component_p (ref));
1130 do {
1131 if (TREE_CODE (ref) == ARRAY_REF)
1132 return true;
1133 ref = TREE_OPERAND (ref, 0);
1134 } while (handled_component_p (ref));
1136 return false;
1139 /* Return true if REF has an VIEW_CONVERT_EXPR somewhere in it. */
1141 static inline bool
1142 contains_view_convert_expr_p (const_tree ref)
1144 while (handled_component_p (ref))
1146 if (TREE_CODE (ref) == VIEW_CONVERT_EXPR)
1147 return true;
1148 ref = TREE_OPERAND (ref, 0);
1151 return false;
1154 /* Return true, if the two ranges [POS1, SIZE1] and [POS2, SIZE2]
1155 overlap. SIZE1 and/or SIZE2 can be (unsigned)-1 in which case the
1156 range is open-ended. Otherwise return false. */
1158 static inline bool
1159 ranges_overlap_p (unsigned HOST_WIDE_INT pos1,
1160 unsigned HOST_WIDE_INT size1,
1161 unsigned HOST_WIDE_INT pos2,
1162 unsigned HOST_WIDE_INT size2)
1164 if (pos1 >= pos2
1165 && (size2 == (unsigned HOST_WIDE_INT)-1
1166 || pos1 < (pos2 + size2)))
1167 return true;
1168 if (pos2 >= pos1
1169 && (size1 == (unsigned HOST_WIDE_INT)-1
1170 || pos2 < (pos1 + size1)))
1171 return true;
1173 return false;
1176 /* Accessor to tree-ssa-operands.c caches. */
1177 static inline struct ssa_operands *
1178 gimple_ssa_operands (const struct function *fun)
1180 return &fun->gimple_df->ssa_operands;
1183 /* Given an edge_var_map V, return the PHI arg definition. */
1185 static inline tree
1186 redirect_edge_var_map_def (edge_var_map *v)
1188 return v->def;
1191 /* Given an edge_var_map V, return the PHI result. */
1193 static inline tree
1194 redirect_edge_var_map_result (edge_var_map *v)
1196 return v->result;
1200 /* Return an SSA_NAME node for variable VAR defined in statement STMT
1201 in function cfun. */
1203 static inline tree
1204 make_ssa_name (tree var, gimple stmt)
1206 return make_ssa_name_fn (cfun, var, stmt);
1209 #endif /* _TREE_FLOW_INLINE_H */