1 /* Inline functions for tree-flow.h
2 Copyright (C) 2001, 2003, 2005, 2006, 2007 Free Software Foundation, Inc.
3 Contributed by Diego Novillo <dnovillo@redhat.com>
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 3, 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 COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef _TREE_FLOW_INLINE_H
22 #define _TREE_FLOW_INLINE_H 1
24 /* Inline functions for manipulating various data structures defined in
25 tree-flow.h. See tree-flow.h for documentation. */
27 /* Initialize the hashtable iterator HTI to point to hashtable TABLE */
30 first_htab_element (htab_iterator
*hti
, htab_t table
)
33 hti
->slot
= table
->entries
;
34 hti
->limit
= hti
->slot
+ htab_size (table
);
38 if (x
!= HTAB_EMPTY_ENTRY
&& x
!= HTAB_DELETED_ENTRY
)
40 } while (++(hti
->slot
) < hti
->limit
);
42 if (hti
->slot
< hti
->limit
)
47 /* Return current non-empty/deleted slot of the hashtable pointed to by HTI,
48 or NULL if we have reached the end. */
51 end_htab_p (htab_iterator
*hti
)
53 if (hti
->slot
>= hti
->limit
)
58 /* Advance the hashtable iterator pointed to by HTI to the next element of the
62 next_htab_element (htab_iterator
*hti
)
64 while (++(hti
->slot
) < hti
->limit
)
67 if (x
!= HTAB_EMPTY_ENTRY
&& x
!= HTAB_DELETED_ENTRY
)
73 /* Initialize ITER to point to the first referenced variable in the
74 referenced_vars hashtable, and return that variable. */
77 first_referenced_var (referenced_var_iterator
*iter
)
79 struct int_tree_map
*itm
;
80 itm
= (struct int_tree_map
*) first_htab_element (&iter
->hti
,
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
= (struct int_tree_map
*) next_htab_element (&iter
->hti
);
109 /* Fill up VEC with the variables in the referenced vars hashtable. */
112 fill_referenced_var_vec (VEC (tree
, heap
) **vec
)
114 referenced_var_iterator rvi
;
117 FOR_EACH_REFERENCED_VAR (var
, rvi
)
118 VEC_safe_push (tree
, heap
, *vec
, var
);
121 /* Return the variable annotation for T, which must be a _DECL node.
122 Return NULL if the variable annotation doesn't already exist. */
123 static inline var_ann_t
127 gcc_assert (DECL_P (t
));
128 gcc_assert (TREE_CODE (t
) != FUNCTION_DECL
);
129 gcc_assert (!t
->common
.ann
|| t
->common
.ann
->common
.type
== VAR_ANN
);
131 return (var_ann_t
) t
->common
.ann
;
134 /* Return the variable annotation for T, which must be a _DECL node.
135 Create the variable annotation if it doesn't exist. */
136 static inline var_ann_t
137 get_var_ann (tree var
)
139 var_ann_t ann
= var_ann (var
);
140 return (ann
) ? ann
: create_var_ann (var
);
143 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
144 Return NULL if the function annotation doesn't already exist. */
145 static inline function_ann_t
146 function_ann (tree t
)
149 gcc_assert (TREE_CODE (t
) == FUNCTION_DECL
);
150 gcc_assert (!t
->common
.ann
|| t
->common
.ann
->common
.type
== FUNCTION_ANN
);
152 return (function_ann_t
) t
->common
.ann
;
155 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
156 Create the function annotation if it doesn't exist. */
157 static inline function_ann_t
158 get_function_ann (tree var
)
160 function_ann_t ann
= function_ann (var
);
161 gcc_assert (!var
->common
.ann
|| var
->common
.ann
->common
.type
== FUNCTION_ANN
);
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 gcc_assert (!t
->common
.ann
|| t
->common
.ann
->common
.type
== STMT_ANN
);
174 return (stmt_ann_t
) t
->common
.ann
;
177 /* Return the statement annotation for T, which must be a statement
178 node. Create the statement annotation if it doesn't exist. */
179 static inline stmt_ann_t
180 get_stmt_ann (tree stmt
)
182 stmt_ann_t ann
= stmt_ann (stmt
);
183 return (ann
) ? ann
: create_stmt_ann (stmt
);
186 /* Return the annotation type for annotation ANN. */
187 static inline enum tree_ann_type
188 ann_type (tree_ann_t ann
)
190 return ann
->common
.type
;
193 /* Return the basic block for statement T. */
194 static inline basic_block
199 if (TREE_CODE (t
) == PHI_NODE
)
203 return ann
? ann
->bb
: NULL
;
206 /* Return the may_aliases varray for variable VAR, or NULL if it has
208 static inline VEC(tree
, gc
) *
209 may_aliases (tree var
)
211 var_ann_t ann
= var_ann (var
);
212 return ann
? ann
->may_aliases
: NULL
;
215 /* Return the line number for EXPR, or return -1 if we have no line
216 number information for it. */
218 get_lineno (tree expr
)
220 if (expr
== NULL_TREE
)
223 if (TREE_CODE (expr
) == COMPOUND_EXPR
)
224 expr
= TREE_OPERAND (expr
, 0);
226 if (! EXPR_HAS_LOCATION (expr
))
229 return EXPR_LINENO (expr
);
232 /* Return the file name for EXPR, or return "???" if we have no
233 filename information. */
234 static inline const char *
235 get_filename (tree expr
)
237 const char *filename
;
238 if (expr
== NULL_TREE
)
241 if (TREE_CODE (expr
) == COMPOUND_EXPR
)
242 expr
= TREE_OPERAND (expr
, 0);
244 if (EXPR_HAS_LOCATION (expr
) && (filename
= EXPR_FILENAME (expr
)))
250 /* Return true if T is a noreturn call. */
252 noreturn_call_p (tree t
)
254 tree call
= get_call_expr_in (t
);
255 return call
!= 0 && (call_expr_flags (call
) & ECF_NORETURN
) != 0;
258 /* Mark statement T as modified. */
260 mark_stmt_modified (tree t
)
263 if (TREE_CODE (t
) == PHI_NODE
)
268 ann
= create_stmt_ann (t
);
269 else if (noreturn_call_p (t
))
270 VEC_safe_push (tree
, gc
, modified_noreturn_calls
, t
);
274 /* Mark statement T as modified, and update it. */
278 if (TREE_CODE (t
) == PHI_NODE
)
280 mark_stmt_modified (t
);
281 update_stmt_operands (t
);
285 update_stmt_if_modified (tree t
)
287 if (stmt_modified_p (t
))
288 update_stmt_operands (t
);
291 /* Return true if T is marked as modified, false otherwise. */
293 stmt_modified_p (tree t
)
295 stmt_ann_t ann
= stmt_ann (t
);
297 /* Note that if the statement doesn't yet have an annotation, we consider it
298 modified. This will force the next call to update_stmt_operands to scan
300 return ann
? ann
->modified
: true;
303 /* Delink an immediate_uses node from its chain. */
305 delink_imm_use (ssa_use_operand_t
*linknode
)
307 /* Return if this node is not in a list. */
308 if (linknode
->prev
== NULL
)
311 linknode
->prev
->next
= linknode
->next
;
312 linknode
->next
->prev
= linknode
->prev
;
313 linknode
->prev
= NULL
;
314 linknode
->next
= NULL
;
317 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
319 link_imm_use_to_list (ssa_use_operand_t
*linknode
, ssa_use_operand_t
*list
)
321 /* Link the new node at the head of the list. If we are in the process of
322 traversing the list, we won't visit any new nodes added to it. */
323 linknode
->prev
= list
;
324 linknode
->next
= list
->next
;
325 list
->next
->prev
= linknode
;
326 list
->next
= linknode
;
329 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
331 link_imm_use (ssa_use_operand_t
*linknode
, tree def
)
333 ssa_use_operand_t
*root
;
335 if (!def
|| TREE_CODE (def
) != SSA_NAME
)
336 linknode
->prev
= NULL
;
339 root
= &(SSA_NAME_IMM_USE_NODE (def
));
340 #ifdef ENABLE_CHECKING
342 gcc_assert (*(linknode
->use
) == def
);
344 link_imm_use_to_list (linknode
, root
);
348 /* Set the value of a use pointed to by USE to VAL. */
350 set_ssa_use_from_ptr (use_operand_p use
, tree val
)
352 delink_imm_use (use
);
354 link_imm_use (use
, val
);
357 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
360 link_imm_use_stmt (ssa_use_operand_t
*linknode
, tree def
, tree stmt
)
363 link_imm_use (linknode
, def
);
365 link_imm_use (linknode
, NULL
);
366 linknode
->stmt
= stmt
;
369 /* Relink a new node in place of an old node in the list. */
371 relink_imm_use (ssa_use_operand_t
*node
, ssa_use_operand_t
*old
)
373 /* The node one had better be in the same list. */
374 gcc_assert (*(old
->use
) == *(node
->use
));
375 node
->prev
= old
->prev
;
376 node
->next
= old
->next
;
379 old
->prev
->next
= node
;
380 old
->next
->prev
= node
;
381 /* Remove the old node from the list. */
386 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
389 relink_imm_use_stmt (ssa_use_operand_t
*linknode
, ssa_use_operand_t
*old
, tree stmt
)
392 relink_imm_use (linknode
, old
);
394 link_imm_use (linknode
, NULL
);
395 linknode
->stmt
= stmt
;
399 /* Return true is IMM has reached the end of the immediate use list. */
401 end_readonly_imm_use_p (imm_use_iterator
*imm
)
403 return (imm
->imm_use
== imm
->end_p
);
406 /* Initialize iterator IMM to process the list for VAR. */
407 static inline use_operand_p
408 first_readonly_imm_use (imm_use_iterator
*imm
, tree var
)
410 gcc_assert (TREE_CODE (var
) == SSA_NAME
);
412 imm
->end_p
= &(SSA_NAME_IMM_USE_NODE (var
));
413 imm
->imm_use
= imm
->end_p
->next
;
414 #ifdef ENABLE_CHECKING
415 imm
->iter_node
.next
= imm
->imm_use
->next
;
417 if (end_readonly_imm_use_p (imm
))
418 return NULL_USE_OPERAND_P
;
422 /* Bump IMM to the next use in the list. */
423 static inline use_operand_p
424 next_readonly_imm_use (imm_use_iterator
*imm
)
426 use_operand_p old
= imm
->imm_use
;
428 #ifdef ENABLE_CHECKING
429 /* If this assertion fails, it indicates the 'next' pointer has changed
430 since we the last bump. This indicates that the list is being modified
431 via stmt changes, or SET_USE, or somesuch thing, and you need to be
432 using the SAFE version of the iterator. */
433 gcc_assert (imm
->iter_node
.next
== old
->next
);
434 imm
->iter_node
.next
= old
->next
->next
;
437 imm
->imm_use
= old
->next
;
438 if (end_readonly_imm_use_p (imm
))
443 /* Return true if VAR has no uses. */
445 has_zero_uses (tree var
)
447 ssa_use_operand_t
*ptr
;
448 ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
449 /* A single use means there is no items in the list. */
450 return (ptr
== ptr
->next
);
453 /* Return true if VAR has a single use. */
455 has_single_use (tree var
)
457 ssa_use_operand_t
*ptr
;
458 ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
459 /* A single use means there is one item in the list. */
460 return (ptr
!= ptr
->next
&& ptr
== ptr
->next
->next
);
463 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
464 to the use pointer and stmt of occurrence. */
466 single_imm_use (tree var
, use_operand_p
*use_p
, tree
*stmt
)
468 ssa_use_operand_t
*ptr
;
470 ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
471 if (ptr
!= ptr
->next
&& ptr
== ptr
->next
->next
)
474 *stmt
= ptr
->next
->stmt
;
477 *use_p
= NULL_USE_OPERAND_P
;
482 /* Return the number of immediate uses of VAR. */
483 static inline unsigned int
484 num_imm_uses (tree var
)
486 ssa_use_operand_t
*ptr
, *start
;
489 start
= &(SSA_NAME_IMM_USE_NODE (var
));
491 for (ptr
= start
->next
; ptr
!= start
; ptr
= ptr
->next
)
498 /* Return the tree pointer to by USE. */
500 get_use_from_ptr (use_operand_p use
)
505 /* Return the tree pointer to by DEF. */
507 get_def_from_ptr (def_operand_p def
)
512 /* Return a def_operand_p pointer for the result of PHI. */
513 static inline def_operand_p
514 get_phi_result_ptr (tree phi
)
516 return &(PHI_RESULT_TREE (phi
));
519 /* Return a use_operand_p pointer for argument I of phinode PHI. */
520 static inline use_operand_p
521 get_phi_arg_def_ptr (tree phi
, int i
)
523 return &(PHI_ARG_IMM_USE_NODE (phi
,i
));
527 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
530 addresses_taken (tree stmt
)
532 stmt_ann_t ann
= stmt_ann (stmt
);
533 return ann
? ann
->addresses_taken
: NULL
;
536 /* Return the PHI nodes for basic block BB, or NULL if there are no
539 phi_nodes (basic_block bb
)
541 return bb
->phi_nodes
;
544 /* Set list of phi nodes of a basic block BB to L. */
547 set_phi_nodes (basic_block bb
, tree l
)
552 for (phi
= l
; phi
; phi
= PHI_CHAIN (phi
))
553 set_bb_for_stmt (phi
, bb
);
556 /* Return the phi argument which contains the specified use. */
559 phi_arg_index_from_use (use_operand_p use
)
561 struct phi_arg_d
*element
, *root
;
565 /* Since the use is the first thing in a PHI argument element, we can
566 calculate its index based on casting it to an argument, and performing
567 pointer arithmetic. */
569 phi
= USE_STMT (use
);
570 gcc_assert (TREE_CODE (phi
) == PHI_NODE
);
572 element
= (struct phi_arg_d
*)use
;
573 root
= &(PHI_ARG_ELT (phi
, 0));
574 index
= element
- root
;
576 #ifdef ENABLE_CHECKING
577 /* Make sure the calculation doesn't have any leftover bytes. If it does,
578 then imm_use is likely not the first element in phi_arg_d. */
580 (((char *)element
- (char *)root
) % sizeof (struct phi_arg_d
)) == 0);
581 gcc_assert (index
>= 0 && index
< PHI_ARG_CAPACITY (phi
));
587 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
590 set_is_used (tree var
)
592 var_ann_t ann
= get_var_ann (var
);
597 /* ----------------------------------------------------------------------- */
599 /* Return true if T is an executable statement. */
601 is_exec_stmt (tree t
)
603 return (t
&& !IS_EMPTY_STMT (t
) && t
!= error_mark_node
);
607 /* Return true if this stmt can be the target of a control transfer stmt such
610 is_label_stmt (tree t
)
613 switch (TREE_CODE (t
))
617 case CASE_LABEL_EXPR
:
625 /* PHI nodes should contain only ssa_names and invariants. A test
626 for ssa_name is definitely simpler; don't let invalid contents
627 slip in in the meantime. */
630 phi_ssa_name_p (tree t
)
632 if (TREE_CODE (t
) == SSA_NAME
)
634 #ifdef ENABLE_CHECKING
635 gcc_assert (is_gimple_min_invariant (t
));
640 /* ----------------------------------------------------------------------- */
642 /* Return a block_stmt_iterator that points to beginning of basic
644 static inline block_stmt_iterator
645 bsi_start (basic_block bb
)
647 block_stmt_iterator bsi
;
649 bsi
.tsi
= tsi_start (bb
->stmt_list
);
652 gcc_assert (bb
->index
< NUM_FIXED_BLOCKS
);
654 bsi
.tsi
.container
= NULL
;
660 /* Return a block statement iterator that points to the first non-label
661 statement in block BB. */
663 static inline block_stmt_iterator
664 bsi_after_labels (basic_block bb
)
666 block_stmt_iterator bsi
= bsi_start (bb
);
668 while (!bsi_end_p (bsi
) && TREE_CODE (bsi_stmt (bsi
)) == LABEL_EXPR
)
674 /* Return a block statement iterator that points to the end of basic
676 static inline block_stmt_iterator
677 bsi_last (basic_block bb
)
679 block_stmt_iterator bsi
;
681 bsi
.tsi
= tsi_last (bb
->stmt_list
);
684 gcc_assert (bb
->index
< NUM_FIXED_BLOCKS
);
686 bsi
.tsi
.container
= NULL
;
692 /* Return true if block statement iterator I has reached the end of
695 bsi_end_p (block_stmt_iterator i
)
697 return tsi_end_p (i
.tsi
);
700 /* Modify block statement iterator I so that it is at the next
701 statement in the basic block. */
703 bsi_next (block_stmt_iterator
*i
)
708 /* Modify block statement iterator I so that it is at the previous
709 statement in the basic block. */
711 bsi_prev (block_stmt_iterator
*i
)
716 /* Return the statement that block statement iterator I is currently
719 bsi_stmt (block_stmt_iterator i
)
721 return tsi_stmt (i
.tsi
);
724 /* Return a pointer to the statement that block statement iterator I
727 bsi_stmt_ptr (block_stmt_iterator i
)
729 return tsi_stmt_ptr (i
.tsi
);
732 /* Returns the loop of the statement STMT. */
734 static inline struct loop
*
735 loop_containing_stmt (tree stmt
)
737 basic_block bb
= bb_for_stmt (stmt
);
741 return bb
->loop_father
;
744 /* Return true if VAR is a clobbered by function calls. */
746 is_call_clobbered (tree var
)
749 return DECL_CALL_CLOBBERED (var
);
751 return bitmap_bit_p (call_clobbered_vars
, DECL_UID (var
));
754 /* Mark variable VAR as being clobbered by function calls. */
756 mark_call_clobbered (tree var
, unsigned int escape_type
)
758 var_ann (var
)->escape_mask
|= escape_type
;
760 DECL_CALL_CLOBBERED (var
) = true;
761 bitmap_set_bit (call_clobbered_vars
, DECL_UID (var
));
764 /* Clear the call-clobbered attribute from variable VAR. */
766 clear_call_clobbered (tree var
)
768 var_ann_t ann
= var_ann (var
);
769 ann
->escape_mask
= 0;
770 if (MTAG_P (var
) && TREE_CODE (var
) != STRUCT_FIELD_TAG
)
771 MTAG_GLOBAL (var
) = 0;
773 DECL_CALL_CLOBBERED (var
) = false;
774 bitmap_clear_bit (call_clobbered_vars
, DECL_UID (var
));
777 /* Mark variable VAR as being non-addressable. */
779 mark_non_addressable (tree var
)
782 DECL_CALL_CLOBBERED (var
) = false;
783 bitmap_clear_bit (call_clobbered_vars
, DECL_UID (var
));
784 TREE_ADDRESSABLE (var
) = 0;
787 /* Return the common annotation for T. Return NULL if the annotation
788 doesn't already exist. */
789 static inline tree_ann_common_t
790 tree_common_ann (tree t
)
792 return &t
->common
.ann
->common
;
795 /* Return a common annotation for T. Create the constant annotation if it
797 static inline tree_ann_common_t
798 get_tree_common_ann (tree t
)
800 tree_ann_common_t ann
= tree_common_ann (t
);
801 return (ann
) ? ann
: create_tree_common_ann (t
);
804 /* ----------------------------------------------------------------------- */
806 /* The following set of routines are used to iterator over various type of
809 /* Return true if PTR is finished iterating. */
811 op_iter_done (ssa_op_iter
*ptr
)
816 /* Get the next iterator use value for PTR. */
817 static inline use_operand_p
818 op_iter_next_use (ssa_op_iter
*ptr
)
821 #ifdef ENABLE_CHECKING
822 gcc_assert (ptr
->iter_type
== ssa_op_iter_use
);
826 use_p
= USE_OP_PTR (ptr
->uses
);
827 ptr
->uses
= ptr
->uses
->next
;
832 use_p
= VUSE_OP_PTR (ptr
->vuses
);
833 ptr
->vuses
= ptr
->vuses
->next
;
838 use_p
= MAYDEF_OP_PTR (ptr
->mayuses
);
839 ptr
->mayuses
= ptr
->mayuses
->next
;
844 use_p
= MUSTDEF_KILL_PTR (ptr
->mustkills
);
845 ptr
->mustkills
= ptr
->mustkills
->next
;
848 if (ptr
->phi_i
< ptr
->num_phi
)
850 return PHI_ARG_DEF_PTR (ptr
->phi_stmt
, (ptr
->phi_i
)++);
853 return NULL_USE_OPERAND_P
;
856 /* Get the next iterator def value for PTR. */
857 static inline def_operand_p
858 op_iter_next_def (ssa_op_iter
*ptr
)
861 #ifdef ENABLE_CHECKING
862 gcc_assert (ptr
->iter_type
== ssa_op_iter_def
);
866 def_p
= DEF_OP_PTR (ptr
->defs
);
867 ptr
->defs
= ptr
->defs
->next
;
872 def_p
= MUSTDEF_RESULT_PTR (ptr
->mustdefs
);
873 ptr
->mustdefs
= ptr
->mustdefs
->next
;
878 def_p
= MAYDEF_RESULT_PTR (ptr
->maydefs
);
879 ptr
->maydefs
= ptr
->maydefs
->next
;
883 return NULL_DEF_OPERAND_P
;
886 /* Get the next iterator tree value for PTR. */
888 op_iter_next_tree (ssa_op_iter
*ptr
)
891 #ifdef ENABLE_CHECKING
892 gcc_assert (ptr
->iter_type
== ssa_op_iter_tree
);
896 val
= USE_OP (ptr
->uses
);
897 ptr
->uses
= ptr
->uses
->next
;
902 val
= VUSE_OP (ptr
->vuses
);
903 ptr
->vuses
= ptr
->vuses
->next
;
908 val
= MAYDEF_OP (ptr
->mayuses
);
909 ptr
->mayuses
= ptr
->mayuses
->next
;
914 val
= MUSTDEF_KILL (ptr
->mustkills
);
915 ptr
->mustkills
= ptr
->mustkills
->next
;
920 val
= DEF_OP (ptr
->defs
);
921 ptr
->defs
= ptr
->defs
->next
;
926 val
= MUSTDEF_RESULT (ptr
->mustdefs
);
927 ptr
->mustdefs
= ptr
->mustdefs
->next
;
932 val
= MAYDEF_RESULT (ptr
->maydefs
);
933 ptr
->maydefs
= ptr
->maydefs
->next
;
943 /* This functions clears the iterator PTR, and marks it done. This is normally
944 used to prevent warnings in the compile about might be uninitialized
948 clear_and_done_ssa_iter (ssa_op_iter
*ptr
)
955 ptr
->mustdefs
= NULL
;
956 ptr
->mustkills
= NULL
;
957 ptr
->iter_type
= ssa_op_iter_none
;
960 ptr
->phi_stmt
= NULL_TREE
;
964 /* Initialize the iterator PTR to the virtual defs in STMT. */
966 op_iter_init (ssa_op_iter
*ptr
, tree stmt
, int flags
)
968 #ifdef ENABLE_CHECKING
969 gcc_assert (stmt_ann (stmt
));
972 ptr
->defs
= (flags
& SSA_OP_DEF
) ? DEF_OPS (stmt
) : NULL
;
973 ptr
->uses
= (flags
& SSA_OP_USE
) ? USE_OPS (stmt
) : NULL
;
974 ptr
->vuses
= (flags
& SSA_OP_VUSE
) ? VUSE_OPS (stmt
) : NULL
;
975 ptr
->maydefs
= (flags
& SSA_OP_VMAYDEF
) ? MAYDEF_OPS (stmt
) : NULL
;
976 ptr
->mayuses
= (flags
& SSA_OP_VMAYUSE
) ? MAYDEF_OPS (stmt
) : NULL
;
977 ptr
->mustdefs
= (flags
& SSA_OP_VMUSTDEF
) ? MUSTDEF_OPS (stmt
) : NULL
;
978 ptr
->mustkills
= (flags
& SSA_OP_VMUSTKILL
) ? MUSTDEF_OPS (stmt
) : NULL
;
983 ptr
->phi_stmt
= NULL_TREE
;
986 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
988 static inline use_operand_p
989 op_iter_init_use (ssa_op_iter
*ptr
, tree stmt
, int flags
)
991 gcc_assert ((flags
& SSA_OP_ALL_DEFS
) == 0);
992 op_iter_init (ptr
, stmt
, flags
);
993 ptr
->iter_type
= ssa_op_iter_use
;
994 return op_iter_next_use (ptr
);
997 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
999 static inline def_operand_p
1000 op_iter_init_def (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1002 gcc_assert ((flags
& (SSA_OP_ALL_USES
| SSA_OP_VIRTUAL_KILLS
)) == 0);
1003 op_iter_init (ptr
, stmt
, flags
);
1004 ptr
->iter_type
= ssa_op_iter_def
;
1005 return op_iter_next_def (ptr
);
1008 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1009 the first operand as a tree. */
1011 op_iter_init_tree (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1013 op_iter_init (ptr
, stmt
, flags
);
1014 ptr
->iter_type
= ssa_op_iter_tree
;
1015 return op_iter_next_tree (ptr
);
1018 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1021 op_iter_next_maymustdef (use_operand_p
*use
, def_operand_p
*def
,
1024 #ifdef ENABLE_CHECKING
1025 gcc_assert (ptr
->iter_type
== ssa_op_iter_maymustdef
);
1029 *def
= MAYDEF_RESULT_PTR (ptr
->mayuses
);
1030 *use
= MAYDEF_OP_PTR (ptr
->mayuses
);
1031 ptr
->mayuses
= ptr
->mayuses
->next
;
1037 *def
= MUSTDEF_RESULT_PTR (ptr
->mustkills
);
1038 *use
= MUSTDEF_KILL_PTR (ptr
->mustkills
);
1039 ptr
->mustkills
= ptr
->mustkills
->next
;
1043 *def
= NULL_DEF_OPERAND_P
;
1044 *use
= NULL_USE_OPERAND_P
;
1050 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1053 op_iter_init_maydef (ssa_op_iter
*ptr
, tree stmt
, use_operand_p
*use
,
1056 gcc_assert (TREE_CODE (stmt
) != PHI_NODE
);
1058 op_iter_init (ptr
, stmt
, SSA_OP_VMAYUSE
);
1059 ptr
->iter_type
= ssa_op_iter_maymustdef
;
1060 op_iter_next_maymustdef (use
, def
, ptr
);
1064 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1067 op_iter_init_mustdef (ssa_op_iter
*ptr
, tree stmt
, use_operand_p
*kill
,
1070 gcc_assert (TREE_CODE (stmt
) != PHI_NODE
);
1072 op_iter_init (ptr
, stmt
, SSA_OP_VMUSTKILL
);
1073 ptr
->iter_type
= ssa_op_iter_maymustdef
;
1074 op_iter_next_maymustdef (kill
, def
, ptr
);
1077 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1080 op_iter_init_must_and_may_def (ssa_op_iter
*ptr
, tree stmt
,
1081 use_operand_p
*kill
, def_operand_p
*def
)
1083 gcc_assert (TREE_CODE (stmt
) != PHI_NODE
);
1085 op_iter_init (ptr
, stmt
, SSA_OP_VMUSTKILL
|SSA_OP_VMAYUSE
);
1086 ptr
->iter_type
= ssa_op_iter_maymustdef
;
1087 op_iter_next_maymustdef (kill
, def
, ptr
);
1091 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1094 single_ssa_tree_operand (tree stmt
, int flags
)
1099 var
= op_iter_init_tree (&iter
, stmt
, flags
);
1100 if (op_iter_done (&iter
))
1102 op_iter_next_tree (&iter
);
1103 if (op_iter_done (&iter
))
1109 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1111 static inline use_operand_p
1112 single_ssa_use_operand (tree stmt
, int flags
)
1117 var
= op_iter_init_use (&iter
, stmt
, flags
);
1118 if (op_iter_done (&iter
))
1119 return NULL_USE_OPERAND_P
;
1120 op_iter_next_use (&iter
);
1121 if (op_iter_done (&iter
))
1123 return NULL_USE_OPERAND_P
;
1128 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1130 static inline def_operand_p
1131 single_ssa_def_operand (tree stmt
, int flags
)
1136 var
= op_iter_init_def (&iter
, stmt
, flags
);
1137 if (op_iter_done (&iter
))
1138 return NULL_DEF_OPERAND_P
;
1139 op_iter_next_def (&iter
);
1140 if (op_iter_done (&iter
))
1142 return NULL_DEF_OPERAND_P
;
1146 /* Return true if there are zero operands in STMT matching the type
1149 zero_ssa_operands (tree stmt
, int flags
)
1153 op_iter_init_tree (&iter
, stmt
, flags
);
1154 return op_iter_done (&iter
);
1158 /* Return the number of operands matching FLAGS in STMT. */
1160 num_ssa_operands (tree stmt
, int flags
)
1166 FOR_EACH_SSA_TREE_OPERAND (t
, stmt
, iter
, flags
)
1172 /* Delink all immediate_use information for STMT. */
1174 delink_stmt_imm_use (tree stmt
)
1177 use_operand_p use_p
;
1179 if (ssa_operands_active ())
1180 FOR_EACH_SSA_USE_OPERAND (use_p
, stmt
, iter
,
1181 (SSA_OP_ALL_USES
| SSA_OP_ALL_KILLS
))
1182 delink_imm_use (use_p
);
1186 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1187 in STMT2. TRUE is returned if they are the same. STMTs can be NULL. */
1189 compare_ssa_operands_equal (tree stmt1
, tree stmt2
, int flags
)
1191 ssa_op_iter iter1
, iter2
;
1192 tree op1
= NULL_TREE
;
1193 tree op2
= NULL_TREE
;
1199 look1
= stmt1
&& stmt_ann (stmt1
);
1200 look2
= stmt2
&& stmt_ann (stmt2
);
1204 op1
= op_iter_init_tree (&iter1
, stmt1
, flags
);
1206 return op_iter_done (&iter1
);
1209 clear_and_done_ssa_iter (&iter1
);
1213 op2
= op_iter_init_tree (&iter2
, stmt2
, flags
);
1215 return op_iter_done (&iter2
);
1218 clear_and_done_ssa_iter (&iter2
);
1220 while (!op_iter_done (&iter1
) && !op_iter_done (&iter2
))
1224 op1
= op_iter_next_tree (&iter1
);
1225 op2
= op_iter_next_tree (&iter2
);
1228 return (op_iter_done (&iter1
) && op_iter_done (&iter2
));
1232 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1233 Otherwise return NULL_DEF_OPERAND_P. */
1235 single_phi_def (tree stmt
, int flags
)
1237 tree def
= PHI_RESULT (stmt
);
1238 if ((flags
& SSA_OP_DEF
) && is_gimple_reg (def
))
1240 if ((flags
& SSA_OP_VIRTUAL_DEFS
) && !is_gimple_reg (def
))
1245 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
1246 be either SSA_OP_USES or SSA_OP_VIRTUAL_USES. */
1247 static inline use_operand_p
1248 op_iter_init_phiuse (ssa_op_iter
*ptr
, tree phi
, int flags
)
1250 tree phi_def
= PHI_RESULT (phi
);
1253 clear_and_done_ssa_iter (ptr
);
1256 gcc_assert ((flags
& (SSA_OP_USE
| SSA_OP_VIRTUAL_USES
)) != 0);
1258 comp
= (is_gimple_reg (phi_def
) ? SSA_OP_USE
: SSA_OP_VIRTUAL_USES
);
1260 /* If the PHI node doesn't the operand type we care about, we're done. */
1261 if ((flags
& comp
) == 0)
1264 return NULL_USE_OPERAND_P
;
1267 ptr
->phi_stmt
= phi
;
1268 ptr
->num_phi
= PHI_NUM_ARGS (phi
);
1269 ptr
->iter_type
= ssa_op_iter_use
;
1270 return op_iter_next_use (ptr
);
1274 /* Start an iterator for a PHI definition. */
1276 static inline def_operand_p
1277 op_iter_init_phidef (ssa_op_iter
*ptr
, tree phi
, int flags
)
1279 tree phi_def
= PHI_RESULT (phi
);
1282 clear_and_done_ssa_iter (ptr
);
1285 gcc_assert ((flags
& (SSA_OP_DEF
| SSA_OP_VIRTUAL_DEFS
)) != 0);
1287 comp
= (is_gimple_reg (phi_def
) ? SSA_OP_DEF
: SSA_OP_VIRTUAL_DEFS
);
1289 /* If the PHI node doesn't the operand type we care about, we're done. */
1290 if ((flags
& comp
) == 0)
1293 return NULL_USE_OPERAND_P
;
1296 ptr
->iter_type
= ssa_op_iter_def
;
1297 /* The first call to op_iter_next_def will terminate the iterator since
1298 all the fields are NULL. Simply return the result here as the first and
1299 therefore only result. */
1300 return PHI_RESULT_PTR (phi
);
1303 /* Return true is IMM has reached the end of the immediate use stmt list. */
1306 end_imm_use_stmt_p (imm_use_iterator
*imm
)
1308 return (imm
->imm_use
== imm
->end_p
);
1311 /* Finished the traverse of an immediate use stmt list IMM by removing the
1312 placeholder node from the list. */
1315 end_imm_use_stmt_traverse (imm_use_iterator
*imm
)
1317 delink_imm_use (&(imm
->iter_node
));
1320 /* Immediate use traversal of uses within a stmt require that all the
1321 uses on a stmt be sequentially listed. This routine is used to build up
1322 this sequential list by adding USE_P to the end of the current list
1323 currently delimited by HEAD and LAST_P. The new LAST_P value is
1326 static inline use_operand_p
1327 move_use_after_head (use_operand_p use_p
, use_operand_p head
,
1328 use_operand_p last_p
)
1330 gcc_assert (USE_FROM_PTR (use_p
) == USE_FROM_PTR (head
));
1331 /* Skip head when we find it. */
1334 /* If use_p is already linked in after last_p, continue. */
1335 if (last_p
->next
== use_p
)
1339 /* Delink from current location, and link in at last_p. */
1340 delink_imm_use (use_p
);
1341 link_imm_use_to_list (use_p
, last_p
);
1349 /* This routine will relink all uses with the same stmt as HEAD into the list
1350 immediately following HEAD for iterator IMM. */
1353 link_use_stmts_after (use_operand_p head
, imm_use_iterator
*imm
)
1355 use_operand_p use_p
;
1356 use_operand_p last_p
= head
;
1357 tree head_stmt
= USE_STMT (head
);
1358 tree use
= USE_FROM_PTR (head
);
1359 ssa_op_iter op_iter
;
1362 /* Only look at virtual or real uses, depending on the type of HEAD. */
1363 flag
= (is_gimple_reg (use
) ? SSA_OP_USE
: SSA_OP_VIRTUAL_USES
);
1365 if (TREE_CODE (head_stmt
) == PHI_NODE
)
1367 FOR_EACH_PHI_ARG (use_p
, head_stmt
, op_iter
, flag
)
1368 if (USE_FROM_PTR (use_p
) == use
)
1369 last_p
= move_use_after_head (use_p
, head
, last_p
);
1373 FOR_EACH_SSA_USE_OPERAND (use_p
, head_stmt
, op_iter
, flag
)
1374 if (USE_FROM_PTR (use_p
) == use
)
1375 last_p
= move_use_after_head (use_p
, head
, last_p
);
1377 /* LInk iter node in after last_p. */
1378 if (imm
->iter_node
.prev
!= NULL
)
1379 delink_imm_use (&imm
->iter_node
);
1380 link_imm_use_to_list (&(imm
->iter_node
), last_p
);
1383 /* Initialize IMM to traverse over uses of VAR. Return the first statement. */
1385 first_imm_use_stmt (imm_use_iterator
*imm
, tree var
)
1387 gcc_assert (TREE_CODE (var
) == SSA_NAME
);
1389 imm
->end_p
= &(SSA_NAME_IMM_USE_NODE (var
));
1390 imm
->imm_use
= imm
->end_p
->next
;
1391 imm
->next_imm_name
= NULL_USE_OPERAND_P
;
1393 /* iter_node is used as a marker within the immediate use list to indicate
1394 where the end of the current stmt's uses are. Initialize it to NULL
1395 stmt and use, which indicates a marker node. */
1396 imm
->iter_node
.prev
= NULL_USE_OPERAND_P
;
1397 imm
->iter_node
.next
= NULL_USE_OPERAND_P
;
1398 imm
->iter_node
.stmt
= NULL_TREE
;
1399 imm
->iter_node
.use
= NULL_USE_OPERAND_P
;
1401 if (end_imm_use_stmt_p (imm
))
1404 link_use_stmts_after (imm
->imm_use
, imm
);
1406 return USE_STMT (imm
->imm_use
);
1409 /* Bump IMM to the next stmt which has a use of var. */
1412 next_imm_use_stmt (imm_use_iterator
*imm
)
1414 imm
->imm_use
= imm
->iter_node
.next
;
1415 if (end_imm_use_stmt_p (imm
))
1417 if (imm
->iter_node
.prev
!= NULL
)
1418 delink_imm_use (&imm
->iter_node
);
1422 link_use_stmts_after (imm
->imm_use
, imm
);
1423 return USE_STMT (imm
->imm_use
);
1427 /* This routine will return the first use on the stmt IMM currently refers
1430 static inline use_operand_p
1431 first_imm_use_on_stmt (imm_use_iterator
*imm
)
1433 imm
->next_imm_name
= imm
->imm_use
->next
;
1434 return imm
->imm_use
;
1437 /* Return TRUE if the last use on the stmt IMM refers to has been visited. */
1440 end_imm_use_on_stmt_p (imm_use_iterator
*imm
)
1442 return (imm
->imm_use
== &(imm
->iter_node
));
1445 /* Bump to the next use on the stmt IMM refers to, return NULL if done. */
1447 static inline use_operand_p
1448 next_imm_use_on_stmt (imm_use_iterator
*imm
)
1450 imm
->imm_use
= imm
->next_imm_name
;
1451 if (end_imm_use_on_stmt_p (imm
))
1452 return NULL_USE_OPERAND_P
;
1455 imm
->next_imm_name
= imm
->imm_use
->next
;
1456 return imm
->imm_use
;
1460 /* Return true if VAR cannot be modified by the program. */
1463 unmodifiable_var_p (tree var
)
1465 if (TREE_CODE (var
) == SSA_NAME
)
1466 var
= SSA_NAME_VAR (var
);
1469 return TREE_READONLY (var
) && (TREE_STATIC (var
) || MTAG_GLOBAL (var
));
1471 return TREE_READONLY (var
) && (TREE_STATIC (var
) || DECL_EXTERNAL (var
));
1474 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it. */
1477 array_ref_contains_indirect_ref (tree ref
)
1479 gcc_assert (TREE_CODE (ref
) == ARRAY_REF
);
1482 ref
= TREE_OPERAND (ref
, 0);
1483 } while (handled_component_p (ref
));
1485 return TREE_CODE (ref
) == INDIRECT_REF
;
1488 /* Return true if REF, a handled component reference, has an ARRAY_REF
1492 ref_contains_array_ref (tree ref
)
1494 gcc_assert (handled_component_p (ref
));
1497 if (TREE_CODE (ref
) == ARRAY_REF
)
1499 ref
= TREE_OPERAND (ref
, 0);
1500 } while (handled_component_p (ref
));
1505 /* Given a variable VAR, lookup and return a pointer to the list of
1506 subvariables for it. */
1508 static inline subvar_t
*
1509 lookup_subvars_for_var (tree var
)
1511 var_ann_t ann
= var_ann (var
);
1513 return &ann
->subvars
;
1516 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1517 NULL, if there are no subvariables. */
1519 static inline subvar_t
1520 get_subvars_for_var (tree var
)
1524 gcc_assert (SSA_VAR_P (var
));
1526 if (TREE_CODE (var
) == SSA_NAME
)
1527 subvars
= *(lookup_subvars_for_var (SSA_NAME_VAR (var
)));
1529 subvars
= *(lookup_subvars_for_var (var
));
1533 /* Return the subvariable of VAR at offset OFFSET. */
1536 get_subvar_at (tree var
, unsigned HOST_WIDE_INT offset
)
1540 for (sv
= get_subvars_for_var (var
); sv
; sv
= sv
->next
)
1541 if (SFT_OFFSET (sv
->var
) == offset
)
1547 /* Return true if V is a tree that we can have subvars for.
1548 Normally, this is any aggregate type. Also complex
1549 types which are not gimple registers can have subvars. */
1552 var_can_have_subvars (tree v
)
1554 /* Volatile variables should never have subvars. */
1555 if (TREE_THIS_VOLATILE (v
))
1558 /* Non decls or memory tags can never have subvars. */
1559 if (!DECL_P (v
) || MTAG_P (v
))
1562 /* Aggregates can have subvars. */
1563 if (AGGREGATE_TYPE_P (TREE_TYPE (v
)))
1566 /* Complex types variables which are not also a gimple register can
1568 if (TREE_CODE (TREE_TYPE (v
)) == COMPLEX_TYPE
1569 && !DECL_COMPLEX_GIMPLE_REG_P (v
))
1576 /* Return true if OFFSET and SIZE define a range that overlaps with some
1577 portion of the range of SV, a subvar. If there was an exact overlap,
1578 *EXACT will be set to true upon return. */
1581 overlap_subvar (unsigned HOST_WIDE_INT offset
, unsigned HOST_WIDE_INT size
,
1582 tree sv
, bool *exact
)
1584 /* There are three possible cases of overlap.
1585 1. We can have an exact overlap, like so:
1586 |offset, offset + size |
1587 |sv->offset, sv->offset + sv->size |
1589 2. We can have offset starting after sv->offset, like so:
1591 |offset, offset + size |
1592 |sv->offset, sv->offset + sv->size |
1594 3. We can have offset starting before sv->offset, like so:
1596 |offset, offset + size |
1597 |sv->offset, sv->offset + sv->size|
1602 if (offset
== SFT_OFFSET (sv
) && size
== SFT_SIZE (sv
))
1608 else if (offset
>= SFT_OFFSET (sv
)
1609 && offset
< (SFT_OFFSET (sv
) + SFT_SIZE (sv
)))
1613 else if (offset
< SFT_OFFSET (sv
)
1614 && (size
> SFT_OFFSET (sv
) - offset
))
1622 #endif /* _TREE_FLOW_INLINE_H */