OSDN Git Service

2009-04-10 Robert Dewar <dewar@adacore.com>
[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   var_ann_t ann;
156
157   if (!t->base.ann)
158     return NULL;
159   ann = (var_ann_t) t->base.ann;
160
161   gcc_assert (ann->common.type == VAR_ANN);
162
163   return ann;
164 }
165
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)
170 {
171   var_ann_t ann = var_ann (var);
172   return (ann) ? ann : create_var_ann (var);
173 }
174
175 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
176    Return NULL if the function annotation doesn't already exist.  */
177 static inline function_ann_t
178 function_ann (const_tree t)
179 {
180   gcc_assert (t);
181   gcc_assert (TREE_CODE (t) == FUNCTION_DECL);
182   gcc_assert (!t->base.ann
183               || t->base.ann->common.type == FUNCTION_ANN);
184
185   return (function_ann_t) t->base.ann;
186 }
187
188 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
189    Create the function annotation if it doesn't exist.  */
190 static inline function_ann_t
191 get_function_ann (tree var)
192 {
193   function_ann_t ann = function_ann (var);
194   gcc_assert (!var->base.ann || var->base.ann->common.type == FUNCTION_ANN);
195   return (ann) ? ann : create_function_ann (var);
196 }
197
198 /* Get the number of the next statement uid to be allocated.  */
199 static inline unsigned int
200 gimple_stmt_max_uid (struct function *fn)
201 {
202   return fn->last_stmt_uid;
203 }
204
205 /* Set the number of the next statement uid to be allocated.  */
206 static inline void
207 set_gimple_stmt_max_uid (struct function *fn, unsigned int maxid)
208 {
209   fn->last_stmt_uid = maxid;
210 }
211
212 /* Set the number of the next statement uid to be allocated.  */
213 static inline unsigned int
214 inc_gimple_stmt_max_uid (struct function *fn)
215 {
216   return fn->last_stmt_uid++;
217 }
218
219 /* Return the annotation type for annotation ANN.  */
220 static inline enum tree_ann_type
221 ann_type (tree_ann_t ann)
222 {
223   return ann->common.type;
224 }
225
226 /* Return the line number for EXPR, or return -1 if we have no line
227    number information for it.  */
228 static inline int
229 get_lineno (const_gimple stmt)
230 {
231   location_t loc;
232
233   if (!stmt)
234     return -1;
235
236   loc = gimple_location (stmt);
237   if (loc != UNKNOWN_LOCATION)
238     return -1;
239
240   return LOCATION_LINE (loc);
241 }
242
243 /* Delink an immediate_uses node from its chain.  */
244 static inline void
245 delink_imm_use (ssa_use_operand_t *linknode)
246 {
247   /* Return if this node is not in a list.  */
248   if (linknode->prev == NULL)
249     return;
250
251   linknode->prev->next = linknode->next;
252   linknode->next->prev = linknode->prev;
253   linknode->prev = NULL;
254   linknode->next = NULL;
255 }
256
257 /* Link ssa_imm_use node LINKNODE into the chain for LIST.  */
258 static inline void
259 link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
260 {
261   /* Link the new node at the head of the list.  If we are in the process of 
262      traversing the list, we won't visit any new nodes added to it.  */
263   linknode->prev = list;
264   linknode->next = list->next;
265   list->next->prev = linknode;
266   list->next = linknode;
267 }
268
269 /* Link ssa_imm_use node LINKNODE into the chain for DEF.  */
270 static inline void
271 link_imm_use (ssa_use_operand_t *linknode, tree def)
272 {
273   ssa_use_operand_t *root;
274
275   if (!def || TREE_CODE (def) != SSA_NAME)
276     linknode->prev = NULL;
277   else
278     {
279       root = &(SSA_NAME_IMM_USE_NODE (def));
280 #ifdef ENABLE_CHECKING
281       if (linknode->use)
282         gcc_assert (*(linknode->use) == def);
283 #endif
284       link_imm_use_to_list (linknode, root);
285     }
286 }
287
288 /* Set the value of a use pointed to by USE to VAL.  */
289 static inline void
290 set_ssa_use_from_ptr (use_operand_p use, tree val)
291 {
292   delink_imm_use (use);
293   *(use->use) = val;
294   link_imm_use (use, val);
295 }
296
297 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring 
298    in STMT.  */
299 static inline void
300 link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, gimple stmt)
301 {
302   if (stmt)
303     link_imm_use (linknode, def);
304   else
305     link_imm_use (linknode, NULL);
306   linknode->loc.stmt = stmt;
307 }
308
309 /* Relink a new node in place of an old node in the list.  */
310 static inline void
311 relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
312 {
313   /* The node one had better be in the same list.  */
314   gcc_assert (*(old->use) == *(node->use));
315   node->prev = old->prev;
316   node->next = old->next;
317   if (old->prev)
318     {
319       old->prev->next = node;
320       old->next->prev = node;
321       /* Remove the old node from the list.  */
322       old->prev = NULL;
323     }
324 }
325
326 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring 
327    in STMT.  */
328 static inline void
329 relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old,
330                      gimple stmt)
331 {
332   if (stmt)
333     relink_imm_use (linknode, old);
334   else
335     link_imm_use (linknode, NULL);
336   linknode->loc.stmt = stmt;
337 }
338
339
340 /* Return true is IMM has reached the end of the immediate use list.  */
341 static inline bool
342 end_readonly_imm_use_p (const imm_use_iterator *imm)
343 {
344   return (imm->imm_use == imm->end_p);
345 }
346
347 /* Initialize iterator IMM to process the list for VAR.  */
348 static inline use_operand_p
349 first_readonly_imm_use (imm_use_iterator *imm, tree var)
350 {
351   gcc_assert (TREE_CODE (var) == SSA_NAME);
352
353   imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
354   imm->imm_use = imm->end_p->next;
355 #ifdef ENABLE_CHECKING
356   imm->iter_node.next = imm->imm_use->next;
357 #endif
358   if (end_readonly_imm_use_p (imm))
359     return NULL_USE_OPERAND_P;
360   return imm->imm_use;
361 }
362
363 /* Bump IMM to the next use in the list.  */
364 static inline use_operand_p
365 next_readonly_imm_use (imm_use_iterator *imm)
366 {
367   use_operand_p old = imm->imm_use;
368
369 #ifdef ENABLE_CHECKING
370   /* If this assertion fails, it indicates the 'next' pointer has changed
371      since the last bump.  This indicates that the list is being modified
372      via stmt changes, or SET_USE, or somesuch thing, and you need to be
373      using the SAFE version of the iterator.  */
374   gcc_assert (imm->iter_node.next == old->next);
375   imm->iter_node.next = old->next->next;
376 #endif
377
378   imm->imm_use = old->next;
379   if (end_readonly_imm_use_p (imm))
380     return NULL_USE_OPERAND_P;
381   return imm->imm_use;
382 }
383
384 /* Return true if VAR has no uses.  */
385 static inline bool
386 has_zero_uses (const_tree var)
387 {
388   const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
389   /* A single use means there is no items in the list.  */
390   return (ptr == ptr->next);
391 }
392
393 /* Return true if VAR has a single use.  */
394 static inline bool
395 has_single_use (const_tree var)
396 {
397   const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
398   /* A single use means there is one item in the list.  */
399   return (ptr != ptr->next && ptr == ptr->next->next);
400 }
401
402
403 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
404    to the use pointer and stmt of occurrence.  */
405 static inline bool
406 single_imm_use (const_tree var, use_operand_p *use_p, gimple *stmt)
407 {
408   const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
409   if (ptr != ptr->next && ptr == ptr->next->next)
410     {
411       *use_p = ptr->next;
412       *stmt = ptr->next->loc.stmt;
413       return true;
414     }
415   *use_p = NULL_USE_OPERAND_P;
416   *stmt = NULL;
417   return false;
418 }
419
420 /* Return the number of immediate uses of VAR.  */
421 static inline unsigned int
422 num_imm_uses (const_tree var)
423 {
424   const ssa_use_operand_t *const start = &(SSA_NAME_IMM_USE_NODE (var));
425   const ssa_use_operand_t *ptr;
426   unsigned int num = 0;
427
428   for (ptr = start->next; ptr != start; ptr = ptr->next)
429      num++;
430
431   return num;
432 }
433
434 /* Return the tree pointed-to by USE.  */ 
435 static inline tree
436 get_use_from_ptr (use_operand_p use)
437
438   return *(use->use);
439
440
441 /* Return the tree pointed-to by DEF.  */
442 static inline tree
443 get_def_from_ptr (def_operand_p def)
444 {
445   return *def;
446 }
447
448 /* Return a use_operand_p pointer for argument I of PHI node GS.  */
449
450 static inline use_operand_p
451 gimple_phi_arg_imm_use_ptr (gimple gs, int i)
452 {
453   return &gimple_phi_arg (gs, i)->imm_use;
454 }
455
456 /* Return the tree operand for argument I of PHI node GS.  */
457
458 static inline tree
459 gimple_phi_arg_def (gimple gs, size_t index)
460 {
461   struct phi_arg_d *pd = gimple_phi_arg (gs, index);
462   return get_use_from_ptr (&pd->imm_use);
463 }
464
465 /* Return a pointer to the tree operand for argument I of PHI node GS.  */
466
467 static inline tree *
468 gimple_phi_arg_def_ptr (gimple gs, size_t index)
469 {
470   return &gimple_phi_arg (gs, index)->def;
471 }
472
473 /* Return the edge associated with argument I of phi node GS.  */
474
475 static inline edge
476 gimple_phi_arg_edge (gimple gs, size_t i)
477 {
478   return EDGE_PRED (gimple_bb (gs), i);
479 }
480
481 /* Return the PHI nodes for basic block BB, or NULL if there are no
482    PHI nodes.  */
483 static inline gimple_seq
484 phi_nodes (const_basic_block bb)
485 {
486   gcc_assert (!(bb->flags & BB_RTL));
487   if (!bb->il.gimple)
488     return NULL;
489   return bb->il.gimple->phi_nodes;
490 }
491
492 /* Set PHI nodes of a basic block BB to SEQ.  */
493
494 static inline void
495 set_phi_nodes (basic_block bb, gimple_seq seq)
496 {
497   gimple_stmt_iterator i;
498
499   gcc_assert (!(bb->flags & BB_RTL));
500   bb->il.gimple->phi_nodes = seq;
501   if (seq)
502     for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
503       gimple_set_bb (gsi_stmt (i), bb);
504 }
505
506 /* Return the phi argument which contains the specified use.  */
507
508 static inline int
509 phi_arg_index_from_use (use_operand_p use)
510 {
511   struct phi_arg_d *element, *root;
512   size_t index;
513   gimple phi;
514
515   /* Since the use is the first thing in a PHI argument element, we can
516      calculate its index based on casting it to an argument, and performing
517      pointer arithmetic.  */
518
519   phi = USE_STMT (use);
520   gcc_assert (gimple_code (phi) == GIMPLE_PHI);
521
522   element = (struct phi_arg_d *)use;
523   root = gimple_phi_arg (phi, 0);
524   index = element - root;
525
526 #ifdef ENABLE_CHECKING
527   /* Make sure the calculation doesn't have any leftover bytes.  If it does, 
528      then imm_use is likely not the first element in phi_arg_d.  */
529   gcc_assert (
530           (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
531   gcc_assert (index < gimple_phi_capacity (phi));
532 #endif
533  
534  return index;
535 }
536
537 /* Mark VAR as used, so that it'll be preserved during rtl expansion.  */
538
539 static inline void
540 set_is_used (tree var)
541 {
542   var_ann_t ann = get_var_ann (var);
543   ann->used = 1;
544 }
545
546
547 /* Return true if T (assumed to be a DECL) is a global variable.
548    A variable is considered global if its storage is not automatic.  */
549
550 static inline bool
551 is_global_var (const_tree t)
552 {
553   return (TREE_STATIC (t) || DECL_EXTERNAL (t));
554 }
555
556
557 /* Return true if VAR may be aliased.  A variable is considered as
558    maybe aliased if it has its address taken by the local TU
559    or possibly by another TU.  */
560
561 static inline bool
562 may_be_aliased (const_tree var)
563 {
564   return (TREE_PUBLIC (var) || DECL_EXTERNAL (var) || TREE_ADDRESSABLE (var));
565 }
566
567
568 /* PHI nodes should contain only ssa_names and invariants.  A test
569    for ssa_name is definitely simpler; don't let invalid contents
570    slip in in the meantime.  */
571
572 static inline bool
573 phi_ssa_name_p (const_tree t)
574 {
575   if (TREE_CODE (t) == SSA_NAME)
576     return true;
577 #ifdef ENABLE_CHECKING
578   gcc_assert (is_gimple_min_invariant (t));
579 #endif
580   return false;
581 }
582
583
584 /* Returns the loop of the statement STMT.  */
585
586 static inline struct loop *
587 loop_containing_stmt (gimple stmt)
588 {
589   basic_block bb = gimple_bb (stmt);
590   if (!bb)
591     return NULL;
592
593   return bb->loop_father;
594 }
595
596
597 /* Return true if VAR is clobbered by function calls.  */
598 static inline bool
599 is_call_clobbered (const_tree var)
600 {
601   return (is_global_var (var)
602           || (may_be_aliased (var)
603               && pt_solution_includes (&cfun->gimple_df->escaped, var)));
604 }
605
606 /* Return true if VAR is used by function calls.  */
607 static inline bool
608 is_call_used (const_tree var)
609 {
610   return (is_call_clobbered (var)
611           || (may_be_aliased (var)
612               && pt_solution_includes (&cfun->gimple_df->callused, var)));
613 }
614
615 /* Return the common annotation for T.  Return NULL if the annotation
616    doesn't already exist.  */
617 static inline tree_ann_common_t
618 tree_common_ann (const_tree t)
619 {
620   /* Watch out static variables with unshared annotations.  */
621   if (DECL_P (t) && TREE_CODE (t) == VAR_DECL)
622     return &var_ann (t)->common;
623   return &t->base.ann->common;
624 }
625
626 /* Return a common annotation for T.  Create the constant annotation if it
627    doesn't exist.  */
628 static inline tree_ann_common_t
629 get_tree_common_ann (tree t)
630 {
631   tree_ann_common_t ann = tree_common_ann (t);
632   return (ann) ? ann : create_tree_common_ann (t);
633 }
634
635 /*  -----------------------------------------------------------------------  */
636
637 /* The following set of routines are used to iterator over various type of
638    SSA operands.  */
639
640 /* Return true if PTR is finished iterating.  */
641 static inline bool
642 op_iter_done (const ssa_op_iter *ptr)
643 {
644   return ptr->done;
645 }
646
647 /* Get the next iterator use value for PTR.  */
648 static inline use_operand_p
649 op_iter_next_use (ssa_op_iter *ptr)
650 {
651   use_operand_p use_p;
652 #ifdef ENABLE_CHECKING
653   gcc_assert (ptr->iter_type == ssa_op_iter_use);
654 #endif
655   if (ptr->uses)
656     {
657       use_p = USE_OP_PTR (ptr->uses);
658       ptr->uses = ptr->uses->next;
659       return use_p;
660     }
661   if (ptr->phi_i < ptr->num_phi)
662     {
663       return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
664     }
665   ptr->done = true;
666   return NULL_USE_OPERAND_P;
667 }
668
669 /* Get the next iterator def value for PTR.  */
670 static inline def_operand_p
671 op_iter_next_def (ssa_op_iter *ptr)
672 {
673   def_operand_p def_p;
674 #ifdef ENABLE_CHECKING
675   gcc_assert (ptr->iter_type == ssa_op_iter_def);
676 #endif
677   if (ptr->defs)
678     {
679       def_p = DEF_OP_PTR (ptr->defs);
680       ptr->defs = ptr->defs->next;
681       return def_p;
682     }
683   ptr->done = true;
684   return NULL_DEF_OPERAND_P;
685 }
686
687 /* Get the next iterator tree value for PTR.  */
688 static inline tree
689 op_iter_next_tree (ssa_op_iter *ptr)
690 {
691   tree val;
692 #ifdef ENABLE_CHECKING
693   gcc_assert (ptr->iter_type == ssa_op_iter_tree);
694 #endif
695   if (ptr->uses)
696     {
697       val = USE_OP (ptr->uses);
698       ptr->uses = ptr->uses->next;
699       return val;
700     }
701   if (ptr->defs)
702     {
703       val = DEF_OP (ptr->defs);
704       ptr->defs = ptr->defs->next;
705       return val;
706     }
707
708   ptr->done = true;
709   return NULL_TREE;
710
711 }
712
713
714 /* This functions clears the iterator PTR, and marks it done.  This is normally
715    used to prevent warnings in the compile about might be uninitialized
716    components.  */
717
718 static inline void
719 clear_and_done_ssa_iter (ssa_op_iter *ptr)
720 {
721   ptr->defs = NULL;
722   ptr->uses = NULL;
723   ptr->iter_type = ssa_op_iter_none;
724   ptr->phi_i = 0;
725   ptr->num_phi = 0;
726   ptr->phi_stmt = NULL;
727   ptr->done = true;
728 }
729
730 /* Initialize the iterator PTR to the virtual defs in STMT.  */
731 static inline void
732 op_iter_init (ssa_op_iter *ptr, gimple stmt, int flags)
733 {
734   /* We do not support iterating over virtual defs or uses without
735      iterating over defs or uses at the same time.  */
736   gcc_assert ((!(flags & SSA_OP_VDEF) || (flags & SSA_OP_DEF))
737               && (!(flags & SSA_OP_VUSE) || (flags & SSA_OP_USE)));
738   ptr->defs = (flags & (SSA_OP_DEF|SSA_OP_VDEF)) ? gimple_def_ops (stmt) : NULL;
739   if (!(flags & SSA_OP_VDEF)
740       && ptr->defs
741       && gimple_vdef (stmt) != NULL_TREE)
742     ptr->defs = ptr->defs->next;
743   ptr->uses = (flags & (SSA_OP_USE|SSA_OP_VUSE)) ? gimple_use_ops (stmt) : NULL;
744   if (!(flags & SSA_OP_VUSE)
745       && ptr->uses
746       && gimple_vuse (stmt) != NULL_TREE)
747     ptr->uses = ptr->uses->next;
748   ptr->done = false;
749
750   ptr->phi_i = 0;
751   ptr->num_phi = 0;
752   ptr->phi_stmt = NULL;
753 }
754
755 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
756    the first use.  */
757 static inline use_operand_p
758 op_iter_init_use (ssa_op_iter *ptr, gimple stmt, int flags)
759 {
760   gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0
761               && (flags & SSA_OP_USE));
762   op_iter_init (ptr, stmt, flags);
763   ptr->iter_type = ssa_op_iter_use;
764   return op_iter_next_use (ptr);
765 }
766
767 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
768    the first def.  */
769 static inline def_operand_p
770 op_iter_init_def (ssa_op_iter *ptr, gimple stmt, int flags)
771 {
772   gcc_assert ((flags & SSA_OP_ALL_USES) == 0
773               && (flags & SSA_OP_DEF));
774   op_iter_init (ptr, stmt, flags);
775   ptr->iter_type = ssa_op_iter_def;
776   return op_iter_next_def (ptr);
777 }
778
779 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
780    the first operand as a tree.  */
781 static inline tree
782 op_iter_init_tree (ssa_op_iter *ptr, gimple stmt, int flags)
783 {
784   op_iter_init (ptr, stmt, flags);
785   ptr->iter_type = ssa_op_iter_tree;
786   return op_iter_next_tree (ptr);
787 }
788
789
790 /* If there is a single operand in STMT matching FLAGS, return it.  Otherwise
791    return NULL.  */
792 static inline tree
793 single_ssa_tree_operand (gimple stmt, int flags)
794 {
795   tree var;
796   ssa_op_iter iter;
797
798   var = op_iter_init_tree (&iter, stmt, flags);
799   if (op_iter_done (&iter))
800     return NULL_TREE;
801   op_iter_next_tree (&iter);
802   if (op_iter_done (&iter))
803     return var;
804   return NULL_TREE;
805 }
806
807
808 /* If there is a single operand in STMT matching FLAGS, return it.  Otherwise
809    return NULL.  */
810 static inline use_operand_p
811 single_ssa_use_operand (gimple stmt, int flags)
812 {
813   use_operand_p var;
814   ssa_op_iter iter;
815
816   var = op_iter_init_use (&iter, stmt, flags);
817   if (op_iter_done (&iter))
818     return NULL_USE_OPERAND_P;
819   op_iter_next_use (&iter);
820   if (op_iter_done (&iter))
821     return var;
822   return NULL_USE_OPERAND_P;
823 }
824
825
826
827 /* If there is a single operand in STMT matching FLAGS, return it.  Otherwise
828    return NULL.  */
829 static inline def_operand_p
830 single_ssa_def_operand (gimple stmt, int flags)
831 {
832   def_operand_p var;
833   ssa_op_iter iter;
834
835   var = op_iter_init_def (&iter, stmt, flags);
836   if (op_iter_done (&iter))
837     return NULL_DEF_OPERAND_P;
838   op_iter_next_def (&iter);
839   if (op_iter_done (&iter))
840     return var;
841   return NULL_DEF_OPERAND_P;
842 }
843
844
845 /* Return true if there are zero operands in STMT matching the type 
846    given in FLAGS.  */
847 static inline bool
848 zero_ssa_operands (gimple stmt, int flags)
849 {
850   ssa_op_iter iter;
851
852   op_iter_init_tree (&iter, stmt, flags);
853   return op_iter_done (&iter);
854 }
855
856
857 /* Return the number of operands matching FLAGS in STMT.  */
858 static inline int
859 num_ssa_operands (gimple stmt, int flags)
860 {
861   ssa_op_iter iter;
862   tree t;
863   int num = 0;
864
865   FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
866     num++;
867   return num;
868 }
869
870
871 /* Delink all immediate_use information for STMT.  */
872 static inline void
873 delink_stmt_imm_use (gimple stmt)
874 {
875    ssa_op_iter iter;
876    use_operand_p use_p;
877
878    if (ssa_operands_active ())
879      FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_ALL_USES)
880        delink_imm_use (use_p);
881 }
882
883
884 /* If there is a single DEF in the PHI node which matches FLAG, return it.
885    Otherwise return NULL_DEF_OPERAND_P.  */
886 static inline tree
887 single_phi_def (gimple stmt, int flags)
888 {
889   tree def = PHI_RESULT (stmt);
890   if ((flags & SSA_OP_DEF) && is_gimple_reg (def)) 
891     return def;
892   if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
893     return def;
894   return NULL_TREE;
895 }
896
897 /* Initialize the iterator PTR for uses matching FLAGS in PHI.  FLAGS should
898    be either SSA_OP_USES or SSA_OP_VIRTUAL_USES.  */
899 static inline use_operand_p
900 op_iter_init_phiuse (ssa_op_iter *ptr, gimple phi, int flags)
901 {
902   tree phi_def = gimple_phi_result (phi);
903   int comp;
904
905   clear_and_done_ssa_iter (ptr);
906   ptr->done = false;
907
908   gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
909
910   comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
911     
912   /* If the PHI node doesn't the operand type we care about, we're done.  */
913   if ((flags & comp) == 0)
914     {
915       ptr->done = true;
916       return NULL_USE_OPERAND_P;
917     }
918
919   ptr->phi_stmt = phi;
920   ptr->num_phi = gimple_phi_num_args (phi);
921   ptr->iter_type = ssa_op_iter_use;
922   return op_iter_next_use (ptr);
923 }
924
925
926 /* Start an iterator for a PHI definition.  */
927
928 static inline def_operand_p
929 op_iter_init_phidef (ssa_op_iter *ptr, gimple phi, int flags)
930 {
931   tree phi_def = PHI_RESULT (phi);
932   int comp;
933
934   clear_and_done_ssa_iter (ptr);
935   ptr->done = false;
936
937   gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
938
939   comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
940     
941   /* If the PHI node doesn't have the operand type we care about,
942      we're done.  */
943   if ((flags & comp) == 0)
944     {
945       ptr->done = true;
946       return NULL_DEF_OPERAND_P;
947     }
948
949   ptr->iter_type = ssa_op_iter_def;
950   /* The first call to op_iter_next_def will terminate the iterator since
951      all the fields are NULL.  Simply return the result here as the first and
952      therefore only result.  */
953   return PHI_RESULT_PTR (phi);
954 }
955
956 /* Return true is IMM has reached the end of the immediate use stmt list.  */
957
958 static inline bool
959 end_imm_use_stmt_p (const imm_use_iterator *imm)
960 {
961   return (imm->imm_use == imm->end_p);
962 }
963
964 /* Finished the traverse of an immediate use stmt list IMM by removing the
965    placeholder node from the list.  */
966
967 static inline void
968 end_imm_use_stmt_traverse (imm_use_iterator *imm)
969 {
970   delink_imm_use (&(imm->iter_node));
971 }
972
973 /* Immediate use traversal of uses within a stmt require that all the
974    uses on a stmt be sequentially listed.  This routine is used to build up
975    this sequential list by adding USE_P to the end of the current list 
976    currently delimited by HEAD and LAST_P.  The new LAST_P value is 
977    returned.  */
978
979 static inline use_operand_p
980 move_use_after_head (use_operand_p use_p, use_operand_p head, 
981                       use_operand_p last_p)
982 {
983   gcc_assert (USE_FROM_PTR (use_p) == USE_FROM_PTR (head));
984   /* Skip head when we find it.  */
985   if (use_p != head)
986     {
987       /* If use_p is already linked in after last_p, continue.  */
988       if (last_p->next == use_p)
989         last_p = use_p;
990       else
991         {
992           /* Delink from current location, and link in at last_p.  */
993           delink_imm_use (use_p);
994           link_imm_use_to_list (use_p, last_p);
995           last_p = use_p;
996         }
997     }
998   return last_p;
999 }
1000
1001
1002 /* This routine will relink all uses with the same stmt as HEAD into the list
1003    immediately following HEAD for iterator IMM.  */
1004
1005 static inline void
1006 link_use_stmts_after (use_operand_p head, imm_use_iterator *imm)
1007 {
1008   use_operand_p use_p;
1009   use_operand_p last_p = head;
1010   gimple head_stmt = USE_STMT (head);
1011   tree use = USE_FROM_PTR (head);
1012   ssa_op_iter op_iter;
1013   int flag;
1014
1015   /* Only look at virtual or real uses, depending on the type of HEAD.  */
1016   flag = (is_gimple_reg (use) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1017
1018   if (gimple_code (head_stmt) == GIMPLE_PHI)
1019     {
1020       FOR_EACH_PHI_ARG (use_p, head_stmt, op_iter, flag)
1021         if (USE_FROM_PTR (use_p) == use)
1022           last_p = move_use_after_head (use_p, head, last_p);
1023     }
1024   else
1025     {
1026       if (flag == SSA_OP_USE)
1027         {
1028           FOR_EACH_SSA_USE_OPERAND (use_p, head_stmt, op_iter, flag)
1029             if (USE_FROM_PTR (use_p) == use)
1030               last_p = move_use_after_head (use_p, head, last_p);
1031         }
1032       else if ((use_p = gimple_vuse_op (head_stmt)) != NULL_USE_OPERAND_P)
1033         {
1034           if (USE_FROM_PTR (use_p) == use)
1035             last_p = move_use_after_head (use_p, head, last_p);
1036         }
1037     }
1038   /* Link iter node in after last_p.  */
1039   if (imm->iter_node.prev != NULL)
1040     delink_imm_use (&imm->iter_node);
1041   link_imm_use_to_list (&(imm->iter_node), last_p);
1042 }
1043
1044 /* Initialize IMM to traverse over uses of VAR.  Return the first statement.  */
1045 static inline gimple
1046 first_imm_use_stmt (imm_use_iterator *imm, tree var)
1047 {
1048   gcc_assert (TREE_CODE (var) == SSA_NAME);
1049   
1050   imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
1051   imm->imm_use = imm->end_p->next;
1052   imm->next_imm_name = NULL_USE_OPERAND_P;
1053
1054   /* iter_node is used as a marker within the immediate use list to indicate
1055      where the end of the current stmt's uses are.  Initialize it to NULL
1056      stmt and use, which indicates a marker node.  */
1057   imm->iter_node.prev = NULL_USE_OPERAND_P;
1058   imm->iter_node.next = NULL_USE_OPERAND_P;
1059   imm->iter_node.loc.stmt = NULL;
1060   imm->iter_node.use = NULL;
1061
1062   if (end_imm_use_stmt_p (imm))
1063     return NULL;
1064
1065   link_use_stmts_after (imm->imm_use, imm);
1066
1067   return USE_STMT (imm->imm_use);
1068 }
1069
1070 /* Bump IMM to the next stmt which has a use of var.  */
1071
1072 static inline gimple
1073 next_imm_use_stmt (imm_use_iterator *imm)
1074 {
1075   imm->imm_use = imm->iter_node.next;
1076   if (end_imm_use_stmt_p (imm))
1077     {
1078       if (imm->iter_node.prev != NULL)
1079         delink_imm_use (&imm->iter_node);
1080       return NULL;
1081     }
1082
1083   link_use_stmts_after (imm->imm_use, imm);
1084   return USE_STMT (imm->imm_use);
1085 }
1086
1087 /* This routine will return the first use on the stmt IMM currently refers
1088    to.  */
1089
1090 static inline use_operand_p
1091 first_imm_use_on_stmt (imm_use_iterator *imm)
1092 {
1093   imm->next_imm_name = imm->imm_use->next;
1094   return imm->imm_use;
1095 }
1096
1097 /*  Return TRUE if the last use on the stmt IMM refers to has been visited.  */
1098
1099 static inline bool
1100 end_imm_use_on_stmt_p (const imm_use_iterator *imm)
1101 {
1102   return (imm->imm_use == &(imm->iter_node));
1103 }
1104
1105 /* Bump to the next use on the stmt IMM refers to, return NULL if done.  */
1106
1107 static inline use_operand_p
1108 next_imm_use_on_stmt (imm_use_iterator *imm)
1109 {
1110   imm->imm_use = imm->next_imm_name;
1111   if (end_imm_use_on_stmt_p (imm))
1112     return NULL_USE_OPERAND_P;
1113   else
1114     {
1115       imm->next_imm_name = imm->imm_use->next;
1116       return imm->imm_use;
1117     }
1118 }
1119
1120 /* Return true if VAR cannot be modified by the program.  */
1121
1122 static inline bool
1123 unmodifiable_var_p (const_tree var)
1124 {
1125   if (TREE_CODE (var) == SSA_NAME)
1126     var = SSA_NAME_VAR (var);
1127
1128   return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1129 }
1130
1131 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it.  */
1132
1133 static inline bool
1134 array_ref_contains_indirect_ref (const_tree ref)
1135 {
1136   gcc_assert (TREE_CODE (ref) == ARRAY_REF);
1137
1138   do {
1139     ref = TREE_OPERAND (ref, 0);
1140   } while (handled_component_p (ref));
1141
1142   return TREE_CODE (ref) == INDIRECT_REF;
1143 }
1144
1145 /* Return true if REF, a handled component reference, has an ARRAY_REF
1146    somewhere in it.  */
1147
1148 static inline bool
1149 ref_contains_array_ref (const_tree ref)
1150 {
1151   gcc_assert (handled_component_p (ref));
1152
1153   do {
1154     if (TREE_CODE (ref) == ARRAY_REF)
1155       return true;
1156     ref = TREE_OPERAND (ref, 0);
1157   } while (handled_component_p (ref));
1158
1159   return false;
1160 }
1161
1162 /* Return true, if the two ranges [POS1, SIZE1] and [POS2, SIZE2]
1163    overlap.  SIZE1 and/or SIZE2 can be (unsigned)-1 in which case the
1164    range is open-ended.  Otherwise return false.  */
1165
1166 static inline bool
1167 ranges_overlap_p (unsigned HOST_WIDE_INT pos1,
1168                   unsigned HOST_WIDE_INT size1,
1169                   unsigned HOST_WIDE_INT pos2,
1170                   unsigned HOST_WIDE_INT size2)
1171 {
1172   if (pos1 >= pos2
1173       && (size2 == (unsigned HOST_WIDE_INT)-1
1174           || pos1 < (pos2 + size2)))
1175     return true;
1176   if (pos2 >= pos1
1177       && (size1 == (unsigned HOST_WIDE_INT)-1
1178           || pos2 < (pos1 + size1)))
1179     return true;
1180
1181   return false;
1182 }
1183
1184 /* Accessor to tree-ssa-operands.c caches.  */
1185 static inline struct ssa_operands *
1186 gimple_ssa_operands (const struct function *fun)
1187 {
1188   return &fun->gimple_df->ssa_operands;
1189 }
1190
1191 /* Given an edge_var_map V, return the PHI arg definition.  */
1192
1193 static inline tree
1194 redirect_edge_var_map_def (edge_var_map *v)
1195 {
1196   return v->def;
1197 }
1198
1199 /* Given an edge_var_map V, return the PHI result.  */
1200
1201 static inline tree
1202 redirect_edge_var_map_result (edge_var_map *v)
1203 {
1204   return v->result;
1205 }
1206
1207
1208 /* Return an SSA_NAME node for variable VAR defined in statement STMT
1209    in function cfun.  */
1210
1211 static inline tree
1212 make_ssa_name (tree var, gimple stmt)
1213 {
1214   return make_ssa_name_fn (cfun, var, stmt);
1215 }
1216
1217 #endif /* _TREE_FLOW_INLINE_H  */