OSDN Git Service

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