OSDN Git Service

* de.po: Update.
[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 occuring 
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 occuring 
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 basic_block annotation for BB.  */
498 static inline bb_ann_t
499 bb_ann (basic_block bb)
500 {
501   return (bb_ann_t)bb->tree_annotations;
502 }
503
504 /* Return the PHI nodes for basic block BB, or NULL if there are no
505    PHI nodes.  */
506 static inline tree
507 phi_nodes (basic_block bb)
508 {
509   return bb_ann (bb)->phi_nodes;
510 }
511
512 /* Set list of phi nodes of a basic block BB to L.  */
513
514 static inline void
515 set_phi_nodes (basic_block bb, tree l)
516 {
517   tree phi;
518
519   bb_ann (bb)->phi_nodes = l;
520   for (phi = l; phi; phi = PHI_CHAIN (phi))
521     set_bb_for_stmt (phi, bb);
522 }
523
524 /* Return the phi argument which contains the specified use.  */
525
526 static inline int
527 phi_arg_index_from_use (use_operand_p use)
528 {
529   struct phi_arg_d *element, *root;
530   int index;
531   tree phi;
532
533   /* Since the use is the first thing in a PHI argument element, we can
534      calculate its index based on casting it to an argument, and performing
535      pointer arithmetic.  */
536
537   phi = USE_STMT (use);
538   gcc_assert (TREE_CODE (phi) == PHI_NODE);
539
540   element = (struct phi_arg_d *)use;
541   root = &(PHI_ARG_ELT (phi, 0));
542   index = element - root;
543
544 #ifdef ENABLE_CHECKING
545   /* Make sure the calculation doesn't have any leftover bytes.  If it does, 
546      then imm_use is likely not the first element in phi_arg_d.  */
547   gcc_assert (
548           (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
549   gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
550 #endif
551  
552  return index;
553 }
554
555 /* Mark VAR as used, so that it'll be preserved during rtl expansion.  */
556
557 static inline void
558 set_is_used (tree var)
559 {
560   var_ann_t ann = get_var_ann (var);
561   ann->used = 1;
562 }
563
564
565 /*  -----------------------------------------------------------------------  */
566
567 /* Return true if T is an executable statement.  */
568 static inline bool
569 is_exec_stmt (tree t)
570 {
571   return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
572 }
573
574
575 /* Return true if this stmt can be the target of a control transfer stmt such
576    as a goto.  */
577 static inline bool
578 is_label_stmt (tree t)
579 {
580   if (t)
581     switch (TREE_CODE (t))
582       {
583         case LABEL_DECL:
584         case LABEL_EXPR:
585         case CASE_LABEL_EXPR:
586           return true;
587         default:
588           return false;
589       }
590   return false;
591 }
592
593 /* Set the default definition for VAR to DEF.  */
594 static inline void
595 set_default_def (tree var, tree def)
596 {
597   var_ann_t ann = get_var_ann (var);
598   ann->default_def = def;
599 }
600
601 /* Return the default definition for variable VAR, or NULL if none
602    exists.  */
603 static inline tree
604 default_def (tree var)
605 {
606   var_ann_t ann = var_ann (var);
607   return ann ? ann->default_def : NULL_TREE;
608 }
609
610 /* PHI nodes should contain only ssa_names and invariants.  A test
611    for ssa_name is definitely simpler; don't let invalid contents
612    slip in in the meantime.  */
613
614 static inline bool
615 phi_ssa_name_p (tree t)
616 {
617   if (TREE_CODE (t) == SSA_NAME)
618     return true;
619 #ifdef ENABLE_CHECKING
620   gcc_assert (is_gimple_min_invariant (t));
621 #endif
622   return false;
623 }
624
625 /*  -----------------------------------------------------------------------  */
626
627 /* Return a block_stmt_iterator that points to beginning of basic
628    block BB.  */
629 static inline block_stmt_iterator
630 bsi_start (basic_block bb)
631 {
632   block_stmt_iterator bsi;
633   if (bb->stmt_list)
634     bsi.tsi = tsi_start (bb->stmt_list);
635   else
636     {
637       gcc_assert (bb->index < 0);
638       bsi.tsi.ptr = NULL;
639       bsi.tsi.container = NULL;
640     }
641   bsi.bb = bb;
642   return bsi;
643 }
644
645 /* Return a block statement iterator that points to the last label in
646    block BB.  */
647
648 static inline block_stmt_iterator
649 bsi_after_labels (basic_block bb)
650 {
651   block_stmt_iterator bsi;
652   tree_stmt_iterator next;
653
654   bsi.bb = bb;
655
656   if (!bb->stmt_list)
657     {
658       gcc_assert (bb->index < 0);
659       bsi.tsi.ptr = NULL;
660       bsi.tsi.container = NULL;
661       return bsi;
662     }
663
664   bsi.tsi = tsi_start (bb->stmt_list);
665   if (tsi_end_p (bsi.tsi))
666     return bsi;
667
668   /* Ensure that there are some labels.  The rationale is that we want
669      to insert after the bsi that is returned, and these insertions should
670      be placed at the start of the basic block.  This would not work if the
671      first statement was not label; rather fail here than enable the user
672      proceed in wrong way.  */
673   gcc_assert (TREE_CODE (tsi_stmt (bsi.tsi)) == LABEL_EXPR);
674
675   next = bsi.tsi;
676   tsi_next (&next);
677
678   while (!tsi_end_p (next)
679          && TREE_CODE (tsi_stmt (next)) == LABEL_EXPR)
680     {
681       bsi.tsi = next;
682       tsi_next (&next);
683     }
684
685   return bsi;
686 }
687
688 /* Return a block statement iterator that points to the end of basic
689    block BB.  */
690 static inline block_stmt_iterator
691 bsi_last (basic_block bb)
692 {
693   block_stmt_iterator bsi;
694   if (bb->stmt_list)
695     bsi.tsi = tsi_last (bb->stmt_list);
696   else
697     {
698       gcc_assert (bb->index < 0);
699       bsi.tsi.ptr = NULL;
700       bsi.tsi.container = NULL;
701     }
702   bsi.bb = bb;
703   return bsi;
704 }
705
706 /* Return true if block statement iterator I has reached the end of
707    the basic block.  */
708 static inline bool
709 bsi_end_p (block_stmt_iterator i)
710 {
711   return tsi_end_p (i.tsi);
712 }
713
714 /* Modify block statement iterator I so that it is at the next
715    statement in the basic block.  */
716 static inline void
717 bsi_next (block_stmt_iterator *i)
718 {
719   tsi_next (&i->tsi);
720 }
721
722 /* Modify block statement iterator I so that it is at the previous
723    statement in the basic block.  */
724 static inline void
725 bsi_prev (block_stmt_iterator *i)
726 {
727   tsi_prev (&i->tsi);
728 }
729
730 /* Return the statement that block statement iterator I is currently
731    at.  */
732 static inline tree
733 bsi_stmt (block_stmt_iterator i)
734 {
735   return tsi_stmt (i.tsi);
736 }
737
738 /* Return a pointer to the statement that block statement iterator I
739    is currently at.  */
740 static inline tree *
741 bsi_stmt_ptr (block_stmt_iterator i)
742 {
743   return tsi_stmt_ptr (i.tsi);
744 }
745
746 /* Returns the loop of the statement STMT.  */
747
748 static inline struct loop *
749 loop_containing_stmt (tree stmt)
750 {
751   basic_block bb = bb_for_stmt (stmt);
752   if (!bb)
753     return NULL;
754
755   return bb->loop_father;
756 }
757
758 /* Return true if VAR is a clobbered by function calls.  */
759 static inline bool
760 is_call_clobbered (tree var)
761 {
762   return is_global_var (var)
763          || bitmap_bit_p (call_clobbered_vars, var_ann (var)->uid);
764 }
765
766 /* Mark variable VAR as being clobbered by function calls.  */
767 static inline void
768 mark_call_clobbered (tree var)
769 {
770   var_ann_t ann = var_ann (var);
771   /* If VAR is a memory tag, then we need to consider it a global
772      variable.  This is because the pointer that VAR represents has
773      been found to point to either an arbitrary location or to a known
774      location in global memory.  */
775   if (ann->mem_tag_kind != NOT_A_TAG && ann->mem_tag_kind != STRUCT_FIELD)
776     DECL_EXTERNAL (var) = 1;
777   bitmap_set_bit (call_clobbered_vars, ann->uid);
778   ssa_call_clobbered_cache_valid = false;
779   ssa_ro_call_cache_valid = false;
780 }
781
782 /* Clear the call-clobbered attribute from variable VAR.  */
783 static inline void
784 clear_call_clobbered (tree var)
785 {
786   var_ann_t ann = var_ann (var);
787   if (ann->mem_tag_kind != NOT_A_TAG && ann->mem_tag_kind != STRUCT_FIELD)
788     DECL_EXTERNAL (var) = 0;
789   bitmap_clear_bit (call_clobbered_vars, ann->uid);
790   ssa_call_clobbered_cache_valid = false;
791   ssa_ro_call_cache_valid = false;
792 }
793
794 /* Mark variable VAR as being non-addressable.  */
795 static inline void
796 mark_non_addressable (tree var)
797 {
798   bitmap_clear_bit (call_clobbered_vars, var_ann (var)->uid);
799   TREE_ADDRESSABLE (var) = 0;
800   ssa_call_clobbered_cache_valid = false;
801   ssa_ro_call_cache_valid = false;
802 }
803
804 /* Return the common annotation for T.  Return NULL if the annotation
805    doesn't already exist.  */
806 static inline tree_ann_t
807 tree_ann (tree t)
808 {
809   return t->common.ann;
810 }
811
812 /* Return a common annotation for T.  Create the constant annotation if it
813    doesn't exist.  */
814 static inline tree_ann_t
815 get_tree_ann (tree t)
816 {
817   tree_ann_t ann = tree_ann (t);
818   return (ann) ? ann : create_tree_ann (t);
819 }
820
821 /*  -----------------------------------------------------------------------  */
822
823 /* The following set of routines are used to iterator over various type of
824    SSA operands.  */
825
826 /* Return true if PTR is finished iterating.  */
827 static inline bool
828 op_iter_done (ssa_op_iter *ptr)
829 {
830   return ptr->done;
831 }
832
833 /* Get the next iterator use value for PTR.  */
834 static inline use_operand_p
835 op_iter_next_use (ssa_op_iter *ptr)
836 {
837   use_operand_p use_p;
838 #ifdef ENABLE_CHECKING
839   gcc_assert (ptr->iter_type == ssa_op_iter_use);
840 #endif
841   if (ptr->uses)
842     {
843       use_p = USE_OP_PTR (ptr->uses);
844       ptr->uses = ptr->uses->next;
845       return use_p;
846     }
847   if (ptr->vuses)
848     {
849       use_p = VUSE_OP_PTR (ptr->vuses);
850       ptr->vuses = ptr->vuses->next;
851       return use_p;
852     }
853   if (ptr->mayuses)
854     {
855       use_p = MAYDEF_OP_PTR (ptr->mayuses);
856       ptr->mayuses = ptr->mayuses->next;
857       return use_p;
858     }
859   if (ptr->mustkills)
860     {
861       use_p = MUSTDEF_KILL_PTR (ptr->mustkills);
862       ptr->mustkills = ptr->mustkills->next;
863       return use_p;
864     }
865   if (ptr->phi_i < ptr->num_phi)
866     {
867       return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
868     }
869   ptr->done = true;
870   return NULL_USE_OPERAND_P;
871 }
872
873 /* Get the next iterator def value for PTR.  */
874 static inline def_operand_p
875 op_iter_next_def (ssa_op_iter *ptr)
876 {
877   def_operand_p def_p;
878 #ifdef ENABLE_CHECKING
879   gcc_assert (ptr->iter_type == ssa_op_iter_def);
880 #endif
881   if (ptr->defs)
882     {
883       def_p = DEF_OP_PTR (ptr->defs);
884       ptr->defs = ptr->defs->next;
885       return def_p;
886     }
887   if (ptr->mustdefs)
888     {
889       def_p = MUSTDEF_RESULT_PTR (ptr->mustdefs);
890       ptr->mustdefs = ptr->mustdefs->next;
891       return def_p;
892     }
893   if (ptr->maydefs)
894     {
895       def_p = MAYDEF_RESULT_PTR (ptr->maydefs);
896       ptr->maydefs = ptr->maydefs->next;
897       return def_p;
898     }
899   ptr->done = true;
900   return NULL_DEF_OPERAND_P;
901 }
902
903 /* Get the next iterator tree value for PTR.  */
904 static inline tree
905 op_iter_next_tree (ssa_op_iter *ptr)
906 {
907   tree val;
908 #ifdef ENABLE_CHECKING
909   gcc_assert (ptr->iter_type == ssa_op_iter_tree);
910 #endif
911   if (ptr->uses)
912     {
913       val = USE_OP (ptr->uses);
914       ptr->uses = ptr->uses->next;
915       return val;
916     }
917   if (ptr->vuses)
918     {
919       val = VUSE_OP (ptr->vuses);
920       ptr->vuses = ptr->vuses->next;
921       return val;
922     }
923   if (ptr->mayuses)
924     {
925       val = MAYDEF_OP (ptr->mayuses);
926       ptr->mayuses = ptr->mayuses->next;
927       return val;
928     }
929   if (ptr->mustkills)
930     {
931       val = MUSTDEF_KILL (ptr->mustkills);
932       ptr->mustkills = ptr->mustkills->next;
933       return val;
934     }
935   if (ptr->defs)
936     {
937       val = DEF_OP (ptr->defs);
938       ptr->defs = ptr->defs->next;
939       return val;
940     }
941   if (ptr->mustdefs)
942     {
943       val = MUSTDEF_RESULT (ptr->mustdefs);
944       ptr->mustdefs = ptr->mustdefs->next;
945       return val;
946     }
947   if (ptr->maydefs)
948     {
949       val = MAYDEF_RESULT (ptr->maydefs);
950       ptr->maydefs = ptr->maydefs->next;
951       return val;
952     }
953
954   ptr->done = true;
955   return NULL_TREE;
956
957 }
958
959
960 /* This functiins clears the iterator PTR, and marks it done.  This is normally
961    used to prevent warnings in the compile about might be uninitailzied
962    components.  */
963
964 static inline void
965 clear_and_done_ssa_iter (ssa_op_iter *ptr)
966 {
967   ptr->defs = NULL;
968   ptr->uses = NULL;
969   ptr->vuses = NULL;
970   ptr->maydefs = NULL;
971   ptr->mayuses = NULL;
972   ptr->mustdefs = NULL;
973   ptr->mustkills = NULL;
974   ptr->iter_type = ssa_op_iter_none;
975   ptr->phi_i = 0;
976   ptr->num_phi = 0;
977   ptr->phi_stmt = NULL_TREE;
978   ptr->done = true;
979 }
980
981 /* Initialize the iterator PTR to the virtual defs in STMT.  */
982 static inline void
983 op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
984 {
985 #ifdef ENABLE_CHECKING
986   gcc_assert (stmt_ann (stmt));
987 #endif
988
989   ptr->defs = (flags & SSA_OP_DEF) ? DEF_OPS (stmt) : NULL;
990   ptr->uses = (flags & SSA_OP_USE) ? USE_OPS (stmt) : NULL;
991   ptr->vuses = (flags & SSA_OP_VUSE) ? VUSE_OPS (stmt) : NULL;
992   ptr->maydefs = (flags & SSA_OP_VMAYDEF) ? MAYDEF_OPS (stmt) : NULL;
993   ptr->mayuses = (flags & SSA_OP_VMAYUSE) ? MAYDEF_OPS (stmt) : NULL;
994   ptr->mustdefs = (flags & SSA_OP_VMUSTDEF) ? MUSTDEF_OPS (stmt) : NULL;
995   ptr->mustkills = (flags & SSA_OP_VMUSTKILL) ? MUSTDEF_OPS (stmt) : NULL;
996   ptr->done = false;
997
998   ptr->phi_i = 0;
999   ptr->num_phi = 0;
1000   ptr->phi_stmt = NULL_TREE;
1001 }
1002
1003 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1004    the first use.  */
1005 static inline use_operand_p
1006 op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
1007 {
1008   op_iter_init (ptr, stmt, flags);
1009   ptr->iter_type = ssa_op_iter_use;
1010   return op_iter_next_use (ptr);
1011 }
1012
1013 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1014    the first def.  */
1015 static inline def_operand_p
1016 op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1017 {
1018   op_iter_init (ptr, stmt, flags);
1019   ptr->iter_type = ssa_op_iter_def;
1020   return op_iter_next_def (ptr);
1021 }
1022
1023 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1024    the first operand as a tree.  */
1025 static inline tree
1026 op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1027 {
1028   op_iter_init (ptr, stmt, flags);
1029   ptr->iter_type = ssa_op_iter_tree;
1030   return op_iter_next_tree (ptr);
1031 }
1032
1033 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1034    KILL and DEF.  */
1035 static inline void
1036 op_iter_next_maymustdef (use_operand_p *use, def_operand_p *def, 
1037                          ssa_op_iter *ptr)
1038 {
1039 #ifdef ENABLE_CHECKING
1040   gcc_assert (ptr->iter_type == ssa_op_iter_maymustdef);
1041 #endif
1042   if (ptr->mayuses)
1043     {
1044       *def = MAYDEF_RESULT_PTR (ptr->mayuses);
1045       *use = MAYDEF_OP_PTR (ptr->mayuses);
1046       ptr->mayuses = ptr->mayuses->next;
1047       return;
1048     }
1049
1050   if (ptr->mustkills)
1051     {
1052       *def = MUSTDEF_RESULT_PTR (ptr->mustkills);
1053       *use = MUSTDEF_KILL_PTR (ptr->mustkills);
1054       ptr->mustkills = ptr->mustkills->next;
1055       return;
1056     }
1057
1058   *def = NULL_DEF_OPERAND_P;
1059   *use = NULL_USE_OPERAND_P;
1060   ptr->done = true;
1061   return;
1062 }
1063
1064
1065 /* Initialize iterator PTR to the operands in STMT.  Return the first operands
1066    in USE and DEF.  */
1067 static inline void
1068 op_iter_init_maydef (ssa_op_iter *ptr, tree stmt, use_operand_p *use, 
1069                      def_operand_p *def)
1070 {
1071   gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1072
1073   op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1074   ptr->iter_type = ssa_op_iter_maymustdef;
1075   op_iter_next_maymustdef (use, def, ptr);
1076 }
1077
1078
1079 /* Initialize iterator PTR to the operands in STMT.  Return the first operands
1080    in KILL and DEF.  */
1081 static inline void
1082 op_iter_init_mustdef (ssa_op_iter *ptr, tree stmt, use_operand_p *kill, 
1083                      def_operand_p *def)
1084 {
1085   gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1086
1087   op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL);
1088   ptr->iter_type = ssa_op_iter_maymustdef;
1089   op_iter_next_maymustdef (kill, def, ptr);
1090 }
1091
1092 /* Initialize iterator PTR to the operands in STMT.  Return the first operands
1093    in KILL and DEF.  */
1094 static inline void
1095 op_iter_init_must_and_may_def (ssa_op_iter *ptr, tree stmt,
1096                                use_operand_p *kill, def_operand_p *def)
1097 {
1098   gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1099
1100   op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL|SSA_OP_VMAYUSE);
1101   ptr->iter_type = ssa_op_iter_maymustdef;
1102   op_iter_next_maymustdef (kill, def, ptr);
1103 }
1104
1105
1106 /* If there is a single opernad in STMT matching FLAGS, return it.  Otherwise
1107    return NULL.  PTR is the iterator to use.  */
1108 static inline tree
1109 single_ssa_tree_operand (tree stmt, int flags)
1110 {
1111   tree var;
1112   ssa_op_iter iter;
1113
1114   var = op_iter_init_tree (&iter, stmt, flags);
1115   if (op_iter_done (&iter))
1116     return NULL_TREE;
1117   op_iter_next_tree (&iter);
1118   if (op_iter_done (&iter))
1119     return var;
1120   return NULL_TREE;
1121 }
1122
1123
1124 /* If there is a single opernad in STMT matching FLAGS, return it.  Otherwise
1125    return NULL.  PTR is the iterator to use.  */
1126 static inline use_operand_p
1127 single_ssa_use_operand (tree stmt, int flags)
1128 {
1129   use_operand_p var;
1130   ssa_op_iter iter;
1131
1132   var = op_iter_init_use (&iter, stmt, flags);
1133   if (op_iter_done (&iter))
1134     return NULL_USE_OPERAND_P;
1135   op_iter_next_use (&iter);
1136   if (op_iter_done (&iter))
1137     return var;
1138   return NULL_USE_OPERAND_P;
1139 }
1140
1141
1142
1143 /* If there is a single opernad in STMT matching FLAGS, return it.  Otherwise
1144    return NULL.  PTR is the iterator to use.  */
1145 static inline def_operand_p
1146 single_ssa_def_operand (tree stmt, int flags)
1147 {
1148   def_operand_p var;
1149   ssa_op_iter iter;
1150
1151   var = op_iter_init_def (&iter, stmt, flags);
1152   if (op_iter_done (&iter))
1153     return NULL_DEF_OPERAND_P;
1154   op_iter_next_def (&iter);
1155   if (op_iter_done (&iter))
1156     return var;
1157   return NULL_DEF_OPERAND_P;
1158 }
1159
1160
1161 /* If there is a single opernad in STMT matching FLAGS, return it.  Otherwise
1162    return NULL.  PTR is the iterator to use.  */
1163 static inline bool
1164 zero_ssa_operands (tree stmt, int flags)
1165 {
1166   ssa_op_iter iter;
1167
1168   op_iter_init_tree (&iter, stmt, flags);
1169   return op_iter_done (&iter);
1170 }
1171
1172
1173 /* Return the  number of opernads mathcing FLAGS in STMT.  */
1174 static inline int
1175 num_ssa_operands (tree stmt, int flags)
1176 {
1177   ssa_op_iter iter;
1178   int num = 0;
1179
1180   op_iter_init (&iter, stmt, flags);
1181   for ( ; iter.defs; iter.defs = iter.defs->next)
1182     num++;
1183   for ( ; iter.uses; iter.uses = iter.uses->next)
1184     num++;
1185   for ( ; iter.vuses; iter.vuses = iter.vuses->next)
1186     num++;
1187   for ( ; iter.maydefs; iter.maydefs = iter.maydefs->next)
1188     num++;
1189   for ( ; iter.mayuses; iter.mayuses = iter.mayuses->next)
1190     num++;
1191   for ( ; iter.mustdefs; iter.mustdefs = iter.mustdefs->next)
1192     num++;
1193   for ( ; iter.mustkills; iter.mustkills = iter.mustkills->next)
1194     num++;
1195
1196   return num;
1197 }
1198
1199
1200 /* Delink all immediate_use information for STMT.  */
1201 static inline void
1202 delink_stmt_imm_use (tree stmt)
1203 {
1204    ssa_op_iter iter;
1205    use_operand_p use_p;
1206
1207    if (ssa_operands_active ())
1208      FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter,
1209                                (SSA_OP_ALL_USES | SSA_OP_ALL_KILLS))
1210        delink_imm_use (use_p);
1211 }
1212
1213
1214 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1215    in STMT2.  TRUE is returned if they are the same.  STMTs can be NULL.  */
1216 static inline bool
1217 compare_ssa_operands_equal (tree stmt1, tree stmt2, int flags)
1218 {
1219   ssa_op_iter iter1, iter2;
1220   tree op1 = NULL_TREE;
1221   tree op2 = NULL_TREE;
1222   bool look1, look2;
1223
1224   if (stmt1 == stmt2)
1225     return true;
1226
1227   look1 = stmt1 && stmt_ann (stmt1);
1228   look2 = stmt2 && stmt_ann (stmt2);
1229
1230   if (look1)
1231     {
1232       op1 = op_iter_init_tree (&iter1, stmt1, flags);
1233       if (!look2)
1234         return op_iter_done (&iter1);
1235     }
1236   else
1237     clear_and_done_ssa_iter (&iter1);
1238
1239   if (look2)
1240     {
1241       op2 = op_iter_init_tree (&iter2, stmt2, flags);
1242       if (!look1)
1243         return op_iter_done (&iter2);
1244     }
1245   else
1246     clear_and_done_ssa_iter (&iter2);
1247
1248   while (!op_iter_done (&iter1) && !op_iter_done (&iter2))
1249     {
1250       if (op1 != op2)
1251         return false;
1252       op1 = op_iter_next_tree (&iter1);
1253       op2 = op_iter_next_tree (&iter2);
1254     }
1255
1256   return (op_iter_done (&iter1) && op_iter_done (&iter2));
1257 }
1258
1259
1260 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1261    Otherwise return NULL_DEF_OPERAND_P.  */
1262 static inline tree
1263 single_phi_def (tree stmt, int flags)
1264 {
1265   tree def = PHI_RESULT (stmt);
1266   if ((flags & SSA_OP_DEF) && is_gimple_reg (def)) 
1267     return def;
1268   if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
1269     return def;
1270   return NULL_TREE;
1271 }
1272
1273 /* Initialize the iterator PTR for uses matching FLAGS in PHI.  FLAGS should
1274    be either SSA_OP_USES or SAS_OP_VIRTUAL_USES.  */
1275 static inline use_operand_p
1276 op_iter_init_phiuse (ssa_op_iter *ptr, tree phi, int flags)
1277 {
1278   tree phi_def = PHI_RESULT (phi);
1279   int comp;
1280
1281   clear_and_done_ssa_iter (ptr);
1282   ptr->done = false;
1283
1284   gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
1285
1286   comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1287     
1288   /* if the PHI node deosn't the operand type we care about, we're done.  */
1289   if ((flags & comp) == 0)
1290     {
1291       ptr->done = true;
1292       return NULL_USE_OPERAND_P;
1293     }
1294
1295   ptr->phi_stmt = phi;
1296   ptr->num_phi = PHI_NUM_ARGS (phi);
1297   ptr->iter_type = ssa_op_iter_use;
1298   return op_iter_next_use (ptr);
1299 }
1300
1301
1302 /* Start an iterator for a PHI defintion.  */
1303
1304 static inline def_operand_p
1305 op_iter_init_phidef (ssa_op_iter *ptr, tree phi, int flags)
1306 {
1307   tree phi_def = PHI_RESULT (phi);
1308   int comp;
1309
1310   clear_and_done_ssa_iter (ptr);
1311   ptr->done = false;
1312
1313   gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
1314
1315   comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
1316     
1317   /* if the PHI node deosn't the operand type we care about, we're done.  */
1318   if ((flags & comp) == 0)
1319     {
1320       ptr->done = true;
1321       return NULL_USE_OPERAND_P;
1322     }
1323
1324   ptr->iter_type = ssa_op_iter_def;
1325   /* The first call to op_iter_next_def will terminate the iterator since
1326      all the fields are NULL.  Simply return the result here as the first and
1327      therefore only result.  */
1328   return PHI_RESULT_PTR (phi);
1329 }
1330
1331
1332
1333 /* Return true if VAR cannot be modified by the program.  */
1334
1335 static inline bool
1336 unmodifiable_var_p (tree var)
1337 {
1338   if (TREE_CODE (var) == SSA_NAME)
1339     var = SSA_NAME_VAR (var);
1340   return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1341 }
1342
1343 /* Return true if REF, a COMPONENT_REF, has an ARRAY_REF somewhere in it.  */
1344
1345 static inline bool
1346 ref_contains_array_ref (tree ref)
1347 {
1348   while (handled_component_p (ref))
1349     {
1350       if (TREE_CODE (ref) == ARRAY_REF)
1351         return true;
1352       ref = TREE_OPERAND (ref, 0);
1353     }
1354   return false;
1355 }
1356
1357 /* Given a variable VAR, lookup and return a pointer to the list of
1358    subvariables for it.  */
1359
1360 static inline subvar_t *
1361 lookup_subvars_for_var (tree var)
1362 {
1363   var_ann_t ann = var_ann (var);
1364   gcc_assert (ann);
1365   return &ann->subvars;
1366 }
1367
1368 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1369    NULL, if there are no subvariables.  */
1370
1371 static inline subvar_t
1372 get_subvars_for_var (tree var)
1373 {
1374   subvar_t subvars;
1375
1376   gcc_assert (SSA_VAR_P (var));  
1377   
1378   if (TREE_CODE (var) == SSA_NAME)
1379     subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
1380   else
1381     subvars = *(lookup_subvars_for_var (var));
1382   return subvars;
1383 }
1384
1385 /* Return true if V is a tree that we can have subvars for.
1386    Normally, this is any aggregate type, however, due to implementation
1387    limitations ATM, we exclude array types as well.  */
1388
1389 static inline bool
1390 var_can_have_subvars (tree v)
1391 {
1392   return (AGGREGATE_TYPE_P (TREE_TYPE (v)) &&
1393           TREE_CODE (TREE_TYPE (v)) != ARRAY_TYPE);
1394 }
1395
1396   
1397 /* Return true if OFFSET and SIZE define a range that overlaps with some
1398    portion of the range of SV, a subvar.  If there was an exact overlap,
1399    *EXACT will be set to true upon return. */
1400
1401 static inline bool
1402 overlap_subvar (HOST_WIDE_INT offset, HOST_WIDE_INT size,
1403                 subvar_t sv,  bool *exact)
1404 {
1405   /* There are three possible cases of overlap.
1406      1. We can have an exact overlap, like so:   
1407      |offset, offset + size             |
1408      |sv->offset, sv->offset + sv->size |
1409      
1410      2. We can have offset starting after sv->offset, like so:
1411      
1412            |offset, offset + size              |
1413      |sv->offset, sv->offset + sv->size  |
1414
1415      3. We can have offset starting before sv->offset, like so:
1416      
1417      |offset, offset + size    |
1418        |sv->offset, sv->offset + sv->size|
1419   */
1420
1421   if (exact)
1422     *exact = false;
1423   if (offset == sv->offset && size == sv->size)
1424     {
1425       if (exact)
1426         *exact = true;
1427       return true;
1428     }
1429   else if (offset >= sv->offset && offset < (sv->offset + sv->size))
1430     {
1431       return true;
1432     }
1433   else if (offset < sv->offset && (offset + size > sv->offset))
1434     {
1435       return true;
1436     }
1437   return false;
1438
1439 }
1440
1441 #endif /* _TREE_FLOW_INLINE_H  */