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 /* Return true when gimple SSA form was built.
29 gimple_in_ssa_p is queried by gimplifier in various early stages before SSA
30 infrastructure is initialized. Check for presence of the datastructures
33 gimple_in_ssa_p (struct function
*fun
)
35 return fun
&& fun
->gimple_df
&& fun
->gimple_df
->in_ssa_p
;
38 /* 'true' after aliases have been computed (see compute_may_aliases). */
40 gimple_aliases_computed_p (struct function
*fun
)
42 gcc_assert (fun
&& fun
->gimple_df
);
43 return fun
->gimple_df
->aliases_computed_p
;
46 /* Addressable variables in the function. If bit I is set, then
47 REFERENCED_VARS (I) has had its address taken. Note that
48 CALL_CLOBBERED_VARS and ADDRESSABLE_VARS are not related. An
49 addressable variable is not necessarily call-clobbered (e.g., a
50 local addressable whose address does not escape) and not all
51 call-clobbered variables are addressable (e.g., a local static
54 gimple_addressable_vars (struct function
*fun
)
56 gcc_assert (fun
&& fun
->gimple_df
);
57 return fun
->gimple_df
->addressable_vars
;
60 /* Call clobbered variables in the function. If bit I is set, then
61 REFERENCED_VARS (I) is call-clobbered. */
63 gimple_call_clobbered_vars (struct function
*fun
)
65 gcc_assert (fun
&& fun
->gimple_df
);
66 return fun
->gimple_df
->call_clobbered_vars
;
69 /* Array of all variables referenced in the function. */
71 gimple_referenced_vars (struct function
*fun
)
75 return fun
->gimple_df
->referenced_vars
;
78 /* Artificial variable used to model the effects of function calls. */
80 gimple_global_var (struct function
*fun
)
82 gcc_assert (fun
&& fun
->gimple_df
);
83 return fun
->gimple_df
->global_var
;
86 /* Artificial variable used to model the effects of nonlocal
89 gimple_nonlocal_all (struct function
*fun
)
91 gcc_assert (fun
&& fun
->gimple_df
);
92 return fun
->gimple_df
->nonlocal_all
;
94 /* Initialize the hashtable iterator HTI to point to hashtable TABLE */
97 first_htab_element (htab_iterator
*hti
, htab_t table
)
100 hti
->slot
= table
->entries
;
101 hti
->limit
= hti
->slot
+ htab_size (table
);
104 PTR x
= *(hti
->slot
);
105 if (x
!= HTAB_EMPTY_ENTRY
&& x
!= HTAB_DELETED_ENTRY
)
107 } while (++(hti
->slot
) < hti
->limit
);
109 if (hti
->slot
< hti
->limit
)
114 /* Return current non-empty/deleted slot of the hashtable pointed to by HTI,
115 or NULL if we have reached the end. */
118 end_htab_p (htab_iterator
*hti
)
120 if (hti
->slot
>= hti
->limit
)
125 /* Advance the hashtable iterator pointed to by HTI to the next element of the
129 next_htab_element (htab_iterator
*hti
)
131 while (++(hti
->slot
) < hti
->limit
)
133 PTR x
= *(hti
->slot
);
134 if (x
!= HTAB_EMPTY_ENTRY
&& x
!= HTAB_DELETED_ENTRY
)
140 /* Initialize ITER to point to the first referenced variable in the
141 referenced_vars hashtable, and return that variable. */
144 first_referenced_var (referenced_var_iterator
*iter
)
146 struct int_tree_map
*itm
;
147 itm
= (struct int_tree_map
*) first_htab_element (&iter
->hti
,
148 gimple_referenced_vars
155 /* Return true if we have hit the end of the referenced variables ITER is
156 iterating through. */
159 end_referenced_vars_p (referenced_var_iterator
*iter
)
161 return end_htab_p (&iter
->hti
);
164 /* Make ITER point to the next referenced_var in the referenced_var hashtable,
165 and return that variable. */
168 next_referenced_var (referenced_var_iterator
*iter
)
170 struct int_tree_map
*itm
;
171 itm
= (struct int_tree_map
*) next_htab_element (&iter
->hti
);
177 /* Fill up VEC with the variables in the referenced vars hashtable. */
180 fill_referenced_var_vec (VEC (tree
, heap
) **vec
)
182 referenced_var_iterator rvi
;
185 FOR_EACH_REFERENCED_VAR (var
, rvi
)
186 VEC_safe_push (tree
, heap
, *vec
, var
);
189 /* Return the variable annotation for T, which must be a _DECL node.
190 Return NULL if the variable annotation doesn't already exist. */
191 static inline var_ann_t
195 gcc_assert (DECL_P (t
));
196 gcc_assert (TREE_CODE (t
) != FUNCTION_DECL
);
197 gcc_assert (!t
->common
.ann
|| t
->common
.ann
->common
.type
== VAR_ANN
);
199 return (var_ann_t
) t
->common
.ann
;
202 /* Return the variable annotation for T, which must be a _DECL node.
203 Create the variable annotation if it doesn't exist. */
204 static inline var_ann_t
205 get_var_ann (tree var
)
207 var_ann_t ann
= var_ann (var
);
208 return (ann
) ? ann
: create_var_ann (var
);
211 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
212 Return NULL if the function annotation doesn't already exist. */
213 static inline function_ann_t
214 function_ann (tree t
)
217 gcc_assert (TREE_CODE (t
) == FUNCTION_DECL
);
218 gcc_assert (!t
->common
.ann
|| t
->common
.ann
->common
.type
== FUNCTION_ANN
);
220 return (function_ann_t
) t
->common
.ann
;
223 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
224 Create the function annotation if it doesn't exist. */
225 static inline function_ann_t
226 get_function_ann (tree var
)
228 function_ann_t ann
= function_ann (var
);
229 gcc_assert (!var
->common
.ann
|| var
->common
.ann
->common
.type
== FUNCTION_ANN
);
230 return (ann
) ? ann
: create_function_ann (var
);
233 /* Return true if T has a statement annotation attached to it. */
236 has_stmt_ann (tree t
)
238 #ifdef ENABLE_CHECKING
239 gcc_assert (is_gimple_stmt (t
));
241 return t
->common
.ann
&& t
->common
.ann
->common
.type
== STMT_ANN
;
244 /* Return the statement annotation for T, which must be a statement
245 node. Return NULL if the statement annotation doesn't exist. */
246 static inline stmt_ann_t
249 #ifdef ENABLE_CHECKING
250 gcc_assert (is_gimple_stmt (t
));
252 gcc_assert (!t
->common
.ann
|| t
->common
.ann
->common
.type
== STMT_ANN
);
253 return (stmt_ann_t
) t
->common
.ann
;
256 /* Return the statement annotation for T, which must be a statement
257 node. Create the statement annotation if it doesn't exist. */
258 static inline stmt_ann_t
259 get_stmt_ann (tree stmt
)
261 stmt_ann_t ann
= stmt_ann (stmt
);
262 return (ann
) ? ann
: create_stmt_ann (stmt
);
265 /* Return the annotation type for annotation ANN. */
266 static inline enum tree_ann_type
267 ann_type (tree_ann_t ann
)
269 return ann
->common
.type
;
272 /* Return the basic block for statement T. */
273 static inline basic_block
278 if (TREE_CODE (t
) == PHI_NODE
)
282 return ann
? ann
->bb
: NULL
;
285 /* Return the may_aliases varray for variable VAR, or NULL if it has
287 static inline VEC(tree
, gc
) *
288 may_aliases (tree var
)
290 var_ann_t ann
= var_ann (var
);
291 return ann
? ann
->may_aliases
: NULL
;
294 /* Return the line number for EXPR, or return -1 if we have no line
295 number information for it. */
297 get_lineno (tree expr
)
299 if (expr
== NULL_TREE
)
302 if (TREE_CODE (expr
) == COMPOUND_EXPR
)
303 expr
= TREE_OPERAND (expr
, 0);
305 if (! EXPR_HAS_LOCATION (expr
))
308 return EXPR_LINENO (expr
);
311 /* Return the file name for EXPR, or return "???" if we have no
312 filename information. */
313 static inline const char *
314 get_filename (tree expr
)
316 const char *filename
;
317 if (expr
== NULL_TREE
)
320 if (TREE_CODE (expr
) == COMPOUND_EXPR
)
321 expr
= TREE_OPERAND (expr
, 0);
323 if (EXPR_HAS_LOCATION (expr
) && (filename
= EXPR_FILENAME (expr
)))
329 /* Return true if T is a noreturn call. */
331 noreturn_call_p (tree t
)
333 tree call
= get_call_expr_in (t
);
334 return call
!= 0 && (call_expr_flags (call
) & ECF_NORETURN
) != 0;
337 /* Mark statement T as modified. */
339 mark_stmt_modified (tree t
)
342 if (TREE_CODE (t
) == PHI_NODE
)
347 ann
= create_stmt_ann (t
);
348 else if (noreturn_call_p (t
) && cfun
->gimple_df
)
349 VEC_safe_push (tree
, gc
, MODIFIED_NORETURN_CALLS (cfun
), t
);
353 /* Mark statement T as modified, and update it. */
357 if (TREE_CODE (t
) == PHI_NODE
)
359 mark_stmt_modified (t
);
360 update_stmt_operands (t
);
364 update_stmt_if_modified (tree t
)
366 if (stmt_modified_p (t
))
367 update_stmt_operands (t
);
370 /* Return true if T is marked as modified, false otherwise. */
372 stmt_modified_p (tree t
)
374 stmt_ann_t ann
= stmt_ann (t
);
376 /* Note that if the statement doesn't yet have an annotation, we consider it
377 modified. This will force the next call to update_stmt_operands to scan
379 return ann
? ann
->modified
: true;
382 /* Delink an immediate_uses node from its chain. */
384 delink_imm_use (ssa_use_operand_t
*linknode
)
386 /* Return if this node is not in a list. */
387 if (linknode
->prev
== NULL
)
390 linknode
->prev
->next
= linknode
->next
;
391 linknode
->next
->prev
= linknode
->prev
;
392 linknode
->prev
= NULL
;
393 linknode
->next
= NULL
;
396 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
398 link_imm_use_to_list (ssa_use_operand_t
*linknode
, ssa_use_operand_t
*list
)
400 /* Link the new node at the head of the list. If we are in the process of
401 traversing the list, we won't visit any new nodes added to it. */
402 linknode
->prev
= list
;
403 linknode
->next
= list
->next
;
404 list
->next
->prev
= linknode
;
405 list
->next
= linknode
;
408 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
410 link_imm_use (ssa_use_operand_t
*linknode
, tree def
)
412 ssa_use_operand_t
*root
;
414 if (!def
|| TREE_CODE (def
) != SSA_NAME
)
415 linknode
->prev
= NULL
;
418 root
= &(SSA_NAME_IMM_USE_NODE (def
));
419 #ifdef ENABLE_CHECKING
421 gcc_assert (*(linknode
->use
) == def
);
423 link_imm_use_to_list (linknode
, root
);
427 /* Set the value of a use pointed to by USE to VAL. */
429 set_ssa_use_from_ptr (use_operand_p use
, tree val
)
431 delink_imm_use (use
);
433 link_imm_use (use
, val
);
436 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
439 link_imm_use_stmt (ssa_use_operand_t
*linknode
, tree def
, tree stmt
)
442 link_imm_use (linknode
, def
);
444 link_imm_use (linknode
, NULL
);
445 linknode
->stmt
= stmt
;
448 /* Relink a new node in place of an old node in the list. */
450 relink_imm_use (ssa_use_operand_t
*node
, ssa_use_operand_t
*old
)
452 /* The node one had better be in the same list. */
453 gcc_assert (*(old
->use
) == *(node
->use
));
454 node
->prev
= old
->prev
;
455 node
->next
= old
->next
;
458 old
->prev
->next
= node
;
459 old
->next
->prev
= node
;
460 /* Remove the old node from the list. */
465 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
468 relink_imm_use_stmt (ssa_use_operand_t
*linknode
, ssa_use_operand_t
*old
, tree stmt
)
471 relink_imm_use (linknode
, old
);
473 link_imm_use (linknode
, NULL
);
474 linknode
->stmt
= stmt
;
478 /* Return true is IMM has reached the end of the immediate use list. */
480 end_readonly_imm_use_p (imm_use_iterator
*imm
)
482 return (imm
->imm_use
== imm
->end_p
);
485 /* Initialize iterator IMM to process the list for VAR. */
486 static inline use_operand_p
487 first_readonly_imm_use (imm_use_iterator
*imm
, tree var
)
489 gcc_assert (TREE_CODE (var
) == SSA_NAME
);
491 imm
->end_p
= &(SSA_NAME_IMM_USE_NODE (var
));
492 imm
->imm_use
= imm
->end_p
->next
;
493 #ifdef ENABLE_CHECKING
494 imm
->iter_node
.next
= imm
->imm_use
->next
;
496 if (end_readonly_imm_use_p (imm
))
497 return NULL_USE_OPERAND_P
;
501 /* Bump IMM to the next use in the list. */
502 static inline use_operand_p
503 next_readonly_imm_use (imm_use_iterator
*imm
)
505 use_operand_p old
= imm
->imm_use
;
507 #ifdef ENABLE_CHECKING
508 /* If this assertion fails, it indicates the 'next' pointer has changed
509 since we the last bump. This indicates that the list is being modified
510 via stmt changes, or SET_USE, or somesuch thing, and you need to be
511 using the SAFE version of the iterator. */
512 gcc_assert (imm
->iter_node
.next
== old
->next
);
513 imm
->iter_node
.next
= old
->next
->next
;
516 imm
->imm_use
= old
->next
;
517 if (end_readonly_imm_use_p (imm
))
522 /* Return true if VAR has no uses. */
524 has_zero_uses (tree var
)
526 ssa_use_operand_t
*ptr
;
527 ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
528 /* A single use means there is no items in the list. */
529 return (ptr
== ptr
->next
);
532 /* Return true if VAR has a single use. */
534 has_single_use (tree var
)
536 ssa_use_operand_t
*ptr
;
537 ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
538 /* A single use means there is one item in the list. */
539 return (ptr
!= ptr
->next
&& ptr
== ptr
->next
->next
);
542 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
543 to the use pointer and stmt of occurrence. */
545 single_imm_use (tree var
, use_operand_p
*use_p
, tree
*stmt
)
547 ssa_use_operand_t
*ptr
;
549 ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
550 if (ptr
!= ptr
->next
&& ptr
== ptr
->next
->next
)
553 *stmt
= ptr
->next
->stmt
;
556 *use_p
= NULL_USE_OPERAND_P
;
561 /* Return the number of immediate uses of VAR. */
562 static inline unsigned int
563 num_imm_uses (tree var
)
565 ssa_use_operand_t
*ptr
, *start
;
568 start
= &(SSA_NAME_IMM_USE_NODE (var
));
570 for (ptr
= start
->next
; ptr
!= start
; ptr
= ptr
->next
)
577 /* Return the tree pointer to by USE. */
579 get_use_from_ptr (use_operand_p use
)
584 /* Return the tree pointer to by DEF. */
586 get_def_from_ptr (def_operand_p def
)
591 /* Return a def_operand_p pointer for the result of PHI. */
592 static inline def_operand_p
593 get_phi_result_ptr (tree phi
)
595 return &(PHI_RESULT_TREE (phi
));
598 /* Return a use_operand_p pointer for argument I of phinode PHI. */
599 static inline use_operand_p
600 get_phi_arg_def_ptr (tree phi
, int i
)
602 return &(PHI_ARG_IMM_USE_NODE (phi
,i
));
606 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
609 addresses_taken (tree stmt
)
611 stmt_ann_t ann
= stmt_ann (stmt
);
612 return ann
? ann
->addresses_taken
: NULL
;
615 /* Return the PHI nodes for basic block BB, or NULL if there are no
618 phi_nodes (basic_block bb
)
620 return bb
->phi_nodes
;
623 /* Set list of phi nodes of a basic block BB to L. */
626 set_phi_nodes (basic_block bb
, tree l
)
631 for (phi
= l
; phi
; phi
= PHI_CHAIN (phi
))
632 set_bb_for_stmt (phi
, bb
);
635 /* Return the phi argument which contains the specified use. */
638 phi_arg_index_from_use (use_operand_p use
)
640 struct phi_arg_d
*element
, *root
;
644 /* Since the use is the first thing in a PHI argument element, we can
645 calculate its index based on casting it to an argument, and performing
646 pointer arithmetic. */
648 phi
= USE_STMT (use
);
649 gcc_assert (TREE_CODE (phi
) == PHI_NODE
);
651 element
= (struct phi_arg_d
*)use
;
652 root
= &(PHI_ARG_ELT (phi
, 0));
653 index
= element
- root
;
655 #ifdef ENABLE_CHECKING
656 /* Make sure the calculation doesn't have any leftover bytes. If it does,
657 then imm_use is likely not the first element in phi_arg_d. */
659 (((char *)element
- (char *)root
) % sizeof (struct phi_arg_d
)) == 0);
660 gcc_assert (index
>= 0 && index
< PHI_ARG_CAPACITY (phi
));
666 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
669 set_is_used (tree var
)
671 var_ann_t ann
= get_var_ann (var
);
676 /* ----------------------------------------------------------------------- */
678 /* Return true if T is an executable statement. */
680 is_exec_stmt (tree t
)
682 return (t
&& !IS_EMPTY_STMT (t
) && t
!= error_mark_node
);
686 /* Return true if this stmt can be the target of a control transfer stmt such
689 is_label_stmt (tree t
)
692 switch (TREE_CODE (t
))
696 case CASE_LABEL_EXPR
:
704 /* PHI nodes should contain only ssa_names and invariants. A test
705 for ssa_name is definitely simpler; don't let invalid contents
706 slip in in the meantime. */
709 phi_ssa_name_p (tree t
)
711 if (TREE_CODE (t
) == SSA_NAME
)
713 #ifdef ENABLE_CHECKING
714 gcc_assert (is_gimple_min_invariant (t
));
719 /* ----------------------------------------------------------------------- */
721 /* Return a block_stmt_iterator that points to beginning of basic
723 static inline block_stmt_iterator
724 bsi_start (basic_block bb
)
726 block_stmt_iterator bsi
;
728 bsi
.tsi
= tsi_start (bb
->stmt_list
);
731 gcc_assert (bb
->index
< NUM_FIXED_BLOCKS
);
733 bsi
.tsi
.container
= NULL
;
739 /* Return a block statement iterator that points to the first non-label
740 statement in block BB. */
742 static inline block_stmt_iterator
743 bsi_after_labels (basic_block bb
)
745 block_stmt_iterator bsi
= bsi_start (bb
);
747 while (!bsi_end_p (bsi
) && TREE_CODE (bsi_stmt (bsi
)) == LABEL_EXPR
)
753 /* Return a block statement iterator that points to the end of basic
755 static inline block_stmt_iterator
756 bsi_last (basic_block bb
)
758 block_stmt_iterator bsi
;
760 bsi
.tsi
= tsi_last (bb
->stmt_list
);
763 gcc_assert (bb
->index
< NUM_FIXED_BLOCKS
);
765 bsi
.tsi
.container
= NULL
;
771 /* Return true if block statement iterator I has reached the end of
774 bsi_end_p (block_stmt_iterator i
)
776 return tsi_end_p (i
.tsi
);
779 /* Modify block statement iterator I so that it is at the next
780 statement in the basic block. */
782 bsi_next (block_stmt_iterator
*i
)
787 /* Modify block statement iterator I so that it is at the previous
788 statement in the basic block. */
790 bsi_prev (block_stmt_iterator
*i
)
795 /* Return the statement that block statement iterator I is currently
798 bsi_stmt (block_stmt_iterator i
)
800 return tsi_stmt (i
.tsi
);
803 /* Return a pointer to the statement that block statement iterator I
806 bsi_stmt_ptr (block_stmt_iterator i
)
808 return tsi_stmt_ptr (i
.tsi
);
811 /* Returns the loop of the statement STMT. */
813 static inline struct loop
*
814 loop_containing_stmt (tree stmt
)
816 basic_block bb
= bb_for_stmt (stmt
);
820 return bb
->loop_father
;
823 /* Return true if VAR is a clobbered by function calls. */
825 is_call_clobbered (tree var
)
828 return DECL_CALL_CLOBBERED (var
);
830 return bitmap_bit_p (gimple_call_clobbered_vars (cfun
), DECL_UID (var
));
833 /* Mark variable VAR as being clobbered by function calls. */
835 mark_call_clobbered (tree var
, unsigned int escape_type
)
837 var_ann (var
)->escape_mask
|= escape_type
;
839 DECL_CALL_CLOBBERED (var
) = true;
840 bitmap_set_bit (gimple_call_clobbered_vars (cfun
), DECL_UID (var
));
843 /* Clear the call-clobbered attribute from variable VAR. */
845 clear_call_clobbered (tree var
)
847 var_ann_t ann
= var_ann (var
);
848 ann
->escape_mask
= 0;
849 if (MTAG_P (var
) && TREE_CODE (var
) != STRUCT_FIELD_TAG
)
850 MTAG_GLOBAL (var
) = 0;
852 DECL_CALL_CLOBBERED (var
) = false;
853 bitmap_clear_bit (gimple_call_clobbered_vars (cfun
), DECL_UID (var
));
856 /* Mark variable VAR as being non-addressable. */
858 mark_non_addressable (tree var
)
861 DECL_CALL_CLOBBERED (var
) = false;
862 bitmap_clear_bit (gimple_call_clobbered_vars (cfun
), DECL_UID (var
));
863 TREE_ADDRESSABLE (var
) = 0;
866 /* Return the common annotation for T. Return NULL if the annotation
867 doesn't already exist. */
868 static inline tree_ann_common_t
869 tree_common_ann (tree t
)
871 return &t
->common
.ann
->common
;
874 /* Return a common annotation for T. Create the constant annotation if it
876 static inline tree_ann_common_t
877 get_tree_common_ann (tree t
)
879 tree_ann_common_t ann
= tree_common_ann (t
);
880 return (ann
) ? ann
: create_tree_common_ann (t
);
883 /* ----------------------------------------------------------------------- */
885 /* The following set of routines are used to iterator over various type of
888 /* Return true if PTR is finished iterating. */
890 op_iter_done (ssa_op_iter
*ptr
)
895 /* Get the next iterator use value for PTR. */
896 static inline use_operand_p
897 op_iter_next_use (ssa_op_iter
*ptr
)
900 #ifdef ENABLE_CHECKING
901 gcc_assert (ptr
->iter_type
== ssa_op_iter_use
);
905 use_p
= USE_OP_PTR (ptr
->uses
);
906 ptr
->uses
= ptr
->uses
->next
;
911 use_p
= VUSE_OP_PTR (ptr
->vuses
);
912 ptr
->vuses
= ptr
->vuses
->next
;
917 use_p
= MAYDEF_OP_PTR (ptr
->mayuses
);
918 ptr
->mayuses
= ptr
->mayuses
->next
;
923 use_p
= MUSTDEF_KILL_PTR (ptr
->mustkills
);
924 ptr
->mustkills
= ptr
->mustkills
->next
;
927 if (ptr
->phi_i
< ptr
->num_phi
)
929 return PHI_ARG_DEF_PTR (ptr
->phi_stmt
, (ptr
->phi_i
)++);
932 return NULL_USE_OPERAND_P
;
935 /* Get the next iterator def value for PTR. */
936 static inline def_operand_p
937 op_iter_next_def (ssa_op_iter
*ptr
)
940 #ifdef ENABLE_CHECKING
941 gcc_assert (ptr
->iter_type
== ssa_op_iter_def
);
945 def_p
= DEF_OP_PTR (ptr
->defs
);
946 ptr
->defs
= ptr
->defs
->next
;
951 def_p
= MUSTDEF_RESULT_PTR (ptr
->mustdefs
);
952 ptr
->mustdefs
= ptr
->mustdefs
->next
;
957 def_p
= MAYDEF_RESULT_PTR (ptr
->maydefs
);
958 ptr
->maydefs
= ptr
->maydefs
->next
;
962 return NULL_DEF_OPERAND_P
;
965 /* Get the next iterator tree value for PTR. */
967 op_iter_next_tree (ssa_op_iter
*ptr
)
970 #ifdef ENABLE_CHECKING
971 gcc_assert (ptr
->iter_type
== ssa_op_iter_tree
);
975 val
= USE_OP (ptr
->uses
);
976 ptr
->uses
= ptr
->uses
->next
;
981 val
= VUSE_OP (ptr
->vuses
);
982 ptr
->vuses
= ptr
->vuses
->next
;
987 val
= MAYDEF_OP (ptr
->mayuses
);
988 ptr
->mayuses
= ptr
->mayuses
->next
;
993 val
= MUSTDEF_KILL (ptr
->mustkills
);
994 ptr
->mustkills
= ptr
->mustkills
->next
;
999 val
= DEF_OP (ptr
->defs
);
1000 ptr
->defs
= ptr
->defs
->next
;
1005 val
= MUSTDEF_RESULT (ptr
->mustdefs
);
1006 ptr
->mustdefs
= ptr
->mustdefs
->next
;
1011 val
= MAYDEF_RESULT (ptr
->maydefs
);
1012 ptr
->maydefs
= ptr
->maydefs
->next
;
1022 /* This functions clears the iterator PTR, and marks it done. This is normally
1023 used to prevent warnings in the compile about might be uninitialized
1027 clear_and_done_ssa_iter (ssa_op_iter
*ptr
)
1032 ptr
->maydefs
= NULL
;
1033 ptr
->mayuses
= NULL
;
1034 ptr
->mustdefs
= NULL
;
1035 ptr
->mustkills
= NULL
;
1036 ptr
->iter_type
= ssa_op_iter_none
;
1039 ptr
->phi_stmt
= NULL_TREE
;
1043 /* Initialize the iterator PTR to the virtual defs in STMT. */
1045 op_iter_init (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1047 #ifdef ENABLE_CHECKING
1048 gcc_assert (stmt_ann (stmt
));
1051 ptr
->defs
= (flags
& SSA_OP_DEF
) ? DEF_OPS (stmt
) : NULL
;
1052 ptr
->uses
= (flags
& SSA_OP_USE
) ? USE_OPS (stmt
) : NULL
;
1053 ptr
->vuses
= (flags
& SSA_OP_VUSE
) ? VUSE_OPS (stmt
) : NULL
;
1054 ptr
->maydefs
= (flags
& SSA_OP_VMAYDEF
) ? MAYDEF_OPS (stmt
) : NULL
;
1055 ptr
->mayuses
= (flags
& SSA_OP_VMAYUSE
) ? MAYDEF_OPS (stmt
) : NULL
;
1056 ptr
->mustdefs
= (flags
& SSA_OP_VMUSTDEF
) ? MUSTDEF_OPS (stmt
) : NULL
;
1057 ptr
->mustkills
= (flags
& SSA_OP_VMUSTKILL
) ? MUSTDEF_OPS (stmt
) : NULL
;
1062 ptr
->phi_stmt
= NULL_TREE
;
1065 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1067 static inline use_operand_p
1068 op_iter_init_use (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1070 gcc_assert ((flags
& SSA_OP_ALL_DEFS
) == 0);
1071 op_iter_init (ptr
, stmt
, flags
);
1072 ptr
->iter_type
= ssa_op_iter_use
;
1073 return op_iter_next_use (ptr
);
1076 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1078 static inline def_operand_p
1079 op_iter_init_def (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1081 gcc_assert ((flags
& (SSA_OP_ALL_USES
| SSA_OP_VIRTUAL_KILLS
)) == 0);
1082 op_iter_init (ptr
, stmt
, flags
);
1083 ptr
->iter_type
= ssa_op_iter_def
;
1084 return op_iter_next_def (ptr
);
1087 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1088 the first operand as a tree. */
1090 op_iter_init_tree (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1092 op_iter_init (ptr
, stmt
, flags
);
1093 ptr
->iter_type
= ssa_op_iter_tree
;
1094 return op_iter_next_tree (ptr
);
1097 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1100 op_iter_next_maymustdef (use_operand_p
*use
, def_operand_p
*def
,
1103 #ifdef ENABLE_CHECKING
1104 gcc_assert (ptr
->iter_type
== ssa_op_iter_maymustdef
);
1108 *def
= MAYDEF_RESULT_PTR (ptr
->mayuses
);
1109 *use
= MAYDEF_OP_PTR (ptr
->mayuses
);
1110 ptr
->mayuses
= ptr
->mayuses
->next
;
1116 *def
= MUSTDEF_RESULT_PTR (ptr
->mustkills
);
1117 *use
= MUSTDEF_KILL_PTR (ptr
->mustkills
);
1118 ptr
->mustkills
= ptr
->mustkills
->next
;
1122 *def
= NULL_DEF_OPERAND_P
;
1123 *use
= NULL_USE_OPERAND_P
;
1129 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1132 op_iter_init_maydef (ssa_op_iter
*ptr
, tree stmt
, use_operand_p
*use
,
1135 gcc_assert (TREE_CODE (stmt
) != PHI_NODE
);
1137 op_iter_init (ptr
, stmt
, SSA_OP_VMAYUSE
);
1138 ptr
->iter_type
= ssa_op_iter_maymustdef
;
1139 op_iter_next_maymustdef (use
, def
, ptr
);
1143 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1146 op_iter_init_mustdef (ssa_op_iter
*ptr
, tree stmt
, use_operand_p
*kill
,
1149 gcc_assert (TREE_CODE (stmt
) != PHI_NODE
);
1151 op_iter_init (ptr
, stmt
, SSA_OP_VMUSTKILL
);
1152 ptr
->iter_type
= ssa_op_iter_maymustdef
;
1153 op_iter_next_maymustdef (kill
, def
, ptr
);
1156 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1159 op_iter_init_must_and_may_def (ssa_op_iter
*ptr
, tree stmt
,
1160 use_operand_p
*kill
, def_operand_p
*def
)
1162 gcc_assert (TREE_CODE (stmt
) != PHI_NODE
);
1164 op_iter_init (ptr
, stmt
, SSA_OP_VMUSTKILL
|SSA_OP_VMAYUSE
);
1165 ptr
->iter_type
= ssa_op_iter_maymustdef
;
1166 op_iter_next_maymustdef (kill
, def
, ptr
);
1170 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1173 single_ssa_tree_operand (tree stmt
, int flags
)
1178 var
= op_iter_init_tree (&iter
, stmt
, flags
);
1179 if (op_iter_done (&iter
))
1181 op_iter_next_tree (&iter
);
1182 if (op_iter_done (&iter
))
1188 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1190 static inline use_operand_p
1191 single_ssa_use_operand (tree stmt
, int flags
)
1196 var
= op_iter_init_use (&iter
, stmt
, flags
);
1197 if (op_iter_done (&iter
))
1198 return NULL_USE_OPERAND_P
;
1199 op_iter_next_use (&iter
);
1200 if (op_iter_done (&iter
))
1202 return NULL_USE_OPERAND_P
;
1207 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1209 static inline def_operand_p
1210 single_ssa_def_operand (tree stmt
, int flags
)
1215 var
= op_iter_init_def (&iter
, stmt
, flags
);
1216 if (op_iter_done (&iter
))
1217 return NULL_DEF_OPERAND_P
;
1218 op_iter_next_def (&iter
);
1219 if (op_iter_done (&iter
))
1221 return NULL_DEF_OPERAND_P
;
1225 /* Return true if there are zero operands in STMT matching the type
1228 zero_ssa_operands (tree stmt
, int flags
)
1232 op_iter_init_tree (&iter
, stmt
, flags
);
1233 return op_iter_done (&iter
);
1237 /* Return the number of operands matching FLAGS in STMT. */
1239 num_ssa_operands (tree stmt
, int flags
)
1245 FOR_EACH_SSA_TREE_OPERAND (t
, stmt
, iter
, flags
)
1251 /* Delink all immediate_use information for STMT. */
1253 delink_stmt_imm_use (tree stmt
)
1256 use_operand_p use_p
;
1258 if (ssa_operands_active ())
1259 FOR_EACH_SSA_USE_OPERAND (use_p
, stmt
, iter
,
1260 (SSA_OP_ALL_USES
| SSA_OP_ALL_KILLS
))
1261 delink_imm_use (use_p
);
1265 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1266 in STMT2. TRUE is returned if they are the same. STMTs can be NULL. */
1268 compare_ssa_operands_equal (tree stmt1
, tree stmt2
, int flags
)
1270 ssa_op_iter iter1
, iter2
;
1271 tree op1
= NULL_TREE
;
1272 tree op2
= NULL_TREE
;
1278 look1
= stmt1
&& stmt_ann (stmt1
);
1279 look2
= stmt2
&& stmt_ann (stmt2
);
1283 op1
= op_iter_init_tree (&iter1
, stmt1
, flags
);
1285 return op_iter_done (&iter1
);
1288 clear_and_done_ssa_iter (&iter1
);
1292 op2
= op_iter_init_tree (&iter2
, stmt2
, flags
);
1294 return op_iter_done (&iter2
);
1297 clear_and_done_ssa_iter (&iter2
);
1299 while (!op_iter_done (&iter1
) && !op_iter_done (&iter2
))
1303 op1
= op_iter_next_tree (&iter1
);
1304 op2
= op_iter_next_tree (&iter2
);
1307 return (op_iter_done (&iter1
) && op_iter_done (&iter2
));
1311 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1312 Otherwise return NULL_DEF_OPERAND_P. */
1314 single_phi_def (tree stmt
, int flags
)
1316 tree def
= PHI_RESULT (stmt
);
1317 if ((flags
& SSA_OP_DEF
) && is_gimple_reg (def
))
1319 if ((flags
& SSA_OP_VIRTUAL_DEFS
) && !is_gimple_reg (def
))
1324 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
1325 be either SSA_OP_USES or SSA_OP_VIRTUAL_USES. */
1326 static inline use_operand_p
1327 op_iter_init_phiuse (ssa_op_iter
*ptr
, tree phi
, int flags
)
1329 tree phi_def
= PHI_RESULT (phi
);
1332 clear_and_done_ssa_iter (ptr
);
1335 gcc_assert ((flags
& (SSA_OP_USE
| SSA_OP_VIRTUAL_USES
)) != 0);
1337 comp
= (is_gimple_reg (phi_def
) ? SSA_OP_USE
: SSA_OP_VIRTUAL_USES
);
1339 /* If the PHI node doesn't the operand type we care about, we're done. */
1340 if ((flags
& comp
) == 0)
1343 return NULL_USE_OPERAND_P
;
1346 ptr
->phi_stmt
= phi
;
1347 ptr
->num_phi
= PHI_NUM_ARGS (phi
);
1348 ptr
->iter_type
= ssa_op_iter_use
;
1349 return op_iter_next_use (ptr
);
1353 /* Start an iterator for a PHI definition. */
1355 static inline def_operand_p
1356 op_iter_init_phidef (ssa_op_iter
*ptr
, tree phi
, int flags
)
1358 tree phi_def
= PHI_RESULT (phi
);
1361 clear_and_done_ssa_iter (ptr
);
1364 gcc_assert ((flags
& (SSA_OP_DEF
| SSA_OP_VIRTUAL_DEFS
)) != 0);
1366 comp
= (is_gimple_reg (phi_def
) ? SSA_OP_DEF
: SSA_OP_VIRTUAL_DEFS
);
1368 /* If the PHI node doesn't the operand type we care about, we're done. */
1369 if ((flags
& comp
) == 0)
1372 return NULL_USE_OPERAND_P
;
1375 ptr
->iter_type
= ssa_op_iter_def
;
1376 /* The first call to op_iter_next_def will terminate the iterator since
1377 all the fields are NULL. Simply return the result here as the first and
1378 therefore only result. */
1379 return PHI_RESULT_PTR (phi
);
1382 /* Return true is IMM has reached the end of the immediate use stmt list. */
1385 end_imm_use_stmt_p (imm_use_iterator
*imm
)
1387 return (imm
->imm_use
== imm
->end_p
);
1390 /* Finished the traverse of an immediate use stmt list IMM by removing the
1391 placeholder node from the list. */
1394 end_imm_use_stmt_traverse (imm_use_iterator
*imm
)
1396 delink_imm_use (&(imm
->iter_node
));
1399 /* Immediate use traversal of uses within a stmt require that all the
1400 uses on a stmt be sequentially listed. This routine is used to build up
1401 this sequential list by adding USE_P to the end of the current list
1402 currently delimited by HEAD and LAST_P. The new LAST_P value is
1405 static inline use_operand_p
1406 move_use_after_head (use_operand_p use_p
, use_operand_p head
,
1407 use_operand_p last_p
)
1409 gcc_assert (USE_FROM_PTR (use_p
) == USE_FROM_PTR (head
));
1410 /* Skip head when we find it. */
1413 /* If use_p is already linked in after last_p, continue. */
1414 if (last_p
->next
== use_p
)
1418 /* Delink from current location, and link in at last_p. */
1419 delink_imm_use (use_p
);
1420 link_imm_use_to_list (use_p
, last_p
);
1428 /* This routine will relink all uses with the same stmt as HEAD into the list
1429 immediately following HEAD for iterator IMM. */
1432 link_use_stmts_after (use_operand_p head
, imm_use_iterator
*imm
)
1434 use_operand_p use_p
;
1435 use_operand_p last_p
= head
;
1436 tree head_stmt
= USE_STMT (head
);
1437 tree use
= USE_FROM_PTR (head
);
1438 ssa_op_iter op_iter
;
1441 /* Only look at virtual or real uses, depending on the type of HEAD. */
1442 flag
= (is_gimple_reg (use
) ? SSA_OP_USE
: SSA_OP_VIRTUAL_USES
);
1444 if (TREE_CODE (head_stmt
) == PHI_NODE
)
1446 FOR_EACH_PHI_ARG (use_p
, head_stmt
, op_iter
, flag
)
1447 if (USE_FROM_PTR (use_p
) == use
)
1448 last_p
= move_use_after_head (use_p
, head
, last_p
);
1452 FOR_EACH_SSA_USE_OPERAND (use_p
, head_stmt
, op_iter
, flag
)
1453 if (USE_FROM_PTR (use_p
) == use
)
1454 last_p
= move_use_after_head (use_p
, head
, last_p
);
1456 /* LInk iter node in after last_p. */
1457 if (imm
->iter_node
.prev
!= NULL
)
1458 delink_imm_use (&imm
->iter_node
);
1459 link_imm_use_to_list (&(imm
->iter_node
), last_p
);
1462 /* Initialize IMM to traverse over uses of VAR. Return the first statement. */
1464 first_imm_use_stmt (imm_use_iterator
*imm
, tree var
)
1466 gcc_assert (TREE_CODE (var
) == SSA_NAME
);
1468 imm
->end_p
= &(SSA_NAME_IMM_USE_NODE (var
));
1469 imm
->imm_use
= imm
->end_p
->next
;
1470 imm
->next_imm_name
= NULL_USE_OPERAND_P
;
1472 /* iter_node is used as a marker within the immediate use list to indicate
1473 where the end of the current stmt's uses are. Initialize it to NULL
1474 stmt and use, which indicates a marker node. */
1475 imm
->iter_node
.prev
= NULL_USE_OPERAND_P
;
1476 imm
->iter_node
.next
= NULL_USE_OPERAND_P
;
1477 imm
->iter_node
.stmt
= NULL_TREE
;
1478 imm
->iter_node
.use
= NULL_USE_OPERAND_P
;
1480 if (end_imm_use_stmt_p (imm
))
1483 link_use_stmts_after (imm
->imm_use
, imm
);
1485 return USE_STMT (imm
->imm_use
);
1488 /* Bump IMM to the next stmt which has a use of var. */
1491 next_imm_use_stmt (imm_use_iterator
*imm
)
1493 imm
->imm_use
= imm
->iter_node
.next
;
1494 if (end_imm_use_stmt_p (imm
))
1496 if (imm
->iter_node
.prev
!= NULL
)
1497 delink_imm_use (&imm
->iter_node
);
1501 link_use_stmts_after (imm
->imm_use
, imm
);
1502 return USE_STMT (imm
->imm_use
);
1506 /* This routine will return the first use on the stmt IMM currently refers
1509 static inline use_operand_p
1510 first_imm_use_on_stmt (imm_use_iterator
*imm
)
1512 imm
->next_imm_name
= imm
->imm_use
->next
;
1513 return imm
->imm_use
;
1516 /* Return TRUE if the last use on the stmt IMM refers to has been visited. */
1519 end_imm_use_on_stmt_p (imm_use_iterator
*imm
)
1521 return (imm
->imm_use
== &(imm
->iter_node
));
1524 /* Bump to the next use on the stmt IMM refers to, return NULL if done. */
1526 static inline use_operand_p
1527 next_imm_use_on_stmt (imm_use_iterator
*imm
)
1529 imm
->imm_use
= imm
->next_imm_name
;
1530 if (end_imm_use_on_stmt_p (imm
))
1531 return NULL_USE_OPERAND_P
;
1534 imm
->next_imm_name
= imm
->imm_use
->next
;
1535 return imm
->imm_use
;
1539 /* Return true if VAR cannot be modified by the program. */
1542 unmodifiable_var_p (tree var
)
1544 if (TREE_CODE (var
) == SSA_NAME
)
1545 var
= SSA_NAME_VAR (var
);
1548 return TREE_READONLY (var
) && (TREE_STATIC (var
) || MTAG_GLOBAL (var
));
1550 return TREE_READONLY (var
) && (TREE_STATIC (var
) || DECL_EXTERNAL (var
));
1553 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it. */
1556 array_ref_contains_indirect_ref (tree ref
)
1558 gcc_assert (TREE_CODE (ref
) == ARRAY_REF
);
1561 ref
= TREE_OPERAND (ref
, 0);
1562 } while (handled_component_p (ref
));
1564 return TREE_CODE (ref
) == INDIRECT_REF
;
1567 /* Return true if REF, a handled component reference, has an ARRAY_REF
1571 ref_contains_array_ref (tree ref
)
1573 gcc_assert (handled_component_p (ref
));
1576 if (TREE_CODE (ref
) == ARRAY_REF
)
1578 ref
= TREE_OPERAND (ref
, 0);
1579 } while (handled_component_p (ref
));
1584 /* Given a variable VAR, lookup and return a pointer to the list of
1585 subvariables for it. */
1587 static inline subvar_t
*
1588 lookup_subvars_for_var (tree var
)
1590 var_ann_t ann
= var_ann (var
);
1592 return &ann
->subvars
;
1595 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1596 NULL, if there are no subvariables. */
1598 static inline subvar_t
1599 get_subvars_for_var (tree var
)
1603 gcc_assert (SSA_VAR_P (var
));
1605 if (TREE_CODE (var
) == SSA_NAME
)
1606 subvars
= *(lookup_subvars_for_var (SSA_NAME_VAR (var
)));
1608 subvars
= *(lookup_subvars_for_var (var
));
1612 /* Return the subvariable of VAR at offset OFFSET. */
1615 get_subvar_at (tree var
, unsigned HOST_WIDE_INT offset
)
1619 for (sv
= get_subvars_for_var (var
); sv
; sv
= sv
->next
)
1620 if (SFT_OFFSET (sv
->var
) == offset
)
1626 /* Return true if V is a tree that we can have subvars for.
1627 Normally, this is any aggregate type. Also complex
1628 types which are not gimple registers can have subvars. */
1631 var_can_have_subvars (tree v
)
1633 /* Volatile variables should never have subvars. */
1634 if (TREE_THIS_VOLATILE (v
))
1637 /* Non decls or memory tags can never have subvars. */
1638 if (!DECL_P (v
) || MTAG_P (v
))
1641 /* Aggregates can have subvars. */
1642 if (AGGREGATE_TYPE_P (TREE_TYPE (v
)))
1645 /* Complex types variables which are not also a gimple register can
1647 if (TREE_CODE (TREE_TYPE (v
)) == COMPLEX_TYPE
1648 && !DECL_COMPLEX_GIMPLE_REG_P (v
))
1655 /* Return true if OFFSET and SIZE define a range that overlaps with some
1656 portion of the range of SV, a subvar. If there was an exact overlap,
1657 *EXACT will be set to true upon return. */
1660 overlap_subvar (unsigned HOST_WIDE_INT offset
, unsigned HOST_WIDE_INT size
,
1661 tree sv
, bool *exact
)
1663 /* There are three possible cases of overlap.
1664 1. We can have an exact overlap, like so:
1665 |offset, offset + size |
1666 |sv->offset, sv->offset + sv->size |
1668 2. We can have offset starting after sv->offset, like so:
1670 |offset, offset + size |
1671 |sv->offset, sv->offset + sv->size |
1673 3. We can have offset starting before sv->offset, like so:
1675 |offset, offset + size |
1676 |sv->offset, sv->offset + sv->size|
1681 if (offset
== SFT_OFFSET (sv
) && size
== SFT_SIZE (sv
))
1687 else if (offset
>= SFT_OFFSET (sv
)
1688 && offset
< (SFT_OFFSET (sv
) + SFT_SIZE (sv
)))
1692 else if (offset
< SFT_OFFSET (sv
)
1693 && (size
> SFT_OFFSET (sv
) - offset
))
1701 /* Get the value handle of EXPR. This is the only correct way to get
1702 the value handle for a "thing". If EXPR does not have a value
1703 handle associated, it returns NULL_TREE.
1704 NB: If EXPR is min_invariant, this function is *required* to return
1708 get_value_handle (tree expr
)
1710 if (TREE_CODE (expr
) == SSA_NAME
)
1711 return SSA_NAME_VALUE (expr
);
1712 else if (DECL_P (expr
) || TREE_CODE (expr
) == TREE_LIST
1713 || TREE_CODE (expr
) == CONSTRUCTOR
)
1715 tree_ann_common_t ann
= tree_common_ann (expr
);
1716 return ((ann
) ? ann
->value_handle
: NULL_TREE
);
1718 else if (is_gimple_min_invariant (expr
))
1720 else if (EXPR_P (expr
))
1722 tree_ann_common_t ann
= tree_common_ann (expr
);
1723 return ((ann
) ? ann
->value_handle
: NULL_TREE
);
1729 #endif /* _TREE_FLOW_INLINE_H */