OSDN Git Service

* basic-block.h (basic_block_def): Add phi_nodes and
[pf3gnuchains/gcc-fork.git] / gcc / tree-flow-inline.h
1 /* Inline functions for tree-flow.h
2    Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc.
3    Contributed by Diego Novillo <dnovillo@redhat.com>
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 #ifndef _TREE_FLOW_INLINE_H
23 #define _TREE_FLOW_INLINE_H 1
24
25 /* Inline functions for manipulating various data structures defined in
26    tree-flow.h.  See tree-flow.h for documentation.  */
27
28 /* Return the variable annotation for T, which must be a _DECL node.
29    Return NULL if the variable annotation doesn't already exist.  */
30 static inline var_ann_t
31 var_ann (tree t)
32 {
33   gcc_assert (t);
34   gcc_assert (DECL_P (t));
35   gcc_assert (!t->common.ann || t->common.ann->common.type == VAR_ANN);
36
37   return (var_ann_t) t->common.ann;
38 }
39
40 /* Return the variable annotation for T, which must be a _DECL node.
41    Create the variable annotation if it doesn't exist.  */
42 static inline var_ann_t
43 get_var_ann (tree var)
44 {
45   var_ann_t ann = var_ann (var);
46   return (ann) ? ann : create_var_ann (var);
47 }
48
49 /* Return the statement annotation for T, which must be a statement
50    node.  Return NULL if the statement annotation doesn't exist.  */
51 static inline stmt_ann_t
52 stmt_ann (tree t)
53 {
54 #ifdef ENABLE_CHECKING
55   gcc_assert (is_gimple_stmt (t));
56 #endif
57   return (stmt_ann_t) t->common.ann;
58 }
59
60 /* Return the statement annotation for T, which must be a statement
61    node.  Create the statement annotation if it doesn't exist.  */
62 static inline stmt_ann_t
63 get_stmt_ann (tree stmt)
64 {
65   stmt_ann_t ann = stmt_ann (stmt);
66   return (ann) ? ann : create_stmt_ann (stmt);
67 }
68
69
70 /* Return the annotation type for annotation ANN.  */
71 static inline enum tree_ann_type
72 ann_type (tree_ann_t ann)
73 {
74   return ann->common.type;
75 }
76
77 /* Return the basic block for statement T.  */
78 static inline basic_block
79 bb_for_stmt (tree t)
80 {
81   stmt_ann_t ann;
82
83   if (TREE_CODE (t) == PHI_NODE)
84     return PHI_BB (t);
85
86   ann = stmt_ann (t);
87   return ann ? ann->bb : NULL;
88 }
89
90 /* Return the may_aliases varray for variable VAR, or NULL if it has
91    no may aliases.  */
92 static inline varray_type
93 may_aliases (tree var)
94 {
95   var_ann_t ann = var_ann (var);
96   return ann ? ann->may_aliases : NULL;
97 }
98
99 /* Return the line number for EXPR, or return -1 if we have no line
100    number information for it.  */
101 static inline int
102 get_lineno (tree expr)
103 {
104   if (expr == NULL_TREE)
105     return -1;
106
107   if (TREE_CODE (expr) == COMPOUND_EXPR)
108     expr = TREE_OPERAND (expr, 0);
109
110   if (! EXPR_HAS_LOCATION (expr))
111     return -1;
112
113   return EXPR_LINENO (expr);
114 }
115
116 /* Return the file name for EXPR, or return "???" if we have no
117    filename information.  */
118 static inline const char *
119 get_filename (tree expr)
120 {
121   const char *filename;
122   if (expr == NULL_TREE)
123     return "???";
124
125   if (TREE_CODE (expr) == COMPOUND_EXPR)
126     expr = TREE_OPERAND (expr, 0);
127
128   if (EXPR_HAS_LOCATION (expr) && (filename = EXPR_FILENAME (expr)))
129     return filename;
130   else
131     return "???";
132 }
133
134 /* Return true if T is a noreturn call.  */
135 static inline bool
136 noreturn_call_p (tree t)
137 {
138   tree call = get_call_expr_in (t);
139   return call != 0 && (call_expr_flags (call) & ECF_NORETURN) != 0;
140 }
141
142 /* Mark statement T as modified.  */
143 static inline void
144 mark_stmt_modified (tree t)
145 {
146   stmt_ann_t ann;
147   if (TREE_CODE (t) == PHI_NODE)
148     return;
149
150   ann = stmt_ann (t);
151   if (ann == NULL)
152     ann = create_stmt_ann (t);
153   else if (noreturn_call_p (t))
154     VEC_safe_push (tree, gc, modified_noreturn_calls, t);
155   ann->modified = 1;
156 }
157
158 /* Mark statement T as modified, and update it.  */
159 static inline void
160 update_stmt (tree t)
161 {
162   if (TREE_CODE (t) == PHI_NODE)
163     return;
164   mark_stmt_modified (t);
165   update_stmt_operands (t);
166 }
167
168 static inline void
169 update_stmt_if_modified (tree t)
170 {
171   if (stmt_modified_p (t))
172     update_stmt_operands (t);
173 }
174
175 /* Return true if T is marked as modified, false otherwise.  */
176 static inline bool
177 stmt_modified_p (tree t)
178 {
179   stmt_ann_t ann = stmt_ann (t);
180
181   /* Note that if the statement doesn't yet have an annotation, we consider it
182      modified.  This will force the next call to update_stmt_operands to scan 
183      the statement.  */
184   return ann ? ann->modified : true;
185 }
186
187 /* Delink an immediate_uses node from its chain.  */
188 static inline void
189 delink_imm_use (ssa_use_operand_t *linknode)
190 {
191   /* Return if this node is not in a list.  */
192   if (linknode->prev == NULL)
193     return;
194
195   linknode->prev->next = linknode->next;
196   linknode->next->prev = linknode->prev;
197   linknode->prev = NULL;
198   linknode->next = NULL;
199 }
200
201 /* Link ssa_imm_use node LINKNODE into the chain for LIST.  */
202 static inline void
203 link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
204 {
205   /* Link the new node at the head of the list.  If we are in the process of 
206      traversing the list, we won't visit any new nodes added to it.  */
207   linknode->prev = list;
208   linknode->next = list->next;
209   list->next->prev = linknode;
210   list->next = linknode;
211 }
212
213 /* Link ssa_imm_use node LINKNODE into the chain for DEF.  */
214 static inline void
215 link_imm_use (ssa_use_operand_t *linknode, tree def)
216 {
217   ssa_use_operand_t *root;
218
219   if (!def || TREE_CODE (def) != SSA_NAME)
220     linknode->prev = NULL;
221   else
222     {
223       root = &(SSA_NAME_IMM_USE_NODE (def));
224 #ifdef ENABLE_CHECKING
225       if (linknode->use)
226         gcc_assert (*(linknode->use) == def);
227 #endif
228       link_imm_use_to_list (linknode, root);
229     }
230 }
231
232 /* Set the value of a use pointed by USE to VAL.  */
233 static inline void
234 set_ssa_use_from_ptr (use_operand_p use, tree val)
235 {
236   delink_imm_use (use);
237   *(use->use) = val;
238   link_imm_use (use, val);
239 }
240
241 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring 
242    in STMT.  */
243 static inline void
244 link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, tree stmt)
245 {
246   if (stmt)
247     link_imm_use (linknode, def);
248   else
249     link_imm_use (linknode, NULL);
250   linknode->stmt = stmt;
251 }
252
253 /* Relink a new node in place of an old node in the list.  */
254 static inline void
255 relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
256 {
257   /* The node one had better be in the same list.  */
258   gcc_assert (*(old->use) == *(node->use));
259   node->prev = old->prev;
260   node->next = old->next;
261   if (old->prev)
262     {
263       old->prev->next = node;
264       old->next->prev = node;
265       /* Remove the old node from the list.  */
266       old->prev = NULL;
267     }
268 }
269
270 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring 
271    in STMT.  */
272 static inline void
273 relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old, tree stmt)
274 {
275   if (stmt)
276     relink_imm_use (linknode, old);
277   else
278     link_imm_use (linknode, NULL);
279   linknode->stmt = stmt;
280 }
281
282 /* Finished the traverse of an immediate use list IMM by removing it from 
283    the list.  */
284 static inline void
285 end_safe_imm_use_traverse (imm_use_iterator *imm)
286 {
287  delink_imm_use (&(imm->iter_node));
288 }
289
290 /* Return true if IMM is at the end of the list.  */
291 static inline bool
292 end_safe_imm_use_p (imm_use_iterator *imm)
293 {
294   return (imm->imm_use == imm->end_p);
295 }
296
297 /* Initialize iterator IMM to process the list for VAR.  */
298 static inline use_operand_p
299 first_safe_imm_use (imm_use_iterator *imm, tree var)
300 {
301   /* Set up and link the iterator node into the linked list for VAR.  */
302   imm->iter_node.use = NULL;
303   imm->iter_node.stmt = NULL_TREE;
304   imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
305   /* Check if there are 0 elements.  */
306   if (imm->end_p->next == imm->end_p)
307     {
308       imm->imm_use = imm->end_p;
309       return NULL_USE_OPERAND_P;
310     }
311
312   link_imm_use (&(imm->iter_node), var);
313   imm->imm_use = imm->iter_node.next;
314   return imm->imm_use;
315 }
316
317 /* Bump IMM to the next use in the list.  */
318 static inline use_operand_p
319 next_safe_imm_use (imm_use_iterator *imm)
320 {
321   ssa_use_operand_t *ptr;
322   use_operand_p old;
323
324   old = imm->imm_use;
325   /* If the next node following the iter_node is still the one referred to by
326      imm_use, then the list hasn't changed, go to the next node.  */
327   if (imm->iter_node.next == imm->imm_use)
328     {
329       ptr = &(imm->iter_node);
330       /* Remove iternode from the list.  */
331       delink_imm_use (ptr);
332       imm->imm_use = imm->imm_use->next;
333       if (! end_safe_imm_use_p (imm))
334         {
335           /* This isn't the end, link iternode before the next use.  */
336           ptr->prev = imm->imm_use->prev;
337           ptr->next = imm->imm_use;
338           imm->imm_use->prev->next = ptr;
339           imm->imm_use->prev = ptr;
340         }
341       else
342         return old;
343     }
344   else
345     {
346       /* If the 'next' value after the iterator isn't the same as it was, then
347          a node has been deleted, so we simply proceed to the node following 
348          where the iterator is in the list.  */
349       imm->imm_use = imm->iter_node.next;
350       if (end_safe_imm_use_p (imm))
351         {
352           end_safe_imm_use_traverse (imm);
353           return old;
354         }
355     }
356
357   return imm->imm_use;
358 }
359
360 /* Return true is IMM has reached the end of the immediate use list.  */
361 static inline bool
362 end_readonly_imm_use_p (imm_use_iterator *imm)
363 {
364   return (imm->imm_use == imm->end_p);
365 }
366
367 /* Initialize iterator IMM to process the list for VAR.  */
368 static inline use_operand_p
369 first_readonly_imm_use (imm_use_iterator *imm, tree var)
370 {
371   gcc_assert (TREE_CODE (var) == SSA_NAME);
372
373   imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
374   imm->imm_use = imm->end_p->next;
375 #ifdef ENABLE_CHECKING
376   imm->iter_node.next = imm->imm_use->next;
377 #endif
378   if (end_readonly_imm_use_p (imm))
379     return NULL_USE_OPERAND_P;
380   return imm->imm_use;
381 }
382
383 /* Bump IMM to the next use in the list.  */
384 static inline use_operand_p
385 next_readonly_imm_use (imm_use_iterator *imm)
386 {
387   use_operand_p old = imm->imm_use;
388
389 #ifdef ENABLE_CHECKING
390   /* If this assertion fails, it indicates the 'next' pointer has changed 
391      since we the last bump.  This indicates that the list is being modified
392      via stmt changes, or SET_USE, or somesuch thing, and you need to be
393      using the SAFE version of the iterator.  */
394   gcc_assert (imm->iter_node.next == old->next);
395   imm->iter_node.next = old->next->next;
396 #endif
397
398   imm->imm_use = old->next;
399   if (end_readonly_imm_use_p (imm))
400     return old;
401   return imm->imm_use;
402 }
403
404 /* Return true if VAR has no uses.  */
405 static inline bool
406 has_zero_uses (tree var)
407 {
408   ssa_use_operand_t *ptr;
409   ptr = &(SSA_NAME_IMM_USE_NODE (var));
410   /* A single use means there is no items in the list.  */
411   return (ptr == ptr->next);
412 }
413
414 /* Return true if VAR has a single use.  */
415 static inline bool
416 has_single_use (tree var)
417 {
418   ssa_use_operand_t *ptr;
419   ptr = &(SSA_NAME_IMM_USE_NODE (var));
420   /* A single use means there is one item in the list.  */
421   return (ptr != ptr->next && ptr == ptr->next->next);
422 }
423
424 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
425    to the use pointer and stmt of occurrence.  */
426 static inline bool
427 single_imm_use (tree var, use_operand_p *use_p, tree *stmt)
428 {
429   ssa_use_operand_t *ptr;
430
431   ptr = &(SSA_NAME_IMM_USE_NODE (var));
432   if (ptr != ptr->next && ptr == ptr->next->next)
433     {
434       *use_p = ptr->next;
435       *stmt = ptr->next->stmt;
436       return true;
437     }
438   *use_p = NULL_USE_OPERAND_P;
439   *stmt = NULL_TREE;
440   return false;
441 }
442
443 /* Return the number of immediate uses of VAR.  */
444 static inline unsigned int
445 num_imm_uses (tree var)
446 {
447   ssa_use_operand_t *ptr, *start;
448   unsigned int num;
449
450   start = &(SSA_NAME_IMM_USE_NODE (var));
451   num = 0;
452   for (ptr = start->next; ptr != start; ptr = ptr->next)
453      num++;
454
455   return num;
456 }
457
458
459 /* Return the tree pointer to by USE.  */ 
460 static inline tree
461 get_use_from_ptr (use_operand_p use)
462
463   return *(use->use);
464
465
466 /* Return the tree pointer to by DEF.  */
467 static inline tree
468 get_def_from_ptr (def_operand_p def)
469 {
470   return *def;
471 }
472
473 /* Return a def_operand_p pointer for the result of PHI.  */
474 static inline def_operand_p
475 get_phi_result_ptr (tree phi)
476 {
477   return &(PHI_RESULT_TREE (phi));
478 }
479
480 /* Return a use_operand_p pointer for argument I of phinode PHI.  */
481 static inline use_operand_p
482 get_phi_arg_def_ptr (tree phi, int i)
483 {
484   return &(PHI_ARG_IMM_USE_NODE (phi,i));
485 }
486
487
488 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
489    no addresses.  */
490 static inline bitmap
491 addresses_taken (tree stmt)
492 {
493   stmt_ann_t ann = stmt_ann (stmt);
494   return ann ? ann->addresses_taken : NULL;
495 }
496
497 /* Return the PHI nodes for basic block BB, or NULL if there are no
498    PHI nodes.  */
499 static inline tree
500 phi_nodes (basic_block bb)
501 {
502   return bb->phi_nodes;
503 }
504
505 /* Set list of phi nodes of a basic block BB to L.  */
506
507 static inline void
508 set_phi_nodes (basic_block bb, tree l)
509 {
510   tree phi;
511
512   bb->phi_nodes = l;
513   for (phi = l; phi; phi = PHI_CHAIN (phi))
514     set_bb_for_stmt (phi, bb);
515 }
516
517 /* Return the phi argument which contains the specified use.  */
518
519 static inline int
520 phi_arg_index_from_use (use_operand_p use)
521 {
522   struct phi_arg_d *element, *root;
523   int index;
524   tree phi;
525
526   /* Since the use is the first thing in a PHI argument element, we can
527      calculate its index based on casting it to an argument, and performing
528      pointer arithmetic.  */
529
530   phi = USE_STMT (use);
531   gcc_assert (TREE_CODE (phi) == PHI_NODE);
532
533   element = (struct phi_arg_d *)use;
534   root = &(PHI_ARG_ELT (phi, 0));
535   index = element - root;
536
537 #ifdef ENABLE_CHECKING
538   /* Make sure the calculation doesn't have any leftover bytes.  If it does, 
539      then imm_use is likely not the first element in phi_arg_d.  */
540   gcc_assert (
541           (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
542   gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
543 #endif
544  
545  return index;
546 }
547
548 /* Mark VAR as used, so that it'll be preserved during rtl expansion.  */
549
550 static inline void
551 set_is_used (tree var)
552 {
553   var_ann_t ann = get_var_ann (var);
554   ann->used = 1;
555 }
556
557
558 /*  -----------------------------------------------------------------------  */
559
560 /* Return true if T is an executable statement.  */
561 static inline bool
562 is_exec_stmt (tree t)
563 {
564   return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
565 }
566
567
568 /* Return true if this stmt can be the target of a control transfer stmt such
569    as a goto.  */
570 static inline bool
571 is_label_stmt (tree t)
572 {
573   if (t)
574     switch (TREE_CODE (t))
575       {
576         case LABEL_DECL:
577         case LABEL_EXPR:
578         case CASE_LABEL_EXPR:
579           return true;
580         default:
581           return false;
582       }
583   return false;
584 }
585
586 /* Set the default definition for VAR to DEF.  */
587 static inline void
588 set_default_def (tree var, tree def)
589 {
590   var_ann_t ann = get_var_ann (var);
591   ann->default_def = def;
592 }
593
594 /* Return the default definition for variable VAR, or NULL if none
595    exists.  */
596 static inline tree
597 default_def (tree var)
598 {
599   var_ann_t ann = var_ann (var);
600   return ann ? ann->default_def : NULL_TREE;
601 }
602
603 /* PHI nodes should contain only ssa_names and invariants.  A test
604    for ssa_name is definitely simpler; don't let invalid contents
605    slip in in the meantime.  */
606
607 static inline bool
608 phi_ssa_name_p (tree t)
609 {
610   if (TREE_CODE (t) == SSA_NAME)
611     return true;
612 #ifdef ENABLE_CHECKING
613   gcc_assert (is_gimple_min_invariant (t));
614 #endif
615   return false;
616 }
617
618 /*  -----------------------------------------------------------------------  */
619
620 /* Return a block_stmt_iterator that points to beginning of basic
621    block BB.  */
622 static inline block_stmt_iterator
623 bsi_start (basic_block bb)
624 {
625   block_stmt_iterator bsi;
626   if (bb->stmt_list)
627     bsi.tsi = tsi_start (bb->stmt_list);
628   else
629     {
630       gcc_assert (bb->index < 0);
631       bsi.tsi.ptr = NULL;
632       bsi.tsi.container = NULL;
633     }
634   bsi.bb = bb;
635   return bsi;
636 }
637
638 /* Return a block statement iterator that points to the last label in
639    block BB.  */
640
641 static inline block_stmt_iterator
642 bsi_after_labels (basic_block bb)
643 {
644   block_stmt_iterator bsi;
645   tree_stmt_iterator next;
646
647   bsi.bb = bb;
648
649   if (!bb->stmt_list)
650     {
651       gcc_assert (bb->index < 0);
652       bsi.tsi.ptr = NULL;
653       bsi.tsi.container = NULL;
654       return bsi;
655     }
656
657   bsi.tsi = tsi_start (bb->stmt_list);
658   if (tsi_end_p (bsi.tsi))
659     return bsi;
660
661   /* Ensure that there are some labels.  The rationale is that we want
662      to insert after the bsi that is returned, and these insertions should
663      be placed at the start of the basic block.  This would not work if the
664      first statement was not label; rather fail here than enable the user
665      proceed in wrong way.  */
666   gcc_assert (TREE_CODE (tsi_stmt (bsi.tsi)) == LABEL_EXPR);
667
668   next = bsi.tsi;
669   tsi_next (&next);
670
671   while (!tsi_end_p (next)
672          && TREE_CODE (tsi_stmt (next)) == LABEL_EXPR)
673     {
674       bsi.tsi = next;
675       tsi_next (&next);
676     }
677
678   return bsi;
679 }
680
681 /* Return a block statement iterator that points to the end of basic
682    block BB.  */
683 static inline block_stmt_iterator
684 bsi_last (basic_block bb)
685 {
686   block_stmt_iterator bsi;
687   if (bb->stmt_list)
688     bsi.tsi = tsi_last (bb->stmt_list);
689   else
690     {
691       gcc_assert (bb->index < 0);
692       bsi.tsi.ptr = NULL;
693       bsi.tsi.container = NULL;
694     }
695   bsi.bb = bb;
696   return bsi;
697 }
698
699 /* Return true if block statement iterator I has reached the end of
700    the basic block.  */
701 static inline bool
702 bsi_end_p (block_stmt_iterator i)
703 {
704   return tsi_end_p (i.tsi);
705 }
706
707 /* Modify block statement iterator I so that it is at the next
708    statement in the basic block.  */
709 static inline void
710 bsi_next (block_stmt_iterator *i)
711 {
712   tsi_next (&i->tsi);
713 }
714
715 /* Modify block statement iterator I so that it is at the previous
716    statement in the basic block.  */
717 static inline void
718 bsi_prev (block_stmt_iterator *i)
719 {
720   tsi_prev (&i->tsi);
721 }
722
723 /* Return the statement that block statement iterator I is currently
724    at.  */
725 static inline tree
726 bsi_stmt (block_stmt_iterator i)
727 {
728   return tsi_stmt (i.tsi);
729 }
730
731 /* Return a pointer to the statement that block statement iterator I
732    is currently at.  */
733 static inline tree *
734 bsi_stmt_ptr (block_stmt_iterator i)
735 {
736   return tsi_stmt_ptr (i.tsi);
737 }
738
739 /* Returns the loop of the statement STMT.  */
740
741 static inline struct loop *
742 loop_containing_stmt (tree stmt)
743 {
744   basic_block bb = bb_for_stmt (stmt);
745   if (!bb)
746     return NULL;
747
748   return bb->loop_father;
749 }
750
751 /* Return true if VAR is a clobbered by function calls.  */
752 static inline bool
753 is_call_clobbered (tree var)
754 {
755   return is_global_var (var)
756          || bitmap_bit_p (call_clobbered_vars, var_ann (var)->uid);
757 }
758
759 /* Mark variable VAR as being clobbered by function calls.  */
760 static inline void
761 mark_call_clobbered (tree var)
762 {
763   var_ann_t ann = var_ann (var);
764   /* If VAR is a memory tag, then we need to consider it a global
765      variable.  This is because the pointer that VAR represents has
766      been found to point to either an arbitrary location or to a known
767      location in global memory.  */
768   if (ann->mem_tag_kind != NOT_A_TAG && ann->mem_tag_kind != STRUCT_FIELD)
769     DECL_EXTERNAL (var) = 1;
770   bitmap_set_bit (call_clobbered_vars, ann->uid);
771   ssa_call_clobbered_cache_valid = false;
772   ssa_ro_call_cache_valid = false;
773 }
774
775 /* Clear the call-clobbered attribute from variable VAR.  */
776 static inline void
777 clear_call_clobbered (tree var)
778 {
779   var_ann_t ann = var_ann (var);
780   if (ann->mem_tag_kind != NOT_A_TAG && ann->mem_tag_kind != STRUCT_FIELD)
781     DECL_EXTERNAL (var) = 0;
782   bitmap_clear_bit (call_clobbered_vars, ann->uid);
783   ssa_call_clobbered_cache_valid = false;
784   ssa_ro_call_cache_valid = false;
785 }
786
787 /* Mark variable VAR as being non-addressable.  */
788 static inline void
789 mark_non_addressable (tree var)
790 {
791   bitmap_clear_bit (call_clobbered_vars, var_ann (var)->uid);
792   TREE_ADDRESSABLE (var) = 0;
793   ssa_call_clobbered_cache_valid = false;
794   ssa_ro_call_cache_valid = false;
795 }
796
797 /* Return the common annotation for T.  Return NULL if the annotation
798    doesn't already exist.  */
799 static inline tree_ann_t
800 tree_ann (tree t)
801 {
802   return t->common.ann;
803 }
804
805 /* Return a common annotation for T.  Create the constant annotation if it
806    doesn't exist.  */
807 static inline tree_ann_t
808 get_tree_ann (tree t)
809 {
810   tree_ann_t ann = tree_ann (t);
811   return (ann) ? ann : create_tree_ann (t);
812 }
813
814 /*  -----------------------------------------------------------------------  */
815
816 /* The following set of routines are used to iterator over various type of
817    SSA operands.  */
818
819 /* Return true if PTR is finished iterating.  */
820 static inline bool
821 op_iter_done (ssa_op_iter *ptr)
822 {
823   return ptr->done;
824 }
825
826 /* Get the next iterator use value for PTR.  */
827 static inline use_operand_p
828 op_iter_next_use (ssa_op_iter *ptr)
829 {
830   use_operand_p use_p;
831 #ifdef ENABLE_CHECKING
832   gcc_assert (ptr->iter_type == ssa_op_iter_use);
833 #endif
834   if (ptr->uses)
835     {
836       use_p = USE_OP_PTR (ptr->uses);
837       ptr->uses = ptr->uses->next;
838       return use_p;
839     }
840   if (ptr->vuses)
841     {
842       use_p = VUSE_OP_PTR (ptr->vuses);
843       ptr->vuses = ptr->vuses->next;
844       return use_p;
845     }
846   if (ptr->mayuses)
847     {
848       use_p = MAYDEF_OP_PTR (ptr->mayuses);
849       ptr->mayuses = ptr->mayuses->next;
850       return use_p;
851     }
852   if (ptr->mustkills)
853     {
854       use_p = MUSTDEF_KILL_PTR (ptr->mustkills);
855       ptr->mustkills = ptr->mustkills->next;
856       return use_p;
857     }
858   if (ptr->phi_i < ptr->num_phi)
859     {
860       return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
861     }
862   ptr->done = true;
863   return NULL_USE_OPERAND_P;
864 }
865
866 /* Get the next iterator def value for PTR.  */
867 static inline def_operand_p
868 op_iter_next_def (ssa_op_iter *ptr)
869 {
870   def_operand_p def_p;
871 #ifdef ENABLE_CHECKING
872   gcc_assert (ptr->iter_type == ssa_op_iter_def);
873 #endif
874   if (ptr->defs)
875     {
876       def_p = DEF_OP_PTR (ptr->defs);
877       ptr->defs = ptr->defs->next;
878       return def_p;
879     }
880   if (ptr->mustdefs)
881     {
882       def_p = MUSTDEF_RESULT_PTR (ptr->mustdefs);
883       ptr->mustdefs = ptr->mustdefs->next;
884       return def_p;
885     }
886   if (ptr->maydefs)
887     {
888       def_p = MAYDEF_RESULT_PTR (ptr->maydefs);
889       ptr->maydefs = ptr->maydefs->next;
890       return def_p;
891     }
892   ptr->done = true;
893   return NULL_DEF_OPERAND_P;
894 }
895
896 /* Get the next iterator tree value for PTR.  */
897 static inline tree
898 op_iter_next_tree (ssa_op_iter *ptr)
899 {
900   tree val;
901 #ifdef ENABLE_CHECKING
902   gcc_assert (ptr->iter_type == ssa_op_iter_tree);
903 #endif
904   if (ptr->uses)
905     {
906       val = USE_OP (ptr->uses);
907       ptr->uses = ptr->uses->next;
908       return val;
909     }
910   if (ptr->vuses)
911     {
912       val = VUSE_OP (ptr->vuses);
913       ptr->vuses = ptr->vuses->next;
914       return val;
915     }
916   if (ptr->mayuses)
917     {
918       val = MAYDEF_OP (ptr->mayuses);
919       ptr->mayuses = ptr->mayuses->next;
920       return val;
921     }
922   if (ptr->mustkills)
923     {
924       val = MUSTDEF_KILL (ptr->mustkills);
925       ptr->mustkills = ptr->mustkills->next;
926       return val;
927     }
928   if (ptr->defs)
929     {
930       val = DEF_OP (ptr->defs);
931       ptr->defs = ptr->defs->next;
932       return val;
933     }
934   if (ptr->mustdefs)
935     {
936       val = MUSTDEF_RESULT (ptr->mustdefs);
937       ptr->mustdefs = ptr->mustdefs->next;
938       return val;
939     }
940   if (ptr->maydefs)
941     {
942       val = MAYDEF_RESULT (ptr->maydefs);
943       ptr->maydefs = ptr->maydefs->next;
944       return val;
945     }
946
947   ptr->done = true;
948   return NULL_TREE;
949
950 }
951
952
953 /* This functions clears the iterator PTR, and marks it done.  This is normally
954    used to prevent warnings in the compile about might be uninitailzied
955    components.  */
956
957 static inline void
958 clear_and_done_ssa_iter (ssa_op_iter *ptr)
959 {
960   ptr->defs = NULL;
961   ptr->uses = NULL;
962   ptr->vuses = NULL;
963   ptr->maydefs = NULL;
964   ptr->mayuses = NULL;
965   ptr->mustdefs = NULL;
966   ptr->mustkills = NULL;
967   ptr->iter_type = ssa_op_iter_none;
968   ptr->phi_i = 0;
969   ptr->num_phi = 0;
970   ptr->phi_stmt = NULL_TREE;
971   ptr->done = true;
972 }
973
974 /* Initialize the iterator PTR to the virtual defs in STMT.  */
975 static inline void
976 op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
977 {
978 #ifdef ENABLE_CHECKING
979   gcc_assert (stmt_ann (stmt));
980 #endif
981
982   ptr->defs = (flags & SSA_OP_DEF) ? DEF_OPS (stmt) : NULL;
983   ptr->uses = (flags & SSA_OP_USE) ? USE_OPS (stmt) : NULL;
984   ptr->vuses = (flags & SSA_OP_VUSE) ? VUSE_OPS (stmt) : NULL;
985   ptr->maydefs = (flags & SSA_OP_VMAYDEF) ? MAYDEF_OPS (stmt) : NULL;
986   ptr->mayuses = (flags & SSA_OP_VMAYUSE) ? MAYDEF_OPS (stmt) : NULL;
987   ptr->mustdefs = (flags & SSA_OP_VMUSTDEF) ? MUSTDEF_OPS (stmt) : NULL;
988   ptr->mustkills = (flags & SSA_OP_VMUSTKILL) ? MUSTDEF_OPS (stmt) : NULL;
989   ptr->done = false;
990
991   ptr->phi_i = 0;
992   ptr->num_phi = 0;
993   ptr->phi_stmt = NULL_TREE;
994 }
995
996 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
997    the first use.  */
998 static inline use_operand_p
999 op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
1000 {
1001   gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0);
1002   op_iter_init (ptr, stmt, flags);
1003   ptr->iter_type = ssa_op_iter_use;
1004   return op_iter_next_use (ptr);
1005 }
1006
1007 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1008    the first def.  */
1009 static inline def_operand_p
1010 op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1011 {
1012   gcc_assert ((flags & (SSA_OP_ALL_USES | SSA_OP_VIRTUAL_KILLS)) == 0);
1013   op_iter_init (ptr, stmt, flags);
1014   ptr->iter_type = ssa_op_iter_def;
1015   return op_iter_next_def (ptr);
1016 }
1017
1018 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1019    the first operand as a tree.  */
1020 static inline tree
1021 op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1022 {
1023   op_iter_init (ptr, stmt, flags);
1024   ptr->iter_type = ssa_op_iter_tree;
1025   return op_iter_next_tree (ptr);
1026 }
1027
1028 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1029    KILL and DEF.  */
1030 static inline void
1031 op_iter_next_maymustdef (use_operand_p *use, def_operand_p *def, 
1032                          ssa_op_iter *ptr)
1033 {
1034 #ifdef ENABLE_CHECKING
1035   gcc_assert (ptr->iter_type == ssa_op_iter_maymustdef);
1036 #endif
1037   if (ptr->mayuses)
1038     {
1039       *def = MAYDEF_RESULT_PTR (ptr->mayuses);
1040       *use = MAYDEF_OP_PTR (ptr->mayuses);
1041       ptr->mayuses = ptr->mayuses->next;
1042       return;
1043     }
1044
1045   if (ptr->mustkills)
1046     {
1047       *def = MUSTDEF_RESULT_PTR (ptr->mustkills);
1048       *use = MUSTDEF_KILL_PTR (ptr->mustkills);
1049       ptr->mustkills = ptr->mustkills->next;
1050       return;
1051     }
1052
1053   *def = NULL_DEF_OPERAND_P;
1054   *use = NULL_USE_OPERAND_P;
1055   ptr->done = true;
1056   return;
1057 }
1058
1059
1060 /* Initialize iterator PTR to the operands in STMT.  Return the first operands
1061    in USE and DEF.  */
1062 static inline void
1063 op_iter_init_maydef (ssa_op_iter *ptr, tree stmt, use_operand_p *use, 
1064                      def_operand_p *def)
1065 {
1066   gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1067
1068   op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1069   ptr->iter_type = ssa_op_iter_maymustdef;
1070   op_iter_next_maymustdef (use, def, ptr);
1071 }
1072
1073
1074 /* Initialize iterator PTR to the operands in STMT.  Return the first operands
1075    in KILL and DEF.  */
1076 static inline void
1077 op_iter_init_mustdef (ssa_op_iter *ptr, tree stmt, use_operand_p *kill, 
1078                      def_operand_p *def)
1079 {
1080   gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1081
1082   op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL);
1083   ptr->iter_type = ssa_op_iter_maymustdef;
1084   op_iter_next_maymustdef (kill, def, ptr);
1085 }
1086
1087 /* Initialize iterator PTR to the operands in STMT.  Return the first operands
1088    in KILL and DEF.  */
1089 static inline void
1090 op_iter_init_must_and_may_def (ssa_op_iter *ptr, tree stmt,
1091                                use_operand_p *kill, def_operand_p *def)
1092 {
1093   gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1094
1095   op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL|SSA_OP_VMAYUSE);
1096   ptr->iter_type = ssa_op_iter_maymustdef;
1097   op_iter_next_maymustdef (kill, def, ptr);
1098 }
1099
1100
1101 /* If there is a single operand in STMT matching FLAGS, return it.  Otherwise
1102    return NULL.  PTR is the iterator to use.  */
1103 static inline tree
1104 single_ssa_tree_operand (tree stmt, int flags)
1105 {
1106   tree var;
1107   ssa_op_iter iter;
1108
1109   var = op_iter_init_tree (&iter, stmt, flags);
1110   if (op_iter_done (&iter))
1111     return NULL_TREE;
1112   op_iter_next_tree (&iter);
1113   if (op_iter_done (&iter))
1114     return var;
1115   return NULL_TREE;
1116 }
1117
1118
1119 /* If there is a single operand in STMT matching FLAGS, return it.  Otherwise
1120    return NULL.  PTR is the iterator to use.  */
1121 static inline use_operand_p
1122 single_ssa_use_operand (tree stmt, int flags)
1123 {
1124   use_operand_p var;
1125   ssa_op_iter iter;
1126
1127   var = op_iter_init_use (&iter, stmt, flags);
1128   if (op_iter_done (&iter))
1129     return NULL_USE_OPERAND_P;
1130   op_iter_next_use (&iter);
1131   if (op_iter_done (&iter))
1132     return var;
1133   return NULL_USE_OPERAND_P;
1134 }
1135
1136
1137
1138 /* If there is a single operand in STMT matching FLAGS, return it.  Otherwise
1139    return NULL.  PTR is the iterator to use.  */
1140 static inline def_operand_p
1141 single_ssa_def_operand (tree stmt, int flags)
1142 {
1143   def_operand_p var;
1144   ssa_op_iter iter;
1145
1146   var = op_iter_init_def (&iter, stmt, flags);
1147   if (op_iter_done (&iter))
1148     return NULL_DEF_OPERAND_P;
1149   op_iter_next_def (&iter);
1150   if (op_iter_done (&iter))
1151     return var;
1152   return NULL_DEF_OPERAND_P;
1153 }
1154
1155
1156 /* If there is a single operand in STMT matching FLAGS, return it.  Otherwise
1157    return NULL.  PTR is the iterator to use.  */
1158 static inline bool
1159 zero_ssa_operands (tree stmt, int flags)
1160 {
1161   ssa_op_iter iter;
1162
1163   op_iter_init_tree (&iter, stmt, flags);
1164   return op_iter_done (&iter);
1165 }
1166
1167
1168 /* Return the number of operands matching FLAGS in STMT.  */
1169 static inline int
1170 num_ssa_operands (tree stmt, int flags)
1171 {
1172   ssa_op_iter iter;
1173   tree t;
1174   int num = 0;
1175
1176   FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
1177     num++;
1178   return num;
1179 }
1180
1181
1182 /* Delink all immediate_use information for STMT.  */
1183 static inline void
1184 delink_stmt_imm_use (tree stmt)
1185 {
1186    ssa_op_iter iter;
1187    use_operand_p use_p;
1188
1189    if (ssa_operands_active ())
1190      FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter,
1191                                (SSA_OP_ALL_USES | SSA_OP_ALL_KILLS))
1192        delink_imm_use (use_p);
1193 }
1194
1195
1196 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1197    in STMT2.  TRUE is returned if they are the same.  STMTs can be NULL.  */
1198 static inline bool
1199 compare_ssa_operands_equal (tree stmt1, tree stmt2, int flags)
1200 {
1201   ssa_op_iter iter1, iter2;
1202   tree op1 = NULL_TREE;
1203   tree op2 = NULL_TREE;
1204   bool look1, look2;
1205
1206   if (stmt1 == stmt2)
1207     return true;
1208
1209   look1 = stmt1 && stmt_ann (stmt1);
1210   look2 = stmt2 && stmt_ann (stmt2);
1211
1212   if (look1)
1213     {
1214       op1 = op_iter_init_tree (&iter1, stmt1, flags);
1215       if (!look2)
1216         return op_iter_done (&iter1);
1217     }
1218   else
1219     clear_and_done_ssa_iter (&iter1);
1220
1221   if (look2)
1222     {
1223       op2 = op_iter_init_tree (&iter2, stmt2, flags);
1224       if (!look1)
1225         return op_iter_done (&iter2);
1226     }
1227   else
1228     clear_and_done_ssa_iter (&iter2);
1229
1230   while (!op_iter_done (&iter1) && !op_iter_done (&iter2))
1231     {
1232       if (op1 != op2)
1233         return false;
1234       op1 = op_iter_next_tree (&iter1);
1235       op2 = op_iter_next_tree (&iter2);
1236     }
1237
1238   return (op_iter_done (&iter1) && op_iter_done (&iter2));
1239 }
1240
1241
1242 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1243    Otherwise return NULL_DEF_OPERAND_P.  */
1244 static inline tree
1245 single_phi_def (tree stmt, int flags)
1246 {
1247   tree def = PHI_RESULT (stmt);
1248   if ((flags & SSA_OP_DEF) && is_gimple_reg (def)) 
1249     return def;
1250   if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
1251     return def;
1252   return NULL_TREE;
1253 }
1254
1255 /* Initialize the iterator PTR for uses matching FLAGS in PHI.  FLAGS should
1256    be either SSA_OP_USES or SAS_OP_VIRTUAL_USES.  */
1257 static inline use_operand_p
1258 op_iter_init_phiuse (ssa_op_iter *ptr, tree phi, int flags)
1259 {
1260   tree phi_def = PHI_RESULT (phi);
1261   int comp;
1262
1263   clear_and_done_ssa_iter (ptr);
1264   ptr->done = false;
1265
1266   gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
1267
1268   comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1269     
1270   /* If the PHI node doesn't the operand type we care about, we're done.  */
1271   if ((flags & comp) == 0)
1272     {
1273       ptr->done = true;
1274       return NULL_USE_OPERAND_P;
1275     }
1276
1277   ptr->phi_stmt = phi;
1278   ptr->num_phi = PHI_NUM_ARGS (phi);
1279   ptr->iter_type = ssa_op_iter_use;
1280   return op_iter_next_use (ptr);
1281 }
1282
1283
1284 /* Start an iterator for a PHI definition.  */
1285
1286 static inline def_operand_p
1287 op_iter_init_phidef (ssa_op_iter *ptr, tree phi, int flags)
1288 {
1289   tree phi_def = PHI_RESULT (phi);
1290   int comp;
1291
1292   clear_and_done_ssa_iter (ptr);
1293   ptr->done = false;
1294
1295   gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
1296
1297   comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
1298     
1299   /* If the PHI node doesn't the operand type we care about, we're done.  */
1300   if ((flags & comp) == 0)
1301     {
1302       ptr->done = true;
1303       return NULL_USE_OPERAND_P;
1304     }
1305
1306   ptr->iter_type = ssa_op_iter_def;
1307   /* The first call to op_iter_next_def will terminate the iterator since
1308      all the fields are NULL.  Simply return the result here as the first and
1309      therefore only result.  */
1310   return PHI_RESULT_PTR (phi);
1311 }
1312
1313
1314
1315 /* Return true if VAR cannot be modified by the program.  */
1316
1317 static inline bool
1318 unmodifiable_var_p (tree var)
1319 {
1320   if (TREE_CODE (var) == SSA_NAME)
1321     var = SSA_NAME_VAR (var);
1322   return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1323 }
1324
1325 /* Return true if REF, a COMPONENT_REF, has an ARRAY_REF somewhere in it.  */
1326
1327 static inline bool
1328 ref_contains_array_ref (tree ref)
1329 {
1330   while (handled_component_p (ref))
1331     {
1332       if (TREE_CODE (ref) == ARRAY_REF)
1333         return true;
1334       ref = TREE_OPERAND (ref, 0);
1335     }
1336   return false;
1337 }
1338
1339 /* Given a variable VAR, lookup and return a pointer to the list of
1340    subvariables for it.  */
1341
1342 static inline subvar_t *
1343 lookup_subvars_for_var (tree var)
1344 {
1345   var_ann_t ann = var_ann (var);
1346   gcc_assert (ann);
1347   return &ann->subvars;
1348 }
1349
1350 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1351    NULL, if there are no subvariables.  */
1352
1353 static inline subvar_t
1354 get_subvars_for_var (tree var)
1355 {
1356   subvar_t subvars;
1357
1358   gcc_assert (SSA_VAR_P (var));  
1359   
1360   if (TREE_CODE (var) == SSA_NAME)
1361     subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
1362   else
1363     subvars = *(lookup_subvars_for_var (var));
1364   return subvars;
1365 }
1366
1367 /* Return true if V is a tree that we can have subvars for.
1368    Normally, this is any aggregate type, however, due to implementation
1369    limitations ATM, we exclude array types as well.  */
1370
1371 static inline bool
1372 var_can_have_subvars (tree v)
1373 {
1374   return (AGGREGATE_TYPE_P (TREE_TYPE (v)) &&
1375           TREE_CODE (TREE_TYPE (v)) != ARRAY_TYPE);
1376 }
1377
1378   
1379 /* Return true if OFFSET and SIZE define a range that overlaps with some
1380    portion of the range of SV, a subvar.  If there was an exact overlap,
1381    *EXACT will be set to true upon return. */
1382
1383 static inline bool
1384 overlap_subvar (HOST_WIDE_INT offset, HOST_WIDE_INT size,
1385                 subvar_t sv,  bool *exact)
1386 {
1387   /* There are three possible cases of overlap.
1388      1. We can have an exact overlap, like so:   
1389      |offset, offset + size             |
1390      |sv->offset, sv->offset + sv->size |
1391      
1392      2. We can have offset starting after sv->offset, like so:
1393      
1394            |offset, offset + size              |
1395      |sv->offset, sv->offset + sv->size  |
1396
1397      3. We can have offset starting before sv->offset, like so:
1398      
1399      |offset, offset + size    |
1400        |sv->offset, sv->offset + sv->size|
1401   */
1402
1403   if (exact)
1404     *exact = false;
1405   if (offset == sv->offset && size == sv->size)
1406     {
1407       if (exact)
1408         *exact = true;
1409       return true;
1410     }
1411   else if (offset >= sv->offset && offset < (sv->offset + sv->size))
1412     {
1413       return true;
1414     }
1415   else if (offset < sv->offset && (offset + size > sv->offset))
1416     {
1417       return true;
1418     }
1419   return false;
1420
1421 }
1422
1423 #endif /* _TREE_FLOW_INLINE_H  */