1 /* Inline functions for tree-flow.h
2 Copyright (C) 2001, 2003, 2005, 2006 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)
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 /* Initialize the hashtable iterator HTI to point to hashtable TABLE */
31 first_htab_element (htab_iterator *hti, htab_t table)
34 hti->slot = table->entries;
35 hti->limit = hti->slot + htab_size (table);
39 if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
41 } while (++(hti->slot) < hti->limit);
43 if (hti->slot < hti->limit)
48 /* Return current non-empty/deleted slot of the hashtable pointed to by HTI,
49 or NULL if we have reached the end. */
52 end_htab_p (htab_iterator *hti)
54 if (hti->slot >= hti->limit)
59 /* Advance the hashtable iterator pointed to by HTI to the next element of the
63 next_htab_element (htab_iterator *hti)
65 while (++(hti->slot) < hti->limit)
68 if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
74 /* Initialize ITER to point to the first referenced variable in the
75 referenced_vars hashtable, and return that variable. */
78 first_referenced_var (referenced_var_iterator *iter)
80 struct int_tree_map *itm;
81 itm = (struct int_tree_map *) first_htab_element (&iter->hti,
88 /* Return true if we have hit the end of the referenced variables ITER is
92 end_referenced_vars_p (referenced_var_iterator *iter)
94 return end_htab_p (&iter->hti);
97 /* Make ITER point to the next referenced_var in the referenced_var hashtable,
98 and return that variable. */
101 next_referenced_var (referenced_var_iterator *iter)
103 struct int_tree_map *itm;
104 itm = (struct int_tree_map *) next_htab_element (&iter->hti);
110 /* Fill up VEC with the variables in the referenced vars hashtable. */
113 fill_referenced_var_vec (VEC (tree, heap) **vec)
115 referenced_var_iterator rvi;
118 FOR_EACH_REFERENCED_VAR (var, rvi)
119 VEC_safe_push (tree, heap, *vec, var);
122 /* Return the variable annotation for T, which must be a _DECL node.
123 Return NULL if the variable annotation doesn't already exist. */
124 static inline var_ann_t
128 gcc_assert (DECL_P (t));
129 gcc_assert (TREE_CODE (t) != FUNCTION_DECL);
130 gcc_assert (!t->common.ann || t->common.ann->common.type == VAR_ANN);
132 return (var_ann_t) t->common.ann;
135 /* Return the variable annotation for T, which must be a _DECL node.
136 Create the variable annotation if it doesn't exist. */
137 static inline var_ann_t
138 get_var_ann (tree var)
140 var_ann_t ann = var_ann (var);
141 return (ann) ? ann : create_var_ann (var);
144 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
145 Return NULL if the function annotation doesn't already exist. */
146 static inline function_ann_t
147 function_ann (tree t)
150 gcc_assert (TREE_CODE (t) == FUNCTION_DECL);
151 gcc_assert (!t->common.ann || t->common.ann->common.type == FUNCTION_ANN);
153 return (function_ann_t) t->common.ann;
156 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
157 Create the function annotation if it doesn't exist. */
158 static inline function_ann_t
159 get_function_ann (tree var)
161 function_ann_t ann = function_ann (var);
162 gcc_assert (!var->common.ann || var->common.ann->common.type == FUNCTION_ANN);
163 return (ann) ? ann : create_function_ann (var);
166 /* Return true if T has a statement annotation attached to it. */
169 has_stmt_ann (tree t)
171 #ifdef ENABLE_CHECKING
172 gcc_assert (is_gimple_stmt (t));
174 return t->common.ann && t->common.ann->common.type == STMT_ANN;
177 /* Return the statement annotation for T, which must be a statement
178 node. Return NULL if the statement annotation doesn't exist. */
179 static inline stmt_ann_t
182 #ifdef ENABLE_CHECKING
183 gcc_assert (is_gimple_stmt (t));
185 gcc_assert (!t->common.ann || t->common.ann->common.type == STMT_ANN);
186 return (stmt_ann_t) t->common.ann;
189 /* Return the statement annotation for T, which must be a statement
190 node. Create the statement annotation if it doesn't exist. */
191 static inline stmt_ann_t
192 get_stmt_ann (tree stmt)
194 stmt_ann_t ann = stmt_ann (stmt);
195 return (ann) ? ann : create_stmt_ann (stmt);
198 /* Return the annotation type for annotation ANN. */
199 static inline enum tree_ann_type
200 ann_type (tree_ann_t ann)
202 return ann->common.type;
205 /* Return the basic block for statement T. */
206 static inline basic_block
211 if (TREE_CODE (t) == PHI_NODE)
215 return ann ? ann->bb : NULL;
218 /* Return the may_aliases varray for variable VAR, or NULL if it has
220 static inline VEC(tree, gc) *
221 may_aliases (tree var)
223 var_ann_t ann = var_ann (var);
224 return ann ? ann->may_aliases : NULL;
227 /* Return the line number for EXPR, or return -1 if we have no line
228 number information for it. */
230 get_lineno (tree expr)
232 if (expr == NULL_TREE)
235 if (TREE_CODE (expr) == COMPOUND_EXPR)
236 expr = TREE_OPERAND (expr, 0);
238 if (! EXPR_HAS_LOCATION (expr))
241 return EXPR_LINENO (expr);
244 /* Return the file name for EXPR, or return "???" if we have no
245 filename information. */
246 static inline const char *
247 get_filename (tree expr)
249 const char *filename;
250 if (expr == NULL_TREE)
253 if (TREE_CODE (expr) == COMPOUND_EXPR)
254 expr = TREE_OPERAND (expr, 0);
256 if (EXPR_HAS_LOCATION (expr) && (filename = EXPR_FILENAME (expr)))
262 /* Return true if T is a noreturn call. */
264 noreturn_call_p (tree t)
266 tree call = get_call_expr_in (t);
267 return call != 0 && (call_expr_flags (call) & ECF_NORETURN) != 0;
270 /* Mark statement T as modified. */
272 mark_stmt_modified (tree t)
275 if (TREE_CODE (t) == PHI_NODE)
280 ann = create_stmt_ann (t);
281 else if (noreturn_call_p (t))
282 VEC_safe_push (tree, gc, modified_noreturn_calls, t);
286 /* Mark statement T as modified, and update it. */
290 if (TREE_CODE (t) == PHI_NODE)
292 mark_stmt_modified (t);
293 update_stmt_operands (t);
297 update_stmt_if_modified (tree t)
299 if (stmt_modified_p (t))
300 update_stmt_operands (t);
303 /* Return true if T is marked as modified, false otherwise. */
305 stmt_modified_p (tree t)
307 stmt_ann_t ann = stmt_ann (t);
309 /* Note that if the statement doesn't yet have an annotation, we consider it
310 modified. This will force the next call to update_stmt_operands to scan
312 return ann ? ann->modified : true;
315 /* Delink an immediate_uses node from its chain. */
317 delink_imm_use (ssa_use_operand_t *linknode)
319 /* Return if this node is not in a list. */
320 if (linknode->prev == NULL)
323 linknode->prev->next = linknode->next;
324 linknode->next->prev = linknode->prev;
325 linknode->prev = NULL;
326 linknode->next = NULL;
329 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
331 link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
333 /* Link the new node at the head of the list. If we are in the process of
334 traversing the list, we won't visit any new nodes added to it. */
335 linknode->prev = list;
336 linknode->next = list->next;
337 list->next->prev = linknode;
338 list->next = linknode;
341 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
343 link_imm_use (ssa_use_operand_t *linknode, tree def)
345 ssa_use_operand_t *root;
347 if (!def || TREE_CODE (def) != SSA_NAME)
348 linknode->prev = NULL;
351 root = &(SSA_NAME_IMM_USE_NODE (def));
352 #ifdef ENABLE_CHECKING
354 gcc_assert (*(linknode->use) == def);
356 link_imm_use_to_list (linknode, root);
360 /* Set the value of a use pointed to by USE to VAL. */
362 set_ssa_use_from_ptr (use_operand_p use, tree val)
364 delink_imm_use (use);
366 link_imm_use (use, val);
369 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
372 link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, tree stmt)
375 link_imm_use (linknode, def);
377 link_imm_use (linknode, NULL);
378 linknode->stmt = stmt;
381 /* Relink a new node in place of an old node in the list. */
383 relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
385 /* The node one had better be in the same list. */
386 gcc_assert (*(old->use) == *(node->use));
387 node->prev = old->prev;
388 node->next = old->next;
391 old->prev->next = node;
392 old->next->prev = node;
393 /* Remove the old node from the list. */
398 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
401 relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old, tree stmt)
404 relink_imm_use (linknode, old);
406 link_imm_use (linknode, NULL);
407 linknode->stmt = stmt;
411 /* Return true is IMM has reached the end of the immediate use list. */
413 end_readonly_imm_use_p (imm_use_iterator *imm)
415 return (imm->imm_use == imm->end_p);
418 /* Initialize iterator IMM to process the list for VAR. */
419 static inline use_operand_p
420 first_readonly_imm_use (imm_use_iterator *imm, tree var)
422 gcc_assert (TREE_CODE (var) == SSA_NAME);
424 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
425 imm->imm_use = imm->end_p->next;
426 #ifdef ENABLE_CHECKING
427 imm->iter_node.next = imm->imm_use->next;
429 if (end_readonly_imm_use_p (imm))
430 return NULL_USE_OPERAND_P;
434 /* Bump IMM to the next use in the list. */
435 static inline use_operand_p
436 next_readonly_imm_use (imm_use_iterator *imm)
438 use_operand_p old = imm->imm_use;
440 #ifdef ENABLE_CHECKING
441 /* If this assertion fails, it indicates the 'next' pointer has changed
442 since we the last bump. This indicates that the list is being modified
443 via stmt changes, or SET_USE, or somesuch thing, and you need to be
444 using the SAFE version of the iterator. */
445 gcc_assert (imm->iter_node.next == old->next);
446 imm->iter_node.next = old->next->next;
449 imm->imm_use = old->next;
450 if (end_readonly_imm_use_p (imm))
455 /* Return true if VAR has no uses. */
457 has_zero_uses (tree var)
459 ssa_use_operand_t *ptr;
460 ptr = &(SSA_NAME_IMM_USE_NODE (var));
461 /* A single use means there is no items in the list. */
462 return (ptr == ptr->next);
465 /* Return true if VAR has a single use. */
467 has_single_use (tree var)
469 ssa_use_operand_t *ptr;
470 ptr = &(SSA_NAME_IMM_USE_NODE (var));
471 /* A single use means there is one item in the list. */
472 return (ptr != ptr->next && ptr == ptr->next->next);
475 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
476 to the use pointer and stmt of occurrence. */
478 single_imm_use (tree var, use_operand_p *use_p, tree *stmt)
480 ssa_use_operand_t *ptr;
482 ptr = &(SSA_NAME_IMM_USE_NODE (var));
483 if (ptr != ptr->next && ptr == ptr->next->next)
486 *stmt = ptr->next->stmt;
489 *use_p = NULL_USE_OPERAND_P;
494 /* Return the number of immediate uses of VAR. */
495 static inline unsigned int
496 num_imm_uses (tree var)
498 ssa_use_operand_t *ptr, *start;
501 start = &(SSA_NAME_IMM_USE_NODE (var));
503 for (ptr = start->next; ptr != start; ptr = ptr->next)
510 /* Return the tree pointer to by USE. */
512 get_use_from_ptr (use_operand_p use)
517 /* Return the tree pointer to by DEF. */
519 get_def_from_ptr (def_operand_p def)
524 /* Return a def_operand_p pointer for the result of PHI. */
525 static inline def_operand_p
526 get_phi_result_ptr (tree phi)
528 return &(PHI_RESULT_TREE (phi));
531 /* Return a use_operand_p pointer for argument I of phinode PHI. */
532 static inline use_operand_p
533 get_phi_arg_def_ptr (tree phi, int i)
535 return &(PHI_ARG_IMM_USE_NODE (phi,i));
539 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
542 addresses_taken (tree stmt)
544 stmt_ann_t ann = stmt_ann (stmt);
545 return ann ? ann->addresses_taken : NULL;
548 /* Return the PHI nodes for basic block BB, or NULL if there are no
551 phi_nodes (basic_block bb)
553 return bb->phi_nodes;
556 /* Set list of phi nodes of a basic block BB to L. */
559 set_phi_nodes (basic_block bb, tree l)
564 for (phi = l; phi; phi = PHI_CHAIN (phi))
565 set_bb_for_stmt (phi, bb);
568 /* Return the phi argument which contains the specified use. */
571 phi_arg_index_from_use (use_operand_p use)
573 struct phi_arg_d *element, *root;
577 /* Since the use is the first thing in a PHI argument element, we can
578 calculate its index based on casting it to an argument, and performing
579 pointer arithmetic. */
581 phi = USE_STMT (use);
582 gcc_assert (TREE_CODE (phi) == PHI_NODE);
584 element = (struct phi_arg_d *)use;
585 root = &(PHI_ARG_ELT (phi, 0));
586 index = element - root;
588 #ifdef ENABLE_CHECKING
589 /* Make sure the calculation doesn't have any leftover bytes. If it does,
590 then imm_use is likely not the first element in phi_arg_d. */
592 (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
593 gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
599 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
602 set_is_used (tree var)
604 var_ann_t ann = get_var_ann (var);
609 /* ----------------------------------------------------------------------- */
611 /* Return true if T is an executable statement. */
613 is_exec_stmt (tree t)
615 return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
619 /* Return true if this stmt can be the target of a control transfer stmt such
622 is_label_stmt (tree t)
625 switch (TREE_CODE (t))
629 case CASE_LABEL_EXPR:
637 /* PHI nodes should contain only ssa_names and invariants. A test
638 for ssa_name is definitely simpler; don't let invalid contents
639 slip in in the meantime. */
642 phi_ssa_name_p (tree t)
644 if (TREE_CODE (t) == SSA_NAME)
646 #ifdef ENABLE_CHECKING
647 gcc_assert (is_gimple_min_invariant (t));
652 /* ----------------------------------------------------------------------- */
654 /* Return a block_stmt_iterator that points to beginning of basic
656 static inline block_stmt_iterator
657 bsi_start (basic_block bb)
659 block_stmt_iterator bsi;
661 bsi.tsi = tsi_start (bb->stmt_list);
664 gcc_assert (bb->index < NUM_FIXED_BLOCKS);
666 bsi.tsi.container = NULL;
672 /* Return a block statement iterator that points to the first non-label
673 statement in block BB. */
675 static inline block_stmt_iterator
676 bsi_after_labels (basic_block bb)
678 block_stmt_iterator bsi = bsi_start (bb);
680 while (!bsi_end_p (bsi) && TREE_CODE (bsi_stmt (bsi)) == LABEL_EXPR)
686 /* Return a block statement iterator that points to the end of basic
688 static inline block_stmt_iterator
689 bsi_last (basic_block bb)
691 block_stmt_iterator bsi;
693 bsi.tsi = tsi_last (bb->stmt_list);
696 gcc_assert (bb->index < NUM_FIXED_BLOCKS);
698 bsi.tsi.container = NULL;
704 /* Return true if block statement iterator I has reached the end of
707 bsi_end_p (block_stmt_iterator i)
709 return tsi_end_p (i.tsi);
712 /* Modify block statement iterator I so that it is at the next
713 statement in the basic block. */
715 bsi_next (block_stmt_iterator *i)
720 /* Modify block statement iterator I so that it is at the previous
721 statement in the basic block. */
723 bsi_prev (block_stmt_iterator *i)
728 /* Return the statement that block statement iterator I is currently
731 bsi_stmt (block_stmt_iterator i)
733 return tsi_stmt (i.tsi);
736 /* Return a pointer to the statement that block statement iterator I
739 bsi_stmt_ptr (block_stmt_iterator i)
741 return tsi_stmt_ptr (i.tsi);
744 /* Returns the loop of the statement STMT. */
746 static inline struct loop *
747 loop_containing_stmt (tree stmt)
749 basic_block bb = bb_for_stmt (stmt);
753 return bb->loop_father;
756 /* Return true if VAR is a clobbered by function calls. */
758 is_call_clobbered (tree var)
761 return DECL_CALL_CLOBBERED (var);
763 return bitmap_bit_p (call_clobbered_vars, DECL_UID (var));
766 /* Mark variable VAR as being clobbered by function calls. */
768 mark_call_clobbered (tree var, unsigned int escape_type)
770 var_ann (var)->escape_mask |= escape_type;
772 DECL_CALL_CLOBBERED (var) = true;
773 bitmap_set_bit (call_clobbered_vars, DECL_UID (var));
776 /* Clear the call-clobbered attribute from variable VAR. */
778 clear_call_clobbered (tree var)
780 var_ann_t ann = var_ann (var);
781 ann->escape_mask = 0;
782 if (MTAG_P (var) && TREE_CODE (var) != STRUCT_FIELD_TAG)
783 MTAG_GLOBAL (var) = 0;
785 DECL_CALL_CLOBBERED (var) = false;
786 bitmap_clear_bit (call_clobbered_vars, DECL_UID (var));
789 /* Mark variable VAR as being non-addressable. */
791 mark_non_addressable (tree var)
794 DECL_CALL_CLOBBERED (var) = false;
795 bitmap_clear_bit (call_clobbered_vars, DECL_UID (var));
796 TREE_ADDRESSABLE (var) = 0;
799 /* Return the common annotation for T. Return NULL if the annotation
800 doesn't already exist. */
801 static inline tree_ann_common_t
802 tree_common_ann (tree t)
804 return &t->common.ann->common;
807 /* Return a common annotation for T. Create the constant annotation if it
809 static inline tree_ann_common_t
810 get_tree_common_ann (tree t)
812 tree_ann_common_t ann = tree_common_ann (t);
813 return (ann) ? ann : create_tree_common_ann (t);
816 /* ----------------------------------------------------------------------- */
818 /* The following set of routines are used to iterator over various type of
821 /* Return true if PTR is finished iterating. */
823 op_iter_done (ssa_op_iter *ptr)
828 /* Get the next iterator use value for PTR. */
829 static inline use_operand_p
830 op_iter_next_use (ssa_op_iter *ptr)
833 #ifdef ENABLE_CHECKING
834 gcc_assert (ptr->iter_type == ssa_op_iter_use);
838 use_p = USE_OP_PTR (ptr->uses);
839 ptr->uses = ptr->uses->next;
844 use_p = VUSE_OP_PTR (ptr->vuses);
845 ptr->vuses = ptr->vuses->next;
850 use_p = MAYDEF_OP_PTR (ptr->mayuses);
851 ptr->mayuses = ptr->mayuses->next;
856 use_p = MUSTDEF_KILL_PTR (ptr->mustkills);
857 ptr->mustkills = ptr->mustkills->next;
860 if (ptr->phi_i < ptr->num_phi)
862 return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
865 return NULL_USE_OPERAND_P;
868 /* Get the next iterator def value for PTR. */
869 static inline def_operand_p
870 op_iter_next_def (ssa_op_iter *ptr)
873 #ifdef ENABLE_CHECKING
874 gcc_assert (ptr->iter_type == ssa_op_iter_def);
878 def_p = DEF_OP_PTR (ptr->defs);
879 ptr->defs = ptr->defs->next;
884 def_p = MUSTDEF_RESULT_PTR (ptr->mustdefs);
885 ptr->mustdefs = ptr->mustdefs->next;
890 def_p = MAYDEF_RESULT_PTR (ptr->maydefs);
891 ptr->maydefs = ptr->maydefs->next;
895 return NULL_DEF_OPERAND_P;
898 /* Get the next iterator tree value for PTR. */
900 op_iter_next_tree (ssa_op_iter *ptr)
903 #ifdef ENABLE_CHECKING
904 gcc_assert (ptr->iter_type == ssa_op_iter_tree);
908 val = USE_OP (ptr->uses);
909 ptr->uses = ptr->uses->next;
914 val = VUSE_OP (ptr->vuses);
915 ptr->vuses = ptr->vuses->next;
920 val = MAYDEF_OP (ptr->mayuses);
921 ptr->mayuses = ptr->mayuses->next;
926 val = MUSTDEF_KILL (ptr->mustkills);
927 ptr->mustkills = ptr->mustkills->next;
932 val = DEF_OP (ptr->defs);
933 ptr->defs = ptr->defs->next;
938 val = MUSTDEF_RESULT (ptr->mustdefs);
939 ptr->mustdefs = ptr->mustdefs->next;
944 val = MAYDEF_RESULT (ptr->maydefs);
945 ptr->maydefs = ptr->maydefs->next;
955 /* This functions clears the iterator PTR, and marks it done. This is normally
956 used to prevent warnings in the compile about might be uninitialized
960 clear_and_done_ssa_iter (ssa_op_iter *ptr)
967 ptr->mustdefs = NULL;
968 ptr->mustkills = NULL;
969 ptr->iter_type = ssa_op_iter_none;
972 ptr->phi_stmt = NULL_TREE;
976 /* Initialize the iterator PTR to the virtual defs in STMT. */
978 op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
980 #ifdef ENABLE_CHECKING
981 gcc_assert (stmt_ann (stmt));
984 ptr->defs = (flags & SSA_OP_DEF) ? DEF_OPS (stmt) : NULL;
985 ptr->uses = (flags & SSA_OP_USE) ? USE_OPS (stmt) : NULL;
986 ptr->vuses = (flags & SSA_OP_VUSE) ? VUSE_OPS (stmt) : NULL;
987 ptr->maydefs = (flags & SSA_OP_VMAYDEF) ? MAYDEF_OPS (stmt) : NULL;
988 ptr->mayuses = (flags & SSA_OP_VMAYUSE) ? MAYDEF_OPS (stmt) : NULL;
989 ptr->mustdefs = (flags & SSA_OP_VMUSTDEF) ? MUSTDEF_OPS (stmt) : NULL;
990 ptr->mustkills = (flags & SSA_OP_VMUSTKILL) ? MUSTDEF_OPS (stmt) : NULL;
995 ptr->phi_stmt = NULL_TREE;
998 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1000 static inline use_operand_p
1001 op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
1003 gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0);
1004 op_iter_init (ptr, stmt, flags);
1005 ptr->iter_type = ssa_op_iter_use;
1006 return op_iter_next_use (ptr);
1009 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1011 static inline def_operand_p
1012 op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1014 gcc_assert ((flags & (SSA_OP_ALL_USES | SSA_OP_VIRTUAL_KILLS)) == 0);
1015 op_iter_init (ptr, stmt, flags);
1016 ptr->iter_type = ssa_op_iter_def;
1017 return op_iter_next_def (ptr);
1020 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1021 the first operand as a tree. */
1023 op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1025 op_iter_init (ptr, stmt, flags);
1026 ptr->iter_type = ssa_op_iter_tree;
1027 return op_iter_next_tree (ptr);
1030 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1033 op_iter_next_maymustdef (use_operand_p *use, def_operand_p *def,
1036 #ifdef ENABLE_CHECKING
1037 gcc_assert (ptr->iter_type == ssa_op_iter_maymustdef);
1041 *def = MAYDEF_RESULT_PTR (ptr->mayuses);
1042 *use = MAYDEF_OP_PTR (ptr->mayuses);
1043 ptr->mayuses = ptr->mayuses->next;
1049 *def = MUSTDEF_RESULT_PTR (ptr->mustkills);
1050 *use = MUSTDEF_KILL_PTR (ptr->mustkills);
1051 ptr->mustkills = ptr->mustkills->next;
1055 *def = NULL_DEF_OPERAND_P;
1056 *use = NULL_USE_OPERAND_P;
1062 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1065 op_iter_init_maydef (ssa_op_iter *ptr, tree stmt, use_operand_p *use,
1068 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1070 op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1071 ptr->iter_type = ssa_op_iter_maymustdef;
1072 op_iter_next_maymustdef (use, def, ptr);
1076 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1079 op_iter_init_mustdef (ssa_op_iter *ptr, tree stmt, use_operand_p *kill,
1082 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1084 op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL);
1085 ptr->iter_type = ssa_op_iter_maymustdef;
1086 op_iter_next_maymustdef (kill, def, ptr);
1089 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1092 op_iter_init_must_and_may_def (ssa_op_iter *ptr, tree stmt,
1093 use_operand_p *kill, def_operand_p *def)
1095 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1097 op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL|SSA_OP_VMAYUSE);
1098 ptr->iter_type = ssa_op_iter_maymustdef;
1099 op_iter_next_maymustdef (kill, def, ptr);
1103 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1106 single_ssa_tree_operand (tree stmt, int flags)
1111 var = op_iter_init_tree (&iter, stmt, flags);
1112 if (op_iter_done (&iter))
1114 op_iter_next_tree (&iter);
1115 if (op_iter_done (&iter))
1121 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1123 static inline use_operand_p
1124 single_ssa_use_operand (tree stmt, int flags)
1129 var = op_iter_init_use (&iter, stmt, flags);
1130 if (op_iter_done (&iter))
1131 return NULL_USE_OPERAND_P;
1132 op_iter_next_use (&iter);
1133 if (op_iter_done (&iter))
1135 return NULL_USE_OPERAND_P;
1140 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1142 static inline def_operand_p
1143 single_ssa_def_operand (tree stmt, int flags)
1148 var = op_iter_init_def (&iter, stmt, flags);
1149 if (op_iter_done (&iter))
1150 return NULL_DEF_OPERAND_P;
1151 op_iter_next_def (&iter);
1152 if (op_iter_done (&iter))
1154 return NULL_DEF_OPERAND_P;
1158 /* Return true if there are zero operands in STMT matching the type
1161 zero_ssa_operands (tree stmt, int flags)
1165 op_iter_init_tree (&iter, stmt, flags);
1166 return op_iter_done (&iter);
1170 /* Return the number of operands matching FLAGS in STMT. */
1172 num_ssa_operands (tree stmt, int flags)
1178 FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
1184 /* Delink all immediate_use information for STMT. */
1186 delink_stmt_imm_use (tree stmt)
1189 use_operand_p use_p;
1191 if (ssa_operands_active ())
1192 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter,
1193 (SSA_OP_ALL_USES | SSA_OP_ALL_KILLS))
1194 delink_imm_use (use_p);
1198 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1199 in STMT2. TRUE is returned if they are the same. STMTs can be NULL. */
1201 compare_ssa_operands_equal (tree stmt1, tree stmt2, int flags)
1203 ssa_op_iter iter1, iter2;
1204 tree op1 = NULL_TREE;
1205 tree op2 = NULL_TREE;
1211 look1 = stmt1 && stmt_ann (stmt1);
1212 look2 = stmt2 && stmt_ann (stmt2);
1216 op1 = op_iter_init_tree (&iter1, stmt1, flags);
1218 return op_iter_done (&iter1);
1221 clear_and_done_ssa_iter (&iter1);
1225 op2 = op_iter_init_tree (&iter2, stmt2, flags);
1227 return op_iter_done (&iter2);
1230 clear_and_done_ssa_iter (&iter2);
1232 while (!op_iter_done (&iter1) && !op_iter_done (&iter2))
1236 op1 = op_iter_next_tree (&iter1);
1237 op2 = op_iter_next_tree (&iter2);
1240 return (op_iter_done (&iter1) && op_iter_done (&iter2));
1244 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1245 Otherwise return NULL_DEF_OPERAND_P. */
1247 single_phi_def (tree stmt, int flags)
1249 tree def = PHI_RESULT (stmt);
1250 if ((flags & SSA_OP_DEF) && is_gimple_reg (def))
1252 if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
1257 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
1258 be either SSA_OP_USES or SSA_OP_VIRTUAL_USES. */
1259 static inline use_operand_p
1260 op_iter_init_phiuse (ssa_op_iter *ptr, tree phi, int flags)
1262 tree phi_def = PHI_RESULT (phi);
1265 clear_and_done_ssa_iter (ptr);
1268 gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
1270 comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1272 /* If the PHI node doesn't the operand type we care about, we're done. */
1273 if ((flags & comp) == 0)
1276 return NULL_USE_OPERAND_P;
1279 ptr->phi_stmt = phi;
1280 ptr->num_phi = PHI_NUM_ARGS (phi);
1281 ptr->iter_type = ssa_op_iter_use;
1282 return op_iter_next_use (ptr);
1286 /* Start an iterator for a PHI definition. */
1288 static inline def_operand_p
1289 op_iter_init_phidef (ssa_op_iter *ptr, tree phi, int flags)
1291 tree phi_def = PHI_RESULT (phi);
1294 clear_and_done_ssa_iter (ptr);
1297 gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
1299 comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
1301 /* If the PHI node doesn't the operand type we care about, we're done. */
1302 if ((flags & comp) == 0)
1305 return NULL_USE_OPERAND_P;
1308 ptr->iter_type = ssa_op_iter_def;
1309 /* The first call to op_iter_next_def will terminate the iterator since
1310 all the fields are NULL. Simply return the result here as the first and
1311 therefore only result. */
1312 return PHI_RESULT_PTR (phi);
1315 /* Return true is IMM has reached the end of the immediate use stmt list. */
1318 end_imm_use_stmt_p (imm_use_iterator *imm)
1320 return (imm->imm_use == imm->end_p);
1323 /* Finished the traverse of an immediate use stmt list IMM by removing the
1324 placeholder node from the list. */
1327 end_imm_use_stmt_traverse (imm_use_iterator *imm)
1329 delink_imm_use (&(imm->iter_node));
1332 /* Immediate use traversal of uses within a stmt require that all the
1333 uses on a stmt be sequentially listed. This routine is used to build up
1334 this sequential list by adding USE_P to the end of the current list
1335 currently delimited by HEAD and LAST_P. The new LAST_P value is
1338 static inline use_operand_p
1339 move_use_after_head (use_operand_p use_p, use_operand_p head,
1340 use_operand_p last_p)
1342 gcc_assert (USE_FROM_PTR (use_p) == USE_FROM_PTR (head));
1343 /* Skip head when we find it. */
1346 /* If use_p is already linked in after last_p, continue. */
1347 if (last_p->next == use_p)
1351 /* Delink from current location, and link in at last_p. */
1352 delink_imm_use (use_p);
1353 link_imm_use_to_list (use_p, last_p);
1361 /* This routine will relink all uses with the same stmt as HEAD into the list
1362 immediately following HEAD for iterator IMM. */
1365 link_use_stmts_after (use_operand_p head, imm_use_iterator *imm)
1367 use_operand_p use_p;
1368 use_operand_p last_p = head;
1369 tree head_stmt = USE_STMT (head);
1370 tree use = USE_FROM_PTR (head);
1371 ssa_op_iter op_iter;
1374 /* Only look at virtual or real uses, depending on the type of HEAD. */
1375 flag = (is_gimple_reg (use) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1377 if (TREE_CODE (head_stmt) == PHI_NODE)
1379 FOR_EACH_PHI_ARG (use_p, head_stmt, op_iter, flag)
1380 if (USE_FROM_PTR (use_p) == use)
1381 last_p = move_use_after_head (use_p, head, last_p);
1385 FOR_EACH_SSA_USE_OPERAND (use_p, head_stmt, op_iter, flag)
1386 if (USE_FROM_PTR (use_p) == use)
1387 last_p = move_use_after_head (use_p, head, last_p);
1389 /* LInk iter node in after last_p. */
1390 if (imm->iter_node.prev != NULL)
1391 delink_imm_use (&imm->iter_node);
1392 link_imm_use_to_list (&(imm->iter_node), last_p);
1395 /* Initialize IMM to traverse over uses of VAR. Return the first statement. */
1397 first_imm_use_stmt (imm_use_iterator *imm, tree var)
1399 gcc_assert (TREE_CODE (var) == SSA_NAME);
1401 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
1402 imm->imm_use = imm->end_p->next;
1403 imm->next_imm_name = NULL_USE_OPERAND_P;
1405 /* iter_node is used as a marker within the immediate use list to indicate
1406 where the end of the current stmt's uses are. Initialize it to NULL
1407 stmt and use, which indicates a marker node. */
1408 imm->iter_node.prev = NULL_USE_OPERAND_P;
1409 imm->iter_node.next = NULL_USE_OPERAND_P;
1410 imm->iter_node.stmt = NULL_TREE;
1411 imm->iter_node.use = NULL_USE_OPERAND_P;
1413 if (end_imm_use_stmt_p (imm))
1416 link_use_stmts_after (imm->imm_use, imm);
1418 return USE_STMT (imm->imm_use);
1421 /* Bump IMM to the next stmt which has a use of var. */
1424 next_imm_use_stmt (imm_use_iterator *imm)
1426 imm->imm_use = imm->iter_node.next;
1427 if (end_imm_use_stmt_p (imm))
1429 if (imm->iter_node.prev != NULL)
1430 delink_imm_use (&imm->iter_node);
1434 link_use_stmts_after (imm->imm_use, imm);
1435 return USE_STMT (imm->imm_use);
1439 /* This routine will return the first use on the stmt IMM currently refers
1442 static inline use_operand_p
1443 first_imm_use_on_stmt (imm_use_iterator *imm)
1445 imm->next_imm_name = imm->imm_use->next;
1446 return imm->imm_use;
1449 /* Return TRUE if the last use on the stmt IMM refers to has been visited. */
1452 end_imm_use_on_stmt_p (imm_use_iterator *imm)
1454 return (imm->imm_use == &(imm->iter_node));
1457 /* Bump to the next use on the stmt IMM refers to, return NULL if done. */
1459 static inline use_operand_p
1460 next_imm_use_on_stmt (imm_use_iterator *imm)
1462 imm->imm_use = imm->next_imm_name;
1463 if (end_imm_use_on_stmt_p (imm))
1464 return NULL_USE_OPERAND_P;
1467 imm->next_imm_name = imm->imm_use->next;
1468 return imm->imm_use;
1472 /* Return true if VAR cannot be modified by the program. */
1475 unmodifiable_var_p (tree var)
1477 if (TREE_CODE (var) == SSA_NAME)
1478 var = SSA_NAME_VAR (var);
1481 return TREE_READONLY (var) && (TREE_STATIC (var) || MTAG_GLOBAL (var));
1483 return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1486 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it. */
1489 array_ref_contains_indirect_ref (tree ref)
1491 gcc_assert (TREE_CODE (ref) == ARRAY_REF);
1494 ref = TREE_OPERAND (ref, 0);
1495 } while (handled_component_p (ref));
1497 return TREE_CODE (ref) == INDIRECT_REF;
1500 /* Return true if REF, a handled component reference, has an ARRAY_REF
1504 ref_contains_array_ref (tree ref)
1506 gcc_assert (handled_component_p (ref));
1509 if (TREE_CODE (ref) == ARRAY_REF)
1511 ref = TREE_OPERAND (ref, 0);
1512 } while (handled_component_p (ref));
1517 /* Given a variable VAR, lookup and return a pointer to the list of
1518 subvariables for it. */
1520 static inline subvar_t *
1521 lookup_subvars_for_var (tree var)
1523 var_ann_t ann = var_ann (var);
1525 return &ann->subvars;
1528 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1529 NULL, if there are no subvariables. */
1531 static inline subvar_t
1532 get_subvars_for_var (tree var)
1536 gcc_assert (SSA_VAR_P (var));
1538 if (TREE_CODE (var) == SSA_NAME)
1539 subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
1541 subvars = *(lookup_subvars_for_var (var));
1545 /* Return the subvariable of VAR at offset OFFSET. */
1548 get_subvar_at (tree var, unsigned HOST_WIDE_INT offset)
1552 for (sv = get_subvars_for_var (var); sv; sv = sv->next)
1553 if (SFT_OFFSET (sv->var) == offset)
1559 /* Return true if V is a tree that we can have subvars for.
1560 Normally, this is any aggregate type. Also complex
1561 types which are not gimple registers can have subvars. */
1564 var_can_have_subvars (tree v)
1566 /* Volatile variables should never have subvars. */
1567 if (TREE_THIS_VOLATILE (v))
1570 /* Non decls or memory tags can never have subvars. */
1571 if (!DECL_P (v) || MTAG_P (v))
1574 /* Aggregates can have subvars. */
1575 if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
1578 /* Complex types variables which are not also a gimple register can
1580 if (TREE_CODE (TREE_TYPE (v)) == COMPLEX_TYPE
1581 && !DECL_COMPLEX_GIMPLE_REG_P (v))
1588 /* Return true if OFFSET and SIZE define a range that overlaps with some
1589 portion of the range of SV, a subvar. If there was an exact overlap,
1590 *EXACT will be set to true upon return. */
1593 overlap_subvar (unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT size,
1594 tree sv, bool *exact)
1596 /* There are three possible cases of overlap.
1597 1. We can have an exact overlap, like so:
1598 |offset, offset + size |
1599 |sv->offset, sv->offset + sv->size |
1601 2. We can have offset starting after sv->offset, like so:
1603 |offset, offset + size |
1604 |sv->offset, sv->offset + sv->size |
1606 3. We can have offset starting before sv->offset, like so:
1608 |offset, offset + size |
1609 |sv->offset, sv->offset + sv->size|
1614 if (offset == SFT_OFFSET (sv) && size == SFT_SIZE (sv))
1620 else if (offset >= SFT_OFFSET (sv)
1621 && offset < (SFT_OFFSET (sv) + SFT_SIZE (sv)))
1625 else if (offset < SFT_OFFSET (sv)
1626 && (size > SFT_OFFSET (sv) - offset))
1634 /* Get the value handle of EXPR. This is the only correct way to get
1635 the value handle for a "thing". If EXPR does not have a value
1636 handle associated, it returns NULL_TREE.
1637 NB: If EXPR is min_invariant, this function is *required* to return
1641 get_value_handle (tree expr)
1643 if (TREE_CODE (expr) == SSA_NAME)
1644 return SSA_NAME_VALUE (expr);
1645 else if (DECL_P (expr) || TREE_CODE (expr) == TREE_LIST
1646 || TREE_CODE (expr) == CONSTRUCTOR)
1648 tree_ann_common_t ann = tree_common_ann (expr);
1649 return ((ann) ? ann->value_handle : NULL_TREE);
1651 else if (is_gimple_min_invariant (expr))
1653 else if (EXPR_P (expr))
1655 tree_ann_common_t ann = tree_common_ann (expr);
1656 return ((ann) ? ann->value_handle : NULL_TREE);
1662 #endif /* _TREE_FLOW_INLINE_H */