OSDN Git Service

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