gcc/
[official-gcc.git] / gcc / tree-flow-inline.h
blob057b2496c1a546d131567c47fb1b652e8e970d95
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)
10 any later version.
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 */
30 static inline void *
31 first_htab_element (htab_iterator *hti, htab_t table)
33 hti->htab = table;
34 hti->slot = table->entries;
35 hti->limit = hti->slot + htab_size (table);
38 PTR x = *(hti->slot);
39 if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
40 break;
41 } while (++(hti->slot) < hti->limit);
43 if (hti->slot < hti->limit)
44 return *(hti->slot);
45 return NULL;
48 /* Return current non-empty/deleted slot of the hashtable pointed to by HTI,
49 or NULL if we have reached the end. */
51 static inline bool
52 end_htab_p (htab_iterator *hti)
54 if (hti->slot >= hti->limit)
55 return true;
56 return false;
59 /* Advance the hashtable iterator pointed to by HTI to the next element of the
60 hashtable. */
62 static inline void *
63 next_htab_element (htab_iterator *hti)
65 while (++(hti->slot) < hti->limit)
67 PTR x = *(hti->slot);
68 if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
69 return x;
71 return NULL;
74 /* Initialize ITER to point to the first referenced variable in the
75 referenced_vars hashtable, and return that variable. */
77 static inline tree
78 first_referenced_var (referenced_var_iterator *iter)
80 struct int_tree_map *itm;
81 itm = (struct int_tree_map *) first_htab_element (&iter->hti,
82 referenced_vars);
83 if (!itm)
84 return NULL;
85 return itm->to;
88 /* Return true if we have hit the end of the referenced variables ITER is
89 iterating through. */
91 static inline bool
92 end_referenced_vars_p (referenced_var_iterator *iter)
94 return end_htab_p (&iter->hti);
97 /* Make ITER point to the next referenced_var in the referenced_var hashtable,
98 and return that variable. */
100 static inline tree
101 next_referenced_var (referenced_var_iterator *iter)
103 struct int_tree_map *itm;
104 itm = (struct int_tree_map *) next_htab_element (&iter->hti);
105 if (!itm)
106 return NULL;
107 return itm->to;
110 /* Fill up VEC with the variables in the referenced vars hashtable. */
112 static inline void
113 fill_referenced_var_vec (VEC (tree, heap) **vec)
115 referenced_var_iterator rvi;
116 tree var;
117 *vec = NULL;
118 FOR_EACH_REFERENCED_VAR (var, rvi)
119 VEC_safe_push (tree, heap, *vec, var);
122 /* Return the variable annotation for T, which must be a _DECL node.
123 Return NULL if the variable annotation doesn't already exist. */
124 static inline var_ann_t
125 var_ann (tree t)
127 gcc_assert (t);
128 gcc_assert (DECL_P (t));
129 gcc_assert (!t->common.ann || t->common.ann->common.type == VAR_ANN);
131 return (var_ann_t) t->common.ann;
134 /* Return the variable annotation for T, which must be a _DECL node.
135 Create the variable annotation if it doesn't exist. */
136 static inline var_ann_t
137 get_var_ann (tree var)
139 var_ann_t ann = var_ann (var);
140 return (ann) ? ann : create_var_ann (var);
143 /* Return the statement annotation for T, which must be a statement
144 node. Return NULL if the statement annotation doesn't exist. */
145 static inline stmt_ann_t
146 stmt_ann (tree t)
148 #ifdef ENABLE_CHECKING
149 gcc_assert (is_gimple_stmt (t));
150 #endif
151 return (stmt_ann_t) t->common.ann;
154 /* Return the statement annotation for T, which must be a statement
155 node. Create the statement annotation if it doesn't exist. */
156 static inline stmt_ann_t
157 get_stmt_ann (tree stmt)
159 stmt_ann_t ann = stmt_ann (stmt);
160 return (ann) ? ann : create_stmt_ann (stmt);
163 /* Return the annotation type for annotation ANN. */
164 static inline enum tree_ann_type
165 ann_type (tree_ann_t ann)
167 return ann->common.type;
170 /* Return the basic block for statement T. */
171 static inline basic_block
172 bb_for_stmt (tree t)
174 stmt_ann_t ann;
176 if (TREE_CODE (t) == PHI_NODE)
177 return PHI_BB (t);
179 ann = stmt_ann (t);
180 return ann ? ann->bb : NULL;
183 /* Return the may_aliases varray for variable VAR, or NULL if it has
184 no may aliases. */
185 static inline VEC(tree, gc) *
186 may_aliases (tree var)
188 var_ann_t ann = var_ann (var);
189 return ann ? ann->may_aliases : NULL;
192 /* Return the line number for EXPR, or return -1 if we have no line
193 number information for it. */
194 static inline int
195 get_lineno (tree expr)
197 if (expr == NULL_TREE)
198 return -1;
200 if (TREE_CODE (expr) == COMPOUND_EXPR)
201 expr = TREE_OPERAND (expr, 0);
203 if (! EXPR_HAS_LOCATION (expr))
204 return -1;
206 return EXPR_LINENO (expr);
209 /* Return the file name for EXPR, or return "???" if we have no
210 filename information. */
211 static inline const char *
212 get_filename (tree expr)
214 const char *filename;
215 if (expr == NULL_TREE)
216 return "???";
218 if (TREE_CODE (expr) == COMPOUND_EXPR)
219 expr = TREE_OPERAND (expr, 0);
221 if (EXPR_HAS_LOCATION (expr) && (filename = EXPR_FILENAME (expr)))
222 return filename;
223 else
224 return "???";
227 /* Return true if T is a noreturn call. */
228 static inline bool
229 noreturn_call_p (tree t)
231 tree call = get_call_expr_in (t);
232 return call != 0 && (call_expr_flags (call) & ECF_NORETURN) != 0;
235 /* Mark statement T as modified. */
236 static inline void
237 mark_stmt_modified (tree t)
239 stmt_ann_t ann;
240 if (TREE_CODE (t) == PHI_NODE)
241 return;
243 ann = stmt_ann (t);
244 if (ann == NULL)
245 ann = create_stmt_ann (t);
246 else if (noreturn_call_p (t))
247 VEC_safe_push (tree, gc, modified_noreturn_calls, t);
248 ann->modified = 1;
251 /* Mark statement T as modified, and update it. */
252 static inline void
253 update_stmt (tree t)
255 if (TREE_CODE (t) == PHI_NODE)
256 return;
257 mark_stmt_modified (t);
258 update_stmt_operands (t);
261 static inline void
262 update_stmt_if_modified (tree t)
264 if (stmt_modified_p (t))
265 update_stmt_operands (t);
268 /* Return true if T is marked as modified, false otherwise. */
269 static inline bool
270 stmt_modified_p (tree t)
272 stmt_ann_t ann = stmt_ann (t);
274 /* Note that if the statement doesn't yet have an annotation, we consider it
275 modified. This will force the next call to update_stmt_operands to scan
276 the statement. */
277 return ann ? ann->modified : true;
280 /* Delink an immediate_uses node from its chain. */
281 static inline void
282 delink_imm_use (ssa_use_operand_t *linknode)
284 /* Return if this node is not in a list. */
285 if (linknode->prev == NULL)
286 return;
288 linknode->prev->next = linknode->next;
289 linknode->next->prev = linknode->prev;
290 linknode->prev = NULL;
291 linknode->next = NULL;
294 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
295 static inline void
296 link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
298 /* Link the new node at the head of the list. If we are in the process of
299 traversing the list, we won't visit any new nodes added to it. */
300 linknode->prev = list;
301 linknode->next = list->next;
302 list->next->prev = linknode;
303 list->next = linknode;
306 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
307 static inline void
308 link_imm_use (ssa_use_operand_t *linknode, tree def)
310 ssa_use_operand_t *root;
312 if (!def || TREE_CODE (def) != SSA_NAME)
313 linknode->prev = NULL;
314 else
316 root = &(SSA_NAME_IMM_USE_NODE (def));
317 #ifdef ENABLE_CHECKING
318 if (linknode->use)
319 gcc_assert (*(linknode->use) == def);
320 #endif
321 link_imm_use_to_list (linknode, root);
325 /* Set the value of a use pointed to by USE to VAL. */
326 static inline void
327 set_ssa_use_from_ptr (use_operand_p use, tree val)
329 delink_imm_use (use);
330 *(use->use) = val;
331 link_imm_use (use, val);
334 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
335 in STMT. */
336 static inline void
337 link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, tree stmt)
339 if (stmt)
340 link_imm_use (linknode, def);
341 else
342 link_imm_use (linknode, NULL);
343 linknode->stmt = stmt;
346 /* Relink a new node in place of an old node in the list. */
347 static inline void
348 relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
350 /* The node one had better be in the same list. */
351 gcc_assert (*(old->use) == *(node->use));
352 node->prev = old->prev;
353 node->next = old->next;
354 if (old->prev)
356 old->prev->next = node;
357 old->next->prev = node;
358 /* Remove the old node from the list. */
359 old->prev = NULL;
363 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
364 in STMT. */
365 static inline void
366 relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old, tree stmt)
368 if (stmt)
369 relink_imm_use (linknode, old);
370 else
371 link_imm_use (linknode, NULL);
372 linknode->stmt = stmt;
375 /* Finished the traverse of an immediate use list IMM by removing it from
376 the list. */
377 static inline void
378 end_safe_imm_use_traverse (imm_use_iterator *imm)
380 delink_imm_use (&(imm->iter_node));
383 /* Return true if IMM is at the end of the list. */
384 static inline bool
385 end_safe_imm_use_p (imm_use_iterator *imm)
387 return (imm->imm_use == imm->end_p);
390 /* Initialize iterator IMM to process the list for VAR. */
391 static inline use_operand_p
392 first_safe_imm_use (imm_use_iterator *imm, tree var)
394 /* Set up and link the iterator node into the linked list for VAR. */
395 imm->iter_node.use = NULL;
396 imm->iter_node.stmt = NULL_TREE;
397 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
398 /* Check if there are 0 elements. */
399 if (imm->end_p->next == imm->end_p)
401 imm->imm_use = imm->end_p;
402 return NULL_USE_OPERAND_P;
405 link_imm_use (&(imm->iter_node), var);
406 imm->imm_use = imm->iter_node.next;
407 return imm->imm_use;
410 /* Bump IMM to the next use in the list. */
411 static inline use_operand_p
412 next_safe_imm_use (imm_use_iterator *imm)
414 ssa_use_operand_t *ptr;
415 use_operand_p old;
417 old = imm->imm_use;
418 /* If the next node following the iter_node is still the one referred to by
419 imm_use, then the list hasn't changed, go to the next node. */
420 if (imm->iter_node.next == imm->imm_use)
422 ptr = &(imm->iter_node);
423 /* Remove iternode from the list. */
424 delink_imm_use (ptr);
425 imm->imm_use = imm->imm_use->next;
426 if (! end_safe_imm_use_p (imm))
428 /* This isn't the end, link iternode before the next use. */
429 ptr->prev = imm->imm_use->prev;
430 ptr->next = imm->imm_use;
431 imm->imm_use->prev->next = ptr;
432 imm->imm_use->prev = ptr;
434 else
435 return old;
437 else
439 /* If the 'next' value after the iterator isn't the same as it was, then
440 a node has been deleted, so we simply proceed to the node following
441 where the iterator is in the list. */
442 imm->imm_use = imm->iter_node.next;
443 if (end_safe_imm_use_p (imm))
445 end_safe_imm_use_traverse (imm);
446 return old;
450 return imm->imm_use;
453 /* Return true is IMM has reached the end of the immediate use list. */
454 static inline bool
455 end_readonly_imm_use_p (imm_use_iterator *imm)
457 return (imm->imm_use == imm->end_p);
460 /* Initialize iterator IMM to process the list for VAR. */
461 static inline use_operand_p
462 first_readonly_imm_use (imm_use_iterator *imm, tree var)
464 gcc_assert (TREE_CODE (var) == SSA_NAME);
466 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
467 imm->imm_use = imm->end_p->next;
468 #ifdef ENABLE_CHECKING
469 imm->iter_node.next = imm->imm_use->next;
470 #endif
471 if (end_readonly_imm_use_p (imm))
472 return NULL_USE_OPERAND_P;
473 return imm->imm_use;
476 /* Bump IMM to the next use in the list. */
477 static inline use_operand_p
478 next_readonly_imm_use (imm_use_iterator *imm)
480 use_operand_p old = imm->imm_use;
482 #ifdef ENABLE_CHECKING
483 /* If this assertion fails, it indicates the 'next' pointer has changed
484 since we the last bump. This indicates that the list is being modified
485 via stmt changes, or SET_USE, or somesuch thing, and you need to be
486 using the SAFE version of the iterator. */
487 gcc_assert (imm->iter_node.next == old->next);
488 imm->iter_node.next = old->next->next;
489 #endif
491 imm->imm_use = old->next;
492 if (end_readonly_imm_use_p (imm))
493 return old;
494 return imm->imm_use;
497 /* Return true if VAR has no uses. */
498 static inline bool
499 has_zero_uses (tree var)
501 ssa_use_operand_t *ptr;
502 ptr = &(SSA_NAME_IMM_USE_NODE (var));
503 /* A single use means there is no items in the list. */
504 return (ptr == ptr->next);
507 /* Return true if VAR has a single use. */
508 static inline bool
509 has_single_use (tree var)
511 ssa_use_operand_t *ptr;
512 ptr = &(SSA_NAME_IMM_USE_NODE (var));
513 /* A single use means there is one item in the list. */
514 return (ptr != ptr->next && ptr == ptr->next->next);
517 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
518 to the use pointer and stmt of occurrence. */
519 static inline bool
520 single_imm_use (tree var, use_operand_p *use_p, tree *stmt)
522 ssa_use_operand_t *ptr;
524 ptr = &(SSA_NAME_IMM_USE_NODE (var));
525 if (ptr != ptr->next && ptr == ptr->next->next)
527 *use_p = ptr->next;
528 *stmt = ptr->next->stmt;
529 return true;
531 *use_p = NULL_USE_OPERAND_P;
532 *stmt = NULL_TREE;
533 return false;
536 /* Return the number of immediate uses of VAR. */
537 static inline unsigned int
538 num_imm_uses (tree var)
540 ssa_use_operand_t *ptr, *start;
541 unsigned int num;
543 start = &(SSA_NAME_IMM_USE_NODE (var));
544 num = 0;
545 for (ptr = start->next; ptr != start; ptr = ptr->next)
546 num++;
548 return num;
552 /* Return the tree pointer to by USE. */
553 static inline tree
554 get_use_from_ptr (use_operand_p use)
556 return *(use->use);
559 /* Return the tree pointer to by DEF. */
560 static inline tree
561 get_def_from_ptr (def_operand_p def)
563 return *def;
566 /* Return a def_operand_p pointer for the result of PHI. */
567 static inline def_operand_p
568 get_phi_result_ptr (tree phi)
570 return &(PHI_RESULT_TREE (phi));
573 /* Return a use_operand_p pointer for argument I of phinode PHI. */
574 static inline use_operand_p
575 get_phi_arg_def_ptr (tree phi, int i)
577 return &(PHI_ARG_IMM_USE_NODE (phi,i));
581 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
582 no addresses. */
583 static inline bitmap
584 addresses_taken (tree stmt)
586 stmt_ann_t ann = stmt_ann (stmt);
587 return ann ? ann->addresses_taken : NULL;
590 /* Return the PHI nodes for basic block BB, or NULL if there are no
591 PHI nodes. */
592 static inline tree
593 phi_nodes (basic_block bb)
595 return bb->phi_nodes;
598 /* Set list of phi nodes of a basic block BB to L. */
600 static inline void
601 set_phi_nodes (basic_block bb, tree l)
603 tree phi;
605 bb->phi_nodes = l;
606 for (phi = l; phi; phi = PHI_CHAIN (phi))
607 set_bb_for_stmt (phi, bb);
610 /* Return the phi argument which contains the specified use. */
612 static inline int
613 phi_arg_index_from_use (use_operand_p use)
615 struct phi_arg_d *element, *root;
616 int index;
617 tree phi;
619 /* Since the use is the first thing in a PHI argument element, we can
620 calculate its index based on casting it to an argument, and performing
621 pointer arithmetic. */
623 phi = USE_STMT (use);
624 gcc_assert (TREE_CODE (phi) == PHI_NODE);
626 element = (struct phi_arg_d *)use;
627 root = &(PHI_ARG_ELT (phi, 0));
628 index = element - root;
630 #ifdef ENABLE_CHECKING
631 /* Make sure the calculation doesn't have any leftover bytes. If it does,
632 then imm_use is likely not the first element in phi_arg_d. */
633 gcc_assert (
634 (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
635 gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
636 #endif
638 return index;
641 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
643 static inline void
644 set_is_used (tree var)
646 var_ann_t ann = get_var_ann (var);
647 ann->used = 1;
651 /* ----------------------------------------------------------------------- */
653 /* Return true if T is an executable statement. */
654 static inline bool
655 is_exec_stmt (tree t)
657 return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
661 /* Return true if this stmt can be the target of a control transfer stmt such
662 as a goto. */
663 static inline bool
664 is_label_stmt (tree t)
666 if (t)
667 switch (TREE_CODE (t))
669 case LABEL_DECL:
670 case LABEL_EXPR:
671 case CASE_LABEL_EXPR:
672 return true;
673 default:
674 return false;
676 return false;
679 /* PHI nodes should contain only ssa_names and invariants. A test
680 for ssa_name is definitely simpler; don't let invalid contents
681 slip in in the meantime. */
683 static inline bool
684 phi_ssa_name_p (tree t)
686 if (TREE_CODE (t) == SSA_NAME)
687 return true;
688 #ifdef ENABLE_CHECKING
689 gcc_assert (is_gimple_min_invariant (t));
690 #endif
691 return false;
694 /* ----------------------------------------------------------------------- */
696 /* Return a block_stmt_iterator that points to beginning of basic
697 block BB. */
698 static inline block_stmt_iterator
699 bsi_start (basic_block bb)
701 block_stmt_iterator bsi;
702 if (bb->stmt_list)
703 bsi.tsi = tsi_start (bb->stmt_list);
704 else
706 gcc_assert (bb->index < NUM_FIXED_BLOCKS);
707 bsi.tsi.ptr = NULL;
708 bsi.tsi.container = NULL;
710 bsi.bb = bb;
711 return bsi;
714 /* Return a block statement iterator that points to the first non-label
715 block BB. */
717 static inline block_stmt_iterator
718 bsi_after_labels (basic_block bb)
720 block_stmt_iterator bsi;
721 tree_stmt_iterator next;
723 bsi.bb = bb;
725 if (!bb->stmt_list)
727 gcc_assert (bb->index < NUM_FIXED_BLOCKS);
728 bsi.tsi.ptr = NULL;
729 bsi.tsi.container = NULL;
730 return bsi;
733 bsi.tsi = tsi_start (bb->stmt_list);
734 if (tsi_end_p (bsi.tsi))
735 return bsi;
737 next = bsi.tsi;
738 tsi_next (&next);
740 while (!tsi_end_p (next)
741 && TREE_CODE (tsi_stmt (next)) == LABEL_EXPR)
743 bsi.tsi = next;
744 tsi_next (&next);
747 return bsi;
750 /* Return a block statement iterator that points to the end of basic
751 block BB. */
752 static inline block_stmt_iterator
753 bsi_last (basic_block bb)
755 block_stmt_iterator bsi;
756 if (bb->stmt_list)
757 bsi.tsi = tsi_last (bb->stmt_list);
758 else
760 gcc_assert (bb->index < NUM_FIXED_BLOCKS);
761 bsi.tsi.ptr = NULL;
762 bsi.tsi.container = NULL;
764 bsi.bb = bb;
765 return bsi;
768 /* Return true if block statement iterator I has reached the end of
769 the basic block. */
770 static inline bool
771 bsi_end_p (block_stmt_iterator i)
773 return tsi_end_p (i.tsi);
776 /* Modify block statement iterator I so that it is at the next
777 statement in the basic block. */
778 static inline void
779 bsi_next (block_stmt_iterator *i)
781 tsi_next (&i->tsi);
784 /* Modify block statement iterator I so that it is at the previous
785 statement in the basic block. */
786 static inline void
787 bsi_prev (block_stmt_iterator *i)
789 tsi_prev (&i->tsi);
792 /* Return the statement that block statement iterator I is currently
793 at. */
794 static inline tree
795 bsi_stmt (block_stmt_iterator i)
797 return tsi_stmt (i.tsi);
800 /* Return a pointer to the statement that block statement iterator I
801 is currently at. */
802 static inline tree *
803 bsi_stmt_ptr (block_stmt_iterator i)
805 return tsi_stmt_ptr (i.tsi);
808 /* Returns the loop of the statement STMT. */
810 static inline struct loop *
811 loop_containing_stmt (tree stmt)
813 basic_block bb = bb_for_stmt (stmt);
814 if (!bb)
815 return NULL;
817 return bb->loop_father;
820 /* Return true if VAR is a clobbered by function calls. */
821 static inline bool
822 is_call_clobbered (tree var)
824 return is_global_var (var)
825 || bitmap_bit_p (call_clobbered_vars, DECL_UID (var));
828 /* Mark variable VAR as being clobbered by function calls. */
829 static inline void
830 mark_call_clobbered (tree var)
832 /* If VAR is a memory tag, then we need to consider it a global
833 variable. This is because the pointer that VAR represents has
834 been found to point to either an arbitrary location or to a known
835 location in global memory. */
836 if (MTAG_P (var) && TREE_CODE (var) != STRUCT_FIELD_TAG)
837 MTAG_GLOBAL (var) = 1;
838 bitmap_set_bit (call_clobbered_vars, DECL_UID (var));
839 ssa_call_clobbered_cache_valid = false;
840 ssa_ro_call_cache_valid = false;
843 /* Clear the call-clobbered attribute from variable VAR. */
844 static inline void
845 clear_call_clobbered (tree var)
847 if (MTAG_P (var) && TREE_CODE (var) != STRUCT_FIELD_TAG)
848 MTAG_GLOBAL (var) = 0;
849 bitmap_clear_bit (call_clobbered_vars, DECL_UID (var));
850 ssa_call_clobbered_cache_valid = false;
851 ssa_ro_call_cache_valid = false;
854 /* Mark variable VAR as being non-addressable. */
855 static inline void
856 mark_non_addressable (tree var)
858 bitmap_clear_bit (call_clobbered_vars, DECL_UID (var));
859 TREE_ADDRESSABLE (var) = 0;
860 ssa_call_clobbered_cache_valid = false;
861 ssa_ro_call_cache_valid = false;
864 /* Return the common annotation for T. Return NULL if the annotation
865 doesn't already exist. */
866 static inline tree_ann_t
867 tree_ann (tree t)
869 return t->common.ann;
872 /* Return a common annotation for T. Create the constant annotation if it
873 doesn't exist. */
874 static inline tree_ann_t
875 get_tree_ann (tree t)
877 tree_ann_t ann = tree_ann (t);
878 return (ann) ? ann : create_tree_ann (t);
881 /* ----------------------------------------------------------------------- */
883 /* The following set of routines are used to iterator over various type of
884 SSA operands. */
886 /* Return true if PTR is finished iterating. */
887 static inline bool
888 op_iter_done (ssa_op_iter *ptr)
890 return ptr->done;
893 /* Get the next iterator use value for PTR. */
894 static inline use_operand_p
895 op_iter_next_use (ssa_op_iter *ptr)
897 use_operand_p use_p;
898 #ifdef ENABLE_CHECKING
899 gcc_assert (ptr->iter_type == ssa_op_iter_use);
900 #endif
901 if (ptr->uses)
903 use_p = USE_OP_PTR (ptr->uses);
904 ptr->uses = ptr->uses->next;
905 return use_p;
907 if (ptr->vuses)
909 use_p = VUSE_OP_PTR (ptr->vuses);
910 ptr->vuses = ptr->vuses->next;
911 return use_p;
913 if (ptr->mayuses)
915 use_p = MAYDEF_OP_PTR (ptr->mayuses);
916 ptr->mayuses = ptr->mayuses->next;
917 return use_p;
919 if (ptr->mustkills)
921 use_p = MUSTDEF_KILL_PTR (ptr->mustkills);
922 ptr->mustkills = ptr->mustkills->next;
923 return use_p;
925 if (ptr->phi_i < ptr->num_phi)
927 return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
929 ptr->done = true;
930 return NULL_USE_OPERAND_P;
933 /* Get the next iterator def value for PTR. */
934 static inline def_operand_p
935 op_iter_next_def (ssa_op_iter *ptr)
937 def_operand_p def_p;
938 #ifdef ENABLE_CHECKING
939 gcc_assert (ptr->iter_type == ssa_op_iter_def);
940 #endif
941 if (ptr->defs)
943 def_p = DEF_OP_PTR (ptr->defs);
944 ptr->defs = ptr->defs->next;
945 return def_p;
947 if (ptr->mustdefs)
949 def_p = MUSTDEF_RESULT_PTR (ptr->mustdefs);
950 ptr->mustdefs = ptr->mustdefs->next;
951 return def_p;
953 if (ptr->maydefs)
955 def_p = MAYDEF_RESULT_PTR (ptr->maydefs);
956 ptr->maydefs = ptr->maydefs->next;
957 return def_p;
959 ptr->done = true;
960 return NULL_DEF_OPERAND_P;
963 /* Get the next iterator tree value for PTR. */
964 static inline tree
965 op_iter_next_tree (ssa_op_iter *ptr)
967 tree val;
968 #ifdef ENABLE_CHECKING
969 gcc_assert (ptr->iter_type == ssa_op_iter_tree);
970 #endif
971 if (ptr->uses)
973 val = USE_OP (ptr->uses);
974 ptr->uses = ptr->uses->next;
975 return val;
977 if (ptr->vuses)
979 val = VUSE_OP (ptr->vuses);
980 ptr->vuses = ptr->vuses->next;
981 return val;
983 if (ptr->mayuses)
985 val = MAYDEF_OP (ptr->mayuses);
986 ptr->mayuses = ptr->mayuses->next;
987 return val;
989 if (ptr->mustkills)
991 val = MUSTDEF_KILL (ptr->mustkills);
992 ptr->mustkills = ptr->mustkills->next;
993 return val;
995 if (ptr->defs)
997 val = DEF_OP (ptr->defs);
998 ptr->defs = ptr->defs->next;
999 return val;
1001 if (ptr->mustdefs)
1003 val = MUSTDEF_RESULT (ptr->mustdefs);
1004 ptr->mustdefs = ptr->mustdefs->next;
1005 return val;
1007 if (ptr->maydefs)
1009 val = MAYDEF_RESULT (ptr->maydefs);
1010 ptr->maydefs = ptr->maydefs->next;
1011 return val;
1014 ptr->done = true;
1015 return NULL_TREE;
1020 /* This functions clears the iterator PTR, and marks it done. This is normally
1021 used to prevent warnings in the compile about might be uninitialized
1022 components. */
1024 static inline void
1025 clear_and_done_ssa_iter (ssa_op_iter *ptr)
1027 ptr->defs = NULL;
1028 ptr->uses = NULL;
1029 ptr->vuses = NULL;
1030 ptr->maydefs = NULL;
1031 ptr->mayuses = NULL;
1032 ptr->mustdefs = NULL;
1033 ptr->mustkills = NULL;
1034 ptr->iter_type = ssa_op_iter_none;
1035 ptr->phi_i = 0;
1036 ptr->num_phi = 0;
1037 ptr->phi_stmt = NULL_TREE;
1038 ptr->done = true;
1041 /* Initialize the iterator PTR to the virtual defs in STMT. */
1042 static inline void
1043 op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
1045 #ifdef ENABLE_CHECKING
1046 gcc_assert (stmt_ann (stmt));
1047 #endif
1049 ptr->defs = (flags & SSA_OP_DEF) ? DEF_OPS (stmt) : NULL;
1050 ptr->uses = (flags & SSA_OP_USE) ? USE_OPS (stmt) : NULL;
1051 ptr->vuses = (flags & SSA_OP_VUSE) ? VUSE_OPS (stmt) : NULL;
1052 ptr->maydefs = (flags & SSA_OP_VMAYDEF) ? MAYDEF_OPS (stmt) : NULL;
1053 ptr->mayuses = (flags & SSA_OP_VMAYUSE) ? MAYDEF_OPS (stmt) : NULL;
1054 ptr->mustdefs = (flags & SSA_OP_VMUSTDEF) ? MUSTDEF_OPS (stmt) : NULL;
1055 ptr->mustkills = (flags & SSA_OP_VMUSTKILL) ? MUSTDEF_OPS (stmt) : NULL;
1056 ptr->done = false;
1058 ptr->phi_i = 0;
1059 ptr->num_phi = 0;
1060 ptr->phi_stmt = NULL_TREE;
1063 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1064 the first use. */
1065 static inline use_operand_p
1066 op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
1068 gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0);
1069 op_iter_init (ptr, stmt, flags);
1070 ptr->iter_type = ssa_op_iter_use;
1071 return op_iter_next_use (ptr);
1074 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1075 the first def. */
1076 static inline def_operand_p
1077 op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1079 gcc_assert ((flags & (SSA_OP_ALL_USES | SSA_OP_VIRTUAL_KILLS)) == 0);
1080 op_iter_init (ptr, stmt, flags);
1081 ptr->iter_type = ssa_op_iter_def;
1082 return op_iter_next_def (ptr);
1085 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1086 the first operand as a tree. */
1087 static inline tree
1088 op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1090 op_iter_init (ptr, stmt, flags);
1091 ptr->iter_type = ssa_op_iter_tree;
1092 return op_iter_next_tree (ptr);
1095 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1096 KILL and DEF. */
1097 static inline void
1098 op_iter_next_maymustdef (use_operand_p *use, def_operand_p *def,
1099 ssa_op_iter *ptr)
1101 #ifdef ENABLE_CHECKING
1102 gcc_assert (ptr->iter_type == ssa_op_iter_maymustdef);
1103 #endif
1104 if (ptr->mayuses)
1106 *def = MAYDEF_RESULT_PTR (ptr->mayuses);
1107 *use = MAYDEF_OP_PTR (ptr->mayuses);
1108 ptr->mayuses = ptr->mayuses->next;
1109 return;
1112 if (ptr->mustkills)
1114 *def = MUSTDEF_RESULT_PTR (ptr->mustkills);
1115 *use = MUSTDEF_KILL_PTR (ptr->mustkills);
1116 ptr->mustkills = ptr->mustkills->next;
1117 return;
1120 *def = NULL_DEF_OPERAND_P;
1121 *use = NULL_USE_OPERAND_P;
1122 ptr->done = true;
1123 return;
1127 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1128 in USE and DEF. */
1129 static inline void
1130 op_iter_init_maydef (ssa_op_iter *ptr, tree stmt, use_operand_p *use,
1131 def_operand_p *def)
1133 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1135 op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1136 ptr->iter_type = ssa_op_iter_maymustdef;
1137 op_iter_next_maymustdef (use, def, ptr);
1141 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1142 in KILL and DEF. */
1143 static inline void
1144 op_iter_init_mustdef (ssa_op_iter *ptr, tree stmt, use_operand_p *kill,
1145 def_operand_p *def)
1147 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1149 op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL);
1150 ptr->iter_type = ssa_op_iter_maymustdef;
1151 op_iter_next_maymustdef (kill, def, ptr);
1154 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1155 in KILL and DEF. */
1156 static inline void
1157 op_iter_init_must_and_may_def (ssa_op_iter *ptr, tree stmt,
1158 use_operand_p *kill, def_operand_p *def)
1160 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1162 op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL|SSA_OP_VMAYUSE);
1163 ptr->iter_type = ssa_op_iter_maymustdef;
1164 op_iter_next_maymustdef (kill, def, ptr);
1168 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1169 return NULL. */
1170 static inline tree
1171 single_ssa_tree_operand (tree stmt, int flags)
1173 tree var;
1174 ssa_op_iter iter;
1176 var = op_iter_init_tree (&iter, stmt, flags);
1177 if (op_iter_done (&iter))
1178 return NULL_TREE;
1179 op_iter_next_tree (&iter);
1180 if (op_iter_done (&iter))
1181 return var;
1182 return NULL_TREE;
1186 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1187 return NULL. */
1188 static inline use_operand_p
1189 single_ssa_use_operand (tree stmt, int flags)
1191 use_operand_p var;
1192 ssa_op_iter iter;
1194 var = op_iter_init_use (&iter, stmt, flags);
1195 if (op_iter_done (&iter))
1196 return NULL_USE_OPERAND_P;
1197 op_iter_next_use (&iter);
1198 if (op_iter_done (&iter))
1199 return var;
1200 return NULL_USE_OPERAND_P;
1205 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1206 return NULL. */
1207 static inline def_operand_p
1208 single_ssa_def_operand (tree stmt, int flags)
1210 def_operand_p var;
1211 ssa_op_iter iter;
1213 var = op_iter_init_def (&iter, stmt, flags);
1214 if (op_iter_done (&iter))
1215 return NULL_DEF_OPERAND_P;
1216 op_iter_next_def (&iter);
1217 if (op_iter_done (&iter))
1218 return var;
1219 return NULL_DEF_OPERAND_P;
1223 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1224 return NULL. */
1225 static inline bool
1226 zero_ssa_operands (tree stmt, int flags)
1228 ssa_op_iter iter;
1230 op_iter_init_tree (&iter, stmt, flags);
1231 return op_iter_done (&iter);
1235 /* Return the number of operands matching FLAGS in STMT. */
1236 static inline int
1237 num_ssa_operands (tree stmt, int flags)
1239 ssa_op_iter iter;
1240 tree t;
1241 int num = 0;
1243 FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
1244 num++;
1245 return num;
1249 /* Delink all immediate_use information for STMT. */
1250 static inline void
1251 delink_stmt_imm_use (tree stmt)
1253 ssa_op_iter iter;
1254 use_operand_p use_p;
1256 if (ssa_operands_active ())
1257 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter,
1258 (SSA_OP_ALL_USES | SSA_OP_ALL_KILLS))
1259 delink_imm_use (use_p);
1263 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1264 in STMT2. TRUE is returned if they are the same. STMTs can be NULL. */
1265 static inline bool
1266 compare_ssa_operands_equal (tree stmt1, tree stmt2, int flags)
1268 ssa_op_iter iter1, iter2;
1269 tree op1 = NULL_TREE;
1270 tree op2 = NULL_TREE;
1271 bool look1, look2;
1273 if (stmt1 == stmt2)
1274 return true;
1276 look1 = stmt1 && stmt_ann (stmt1);
1277 look2 = stmt2 && stmt_ann (stmt2);
1279 if (look1)
1281 op1 = op_iter_init_tree (&iter1, stmt1, flags);
1282 if (!look2)
1283 return op_iter_done (&iter1);
1285 else
1286 clear_and_done_ssa_iter (&iter1);
1288 if (look2)
1290 op2 = op_iter_init_tree (&iter2, stmt2, flags);
1291 if (!look1)
1292 return op_iter_done (&iter2);
1294 else
1295 clear_and_done_ssa_iter (&iter2);
1297 while (!op_iter_done (&iter1) && !op_iter_done (&iter2))
1299 if (op1 != op2)
1300 return false;
1301 op1 = op_iter_next_tree (&iter1);
1302 op2 = op_iter_next_tree (&iter2);
1305 return (op_iter_done (&iter1) && op_iter_done (&iter2));
1309 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1310 Otherwise return NULL_DEF_OPERAND_P. */
1311 static inline tree
1312 single_phi_def (tree stmt, int flags)
1314 tree def = PHI_RESULT (stmt);
1315 if ((flags & SSA_OP_DEF) && is_gimple_reg (def))
1316 return def;
1317 if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
1318 return def;
1319 return NULL_TREE;
1322 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
1323 be either SSA_OP_USES or SAS_OP_VIRTUAL_USES. */
1324 static inline use_operand_p
1325 op_iter_init_phiuse (ssa_op_iter *ptr, tree phi, int flags)
1327 tree phi_def = PHI_RESULT (phi);
1328 int comp;
1330 clear_and_done_ssa_iter (ptr);
1331 ptr->done = false;
1333 gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
1335 comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1337 /* If the PHI node doesn't the operand type we care about, we're done. */
1338 if ((flags & comp) == 0)
1340 ptr->done = true;
1341 return NULL_USE_OPERAND_P;
1344 ptr->phi_stmt = phi;
1345 ptr->num_phi = PHI_NUM_ARGS (phi);
1346 ptr->iter_type = ssa_op_iter_use;
1347 return op_iter_next_use (ptr);
1351 /* Start an iterator for a PHI definition. */
1353 static inline def_operand_p
1354 op_iter_init_phidef (ssa_op_iter *ptr, tree phi, int flags)
1356 tree phi_def = PHI_RESULT (phi);
1357 int comp;
1359 clear_and_done_ssa_iter (ptr);
1360 ptr->done = false;
1362 gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
1364 comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
1366 /* If the PHI node doesn't the operand type we care about, we're done. */
1367 if ((flags & comp) == 0)
1369 ptr->done = true;
1370 return NULL_USE_OPERAND_P;
1373 ptr->iter_type = ssa_op_iter_def;
1374 /* The first call to op_iter_next_def will terminate the iterator since
1375 all the fields are NULL. Simply return the result here as the first and
1376 therefore only result. */
1377 return PHI_RESULT_PTR (phi);
1382 /* Return true if VAR cannot be modified by the program. */
1384 static inline bool
1385 unmodifiable_var_p (tree var)
1387 if (TREE_CODE (var) == SSA_NAME)
1388 var = SSA_NAME_VAR (var);
1390 if (MTAG_P (var))
1391 return TREE_READONLY (var) && (TREE_STATIC (var) || MTAG_GLOBAL (var));
1393 return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1396 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it. */
1398 static inline bool
1399 array_ref_contains_indirect_ref (tree ref)
1401 gcc_assert (TREE_CODE (ref) == ARRAY_REF);
1403 do {
1404 ref = TREE_OPERAND (ref, 0);
1405 } while (handled_component_p (ref));
1407 return TREE_CODE (ref) == INDIRECT_REF;
1410 /* Return true if REF, a handled component reference, has an ARRAY_REF
1411 somewhere in it. */
1413 static inline bool
1414 ref_contains_array_ref (tree ref)
1416 gcc_assert (handled_component_p (ref));
1418 do {
1419 if (TREE_CODE (ref) == ARRAY_REF)
1420 return true;
1421 ref = TREE_OPERAND (ref, 0);
1422 } while (handled_component_p (ref));
1424 return false;
1427 /* Given a variable VAR, lookup and return a pointer to the list of
1428 subvariables for it. */
1430 static inline subvar_t *
1431 lookup_subvars_for_var (tree var)
1433 var_ann_t ann = var_ann (var);
1434 gcc_assert (ann);
1435 return &ann->subvars;
1438 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1439 NULL, if there are no subvariables. */
1441 static inline subvar_t
1442 get_subvars_for_var (tree var)
1444 subvar_t subvars;
1446 gcc_assert (SSA_VAR_P (var));
1448 if (TREE_CODE (var) == SSA_NAME)
1449 subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
1450 else
1451 subvars = *(lookup_subvars_for_var (var));
1452 return subvars;
1455 /* Return the subvariable of VAR at offset OFFSET. */
1457 static inline tree
1458 get_subvar_at (tree var, unsigned HOST_WIDE_INT offset)
1460 subvar_t sv;
1462 for (sv = get_subvars_for_var (var); sv; sv = sv->next)
1463 if (sv->offset == offset)
1464 return sv->var;
1466 return NULL_TREE;
1469 /* Return true if V is a tree that we can have subvars for.
1470 Normally, this is any aggregate type, however, due to implementation
1471 limitations ATM, we exclude array types as well. */
1473 static inline bool
1474 var_can_have_subvars (tree v)
1476 return (AGGREGATE_TYPE_P (TREE_TYPE (v)) &&
1477 TREE_CODE (TREE_TYPE (v)) != ARRAY_TYPE);
1481 /* Return true if OFFSET and SIZE define a range that overlaps with some
1482 portion of the range of SV, a subvar. If there was an exact overlap,
1483 *EXACT will be set to true upon return. */
1485 static inline bool
1486 overlap_subvar (unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT size,
1487 subvar_t sv, bool *exact)
1489 /* There are three possible cases of overlap.
1490 1. We can have an exact overlap, like so:
1491 |offset, offset + size |
1492 |sv->offset, sv->offset + sv->size |
1494 2. We can have offset starting after sv->offset, like so:
1496 |offset, offset + size |
1497 |sv->offset, sv->offset + sv->size |
1499 3. We can have offset starting before sv->offset, like so:
1501 |offset, offset + size |
1502 |sv->offset, sv->offset + sv->size|
1505 if (exact)
1506 *exact = false;
1507 if (offset == sv->offset && size == sv->size)
1509 if (exact)
1510 *exact = true;
1511 return true;
1513 else if (offset >= sv->offset && offset < (sv->offset + sv->size))
1515 return true;
1517 else if (offset < sv->offset && (size > sv->offset - offset))
1519 return true;
1521 return false;
1525 #endif /* _TREE_FLOW_INLINE_H */