OSDN Git Service

Remove trailing white spaces.
[pf3gnuchains/gcc-fork.git] / gcc / tree-flow-inline.h
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>
5
6 This file is part of GCC.
7
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.
12
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.
17
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/>.  */
21
22 #ifndef _TREE_FLOW_INLINE_H
23 #define _TREE_FLOW_INLINE_H 1
24
25 /* Inline functions for manipulating various data structures defined in
26    tree-flow.h.  See tree-flow.h for documentation.  */
27
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)
34 {
35   return fun && fun->gimple_df && fun->gimple_df->in_ssa_p;
36 }
37
38 /* Array of all variables referenced in the function.  */
39 static inline htab_t
40 gimple_referenced_vars (const struct function *fun)
41 {
42   if (!fun->gimple_df)
43     return NULL;
44   return fun->gimple_df->referenced_vars;
45 }
46
47 /* Artificial variable used to model the effects of nonlocal
48    variables.  */
49 static inline tree
50 gimple_nonlocal_all (const struct function *fun)
51 {
52   gcc_assert (fun && fun->gimple_df);
53   return fun->gimple_df->nonlocal_all;
54 }
55
56 /* Artificial variable used for the virtual operand FUD chain.  */
57 static inline tree
58 gimple_vop (const struct function *fun)
59 {
60   gcc_assert (fun && fun->gimple_df);
61   return fun->gimple_df->vop;
62 }
63
64 /* Initialize the hashtable iterator HTI to point to hashtable TABLE */
65
66 static inline void *
67 first_htab_element (htab_iterator *hti, htab_t table)
68 {
69   hti->htab = table;
70   hti->slot = table->entries;
71   hti->limit = hti->slot + htab_size (table);
72   do
73     {
74       PTR x = *(hti->slot);
75       if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
76         break;
77     } while (++(hti->slot) < hti->limit);
78
79   if (hti->slot < hti->limit)
80     return *(hti->slot);
81   return NULL;
82 }
83
84 /* Return current non-empty/deleted slot of the hashtable pointed to by HTI,
85    or NULL if we have  reached the end.  */
86
87 static inline bool
88 end_htab_p (const htab_iterator *hti)
89 {
90   if (hti->slot >= hti->limit)
91     return true;
92   return false;
93 }
94
95 /* Advance the hashtable iterator pointed to by HTI to the next element of the
96    hashtable.  */
97
98 static inline void *
99 next_htab_element (htab_iterator *hti)
100 {
101   while (++(hti->slot) < hti->limit)
102     {
103       PTR x = *(hti->slot);
104       if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
105         return x;
106     };
107   return NULL;
108 }
109
110 /* Initialize ITER to point to the first referenced variable in the
111    referenced_vars hashtable, and return that variable.  */
112
113 static inline tree
114 first_referenced_var (referenced_var_iterator *iter)
115 {
116   return (tree) first_htab_element (&iter->hti,
117                                     gimple_referenced_vars (cfun));
118 }
119
120 /* Return true if we have hit the end of the referenced variables ITER is
121    iterating through.  */
122
123 static inline bool
124 end_referenced_vars_p (const referenced_var_iterator *iter)
125 {
126   return end_htab_p (&iter->hti);
127 }
128
129 /* Make ITER point to the next referenced_var in the referenced_var hashtable,
130    and return that variable.  */
131
132 static inline tree
133 next_referenced_var (referenced_var_iterator *iter)
134 {
135   return (tree) next_htab_element (&iter->hti);
136 }
137
138 /* Fill up VEC with the variables in the referenced vars hashtable.  */
139
140 static inline void
141 fill_referenced_var_vec (VEC (tree, heap) **vec)
142 {
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);
148 }
149
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)
154 {
155   const var_ann_t *p = DECL_VAR_ANN_PTR (t);
156   return p ? *p : NULL;
157 }
158
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)
163 {
164   var_ann_t *p = DECL_VAR_ANN_PTR (var);
165   gcc_assert (p);
166   return *p ? *p : create_var_ann (var);
167 }
168
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)
172 {
173   return fn->last_stmt_uid;
174 }
175
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)
179 {
180   fn->last_stmt_uid = maxid;
181 }
182
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)
186 {
187   return fn->last_stmt_uid++;
188 }
189
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)
194 {
195   location_t loc;
196
197   if (!stmt)
198     return -1;
199
200   loc = gimple_location (stmt);
201   if (loc == UNKNOWN_LOCATION)
202     return -1;
203
204   return LOCATION_LINE (loc);
205 }
206
207 /* Delink an immediate_uses node from its chain.  */
208 static inline void
209 delink_imm_use (ssa_use_operand_t *linknode)
210 {
211   /* Return if this node is not in a list.  */
212   if (linknode->prev == NULL)
213     return;
214
215   linknode->prev->next = linknode->next;
216   linknode->next->prev = linknode->prev;
217   linknode->prev = NULL;
218   linknode->next = NULL;
219 }
220
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)
224 {
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;
231 }
232
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)
236 {
237   ssa_use_operand_t *root;
238
239   if (!def || TREE_CODE (def) != SSA_NAME)
240     linknode->prev = NULL;
241   else
242     {
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);
249     }
250 }
251
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)
255 {
256   delink_imm_use (use);
257   *(use->use) = val;
258   link_imm_use (use, val);
259 }
260
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)
265 {
266   if (stmt)
267     link_imm_use (linknode, def);
268   else
269     link_imm_use (linknode, NULL);
270   linknode->loc.stmt = stmt;
271 }
272
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)
276 {
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)
282     {
283       old->prev->next = node;
284       old->next->prev = node;
285       /* Remove the old node from the list.  */
286       old->prev = NULL;
287     }
288 }
289
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)
295 {
296   if (stmt)
297     relink_imm_use (linknode, old);
298   else
299     link_imm_use (linknode, NULL);
300   linknode->loc.stmt = stmt;
301 }
302
303
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)
307 {
308   return (imm->imm_use == imm->end_p);
309 }
310
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)
314 {
315   gcc_assert (TREE_CODE (var) == SSA_NAME);
316
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;
325 }
326
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)
330 {
331   use_operand_p old = imm->imm_use;
332
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
341
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;
346 }
347
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);
352
353 /* Return true if VAR has no nondebug uses.  */
354 static inline bool
355 has_zero_uses (const_tree var)
356 {
357   const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
358
359   /* A single use_operand means there is no items in the list.  */
360   if (ptr == ptr->next)
361     return true;
362
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;
367
368   return has_zero_uses_1 (ptr);
369 }
370
371 /* Return true if VAR has a single nondebug use.  */
372 static inline bool
373 has_single_use (const_tree var)
374 {
375   const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
376
377   /* If there aren't any uses whatsoever, we're done.  */
378   if (ptr == ptr->next)
379     return false;
380
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));
384
385   /* If there are debug stmts, we have to look at each of them.  */
386   if (!MAY_HAVE_DEBUG_STMTS)
387     return false;
388
389   return single_imm_use_1 (ptr, NULL, NULL);
390 }
391
392
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)
397 {
398   const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
399
400   /* If there aren't any uses whatsoever, we're done.  */
401   if (ptr == ptr->next)
402     {
403     return_false:
404       *use_p = NULL_USE_OPERAND_P;
405       *stmt = NULL;
406       return false;
407     }
408
409   /* If there's a single use, check that it's not a debug stmt.  */
410   if (ptr == ptr->next->next)
411     {
412       if (!is_gimple_debug (USE_STMT (ptr->next)))
413         {
414           *use_p = ptr->next;
415           *stmt = ptr->next->loc.stmt;
416           return true;
417         }
418       else
419         goto return_false;
420     }
421
422   /* If there are debug stmts, we have to look at each of them.  */
423   if (!MAY_HAVE_DEBUG_STMTS)
424     goto return_false;
425
426   return single_imm_use_1 (ptr, use_p, stmt);
427 }
428
429 /* Return the number of nondebug immediate uses of VAR.  */
430 static inline unsigned int
431 num_imm_uses (const_tree var)
432 {
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;
436
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++;
444
445   return num;
446 }
447
448 /* Return the tree pointed-to by USE.  */
449 static inline tree
450 get_use_from_ptr (use_operand_p use)
451 {
452   return *(use->use);
453 }
454
455 /* Return the tree pointed-to by DEF.  */
456 static inline tree
457 get_def_from_ptr (def_operand_p def)
458 {
459   return *def;
460 }
461
462 /* Return a use_operand_p pointer for argument I of PHI node GS.  */
463
464 static inline use_operand_p
465 gimple_phi_arg_imm_use_ptr (gimple gs, int i)
466 {
467   return &gimple_phi_arg (gs, i)->imm_use;
468 }
469
470 /* Return the tree operand for argument I of PHI node GS.  */
471
472 static inline tree
473 gimple_phi_arg_def (gimple gs, size_t index)
474 {
475   struct phi_arg_d *pd = gimple_phi_arg (gs, index);
476   return get_use_from_ptr (&pd->imm_use);
477 }
478
479 /* Return a pointer to the tree operand for argument I of PHI node GS.  */
480
481 static inline tree *
482 gimple_phi_arg_def_ptr (gimple gs, size_t index)
483 {
484   return &gimple_phi_arg (gs, index)->def;
485 }
486
487 /* Return the edge associated with argument I of phi node GS.  */
488
489 static inline edge
490 gimple_phi_arg_edge (gimple gs, size_t i)
491 {
492   return EDGE_PRED (gimple_bb (gs), i);
493 }
494
495 /* Return the source location of gimple argument I of phi node GS.  */
496
497 static inline source_location
498 gimple_phi_arg_location (gimple gs, size_t i)
499 {
500   return gimple_phi_arg (gs, i)->locus;
501 }
502
503 /* Return the source location of the argument on edge E of phi node GS.  */
504
505 static inline source_location
506 gimple_phi_arg_location_from_edge (gimple gs, edge e)
507 {
508   return gimple_phi_arg (gs, e->dest_idx)->locus;
509 }
510
511 /* Set the source location of gimple argument I of phi node GS to LOC.  */
512
513 static inline void
514 gimple_phi_arg_set_location (gimple gs, size_t i, source_location loc)
515 {
516   gimple_phi_arg (gs, i)->locus = loc;
517 }
518
519 /* Return TRUE if argument I of phi node GS has a location record.  */
520
521 static inline bool
522 gimple_phi_arg_has_location (gimple gs, size_t i)
523 {
524   return gimple_phi_arg_location (gs, i) != UNKNOWN_LOCATION;
525 }
526
527
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)
532 {
533   gcc_assert (!(bb->flags & BB_RTL));
534   if (!bb->il.gimple)
535     return NULL;
536   return bb->il.gimple->phi_nodes;
537 }
538
539 /* Set PHI nodes of a basic block BB to SEQ.  */
540
541 static inline void
542 set_phi_nodes (basic_block bb, gimple_seq seq)
543 {
544   gimple_stmt_iterator i;
545
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);
551 }
552
553 /* Return the phi argument which contains the specified use.  */
554
555 static inline int
556 phi_arg_index_from_use (use_operand_p use)
557 {
558   struct phi_arg_d *element, *root;
559   size_t index;
560   gimple phi;
561
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.  */
565
566   phi = USE_STMT (use);
567   gcc_assert (gimple_code (phi) == GIMPLE_PHI);
568
569   element = (struct phi_arg_d *)use;
570   root = gimple_phi_arg (phi, 0);
571   index = element - root;
572
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
580
581  return index;
582 }
583
584 /* Mark VAR as used, so that it'll be preserved during rtl expansion.  */
585
586 static inline void
587 set_is_used (tree var)
588 {
589   var_ann_t ann = get_var_ann (var);
590   ann->used = 1;
591 }
592
593
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.  */
596
597 static inline bool
598 is_global_var (const_tree t)
599 {
600   return (TREE_STATIC (t) || DECL_EXTERNAL (t));
601 }
602
603
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.  */
607
608 static inline bool
609 may_be_aliased (const_tree var)
610 {
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)));
618 }
619
620
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.  */
624
625 static inline bool
626 phi_ssa_name_p (const_tree t)
627 {
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;
634 }
635
636
637 /* Returns the loop of the statement STMT.  */
638
639 static inline struct loop *
640 loop_containing_stmt (gimple stmt)
641 {
642   basic_block bb = gimple_bb (stmt);
643   if (!bb)
644     return NULL;
645
646   return bb->loop_father;
647 }
648
649
650 /* Return true if VAR is clobbered by function calls.  */
651 static inline bool
652 is_call_clobbered (const_tree var)
653 {
654   return (is_global_var (var)
655           || (may_be_aliased (var)
656               && pt_solution_includes (&cfun->gimple_df->escaped, var)));
657 }
658
659 /* Return true if VAR is used by function calls.  */
660 static inline bool
661 is_call_used (const_tree var)
662 {
663   return (is_call_clobbered (var)
664           || (may_be_aliased (var)
665               && pt_solution_includes (&cfun->gimple_df->callused, var)));
666 }
667
668 /*  -----------------------------------------------------------------------  */
669
670 /* The following set of routines are used to iterator over various type of
671    SSA operands.  */
672
673 /* Return true if PTR is finished iterating.  */
674 static inline bool
675 op_iter_done (const ssa_op_iter *ptr)
676 {
677   return ptr->done;
678 }
679
680 /* Get the next iterator use value for PTR.  */
681 static inline use_operand_p
682 op_iter_next_use (ssa_op_iter *ptr)
683 {
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)
689     {
690       use_p = USE_OP_PTR (ptr->uses);
691       ptr->uses = ptr->uses->next;
692       return use_p;
693     }
694   if (ptr->phi_i < ptr->num_phi)
695     {
696       return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
697     }
698   ptr->done = true;
699   return NULL_USE_OPERAND_P;
700 }
701
702 /* Get the next iterator def value for PTR.  */
703 static inline def_operand_p
704 op_iter_next_def (ssa_op_iter *ptr)
705 {
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)
711     {
712       def_p = DEF_OP_PTR (ptr->defs);
713       ptr->defs = ptr->defs->next;
714       return def_p;
715     }
716   ptr->done = true;
717   return NULL_DEF_OPERAND_P;
718 }
719
720 /* Get the next iterator tree value for PTR.  */
721 static inline tree
722 op_iter_next_tree (ssa_op_iter *ptr)
723 {
724   tree val;
725 #ifdef ENABLE_CHECKING
726   gcc_assert (ptr->iter_type == ssa_op_iter_tree);
727 #endif
728   if (ptr->uses)
729     {
730       val = USE_OP (ptr->uses);
731       ptr->uses = ptr->uses->next;
732       return val;
733     }
734   if (ptr->defs)
735     {
736       val = DEF_OP (ptr->defs);
737       ptr->defs = ptr->defs->next;
738       return val;
739     }
740
741   ptr->done = true;
742   return NULL_TREE;
743
744 }
745
746
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.  */
750
751 static inline void
752 clear_and_done_ssa_iter (ssa_op_iter *ptr)
753 {
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;
761 }
762
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)
766 {
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;
782
783   ptr->phi_i = 0;
784   ptr->num_phi = 0;
785   ptr->phi_stmt = NULL;
786 }
787
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)
792 {
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);
798 }
799
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)
804 {
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);
810 }
811
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)
816 {
817   op_iter_init (ptr, stmt, flags);
818   ptr->iter_type = ssa_op_iter_tree;
819   return op_iter_next_tree (ptr);
820 }
821
822
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)
827 {
828   tree var;
829   ssa_op_iter iter;
830
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;
838 }
839
840
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)
845 {
846   use_operand_p var;
847   ssa_op_iter iter;
848
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;
856 }
857
858
859
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)
864 {
865   def_operand_p var;
866   ssa_op_iter iter;
867
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;
875 }
876
877
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)
882 {
883   ssa_op_iter iter;
884
885   op_iter_init_tree (&iter, stmt, flags);
886   return op_iter_done (&iter);
887 }
888
889
890 /* Return the number of operands matching FLAGS in STMT.  */
891 static inline int
892 num_ssa_operands (gimple stmt, int flags)
893 {
894   ssa_op_iter iter;
895   tree t;
896   int num = 0;
897
898   FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
899     num++;
900   return num;
901 }
902
903
904 /* Delink all immediate_use information for STMT.  */
905 static inline void
906 delink_stmt_imm_use (gimple stmt)
907 {
908    ssa_op_iter iter;
909    use_operand_p use_p;
910
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);
914 }
915
916
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)
921 {
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;
928 }
929
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)
934 {
935   tree phi_def = gimple_phi_result (phi);
936   int comp;
937
938   clear_and_done_ssa_iter (ptr);
939   ptr->done = false;
940
941   gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
942
943   comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
944
945   /* If the PHI node doesn't the operand type we care about, we're done.  */
946   if ((flags & comp) == 0)
947     {
948       ptr->done = true;
949       return NULL_USE_OPERAND_P;
950     }
951
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);
956 }
957
958
959 /* Start an iterator for a PHI definition.  */
960
961 static inline def_operand_p
962 op_iter_init_phidef (ssa_op_iter *ptr, gimple phi, int flags)
963 {
964   tree phi_def = PHI_RESULT (phi);
965   int comp;
966
967   clear_and_done_ssa_iter (ptr);
968   ptr->done = false;
969
970   gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
971
972   comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
973
974   /* If the PHI node doesn't have the operand type we care about,
975      we're done.  */
976   if ((flags & comp) == 0)
977     {
978       ptr->done = true;
979       return NULL_DEF_OPERAND_P;
980     }
981
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);
987 }
988
989 /* Return true is IMM has reached the end of the immediate use stmt list.  */
990
991 static inline bool
992 end_imm_use_stmt_p (const imm_use_iterator *imm)
993 {
994   return (imm->imm_use == imm->end_p);
995 }
996
997 /* Finished the traverse of an immediate use stmt list IMM by removing the
998    placeholder node from the list.  */
999
1000 static inline void
1001 end_imm_use_stmt_traverse (imm_use_iterator *imm)
1002 {
1003   delink_imm_use (&(imm->iter_node));
1004 }
1005
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.  */
1011
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)
1015 {
1016   gcc_assert (USE_FROM_PTR (use_p) == USE_FROM_PTR (head));
1017   /* Skip head when we find it.  */
1018   if (use_p != head)
1019     {
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
1024         {
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;
1029         }
1030     }
1031   return last_p;
1032 }
1033
1034
1035 /* This routine will relink all uses with the same stmt as HEAD into the list
1036    immediately following HEAD for iterator IMM.  */
1037
1038 static inline void
1039 link_use_stmts_after (use_operand_p head, imm_use_iterator *imm)
1040 {
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;
1047
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);
1050
1051   if (gimple_code (head_stmt) == GIMPLE_PHI)
1052     {
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);
1056     }
1057   else
1058     {
1059       if (flag == SSA_OP_USE)
1060         {
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);
1064         }
1065       else if ((use_p = gimple_vuse_op (head_stmt)) != NULL_USE_OPERAND_P)
1066         {
1067           if (USE_FROM_PTR (use_p) == use)
1068             last_p = move_use_after_head (use_p, head, last_p);
1069         }
1070     }
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);
1075 }
1076
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)
1080 {
1081   gcc_assert (TREE_CODE (var) == SSA_NAME);
1082
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;
1086
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;
1094
1095   if (end_imm_use_stmt_p (imm))
1096     return NULL;
1097
1098   link_use_stmts_after (imm->imm_use, imm);
1099
1100   return USE_STMT (imm->imm_use);
1101 }
1102
1103 /* Bump IMM to the next stmt which has a use of var.  */
1104
1105 static inline gimple
1106 next_imm_use_stmt (imm_use_iterator *imm)
1107 {
1108   imm->imm_use = imm->iter_node.next;
1109   if (end_imm_use_stmt_p (imm))
1110     {
1111       if (imm->iter_node.prev != NULL)
1112         delink_imm_use (&imm->iter_node);
1113       return NULL;
1114     }
1115
1116   link_use_stmts_after (imm->imm_use, imm);
1117   return USE_STMT (imm->imm_use);
1118 }
1119
1120 /* This routine will return the first use on the stmt IMM currently refers
1121    to.  */
1122
1123 static inline use_operand_p
1124 first_imm_use_on_stmt (imm_use_iterator *imm)
1125 {
1126   imm->next_imm_name = imm->imm_use->next;
1127   return imm->imm_use;
1128 }
1129
1130 /*  Return TRUE if the last use on the stmt IMM refers to has been visited.  */
1131
1132 static inline bool
1133 end_imm_use_on_stmt_p (const imm_use_iterator *imm)
1134 {
1135   return (imm->imm_use == &(imm->iter_node));
1136 }
1137
1138 /* Bump to the next use on the stmt IMM refers to, return NULL if done.  */
1139
1140 static inline use_operand_p
1141 next_imm_use_on_stmt (imm_use_iterator *imm)
1142 {
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
1147     {
1148       imm->next_imm_name = imm->imm_use->next;
1149       return imm->imm_use;
1150     }
1151 }
1152
1153 /* Return true if VAR cannot be modified by the program.  */
1154
1155 static inline bool
1156 unmodifiable_var_p (const_tree var)
1157 {
1158   if (TREE_CODE (var) == SSA_NAME)
1159     var = SSA_NAME_VAR (var);
1160
1161   return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1162 }
1163
1164 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it.  */
1165
1166 static inline bool
1167 array_ref_contains_indirect_ref (const_tree ref)
1168 {
1169   gcc_assert (TREE_CODE (ref) == ARRAY_REF);
1170
1171   do {
1172     ref = TREE_OPERAND (ref, 0);
1173   } while (handled_component_p (ref));
1174
1175   return TREE_CODE (ref) == INDIRECT_REF;
1176 }
1177
1178 /* Return true if REF, a handled component reference, has an ARRAY_REF
1179    somewhere in it.  */
1180
1181 static inline bool
1182 ref_contains_array_ref (const_tree ref)
1183 {
1184   gcc_assert (handled_component_p (ref));
1185
1186   do {
1187     if (TREE_CODE (ref) == ARRAY_REF)
1188       return true;
1189     ref = TREE_OPERAND (ref, 0);
1190   } while (handled_component_p (ref));
1191
1192   return false;
1193 }
1194
1195 /* Return true if REF has an VIEW_CONVERT_EXPR somewhere in it.  */
1196
1197 static inline bool
1198 contains_view_convert_expr_p (const_tree ref)
1199 {
1200   while (handled_component_p (ref))
1201     {
1202       if (TREE_CODE (ref) == VIEW_CONVERT_EXPR)
1203         return true;
1204       ref = TREE_OPERAND (ref, 0);
1205     }
1206
1207   return false;
1208 }
1209
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.  */
1213
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)
1219 {
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;
1228
1229   return false;
1230 }
1231
1232 /* Accessor to tree-ssa-operands.c caches.  */
1233 static inline struct ssa_operands *
1234 gimple_ssa_operands (const struct function *fun)
1235 {
1236   return &fun->gimple_df->ssa_operands;
1237 }
1238
1239 /* Given an edge_var_map V, return the PHI arg definition.  */
1240
1241 static inline tree
1242 redirect_edge_var_map_def (edge_var_map *v)
1243 {
1244   return v->def;
1245 }
1246
1247 /* Given an edge_var_map V, return the PHI result.  */
1248
1249 static inline tree
1250 redirect_edge_var_map_result (edge_var_map *v)
1251 {
1252   return v->result;
1253 }
1254
1255 /* Given an edge_var_map V, return the PHI arg location.  */
1256
1257 static inline source_location
1258 redirect_edge_var_map_location (edge_var_map *v)
1259 {
1260   return v->locus;
1261 }
1262
1263
1264 /* Return an SSA_NAME node for variable VAR defined in statement STMT
1265    in function cfun.  */
1266
1267 static inline tree
1268 make_ssa_name (tree var, gimple stmt)
1269 {
1270   return make_ssa_name_fn (cfun, var, stmt);
1271 }
1272
1273 #endif /* _TREE_FLOW_INLINE_H  */