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)
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 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
= first_htab_element (&iter
->hti
, referenced_vars
);
87 /* Return true if we have hit the end of the referenced variables ITER is
91 end_referenced_vars_p (referenced_var_iterator
*iter
)
93 return end_htab_p (&iter
->hti
);
96 /* Make ITER point to the next referenced_var in the referenced_var hashtable,
97 and return that variable. */
100 next_referenced_var (referenced_var_iterator
*iter
)
102 struct int_tree_map
*itm
;
103 itm
= next_htab_element (&iter
->hti
);
109 /* Return the variable annotation for T, which must be a _DECL node.
110 Return NULL if the variable annotation doesn't already exist. */
111 static inline var_ann_t
115 gcc_assert (DECL_P (t
));
116 gcc_assert (!t
->common
.ann
|| t
->common
.ann
->common
.type
== VAR_ANN
);
118 return (var_ann_t
) t
->common
.ann
;
121 /* Return the variable annotation for T, which must be a _DECL node.
122 Create the variable annotation if it doesn't exist. */
123 static inline var_ann_t
124 get_var_ann (tree var
)
126 var_ann_t ann
= var_ann (var
);
127 return (ann
) ? ann
: create_var_ann (var
);
130 /* Return the statement annotation for T, which must be a statement
131 node. Return NULL if the statement annotation doesn't exist. */
132 static inline stmt_ann_t
135 #ifdef ENABLE_CHECKING
136 gcc_assert (is_gimple_stmt (t
));
138 return (stmt_ann_t
) t
->common
.ann
;
141 /* Return the statement annotation for T, which must be a statement
142 node. Create the statement annotation if it doesn't exist. */
143 static inline stmt_ann_t
144 get_stmt_ann (tree stmt
)
146 stmt_ann_t ann
= stmt_ann (stmt
);
147 return (ann
) ? ann
: create_stmt_ann (stmt
);
150 /* Return the annotation type for annotation ANN. */
151 static inline enum tree_ann_type
152 ann_type (tree_ann_t ann
)
154 return ann
->common
.type
;
157 /* Return the basic block for statement T. */
158 static inline basic_block
163 if (TREE_CODE (t
) == PHI_NODE
)
167 return ann
? ann
->bb
: NULL
;
170 /* Return the may_aliases varray for variable VAR, or NULL if it has
172 static inline varray_type
173 may_aliases (tree var
)
175 var_ann_t ann
= var_ann (var
);
176 return ann
? ann
->may_aliases
: NULL
;
179 /* Return the line number for EXPR, or return -1 if we have no line
180 number information for it. */
182 get_lineno (tree expr
)
184 if (expr
== NULL_TREE
)
187 if (TREE_CODE (expr
) == COMPOUND_EXPR
)
188 expr
= TREE_OPERAND (expr
, 0);
190 if (! EXPR_HAS_LOCATION (expr
))
193 return EXPR_LINENO (expr
);
196 /* Return the file name for EXPR, or return "???" if we have no
197 filename information. */
198 static inline const char *
199 get_filename (tree expr
)
201 const char *filename
;
202 if (expr
== NULL_TREE
)
205 if (TREE_CODE (expr
) == COMPOUND_EXPR
)
206 expr
= TREE_OPERAND (expr
, 0);
208 if (EXPR_HAS_LOCATION (expr
) && (filename
= EXPR_FILENAME (expr
)))
214 /* Return true if T is a noreturn call. */
216 noreturn_call_p (tree t
)
218 tree call
= get_call_expr_in (t
);
219 return call
!= 0 && (call_expr_flags (call
) & ECF_NORETURN
) != 0;
222 /* Mark statement T as modified. */
224 mark_stmt_modified (tree t
)
227 if (TREE_CODE (t
) == PHI_NODE
)
232 ann
= create_stmt_ann (t
);
233 else if (noreturn_call_p (t
))
234 VEC_safe_push (tree
, gc
, modified_noreturn_calls
, t
);
238 /* Mark statement T as modified, and update it. */
242 if (TREE_CODE (t
) == PHI_NODE
)
244 mark_stmt_modified (t
);
245 update_stmt_operands (t
);
249 update_stmt_if_modified (tree t
)
251 if (stmt_modified_p (t
))
252 update_stmt_operands (t
);
255 /* Return true if T is marked as modified, false otherwise. */
257 stmt_modified_p (tree t
)
259 stmt_ann_t ann
= stmt_ann (t
);
261 /* Note that if the statement doesn't yet have an annotation, we consider it
262 modified. This will force the next call to update_stmt_operands to scan
264 return ann
? ann
->modified
: true;
267 /* Delink an immediate_uses node from its chain. */
269 delink_imm_use (ssa_use_operand_t
*linknode
)
271 /* Return if this node is not in a list. */
272 if (linknode
->prev
== NULL
)
275 linknode
->prev
->next
= linknode
->next
;
276 linknode
->next
->prev
= linknode
->prev
;
277 linknode
->prev
= NULL
;
278 linknode
->next
= NULL
;
281 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
283 link_imm_use_to_list (ssa_use_operand_t
*linknode
, ssa_use_operand_t
*list
)
285 /* Link the new node at the head of the list. If we are in the process of
286 traversing the list, we won't visit any new nodes added to it. */
287 linknode
->prev
= list
;
288 linknode
->next
= list
->next
;
289 list
->next
->prev
= linknode
;
290 list
->next
= linknode
;
293 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
295 link_imm_use (ssa_use_operand_t
*linknode
, tree def
)
297 ssa_use_operand_t
*root
;
299 if (!def
|| TREE_CODE (def
) != SSA_NAME
)
300 linknode
->prev
= NULL
;
303 root
= &(SSA_NAME_IMM_USE_NODE (def
));
304 #ifdef ENABLE_CHECKING
306 gcc_assert (*(linknode
->use
) == def
);
308 link_imm_use_to_list (linknode
, root
);
312 /* Set the value of a use pointed by USE to VAL. */
314 set_ssa_use_from_ptr (use_operand_p use
, tree val
)
316 delink_imm_use (use
);
318 link_imm_use (use
, val
);
321 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
324 link_imm_use_stmt (ssa_use_operand_t
*linknode
, tree def
, tree stmt
)
327 link_imm_use (linknode
, def
);
329 link_imm_use (linknode
, NULL
);
330 linknode
->stmt
= stmt
;
333 /* Relink a new node in place of an old node in the list. */
335 relink_imm_use (ssa_use_operand_t
*node
, ssa_use_operand_t
*old
)
337 /* The node one had better be in the same list. */
338 gcc_assert (*(old
->use
) == *(node
->use
));
339 node
->prev
= old
->prev
;
340 node
->next
= old
->next
;
343 old
->prev
->next
= node
;
344 old
->next
->prev
= node
;
345 /* Remove the old node from the list. */
350 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
353 relink_imm_use_stmt (ssa_use_operand_t
*linknode
, ssa_use_operand_t
*old
, tree stmt
)
356 relink_imm_use (linknode
, old
);
358 link_imm_use (linknode
, NULL
);
359 linknode
->stmt
= stmt
;
362 /* Finished the traverse of an immediate use list IMM by removing it from
365 end_safe_imm_use_traverse (imm_use_iterator
*imm
)
367 delink_imm_use (&(imm
->iter_node
));
370 /* Return true if IMM is at the end of the list. */
372 end_safe_imm_use_p (imm_use_iterator
*imm
)
374 return (imm
->imm_use
== imm
->end_p
);
377 /* Initialize iterator IMM to process the list for VAR. */
378 static inline use_operand_p
379 first_safe_imm_use (imm_use_iterator
*imm
, tree var
)
381 /* Set up and link the iterator node into the linked list for VAR. */
382 imm
->iter_node
.use
= NULL
;
383 imm
->iter_node
.stmt
= NULL_TREE
;
384 imm
->end_p
= &(SSA_NAME_IMM_USE_NODE (var
));
385 /* Check if there are 0 elements. */
386 if (imm
->end_p
->next
== imm
->end_p
)
388 imm
->imm_use
= imm
->end_p
;
389 return NULL_USE_OPERAND_P
;
392 link_imm_use (&(imm
->iter_node
), var
);
393 imm
->imm_use
= imm
->iter_node
.next
;
397 /* Bump IMM to the next use in the list. */
398 static inline use_operand_p
399 next_safe_imm_use (imm_use_iterator
*imm
)
401 ssa_use_operand_t
*ptr
;
405 /* If the next node following the iter_node is still the one referred to by
406 imm_use, then the list hasn't changed, go to the next node. */
407 if (imm
->iter_node
.next
== imm
->imm_use
)
409 ptr
= &(imm
->iter_node
);
410 /* Remove iternode from the list. */
411 delink_imm_use (ptr
);
412 imm
->imm_use
= imm
->imm_use
->next
;
413 if (! end_safe_imm_use_p (imm
))
415 /* This isn't the end, link iternode before the next use. */
416 ptr
->prev
= imm
->imm_use
->prev
;
417 ptr
->next
= imm
->imm_use
;
418 imm
->imm_use
->prev
->next
= ptr
;
419 imm
->imm_use
->prev
= ptr
;
426 /* If the 'next' value after the iterator isn't the same as it was, then
427 a node has been deleted, so we simply proceed to the node following
428 where the iterator is in the list. */
429 imm
->imm_use
= imm
->iter_node
.next
;
430 if (end_safe_imm_use_p (imm
))
432 end_safe_imm_use_traverse (imm
);
440 /* Return true is IMM has reached the end of the immediate use list. */
442 end_readonly_imm_use_p (imm_use_iterator
*imm
)
444 return (imm
->imm_use
== imm
->end_p
);
447 /* Initialize iterator IMM to process the list for VAR. */
448 static inline use_operand_p
449 first_readonly_imm_use (imm_use_iterator
*imm
, tree var
)
451 gcc_assert (TREE_CODE (var
) == SSA_NAME
);
453 imm
->end_p
= &(SSA_NAME_IMM_USE_NODE (var
));
454 imm
->imm_use
= imm
->end_p
->next
;
455 #ifdef ENABLE_CHECKING
456 imm
->iter_node
.next
= imm
->imm_use
->next
;
458 if (end_readonly_imm_use_p (imm
))
459 return NULL_USE_OPERAND_P
;
463 /* Bump IMM to the next use in the list. */
464 static inline use_operand_p
465 next_readonly_imm_use (imm_use_iterator
*imm
)
467 use_operand_p old
= imm
->imm_use
;
469 #ifdef ENABLE_CHECKING
470 /* If this assertion fails, it indicates the 'next' pointer has changed
471 since we the last bump. This indicates that the list is being modified
472 via stmt changes, or SET_USE, or somesuch thing, and you need to be
473 using the SAFE version of the iterator. */
474 gcc_assert (imm
->iter_node
.next
== old
->next
);
475 imm
->iter_node
.next
= old
->next
->next
;
478 imm
->imm_use
= old
->next
;
479 if (end_readonly_imm_use_p (imm
))
484 /* Return true if VAR has no uses. */
486 has_zero_uses (tree var
)
488 ssa_use_operand_t
*ptr
;
489 ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
490 /* A single use means there is no items in the list. */
491 return (ptr
== ptr
->next
);
494 /* Return true if VAR has a single use. */
496 has_single_use (tree var
)
498 ssa_use_operand_t
*ptr
;
499 ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
500 /* A single use means there is one item in the list. */
501 return (ptr
!= ptr
->next
&& ptr
== ptr
->next
->next
);
504 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
505 to the use pointer and stmt of occurrence. */
507 single_imm_use (tree var
, use_operand_p
*use_p
, tree
*stmt
)
509 ssa_use_operand_t
*ptr
;
511 ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
512 if (ptr
!= ptr
->next
&& ptr
== ptr
->next
->next
)
515 *stmt
= ptr
->next
->stmt
;
518 *use_p
= NULL_USE_OPERAND_P
;
523 /* Return the number of immediate uses of VAR. */
524 static inline unsigned int
525 num_imm_uses (tree var
)
527 ssa_use_operand_t
*ptr
, *start
;
530 start
= &(SSA_NAME_IMM_USE_NODE (var
));
532 for (ptr
= start
->next
; ptr
!= start
; ptr
= ptr
->next
)
539 /* Return the tree pointer to by USE. */
541 get_use_from_ptr (use_operand_p use
)
546 /* Return the tree pointer to by DEF. */
548 get_def_from_ptr (def_operand_p def
)
553 /* Return a def_operand_p pointer for the result of PHI. */
554 static inline def_operand_p
555 get_phi_result_ptr (tree phi
)
557 return &(PHI_RESULT_TREE (phi
));
560 /* Return a use_operand_p pointer for argument I of phinode PHI. */
561 static inline use_operand_p
562 get_phi_arg_def_ptr (tree phi
, int i
)
564 return &(PHI_ARG_IMM_USE_NODE (phi
,i
));
568 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
571 addresses_taken (tree stmt
)
573 stmt_ann_t ann
= stmt_ann (stmt
);
574 return ann
? ann
->addresses_taken
: NULL
;
577 /* Return the PHI nodes for basic block BB, or NULL if there are no
580 phi_nodes (basic_block bb
)
582 return bb
->phi_nodes
;
585 /* Set list of phi nodes of a basic block BB to L. */
588 set_phi_nodes (basic_block bb
, tree l
)
593 for (phi
= l
; phi
; phi
= PHI_CHAIN (phi
))
594 set_bb_for_stmt (phi
, bb
);
597 /* Return the phi argument which contains the specified use. */
600 phi_arg_index_from_use (use_operand_p use
)
602 struct phi_arg_d
*element
, *root
;
606 /* Since the use is the first thing in a PHI argument element, we can
607 calculate its index based on casting it to an argument, and performing
608 pointer arithmetic. */
610 phi
= USE_STMT (use
);
611 gcc_assert (TREE_CODE (phi
) == PHI_NODE
);
613 element
= (struct phi_arg_d
*)use
;
614 root
= &(PHI_ARG_ELT (phi
, 0));
615 index
= element
- root
;
617 #ifdef ENABLE_CHECKING
618 /* Make sure the calculation doesn't have any leftover bytes. If it does,
619 then imm_use is likely not the first element in phi_arg_d. */
621 (((char *)element
- (char *)root
) % sizeof (struct phi_arg_d
)) == 0);
622 gcc_assert (index
>= 0 && index
< PHI_ARG_CAPACITY (phi
));
628 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
631 set_is_used (tree var
)
633 var_ann_t ann
= get_var_ann (var
);
638 /* ----------------------------------------------------------------------- */
640 /* Return true if T is an executable statement. */
642 is_exec_stmt (tree t
)
644 return (t
&& !IS_EMPTY_STMT (t
) && t
!= error_mark_node
);
648 /* Return true if this stmt can be the target of a control transfer stmt such
651 is_label_stmt (tree t
)
654 switch (TREE_CODE (t
))
658 case CASE_LABEL_EXPR
:
666 /* Set the default definition for VAR to DEF. */
668 set_default_def (tree var
, tree def
)
670 var_ann_t ann
= get_var_ann (var
);
671 ann
->default_def
= def
;
674 /* Return the default definition for variable VAR, or NULL if none
677 default_def (tree var
)
679 var_ann_t ann
= var_ann (var
);
680 return ann
? ann
->default_def
: NULL_TREE
;
683 /* PHI nodes should contain only ssa_names and invariants. A test
684 for ssa_name is definitely simpler; don't let invalid contents
685 slip in in the meantime. */
688 phi_ssa_name_p (tree t
)
690 if (TREE_CODE (t
) == SSA_NAME
)
692 #ifdef ENABLE_CHECKING
693 gcc_assert (is_gimple_min_invariant (t
));
698 /* ----------------------------------------------------------------------- */
700 /* Return a block_stmt_iterator that points to beginning of basic
702 static inline block_stmt_iterator
703 bsi_start (basic_block bb
)
705 block_stmt_iterator bsi
;
707 bsi
.tsi
= tsi_start (bb
->stmt_list
);
710 gcc_assert (bb
->index
< 0);
712 bsi
.tsi
.container
= NULL
;
718 /* Return a block statement iterator that points to the last label in
721 static inline block_stmt_iterator
722 bsi_after_labels (basic_block bb
)
724 block_stmt_iterator bsi
;
725 tree_stmt_iterator next
;
731 gcc_assert (bb
->index
< 0);
733 bsi
.tsi
.container
= NULL
;
737 bsi
.tsi
= tsi_start (bb
->stmt_list
);
738 if (tsi_end_p (bsi
.tsi
))
741 /* Ensure that there are some labels. The rationale is that we want
742 to insert after the bsi that is returned, and these insertions should
743 be placed at the start of the basic block. This would not work if the
744 first statement was not label; rather fail here than enable the user
745 proceed in wrong way. */
746 gcc_assert (TREE_CODE (tsi_stmt (bsi
.tsi
)) == LABEL_EXPR
);
751 while (!tsi_end_p (next
)
752 && TREE_CODE (tsi_stmt (next
)) == LABEL_EXPR
)
761 /* Return a block statement iterator that points to the end of basic
763 static inline block_stmt_iterator
764 bsi_last (basic_block bb
)
766 block_stmt_iterator bsi
;
768 bsi
.tsi
= tsi_last (bb
->stmt_list
);
771 gcc_assert (bb
->index
< 0);
773 bsi
.tsi
.container
= NULL
;
779 /* Return true if block statement iterator I has reached the end of
782 bsi_end_p (block_stmt_iterator i
)
784 return tsi_end_p (i
.tsi
);
787 /* Modify block statement iterator I so that it is at the next
788 statement in the basic block. */
790 bsi_next (block_stmt_iterator
*i
)
795 /* Modify block statement iterator I so that it is at the previous
796 statement in the basic block. */
798 bsi_prev (block_stmt_iterator
*i
)
803 /* Return the statement that block statement iterator I is currently
806 bsi_stmt (block_stmt_iterator i
)
808 return tsi_stmt (i
.tsi
);
811 /* Return a pointer to the statement that block statement iterator I
814 bsi_stmt_ptr (block_stmt_iterator i
)
816 return tsi_stmt_ptr (i
.tsi
);
819 /* Returns the loop of the statement STMT. */
821 static inline struct loop
*
822 loop_containing_stmt (tree stmt
)
824 basic_block bb
= bb_for_stmt (stmt
);
828 return bb
->loop_father
;
831 /* Return true if VAR is a clobbered by function calls. */
833 is_call_clobbered (tree var
)
835 return is_global_var (var
)
836 || bitmap_bit_p (call_clobbered_vars
, DECL_UID (var
));
839 /* Mark variable VAR as being clobbered by function calls. */
841 mark_call_clobbered (tree var
)
843 var_ann_t ann
= var_ann (var
);
844 /* If VAR is a memory tag, then we need to consider it a global
845 variable. This is because the pointer that VAR represents has
846 been found to point to either an arbitrary location or to a known
847 location in global memory. */
848 if (ann
->mem_tag_kind
!= NOT_A_TAG
&& ann
->mem_tag_kind
!= STRUCT_FIELD
)
849 DECL_EXTERNAL (var
) = 1;
850 bitmap_set_bit (call_clobbered_vars
, DECL_UID (var
));
851 ssa_call_clobbered_cache_valid
= false;
852 ssa_ro_call_cache_valid
= false;
855 /* Clear the call-clobbered attribute from variable VAR. */
857 clear_call_clobbered (tree var
)
859 var_ann_t ann
= var_ann (var
);
860 if (ann
->mem_tag_kind
!= NOT_A_TAG
&& ann
->mem_tag_kind
!= STRUCT_FIELD
)
861 DECL_EXTERNAL (var
) = 0;
862 bitmap_clear_bit (call_clobbered_vars
, DECL_UID (var
));
863 ssa_call_clobbered_cache_valid
= false;
864 ssa_ro_call_cache_valid
= false;
867 /* Mark variable VAR as being non-addressable. */
869 mark_non_addressable (tree var
)
871 bitmap_clear_bit (call_clobbered_vars
, DECL_UID (var
));
872 TREE_ADDRESSABLE (var
) = 0;
873 ssa_call_clobbered_cache_valid
= false;
874 ssa_ro_call_cache_valid
= false;
877 /* Return the common annotation for T. Return NULL if the annotation
878 doesn't already exist. */
879 static inline tree_ann_t
882 return t
->common
.ann
;
885 /* Return a common annotation for T. Create the constant annotation if it
887 static inline tree_ann_t
888 get_tree_ann (tree t
)
890 tree_ann_t ann
= tree_ann (t
);
891 return (ann
) ? ann
: create_tree_ann (t
);
894 /* ----------------------------------------------------------------------- */
896 /* The following set of routines are used to iterator over various type of
899 /* Return true if PTR is finished iterating. */
901 op_iter_done (ssa_op_iter
*ptr
)
906 /* Get the next iterator use value for PTR. */
907 static inline use_operand_p
908 op_iter_next_use (ssa_op_iter
*ptr
)
911 #ifdef ENABLE_CHECKING
912 gcc_assert (ptr
->iter_type
== ssa_op_iter_use
);
916 use_p
= USE_OP_PTR (ptr
->uses
);
917 ptr
->uses
= ptr
->uses
->next
;
922 use_p
= VUSE_OP_PTR (ptr
->vuses
);
923 ptr
->vuses
= ptr
->vuses
->next
;
928 use_p
= MAYDEF_OP_PTR (ptr
->mayuses
);
929 ptr
->mayuses
= ptr
->mayuses
->next
;
934 use_p
= MUSTDEF_KILL_PTR (ptr
->mustkills
);
935 ptr
->mustkills
= ptr
->mustkills
->next
;
938 if (ptr
->phi_i
< ptr
->num_phi
)
940 return PHI_ARG_DEF_PTR (ptr
->phi_stmt
, (ptr
->phi_i
)++);
943 return NULL_USE_OPERAND_P
;
946 /* Get the next iterator def value for PTR. */
947 static inline def_operand_p
948 op_iter_next_def (ssa_op_iter
*ptr
)
951 #ifdef ENABLE_CHECKING
952 gcc_assert (ptr
->iter_type
== ssa_op_iter_def
);
956 def_p
= DEF_OP_PTR (ptr
->defs
);
957 ptr
->defs
= ptr
->defs
->next
;
962 def_p
= MUSTDEF_RESULT_PTR (ptr
->mustdefs
);
963 ptr
->mustdefs
= ptr
->mustdefs
->next
;
968 def_p
= MAYDEF_RESULT_PTR (ptr
->maydefs
);
969 ptr
->maydefs
= ptr
->maydefs
->next
;
973 return NULL_DEF_OPERAND_P
;
976 /* Get the next iterator tree value for PTR. */
978 op_iter_next_tree (ssa_op_iter
*ptr
)
981 #ifdef ENABLE_CHECKING
982 gcc_assert (ptr
->iter_type
== ssa_op_iter_tree
);
986 val
= USE_OP (ptr
->uses
);
987 ptr
->uses
= ptr
->uses
->next
;
992 val
= VUSE_OP (ptr
->vuses
);
993 ptr
->vuses
= ptr
->vuses
->next
;
998 val
= MAYDEF_OP (ptr
->mayuses
);
999 ptr
->mayuses
= ptr
->mayuses
->next
;
1004 val
= MUSTDEF_KILL (ptr
->mustkills
);
1005 ptr
->mustkills
= ptr
->mustkills
->next
;
1010 val
= DEF_OP (ptr
->defs
);
1011 ptr
->defs
= ptr
->defs
->next
;
1016 val
= MUSTDEF_RESULT (ptr
->mustdefs
);
1017 ptr
->mustdefs
= ptr
->mustdefs
->next
;
1022 val
= MAYDEF_RESULT (ptr
->maydefs
);
1023 ptr
->maydefs
= ptr
->maydefs
->next
;
1033 /* This functions clears the iterator PTR, and marks it done. This is normally
1034 used to prevent warnings in the compile about might be uninitailzied
1038 clear_and_done_ssa_iter (ssa_op_iter
*ptr
)
1043 ptr
->maydefs
= NULL
;
1044 ptr
->mayuses
= NULL
;
1045 ptr
->mustdefs
= NULL
;
1046 ptr
->mustkills
= NULL
;
1047 ptr
->iter_type
= ssa_op_iter_none
;
1050 ptr
->phi_stmt
= NULL_TREE
;
1054 /* Initialize the iterator PTR to the virtual defs in STMT. */
1056 op_iter_init (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1058 #ifdef ENABLE_CHECKING
1059 gcc_assert (stmt_ann (stmt
));
1062 ptr
->defs
= (flags
& SSA_OP_DEF
) ? DEF_OPS (stmt
) : NULL
;
1063 ptr
->uses
= (flags
& SSA_OP_USE
) ? USE_OPS (stmt
) : NULL
;
1064 ptr
->vuses
= (flags
& SSA_OP_VUSE
) ? VUSE_OPS (stmt
) : NULL
;
1065 ptr
->maydefs
= (flags
& SSA_OP_VMAYDEF
) ? MAYDEF_OPS (stmt
) : NULL
;
1066 ptr
->mayuses
= (flags
& SSA_OP_VMAYUSE
) ? MAYDEF_OPS (stmt
) : NULL
;
1067 ptr
->mustdefs
= (flags
& SSA_OP_VMUSTDEF
) ? MUSTDEF_OPS (stmt
) : NULL
;
1068 ptr
->mustkills
= (flags
& SSA_OP_VMUSTKILL
) ? MUSTDEF_OPS (stmt
) : NULL
;
1073 ptr
->phi_stmt
= NULL_TREE
;
1076 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1078 static inline use_operand_p
1079 op_iter_init_use (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1081 gcc_assert ((flags
& SSA_OP_ALL_DEFS
) == 0);
1082 op_iter_init (ptr
, stmt
, flags
);
1083 ptr
->iter_type
= ssa_op_iter_use
;
1084 return op_iter_next_use (ptr
);
1087 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1089 static inline def_operand_p
1090 op_iter_init_def (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1092 gcc_assert ((flags
& (SSA_OP_ALL_USES
| SSA_OP_VIRTUAL_KILLS
)) == 0);
1093 op_iter_init (ptr
, stmt
, flags
);
1094 ptr
->iter_type
= ssa_op_iter_def
;
1095 return op_iter_next_def (ptr
);
1098 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1099 the first operand as a tree. */
1101 op_iter_init_tree (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1103 op_iter_init (ptr
, stmt
, flags
);
1104 ptr
->iter_type
= ssa_op_iter_tree
;
1105 return op_iter_next_tree (ptr
);
1108 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1111 op_iter_next_maymustdef (use_operand_p
*use
, def_operand_p
*def
,
1114 #ifdef ENABLE_CHECKING
1115 gcc_assert (ptr
->iter_type
== ssa_op_iter_maymustdef
);
1119 *def
= MAYDEF_RESULT_PTR (ptr
->mayuses
);
1120 *use
= MAYDEF_OP_PTR (ptr
->mayuses
);
1121 ptr
->mayuses
= ptr
->mayuses
->next
;
1127 *def
= MUSTDEF_RESULT_PTR (ptr
->mustkills
);
1128 *use
= MUSTDEF_KILL_PTR (ptr
->mustkills
);
1129 ptr
->mustkills
= ptr
->mustkills
->next
;
1133 *def
= NULL_DEF_OPERAND_P
;
1134 *use
= NULL_USE_OPERAND_P
;
1140 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1143 op_iter_init_maydef (ssa_op_iter
*ptr
, tree stmt
, use_operand_p
*use
,
1146 gcc_assert (TREE_CODE (stmt
) != PHI_NODE
);
1148 op_iter_init (ptr
, stmt
, SSA_OP_VMAYUSE
);
1149 ptr
->iter_type
= ssa_op_iter_maymustdef
;
1150 op_iter_next_maymustdef (use
, def
, ptr
);
1154 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1157 op_iter_init_mustdef (ssa_op_iter
*ptr
, tree stmt
, use_operand_p
*kill
,
1160 gcc_assert (TREE_CODE (stmt
) != PHI_NODE
);
1162 op_iter_init (ptr
, stmt
, SSA_OP_VMUSTKILL
);
1163 ptr
->iter_type
= ssa_op_iter_maymustdef
;
1164 op_iter_next_maymustdef (kill
, def
, ptr
);
1167 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1170 op_iter_init_must_and_may_def (ssa_op_iter
*ptr
, tree stmt
,
1171 use_operand_p
*kill
, def_operand_p
*def
)
1173 gcc_assert (TREE_CODE (stmt
) != PHI_NODE
);
1175 op_iter_init (ptr
, stmt
, SSA_OP_VMUSTKILL
|SSA_OP_VMAYUSE
);
1176 ptr
->iter_type
= ssa_op_iter_maymustdef
;
1177 op_iter_next_maymustdef (kill
, def
, ptr
);
1181 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1182 return NULL. PTR is the iterator to use. */
1184 single_ssa_tree_operand (tree stmt
, int flags
)
1189 var
= op_iter_init_tree (&iter
, stmt
, flags
);
1190 if (op_iter_done (&iter
))
1192 op_iter_next_tree (&iter
);
1193 if (op_iter_done (&iter
))
1199 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1200 return NULL. PTR is the iterator to use. */
1201 static inline use_operand_p
1202 single_ssa_use_operand (tree stmt
, int flags
)
1207 var
= op_iter_init_use (&iter
, stmt
, flags
);
1208 if (op_iter_done (&iter
))
1209 return NULL_USE_OPERAND_P
;
1210 op_iter_next_use (&iter
);
1211 if (op_iter_done (&iter
))
1213 return NULL_USE_OPERAND_P
;
1218 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1219 return NULL. PTR is the iterator to use. */
1220 static inline def_operand_p
1221 single_ssa_def_operand (tree stmt
, int flags
)
1226 var
= op_iter_init_def (&iter
, stmt
, flags
);
1227 if (op_iter_done (&iter
))
1228 return NULL_DEF_OPERAND_P
;
1229 op_iter_next_def (&iter
);
1230 if (op_iter_done (&iter
))
1232 return NULL_DEF_OPERAND_P
;
1236 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1237 return NULL. PTR is the iterator to use. */
1239 zero_ssa_operands (tree stmt
, int flags
)
1243 op_iter_init_tree (&iter
, stmt
, flags
);
1244 return op_iter_done (&iter
);
1248 /* Return the number of operands matching FLAGS in STMT. */
1250 num_ssa_operands (tree stmt
, int flags
)
1256 FOR_EACH_SSA_TREE_OPERAND (t
, stmt
, iter
, flags
)
1262 /* Delink all immediate_use information for STMT. */
1264 delink_stmt_imm_use (tree stmt
)
1267 use_operand_p use_p
;
1269 if (ssa_operands_active ())
1270 FOR_EACH_SSA_USE_OPERAND (use_p
, stmt
, iter
,
1271 (SSA_OP_ALL_USES
| SSA_OP_ALL_KILLS
))
1272 delink_imm_use (use_p
);
1276 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1277 in STMT2. TRUE is returned if they are the same. STMTs can be NULL. */
1279 compare_ssa_operands_equal (tree stmt1
, tree stmt2
, int flags
)
1281 ssa_op_iter iter1
, iter2
;
1282 tree op1
= NULL_TREE
;
1283 tree op2
= NULL_TREE
;
1289 look1
= stmt1
&& stmt_ann (stmt1
);
1290 look2
= stmt2
&& stmt_ann (stmt2
);
1294 op1
= op_iter_init_tree (&iter1
, stmt1
, flags
);
1296 return op_iter_done (&iter1
);
1299 clear_and_done_ssa_iter (&iter1
);
1303 op2
= op_iter_init_tree (&iter2
, stmt2
, flags
);
1305 return op_iter_done (&iter2
);
1308 clear_and_done_ssa_iter (&iter2
);
1310 while (!op_iter_done (&iter1
) && !op_iter_done (&iter2
))
1314 op1
= op_iter_next_tree (&iter1
);
1315 op2
= op_iter_next_tree (&iter2
);
1318 return (op_iter_done (&iter1
) && op_iter_done (&iter2
));
1322 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1323 Otherwise return NULL_DEF_OPERAND_P. */
1325 single_phi_def (tree stmt
, int flags
)
1327 tree def
= PHI_RESULT (stmt
);
1328 if ((flags
& SSA_OP_DEF
) && is_gimple_reg (def
))
1330 if ((flags
& SSA_OP_VIRTUAL_DEFS
) && !is_gimple_reg (def
))
1335 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
1336 be either SSA_OP_USES or SAS_OP_VIRTUAL_USES. */
1337 static inline use_operand_p
1338 op_iter_init_phiuse (ssa_op_iter
*ptr
, tree phi
, int flags
)
1340 tree phi_def
= PHI_RESULT (phi
);
1343 clear_and_done_ssa_iter (ptr
);
1346 gcc_assert ((flags
& (SSA_OP_USE
| SSA_OP_VIRTUAL_USES
)) != 0);
1348 comp
= (is_gimple_reg (phi_def
) ? SSA_OP_USE
: SSA_OP_VIRTUAL_USES
);
1350 /* If the PHI node doesn't the operand type we care about, we're done. */
1351 if ((flags
& comp
) == 0)
1354 return NULL_USE_OPERAND_P
;
1357 ptr
->phi_stmt
= phi
;
1358 ptr
->num_phi
= PHI_NUM_ARGS (phi
);
1359 ptr
->iter_type
= ssa_op_iter_use
;
1360 return op_iter_next_use (ptr
);
1364 /* Start an iterator for a PHI definition. */
1366 static inline def_operand_p
1367 op_iter_init_phidef (ssa_op_iter
*ptr
, tree phi
, int flags
)
1369 tree phi_def
= PHI_RESULT (phi
);
1372 clear_and_done_ssa_iter (ptr
);
1375 gcc_assert ((flags
& (SSA_OP_DEF
| SSA_OP_VIRTUAL_DEFS
)) != 0);
1377 comp
= (is_gimple_reg (phi_def
) ? SSA_OP_DEF
: SSA_OP_VIRTUAL_DEFS
);
1379 /* If the PHI node doesn't the operand type we care about, we're done. */
1380 if ((flags
& comp
) == 0)
1383 return NULL_USE_OPERAND_P
;
1386 ptr
->iter_type
= ssa_op_iter_def
;
1387 /* The first call to op_iter_next_def will terminate the iterator since
1388 all the fields are NULL. Simply return the result here as the first and
1389 therefore only result. */
1390 return PHI_RESULT_PTR (phi
);
1395 /* Return true if VAR cannot be modified by the program. */
1398 unmodifiable_var_p (tree var
)
1400 if (TREE_CODE (var
) == SSA_NAME
)
1401 var
= SSA_NAME_VAR (var
);
1402 return TREE_READONLY (var
) && (TREE_STATIC (var
) || DECL_EXTERNAL (var
));
1405 /* Return true if REF, a COMPONENT_REF, has an ARRAY_REF somewhere in it. */
1408 ref_contains_array_ref (tree ref
)
1410 while (handled_component_p (ref
))
1412 if (TREE_CODE (ref
) == ARRAY_REF
)
1414 ref
= TREE_OPERAND (ref
, 0);
1419 /* Given a variable VAR, lookup and return a pointer to the list of
1420 subvariables for it. */
1422 static inline subvar_t
*
1423 lookup_subvars_for_var (tree var
)
1425 var_ann_t ann
= var_ann (var
);
1427 return &ann
->subvars
;
1430 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1431 NULL, if there are no subvariables. */
1433 static inline subvar_t
1434 get_subvars_for_var (tree var
)
1438 gcc_assert (SSA_VAR_P (var
));
1440 if (TREE_CODE (var
) == SSA_NAME
)
1441 subvars
= *(lookup_subvars_for_var (SSA_NAME_VAR (var
)));
1443 subvars
= *(lookup_subvars_for_var (var
));
1447 /* Return the subvariable of VAR at offset OFFSET. */
1450 get_subvar_at (tree var
, unsigned HOST_WIDE_INT offset
)
1454 for (sv
= get_subvars_for_var (var
); sv
; sv
= sv
->next
)
1455 if (sv
->offset
== offset
)
1461 /* Return true if V is a tree that we can have subvars for.
1462 Normally, this is any aggregate type, however, due to implementation
1463 limitations ATM, we exclude array types as well. */
1466 var_can_have_subvars (tree v
)
1468 return (AGGREGATE_TYPE_P (TREE_TYPE (v
)) &&
1469 TREE_CODE (TREE_TYPE (v
)) != ARRAY_TYPE
);
1473 /* Return true if OFFSET and SIZE define a range that overlaps with some
1474 portion of the range of SV, a subvar. If there was an exact overlap,
1475 *EXACT will be set to true upon return. */
1478 overlap_subvar (unsigned HOST_WIDE_INT offset
, unsigned HOST_WIDE_INT size
,
1479 subvar_t sv
, bool *exact
)
1481 /* There are three possible cases of overlap.
1482 1. We can have an exact overlap, like so:
1483 |offset, offset + size |
1484 |sv->offset, sv->offset + sv->size |
1486 2. We can have offset starting after sv->offset, like so:
1488 |offset, offset + size |
1489 |sv->offset, sv->offset + sv->size |
1491 3. We can have offset starting before sv->offset, like so:
1493 |offset, offset + size |
1494 |sv->offset, sv->offset + sv->size|
1499 if (offset
== sv
->offset
&& size
== sv
->size
)
1505 else if (offset
>= sv
->offset
&& offset
< (sv
->offset
+ sv
->size
))
1509 else if (offset
< sv
->offset
&& (offset
+ size
> sv
->offset
))
1517 #endif /* _TREE_FLOW_INLINE_H */