OSDN Git Service

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