OSDN Git Service

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