OSDN Git Service

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