* defaults.h (FRAME_GROWS_DOWNWARD): Define to 0 if not defined.
[official-gcc.git] / gcc / tree-flow-inline.h
blobe2ed2f30d2a31828c729489bec943de132c839a3
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>
5 This file is part of GCC.
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.
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.
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, 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 #ifndef _TREE_FLOW_INLINE_H
23 #define _TREE_FLOW_INLINE_H 1
25 /* Inline functions for manipulating various data structures defined in
26 tree-flow.h. See tree-flow.h for documentation. */
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)
33 gcc_assert (t);
34 gcc_assert (DECL_P (t));
35 gcc_assert (!t->common.ann || t->common.ann->common.type == VAR_ANN);
37 return (var_ann_t) t->common.ann;
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)
45 var_ann_t ann = var_ann (var);
46 return (ann) ? ann : create_var_ann (var);
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)
54 #ifdef ENABLE_CHECKING
55 gcc_assert (is_gimple_stmt (t));
56 #endif
57 return (stmt_ann_t) t->common.ann;
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)
65 stmt_ann_t ann = stmt_ann (stmt);
66 return (ann) ? ann : create_stmt_ann (stmt);
69 /* Return the annotation type for annotation ANN. */
70 static inline enum tree_ann_type
71 ann_type (tree_ann_t ann)
73 return ann->common.type;
76 /* Return the basic block for statement T. */
77 static inline basic_block
78 bb_for_stmt (tree t)
80 stmt_ann_t ann;
82 if (TREE_CODE (t) == PHI_NODE)
83 return PHI_BB (t);
85 ann = stmt_ann (t);
86 return ann ? ann->bb : NULL;
89 /* Return the may_aliases varray for variable VAR, or NULL if it has
90 no may aliases. */
91 static inline varray_type
92 may_aliases (tree var)
94 var_ann_t ann = var_ann (var);
95 return ann ? ann->may_aliases : NULL;
98 /* Return the line number for EXPR, or return -1 if we have no line
99 number information for it. */
100 static inline int
101 get_lineno (tree expr)
103 if (expr == NULL_TREE)
104 return -1;
106 if (TREE_CODE (expr) == COMPOUND_EXPR)
107 expr = TREE_OPERAND (expr, 0);
109 if (! EXPR_HAS_LOCATION (expr))
110 return -1;
112 return EXPR_LINENO (expr);
115 /* Return the file name for EXPR, or return "???" if we have no
116 filename information. */
117 static inline const char *
118 get_filename (tree expr)
120 const char *filename;
121 if (expr == NULL_TREE)
122 return "???";
124 if (TREE_CODE (expr) == COMPOUND_EXPR)
125 expr = TREE_OPERAND (expr, 0);
127 if (EXPR_HAS_LOCATION (expr) && (filename = EXPR_FILENAME (expr)))
128 return filename;
129 else
130 return "???";
133 /* Return true if T is a noreturn call. */
134 static inline bool
135 noreturn_call_p (tree t)
137 tree call = get_call_expr_in (t);
138 return call != 0 && (call_expr_flags (call) & ECF_NORETURN) != 0;
141 /* Mark statement T as modified. */
142 static inline void
143 mark_stmt_modified (tree t)
145 stmt_ann_t ann;
146 if (TREE_CODE (t) == PHI_NODE)
147 return;
149 ann = stmt_ann (t);
150 if (ann == NULL)
151 ann = create_stmt_ann (t);
152 else if (noreturn_call_p (t))
153 VEC_safe_push (tree, gc, modified_noreturn_calls, t);
154 ann->modified = 1;
157 /* Mark statement T as modified, and update it. */
158 static inline void
159 update_stmt (tree t)
161 if (TREE_CODE (t) == PHI_NODE)
162 return;
163 mark_stmt_modified (t);
164 update_stmt_operands (t);
167 static inline void
168 update_stmt_if_modified (tree t)
170 if (stmt_modified_p (t))
171 update_stmt_operands (t);
174 /* Return true if T is marked as modified, false otherwise. */
175 static inline bool
176 stmt_modified_p (tree t)
178 stmt_ann_t ann = stmt_ann (t);
180 /* Note that if the statement doesn't yet have an annotation, we consider it
181 modified. This will force the next call to update_stmt_operands to scan
182 the statement. */
183 return ann ? ann->modified : true;
186 /* Delink an immediate_uses node from its chain. */
187 static inline void
188 delink_imm_use (ssa_use_operand_t *linknode)
190 /* Return if this node is not in a list. */
191 if (linknode->prev == NULL)
192 return;
194 linknode->prev->next = linknode->next;
195 linknode->next->prev = linknode->prev;
196 linknode->prev = NULL;
197 linknode->next = NULL;
200 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
201 static inline void
202 link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
204 /* Link the new node at the head of the list. If we are in the process of
205 traversing the list, we won't visit any new nodes added to it. */
206 linknode->prev = list;
207 linknode->next = list->next;
208 list->next->prev = linknode;
209 list->next = linknode;
212 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
213 static inline void
214 link_imm_use (ssa_use_operand_t *linknode, tree def)
216 ssa_use_operand_t *root;
218 if (!def || TREE_CODE (def) != SSA_NAME)
219 linknode->prev = NULL;
220 else
222 root = &(SSA_NAME_IMM_USE_NODE (def));
223 #ifdef ENABLE_CHECKING
224 if (linknode->use)
225 gcc_assert (*(linknode->use) == def);
226 #endif
227 link_imm_use_to_list (linknode, root);
231 /* Set the value of a use pointed by USE to VAL. */
232 static inline void
233 set_ssa_use_from_ptr (use_operand_p use, tree val)
235 delink_imm_use (use);
236 *(use->use) = val;
237 link_imm_use (use, val);
240 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
241 in STMT. */
242 static inline void
243 link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, tree stmt)
245 if (stmt)
246 link_imm_use (linknode, def);
247 else
248 link_imm_use (linknode, NULL);
249 linknode->stmt = stmt;
252 /* Relink a new node in place of an old node in the list. */
253 static inline void
254 relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
256 /* The node one had better be in the same list. */
257 gcc_assert (*(old->use) == *(node->use));
258 node->prev = old->prev;
259 node->next = old->next;
260 if (old->prev)
262 old->prev->next = node;
263 old->next->prev = node;
264 /* Remove the old node from the list. */
265 old->prev = NULL;
269 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
270 in STMT. */
271 static inline void
272 relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old, tree stmt)
274 if (stmt)
275 relink_imm_use (linknode, old);
276 else
277 link_imm_use (linknode, NULL);
278 linknode->stmt = stmt;
281 /* Finished the traverse of an immediate use list IMM by removing it from
282 the list. */
283 static inline void
284 end_safe_imm_use_traverse (imm_use_iterator *imm)
286 delink_imm_use (&(imm->iter_node));
289 /* Return true if IMM is at the end of the list. */
290 static inline bool
291 end_safe_imm_use_p (imm_use_iterator *imm)
293 return (imm->imm_use == imm->end_p);
296 /* Initialize iterator IMM to process the list for VAR. */
297 static inline use_operand_p
298 first_safe_imm_use (imm_use_iterator *imm, tree var)
300 /* Set up and link the iterator node into the linked list for VAR. */
301 imm->iter_node.use = NULL;
302 imm->iter_node.stmt = NULL_TREE;
303 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
304 /* Check if there are 0 elements. */
305 if (imm->end_p->next == imm->end_p)
307 imm->imm_use = imm->end_p;
308 return NULL_USE_OPERAND_P;
311 link_imm_use (&(imm->iter_node), var);
312 imm->imm_use = imm->iter_node.next;
313 return imm->imm_use;
316 /* Bump IMM to the next use in the list. */
317 static inline use_operand_p
318 next_safe_imm_use (imm_use_iterator *imm)
320 ssa_use_operand_t *ptr;
321 use_operand_p old;
323 old = imm->imm_use;
324 /* If the next node following the iter_node is still the one referred to by
325 imm_use, then the list hasn't changed, go to the next node. */
326 if (imm->iter_node.next == imm->imm_use)
328 ptr = &(imm->iter_node);
329 /* Remove iternode from the list. */
330 delink_imm_use (ptr);
331 imm->imm_use = imm->imm_use->next;
332 if (! end_safe_imm_use_p (imm))
334 /* This isn't the end, link iternode before the next use. */
335 ptr->prev = imm->imm_use->prev;
336 ptr->next = imm->imm_use;
337 imm->imm_use->prev->next = ptr;
338 imm->imm_use->prev = ptr;
340 else
341 return old;
343 else
345 /* If the 'next' value after the iterator isn't the same as it was, then
346 a node has been deleted, so we simply proceed to the node following
347 where the iterator is in the list. */
348 imm->imm_use = imm->iter_node.next;
349 if (end_safe_imm_use_p (imm))
351 end_safe_imm_use_traverse (imm);
352 return old;
356 return imm->imm_use;
359 /* Return true is IMM has reached the end of the immediate use list. */
360 static inline bool
361 end_readonly_imm_use_p (imm_use_iterator *imm)
363 return (imm->imm_use == imm->end_p);
366 /* Initialize iterator IMM to process the list for VAR. */
367 static inline use_operand_p
368 first_readonly_imm_use (imm_use_iterator *imm, tree var)
370 gcc_assert (TREE_CODE (var) == SSA_NAME);
372 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
373 imm->imm_use = imm->end_p->next;
374 #ifdef ENABLE_CHECKING
375 imm->iter_node.next = imm->imm_use->next;
376 #endif
377 if (end_readonly_imm_use_p (imm))
378 return NULL_USE_OPERAND_P;
379 return imm->imm_use;
382 /* Bump IMM to the next use in the list. */
383 static inline use_operand_p
384 next_readonly_imm_use (imm_use_iterator *imm)
386 use_operand_p old = imm->imm_use;
388 #ifdef ENABLE_CHECKING
389 /* If this assertion fails, it indicates the 'next' pointer has changed
390 since we the last bump. This indicates that the list is being modified
391 via stmt changes, or SET_USE, or somesuch thing, and you need to be
392 using the SAFE version of the iterator. */
393 gcc_assert (imm->iter_node.next == old->next);
394 imm->iter_node.next = old->next->next;
395 #endif
397 imm->imm_use = old->next;
398 if (end_readonly_imm_use_p (imm))
399 return old;
400 return imm->imm_use;
403 /* Return true if VAR has no uses. */
404 static inline bool
405 has_zero_uses (tree var)
407 ssa_use_operand_t *ptr;
408 ptr = &(SSA_NAME_IMM_USE_NODE (var));
409 /* A single use means there is no items in the list. */
410 return (ptr == ptr->next);
413 /* Return true if VAR has a single use. */
414 static inline bool
415 has_single_use (tree var)
417 ssa_use_operand_t *ptr;
418 ptr = &(SSA_NAME_IMM_USE_NODE (var));
419 /* A single use means there is one item in the list. */
420 return (ptr != ptr->next && ptr == ptr->next->next);
423 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
424 to the use pointer and stmt of occurrence. */
425 static inline bool
426 single_imm_use (tree var, use_operand_p *use_p, tree *stmt)
428 ssa_use_operand_t *ptr;
430 ptr = &(SSA_NAME_IMM_USE_NODE (var));
431 if (ptr != ptr->next && ptr == ptr->next->next)
433 *use_p = ptr->next;
434 *stmt = ptr->next->stmt;
435 return true;
437 *use_p = NULL_USE_OPERAND_P;
438 *stmt = NULL_TREE;
439 return false;
442 /* Return the number of immediate uses of VAR. */
443 static inline unsigned int
444 num_imm_uses (tree var)
446 ssa_use_operand_t *ptr, *start;
447 unsigned int num;
449 start = &(SSA_NAME_IMM_USE_NODE (var));
450 num = 0;
451 for (ptr = start->next; ptr != start; ptr = ptr->next)
452 num++;
454 return num;
458 /* Return the tree pointer to by USE. */
459 static inline tree
460 get_use_from_ptr (use_operand_p use)
462 return *(use->use);
465 /* Return the tree pointer to by DEF. */
466 static inline tree
467 get_def_from_ptr (def_operand_p def)
469 return *def;
472 /* Return a def_operand_p pointer for the result of PHI. */
473 static inline def_operand_p
474 get_phi_result_ptr (tree phi)
476 return &(PHI_RESULT_TREE (phi));
479 /* Return a use_operand_p pointer for argument I of phinode PHI. */
480 static inline use_operand_p
481 get_phi_arg_def_ptr (tree phi, int i)
483 return &(PHI_ARG_IMM_USE_NODE (phi,i));
487 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
488 no addresses. */
489 static inline bitmap
490 addresses_taken (tree stmt)
492 stmt_ann_t ann = stmt_ann (stmt);
493 return ann ? ann->addresses_taken : NULL;
496 /* Return the PHI nodes for basic block BB, or NULL if there are no
497 PHI nodes. */
498 static inline tree
499 phi_nodes (basic_block bb)
501 return bb->phi_nodes;
504 /* Set list of phi nodes of a basic block BB to L. */
506 static inline void
507 set_phi_nodes (basic_block bb, tree l)
509 tree phi;
511 bb->phi_nodes = l;
512 for (phi = l; phi; phi = PHI_CHAIN (phi))
513 set_bb_for_stmt (phi, bb);
516 /* Return the phi argument which contains the specified use. */
518 static inline int
519 phi_arg_index_from_use (use_operand_p use)
521 struct phi_arg_d *element, *root;
522 int index;
523 tree phi;
525 /* Since the use is the first thing in a PHI argument element, we can
526 calculate its index based on casting it to an argument, and performing
527 pointer arithmetic. */
529 phi = USE_STMT (use);
530 gcc_assert (TREE_CODE (phi) == PHI_NODE);
532 element = (struct phi_arg_d *)use;
533 root = &(PHI_ARG_ELT (phi, 0));
534 index = element - root;
536 #ifdef ENABLE_CHECKING
537 /* Make sure the calculation doesn't have any leftover bytes. If it does,
538 then imm_use is likely not the first element in phi_arg_d. */
539 gcc_assert (
540 (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
541 gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
542 #endif
544 return index;
547 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
549 static inline void
550 set_is_used (tree var)
552 var_ann_t ann = get_var_ann (var);
553 ann->used = 1;
557 /* ----------------------------------------------------------------------- */
559 /* Return true if T is an executable statement. */
560 static inline bool
561 is_exec_stmt (tree t)
563 return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
567 /* Return true if this stmt can be the target of a control transfer stmt such
568 as a goto. */
569 static inline bool
570 is_label_stmt (tree t)
572 if (t)
573 switch (TREE_CODE (t))
575 case LABEL_DECL:
576 case LABEL_EXPR:
577 case CASE_LABEL_EXPR:
578 return true;
579 default:
580 return false;
582 return false;
585 /* Set the default definition for VAR to DEF. */
586 static inline void
587 set_default_def (tree var, tree def)
589 var_ann_t ann = get_var_ann (var);
590 ann->default_def = def;
593 /* Return the default definition for variable VAR, or NULL if none
594 exists. */
595 static inline tree
596 default_def (tree var)
598 var_ann_t ann = var_ann (var);
599 return ann ? ann->default_def : NULL_TREE;
602 /* PHI nodes should contain only ssa_names and invariants. A test
603 for ssa_name is definitely simpler; don't let invalid contents
604 slip in in the meantime. */
606 static inline bool
607 phi_ssa_name_p (tree t)
609 if (TREE_CODE (t) == SSA_NAME)
610 return true;
611 #ifdef ENABLE_CHECKING
612 gcc_assert (is_gimple_min_invariant (t));
613 #endif
614 return false;
617 /* ----------------------------------------------------------------------- */
619 /* Return a block_stmt_iterator that points to beginning of basic
620 block BB. */
621 static inline block_stmt_iterator
622 bsi_start (basic_block bb)
624 block_stmt_iterator bsi;
625 if (bb->stmt_list)
626 bsi.tsi = tsi_start (bb->stmt_list);
627 else
629 gcc_assert (bb->index < 0);
630 bsi.tsi.ptr = NULL;
631 bsi.tsi.container = NULL;
633 bsi.bb = bb;
634 return bsi;
637 /* Return a block statement iterator that points to the last label in
638 block BB. */
640 static inline block_stmt_iterator
641 bsi_after_labels (basic_block bb)
643 block_stmt_iterator bsi;
644 tree_stmt_iterator next;
646 bsi.bb = bb;
648 if (!bb->stmt_list)
650 gcc_assert (bb->index < 0);
651 bsi.tsi.ptr = NULL;
652 bsi.tsi.container = NULL;
653 return bsi;
656 bsi.tsi = tsi_start (bb->stmt_list);
657 if (tsi_end_p (bsi.tsi))
658 return bsi;
660 /* Ensure that there are some labels. The rationale is that we want
661 to insert after the bsi that is returned, and these insertions should
662 be placed at the start of the basic block. This would not work if the
663 first statement was not label; rather fail here than enable the user
664 proceed in wrong way. */
665 gcc_assert (TREE_CODE (tsi_stmt (bsi.tsi)) == LABEL_EXPR);
667 next = bsi.tsi;
668 tsi_next (&next);
670 while (!tsi_end_p (next)
671 && TREE_CODE (tsi_stmt (next)) == LABEL_EXPR)
673 bsi.tsi = next;
674 tsi_next (&next);
677 return bsi;
680 /* Return a block statement iterator that points to the end of basic
681 block BB. */
682 static inline block_stmt_iterator
683 bsi_last (basic_block bb)
685 block_stmt_iterator bsi;
686 if (bb->stmt_list)
687 bsi.tsi = tsi_last (bb->stmt_list);
688 else
690 gcc_assert (bb->index < 0);
691 bsi.tsi.ptr = NULL;
692 bsi.tsi.container = NULL;
694 bsi.bb = bb;
695 return bsi;
698 /* Return true if block statement iterator I has reached the end of
699 the basic block. */
700 static inline bool
701 bsi_end_p (block_stmt_iterator i)
703 return tsi_end_p (i.tsi);
706 /* Modify block statement iterator I so that it is at the next
707 statement in the basic block. */
708 static inline void
709 bsi_next (block_stmt_iterator *i)
711 tsi_next (&i->tsi);
714 /* Modify block statement iterator I so that it is at the previous
715 statement in the basic block. */
716 static inline void
717 bsi_prev (block_stmt_iterator *i)
719 tsi_prev (&i->tsi);
722 /* Return the statement that block statement iterator I is currently
723 at. */
724 static inline tree
725 bsi_stmt (block_stmt_iterator i)
727 return tsi_stmt (i.tsi);
730 /* Return a pointer to the statement that block statement iterator I
731 is currently at. */
732 static inline tree *
733 bsi_stmt_ptr (block_stmt_iterator i)
735 return tsi_stmt_ptr (i.tsi);
738 /* Returns the loop of the statement STMT. */
740 static inline struct loop *
741 loop_containing_stmt (tree stmt)
743 basic_block bb = bb_for_stmt (stmt);
744 if (!bb)
745 return NULL;
747 return bb->loop_father;
750 /* Return true if VAR is a clobbered by function calls. */
751 static inline bool
752 is_call_clobbered (tree var)
754 return is_global_var (var)
755 || bitmap_bit_p (call_clobbered_vars, var_ann (var)->uid);
758 /* Mark variable VAR as being clobbered by function calls. */
759 static inline void
760 mark_call_clobbered (tree var)
762 var_ann_t ann = var_ann (var);
763 /* If VAR is a memory tag, then we need to consider it a global
764 variable. This is because the pointer that VAR represents has
765 been found to point to either an arbitrary location or to a known
766 location in global memory. */
767 if (ann->mem_tag_kind != NOT_A_TAG && ann->mem_tag_kind != STRUCT_FIELD)
768 DECL_EXTERNAL (var) = 1;
769 bitmap_set_bit (call_clobbered_vars, ann->uid);
770 ssa_call_clobbered_cache_valid = false;
771 ssa_ro_call_cache_valid = false;
774 /* Clear the call-clobbered attribute from variable VAR. */
775 static inline void
776 clear_call_clobbered (tree var)
778 var_ann_t ann = var_ann (var);
779 if (ann->mem_tag_kind != NOT_A_TAG && ann->mem_tag_kind != STRUCT_FIELD)
780 DECL_EXTERNAL (var) = 0;
781 bitmap_clear_bit (call_clobbered_vars, ann->uid);
782 ssa_call_clobbered_cache_valid = false;
783 ssa_ro_call_cache_valid = false;
786 /* Mark variable VAR as being non-addressable. */
787 static inline void
788 mark_non_addressable (tree var)
790 bitmap_clear_bit (call_clobbered_vars, var_ann (var)->uid);
791 TREE_ADDRESSABLE (var) = 0;
792 ssa_call_clobbered_cache_valid = false;
793 ssa_ro_call_cache_valid = false;
796 /* Return the common annotation for T. Return NULL if the annotation
797 doesn't already exist. */
798 static inline tree_ann_t
799 tree_ann (tree t)
801 return t->common.ann;
804 /* Return a common annotation for T. Create the constant annotation if it
805 doesn't exist. */
806 static inline tree_ann_t
807 get_tree_ann (tree t)
809 tree_ann_t ann = tree_ann (t);
810 return (ann) ? ann : create_tree_ann (t);
813 /* ----------------------------------------------------------------------- */
815 /* The following set of routines are used to iterator over various type of
816 SSA operands. */
818 /* Return true if PTR is finished iterating. */
819 static inline bool
820 op_iter_done (ssa_op_iter *ptr)
822 return ptr->done;
825 /* Get the next iterator use value for PTR. */
826 static inline use_operand_p
827 op_iter_next_use (ssa_op_iter *ptr)
829 use_operand_p use_p;
830 #ifdef ENABLE_CHECKING
831 gcc_assert (ptr->iter_type == ssa_op_iter_use);
832 #endif
833 if (ptr->uses)
835 use_p = USE_OP_PTR (ptr->uses);
836 ptr->uses = ptr->uses->next;
837 return use_p;
839 if (ptr->vuses)
841 use_p = VUSE_OP_PTR (ptr->vuses);
842 ptr->vuses = ptr->vuses->next;
843 return use_p;
845 if (ptr->mayuses)
847 use_p = MAYDEF_OP_PTR (ptr->mayuses);
848 ptr->mayuses = ptr->mayuses->next;
849 return use_p;
851 if (ptr->mustkills)
853 use_p = MUSTDEF_KILL_PTR (ptr->mustkills);
854 ptr->mustkills = ptr->mustkills->next;
855 return use_p;
857 if (ptr->phi_i < ptr->num_phi)
859 return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
861 ptr->done = true;
862 return NULL_USE_OPERAND_P;
865 /* Get the next iterator def value for PTR. */
866 static inline def_operand_p
867 op_iter_next_def (ssa_op_iter *ptr)
869 def_operand_p def_p;
870 #ifdef ENABLE_CHECKING
871 gcc_assert (ptr->iter_type == ssa_op_iter_def);
872 #endif
873 if (ptr->defs)
875 def_p = DEF_OP_PTR (ptr->defs);
876 ptr->defs = ptr->defs->next;
877 return def_p;
879 if (ptr->mustdefs)
881 def_p = MUSTDEF_RESULT_PTR (ptr->mustdefs);
882 ptr->mustdefs = ptr->mustdefs->next;
883 return def_p;
885 if (ptr->maydefs)
887 def_p = MAYDEF_RESULT_PTR (ptr->maydefs);
888 ptr->maydefs = ptr->maydefs->next;
889 return def_p;
891 ptr->done = true;
892 return NULL_DEF_OPERAND_P;
895 /* Get the next iterator tree value for PTR. */
896 static inline tree
897 op_iter_next_tree (ssa_op_iter *ptr)
899 tree val;
900 #ifdef ENABLE_CHECKING
901 gcc_assert (ptr->iter_type == ssa_op_iter_tree);
902 #endif
903 if (ptr->uses)
905 val = USE_OP (ptr->uses);
906 ptr->uses = ptr->uses->next;
907 return val;
909 if (ptr->vuses)
911 val = VUSE_OP (ptr->vuses);
912 ptr->vuses = ptr->vuses->next;
913 return val;
915 if (ptr->mayuses)
917 val = MAYDEF_OP (ptr->mayuses);
918 ptr->mayuses = ptr->mayuses->next;
919 return val;
921 if (ptr->mustkills)
923 val = MUSTDEF_KILL (ptr->mustkills);
924 ptr->mustkills = ptr->mustkills->next;
925 return val;
927 if (ptr->defs)
929 val = DEF_OP (ptr->defs);
930 ptr->defs = ptr->defs->next;
931 return val;
933 if (ptr->mustdefs)
935 val = MUSTDEF_RESULT (ptr->mustdefs);
936 ptr->mustdefs = ptr->mustdefs->next;
937 return val;
939 if (ptr->maydefs)
941 val = MAYDEF_RESULT (ptr->maydefs);
942 ptr->maydefs = ptr->maydefs->next;
943 return val;
946 ptr->done = true;
947 return NULL_TREE;
952 /* This functions clears the iterator PTR, and marks it done. This is normally
953 used to prevent warnings in the compile about might be uninitailzied
954 components. */
956 static inline void
957 clear_and_done_ssa_iter (ssa_op_iter *ptr)
959 ptr->defs = NULL;
960 ptr->uses = NULL;
961 ptr->vuses = NULL;
962 ptr->maydefs = NULL;
963 ptr->mayuses = NULL;
964 ptr->mustdefs = NULL;
965 ptr->mustkills = NULL;
966 ptr->iter_type = ssa_op_iter_none;
967 ptr->phi_i = 0;
968 ptr->num_phi = 0;
969 ptr->phi_stmt = NULL_TREE;
970 ptr->done = true;
973 /* Initialize the iterator PTR to the virtual defs in STMT. */
974 static inline void
975 op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
977 #ifdef ENABLE_CHECKING
978 gcc_assert (stmt_ann (stmt));
979 #endif
981 ptr->defs = (flags & SSA_OP_DEF) ? DEF_OPS (stmt) : NULL;
982 ptr->uses = (flags & SSA_OP_USE) ? USE_OPS (stmt) : NULL;
983 ptr->vuses = (flags & SSA_OP_VUSE) ? VUSE_OPS (stmt) : NULL;
984 ptr->maydefs = (flags & SSA_OP_VMAYDEF) ? MAYDEF_OPS (stmt) : NULL;
985 ptr->mayuses = (flags & SSA_OP_VMAYUSE) ? MAYDEF_OPS (stmt) : NULL;
986 ptr->mustdefs = (flags & SSA_OP_VMUSTDEF) ? MUSTDEF_OPS (stmt) : NULL;
987 ptr->mustkills = (flags & SSA_OP_VMUSTKILL) ? MUSTDEF_OPS (stmt) : NULL;
988 ptr->done = false;
990 ptr->phi_i = 0;
991 ptr->num_phi = 0;
992 ptr->phi_stmt = NULL_TREE;
995 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
996 the first use. */
997 static inline use_operand_p
998 op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
1000 gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0);
1001 op_iter_init (ptr, stmt, flags);
1002 ptr->iter_type = ssa_op_iter_use;
1003 return op_iter_next_use (ptr);
1006 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1007 the first def. */
1008 static inline def_operand_p
1009 op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1011 gcc_assert ((flags & (SSA_OP_ALL_USES | SSA_OP_VIRTUAL_KILLS)) == 0);
1012 op_iter_init (ptr, stmt, flags);
1013 ptr->iter_type = ssa_op_iter_def;
1014 return op_iter_next_def (ptr);
1017 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1018 the first operand as a tree. */
1019 static inline tree
1020 op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1022 op_iter_init (ptr, stmt, flags);
1023 ptr->iter_type = ssa_op_iter_tree;
1024 return op_iter_next_tree (ptr);
1027 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1028 KILL and DEF. */
1029 static inline void
1030 op_iter_next_maymustdef (use_operand_p *use, def_operand_p *def,
1031 ssa_op_iter *ptr)
1033 #ifdef ENABLE_CHECKING
1034 gcc_assert (ptr->iter_type == ssa_op_iter_maymustdef);
1035 #endif
1036 if (ptr->mayuses)
1038 *def = MAYDEF_RESULT_PTR (ptr->mayuses);
1039 *use = MAYDEF_OP_PTR (ptr->mayuses);
1040 ptr->mayuses = ptr->mayuses->next;
1041 return;
1044 if (ptr->mustkills)
1046 *def = MUSTDEF_RESULT_PTR (ptr->mustkills);
1047 *use = MUSTDEF_KILL_PTR (ptr->mustkills);
1048 ptr->mustkills = ptr->mustkills->next;
1049 return;
1052 *def = NULL_DEF_OPERAND_P;
1053 *use = NULL_USE_OPERAND_P;
1054 ptr->done = true;
1055 return;
1059 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1060 in USE and DEF. */
1061 static inline void
1062 op_iter_init_maydef (ssa_op_iter *ptr, tree stmt, use_operand_p *use,
1063 def_operand_p *def)
1065 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1067 op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1068 ptr->iter_type = ssa_op_iter_maymustdef;
1069 op_iter_next_maymustdef (use, def, ptr);
1073 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1074 in KILL and DEF. */
1075 static inline void
1076 op_iter_init_mustdef (ssa_op_iter *ptr, tree stmt, use_operand_p *kill,
1077 def_operand_p *def)
1079 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1081 op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL);
1082 ptr->iter_type = ssa_op_iter_maymustdef;
1083 op_iter_next_maymustdef (kill, def, ptr);
1086 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1087 in KILL and DEF. */
1088 static inline void
1089 op_iter_init_must_and_may_def (ssa_op_iter *ptr, tree stmt,
1090 use_operand_p *kill, def_operand_p *def)
1092 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1094 op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL|SSA_OP_VMAYUSE);
1095 ptr->iter_type = ssa_op_iter_maymustdef;
1096 op_iter_next_maymustdef (kill, def, ptr);
1100 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1101 return NULL. PTR is the iterator to use. */
1102 static inline tree
1103 single_ssa_tree_operand (tree stmt, int flags)
1105 tree var;
1106 ssa_op_iter iter;
1108 var = op_iter_init_tree (&iter, stmt, flags);
1109 if (op_iter_done (&iter))
1110 return NULL_TREE;
1111 op_iter_next_tree (&iter);
1112 if (op_iter_done (&iter))
1113 return var;
1114 return NULL_TREE;
1118 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1119 return NULL. PTR is the iterator to use. */
1120 static inline use_operand_p
1121 single_ssa_use_operand (tree stmt, int flags)
1123 use_operand_p var;
1124 ssa_op_iter iter;
1126 var = op_iter_init_use (&iter, stmt, flags);
1127 if (op_iter_done (&iter))
1128 return NULL_USE_OPERAND_P;
1129 op_iter_next_use (&iter);
1130 if (op_iter_done (&iter))
1131 return var;
1132 return NULL_USE_OPERAND_P;
1137 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1138 return NULL. PTR is the iterator to use. */
1139 static inline def_operand_p
1140 single_ssa_def_operand (tree stmt, int flags)
1142 def_operand_p var;
1143 ssa_op_iter iter;
1145 var = op_iter_init_def (&iter, stmt, flags);
1146 if (op_iter_done (&iter))
1147 return NULL_DEF_OPERAND_P;
1148 op_iter_next_def (&iter);
1149 if (op_iter_done (&iter))
1150 return var;
1151 return NULL_DEF_OPERAND_P;
1155 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1156 return NULL. PTR is the iterator to use. */
1157 static inline bool
1158 zero_ssa_operands (tree stmt, int flags)
1160 ssa_op_iter iter;
1162 op_iter_init_tree (&iter, stmt, flags);
1163 return op_iter_done (&iter);
1167 /* Return the number of operands matching FLAGS in STMT. */
1168 static inline int
1169 num_ssa_operands (tree stmt, int flags)
1171 ssa_op_iter iter;
1172 tree t;
1173 int num = 0;
1175 FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
1176 num++;
1177 return num;
1181 /* Delink all immediate_use information for STMT. */
1182 static inline void
1183 delink_stmt_imm_use (tree stmt)
1185 ssa_op_iter iter;
1186 use_operand_p use_p;
1188 if (ssa_operands_active ())
1189 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter,
1190 (SSA_OP_ALL_USES | SSA_OP_ALL_KILLS))
1191 delink_imm_use (use_p);
1195 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1196 in STMT2. TRUE is returned if they are the same. STMTs can be NULL. */
1197 static inline bool
1198 compare_ssa_operands_equal (tree stmt1, tree stmt2, int flags)
1200 ssa_op_iter iter1, iter2;
1201 tree op1 = NULL_TREE;
1202 tree op2 = NULL_TREE;
1203 bool look1, look2;
1205 if (stmt1 == stmt2)
1206 return true;
1208 look1 = stmt1 && stmt_ann (stmt1);
1209 look2 = stmt2 && stmt_ann (stmt2);
1211 if (look1)
1213 op1 = op_iter_init_tree (&iter1, stmt1, flags);
1214 if (!look2)
1215 return op_iter_done (&iter1);
1217 else
1218 clear_and_done_ssa_iter (&iter1);
1220 if (look2)
1222 op2 = op_iter_init_tree (&iter2, stmt2, flags);
1223 if (!look1)
1224 return op_iter_done (&iter2);
1226 else
1227 clear_and_done_ssa_iter (&iter2);
1229 while (!op_iter_done (&iter1) && !op_iter_done (&iter2))
1231 if (op1 != op2)
1232 return false;
1233 op1 = op_iter_next_tree (&iter1);
1234 op2 = op_iter_next_tree (&iter2);
1237 return (op_iter_done (&iter1) && op_iter_done (&iter2));
1241 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1242 Otherwise return NULL_DEF_OPERAND_P. */
1243 static inline tree
1244 single_phi_def (tree stmt, int flags)
1246 tree def = PHI_RESULT (stmt);
1247 if ((flags & SSA_OP_DEF) && is_gimple_reg (def))
1248 return def;
1249 if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
1250 return def;
1251 return NULL_TREE;
1254 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
1255 be either SSA_OP_USES or SAS_OP_VIRTUAL_USES. */
1256 static inline use_operand_p
1257 op_iter_init_phiuse (ssa_op_iter *ptr, tree phi, int flags)
1259 tree phi_def = PHI_RESULT (phi);
1260 int comp;
1262 clear_and_done_ssa_iter (ptr);
1263 ptr->done = false;
1265 gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
1267 comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1269 /* If the PHI node doesn't the operand type we care about, we're done. */
1270 if ((flags & comp) == 0)
1272 ptr->done = true;
1273 return NULL_USE_OPERAND_P;
1276 ptr->phi_stmt = phi;
1277 ptr->num_phi = PHI_NUM_ARGS (phi);
1278 ptr->iter_type = ssa_op_iter_use;
1279 return op_iter_next_use (ptr);
1283 /* Start an iterator for a PHI definition. */
1285 static inline def_operand_p
1286 op_iter_init_phidef (ssa_op_iter *ptr, tree phi, int flags)
1288 tree phi_def = PHI_RESULT (phi);
1289 int comp;
1291 clear_and_done_ssa_iter (ptr);
1292 ptr->done = false;
1294 gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
1296 comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
1298 /* If the PHI node doesn't the operand type we care about, we're done. */
1299 if ((flags & comp) == 0)
1301 ptr->done = true;
1302 return NULL_USE_OPERAND_P;
1305 ptr->iter_type = ssa_op_iter_def;
1306 /* The first call to op_iter_next_def will terminate the iterator since
1307 all the fields are NULL. Simply return the result here as the first and
1308 therefore only result. */
1309 return PHI_RESULT_PTR (phi);
1314 /* Return true if VAR cannot be modified by the program. */
1316 static inline bool
1317 unmodifiable_var_p (tree var)
1319 if (TREE_CODE (var) == SSA_NAME)
1320 var = SSA_NAME_VAR (var);
1321 return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1324 /* Return true if REF, a COMPONENT_REF, has an ARRAY_REF somewhere in it. */
1326 static inline bool
1327 ref_contains_array_ref (tree ref)
1329 while (handled_component_p (ref))
1331 if (TREE_CODE (ref) == ARRAY_REF)
1332 return true;
1333 ref = TREE_OPERAND (ref, 0);
1335 return false;
1338 /* Given a variable VAR, lookup and return a pointer to the list of
1339 subvariables for it. */
1341 static inline subvar_t *
1342 lookup_subvars_for_var (tree var)
1344 var_ann_t ann = var_ann (var);
1345 gcc_assert (ann);
1346 return &ann->subvars;
1349 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1350 NULL, if there are no subvariables. */
1352 static inline subvar_t
1353 get_subvars_for_var (tree var)
1355 subvar_t subvars;
1357 gcc_assert (SSA_VAR_P (var));
1359 if (TREE_CODE (var) == SSA_NAME)
1360 subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
1361 else
1362 subvars = *(lookup_subvars_for_var (var));
1363 return subvars;
1366 /* Return true if V is a tree that we can have subvars for.
1367 Normally, this is any aggregate type, however, due to implementation
1368 limitations ATM, we exclude array types as well. */
1370 static inline bool
1371 var_can_have_subvars (tree v)
1373 return (AGGREGATE_TYPE_P (TREE_TYPE (v)) &&
1374 TREE_CODE (TREE_TYPE (v)) != ARRAY_TYPE);
1378 /* Return true if OFFSET and SIZE define a range that overlaps with some
1379 portion of the range of SV, a subvar. If there was an exact overlap,
1380 *EXACT will be set to true upon return. */
1382 static inline bool
1383 overlap_subvar (HOST_WIDE_INT offset, HOST_WIDE_INT size,
1384 subvar_t sv, bool *exact)
1386 /* There are three possible cases of overlap.
1387 1. We can have an exact overlap, like so:
1388 |offset, offset + size |
1389 |sv->offset, sv->offset + sv->size |
1391 2. We can have offset starting after sv->offset, like so:
1393 |offset, offset + size |
1394 |sv->offset, sv->offset + sv->size |
1396 3. We can have offset starting before sv->offset, like so:
1398 |offset, offset + size |
1399 |sv->offset, sv->offset + sv->size|
1402 if (exact)
1403 *exact = false;
1404 if (offset == sv->offset && size == sv->size)
1406 if (exact)
1407 *exact = true;
1408 return true;
1410 else if (offset >= sv->offset && offset < (sv->offset + sv->size))
1412 return true;
1414 else if (offset < sv->offset && (offset + size > sv->offset))
1416 return true;
1418 return false;
1422 #endif /* _TREE_FLOW_INLINE_H */