OSDN Git Service

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