Fix DealII type problems.
[official-gcc/Ramakrishna.git] / gcc / tree-flow-inline.h
blob3446790fa7a0e715b839af9ee38ed0f37b28a68c
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 const var_ann_t *p = DECL_VAR_ANN_PTR (t);
156 return p ? *p : NULL;
159 /* Return the variable annotation for T, which must be a _DECL node.
160 Create the variable annotation if it doesn't exist. */
161 static inline var_ann_t
162 get_var_ann (tree var)
164 var_ann_t *p = DECL_VAR_ANN_PTR (var);
165 gcc_assert (p);
166 return *p ? *p : create_var_ann (var);
169 /* Get the number of the next statement uid to be allocated. */
170 static inline unsigned int
171 gimple_stmt_max_uid (struct function *fn)
173 return fn->last_stmt_uid;
176 /* Set the number of the next statement uid to be allocated. */
177 static inline void
178 set_gimple_stmt_max_uid (struct function *fn, unsigned int maxid)
180 fn->last_stmt_uid = maxid;
183 /* Set the number of the next statement uid to be allocated. */
184 static inline unsigned int
185 inc_gimple_stmt_max_uid (struct function *fn)
187 return fn->last_stmt_uid++;
190 /* Return the line number for EXPR, or return -1 if we have no line
191 number information for it. */
192 static inline int
193 get_lineno (const_gimple stmt)
195 location_t loc;
197 if (!stmt)
198 return -1;
200 loc = gimple_location (stmt);
201 if (loc == UNKNOWN_LOCATION)
202 return -1;
204 return LOCATION_LINE (loc);
207 /* Delink an immediate_uses node from its chain. */
208 static inline void
209 delink_imm_use (ssa_use_operand_t *linknode)
211 /* Return if this node is not in a list. */
212 if (linknode->prev == NULL)
213 return;
215 linknode->prev->next = linknode->next;
216 linknode->next->prev = linknode->prev;
217 linknode->prev = NULL;
218 linknode->next = NULL;
221 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
222 static inline void
223 link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
225 /* Link the new node at the head of the list. If we are in the process of
226 traversing the list, we won't visit any new nodes added to it. */
227 linknode->prev = list;
228 linknode->next = list->next;
229 list->next->prev = linknode;
230 list->next = linknode;
233 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
234 static inline void
235 link_imm_use (ssa_use_operand_t *linknode, tree def)
237 ssa_use_operand_t *root;
239 if (!def || TREE_CODE (def) != SSA_NAME)
240 linknode->prev = NULL;
241 else
243 root = &(SSA_NAME_IMM_USE_NODE (def));
244 #ifdef ENABLE_CHECKING
245 if (linknode->use)
246 gcc_assert (*(linknode->use) == def);
247 #endif
248 link_imm_use_to_list (linknode, root);
252 /* Set the value of a use pointed to by USE to VAL. */
253 static inline void
254 set_ssa_use_from_ptr (use_operand_p use, tree val)
256 delink_imm_use (use);
257 *(use->use) = val;
258 link_imm_use (use, val);
261 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
262 in STMT. */
263 static inline void
264 link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, gimple stmt)
266 if (stmt)
267 link_imm_use (linknode, def);
268 else
269 link_imm_use (linknode, NULL);
270 linknode->loc.stmt = stmt;
273 /* Relink a new node in place of an old node in the list. */
274 static inline void
275 relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
277 /* The node one had better be in the same list. */
278 gcc_assert (*(old->use) == *(node->use));
279 node->prev = old->prev;
280 node->next = old->next;
281 if (old->prev)
283 old->prev->next = node;
284 old->next->prev = node;
285 /* Remove the old node from the list. */
286 old->prev = NULL;
290 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
291 in STMT. */
292 static inline void
293 relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old,
294 gimple stmt)
296 if (stmt)
297 relink_imm_use (linknode, old);
298 else
299 link_imm_use (linknode, NULL);
300 linknode->loc.stmt = stmt;
304 /* Return true is IMM has reached the end of the immediate use list. */
305 static inline bool
306 end_readonly_imm_use_p (const imm_use_iterator *imm)
308 return (imm->imm_use == imm->end_p);
311 /* Initialize iterator IMM to process the list for VAR. */
312 static inline use_operand_p
313 first_readonly_imm_use (imm_use_iterator *imm, tree var)
315 gcc_assert (TREE_CODE (var) == SSA_NAME);
317 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
318 imm->imm_use = imm->end_p->next;
319 #ifdef ENABLE_CHECKING
320 imm->iter_node.next = imm->imm_use->next;
321 #endif
322 if (end_readonly_imm_use_p (imm))
323 return NULL_USE_OPERAND_P;
324 return imm->imm_use;
327 /* Bump IMM to the next use in the list. */
328 static inline use_operand_p
329 next_readonly_imm_use (imm_use_iterator *imm)
331 use_operand_p old = imm->imm_use;
333 #ifdef ENABLE_CHECKING
334 /* If this assertion fails, it indicates the 'next' pointer has changed
335 since the last bump. This indicates that the list is being modified
336 via stmt changes, or SET_USE, or somesuch thing, and you need to be
337 using the SAFE version of the iterator. */
338 gcc_assert (imm->iter_node.next == old->next);
339 imm->iter_node.next = old->next->next;
340 #endif
342 imm->imm_use = old->next;
343 if (end_readonly_imm_use_p (imm))
344 return NULL_USE_OPERAND_P;
345 return imm->imm_use;
348 /* tree-cfg.c */
349 extern bool has_zero_uses_1 (const ssa_use_operand_t *head);
350 extern bool single_imm_use_1 (const ssa_use_operand_t *head,
351 use_operand_p *use_p, gimple *stmt);
353 /* Return true if VAR has no nondebug uses. */
354 static inline bool
355 has_zero_uses (const_tree var)
357 const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
359 /* A single use_operand means there is no items in the list. */
360 if (ptr == ptr->next)
361 return true;
363 /* If there are debug stmts, we have to look at each use and see
364 whether there are any nondebug uses. */
365 if (!MAY_HAVE_DEBUG_STMTS)
366 return false;
368 return has_zero_uses_1 (ptr);
371 /* Return true if VAR has a single nondebug use. */
372 static inline bool
373 has_single_use (const_tree var)
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)
379 return false;
381 /* If there's a single use, check that it's not a debug stmt. */
382 if (ptr == ptr->next->next)
383 return !is_gimple_debug (USE_STMT (ptr->next));
385 /* If there are debug stmts, we have to look at each of them. */
386 if (!MAY_HAVE_DEBUG_STMTS)
387 return false;
389 return single_imm_use_1 (ptr, NULL, NULL);
393 /* If VAR has only a single immediate nondebug use, return true, and
394 set USE_P and STMT to the use pointer and stmt of occurrence. */
395 static inline bool
396 single_imm_use (const_tree var, use_operand_p *use_p, gimple *stmt)
398 const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
400 /* If there aren't any uses whatsoever, we're done. */
401 if (ptr == ptr->next)
403 return_false:
404 *use_p = NULL_USE_OPERAND_P;
405 *stmt = NULL;
406 return false;
409 /* If there's a single use, check that it's not a debug stmt. */
410 if (ptr == ptr->next->next)
412 if (!is_gimple_debug (USE_STMT (ptr->next)))
414 *use_p = ptr->next;
415 *stmt = ptr->next->loc.stmt;
416 return true;
418 else
419 goto return_false;
422 /* If there are debug stmts, we have to look at each of them. */
423 if (!MAY_HAVE_DEBUG_STMTS)
424 goto return_false;
426 return single_imm_use_1 (ptr, use_p, stmt);
429 /* Return the number of nondebug immediate uses of VAR. */
430 static inline unsigned int
431 num_imm_uses (const_tree var)
433 const ssa_use_operand_t *const start = &(SSA_NAME_IMM_USE_NODE (var));
434 const ssa_use_operand_t *ptr;
435 unsigned int num = 0;
437 if (!MAY_HAVE_DEBUG_STMTS)
438 for (ptr = start->next; ptr != start; ptr = ptr->next)
439 num++;
440 else
441 for (ptr = start->next; ptr != start; ptr = ptr->next)
442 if (!is_gimple_debug (USE_STMT (ptr)))
443 num++;
445 return num;
448 /* Return the tree pointed-to by USE. */
449 static inline tree
450 get_use_from_ptr (use_operand_p use)
452 return *(use->use);
455 /* Return the tree pointed-to by DEF. */
456 static inline tree
457 get_def_from_ptr (def_operand_p def)
459 return *def;
462 /* Return a use_operand_p pointer for argument I of PHI node GS. */
464 static inline use_operand_p
465 gimple_phi_arg_imm_use_ptr (gimple gs, int i)
467 return &gimple_phi_arg (gs, i)->imm_use;
470 /* Return the tree operand for argument I of PHI node GS. */
472 static inline tree
473 gimple_phi_arg_def (gimple gs, size_t index)
475 struct phi_arg_d *pd = gimple_phi_arg (gs, index);
476 return get_use_from_ptr (&pd->imm_use);
479 /* Return a pointer to the tree operand for argument I of PHI node GS. */
481 static inline tree *
482 gimple_phi_arg_def_ptr (gimple gs, size_t index)
484 return &gimple_phi_arg (gs, index)->def;
487 /* Return the edge associated with argument I of phi node GS. */
489 static inline edge
490 gimple_phi_arg_edge (gimple gs, size_t i)
492 return EDGE_PRED (gimple_bb (gs), i);
495 /* Return the source location of gimple argument I of phi node GS. */
497 static inline source_location
498 gimple_phi_arg_location (gimple gs, size_t i)
500 return gimple_phi_arg (gs, i)->locus;
503 /* Return the source location of the argument on edge E of phi node GS. */
505 static inline source_location
506 gimple_phi_arg_location_from_edge (gimple gs, edge e)
508 return gimple_phi_arg (gs, e->dest_idx)->locus;
511 /* Set the source location of gimple argument I of phi node GS to LOC. */
513 static inline void
514 gimple_phi_arg_set_location (gimple gs, size_t i, source_location loc)
516 gimple_phi_arg (gs, i)->locus = loc;
519 /* Return TRUE if argument I of phi node GS has a location record. */
521 static inline bool
522 gimple_phi_arg_has_location (gimple gs, size_t i)
524 return gimple_phi_arg_location (gs, i) != UNKNOWN_LOCATION;
528 /* Return the PHI nodes for basic block BB, or NULL if there are no
529 PHI nodes. */
530 static inline gimple_seq
531 phi_nodes (const_basic_block bb)
533 gcc_assert (!(bb->flags & BB_RTL));
534 if (!bb->il.gimple)
535 return NULL;
536 return bb->il.gimple->phi_nodes;
539 /* Set PHI nodes of a basic block BB to SEQ. */
541 static inline void
542 set_phi_nodes (basic_block bb, gimple_seq seq)
544 gimple_stmt_iterator i;
546 gcc_assert (!(bb->flags & BB_RTL));
547 bb->il.gimple->phi_nodes = seq;
548 if (seq)
549 for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
550 gimple_set_bb (gsi_stmt (i), bb);
553 /* Return the phi argument which contains the specified use. */
555 static inline int
556 phi_arg_index_from_use (use_operand_p use)
558 struct phi_arg_d *element, *root;
559 size_t index;
560 gimple phi;
562 /* Since the use is the first thing in a PHI argument element, we can
563 calculate its index based on casting it to an argument, and performing
564 pointer arithmetic. */
566 phi = USE_STMT (use);
567 gcc_assert (gimple_code (phi) == GIMPLE_PHI);
569 element = (struct phi_arg_d *)use;
570 root = gimple_phi_arg (phi, 0);
571 index = element - root;
573 #ifdef ENABLE_CHECKING
574 /* Make sure the calculation doesn't have any leftover bytes. If it does,
575 then imm_use is likely not the first element in phi_arg_d. */
576 gcc_assert (
577 (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
578 gcc_assert (index < gimple_phi_capacity (phi));
579 #endif
581 return index;
584 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
586 static inline void
587 set_is_used (tree var)
589 var_ann_t ann = get_var_ann (var);
590 ann->used = 1;
594 /* Return true if T (assumed to be a DECL) is a global variable.
595 A variable is considered global if its storage is not automatic. */
597 static inline bool
598 is_global_var (const_tree t)
600 return (TREE_STATIC (t) || DECL_EXTERNAL (t));
604 /* Return true if VAR may be aliased. A variable is considered as
605 maybe aliased if it has its address taken by the local TU
606 or possibly by another TU and might be modified through a pointer. */
608 static inline bool
609 may_be_aliased (const_tree var)
611 return (TREE_CODE (var) != CONST_DECL
612 && !((TREE_STATIC (var) || TREE_PUBLIC (var) || DECL_EXTERNAL (var))
613 && TREE_READONLY (var)
614 && !TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (var)))
615 && (TREE_PUBLIC (var)
616 || DECL_EXTERNAL (var)
617 || TREE_ADDRESSABLE (var)));
621 /* PHI nodes should contain only ssa_names and invariants. A test
622 for ssa_name is definitely simpler; don't let invalid contents
623 slip in in the meantime. */
625 static inline bool
626 phi_ssa_name_p (const_tree t)
628 if (TREE_CODE (t) == SSA_NAME)
629 return true;
630 #ifdef ENABLE_CHECKING
631 gcc_assert (is_gimple_min_invariant (t));
632 #endif
633 return false;
637 /* Returns the loop of the statement STMT. */
639 static inline struct loop *
640 loop_containing_stmt (gimple stmt)
642 basic_block bb = gimple_bb (stmt);
643 if (!bb)
644 return NULL;
646 return bb->loop_father;
650 /* Return true if VAR is clobbered by function calls. */
651 static inline bool
652 is_call_clobbered (const_tree var)
654 return (is_global_var (var)
655 || (may_be_aliased (var)
656 && pt_solution_includes (&cfun->gimple_df->escaped, var)));
659 /* Return true if VAR is used by function calls. */
660 static inline bool
661 is_call_used (const_tree var)
663 return (is_call_clobbered (var)
664 || (may_be_aliased (var)
665 && pt_solution_includes (&cfun->gimple_df->callused, var)));
668 /* ----------------------------------------------------------------------- */
670 /* The following set of routines are used to iterator over various type of
671 SSA operands. */
673 /* Return true if PTR is finished iterating. */
674 static inline bool
675 op_iter_done (const ssa_op_iter *ptr)
677 return ptr->done;
680 /* Get the next iterator use value for PTR. */
681 static inline use_operand_p
682 op_iter_next_use (ssa_op_iter *ptr)
684 use_operand_p use_p;
685 #ifdef ENABLE_CHECKING
686 gcc_assert (ptr->iter_type == ssa_op_iter_use);
687 #endif
688 if (ptr->uses)
690 use_p = USE_OP_PTR (ptr->uses);
691 ptr->uses = ptr->uses->next;
692 return use_p;
694 if (ptr->phi_i < ptr->num_phi)
696 return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
698 ptr->done = true;
699 return NULL_USE_OPERAND_P;
702 /* Get the next iterator def value for PTR. */
703 static inline def_operand_p
704 op_iter_next_def (ssa_op_iter *ptr)
706 def_operand_p def_p;
707 #ifdef ENABLE_CHECKING
708 gcc_assert (ptr->iter_type == ssa_op_iter_def);
709 #endif
710 if (ptr->defs)
712 def_p = DEF_OP_PTR (ptr->defs);
713 ptr->defs = ptr->defs->next;
714 return def_p;
716 ptr->done = true;
717 return NULL_DEF_OPERAND_P;
720 /* Get the next iterator tree value for PTR. */
721 static inline tree
722 op_iter_next_tree (ssa_op_iter *ptr)
724 tree val;
725 #ifdef ENABLE_CHECKING
726 gcc_assert (ptr->iter_type == ssa_op_iter_tree);
727 #endif
728 if (ptr->uses)
730 val = USE_OP (ptr->uses);
731 ptr->uses = ptr->uses->next;
732 return val;
734 if (ptr->defs)
736 val = DEF_OP (ptr->defs);
737 ptr->defs = ptr->defs->next;
738 return val;
741 ptr->done = true;
742 return NULL_TREE;
747 /* This functions clears the iterator PTR, and marks it done. This is normally
748 used to prevent warnings in the compile about might be uninitialized
749 components. */
751 static inline void
752 clear_and_done_ssa_iter (ssa_op_iter *ptr)
754 ptr->defs = NULL;
755 ptr->uses = NULL;
756 ptr->iter_type = ssa_op_iter_none;
757 ptr->phi_i = 0;
758 ptr->num_phi = 0;
759 ptr->phi_stmt = NULL;
760 ptr->done = true;
763 /* Initialize the iterator PTR to the virtual defs in STMT. */
764 static inline void
765 op_iter_init (ssa_op_iter *ptr, gimple stmt, int flags)
767 /* We do not support iterating over virtual defs or uses without
768 iterating over defs or uses at the same time. */
769 gcc_assert ((!(flags & SSA_OP_VDEF) || (flags & SSA_OP_DEF))
770 && (!(flags & SSA_OP_VUSE) || (flags & SSA_OP_USE)));
771 ptr->defs = (flags & (SSA_OP_DEF|SSA_OP_VDEF)) ? gimple_def_ops (stmt) : NULL;
772 if (!(flags & SSA_OP_VDEF)
773 && ptr->defs
774 && gimple_vdef (stmt) != NULL_TREE)
775 ptr->defs = ptr->defs->next;
776 ptr->uses = (flags & (SSA_OP_USE|SSA_OP_VUSE)) ? gimple_use_ops (stmt) : NULL;
777 if (!(flags & SSA_OP_VUSE)
778 && ptr->uses
779 && gimple_vuse (stmt) != NULL_TREE)
780 ptr->uses = ptr->uses->next;
781 ptr->done = false;
783 ptr->phi_i = 0;
784 ptr->num_phi = 0;
785 ptr->phi_stmt = NULL;
788 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
789 the first use. */
790 static inline use_operand_p
791 op_iter_init_use (ssa_op_iter *ptr, gimple stmt, int flags)
793 gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0
794 && (flags & SSA_OP_USE));
795 op_iter_init (ptr, stmt, flags);
796 ptr->iter_type = ssa_op_iter_use;
797 return op_iter_next_use (ptr);
800 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
801 the first def. */
802 static inline def_operand_p
803 op_iter_init_def (ssa_op_iter *ptr, gimple stmt, int flags)
805 gcc_assert ((flags & SSA_OP_ALL_USES) == 0
806 && (flags & SSA_OP_DEF));
807 op_iter_init (ptr, stmt, flags);
808 ptr->iter_type = ssa_op_iter_def;
809 return op_iter_next_def (ptr);
812 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
813 the first operand as a tree. */
814 static inline tree
815 op_iter_init_tree (ssa_op_iter *ptr, gimple stmt, int flags)
817 op_iter_init (ptr, stmt, flags);
818 ptr->iter_type = ssa_op_iter_tree;
819 return op_iter_next_tree (ptr);
823 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
824 return NULL. */
825 static inline tree
826 single_ssa_tree_operand (gimple stmt, int flags)
828 tree var;
829 ssa_op_iter iter;
831 var = op_iter_init_tree (&iter, stmt, flags);
832 if (op_iter_done (&iter))
833 return NULL_TREE;
834 op_iter_next_tree (&iter);
835 if (op_iter_done (&iter))
836 return var;
837 return NULL_TREE;
841 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
842 return NULL. */
843 static inline use_operand_p
844 single_ssa_use_operand (gimple stmt, int flags)
846 use_operand_p var;
847 ssa_op_iter iter;
849 var = op_iter_init_use (&iter, stmt, flags);
850 if (op_iter_done (&iter))
851 return NULL_USE_OPERAND_P;
852 op_iter_next_use (&iter);
853 if (op_iter_done (&iter))
854 return var;
855 return NULL_USE_OPERAND_P;
860 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
861 return NULL. */
862 static inline def_operand_p
863 single_ssa_def_operand (gimple stmt, int flags)
865 def_operand_p var;
866 ssa_op_iter iter;
868 var = op_iter_init_def (&iter, stmt, flags);
869 if (op_iter_done (&iter))
870 return NULL_DEF_OPERAND_P;
871 op_iter_next_def (&iter);
872 if (op_iter_done (&iter))
873 return var;
874 return NULL_DEF_OPERAND_P;
878 /* Return true if there are zero operands in STMT matching the type
879 given in FLAGS. */
880 static inline bool
881 zero_ssa_operands (gimple stmt, int flags)
883 ssa_op_iter iter;
885 op_iter_init_tree (&iter, stmt, flags);
886 return op_iter_done (&iter);
890 /* Return the number of operands matching FLAGS in STMT. */
891 static inline int
892 num_ssa_operands (gimple stmt, int flags)
894 ssa_op_iter iter;
895 tree t;
896 int num = 0;
898 FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
899 num++;
900 return num;
904 /* Delink all immediate_use information for STMT. */
905 static inline void
906 delink_stmt_imm_use (gimple stmt)
908 ssa_op_iter iter;
909 use_operand_p use_p;
911 if (ssa_operands_active ())
912 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_ALL_USES)
913 delink_imm_use (use_p);
917 /* If there is a single DEF in the PHI node which matches FLAG, return it.
918 Otherwise return NULL_DEF_OPERAND_P. */
919 static inline tree
920 single_phi_def (gimple stmt, int flags)
922 tree def = PHI_RESULT (stmt);
923 if ((flags & SSA_OP_DEF) && is_gimple_reg (def))
924 return def;
925 if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
926 return def;
927 return NULL_TREE;
930 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
931 be either SSA_OP_USES or SSA_OP_VIRTUAL_USES. */
932 static inline use_operand_p
933 op_iter_init_phiuse (ssa_op_iter *ptr, gimple phi, int flags)
935 tree phi_def = gimple_phi_result (phi);
936 int comp;
938 clear_and_done_ssa_iter (ptr);
939 ptr->done = false;
941 gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
943 comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
945 /* If the PHI node doesn't the operand type we care about, we're done. */
946 if ((flags & comp) == 0)
948 ptr->done = true;
949 return NULL_USE_OPERAND_P;
952 ptr->phi_stmt = phi;
953 ptr->num_phi = gimple_phi_num_args (phi);
954 ptr->iter_type = ssa_op_iter_use;
955 return op_iter_next_use (ptr);
959 /* Start an iterator for a PHI definition. */
961 static inline def_operand_p
962 op_iter_init_phidef (ssa_op_iter *ptr, gimple phi, int flags)
964 tree phi_def = PHI_RESULT (phi);
965 int comp;
967 clear_and_done_ssa_iter (ptr);
968 ptr->done = false;
970 gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
972 comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
974 /* If the PHI node doesn't have the operand type we care about,
975 we're done. */
976 if ((flags & comp) == 0)
978 ptr->done = true;
979 return NULL_DEF_OPERAND_P;
982 ptr->iter_type = ssa_op_iter_def;
983 /* The first call to op_iter_next_def will terminate the iterator since
984 all the fields are NULL. Simply return the result here as the first and
985 therefore only result. */
986 return PHI_RESULT_PTR (phi);
989 /* Return true is IMM has reached the end of the immediate use stmt list. */
991 static inline bool
992 end_imm_use_stmt_p (const imm_use_iterator *imm)
994 return (imm->imm_use == imm->end_p);
997 /* Finished the traverse of an immediate use stmt list IMM by removing the
998 placeholder node from the list. */
1000 static inline void
1001 end_imm_use_stmt_traverse (imm_use_iterator *imm)
1003 delink_imm_use (&(imm->iter_node));
1006 /* Immediate use traversal of uses within a stmt require that all the
1007 uses on a stmt be sequentially listed. This routine is used to build up
1008 this sequential list by adding USE_P to the end of the current list
1009 currently delimited by HEAD and LAST_P. The new LAST_P value is
1010 returned. */
1012 static inline use_operand_p
1013 move_use_after_head (use_operand_p use_p, use_operand_p head,
1014 use_operand_p last_p)
1016 gcc_assert (USE_FROM_PTR (use_p) == USE_FROM_PTR (head));
1017 /* Skip head when we find it. */
1018 if (use_p != head)
1020 /* If use_p is already linked in after last_p, continue. */
1021 if (last_p->next == use_p)
1022 last_p = use_p;
1023 else
1025 /* Delink from current location, and link in at last_p. */
1026 delink_imm_use (use_p);
1027 link_imm_use_to_list (use_p, last_p);
1028 last_p = use_p;
1031 return last_p;
1035 /* This routine will relink all uses with the same stmt as HEAD into the list
1036 immediately following HEAD for iterator IMM. */
1038 static inline void
1039 link_use_stmts_after (use_operand_p head, imm_use_iterator *imm)
1041 use_operand_p use_p;
1042 use_operand_p last_p = head;
1043 gimple head_stmt = USE_STMT (head);
1044 tree use = USE_FROM_PTR (head);
1045 ssa_op_iter op_iter;
1046 int flag;
1048 /* Only look at virtual or real uses, depending on the type of HEAD. */
1049 flag = (is_gimple_reg (use) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1051 if (gimple_code (head_stmt) == GIMPLE_PHI)
1053 FOR_EACH_PHI_ARG (use_p, head_stmt, op_iter, flag)
1054 if (USE_FROM_PTR (use_p) == use)
1055 last_p = move_use_after_head (use_p, head, last_p);
1057 else
1059 if (flag == SSA_OP_USE)
1061 FOR_EACH_SSA_USE_OPERAND (use_p, head_stmt, op_iter, flag)
1062 if (USE_FROM_PTR (use_p) == use)
1063 last_p = move_use_after_head (use_p, head, last_p);
1065 else if ((use_p = gimple_vuse_op (head_stmt)) != NULL_USE_OPERAND_P)
1067 if (USE_FROM_PTR (use_p) == use)
1068 last_p = move_use_after_head (use_p, head, last_p);
1071 /* Link iter node in after last_p. */
1072 if (imm->iter_node.prev != NULL)
1073 delink_imm_use (&imm->iter_node);
1074 link_imm_use_to_list (&(imm->iter_node), last_p);
1077 /* Initialize IMM to traverse over uses of VAR. Return the first statement. */
1078 static inline gimple
1079 first_imm_use_stmt (imm_use_iterator *imm, tree var)
1081 gcc_assert (TREE_CODE (var) == SSA_NAME);
1083 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
1084 imm->imm_use = imm->end_p->next;
1085 imm->next_imm_name = NULL_USE_OPERAND_P;
1087 /* iter_node is used as a marker within the immediate use list to indicate
1088 where the end of the current stmt's uses are. Initialize it to NULL
1089 stmt and use, which indicates a marker node. */
1090 imm->iter_node.prev = NULL_USE_OPERAND_P;
1091 imm->iter_node.next = NULL_USE_OPERAND_P;
1092 imm->iter_node.loc.stmt = NULL;
1093 imm->iter_node.use = NULL;
1095 if (end_imm_use_stmt_p (imm))
1096 return NULL;
1098 link_use_stmts_after (imm->imm_use, imm);
1100 return USE_STMT (imm->imm_use);
1103 /* Bump IMM to the next stmt which has a use of var. */
1105 static inline gimple
1106 next_imm_use_stmt (imm_use_iterator *imm)
1108 imm->imm_use = imm->iter_node.next;
1109 if (end_imm_use_stmt_p (imm))
1111 if (imm->iter_node.prev != NULL)
1112 delink_imm_use (&imm->iter_node);
1113 return NULL;
1116 link_use_stmts_after (imm->imm_use, imm);
1117 return USE_STMT (imm->imm_use);
1120 /* This routine will return the first use on the stmt IMM currently refers
1121 to. */
1123 static inline use_operand_p
1124 first_imm_use_on_stmt (imm_use_iterator *imm)
1126 imm->next_imm_name = imm->imm_use->next;
1127 return imm->imm_use;
1130 /* Return TRUE if the last use on the stmt IMM refers to has been visited. */
1132 static inline bool
1133 end_imm_use_on_stmt_p (const imm_use_iterator *imm)
1135 return (imm->imm_use == &(imm->iter_node));
1138 /* Bump to the next use on the stmt IMM refers to, return NULL if done. */
1140 static inline use_operand_p
1141 next_imm_use_on_stmt (imm_use_iterator *imm)
1143 imm->imm_use = imm->next_imm_name;
1144 if (end_imm_use_on_stmt_p (imm))
1145 return NULL_USE_OPERAND_P;
1146 else
1148 imm->next_imm_name = imm->imm_use->next;
1149 return imm->imm_use;
1153 /* Return true if VAR cannot be modified by the program. */
1155 static inline bool
1156 unmodifiable_var_p (const_tree var)
1158 if (TREE_CODE (var) == SSA_NAME)
1159 var = SSA_NAME_VAR (var);
1161 return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1164 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it. */
1166 static inline bool
1167 array_ref_contains_indirect_ref (const_tree ref)
1169 gcc_assert (TREE_CODE (ref) == ARRAY_REF);
1171 do {
1172 ref = TREE_OPERAND (ref, 0);
1173 } while (handled_component_p (ref));
1175 return TREE_CODE (ref) == INDIRECT_REF;
1178 /* Return true if REF, a handled component reference, has an ARRAY_REF
1179 somewhere in it. */
1181 static inline bool
1182 ref_contains_array_ref (const_tree ref)
1184 gcc_assert (handled_component_p (ref));
1186 do {
1187 if (TREE_CODE (ref) == ARRAY_REF)
1188 return true;
1189 ref = TREE_OPERAND (ref, 0);
1190 } while (handled_component_p (ref));
1192 return false;
1195 /* Return true if REF has an VIEW_CONVERT_EXPR somewhere in it. */
1197 static inline bool
1198 contains_view_convert_expr_p (const_tree ref)
1200 while (handled_component_p (ref))
1202 if (TREE_CODE (ref) == VIEW_CONVERT_EXPR)
1203 return true;
1204 ref = TREE_OPERAND (ref, 0);
1207 return false;
1210 /* Return true, if the two ranges [POS1, SIZE1] and [POS2, SIZE2]
1211 overlap. SIZE1 and/or SIZE2 can be (unsigned)-1 in which case the
1212 range is open-ended. Otherwise return false. */
1214 static inline bool
1215 ranges_overlap_p (unsigned HOST_WIDE_INT pos1,
1216 unsigned HOST_WIDE_INT size1,
1217 unsigned HOST_WIDE_INT pos2,
1218 unsigned HOST_WIDE_INT size2)
1220 if (pos1 >= pos2
1221 && (size2 == (unsigned HOST_WIDE_INT)-1
1222 || pos1 < (pos2 + size2)))
1223 return true;
1224 if (pos2 >= pos1
1225 && (size1 == (unsigned HOST_WIDE_INT)-1
1226 || pos2 < (pos1 + size1)))
1227 return true;
1229 return false;
1232 /* Accessor to tree-ssa-operands.c caches. */
1233 static inline struct ssa_operands *
1234 gimple_ssa_operands (const struct function *fun)
1236 return &fun->gimple_df->ssa_operands;
1239 /* Given an edge_var_map V, return the PHI arg definition. */
1241 static inline tree
1242 redirect_edge_var_map_def (edge_var_map *v)
1244 return v->def;
1247 /* Given an edge_var_map V, return the PHI result. */
1249 static inline tree
1250 redirect_edge_var_map_result (edge_var_map *v)
1252 return v->result;
1255 /* Given an edge_var_map V, return the PHI arg location. */
1257 static inline source_location
1258 redirect_edge_var_map_location (edge_var_map *v)
1260 return v->locus;
1264 /* Return an SSA_NAME node for variable VAR defined in statement STMT
1265 in function cfun. */
1267 static inline tree
1268 make_ssa_name (tree var, gimple stmt)
1270 return make_ssa_name_fn (cfun, var, stmt);
1273 #endif /* _TREE_FLOW_INLINE_H */