1 /* Inline functions for tree-flow.h
2 Copyright (C) 2001, 2003, 2005, 2006, 2007, 2008 Free Software
4 Contributed by Diego Novillo <dnovillo@redhat.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
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 (const 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 (const 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 (const 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 (const struct function
*fun
)
65 gcc_assert (fun
&& fun
->gimple_df
);
66 return fun
->gimple_df
->call_clobbered_vars
;
69 /* Call-used variables in the function. If bit I is set, then
70 REFERENCED_VARS (I) is call-used at pure function call-sites. */
72 gimple_call_used_vars (const struct function
*fun
)
74 gcc_assert (fun
&& fun
->gimple_df
);
75 return fun
->gimple_df
->call_used_vars
;
78 /* Array of all variables referenced in the function. */
80 gimple_referenced_vars (const struct function
*fun
)
84 return fun
->gimple_df
->referenced_vars
;
87 /* Artificial variable used to model the effects of function calls. */
89 gimple_global_var (const struct function
*fun
)
91 gcc_assert (fun
&& fun
->gimple_df
);
92 return fun
->gimple_df
->global_var
;
95 /* Artificial variable used to model the effects of nonlocal
98 gimple_nonlocal_all (const struct function
*fun
)
100 gcc_assert (fun
&& fun
->gimple_df
);
101 return fun
->gimple_df
->nonlocal_all
;
104 /* Initialize the hashtable iterator HTI to point to hashtable TABLE */
107 first_htab_element (htab_iterator
*hti
, htab_t table
)
110 hti
->slot
= table
->entries
;
111 hti
->limit
= hti
->slot
+ htab_size (table
);
114 PTR x
= *(hti
->slot
);
115 if (x
!= HTAB_EMPTY_ENTRY
&& x
!= HTAB_DELETED_ENTRY
)
117 } while (++(hti
->slot
) < hti
->limit
);
119 if (hti
->slot
< hti
->limit
)
124 /* Return current non-empty/deleted slot of the hashtable pointed to by HTI,
125 or NULL if we have reached the end. */
128 end_htab_p (const htab_iterator
*hti
)
130 if (hti
->slot
>= hti
->limit
)
135 /* Advance the hashtable iterator pointed to by HTI to the next element of the
139 next_htab_element (htab_iterator
*hti
)
141 while (++(hti
->slot
) < hti
->limit
)
143 PTR x
= *(hti
->slot
);
144 if (x
!= HTAB_EMPTY_ENTRY
&& x
!= HTAB_DELETED_ENTRY
)
150 /* Initialize ITER to point to the first referenced variable in the
151 referenced_vars hashtable, and return that variable. */
154 first_referenced_var (referenced_var_iterator
*iter
)
156 return (tree
) first_htab_element (&iter
->hti
,
157 gimple_referenced_vars (cfun
));
160 /* Return true if we have hit the end of the referenced variables ITER is
161 iterating through. */
164 end_referenced_vars_p (const referenced_var_iterator
*iter
)
166 return end_htab_p (&iter
->hti
);
169 /* Make ITER point to the next referenced_var in the referenced_var hashtable,
170 and return that variable. */
173 next_referenced_var (referenced_var_iterator
*iter
)
175 return (tree
) next_htab_element (&iter
->hti
);
178 /* Fill up VEC with the variables in the referenced vars hashtable. */
181 fill_referenced_var_vec (VEC (tree
, heap
) **vec
)
183 referenced_var_iterator rvi
;
186 FOR_EACH_REFERENCED_VAR (var
, rvi
)
187 VEC_safe_push (tree
, heap
, *vec
, var
);
190 /* Return the variable annotation for T, which must be a _DECL node.
191 Return NULL if the variable annotation doesn't already exist. */
192 static inline var_ann_t
193 var_ann (const_tree t
)
199 ann
= (var_ann_t
) t
->base
.ann
;
201 gcc_assert (ann
->common
.type
== VAR_ANN
);
206 /* Return the variable annotation for T, which must be a _DECL node.
207 Create the variable annotation if it doesn't exist. */
208 static inline var_ann_t
209 get_var_ann (tree var
)
211 var_ann_t ann
= var_ann (var
);
212 return (ann
) ? ann
: create_var_ann (var
);
215 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
216 Return NULL if the function annotation doesn't already exist. */
217 static inline function_ann_t
218 function_ann (const_tree t
)
221 gcc_assert (TREE_CODE (t
) == FUNCTION_DECL
);
222 gcc_assert (!t
->base
.ann
223 || t
->base
.ann
->common
.type
== FUNCTION_ANN
);
225 return (function_ann_t
) t
->base
.ann
;
228 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
229 Create the function annotation if it doesn't exist. */
230 static inline function_ann_t
231 get_function_ann (tree var
)
233 function_ann_t ann
= function_ann (var
);
234 gcc_assert (!var
->base
.ann
|| var
->base
.ann
->common
.type
== FUNCTION_ANN
);
235 return (ann
) ? ann
: create_function_ann (var
);
238 /* Return true if T has a statement annotation attached to it. */
241 has_stmt_ann (tree t
)
243 #ifdef ENABLE_CHECKING
244 gcc_assert (is_gimple_stmt (t
));
246 return t
->base
.ann
&& t
->base
.ann
->common
.type
== STMT_ANN
;
249 /* Return the statement annotation for T, which must be a statement
250 node. Return NULL if the statement annotation doesn't exist. */
251 static inline stmt_ann_t
254 #ifdef ENABLE_CHECKING
255 gcc_assert (is_gimple_stmt (t
));
257 gcc_assert (!t
->base
.ann
|| t
->base
.ann
->common
.type
== STMT_ANN
);
258 return (stmt_ann_t
) t
->base
.ann
;
261 /* Return the statement annotation for T, which must be a statement
262 node. Create the statement annotation if it doesn't exist. */
263 static inline stmt_ann_t
264 get_stmt_ann (tree stmt
)
266 stmt_ann_t ann
= stmt_ann (stmt
);
267 return (ann
) ? ann
: create_stmt_ann (stmt
);
270 /* Set the uid of all non phi function statements. */
272 set_gimple_stmt_uid (tree stmt
, unsigned int uid
)
274 get_stmt_ann (stmt
)->uid
= uid
;
277 /* Get the uid of all non phi function statements. */
278 static inline unsigned int
279 gimple_stmt_uid (tree stmt
)
281 return get_stmt_ann (stmt
)->uid
;
284 /* Get the number of the next statement uid to be allocated. */
285 static inline unsigned int
286 gimple_stmt_max_uid (struct function
*fn
)
288 return fn
->last_stmt_uid
;
291 /* Set the number of the next statement uid to be allocated. */
293 set_gimple_stmt_max_uid (struct function
*fn
, unsigned int maxid
)
295 fn
->last_stmt_uid
= maxid
;
298 /* Set the number of the next statement uid to be allocated. */
299 static inline unsigned int
300 inc_gimple_stmt_max_uid (struct function
*fn
)
302 return fn
->last_stmt_uid
++;
305 /* Return the annotation type for annotation ANN. */
306 static inline enum tree_ann_type
307 ann_type (tree_ann_t ann
)
309 return ann
->common
.type
;
312 /* Return the basic block for statement T. */
313 static inline basic_block
318 if (TREE_CODE (t
) == PHI_NODE
)
322 return ann
? ann
->bb
: NULL
;
325 /* Return the may_aliases bitmap for variable VAR, or NULL if it has
328 may_aliases (const_tree var
)
330 return MTAG_ALIASES (var
);
333 /* Return the line number for EXPR, or return -1 if we have no line
334 number information for it. */
336 get_lineno (const_tree expr
)
338 if (expr
== NULL_TREE
)
341 if (TREE_CODE (expr
) == COMPOUND_EXPR
)
342 expr
= TREE_OPERAND (expr
, 0);
344 if (! EXPR_HAS_LOCATION (expr
))
347 return EXPR_LINENO (expr
);
350 /* Return true if T is a noreturn call. */
352 noreturn_call_p (tree t
)
354 tree call
= get_call_expr_in (t
);
355 return call
!= 0 && (call_expr_flags (call
) & ECF_NORETURN
) != 0;
358 /* Mark statement T as modified. */
360 mark_stmt_modified (tree t
)
363 if (TREE_CODE (t
) == PHI_NODE
)
368 ann
= create_stmt_ann (t
);
369 else if (noreturn_call_p (t
) && cfun
->gimple_df
)
370 VEC_safe_push (tree
, gc
, MODIFIED_NORETURN_CALLS (cfun
), t
);
374 /* Mark statement T as modified, and update it. */
378 if (TREE_CODE (t
) == PHI_NODE
)
380 mark_stmt_modified (t
);
381 update_stmt_operands (t
);
385 update_stmt_if_modified (tree t
)
387 if (stmt_modified_p (t
))
388 update_stmt_operands (t
);
391 /* Return true if T is marked as modified, false otherwise. */
393 stmt_modified_p (tree t
)
395 stmt_ann_t ann
= stmt_ann (t
);
397 /* Note that if the statement doesn't yet have an annotation, we consider it
398 modified. This will force the next call to update_stmt_operands to scan
400 return ann
? ann
->modified
: true;
403 /* Delink an immediate_uses node from its chain. */
405 delink_imm_use (ssa_use_operand_t
*linknode
)
407 /* Return if this node is not in a list. */
408 if (linknode
->prev
== NULL
)
411 linknode
->prev
->next
= linknode
->next
;
412 linknode
->next
->prev
= linknode
->prev
;
413 linknode
->prev
= NULL
;
414 linknode
->next
= NULL
;
417 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
419 link_imm_use_to_list (ssa_use_operand_t
*linknode
, ssa_use_operand_t
*list
)
421 /* Link the new node at the head of the list. If we are in the process of
422 traversing the list, we won't visit any new nodes added to it. */
423 linknode
->prev
= list
;
424 linknode
->next
= list
->next
;
425 list
->next
->prev
= linknode
;
426 list
->next
= linknode
;
429 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
431 link_imm_use (ssa_use_operand_t
*linknode
, tree def
)
433 ssa_use_operand_t
*root
;
435 if (!def
|| TREE_CODE (def
) != SSA_NAME
)
436 linknode
->prev
= NULL
;
439 root
= &(SSA_NAME_IMM_USE_NODE (def
));
440 #ifdef ENABLE_CHECKING
442 gcc_assert (*(linknode
->use
) == def
);
444 link_imm_use_to_list (linknode
, root
);
448 /* Set the value of a use pointed to by USE to VAL. */
450 set_ssa_use_from_ptr (use_operand_p use
, tree val
)
452 delink_imm_use (use
);
454 link_imm_use (use
, val
);
457 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
460 link_imm_use_stmt (ssa_use_operand_t
*linknode
, tree def
, tree stmt
)
463 link_imm_use (linknode
, def
);
465 link_imm_use (linknode
, NULL
);
466 linknode
->stmt
= stmt
;
469 /* Relink a new node in place of an old node in the list. */
471 relink_imm_use (ssa_use_operand_t
*node
, ssa_use_operand_t
*old
)
473 /* The node one had better be in the same list. */
474 gcc_assert (*(old
->use
) == *(node
->use
));
475 node
->prev
= old
->prev
;
476 node
->next
= old
->next
;
479 old
->prev
->next
= node
;
480 old
->next
->prev
= node
;
481 /* Remove the old node from the list. */
486 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
489 relink_imm_use_stmt (ssa_use_operand_t
*linknode
, ssa_use_operand_t
*old
, tree stmt
)
492 relink_imm_use (linknode
, old
);
494 link_imm_use (linknode
, NULL
);
495 linknode
->stmt
= stmt
;
499 /* Return true is IMM has reached the end of the immediate use list. */
501 end_readonly_imm_use_p (const imm_use_iterator
*imm
)
503 return (imm
->imm_use
== imm
->end_p
);
506 /* Initialize iterator IMM to process the list for VAR. */
507 static inline use_operand_p
508 first_readonly_imm_use (imm_use_iterator
*imm
, tree var
)
510 gcc_assert (TREE_CODE (var
) == SSA_NAME
);
512 imm
->end_p
= &(SSA_NAME_IMM_USE_NODE (var
));
513 imm
->imm_use
= imm
->end_p
->next
;
514 #ifdef ENABLE_CHECKING
515 imm
->iter_node
.next
= imm
->imm_use
->next
;
517 if (end_readonly_imm_use_p (imm
))
518 return NULL_USE_OPERAND_P
;
522 /* Bump IMM to the next use in the list. */
523 static inline use_operand_p
524 next_readonly_imm_use (imm_use_iterator
*imm
)
526 use_operand_p old
= imm
->imm_use
;
528 #ifdef ENABLE_CHECKING
529 /* If this assertion fails, it indicates the 'next' pointer has changed
530 since the last bump. This indicates that the list is being modified
531 via stmt changes, or SET_USE, or somesuch thing, and you need to be
532 using the SAFE version of the iterator. */
533 gcc_assert (imm
->iter_node
.next
== old
->next
);
534 imm
->iter_node
.next
= old
->next
->next
;
537 imm
->imm_use
= old
->next
;
538 if (end_readonly_imm_use_p (imm
))
539 return NULL_USE_OPERAND_P
;
543 /* Return true if VAR has no uses. */
545 has_zero_uses (const_tree var
)
547 const ssa_use_operand_t
*const ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
548 /* A single use means there is no items in the list. */
549 return (ptr
== ptr
->next
);
552 /* Return true if VAR has a single use. */
554 has_single_use (const_tree var
)
556 const ssa_use_operand_t
*const ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
557 /* A single use means there is one item in the list. */
558 return (ptr
!= ptr
->next
&& ptr
== ptr
->next
->next
);
562 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
563 to the use pointer and stmt of occurrence. */
565 single_imm_use (const_tree var
, use_operand_p
*use_p
, tree
*stmt
)
567 const ssa_use_operand_t
*const ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
568 if (ptr
!= ptr
->next
&& ptr
== ptr
->next
->next
)
571 *stmt
= ptr
->next
->stmt
;
574 *use_p
= NULL_USE_OPERAND_P
;
579 /* Return the number of immediate uses of VAR. */
580 static inline unsigned int
581 num_imm_uses (const_tree var
)
583 const ssa_use_operand_t
*const start
= &(SSA_NAME_IMM_USE_NODE (var
));
584 const ssa_use_operand_t
*ptr
;
585 unsigned int num
= 0;
587 for (ptr
= start
->next
; ptr
!= start
; ptr
= ptr
->next
)
593 /* Return the tree pointer to by USE. */
595 get_use_from_ptr (use_operand_p use
)
600 /* Return the tree pointer to by DEF. */
602 get_def_from_ptr (def_operand_p def
)
607 /* Return a def_operand_p pointer for the result of PHI. */
608 static inline def_operand_p
609 get_phi_result_ptr (tree phi
)
611 return &(PHI_RESULT_TREE (phi
));
614 /* Return a use_operand_p pointer for argument I of phinode PHI. */
615 static inline use_operand_p
616 get_phi_arg_def_ptr (tree phi
, int i
)
618 return &(PHI_ARG_IMM_USE_NODE (phi
,i
));
622 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
625 addresses_taken (tree stmt
)
627 stmt_ann_t ann
= stmt_ann (stmt
);
628 return ann
? ann
->addresses_taken
: NULL
;
631 /* Return the PHI nodes for basic block BB, or NULL if there are no
634 phi_nodes (const_basic_block bb
)
636 gcc_assert (!(bb
->flags
& BB_RTL
));
639 return bb
->il
.tree
->phi_nodes
;
642 /* Return pointer to the list of PHI nodes for basic block BB. */
645 phi_nodes_ptr (basic_block bb
)
647 gcc_assert (!(bb
->flags
& BB_RTL
));
648 return &bb
->il
.tree
->phi_nodes
;
651 /* Set list of phi nodes of a basic block BB to L. */
654 set_phi_nodes (basic_block bb
, tree l
)
658 gcc_assert (!(bb
->flags
& BB_RTL
));
659 bb
->il
.tree
->phi_nodes
= l
;
660 for (phi
= l
; phi
; phi
= PHI_CHAIN (phi
))
661 set_bb_for_stmt (phi
, bb
);
664 /* Return the phi argument which contains the specified use. */
667 phi_arg_index_from_use (use_operand_p use
)
669 struct phi_arg_d
*element
, *root
;
673 /* Since the use is the first thing in a PHI argument element, we can
674 calculate its index based on casting it to an argument, and performing
675 pointer arithmetic. */
677 phi
= USE_STMT (use
);
678 gcc_assert (TREE_CODE (phi
) == PHI_NODE
);
680 element
= (struct phi_arg_d
*)use
;
681 root
= &(PHI_ARG_ELT (phi
, 0));
682 index
= element
- root
;
684 #ifdef ENABLE_CHECKING
685 /* Make sure the calculation doesn't have any leftover bytes. If it does,
686 then imm_use is likely not the first element in phi_arg_d. */
688 (((char *)element
- (char *)root
) % sizeof (struct phi_arg_d
)) == 0);
689 gcc_assert (index
>= 0 && index
< PHI_ARG_CAPACITY (phi
));
695 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
698 set_is_used (tree var
)
700 var_ann_t ann
= get_var_ann (var
);
705 /* Return true if T (assumed to be a DECL) is a global variable. */
708 is_global_var (const_tree t
)
711 return MTAG_GLOBAL (t
);
713 return (TREE_STATIC (t
) || DECL_EXTERNAL (t
));
716 /* PHI nodes should contain only ssa_names and invariants. A test
717 for ssa_name is definitely simpler; don't let invalid contents
718 slip in in the meantime. */
721 phi_ssa_name_p (const_tree t
)
723 if (TREE_CODE (t
) == SSA_NAME
)
725 #ifdef ENABLE_CHECKING
726 gcc_assert (is_gimple_min_invariant (t
));
731 /* ----------------------------------------------------------------------- */
733 /* Returns the list of statements in BB. */
736 bb_stmt_list (const_basic_block bb
)
738 gcc_assert (!(bb
->flags
& BB_RTL
));
739 return bb
->il
.tree
->stmt_list
;
742 /* Sets the list of statements in BB to LIST. */
745 set_bb_stmt_list (basic_block bb
, tree list
)
747 gcc_assert (!(bb
->flags
& BB_RTL
));
748 bb
->il
.tree
->stmt_list
= list
;
751 /* Return a block_stmt_iterator that points to beginning of basic
753 static inline block_stmt_iterator
754 bsi_start (basic_block bb
)
756 block_stmt_iterator bsi
;
757 if (bb
->index
< NUM_FIXED_BLOCKS
)
760 bsi
.tsi
.container
= NULL
;
763 bsi
.tsi
= tsi_start (bb_stmt_list (bb
));
768 /* Return a block statement iterator that points to the first non-label
769 statement in block BB. */
771 static inline block_stmt_iterator
772 bsi_after_labels (basic_block bb
)
774 block_stmt_iterator bsi
= bsi_start (bb
);
776 while (!bsi_end_p (bsi
) && TREE_CODE (bsi_stmt (bsi
)) == LABEL_EXPR
)
782 /* Return a block statement iterator that points to the end of basic
784 static inline block_stmt_iterator
785 bsi_last (basic_block bb
)
787 block_stmt_iterator bsi
;
789 if (bb
->index
< NUM_FIXED_BLOCKS
)
792 bsi
.tsi
.container
= NULL
;
795 bsi
.tsi
= tsi_last (bb_stmt_list (bb
));
800 /* Return true if block statement iterator I has reached the end of
803 bsi_end_p (block_stmt_iterator i
)
805 return tsi_end_p (i
.tsi
);
808 /* Modify block statement iterator I so that it is at the next
809 statement in the basic block. */
811 bsi_next (block_stmt_iterator
*i
)
816 /* Modify block statement iterator I so that it is at the previous
817 statement in the basic block. */
819 bsi_prev (block_stmt_iterator
*i
)
824 /* Return the statement that block statement iterator I is currently
827 bsi_stmt (block_stmt_iterator i
)
829 return tsi_stmt (i
.tsi
);
832 /* Return a pointer to the statement that block statement iterator I
835 bsi_stmt_ptr (block_stmt_iterator i
)
837 return tsi_stmt_ptr (i
.tsi
);
840 /* Returns the loop of the statement STMT. */
842 static inline struct loop
*
843 loop_containing_stmt (tree stmt
)
845 basic_block bb
= bb_for_stmt (stmt
);
849 return bb
->loop_father
;
853 /* Return the memory partition tag associated with symbol SYM. */
856 memory_partition (tree sym
)
860 /* MPTs belong to their own partition. */
861 if (TREE_CODE (sym
) == MEMORY_PARTITION_TAG
)
864 gcc_assert (!is_gimple_reg (sym
));
865 tag
= get_var_ann (sym
)->mpt
;
867 #if defined ENABLE_CHECKING
869 gcc_assert (TREE_CODE (tag
) == MEMORY_PARTITION_TAG
);
875 /* Return true if NAME is a memory factoring SSA name (i.e., an SSA
876 name for a memory partition. */
879 factoring_name_p (const_tree name
)
881 return TREE_CODE (SSA_NAME_VAR (name
)) == MEMORY_PARTITION_TAG
;
884 /* Return true if VAR is a clobbered by function calls. */
886 is_call_clobbered (const_tree var
)
888 return var_ann (var
)->call_clobbered
;
891 /* Mark variable VAR as being clobbered by function calls. */
893 mark_call_clobbered (tree var
, unsigned int escape_type
)
895 var_ann (var
)->escape_mask
|= escape_type
;
896 var_ann (var
)->call_clobbered
= true;
897 bitmap_set_bit (gimple_call_clobbered_vars (cfun
), DECL_UID (var
));
900 /* Clear the call-clobbered attribute from variable VAR. */
902 clear_call_clobbered (tree var
)
904 var_ann_t ann
= var_ann (var
);
905 ann
->escape_mask
= 0;
907 MTAG_GLOBAL (var
) = 0;
908 var_ann (var
)->call_clobbered
= false;
909 bitmap_clear_bit (gimple_call_clobbered_vars (cfun
), DECL_UID (var
));
912 /* Return the common annotation for T. Return NULL if the annotation
913 doesn't already exist. */
914 static inline tree_ann_common_t
915 tree_common_ann (const_tree t
)
917 /* Watch out static variables with unshared annotations. */
918 if (DECL_P (t
) && TREE_CODE (t
) == VAR_DECL
)
919 return &var_ann (t
)->common
;
920 return &t
->base
.ann
->common
;
923 /* Return a common annotation for T. Create the constant annotation if it
925 static inline tree_ann_common_t
926 get_tree_common_ann (tree t
)
928 tree_ann_common_t ann
= tree_common_ann (t
);
929 return (ann
) ? ann
: create_tree_common_ann (t
);
932 /* ----------------------------------------------------------------------- */
934 /* The following set of routines are used to iterator over various type of
937 /* Return true if PTR is finished iterating. */
939 op_iter_done (const ssa_op_iter
*ptr
)
944 /* Get the next iterator use value for PTR. */
945 static inline use_operand_p
946 op_iter_next_use (ssa_op_iter
*ptr
)
949 #ifdef ENABLE_CHECKING
950 gcc_assert (ptr
->iter_type
== ssa_op_iter_use
);
954 use_p
= USE_OP_PTR (ptr
->uses
);
955 ptr
->uses
= ptr
->uses
->next
;
960 use_p
= VUSE_OP_PTR (ptr
->vuses
, ptr
->vuse_index
);
961 if (++(ptr
->vuse_index
) >= VUSE_NUM (ptr
->vuses
))
964 ptr
->vuses
= ptr
->vuses
->next
;
970 use_p
= VDEF_OP_PTR (ptr
->mayuses
, ptr
->mayuse_index
);
971 if (++(ptr
->mayuse_index
) >= VDEF_NUM (ptr
->mayuses
))
973 ptr
->mayuse_index
= 0;
974 ptr
->mayuses
= ptr
->mayuses
->next
;
978 if (ptr
->phi_i
< ptr
->num_phi
)
980 return PHI_ARG_DEF_PTR (ptr
->phi_stmt
, (ptr
->phi_i
)++);
983 return NULL_USE_OPERAND_P
;
986 /* Get the next iterator def value for PTR. */
987 static inline def_operand_p
988 op_iter_next_def (ssa_op_iter
*ptr
)
991 #ifdef ENABLE_CHECKING
992 gcc_assert (ptr
->iter_type
== ssa_op_iter_def
);
996 def_p
= DEF_OP_PTR (ptr
->defs
);
997 ptr
->defs
= ptr
->defs
->next
;
1002 def_p
= VDEF_RESULT_PTR (ptr
->vdefs
);
1003 ptr
->vdefs
= ptr
->vdefs
->next
;
1007 return NULL_DEF_OPERAND_P
;
1010 /* Get the next iterator tree value for PTR. */
1012 op_iter_next_tree (ssa_op_iter
*ptr
)
1015 #ifdef ENABLE_CHECKING
1016 gcc_assert (ptr
->iter_type
== ssa_op_iter_tree
);
1020 val
= USE_OP (ptr
->uses
);
1021 ptr
->uses
= ptr
->uses
->next
;
1026 val
= VUSE_OP (ptr
->vuses
, ptr
->vuse_index
);
1027 if (++(ptr
->vuse_index
) >= VUSE_NUM (ptr
->vuses
))
1029 ptr
->vuse_index
= 0;
1030 ptr
->vuses
= ptr
->vuses
->next
;
1036 val
= VDEF_OP (ptr
->mayuses
, ptr
->mayuse_index
);
1037 if (++(ptr
->mayuse_index
) >= VDEF_NUM (ptr
->mayuses
))
1039 ptr
->mayuse_index
= 0;
1040 ptr
->mayuses
= ptr
->mayuses
->next
;
1046 val
= DEF_OP (ptr
->defs
);
1047 ptr
->defs
= ptr
->defs
->next
;
1052 val
= VDEF_RESULT (ptr
->vdefs
);
1053 ptr
->vdefs
= ptr
->vdefs
->next
;
1063 /* This functions clears the iterator PTR, and marks it done. This is normally
1064 used to prevent warnings in the compile about might be uninitialized
1068 clear_and_done_ssa_iter (ssa_op_iter
*ptr
)
1074 ptr
->mayuses
= NULL
;
1075 ptr
->iter_type
= ssa_op_iter_none
;
1078 ptr
->phi_stmt
= NULL_TREE
;
1080 ptr
->vuse_index
= 0;
1081 ptr
->mayuse_index
= 0;
1084 /* Initialize the iterator PTR to the virtual defs in STMT. */
1086 op_iter_init (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1088 #ifdef ENABLE_CHECKING
1089 gcc_assert (stmt_ann (stmt
));
1092 ptr
->defs
= (flags
& SSA_OP_DEF
) ? DEF_OPS (stmt
) : NULL
;
1093 ptr
->uses
= (flags
& SSA_OP_USE
) ? USE_OPS (stmt
) : NULL
;
1094 ptr
->vuses
= (flags
& SSA_OP_VUSE
) ? VUSE_OPS (stmt
) : NULL
;
1095 ptr
->vdefs
= (flags
& SSA_OP_VDEF
) ? VDEF_OPS (stmt
) : NULL
;
1096 ptr
->mayuses
= (flags
& SSA_OP_VMAYUSE
) ? VDEF_OPS (stmt
) : NULL
;
1101 ptr
->phi_stmt
= NULL_TREE
;
1102 ptr
->vuse_index
= 0;
1103 ptr
->mayuse_index
= 0;
1106 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1108 static inline use_operand_p
1109 op_iter_init_use (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1111 gcc_assert ((flags
& SSA_OP_ALL_DEFS
) == 0);
1112 op_iter_init (ptr
, stmt
, flags
);
1113 ptr
->iter_type
= ssa_op_iter_use
;
1114 return op_iter_next_use (ptr
);
1117 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1119 static inline def_operand_p
1120 op_iter_init_def (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1122 gcc_assert ((flags
& SSA_OP_ALL_USES
) == 0);
1123 op_iter_init (ptr
, stmt
, flags
);
1124 ptr
->iter_type
= ssa_op_iter_def
;
1125 return op_iter_next_def (ptr
);
1128 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1129 the first operand as a tree. */
1131 op_iter_init_tree (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1133 op_iter_init (ptr
, stmt
, flags
);
1134 ptr
->iter_type
= ssa_op_iter_tree
;
1135 return op_iter_next_tree (ptr
);
1138 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1141 op_iter_next_vdef (vuse_vec_p
*use
, def_operand_p
*def
,
1144 #ifdef ENABLE_CHECKING
1145 gcc_assert (ptr
->iter_type
== ssa_op_iter_vdef
);
1149 *def
= VDEF_RESULT_PTR (ptr
->mayuses
);
1150 *use
= VDEF_VECT (ptr
->mayuses
);
1151 ptr
->mayuses
= ptr
->mayuses
->next
;
1155 *def
= NULL_DEF_OPERAND_P
;
1163 op_iter_next_mustdef (use_operand_p
*use
, def_operand_p
*def
,
1167 op_iter_next_vdef (&vp
, def
, ptr
);
1170 gcc_assert (VUSE_VECT_NUM_ELEM (*vp
) == 1);
1171 *use
= VUSE_ELEMENT_PTR (*vp
, 0);
1174 *use
= NULL_USE_OPERAND_P
;
1177 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1180 op_iter_init_vdef (ssa_op_iter
*ptr
, tree stmt
, vuse_vec_p
*use
,
1183 gcc_assert (TREE_CODE (stmt
) != PHI_NODE
);
1185 op_iter_init (ptr
, stmt
, SSA_OP_VMAYUSE
);
1186 ptr
->iter_type
= ssa_op_iter_vdef
;
1187 op_iter_next_vdef (use
, def
, ptr
);
1191 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1194 single_ssa_tree_operand (tree stmt
, int flags
)
1199 var
= op_iter_init_tree (&iter
, stmt
, flags
);
1200 if (op_iter_done (&iter
))
1202 op_iter_next_tree (&iter
);
1203 if (op_iter_done (&iter
))
1209 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1211 static inline use_operand_p
1212 single_ssa_use_operand (tree stmt
, int flags
)
1217 var
= op_iter_init_use (&iter
, stmt
, flags
);
1218 if (op_iter_done (&iter
))
1219 return NULL_USE_OPERAND_P
;
1220 op_iter_next_use (&iter
);
1221 if (op_iter_done (&iter
))
1223 return NULL_USE_OPERAND_P
;
1228 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1230 static inline def_operand_p
1231 single_ssa_def_operand (tree stmt
, int flags
)
1236 var
= op_iter_init_def (&iter
, stmt
, flags
);
1237 if (op_iter_done (&iter
))
1238 return NULL_DEF_OPERAND_P
;
1239 op_iter_next_def (&iter
);
1240 if (op_iter_done (&iter
))
1242 return NULL_DEF_OPERAND_P
;
1246 /* Return true if there are zero operands in STMT matching the type
1249 zero_ssa_operands (tree stmt
, int flags
)
1253 op_iter_init_tree (&iter
, stmt
, flags
);
1254 return op_iter_done (&iter
);
1258 /* Return the number of operands matching FLAGS in STMT. */
1260 num_ssa_operands (tree stmt
, int flags
)
1266 FOR_EACH_SSA_TREE_OPERAND (t
, stmt
, iter
, flags
)
1272 /* Delink all immediate_use information for STMT. */
1274 delink_stmt_imm_use (tree stmt
)
1277 use_operand_p use_p
;
1279 if (ssa_operands_active ())
1280 FOR_EACH_SSA_USE_OPERAND (use_p
, stmt
, iter
, SSA_OP_ALL_USES
)
1281 delink_imm_use (use_p
);
1285 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1286 in STMT2. TRUE is returned if they are the same. STMTs can be NULL. */
1288 compare_ssa_operands_equal (tree stmt1
, tree stmt2
, int flags
)
1290 ssa_op_iter iter1
, iter2
;
1291 tree op1
= NULL_TREE
;
1292 tree op2
= NULL_TREE
;
1298 look1
= stmt1
&& stmt_ann (stmt1
);
1299 look2
= stmt2
&& stmt_ann (stmt2
);
1303 op1
= op_iter_init_tree (&iter1
, stmt1
, flags
);
1305 return op_iter_done (&iter1
);
1308 clear_and_done_ssa_iter (&iter1
);
1312 op2
= op_iter_init_tree (&iter2
, stmt2
, flags
);
1314 return op_iter_done (&iter2
);
1317 clear_and_done_ssa_iter (&iter2
);
1319 while (!op_iter_done (&iter1
) && !op_iter_done (&iter2
))
1323 op1
= op_iter_next_tree (&iter1
);
1324 op2
= op_iter_next_tree (&iter2
);
1327 return (op_iter_done (&iter1
) && op_iter_done (&iter2
));
1331 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1332 Otherwise return NULL_DEF_OPERAND_P. */
1334 single_phi_def (tree stmt
, int flags
)
1336 tree def
= PHI_RESULT (stmt
);
1337 if ((flags
& SSA_OP_DEF
) && is_gimple_reg (def
))
1339 if ((flags
& SSA_OP_VIRTUAL_DEFS
) && !is_gimple_reg (def
))
1344 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
1345 be either SSA_OP_USES or SSA_OP_VIRTUAL_USES. */
1346 static inline use_operand_p
1347 op_iter_init_phiuse (ssa_op_iter
*ptr
, tree phi
, int flags
)
1349 tree phi_def
= PHI_RESULT (phi
);
1352 clear_and_done_ssa_iter (ptr
);
1355 gcc_assert ((flags
& (SSA_OP_USE
| SSA_OP_VIRTUAL_USES
)) != 0);
1357 comp
= (is_gimple_reg (phi_def
) ? SSA_OP_USE
: SSA_OP_VIRTUAL_USES
);
1359 /* If the PHI node doesn't the operand type we care about, we're done. */
1360 if ((flags
& comp
) == 0)
1363 return NULL_USE_OPERAND_P
;
1366 ptr
->phi_stmt
= phi
;
1367 ptr
->num_phi
= PHI_NUM_ARGS (phi
);
1368 ptr
->iter_type
= ssa_op_iter_use
;
1369 return op_iter_next_use (ptr
);
1373 /* Start an iterator for a PHI definition. */
1375 static inline def_operand_p
1376 op_iter_init_phidef (ssa_op_iter
*ptr
, tree phi
, int flags
)
1378 tree phi_def
= PHI_RESULT (phi
);
1381 clear_and_done_ssa_iter (ptr
);
1384 gcc_assert ((flags
& (SSA_OP_DEF
| SSA_OP_VIRTUAL_DEFS
)) != 0);
1386 comp
= (is_gimple_reg (phi_def
) ? SSA_OP_DEF
: SSA_OP_VIRTUAL_DEFS
);
1388 /* If the PHI node doesn't the operand type we care about, we're done. */
1389 if ((flags
& comp
) == 0)
1392 return NULL_USE_OPERAND_P
;
1395 ptr
->iter_type
= ssa_op_iter_def
;
1396 /* The first call to op_iter_next_def will terminate the iterator since
1397 all the fields are NULL. Simply return the result here as the first and
1398 therefore only result. */
1399 return PHI_RESULT_PTR (phi
);
1402 /* Return true is IMM has reached the end of the immediate use stmt list. */
1405 end_imm_use_stmt_p (const imm_use_iterator
*imm
)
1407 return (imm
->imm_use
== imm
->end_p
);
1410 /* Finished the traverse of an immediate use stmt list IMM by removing the
1411 placeholder node from the list. */
1414 end_imm_use_stmt_traverse (imm_use_iterator
*imm
)
1416 delink_imm_use (&(imm
->iter_node
));
1419 /* Immediate use traversal of uses within a stmt require that all the
1420 uses on a stmt be sequentially listed. This routine is used to build up
1421 this sequential list by adding USE_P to the end of the current list
1422 currently delimited by HEAD and LAST_P. The new LAST_P value is
1425 static inline use_operand_p
1426 move_use_after_head (use_operand_p use_p
, use_operand_p head
,
1427 use_operand_p last_p
)
1429 gcc_assert (USE_FROM_PTR (use_p
) == USE_FROM_PTR (head
));
1430 /* Skip head when we find it. */
1433 /* If use_p is already linked in after last_p, continue. */
1434 if (last_p
->next
== use_p
)
1438 /* Delink from current location, and link in at last_p. */
1439 delink_imm_use (use_p
);
1440 link_imm_use_to_list (use_p
, last_p
);
1448 /* This routine will relink all uses with the same stmt as HEAD into the list
1449 immediately following HEAD for iterator IMM. */
1452 link_use_stmts_after (use_operand_p head
, imm_use_iterator
*imm
)
1454 use_operand_p use_p
;
1455 use_operand_p last_p
= head
;
1456 tree head_stmt
= USE_STMT (head
);
1457 tree use
= USE_FROM_PTR (head
);
1458 ssa_op_iter op_iter
;
1461 /* Only look at virtual or real uses, depending on the type of HEAD. */
1462 flag
= (is_gimple_reg (use
) ? SSA_OP_USE
: SSA_OP_VIRTUAL_USES
);
1464 if (TREE_CODE (head_stmt
) == PHI_NODE
)
1466 FOR_EACH_PHI_ARG (use_p
, head_stmt
, op_iter
, flag
)
1467 if (USE_FROM_PTR (use_p
) == use
)
1468 last_p
= move_use_after_head (use_p
, head
, last_p
);
1472 FOR_EACH_SSA_USE_OPERAND (use_p
, head_stmt
, op_iter
, flag
)
1473 if (USE_FROM_PTR (use_p
) == use
)
1474 last_p
= move_use_after_head (use_p
, head
, last_p
);
1476 /* Link iter node in after last_p. */
1477 if (imm
->iter_node
.prev
!= NULL
)
1478 delink_imm_use (&imm
->iter_node
);
1479 link_imm_use_to_list (&(imm
->iter_node
), last_p
);
1482 /* Initialize IMM to traverse over uses of VAR. Return the first statement. */
1484 first_imm_use_stmt (imm_use_iterator
*imm
, tree var
)
1486 gcc_assert (TREE_CODE (var
) == SSA_NAME
);
1488 imm
->end_p
= &(SSA_NAME_IMM_USE_NODE (var
));
1489 imm
->imm_use
= imm
->end_p
->next
;
1490 imm
->next_imm_name
= NULL_USE_OPERAND_P
;
1492 /* iter_node is used as a marker within the immediate use list to indicate
1493 where the end of the current stmt's uses are. Initialize it to NULL
1494 stmt and use, which indicates a marker node. */
1495 imm
->iter_node
.prev
= NULL_USE_OPERAND_P
;
1496 imm
->iter_node
.next
= NULL_USE_OPERAND_P
;
1497 imm
->iter_node
.stmt
= NULL_TREE
;
1498 imm
->iter_node
.use
= NULL_USE_OPERAND_P
;
1500 if (end_imm_use_stmt_p (imm
))
1503 link_use_stmts_after (imm
->imm_use
, imm
);
1505 return USE_STMT (imm
->imm_use
);
1508 /* Bump IMM to the next stmt which has a use of var. */
1511 next_imm_use_stmt (imm_use_iterator
*imm
)
1513 imm
->imm_use
= imm
->iter_node
.next
;
1514 if (end_imm_use_stmt_p (imm
))
1516 if (imm
->iter_node
.prev
!= NULL
)
1517 delink_imm_use (&imm
->iter_node
);
1521 link_use_stmts_after (imm
->imm_use
, imm
);
1522 return USE_STMT (imm
->imm_use
);
1525 /* This routine will return the first use on the stmt IMM currently refers
1528 static inline use_operand_p
1529 first_imm_use_on_stmt (imm_use_iterator
*imm
)
1531 imm
->next_imm_name
= imm
->imm_use
->next
;
1532 return imm
->imm_use
;
1535 /* Return TRUE if the last use on the stmt IMM refers to has been visited. */
1538 end_imm_use_on_stmt_p (const imm_use_iterator
*imm
)
1540 return (imm
->imm_use
== &(imm
->iter_node
));
1543 /* Bump to the next use on the stmt IMM refers to, return NULL if done. */
1545 static inline use_operand_p
1546 next_imm_use_on_stmt (imm_use_iterator
*imm
)
1548 imm
->imm_use
= imm
->next_imm_name
;
1549 if (end_imm_use_on_stmt_p (imm
))
1550 return NULL_USE_OPERAND_P
;
1553 imm
->next_imm_name
= imm
->imm_use
->next
;
1554 return imm
->imm_use
;
1558 /* Return true if VAR cannot be modified by the program. */
1561 unmodifiable_var_p (const_tree var
)
1563 if (TREE_CODE (var
) == SSA_NAME
)
1564 var
= SSA_NAME_VAR (var
);
1569 return TREE_READONLY (var
) && (TREE_STATIC (var
) || DECL_EXTERNAL (var
));
1572 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it. */
1575 array_ref_contains_indirect_ref (const_tree ref
)
1577 gcc_assert (TREE_CODE (ref
) == ARRAY_REF
);
1580 ref
= TREE_OPERAND (ref
, 0);
1581 } while (handled_component_p (ref
));
1583 return TREE_CODE (ref
) == INDIRECT_REF
;
1586 /* Return true if REF, a handled component reference, has an ARRAY_REF
1590 ref_contains_array_ref (const_tree ref
)
1592 gcc_assert (handled_component_p (ref
));
1595 if (TREE_CODE (ref
) == ARRAY_REF
)
1597 ref
= TREE_OPERAND (ref
, 0);
1598 } while (handled_component_p (ref
));
1603 /* Return true, if the two ranges [POS1, SIZE1] and [POS2, SIZE2]
1604 overlap. SIZE1 and/or SIZE2 can be (unsigned)-1 in which case the
1605 range is open-ended. Otherwise return false. */
1608 ranges_overlap_p (unsigned HOST_WIDE_INT pos1
,
1609 unsigned HOST_WIDE_INT size1
,
1610 unsigned HOST_WIDE_INT pos2
,
1611 unsigned HOST_WIDE_INT size2
)
1614 && (size2
== (unsigned HOST_WIDE_INT
)-1
1615 || pos1
< (pos2
+ size2
)))
1618 && (size1
== (unsigned HOST_WIDE_INT
)-1
1619 || pos2
< (pos1
+ size1
)))
1625 /* Return the memory tag associated with symbol SYM. */
1628 symbol_mem_tag (tree sym
)
1630 tree tag
= get_var_ann (sym
)->symbol_mem_tag
;
1632 #if defined ENABLE_CHECKING
1634 gcc_assert (TREE_CODE (tag
) == SYMBOL_MEMORY_TAG
);
1641 /* Set the memory tag associated with symbol SYM. */
1644 set_symbol_mem_tag (tree sym
, tree tag
)
1646 #if defined ENABLE_CHECKING
1648 gcc_assert (TREE_CODE (tag
) == SYMBOL_MEMORY_TAG
);
1651 get_var_ann (sym
)->symbol_mem_tag
= tag
;
1654 /* Get the value handle of EXPR. This is the only correct way to get
1655 the value handle for a "thing". If EXPR does not have a value
1656 handle associated, it returns NULL_TREE.
1657 NB: If EXPR is min_invariant, this function is *required* to return
1661 get_value_handle (tree expr
)
1663 if (TREE_CODE (expr
) == SSA_NAME
)
1664 return SSA_NAME_VALUE (expr
);
1665 else if (DECL_P (expr
) || TREE_CODE (expr
) == TREE_LIST
1666 || TREE_CODE (expr
) == CONSTRUCTOR
)
1668 tree_ann_common_t ann
= tree_common_ann (expr
);
1669 return ((ann
) ? ann
->value_handle
: NULL_TREE
);
1671 else if (is_gimple_min_invariant (expr
))
1673 else if (EXPR_P (expr
))
1675 tree_ann_common_t ann
= tree_common_ann (expr
);
1676 return ((ann
) ? ann
->value_handle
: NULL_TREE
);
1682 /* Accessor to tree-ssa-operands.c caches. */
1683 static inline struct ssa_operands
*
1684 gimple_ssa_operands (const struct function
*fun
)
1686 return &fun
->gimple_df
->ssa_operands
;
1689 /* Map describing reference statistics for function FN. */
1690 static inline struct mem_ref_stats_d
*
1691 gimple_mem_ref_stats (const struct function
*fn
)
1693 return &fn
->gimple_df
->mem_ref_stats
;
1696 /* Given an edge_var_map V, return the PHI arg definition. */
1699 redirect_edge_var_map_def (edge_var_map
*v
)
1704 /* Given an edge_var_map V, return the PHI result. */
1707 redirect_edge_var_map_result (edge_var_map
*v
)
1713 /* Return an SSA_NAME node for variable VAR defined in statement STMT
1714 in function cfun. */
1717 make_ssa_name (tree var
, tree stmt
)
1719 return make_ssa_name_fn (cfun
, var
, stmt
);
1722 #endif /* _TREE_FLOW_INLINE_H */