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 return (ann
) ? ann
: create_function_ann (var
);
165 /* Return the statement annotation for T, which must be a statement
166 node. Return NULL if the statement annotation doesn't exist. */
167 static inline stmt_ann_t
170 #ifdef ENABLE_CHECKING
171 gcc_assert (is_gimple_stmt (t
));
173 return (stmt_ann_t
) t
->common
.ann
;
176 /* Return the statement annotation for T, which must be a statement
177 node. Create the statement annotation if it doesn't exist. */
178 static inline stmt_ann_t
179 get_stmt_ann (tree stmt
)
181 stmt_ann_t ann
= stmt_ann (stmt
);
182 return (ann
) ? ann
: create_stmt_ann (stmt
);
185 /* Return the annotation type for annotation ANN. */
186 static inline enum tree_ann_type
187 ann_type (tree_ann_t ann
)
189 return ann
->common
.type
;
192 /* Return the basic block for statement T. */
193 static inline basic_block
198 if (TREE_CODE (t
) == PHI_NODE
)
202 return ann
? ann
->bb
: NULL
;
205 /* Return the may_aliases varray for variable VAR, or NULL if it has
207 static inline VEC(tree
, gc
) *
208 may_aliases (tree var
)
210 var_ann_t ann
= var_ann (var
);
211 return ann
? ann
->may_aliases
: NULL
;
214 /* Return the line number for EXPR, or return -1 if we have no line
215 number information for it. */
217 get_lineno (tree expr
)
219 if (expr
== NULL_TREE
)
222 if (TREE_CODE (expr
) == COMPOUND_EXPR
)
223 expr
= TREE_OPERAND (expr
, 0);
225 if (! EXPR_HAS_LOCATION (expr
))
228 return EXPR_LINENO (expr
);
231 /* Return the file name for EXPR, or return "???" if we have no
232 filename information. */
233 static inline const char *
234 get_filename (tree expr
)
236 const char *filename
;
237 if (expr
== NULL_TREE
)
240 if (TREE_CODE (expr
) == COMPOUND_EXPR
)
241 expr
= TREE_OPERAND (expr
, 0);
243 if (EXPR_HAS_LOCATION (expr
) && (filename
= EXPR_FILENAME (expr
)))
249 /* Return true if T is a noreturn call. */
251 noreturn_call_p (tree t
)
253 tree call
= get_call_expr_in (t
);
254 return call
!= 0 && (call_expr_flags (call
) & ECF_NORETURN
) != 0;
257 /* Mark statement T as modified. */
259 mark_stmt_modified (tree t
)
262 if (TREE_CODE (t
) == PHI_NODE
)
267 ann
= create_stmt_ann (t
);
268 else if (noreturn_call_p (t
))
269 VEC_safe_push (tree
, gc
, modified_noreturn_calls
, t
);
273 /* Mark statement T as modified, and update it. */
277 if (TREE_CODE (t
) == PHI_NODE
)
279 mark_stmt_modified (t
);
280 update_stmt_operands (t
);
284 update_stmt_if_modified (tree t
)
286 if (stmt_modified_p (t
))
287 update_stmt_operands (t
);
290 /* Return true if T is marked as modified, false otherwise. */
292 stmt_modified_p (tree t
)
294 stmt_ann_t ann
= stmt_ann (t
);
296 /* Note that if the statement doesn't yet have an annotation, we consider it
297 modified. This will force the next call to update_stmt_operands to scan
299 return ann
? ann
->modified
: true;
302 /* Delink an immediate_uses node from its chain. */
304 delink_imm_use (ssa_use_operand_t
*linknode
)
306 /* Return if this node is not in a list. */
307 if (linknode
->prev
== NULL
)
310 linknode
->prev
->next
= linknode
->next
;
311 linknode
->next
->prev
= linknode
->prev
;
312 linknode
->prev
= NULL
;
313 linknode
->next
= NULL
;
316 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
318 link_imm_use_to_list (ssa_use_operand_t
*linknode
, ssa_use_operand_t
*list
)
320 /* Link the new node at the head of the list. If we are in the process of
321 traversing the list, we won't visit any new nodes added to it. */
322 linknode
->prev
= list
;
323 linknode
->next
= list
->next
;
324 list
->next
->prev
= linknode
;
325 list
->next
= linknode
;
328 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
330 link_imm_use (ssa_use_operand_t
*linknode
, tree def
)
332 ssa_use_operand_t
*root
;
334 if (!def
|| TREE_CODE (def
) != SSA_NAME
)
335 linknode
->prev
= NULL
;
338 root
= &(SSA_NAME_IMM_USE_NODE (def
));
339 #ifdef ENABLE_CHECKING
341 gcc_assert (*(linknode
->use
) == def
);
343 link_imm_use_to_list (linknode
, root
);
347 /* Set the value of a use pointed to by USE to VAL. */
349 set_ssa_use_from_ptr (use_operand_p use
, tree val
)
351 delink_imm_use (use
);
353 link_imm_use (use
, val
);
356 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
359 link_imm_use_stmt (ssa_use_operand_t
*linknode
, tree def
, tree stmt
)
362 link_imm_use (linknode
, def
);
364 link_imm_use (linknode
, NULL
);
365 linknode
->stmt
= stmt
;
368 /* Relink a new node in place of an old node in the list. */
370 relink_imm_use (ssa_use_operand_t
*node
, ssa_use_operand_t
*old
)
372 /* The node one had better be in the same list. */
373 gcc_assert (*(old
->use
) == *(node
->use
));
374 node
->prev
= old
->prev
;
375 node
->next
= old
->next
;
378 old
->prev
->next
= node
;
379 old
->next
->prev
= node
;
380 /* Remove the old node from the list. */
385 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
388 relink_imm_use_stmt (ssa_use_operand_t
*linknode
, ssa_use_operand_t
*old
, tree stmt
)
391 relink_imm_use (linknode
, old
);
393 link_imm_use (linknode
, NULL
);
394 linknode
->stmt
= stmt
;
398 /* Return true is IMM has reached the end of the immediate use list. */
400 end_readonly_imm_use_p (imm_use_iterator
*imm
)
402 return (imm
->imm_use
== imm
->end_p
);
405 /* Initialize iterator IMM to process the list for VAR. */
406 static inline use_operand_p
407 first_readonly_imm_use (imm_use_iterator
*imm
, tree var
)
409 gcc_assert (TREE_CODE (var
) == SSA_NAME
);
411 imm
->end_p
= &(SSA_NAME_IMM_USE_NODE (var
));
412 imm
->imm_use
= imm
->end_p
->next
;
413 #ifdef ENABLE_CHECKING
414 imm
->iter_node
.next
= imm
->imm_use
->next
;
416 if (end_readonly_imm_use_p (imm
))
417 return NULL_USE_OPERAND_P
;
421 /* Bump IMM to the next use in the list. */
422 static inline use_operand_p
423 next_readonly_imm_use (imm_use_iterator
*imm
)
425 use_operand_p old
= imm
->imm_use
;
427 #ifdef ENABLE_CHECKING
428 /* If this assertion fails, it indicates the 'next' pointer has changed
429 since we the last bump. This indicates that the list is being modified
430 via stmt changes, or SET_USE, or somesuch thing, and you need to be
431 using the SAFE version of the iterator. */
432 gcc_assert (imm
->iter_node
.next
== old
->next
);
433 imm
->iter_node
.next
= old
->next
->next
;
436 imm
->imm_use
= old
->next
;
437 if (end_readonly_imm_use_p (imm
))
442 /* Return true if VAR has no uses. */
444 has_zero_uses (tree var
)
446 ssa_use_operand_t
*ptr
;
447 ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
448 /* A single use means there is no items in the list. */
449 return (ptr
== ptr
->next
);
452 /* Return true if VAR has a single use. */
454 has_single_use (tree var
)
456 ssa_use_operand_t
*ptr
;
457 ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
458 /* A single use means there is one item in the list. */
459 return (ptr
!= ptr
->next
&& ptr
== ptr
->next
->next
);
462 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
463 to the use pointer and stmt of occurrence. */
465 single_imm_use (tree var
, use_operand_p
*use_p
, tree
*stmt
)
467 ssa_use_operand_t
*ptr
;
469 ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
470 if (ptr
!= ptr
->next
&& ptr
== ptr
->next
->next
)
473 *stmt
= ptr
->next
->stmt
;
476 *use_p
= NULL_USE_OPERAND_P
;
481 /* Return the number of immediate uses of VAR. */
482 static inline unsigned int
483 num_imm_uses (tree var
)
485 ssa_use_operand_t
*ptr
, *start
;
488 start
= &(SSA_NAME_IMM_USE_NODE (var
));
490 for (ptr
= start
->next
; ptr
!= start
; ptr
= ptr
->next
)
497 /* Return the tree pointer to by USE. */
499 get_use_from_ptr (use_operand_p use
)
504 /* Return the tree pointer to by DEF. */
506 get_def_from_ptr (def_operand_p def
)
511 /* Return a def_operand_p pointer for the result of PHI. */
512 static inline def_operand_p
513 get_phi_result_ptr (tree phi
)
515 return &(PHI_RESULT_TREE (phi
));
518 /* Return a use_operand_p pointer for argument I of phinode PHI. */
519 static inline use_operand_p
520 get_phi_arg_def_ptr (tree phi
, int i
)
522 return &(PHI_ARG_IMM_USE_NODE (phi
,i
));
526 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
529 addresses_taken (tree stmt
)
531 stmt_ann_t ann
= stmt_ann (stmt
);
532 return ann
? ann
->addresses_taken
: NULL
;
535 /* Return the PHI nodes for basic block BB, or NULL if there are no
538 phi_nodes (basic_block bb
)
540 return bb
->phi_nodes
;
543 /* Set list of phi nodes of a basic block BB to L. */
546 set_phi_nodes (basic_block bb
, tree l
)
551 for (phi
= l
; phi
; phi
= PHI_CHAIN (phi
))
552 set_bb_for_stmt (phi
, bb
);
555 /* Return the phi argument which contains the specified use. */
558 phi_arg_index_from_use (use_operand_p use
)
560 struct phi_arg_d
*element
, *root
;
564 /* Since the use is the first thing in a PHI argument element, we can
565 calculate its index based on casting it to an argument, and performing
566 pointer arithmetic. */
568 phi
= USE_STMT (use
);
569 gcc_assert (TREE_CODE (phi
) == PHI_NODE
);
571 element
= (struct phi_arg_d
*)use
;
572 root
= &(PHI_ARG_ELT (phi
, 0));
573 index
= element
- root
;
575 #ifdef ENABLE_CHECKING
576 /* Make sure the calculation doesn't have any leftover bytes. If it does,
577 then imm_use is likely not the first element in phi_arg_d. */
579 (((char *)element
- (char *)root
) % sizeof (struct phi_arg_d
)) == 0);
580 gcc_assert (index
>= 0 && index
< PHI_ARG_CAPACITY (phi
));
586 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
589 set_is_used (tree var
)
591 var_ann_t ann
= get_var_ann (var
);
596 /* ----------------------------------------------------------------------- */
598 /* Return true if T is an executable statement. */
600 is_exec_stmt (tree t
)
602 return (t
&& !IS_EMPTY_STMT (t
) && t
!= error_mark_node
);
606 /* Return true if this stmt can be the target of a control transfer stmt such
609 is_label_stmt (tree t
)
612 switch (TREE_CODE (t
))
616 case CASE_LABEL_EXPR
:
624 /* PHI nodes should contain only ssa_names and invariants. A test
625 for ssa_name is definitely simpler; don't let invalid contents
626 slip in in the meantime. */
629 phi_ssa_name_p (tree t
)
631 if (TREE_CODE (t
) == SSA_NAME
)
633 #ifdef ENABLE_CHECKING
634 gcc_assert (is_gimple_min_invariant (t
));
639 /* ----------------------------------------------------------------------- */
641 /* Return a block_stmt_iterator that points to beginning of basic
643 static inline block_stmt_iterator
644 bsi_start (basic_block bb
)
646 block_stmt_iterator bsi
;
648 bsi
.tsi
= tsi_start (bb
->stmt_list
);
651 gcc_assert (bb
->index
< NUM_FIXED_BLOCKS
);
653 bsi
.tsi
.container
= NULL
;
659 /* Return a block statement iterator that points to the first non-label
660 statement in block BB. */
662 static inline block_stmt_iterator
663 bsi_after_labels (basic_block bb
)
665 block_stmt_iterator bsi
= bsi_start (bb
);
667 while (!bsi_end_p (bsi
) && TREE_CODE (bsi_stmt (bsi
)) == LABEL_EXPR
)
673 /* Return a block statement iterator that points to the end of basic
675 static inline block_stmt_iterator
676 bsi_last (basic_block bb
)
678 block_stmt_iterator bsi
;
680 bsi
.tsi
= tsi_last (bb
->stmt_list
);
683 gcc_assert (bb
->index
< NUM_FIXED_BLOCKS
);
685 bsi
.tsi
.container
= NULL
;
691 /* Return true if block statement iterator I has reached the end of
694 bsi_end_p (block_stmt_iterator i
)
696 return tsi_end_p (i
.tsi
);
699 /* Modify block statement iterator I so that it is at the next
700 statement in the basic block. */
702 bsi_next (block_stmt_iterator
*i
)
707 /* Modify block statement iterator I so that it is at the previous
708 statement in the basic block. */
710 bsi_prev (block_stmt_iterator
*i
)
715 /* Return the statement that block statement iterator I is currently
718 bsi_stmt (block_stmt_iterator i
)
720 return tsi_stmt (i
.tsi
);
723 /* Return a pointer to the statement that block statement iterator I
726 bsi_stmt_ptr (block_stmt_iterator i
)
728 return tsi_stmt_ptr (i
.tsi
);
731 /* Returns the loop of the statement STMT. */
733 static inline struct loop
*
734 loop_containing_stmt (tree stmt
)
736 basic_block bb
= bb_for_stmt (stmt
);
740 return bb
->loop_father
;
743 /* Return true if VAR is a clobbered by function calls. */
745 is_call_clobbered (tree var
)
748 return DECL_CALL_CLOBBERED (var
);
750 return bitmap_bit_p (call_clobbered_vars
, DECL_UID (var
));
753 /* Mark variable VAR as being clobbered by function calls. */
755 mark_call_clobbered (tree var
, unsigned int escape_type
)
757 var_ann (var
)->escape_mask
|= escape_type
;
759 DECL_CALL_CLOBBERED (var
) = true;
760 bitmap_set_bit (call_clobbered_vars
, DECL_UID (var
));
763 /* Clear the call-clobbered attribute from variable VAR. */
765 clear_call_clobbered (tree var
)
767 var_ann_t ann
= var_ann (var
);
768 ann
->escape_mask
= 0;
769 if (MTAG_P (var
) && TREE_CODE (var
) != STRUCT_FIELD_TAG
)
770 MTAG_GLOBAL (var
) = 0;
772 DECL_CALL_CLOBBERED (var
) = false;
773 bitmap_clear_bit (call_clobbered_vars
, DECL_UID (var
));
776 /* Mark variable VAR as being non-addressable. */
778 mark_non_addressable (tree var
)
781 DECL_CALL_CLOBBERED (var
) = false;
782 bitmap_clear_bit (call_clobbered_vars
, DECL_UID (var
));
783 TREE_ADDRESSABLE (var
) = 0;
786 /* Return the common annotation for T. Return NULL if the annotation
787 doesn't already exist. */
788 static inline tree_ann_t
791 return t
->common
.ann
;
794 /* Return a common annotation for T. Create the constant annotation if it
796 static inline tree_ann_t
797 get_tree_ann (tree t
)
799 tree_ann_t ann
= tree_ann (t
);
800 return (ann
) ? ann
: create_tree_ann (t
);
803 /* ----------------------------------------------------------------------- */
805 /* The following set of routines are used to iterator over various type of
808 /* Return true if PTR is finished iterating. */
810 op_iter_done (ssa_op_iter
*ptr
)
815 /* Get the next iterator use value for PTR. */
816 static inline use_operand_p
817 op_iter_next_use (ssa_op_iter
*ptr
)
820 #ifdef ENABLE_CHECKING
821 gcc_assert (ptr
->iter_type
== ssa_op_iter_use
);
825 use_p
= USE_OP_PTR (ptr
->uses
);
826 ptr
->uses
= ptr
->uses
->next
;
831 use_p
= VUSE_OP_PTR (ptr
->vuses
);
832 ptr
->vuses
= ptr
->vuses
->next
;
837 use_p
= MAYDEF_OP_PTR (ptr
->mayuses
);
838 ptr
->mayuses
= ptr
->mayuses
->next
;
843 use_p
= MUSTDEF_KILL_PTR (ptr
->mustkills
);
844 ptr
->mustkills
= ptr
->mustkills
->next
;
847 if (ptr
->phi_i
< ptr
->num_phi
)
849 return PHI_ARG_DEF_PTR (ptr
->phi_stmt
, (ptr
->phi_i
)++);
852 return NULL_USE_OPERAND_P
;
855 /* Get the next iterator def value for PTR. */
856 static inline def_operand_p
857 op_iter_next_def (ssa_op_iter
*ptr
)
860 #ifdef ENABLE_CHECKING
861 gcc_assert (ptr
->iter_type
== ssa_op_iter_def
);
865 def_p
= DEF_OP_PTR (ptr
->defs
);
866 ptr
->defs
= ptr
->defs
->next
;
871 def_p
= MUSTDEF_RESULT_PTR (ptr
->mustdefs
);
872 ptr
->mustdefs
= ptr
->mustdefs
->next
;
877 def_p
= MAYDEF_RESULT_PTR (ptr
->maydefs
);
878 ptr
->maydefs
= ptr
->maydefs
->next
;
882 return NULL_DEF_OPERAND_P
;
885 /* Get the next iterator tree value for PTR. */
887 op_iter_next_tree (ssa_op_iter
*ptr
)
890 #ifdef ENABLE_CHECKING
891 gcc_assert (ptr
->iter_type
== ssa_op_iter_tree
);
895 val
= USE_OP (ptr
->uses
);
896 ptr
->uses
= ptr
->uses
->next
;
901 val
= VUSE_OP (ptr
->vuses
);
902 ptr
->vuses
= ptr
->vuses
->next
;
907 val
= MAYDEF_OP (ptr
->mayuses
);
908 ptr
->mayuses
= ptr
->mayuses
->next
;
913 val
= MUSTDEF_KILL (ptr
->mustkills
);
914 ptr
->mustkills
= ptr
->mustkills
->next
;
919 val
= DEF_OP (ptr
->defs
);
920 ptr
->defs
= ptr
->defs
->next
;
925 val
= MUSTDEF_RESULT (ptr
->mustdefs
);
926 ptr
->mustdefs
= ptr
->mustdefs
->next
;
931 val
= MAYDEF_RESULT (ptr
->maydefs
);
932 ptr
->maydefs
= ptr
->maydefs
->next
;
942 /* This functions clears the iterator PTR, and marks it done. This is normally
943 used to prevent warnings in the compile about might be uninitialized
947 clear_and_done_ssa_iter (ssa_op_iter
*ptr
)
954 ptr
->mustdefs
= NULL
;
955 ptr
->mustkills
= NULL
;
956 ptr
->iter_type
= ssa_op_iter_none
;
959 ptr
->phi_stmt
= NULL_TREE
;
963 /* Initialize the iterator PTR to the virtual defs in STMT. */
965 op_iter_init (ssa_op_iter
*ptr
, tree stmt
, int flags
)
967 #ifdef ENABLE_CHECKING
968 gcc_assert (stmt_ann (stmt
));
971 ptr
->defs
= (flags
& SSA_OP_DEF
) ? DEF_OPS (stmt
) : NULL
;
972 ptr
->uses
= (flags
& SSA_OP_USE
) ? USE_OPS (stmt
) : NULL
;
973 ptr
->vuses
= (flags
& SSA_OP_VUSE
) ? VUSE_OPS (stmt
) : NULL
;
974 ptr
->maydefs
= (flags
& SSA_OP_VMAYDEF
) ? MAYDEF_OPS (stmt
) : NULL
;
975 ptr
->mayuses
= (flags
& SSA_OP_VMAYUSE
) ? MAYDEF_OPS (stmt
) : NULL
;
976 ptr
->mustdefs
= (flags
& SSA_OP_VMUSTDEF
) ? MUSTDEF_OPS (stmt
) : NULL
;
977 ptr
->mustkills
= (flags
& SSA_OP_VMUSTKILL
) ? MUSTDEF_OPS (stmt
) : NULL
;
982 ptr
->phi_stmt
= NULL_TREE
;
985 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
987 static inline use_operand_p
988 op_iter_init_use (ssa_op_iter
*ptr
, tree stmt
, int flags
)
990 gcc_assert ((flags
& SSA_OP_ALL_DEFS
) == 0);
991 op_iter_init (ptr
, stmt
, flags
);
992 ptr
->iter_type
= ssa_op_iter_use
;
993 return op_iter_next_use (ptr
);
996 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
998 static inline def_operand_p
999 op_iter_init_def (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1001 gcc_assert ((flags
& (SSA_OP_ALL_USES
| SSA_OP_VIRTUAL_KILLS
)) == 0);
1002 op_iter_init (ptr
, stmt
, flags
);
1003 ptr
->iter_type
= ssa_op_iter_def
;
1004 return op_iter_next_def (ptr
);
1007 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1008 the first operand as a tree. */
1010 op_iter_init_tree (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1012 op_iter_init (ptr
, stmt
, flags
);
1013 ptr
->iter_type
= ssa_op_iter_tree
;
1014 return op_iter_next_tree (ptr
);
1017 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1020 op_iter_next_maymustdef (use_operand_p
*use
, def_operand_p
*def
,
1023 #ifdef ENABLE_CHECKING
1024 gcc_assert (ptr
->iter_type
== ssa_op_iter_maymustdef
);
1028 *def
= MAYDEF_RESULT_PTR (ptr
->mayuses
);
1029 *use
= MAYDEF_OP_PTR (ptr
->mayuses
);
1030 ptr
->mayuses
= ptr
->mayuses
->next
;
1036 *def
= MUSTDEF_RESULT_PTR (ptr
->mustkills
);
1037 *use
= MUSTDEF_KILL_PTR (ptr
->mustkills
);
1038 ptr
->mustkills
= ptr
->mustkills
->next
;
1042 *def
= NULL_DEF_OPERAND_P
;
1043 *use
= NULL_USE_OPERAND_P
;
1049 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1052 op_iter_init_maydef (ssa_op_iter
*ptr
, tree stmt
, use_operand_p
*use
,
1055 gcc_assert (TREE_CODE (stmt
) != PHI_NODE
);
1057 op_iter_init (ptr
, stmt
, SSA_OP_VMAYUSE
);
1058 ptr
->iter_type
= ssa_op_iter_maymustdef
;
1059 op_iter_next_maymustdef (use
, def
, ptr
);
1063 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1066 op_iter_init_mustdef (ssa_op_iter
*ptr
, tree stmt
, use_operand_p
*kill
,
1069 gcc_assert (TREE_CODE (stmt
) != PHI_NODE
);
1071 op_iter_init (ptr
, stmt
, SSA_OP_VMUSTKILL
);
1072 ptr
->iter_type
= ssa_op_iter_maymustdef
;
1073 op_iter_next_maymustdef (kill
, def
, ptr
);
1076 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1079 op_iter_init_must_and_may_def (ssa_op_iter
*ptr
, tree stmt
,
1080 use_operand_p
*kill
, def_operand_p
*def
)
1082 gcc_assert (TREE_CODE (stmt
) != PHI_NODE
);
1084 op_iter_init (ptr
, stmt
, SSA_OP_VMUSTKILL
|SSA_OP_VMAYUSE
);
1085 ptr
->iter_type
= ssa_op_iter_maymustdef
;
1086 op_iter_next_maymustdef (kill
, def
, ptr
);
1090 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1093 single_ssa_tree_operand (tree stmt
, int flags
)
1098 var
= op_iter_init_tree (&iter
, stmt
, flags
);
1099 if (op_iter_done (&iter
))
1101 op_iter_next_tree (&iter
);
1102 if (op_iter_done (&iter
))
1108 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1110 static inline use_operand_p
1111 single_ssa_use_operand (tree stmt
, int flags
)
1116 var
= op_iter_init_use (&iter
, stmt
, flags
);
1117 if (op_iter_done (&iter
))
1118 return NULL_USE_OPERAND_P
;
1119 op_iter_next_use (&iter
);
1120 if (op_iter_done (&iter
))
1122 return NULL_USE_OPERAND_P
;
1127 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1129 static inline def_operand_p
1130 single_ssa_def_operand (tree stmt
, int flags
)
1135 var
= op_iter_init_def (&iter
, stmt
, flags
);
1136 if (op_iter_done (&iter
))
1137 return NULL_DEF_OPERAND_P
;
1138 op_iter_next_def (&iter
);
1139 if (op_iter_done (&iter
))
1141 return NULL_DEF_OPERAND_P
;
1145 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1148 zero_ssa_operands (tree stmt
, int flags
)
1152 op_iter_init_tree (&iter
, stmt
, flags
);
1153 return op_iter_done (&iter
);
1157 /* Return the number of operands matching FLAGS in STMT. */
1159 num_ssa_operands (tree stmt
, int flags
)
1165 FOR_EACH_SSA_TREE_OPERAND (t
, stmt
, iter
, flags
)
1171 /* Delink all immediate_use information for STMT. */
1173 delink_stmt_imm_use (tree stmt
)
1176 use_operand_p use_p
;
1178 if (ssa_operands_active ())
1179 FOR_EACH_SSA_USE_OPERAND (use_p
, stmt
, iter
,
1180 (SSA_OP_ALL_USES
| SSA_OP_ALL_KILLS
))
1181 delink_imm_use (use_p
);
1185 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1186 in STMT2. TRUE is returned if they are the same. STMTs can be NULL. */
1188 compare_ssa_operands_equal (tree stmt1
, tree stmt2
, int flags
)
1190 ssa_op_iter iter1
, iter2
;
1191 tree op1
= NULL_TREE
;
1192 tree op2
= NULL_TREE
;
1198 look1
= stmt1
&& stmt_ann (stmt1
);
1199 look2
= stmt2
&& stmt_ann (stmt2
);
1203 op1
= op_iter_init_tree (&iter1
, stmt1
, flags
);
1205 return op_iter_done (&iter1
);
1208 clear_and_done_ssa_iter (&iter1
);
1212 op2
= op_iter_init_tree (&iter2
, stmt2
, flags
);
1214 return op_iter_done (&iter2
);
1217 clear_and_done_ssa_iter (&iter2
);
1219 while (!op_iter_done (&iter1
) && !op_iter_done (&iter2
))
1223 op1
= op_iter_next_tree (&iter1
);
1224 op2
= op_iter_next_tree (&iter2
);
1227 return (op_iter_done (&iter1
) && op_iter_done (&iter2
));
1231 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1232 Otherwise return NULL_DEF_OPERAND_P. */
1234 single_phi_def (tree stmt
, int flags
)
1236 tree def
= PHI_RESULT (stmt
);
1237 if ((flags
& SSA_OP_DEF
) && is_gimple_reg (def
))
1239 if ((flags
& SSA_OP_VIRTUAL_DEFS
) && !is_gimple_reg (def
))
1244 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
1245 be either SSA_OP_USES or SSA_OP_VIRTUAL_USES. */
1246 static inline use_operand_p
1247 op_iter_init_phiuse (ssa_op_iter
*ptr
, tree phi
, int flags
)
1249 tree phi_def
= PHI_RESULT (phi
);
1252 clear_and_done_ssa_iter (ptr
);
1255 gcc_assert ((flags
& (SSA_OP_USE
| SSA_OP_VIRTUAL_USES
)) != 0);
1257 comp
= (is_gimple_reg (phi_def
) ? SSA_OP_USE
: SSA_OP_VIRTUAL_USES
);
1259 /* If the PHI node doesn't the operand type we care about, we're done. */
1260 if ((flags
& comp
) == 0)
1263 return NULL_USE_OPERAND_P
;
1266 ptr
->phi_stmt
= phi
;
1267 ptr
->num_phi
= PHI_NUM_ARGS (phi
);
1268 ptr
->iter_type
= ssa_op_iter_use
;
1269 return op_iter_next_use (ptr
);
1273 /* Start an iterator for a PHI definition. */
1275 static inline def_operand_p
1276 op_iter_init_phidef (ssa_op_iter
*ptr
, tree phi
, int flags
)
1278 tree phi_def
= PHI_RESULT (phi
);
1281 clear_and_done_ssa_iter (ptr
);
1284 gcc_assert ((flags
& (SSA_OP_DEF
| SSA_OP_VIRTUAL_DEFS
)) != 0);
1286 comp
= (is_gimple_reg (phi_def
) ? SSA_OP_DEF
: SSA_OP_VIRTUAL_DEFS
);
1288 /* If the PHI node doesn't the operand type we care about, we're done. */
1289 if ((flags
& comp
) == 0)
1292 return NULL_USE_OPERAND_P
;
1295 ptr
->iter_type
= ssa_op_iter_def
;
1296 /* The first call to op_iter_next_def will terminate the iterator since
1297 all the fields are NULL. Simply return the result here as the first and
1298 therefore only result. */
1299 return PHI_RESULT_PTR (phi
);
1302 /* Return true is IMM has reached the end of the immediate use stmt list. */
1305 end_imm_use_stmt_p (imm_use_iterator
*imm
)
1307 return (imm
->imm_use
== imm
->end_p
);
1310 /* Finished the traverse of an immediate use stmt list IMM by removing the
1311 placeholder node from the list. */
1314 end_imm_use_stmt_traverse (imm_use_iterator
*imm
)
1316 delink_imm_use (&(imm
->iter_node
));
1319 /* Immediate use traversal of uses within a stmt require that all the
1320 uses on a stmt be sequentially listed. This routine is used to build up
1321 this sequential list by adding USE_P to the end of the current list
1322 currently delimited by HEAD and LAST_P. The new LAST_P value is
1325 static inline use_operand_p
1326 move_use_after_head (use_operand_p use_p
, use_operand_p head
,
1327 use_operand_p last_p
)
1329 gcc_assert (USE_FROM_PTR (use_p
) == USE_FROM_PTR (head
));
1330 /* Skip head when we find it. */
1333 /* If use_p is already linked in after last_p, continue. */
1334 if (last_p
->next
== use_p
)
1338 /* Delink from current location, and link in at last_p. */
1339 delink_imm_use (use_p
);
1340 link_imm_use_to_list (use_p
, last_p
);
1348 /* This routine will relink all uses with the same stmt as HEAD into the list
1349 immediately following HEAD for iterator IMM. */
1352 link_use_stmts_after (use_operand_p head
, imm_use_iterator
*imm
)
1354 use_operand_p use_p
;
1355 use_operand_p last_p
= head
;
1356 tree head_stmt
= USE_STMT (head
);
1357 tree use
= USE_FROM_PTR (head
);
1358 ssa_op_iter op_iter
;
1361 /* Only look at virtual or real uses, depending on the type of HEAD. */
1362 flag
= (is_gimple_reg (use
) ? SSA_OP_USE
: SSA_OP_VIRTUAL_USES
);
1364 if (TREE_CODE (head_stmt
) == PHI_NODE
)
1366 FOR_EACH_PHI_ARG (use_p
, head_stmt
, op_iter
, flag
)
1367 if (USE_FROM_PTR (use_p
) == use
)
1368 last_p
= move_use_after_head (use_p
, head
, last_p
);
1372 FOR_EACH_SSA_USE_OPERAND (use_p
, head_stmt
, op_iter
, flag
)
1373 if (USE_FROM_PTR (use_p
) == use
)
1374 last_p
= move_use_after_head (use_p
, head
, last_p
);
1376 /* LInk iter node in after last_p. */
1377 if (imm
->iter_node
.prev
!= NULL
)
1378 delink_imm_use (&imm
->iter_node
);
1379 link_imm_use_to_list (&(imm
->iter_node
), last_p
);
1382 /* Initialize IMM to traverse over uses of VAR. Return the first statement. */
1384 first_imm_use_stmt (imm_use_iterator
*imm
, tree var
)
1386 gcc_assert (TREE_CODE (var
) == SSA_NAME
);
1388 imm
->end_p
= &(SSA_NAME_IMM_USE_NODE (var
));
1389 imm
->imm_use
= imm
->end_p
->next
;
1390 imm
->next_imm_name
= NULL_USE_OPERAND_P
;
1392 /* iter_node is used as a marker within the immediate use list to indicate
1393 where the end of the current stmt's uses are. Initialize it to NULL
1394 stmt and use, which indicates a marker node. */
1395 imm
->iter_node
.prev
= NULL_USE_OPERAND_P
;
1396 imm
->iter_node
.next
= NULL_USE_OPERAND_P
;
1397 imm
->iter_node
.stmt
= NULL_TREE
;
1398 imm
->iter_node
.use
= NULL_USE_OPERAND_P
;
1400 if (end_imm_use_stmt_p (imm
))
1403 link_use_stmts_after (imm
->imm_use
, imm
);
1405 return USE_STMT (imm
->imm_use
);
1408 /* Bump IMM to the next stmt which has a use of var. */
1411 next_imm_use_stmt (imm_use_iterator
*imm
)
1413 imm
->imm_use
= imm
->iter_node
.next
;
1414 if (end_imm_use_stmt_p (imm
))
1416 if (imm
->iter_node
.prev
!= NULL
)
1417 delink_imm_use (&imm
->iter_node
);
1421 link_use_stmts_after (imm
->imm_use
, imm
);
1422 return USE_STMT (imm
->imm_use
);
1426 /* This routine will return the first use on the stmt IMM currently refers
1429 static inline use_operand_p
1430 first_imm_use_on_stmt (imm_use_iterator
*imm
)
1432 imm
->next_imm_name
= imm
->imm_use
->next
;
1433 return imm
->imm_use
;
1436 /* Return TRUE if the last use on the stmt IMM refers to has been visited. */
1439 end_imm_use_on_stmt_p (imm_use_iterator
*imm
)
1441 return (imm
->imm_use
== &(imm
->iter_node
));
1444 /* Bump to the next use on the stmt IMM refers to, return NULL if done. */
1446 static inline use_operand_p
1447 next_imm_use_on_stmt (imm_use_iterator
*imm
)
1449 imm
->imm_use
= imm
->next_imm_name
;
1450 if (end_imm_use_on_stmt_p (imm
))
1451 return NULL_USE_OPERAND_P
;
1454 imm
->next_imm_name
= imm
->imm_use
->next
;
1455 return imm
->imm_use
;
1459 /* Return true if VAR cannot be modified by the program. */
1462 unmodifiable_var_p (tree var
)
1464 if (TREE_CODE (var
) == SSA_NAME
)
1465 var
= SSA_NAME_VAR (var
);
1468 return TREE_READONLY (var
) && (TREE_STATIC (var
) || MTAG_GLOBAL (var
));
1470 return TREE_READONLY (var
) && (TREE_STATIC (var
) || DECL_EXTERNAL (var
));
1473 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it. */
1476 array_ref_contains_indirect_ref (tree ref
)
1478 gcc_assert (TREE_CODE (ref
) == ARRAY_REF
);
1481 ref
= TREE_OPERAND (ref
, 0);
1482 } while (handled_component_p (ref
));
1484 return TREE_CODE (ref
) == INDIRECT_REF
;
1487 /* Return true if REF, a handled component reference, has an ARRAY_REF
1491 ref_contains_array_ref (tree ref
)
1493 gcc_assert (handled_component_p (ref
));
1496 if (TREE_CODE (ref
) == ARRAY_REF
)
1498 ref
= TREE_OPERAND (ref
, 0);
1499 } while (handled_component_p (ref
));
1504 /* Given a variable VAR, lookup and return a pointer to the list of
1505 subvariables for it. */
1507 static inline subvar_t
*
1508 lookup_subvars_for_var (tree var
)
1510 var_ann_t ann
= var_ann (var
);
1512 return &ann
->subvars
;
1515 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1516 NULL, if there are no subvariables. */
1518 static inline subvar_t
1519 get_subvars_for_var (tree var
)
1523 gcc_assert (SSA_VAR_P (var
));
1525 if (TREE_CODE (var
) == SSA_NAME
)
1526 subvars
= *(lookup_subvars_for_var (SSA_NAME_VAR (var
)));
1528 subvars
= *(lookup_subvars_for_var (var
));
1532 /* Return the subvariable of VAR at offset OFFSET. */
1535 get_subvar_at (tree var
, unsigned HOST_WIDE_INT offset
)
1539 for (sv
= get_subvars_for_var (var
); sv
; sv
= sv
->next
)
1540 if (SFT_OFFSET (sv
->var
) == offset
)
1546 /* Return true if V is a tree that we can have subvars for.
1547 Normally, this is any aggregate type. Also complex
1548 types which are not gimple registers can have subvars. */
1551 var_can_have_subvars (tree v
)
1553 /* Volatile variables should never have subvars. */
1554 if (TREE_THIS_VOLATILE (v
))
1557 /* Non decls or memory tags can never have subvars. */
1558 if (!DECL_P (v
) || MTAG_P (v
))
1561 /* Aggregates can have subvars. */
1562 if (AGGREGATE_TYPE_P (TREE_TYPE (v
)))
1565 /* Complex types variables which are not also a gimple register can
1567 if (TREE_CODE (TREE_TYPE (v
)) == COMPLEX_TYPE
1568 && !DECL_COMPLEX_GIMPLE_REG_P (v
))
1575 /* Return true if OFFSET and SIZE define a range that overlaps with some
1576 portion of the range of SV, a subvar. If there was an exact overlap,
1577 *EXACT will be set to true upon return. */
1580 overlap_subvar (unsigned HOST_WIDE_INT offset
, unsigned HOST_WIDE_INT size
,
1581 tree sv
, bool *exact
)
1583 /* There are three possible cases of overlap.
1584 1. We can have an exact overlap, like so:
1585 |offset, offset + size |
1586 |sv->offset, sv->offset + sv->size |
1588 2. We can have offset starting after sv->offset, like so:
1590 |offset, offset + size |
1591 |sv->offset, sv->offset + sv->size |
1593 3. We can have offset starting before sv->offset, like so:
1595 |offset, offset + size |
1596 |sv->offset, sv->offset + sv->size|
1601 if (offset
== SFT_OFFSET (sv
) && size
== SFT_SIZE (sv
))
1607 else if (offset
>= SFT_OFFSET (sv
)
1608 && offset
< (SFT_OFFSET (sv
) + SFT_SIZE (sv
)))
1612 else if (offset
< SFT_OFFSET (sv
)
1613 && (size
> SFT_OFFSET (sv
) - offset
))
1621 #endif /* _TREE_FLOW_INLINE_H */