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 = first_htab_element (&iter->hti, referenced_vars);
87 /* Return true if we have hit the end of the referenced variables ITER is
91 end_referenced_vars_p (referenced_var_iterator *iter)
93 return end_htab_p (&iter->hti);
96 /* Make ITER point to the next referenced_var in the referenced_var hashtable,
97 and return that variable. */
100 next_referenced_var (referenced_var_iterator *iter)
102 struct int_tree_map *itm;
103 itm = next_htab_element (&iter->hti);
109 /* Fill up VEC with the variables in the referenced vars hashtable. */
112 fill_referenced_var_vec (VEC (tree, heap) **vec)
114 referenced_var_iterator rvi;
117 FOR_EACH_REFERENCED_VAR (var, rvi)
118 VEC_safe_push (tree, heap, *vec, var);
121 /* Return the variable annotation for T, which must be a _DECL node.
122 Return NULL if the variable annotation doesn't already exist. */
123 static inline var_ann_t
127 gcc_assert (DECL_P (t));
128 gcc_assert (!t->common.ann || t->common.ann->common.type == VAR_ANN);
130 return (var_ann_t) t->common.ann;
133 /* Return the variable annotation for T, which must be a _DECL node.
134 Create the variable annotation if it doesn't exist. */
135 static inline var_ann_t
136 get_var_ann (tree var)
138 var_ann_t ann = var_ann (var);
139 return (ann) ? ann : create_var_ann (var);
142 /* Return the statement annotation for T, which must be a statement
143 node. Return NULL if the statement annotation doesn't exist. */
144 static inline stmt_ann_t
147 #ifdef ENABLE_CHECKING
148 gcc_assert (is_gimple_stmt (t));
150 return (stmt_ann_t) t->common.ann;
153 /* Return the statement annotation for T, which must be a statement
154 node. Create the statement annotation if it doesn't exist. */
155 static inline stmt_ann_t
156 get_stmt_ann (tree stmt)
158 stmt_ann_t ann = stmt_ann (stmt);
159 return (ann) ? ann : create_stmt_ann (stmt);
162 /* Return the annotation type for annotation ANN. */
163 static inline enum tree_ann_type
164 ann_type (tree_ann_t ann)
166 return ann->common.type;
169 /* Return the basic block for statement T. */
170 static inline basic_block
175 if (TREE_CODE (t) == PHI_NODE)
179 return ann ? ann->bb : NULL;
182 /* Return the may_aliases varray for variable VAR, or NULL if it has
184 static inline varray_type
185 may_aliases (tree var)
187 var_ann_t ann = var_ann (var);
188 return ann ? ann->may_aliases : NULL;
191 /* Return the line number for EXPR, or return -1 if we have no line
192 number information for it. */
194 get_lineno (tree expr)
196 if (expr == NULL_TREE)
199 if (TREE_CODE (expr) == COMPOUND_EXPR)
200 expr = TREE_OPERAND (expr, 0);
202 if (! EXPR_HAS_LOCATION (expr))
205 return EXPR_LINENO (expr);
208 /* Return the file name for EXPR, or return "???" if we have no
209 filename information. */
210 static inline const char *
211 get_filename (tree expr)
213 const char *filename;
214 if (expr == NULL_TREE)
217 if (TREE_CODE (expr) == COMPOUND_EXPR)
218 expr = TREE_OPERAND (expr, 0);
220 if (EXPR_HAS_LOCATION (expr) && (filename = EXPR_FILENAME (expr)))
226 /* Return true if T is a noreturn call. */
228 noreturn_call_p (tree t)
230 tree call = get_call_expr_in (t);
231 return call != 0 && (call_expr_flags (call) & ECF_NORETURN) != 0;
234 /* Mark statement T as modified. */
236 mark_stmt_modified (tree t)
239 if (TREE_CODE (t) == PHI_NODE)
244 ann = create_stmt_ann (t);
245 else if (noreturn_call_p (t))
246 VEC_safe_push (tree, gc, modified_noreturn_calls, t);
250 /* Mark statement T as modified, and update it. */
254 if (TREE_CODE (t) == PHI_NODE)
256 mark_stmt_modified (t);
257 update_stmt_operands (t);
261 update_stmt_if_modified (tree t)
263 if (stmt_modified_p (t))
264 update_stmt_operands (t);
267 /* Return true if T is marked as modified, false otherwise. */
269 stmt_modified_p (tree t)
271 stmt_ann_t ann = stmt_ann (t);
273 /* Note that if the statement doesn't yet have an annotation, we consider it
274 modified. This will force the next call to update_stmt_operands to scan
276 return ann ? ann->modified : true;
279 /* Delink an immediate_uses node from its chain. */
281 delink_imm_use (ssa_use_operand_t *linknode)
283 /* Return if this node is not in a list. */
284 if (linknode->prev == NULL)
287 linknode->prev->next = linknode->next;
288 linknode->next->prev = linknode->prev;
289 linknode->prev = NULL;
290 linknode->next = NULL;
293 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
295 link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
297 /* Link the new node at the head of the list. If we are in the process of
298 traversing the list, we won't visit any new nodes added to it. */
299 linknode->prev = list;
300 linknode->next = list->next;
301 list->next->prev = linknode;
302 list->next = linknode;
305 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
307 link_imm_use (ssa_use_operand_t *linknode, tree def)
309 ssa_use_operand_t *root;
311 if (!def || TREE_CODE (def) != SSA_NAME)
312 linknode->prev = NULL;
315 root = &(SSA_NAME_IMM_USE_NODE (def));
316 #ifdef ENABLE_CHECKING
318 gcc_assert (*(linknode->use) == def);
320 link_imm_use_to_list (linknode, root);
324 /* Set the value of a use pointed to by USE to VAL. */
326 set_ssa_use_from_ptr (use_operand_p use, tree val)
328 delink_imm_use (use);
330 link_imm_use (use, val);
333 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
336 link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, tree stmt)
339 link_imm_use (linknode, def);
341 link_imm_use (linknode, NULL);
342 linknode->stmt = stmt;
345 /* Relink a new node in place of an old node in the list. */
347 relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
349 /* The node one had better be in the same list. */
350 gcc_assert (*(old->use) == *(node->use));
351 node->prev = old->prev;
352 node->next = old->next;
355 old->prev->next = node;
356 old->next->prev = node;
357 /* Remove the old node from the list. */
362 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
365 relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old, tree stmt)
368 relink_imm_use (linknode, old);
370 link_imm_use (linknode, NULL);
371 linknode->stmt = stmt;
374 /* Finished the traverse of an immediate use list IMM by removing it from
377 end_safe_imm_use_traverse (imm_use_iterator *imm)
379 delink_imm_use (&(imm->iter_node));
382 /* Return true if IMM is at the end of the list. */
384 end_safe_imm_use_p (imm_use_iterator *imm)
386 return (imm->imm_use == imm->end_p);
389 /* Initialize iterator IMM to process the list for VAR. */
390 static inline use_operand_p
391 first_safe_imm_use (imm_use_iterator *imm, tree var)
393 /* Set up and link the iterator node into the linked list for VAR. */
394 imm->iter_node.use = NULL;
395 imm->iter_node.stmt = NULL_TREE;
396 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
397 /* Check if there are 0 elements. */
398 if (imm->end_p->next == imm->end_p)
400 imm->imm_use = imm->end_p;
401 return NULL_USE_OPERAND_P;
404 link_imm_use (&(imm->iter_node), var);
405 imm->imm_use = imm->iter_node.next;
409 /* Bump IMM to the next use in the list. */
410 static inline use_operand_p
411 next_safe_imm_use (imm_use_iterator *imm)
413 ssa_use_operand_t *ptr;
417 /* If the next node following the iter_node is still the one referred to by
418 imm_use, then the list hasn't changed, go to the next node. */
419 if (imm->iter_node.next == imm->imm_use)
421 ptr = &(imm->iter_node);
422 /* Remove iternode from the list. */
423 delink_imm_use (ptr);
424 imm->imm_use = imm->imm_use->next;
425 if (! end_safe_imm_use_p (imm))
427 /* This isn't the end, link iternode before the next use. */
428 ptr->prev = imm->imm_use->prev;
429 ptr->next = imm->imm_use;
430 imm->imm_use->prev->next = ptr;
431 imm->imm_use->prev = ptr;
438 /* If the 'next' value after the iterator isn't the same as it was, then
439 a node has been deleted, so we simply proceed to the node following
440 where the iterator is in the list. */
441 imm->imm_use = imm->iter_node.next;
442 if (end_safe_imm_use_p (imm))
444 end_safe_imm_use_traverse (imm);
452 /* Return true is IMM has reached the end of the immediate use list. */
454 end_readonly_imm_use_p (imm_use_iterator *imm)
456 return (imm->imm_use == imm->end_p);
459 /* Initialize iterator IMM to process the list for VAR. */
460 static inline use_operand_p
461 first_readonly_imm_use (imm_use_iterator *imm, tree var)
463 gcc_assert (TREE_CODE (var) == SSA_NAME);
465 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
466 imm->imm_use = imm->end_p->next;
467 #ifdef ENABLE_CHECKING
468 imm->iter_node.next = imm->imm_use->next;
470 if (end_readonly_imm_use_p (imm))
471 return NULL_USE_OPERAND_P;
475 /* Bump IMM to the next use in the list. */
476 static inline use_operand_p
477 next_readonly_imm_use (imm_use_iterator *imm)
479 use_operand_p old = imm->imm_use;
481 #ifdef ENABLE_CHECKING
482 /* If this assertion fails, it indicates the 'next' pointer has changed
483 since we the last bump. This indicates that the list is being modified
484 via stmt changes, or SET_USE, or somesuch thing, and you need to be
485 using the SAFE version of the iterator. */
486 gcc_assert (imm->iter_node.next == old->next);
487 imm->iter_node.next = old->next->next;
490 imm->imm_use = old->next;
491 if (end_readonly_imm_use_p (imm))
496 /* Return true if VAR has no uses. */
498 has_zero_uses (tree var)
500 ssa_use_operand_t *ptr;
501 ptr = &(SSA_NAME_IMM_USE_NODE (var));
502 /* A single use means there is no items in the list. */
503 return (ptr == ptr->next);
506 /* Return true if VAR has a single use. */
508 has_single_use (tree var)
510 ssa_use_operand_t *ptr;
511 ptr = &(SSA_NAME_IMM_USE_NODE (var));
512 /* A single use means there is one item in the list. */
513 return (ptr != ptr->next && ptr == ptr->next->next);
516 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
517 to the use pointer and stmt of occurrence. */
519 single_imm_use (tree var, use_operand_p *use_p, tree *stmt)
521 ssa_use_operand_t *ptr;
523 ptr = &(SSA_NAME_IMM_USE_NODE (var));
524 if (ptr != ptr->next && ptr == ptr->next->next)
527 *stmt = ptr->next->stmt;
530 *use_p = NULL_USE_OPERAND_P;
535 /* Return the number of immediate uses of VAR. */
536 static inline unsigned int
537 num_imm_uses (tree var)
539 ssa_use_operand_t *ptr, *start;
542 start = &(SSA_NAME_IMM_USE_NODE (var));
544 for (ptr = start->next; ptr != start; ptr = ptr->next)
551 /* Return the tree pointer to by USE. */
553 get_use_from_ptr (use_operand_p use)
558 /* Return the tree pointer to by DEF. */
560 get_def_from_ptr (def_operand_p def)
565 /* Return a def_operand_p pointer for the result of PHI. */
566 static inline def_operand_p
567 get_phi_result_ptr (tree phi)
569 return &(PHI_RESULT_TREE (phi));
572 /* Return a use_operand_p pointer for argument I of phinode PHI. */
573 static inline use_operand_p
574 get_phi_arg_def_ptr (tree phi, int i)
576 return &(PHI_ARG_IMM_USE_NODE (phi,i));
580 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
583 addresses_taken (tree stmt)
585 stmt_ann_t ann = stmt_ann (stmt);
586 return ann ? ann->addresses_taken : NULL;
589 /* Return the PHI nodes for basic block BB, or NULL if there are no
592 phi_nodes (basic_block bb)
594 return bb->phi_nodes;
597 /* Set list of phi nodes of a basic block BB to L. */
600 set_phi_nodes (basic_block bb, tree l)
605 for (phi = l; phi; phi = PHI_CHAIN (phi))
606 set_bb_for_stmt (phi, bb);
609 /* Return the phi argument which contains the specified use. */
612 phi_arg_index_from_use (use_operand_p use)
614 struct phi_arg_d *element, *root;
618 /* Since the use is the first thing in a PHI argument element, we can
619 calculate its index based on casting it to an argument, and performing
620 pointer arithmetic. */
622 phi = USE_STMT (use);
623 gcc_assert (TREE_CODE (phi) == PHI_NODE);
625 element = (struct phi_arg_d *)use;
626 root = &(PHI_ARG_ELT (phi, 0));
627 index = element - root;
629 #ifdef ENABLE_CHECKING
630 /* Make sure the calculation doesn't have any leftover bytes. If it does,
631 then imm_use is likely not the first element in phi_arg_d. */
633 (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
634 gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
640 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
643 set_is_used (tree var)
645 var_ann_t ann = get_var_ann (var);
650 /* ----------------------------------------------------------------------- */
652 /* Return true if T is an executable statement. */
654 is_exec_stmt (tree t)
656 return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
660 /* Return true if this stmt can be the target of a control transfer stmt such
663 is_label_stmt (tree t)
666 switch (TREE_CODE (t))
670 case CASE_LABEL_EXPR:
678 /* Set the default definition for VAR to DEF. */
680 set_default_def (tree var, tree def)
682 var_ann_t ann = get_var_ann (var);
683 ann->default_def = def;
686 /* Return the default definition for variable VAR, or NULL if none
689 default_def (tree var)
691 var_ann_t ann = var_ann (var);
692 return ann ? ann->default_def : NULL_TREE;
695 /* PHI nodes should contain only ssa_names and invariants. A test
696 for ssa_name is definitely simpler; don't let invalid contents
697 slip in in the meantime. */
700 phi_ssa_name_p (tree t)
702 if (TREE_CODE (t) == SSA_NAME)
704 #ifdef ENABLE_CHECKING
705 gcc_assert (is_gimple_min_invariant (t));
710 /* ----------------------------------------------------------------------- */
712 /* Return a block_stmt_iterator that points to beginning of basic
714 static inline block_stmt_iterator
715 bsi_start (basic_block bb)
717 block_stmt_iterator bsi;
719 bsi.tsi = tsi_start (bb->stmt_list);
722 gcc_assert (bb->index < 0);
724 bsi.tsi.container = NULL;
730 /* Return a block statement iterator that points to the first non-label
733 static inline block_stmt_iterator
734 bsi_after_labels (basic_block bb)
736 block_stmt_iterator bsi;
737 tree_stmt_iterator next;
743 gcc_assert (bb->index < 0);
745 bsi.tsi.container = NULL;
749 bsi.tsi = tsi_start (bb->stmt_list);
750 if (tsi_end_p (bsi.tsi))
756 while (!tsi_end_p (next)
757 && TREE_CODE (tsi_stmt (next)) == LABEL_EXPR)
766 /* Return a block statement iterator that points to the end of basic
768 static inline block_stmt_iterator
769 bsi_last (basic_block bb)
771 block_stmt_iterator bsi;
773 bsi.tsi = tsi_last (bb->stmt_list);
776 gcc_assert (bb->index < 0);
778 bsi.tsi.container = NULL;
784 /* Return true if block statement iterator I has reached the end of
787 bsi_end_p (block_stmt_iterator i)
789 return tsi_end_p (i.tsi);
792 /* Modify block statement iterator I so that it is at the next
793 statement in the basic block. */
795 bsi_next (block_stmt_iterator *i)
800 /* Modify block statement iterator I so that it is at the previous
801 statement in the basic block. */
803 bsi_prev (block_stmt_iterator *i)
808 /* Return the statement that block statement iterator I is currently
811 bsi_stmt (block_stmt_iterator i)
813 return tsi_stmt (i.tsi);
816 /* Return a pointer to the statement that block statement iterator I
819 bsi_stmt_ptr (block_stmt_iterator i)
821 return tsi_stmt_ptr (i.tsi);
824 /* Returns the loop of the statement STMT. */
826 static inline struct loop *
827 loop_containing_stmt (tree stmt)
829 basic_block bb = bb_for_stmt (stmt);
833 return bb->loop_father;
836 /* Return true if VAR is a clobbered by function calls. */
838 is_call_clobbered (tree var)
840 return is_global_var (var)
841 || bitmap_bit_p (call_clobbered_vars, DECL_UID (var));
844 /* Mark variable VAR as being clobbered by function calls. */
846 mark_call_clobbered (tree var)
848 /* If VAR is a memory tag, then we need to consider it a global
849 variable. This is because the pointer that VAR represents has
850 been found to point to either an arbitrary location or to a known
851 location in global memory. */
852 if (MTAG_P (var) && TREE_CODE (var) != STRUCT_FIELD_TAG)
853 MTAG_GLOBAL (var) = 1;
854 bitmap_set_bit (call_clobbered_vars, DECL_UID (var));
855 ssa_call_clobbered_cache_valid = false;
856 ssa_ro_call_cache_valid = false;
859 /* Clear the call-clobbered attribute from variable VAR. */
861 clear_call_clobbered (tree var)
863 if (MTAG_P (var) && TREE_CODE (var) != STRUCT_FIELD_TAG)
864 MTAG_GLOBAL (var) = 0;
865 bitmap_clear_bit (call_clobbered_vars, DECL_UID (var));
866 ssa_call_clobbered_cache_valid = false;
867 ssa_ro_call_cache_valid = false;
870 /* Mark variable VAR as being non-addressable. */
872 mark_non_addressable (tree var)
874 bitmap_clear_bit (call_clobbered_vars, DECL_UID (var));
875 TREE_ADDRESSABLE (var) = 0;
876 ssa_call_clobbered_cache_valid = false;
877 ssa_ro_call_cache_valid = false;
880 /* Return the common annotation for T. Return NULL if the annotation
881 doesn't already exist. */
882 static inline tree_ann_t
885 return t->common.ann;
888 /* Return a common annotation for T. Create the constant annotation if it
890 static inline tree_ann_t
891 get_tree_ann (tree t)
893 tree_ann_t ann = tree_ann (t);
894 return (ann) ? ann : create_tree_ann (t);
897 /* ----------------------------------------------------------------------- */
899 /* The following set of routines are used to iterator over various type of
902 /* Return true if PTR is finished iterating. */
904 op_iter_done (ssa_op_iter *ptr)
909 /* Get the next iterator use value for PTR. */
910 static inline use_operand_p
911 op_iter_next_use (ssa_op_iter *ptr)
914 #ifdef ENABLE_CHECKING
915 gcc_assert (ptr->iter_type == ssa_op_iter_use);
919 use_p = USE_OP_PTR (ptr->uses);
920 ptr->uses = ptr->uses->next;
925 use_p = VUSE_OP_PTR (ptr->vuses);
926 ptr->vuses = ptr->vuses->next;
931 use_p = MAYDEF_OP_PTR (ptr->mayuses);
932 ptr->mayuses = ptr->mayuses->next;
937 use_p = MUSTDEF_KILL_PTR (ptr->mustkills);
938 ptr->mustkills = ptr->mustkills->next;
941 if (ptr->phi_i < ptr->num_phi)
943 return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
946 return NULL_USE_OPERAND_P;
949 /* Get the next iterator def value for PTR. */
950 static inline def_operand_p
951 op_iter_next_def (ssa_op_iter *ptr)
954 #ifdef ENABLE_CHECKING
955 gcc_assert (ptr->iter_type == ssa_op_iter_def);
959 def_p = DEF_OP_PTR (ptr->defs);
960 ptr->defs = ptr->defs->next;
965 def_p = MUSTDEF_RESULT_PTR (ptr->mustdefs);
966 ptr->mustdefs = ptr->mustdefs->next;
971 def_p = MAYDEF_RESULT_PTR (ptr->maydefs);
972 ptr->maydefs = ptr->maydefs->next;
976 return NULL_DEF_OPERAND_P;
979 /* Get the next iterator tree value for PTR. */
981 op_iter_next_tree (ssa_op_iter *ptr)
984 #ifdef ENABLE_CHECKING
985 gcc_assert (ptr->iter_type == ssa_op_iter_tree);
989 val = USE_OP (ptr->uses);
990 ptr->uses = ptr->uses->next;
995 val = VUSE_OP (ptr->vuses);
996 ptr->vuses = ptr->vuses->next;
1001 val = MAYDEF_OP (ptr->mayuses);
1002 ptr->mayuses = ptr->mayuses->next;
1007 val = MUSTDEF_KILL (ptr->mustkills);
1008 ptr->mustkills = ptr->mustkills->next;
1013 val = DEF_OP (ptr->defs);
1014 ptr->defs = ptr->defs->next;
1019 val = MUSTDEF_RESULT (ptr->mustdefs);
1020 ptr->mustdefs = ptr->mustdefs->next;
1025 val = MAYDEF_RESULT (ptr->maydefs);
1026 ptr->maydefs = ptr->maydefs->next;
1036 /* This functions clears the iterator PTR, and marks it done. This is normally
1037 used to prevent warnings in the compile about might be uninitialized
1041 clear_and_done_ssa_iter (ssa_op_iter *ptr)
1046 ptr->maydefs = NULL;
1047 ptr->mayuses = NULL;
1048 ptr->mustdefs = NULL;
1049 ptr->mustkills = NULL;
1050 ptr->iter_type = ssa_op_iter_none;
1053 ptr->phi_stmt = NULL_TREE;
1057 /* Initialize the iterator PTR to the virtual defs in STMT. */
1059 op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
1061 #ifdef ENABLE_CHECKING
1062 gcc_assert (stmt_ann (stmt));
1065 ptr->defs = (flags & SSA_OP_DEF) ? DEF_OPS (stmt) : NULL;
1066 ptr->uses = (flags & SSA_OP_USE) ? USE_OPS (stmt) : NULL;
1067 ptr->vuses = (flags & SSA_OP_VUSE) ? VUSE_OPS (stmt) : NULL;
1068 ptr->maydefs = (flags & SSA_OP_VMAYDEF) ? MAYDEF_OPS (stmt) : NULL;
1069 ptr->mayuses = (flags & SSA_OP_VMAYUSE) ? MAYDEF_OPS (stmt) : NULL;
1070 ptr->mustdefs = (flags & SSA_OP_VMUSTDEF) ? MUSTDEF_OPS (stmt) : NULL;
1071 ptr->mustkills = (flags & SSA_OP_VMUSTKILL) ? MUSTDEF_OPS (stmt) : NULL;
1076 ptr->phi_stmt = NULL_TREE;
1079 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1081 static inline use_operand_p
1082 op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
1084 gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0);
1085 op_iter_init (ptr, stmt, flags);
1086 ptr->iter_type = ssa_op_iter_use;
1087 return op_iter_next_use (ptr);
1090 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1092 static inline def_operand_p
1093 op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1095 gcc_assert ((flags & (SSA_OP_ALL_USES | SSA_OP_VIRTUAL_KILLS)) == 0);
1096 op_iter_init (ptr, stmt, flags);
1097 ptr->iter_type = ssa_op_iter_def;
1098 return op_iter_next_def (ptr);
1101 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1102 the first operand as a tree. */
1104 op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1106 op_iter_init (ptr, stmt, flags);
1107 ptr->iter_type = ssa_op_iter_tree;
1108 return op_iter_next_tree (ptr);
1111 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1114 op_iter_next_maymustdef (use_operand_p *use, def_operand_p *def,
1117 #ifdef ENABLE_CHECKING
1118 gcc_assert (ptr->iter_type == ssa_op_iter_maymustdef);
1122 *def = MAYDEF_RESULT_PTR (ptr->mayuses);
1123 *use = MAYDEF_OP_PTR (ptr->mayuses);
1124 ptr->mayuses = ptr->mayuses->next;
1130 *def = MUSTDEF_RESULT_PTR (ptr->mustkills);
1131 *use = MUSTDEF_KILL_PTR (ptr->mustkills);
1132 ptr->mustkills = ptr->mustkills->next;
1136 *def = NULL_DEF_OPERAND_P;
1137 *use = NULL_USE_OPERAND_P;
1143 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1146 op_iter_init_maydef (ssa_op_iter *ptr, tree stmt, use_operand_p *use,
1149 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1151 op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1152 ptr->iter_type = ssa_op_iter_maymustdef;
1153 op_iter_next_maymustdef (use, def, ptr);
1157 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1160 op_iter_init_mustdef (ssa_op_iter *ptr, tree stmt, use_operand_p *kill,
1163 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1165 op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL);
1166 ptr->iter_type = ssa_op_iter_maymustdef;
1167 op_iter_next_maymustdef (kill, def, ptr);
1170 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1173 op_iter_init_must_and_may_def (ssa_op_iter *ptr, tree stmt,
1174 use_operand_p *kill, def_operand_p *def)
1176 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1178 op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL|SSA_OP_VMAYUSE);
1179 ptr->iter_type = ssa_op_iter_maymustdef;
1180 op_iter_next_maymustdef (kill, def, ptr);
1184 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1187 single_ssa_tree_operand (tree stmt, int flags)
1192 var = op_iter_init_tree (&iter, stmt, flags);
1193 if (op_iter_done (&iter))
1195 op_iter_next_tree (&iter);
1196 if (op_iter_done (&iter))
1202 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1204 static inline use_operand_p
1205 single_ssa_use_operand (tree stmt, int flags)
1210 var = op_iter_init_use (&iter, stmt, flags);
1211 if (op_iter_done (&iter))
1212 return NULL_USE_OPERAND_P;
1213 op_iter_next_use (&iter);
1214 if (op_iter_done (&iter))
1216 return NULL_USE_OPERAND_P;
1221 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1223 static inline def_operand_p
1224 single_ssa_def_operand (tree stmt, int flags)
1229 var = op_iter_init_def (&iter, stmt, flags);
1230 if (op_iter_done (&iter))
1231 return NULL_DEF_OPERAND_P;
1232 op_iter_next_def (&iter);
1233 if (op_iter_done (&iter))
1235 return NULL_DEF_OPERAND_P;
1239 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1242 zero_ssa_operands (tree stmt, int flags)
1246 op_iter_init_tree (&iter, stmt, flags);
1247 return op_iter_done (&iter);
1251 /* Return the number of operands matching FLAGS in STMT. */
1253 num_ssa_operands (tree stmt, int flags)
1259 FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
1265 /* Delink all immediate_use information for STMT. */
1267 delink_stmt_imm_use (tree stmt)
1270 use_operand_p use_p;
1272 if (ssa_operands_active ())
1273 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter,
1274 (SSA_OP_ALL_USES | SSA_OP_ALL_KILLS))
1275 delink_imm_use (use_p);
1279 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1280 in STMT2. TRUE is returned if they are the same. STMTs can be NULL. */
1282 compare_ssa_operands_equal (tree stmt1, tree stmt2, int flags)
1284 ssa_op_iter iter1, iter2;
1285 tree op1 = NULL_TREE;
1286 tree op2 = NULL_TREE;
1292 look1 = stmt1 && stmt_ann (stmt1);
1293 look2 = stmt2 && stmt_ann (stmt2);
1297 op1 = op_iter_init_tree (&iter1, stmt1, flags);
1299 return op_iter_done (&iter1);
1302 clear_and_done_ssa_iter (&iter1);
1306 op2 = op_iter_init_tree (&iter2, stmt2, flags);
1308 return op_iter_done (&iter2);
1311 clear_and_done_ssa_iter (&iter2);
1313 while (!op_iter_done (&iter1) && !op_iter_done (&iter2))
1317 op1 = op_iter_next_tree (&iter1);
1318 op2 = op_iter_next_tree (&iter2);
1321 return (op_iter_done (&iter1) && op_iter_done (&iter2));
1325 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1326 Otherwise return NULL_DEF_OPERAND_P. */
1328 single_phi_def (tree stmt, int flags)
1330 tree def = PHI_RESULT (stmt);
1331 if ((flags & SSA_OP_DEF) && is_gimple_reg (def))
1333 if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
1338 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
1339 be either SSA_OP_USES or SAS_OP_VIRTUAL_USES. */
1340 static inline use_operand_p
1341 op_iter_init_phiuse (ssa_op_iter *ptr, tree phi, int flags)
1343 tree phi_def = PHI_RESULT (phi);
1346 clear_and_done_ssa_iter (ptr);
1349 gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
1351 comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1353 /* If the PHI node doesn't the operand type we care about, we're done. */
1354 if ((flags & comp) == 0)
1357 return NULL_USE_OPERAND_P;
1360 ptr->phi_stmt = phi;
1361 ptr->num_phi = PHI_NUM_ARGS (phi);
1362 ptr->iter_type = ssa_op_iter_use;
1363 return op_iter_next_use (ptr);
1367 /* Start an iterator for a PHI definition. */
1369 static inline def_operand_p
1370 op_iter_init_phidef (ssa_op_iter *ptr, tree phi, int flags)
1372 tree phi_def = PHI_RESULT (phi);
1375 clear_and_done_ssa_iter (ptr);
1378 gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
1380 comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
1382 /* If the PHI node doesn't the operand type we care about, we're done. */
1383 if ((flags & comp) == 0)
1386 return NULL_USE_OPERAND_P;
1389 ptr->iter_type = ssa_op_iter_def;
1390 /* The first call to op_iter_next_def will terminate the iterator since
1391 all the fields are NULL. Simply return the result here as the first and
1392 therefore only result. */
1393 return PHI_RESULT_PTR (phi);
1398 /* Return true if VAR cannot be modified by the program. */
1401 unmodifiable_var_p (tree var)
1403 if (TREE_CODE (var) == SSA_NAME)
1404 var = SSA_NAME_VAR (var);
1407 return TREE_READONLY (var) && (TREE_STATIC (var) || MTAG_GLOBAL (var));
1409 return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1412 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it. */
1415 array_ref_contains_indirect_ref (tree ref)
1417 gcc_assert (TREE_CODE (ref) == ARRAY_REF);
1420 ref = TREE_OPERAND (ref, 0);
1421 } while (handled_component_p (ref));
1423 return TREE_CODE (ref) == INDIRECT_REF;
1426 /* Return true if REF, a handled component reference, has an ARRAY_REF
1430 ref_contains_array_ref (tree ref)
1432 gcc_assert (handled_component_p (ref));
1435 if (TREE_CODE (ref) == ARRAY_REF)
1437 ref = TREE_OPERAND (ref, 0);
1438 } while (handled_component_p (ref));
1443 /* Given a variable VAR, lookup and return a pointer to the list of
1444 subvariables for it. */
1446 static inline subvar_t *
1447 lookup_subvars_for_var (tree var)
1449 var_ann_t ann = var_ann (var);
1451 return &ann->subvars;
1454 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1455 NULL, if there are no subvariables. */
1457 static inline subvar_t
1458 get_subvars_for_var (tree var)
1462 gcc_assert (SSA_VAR_P (var));
1464 if (TREE_CODE (var) == SSA_NAME)
1465 subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
1467 subvars = *(lookup_subvars_for_var (var));
1471 /* Return the subvariable of VAR at offset OFFSET. */
1474 get_subvar_at (tree var, unsigned HOST_WIDE_INT offset)
1478 for (sv = get_subvars_for_var (var); sv; sv = sv->next)
1479 if (sv->offset == offset)
1485 /* Return true if V is a tree that we can have subvars for.
1486 Normally, this is any aggregate type, however, due to implementation
1487 limitations ATM, we exclude array types as well. */
1490 var_can_have_subvars (tree v)
1492 return (AGGREGATE_TYPE_P (TREE_TYPE (v)) &&
1493 TREE_CODE (TREE_TYPE (v)) != ARRAY_TYPE);
1497 /* Return true if OFFSET and SIZE define a range that overlaps with some
1498 portion of the range of SV, a subvar. If there was an exact overlap,
1499 *EXACT will be set to true upon return. */
1502 overlap_subvar (unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT size,
1503 subvar_t sv, bool *exact)
1505 /* There are three possible cases of overlap.
1506 1. We can have an exact overlap, like so:
1507 |offset, offset + size |
1508 |sv->offset, sv->offset + sv->size |
1510 2. We can have offset starting after sv->offset, like so:
1512 |offset, offset + size |
1513 |sv->offset, sv->offset + sv->size |
1515 3. We can have offset starting before sv->offset, like so:
1517 |offset, offset + size |
1518 |sv->offset, sv->offset + sv->size|
1523 if (offset == sv->offset && size == sv->size)
1529 else if (offset >= sv->offset && offset < (sv->offset + sv->size))
1533 else if (offset < sv->offset && (size > sv->offset - offset))
1541 #endif /* _TREE_FLOW_INLINE_H */