1 /* Inline functions for tree-flow.h
2 Copyright (C) 2001, 2003, 2005, 2006 Free Software Foundation, Inc.
3 Contributed by Diego Novillo <dnovillo@redhat.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 #ifndef _TREE_FLOW_INLINE_H
23 #define _TREE_FLOW_INLINE_H 1
25 /* Inline functions for manipulating various data structures defined in
26 tree-flow.h. See tree-flow.h for documentation. */
28 /* Initialize the hashtable iterator HTI to point to hashtable TABLE */
31 first_htab_element (htab_iterator
*hti
, htab_t table
)
34 hti
->slot
= table
->entries
;
35 hti
->limit
= hti
->slot
+ htab_size (table
);
39 if (x
!= HTAB_EMPTY_ENTRY
&& x
!= HTAB_DELETED_ENTRY
)
41 } while (++(hti
->slot
) < hti
->limit
);
43 if (hti
->slot
< hti
->limit
)
48 /* Return current non-empty/deleted slot of the hashtable pointed to by HTI,
49 or NULL if we have reached the end. */
52 end_htab_p (htab_iterator
*hti
)
54 if (hti
->slot
>= hti
->limit
)
59 /* Advance the hashtable iterator pointed to by HTI to the next element of the
63 next_htab_element (htab_iterator
*hti
)
65 while (++(hti
->slot
) < hti
->limit
)
68 if (x
!= HTAB_EMPTY_ENTRY
&& x
!= HTAB_DELETED_ENTRY
)
74 /* Initialize ITER to point to the first referenced variable in the
75 referenced_vars hashtable, and return that variable. */
78 first_referenced_var (referenced_var_iterator
*iter
)
80 struct int_tree_map
*itm
;
81 itm
= (struct int_tree_map
*) first_htab_element (&iter
->hti
,
88 /* Return true if we have hit the end of the referenced variables ITER is
92 end_referenced_vars_p (referenced_var_iterator
*iter
)
94 return end_htab_p (&iter
->hti
);
97 /* Make ITER point to the next referenced_var in the referenced_var hashtable,
98 and return that variable. */
101 next_referenced_var (referenced_var_iterator
*iter
)
103 struct int_tree_map
*itm
;
104 itm
= (struct int_tree_map
*) next_htab_element (&iter
->hti
);
110 /* Fill up VEC with the variables in the referenced vars hashtable. */
113 fill_referenced_var_vec (VEC (tree
, heap
) **vec
)
115 referenced_var_iterator rvi
;
118 FOR_EACH_REFERENCED_VAR (var
, rvi
)
119 VEC_safe_push (tree
, heap
, *vec
, var
);
122 /* Return the variable annotation for T, which must be a _DECL node.
123 Return NULL if the variable annotation doesn't already exist. */
124 static inline var_ann_t
128 gcc_assert (DECL_P (t
));
129 gcc_assert (TREE_CODE (t
) != FUNCTION_DECL
);
130 gcc_assert (!t
->common
.ann
|| t
->common
.ann
->common
.type
== VAR_ANN
);
132 return (var_ann_t
) t
->common
.ann
;
135 /* Return the variable annotation for T, which must be a _DECL node.
136 Create the variable annotation if it doesn't exist. */
137 static inline var_ann_t
138 get_var_ann (tree var
)
140 var_ann_t ann
= var_ann (var
);
141 return (ann
) ? ann
: create_var_ann (var
);
144 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
145 Return NULL if the function annotation doesn't already exist. */
146 static inline function_ann_t
147 function_ann (tree t
)
150 gcc_assert (TREE_CODE (t
) == FUNCTION_DECL
);
151 gcc_assert (!t
->common
.ann
|| t
->common
.ann
->common
.type
== FUNCTION_ANN
);
153 return (function_ann_t
) t
->common
.ann
;
156 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
157 Create the function annotation if it doesn't exist. */
158 static inline function_ann_t
159 get_function_ann (tree var
)
161 function_ann_t ann
= function_ann (var
);
162 gcc_assert (!var
->common
.ann
|| var
->common
.ann
->common
.type
== FUNCTION_ANN
);
163 return (ann
) ? ann
: create_function_ann (var
);
166 /* Return the statement annotation for T, which must be a statement
167 node. Return NULL if the statement annotation doesn't exist. */
168 static inline stmt_ann_t
171 #ifdef ENABLE_CHECKING
172 gcc_assert (is_gimple_stmt (t
));
174 gcc_assert (!t
->common
.ann
|| t
->common
.ann
->common
.type
== STMT_ANN
);
175 return (stmt_ann_t
) t
->common
.ann
;
178 /* Return the statement annotation for T, which must be a statement
179 node. Create the statement annotation if it doesn't exist. */
180 static inline stmt_ann_t
181 get_stmt_ann (tree stmt
)
183 stmt_ann_t ann
= stmt_ann (stmt
);
184 return (ann
) ? ann
: create_stmt_ann (stmt
);
187 /* Return the annotation type for annotation ANN. */
188 static inline enum tree_ann_type
189 ann_type (tree_ann_t ann
)
191 return ann
->common
.type
;
194 /* Return the basic block for statement T. */
195 static inline basic_block
200 if (TREE_CODE (t
) == PHI_NODE
)
204 return ann
? ann
->bb
: NULL
;
207 /* Return the may_aliases varray for variable VAR, or NULL if it has
209 static inline VEC(tree
, gc
) *
210 may_aliases (tree var
)
212 var_ann_t ann
= var_ann (var
);
213 return ann
? ann
->may_aliases
: NULL
;
216 /* Return the line number for EXPR, or return -1 if we have no line
217 number information for it. */
219 get_lineno (tree expr
)
221 if (expr
== NULL_TREE
)
224 if (TREE_CODE (expr
) == COMPOUND_EXPR
)
225 expr
= TREE_OPERAND (expr
, 0);
227 if (! EXPR_HAS_LOCATION (expr
))
230 return EXPR_LINENO (expr
);
233 /* Return the file name for EXPR, or return "???" if we have no
234 filename information. */
235 static inline const char *
236 get_filename (tree expr
)
238 const char *filename
;
239 if (expr
== NULL_TREE
)
242 if (TREE_CODE (expr
) == COMPOUND_EXPR
)
243 expr
= TREE_OPERAND (expr
, 0);
245 if (EXPR_HAS_LOCATION (expr
) && (filename
= EXPR_FILENAME (expr
)))
251 /* Return true if T is a noreturn call. */
253 noreturn_call_p (tree t
)
255 tree call
= get_call_expr_in (t
);
256 return call
!= 0 && (call_expr_flags (call
) & ECF_NORETURN
) != 0;
259 /* Mark statement T as modified. */
261 mark_stmt_modified (tree t
)
264 if (TREE_CODE (t
) == PHI_NODE
)
269 ann
= create_stmt_ann (t
);
270 else if (noreturn_call_p (t
))
271 VEC_safe_push (tree
, gc
, modified_noreturn_calls
, t
);
275 /* Mark statement T as modified, and update it. */
279 if (TREE_CODE (t
) == PHI_NODE
)
281 mark_stmt_modified (t
);
282 update_stmt_operands (t
);
286 update_stmt_if_modified (tree t
)
288 if (stmt_modified_p (t
))
289 update_stmt_operands (t
);
292 /* Return true if T is marked as modified, false otherwise. */
294 stmt_modified_p (tree t
)
296 stmt_ann_t ann
= stmt_ann (t
);
298 /* Note that if the statement doesn't yet have an annotation, we consider it
299 modified. This will force the next call to update_stmt_operands to scan
301 return ann
? ann
->modified
: true;
304 /* Delink an immediate_uses node from its chain. */
306 delink_imm_use (ssa_use_operand_t
*linknode
)
308 /* Return if this node is not in a list. */
309 if (linknode
->prev
== NULL
)
312 linknode
->prev
->next
= linknode
->next
;
313 linknode
->next
->prev
= linknode
->prev
;
314 linknode
->prev
= NULL
;
315 linknode
->next
= NULL
;
318 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
320 link_imm_use_to_list (ssa_use_operand_t
*linknode
, ssa_use_operand_t
*list
)
322 /* Link the new node at the head of the list. If we are in the process of
323 traversing the list, we won't visit any new nodes added to it. */
324 linknode
->prev
= list
;
325 linknode
->next
= list
->next
;
326 list
->next
->prev
= linknode
;
327 list
->next
= linknode
;
330 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
332 link_imm_use (ssa_use_operand_t
*linknode
, tree def
)
334 ssa_use_operand_t
*root
;
336 if (!def
|| TREE_CODE (def
) != SSA_NAME
)
337 linknode
->prev
= NULL
;
340 root
= &(SSA_NAME_IMM_USE_NODE (def
));
341 #ifdef ENABLE_CHECKING
343 gcc_assert (*(linknode
->use
) == def
);
345 link_imm_use_to_list (linknode
, root
);
349 /* Set the value of a use pointed to by USE to VAL. */
351 set_ssa_use_from_ptr (use_operand_p use
, tree val
)
353 delink_imm_use (use
);
355 link_imm_use (use
, val
);
358 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
361 link_imm_use_stmt (ssa_use_operand_t
*linknode
, tree def
, tree stmt
)
364 link_imm_use (linknode
, def
);
366 link_imm_use (linknode
, NULL
);
367 linknode
->stmt
= stmt
;
370 /* Relink a new node in place of an old node in the list. */
372 relink_imm_use (ssa_use_operand_t
*node
, ssa_use_operand_t
*old
)
374 /* The node one had better be in the same list. */
375 gcc_assert (*(old
->use
) == *(node
->use
));
376 node
->prev
= old
->prev
;
377 node
->next
= old
->next
;
380 old
->prev
->next
= node
;
381 old
->next
->prev
= node
;
382 /* Remove the old node from the list. */
387 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
390 relink_imm_use_stmt (ssa_use_operand_t
*linknode
, ssa_use_operand_t
*old
, tree stmt
)
393 relink_imm_use (linknode
, old
);
395 link_imm_use (linknode
, NULL
);
396 linknode
->stmt
= stmt
;
400 /* Return true is IMM has reached the end of the immediate use list. */
402 end_readonly_imm_use_p (imm_use_iterator
*imm
)
404 return (imm
->imm_use
== imm
->end_p
);
407 /* Initialize iterator IMM to process the list for VAR. */
408 static inline use_operand_p
409 first_readonly_imm_use (imm_use_iterator
*imm
, tree var
)
411 gcc_assert (TREE_CODE (var
) == SSA_NAME
);
413 imm
->end_p
= &(SSA_NAME_IMM_USE_NODE (var
));
414 imm
->imm_use
= imm
->end_p
->next
;
415 #ifdef ENABLE_CHECKING
416 imm
->iter_node
.next
= imm
->imm_use
->next
;
418 if (end_readonly_imm_use_p (imm
))
419 return NULL_USE_OPERAND_P
;
423 /* Bump IMM to the next use in the list. */
424 static inline use_operand_p
425 next_readonly_imm_use (imm_use_iterator
*imm
)
427 use_operand_p old
= imm
->imm_use
;
429 #ifdef ENABLE_CHECKING
430 /* If this assertion fails, it indicates the 'next' pointer has changed
431 since we the last bump. This indicates that the list is being modified
432 via stmt changes, or SET_USE, or somesuch thing, and you need to be
433 using the SAFE version of the iterator. */
434 gcc_assert (imm
->iter_node
.next
== old
->next
);
435 imm
->iter_node
.next
= old
->next
->next
;
438 imm
->imm_use
= old
->next
;
439 if (end_readonly_imm_use_p (imm
))
444 /* Return true if VAR has no uses. */
446 has_zero_uses (tree var
)
448 ssa_use_operand_t
*ptr
;
449 ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
450 /* A single use means there is no items in the list. */
451 return (ptr
== ptr
->next
);
454 /* Return true if VAR has a single use. */
456 has_single_use (tree var
)
458 ssa_use_operand_t
*ptr
;
459 ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
460 /* A single use means there is one item in the list. */
461 return (ptr
!= ptr
->next
&& ptr
== ptr
->next
->next
);
464 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
465 to the use pointer and stmt of occurrence. */
467 single_imm_use (tree var
, use_operand_p
*use_p
, tree
*stmt
)
469 ssa_use_operand_t
*ptr
;
471 ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
472 if (ptr
!= ptr
->next
&& ptr
== ptr
->next
->next
)
475 *stmt
= ptr
->next
->stmt
;
478 *use_p
= NULL_USE_OPERAND_P
;
483 /* Return the number of immediate uses of VAR. */
484 static inline unsigned int
485 num_imm_uses (tree var
)
487 ssa_use_operand_t
*ptr
, *start
;
490 start
= &(SSA_NAME_IMM_USE_NODE (var
));
492 for (ptr
= start
->next
; ptr
!= start
; ptr
= ptr
->next
)
499 /* Return the tree pointer to by USE. */
501 get_use_from_ptr (use_operand_p use
)
506 /* Return the tree pointer to by DEF. */
508 get_def_from_ptr (def_operand_p def
)
513 /* Return a def_operand_p pointer for the result of PHI. */
514 static inline def_operand_p
515 get_phi_result_ptr (tree phi
)
517 return &(PHI_RESULT_TREE (phi
));
520 /* Return a use_operand_p pointer for argument I of phinode PHI. */
521 static inline use_operand_p
522 get_phi_arg_def_ptr (tree phi
, int i
)
524 return &(PHI_ARG_IMM_USE_NODE (phi
,i
));
528 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
531 addresses_taken (tree stmt
)
533 stmt_ann_t ann
= stmt_ann (stmt
);
534 return ann
? ann
->addresses_taken
: NULL
;
537 /* Return the PHI nodes for basic block BB, or NULL if there are no
540 phi_nodes (basic_block bb
)
542 return bb
->phi_nodes
;
545 /* Set list of phi nodes of a basic block BB to L. */
548 set_phi_nodes (basic_block bb
, tree l
)
553 for (phi
= l
; phi
; phi
= PHI_CHAIN (phi
))
554 set_bb_for_stmt (phi
, bb
);
557 /* Return the phi argument which contains the specified use. */
560 phi_arg_index_from_use (use_operand_p use
)
562 struct phi_arg_d
*element
, *root
;
566 /* Since the use is the first thing in a PHI argument element, we can
567 calculate its index based on casting it to an argument, and performing
568 pointer arithmetic. */
570 phi
= USE_STMT (use
);
571 gcc_assert (TREE_CODE (phi
) == PHI_NODE
);
573 element
= (struct phi_arg_d
*)use
;
574 root
= &(PHI_ARG_ELT (phi
, 0));
575 index
= element
- root
;
577 #ifdef ENABLE_CHECKING
578 /* Make sure the calculation doesn't have any leftover bytes. If it does,
579 then imm_use is likely not the first element in phi_arg_d. */
581 (((char *)element
- (char *)root
) % sizeof (struct phi_arg_d
)) == 0);
582 gcc_assert (index
>= 0 && index
< PHI_ARG_CAPACITY (phi
));
588 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
591 set_is_used (tree var
)
593 var_ann_t ann
= get_var_ann (var
);
598 /* ----------------------------------------------------------------------- */
600 /* Return true if T is an executable statement. */
602 is_exec_stmt (tree t
)
604 return (t
&& !IS_EMPTY_STMT (t
) && t
!= error_mark_node
);
608 /* Return true if this stmt can be the target of a control transfer stmt such
611 is_label_stmt (tree t
)
614 switch (TREE_CODE (t
))
618 case CASE_LABEL_EXPR
:
626 /* PHI nodes should contain only ssa_names and invariants. A test
627 for ssa_name is definitely simpler; don't let invalid contents
628 slip in in the meantime. */
631 phi_ssa_name_p (tree t
)
633 if (TREE_CODE (t
) == SSA_NAME
)
635 #ifdef ENABLE_CHECKING
636 gcc_assert (is_gimple_min_invariant (t
));
641 /* ----------------------------------------------------------------------- */
643 /* Return a block_stmt_iterator that points to beginning of basic
645 static inline block_stmt_iterator
646 bsi_start (basic_block bb
)
648 block_stmt_iterator bsi
;
650 bsi
.tsi
= tsi_start (bb
->stmt_list
);
653 gcc_assert (bb
->index
< NUM_FIXED_BLOCKS
);
655 bsi
.tsi
.container
= NULL
;
661 /* Return a block statement iterator that points to the first non-label
662 statement in block BB. */
664 static inline block_stmt_iterator
665 bsi_after_labels (basic_block bb
)
667 block_stmt_iterator bsi
= bsi_start (bb
);
669 while (!bsi_end_p (bsi
) && TREE_CODE (bsi_stmt (bsi
)) == LABEL_EXPR
)
675 /* Return a block statement iterator that points to the end of basic
677 static inline block_stmt_iterator
678 bsi_last (basic_block bb
)
680 block_stmt_iterator bsi
;
682 bsi
.tsi
= tsi_last (bb
->stmt_list
);
685 gcc_assert (bb
->index
< NUM_FIXED_BLOCKS
);
687 bsi
.tsi
.container
= NULL
;
693 /* Return true if block statement iterator I has reached the end of
696 bsi_end_p (block_stmt_iterator i
)
698 return tsi_end_p (i
.tsi
);
701 /* Modify block statement iterator I so that it is at the next
702 statement in the basic block. */
704 bsi_next (block_stmt_iterator
*i
)
709 /* Modify block statement iterator I so that it is at the previous
710 statement in the basic block. */
712 bsi_prev (block_stmt_iterator
*i
)
717 /* Return the statement that block statement iterator I is currently
720 bsi_stmt (block_stmt_iterator i
)
722 return tsi_stmt (i
.tsi
);
725 /* Return a pointer to the statement that block statement iterator I
728 bsi_stmt_ptr (block_stmt_iterator i
)
730 return tsi_stmt_ptr (i
.tsi
);
733 /* Returns the loop of the statement STMT. */
735 static inline struct loop
*
736 loop_containing_stmt (tree stmt
)
738 basic_block bb
= bb_for_stmt (stmt
);
742 return bb
->loop_father
;
745 /* Return true if VAR is a clobbered by function calls. */
747 is_call_clobbered (tree var
)
750 return DECL_CALL_CLOBBERED (var
);
752 return bitmap_bit_p (call_clobbered_vars
, DECL_UID (var
));
755 /* Mark variable VAR as being clobbered by function calls. */
757 mark_call_clobbered (tree var
, unsigned int escape_type
)
759 var_ann (var
)->escape_mask
|= escape_type
;
761 DECL_CALL_CLOBBERED (var
) = true;
762 bitmap_set_bit (call_clobbered_vars
, DECL_UID (var
));
765 /* Clear the call-clobbered attribute from variable VAR. */
767 clear_call_clobbered (tree var
)
769 var_ann_t ann
= var_ann (var
);
770 ann
->escape_mask
= 0;
771 if (MTAG_P (var
) && TREE_CODE (var
) != STRUCT_FIELD_TAG
)
772 MTAG_GLOBAL (var
) = 0;
774 DECL_CALL_CLOBBERED (var
) = false;
775 bitmap_clear_bit (call_clobbered_vars
, DECL_UID (var
));
778 /* Mark variable VAR as being non-addressable. */
780 mark_non_addressable (tree var
)
783 DECL_CALL_CLOBBERED (var
) = false;
784 bitmap_clear_bit (call_clobbered_vars
, DECL_UID (var
));
785 TREE_ADDRESSABLE (var
) = 0;
788 /* Return the common annotation for T. Return NULL if the annotation
789 doesn't already exist. */
790 static inline tree_ann_common_t
791 tree_common_ann (tree t
)
793 return &t
->common
.ann
->common
;
796 /* Return a common annotation for T. Create the constant annotation if it
798 static inline tree_ann_common_t
799 get_tree_common_ann (tree t
)
801 tree_ann_common_t ann
= tree_common_ann (t
);
802 return (ann
) ? ann
: create_tree_common_ann (t
);
805 /* ----------------------------------------------------------------------- */
807 /* The following set of routines are used to iterator over various type of
810 /* Return true if PTR is finished iterating. */
812 op_iter_done (ssa_op_iter
*ptr
)
817 /* Get the next iterator use value for PTR. */
818 static inline use_operand_p
819 op_iter_next_use (ssa_op_iter
*ptr
)
822 #ifdef ENABLE_CHECKING
823 gcc_assert (ptr
->iter_type
== ssa_op_iter_use
);
827 use_p
= USE_OP_PTR (ptr
->uses
);
828 ptr
->uses
= ptr
->uses
->next
;
833 use_p
= VUSE_OP_PTR (ptr
->vuses
);
834 ptr
->vuses
= ptr
->vuses
->next
;
839 use_p
= MAYDEF_OP_PTR (ptr
->mayuses
);
840 ptr
->mayuses
= ptr
->mayuses
->next
;
845 use_p
= MUSTDEF_KILL_PTR (ptr
->mustkills
);
846 ptr
->mustkills
= ptr
->mustkills
->next
;
849 if (ptr
->phi_i
< ptr
->num_phi
)
851 return PHI_ARG_DEF_PTR (ptr
->phi_stmt
, (ptr
->phi_i
)++);
854 return NULL_USE_OPERAND_P
;
857 /* Get the next iterator def value for PTR. */
858 static inline def_operand_p
859 op_iter_next_def (ssa_op_iter
*ptr
)
862 #ifdef ENABLE_CHECKING
863 gcc_assert (ptr
->iter_type
== ssa_op_iter_def
);
867 def_p
= DEF_OP_PTR (ptr
->defs
);
868 ptr
->defs
= ptr
->defs
->next
;
873 def_p
= MUSTDEF_RESULT_PTR (ptr
->mustdefs
);
874 ptr
->mustdefs
= ptr
->mustdefs
->next
;
879 def_p
= MAYDEF_RESULT_PTR (ptr
->maydefs
);
880 ptr
->maydefs
= ptr
->maydefs
->next
;
884 return NULL_DEF_OPERAND_P
;
887 /* Get the next iterator tree value for PTR. */
889 op_iter_next_tree (ssa_op_iter
*ptr
)
892 #ifdef ENABLE_CHECKING
893 gcc_assert (ptr
->iter_type
== ssa_op_iter_tree
);
897 val
= USE_OP (ptr
->uses
);
898 ptr
->uses
= ptr
->uses
->next
;
903 val
= VUSE_OP (ptr
->vuses
);
904 ptr
->vuses
= ptr
->vuses
->next
;
909 val
= MAYDEF_OP (ptr
->mayuses
);
910 ptr
->mayuses
= ptr
->mayuses
->next
;
915 val
= MUSTDEF_KILL (ptr
->mustkills
);
916 ptr
->mustkills
= ptr
->mustkills
->next
;
921 val
= DEF_OP (ptr
->defs
);
922 ptr
->defs
= ptr
->defs
->next
;
927 val
= MUSTDEF_RESULT (ptr
->mustdefs
);
928 ptr
->mustdefs
= ptr
->mustdefs
->next
;
933 val
= MAYDEF_RESULT (ptr
->maydefs
);
934 ptr
->maydefs
= ptr
->maydefs
->next
;
944 /* This functions clears the iterator PTR, and marks it done. This is normally
945 used to prevent warnings in the compile about might be uninitialized
949 clear_and_done_ssa_iter (ssa_op_iter
*ptr
)
956 ptr
->mustdefs
= NULL
;
957 ptr
->mustkills
= NULL
;
958 ptr
->iter_type
= ssa_op_iter_none
;
961 ptr
->phi_stmt
= NULL_TREE
;
965 /* Initialize the iterator PTR to the virtual defs in STMT. */
967 op_iter_init (ssa_op_iter
*ptr
, tree stmt
, int flags
)
969 #ifdef ENABLE_CHECKING
970 gcc_assert (stmt_ann (stmt
));
973 ptr
->defs
= (flags
& SSA_OP_DEF
) ? DEF_OPS (stmt
) : NULL
;
974 ptr
->uses
= (flags
& SSA_OP_USE
) ? USE_OPS (stmt
) : NULL
;
975 ptr
->vuses
= (flags
& SSA_OP_VUSE
) ? VUSE_OPS (stmt
) : NULL
;
976 ptr
->maydefs
= (flags
& SSA_OP_VMAYDEF
) ? MAYDEF_OPS (stmt
) : NULL
;
977 ptr
->mayuses
= (flags
& SSA_OP_VMAYUSE
) ? MAYDEF_OPS (stmt
) : NULL
;
978 ptr
->mustdefs
= (flags
& SSA_OP_VMUSTDEF
) ? MUSTDEF_OPS (stmt
) : NULL
;
979 ptr
->mustkills
= (flags
& SSA_OP_VMUSTKILL
) ? MUSTDEF_OPS (stmt
) : NULL
;
984 ptr
->phi_stmt
= NULL_TREE
;
987 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
989 static inline use_operand_p
990 op_iter_init_use (ssa_op_iter
*ptr
, tree stmt
, int flags
)
992 gcc_assert ((flags
& SSA_OP_ALL_DEFS
) == 0);
993 op_iter_init (ptr
, stmt
, flags
);
994 ptr
->iter_type
= ssa_op_iter_use
;
995 return op_iter_next_use (ptr
);
998 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1000 static inline def_operand_p
1001 op_iter_init_def (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1003 gcc_assert ((flags
& (SSA_OP_ALL_USES
| SSA_OP_VIRTUAL_KILLS
)) == 0);
1004 op_iter_init (ptr
, stmt
, flags
);
1005 ptr
->iter_type
= ssa_op_iter_def
;
1006 return op_iter_next_def (ptr
);
1009 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1010 the first operand as a tree. */
1012 op_iter_init_tree (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1014 op_iter_init (ptr
, stmt
, flags
);
1015 ptr
->iter_type
= ssa_op_iter_tree
;
1016 return op_iter_next_tree (ptr
);
1019 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1022 op_iter_next_maymustdef (use_operand_p
*use
, def_operand_p
*def
,
1025 #ifdef ENABLE_CHECKING
1026 gcc_assert (ptr
->iter_type
== ssa_op_iter_maymustdef
);
1030 *def
= MAYDEF_RESULT_PTR (ptr
->mayuses
);
1031 *use
= MAYDEF_OP_PTR (ptr
->mayuses
);
1032 ptr
->mayuses
= ptr
->mayuses
->next
;
1038 *def
= MUSTDEF_RESULT_PTR (ptr
->mustkills
);
1039 *use
= MUSTDEF_KILL_PTR (ptr
->mustkills
);
1040 ptr
->mustkills
= ptr
->mustkills
->next
;
1044 *def
= NULL_DEF_OPERAND_P
;
1045 *use
= NULL_USE_OPERAND_P
;
1051 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1054 op_iter_init_maydef (ssa_op_iter
*ptr
, tree stmt
, use_operand_p
*use
,
1057 gcc_assert (TREE_CODE (stmt
) != PHI_NODE
);
1059 op_iter_init (ptr
, stmt
, SSA_OP_VMAYUSE
);
1060 ptr
->iter_type
= ssa_op_iter_maymustdef
;
1061 op_iter_next_maymustdef (use
, def
, ptr
);
1065 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1068 op_iter_init_mustdef (ssa_op_iter
*ptr
, tree stmt
, use_operand_p
*kill
,
1071 gcc_assert (TREE_CODE (stmt
) != PHI_NODE
);
1073 op_iter_init (ptr
, stmt
, SSA_OP_VMUSTKILL
);
1074 ptr
->iter_type
= ssa_op_iter_maymustdef
;
1075 op_iter_next_maymustdef (kill
, def
, ptr
);
1078 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1081 op_iter_init_must_and_may_def (ssa_op_iter
*ptr
, tree stmt
,
1082 use_operand_p
*kill
, def_operand_p
*def
)
1084 gcc_assert (TREE_CODE (stmt
) != PHI_NODE
);
1086 op_iter_init (ptr
, stmt
, SSA_OP_VMUSTKILL
|SSA_OP_VMAYUSE
);
1087 ptr
->iter_type
= ssa_op_iter_maymustdef
;
1088 op_iter_next_maymustdef (kill
, def
, ptr
);
1092 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1095 single_ssa_tree_operand (tree stmt
, int flags
)
1100 var
= op_iter_init_tree (&iter
, stmt
, flags
);
1101 if (op_iter_done (&iter
))
1103 op_iter_next_tree (&iter
);
1104 if (op_iter_done (&iter
))
1110 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1112 static inline use_operand_p
1113 single_ssa_use_operand (tree stmt
, int flags
)
1118 var
= op_iter_init_use (&iter
, stmt
, flags
);
1119 if (op_iter_done (&iter
))
1120 return NULL_USE_OPERAND_P
;
1121 op_iter_next_use (&iter
);
1122 if (op_iter_done (&iter
))
1124 return NULL_USE_OPERAND_P
;
1129 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1131 static inline def_operand_p
1132 single_ssa_def_operand (tree stmt
, int flags
)
1137 var
= op_iter_init_def (&iter
, stmt
, flags
);
1138 if (op_iter_done (&iter
))
1139 return NULL_DEF_OPERAND_P
;
1140 op_iter_next_def (&iter
);
1141 if (op_iter_done (&iter
))
1143 return NULL_DEF_OPERAND_P
;
1147 /* Return true if there are zero operands in STMT matching the type
1150 zero_ssa_operands (tree stmt
, int flags
)
1154 op_iter_init_tree (&iter
, stmt
, flags
);
1155 return op_iter_done (&iter
);
1159 /* Return the number of operands matching FLAGS in STMT. */
1161 num_ssa_operands (tree stmt
, int flags
)
1167 FOR_EACH_SSA_TREE_OPERAND (t
, stmt
, iter
, flags
)
1173 /* Delink all immediate_use information for STMT. */
1175 delink_stmt_imm_use (tree stmt
)
1178 use_operand_p use_p
;
1180 if (ssa_operands_active ())
1181 FOR_EACH_SSA_USE_OPERAND (use_p
, stmt
, iter
,
1182 (SSA_OP_ALL_USES
| SSA_OP_ALL_KILLS
))
1183 delink_imm_use (use_p
);
1187 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1188 in STMT2. TRUE is returned if they are the same. STMTs can be NULL. */
1190 compare_ssa_operands_equal (tree stmt1
, tree stmt2
, int flags
)
1192 ssa_op_iter iter1
, iter2
;
1193 tree op1
= NULL_TREE
;
1194 tree op2
= NULL_TREE
;
1200 look1
= stmt1
&& stmt_ann (stmt1
);
1201 look2
= stmt2
&& stmt_ann (stmt2
);
1205 op1
= op_iter_init_tree (&iter1
, stmt1
, flags
);
1207 return op_iter_done (&iter1
);
1210 clear_and_done_ssa_iter (&iter1
);
1214 op2
= op_iter_init_tree (&iter2
, stmt2
, flags
);
1216 return op_iter_done (&iter2
);
1219 clear_and_done_ssa_iter (&iter2
);
1221 while (!op_iter_done (&iter1
) && !op_iter_done (&iter2
))
1225 op1
= op_iter_next_tree (&iter1
);
1226 op2
= op_iter_next_tree (&iter2
);
1229 return (op_iter_done (&iter1
) && op_iter_done (&iter2
));
1233 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1234 Otherwise return NULL_DEF_OPERAND_P. */
1236 single_phi_def (tree stmt
, int flags
)
1238 tree def
= PHI_RESULT (stmt
);
1239 if ((flags
& SSA_OP_DEF
) && is_gimple_reg (def
))
1241 if ((flags
& SSA_OP_VIRTUAL_DEFS
) && !is_gimple_reg (def
))
1246 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
1247 be either SSA_OP_USES or SSA_OP_VIRTUAL_USES. */
1248 static inline use_operand_p
1249 op_iter_init_phiuse (ssa_op_iter
*ptr
, tree phi
, int flags
)
1251 tree phi_def
= PHI_RESULT (phi
);
1254 clear_and_done_ssa_iter (ptr
);
1257 gcc_assert ((flags
& (SSA_OP_USE
| SSA_OP_VIRTUAL_USES
)) != 0);
1259 comp
= (is_gimple_reg (phi_def
) ? SSA_OP_USE
: SSA_OP_VIRTUAL_USES
);
1261 /* If the PHI node doesn't the operand type we care about, we're done. */
1262 if ((flags
& comp
) == 0)
1265 return NULL_USE_OPERAND_P
;
1268 ptr
->phi_stmt
= phi
;
1269 ptr
->num_phi
= PHI_NUM_ARGS (phi
);
1270 ptr
->iter_type
= ssa_op_iter_use
;
1271 return op_iter_next_use (ptr
);
1275 /* Start an iterator for a PHI definition. */
1277 static inline def_operand_p
1278 op_iter_init_phidef (ssa_op_iter
*ptr
, tree phi
, int flags
)
1280 tree phi_def
= PHI_RESULT (phi
);
1283 clear_and_done_ssa_iter (ptr
);
1286 gcc_assert ((flags
& (SSA_OP_DEF
| SSA_OP_VIRTUAL_DEFS
)) != 0);
1288 comp
= (is_gimple_reg (phi_def
) ? SSA_OP_DEF
: SSA_OP_VIRTUAL_DEFS
);
1290 /* If the PHI node doesn't the operand type we care about, we're done. */
1291 if ((flags
& comp
) == 0)
1294 return NULL_USE_OPERAND_P
;
1297 ptr
->iter_type
= ssa_op_iter_def
;
1298 /* The first call to op_iter_next_def will terminate the iterator since
1299 all the fields are NULL. Simply return the result here as the first and
1300 therefore only result. */
1301 return PHI_RESULT_PTR (phi
);
1304 /* Return true is IMM has reached the end of the immediate use stmt list. */
1307 end_imm_use_stmt_p (imm_use_iterator
*imm
)
1309 return (imm
->imm_use
== imm
->end_p
);
1312 /* Finished the traverse of an immediate use stmt list IMM by removing the
1313 placeholder node from the list. */
1316 end_imm_use_stmt_traverse (imm_use_iterator
*imm
)
1318 delink_imm_use (&(imm
->iter_node
));
1321 /* Immediate use traversal of uses within a stmt require that all the
1322 uses on a stmt be sequentially listed. This routine is used to build up
1323 this sequential list by adding USE_P to the end of the current list
1324 currently delimited by HEAD and LAST_P. The new LAST_P value is
1327 static inline use_operand_p
1328 move_use_after_head (use_operand_p use_p
, use_operand_p head
,
1329 use_operand_p last_p
)
1331 gcc_assert (USE_FROM_PTR (use_p
) == USE_FROM_PTR (head
));
1332 /* Skip head when we find it. */
1335 /* If use_p is already linked in after last_p, continue. */
1336 if (last_p
->next
== use_p
)
1340 /* Delink from current location, and link in at last_p. */
1341 delink_imm_use (use_p
);
1342 link_imm_use_to_list (use_p
, last_p
);
1350 /* This routine will relink all uses with the same stmt as HEAD into the list
1351 immediately following HEAD for iterator IMM. */
1354 link_use_stmts_after (use_operand_p head
, imm_use_iterator
*imm
)
1356 use_operand_p use_p
;
1357 use_operand_p last_p
= head
;
1358 tree head_stmt
= USE_STMT (head
);
1359 tree use
= USE_FROM_PTR (head
);
1360 ssa_op_iter op_iter
;
1363 /* Only look at virtual or real uses, depending on the type of HEAD. */
1364 flag
= (is_gimple_reg (use
) ? SSA_OP_USE
: SSA_OP_VIRTUAL_USES
);
1366 if (TREE_CODE (head_stmt
) == PHI_NODE
)
1368 FOR_EACH_PHI_ARG (use_p
, head_stmt
, op_iter
, flag
)
1369 if (USE_FROM_PTR (use_p
) == use
)
1370 last_p
= move_use_after_head (use_p
, head
, last_p
);
1374 FOR_EACH_SSA_USE_OPERAND (use_p
, head_stmt
, op_iter
, flag
)
1375 if (USE_FROM_PTR (use_p
) == use
)
1376 last_p
= move_use_after_head (use_p
, head
, last_p
);
1378 /* LInk iter node in after last_p. */
1379 if (imm
->iter_node
.prev
!= NULL
)
1380 delink_imm_use (&imm
->iter_node
);
1381 link_imm_use_to_list (&(imm
->iter_node
), last_p
);
1384 /* Initialize IMM to traverse over uses of VAR. Return the first statement. */
1386 first_imm_use_stmt (imm_use_iterator
*imm
, tree var
)
1388 gcc_assert (TREE_CODE (var
) == SSA_NAME
);
1390 imm
->end_p
= &(SSA_NAME_IMM_USE_NODE (var
));
1391 imm
->imm_use
= imm
->end_p
->next
;
1392 imm
->next_imm_name
= NULL_USE_OPERAND_P
;
1394 /* iter_node is used as a marker within the immediate use list to indicate
1395 where the end of the current stmt's uses are. Initialize it to NULL
1396 stmt and use, which indicates a marker node. */
1397 imm
->iter_node
.prev
= NULL_USE_OPERAND_P
;
1398 imm
->iter_node
.next
= NULL_USE_OPERAND_P
;
1399 imm
->iter_node
.stmt
= NULL_TREE
;
1400 imm
->iter_node
.use
= NULL_USE_OPERAND_P
;
1402 if (end_imm_use_stmt_p (imm
))
1405 link_use_stmts_after (imm
->imm_use
, imm
);
1407 return USE_STMT (imm
->imm_use
);
1410 /* Bump IMM to the next stmt which has a use of var. */
1413 next_imm_use_stmt (imm_use_iterator
*imm
)
1415 imm
->imm_use
= imm
->iter_node
.next
;
1416 if (end_imm_use_stmt_p (imm
))
1418 if (imm
->iter_node
.prev
!= NULL
)
1419 delink_imm_use (&imm
->iter_node
);
1423 link_use_stmts_after (imm
->imm_use
, imm
);
1424 return USE_STMT (imm
->imm_use
);
1428 /* This routine will return the first use on the stmt IMM currently refers
1431 static inline use_operand_p
1432 first_imm_use_on_stmt (imm_use_iterator
*imm
)
1434 imm
->next_imm_name
= imm
->imm_use
->next
;
1435 return imm
->imm_use
;
1438 /* Return TRUE if the last use on the stmt IMM refers to has been visited. */
1441 end_imm_use_on_stmt_p (imm_use_iterator
*imm
)
1443 return (imm
->imm_use
== &(imm
->iter_node
));
1446 /* Bump to the next use on the stmt IMM refers to, return NULL if done. */
1448 static inline use_operand_p
1449 next_imm_use_on_stmt (imm_use_iterator
*imm
)
1451 imm
->imm_use
= imm
->next_imm_name
;
1452 if (end_imm_use_on_stmt_p (imm
))
1453 return NULL_USE_OPERAND_P
;
1456 imm
->next_imm_name
= imm
->imm_use
->next
;
1457 return imm
->imm_use
;
1461 /* Return true if VAR cannot be modified by the program. */
1464 unmodifiable_var_p (tree var
)
1466 if (TREE_CODE (var
) == SSA_NAME
)
1467 var
= SSA_NAME_VAR (var
);
1470 return TREE_READONLY (var
) && (TREE_STATIC (var
) || MTAG_GLOBAL (var
));
1472 return TREE_READONLY (var
) && (TREE_STATIC (var
) || DECL_EXTERNAL (var
));
1475 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it. */
1478 array_ref_contains_indirect_ref (tree ref
)
1480 gcc_assert (TREE_CODE (ref
) == ARRAY_REF
);
1483 ref
= TREE_OPERAND (ref
, 0);
1484 } while (handled_component_p (ref
));
1486 return TREE_CODE (ref
) == INDIRECT_REF
;
1489 /* Return true if REF, a handled component reference, has an ARRAY_REF
1493 ref_contains_array_ref (tree ref
)
1495 gcc_assert (handled_component_p (ref
));
1498 if (TREE_CODE (ref
) == ARRAY_REF
)
1500 ref
= TREE_OPERAND (ref
, 0);
1501 } while (handled_component_p (ref
));
1506 /* Given a variable VAR, lookup and return a pointer to the list of
1507 subvariables for it. */
1509 static inline subvar_t
*
1510 lookup_subvars_for_var (tree var
)
1512 var_ann_t ann
= var_ann (var
);
1514 return &ann
->subvars
;
1517 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1518 NULL, if there are no subvariables. */
1520 static inline subvar_t
1521 get_subvars_for_var (tree var
)
1525 gcc_assert (SSA_VAR_P (var
));
1527 if (TREE_CODE (var
) == SSA_NAME
)
1528 subvars
= *(lookup_subvars_for_var (SSA_NAME_VAR (var
)));
1530 subvars
= *(lookup_subvars_for_var (var
));
1534 /* Return the subvariable of VAR at offset OFFSET. */
1537 get_subvar_at (tree var
, unsigned HOST_WIDE_INT offset
)
1541 for (sv
= get_subvars_for_var (var
); sv
; sv
= sv
->next
)
1542 if (SFT_OFFSET (sv
->var
) == offset
)
1548 /* Return true if V is a tree that we can have subvars for.
1549 Normally, this is any aggregate type. Also complex
1550 types which are not gimple registers can have subvars. */
1553 var_can_have_subvars (tree v
)
1555 /* Volatile variables should never have subvars. */
1556 if (TREE_THIS_VOLATILE (v
))
1559 /* Non decls or memory tags can never have subvars. */
1560 if (!DECL_P (v
) || MTAG_P (v
))
1563 /* Aggregates can have subvars. */
1564 if (AGGREGATE_TYPE_P (TREE_TYPE (v
)))
1567 /* Complex types variables which are not also a gimple register can
1569 if (TREE_CODE (TREE_TYPE (v
)) == COMPLEX_TYPE
1570 && !DECL_COMPLEX_GIMPLE_REG_P (v
))
1577 /* Return true if OFFSET and SIZE define a range that overlaps with some
1578 portion of the range of SV, a subvar. If there was an exact overlap,
1579 *EXACT will be set to true upon return. */
1582 overlap_subvar (unsigned HOST_WIDE_INT offset
, unsigned HOST_WIDE_INT size
,
1583 tree sv
, bool *exact
)
1585 /* There are three possible cases of overlap.
1586 1. We can have an exact overlap, like so:
1587 |offset, offset + size |
1588 |sv->offset, sv->offset + sv->size |
1590 2. We can have offset starting after sv->offset, like so:
1592 |offset, offset + size |
1593 |sv->offset, sv->offset + sv->size |
1595 3. We can have offset starting before sv->offset, like so:
1597 |offset, offset + size |
1598 |sv->offset, sv->offset + sv->size|
1603 if (offset
== SFT_OFFSET (sv
) && size
== SFT_SIZE (sv
))
1609 else if (offset
>= SFT_OFFSET (sv
)
1610 && offset
< (SFT_OFFSET (sv
) + SFT_SIZE (sv
)))
1614 else if (offset
< SFT_OFFSET (sv
)
1615 && (size
> SFT_OFFSET (sv
) - offset
))
1623 #endif /* _TREE_FLOW_INLINE_H */