1 /* Inline functions for tree-flow.h
2 Copyright (C) 2001, 2003, 2005, 2006, 2007, 2008 Free Software
4 Contributed by Diego Novillo <dnovillo@redhat.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #ifndef _TREE_FLOW_INLINE_H
23 #define _TREE_FLOW_INLINE_H 1
25 /* Inline functions for manipulating various data structures defined in
26 tree-flow.h. See tree-flow.h for documentation. */
28 /* Return true when gimple SSA form was built.
29 gimple_in_ssa_p is queried by gimplifier in various early stages before SSA
30 infrastructure is initialized. Check for presence of the datastructures
33 gimple_in_ssa_p (const struct function
*fun
)
35 return fun
&& fun
->gimple_df
&& fun
->gimple_df
->in_ssa_p
;
38 /* Array of all variables referenced in the function. */
40 gimple_referenced_vars (const struct function
*fun
)
44 return fun
->gimple_df
->referenced_vars
;
47 /* Artificial variable used to model the effects of nonlocal
50 gimple_nonlocal_all (const struct function
*fun
)
52 gcc_assert (fun
&& fun
->gimple_df
);
53 return fun
->gimple_df
->nonlocal_all
;
56 /* Artificial variable used for the virtual operand FUD chain. */
58 gimple_vop (const struct function
*fun
)
60 gcc_assert (fun
&& fun
->gimple_df
);
61 return fun
->gimple_df
->vop
;
64 /* Initialize the hashtable iterator HTI to point to hashtable TABLE */
67 first_htab_element (htab_iterator
*hti
, htab_t table
)
70 hti
->slot
= table
->entries
;
71 hti
->limit
= hti
->slot
+ htab_size (table
);
75 if (x
!= HTAB_EMPTY_ENTRY
&& x
!= HTAB_DELETED_ENTRY
)
77 } while (++(hti
->slot
) < hti
->limit
);
79 if (hti
->slot
< hti
->limit
)
84 /* Return current non-empty/deleted slot of the hashtable pointed to by HTI,
85 or NULL if we have reached the end. */
88 end_htab_p (const htab_iterator
*hti
)
90 if (hti
->slot
>= hti
->limit
)
95 /* Advance the hashtable iterator pointed to by HTI to the next element of the
99 next_htab_element (htab_iterator
*hti
)
101 while (++(hti
->slot
) < hti
->limit
)
103 PTR x
= *(hti
->slot
);
104 if (x
!= HTAB_EMPTY_ENTRY
&& x
!= HTAB_DELETED_ENTRY
)
110 /* Initialize ITER to point to the first referenced variable in the
111 referenced_vars hashtable, and return that variable. */
114 first_referenced_var (referenced_var_iterator
*iter
)
116 return (tree
) first_htab_element (&iter
->hti
,
117 gimple_referenced_vars (cfun
));
120 /* Return true if we have hit the end of the referenced variables ITER is
121 iterating through. */
124 end_referenced_vars_p (const referenced_var_iterator
*iter
)
126 return end_htab_p (&iter
->hti
);
129 /* Make ITER point to the next referenced_var in the referenced_var hashtable,
130 and return that variable. */
133 next_referenced_var (referenced_var_iterator
*iter
)
135 return (tree
) next_htab_element (&iter
->hti
);
138 /* Fill up VEC with the variables in the referenced vars hashtable. */
141 fill_referenced_var_vec (VEC (tree
, heap
) **vec
)
143 referenced_var_iterator rvi
;
146 FOR_EACH_REFERENCED_VAR (var
, rvi
)
147 VEC_safe_push (tree
, heap
, *vec
, var
);
150 /* Return the variable annotation for T, which must be a _DECL node.
151 Return NULL if the variable annotation doesn't already exist. */
152 static inline var_ann_t
153 var_ann (const_tree t
)
155 const var_ann_t
*p
= DECL_VAR_ANN_PTR (t
);
156 return p
? *p
: NULL
;
159 /* Return the variable annotation for T, which must be a _DECL node.
160 Create the variable annotation if it doesn't exist. */
161 static inline var_ann_t
162 get_var_ann (tree var
)
164 var_ann_t
*p
= DECL_VAR_ANN_PTR (var
);
166 return *p
? *p
: create_var_ann (var
);
169 /* Get the number of the next statement uid to be allocated. */
170 static inline unsigned int
171 gimple_stmt_max_uid (struct function
*fn
)
173 return fn
->last_stmt_uid
;
176 /* Set the number of the next statement uid to be allocated. */
178 set_gimple_stmt_max_uid (struct function
*fn
, unsigned int maxid
)
180 fn
->last_stmt_uid
= maxid
;
183 /* Set the number of the next statement uid to be allocated. */
184 static inline unsigned int
185 inc_gimple_stmt_max_uid (struct function
*fn
)
187 return fn
->last_stmt_uid
++;
190 /* Return the line number for EXPR, or return -1 if we have no line
191 number information for it. */
193 get_lineno (const_gimple stmt
)
200 loc
= gimple_location (stmt
);
201 if (loc
== UNKNOWN_LOCATION
)
204 return LOCATION_LINE (loc
);
207 /* Delink an immediate_uses node from its chain. */
209 delink_imm_use (ssa_use_operand_t
*linknode
)
211 /* Return if this node is not in a list. */
212 if (linknode
->prev
== NULL
)
215 linknode
->prev
->next
= linknode
->next
;
216 linknode
->next
->prev
= linknode
->prev
;
217 linknode
->prev
= NULL
;
218 linknode
->next
= NULL
;
221 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
223 link_imm_use_to_list (ssa_use_operand_t
*linknode
, ssa_use_operand_t
*list
)
225 /* Link the new node at the head of the list. If we are in the process of
226 traversing the list, we won't visit any new nodes added to it. */
227 linknode
->prev
= list
;
228 linknode
->next
= list
->next
;
229 list
->next
->prev
= linknode
;
230 list
->next
= linknode
;
233 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
235 link_imm_use (ssa_use_operand_t
*linknode
, tree def
)
237 ssa_use_operand_t
*root
;
239 if (!def
|| TREE_CODE (def
) != SSA_NAME
)
240 linknode
->prev
= NULL
;
243 root
= &(SSA_NAME_IMM_USE_NODE (def
));
244 #ifdef ENABLE_CHECKING
246 gcc_assert (*(linknode
->use
) == def
);
248 link_imm_use_to_list (linknode
, root
);
252 /* Set the value of a use pointed to by USE to VAL. */
254 set_ssa_use_from_ptr (use_operand_p use
, tree val
)
256 delink_imm_use (use
);
258 link_imm_use (use
, val
);
261 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
264 link_imm_use_stmt (ssa_use_operand_t
*linknode
, tree def
, gimple stmt
)
267 link_imm_use (linknode
, def
);
269 link_imm_use (linknode
, NULL
);
270 linknode
->loc
.stmt
= stmt
;
273 /* Relink a new node in place of an old node in the list. */
275 relink_imm_use (ssa_use_operand_t
*node
, ssa_use_operand_t
*old
)
277 /* The node one had better be in the same list. */
278 gcc_assert (*(old
->use
) == *(node
->use
));
279 node
->prev
= old
->prev
;
280 node
->next
= old
->next
;
283 old
->prev
->next
= node
;
284 old
->next
->prev
= node
;
285 /* Remove the old node from the list. */
290 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
293 relink_imm_use_stmt (ssa_use_operand_t
*linknode
, ssa_use_operand_t
*old
,
297 relink_imm_use (linknode
, old
);
299 link_imm_use (linknode
, NULL
);
300 linknode
->loc
.stmt
= stmt
;
304 /* Return true is IMM has reached the end of the immediate use list. */
306 end_readonly_imm_use_p (const imm_use_iterator
*imm
)
308 return (imm
->imm_use
== imm
->end_p
);
311 /* Initialize iterator IMM to process the list for VAR. */
312 static inline use_operand_p
313 first_readonly_imm_use (imm_use_iterator
*imm
, tree var
)
315 gcc_assert (TREE_CODE (var
) == SSA_NAME
);
317 imm
->end_p
= &(SSA_NAME_IMM_USE_NODE (var
));
318 imm
->imm_use
= imm
->end_p
->next
;
319 #ifdef ENABLE_CHECKING
320 imm
->iter_node
.next
= imm
->imm_use
->next
;
322 if (end_readonly_imm_use_p (imm
))
323 return NULL_USE_OPERAND_P
;
327 /* Bump IMM to the next use in the list. */
328 static inline use_operand_p
329 next_readonly_imm_use (imm_use_iterator
*imm
)
331 use_operand_p old
= imm
->imm_use
;
333 #ifdef ENABLE_CHECKING
334 /* If this assertion fails, it indicates the 'next' pointer has changed
335 since the last bump. This indicates that the list is being modified
336 via stmt changes, or SET_USE, or somesuch thing, and you need to be
337 using the SAFE version of the iterator. */
338 gcc_assert (imm
->iter_node
.next
== old
->next
);
339 imm
->iter_node
.next
= old
->next
->next
;
342 imm
->imm_use
= old
->next
;
343 if (end_readonly_imm_use_p (imm
))
344 return NULL_USE_OPERAND_P
;
349 extern bool has_zero_uses_1 (const ssa_use_operand_t
*head
);
350 extern bool single_imm_use_1 (const ssa_use_operand_t
*head
,
351 use_operand_p
*use_p
, gimple
*stmt
);
353 /* Return true if VAR has no nondebug uses. */
355 has_zero_uses (const_tree var
)
357 const ssa_use_operand_t
*const ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
359 /* A single use_operand means there is no items in the list. */
360 if (ptr
== ptr
->next
)
363 /* If there are debug stmts, we have to look at each use and see
364 whether there are any nondebug uses. */
365 if (!MAY_HAVE_DEBUG_STMTS
)
368 return has_zero_uses_1 (ptr
);
371 /* Return true if VAR has a single nondebug use. */
373 has_single_use (const_tree var
)
375 const ssa_use_operand_t
*const ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
377 /* If there aren't any uses whatsoever, we're done. */
378 if (ptr
== ptr
->next
)
381 /* If there's a single use, check that it's not a debug stmt. */
382 if (ptr
== ptr
->next
->next
)
383 return !is_gimple_debug (USE_STMT (ptr
->next
));
385 /* If there are debug stmts, we have to look at each of them. */
386 if (!MAY_HAVE_DEBUG_STMTS
)
389 return single_imm_use_1 (ptr
, NULL
, NULL
);
393 /* If VAR has only a single immediate nondebug use, return true, and
394 set USE_P and STMT to the use pointer and stmt of occurrence. */
396 single_imm_use (const_tree var
, use_operand_p
*use_p
, gimple
*stmt
)
398 const ssa_use_operand_t
*const ptr
= &(SSA_NAME_IMM_USE_NODE (var
));
400 /* If there aren't any uses whatsoever, we're done. */
401 if (ptr
== ptr
->next
)
404 *use_p
= NULL_USE_OPERAND_P
;
409 /* If there's a single use, check that it's not a debug stmt. */
410 if (ptr
== ptr
->next
->next
)
412 if (!is_gimple_debug (USE_STMT (ptr
->next
)))
415 *stmt
= ptr
->next
->loc
.stmt
;
422 /* If there are debug stmts, we have to look at each of them. */
423 if (!MAY_HAVE_DEBUG_STMTS
)
426 return single_imm_use_1 (ptr
, use_p
, stmt
);
429 /* Return the number of nondebug immediate uses of VAR. */
430 static inline unsigned int
431 num_imm_uses (const_tree var
)
433 const ssa_use_operand_t
*const start
= &(SSA_NAME_IMM_USE_NODE (var
));
434 const ssa_use_operand_t
*ptr
;
435 unsigned int num
= 0;
437 if (!MAY_HAVE_DEBUG_STMTS
)
438 for (ptr
= start
->next
; ptr
!= start
; ptr
= ptr
->next
)
441 for (ptr
= start
->next
; ptr
!= start
; ptr
= ptr
->next
)
442 if (!is_gimple_debug (USE_STMT (ptr
)))
448 /* Return the tree pointed-to by USE. */
450 get_use_from_ptr (use_operand_p use
)
455 /* Return the tree pointed-to by DEF. */
457 get_def_from_ptr (def_operand_p def
)
462 /* Return a use_operand_p pointer for argument I of PHI node GS. */
464 static inline use_operand_p
465 gimple_phi_arg_imm_use_ptr (gimple gs
, int i
)
467 return &gimple_phi_arg (gs
, i
)->imm_use
;
470 /* Return the tree operand for argument I of PHI node GS. */
473 gimple_phi_arg_def (gimple gs
, size_t index
)
475 struct phi_arg_d
*pd
= gimple_phi_arg (gs
, index
);
476 return get_use_from_ptr (&pd
->imm_use
);
479 /* Return a pointer to the tree operand for argument I of PHI node GS. */
482 gimple_phi_arg_def_ptr (gimple gs
, size_t index
)
484 return &gimple_phi_arg (gs
, index
)->def
;
487 /* Return the edge associated with argument I of phi node GS. */
490 gimple_phi_arg_edge (gimple gs
, size_t i
)
492 return EDGE_PRED (gimple_bb (gs
), i
);
495 /* Return the source location of gimple argument I of phi node GS. */
497 static inline source_location
498 gimple_phi_arg_location (gimple gs
, size_t i
)
500 return gimple_phi_arg (gs
, i
)->locus
;
503 /* Return the source location of the argument on edge E of phi node GS. */
505 static inline source_location
506 gimple_phi_arg_location_from_edge (gimple gs
, edge e
)
508 return gimple_phi_arg (gs
, e
->dest_idx
)->locus
;
511 /* Set the source location of gimple argument I of phi node GS to LOC. */
514 gimple_phi_arg_set_location (gimple gs
, size_t i
, source_location loc
)
516 gimple_phi_arg (gs
, i
)->locus
= loc
;
519 /* Return TRUE if argument I of phi node GS has a location record. */
522 gimple_phi_arg_has_location (gimple gs
, size_t i
)
524 return gimple_phi_arg_location (gs
, i
) != UNKNOWN_LOCATION
;
528 /* Return the PHI nodes for basic block BB, or NULL if there are no
530 static inline gimple_seq
531 phi_nodes (const_basic_block bb
)
533 gcc_assert (!(bb
->flags
& BB_RTL
));
536 return bb
->il
.gimple
->phi_nodes
;
539 /* Set PHI nodes of a basic block BB to SEQ. */
542 set_phi_nodes (basic_block bb
, gimple_seq seq
)
544 gimple_stmt_iterator i
;
546 gcc_assert (!(bb
->flags
& BB_RTL
));
547 bb
->il
.gimple
->phi_nodes
= seq
;
549 for (i
= gsi_start (seq
); !gsi_end_p (i
); gsi_next (&i
))
550 gimple_set_bb (gsi_stmt (i
), bb
);
553 /* Return the phi argument which contains the specified use. */
556 phi_arg_index_from_use (use_operand_p use
)
558 struct phi_arg_d
*element
, *root
;
562 /* Since the use is the first thing in a PHI argument element, we can
563 calculate its index based on casting it to an argument, and performing
564 pointer arithmetic. */
566 phi
= USE_STMT (use
);
567 gcc_assert (gimple_code (phi
) == GIMPLE_PHI
);
569 element
= (struct phi_arg_d
*)use
;
570 root
= gimple_phi_arg (phi
, 0);
571 index
= element
- root
;
573 #ifdef ENABLE_CHECKING
574 /* Make sure the calculation doesn't have any leftover bytes. If it does,
575 then imm_use is likely not the first element in phi_arg_d. */
577 (((char *)element
- (char *)root
) % sizeof (struct phi_arg_d
)) == 0);
578 gcc_assert (index
< gimple_phi_capacity (phi
));
584 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
587 set_is_used (tree var
)
589 var_ann_t ann
= get_var_ann (var
);
594 /* Return true if T (assumed to be a DECL) is a global variable.
595 A variable is considered global if its storage is not automatic. */
598 is_global_var (const_tree t
)
600 return (TREE_STATIC (t
) || DECL_EXTERNAL (t
));
604 /* Return true if VAR may be aliased. A variable is considered as
605 maybe aliased if it has its address taken by the local TU
606 or possibly by another TU and might be modified through a pointer. */
609 may_be_aliased (const_tree var
)
611 return (TREE_CODE (var
) != CONST_DECL
612 && !((TREE_STATIC (var
) || TREE_PUBLIC (var
) || DECL_EXTERNAL (var
))
613 && TREE_READONLY (var
)
614 && !TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (var
)))
615 && (TREE_PUBLIC (var
)
616 || DECL_EXTERNAL (var
)
617 || TREE_ADDRESSABLE (var
)));
621 /* PHI nodes should contain only ssa_names and invariants. A test
622 for ssa_name is definitely simpler; don't let invalid contents
623 slip in in the meantime. */
626 phi_ssa_name_p (const_tree t
)
628 if (TREE_CODE (t
) == SSA_NAME
)
630 #ifdef ENABLE_CHECKING
631 gcc_assert (is_gimple_min_invariant (t
));
637 /* Returns the loop of the statement STMT. */
639 static inline struct loop
*
640 loop_containing_stmt (gimple stmt
)
642 basic_block bb
= gimple_bb (stmt
);
646 return bb
->loop_father
;
650 /* Return true if VAR is clobbered by function calls. */
652 is_call_clobbered (const_tree var
)
654 return (is_global_var (var
)
655 || (may_be_aliased (var
)
656 && pt_solution_includes (&cfun
->gimple_df
->escaped
, var
)));
659 /* Return true if VAR is used by function calls. */
661 is_call_used (const_tree var
)
663 return (is_call_clobbered (var
)
664 || (may_be_aliased (var
)
665 && pt_solution_includes (&cfun
->gimple_df
->callused
, var
)));
668 /* ----------------------------------------------------------------------- */
670 /* The following set of routines are used to iterator over various type of
673 /* Return true if PTR is finished iterating. */
675 op_iter_done (const ssa_op_iter
*ptr
)
680 /* Get the next iterator use value for PTR. */
681 static inline use_operand_p
682 op_iter_next_use (ssa_op_iter
*ptr
)
685 #ifdef ENABLE_CHECKING
686 gcc_assert (ptr
->iter_type
== ssa_op_iter_use
);
690 use_p
= USE_OP_PTR (ptr
->uses
);
691 ptr
->uses
= ptr
->uses
->next
;
694 if (ptr
->phi_i
< ptr
->num_phi
)
696 return PHI_ARG_DEF_PTR (ptr
->phi_stmt
, (ptr
->phi_i
)++);
699 return NULL_USE_OPERAND_P
;
702 /* Get the next iterator def value for PTR. */
703 static inline def_operand_p
704 op_iter_next_def (ssa_op_iter
*ptr
)
707 #ifdef ENABLE_CHECKING
708 gcc_assert (ptr
->iter_type
== ssa_op_iter_def
);
712 def_p
= DEF_OP_PTR (ptr
->defs
);
713 ptr
->defs
= ptr
->defs
->next
;
717 return NULL_DEF_OPERAND_P
;
720 /* Get the next iterator tree value for PTR. */
722 op_iter_next_tree (ssa_op_iter
*ptr
)
725 #ifdef ENABLE_CHECKING
726 gcc_assert (ptr
->iter_type
== ssa_op_iter_tree
);
730 val
= USE_OP (ptr
->uses
);
731 ptr
->uses
= ptr
->uses
->next
;
736 val
= DEF_OP (ptr
->defs
);
737 ptr
->defs
= ptr
->defs
->next
;
747 /* This functions clears the iterator PTR, and marks it done. This is normally
748 used to prevent warnings in the compile about might be uninitialized
752 clear_and_done_ssa_iter (ssa_op_iter
*ptr
)
756 ptr
->iter_type
= ssa_op_iter_none
;
759 ptr
->phi_stmt
= NULL
;
763 /* Initialize the iterator PTR to the virtual defs in STMT. */
765 op_iter_init (ssa_op_iter
*ptr
, gimple stmt
, int flags
)
767 /* We do not support iterating over virtual defs or uses without
768 iterating over defs or uses at the same time. */
769 gcc_assert ((!(flags
& SSA_OP_VDEF
) || (flags
& SSA_OP_DEF
))
770 && (!(flags
& SSA_OP_VUSE
) || (flags
& SSA_OP_USE
)));
771 ptr
->defs
= (flags
& (SSA_OP_DEF
|SSA_OP_VDEF
)) ? gimple_def_ops (stmt
) : NULL
;
772 if (!(flags
& SSA_OP_VDEF
)
774 && gimple_vdef (stmt
) != NULL_TREE
)
775 ptr
->defs
= ptr
->defs
->next
;
776 ptr
->uses
= (flags
& (SSA_OP_USE
|SSA_OP_VUSE
)) ? gimple_use_ops (stmt
) : NULL
;
777 if (!(flags
& SSA_OP_VUSE
)
779 && gimple_vuse (stmt
) != NULL_TREE
)
780 ptr
->uses
= ptr
->uses
->next
;
785 ptr
->phi_stmt
= NULL
;
788 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
790 static inline use_operand_p
791 op_iter_init_use (ssa_op_iter
*ptr
, gimple stmt
, int flags
)
793 gcc_assert ((flags
& SSA_OP_ALL_DEFS
) == 0
794 && (flags
& SSA_OP_USE
));
795 op_iter_init (ptr
, stmt
, flags
);
796 ptr
->iter_type
= ssa_op_iter_use
;
797 return op_iter_next_use (ptr
);
800 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
802 static inline def_operand_p
803 op_iter_init_def (ssa_op_iter
*ptr
, gimple stmt
, int flags
)
805 gcc_assert ((flags
& SSA_OP_ALL_USES
) == 0
806 && (flags
& SSA_OP_DEF
));
807 op_iter_init (ptr
, stmt
, flags
);
808 ptr
->iter_type
= ssa_op_iter_def
;
809 return op_iter_next_def (ptr
);
812 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
813 the first operand as a tree. */
815 op_iter_init_tree (ssa_op_iter
*ptr
, gimple stmt
, int flags
)
817 op_iter_init (ptr
, stmt
, flags
);
818 ptr
->iter_type
= ssa_op_iter_tree
;
819 return op_iter_next_tree (ptr
);
823 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
826 single_ssa_tree_operand (gimple stmt
, int flags
)
831 var
= op_iter_init_tree (&iter
, stmt
, flags
);
832 if (op_iter_done (&iter
))
834 op_iter_next_tree (&iter
);
835 if (op_iter_done (&iter
))
841 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
843 static inline use_operand_p
844 single_ssa_use_operand (gimple stmt
, int flags
)
849 var
= op_iter_init_use (&iter
, stmt
, flags
);
850 if (op_iter_done (&iter
))
851 return NULL_USE_OPERAND_P
;
852 op_iter_next_use (&iter
);
853 if (op_iter_done (&iter
))
855 return NULL_USE_OPERAND_P
;
860 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
862 static inline def_operand_p
863 single_ssa_def_operand (gimple stmt
, int flags
)
868 var
= op_iter_init_def (&iter
, stmt
, flags
);
869 if (op_iter_done (&iter
))
870 return NULL_DEF_OPERAND_P
;
871 op_iter_next_def (&iter
);
872 if (op_iter_done (&iter
))
874 return NULL_DEF_OPERAND_P
;
878 /* Return true if there are zero operands in STMT matching the type
881 zero_ssa_operands (gimple stmt
, int flags
)
885 op_iter_init_tree (&iter
, stmt
, flags
);
886 return op_iter_done (&iter
);
890 /* Return the number of operands matching FLAGS in STMT. */
892 num_ssa_operands (gimple stmt
, int flags
)
898 FOR_EACH_SSA_TREE_OPERAND (t
, stmt
, iter
, flags
)
904 /* Delink all immediate_use information for STMT. */
906 delink_stmt_imm_use (gimple stmt
)
911 if (ssa_operands_active ())
912 FOR_EACH_SSA_USE_OPERAND (use_p
, stmt
, iter
, SSA_OP_ALL_USES
)
913 delink_imm_use (use_p
);
917 /* If there is a single DEF in the PHI node which matches FLAG, return it.
918 Otherwise return NULL_DEF_OPERAND_P. */
920 single_phi_def (gimple stmt
, int flags
)
922 tree def
= PHI_RESULT (stmt
);
923 if ((flags
& SSA_OP_DEF
) && is_gimple_reg (def
))
925 if ((flags
& SSA_OP_VIRTUAL_DEFS
) && !is_gimple_reg (def
))
930 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
931 be either SSA_OP_USES or SSA_OP_VIRTUAL_USES. */
932 static inline use_operand_p
933 op_iter_init_phiuse (ssa_op_iter
*ptr
, gimple phi
, int flags
)
935 tree phi_def
= gimple_phi_result (phi
);
938 clear_and_done_ssa_iter (ptr
);
941 gcc_assert ((flags
& (SSA_OP_USE
| SSA_OP_VIRTUAL_USES
)) != 0);
943 comp
= (is_gimple_reg (phi_def
) ? SSA_OP_USE
: SSA_OP_VIRTUAL_USES
);
945 /* If the PHI node doesn't the operand type we care about, we're done. */
946 if ((flags
& comp
) == 0)
949 return NULL_USE_OPERAND_P
;
953 ptr
->num_phi
= gimple_phi_num_args (phi
);
954 ptr
->iter_type
= ssa_op_iter_use
;
955 return op_iter_next_use (ptr
);
959 /* Start an iterator for a PHI definition. */
961 static inline def_operand_p
962 op_iter_init_phidef (ssa_op_iter
*ptr
, gimple phi
, int flags
)
964 tree phi_def
= PHI_RESULT (phi
);
967 clear_and_done_ssa_iter (ptr
);
970 gcc_assert ((flags
& (SSA_OP_DEF
| SSA_OP_VIRTUAL_DEFS
)) != 0);
972 comp
= (is_gimple_reg (phi_def
) ? SSA_OP_DEF
: SSA_OP_VIRTUAL_DEFS
);
974 /* If the PHI node doesn't have the operand type we care about,
976 if ((flags
& comp
) == 0)
979 return NULL_DEF_OPERAND_P
;
982 ptr
->iter_type
= ssa_op_iter_def
;
983 /* The first call to op_iter_next_def will terminate the iterator since
984 all the fields are NULL. Simply return the result here as the first and
985 therefore only result. */
986 return PHI_RESULT_PTR (phi
);
989 /* Return true is IMM has reached the end of the immediate use stmt list. */
992 end_imm_use_stmt_p (const imm_use_iterator
*imm
)
994 return (imm
->imm_use
== imm
->end_p
);
997 /* Finished the traverse of an immediate use stmt list IMM by removing the
998 placeholder node from the list. */
1001 end_imm_use_stmt_traverse (imm_use_iterator
*imm
)
1003 delink_imm_use (&(imm
->iter_node
));
1006 /* Immediate use traversal of uses within a stmt require that all the
1007 uses on a stmt be sequentially listed. This routine is used to build up
1008 this sequential list by adding USE_P to the end of the current list
1009 currently delimited by HEAD and LAST_P. The new LAST_P value is
1012 static inline use_operand_p
1013 move_use_after_head (use_operand_p use_p
, use_operand_p head
,
1014 use_operand_p last_p
)
1016 gcc_assert (USE_FROM_PTR (use_p
) == USE_FROM_PTR (head
));
1017 /* Skip head when we find it. */
1020 /* If use_p is already linked in after last_p, continue. */
1021 if (last_p
->next
== use_p
)
1025 /* Delink from current location, and link in at last_p. */
1026 delink_imm_use (use_p
);
1027 link_imm_use_to_list (use_p
, last_p
);
1035 /* This routine will relink all uses with the same stmt as HEAD into the list
1036 immediately following HEAD for iterator IMM. */
1039 link_use_stmts_after (use_operand_p head
, imm_use_iterator
*imm
)
1041 use_operand_p use_p
;
1042 use_operand_p last_p
= head
;
1043 gimple head_stmt
= USE_STMT (head
);
1044 tree use
= USE_FROM_PTR (head
);
1045 ssa_op_iter op_iter
;
1048 /* Only look at virtual or real uses, depending on the type of HEAD. */
1049 flag
= (is_gimple_reg (use
) ? SSA_OP_USE
: SSA_OP_VIRTUAL_USES
);
1051 if (gimple_code (head_stmt
) == GIMPLE_PHI
)
1053 FOR_EACH_PHI_ARG (use_p
, head_stmt
, op_iter
, flag
)
1054 if (USE_FROM_PTR (use_p
) == use
)
1055 last_p
= move_use_after_head (use_p
, head
, last_p
);
1059 if (flag
== SSA_OP_USE
)
1061 FOR_EACH_SSA_USE_OPERAND (use_p
, head_stmt
, op_iter
, flag
)
1062 if (USE_FROM_PTR (use_p
) == use
)
1063 last_p
= move_use_after_head (use_p
, head
, last_p
);
1065 else if ((use_p
= gimple_vuse_op (head_stmt
)) != NULL_USE_OPERAND_P
)
1067 if (USE_FROM_PTR (use_p
) == use
)
1068 last_p
= move_use_after_head (use_p
, head
, last_p
);
1071 /* Link iter node in after last_p. */
1072 if (imm
->iter_node
.prev
!= NULL
)
1073 delink_imm_use (&imm
->iter_node
);
1074 link_imm_use_to_list (&(imm
->iter_node
), last_p
);
1077 /* Initialize IMM to traverse over uses of VAR. Return the first statement. */
1078 static inline gimple
1079 first_imm_use_stmt (imm_use_iterator
*imm
, tree var
)
1081 gcc_assert (TREE_CODE (var
) == SSA_NAME
);
1083 imm
->end_p
= &(SSA_NAME_IMM_USE_NODE (var
));
1084 imm
->imm_use
= imm
->end_p
->next
;
1085 imm
->next_imm_name
= NULL_USE_OPERAND_P
;
1087 /* iter_node is used as a marker within the immediate use list to indicate
1088 where the end of the current stmt's uses are. Initialize it to NULL
1089 stmt and use, which indicates a marker node. */
1090 imm
->iter_node
.prev
= NULL_USE_OPERAND_P
;
1091 imm
->iter_node
.next
= NULL_USE_OPERAND_P
;
1092 imm
->iter_node
.loc
.stmt
= NULL
;
1093 imm
->iter_node
.use
= NULL
;
1095 if (end_imm_use_stmt_p (imm
))
1098 link_use_stmts_after (imm
->imm_use
, imm
);
1100 return USE_STMT (imm
->imm_use
);
1103 /* Bump IMM to the next stmt which has a use of var. */
1105 static inline gimple
1106 next_imm_use_stmt (imm_use_iterator
*imm
)
1108 imm
->imm_use
= imm
->iter_node
.next
;
1109 if (end_imm_use_stmt_p (imm
))
1111 if (imm
->iter_node
.prev
!= NULL
)
1112 delink_imm_use (&imm
->iter_node
);
1116 link_use_stmts_after (imm
->imm_use
, imm
);
1117 return USE_STMT (imm
->imm_use
);
1120 /* This routine will return the first use on the stmt IMM currently refers
1123 static inline use_operand_p
1124 first_imm_use_on_stmt (imm_use_iterator
*imm
)
1126 imm
->next_imm_name
= imm
->imm_use
->next
;
1127 return imm
->imm_use
;
1130 /* Return TRUE if the last use on the stmt IMM refers to has been visited. */
1133 end_imm_use_on_stmt_p (const imm_use_iterator
*imm
)
1135 return (imm
->imm_use
== &(imm
->iter_node
));
1138 /* Bump to the next use on the stmt IMM refers to, return NULL if done. */
1140 static inline use_operand_p
1141 next_imm_use_on_stmt (imm_use_iterator
*imm
)
1143 imm
->imm_use
= imm
->next_imm_name
;
1144 if (end_imm_use_on_stmt_p (imm
))
1145 return NULL_USE_OPERAND_P
;
1148 imm
->next_imm_name
= imm
->imm_use
->next
;
1149 return imm
->imm_use
;
1153 /* Return true if VAR cannot be modified by the program. */
1156 unmodifiable_var_p (const_tree var
)
1158 if (TREE_CODE (var
) == SSA_NAME
)
1159 var
= SSA_NAME_VAR (var
);
1161 return TREE_READONLY (var
) && (TREE_STATIC (var
) || DECL_EXTERNAL (var
));
1164 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it. */
1167 array_ref_contains_indirect_ref (const_tree ref
)
1169 gcc_assert (TREE_CODE (ref
) == ARRAY_REF
);
1172 ref
= TREE_OPERAND (ref
, 0);
1173 } while (handled_component_p (ref
));
1175 return TREE_CODE (ref
) == INDIRECT_REF
;
1178 /* Return true if REF, a handled component reference, has an ARRAY_REF
1182 ref_contains_array_ref (const_tree ref
)
1184 gcc_assert (handled_component_p (ref
));
1187 if (TREE_CODE (ref
) == ARRAY_REF
)
1189 ref
= TREE_OPERAND (ref
, 0);
1190 } while (handled_component_p (ref
));
1195 /* Return true if REF has an VIEW_CONVERT_EXPR somewhere in it. */
1198 contains_view_convert_expr_p (const_tree ref
)
1200 while (handled_component_p (ref
))
1202 if (TREE_CODE (ref
) == VIEW_CONVERT_EXPR
)
1204 ref
= TREE_OPERAND (ref
, 0);
1210 /* Return true, if the two ranges [POS1, SIZE1] and [POS2, SIZE2]
1211 overlap. SIZE1 and/or SIZE2 can be (unsigned)-1 in which case the
1212 range is open-ended. Otherwise return false. */
1215 ranges_overlap_p (unsigned HOST_WIDE_INT pos1
,
1216 unsigned HOST_WIDE_INT size1
,
1217 unsigned HOST_WIDE_INT pos2
,
1218 unsigned HOST_WIDE_INT size2
)
1221 && (size2
== (unsigned HOST_WIDE_INT
)-1
1222 || pos1
< (pos2
+ size2
)))
1225 && (size1
== (unsigned HOST_WIDE_INT
)-1
1226 || pos2
< (pos1
+ size1
)))
1232 /* Accessor to tree-ssa-operands.c caches. */
1233 static inline struct ssa_operands
*
1234 gimple_ssa_operands (const struct function
*fun
)
1236 return &fun
->gimple_df
->ssa_operands
;
1239 /* Given an edge_var_map V, return the PHI arg definition. */
1242 redirect_edge_var_map_def (edge_var_map
*v
)
1247 /* Given an edge_var_map V, return the PHI result. */
1250 redirect_edge_var_map_result (edge_var_map
*v
)
1255 /* Given an edge_var_map V, return the PHI arg location. */
1257 static inline source_location
1258 redirect_edge_var_map_location (edge_var_map
*v
)
1264 /* Return an SSA_NAME node for variable VAR defined in statement STMT
1265 in function cfun. */
1268 make_ssa_name (tree var
, gimple stmt
)
1270 return make_ssa_name_fn (cfun
, var
, stmt
);
1273 #endif /* _TREE_FLOW_INLINE_H */