OSDN Git Service

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