OSDN Git Service

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