OSDN Git Service

* config/avr/avr.md (UNSPECV_WRITE_SP_IRQ_ON): New constants.
[pf3gnuchains/gcc-fork.git] / gcc / tree-flow-inline.h
1 /* Inline functions for tree-flow.h
2    Copyright (C) 2001, 2003, 2005, 2006, 2007 Free Software Foundation, Inc.
3    Contributed by Diego Novillo <dnovillo@redhat.com>
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3.  If not see
19 <http://www.gnu.org/licenses/>.  */
20
21 #ifndef _TREE_FLOW_INLINE_H
22 #define _TREE_FLOW_INLINE_H 1
23
24 /* Inline functions for manipulating various data structures defined in
25    tree-flow.h.  See tree-flow.h for documentation.  */
26
27 /* Return true when gimple SSA form was built.
28    gimple_in_ssa_p is queried by gimplifier in various early stages before SSA
29    infrastructure is initialized.  Check for presence of the datastructures
30    at first place.  */
31 static inline bool
32 gimple_in_ssa_p (const struct function *fun)
33 {
34   return fun && fun->gimple_df && fun->gimple_df->in_ssa_p;
35 }
36
37 /* 'true' after aliases have been computed (see compute_may_aliases).  */
38 static inline bool
39 gimple_aliases_computed_p (const struct function *fun)
40 {
41   gcc_assert (fun && fun->gimple_df);
42   return fun->gimple_df->aliases_computed_p;
43 }
44
45 /* Addressable variables in the function.  If bit I is set, then
46    REFERENCED_VARS (I) has had its address taken.  Note that
47    CALL_CLOBBERED_VARS and ADDRESSABLE_VARS are not related.  An
48    addressable variable is not necessarily call-clobbered (e.g., a
49    local addressable whose address does not escape) and not all
50    call-clobbered variables are addressable (e.g., a local static
51    variable).  */
52 static inline bitmap
53 gimple_addressable_vars (const struct function *fun)
54 {
55   gcc_assert (fun && fun->gimple_df);
56   return fun->gimple_df->addressable_vars;
57 }
58
59 /* Call clobbered variables in the function.  If bit I is set, then
60    REFERENCED_VARS (I) is call-clobbered.  */
61 static inline bitmap
62 gimple_call_clobbered_vars (const struct function *fun)
63 {
64   gcc_assert (fun && fun->gimple_df);
65   return fun->gimple_df->call_clobbered_vars;
66 }
67
68 /* Array of all variables referenced in the function.  */
69 static inline htab_t
70 gimple_referenced_vars (const struct function *fun)
71 {
72   if (!fun->gimple_df)
73     return NULL;
74   return fun->gimple_df->referenced_vars;
75 }
76
77 /* Artificial variable used to model the effects of function calls.  */
78 static inline tree
79 gimple_global_var (const struct function *fun)
80 {
81   gcc_assert (fun && fun->gimple_df);
82   return fun->gimple_df->global_var;
83 }
84
85 /* Artificial variable used to model the effects of nonlocal
86    variables.  */
87 static inline tree
88 gimple_nonlocal_all (const struct function *fun)
89 {
90   gcc_assert (fun && fun->gimple_df);
91   return fun->gimple_df->nonlocal_all;
92 }
93
94 /* Initialize the hashtable iterator HTI to point to hashtable TABLE */
95
96 static inline void *
97 first_htab_element (htab_iterator *hti, htab_t table)
98 {
99   hti->htab = table;
100   hti->slot = table->entries;
101   hti->limit = hti->slot + htab_size (table);
102   do
103     {
104       PTR x = *(hti->slot);
105       if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
106         break;
107     } while (++(hti->slot) < hti->limit);
108   
109   if (hti->slot < hti->limit)
110     return *(hti->slot);
111   return NULL;
112 }
113
114 /* Return current non-empty/deleted slot of the hashtable pointed to by HTI,
115    or NULL if we have  reached the end.  */
116
117 static inline bool
118 end_htab_p (const htab_iterator *hti)
119 {
120   if (hti->slot >= hti->limit)
121     return true;
122   return false;
123 }
124
125 /* Advance the hashtable iterator pointed to by HTI to the next element of the
126    hashtable.  */
127
128 static inline void *
129 next_htab_element (htab_iterator *hti)
130 {
131   while (++(hti->slot) < hti->limit)
132     {
133       PTR x = *(hti->slot);
134       if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
135         return x;
136     };
137   return NULL;
138 }
139
140 /* Initialize ITER to point to the first referenced variable in the
141    referenced_vars hashtable, and return that variable.  */
142
143 static inline tree
144 first_referenced_var (referenced_var_iterator *iter)
145 {
146   return (tree) first_htab_element (&iter->hti,
147                                     gimple_referenced_vars (cfun));
148 }
149
150 /* Return true if we have hit the end of the referenced variables ITER is
151    iterating through.  */
152
153 static inline bool
154 end_referenced_vars_p (const referenced_var_iterator *iter)
155 {
156   return end_htab_p (&iter->hti);
157 }
158
159 /* Make ITER point to the next referenced_var in the referenced_var hashtable,
160    and return that variable.  */
161
162 static inline tree
163 next_referenced_var (referenced_var_iterator *iter)
164 {
165   return (tree) next_htab_element (&iter->hti);
166
167
168 /* Fill up VEC with the variables in the referenced vars hashtable.  */
169
170 static inline void
171 fill_referenced_var_vec (VEC (tree, heap) **vec)
172 {
173   referenced_var_iterator rvi;
174   tree var;
175   *vec = NULL;
176   FOR_EACH_REFERENCED_VAR (var, rvi)
177     VEC_safe_push (tree, heap, *vec, var);
178 }
179
180 /* Return the variable annotation for T, which must be a _DECL node.
181    Return NULL if the variable annotation doesn't already exist.  */
182 static inline var_ann_t
183 var_ann (const_tree t)
184 {
185   var_ann_t ann;
186
187   if (!t->base.ann)
188     return NULL;
189   ann = (var_ann_t) t->base.ann;
190
191   gcc_assert (ann->common.type == VAR_ANN);
192
193   return ann;
194 }
195
196 /* Return the variable annotation for T, which must be a _DECL node.
197    Create the variable annotation if it doesn't exist.  */
198 static inline var_ann_t
199 get_var_ann (tree var)
200 {
201   var_ann_t ann = var_ann (var);
202   return (ann) ? ann : create_var_ann (var);
203 }
204
205 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
206    Return NULL if the function annotation doesn't already exist.  */
207 static inline function_ann_t
208 function_ann (const_tree t)
209 {
210   gcc_assert (t);
211   gcc_assert (TREE_CODE (t) == FUNCTION_DECL);
212   gcc_assert (!t->base.ann
213               || t->base.ann->common.type == FUNCTION_ANN);
214
215   return (function_ann_t) t->base.ann;
216 }
217
218 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
219    Create the function annotation if it doesn't exist.  */
220 static inline function_ann_t
221 get_function_ann (tree var)
222 {
223   function_ann_t ann = function_ann (var);
224   gcc_assert (!var->base.ann || var->base.ann->common.type == FUNCTION_ANN);
225   return (ann) ? ann : create_function_ann (var);
226 }
227
228 /* Return true if T has a statement annotation attached to it.  */
229
230 static inline bool
231 has_stmt_ann (tree t)
232 {
233 #ifdef ENABLE_CHECKING
234   gcc_assert (is_gimple_stmt (t));
235 #endif
236   return t->base.ann && t->base.ann->common.type == STMT_ANN;
237 }
238
239 /* Return the statement annotation for T, which must be a statement
240    node.  Return NULL if the statement annotation doesn't exist.  */
241 static inline stmt_ann_t
242 stmt_ann (tree t)
243 {
244 #ifdef ENABLE_CHECKING
245   gcc_assert (is_gimple_stmt (t));
246 #endif
247   gcc_assert (!t->base.ann || t->base.ann->common.type == STMT_ANN);
248   return (stmt_ann_t) t->base.ann;
249 }
250
251 /* Return the statement annotation for T, which must be a statement
252    node.  Create the statement annotation if it doesn't exist.  */
253 static inline stmt_ann_t
254 get_stmt_ann (tree stmt)
255 {
256   stmt_ann_t ann = stmt_ann (stmt);
257   return (ann) ? ann : create_stmt_ann (stmt);
258 }
259
260 /* Set the uid of all non phi function statements.  */
261 static inline void
262 set_gimple_stmt_uid (tree stmt, unsigned int uid)
263 {
264   get_stmt_ann (stmt)->uid = uid;
265 }
266
267 /* Get the uid of all non phi function statements.  */
268 static inline unsigned int
269 gimple_stmt_uid (tree stmt)
270 {
271   return get_stmt_ann (stmt)->uid;
272 }
273
274 /* Get the number of the next statement uid to be allocated.  */
275 static inline unsigned int
276 gimple_stmt_max_uid (struct function *fn)
277 {
278   return fn->last_stmt_uid;
279 }
280
281 /* Set the number of the next statement uid to be allocated.  */
282 static inline void
283 set_gimple_stmt_max_uid (struct function *fn, unsigned int maxid)
284 {
285   fn->last_stmt_uid = maxid;
286 }
287
288 /* Set the number of the next statement uid to be allocated.  */
289 static inline unsigned int
290 inc_gimple_stmt_max_uid (struct function *fn)
291 {
292   return fn->last_stmt_uid++;
293 }
294
295 /* Return the annotation type for annotation ANN.  */
296 static inline enum tree_ann_type
297 ann_type (tree_ann_t ann)
298 {
299   return ann->common.type;
300 }
301
302 /* Return the basic block for statement T.  */
303 static inline basic_block
304 bb_for_stmt (tree t)
305 {
306   stmt_ann_t ann;
307
308   if (TREE_CODE (t) == PHI_NODE)
309     return PHI_BB (t);
310
311   ann = stmt_ann (t);
312   return ann ? ann->bb : NULL;
313 }
314
315 /* Return the may_aliases bitmap for variable VAR, or NULL if it has
316    no may aliases.  */
317 static inline bitmap
318 may_aliases (const_tree var)
319 {
320   return MTAG_ALIASES (var);
321 }
322
323 /* Return the line number for EXPR, or return -1 if we have no line
324    number information for it.  */
325 static inline int
326 get_lineno (const_tree expr)
327 {
328   if (expr == NULL_TREE)
329     return -1;
330
331   if (TREE_CODE (expr) == COMPOUND_EXPR)
332     expr = TREE_OPERAND (expr, 0);
333
334   if (! EXPR_HAS_LOCATION (expr))
335     return -1;
336
337   return EXPR_LINENO (expr);
338 }
339
340 /* Return true if T is a noreturn call.  */
341 static inline bool
342 noreturn_call_p (tree t)
343 {
344   tree call = get_call_expr_in (t);
345   return call != 0 && (call_expr_flags (call) & ECF_NORETURN) != 0;
346 }
347
348 /* Mark statement T as modified.  */
349 static inline void
350 mark_stmt_modified (tree t)
351 {
352   stmt_ann_t ann;
353   if (TREE_CODE (t) == PHI_NODE)
354     return;
355
356   ann = stmt_ann (t);
357   if (ann == NULL)
358     ann = create_stmt_ann (t);
359   else if (noreturn_call_p (t) && cfun->gimple_df)
360     VEC_safe_push (tree, gc, MODIFIED_NORETURN_CALLS (cfun), t);
361   ann->modified = 1;
362 }
363
364 /* Mark statement T as modified, and update it.  */
365 static inline void
366 update_stmt (tree t)
367 {
368   if (TREE_CODE (t) == PHI_NODE)
369     return;
370   mark_stmt_modified (t);
371   update_stmt_operands (t);
372 }
373
374 static inline void
375 update_stmt_if_modified (tree t)
376 {
377   if (stmt_modified_p (t))
378     update_stmt_operands (t);
379 }
380
381 /* Return true if T is marked as modified, false otherwise.  */
382 static inline bool
383 stmt_modified_p (tree t)
384 {
385   stmt_ann_t ann = stmt_ann (t);
386
387   /* Note that if the statement doesn't yet have an annotation, we consider it
388      modified.  This will force the next call to update_stmt_operands to scan 
389      the statement.  */
390   return ann ? ann->modified : true;
391 }
392
393 /* Delink an immediate_uses node from its chain.  */
394 static inline void
395 delink_imm_use (ssa_use_operand_t *linknode)
396 {
397   /* Return if this node is not in a list.  */
398   if (linknode->prev == NULL)
399     return;
400
401   linknode->prev->next = linknode->next;
402   linknode->next->prev = linknode->prev;
403   linknode->prev = NULL;
404   linknode->next = NULL;
405 }
406
407 /* Link ssa_imm_use node LINKNODE into the chain for LIST.  */
408 static inline void
409 link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
410 {
411   /* Link the new node at the head of the list.  If we are in the process of 
412      traversing the list, we won't visit any new nodes added to it.  */
413   linknode->prev = list;
414   linknode->next = list->next;
415   list->next->prev = linknode;
416   list->next = linknode;
417 }
418
419 /* Link ssa_imm_use node LINKNODE into the chain for DEF.  */
420 static inline void
421 link_imm_use (ssa_use_operand_t *linknode, tree def)
422 {
423   ssa_use_operand_t *root;
424
425   if (!def || TREE_CODE (def) != SSA_NAME)
426     linknode->prev = NULL;
427   else
428     {
429       root = &(SSA_NAME_IMM_USE_NODE (def));
430 #ifdef ENABLE_CHECKING
431       if (linknode->use)
432         gcc_assert (*(linknode->use) == def);
433 #endif
434       link_imm_use_to_list (linknode, root);
435     }
436 }
437
438 /* Set the value of a use pointed to by USE to VAL.  */
439 static inline void
440 set_ssa_use_from_ptr (use_operand_p use, tree val)
441 {
442   delink_imm_use (use);
443   *(use->use) = val;
444   link_imm_use (use, val);
445 }
446
447 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring 
448    in STMT.  */
449 static inline void
450 link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, tree stmt)
451 {
452   if (stmt)
453     link_imm_use (linknode, def);
454   else
455     link_imm_use (linknode, NULL);
456   linknode->stmt = stmt;
457 }
458
459 /* Relink a new node in place of an old node in the list.  */
460 static inline void
461 relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
462 {
463   /* The node one had better be in the same list.  */
464   gcc_assert (*(old->use) == *(node->use));
465   node->prev = old->prev;
466   node->next = old->next;
467   if (old->prev)
468     {
469       old->prev->next = node;
470       old->next->prev = node;
471       /* Remove the old node from the list.  */
472       old->prev = NULL;
473     }
474 }
475
476 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring 
477    in STMT.  */
478 static inline void
479 relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old, tree stmt)
480 {
481   if (stmt)
482     relink_imm_use (linknode, old);
483   else
484     link_imm_use (linknode, NULL);
485   linknode->stmt = stmt;
486 }
487
488
489 /* Return true is IMM has reached the end of the immediate use list.  */
490 static inline bool
491 end_readonly_imm_use_p (const imm_use_iterator *imm)
492 {
493   return (imm->imm_use == imm->end_p);
494 }
495
496 /* Initialize iterator IMM to process the list for VAR.  */
497 static inline use_operand_p
498 first_readonly_imm_use (imm_use_iterator *imm, tree var)
499 {
500   gcc_assert (TREE_CODE (var) == SSA_NAME);
501
502   imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
503   imm->imm_use = imm->end_p->next;
504 #ifdef ENABLE_CHECKING
505   imm->iter_node.next = imm->imm_use->next;
506 #endif
507   if (end_readonly_imm_use_p (imm))
508     return NULL_USE_OPERAND_P;
509   return imm->imm_use;
510 }
511
512 /* Bump IMM to the next use in the list.  */
513 static inline use_operand_p
514 next_readonly_imm_use (imm_use_iterator *imm)
515 {
516   use_operand_p old = imm->imm_use;
517
518 #ifdef ENABLE_CHECKING
519   /* If this assertion fails, it indicates the 'next' pointer has changed
520      since the last bump.  This indicates that the list is being modified
521      via stmt changes, or SET_USE, or somesuch thing, and you need to be
522      using the SAFE version of the iterator.  */
523   gcc_assert (imm->iter_node.next == old->next);
524   imm->iter_node.next = old->next->next;
525 #endif
526
527   imm->imm_use = old->next;
528   if (end_readonly_imm_use_p (imm))
529     return NULL_USE_OPERAND_P;
530   return imm->imm_use;
531 }
532
533 /* Return true if VAR has no uses.  */
534 static inline bool
535 has_zero_uses (const_tree var)
536 {
537   const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
538   /* A single use means there is no items in the list.  */
539   return (ptr == ptr->next);
540 }
541
542 /* Return true if VAR has a single use.  */
543 static inline bool
544 has_single_use (const_tree var)
545 {
546   const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
547   /* A single use means there is one item in the list.  */
548   return (ptr != ptr->next && ptr == ptr->next->next);
549 }
550
551
552 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
553    to the use pointer and stmt of occurrence.  */
554 static inline bool
555 single_imm_use (const_tree var, use_operand_p *use_p, tree *stmt)
556 {
557   const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
558   if (ptr != ptr->next && ptr == ptr->next->next)
559     {
560       *use_p = ptr->next;
561       *stmt = ptr->next->stmt;
562       return true;
563     }
564   *use_p = NULL_USE_OPERAND_P;
565   *stmt = NULL_TREE;
566   return false;
567 }
568
569 /* Return the number of immediate uses of VAR.  */
570 static inline unsigned int
571 num_imm_uses (const_tree var)
572 {
573   const ssa_use_operand_t *const start = &(SSA_NAME_IMM_USE_NODE (var));
574   const ssa_use_operand_t *ptr;
575   unsigned int num = 0;
576
577   for (ptr = start->next; ptr != start; ptr = ptr->next)
578      num++;
579
580   return num;
581 }
582
583 /* Return the tree pointer to by USE.  */ 
584 static inline tree
585 get_use_from_ptr (use_operand_p use)
586
587   return *(use->use);
588
589
590 /* Return the tree pointer to by DEF.  */
591 static inline tree
592 get_def_from_ptr (def_operand_p def)
593 {
594   return *def;
595 }
596
597 /* Return a def_operand_p pointer for the result of PHI.  */
598 static inline def_operand_p
599 get_phi_result_ptr (tree phi)
600 {
601   return &(PHI_RESULT_TREE (phi));
602 }
603
604 /* Return a use_operand_p pointer for argument I of phinode PHI.  */
605 static inline use_operand_p
606 get_phi_arg_def_ptr (tree phi, int i)
607 {
608   return &(PHI_ARG_IMM_USE_NODE (phi,i));
609 }
610
611
612 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
613    no addresses.  */
614 static inline bitmap
615 addresses_taken (tree stmt)
616 {
617   stmt_ann_t ann = stmt_ann (stmt);
618   return ann ? ann->addresses_taken : NULL;
619 }
620
621 /* Return the PHI nodes for basic block BB, or NULL if there are no
622    PHI nodes.  */
623 static inline tree
624 phi_nodes (const_basic_block bb)
625 {
626   gcc_assert (!(bb->flags & BB_RTL));
627   if (!bb->il.tree)
628     return NULL;
629   return bb->il.tree->phi_nodes;
630 }
631
632 /* Return pointer to the list of PHI nodes for basic block BB.  */
633
634 static inline tree *
635 phi_nodes_ptr (basic_block bb)
636 {
637   gcc_assert (!(bb->flags & BB_RTL));
638   return &bb->il.tree->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   gcc_assert (!(bb->flags & BB_RTL));
649   bb->il.tree->phi_nodes = l;
650   for (phi = l; phi; phi = PHI_CHAIN (phi))
651     set_bb_for_stmt (phi, bb);
652 }
653
654 /* Return the phi argument which contains the specified use.  */
655
656 static inline int
657 phi_arg_index_from_use (use_operand_p use)
658 {
659   struct phi_arg_d *element, *root;
660   int index;
661   tree phi;
662
663   /* Since the use is the first thing in a PHI argument element, we can
664      calculate its index based on casting it to an argument, and performing
665      pointer arithmetic.  */
666
667   phi = USE_STMT (use);
668   gcc_assert (TREE_CODE (phi) == PHI_NODE);
669
670   element = (struct phi_arg_d *)use;
671   root = &(PHI_ARG_ELT (phi, 0));
672   index = element - root;
673
674 #ifdef ENABLE_CHECKING
675   /* Make sure the calculation doesn't have any leftover bytes.  If it does, 
676      then imm_use is likely not the first element in phi_arg_d.  */
677   gcc_assert (
678           (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
679   gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
680 #endif
681  
682  return index;
683 }
684
685 /* Mark VAR as used, so that it'll be preserved during rtl expansion.  */
686
687 static inline void
688 set_is_used (tree var)
689 {
690   var_ann_t ann = get_var_ann (var);
691   ann->used = 1;
692 }
693
694
695 /* Return true if T (assumed to be a DECL) is a global variable.  */
696
697 static inline bool
698 is_global_var (const_tree t)
699 {
700   if (MTAG_P (t))
701     return (TREE_STATIC (t) || MTAG_GLOBAL (t));
702   else
703     return (TREE_STATIC (t) || DECL_EXTERNAL (t));
704 }
705
706 /* PHI nodes should contain only ssa_names and invariants.  A test
707    for ssa_name is definitely simpler; don't let invalid contents
708    slip in in the meantime.  */
709
710 static inline bool
711 phi_ssa_name_p (const_tree t)
712 {
713   if (TREE_CODE (t) == SSA_NAME)
714     return true;
715 #ifdef ENABLE_CHECKING
716   gcc_assert (is_gimple_min_invariant (t));
717 #endif
718   return false;
719 }
720
721 /*  -----------------------------------------------------------------------  */
722
723 /* Returns the list of statements in BB.  */
724
725 static inline tree
726 bb_stmt_list (const_basic_block bb)
727 {
728   gcc_assert (!(bb->flags & BB_RTL));
729   return bb->il.tree->stmt_list;
730 }
731
732 /* Sets the list of statements in BB to LIST.  */
733
734 static inline void
735 set_bb_stmt_list (basic_block bb, tree list)
736 {
737   gcc_assert (!(bb->flags & BB_RTL));
738   bb->il.tree->stmt_list = list;
739 }
740
741 /* Return a block_stmt_iterator that points to beginning of basic
742    block BB.  */
743 static inline block_stmt_iterator
744 bsi_start (basic_block bb)
745 {
746   block_stmt_iterator bsi;
747   if (bb->index < NUM_FIXED_BLOCKS)
748     {
749       bsi.tsi.ptr = NULL;
750       bsi.tsi.container = NULL;
751     }
752   else
753     bsi.tsi = tsi_start (bb_stmt_list (bb));
754   bsi.bb = bb;
755   return bsi;
756 }
757
758 /* Return a block statement iterator that points to the first non-label
759    statement in block BB.  */
760
761 static inline block_stmt_iterator
762 bsi_after_labels (basic_block bb)
763 {
764   block_stmt_iterator bsi = bsi_start (bb);
765
766   while (!bsi_end_p (bsi) && TREE_CODE (bsi_stmt (bsi)) == LABEL_EXPR)
767     bsi_next (&bsi);
768
769   return bsi;
770 }
771
772 /* Return a block statement iterator that points to the end of basic
773    block BB.  */
774 static inline block_stmt_iterator
775 bsi_last (basic_block bb)
776 {
777   block_stmt_iterator bsi;
778
779   if (bb->index < NUM_FIXED_BLOCKS)
780     {
781       bsi.tsi.ptr = NULL;
782       bsi.tsi.container = NULL;
783     }
784   else
785     bsi.tsi = tsi_last (bb_stmt_list (bb));
786   bsi.bb = bb;
787   return bsi;
788 }
789
790 /* Return true if block statement iterator I has reached the end of
791    the basic block.  */
792 static inline bool
793 bsi_end_p (block_stmt_iterator i)
794 {
795   return tsi_end_p (i.tsi);
796 }
797
798 /* Modify block statement iterator I so that it is at the next
799    statement in the basic block.  */
800 static inline void
801 bsi_next (block_stmt_iterator *i)
802 {
803   tsi_next (&i->tsi);
804 }
805
806 /* Modify block statement iterator I so that it is at the previous
807    statement in the basic block.  */
808 static inline void
809 bsi_prev (block_stmt_iterator *i)
810 {
811   tsi_prev (&i->tsi);
812 }
813
814 /* Return the statement that block statement iterator I is currently
815    at.  */
816 static inline tree
817 bsi_stmt (block_stmt_iterator i)
818 {
819   return tsi_stmt (i.tsi);
820 }
821
822 /* Return a pointer to the statement that block statement iterator I
823    is currently at.  */
824 static inline tree *
825 bsi_stmt_ptr (block_stmt_iterator i)
826 {
827   return tsi_stmt_ptr (i.tsi);
828 }
829
830 /* Returns the loop of the statement STMT.  */
831
832 static inline struct loop *
833 loop_containing_stmt (tree stmt)
834 {
835   basic_block bb = bb_for_stmt (stmt);
836   if (!bb)
837     return NULL;
838
839   return bb->loop_father;
840 }
841
842
843 /* Return the memory partition tag associated with symbol SYM.  */
844
845 static inline tree
846 memory_partition (tree sym)
847 {
848   tree tag;
849
850   /* MPTs belong to their own partition.  */
851   if (TREE_CODE (sym) == MEMORY_PARTITION_TAG)
852     return sym;
853
854   gcc_assert (!is_gimple_reg (sym));
855   tag = get_var_ann (sym)->mpt;
856
857 #if defined ENABLE_CHECKING
858   if (tag)
859     gcc_assert (TREE_CODE (tag) == MEMORY_PARTITION_TAG);
860 #endif
861
862   return tag;
863 }
864
865 /* Return true if NAME is a memory factoring SSA name (i.e., an SSA
866    name for a memory partition.  */
867
868 static inline bool
869 factoring_name_p (const_tree name)
870 {
871   return TREE_CODE (SSA_NAME_VAR (name)) == MEMORY_PARTITION_TAG;
872 }
873
874 /* Return true if VAR is a clobbered by function calls.  */
875 static inline bool
876 is_call_clobbered (const_tree var)
877 {
878   if (!MTAG_P (var))
879     return var_ann (var)->call_clobbered;
880   else
881     return bitmap_bit_p (gimple_call_clobbered_vars (cfun), DECL_UID (var)); 
882 }
883
884 /* Mark variable VAR as being clobbered by function calls.  */
885 static inline void
886 mark_call_clobbered (tree var, unsigned int escape_type)
887 {
888   var_ann (var)->escape_mask |= escape_type;
889   if (!MTAG_P (var))
890     var_ann (var)->call_clobbered = true;
891   bitmap_set_bit (gimple_call_clobbered_vars (cfun), DECL_UID (var));
892 }
893
894 /* Clear the call-clobbered attribute from variable VAR.  */
895 static inline void
896 clear_call_clobbered (tree var)
897 {
898   var_ann_t ann = var_ann (var);
899   ann->escape_mask = 0;
900   if (MTAG_P (var))
901     MTAG_GLOBAL (var) = 0;
902   if (!MTAG_P (var))
903     var_ann (var)->call_clobbered = false;
904   bitmap_clear_bit (gimple_call_clobbered_vars (cfun), DECL_UID (var));
905 }
906
907 /* Return the common annotation for T.  Return NULL if the annotation
908    doesn't already exist.  */
909 static inline tree_ann_common_t
910 tree_common_ann (const_tree t)
911 {
912   /* Watch out static variables with unshared annotations.  */
913   if (DECL_P (t) && TREE_CODE (t) == VAR_DECL)
914     return &var_ann (t)->common;
915   return &t->base.ann->common;
916 }
917
918 /* Return a common annotation for T.  Create the constant annotation if it
919    doesn't exist.  */
920 static inline tree_ann_common_t
921 get_tree_common_ann (tree t)
922 {
923   tree_ann_common_t ann = tree_common_ann (t);
924   return (ann) ? ann : create_tree_common_ann (t);
925 }
926
927 /*  -----------------------------------------------------------------------  */
928
929 /* The following set of routines are used to iterator over various type of
930    SSA operands.  */
931
932 /* Return true if PTR is finished iterating.  */
933 static inline bool
934 op_iter_done (const ssa_op_iter *ptr)
935 {
936   return ptr->done;
937 }
938
939 /* Get the next iterator use value for PTR.  */
940 static inline use_operand_p
941 op_iter_next_use (ssa_op_iter *ptr)
942 {
943   use_operand_p use_p;
944 #ifdef ENABLE_CHECKING
945   gcc_assert (ptr->iter_type == ssa_op_iter_use);
946 #endif
947   if (ptr->uses)
948     {
949       use_p = USE_OP_PTR (ptr->uses);
950       ptr->uses = ptr->uses->next;
951       return use_p;
952     }
953   if (ptr->vuses)
954     {
955       use_p = VUSE_OP_PTR (ptr->vuses, ptr->vuse_index);
956       if (++(ptr->vuse_index) >= VUSE_NUM (ptr->vuses))
957         {
958           ptr->vuse_index = 0;
959           ptr->vuses = ptr->vuses->next;
960         }
961       return use_p;
962     }
963   if (ptr->mayuses)
964     {
965       use_p = VDEF_OP_PTR (ptr->mayuses, ptr->mayuse_index);
966       if (++(ptr->mayuse_index) >= VDEF_NUM (ptr->mayuses))
967         {
968           ptr->mayuse_index = 0;
969           ptr->mayuses = ptr->mayuses->next;
970         }
971       return use_p;
972     }
973   if (ptr->phi_i < ptr->num_phi)
974     {
975       return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
976     }
977   ptr->done = true;
978   return NULL_USE_OPERAND_P;
979 }
980
981 /* Get the next iterator def value for PTR.  */
982 static inline def_operand_p
983 op_iter_next_def (ssa_op_iter *ptr)
984 {
985   def_operand_p def_p;
986 #ifdef ENABLE_CHECKING
987   gcc_assert (ptr->iter_type == ssa_op_iter_def);
988 #endif
989   if (ptr->defs)
990     {
991       def_p = DEF_OP_PTR (ptr->defs);
992       ptr->defs = ptr->defs->next;
993       return def_p;
994     }
995   if (ptr->vdefs)
996     {
997       def_p = VDEF_RESULT_PTR (ptr->vdefs);
998       ptr->vdefs = ptr->vdefs->next;
999       return def_p;
1000     }
1001   ptr->done = true;
1002   return NULL_DEF_OPERAND_P;
1003 }
1004
1005 /* Get the next iterator tree value for PTR.  */
1006 static inline tree
1007 op_iter_next_tree (ssa_op_iter *ptr)
1008 {
1009   tree val;
1010 #ifdef ENABLE_CHECKING
1011   gcc_assert (ptr->iter_type == ssa_op_iter_tree);
1012 #endif
1013   if (ptr->uses)
1014     {
1015       val = USE_OP (ptr->uses);
1016       ptr->uses = ptr->uses->next;
1017       return val;
1018     }
1019   if (ptr->vuses)
1020     {
1021       val = VUSE_OP (ptr->vuses, ptr->vuse_index);
1022       if (++(ptr->vuse_index) >= VUSE_NUM (ptr->vuses))
1023         {
1024           ptr->vuse_index = 0;
1025           ptr->vuses = ptr->vuses->next;
1026         }
1027       return val;
1028     }
1029   if (ptr->mayuses)
1030     {
1031       val = VDEF_OP (ptr->mayuses, ptr->mayuse_index);
1032       if (++(ptr->mayuse_index) >= VDEF_NUM (ptr->mayuses))
1033         {
1034           ptr->mayuse_index = 0;
1035           ptr->mayuses = ptr->mayuses->next;
1036         }
1037       return val;
1038     }
1039   if (ptr->defs)
1040     {
1041       val = DEF_OP (ptr->defs);
1042       ptr->defs = ptr->defs->next;
1043       return val;
1044     }
1045   if (ptr->vdefs)
1046     {
1047       val = VDEF_RESULT (ptr->vdefs);
1048       ptr->vdefs = ptr->vdefs->next;
1049       return val;
1050     }
1051
1052   ptr->done = true;
1053   return NULL_TREE;
1054
1055 }
1056
1057
1058 /* This functions clears the iterator PTR, and marks it done.  This is normally
1059    used to prevent warnings in the compile about might be uninitialized
1060    components.  */
1061
1062 static inline void
1063 clear_and_done_ssa_iter (ssa_op_iter *ptr)
1064 {
1065   ptr->defs = NULL;
1066   ptr->uses = NULL;
1067   ptr->vuses = NULL;
1068   ptr->vdefs = NULL;
1069   ptr->mayuses = NULL;
1070   ptr->iter_type = ssa_op_iter_none;
1071   ptr->phi_i = 0;
1072   ptr->num_phi = 0;
1073   ptr->phi_stmt = NULL_TREE;
1074   ptr->done = true;
1075   ptr->vuse_index = 0;
1076   ptr->mayuse_index = 0;
1077 }
1078
1079 /* Initialize the iterator PTR to the virtual defs in STMT.  */
1080 static inline void
1081 op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
1082 {
1083 #ifdef ENABLE_CHECKING
1084   gcc_assert (stmt_ann (stmt));
1085 #endif
1086
1087   ptr->defs = (flags & SSA_OP_DEF) ? DEF_OPS (stmt) : NULL;
1088   ptr->uses = (flags & SSA_OP_USE) ? USE_OPS (stmt) : NULL;
1089   ptr->vuses = (flags & SSA_OP_VUSE) ? VUSE_OPS (stmt) : NULL;
1090   ptr->vdefs = (flags & SSA_OP_VDEF) ? VDEF_OPS (stmt) : NULL;
1091   ptr->mayuses = (flags & SSA_OP_VMAYUSE) ? VDEF_OPS (stmt) : NULL;
1092   ptr->done = false;
1093
1094   ptr->phi_i = 0;
1095   ptr->num_phi = 0;
1096   ptr->phi_stmt = NULL_TREE;
1097   ptr->vuse_index = 0;
1098   ptr->mayuse_index = 0;
1099 }
1100
1101 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1102    the first use.  */
1103 static inline use_operand_p
1104 op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
1105 {
1106   gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0);
1107   op_iter_init (ptr, stmt, flags);
1108   ptr->iter_type = ssa_op_iter_use;
1109   return op_iter_next_use (ptr);
1110 }
1111
1112 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1113    the first def.  */
1114 static inline def_operand_p
1115 op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1116 {
1117   gcc_assert ((flags & SSA_OP_ALL_USES) == 0);
1118   op_iter_init (ptr, stmt, flags);
1119   ptr->iter_type = ssa_op_iter_def;
1120   return op_iter_next_def (ptr);
1121 }
1122
1123 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1124    the first operand as a tree.  */
1125 static inline tree
1126 op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1127 {
1128   op_iter_init (ptr, stmt, flags);
1129   ptr->iter_type = ssa_op_iter_tree;
1130   return op_iter_next_tree (ptr);
1131 }
1132
1133 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1134    KILL and DEF.  */
1135 static inline void
1136 op_iter_next_vdef (vuse_vec_p *use, def_operand_p *def, 
1137                          ssa_op_iter *ptr)
1138 {
1139 #ifdef ENABLE_CHECKING
1140   gcc_assert (ptr->iter_type == ssa_op_iter_vdef);
1141 #endif
1142   if (ptr->mayuses)
1143     {
1144       *def = VDEF_RESULT_PTR (ptr->mayuses);
1145       *use = VDEF_VECT (ptr->mayuses);
1146       ptr->mayuses = ptr->mayuses->next;
1147       return;
1148     }
1149
1150   *def = NULL_DEF_OPERAND_P;
1151   *use = NULL;
1152   ptr->done = true;
1153   return;
1154 }
1155
1156
1157 static inline void
1158 op_iter_next_mustdef (use_operand_p *use, def_operand_p *def, 
1159                          ssa_op_iter *ptr)
1160 {
1161   vuse_vec_p vp;
1162   op_iter_next_vdef (&vp, def, ptr);
1163   if (vp != NULL)
1164     {
1165       gcc_assert (VUSE_VECT_NUM_ELEM (*vp) == 1);
1166       *use = VUSE_ELEMENT_PTR (*vp, 0);
1167     }
1168   else
1169     *use = NULL_USE_OPERAND_P;
1170 }
1171
1172 /* Initialize iterator PTR to the operands in STMT.  Return the first operands
1173    in USE and DEF.  */
1174 static inline void
1175 op_iter_init_vdef (ssa_op_iter *ptr, tree stmt, vuse_vec_p *use, 
1176                      def_operand_p *def)
1177 {
1178   gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1179
1180   op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1181   ptr->iter_type = ssa_op_iter_vdef;
1182   op_iter_next_vdef (use, def, ptr);
1183 }
1184
1185
1186 /* If there is a single operand in STMT matching FLAGS, return it.  Otherwise
1187    return NULL.  */
1188 static inline tree
1189 single_ssa_tree_operand (tree stmt, int flags)
1190 {
1191   tree var;
1192   ssa_op_iter iter;
1193
1194   var = op_iter_init_tree (&iter, stmt, flags);
1195   if (op_iter_done (&iter))
1196     return NULL_TREE;
1197   op_iter_next_tree (&iter);
1198   if (op_iter_done (&iter))
1199     return var;
1200   return NULL_TREE;
1201 }
1202
1203
1204 /* If there is a single operand in STMT matching FLAGS, return it.  Otherwise
1205    return NULL.  */
1206 static inline use_operand_p
1207 single_ssa_use_operand (tree stmt, int flags)
1208 {
1209   use_operand_p var;
1210   ssa_op_iter iter;
1211
1212   var = op_iter_init_use (&iter, stmt, flags);
1213   if (op_iter_done (&iter))
1214     return NULL_USE_OPERAND_P;
1215   op_iter_next_use (&iter);
1216   if (op_iter_done (&iter))
1217     return var;
1218   return NULL_USE_OPERAND_P;
1219 }
1220
1221
1222
1223 /* If there is a single operand in STMT matching FLAGS, return it.  Otherwise
1224    return NULL.  */
1225 static inline def_operand_p
1226 single_ssa_def_operand (tree stmt, int flags)
1227 {
1228   def_operand_p var;
1229   ssa_op_iter iter;
1230
1231   var = op_iter_init_def (&iter, stmt, flags);
1232   if (op_iter_done (&iter))
1233     return NULL_DEF_OPERAND_P;
1234   op_iter_next_def (&iter);
1235   if (op_iter_done (&iter))
1236     return var;
1237   return NULL_DEF_OPERAND_P;
1238 }
1239
1240
1241 /* Return true if there are zero operands in STMT matching the type 
1242    given in FLAGS.  */
1243 static inline bool
1244 zero_ssa_operands (tree stmt, int flags)
1245 {
1246   ssa_op_iter iter;
1247
1248   op_iter_init_tree (&iter, stmt, flags);
1249   return op_iter_done (&iter);
1250 }
1251
1252
1253 /* Return the number of operands matching FLAGS in STMT.  */
1254 static inline int
1255 num_ssa_operands (tree stmt, int flags)
1256 {
1257   ssa_op_iter iter;
1258   tree t;
1259   int num = 0;
1260
1261   FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
1262     num++;
1263   return num;
1264 }
1265
1266
1267 /* Delink all immediate_use information for STMT.  */
1268 static inline void
1269 delink_stmt_imm_use (tree stmt)
1270 {
1271    ssa_op_iter iter;
1272    use_operand_p use_p;
1273
1274    if (ssa_operands_active ())
1275      FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_ALL_USES)
1276        delink_imm_use (use_p);
1277 }
1278
1279
1280 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1281    in STMT2.  TRUE is returned if they are the same.  STMTs can be NULL.  */
1282 static inline bool
1283 compare_ssa_operands_equal (tree stmt1, tree stmt2, int flags)
1284 {
1285   ssa_op_iter iter1, iter2;
1286   tree op1 = NULL_TREE;
1287   tree op2 = NULL_TREE;
1288   bool look1, look2;
1289
1290   if (stmt1 == stmt2)
1291     return true;
1292
1293   look1 = stmt1 && stmt_ann (stmt1);
1294   look2 = stmt2 && stmt_ann (stmt2);
1295
1296   if (look1)
1297     {
1298       op1 = op_iter_init_tree (&iter1, stmt1, flags);
1299       if (!look2)
1300         return op_iter_done (&iter1);
1301     }
1302   else
1303     clear_and_done_ssa_iter (&iter1);
1304
1305   if (look2)
1306     {
1307       op2 = op_iter_init_tree (&iter2, stmt2, flags);
1308       if (!look1)
1309         return op_iter_done (&iter2);
1310     }
1311   else
1312     clear_and_done_ssa_iter (&iter2);
1313
1314   while (!op_iter_done (&iter1) && !op_iter_done (&iter2))
1315     {
1316       if (op1 != op2)
1317         return false;
1318       op1 = op_iter_next_tree (&iter1);
1319       op2 = op_iter_next_tree (&iter2);
1320     }
1321
1322   return (op_iter_done (&iter1) && op_iter_done (&iter2));
1323 }
1324
1325
1326 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1327    Otherwise return NULL_DEF_OPERAND_P.  */
1328 static inline tree
1329 single_phi_def (tree stmt, int flags)
1330 {
1331   tree def = PHI_RESULT (stmt);
1332   if ((flags & SSA_OP_DEF) && is_gimple_reg (def)) 
1333     return def;
1334   if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
1335     return def;
1336   return NULL_TREE;
1337 }
1338
1339 /* Initialize the iterator PTR for uses matching FLAGS in PHI.  FLAGS should
1340    be either SSA_OP_USES or SSA_OP_VIRTUAL_USES.  */
1341 static inline use_operand_p
1342 op_iter_init_phiuse (ssa_op_iter *ptr, tree phi, int flags)
1343 {
1344   tree phi_def = PHI_RESULT (phi);
1345   int comp;
1346
1347   clear_and_done_ssa_iter (ptr);
1348   ptr->done = false;
1349
1350   gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
1351
1352   comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1353     
1354   /* If the PHI node doesn't the operand type we care about, we're done.  */
1355   if ((flags & comp) == 0)
1356     {
1357       ptr->done = true;
1358       return NULL_USE_OPERAND_P;
1359     }
1360
1361   ptr->phi_stmt = phi;
1362   ptr->num_phi = PHI_NUM_ARGS (phi);
1363   ptr->iter_type = ssa_op_iter_use;
1364   return op_iter_next_use (ptr);
1365 }
1366
1367
1368 /* Start an iterator for a PHI definition.  */
1369
1370 static inline def_operand_p
1371 op_iter_init_phidef (ssa_op_iter *ptr, tree phi, int flags)
1372 {
1373   tree phi_def = PHI_RESULT (phi);
1374   int comp;
1375
1376   clear_and_done_ssa_iter (ptr);
1377   ptr->done = false;
1378
1379   gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
1380
1381   comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
1382     
1383   /* If the PHI node doesn't the operand type we care about, we're done.  */
1384   if ((flags & comp) == 0)
1385     {
1386       ptr->done = true;
1387       return NULL_USE_OPERAND_P;
1388     }
1389
1390   ptr->iter_type = ssa_op_iter_def;
1391   /* The first call to op_iter_next_def will terminate the iterator since
1392      all the fields are NULL.  Simply return the result here as the first and
1393      therefore only result.  */
1394   return PHI_RESULT_PTR (phi);
1395 }
1396
1397 /* Return true is IMM has reached the end of the immediate use stmt list.  */
1398
1399 static inline bool
1400 end_imm_use_stmt_p (const imm_use_iterator *imm)
1401 {
1402   return (imm->imm_use == imm->end_p);
1403 }
1404
1405 /* Finished the traverse of an immediate use stmt list IMM by removing the
1406    placeholder node from the list.  */
1407
1408 static inline void
1409 end_imm_use_stmt_traverse (imm_use_iterator *imm)
1410 {
1411   delink_imm_use (&(imm->iter_node));
1412 }
1413
1414 /* Immediate use traversal of uses within a stmt require that all the
1415    uses on a stmt be sequentially listed.  This routine is used to build up
1416    this sequential list by adding USE_P to the end of the current list 
1417    currently delimited by HEAD and LAST_P.  The new LAST_P value is 
1418    returned.  */
1419
1420 static inline use_operand_p
1421 move_use_after_head (use_operand_p use_p, use_operand_p head, 
1422                       use_operand_p last_p)
1423 {
1424   gcc_assert (USE_FROM_PTR (use_p) == USE_FROM_PTR (head));
1425   /* Skip head when we find it.  */
1426   if (use_p != head)
1427     {
1428       /* If use_p is already linked in after last_p, continue.  */
1429       if (last_p->next == use_p)
1430         last_p = use_p;
1431       else
1432         {
1433           /* Delink from current location, and link in at last_p.  */
1434           delink_imm_use (use_p);
1435           link_imm_use_to_list (use_p, last_p);
1436           last_p = use_p;
1437         }
1438     }
1439   return last_p;
1440 }
1441
1442
1443 /* This routine will relink all uses with the same stmt as HEAD into the list
1444    immediately following HEAD for iterator IMM.  */
1445
1446 static inline void
1447 link_use_stmts_after (use_operand_p head, imm_use_iterator *imm)
1448 {
1449   use_operand_p use_p;
1450   use_operand_p last_p = head;
1451   tree head_stmt = USE_STMT (head);
1452   tree use = USE_FROM_PTR (head);
1453   ssa_op_iter op_iter;
1454   int flag;
1455
1456   /* Only look at virtual or real uses, depending on the type of HEAD.  */
1457   flag = (is_gimple_reg (use) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1458
1459   if (TREE_CODE (head_stmt) == PHI_NODE)
1460     {
1461       FOR_EACH_PHI_ARG (use_p, head_stmt, op_iter, flag)
1462         if (USE_FROM_PTR (use_p) == use)
1463           last_p = move_use_after_head (use_p, head, last_p);
1464     }
1465   else
1466     {
1467       FOR_EACH_SSA_USE_OPERAND (use_p, head_stmt, op_iter, flag)
1468         if (USE_FROM_PTR (use_p) == use)
1469           last_p = move_use_after_head (use_p, head, last_p);
1470     }
1471   /* LInk iter node in after last_p.  */
1472   if (imm->iter_node.prev != NULL)
1473     delink_imm_use (&imm->iter_node);
1474   link_imm_use_to_list (&(imm->iter_node), last_p);
1475 }
1476
1477 /* Initialize IMM to traverse over uses of VAR.  Return the first statement.  */
1478 static inline tree
1479 first_imm_use_stmt (imm_use_iterator *imm, tree var)
1480 {
1481   gcc_assert (TREE_CODE (var) == SSA_NAME);
1482   
1483   imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
1484   imm->imm_use = imm->end_p->next;
1485   imm->next_imm_name = NULL_USE_OPERAND_P;
1486
1487   /* iter_node is used as a marker within the immediate use list to indicate
1488      where the end of the current stmt's uses are.  Initialize it to NULL
1489      stmt and use, which indicates a marker node.  */
1490   imm->iter_node.prev = NULL_USE_OPERAND_P;
1491   imm->iter_node.next = NULL_USE_OPERAND_P;
1492   imm->iter_node.stmt = NULL_TREE;
1493   imm->iter_node.use = NULL_USE_OPERAND_P;
1494
1495   if (end_imm_use_stmt_p (imm))
1496     return NULL_TREE;
1497
1498   link_use_stmts_after (imm->imm_use, imm);
1499
1500   return USE_STMT (imm->imm_use);
1501 }
1502
1503 /* Bump IMM to the next stmt which has a use of var.  */
1504
1505 static inline tree
1506 next_imm_use_stmt (imm_use_iterator *imm)
1507 {
1508   imm->imm_use = imm->iter_node.next;
1509   if (end_imm_use_stmt_p (imm))
1510     {
1511       if (imm->iter_node.prev != NULL)
1512         delink_imm_use (&imm->iter_node);
1513       return NULL_TREE;
1514     }
1515
1516   link_use_stmts_after (imm->imm_use, imm);
1517   return USE_STMT (imm->imm_use);
1518 }
1519
1520 /* This routine will return the first use on the stmt IMM currently refers
1521    to.  */
1522
1523 static inline use_operand_p
1524 first_imm_use_on_stmt (imm_use_iterator *imm)
1525 {
1526   imm->next_imm_name = imm->imm_use->next;
1527   return imm->imm_use;
1528 }
1529
1530 /*  Return TRUE if the last use on the stmt IMM refers to has been visited.  */
1531
1532 static inline bool
1533 end_imm_use_on_stmt_p (const imm_use_iterator *imm)
1534 {
1535   return (imm->imm_use == &(imm->iter_node));
1536 }
1537
1538 /* Bump to the next use on the stmt IMM refers to, return NULL if done.  */
1539
1540 static inline use_operand_p
1541 next_imm_use_on_stmt (imm_use_iterator *imm)
1542 {
1543   imm->imm_use = imm->next_imm_name;
1544   if (end_imm_use_on_stmt_p (imm))
1545     return NULL_USE_OPERAND_P;
1546   else
1547     {
1548       imm->next_imm_name = imm->imm_use->next;
1549       return imm->imm_use;
1550     }
1551 }
1552
1553 /* Return true if VAR cannot be modified by the program.  */
1554
1555 static inline bool
1556 unmodifiable_var_p (const_tree var)
1557 {
1558   if (TREE_CODE (var) == SSA_NAME)
1559     var = SSA_NAME_VAR (var);
1560
1561   if (MTAG_P (var))
1562     return false;
1563
1564   return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1565 }
1566
1567 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it.  */
1568
1569 static inline bool
1570 array_ref_contains_indirect_ref (const_tree ref)
1571 {
1572   gcc_assert (TREE_CODE (ref) == ARRAY_REF);
1573
1574   do {
1575     ref = TREE_OPERAND (ref, 0);
1576   } while (handled_component_p (ref));
1577
1578   return TREE_CODE (ref) == INDIRECT_REF;
1579 }
1580
1581 /* Return true if REF, a handled component reference, has an ARRAY_REF
1582    somewhere in it.  */
1583
1584 static inline bool
1585 ref_contains_array_ref (const_tree ref)
1586 {
1587   gcc_assert (handled_component_p (ref));
1588
1589   do {
1590     if (TREE_CODE (ref) == ARRAY_REF)
1591       return true;
1592     ref = TREE_OPERAND (ref, 0);
1593   } while (handled_component_p (ref));
1594
1595   return false;
1596 }
1597
1598 /* Return true, if the two ranges [POS1, SIZE1] and [POS2, SIZE2]
1599    overlap.  SIZE1 and/or SIZE2 can be (unsigned)-1 in which case the
1600    range is open-ended.  Otherwise return false.  */
1601
1602 static inline bool
1603 ranges_overlap_p (unsigned HOST_WIDE_INT pos1,
1604                   unsigned HOST_WIDE_INT size1,
1605                   unsigned HOST_WIDE_INT pos2,
1606                   unsigned HOST_WIDE_INT size2)
1607 {
1608   if (pos1 >= pos2
1609       && (size2 == (unsigned HOST_WIDE_INT)-1
1610           || pos1 < (pos2 + size2)))
1611     return true;
1612   if (pos2 >= pos1
1613       && (size1 == (unsigned HOST_WIDE_INT)-1
1614           || pos2 < (pos1 + size1)))
1615     return true;
1616
1617   return false;
1618 }
1619
1620 /* Return the memory tag associated with symbol SYM.  */
1621
1622 static inline tree
1623 symbol_mem_tag (tree sym)
1624 {
1625   tree tag = get_var_ann (sym)->symbol_mem_tag;
1626
1627 #if defined ENABLE_CHECKING
1628   if (tag)
1629     gcc_assert (TREE_CODE (tag) == SYMBOL_MEMORY_TAG);
1630 #endif
1631
1632   return tag;
1633 }
1634
1635
1636 /* Set the memory tag associated with symbol SYM.  */
1637
1638 static inline void
1639 set_symbol_mem_tag (tree sym, tree tag)
1640 {
1641 #if defined ENABLE_CHECKING
1642   if (tag)
1643     gcc_assert (TREE_CODE (tag) == SYMBOL_MEMORY_TAG);
1644 #endif
1645
1646   get_var_ann (sym)->symbol_mem_tag = tag;
1647 }
1648
1649 /* Get the value handle of EXPR.  This is the only correct way to get
1650    the value handle for a "thing".  If EXPR does not have a value
1651    handle associated, it returns NULL_TREE.  
1652    NB: If EXPR is min_invariant, this function is *required* to return
1653    EXPR.  */
1654
1655 static inline tree
1656 get_value_handle (tree expr)
1657 {
1658   if (TREE_CODE (expr) == SSA_NAME)
1659     return SSA_NAME_VALUE (expr);
1660   else if (DECL_P (expr) || TREE_CODE (expr) == TREE_LIST
1661            || TREE_CODE (expr) == CONSTRUCTOR)
1662     {
1663       tree_ann_common_t ann = tree_common_ann (expr);
1664       return ((ann) ? ann->value_handle : NULL_TREE);
1665     }
1666   else if (is_gimple_min_invariant (expr))
1667     return expr;
1668   else if (EXPR_P (expr))
1669     {
1670       tree_ann_common_t ann = tree_common_ann (expr);
1671       return ((ann) ? ann->value_handle : NULL_TREE);
1672     }
1673   else
1674     gcc_unreachable ();
1675 }
1676
1677 /* Accessor to tree-ssa-operands.c caches.  */
1678 static inline struct ssa_operands *
1679 gimple_ssa_operands (const struct function *fun)
1680 {
1681   return &fun->gimple_df->ssa_operands;
1682 }
1683
1684 /* Map describing reference statistics for function FN.  */
1685 static inline struct mem_ref_stats_d *
1686 gimple_mem_ref_stats (const struct function *fn)
1687 {
1688   return &fn->gimple_df->mem_ref_stats;
1689 }
1690
1691 /* Given an edge_var_map V, return the PHI arg definition.  */
1692
1693 static inline tree
1694 redirect_edge_var_map_def (edge_var_map *v)
1695 {
1696   return v->def;
1697 }
1698
1699 /* Given an edge_var_map V, return the PHI result.  */
1700
1701 static inline tree
1702 redirect_edge_var_map_result (edge_var_map *v)
1703 {
1704   return v->result;
1705 }
1706
1707
1708 /* Return an SSA_NAME node for variable VAR defined in statement STMT
1709    in function cfun.  */
1710
1711 static inline tree
1712 make_ssa_name (tree var, tree stmt)
1713 {
1714   return make_ssa_name_fn (cfun, var, stmt);
1715 }
1716
1717 #endif /* _TREE_FLOW_INLINE_H  */