OSDN Git Service

bc4c3946335b3ed4d292c03cfea1fc26bb545358
[pf3gnuchains/gcc-fork.git] / gcc / tree-flow-inline.h
1 /* Inline functions for tree-flow.h
2    Copyright (C) 2001, 2003, 2005, 2006 Free Software Foundation, Inc.
3    Contributed by Diego Novillo <dnovillo@redhat.com>
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.  */
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 (struct function *fun)
34 {
35   return fun && fun->gimple_df && fun->gimple_df->in_ssa_p;
36 }
37
38 /* 'true' after aliases have been computed (see compute_may_aliases).  */
39 static inline bool
40 gimple_aliases_computed_p (struct function *fun)
41 {
42   gcc_assert (fun && fun->gimple_df);
43   return fun->gimple_df->aliases_computed_p;
44 }
45
46 /* Addressable variables in the function.  If bit I is set, then
47    REFERENCED_VARS (I) has had its address taken.  Note that
48    CALL_CLOBBERED_VARS and ADDRESSABLE_VARS are not related.  An
49    addressable variable is not necessarily call-clobbered (e.g., a
50    local addressable whose address does not escape) and not all
51    call-clobbered variables are addressable (e.g., a local static
52    variable).  */
53 static inline bitmap
54 gimple_addressable_vars (struct function *fun)
55 {
56   gcc_assert (fun && fun->gimple_df);
57   return fun->gimple_df->addressable_vars;
58 }
59
60 /* Call clobbered variables in the function.  If bit I is set, then
61    REFERENCED_VARS (I) is call-clobbered.  */
62 static inline bitmap
63 gimple_call_clobbered_vars (struct function *fun)
64 {
65   gcc_assert (fun && fun->gimple_df);
66   return fun->gimple_df->call_clobbered_vars;
67 }
68
69 /* Array of all variables referenced in the function.  */
70 static inline htab_t
71 gimple_referenced_vars (struct function *fun)
72 {
73   if (!fun->gimple_df)
74     return NULL;
75   return fun->gimple_df->referenced_vars;
76 }
77
78 /* Artificial variable used to model the effects of function calls.  */
79 static inline tree
80 gimple_global_var (struct function *fun)
81 {
82   gcc_assert (fun && fun->gimple_df);
83   return fun->gimple_df->global_var;
84 }
85
86 /* Artificial variable used to model the effects of nonlocal
87    variables.  */
88 static inline tree
89 gimple_nonlocal_all (struct function *fun)
90 {
91   gcc_assert (fun && fun->gimple_df);
92   return fun->gimple_df->nonlocal_all;
93 }
94 /* Initialize the hashtable iterator HTI to point to hashtable TABLE */
95
96 static inline void *
97 first_htab_element (htab_iterator *hti, htab_t table)
98 {
99   hti->htab = table;
100   hti->slot = table->entries;
101   hti->limit = hti->slot + htab_size (table);
102   do
103     {
104       PTR x = *(hti->slot);
105       if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
106         break;
107     } while (++(hti->slot) < hti->limit);
108   
109   if (hti->slot < hti->limit)
110     return *(hti->slot);
111   return NULL;
112 }
113
114 /* Return current non-empty/deleted slot of the hashtable pointed to by HTI,
115    or NULL if we have  reached the end.  */
116
117 static inline bool
118 end_htab_p (htab_iterator *hti)
119 {
120   if (hti->slot >= hti->limit)
121     return true;
122   return false;
123 }
124
125 /* Advance the hashtable iterator pointed to by HTI to the next element of the
126    hashtable.  */
127
128 static inline void *
129 next_htab_element (htab_iterator *hti)
130 {
131   while (++(hti->slot) < hti->limit)
132     {
133       PTR x = *(hti->slot);
134       if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
135         return x;
136     };
137   return NULL;
138 }
139
140 /* Initialize ITER to point to the first referenced variable in the
141    referenced_vars hashtable, and return that variable.  */
142
143 static inline tree
144 first_referenced_var (referenced_var_iterator *iter)
145 {
146   struct int_tree_map *itm;
147   itm = (struct int_tree_map *) first_htab_element (&iter->hti,
148                                                     gimple_referenced_vars
149                                                     (cfun));
150   if (!itm) 
151     return NULL;
152   return itm->to;
153 }
154
155 /* Return true if we have hit the end of the referenced variables ITER is
156    iterating through.  */
157
158 static inline bool
159 end_referenced_vars_p (referenced_var_iterator *iter)
160 {
161   return end_htab_p (&iter->hti);
162 }
163
164 /* Make ITER point to the next referenced_var in the referenced_var hashtable,
165    and return that variable.  */
166
167 static inline tree
168 next_referenced_var (referenced_var_iterator *iter)
169 {
170   struct int_tree_map *itm;
171   itm = (struct int_tree_map *) next_htab_element (&iter->hti);
172   if (!itm) 
173     return NULL;
174   return itm->to;
175
176
177 /* Fill up VEC with the variables in the referenced vars hashtable.  */
178
179 static inline void
180 fill_referenced_var_vec (VEC (tree, heap) **vec)
181 {
182   referenced_var_iterator rvi;
183   tree var;
184   *vec = NULL;
185   FOR_EACH_REFERENCED_VAR (var, rvi)
186     VEC_safe_push (tree, heap, *vec, var);
187 }
188
189 /* Return the variable annotation for T, which must be a _DECL node.
190    Return NULL if the variable annotation doesn't already exist.  */
191 static inline var_ann_t
192 var_ann (tree t)
193 {
194   gcc_assert (t);
195   gcc_assert (DECL_P (t));
196   gcc_assert (TREE_CODE (t) != FUNCTION_DECL);
197   gcc_assert (!t->base.ann
198               || t->base.ann->common.type == VAR_ANN);
199
200   return (var_ann_t) t->base.ann;
201 }
202
203 /* Return the variable annotation for T, which must be a _DECL node.
204    Create the variable annotation if it doesn't exist.  */
205 static inline var_ann_t
206 get_var_ann (tree var)
207 {
208   var_ann_t ann = var_ann (var);
209   return (ann) ? ann : create_var_ann (var);
210 }
211
212 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
213    Return NULL if the function annotation doesn't already exist.  */
214 static inline function_ann_t
215 function_ann (tree t)
216 {
217   gcc_assert (t);
218   gcc_assert (TREE_CODE (t) == FUNCTION_DECL);
219   gcc_assert (!t->base.ann
220               || t->base.ann->common.type == FUNCTION_ANN);
221
222   return (function_ann_t) t->base.ann;
223 }
224
225 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
226    Create the function annotation if it doesn't exist.  */
227 static inline function_ann_t
228 get_function_ann (tree var)
229 {
230   function_ann_t ann = function_ann (var);
231   gcc_assert (!var->base.ann || var->base.ann->common.type == FUNCTION_ANN);
232   return (ann) ? ann : create_function_ann (var);
233 }
234
235 /* Return true if T has a statement annotation attached to it.  */
236
237 static inline bool
238 has_stmt_ann (tree t)
239 {
240 #ifdef ENABLE_CHECKING
241   gcc_assert (is_gimple_stmt (t));
242 #endif
243   return t->base.ann && t->base.ann->common.type == STMT_ANN;
244 }
245
246 /* Return the statement annotation for T, which must be a statement
247    node.  Return NULL if the statement annotation doesn't exist.  */
248 static inline stmt_ann_t
249 stmt_ann (tree t)
250 {
251 #ifdef ENABLE_CHECKING
252   gcc_assert (is_gimple_stmt (t));
253 #endif
254   gcc_assert (!t->base.ann || t->base.ann->common.type == STMT_ANN);
255   return (stmt_ann_t) t->base.ann;
256 }
257
258 /* Return the statement annotation for T, which must be a statement
259    node.  Create the statement annotation if it doesn't exist.  */
260 static inline stmt_ann_t
261 get_stmt_ann (tree stmt)
262 {
263   stmt_ann_t ann = stmt_ann (stmt);
264   return (ann) ? ann : create_stmt_ann (stmt);
265 }
266
267 /* Return the annotation type for annotation ANN.  */
268 static inline enum tree_ann_type
269 ann_type (tree_ann_t ann)
270 {
271   return ann->common.type;
272 }
273
274 /* Return the basic block for statement T.  */
275 static inline basic_block
276 bb_for_stmt (tree t)
277 {
278   stmt_ann_t ann;
279
280   if (TREE_CODE (t) == PHI_NODE)
281     return PHI_BB (t);
282
283   ann = stmt_ann (t);
284   return ann ? ann->bb : NULL;
285 }
286
287 /* Return the may_aliases varray for variable VAR, or NULL if it has
288    no may aliases.  */
289 static inline VEC(tree, gc) *
290 may_aliases (tree var)
291 {
292   var_ann_t ann = var_ann (var);
293   return ann ? ann->may_aliases : NULL;
294 }
295
296 /* Return the line number for EXPR, or return -1 if we have no line
297    number information for it.  */
298 static inline int
299 get_lineno (tree expr)
300 {
301   if (expr == NULL_TREE)
302     return -1;
303
304   if (TREE_CODE (expr) == COMPOUND_EXPR)
305     expr = TREE_OPERAND (expr, 0);
306
307   if (! EXPR_HAS_LOCATION (expr))
308     return -1;
309
310   return EXPR_LINENO (expr);
311 }
312
313 /* Return the file name for EXPR, or return "???" if we have no
314    filename information.  */
315 static inline const char *
316 get_filename (tree expr)
317 {
318   const char *filename;
319   if (expr == NULL_TREE)
320     return "???";
321
322   if (TREE_CODE (expr) == COMPOUND_EXPR)
323     expr = TREE_OPERAND (expr, 0);
324
325   if (EXPR_HAS_LOCATION (expr) && (filename = EXPR_FILENAME (expr)))
326     return filename;
327   else
328     return "???";
329 }
330
331 /* Return true if T is a noreturn call.  */
332 static inline bool
333 noreturn_call_p (tree t)
334 {
335   tree call = get_call_expr_in (t);
336   return call != 0 && (call_expr_flags (call) & ECF_NORETURN) != 0;
337 }
338
339 /* Mark statement T as modified.  */
340 static inline void
341 mark_stmt_modified (tree t)
342 {
343   stmt_ann_t ann;
344   if (TREE_CODE (t) == PHI_NODE)
345     return;
346
347   ann = stmt_ann (t);
348   if (ann == NULL)
349     ann = create_stmt_ann (t);
350   else if (noreturn_call_p (t) && cfun->gimple_df)
351     VEC_safe_push (tree, gc, MODIFIED_NORETURN_CALLS (cfun), t);
352   ann->modified = 1;
353 }
354
355 /* Mark statement T as modified, and update it.  */
356 static inline void
357 update_stmt (tree t)
358 {
359   if (TREE_CODE (t) == PHI_NODE)
360     return;
361   mark_stmt_modified (t);
362   update_stmt_operands (t);
363 }
364
365 static inline void
366 update_stmt_if_modified (tree t)
367 {
368   if (stmt_modified_p (t))
369     update_stmt_operands (t);
370 }
371
372 /* Return true if T is marked as modified, false otherwise.  */
373 static inline bool
374 stmt_modified_p (tree t)
375 {
376   stmt_ann_t ann = stmt_ann (t);
377
378   /* Note that if the statement doesn't yet have an annotation, we consider it
379      modified.  This will force the next call to update_stmt_operands to scan 
380      the statement.  */
381   return ann ? ann->modified : true;
382 }
383
384 /* Delink an immediate_uses node from its chain.  */
385 static inline void
386 delink_imm_use (ssa_use_operand_t *linknode)
387 {
388   /* Return if this node is not in a list.  */
389   if (linknode->prev == NULL)
390     return;
391
392   linknode->prev->next = linknode->next;
393   linknode->next->prev = linknode->prev;
394   linknode->prev = NULL;
395   linknode->next = NULL;
396 }
397
398 /* Link ssa_imm_use node LINKNODE into the chain for LIST.  */
399 static inline void
400 link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
401 {
402   /* Link the new node at the head of the list.  If we are in the process of 
403      traversing the list, we won't visit any new nodes added to it.  */
404   linknode->prev = list;
405   linknode->next = list->next;
406   list->next->prev = linknode;
407   list->next = linknode;
408 }
409
410 /* Link ssa_imm_use node LINKNODE into the chain for DEF.  */
411 static inline void
412 link_imm_use (ssa_use_operand_t *linknode, tree def)
413 {
414   ssa_use_operand_t *root;
415
416   if (!def || TREE_CODE (def) != SSA_NAME)
417     linknode->prev = NULL;
418   else
419     {
420       root = &(SSA_NAME_IMM_USE_NODE (def));
421 #ifdef ENABLE_CHECKING
422       if (linknode->use)
423         gcc_assert (*(linknode->use) == def);
424 #endif
425       link_imm_use_to_list (linknode, root);
426     }
427 }
428
429 /* Set the value of a use pointed to by USE to VAL.  */
430 static inline void
431 set_ssa_use_from_ptr (use_operand_p use, tree val)
432 {
433   delink_imm_use (use);
434   *(use->use) = val;
435   link_imm_use (use, val);
436 }
437
438 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring 
439    in STMT.  */
440 static inline void
441 link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, tree stmt)
442 {
443   if (stmt)
444     link_imm_use (linknode, def);
445   else
446     link_imm_use (linknode, NULL);
447   linknode->stmt = stmt;
448 }
449
450 /* Relink a new node in place of an old node in the list.  */
451 static inline void
452 relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
453 {
454   /* The node one had better be in the same list.  */
455   gcc_assert (*(old->use) == *(node->use));
456   node->prev = old->prev;
457   node->next = old->next;
458   if (old->prev)
459     {
460       old->prev->next = node;
461       old->next->prev = node;
462       /* Remove the old node from the list.  */
463       old->prev = NULL;
464     }
465 }
466
467 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring 
468    in STMT.  */
469 static inline void
470 relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old, tree stmt)
471 {
472   if (stmt)
473     relink_imm_use (linknode, old);
474   else
475     link_imm_use (linknode, NULL);
476   linknode->stmt = stmt;
477 }
478
479
480 /* Return true is IMM has reached the end of the immediate use list.  */
481 static inline bool
482 end_readonly_imm_use_p (imm_use_iterator *imm)
483 {
484   return (imm->imm_use == imm->end_p);
485 }
486
487 /* Initialize iterator IMM to process the list for VAR.  */
488 static inline use_operand_p
489 first_readonly_imm_use (imm_use_iterator *imm, tree var)
490 {
491   gcc_assert (TREE_CODE (var) == SSA_NAME);
492
493   imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
494   imm->imm_use = imm->end_p->next;
495 #ifdef ENABLE_CHECKING
496   imm->iter_node.next = imm->imm_use->next;
497 #endif
498   if (end_readonly_imm_use_p (imm))
499     return NULL_USE_OPERAND_P;
500   return imm->imm_use;
501 }
502
503 /* Bump IMM to the next use in the list.  */
504 static inline use_operand_p
505 next_readonly_imm_use (imm_use_iterator *imm)
506 {
507   use_operand_p old = imm->imm_use;
508
509 #ifdef ENABLE_CHECKING
510   /* If this assertion fails, it indicates the 'next' pointer has changed 
511      since we the last bump.  This indicates that the list is being modified
512      via stmt changes, or SET_USE, or somesuch thing, and you need to be
513      using the SAFE version of the iterator.  */
514   gcc_assert (imm->iter_node.next == old->next);
515   imm->iter_node.next = old->next->next;
516 #endif
517
518   imm->imm_use = old->next;
519   if (end_readonly_imm_use_p (imm))
520     return old;
521   return imm->imm_use;
522 }
523
524 /* Return true if VAR has no uses.  */
525 static inline bool
526 has_zero_uses (tree var)
527 {
528   ssa_use_operand_t *ptr;
529   ptr = &(SSA_NAME_IMM_USE_NODE (var));
530   /* A single use means there is no items in the list.  */
531   return (ptr == ptr->next);
532 }
533
534 /* Return true if VAR has a single use.  */
535 static inline bool
536 has_single_use (tree var)
537 {
538   ssa_use_operand_t *ptr;
539   ptr = &(SSA_NAME_IMM_USE_NODE (var));
540   /* A single use means there is one item in the list.  */
541   return (ptr != ptr->next && ptr == ptr->next->next);
542 }
543
544
545 /* If VAR has only a single immediate use, return true.  */
546 static inline bool
547 single_imm_use_p (tree var)
548 {
549   ssa_use_operand_t *ptr;
550
551   ptr = &(SSA_NAME_IMM_USE_NODE (var));
552   return (ptr != ptr->next && ptr == ptr->next->next);
553 }
554
555
556 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
557    to the use pointer and stmt of occurrence.  */
558 static inline bool
559 single_imm_use (tree var, use_operand_p *use_p, tree *stmt)
560 {
561   ssa_use_operand_t *ptr;
562
563   ptr = &(SSA_NAME_IMM_USE_NODE (var));
564   if (ptr != ptr->next && ptr == ptr->next->next)
565     {
566       *use_p = ptr->next;
567       *stmt = ptr->next->stmt;
568       return true;
569     }
570   *use_p = NULL_USE_OPERAND_P;
571   *stmt = NULL_TREE;
572   return false;
573 }
574
575 /* Return the number of immediate uses of VAR.  */
576 static inline unsigned int
577 num_imm_uses (tree var)
578 {
579   ssa_use_operand_t *ptr, *start;
580   unsigned int num;
581
582   start = &(SSA_NAME_IMM_USE_NODE (var));
583   num = 0;
584   for (ptr = start->next; ptr != start; ptr = ptr->next)
585      num++;
586
587   return num;
588 }
589
590
591 /* Return the tree pointer to by USE.  */ 
592 static inline tree
593 get_use_from_ptr (use_operand_p use)
594
595   return *(use->use);
596
597
598 /* Return the tree pointer to by DEF.  */
599 static inline tree
600 get_def_from_ptr (def_operand_p def)
601 {
602   return *def;
603 }
604
605 /* Return a def_operand_p pointer for the result of PHI.  */
606 static inline def_operand_p
607 get_phi_result_ptr (tree phi)
608 {
609   return &(PHI_RESULT_TREE (phi));
610 }
611
612 /* Return a use_operand_p pointer for argument I of phinode PHI.  */
613 static inline use_operand_p
614 get_phi_arg_def_ptr (tree phi, int i)
615 {
616   return &(PHI_ARG_IMM_USE_NODE (phi,i));
617 }
618
619
620 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
621    no addresses.  */
622 static inline bitmap
623 addresses_taken (tree stmt)
624 {
625   stmt_ann_t ann = stmt_ann (stmt);
626   return ann ? ann->addresses_taken : NULL;
627 }
628
629 /* Return the PHI nodes for basic block BB, or NULL if there are no
630    PHI nodes.  */
631 static inline tree
632 phi_nodes (basic_block bb)
633 {
634   return bb->phi_nodes;
635 }
636
637 /* Set list of phi nodes of a basic block BB to L.  */
638
639 static inline void
640 set_phi_nodes (basic_block bb, tree l)
641 {
642   tree phi;
643
644   bb->phi_nodes = l;
645   for (phi = l; phi; phi = PHI_CHAIN (phi))
646     set_bb_for_stmt (phi, bb);
647 }
648
649 /* Return the phi argument which contains the specified use.  */
650
651 static inline int
652 phi_arg_index_from_use (use_operand_p use)
653 {
654   struct phi_arg_d *element, *root;
655   int index;
656   tree phi;
657
658   /* Since the use is the first thing in a PHI argument element, we can
659      calculate its index based on casting it to an argument, and performing
660      pointer arithmetic.  */
661
662   phi = USE_STMT (use);
663   gcc_assert (TREE_CODE (phi) == PHI_NODE);
664
665   element = (struct phi_arg_d *)use;
666   root = &(PHI_ARG_ELT (phi, 0));
667   index = element - root;
668
669 #ifdef ENABLE_CHECKING
670   /* Make sure the calculation doesn't have any leftover bytes.  If it does, 
671      then imm_use is likely not the first element in phi_arg_d.  */
672   gcc_assert (
673           (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
674   gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
675 #endif
676  
677  return index;
678 }
679
680 /* Mark VAR as used, so that it'll be preserved during rtl expansion.  */
681
682 static inline void
683 set_is_used (tree var)
684 {
685   var_ann_t ann = get_var_ann (var);
686   ann->used = 1;
687 }
688
689
690 /*  -----------------------------------------------------------------------  */
691
692 /* Return true if T is an executable statement.  */
693 static inline bool
694 is_exec_stmt (tree t)
695 {
696   return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
697 }
698
699
700 /* Return true if this stmt can be the target of a control transfer stmt such
701    as a goto.  */
702 static inline bool
703 is_label_stmt (tree t)
704 {
705   if (t)
706     switch (TREE_CODE (t))
707       {
708         case LABEL_DECL:
709         case LABEL_EXPR:
710         case CASE_LABEL_EXPR:
711           return true;
712         default:
713           return false;
714       }
715   return false;
716 }
717
718 /* PHI nodes should contain only ssa_names and invariants.  A test
719    for ssa_name is definitely simpler; don't let invalid contents
720    slip in in the meantime.  */
721
722 static inline bool
723 phi_ssa_name_p (tree t)
724 {
725   if (TREE_CODE (t) == SSA_NAME)
726     return true;
727 #ifdef ENABLE_CHECKING
728   gcc_assert (is_gimple_min_invariant (t));
729 #endif
730   return false;
731 }
732
733 /*  -----------------------------------------------------------------------  */
734
735 /* Return a block_stmt_iterator that points to beginning of basic
736    block BB.  */
737 static inline block_stmt_iterator
738 bsi_start (basic_block bb)
739 {
740   block_stmt_iterator bsi;
741   if (bb->stmt_list)
742     bsi.tsi = tsi_start (bb->stmt_list);
743   else
744     {
745       gcc_assert (bb->index < NUM_FIXED_BLOCKS);
746       bsi.tsi.ptr = NULL;
747       bsi.tsi.container = NULL;
748     }
749   bsi.bb = bb;
750   return bsi;
751 }
752
753 /* Return a block statement iterator that points to the first non-label
754    statement in block BB.  */
755
756 static inline block_stmt_iterator
757 bsi_after_labels (basic_block bb)
758 {
759   block_stmt_iterator bsi = bsi_start (bb);
760
761   while (!bsi_end_p (bsi) && TREE_CODE (bsi_stmt (bsi)) == LABEL_EXPR)
762     bsi_next (&bsi);
763
764   return bsi;
765 }
766
767 /* Return a block statement iterator that points to the end of basic
768    block BB.  */
769 static inline block_stmt_iterator
770 bsi_last (basic_block bb)
771 {
772   block_stmt_iterator bsi;
773   if (bb->stmt_list)
774     bsi.tsi = tsi_last (bb->stmt_list);
775   else
776     {
777       gcc_assert (bb->index < NUM_FIXED_BLOCKS);
778       bsi.tsi.ptr = NULL;
779       bsi.tsi.container = NULL;
780     }
781   bsi.bb = bb;
782   return bsi;
783 }
784
785 /* Return true if block statement iterator I has reached the end of
786    the basic block.  */
787 static inline bool
788 bsi_end_p (block_stmt_iterator i)
789 {
790   return tsi_end_p (i.tsi);
791 }
792
793 /* Modify block statement iterator I so that it is at the next
794    statement in the basic block.  */
795 static inline void
796 bsi_next (block_stmt_iterator *i)
797 {
798   tsi_next (&i->tsi);
799 }
800
801 /* Modify block statement iterator I so that it is at the previous
802    statement in the basic block.  */
803 static inline void
804 bsi_prev (block_stmt_iterator *i)
805 {
806   tsi_prev (&i->tsi);
807 }
808
809 /* Return the statement that block statement iterator I is currently
810    at.  */
811 static inline tree
812 bsi_stmt (block_stmt_iterator i)
813 {
814   return tsi_stmt (i.tsi);
815 }
816
817 /* Return a pointer to the statement that block statement iterator I
818    is currently at.  */
819 static inline tree *
820 bsi_stmt_ptr (block_stmt_iterator i)
821 {
822   return tsi_stmt_ptr (i.tsi);
823 }
824
825 /* Returns the loop of the statement STMT.  */
826
827 static inline struct loop *
828 loop_containing_stmt (tree stmt)
829 {
830   basic_block bb = bb_for_stmt (stmt);
831   if (!bb)
832     return NULL;
833
834   return bb->loop_father;
835 }
836
837 /* Return true if VAR is a clobbered by function calls.  */
838 static inline bool
839 is_call_clobbered (tree var)
840 {
841   if (!MTAG_P (var))
842     return DECL_CALL_CLOBBERED (var);
843   else
844     return bitmap_bit_p (gimple_call_clobbered_vars (cfun), DECL_UID (var)); 
845 }
846
847 /* Mark variable VAR as being clobbered by function calls.  */
848 static inline void
849 mark_call_clobbered (tree var, unsigned int escape_type)
850 {
851   var_ann (var)->escape_mask |= escape_type;
852   if (!MTAG_P (var))
853     DECL_CALL_CLOBBERED (var) = true;
854   bitmap_set_bit (gimple_call_clobbered_vars (cfun), DECL_UID (var));
855 }
856
857 /* Clear the call-clobbered attribute from variable VAR.  */
858 static inline void
859 clear_call_clobbered (tree var)
860 {
861   var_ann_t ann = var_ann (var);
862   ann->escape_mask = 0;
863   if (MTAG_P (var) && TREE_CODE (var) != STRUCT_FIELD_TAG)
864     MTAG_GLOBAL (var) = 0;
865   if (!MTAG_P (var))
866     DECL_CALL_CLOBBERED (var) = false;
867   bitmap_clear_bit (gimple_call_clobbered_vars (cfun), DECL_UID (var));
868 }
869
870 /* Mark variable VAR as being non-addressable.  */
871 static inline void
872 mark_non_addressable (tree var)
873 {
874   if (!MTAG_P (var))
875     DECL_CALL_CLOBBERED (var) = false;
876   bitmap_clear_bit (gimple_call_clobbered_vars (cfun), DECL_UID (var));
877   TREE_ADDRESSABLE (var) = 0;
878 }
879
880 /* Return the common annotation for T.  Return NULL if the annotation
881    doesn't already exist.  */
882 static inline tree_ann_common_t
883 tree_common_ann (tree t)
884 {
885   return &t->base.ann->common;
886 }
887
888 /* Return a common annotation for T.  Create the constant annotation if it
889    doesn't exist.  */
890 static inline tree_ann_common_t
891 get_tree_common_ann (tree t)
892 {
893   tree_ann_common_t ann = tree_common_ann (t);
894   return (ann) ? ann : create_tree_common_ann (t);
895 }
896
897 /*  -----------------------------------------------------------------------  */
898
899 /* The following set of routines are used to iterator over various type of
900    SSA operands.  */
901
902 /* Return true if PTR is finished iterating.  */
903 static inline bool
904 op_iter_done (ssa_op_iter *ptr)
905 {
906   return ptr->done;
907 }
908
909 /* Get the next iterator use value for PTR.  */
910 static inline use_operand_p
911 op_iter_next_use (ssa_op_iter *ptr)
912 {
913   use_operand_p use_p;
914 #ifdef ENABLE_CHECKING
915   gcc_assert (ptr->iter_type == ssa_op_iter_use);
916 #endif
917   if (ptr->uses)
918     {
919       use_p = USE_OP_PTR (ptr->uses);
920       ptr->uses = ptr->uses->next;
921       return use_p;
922     }
923   if (ptr->vuses)
924     {
925       use_p = VUSE_OP_PTR (ptr->vuses);
926       ptr->vuses = ptr->vuses->next;
927       return use_p;
928     }
929   if (ptr->mayuses)
930     {
931       use_p = MAYDEF_OP_PTR (ptr->mayuses);
932       ptr->mayuses = ptr->mayuses->next;
933       return use_p;
934     }
935   if (ptr->mustkills)
936     {
937       use_p = MUSTDEF_KILL_PTR (ptr->mustkills);
938       ptr->mustkills = ptr->mustkills->next;
939       return use_p;
940     }
941   if (ptr->phi_i < ptr->num_phi)
942     {
943       return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
944     }
945   ptr->done = true;
946   return NULL_USE_OPERAND_P;
947 }
948
949 /* Get the next iterator def value for PTR.  */
950 static inline def_operand_p
951 op_iter_next_def (ssa_op_iter *ptr)
952 {
953   def_operand_p def_p;
954 #ifdef ENABLE_CHECKING
955   gcc_assert (ptr->iter_type == ssa_op_iter_def);
956 #endif
957   if (ptr->defs)
958     {
959       def_p = DEF_OP_PTR (ptr->defs);
960       ptr->defs = ptr->defs->next;
961       return def_p;
962     }
963   if (ptr->mustdefs)
964     {
965       def_p = MUSTDEF_RESULT_PTR (ptr->mustdefs);
966       ptr->mustdefs = ptr->mustdefs->next;
967       return def_p;
968     }
969   if (ptr->maydefs)
970     {
971       def_p = MAYDEF_RESULT_PTR (ptr->maydefs);
972       ptr->maydefs = ptr->maydefs->next;
973       return def_p;
974     }
975   ptr->done = true;
976   return NULL_DEF_OPERAND_P;
977 }
978
979 /* Get the next iterator tree value for PTR.  */
980 static inline tree
981 op_iter_next_tree (ssa_op_iter *ptr)
982 {
983   tree val;
984 #ifdef ENABLE_CHECKING
985   gcc_assert (ptr->iter_type == ssa_op_iter_tree);
986 #endif
987   if (ptr->uses)
988     {
989       val = USE_OP (ptr->uses);
990       ptr->uses = ptr->uses->next;
991       return val;
992     }
993   if (ptr->vuses)
994     {
995       val = VUSE_OP (ptr->vuses);
996       ptr->vuses = ptr->vuses->next;
997       return val;
998     }
999   if (ptr->mayuses)
1000     {
1001       val = MAYDEF_OP (ptr->mayuses);
1002       ptr->mayuses = ptr->mayuses->next;
1003       return val;
1004     }
1005   if (ptr->mustkills)
1006     {
1007       val = MUSTDEF_KILL (ptr->mustkills);
1008       ptr->mustkills = ptr->mustkills->next;
1009       return val;
1010     }
1011   if (ptr->defs)
1012     {
1013       val = DEF_OP (ptr->defs);
1014       ptr->defs = ptr->defs->next;
1015       return val;
1016     }
1017   if (ptr->mustdefs)
1018     {
1019       val = MUSTDEF_RESULT (ptr->mustdefs);
1020       ptr->mustdefs = ptr->mustdefs->next;
1021       return val;
1022     }
1023   if (ptr->maydefs)
1024     {
1025       val = MAYDEF_RESULT (ptr->maydefs);
1026       ptr->maydefs = ptr->maydefs->next;
1027       return val;
1028     }
1029
1030   ptr->done = true;
1031   return NULL_TREE;
1032
1033 }
1034
1035
1036 /* This functions clears the iterator PTR, and marks it done.  This is normally
1037    used to prevent warnings in the compile about might be uninitialized
1038    components.  */
1039
1040 static inline void
1041 clear_and_done_ssa_iter (ssa_op_iter *ptr)
1042 {
1043   ptr->defs = NULL;
1044   ptr->uses = NULL;
1045   ptr->vuses = NULL;
1046   ptr->maydefs = NULL;
1047   ptr->mayuses = NULL;
1048   ptr->mustdefs = NULL;
1049   ptr->mustkills = NULL;
1050   ptr->iter_type = ssa_op_iter_none;
1051   ptr->phi_i = 0;
1052   ptr->num_phi = 0;
1053   ptr->phi_stmt = NULL_TREE;
1054   ptr->done = true;
1055 }
1056
1057 /* Initialize the iterator PTR to the virtual defs in STMT.  */
1058 static inline void
1059 op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
1060 {
1061 #ifdef ENABLE_CHECKING
1062   gcc_assert (stmt_ann (stmt));
1063 #endif
1064
1065   ptr->defs = (flags & SSA_OP_DEF) ? DEF_OPS (stmt) : NULL;
1066   ptr->uses = (flags & SSA_OP_USE) ? USE_OPS (stmt) : NULL;
1067   ptr->vuses = (flags & SSA_OP_VUSE) ? VUSE_OPS (stmt) : NULL;
1068   ptr->maydefs = (flags & SSA_OP_VMAYDEF) ? MAYDEF_OPS (stmt) : NULL;
1069   ptr->mayuses = (flags & SSA_OP_VMAYUSE) ? MAYDEF_OPS (stmt) : NULL;
1070   ptr->mustdefs = (flags & SSA_OP_VMUSTDEF) ? MUSTDEF_OPS (stmt) : NULL;
1071   ptr->mustkills = (flags & SSA_OP_VMUSTKILL) ? MUSTDEF_OPS (stmt) : NULL;
1072   ptr->done = false;
1073
1074   ptr->phi_i = 0;
1075   ptr->num_phi = 0;
1076   ptr->phi_stmt = NULL_TREE;
1077 }
1078
1079 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1080    the first use.  */
1081 static inline use_operand_p
1082 op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
1083 {
1084   gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0);
1085   op_iter_init (ptr, stmt, flags);
1086   ptr->iter_type = ssa_op_iter_use;
1087   return op_iter_next_use (ptr);
1088 }
1089
1090 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1091    the first def.  */
1092 static inline def_operand_p
1093 op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1094 {
1095   gcc_assert ((flags & (SSA_OP_ALL_USES | SSA_OP_VIRTUAL_KILLS)) == 0);
1096   op_iter_init (ptr, stmt, flags);
1097   ptr->iter_type = ssa_op_iter_def;
1098   return op_iter_next_def (ptr);
1099 }
1100
1101 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1102    the first operand as a tree.  */
1103 static inline tree
1104 op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1105 {
1106   op_iter_init (ptr, stmt, flags);
1107   ptr->iter_type = ssa_op_iter_tree;
1108   return op_iter_next_tree (ptr);
1109 }
1110
1111 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1112    KILL and DEF.  */
1113 static inline void
1114 op_iter_next_maymustdef (use_operand_p *use, def_operand_p *def, 
1115                          ssa_op_iter *ptr)
1116 {
1117 #ifdef ENABLE_CHECKING
1118   gcc_assert (ptr->iter_type == ssa_op_iter_maymustdef);
1119 #endif
1120   if (ptr->mayuses)
1121     {
1122       *def = MAYDEF_RESULT_PTR (ptr->mayuses);
1123       *use = MAYDEF_OP_PTR (ptr->mayuses);
1124       ptr->mayuses = ptr->mayuses->next;
1125       return;
1126     }
1127
1128   if (ptr->mustkills)
1129     {
1130       *def = MUSTDEF_RESULT_PTR (ptr->mustkills);
1131       *use = MUSTDEF_KILL_PTR (ptr->mustkills);
1132       ptr->mustkills = ptr->mustkills->next;
1133       return;
1134     }
1135
1136   *def = NULL_DEF_OPERAND_P;
1137   *use = NULL_USE_OPERAND_P;
1138   ptr->done = true;
1139   return;
1140 }
1141
1142
1143 /* Initialize iterator PTR to the operands in STMT.  Return the first operands
1144    in USE and DEF.  */
1145 static inline void
1146 op_iter_init_maydef (ssa_op_iter *ptr, tree stmt, use_operand_p *use, 
1147                      def_operand_p *def)
1148 {
1149   gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1150
1151   op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1152   ptr->iter_type = ssa_op_iter_maymustdef;
1153   op_iter_next_maymustdef (use, def, ptr);
1154 }
1155
1156
1157 /* Initialize iterator PTR to the operands in STMT.  Return the first operands
1158    in KILL and DEF.  */
1159 static inline void
1160 op_iter_init_mustdef (ssa_op_iter *ptr, tree stmt, use_operand_p *kill, 
1161                      def_operand_p *def)
1162 {
1163   gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1164
1165   op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL);
1166   ptr->iter_type = ssa_op_iter_maymustdef;
1167   op_iter_next_maymustdef (kill, def, ptr);
1168 }
1169
1170 /* Initialize iterator PTR to the operands in STMT.  Return the first operands
1171    in KILL and DEF.  */
1172 static inline void
1173 op_iter_init_must_and_may_def (ssa_op_iter *ptr, tree stmt,
1174                                use_operand_p *kill, def_operand_p *def)
1175 {
1176   gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1177
1178   op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL|SSA_OP_VMAYUSE);
1179   ptr->iter_type = ssa_op_iter_maymustdef;
1180   op_iter_next_maymustdef (kill, def, ptr);
1181 }
1182
1183
1184 /* If there is a single operand in STMT matching FLAGS, return it.  Otherwise
1185    return NULL.  */
1186 static inline tree
1187 single_ssa_tree_operand (tree stmt, int flags)
1188 {
1189   tree var;
1190   ssa_op_iter iter;
1191
1192   var = op_iter_init_tree (&iter, stmt, flags);
1193   if (op_iter_done (&iter))
1194     return NULL_TREE;
1195   op_iter_next_tree (&iter);
1196   if (op_iter_done (&iter))
1197     return var;
1198   return NULL_TREE;
1199 }
1200
1201
1202 /* If there is a single operand in STMT matching FLAGS, return it.  Otherwise
1203    return NULL.  */
1204 static inline use_operand_p
1205 single_ssa_use_operand (tree stmt, int flags)
1206 {
1207   use_operand_p var;
1208   ssa_op_iter iter;
1209
1210   var = op_iter_init_use (&iter, stmt, flags);
1211   if (op_iter_done (&iter))
1212     return NULL_USE_OPERAND_P;
1213   op_iter_next_use (&iter);
1214   if (op_iter_done (&iter))
1215     return var;
1216   return NULL_USE_OPERAND_P;
1217 }
1218
1219
1220
1221 /* If there is a single operand in STMT matching FLAGS, return it.  Otherwise
1222    return NULL.  */
1223 static inline def_operand_p
1224 single_ssa_def_operand (tree stmt, int flags)
1225 {
1226   def_operand_p var;
1227   ssa_op_iter iter;
1228
1229   var = op_iter_init_def (&iter, stmt, flags);
1230   if (op_iter_done (&iter))
1231     return NULL_DEF_OPERAND_P;
1232   op_iter_next_def (&iter);
1233   if (op_iter_done (&iter))
1234     return var;
1235   return NULL_DEF_OPERAND_P;
1236 }
1237
1238
1239 /* Return true if there are zero operands in STMT matching the type 
1240    given in FLAGS.  */
1241 static inline bool
1242 zero_ssa_operands (tree stmt, int flags)
1243 {
1244   ssa_op_iter iter;
1245
1246   op_iter_init_tree (&iter, stmt, flags);
1247   return op_iter_done (&iter);
1248 }
1249
1250
1251 /* Return the number of operands matching FLAGS in STMT.  */
1252 static inline int
1253 num_ssa_operands (tree stmt, int flags)
1254 {
1255   ssa_op_iter iter;
1256   tree t;
1257   int num = 0;
1258
1259   FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
1260     num++;
1261   return num;
1262 }
1263
1264
1265 /* Delink all immediate_use information for STMT.  */
1266 static inline void
1267 delink_stmt_imm_use (tree stmt)
1268 {
1269    ssa_op_iter iter;
1270    use_operand_p use_p;
1271
1272    if (ssa_operands_active ())
1273      FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter,
1274                                (SSA_OP_ALL_USES | SSA_OP_ALL_KILLS))
1275        delink_imm_use (use_p);
1276 }
1277
1278
1279 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1280    in STMT2.  TRUE is returned if they are the same.  STMTs can be NULL.  */
1281 static inline bool
1282 compare_ssa_operands_equal (tree stmt1, tree stmt2, int flags)
1283 {
1284   ssa_op_iter iter1, iter2;
1285   tree op1 = NULL_TREE;
1286   tree op2 = NULL_TREE;
1287   bool look1, look2;
1288
1289   if (stmt1 == stmt2)
1290     return true;
1291
1292   look1 = stmt1 && stmt_ann (stmt1);
1293   look2 = stmt2 && stmt_ann (stmt2);
1294
1295   if (look1)
1296     {
1297       op1 = op_iter_init_tree (&iter1, stmt1, flags);
1298       if (!look2)
1299         return op_iter_done (&iter1);
1300     }
1301   else
1302     clear_and_done_ssa_iter (&iter1);
1303
1304   if (look2)
1305     {
1306       op2 = op_iter_init_tree (&iter2, stmt2, flags);
1307       if (!look1)
1308         return op_iter_done (&iter2);
1309     }
1310   else
1311     clear_and_done_ssa_iter (&iter2);
1312
1313   while (!op_iter_done (&iter1) && !op_iter_done (&iter2))
1314     {
1315       if (op1 != op2)
1316         return false;
1317       op1 = op_iter_next_tree (&iter1);
1318       op2 = op_iter_next_tree (&iter2);
1319     }
1320
1321   return (op_iter_done (&iter1) && op_iter_done (&iter2));
1322 }
1323
1324
1325 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1326    Otherwise return NULL_DEF_OPERAND_P.  */
1327 static inline tree
1328 single_phi_def (tree stmt, int flags)
1329 {
1330   tree def = PHI_RESULT (stmt);
1331   if ((flags & SSA_OP_DEF) && is_gimple_reg (def)) 
1332     return def;
1333   if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
1334     return def;
1335   return NULL_TREE;
1336 }
1337
1338 /* Initialize the iterator PTR for uses matching FLAGS in PHI.  FLAGS should
1339    be either SSA_OP_USES or SSA_OP_VIRTUAL_USES.  */
1340 static inline use_operand_p
1341 op_iter_init_phiuse (ssa_op_iter *ptr, tree phi, int flags)
1342 {
1343   tree phi_def = PHI_RESULT (phi);
1344   int comp;
1345
1346   clear_and_done_ssa_iter (ptr);
1347   ptr->done = false;
1348
1349   gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
1350
1351   comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1352     
1353   /* If the PHI node doesn't the operand type we care about, we're done.  */
1354   if ((flags & comp) == 0)
1355     {
1356       ptr->done = true;
1357       return NULL_USE_OPERAND_P;
1358     }
1359
1360   ptr->phi_stmt = phi;
1361   ptr->num_phi = PHI_NUM_ARGS (phi);
1362   ptr->iter_type = ssa_op_iter_use;
1363   return op_iter_next_use (ptr);
1364 }
1365
1366
1367 /* Start an iterator for a PHI definition.  */
1368
1369 static inline def_operand_p
1370 op_iter_init_phidef (ssa_op_iter *ptr, tree phi, int flags)
1371 {
1372   tree phi_def = PHI_RESULT (phi);
1373   int comp;
1374
1375   clear_and_done_ssa_iter (ptr);
1376   ptr->done = false;
1377
1378   gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
1379
1380   comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
1381     
1382   /* If the PHI node doesn't the operand type we care about, we're done.  */
1383   if ((flags & comp) == 0)
1384     {
1385       ptr->done = true;
1386       return NULL_USE_OPERAND_P;
1387     }
1388
1389   ptr->iter_type = ssa_op_iter_def;
1390   /* The first call to op_iter_next_def will terminate the iterator since
1391      all the fields are NULL.  Simply return the result here as the first and
1392      therefore only result.  */
1393   return PHI_RESULT_PTR (phi);
1394 }
1395
1396 /* Return true is IMM has reached the end of the immediate use stmt list.  */
1397
1398 static inline bool
1399 end_imm_use_stmt_p (imm_use_iterator *imm)
1400 {
1401   return (imm->imm_use == imm->end_p);
1402 }
1403
1404 /* Finished the traverse of an immediate use stmt list IMM by removing the
1405    placeholder node from the list.  */
1406
1407 static inline void
1408 end_imm_use_stmt_traverse (imm_use_iterator *imm)
1409 {
1410   delink_imm_use (&(imm->iter_node));
1411 }
1412
1413 /* Immediate use traversal of uses within a stmt require that all the
1414    uses on a stmt be sequentially listed.  This routine is used to build up
1415    this sequential list by adding USE_P to the end of the current list 
1416    currently delimited by HEAD and LAST_P.  The new LAST_P value is 
1417    returned.  */
1418
1419 static inline use_operand_p
1420 move_use_after_head (use_operand_p use_p, use_operand_p head, 
1421                       use_operand_p last_p)
1422 {
1423   gcc_assert (USE_FROM_PTR (use_p) == USE_FROM_PTR (head));
1424   /* Skip head when we find it.  */
1425   if (use_p != head)
1426     {
1427       /* If use_p is already linked in after last_p, continue.  */
1428       if (last_p->next == use_p)
1429         last_p = use_p;
1430       else
1431         {
1432           /* Delink from current location, and link in at last_p.  */
1433           delink_imm_use (use_p);
1434           link_imm_use_to_list (use_p, last_p);
1435           last_p = use_p;
1436         }
1437     }
1438   return last_p;
1439 }
1440
1441
1442 /* This routine will relink all uses with the same stmt as HEAD into the list
1443    immediately following HEAD for iterator IMM.  */
1444
1445 static inline void
1446 link_use_stmts_after (use_operand_p head, imm_use_iterator *imm)
1447 {
1448   use_operand_p use_p;
1449   use_operand_p last_p = head;
1450   tree head_stmt = USE_STMT (head);
1451   tree use = USE_FROM_PTR (head);
1452   ssa_op_iter op_iter;
1453   int flag;
1454
1455   /* Only look at virtual or real uses, depending on the type of HEAD.  */
1456   flag = (is_gimple_reg (use) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1457
1458   if (TREE_CODE (head_stmt) == PHI_NODE)
1459     {
1460       FOR_EACH_PHI_ARG (use_p, head_stmt, op_iter, flag)
1461         if (USE_FROM_PTR (use_p) == use)
1462           last_p = move_use_after_head (use_p, head, last_p);
1463     }
1464   else
1465     {
1466       FOR_EACH_SSA_USE_OPERAND (use_p, head_stmt, op_iter, flag)
1467         if (USE_FROM_PTR (use_p) == use)
1468           last_p = move_use_after_head (use_p, head, last_p);
1469     }
1470   /* LInk iter node in after last_p.  */
1471   if (imm->iter_node.prev != NULL)
1472     delink_imm_use (&imm->iter_node);
1473   link_imm_use_to_list (&(imm->iter_node), last_p);
1474 }
1475
1476 /* Initialize IMM to traverse over uses of VAR.  Return the first statement.  */
1477 static inline tree
1478 first_imm_use_stmt (imm_use_iterator *imm, tree var)
1479 {
1480   gcc_assert (TREE_CODE (var) == SSA_NAME);
1481   
1482   imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
1483   imm->imm_use = imm->end_p->next;
1484   imm->next_imm_name = NULL_USE_OPERAND_P;
1485
1486   /* iter_node is used as a marker within the immediate use list to indicate
1487      where the end of the current stmt's uses are.  Initialize it to NULL
1488      stmt and use, which indicates a marker node.  */
1489   imm->iter_node.prev = NULL_USE_OPERAND_P;
1490   imm->iter_node.next = NULL_USE_OPERAND_P;
1491   imm->iter_node.stmt = NULL_TREE;
1492   imm->iter_node.use = NULL_USE_OPERAND_P;
1493
1494   if (end_imm_use_stmt_p (imm))
1495     return NULL_TREE;
1496
1497   link_use_stmts_after (imm->imm_use, imm);
1498
1499   return USE_STMT (imm->imm_use);
1500 }
1501
1502 /* Bump IMM to the next stmt which has a use of var.  */
1503
1504 static inline tree
1505 next_imm_use_stmt (imm_use_iterator *imm)
1506 {
1507   imm->imm_use = imm->iter_node.next;
1508   if (end_imm_use_stmt_p (imm))
1509     {
1510       if (imm->iter_node.prev != NULL)
1511         delink_imm_use (&imm->iter_node);
1512       return NULL_TREE;
1513     }
1514
1515   link_use_stmts_after (imm->imm_use, imm);
1516   return USE_STMT (imm->imm_use);
1517
1518 }
1519
1520 /* This routine will return the first use on the stmt IMM currently refers
1521    to.  */
1522
1523 static inline use_operand_p
1524 first_imm_use_on_stmt (imm_use_iterator *imm)
1525 {
1526   imm->next_imm_name = imm->imm_use->next;
1527   return imm->imm_use;
1528 }
1529
1530 /*  Return TRUE if the last use on the stmt IMM refers to has been visited.  */
1531
1532 static inline bool
1533 end_imm_use_on_stmt_p (imm_use_iterator *imm)
1534 {
1535   return (imm->imm_use == &(imm->iter_node));
1536 }
1537
1538 /* Bump to the next use on the stmt IMM refers to, return NULL if done.  */
1539
1540 static inline use_operand_p
1541 next_imm_use_on_stmt (imm_use_iterator *imm)
1542 {
1543   imm->imm_use = imm->next_imm_name;
1544   if (end_imm_use_on_stmt_p (imm))
1545     return NULL_USE_OPERAND_P;
1546   else
1547     {
1548       imm->next_imm_name = imm->imm_use->next;
1549       return imm->imm_use;
1550     }
1551 }
1552
1553 /* Return true if VAR cannot be modified by the program.  */
1554
1555 static inline bool
1556 unmodifiable_var_p (tree var)
1557 {
1558   if (TREE_CODE (var) == SSA_NAME)
1559     var = SSA_NAME_VAR (var);
1560
1561   if (MTAG_P (var))
1562     return TREE_READONLY (var) && (TREE_STATIC (var) || MTAG_GLOBAL (var));
1563
1564   return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1565 }
1566
1567 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it.  */
1568
1569 static inline bool
1570 array_ref_contains_indirect_ref (tree ref)
1571 {
1572   gcc_assert (TREE_CODE (ref) == ARRAY_REF);
1573
1574   do {
1575     ref = TREE_OPERAND (ref, 0);
1576   } while (handled_component_p (ref));
1577
1578   return TREE_CODE (ref) == INDIRECT_REF;
1579 }
1580
1581 /* Return true if REF, a handled component reference, has an ARRAY_REF
1582    somewhere in it.  */
1583
1584 static inline bool
1585 ref_contains_array_ref (tree ref)
1586 {
1587   gcc_assert (handled_component_p (ref));
1588
1589   do {
1590     if (TREE_CODE (ref) == ARRAY_REF)
1591       return true;
1592     ref = TREE_OPERAND (ref, 0);
1593   } while (handled_component_p (ref));
1594
1595   return false;
1596 }
1597
1598 /* Given a variable VAR, lookup and return a pointer to the list of
1599    subvariables for it.  */
1600
1601 static inline subvar_t *
1602 lookup_subvars_for_var (tree var)
1603 {
1604   var_ann_t ann = var_ann (var);
1605   gcc_assert (ann);
1606   return &ann->subvars;
1607 }
1608
1609 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1610    NULL, if there are no subvariables.  */
1611
1612 static inline subvar_t
1613 get_subvars_for_var (tree var)
1614 {
1615   subvar_t subvars;
1616
1617   gcc_assert (SSA_VAR_P (var));  
1618   
1619   if (TREE_CODE (var) == SSA_NAME)
1620     subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
1621   else
1622     subvars = *(lookup_subvars_for_var (var));
1623   return subvars;
1624 }
1625
1626 /* Return the subvariable of VAR at offset OFFSET.  */
1627
1628 static inline tree
1629 get_subvar_at (tree var, unsigned HOST_WIDE_INT offset)
1630 {
1631   subvar_t sv;
1632
1633   for (sv = get_subvars_for_var (var); sv; sv = sv->next)
1634     if (SFT_OFFSET (sv->var) == offset)
1635       return sv->var;
1636
1637   return NULL_TREE;
1638 }
1639
1640 /* Return true if V is a tree that we can have subvars for.
1641    Normally, this is any aggregate type.  Also complex
1642    types which are not gimple registers can have subvars.  */
1643
1644 static inline bool
1645 var_can_have_subvars (tree v)
1646 {
1647   /* Volatile variables should never have subvars.  */
1648   if (TREE_THIS_VOLATILE (v))
1649     return false;
1650
1651   /* Non decls or memory tags can never have subvars.  */
1652   if (!DECL_P (v) || MTAG_P (v))
1653     return false;
1654
1655   /* Aggregates can have subvars.  */
1656   if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
1657     return true;
1658
1659   /* Complex types variables which are not also a gimple register can
1660     have subvars. */
1661   if (TREE_CODE (TREE_TYPE (v)) == COMPLEX_TYPE
1662       && !DECL_COMPLEX_GIMPLE_REG_P (v))
1663     return true;
1664
1665   return false;
1666 }
1667
1668   
1669 /* Return true if OFFSET and SIZE define a range that overlaps with some
1670    portion of the range of SV, a subvar.  If there was an exact overlap,
1671    *EXACT will be set to true upon return. */
1672
1673 static inline bool
1674 overlap_subvar (unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT size,
1675                 tree sv,  bool *exact)
1676 {
1677   /* There are three possible cases of overlap.
1678      1. We can have an exact overlap, like so:   
1679      |offset, offset + size             |
1680      |sv->offset, sv->offset + sv->size |
1681      
1682      2. We can have offset starting after sv->offset, like so:
1683      
1684            |offset, offset + size              |
1685      |sv->offset, sv->offset + sv->size  |
1686
1687      3. We can have offset starting before sv->offset, like so:
1688      
1689      |offset, offset + size    |
1690        |sv->offset, sv->offset + sv->size|
1691   */
1692
1693   if (exact)
1694     *exact = false;
1695   if (offset == SFT_OFFSET (sv) && size == SFT_SIZE (sv))
1696     {
1697       if (exact)
1698         *exact = true;
1699       return true;
1700     }
1701   else if (offset >= SFT_OFFSET (sv) 
1702            && offset < (SFT_OFFSET (sv) + SFT_SIZE (sv)))
1703     {
1704       return true;
1705     }
1706   else if (offset < SFT_OFFSET (sv) 
1707            && (size > SFT_OFFSET (sv) - offset))
1708     {
1709       return true;
1710     }
1711   return false;
1712
1713 }
1714
1715 /* Get the value handle of EXPR.  This is the only correct way to get
1716    the value handle for a "thing".  If EXPR does not have a value
1717    handle associated, it returns NULL_TREE.  
1718    NB: If EXPR is min_invariant, this function is *required* to return
1719    EXPR.  */
1720
1721 static inline tree
1722 get_value_handle (tree expr)
1723 {
1724   if (TREE_CODE (expr) == SSA_NAME)
1725     return SSA_NAME_VALUE (expr);
1726   else if (DECL_P (expr) || TREE_CODE (expr) == TREE_LIST
1727            || TREE_CODE (expr) == CONSTRUCTOR)
1728     {
1729       tree_ann_common_t ann = tree_common_ann (expr);
1730       return ((ann) ? ann->value_handle : NULL_TREE);
1731     }
1732   else if (is_gimple_min_invariant (expr))
1733     return expr;
1734   else if (EXPR_P (expr))
1735     {
1736       tree_ann_common_t ann = tree_common_ann (expr);
1737       return ((ann) ? ann->value_handle : NULL_TREE);
1738     }
1739   else
1740     gcc_unreachable ();
1741 }
1742
1743 /* Accessor to tree-ssa-operands.c caches.  */
1744 static inline struct ssa_operands *
1745 gimple_ssa_operands (struct function *fun)
1746 {
1747   return &fun->gimple_df->ssa_operands;
1748 }
1749 #endif /* _TREE_FLOW_INLINE_H  */