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, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #ifndef _TREE_FLOW_INLINE_H
23 #define _TREE_FLOW_INLINE_H 1
25 /* Inline functions for manipulating various data structures defined in
26 tree-flow.h. See tree-flow.h for documentation. */
28 /* Return the variable annotation for T, which must be a _DECL node.
29 Return NULL if the variable annotation doesn't already exist. */
30 static inline var_ann_t
34 gcc_assert (DECL_P (t
));
35 gcc_assert (!t
->common
.ann
|| t
->common
.ann
->common
.type
== VAR_ANN
);
37 return (var_ann_t
) t
->common
.ann
;
40 /* Return the variable annotation for T, which must be a _DECL node.
41 Create the variable annotation if it doesn't exist. */
42 static inline var_ann_t
43 get_var_ann (tree var
)
45 var_ann_t ann
= var_ann (var
);
46 return (ann
) ? ann
: create_var_ann (var
);
49 /* Return the statement annotation for T, which must be a statement
50 node. Return NULL if the statement annotation doesn't exist. */
51 static inline stmt_ann_t
54 #ifdef ENABLE_CHECKING
55 gcc_assert (is_gimple_stmt (t
));
57 return (stmt_ann_t
) t
->common
.ann
;
60 /* Return the statement annotation for T, which must be a statement
61 node. Create the statement annotation if it doesn't exist. */
62 static inline stmt_ann_t
63 get_stmt_ann (tree stmt
)
65 stmt_ann_t ann
= stmt_ann (stmt
);
66 return (ann
) ? ann
: create_stmt_ann (stmt
);
69 /* Return the annotation type for annotation ANN. */
70 static inline enum tree_ann_type
71 ann_type (tree_ann_t ann
)
73 return ann
->common
.type
;
76 /* Return the basic block for statement T. */
77 static inline basic_block
82 if (TREE_CODE (t
) == PHI_NODE
)
86 return ann
? ann
->bb
: NULL
;
89 /* Return the may_aliases varray for variable VAR, or NULL if it has
91 static inline varray_type
92 may_aliases (tree var
)
94 var_ann_t ann
= var_ann (var
);
95 return ann
? ann
->may_aliases
: NULL
;
98 /* Return the line number for EXPR, or return -1 if we have no line
99 number information for it. */
101 get_lineno (tree expr
)
103 if (expr
== NULL_TREE
)
106 if (TREE_CODE (expr
) == COMPOUND_EXPR
)
107 expr
= TREE_OPERAND (expr
, 0);
109 if (! EXPR_HAS_LOCATION (expr
))
112 return EXPR_LINENO (expr
);
115 /* Return the file name for EXPR, or return "???" if we have no
116 filename information. */
117 static inline const char *
118 get_filename (tree expr
)
120 const char *filename
;
121 if (expr
== NULL_TREE
)
124 if (TREE_CODE (expr
) == COMPOUND_EXPR
)
125 expr
= TREE_OPERAND (expr
, 0);
127 if (EXPR_HAS_LOCATION (expr
) && (filename
= EXPR_FILENAME (expr
)))
133 /* Return true if T is a noreturn call. */
135 noreturn_call_p (tree t
)
137 tree call
= get_call_expr_in (t
);
138 return call
!= 0 && (call_expr_flags (call
) & ECF_NORETURN
) != 0;
141 /* Mark statement T as modified. */
143 mark_stmt_modified (tree t
)
146 if (TREE_CODE (t
) == PHI_NODE
)
151 ann
= create_stmt_ann (t
);
152 else if (noreturn_call_p (t
))
153 VEC_safe_push (tree
, gc
, modified_noreturn_calls
, t
);
157 /* Mark statement T as modified, and update it. */
161 if (TREE_CODE (t
) == PHI_NODE
)
163 mark_stmt_modified (t
);
164 update_stmt_operands (t
);
168 update_stmt_if_modified (tree t
)
170 if (stmt_modified_p (t
))
171 update_stmt_operands (t
);
174 /* Return true if T is marked as modified, false otherwise. */
176 stmt_modified_p (tree t
)
178 stmt_ann_t ann
= stmt_ann (t
);
180 /* Note that if the statement doesn't yet have an annotation, we consider it
181 modified. This will force the next call to update_stmt_operands to scan
183 return ann
? ann
->modified
: true;
186 /* Delink an immediate_uses node from its chain. */
188 delink_imm_use (ssa_use_operand_t
*linknode
)
190 /* Return if this node is not in a list. */
191 if (linknode
->prev
== NULL
)
194 linknode
->prev
->next
= linknode
->next
;
195 linknode
->next
->prev
= linknode
->prev
;
196 linknode
->prev
= NULL
;
197 linknode
->next
= NULL
;
200 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
202 link_imm_use_to_list (ssa_use_operand_t
*linknode
, ssa_use_operand_t
*list
)
204 /* Link the new node at the head of the list. If we are in the process of
205 traversing the list, we won't visit any new nodes added to it. */
206 linknode
->prev
= list
;
207 linknode
->next
= list
->next
;
208 list
->next
->prev
= linknode
;
209 list
->next
= linknode
;
212 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
214 link_imm_use (ssa_use_operand_t
*linknode
, tree def
)
216 ssa_use_operand_t
*root
;
218 if (!def
|| TREE_CODE (def
) != SSA_NAME
)
219 linknode
->prev
= NULL
;
222 root
= &(SSA_NAME_IMM_USE_NODE (def
));
223 #ifdef ENABLE_CHECKING
225 gcc_assert (*(linknode
->use
) == def
);
227 link_imm_use_to_list (linknode
, root
);
231 /* Set the value of a use pointed by USE to VAL. */
233 set_ssa_use_from_ptr (use_operand_p use
, tree val
)
235 delink_imm_use (use
);
237 link_imm_use (use
, val
);
240 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
243 link_imm_use_stmt (ssa_use_operand_t
*linknode
, tree def
, tree stmt
)
246 link_imm_use (linknode
, def
);
248 link_imm_use (linknode
, NULL
);
249 linknode
->stmt
= stmt
;
252 /* Relink a new node in place of an old node in the list. */
254 relink_imm_use (ssa_use_operand_t
*node
, ssa_use_operand_t
*old
)
256 /* The node one had better be in the same list. */
257 gcc_assert (*(old
->use
) == *(node
->use
));
258 node
->prev
= old
->prev
;
259 node
->next
= old
->next
;
262 old
->prev
->next
= node
;
263 old
->next
->prev
= node
;
264 /* Remove the old node from the list. */
269 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
272 relink_imm_use_stmt (ssa_use_operand_t
*linknode
, ssa_use_operand_t
*old
, tree stmt
)
275 relink_imm_use (linknode
, old
);
277 link_imm_use (linknode
, NULL
);
278 linknode
->stmt
= stmt
;
281 /* Finished the traverse of an immediate use list IMM by removing it from
284 end_safe_imm_use_traverse (imm_use_iterator
*imm
)
286 delink_imm_use (&(imm
->iter_node
));
289 /* Return true if IMM is at the end of the list. */
291 end_safe_imm_use_p (imm_use_iterator
*imm
)
293 return (imm
->imm_use
== imm
->end_p
);
296 /* Initialize iterator IMM to process the list for VAR. */
297 static inline use_operand_p
298 first_safe_imm_use (imm_use_iterator
*imm
, tree var
)
300 /* Set up and link the iterator node into the linked list for VAR. */
301 imm
->iter_node
.use
= NULL
;
302 imm
->iter_node
.stmt
= NULL_TREE
;
303 imm
->end_p
= &(SSA_NAME_IMM_USE_NODE (var
));
304 /* Check if there are 0 elements. */
305 if (imm
->end_p
->next
== imm
->end_p
)
307 imm
->imm_use
= imm
->end_p
;
308 return NULL_USE_OPERAND_P
;
311 link_imm_use (&(imm
->iter_node
), var
);
312 imm
->imm_use
= imm
->iter_node
.next
;
316 /* Bump IMM to the next use in the list. */
317 static inline use_operand_p
318 next_safe_imm_use (imm_use_iterator
*imm
)
320 ssa_use_operand_t
*ptr
;
324 /* If the next node following the iter_node is still the one referred to by
325 imm_use, then the list hasn't changed, go to the next node. */
326 if (imm
->iter_node
.next
== imm
->imm_use
)
328 ptr
= &(imm
->iter_node
);
329 /* Remove iternode from the list. */
330 delink_imm_use (ptr
);
331 imm
->imm_use
= imm
->imm_use
->next
;
332 if (! end_safe_imm_use_p (imm
))
334 /* This isn't the end, link iternode before the next use. */
335 ptr
->prev
= imm
->imm_use
->prev
;
336 ptr
->next
= imm
->imm_use
;
337 imm
->imm_use
->prev
->next
= ptr
;
338 imm
->imm_use
->prev
= ptr
;
345 /* If the 'next' value after the iterator isn't the same as it was, then
346 a node has been deleted, so we simply proceed to the node following
347 where the iterator is in the list. */
348 imm
->imm_use
= imm
->iter_node
.next
;
349 if (end_safe_imm_use_p (imm
))
351 end_safe_imm_use_traverse (imm
);
359 /* Return true is IMM has reached the end of the immediate use list. */
361 end_readonly_imm_use_p (imm_use_iterator
*imm
)
363 return (imm
->imm_use
== imm
->end_p
);
366 /* Initialize iterator IMM to process the list for VAR. */
367 static inline use_operand_p
368 first_readonly_imm_use (imm_use_iterator
*imm
, tree var
)
370 gcc_assert (TREE_CODE (var
) == SSA_NAME
);
372 imm
->end_p
= &(SSA_NAME_IMM_USE_NODE (var
));
373 imm
->imm_use
= imm
->end_p
->next
;
374 #ifdef ENABLE_CHECKING
375 imm
->iter_node
.next
= imm
->imm_use
->next
;
377 if (end_readonly_imm_use_p (imm
))
378 return NULL_USE_OPERAND_P
;
382 /* Bump IMM to the next use in the list. */
383 static inline use_operand_p
384 next_readonly_imm_use (imm_use_iterator
*imm
)
386 use_operand_p old
= imm
->imm_use
;
388 #ifdef ENABLE_CHECKING
389 /* If this assertion fails, it indicates the 'next' pointer has changed
390 since we the last bump. This indicates that the list is being modified
391 via stmt changes, or SET_USE, or somesuch thing, and you need to be
392 using the SAFE version of the iterator. */
393 gcc_assert (imm
->iter_node
.next
== old
->next
);
394 imm
->iter_node
.next
= old
->next
->next
;
397 imm
->imm_use
= old
->next
;
398 if (end_readonly_imm_use_p (imm
))
403 /* Return true if VAR has no uses. */
405 has_zero_uses (tree var
)
407 ssa_use_operand_t
*ptr
;
408 ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
409 /* A single use means there is no items in the list. */
410 return (ptr
== ptr
->next
);
413 /* Return true if VAR has a single use. */
415 has_single_use (tree var
)
417 ssa_use_operand_t
*ptr
;
418 ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
419 /* A single use means there is one item in the list. */
420 return (ptr
!= ptr
->next
&& ptr
== ptr
->next
->next
);
423 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
424 to the use pointer and stmt of occurrence. */
426 single_imm_use (tree var
, use_operand_p
*use_p
, tree
*stmt
)
428 ssa_use_operand_t
*ptr
;
430 ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
431 if (ptr
!= ptr
->next
&& ptr
== ptr
->next
->next
)
434 *stmt
= ptr
->next
->stmt
;
437 *use_p
= NULL_USE_OPERAND_P
;
442 /* Return the number of immediate uses of VAR. */
443 static inline unsigned int
444 num_imm_uses (tree var
)
446 ssa_use_operand_t
*ptr
, *start
;
449 start
= &(SSA_NAME_IMM_USE_NODE (var
));
451 for (ptr
= start
->next
; ptr
!= start
; ptr
= ptr
->next
)
458 /* Return the tree pointer to by USE. */
460 get_use_from_ptr (use_operand_p use
)
465 /* Return the tree pointer to by DEF. */
467 get_def_from_ptr (def_operand_p def
)
472 /* Return a def_operand_p pointer for the result of PHI. */
473 static inline def_operand_p
474 get_phi_result_ptr (tree phi
)
476 return &(PHI_RESULT_TREE (phi
));
479 /* Return a use_operand_p pointer for argument I of phinode PHI. */
480 static inline use_operand_p
481 get_phi_arg_def_ptr (tree phi
, int i
)
483 return &(PHI_ARG_IMM_USE_NODE (phi
,i
));
487 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
490 addresses_taken (tree stmt
)
492 stmt_ann_t ann
= stmt_ann (stmt
);
493 return ann
? ann
->addresses_taken
: NULL
;
496 /* Return the PHI nodes for basic block BB, or NULL if there are no
499 phi_nodes (basic_block bb
)
501 return bb
->phi_nodes
;
504 /* Set list of phi nodes of a basic block BB to L. */
507 set_phi_nodes (basic_block bb
, tree l
)
512 for (phi
= l
; phi
; phi
= PHI_CHAIN (phi
))
513 set_bb_for_stmt (phi
, bb
);
516 /* Return the phi argument which contains the specified use. */
519 phi_arg_index_from_use (use_operand_p use
)
521 struct phi_arg_d
*element
, *root
;
525 /* Since the use is the first thing in a PHI argument element, we can
526 calculate its index based on casting it to an argument, and performing
527 pointer arithmetic. */
529 phi
= USE_STMT (use
);
530 gcc_assert (TREE_CODE (phi
) == PHI_NODE
);
532 element
= (struct phi_arg_d
*)use
;
533 root
= &(PHI_ARG_ELT (phi
, 0));
534 index
= element
- root
;
536 #ifdef ENABLE_CHECKING
537 /* Make sure the calculation doesn't have any leftover bytes. If it does,
538 then imm_use is likely not the first element in phi_arg_d. */
540 (((char *)element
- (char *)root
) % sizeof (struct phi_arg_d
)) == 0);
541 gcc_assert (index
>= 0 && index
< PHI_ARG_CAPACITY (phi
));
547 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
550 set_is_used (tree var
)
552 var_ann_t ann
= get_var_ann (var
);
557 /* ----------------------------------------------------------------------- */
559 /* Return true if T is an executable statement. */
561 is_exec_stmt (tree t
)
563 return (t
&& !IS_EMPTY_STMT (t
) && t
!= error_mark_node
);
567 /* Return true if this stmt can be the target of a control transfer stmt such
570 is_label_stmt (tree t
)
573 switch (TREE_CODE (t
))
577 case CASE_LABEL_EXPR
:
585 /* Set the default definition for VAR to DEF. */
587 set_default_def (tree var
, tree def
)
589 var_ann_t ann
= get_var_ann (var
);
590 ann
->default_def
= def
;
593 /* Return the default definition for variable VAR, or NULL if none
596 default_def (tree var
)
598 var_ann_t ann
= var_ann (var
);
599 return ann
? ann
->default_def
: NULL_TREE
;
602 /* PHI nodes should contain only ssa_names and invariants. A test
603 for ssa_name is definitely simpler; don't let invalid contents
604 slip in in the meantime. */
607 phi_ssa_name_p (tree t
)
609 if (TREE_CODE (t
) == SSA_NAME
)
611 #ifdef ENABLE_CHECKING
612 gcc_assert (is_gimple_min_invariant (t
));
617 /* ----------------------------------------------------------------------- */
619 /* Return a block_stmt_iterator that points to beginning of basic
621 static inline block_stmt_iterator
622 bsi_start (basic_block bb
)
624 block_stmt_iterator bsi
;
626 bsi
.tsi
= tsi_start (bb
->stmt_list
);
629 gcc_assert (bb
->index
< 0);
631 bsi
.tsi
.container
= NULL
;
637 /* Return a block statement iterator that points to the last label in
640 static inline block_stmt_iterator
641 bsi_after_labels (basic_block bb
)
643 block_stmt_iterator bsi
;
644 tree_stmt_iterator next
;
650 gcc_assert (bb
->index
< 0);
652 bsi
.tsi
.container
= NULL
;
656 bsi
.tsi
= tsi_start (bb
->stmt_list
);
657 if (tsi_end_p (bsi
.tsi
))
660 /* Ensure that there are some labels. The rationale is that we want
661 to insert after the bsi that is returned, and these insertions should
662 be placed at the start of the basic block. This would not work if the
663 first statement was not label; rather fail here than enable the user
664 proceed in wrong way. */
665 gcc_assert (TREE_CODE (tsi_stmt (bsi
.tsi
)) == LABEL_EXPR
);
670 while (!tsi_end_p (next
)
671 && TREE_CODE (tsi_stmt (next
)) == LABEL_EXPR
)
680 /* Return a block statement iterator that points to the end of basic
682 static inline block_stmt_iterator
683 bsi_last (basic_block bb
)
685 block_stmt_iterator bsi
;
687 bsi
.tsi
= tsi_last (bb
->stmt_list
);
690 gcc_assert (bb
->index
< 0);
692 bsi
.tsi
.container
= NULL
;
698 /* Return true if block statement iterator I has reached the end of
701 bsi_end_p (block_stmt_iterator i
)
703 return tsi_end_p (i
.tsi
);
706 /* Modify block statement iterator I so that it is at the next
707 statement in the basic block. */
709 bsi_next (block_stmt_iterator
*i
)
714 /* Modify block statement iterator I so that it is at the previous
715 statement in the basic block. */
717 bsi_prev (block_stmt_iterator
*i
)
722 /* Return the statement that block statement iterator I is currently
725 bsi_stmt (block_stmt_iterator i
)
727 return tsi_stmt (i
.tsi
);
730 /* Return a pointer to the statement that block statement iterator I
733 bsi_stmt_ptr (block_stmt_iterator i
)
735 return tsi_stmt_ptr (i
.tsi
);
738 /* Returns the loop of the statement STMT. */
740 static inline struct loop
*
741 loop_containing_stmt (tree stmt
)
743 basic_block bb
= bb_for_stmt (stmt
);
747 return bb
->loop_father
;
750 /* Return true if VAR is a clobbered by function calls. */
752 is_call_clobbered (tree var
)
754 return is_global_var (var
)
755 || bitmap_bit_p (call_clobbered_vars
, var_ann (var
)->uid
);
758 /* Mark variable VAR as being clobbered by function calls. */
760 mark_call_clobbered (tree var
)
762 var_ann_t ann
= var_ann (var
);
763 /* If VAR is a memory tag, then we need to consider it a global
764 variable. This is because the pointer that VAR represents has
765 been found to point to either an arbitrary location or to a known
766 location in global memory. */
767 if (ann
->mem_tag_kind
!= NOT_A_TAG
&& ann
->mem_tag_kind
!= STRUCT_FIELD
)
768 DECL_EXTERNAL (var
) = 1;
769 bitmap_set_bit (call_clobbered_vars
, ann
->uid
);
770 ssa_call_clobbered_cache_valid
= false;
771 ssa_ro_call_cache_valid
= false;
774 /* Clear the call-clobbered attribute from variable VAR. */
776 clear_call_clobbered (tree var
)
778 var_ann_t ann
= var_ann (var
);
779 if (ann
->mem_tag_kind
!= NOT_A_TAG
&& ann
->mem_tag_kind
!= STRUCT_FIELD
)
780 DECL_EXTERNAL (var
) = 0;
781 bitmap_clear_bit (call_clobbered_vars
, ann
->uid
);
782 ssa_call_clobbered_cache_valid
= false;
783 ssa_ro_call_cache_valid
= false;
786 /* Mark variable VAR as being non-addressable. */
788 mark_non_addressable (tree var
)
790 bitmap_clear_bit (call_clobbered_vars
, var_ann (var
)->uid
);
791 TREE_ADDRESSABLE (var
) = 0;
792 ssa_call_clobbered_cache_valid
= false;
793 ssa_ro_call_cache_valid
= false;
796 /* Return the common annotation for T. Return NULL if the annotation
797 doesn't already exist. */
798 static inline tree_ann_t
801 return t
->common
.ann
;
804 /* Return a common annotation for T. Create the constant annotation if it
806 static inline tree_ann_t
807 get_tree_ann (tree t
)
809 tree_ann_t ann
= tree_ann (t
);
810 return (ann
) ? ann
: create_tree_ann (t
);
813 /* ----------------------------------------------------------------------- */
815 /* The following set of routines are used to iterator over various type of
818 /* Return true if PTR is finished iterating. */
820 op_iter_done (ssa_op_iter
*ptr
)
825 /* Get the next iterator use value for PTR. */
826 static inline use_operand_p
827 op_iter_next_use (ssa_op_iter
*ptr
)
830 #ifdef ENABLE_CHECKING
831 gcc_assert (ptr
->iter_type
== ssa_op_iter_use
);
835 use_p
= USE_OP_PTR (ptr
->uses
);
836 ptr
->uses
= ptr
->uses
->next
;
841 use_p
= VUSE_OP_PTR (ptr
->vuses
);
842 ptr
->vuses
= ptr
->vuses
->next
;
847 use_p
= MAYDEF_OP_PTR (ptr
->mayuses
);
848 ptr
->mayuses
= ptr
->mayuses
->next
;
853 use_p
= MUSTDEF_KILL_PTR (ptr
->mustkills
);
854 ptr
->mustkills
= ptr
->mustkills
->next
;
857 if (ptr
->phi_i
< ptr
->num_phi
)
859 return PHI_ARG_DEF_PTR (ptr
->phi_stmt
, (ptr
->phi_i
)++);
862 return NULL_USE_OPERAND_P
;
865 /* Get the next iterator def value for PTR. */
866 static inline def_operand_p
867 op_iter_next_def (ssa_op_iter
*ptr
)
870 #ifdef ENABLE_CHECKING
871 gcc_assert (ptr
->iter_type
== ssa_op_iter_def
);
875 def_p
= DEF_OP_PTR (ptr
->defs
);
876 ptr
->defs
= ptr
->defs
->next
;
881 def_p
= MUSTDEF_RESULT_PTR (ptr
->mustdefs
);
882 ptr
->mustdefs
= ptr
->mustdefs
->next
;
887 def_p
= MAYDEF_RESULT_PTR (ptr
->maydefs
);
888 ptr
->maydefs
= ptr
->maydefs
->next
;
892 return NULL_DEF_OPERAND_P
;
895 /* Get the next iterator tree value for PTR. */
897 op_iter_next_tree (ssa_op_iter
*ptr
)
900 #ifdef ENABLE_CHECKING
901 gcc_assert (ptr
->iter_type
== ssa_op_iter_tree
);
905 val
= USE_OP (ptr
->uses
);
906 ptr
->uses
= ptr
->uses
->next
;
911 val
= VUSE_OP (ptr
->vuses
);
912 ptr
->vuses
= ptr
->vuses
->next
;
917 val
= MAYDEF_OP (ptr
->mayuses
);
918 ptr
->mayuses
= ptr
->mayuses
->next
;
923 val
= MUSTDEF_KILL (ptr
->mustkills
);
924 ptr
->mustkills
= ptr
->mustkills
->next
;
929 val
= DEF_OP (ptr
->defs
);
930 ptr
->defs
= ptr
->defs
->next
;
935 val
= MUSTDEF_RESULT (ptr
->mustdefs
);
936 ptr
->mustdefs
= ptr
->mustdefs
->next
;
941 val
= MAYDEF_RESULT (ptr
->maydefs
);
942 ptr
->maydefs
= ptr
->maydefs
->next
;
952 /* This functions clears the iterator PTR, and marks it done. This is normally
953 used to prevent warnings in the compile about might be uninitailzied
957 clear_and_done_ssa_iter (ssa_op_iter
*ptr
)
964 ptr
->mustdefs
= NULL
;
965 ptr
->mustkills
= NULL
;
966 ptr
->iter_type
= ssa_op_iter_none
;
969 ptr
->phi_stmt
= NULL_TREE
;
973 /* Initialize the iterator PTR to the virtual defs in STMT. */
975 op_iter_init (ssa_op_iter
*ptr
, tree stmt
, int flags
)
977 #ifdef ENABLE_CHECKING
978 gcc_assert (stmt_ann (stmt
));
981 ptr
->defs
= (flags
& SSA_OP_DEF
) ? DEF_OPS (stmt
) : NULL
;
982 ptr
->uses
= (flags
& SSA_OP_USE
) ? USE_OPS (stmt
) : NULL
;
983 ptr
->vuses
= (flags
& SSA_OP_VUSE
) ? VUSE_OPS (stmt
) : NULL
;
984 ptr
->maydefs
= (flags
& SSA_OP_VMAYDEF
) ? MAYDEF_OPS (stmt
) : NULL
;
985 ptr
->mayuses
= (flags
& SSA_OP_VMAYUSE
) ? MAYDEF_OPS (stmt
) : NULL
;
986 ptr
->mustdefs
= (flags
& SSA_OP_VMUSTDEF
) ? MUSTDEF_OPS (stmt
) : NULL
;
987 ptr
->mustkills
= (flags
& SSA_OP_VMUSTKILL
) ? MUSTDEF_OPS (stmt
) : NULL
;
992 ptr
->phi_stmt
= NULL_TREE
;
995 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
997 static inline use_operand_p
998 op_iter_init_use (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1000 gcc_assert ((flags
& SSA_OP_ALL_DEFS
) == 0);
1001 op_iter_init (ptr
, stmt
, flags
);
1002 ptr
->iter_type
= ssa_op_iter_use
;
1003 return op_iter_next_use (ptr
);
1006 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1008 static inline def_operand_p
1009 op_iter_init_def (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1011 gcc_assert ((flags
& (SSA_OP_ALL_USES
| SSA_OP_VIRTUAL_KILLS
)) == 0);
1012 op_iter_init (ptr
, stmt
, flags
);
1013 ptr
->iter_type
= ssa_op_iter_def
;
1014 return op_iter_next_def (ptr
);
1017 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1018 the first operand as a tree. */
1020 op_iter_init_tree (ssa_op_iter
*ptr
, tree stmt
, int flags
)
1022 op_iter_init (ptr
, stmt
, flags
);
1023 ptr
->iter_type
= ssa_op_iter_tree
;
1024 return op_iter_next_tree (ptr
);
1027 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1030 op_iter_next_maymustdef (use_operand_p
*use
, def_operand_p
*def
,
1033 #ifdef ENABLE_CHECKING
1034 gcc_assert (ptr
->iter_type
== ssa_op_iter_maymustdef
);
1038 *def
= MAYDEF_RESULT_PTR (ptr
->mayuses
);
1039 *use
= MAYDEF_OP_PTR (ptr
->mayuses
);
1040 ptr
->mayuses
= ptr
->mayuses
->next
;
1046 *def
= MUSTDEF_RESULT_PTR (ptr
->mustkills
);
1047 *use
= MUSTDEF_KILL_PTR (ptr
->mustkills
);
1048 ptr
->mustkills
= ptr
->mustkills
->next
;
1052 *def
= NULL_DEF_OPERAND_P
;
1053 *use
= NULL_USE_OPERAND_P
;
1059 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1062 op_iter_init_maydef (ssa_op_iter
*ptr
, tree stmt
, use_operand_p
*use
,
1065 gcc_assert (TREE_CODE (stmt
) != PHI_NODE
);
1067 op_iter_init (ptr
, stmt
, SSA_OP_VMAYUSE
);
1068 ptr
->iter_type
= ssa_op_iter_maymustdef
;
1069 op_iter_next_maymustdef (use
, def
, ptr
);
1073 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1076 op_iter_init_mustdef (ssa_op_iter
*ptr
, tree stmt
, use_operand_p
*kill
,
1079 gcc_assert (TREE_CODE (stmt
) != PHI_NODE
);
1081 op_iter_init (ptr
, stmt
, SSA_OP_VMUSTKILL
);
1082 ptr
->iter_type
= ssa_op_iter_maymustdef
;
1083 op_iter_next_maymustdef (kill
, def
, ptr
);
1086 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1089 op_iter_init_must_and_may_def (ssa_op_iter
*ptr
, tree stmt
,
1090 use_operand_p
*kill
, def_operand_p
*def
)
1092 gcc_assert (TREE_CODE (stmt
) != PHI_NODE
);
1094 op_iter_init (ptr
, stmt
, SSA_OP_VMUSTKILL
|SSA_OP_VMAYUSE
);
1095 ptr
->iter_type
= ssa_op_iter_maymustdef
;
1096 op_iter_next_maymustdef (kill
, def
, ptr
);
1100 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1101 return NULL. PTR is the iterator to use. */
1103 single_ssa_tree_operand (tree stmt
, int flags
)
1108 var
= op_iter_init_tree (&iter
, stmt
, flags
);
1109 if (op_iter_done (&iter
))
1111 op_iter_next_tree (&iter
);
1112 if (op_iter_done (&iter
))
1118 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1119 return NULL. PTR is the iterator to use. */
1120 static inline use_operand_p
1121 single_ssa_use_operand (tree stmt
, int flags
)
1126 var
= op_iter_init_use (&iter
, stmt
, flags
);
1127 if (op_iter_done (&iter
))
1128 return NULL_USE_OPERAND_P
;
1129 op_iter_next_use (&iter
);
1130 if (op_iter_done (&iter
))
1132 return NULL_USE_OPERAND_P
;
1137 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1138 return NULL. PTR is the iterator to use. */
1139 static inline def_operand_p
1140 single_ssa_def_operand (tree stmt
, int flags
)
1145 var
= op_iter_init_def (&iter
, stmt
, flags
);
1146 if (op_iter_done (&iter
))
1147 return NULL_DEF_OPERAND_P
;
1148 op_iter_next_def (&iter
);
1149 if (op_iter_done (&iter
))
1151 return NULL_DEF_OPERAND_P
;
1155 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1156 return NULL. PTR is the iterator to use. */
1158 zero_ssa_operands (tree stmt
, int flags
)
1162 op_iter_init_tree (&iter
, stmt
, flags
);
1163 return op_iter_done (&iter
);
1167 /* Return the number of operands matching FLAGS in STMT. */
1169 num_ssa_operands (tree stmt
, int flags
)
1175 FOR_EACH_SSA_TREE_OPERAND (t
, stmt
, iter
, flags
)
1181 /* Delink all immediate_use information for STMT. */
1183 delink_stmt_imm_use (tree stmt
)
1186 use_operand_p use_p
;
1188 if (ssa_operands_active ())
1189 FOR_EACH_SSA_USE_OPERAND (use_p
, stmt
, iter
,
1190 (SSA_OP_ALL_USES
| SSA_OP_ALL_KILLS
))
1191 delink_imm_use (use_p
);
1195 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1196 in STMT2. TRUE is returned if they are the same. STMTs can be NULL. */
1198 compare_ssa_operands_equal (tree stmt1
, tree stmt2
, int flags
)
1200 ssa_op_iter iter1
, iter2
;
1201 tree op1
= NULL_TREE
;
1202 tree op2
= NULL_TREE
;
1208 look1
= stmt1
&& stmt_ann (stmt1
);
1209 look2
= stmt2
&& stmt_ann (stmt2
);
1213 op1
= op_iter_init_tree (&iter1
, stmt1
, flags
);
1215 return op_iter_done (&iter1
);
1218 clear_and_done_ssa_iter (&iter1
);
1222 op2
= op_iter_init_tree (&iter2
, stmt2
, flags
);
1224 return op_iter_done (&iter2
);
1227 clear_and_done_ssa_iter (&iter2
);
1229 while (!op_iter_done (&iter1
) && !op_iter_done (&iter2
))
1233 op1
= op_iter_next_tree (&iter1
);
1234 op2
= op_iter_next_tree (&iter2
);
1237 return (op_iter_done (&iter1
) && op_iter_done (&iter2
));
1241 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1242 Otherwise return NULL_DEF_OPERAND_P. */
1244 single_phi_def (tree stmt
, int flags
)
1246 tree def
= PHI_RESULT (stmt
);
1247 if ((flags
& SSA_OP_DEF
) && is_gimple_reg (def
))
1249 if ((flags
& SSA_OP_VIRTUAL_DEFS
) && !is_gimple_reg (def
))
1254 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
1255 be either SSA_OP_USES or SAS_OP_VIRTUAL_USES. */
1256 static inline use_operand_p
1257 op_iter_init_phiuse (ssa_op_iter
*ptr
, tree phi
, int flags
)
1259 tree phi_def
= PHI_RESULT (phi
);
1262 clear_and_done_ssa_iter (ptr
);
1265 gcc_assert ((flags
& (SSA_OP_USE
| SSA_OP_VIRTUAL_USES
)) != 0);
1267 comp
= (is_gimple_reg (phi_def
) ? SSA_OP_USE
: SSA_OP_VIRTUAL_USES
);
1269 /* If the PHI node doesn't the operand type we care about, we're done. */
1270 if ((flags
& comp
) == 0)
1273 return NULL_USE_OPERAND_P
;
1276 ptr
->phi_stmt
= phi
;
1277 ptr
->num_phi
= PHI_NUM_ARGS (phi
);
1278 ptr
->iter_type
= ssa_op_iter_use
;
1279 return op_iter_next_use (ptr
);
1283 /* Start an iterator for a PHI definition. */
1285 static inline def_operand_p
1286 op_iter_init_phidef (ssa_op_iter
*ptr
, tree phi
, int flags
)
1288 tree phi_def
= PHI_RESULT (phi
);
1291 clear_and_done_ssa_iter (ptr
);
1294 gcc_assert ((flags
& (SSA_OP_DEF
| SSA_OP_VIRTUAL_DEFS
)) != 0);
1296 comp
= (is_gimple_reg (phi_def
) ? SSA_OP_DEF
: SSA_OP_VIRTUAL_DEFS
);
1298 /* If the PHI node doesn't the operand type we care about, we're done. */
1299 if ((flags
& comp
) == 0)
1302 return NULL_USE_OPERAND_P
;
1305 ptr
->iter_type
= ssa_op_iter_def
;
1306 /* The first call to op_iter_next_def will terminate the iterator since
1307 all the fields are NULL. Simply return the result here as the first and
1308 therefore only result. */
1309 return PHI_RESULT_PTR (phi
);
1314 /* Return true if VAR cannot be modified by the program. */
1317 unmodifiable_var_p (tree var
)
1319 if (TREE_CODE (var
) == SSA_NAME
)
1320 var
= SSA_NAME_VAR (var
);
1321 return TREE_READONLY (var
) && (TREE_STATIC (var
) || DECL_EXTERNAL (var
));
1324 /* Return true if REF, a COMPONENT_REF, has an ARRAY_REF somewhere in it. */
1327 ref_contains_array_ref (tree ref
)
1329 while (handled_component_p (ref
))
1331 if (TREE_CODE (ref
) == ARRAY_REF
)
1333 ref
= TREE_OPERAND (ref
, 0);
1338 /* Given a variable VAR, lookup and return a pointer to the list of
1339 subvariables for it. */
1341 static inline subvar_t
*
1342 lookup_subvars_for_var (tree var
)
1344 var_ann_t ann
= var_ann (var
);
1346 return &ann
->subvars
;
1349 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1350 NULL, if there are no subvariables. */
1352 static inline subvar_t
1353 get_subvars_for_var (tree var
)
1357 gcc_assert (SSA_VAR_P (var
));
1359 if (TREE_CODE (var
) == SSA_NAME
)
1360 subvars
= *(lookup_subvars_for_var (SSA_NAME_VAR (var
)));
1362 subvars
= *(lookup_subvars_for_var (var
));
1366 /* Return true if V is a tree that we can have subvars for.
1367 Normally, this is any aggregate type, however, due to implementation
1368 limitations ATM, we exclude array types as well. */
1371 var_can_have_subvars (tree v
)
1373 return (AGGREGATE_TYPE_P (TREE_TYPE (v
)) &&
1374 TREE_CODE (TREE_TYPE (v
)) != ARRAY_TYPE
);
1378 /* Return true if OFFSET and SIZE define a range that overlaps with some
1379 portion of the range of SV, a subvar. If there was an exact overlap,
1380 *EXACT will be set to true upon return. */
1383 overlap_subvar (HOST_WIDE_INT offset
, HOST_WIDE_INT size
,
1384 subvar_t sv
, bool *exact
)
1386 /* There are three possible cases of overlap.
1387 1. We can have an exact overlap, like so:
1388 |offset, offset + size |
1389 |sv->offset, sv->offset + sv->size |
1391 2. We can have offset starting after sv->offset, like so:
1393 |offset, offset + size |
1394 |sv->offset, sv->offset + sv->size |
1396 3. We can have offset starting before sv->offset, like so:
1398 |offset, offset + size |
1399 |sv->offset, sv->offset + sv->size|
1404 if (offset
== sv
->offset
&& size
== sv
->size
)
1410 else if (offset
>= sv
->offset
&& offset
< (sv
->offset
+ sv
->size
))
1414 else if (offset
< sv
->offset
&& (offset
+ size
> sv
->offset
))
1422 #endif /* _TREE_FLOW_INLINE_H */