OSDN Git Service

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