1 /* Inline functions for tree-flow.h
2 Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc.
3 Contributed by Diego Novillo <dnovillo@redhat.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 #ifndef _TREE_FLOW_INLINE_H
23 #define _TREE_FLOW_INLINE_H 1
25 /* Inline functions for manipulating various data structures defined in
26 tree-flow.h. See tree-flow.h for documentation. */
28 /* Initialize the hashtable iterator HTI to point to hashtable TABLE */
31 first_htab_element (htab_iterator
*hti
, htab_t table
)
34 hti
->slot
= table
->entries
;
35 hti
->limit
= hti
->slot
+ htab_size (table
);
39 if (x
!= HTAB_EMPTY_ENTRY
&& x
!= HTAB_DELETED_ENTRY
)
41 } while (++(hti
->slot
) < hti
->limit
);
43 if (hti
->slot
< hti
->limit
)
48 /* Return current non-empty/deleted slot of the hashtable pointed to by HTI,
49 or NULL if we have reached the end. */
52 end_htab_p (htab_iterator
*hti
)
54 if (hti
->slot
>= hti
->limit
)
59 /* Advance the hashtable iterator pointed 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 (!t
->common
.ann
|| t
->common
.ann
->common
.type
== VAR_ANN
);
131 return (var_ann_t
) t
->common
.ann
;
134 /* Return the variable annotation for T, which must be a _DECL node.
135 Create the variable annotation if it doesn't exist. */
136 static inline var_ann_t
137 get_var_ann (tree var
)
139 var_ann_t ann
= var_ann (var
);
140 return (ann
) ? ann
: create_var_ann (var
);
143 /* Return the statement annotation for T, which must be a statement
144 node. Return NULL if the statement annotation doesn't exist. */
145 static inline stmt_ann_t
148 #ifdef ENABLE_CHECKING
149 gcc_assert (is_gimple_stmt (t
));
151 return (stmt_ann_t
) t
->common
.ann
;
154 /* Return the statement annotation for T, which must be a statement
155 node. Create the statement annotation if it doesn't exist. */
156 static inline stmt_ann_t
157 get_stmt_ann (tree stmt
)
159 stmt_ann_t ann
= stmt_ann (stmt
);
160 return (ann
) ? ann
: create_stmt_ann (stmt
);
163 /* Return the annotation type for annotation ANN. */
164 static inline enum tree_ann_type
165 ann_type (tree_ann_t ann
)
167 return ann
->common
.type
;
170 /* Return the basic block for statement T. */
171 static inline basic_block
176 if (TREE_CODE (t
) == PHI_NODE
)
180 return ann
? ann
->bb
: NULL
;
183 /* Return the may_aliases varray for variable VAR, or NULL if it has
185 static inline varray_type
186 may_aliases (tree var
)
188 var_ann_t ann
= var_ann (var
);
189 return ann
? ann
->may_aliases
: NULL
;
192 /* Return the line number for EXPR, or return -1 if we have no line
193 number information for it. */
195 get_lineno (tree expr
)
197 if (expr
== NULL_TREE
)
200 if (TREE_CODE (expr
) == COMPOUND_EXPR
)
201 expr
= TREE_OPERAND (expr
, 0);
203 if (! EXPR_HAS_LOCATION (expr
))
206 return EXPR_LINENO (expr
);
209 /* Return the file name for EXPR, or return "???" if we have no
210 filename information. */
211 static inline const char *
212 get_filename (tree expr
)
214 const char *filename
;
215 if (expr
== NULL_TREE
)
218 if (TREE_CODE (expr
) == COMPOUND_EXPR
)
219 expr
= TREE_OPERAND (expr
, 0);
221 if (EXPR_HAS_LOCATION (expr
) && (filename
= EXPR_FILENAME (expr
)))
227 /* Return true if T is a noreturn call. */
229 noreturn_call_p (tree t
)
231 tree call
= get_call_expr_in (t
);
232 return call
!= 0 && (call_expr_flags (call
) & ECF_NORETURN
) != 0;
235 /* Mark statement T as modified. */
237 mark_stmt_modified (tree t
)
240 if (TREE_CODE (t
) == PHI_NODE
)
245 ann
= create_stmt_ann (t
);
246 else if (noreturn_call_p (t
))
247 VEC_safe_push (tree
, gc
, modified_noreturn_calls
, t
);
251 /* Mark statement T as modified, and update it. */
255 if (TREE_CODE (t
) == PHI_NODE
)
257 mark_stmt_modified (t
);
258 update_stmt_operands (t
);
262 update_stmt_if_modified (tree t
)
264 if (stmt_modified_p (t
))
265 update_stmt_operands (t
);
268 /* Return true if T is marked as modified, false otherwise. */
270 stmt_modified_p (tree t
)
272 stmt_ann_t ann
= stmt_ann (t
);
274 /* Note that if the statement doesn't yet have an annotation, we consider it
275 modified. This will force the next call to update_stmt_operands to scan
277 return ann
? ann
->modified
: true;
280 /* Delink an immediate_uses node from its chain. */
282 delink_imm_use (ssa_use_operand_t
*linknode
)
284 /* Return if this node is not in a list. */
285 if (linknode
->prev
== NULL
)
288 linknode
->prev
->next
= linknode
->next
;
289 linknode
->next
->prev
= linknode
->prev
;
290 linknode
->prev
= NULL
;
291 linknode
->next
= NULL
;
294 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
296 link_imm_use_to_list (ssa_use_operand_t
*linknode
, ssa_use_operand_t
*list
)
298 /* Link the new node at the head of the list. If we are in the process of
299 traversing the list, we won't visit any new nodes added to it. */
300 linknode
->prev
= list
;
301 linknode
->next
= list
->next
;
302 list
->next
->prev
= linknode
;
303 list
->next
= linknode
;
306 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
308 link_imm_use (ssa_use_operand_t
*linknode
, tree def
)
310 ssa_use_operand_t
*root
;
312 if (!def
|| TREE_CODE (def
) != SSA_NAME
)
313 linknode
->prev
= NULL
;
316 root
= &(SSA_NAME_IMM_USE_NODE (def
));
317 #ifdef ENABLE_CHECKING
319 gcc_assert (*(linknode
->use
) == def
);
321 link_imm_use_to_list (linknode
, root
);
325 /* Set the value of a use pointed to by USE to VAL. */
327 set_ssa_use_from_ptr (use_operand_p use
, tree val
)
329 delink_imm_use (use
);
331 link_imm_use (use
, val
);
334 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
337 link_imm_use_stmt (ssa_use_operand_t
*linknode
, tree def
, tree stmt
)
340 link_imm_use (linknode
, def
);
342 link_imm_use (linknode
, NULL
);
343 linknode
->stmt
= stmt
;
346 /* Relink a new node in place of an old node in the list. */
348 relink_imm_use (ssa_use_operand_t
*node
, ssa_use_operand_t
*old
)
350 /* The node one had better be in the same list. */
351 gcc_assert (*(old
->use
) == *(node
->use
));
352 node
->prev
= old
->prev
;
353 node
->next
= old
->next
;
356 old
->prev
->next
= node
;
357 old
->next
->prev
= node
;
358 /* Remove the old node from the list. */
363 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
366 relink_imm_use_stmt (ssa_use_operand_t
*linknode
, ssa_use_operand_t
*old
, tree stmt
)
369 relink_imm_use (linknode
, old
);
371 link_imm_use (linknode
, NULL
);
372 linknode
->stmt
= stmt
;
375 /* Finished the traverse of an immediate use list IMM by removing it from
378 end_safe_imm_use_traverse (imm_use_iterator
*imm
)
380 delink_imm_use (&(imm
->iter_node
));
383 /* Return true if IMM is at the end of the list. */
385 end_safe_imm_use_p (imm_use_iterator
*imm
)
387 return (imm
->imm_use
== imm
->end_p
);
390 /* Initialize iterator IMM to process the list for VAR. */
391 static inline use_operand_p
392 first_safe_imm_use (imm_use_iterator
*imm
, tree var
)
394 /* Set up and link the iterator node into the linked list for VAR. */
395 imm
->iter_node
.use
= NULL
;
396 imm
->iter_node
.stmt
= NULL_TREE
;
397 imm
->end_p
= &(SSA_NAME_IMM_USE_NODE (var
));
398 /* Check if there are 0 elements. */
399 if (imm
->end_p
->next
== imm
->end_p
)
401 imm
->imm_use
= imm
->end_p
;
402 return NULL_USE_OPERAND_P
;
405 link_imm_use (&(imm
->iter_node
), var
);
406 imm
->imm_use
= imm
->iter_node
.next
;
410 /* Bump IMM to the next use in the list. */
411 static inline use_operand_p
412 next_safe_imm_use (imm_use_iterator
*imm
)
414 ssa_use_operand_t
*ptr
;
418 /* If the next node following the iter_node is still the one referred to by
419 imm_use, then the list hasn't changed, go to the next node. */
420 if (imm
->iter_node
.next
== imm
->imm_use
)
422 ptr
= &(imm
->iter_node
);
423 /* Remove iternode from the list. */
424 delink_imm_use (ptr
);
425 imm
->imm_use
= imm
->imm_use
->next
;
426 if (! end_safe_imm_use_p (imm
))
428 /* This isn't the end, link iternode before the next use. */
429 ptr
->prev
= imm
->imm_use
->prev
;
430 ptr
->next
= imm
->imm_use
;
431 imm
->imm_use
->prev
->next
= ptr
;
432 imm
->imm_use
->prev
= ptr
;
439 /* If the 'next' value after the iterator isn't the same as it was, then
440 a node has been deleted, so we simply proceed to the node following
441 where the iterator is in the list. */
442 imm
->imm_use
= imm
->iter_node
.next
;
443 if (end_safe_imm_use_p (imm
))
445 end_safe_imm_use_traverse (imm
);
453 /* Return true is IMM has reached the end of the immediate use list. */
455 end_readonly_imm_use_p (imm_use_iterator
*imm
)
457 return (imm
->imm_use
== imm
->end_p
);
460 /* Initialize iterator IMM to process the list for VAR. */
461 static inline use_operand_p
462 first_readonly_imm_use (imm_use_iterator
*imm
, tree var
)
464 gcc_assert (TREE_CODE (var
) == SSA_NAME
);
466 imm
->end_p
= &(SSA_NAME_IMM_USE_NODE (var
));
467 imm
->imm_use
= imm
->end_p
->next
;
468 #ifdef ENABLE_CHECKING
469 imm
->iter_node
.next
= imm
->imm_use
->next
;
471 if (end_readonly_imm_use_p (imm
))
472 return NULL_USE_OPERAND_P
;
476 /* Bump IMM to the next use in the list. */
477 static inline use_operand_p
478 next_readonly_imm_use (imm_use_iterator
*imm
)
480 use_operand_p old
= imm
->imm_use
;
482 #ifdef ENABLE_CHECKING
483 /* If this assertion fails, it indicates the 'next' pointer has changed
484 since we the last bump. This indicates that the list is being modified
485 via stmt changes, or SET_USE, or somesuch thing, and you need to be
486 using the SAFE version of the iterator. */
487 gcc_assert (imm
->iter_node
.next
== old
->next
);
488 imm
->iter_node
.next
= old
->next
->next
;
491 imm
->imm_use
= old
->next
;
492 if (end_readonly_imm_use_p (imm
))
497 /* Return true if VAR has no uses. */
499 has_zero_uses (tree var
)
501 ssa_use_operand_t
*ptr
;
502 ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
503 /* A single use means there is no items in the list. */
504 return (ptr
== ptr
->next
);
507 /* Return true if VAR has a single use. */
509 has_single_use (tree var
)
511 ssa_use_operand_t
*ptr
;
512 ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
513 /* A single use means there is one item in the list. */
514 return (ptr
!= ptr
->next
&& ptr
== ptr
->next
->next
);
517 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
518 to the use pointer and stmt of occurrence. */
520 single_imm_use (tree var
, use_operand_p
*use_p
, tree
*stmt
)
522 ssa_use_operand_t
*ptr
;
524 ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
525 if (ptr
!= ptr
->next
&& ptr
== ptr
->next
->next
)
528 *stmt
= ptr
->next
->stmt
;
531 *use_p
= NULL_USE_OPERAND_P
;
536 /* Return the number of immediate uses of VAR. */
537 static inline unsigned int
538 num_imm_uses (tree var
)
540 ssa_use_operand_t
*ptr
, *start
;
543 start
= &(SSA_NAME_IMM_USE_NODE (var
));
545 for (ptr
= start
->next
; ptr
!= start
; ptr
= ptr
->next
)
552 /* Return the tree pointer to by USE. */
554 get_use_from_ptr (use_operand_p use
)
559 /* Return the tree pointer to by DEF. */
561 get_def_from_ptr (def_operand_p def
)
566 /* Return a def_operand_p pointer for the result of PHI. */
567 static inline def_operand_p
568 get_phi_result_ptr (tree phi
)
570 return &(PHI_RESULT_TREE (phi
));
573 /* Return a use_operand_p pointer for argument I of phinode PHI. */
574 static inline use_operand_p
575 get_phi_arg_def_ptr (tree phi
, int i
)
577 return &(PHI_ARG_IMM_USE_NODE (phi
,i
));
581 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
584 addresses_taken (tree stmt
)
586 stmt_ann_t ann
= stmt_ann (stmt
);
587 return ann
? ann
->addresses_taken
: NULL
;
590 /* Return the PHI nodes for basic block BB, or NULL if there are no
593 phi_nodes (basic_block bb
)
595 return bb
->phi_nodes
;
598 /* Set list of phi nodes of a basic block BB to L. */
601 set_phi_nodes (basic_block bb
, tree l
)
606 for (phi
= l
; phi
; phi
= PHI_CHAIN (phi
))
607 set_bb_for_stmt (phi
, bb
);
610 /* Return the phi argument which contains the specified use. */
613 phi_arg_index_from_use (use_operand_p use
)
615 struct phi_arg_d
*element
, *root
;
619 /* Since the use is the first thing in a PHI argument element, we can
620 calculate its index based on casting it to an argument, and performing
621 pointer arithmetic. */
623 phi
= USE_STMT (use
);
624 gcc_assert (TREE_CODE (phi
) == PHI_NODE
);
626 element
= (struct phi_arg_d
*)use
;
627 root
= &(PHI_ARG_ELT (phi
, 0));
628 index
= element
- root
;
630 #ifdef ENABLE_CHECKING
631 /* Make sure the calculation doesn't have any leftover bytes. If it does,
632 then imm_use is likely not the first element in phi_arg_d. */
634 (((char *)element
- (char *)root
) % sizeof (struct phi_arg_d
)) == 0);
635 gcc_assert (index
>= 0 && index
< PHI_ARG_CAPACITY (phi
));
641 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
644 set_is_used (tree var
)
646 var_ann_t ann
= get_var_ann (var
);
651 /* ----------------------------------------------------------------------- */
653 /* Return true if T is an executable statement. */
655 is_exec_stmt (tree t
)
657 return (t
&& !IS_EMPTY_STMT (t
) && t
!= error_mark_node
);
661 /* Return true if this stmt can be the target of a control transfer stmt such
664 is_label_stmt (tree t
)
667 switch (TREE_CODE (t
))
671 case CASE_LABEL_EXPR
:
679 /* PHI nodes should contain only ssa_names and invariants. A test
680 for ssa_name is definitely simpler; don't let invalid contents
681 slip in in the meantime. */
684 phi_ssa_name_p (tree t
)
686 if (TREE_CODE (t
) == SSA_NAME
)
688 #ifdef ENABLE_CHECKING
689 gcc_assert (is_gimple_min_invariant (t
));
694 /* ----------------------------------------------------------------------- */
696 /* Return a block_stmt_iterator that points to beginning of basic
698 static inline block_stmt_iterator
699 bsi_start (basic_block bb
)
701 block_stmt_iterator bsi
;
703 bsi
.tsi
= tsi_start (bb
->stmt_list
);
706 gcc_assert (bb
->index
< NUM_FIXED_BLOCKS
);
708 bsi
.tsi
.container
= NULL
;
714 /* Return a block statement iterator that points to the first non-label
717 static inline block_stmt_iterator
718 bsi_after_labels (basic_block bb
)
720 block_stmt_iterator bsi
;
721 tree_stmt_iterator next
;
727 gcc_assert (bb
->index
< NUM_FIXED_BLOCKS
);
729 bsi
.tsi
.container
= NULL
;
733 bsi
.tsi
= tsi_start (bb
->stmt_list
);
734 if (tsi_end_p (bsi
.tsi
))
740 while (!tsi_end_p (next
)
741 && TREE_CODE (tsi_stmt (next
)) == LABEL_EXPR
)
750 /* Return a block statement iterator that points to the end of basic
752 static inline block_stmt_iterator
753 bsi_last (basic_block bb
)
755 block_stmt_iterator bsi
;
757 bsi
.tsi
= tsi_last (bb
->stmt_list
);
760 gcc_assert (bb
->index
< NUM_FIXED_BLOCKS
);
762 bsi
.tsi
.container
= NULL
;
768 /* Return true if block statement iterator I has reached the end of
771 bsi_end_p (block_stmt_iterator i
)
773 return tsi_end_p (i
.tsi
);
776 /* Modify block statement iterator I so that it is at the next
777 statement in the basic block. */
779 bsi_next (block_stmt_iterator
*i
)
784 /* Modify block statement iterator I so that it is at the previous
785 statement in the basic block. */
787 bsi_prev (block_stmt_iterator
*i
)
792 /* Return the statement that block statement iterator I is currently
795 bsi_stmt (block_stmt_iterator i
)
797 return tsi_stmt (i
.tsi
);
800 /* Return a pointer to the statement that block statement iterator I
803 bsi_stmt_ptr (block_stmt_iterator i
)
805 return tsi_stmt_ptr (i
.tsi
);
808 /* Returns the loop of the statement STMT. */
810 static inline struct loop
*
811 loop_containing_stmt (tree stmt
)
813 basic_block bb
= bb_for_stmt (stmt
);
817 return bb
->loop_father
;
820 /* Return true if VAR is a clobbered by function calls. */
822 is_call_clobbered (tree var
)
824 return is_global_var (var
)
825 || bitmap_bit_p (call_clobbered_vars
, DECL_UID (var
));
828 /* Mark variable VAR as being clobbered by function calls. */
830 mark_call_clobbered (tree var
)
832 /* If VAR is a memory tag, then we need to consider it a global
833 variable. This is because the pointer that VAR represents has
834 been found to point to either an arbitrary location or to a known
835 location in global memory. */
836 if (MTAG_P (var
) && TREE_CODE (var
) != STRUCT_FIELD_TAG
)
837 MTAG_GLOBAL (var
) = 1;
838 bitmap_set_bit (call_clobbered_vars
, DECL_UID (var
));
839 ssa_call_clobbered_cache_valid
= false;
840 ssa_ro_call_cache_valid
= false;
843 /* Clear the call-clobbered attribute from variable VAR. */
845 clear_call_clobbered (tree var
)
847 if (MTAG_P (var
) && TREE_CODE (var
) != STRUCT_FIELD_TAG
)
848 MTAG_GLOBAL (var
) = 0;
849 bitmap_clear_bit (call_clobbered_vars
, DECL_UID (var
));
850 ssa_call_clobbered_cache_valid
= false;
851 ssa_ro_call_cache_valid
= false;
854 /* Mark variable VAR as being non-addressable. */
856 mark_non_addressable (tree var
)
858 bitmap_clear_bit (call_clobbered_vars
, DECL_UID (var
));
859 TREE_ADDRESSABLE (var
) = 0;
860 ssa_call_clobbered_cache_valid
= false;
861 ssa_ro_call_cache_valid
= false;
864 /* Return the common annotation for T. Return NULL if the annotation
865 doesn't already exist. */
866 static inline tree_ann_t
869 return t
->common
.ann
;
872 /* Return a common annotation for T. Create the constant annotation if it
874 static inline tree_ann_t
875 get_tree_ann (tree t
)
877 tree_ann_t ann
= tree_ann (t
);
878 return (ann
) ? ann
: create_tree_ann (t
);
881 /* ----------------------------------------------------------------------- */
883 /* The following set of routines are used to iterator over various type of
886 /* Return true if PTR is finished iterating. */
888 op_iter_done (ssa_op_iter
*ptr
)
893 /* Get the next iterator use value for PTR. */
894 static inline use_operand_p
895 op_iter_next_use (ssa_op_iter
*ptr
)
898 #ifdef ENABLE_CHECKING
899 gcc_assert (ptr
->iter_type
== ssa_op_iter_use
);
903 use_p
= USE_OP_PTR (ptr
->uses
);
904 ptr
->uses
= ptr
->uses
->next
;
909 use_p
= VUSE_OP_PTR (ptr
->vuses
);
910 ptr
->vuses
= ptr
->vuses
->next
;
915 use_p
= MAYDEF_OP_PTR (ptr
->mayuses
);
916 ptr
->mayuses
= ptr
->mayuses
->next
;
921 use_p
= MUSTDEF_KILL_PTR (ptr
->mustkills
);
922 ptr
->mustkills
= ptr
->mustkills
->next
;
925 if (ptr
->phi_i
< ptr
->num_phi
)
927 return PHI_ARG_DEF_PTR (ptr
->phi_stmt
, (ptr
->phi_i
)++);
930 return NULL_USE_OPERAND_P
;
933 /* Get the next iterator def value for PTR. */
934 static inline def_operand_p
935 op_iter_next_def (ssa_op_iter
*ptr
)
938 #ifdef ENABLE_CHECKING
939 gcc_assert (ptr
->iter_type
== ssa_op_iter_def
);
943 def_p
= DEF_OP_PTR (ptr
->defs
);
944 ptr
->defs
= ptr
->defs
->next
;
949 def_p
= MUSTDEF_RESULT_PTR (ptr
->mustdefs
);
950 ptr
->mustdefs
= ptr
->mustdefs
->next
;
955 def_p
= MAYDEF_RESULT_PTR (ptr
->maydefs
);
956 ptr
->maydefs
= ptr
->maydefs
->next
;
960 return NULL_DEF_OPERAND_P
;
963 /* Get the next iterator tree value for PTR. */
965 op_iter_next_tree (ssa_op_iter
*ptr
)
968 #ifdef ENABLE_CHECKING
969 gcc_assert (ptr
->iter_type
== ssa_op_iter_tree
);
973 val
= USE_OP (ptr
->uses
);
974 ptr
->uses
= ptr
->uses
->next
;
979 val
= VUSE_OP (ptr
->vuses
);
980 ptr
->vuses
= ptr
->vuses
->next
;
985 val
= MAYDEF_OP (ptr
->mayuses
);
986 ptr
->mayuses
= ptr
->mayuses
->next
;
991 val
= MUSTDEF_KILL (ptr
->mustkills
);
992 ptr
->mustkills
= ptr
->mustkills
->next
;
997 val
= DEF_OP (ptr
->defs
);
998 ptr
->defs
= ptr
->defs
->next
;
1003 val
= MUSTDEF_RESULT (ptr
->mustdefs
);
1004 ptr
->mustdefs
= ptr
->mustdefs
->next
;
1009 val
= MAYDEF_RESULT (ptr
->maydefs
);
1010 ptr
->maydefs
= ptr
->maydefs
->next
;
1020 /* This functions clears the iterator PTR, and marks it done. This is normally
1021 used to prevent warnings in the compile about might be uninitialized
1025 clear_and_done_ssa_iter (ssa_op_iter
*ptr
)
1030 ptr
->maydefs
= NULL
;
1031 ptr
->mayuses
= NULL
;
1032 ptr
->mustdefs
= NULL
;
1033 ptr
->mustkills
= NULL
;
1034 ptr
->iter_type
= ssa_op_iter_none
;
1037 ptr
->phi_stmt
= NULL_TREE
;
1041 /* Initialize the iterator PTR to the virtual defs in STMT. */
1043 op_iter_init (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1045 #ifdef ENABLE_CHECKING
1046 gcc_assert (stmt_ann (stmt
));
1049 ptr
->defs
= (flags
& SSA_OP_DEF
) ? DEF_OPS (stmt
) : NULL
;
1050 ptr
->uses
= (flags
& SSA_OP_USE
) ? USE_OPS (stmt
) : NULL
;
1051 ptr
->vuses
= (flags
& SSA_OP_VUSE
) ? VUSE_OPS (stmt
) : NULL
;
1052 ptr
->maydefs
= (flags
& SSA_OP_VMAYDEF
) ? MAYDEF_OPS (stmt
) : NULL
;
1053 ptr
->mayuses
= (flags
& SSA_OP_VMAYUSE
) ? MAYDEF_OPS (stmt
) : NULL
;
1054 ptr
->mustdefs
= (flags
& SSA_OP_VMUSTDEF
) ? MUSTDEF_OPS (stmt
) : NULL
;
1055 ptr
->mustkills
= (flags
& SSA_OP_VMUSTKILL
) ? MUSTDEF_OPS (stmt
) : NULL
;
1060 ptr
->phi_stmt
= NULL_TREE
;
1063 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1065 static inline use_operand_p
1066 op_iter_init_use (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1068 gcc_assert ((flags
& SSA_OP_ALL_DEFS
) == 0);
1069 op_iter_init (ptr
, stmt
, flags
);
1070 ptr
->iter_type
= ssa_op_iter_use
;
1071 return op_iter_next_use (ptr
);
1074 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1076 static inline def_operand_p
1077 op_iter_init_def (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1079 gcc_assert ((flags
& (SSA_OP_ALL_USES
| SSA_OP_VIRTUAL_KILLS
)) == 0);
1080 op_iter_init (ptr
, stmt
, flags
);
1081 ptr
->iter_type
= ssa_op_iter_def
;
1082 return op_iter_next_def (ptr
);
1085 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1086 the first operand as a tree. */
1088 op_iter_init_tree (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1090 op_iter_init (ptr
, stmt
, flags
);
1091 ptr
->iter_type
= ssa_op_iter_tree
;
1092 return op_iter_next_tree (ptr
);
1095 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1098 op_iter_next_maymustdef (use_operand_p
*use
, def_operand_p
*def
,
1101 #ifdef ENABLE_CHECKING
1102 gcc_assert (ptr
->iter_type
== ssa_op_iter_maymustdef
);
1106 *def
= MAYDEF_RESULT_PTR (ptr
->mayuses
);
1107 *use
= MAYDEF_OP_PTR (ptr
->mayuses
);
1108 ptr
->mayuses
= ptr
->mayuses
->next
;
1114 *def
= MUSTDEF_RESULT_PTR (ptr
->mustkills
);
1115 *use
= MUSTDEF_KILL_PTR (ptr
->mustkills
);
1116 ptr
->mustkills
= ptr
->mustkills
->next
;
1120 *def
= NULL_DEF_OPERAND_P
;
1121 *use
= NULL_USE_OPERAND_P
;
1127 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1130 op_iter_init_maydef (ssa_op_iter
*ptr
, tree stmt
, use_operand_p
*use
,
1133 gcc_assert (TREE_CODE (stmt
) != PHI_NODE
);
1135 op_iter_init (ptr
, stmt
, SSA_OP_VMAYUSE
);
1136 ptr
->iter_type
= ssa_op_iter_maymustdef
;
1137 op_iter_next_maymustdef (use
, def
, ptr
);
1141 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1144 op_iter_init_mustdef (ssa_op_iter
*ptr
, tree stmt
, use_operand_p
*kill
,
1147 gcc_assert (TREE_CODE (stmt
) != PHI_NODE
);
1149 op_iter_init (ptr
, stmt
, SSA_OP_VMUSTKILL
);
1150 ptr
->iter_type
= ssa_op_iter_maymustdef
;
1151 op_iter_next_maymustdef (kill
, def
, ptr
);
1154 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1157 op_iter_init_must_and_may_def (ssa_op_iter
*ptr
, tree stmt
,
1158 use_operand_p
*kill
, def_operand_p
*def
)
1160 gcc_assert (TREE_CODE (stmt
) != PHI_NODE
);
1162 op_iter_init (ptr
, stmt
, SSA_OP_VMUSTKILL
|SSA_OP_VMAYUSE
);
1163 ptr
->iter_type
= ssa_op_iter_maymustdef
;
1164 op_iter_next_maymustdef (kill
, def
, ptr
);
1168 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1171 single_ssa_tree_operand (tree stmt
, int flags
)
1176 var
= op_iter_init_tree (&iter
, stmt
, flags
);
1177 if (op_iter_done (&iter
))
1179 op_iter_next_tree (&iter
);
1180 if (op_iter_done (&iter
))
1186 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1188 static inline use_operand_p
1189 single_ssa_use_operand (tree stmt
, int flags
)
1194 var
= op_iter_init_use (&iter
, stmt
, flags
);
1195 if (op_iter_done (&iter
))
1196 return NULL_USE_OPERAND_P
;
1197 op_iter_next_use (&iter
);
1198 if (op_iter_done (&iter
))
1200 return NULL_USE_OPERAND_P
;
1205 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1207 static inline def_operand_p
1208 single_ssa_def_operand (tree stmt
, int flags
)
1213 var
= op_iter_init_def (&iter
, stmt
, flags
);
1214 if (op_iter_done (&iter
))
1215 return NULL_DEF_OPERAND_P
;
1216 op_iter_next_def (&iter
);
1217 if (op_iter_done (&iter
))
1219 return NULL_DEF_OPERAND_P
;
1223 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1226 zero_ssa_operands (tree stmt
, int flags
)
1230 op_iter_init_tree (&iter
, stmt
, flags
);
1231 return op_iter_done (&iter
);
1235 /* Return the number of operands matching FLAGS in STMT. */
1237 num_ssa_operands (tree stmt
, int flags
)
1243 FOR_EACH_SSA_TREE_OPERAND (t
, stmt
, iter
, flags
)
1249 /* Delink all immediate_use information for STMT. */
1251 delink_stmt_imm_use (tree stmt
)
1254 use_operand_p use_p
;
1256 if (ssa_operands_active ())
1257 FOR_EACH_SSA_USE_OPERAND (use_p
, stmt
, iter
,
1258 (SSA_OP_ALL_USES
| SSA_OP_ALL_KILLS
))
1259 delink_imm_use (use_p
);
1263 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1264 in STMT2. TRUE is returned if they are the same. STMTs can be NULL. */
1266 compare_ssa_operands_equal (tree stmt1
, tree stmt2
, int flags
)
1268 ssa_op_iter iter1
, iter2
;
1269 tree op1
= NULL_TREE
;
1270 tree op2
= NULL_TREE
;
1276 look1
= stmt1
&& stmt_ann (stmt1
);
1277 look2
= stmt2
&& stmt_ann (stmt2
);
1281 op1
= op_iter_init_tree (&iter1
, stmt1
, flags
);
1283 return op_iter_done (&iter1
);
1286 clear_and_done_ssa_iter (&iter1
);
1290 op2
= op_iter_init_tree (&iter2
, stmt2
, flags
);
1292 return op_iter_done (&iter2
);
1295 clear_and_done_ssa_iter (&iter2
);
1297 while (!op_iter_done (&iter1
) && !op_iter_done (&iter2
))
1301 op1
= op_iter_next_tree (&iter1
);
1302 op2
= op_iter_next_tree (&iter2
);
1305 return (op_iter_done (&iter1
) && op_iter_done (&iter2
));
1309 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1310 Otherwise return NULL_DEF_OPERAND_P. */
1312 single_phi_def (tree stmt
, int flags
)
1314 tree def
= PHI_RESULT (stmt
);
1315 if ((flags
& SSA_OP_DEF
) && is_gimple_reg (def
))
1317 if ((flags
& SSA_OP_VIRTUAL_DEFS
) && !is_gimple_reg (def
))
1322 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
1323 be either SSA_OP_USES or SAS_OP_VIRTUAL_USES. */
1324 static inline use_operand_p
1325 op_iter_init_phiuse (ssa_op_iter
*ptr
, tree phi
, int flags
)
1327 tree phi_def
= PHI_RESULT (phi
);
1330 clear_and_done_ssa_iter (ptr
);
1333 gcc_assert ((flags
& (SSA_OP_USE
| SSA_OP_VIRTUAL_USES
)) != 0);
1335 comp
= (is_gimple_reg (phi_def
) ? SSA_OP_USE
: SSA_OP_VIRTUAL_USES
);
1337 /* If the PHI node doesn't the operand type we care about, we're done. */
1338 if ((flags
& comp
) == 0)
1341 return NULL_USE_OPERAND_P
;
1344 ptr
->phi_stmt
= phi
;
1345 ptr
->num_phi
= PHI_NUM_ARGS (phi
);
1346 ptr
->iter_type
= ssa_op_iter_use
;
1347 return op_iter_next_use (ptr
);
1351 /* Start an iterator for a PHI definition. */
1353 static inline def_operand_p
1354 op_iter_init_phidef (ssa_op_iter
*ptr
, tree phi
, int flags
)
1356 tree phi_def
= PHI_RESULT (phi
);
1359 clear_and_done_ssa_iter (ptr
);
1362 gcc_assert ((flags
& (SSA_OP_DEF
| SSA_OP_VIRTUAL_DEFS
)) != 0);
1364 comp
= (is_gimple_reg (phi_def
) ? SSA_OP_DEF
: SSA_OP_VIRTUAL_DEFS
);
1366 /* If the PHI node doesn't the operand type we care about, we're done. */
1367 if ((flags
& comp
) == 0)
1370 return NULL_USE_OPERAND_P
;
1373 ptr
->iter_type
= ssa_op_iter_def
;
1374 /* The first call to op_iter_next_def will terminate the iterator since
1375 all the fields are NULL. Simply return the result here as the first and
1376 therefore only result. */
1377 return PHI_RESULT_PTR (phi
);
1382 /* Return true if VAR cannot be modified by the program. */
1385 unmodifiable_var_p (tree var
)
1387 if (TREE_CODE (var
) == SSA_NAME
)
1388 var
= SSA_NAME_VAR (var
);
1391 return TREE_READONLY (var
) && (TREE_STATIC (var
) || MTAG_GLOBAL (var
));
1393 return TREE_READONLY (var
) && (TREE_STATIC (var
) || DECL_EXTERNAL (var
));
1396 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it. */
1399 array_ref_contains_indirect_ref (tree ref
)
1401 gcc_assert (TREE_CODE (ref
) == ARRAY_REF
);
1404 ref
= TREE_OPERAND (ref
, 0);
1405 } while (handled_component_p (ref
));
1407 return TREE_CODE (ref
) == INDIRECT_REF
;
1410 /* Return true if REF, a handled component reference, has an ARRAY_REF
1414 ref_contains_array_ref (tree ref
)
1416 gcc_assert (handled_component_p (ref
));
1419 if (TREE_CODE (ref
) == ARRAY_REF
)
1421 ref
= TREE_OPERAND (ref
, 0);
1422 } while (handled_component_p (ref
));
1427 /* Given a variable VAR, lookup and return a pointer to the list of
1428 subvariables for it. */
1430 static inline subvar_t
*
1431 lookup_subvars_for_var (tree var
)
1433 var_ann_t ann
= var_ann (var
);
1435 return &ann
->subvars
;
1438 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1439 NULL, if there are no subvariables. */
1441 static inline subvar_t
1442 get_subvars_for_var (tree var
)
1446 gcc_assert (SSA_VAR_P (var
));
1448 if (TREE_CODE (var
) == SSA_NAME
)
1449 subvars
= *(lookup_subvars_for_var (SSA_NAME_VAR (var
)));
1451 subvars
= *(lookup_subvars_for_var (var
));
1455 /* Return the subvariable of VAR at offset OFFSET. */
1458 get_subvar_at (tree var
, unsigned HOST_WIDE_INT offset
)
1462 for (sv
= get_subvars_for_var (var
); sv
; sv
= sv
->next
)
1463 if (sv
->offset
== offset
)
1469 /* Return true if V is a tree that we can have subvars for.
1470 Normally, this is any aggregate type, however, due to implementation
1471 limitations ATM, we exclude array types as well. */
1474 var_can_have_subvars (tree v
)
1476 return (AGGREGATE_TYPE_P (TREE_TYPE (v
)) &&
1477 TREE_CODE (TREE_TYPE (v
)) != ARRAY_TYPE
);
1481 /* Return true if OFFSET and SIZE define a range that overlaps with some
1482 portion of the range of SV, a subvar. If there was an exact overlap,
1483 *EXACT will be set to true upon return. */
1486 overlap_subvar (unsigned HOST_WIDE_INT offset
, unsigned HOST_WIDE_INT size
,
1487 subvar_t sv
, bool *exact
)
1489 /* There are three possible cases of overlap.
1490 1. We can have an exact overlap, like so:
1491 |offset, offset + size |
1492 |sv->offset, sv->offset + sv->size |
1494 2. We can have offset starting after sv->offset, like so:
1496 |offset, offset + size |
1497 |sv->offset, sv->offset + sv->size |
1499 3. We can have offset starting before sv->offset, like so:
1501 |offset, offset + size |
1502 |sv->offset, sv->offset + sv->size|
1507 if (offset
== sv
->offset
&& size
== sv
->size
)
1513 else if (offset
>= sv
->offset
&& offset
< (sv
->offset
+ sv
->size
))
1517 else if (offset
< sv
->offset
&& (size
> sv
->offset
- offset
))
1525 #endif /* _TREE_FLOW_INLINE_H */