OSDN Git Service

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