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);
70 /* Return the annotation type for annotation ANN. */
71 static inline enum tree_ann_type
72 ann_type (tree_ann_t ann)
74 return ann->common.type;
77 /* Return the basic block for statement T. */
78 static inline basic_block
83 if (TREE_CODE (t) == PHI_NODE)
87 return ann ? ann->bb : NULL;
90 /* Return the may_aliases varray for variable VAR, or NULL if it has
92 static inline varray_type
93 may_aliases (tree var)
95 var_ann_t ann = var_ann (var);
96 return ann ? ann->may_aliases : NULL;
99 /* Return the line number for EXPR, or return -1 if we have no line
100 number information for it. */
102 get_lineno (tree expr)
104 if (expr == NULL_TREE)
107 if (TREE_CODE (expr) == COMPOUND_EXPR)
108 expr = TREE_OPERAND (expr, 0);
110 if (! EXPR_HAS_LOCATION (expr))
113 return EXPR_LINENO (expr);
116 /* Return the file name for EXPR, or return "???" if we have no
117 filename information. */
118 static inline const char *
119 get_filename (tree expr)
121 const char *filename;
122 if (expr == NULL_TREE)
125 if (TREE_CODE (expr) == COMPOUND_EXPR)
126 expr = TREE_OPERAND (expr, 0);
128 if (EXPR_HAS_LOCATION (expr) && (filename = EXPR_FILENAME (expr)))
134 /* Return true if T is a noreturn call. */
136 noreturn_call_p (tree t)
138 tree call = get_call_expr_in (t);
139 return call != 0 && (call_expr_flags (call) & ECF_NORETURN) != 0;
142 /* Mark statement T as modified. */
144 mark_stmt_modified (tree t)
147 if (TREE_CODE (t) == PHI_NODE)
152 ann = create_stmt_ann (t);
153 else if (noreturn_call_p (t))
154 VEC_safe_push (tree, gc, modified_noreturn_calls, t);
158 /* Mark statement T as modified, and update it. */
162 if (TREE_CODE (t) == PHI_NODE)
164 mark_stmt_modified (t);
165 update_stmt_operands (t);
169 update_stmt_if_modified (tree t)
171 if (stmt_modified_p (t))
172 update_stmt_operands (t);
175 /* Return true if T is marked as modified, false otherwise. */
177 stmt_modified_p (tree t)
179 stmt_ann_t ann = stmt_ann (t);
181 /* Note that if the statement doesn't yet have an annotation, we consider it
182 modified. This will force the next call to update_stmt_operands to scan
184 return ann ? ann->modified : true;
187 /* Delink an immediate_uses node from its chain. */
189 delink_imm_use (ssa_imm_use_t *linknode)
191 /* Return if this node is not in a list. */
192 if (linknode->prev == NULL)
195 linknode->prev->next = linknode->next;
196 linknode->next->prev = linknode->prev;
197 linknode->prev = NULL;
198 linknode->next = NULL;
201 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
203 link_imm_use_to_list (ssa_imm_use_t *linknode, ssa_imm_use_t *list)
205 /* Link the new node at the head of the list. If we are in the process of
206 traversing the list, we wont visit any new nodes added to it. */
207 linknode->prev = list;
208 linknode->next = list->next;
209 list->next->prev = linknode;
210 list->next = linknode;
213 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
215 link_imm_use (ssa_imm_use_t *linknode, tree def)
219 if (!def || TREE_CODE (def) != SSA_NAME)
220 linknode->prev = NULL;
223 root = &(SSA_NAME_IMM_USE_NODE (def));
224 #ifdef ENABLE_CHECKING
226 gcc_assert (*(linknode->use) == def);
228 link_imm_use_to_list (linknode, root);
232 /* Set the value of a use pointed by USE to VAL. */
234 set_ssa_use_from_ptr (use_operand_p use, tree val)
236 delink_imm_use (use);
238 link_imm_use (use, val);
241 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occuring
244 link_imm_use_stmt (ssa_imm_use_t *linknode, tree def, tree stmt)
247 link_imm_use (linknode, def);
249 link_imm_use (linknode, NULL);
250 linknode->stmt = stmt;
253 /* Relink a new node in place of an old node in the list. */
255 relink_imm_use (ssa_imm_use_t *node, ssa_imm_use_t *old)
257 #ifdef ENABLE_CHECKING
258 /* The node one had better be in the same list. */
259 if (*(old->use) != *(node->use))
262 node->prev = old->prev;
263 node->next = old->next;
266 old->prev->next = node;
267 old->next->prev = node;
268 /* Remove the old node from the list. */
274 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occuring
277 relink_imm_use_stmt (ssa_imm_use_t *linknode, ssa_imm_use_t *old, tree stmt)
280 relink_imm_use (linknode, old);
282 link_imm_use (linknode, NULL);
283 linknode->stmt = stmt;
286 /* Finished the traverse of an immediate use list IMM by removing it from
289 end_safe_imm_use_traverse (imm_use_iterator *imm)
291 delink_imm_use (&(imm->iter_node));
294 /* Return true if IMM is at the end of the list. */
296 end_safe_imm_use_p (imm_use_iterator *imm)
298 return (imm->imm_use == imm->end_p);
301 /* Initialize iterator IMM to process the list for VAR. */
302 static inline use_operand_p
303 first_safe_imm_use (imm_use_iterator *imm, tree var)
305 /* Set up and link the iterator node into the linked list for VAR. */
306 imm->iter_node.use = NULL;
307 imm->iter_node.stmt = NULL_TREE;
308 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
309 /* Check if there are 0 elements. */
310 if (imm->end_p->next == imm->end_p)
312 imm->imm_use = imm->end_p;
313 return NULL_USE_OPERAND_P;
316 link_imm_use (&(imm->iter_node), var);
317 imm->imm_use = imm->iter_node.next;
321 /* Bump IMM to then next use in the list. */
322 static inline use_operand_p
323 next_safe_imm_use (imm_use_iterator *imm)
329 /* If the next node following the iter_node is still the one referred to by
330 imm_use, then the list hasn't changed, go to the next node. */
331 if (imm->iter_node.next == imm->imm_use)
333 ptr = &(imm->iter_node);
334 /* Remove iternode from the list. */
335 delink_imm_use (ptr);
336 imm->imm_use = imm->imm_use->next;
337 if (! end_safe_imm_use_p (imm))
339 /* This isnt the end, link iternode before the next use. */
340 ptr->prev = imm->imm_use->prev;
341 ptr->next = imm->imm_use;
342 imm->imm_use->prev->next = ptr;
343 imm->imm_use->prev = ptr;
350 /* If the 'next' value after the iterator isn't the same as it was, then
351 a node has been deleted, so we simply proceed to the node following
352 where the iterator is in the list. */
353 imm->imm_use = imm->iter_node.next;
354 if (end_safe_imm_use_p (imm))
356 end_safe_imm_use_traverse (imm);
364 /* Return true is IMM has reached the end of the immediate use list. */
366 end_readonly_imm_use_p (imm_use_iterator *imm)
368 return (imm->imm_use == imm->end_p);
371 /* Initialize iterator IMM to process the list for VAR. */
372 static inline use_operand_p
373 first_readonly_imm_use (imm_use_iterator *imm, tree var)
375 gcc_assert (TREE_CODE (var) == SSA_NAME);
377 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
378 imm->imm_use = imm->end_p->next;
379 #ifdef ENABLE_CHECKING
380 imm->iter_node.next = imm->imm_use->next;
382 if (end_readonly_imm_use_p (imm))
383 return NULL_USE_OPERAND_P;
387 /* Bump IMM to then next use in the list. */
388 static inline use_operand_p
389 next_readonly_imm_use (imm_use_iterator *imm)
391 use_operand_p old = imm->imm_use;
393 #ifdef ENABLE_CHECKING
394 /* If this assertion fails, it indicates the 'next' pointer has changed
395 since we the last bump. This indicates that the list is being modified
396 via stmt changes, or SET_USE, or somesuch thing, and you need to be
397 using the SAFE version of the iterator. */
398 gcc_assert (imm->iter_node.next == old->next);
399 imm->iter_node.next = old->next->next;
402 imm->imm_use = old->next;
403 if (end_readonly_imm_use_p (imm))
408 /* Return true if VAR has no uses. */
410 has_zero_uses (tree var)
413 ptr = &(SSA_NAME_IMM_USE_NODE (var));
414 /* A single use means there is no items in the list. */
415 return (ptr == ptr->next);
418 /* Return true if VAR has a single use. */
420 has_single_use (tree var)
423 ptr = &(SSA_NAME_IMM_USE_NODE (var));
424 /* A single use means there is one item in the list. */
425 return (ptr != ptr->next && ptr == ptr->next->next);
428 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
429 to the use pointer and stmt of occurrence. */
431 single_imm_use (tree var, use_operand_p *use_p, tree *stmt)
435 ptr = &(SSA_NAME_IMM_USE_NODE (var));
436 if (ptr != ptr->next && ptr == ptr->next->next)
439 *stmt = ptr->next->stmt;
442 *use_p = NULL_USE_OPERAND_P;
447 /* Return the number of immediate uses of VAR. */
448 static inline unsigned int
449 num_imm_uses (tree var)
451 ssa_imm_use_t *ptr, *start;
454 start = &(SSA_NAME_IMM_USE_NODE (var));
456 for (ptr = start->next; ptr != start; ptr = ptr->next)
462 /* Return the definitions present in ANN, a statement annotation.
463 Return NULL if this annotation contains no definitions. */
464 static inline def_optype
465 get_def_ops (stmt_ann_t ann)
467 return ann ? ann->operands.def_ops : NULL;
470 /* Return the uses present in ANN, a statement annotation.
471 Return NULL if this annotation contains no uses. */
472 static inline use_optype
473 get_use_ops (stmt_ann_t ann)
475 return ann ? ann->operands.use_ops : NULL;
478 /* Return the virtual may-defs present in ANN, a statement
480 Return NULL if this annotation contains no virtual may-defs. */
481 static inline v_may_def_optype
482 get_v_may_def_ops (stmt_ann_t ann)
484 return ann ? ann->operands.v_may_def_ops : NULL;
487 /* Return the virtual uses present in ANN, a statement annotation.
488 Return NULL if this annotation contains no virtual uses. */
489 static inline vuse_optype
490 get_vuse_ops (stmt_ann_t ann)
492 return ann ? ann->operands.vuse_ops : NULL;
495 /* Return the virtual must-defs present in ANN, a statement
496 annotation. Return NULL if this annotation contains no must-defs.*/
497 static inline v_must_def_optype
498 get_v_must_def_ops (stmt_ann_t ann)
500 return ann ? ann->operands.v_must_def_ops : NULL;
503 /* Return the tree pointer to by USE. */
505 get_use_from_ptr (use_operand_p use)
510 /* Return the tree pointer to by DEF. */
512 get_def_from_ptr (def_operand_p def)
517 /* Return a pointer to the tree that is at INDEX in the USES array. */
518 static inline use_operand_p
519 get_use_op_ptr (use_optype uses, unsigned int index)
521 gcc_assert (index < uses->num_uses);
522 return &(uses->uses[index]);
525 /* Return a def_operand_p pointer for element INDEX of DEFS. */
526 static inline def_operand_p
527 get_def_op_ptr (def_optype defs, unsigned int index)
529 gcc_assert (index < defs->num_defs);
530 return defs->defs[index];
533 /* Return the def_operand_p that is the V_MAY_DEF_RESULT for the V_MAY_DEF
534 at INDEX in the V_MAY_DEFS array. */
535 static inline def_operand_p
536 get_v_may_def_result_ptr(v_may_def_optype v_may_defs, unsigned int index)
539 gcc_assert (index < v_may_defs->num_v_may_defs);
540 op.def = &(v_may_defs->v_may_defs[index].def);
544 /* Return a use_operand_p that is the V_MAY_DEF_OP for the V_MAY_DEF at
545 INDEX in the V_MAY_DEFS array. */
546 static inline use_operand_p
547 get_v_may_def_op_ptr(v_may_def_optype v_may_defs, unsigned int index)
549 gcc_assert (index < v_may_defs->num_v_may_defs);
550 return &(v_may_defs->v_may_defs[index].imm_use);
553 /* Return a use_operand_p that is at INDEX in the VUSES array. */
554 static inline use_operand_p
555 get_vuse_op_ptr(vuse_optype vuses, unsigned int index)
557 gcc_assert (index < vuses->num_vuses);
558 return &(vuses->vuses[index].imm_use);
561 /* Return a def_operand_p that is the V_MUST_DEF_RESULT for the
562 V_MUST_DEF at INDEX in the V_MUST_DEFS array. */
563 static inline def_operand_p
564 get_v_must_def_result_ptr (v_must_def_optype v_must_defs, unsigned int index)
567 gcc_assert (index < v_must_defs->num_v_must_defs);
568 op.def = &(v_must_defs->v_must_defs[index].def);
572 /* Return a use_operand_p that is the V_MUST_DEF_KILL for the
573 V_MUST_DEF at INDEX in the V_MUST_DEFS array. */
574 static inline use_operand_p
575 get_v_must_def_kill_ptr (v_must_def_optype v_must_defs, unsigned int index)
577 gcc_assert (index < v_must_defs->num_v_must_defs);
578 return &(v_must_defs->v_must_defs[index].imm_use);
581 /* Return a def_operand_p pointer for the result of PHI. */
582 static inline def_operand_p
583 get_phi_result_ptr (tree phi)
586 op.def = &(PHI_RESULT_TREE (phi));
590 /* Return a use_operand_p pointer for argument I of phinode PHI. */
591 static inline use_operand_p
592 get_phi_arg_def_ptr (tree phi, int i)
594 return &(PHI_ARG_IMM_USE_NODE (phi,i));
597 /* Delink all immediate_use information for STMT. */
599 delink_stmt_imm_use (tree stmt)
602 use_optype uses = STMT_USE_OPS (stmt);
603 vuse_optype vuses = STMT_VUSE_OPS (stmt);
604 v_may_def_optype v_may_defs = STMT_V_MAY_DEF_OPS (stmt);
605 v_must_def_optype v_must_defs = STMT_V_MUST_DEF_OPS (stmt);
607 for (x = 0; x < NUM_USES (uses); x++)
608 delink_imm_use (&(uses->uses[x]));
610 for (x = 0; x < NUM_VUSES (vuses); x++)
611 delink_imm_use (&(vuses->vuses[x].imm_use));
613 for (x = 0; x < NUM_V_MAY_DEFS (v_may_defs); x++)
614 delink_imm_use (&(v_may_defs->v_may_defs[x].imm_use));
616 for (x = 0; x < NUM_V_MUST_DEFS (v_must_defs); x++)
617 delink_imm_use (&(v_must_defs->v_must_defs[x].imm_use));
621 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
624 addresses_taken (tree stmt)
626 stmt_ann_t ann = stmt_ann (stmt);
627 return ann ? ann->addresses_taken : NULL;
630 /* Return the basic_block annotation for BB. */
631 static inline bb_ann_t
632 bb_ann (basic_block bb)
634 return (bb_ann_t)bb->tree_annotations;
637 /* Return the PHI nodes for basic block BB, or NULL if there are no
640 phi_nodes (basic_block bb)
642 return bb_ann (bb)->phi_nodes;
645 /* Set list of phi nodes of a basic block BB to L. */
648 set_phi_nodes (basic_block bb, tree l)
652 bb_ann (bb)->phi_nodes = l;
653 for (phi = l; phi; phi = PHI_CHAIN (phi))
654 set_bb_for_stmt (phi, bb);
657 /* Return the phi argument which contains the specified use. */
660 phi_arg_index_from_use (use_operand_p use)
662 struct phi_arg_d *element, *root;
666 /* Since the use is the first thing in a PHI argument element, we can
667 calculate its index based on casting it to an argument, and performing
668 pointer arithmetic. */
670 phi = USE_STMT (use);
671 gcc_assert (TREE_CODE (phi) == PHI_NODE);
673 element = (struct phi_arg_d *)use;
674 root = &(PHI_ARG_ELT (phi, 0));
675 index = element - root;
677 #ifdef ENABLE_CHECKING
678 /* Make sure the calculation doesn't have any leftover bytes. If it does,
679 then imm_use is likely not the first element in phi_arg_d. */
681 (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
682 gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
688 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
691 set_is_used (tree var)
693 var_ann_t ann = get_var_ann (var);
698 /* ----------------------------------------------------------------------- */
700 /* Return true if T is an executable statement. */
702 is_exec_stmt (tree t)
704 return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
708 /* Return true if this stmt can be the target of a control transfer stmt such
711 is_label_stmt (tree t)
714 switch (TREE_CODE (t))
718 case CASE_LABEL_EXPR:
726 /* Set the default definition for VAR to DEF. */
728 set_default_def (tree var, tree def)
730 var_ann_t ann = get_var_ann (var);
731 ann->default_def = def;
734 /* Return the default definition for variable VAR, or NULL if none
737 default_def (tree var)
739 var_ann_t ann = var_ann (var);
740 return ann ? ann->default_def : NULL_TREE;
743 /* PHI nodes should contain only ssa_names and invariants. A test
744 for ssa_name is definitely simpler; don't let invalid contents
745 slip in in the meantime. */
748 phi_ssa_name_p (tree t)
750 if (TREE_CODE (t) == SSA_NAME)
752 #ifdef ENABLE_CHECKING
753 gcc_assert (is_gimple_min_invariant (t));
758 /* ----------------------------------------------------------------------- */
760 /* Return a block_stmt_iterator that points to beginning of basic
762 static inline block_stmt_iterator
763 bsi_start (basic_block bb)
765 block_stmt_iterator bsi;
767 bsi.tsi = tsi_start (bb->stmt_list);
770 gcc_assert (bb->index < 0);
772 bsi.tsi.container = NULL;
778 /* Return a block statement iterator that points to the last label in
781 static inline block_stmt_iterator
782 bsi_after_labels (basic_block bb)
784 block_stmt_iterator bsi;
785 tree_stmt_iterator next;
791 gcc_assert (bb->index < 0);
793 bsi.tsi.container = NULL;
797 bsi.tsi = tsi_start (bb->stmt_list);
798 if (tsi_end_p (bsi.tsi))
801 /* Ensure that there are some labels. The rationale is that we want
802 to insert after the bsi that is returned, and these insertions should
803 be placed at the start of the basic block. This would not work if the
804 first statement was not label; rather fail here than enable the user
805 proceed in wrong way. */
806 gcc_assert (TREE_CODE (tsi_stmt (bsi.tsi)) == LABEL_EXPR);
811 while (!tsi_end_p (next)
812 && TREE_CODE (tsi_stmt (next)) == LABEL_EXPR)
821 /* Return a block statement iterator that points to the end of basic
823 static inline block_stmt_iterator
824 bsi_last (basic_block bb)
826 block_stmt_iterator bsi;
828 bsi.tsi = tsi_last (bb->stmt_list);
831 gcc_assert (bb->index < 0);
833 bsi.tsi.container = NULL;
839 /* Return true if block statement iterator I has reached the end of
842 bsi_end_p (block_stmt_iterator i)
844 return tsi_end_p (i.tsi);
847 /* Modify block statement iterator I so that it is at the next
848 statement in the basic block. */
850 bsi_next (block_stmt_iterator *i)
855 /* Modify block statement iterator I so that it is at the previous
856 statement in the basic block. */
858 bsi_prev (block_stmt_iterator *i)
863 /* Return the statement that block statement iterator I is currently
866 bsi_stmt (block_stmt_iterator i)
868 return tsi_stmt (i.tsi);
871 /* Return a pointer to the statement that block statement iterator I
874 bsi_stmt_ptr (block_stmt_iterator i)
876 return tsi_stmt_ptr (i.tsi);
879 /* Returns the loop of the statement STMT. */
881 static inline struct loop *
882 loop_containing_stmt (tree stmt)
884 basic_block bb = bb_for_stmt (stmt);
888 return bb->loop_father;
891 /* Return true if VAR is a clobbered by function calls. */
893 is_call_clobbered (tree var)
895 return is_global_var (var)
896 || bitmap_bit_p (call_clobbered_vars, var_ann (var)->uid);
899 /* Mark variable VAR as being clobbered by function calls. */
901 mark_call_clobbered (tree var)
903 var_ann_t ann = var_ann (var);
904 /* If VAR is a memory tag, then we need to consider it a global
905 variable. This is because the pointer that VAR represents has
906 been found to point to either an arbitrary location or to a known
907 location in global memory. */
908 if (ann->mem_tag_kind != NOT_A_TAG && ann->mem_tag_kind != STRUCT_FIELD)
909 DECL_EXTERNAL (var) = 1;
910 bitmap_set_bit (call_clobbered_vars, ann->uid);
911 ssa_call_clobbered_cache_valid = false;
912 ssa_ro_call_cache_valid = false;
915 /* Clear the call-clobbered attribute from variable VAR. */
917 clear_call_clobbered (tree var)
919 var_ann_t ann = var_ann (var);
920 if (ann->mem_tag_kind != NOT_A_TAG && ann->mem_tag_kind != STRUCT_FIELD)
921 DECL_EXTERNAL (var) = 0;
922 bitmap_clear_bit (call_clobbered_vars, ann->uid);
923 ssa_call_clobbered_cache_valid = false;
924 ssa_ro_call_cache_valid = false;
927 /* Mark variable VAR as being non-addressable. */
929 mark_non_addressable (tree var)
931 bitmap_clear_bit (call_clobbered_vars, var_ann (var)->uid);
932 TREE_ADDRESSABLE (var) = 0;
933 ssa_call_clobbered_cache_valid = false;
934 ssa_ro_call_cache_valid = false;
937 /* Return the common annotation for T. Return NULL if the annotation
938 doesn't already exist. */
939 static inline tree_ann_t
942 return t->common.ann;
945 /* Return a common annotation for T. Create the constant annotation if it
947 static inline tree_ann_t
948 get_tree_ann (tree t)
950 tree_ann_t ann = tree_ann (t);
951 return (ann) ? ann : create_tree_ann (t);
954 /* ----------------------------------------------------------------------- */
956 /* The following set of routines are used to iterator over various type of
959 /* Return true if PTR is finished iterating. */
961 op_iter_done (ssa_op_iter *ptr)
966 /* Get the next iterator use value for PTR. */
967 static inline use_operand_p
968 op_iter_next_use (ssa_op_iter *ptr)
970 if (ptr->use_i < ptr->num_use)
972 return USE_OP_PTR (ptr->ops->use_ops, (ptr->use_i)++);
974 if (ptr->vuse_i < ptr->num_vuse)
976 return VUSE_OP_PTR (ptr->ops->vuse_ops, (ptr->vuse_i)++);
978 if (ptr->v_mayu_i < ptr->num_v_mayu)
980 return V_MAY_DEF_OP_PTR (ptr->ops->v_may_def_ops,
983 if (ptr->v_mustu_i < ptr->num_v_mustu)
985 return V_MUST_DEF_KILL_PTR (ptr->ops->v_must_def_ops,
989 return NULL_USE_OPERAND_P;
992 /* Get the next iterator def value for PTR. */
993 static inline def_operand_p
994 op_iter_next_def (ssa_op_iter *ptr)
996 if (ptr->def_i < ptr->num_def)
998 return DEF_OP_PTR (ptr->ops->def_ops, (ptr->def_i)++);
1000 if (ptr->v_mustd_i < ptr->num_v_mustd)
1002 return V_MUST_DEF_RESULT_PTR (ptr->ops->v_must_def_ops,
1003 (ptr->v_mustd_i)++);
1005 if (ptr->v_mayd_i < ptr->num_v_mayd)
1007 return V_MAY_DEF_RESULT_PTR (ptr->ops->v_may_def_ops,
1011 return NULL_DEF_OPERAND_P;
1014 /* Get the next iterator tree value for PTR. */
1016 op_iter_next_tree (ssa_op_iter *ptr)
1018 if (ptr->use_i < ptr->num_use)
1020 return USE_OP (ptr->ops->use_ops, (ptr->use_i)++);
1022 if (ptr->vuse_i < ptr->num_vuse)
1024 return VUSE_OP (ptr->ops->vuse_ops, (ptr->vuse_i)++);
1026 if (ptr->v_mayu_i < ptr->num_v_mayu)
1028 return V_MAY_DEF_OP (ptr->ops->v_may_def_ops, (ptr->v_mayu_i)++);
1030 if (ptr->v_mustu_i < ptr->num_v_mustu)
1032 return V_MUST_DEF_KILL (ptr->ops->v_must_def_ops, (ptr->v_mustu_i)++);
1034 if (ptr->def_i < ptr->num_def)
1036 return DEF_OP (ptr->ops->def_ops, (ptr->def_i)++);
1038 if (ptr->v_mustd_i < ptr->num_v_mustd)
1040 return V_MUST_DEF_RESULT (ptr->ops->v_must_def_ops,
1041 (ptr->v_mustd_i)++);
1043 if (ptr->v_mayd_i < ptr->num_v_mayd)
1045 return V_MAY_DEF_RESULT (ptr->ops->v_may_def_ops,
1052 /* Initialize the iterator PTR to the virtual defs in STMT. */
1054 op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
1056 stmt_operands_p ops;
1057 stmt_ann_t ann = get_stmt_ann (stmt);
1059 ops = &(ann->operands);
1062 ptr->num_def = (flags & SSA_OP_DEF) ? NUM_DEFS (ops->def_ops) : 0;
1063 ptr->num_use = (flags & SSA_OP_USE) ? NUM_USES (ops->use_ops) : 0;
1064 ptr->num_vuse = (flags & SSA_OP_VUSE) ? NUM_VUSES (ops->vuse_ops) : 0;
1065 ptr->num_v_mayu = (flags & SSA_OP_VMAYUSE)
1066 ? NUM_V_MAY_DEFS (ops->v_may_def_ops) : 0;
1067 ptr->num_v_mayd = (flags & SSA_OP_VMAYDEF)
1068 ? NUM_V_MAY_DEFS (ops->v_may_def_ops) : 0;
1069 ptr->num_v_mustu = (flags & SSA_OP_VMUSTDEFKILL)
1070 ? NUM_V_MUST_DEFS (ops->v_must_def_ops) : 0;
1071 ptr->num_v_mustd = (flags & SSA_OP_VMUSTDEF)
1072 ? NUM_V_MUST_DEFS (ops->v_must_def_ops) : 0;
1082 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1084 static inline use_operand_p
1085 op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
1087 op_iter_init (ptr, stmt, flags);
1088 return op_iter_next_use (ptr);
1091 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1093 static inline def_operand_p
1094 op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1096 op_iter_init (ptr, stmt, flags);
1097 return op_iter_next_def (ptr);
1100 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1101 the first operand as a tree. */
1103 op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1105 op_iter_init (ptr, stmt, flags);
1106 return op_iter_next_tree (ptr);
1109 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1112 op_iter_next_mustdef (use_operand_p *kill, def_operand_p *def, ssa_op_iter *ptr)
1114 if (ptr->v_mustu_i < ptr->num_v_mustu)
1116 *def = V_MUST_DEF_RESULT_PTR (ptr->ops->v_must_def_ops, ptr->v_mustu_i);
1117 *kill = V_MUST_DEF_KILL_PTR (ptr->ops->v_must_def_ops, (ptr->v_mustu_i)++);
1122 *def = NULL_DEF_OPERAND_P;
1123 *kill = NULL_USE_OPERAND_P;
1128 /* Get the next iterator maydef value for PTR, returning the maydef values in
1131 op_iter_next_maydef (use_operand_p *use, def_operand_p *def, ssa_op_iter *ptr)
1133 if (ptr->v_mayu_i < ptr->num_v_mayu)
1135 *def = V_MAY_DEF_RESULT_PTR (ptr->ops->v_may_def_ops, ptr->v_mayu_i);
1136 *use = V_MAY_DEF_OP_PTR (ptr->ops->v_may_def_ops, (ptr->v_mayu_i)++);
1141 *def = NULL_DEF_OPERAND_P;
1142 *use = NULL_USE_OPERAND_P;
1148 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1151 op_iter_init_maydef (ssa_op_iter *ptr, tree stmt, use_operand_p *use,
1154 op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1155 op_iter_next_maydef (use, def, ptr);
1158 /* Return true if VAR cannot be modified by the program. */
1161 unmodifiable_var_p (tree var)
1163 if (TREE_CODE (var) == SSA_NAME)
1164 var = SSA_NAME_VAR (var);
1165 return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1169 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1172 op_iter_init_mustdef (ssa_op_iter *ptr, tree stmt, use_operand_p *kill,
1175 op_iter_init (ptr, stmt, SSA_OP_VMUSTDEFKILL);
1176 op_iter_next_mustdef (kill, def, ptr);
1179 /* Return true if REF, a COMPONENT_REF, has an ARRAY_REF somewhere in it. */
1182 ref_contains_array_ref (tree ref)
1184 while (handled_component_p (ref))
1186 if (TREE_CODE (ref) == ARRAY_REF)
1188 ref = TREE_OPERAND (ref, 0);
1193 /* Given a variable VAR, lookup and return a pointer to the list of
1194 subvariables for it. */
1196 static inline subvar_t *
1197 lookup_subvars_for_var (tree var)
1199 var_ann_t ann = var_ann (var);
1201 return &ann->subvars;
1204 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1205 NULL, if there are no subvariables. */
1207 static inline subvar_t
1208 get_subvars_for_var (tree var)
1212 gcc_assert (SSA_VAR_P (var));
1214 if (TREE_CODE (var) == SSA_NAME)
1215 subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
1217 subvars = *(lookup_subvars_for_var (var));
1221 /* Return true if V is a tree that we can have subvars for.
1222 Normally, this is any aggregate type, however, due to implementation
1223 limitations ATM, we exclude array types as well. */
1226 var_can_have_subvars (tree v)
1228 return (AGGREGATE_TYPE_P (TREE_TYPE (v)) &&
1229 TREE_CODE (TREE_TYPE (v)) != ARRAY_TYPE);
1233 /* Return true if OFFSET and SIZE define a range that overlaps with some
1234 portion of the range of SV, a subvar. If there was an exact overlap,
1235 *EXACT will be set to true upon return. */
1238 overlap_subvar (HOST_WIDE_INT offset, HOST_WIDE_INT size,
1239 subvar_t sv, bool *exact)
1241 /* There are three possible cases of overlap.
1242 1. We can have an exact overlap, like so:
1243 |offset, offset + size |
1244 |sv->offset, sv->offset + sv->size |
1246 2. We can have offset starting after sv->offset, like so:
1248 |offset, offset + size |
1249 |sv->offset, sv->offset + sv->size |
1251 3. We can have offset starting before sv->offset, like so:
1253 |offset, offset + size |
1254 |sv->offset, sv->offset + sv->size|
1259 if (offset == sv->offset && size == sv->size)
1265 else if (offset >= sv->offset && offset < (sv->offset + sv->size))
1269 else if (offset < sv->offset && (offset + size > sv->offset))
1277 #endif /* _TREE_FLOW_INLINE_H */