OSDN Git Service

* vec.h: Update API to separate allocation mechanism from type.
[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_imm_use_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_imm_use_t *linknode, ssa_imm_use_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 wont 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_imm_use_t *linknode, tree def)
216 {
217   ssa_imm_use_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_imm_use_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_imm_use_t *node, ssa_imm_use_t *old)
256 {
257 #ifdef ENABLE_CHECKING
258   /* The node one had better be in the same list.  */
259   if (*(old->use) != *(node->use))
260     abort ();
261 #endif
262   node->prev = old->prev;
263   node->next = old->next;
264   if (old->prev)
265     {
266       old->prev->next = node;
267       old->next->prev = node;
268       /* Remove the old node from the list.  */
269       old->prev = NULL;
270     }
271
272 }
273
274 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occuring 
275    in STMT.  */
276 static inline void
277 relink_imm_use_stmt (ssa_imm_use_t *linknode, ssa_imm_use_t *old, tree stmt)
278 {
279   if (stmt)
280     relink_imm_use (linknode, old);
281   else
282     link_imm_use (linknode, NULL);
283   linknode->stmt = stmt;
284 }
285
286 /* Finished the traverse of an immediate use list IMM by removing it from 
287    the list.  */
288 static inline void
289 end_safe_imm_use_traverse (imm_use_iterator *imm)
290 {
291  delink_imm_use (&(imm->iter_node));
292 }
293
294 /* Return true if IMM is at the end of the list.  */
295 static inline bool
296 end_safe_imm_use_p (imm_use_iterator *imm)
297 {
298   return (imm->imm_use == imm->end_p);
299 }
300
301 /* Initialize iterator IMM to process the list for VAR.  */
302 static inline use_operand_p
303 first_safe_imm_use (imm_use_iterator *imm, tree var)
304 {
305   /* Set up and link the iterator node into the linked list for VAR.  */
306   imm->iter_node.use = NULL;
307   imm->iter_node.stmt = NULL_TREE;
308   imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
309   /* Check if there are 0 elements.  */
310   if (imm->end_p->next == imm->end_p)
311     {
312       imm->imm_use = imm->end_p;
313       return NULL_USE_OPERAND_P;
314     }
315
316   link_imm_use (&(imm->iter_node), var);
317   imm->imm_use = imm->iter_node.next;
318   return imm->imm_use;
319 }
320
321 /* Bump IMM to then next use in the list.  */
322 static inline use_operand_p
323 next_safe_imm_use (imm_use_iterator *imm)
324 {
325   ssa_imm_use_t *ptr;
326   use_operand_p old;
327
328   old = imm->imm_use;
329   /* If the next node following the iter_node is still the one referred to by
330      imm_use, then the list hasn't changed, go to the next node.  */
331   if (imm->iter_node.next == imm->imm_use)
332     {
333       ptr = &(imm->iter_node);
334       /* Remove iternode from the list.  */
335       delink_imm_use (ptr);
336       imm->imm_use = imm->imm_use->next;
337       if (! end_safe_imm_use_p (imm))
338         {
339           /* This isnt the end, link iternode before the next use.  */
340           ptr->prev = imm->imm_use->prev;
341           ptr->next = imm->imm_use;
342           imm->imm_use->prev->next = ptr;
343           imm->imm_use->prev = ptr;
344         }
345       else
346         return old;
347     }
348   else
349     {
350       /* If the 'next' value after the iterator isn't the same as it was, then
351          a node has been deleted, so we simply proceed to the node following 
352          where the iterator is in the list.  */
353       imm->imm_use = imm->iter_node.next;
354       if (end_safe_imm_use_p (imm))
355         {
356           end_safe_imm_use_traverse (imm);
357           return old;
358         }
359     }
360
361   return imm->imm_use;
362 }
363
364 /* Return true is IMM has reached the end of the immediate use list.  */
365 static inline bool
366 end_readonly_imm_use_p (imm_use_iterator *imm)
367 {
368   return (imm->imm_use == imm->end_p);
369 }
370
371 /* Initialize iterator IMM to process the list for VAR.  */
372 static inline use_operand_p
373 first_readonly_imm_use (imm_use_iterator *imm, tree var)
374 {
375   gcc_assert (TREE_CODE (var) == SSA_NAME);
376
377   imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
378   imm->imm_use = imm->end_p->next;
379 #ifdef ENABLE_CHECKING
380   imm->iter_node.next = imm->imm_use->next;
381 #endif
382   if (end_readonly_imm_use_p (imm))
383     return NULL_USE_OPERAND_P;
384   return imm->imm_use;
385 }
386
387 /* Bump IMM to then next use in the list.  */
388 static inline use_operand_p
389 next_readonly_imm_use (imm_use_iterator *imm)
390 {
391   use_operand_p old = imm->imm_use;
392
393 #ifdef ENABLE_CHECKING
394   /* If this assertion fails, it indicates the 'next' pointer has changed 
395      since we the last bump.  This indicates that the list is being modified
396      via stmt changes, or SET_USE, or somesuch thing, and you need to be
397      using the SAFE version of the iterator.  */
398   gcc_assert (imm->iter_node.next == old->next);
399   imm->iter_node.next = old->next->next;
400 #endif
401
402   imm->imm_use = old->next;
403   if (end_readonly_imm_use_p (imm))
404     return old;
405   return imm->imm_use;
406 }
407
408 /* Return true if VAR has no uses.  */
409 static inline bool
410 has_zero_uses (tree var)
411 {
412   ssa_imm_use_t *ptr;
413   ptr = &(SSA_NAME_IMM_USE_NODE (var));
414   /* A single use means there is no items in the list.  */
415   return (ptr == ptr->next);
416 }
417
418 /* Return true if VAR has a single use.  */
419 static inline bool
420 has_single_use (tree var)
421 {
422   ssa_imm_use_t *ptr;
423   ptr = &(SSA_NAME_IMM_USE_NODE (var));
424   /* A single use means there is one item in the list.  */
425   return (ptr != ptr->next && ptr == ptr->next->next);
426 }
427
428 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
429    to the use pointer and stmt of occurrence.  */
430 static inline bool
431 single_imm_use (tree var, use_operand_p *use_p, tree *stmt)
432 {
433   ssa_imm_use_t *ptr;
434
435   ptr = &(SSA_NAME_IMM_USE_NODE (var));
436   if (ptr != ptr->next && ptr == ptr->next->next)
437     {
438       *use_p = ptr->next;
439       *stmt = ptr->next->stmt;
440       return true;
441     }
442   *use_p = NULL_USE_OPERAND_P;
443   *stmt = NULL_TREE;
444   return false;
445 }
446
447 /* Return the number of immediate uses of VAR.  */
448 static inline unsigned int
449 num_imm_uses (tree var)
450 {
451   ssa_imm_use_t *ptr, *start;
452   unsigned int num;
453
454   start = &(SSA_NAME_IMM_USE_NODE (var));
455   num = 0;
456   for (ptr = start->next; ptr != start; ptr = ptr->next)
457      num++;
458
459   return num;
460 }
461
462 /* Return the definitions present in ANN, a statement annotation.
463    Return NULL if this annotation contains no definitions.  */
464 static inline def_optype
465 get_def_ops (stmt_ann_t ann)
466 {
467   return ann ? ann->operands.def_ops : NULL;
468 }
469
470 /* Return the uses present in ANN, a statement annotation.
471    Return NULL if this annotation contains no uses.  */
472 static inline use_optype
473 get_use_ops (stmt_ann_t ann)
474 {
475   return ann ? ann->operands.use_ops : NULL;
476 }
477
478 /* Return the virtual may-defs present in ANN, a statement
479    annotation.
480    Return NULL if this annotation contains no virtual may-defs.  */
481 static inline v_may_def_optype
482 get_v_may_def_ops (stmt_ann_t ann)
483 {
484   return ann ? ann->operands.v_may_def_ops : NULL;
485 }
486
487 /* Return the virtual uses present in ANN, a statement annotation.
488    Return NULL if this annotation contains no virtual uses.  */
489 static inline vuse_optype
490 get_vuse_ops (stmt_ann_t ann)
491 {
492   return ann ? ann->operands.vuse_ops : NULL;
493 }
494
495 /* Return the virtual must-defs present in ANN, a statement
496    annotation.  Return NULL if this annotation contains no must-defs.*/
497 static inline v_must_def_optype
498 get_v_must_def_ops (stmt_ann_t ann)
499 {
500   return ann ? ann->operands.v_must_def_ops : NULL;
501 }
502
503 /* Return the tree pointer to by USE.  */ 
504 static inline tree
505 get_use_from_ptr (use_operand_p use)
506
507   return *(use->use);
508
509
510 /* Return the tree pointer to by DEF.  */
511 static inline tree
512 get_def_from_ptr (def_operand_p def)
513 {
514   return *(def.def);
515 }
516
517 /* Return a pointer to the tree that is at INDEX in the USES array.  */
518 static inline use_operand_p
519 get_use_op_ptr (use_optype uses, unsigned int index)
520 {
521   gcc_assert (index < uses->num_uses);
522   return &(uses->uses[index]);
523 }
524
525 /* Return a def_operand_p pointer for element INDEX of DEFS.  */
526 static inline def_operand_p
527 get_def_op_ptr (def_optype defs, unsigned int index)
528 {
529   gcc_assert (index < defs->num_defs);
530   return defs->defs[index];
531 }
532
533 /* Return the def_operand_p that is the V_MAY_DEF_RESULT for the V_MAY_DEF
534    at INDEX in the V_MAY_DEFS array.  */
535 static inline def_operand_p
536 get_v_may_def_result_ptr(v_may_def_optype v_may_defs, unsigned int index)
537 {
538   def_operand_p op;
539   gcc_assert (index < v_may_defs->num_v_may_defs);
540   op.def = &(v_may_defs->v_may_defs[index].def);
541   return op;
542 }
543
544 /* Return a use_operand_p that is the V_MAY_DEF_OP for the V_MAY_DEF at
545    INDEX in the V_MAY_DEFS array.  */
546 static inline use_operand_p
547 get_v_may_def_op_ptr(v_may_def_optype v_may_defs, unsigned int index)
548 {
549   gcc_assert (index < v_may_defs->num_v_may_defs);
550   return &(v_may_defs->v_may_defs[index].imm_use);
551 }
552
553 /* Return a use_operand_p that is at INDEX in the VUSES array.  */
554 static inline use_operand_p
555 get_vuse_op_ptr(vuse_optype vuses, unsigned int index)
556 {
557   gcc_assert (index < vuses->num_vuses);
558   return &(vuses->vuses[index].imm_use);
559 }
560
561 /* Return a def_operand_p that is the V_MUST_DEF_RESULT for the
562    V_MUST_DEF at INDEX in the V_MUST_DEFS array.  */
563 static inline def_operand_p
564 get_v_must_def_result_ptr (v_must_def_optype v_must_defs, unsigned int index)
565 {
566   def_operand_p op;
567   gcc_assert (index < v_must_defs->num_v_must_defs);
568   op.def = &(v_must_defs->v_must_defs[index].def);
569   return op;
570 }
571
572 /* Return a use_operand_p that is the V_MUST_DEF_KILL for the 
573    V_MUST_DEF at INDEX in the V_MUST_DEFS array.  */
574 static inline use_operand_p
575 get_v_must_def_kill_ptr (v_must_def_optype v_must_defs, unsigned int index)
576 {
577   gcc_assert (index < v_must_defs->num_v_must_defs);
578   return &(v_must_defs->v_must_defs[index].imm_use);
579 }
580
581 /* Return a def_operand_p pointer for the result of PHI.  */
582 static inline def_operand_p
583 get_phi_result_ptr (tree phi)
584 {
585   def_operand_p op;
586   op.def = &(PHI_RESULT_TREE (phi));
587   return op;
588 }
589
590 /* Return a use_operand_p pointer for argument I of phinode PHI.  */
591 static inline use_operand_p
592 get_phi_arg_def_ptr (tree phi, int i)
593 {
594   return &(PHI_ARG_IMM_USE_NODE (phi,i));
595 }
596
597 /* Delink all immediate_use information for STMT.  */
598 static inline void
599 delink_stmt_imm_use (tree stmt)
600 {
601    unsigned int x;
602    use_optype uses = STMT_USE_OPS (stmt);
603    vuse_optype vuses = STMT_VUSE_OPS (stmt);
604    v_may_def_optype v_may_defs = STMT_V_MAY_DEF_OPS (stmt);
605    v_must_def_optype v_must_defs = STMT_V_MUST_DEF_OPS (stmt);
606
607    for (x = 0; x < NUM_USES (uses); x++)
608      delink_imm_use (&(uses->uses[x]));
609
610    for (x = 0; x < NUM_VUSES (vuses); x++)
611      delink_imm_use (&(vuses->vuses[x].imm_use));
612
613    for (x = 0; x < NUM_V_MAY_DEFS (v_may_defs); x++)
614      delink_imm_use (&(v_may_defs->v_may_defs[x].imm_use));
615
616    for (x = 0; x < NUM_V_MUST_DEFS (v_must_defs); x++)
617      delink_imm_use (&(v_must_defs->v_must_defs[x].imm_use));
618 }
619
620
621 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
622    no addresses.  */
623 static inline bitmap
624 addresses_taken (tree stmt)
625 {
626   stmt_ann_t ann = stmt_ann (stmt);
627   return ann ? ann->addresses_taken : NULL;
628 }
629
630 /* Return the basic_block annotation for BB.  */
631 static inline bb_ann_t
632 bb_ann (basic_block bb)
633 {
634   return (bb_ann_t)bb->tree_annotations;
635 }
636
637 /* Return the PHI nodes for basic block BB, or NULL if there are no
638    PHI nodes.  */
639 static inline tree
640 phi_nodes (basic_block bb)
641 {
642   return bb_ann (bb)->phi_nodes;
643 }
644
645 /* Set list of phi nodes of a basic block BB to L.  */
646
647 static inline void
648 set_phi_nodes (basic_block bb, tree l)
649 {
650   tree phi;
651
652   bb_ann (bb)->phi_nodes = l;
653   for (phi = l; phi; phi = PHI_CHAIN (phi))
654     set_bb_for_stmt (phi, bb);
655 }
656
657 /* Return the phi argument which contains the specified use.  */
658
659 static inline int
660 phi_arg_index_from_use (use_operand_p use)
661 {
662   struct phi_arg_d *element, *root;
663   int index;
664   tree phi;
665
666   /* Since the use is the first thing in a PHI argument element, we can
667      calculate its index based on casting it to an argument, and performing
668      pointer arithmetic.  */
669
670   phi = USE_STMT (use);
671   gcc_assert (TREE_CODE (phi) == PHI_NODE);
672
673   element = (struct phi_arg_d *)use;
674   root = &(PHI_ARG_ELT (phi, 0));
675   index = element - root;
676
677 #ifdef ENABLE_CHECKING
678   /* Make sure the calculation doesn't have any leftover bytes.  If it does, 
679      then imm_use is likely not the first element in phi_arg_d.  */
680   gcc_assert (
681           (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
682   gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
683 #endif
684  
685  return index;
686 }
687
688 /* Mark VAR as used, so that it'll be preserved during rtl expansion.  */
689
690 static inline void
691 set_is_used (tree var)
692 {
693   var_ann_t ann = get_var_ann (var);
694   ann->used = 1;
695 }
696
697
698 /*  -----------------------------------------------------------------------  */
699
700 /* Return true if T is an executable statement.  */
701 static inline bool
702 is_exec_stmt (tree t)
703 {
704   return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
705 }
706
707
708 /* Return true if this stmt can be the target of a control transfer stmt such
709    as a goto.  */
710 static inline bool
711 is_label_stmt (tree t)
712 {
713   if (t)
714     switch (TREE_CODE (t))
715       {
716         case LABEL_DECL:
717         case LABEL_EXPR:
718         case CASE_LABEL_EXPR:
719           return true;
720         default:
721           return false;
722       }
723   return false;
724 }
725
726 /* Set the default definition for VAR to DEF.  */
727 static inline void
728 set_default_def (tree var, tree def)
729 {
730   var_ann_t ann = get_var_ann (var);
731   ann->default_def = def;
732 }
733
734 /* Return the default definition for variable VAR, or NULL if none
735    exists.  */
736 static inline tree
737 default_def (tree var)
738 {
739   var_ann_t ann = var_ann (var);
740   return ann ? ann->default_def : NULL_TREE;
741 }
742
743 /* PHI nodes should contain only ssa_names and invariants.  A test
744    for ssa_name is definitely simpler; don't let invalid contents
745    slip in in the meantime.  */
746
747 static inline bool
748 phi_ssa_name_p (tree t)
749 {
750   if (TREE_CODE (t) == SSA_NAME)
751     return true;
752 #ifdef ENABLE_CHECKING
753   gcc_assert (is_gimple_min_invariant (t));
754 #endif
755   return false;
756 }
757
758 /*  -----------------------------------------------------------------------  */
759
760 /* Return a block_stmt_iterator that points to beginning of basic
761    block BB.  */
762 static inline block_stmt_iterator
763 bsi_start (basic_block bb)
764 {
765   block_stmt_iterator bsi;
766   if (bb->stmt_list)
767     bsi.tsi = tsi_start (bb->stmt_list);
768   else
769     {
770       gcc_assert (bb->index < 0);
771       bsi.tsi.ptr = NULL;
772       bsi.tsi.container = NULL;
773     }
774   bsi.bb = bb;
775   return bsi;
776 }
777
778 /* Return a block statement iterator that points to the last label in
779    block BB.  */
780
781 static inline block_stmt_iterator
782 bsi_after_labels (basic_block bb)
783 {
784   block_stmt_iterator bsi;
785   tree_stmt_iterator next;
786
787   bsi.bb = bb;
788
789   if (!bb->stmt_list)
790     {
791       gcc_assert (bb->index < 0);
792       bsi.tsi.ptr = NULL;
793       bsi.tsi.container = NULL;
794       return bsi;
795     }
796
797   bsi.tsi = tsi_start (bb->stmt_list);
798   if (tsi_end_p (bsi.tsi))
799     return bsi;
800
801   /* Ensure that there are some labels.  The rationale is that we want
802      to insert after the bsi that is returned, and these insertions should
803      be placed at the start of the basic block.  This would not work if the
804      first statement was not label; rather fail here than enable the user
805      proceed in wrong way.  */
806   gcc_assert (TREE_CODE (tsi_stmt (bsi.tsi)) == LABEL_EXPR);
807
808   next = bsi.tsi;
809   tsi_next (&next);
810
811   while (!tsi_end_p (next)
812          && TREE_CODE (tsi_stmt (next)) == LABEL_EXPR)
813     {
814       bsi.tsi = next;
815       tsi_next (&next);
816     }
817
818   return bsi;
819 }
820
821 /* Return a block statement iterator that points to the end of basic
822    block BB.  */
823 static inline block_stmt_iterator
824 bsi_last (basic_block bb)
825 {
826   block_stmt_iterator bsi;
827   if (bb->stmt_list)
828     bsi.tsi = tsi_last (bb->stmt_list);
829   else
830     {
831       gcc_assert (bb->index < 0);
832       bsi.tsi.ptr = NULL;
833       bsi.tsi.container = NULL;
834     }
835   bsi.bb = bb;
836   return bsi;
837 }
838
839 /* Return true if block statement iterator I has reached the end of
840    the basic block.  */
841 static inline bool
842 bsi_end_p (block_stmt_iterator i)
843 {
844   return tsi_end_p (i.tsi);
845 }
846
847 /* Modify block statement iterator I so that it is at the next
848    statement in the basic block.  */
849 static inline void
850 bsi_next (block_stmt_iterator *i)
851 {
852   tsi_next (&i->tsi);
853 }
854
855 /* Modify block statement iterator I so that it is at the previous
856    statement in the basic block.  */
857 static inline void
858 bsi_prev (block_stmt_iterator *i)
859 {
860   tsi_prev (&i->tsi);
861 }
862
863 /* Return the statement that block statement iterator I is currently
864    at.  */
865 static inline tree
866 bsi_stmt (block_stmt_iterator i)
867 {
868   return tsi_stmt (i.tsi);
869 }
870
871 /* Return a pointer to the statement that block statement iterator I
872    is currently at.  */
873 static inline tree *
874 bsi_stmt_ptr (block_stmt_iterator i)
875 {
876   return tsi_stmt_ptr (i.tsi);
877 }
878
879 /* Returns the loop of the statement STMT.  */
880
881 static inline struct loop *
882 loop_containing_stmt (tree stmt)
883 {
884   basic_block bb = bb_for_stmt (stmt);
885   if (!bb)
886     return NULL;
887
888   return bb->loop_father;
889 }
890
891 /* Return true if VAR is a clobbered by function calls.  */
892 static inline bool
893 is_call_clobbered (tree var)
894 {
895   return is_global_var (var)
896          || bitmap_bit_p (call_clobbered_vars, var_ann (var)->uid);
897 }
898
899 /* Mark variable VAR as being clobbered by function calls.  */
900 static inline void
901 mark_call_clobbered (tree var)
902 {
903   var_ann_t ann = var_ann (var);
904   /* If VAR is a memory tag, then we need to consider it a global
905      variable.  This is because the pointer that VAR represents has
906      been found to point to either an arbitrary location or to a known
907      location in global memory.  */
908   if (ann->mem_tag_kind != NOT_A_TAG && ann->mem_tag_kind != STRUCT_FIELD)
909     DECL_EXTERNAL (var) = 1;
910   bitmap_set_bit (call_clobbered_vars, ann->uid);
911   ssa_call_clobbered_cache_valid = false;
912   ssa_ro_call_cache_valid = false;
913 }
914
915 /* Clear the call-clobbered attribute from variable VAR.  */
916 static inline void
917 clear_call_clobbered (tree var)
918 {
919   var_ann_t ann = var_ann (var);
920   if (ann->mem_tag_kind != NOT_A_TAG && ann->mem_tag_kind != STRUCT_FIELD)
921     DECL_EXTERNAL (var) = 0;
922   bitmap_clear_bit (call_clobbered_vars, ann->uid);
923   ssa_call_clobbered_cache_valid = false;
924   ssa_ro_call_cache_valid = false;
925 }
926
927 /* Mark variable VAR as being non-addressable.  */
928 static inline void
929 mark_non_addressable (tree var)
930 {
931   bitmap_clear_bit (call_clobbered_vars, var_ann (var)->uid);
932   TREE_ADDRESSABLE (var) = 0;
933   ssa_call_clobbered_cache_valid = false;
934   ssa_ro_call_cache_valid = false;
935 }
936
937 /* Return the common annotation for T.  Return NULL if the annotation
938    doesn't already exist.  */
939 static inline tree_ann_t
940 tree_ann (tree t)
941 {
942   return t->common.ann;
943 }
944
945 /* Return a common annotation for T.  Create the constant annotation if it
946    doesn't exist.  */
947 static inline tree_ann_t
948 get_tree_ann (tree t)
949 {
950   tree_ann_t ann = tree_ann (t);
951   return (ann) ? ann : create_tree_ann (t);
952 }
953
954 /*  -----------------------------------------------------------------------  */
955
956 /* The following set of routines are used to iterator over various type of
957    SSA operands.  */
958
959 /* Return true if PTR is finished iterating.  */
960 static inline bool
961 op_iter_done (ssa_op_iter *ptr)
962 {
963   return ptr->done;
964 }
965
966 /* Get the next iterator use value for PTR.  */
967 static inline use_operand_p
968 op_iter_next_use (ssa_op_iter *ptr)
969 {
970   if (ptr->use_i < ptr->num_use)
971     {
972       return USE_OP_PTR (ptr->ops->use_ops, (ptr->use_i)++);
973     }
974   if (ptr->vuse_i < ptr->num_vuse)
975     {
976       return VUSE_OP_PTR (ptr->ops->vuse_ops, (ptr->vuse_i)++);
977     }
978   if (ptr->v_mayu_i < ptr->num_v_mayu)
979     {
980       return V_MAY_DEF_OP_PTR (ptr->ops->v_may_def_ops,
981                                (ptr->v_mayu_i)++);
982     }
983   if (ptr->v_mustu_i < ptr->num_v_mustu)
984     {
985       return V_MUST_DEF_KILL_PTR (ptr->ops->v_must_def_ops,
986                                   (ptr->v_mustu_i)++);
987     }
988   ptr->done = true;
989   return NULL_USE_OPERAND_P;
990 }
991
992 /* Get the next iterator def value for PTR.  */
993 static inline def_operand_p
994 op_iter_next_def (ssa_op_iter *ptr)
995 {
996   if (ptr->def_i < ptr->num_def)
997     {
998       return DEF_OP_PTR (ptr->ops->def_ops, (ptr->def_i)++);
999     }
1000   if (ptr->v_mustd_i < ptr->num_v_mustd)
1001     {
1002       return V_MUST_DEF_RESULT_PTR (ptr->ops->v_must_def_ops, 
1003                                         (ptr->v_mustd_i)++);
1004     }
1005   if (ptr->v_mayd_i < ptr->num_v_mayd)
1006     {
1007       return V_MAY_DEF_RESULT_PTR (ptr->ops->v_may_def_ops,
1008                                            (ptr->v_mayd_i)++);
1009     }
1010   ptr->done = true;
1011   return NULL_DEF_OPERAND_P;
1012 }
1013
1014 /* Get the next iterator tree value for PTR.  */
1015 static inline tree
1016 op_iter_next_tree (ssa_op_iter *ptr)
1017 {
1018   if (ptr->use_i < ptr->num_use)
1019     {
1020       return USE_OP (ptr->ops->use_ops, (ptr->use_i)++);
1021     }
1022   if (ptr->vuse_i < ptr->num_vuse)
1023     {
1024       return VUSE_OP (ptr->ops->vuse_ops, (ptr->vuse_i)++);
1025     }
1026   if (ptr->v_mayu_i < ptr->num_v_mayu)
1027     {
1028       return V_MAY_DEF_OP (ptr->ops->v_may_def_ops, (ptr->v_mayu_i)++);
1029     }
1030   if (ptr->v_mustu_i < ptr->num_v_mustu)
1031     {
1032       return V_MUST_DEF_KILL (ptr->ops->v_must_def_ops, (ptr->v_mustu_i)++);
1033     }
1034   if (ptr->def_i < ptr->num_def)
1035     {
1036       return DEF_OP (ptr->ops->def_ops, (ptr->def_i)++);
1037     }
1038   if (ptr->v_mustd_i < ptr->num_v_mustd)
1039     {
1040       return V_MUST_DEF_RESULT (ptr->ops->v_must_def_ops, 
1041                                         (ptr->v_mustd_i)++);
1042     }
1043   if (ptr->v_mayd_i < ptr->num_v_mayd)
1044     {
1045       return V_MAY_DEF_RESULT (ptr->ops->v_may_def_ops,
1046                                            (ptr->v_mayd_i)++);
1047     }
1048   ptr->done = true;
1049   return NULL;
1050 }
1051
1052 /* Initialize the iterator PTR to the virtual defs in STMT.  */
1053 static inline void
1054 op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
1055 {
1056   stmt_operands_p ops;
1057   stmt_ann_t ann = get_stmt_ann (stmt);
1058
1059   ops = &(ann->operands);
1060   ptr->done = false;
1061   ptr->ops = ops;
1062   ptr->num_def = (flags & SSA_OP_DEF) ? NUM_DEFS (ops->def_ops) : 0;
1063   ptr->num_use = (flags & SSA_OP_USE) ? NUM_USES (ops->use_ops) : 0;
1064   ptr->num_vuse = (flags & SSA_OP_VUSE) ? NUM_VUSES (ops->vuse_ops) : 0;
1065   ptr->num_v_mayu = (flags & SSA_OP_VMAYUSE)
1066                      ?  NUM_V_MAY_DEFS (ops->v_may_def_ops) : 0;
1067   ptr->num_v_mayd = (flags & SSA_OP_VMAYDEF) 
1068                      ?  NUM_V_MAY_DEFS (ops->v_may_def_ops) : 0;
1069   ptr->num_v_mustu = (flags & SSA_OP_VMUSTDEFKILL)
1070                      ? NUM_V_MUST_DEFS (ops->v_must_def_ops) : 0;
1071   ptr->num_v_mustd = (flags & SSA_OP_VMUSTDEF) 
1072                      ? NUM_V_MUST_DEFS (ops->v_must_def_ops) : 0;
1073   ptr->def_i = 0;
1074   ptr->use_i = 0;
1075   ptr->vuse_i = 0;
1076   ptr->v_mayu_i = 0;
1077   ptr->v_mayd_i = 0;
1078   ptr->v_mustu_i = 0;
1079   ptr->v_mustd_i = 0;
1080 }
1081
1082 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1083    the first use.  */
1084 static inline use_operand_p
1085 op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
1086 {
1087   op_iter_init (ptr, stmt, flags);
1088   return op_iter_next_use (ptr);
1089 }
1090
1091 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1092    the first def.  */
1093 static inline def_operand_p
1094 op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1095 {
1096   op_iter_init (ptr, stmt, flags);
1097   return op_iter_next_def (ptr);
1098 }
1099
1100 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1101    the first operand as a tree.  */
1102 static inline tree
1103 op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1104 {
1105   op_iter_init (ptr, stmt, flags);
1106   return op_iter_next_tree (ptr);
1107 }
1108
1109 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1110    KILL and DEF.  */
1111 static inline void
1112 op_iter_next_mustdef (use_operand_p *kill, def_operand_p *def, ssa_op_iter *ptr)
1113 {
1114   if (ptr->v_mustu_i < ptr->num_v_mustu)
1115     {
1116       *def = V_MUST_DEF_RESULT_PTR (ptr->ops->v_must_def_ops, ptr->v_mustu_i);
1117       *kill = V_MUST_DEF_KILL_PTR (ptr->ops->v_must_def_ops, (ptr->v_mustu_i)++);
1118       return;
1119     }
1120   else
1121     {
1122       *def = NULL_DEF_OPERAND_P;
1123       *kill = NULL_USE_OPERAND_P;
1124     }
1125   ptr->done = true;
1126   return;
1127 }
1128 /* Get the next iterator maydef value for PTR, returning the maydef values in
1129    USE and DEF.  */
1130 static inline void
1131 op_iter_next_maydef (use_operand_p *use, def_operand_p *def, ssa_op_iter *ptr)
1132 {
1133   if (ptr->v_mayu_i < ptr->num_v_mayu)
1134     {
1135       *def = V_MAY_DEF_RESULT_PTR (ptr->ops->v_may_def_ops, ptr->v_mayu_i);
1136       *use = V_MAY_DEF_OP_PTR (ptr->ops->v_may_def_ops, (ptr->v_mayu_i)++);
1137       return;
1138     }
1139   else
1140     {
1141       *def = NULL_DEF_OPERAND_P;
1142       *use = NULL_USE_OPERAND_P;
1143     }
1144   ptr->done = true;
1145   return;
1146 }
1147
1148 /* Initialize iterator PTR to the operands in STMT.  Return the first operands
1149    in USE and DEF.  */
1150 static inline void
1151 op_iter_init_maydef (ssa_op_iter *ptr, tree stmt, use_operand_p *use, 
1152                      def_operand_p *def)
1153 {
1154   op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1155   op_iter_next_maydef (use, def, ptr);
1156 }
1157
1158 /* Return true if VAR cannot be modified by the program.  */
1159
1160 static inline bool
1161 unmodifiable_var_p (tree var)
1162 {
1163   if (TREE_CODE (var) == SSA_NAME)
1164     var = SSA_NAME_VAR (var);
1165   return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1166 }
1167
1168
1169 /* Initialize iterator PTR to the operands in STMT.  Return the first operands
1170    in KILL and DEF.  */
1171 static inline void
1172 op_iter_init_mustdef (ssa_op_iter *ptr, tree stmt, use_operand_p *kill, 
1173                      def_operand_p *def)
1174 {
1175   op_iter_init (ptr, stmt, SSA_OP_VMUSTDEFKILL);
1176   op_iter_next_mustdef (kill, def, ptr);
1177 }
1178
1179 /* Return true if REF, a COMPONENT_REF, has an ARRAY_REF somewhere in it.  */
1180
1181 static inline bool
1182 ref_contains_array_ref (tree ref)
1183 {
1184   while (handled_component_p (ref))
1185     {
1186       if (TREE_CODE (ref) == ARRAY_REF)
1187         return true;
1188       ref = TREE_OPERAND (ref, 0);
1189     }
1190   return false;
1191 }
1192
1193 /* Given a variable VAR, lookup and return a pointer to the list of
1194    subvariables for it.  */
1195
1196 static inline subvar_t *
1197 lookup_subvars_for_var (tree var)
1198 {
1199   var_ann_t ann = var_ann (var);
1200   gcc_assert (ann);
1201   return &ann->subvars;
1202 }
1203
1204 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1205    NULL, if there are no subvariables.  */
1206
1207 static inline subvar_t
1208 get_subvars_for_var (tree var)
1209 {
1210   subvar_t subvars;
1211
1212   gcc_assert (SSA_VAR_P (var));  
1213   
1214   if (TREE_CODE (var) == SSA_NAME)
1215     subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
1216   else
1217     subvars = *(lookup_subvars_for_var (var));
1218   return subvars;
1219 }
1220
1221 /* Return true if V is a tree that we can have subvars for.
1222    Normally, this is any aggregate type, however, due to implementation
1223    limitations ATM, we exclude array types as well.  */
1224
1225 static inline bool
1226 var_can_have_subvars (tree v)
1227 {
1228   return (AGGREGATE_TYPE_P (TREE_TYPE (v)) &&
1229           TREE_CODE (TREE_TYPE (v)) != ARRAY_TYPE);
1230 }
1231
1232   
1233 /* Return true if OFFSET and SIZE define a range that overlaps with some
1234    portion of the range of SV, a subvar.  If there was an exact overlap,
1235    *EXACT will be set to true upon return. */
1236
1237 static inline bool
1238 overlap_subvar (HOST_WIDE_INT offset, HOST_WIDE_INT size,
1239                 subvar_t sv,  bool *exact)
1240 {
1241   /* There are three possible cases of overlap.
1242      1. We can have an exact overlap, like so:   
1243      |offset, offset + size             |
1244      |sv->offset, sv->offset + sv->size |
1245      
1246      2. We can have offset starting after sv->offset, like so:
1247      
1248            |offset, offset + size              |
1249      |sv->offset, sv->offset + sv->size  |
1250
1251      3. We can have offset starting before sv->offset, like so:
1252      
1253      |offset, offset + size    |
1254        |sv->offset, sv->offset + sv->size|
1255   */
1256
1257   if (exact)
1258     *exact = false;
1259   if (offset == sv->offset && size == sv->size)
1260     {
1261       if (exact)
1262         *exact = true;
1263       return true;
1264     }
1265   else if (offset >= sv->offset && offset < (sv->offset + sv->size))
1266     {
1267       return true;
1268     }
1269   else if (offset < sv->offset && (offset + size > sv->offset))
1270     {
1271       return true;
1272     }
1273   return false;
1274
1275 }
1276
1277 #endif /* _TREE_FLOW_INLINE_H  */