2006-01-10 Jan Beulich <jbeulich@novell.com>
[official-gcc.git] / gcc / tree-flow-inline.h
blob3f8e89d136199b9139b23aeb08c06025b9ffb195
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 (TREE_CODE (t) != FUNCTION_DECL);
130 gcc_assert (!t->common.ann || t->common.ann->common.type == VAR_ANN);
132 return (var_ann_t) t->common.ann;
135 /* Return the variable annotation for T, which must be a _DECL node.
136 Create the variable annotation if it doesn't exist. */
137 static inline var_ann_t
138 get_var_ann (tree var)
140 var_ann_t ann = var_ann (var);
141 return (ann) ? ann : create_var_ann (var);
144 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
145 Return NULL if the function annotation doesn't already exist. */
146 static inline function_ann_t
147 function_ann (tree t)
149 gcc_assert (t);
150 gcc_assert (TREE_CODE (t) == FUNCTION_DECL);
151 gcc_assert (!t->common.ann || t->common.ann->common.type == FUNCTION_ANN);
153 return (function_ann_t) t->common.ann;
156 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
157 Create the function annotation if it doesn't exist. */
158 static inline function_ann_t
159 get_function_ann (tree var)
161 function_ann_t ann = function_ann (var);
162 return (ann) ? ann : create_function_ann (var);
165 /* Return the statement annotation for T, which must be a statement
166 node. Return NULL if the statement annotation doesn't exist. */
167 static inline stmt_ann_t
168 stmt_ann (tree t)
170 #ifdef ENABLE_CHECKING
171 gcc_assert (is_gimple_stmt (t));
172 #endif
173 return (stmt_ann_t) t->common.ann;
176 /* Return the statement annotation for T, which must be a statement
177 node. Create the statement annotation if it doesn't exist. */
178 static inline stmt_ann_t
179 get_stmt_ann (tree stmt)
181 stmt_ann_t ann = stmt_ann (stmt);
182 return (ann) ? ann : create_stmt_ann (stmt);
185 /* Return the annotation type for annotation ANN. */
186 static inline enum tree_ann_type
187 ann_type (tree_ann_t ann)
189 return ann->common.type;
192 /* Return the basic block for statement T. */
193 static inline basic_block
194 bb_for_stmt (tree t)
196 stmt_ann_t ann;
198 if (TREE_CODE (t) == PHI_NODE)
199 return PHI_BB (t);
201 ann = stmt_ann (t);
202 return ann ? ann->bb : NULL;
205 /* Return the may_aliases varray for variable VAR, or NULL if it has
206 no may aliases. */
207 static inline VEC(tree, gc) *
208 may_aliases (tree var)
210 var_ann_t ann = var_ann (var);
211 return ann ? ann->may_aliases : NULL;
214 /* Return the line number for EXPR, or return -1 if we have no line
215 number information for it. */
216 static inline int
217 get_lineno (tree expr)
219 if (expr == NULL_TREE)
220 return -1;
222 if (TREE_CODE (expr) == COMPOUND_EXPR)
223 expr = TREE_OPERAND (expr, 0);
225 if (! EXPR_HAS_LOCATION (expr))
226 return -1;
228 return EXPR_LINENO (expr);
231 /* Return the file name for EXPR, or return "???" if we have no
232 filename information. */
233 static inline const char *
234 get_filename (tree expr)
236 const char *filename;
237 if (expr == NULL_TREE)
238 return "???";
240 if (TREE_CODE (expr) == COMPOUND_EXPR)
241 expr = TREE_OPERAND (expr, 0);
243 if (EXPR_HAS_LOCATION (expr) && (filename = EXPR_FILENAME (expr)))
244 return filename;
245 else
246 return "???";
249 /* Return true if T is a noreturn call. */
250 static inline bool
251 noreturn_call_p (tree t)
253 tree call = get_call_expr_in (t);
254 return call != 0 && (call_expr_flags (call) & ECF_NORETURN) != 0;
257 /* Mark statement T as modified. */
258 static inline void
259 mark_stmt_modified (tree t)
261 stmt_ann_t ann;
262 if (TREE_CODE (t) == PHI_NODE)
263 return;
265 ann = stmt_ann (t);
266 if (ann == NULL)
267 ann = create_stmt_ann (t);
268 else if (noreturn_call_p (t))
269 VEC_safe_push (tree, gc, modified_noreturn_calls, t);
270 ann->modified = 1;
273 /* Mark statement T as modified, and update it. */
274 static inline void
275 update_stmt (tree t)
277 if (TREE_CODE (t) == PHI_NODE)
278 return;
279 mark_stmt_modified (t);
280 update_stmt_operands (t);
283 static inline void
284 update_stmt_if_modified (tree t)
286 if (stmt_modified_p (t))
287 update_stmt_operands (t);
290 /* Return true if T is marked as modified, false otherwise. */
291 static inline bool
292 stmt_modified_p (tree t)
294 stmt_ann_t ann = stmt_ann (t);
296 /* Note that if the statement doesn't yet have an annotation, we consider it
297 modified. This will force the next call to update_stmt_operands to scan
298 the statement. */
299 return ann ? ann->modified : true;
302 /* Delink an immediate_uses node from its chain. */
303 static inline void
304 delink_imm_use (ssa_use_operand_t *linknode)
306 /* Return if this node is not in a list. */
307 if (linknode->prev == NULL)
308 return;
310 linknode->prev->next = linknode->next;
311 linknode->next->prev = linknode->prev;
312 linknode->prev = NULL;
313 linknode->next = NULL;
316 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
317 static inline void
318 link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
320 /* Link the new node at the head of the list. If we are in the process of
321 traversing the list, we won't visit any new nodes added to it. */
322 linknode->prev = list;
323 linknode->next = list->next;
324 list->next->prev = linknode;
325 list->next = linknode;
328 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
329 static inline void
330 link_imm_use (ssa_use_operand_t *linknode, tree def)
332 ssa_use_operand_t *root;
334 if (!def || TREE_CODE (def) != SSA_NAME)
335 linknode->prev = NULL;
336 else
338 root = &(SSA_NAME_IMM_USE_NODE (def));
339 #ifdef ENABLE_CHECKING
340 if (linknode->use)
341 gcc_assert (*(linknode->use) == def);
342 #endif
343 link_imm_use_to_list (linknode, root);
347 /* Set the value of a use pointed to by USE to VAL. */
348 static inline void
349 set_ssa_use_from_ptr (use_operand_p use, tree val)
351 delink_imm_use (use);
352 *(use->use) = val;
353 link_imm_use (use, val);
356 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
357 in STMT. */
358 static inline void
359 link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, tree stmt)
361 if (stmt)
362 link_imm_use (linknode, def);
363 else
364 link_imm_use (linknode, NULL);
365 linknode->stmt = stmt;
368 /* Relink a new node in place of an old node in the list. */
369 static inline void
370 relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
372 /* The node one had better be in the same list. */
373 gcc_assert (*(old->use) == *(node->use));
374 node->prev = old->prev;
375 node->next = old->next;
376 if (old->prev)
378 old->prev->next = node;
379 old->next->prev = node;
380 /* Remove the old node from the list. */
381 old->prev = NULL;
385 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
386 in STMT. */
387 static inline void
388 relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old, tree stmt)
390 if (stmt)
391 relink_imm_use (linknode, old);
392 else
393 link_imm_use (linknode, NULL);
394 linknode->stmt = stmt;
397 /* Finished the traverse of an immediate use list IMM by removing it from
398 the list. */
399 static inline void
400 end_safe_imm_use_traverse (imm_use_iterator *imm)
402 delink_imm_use (&(imm->iter_node));
405 /* Return true if IMM is at the end of the list. */
406 static inline bool
407 end_safe_imm_use_p (imm_use_iterator *imm)
409 return (imm->imm_use == imm->end_p);
412 /* Initialize iterator IMM to process the list for VAR. */
413 static inline use_operand_p
414 first_safe_imm_use (imm_use_iterator *imm, tree var)
416 /* Set up and link the iterator node into the linked list for VAR. */
417 imm->iter_node.use = NULL;
418 imm->iter_node.stmt = NULL_TREE;
419 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
420 /* Check if there are 0 elements. */
421 if (imm->end_p->next == imm->end_p)
423 imm->imm_use = imm->end_p;
424 return NULL_USE_OPERAND_P;
427 link_imm_use (&(imm->iter_node), var);
428 imm->imm_use = imm->iter_node.next;
429 return imm->imm_use;
432 /* Bump IMM to the next use in the list. */
433 static inline use_operand_p
434 next_safe_imm_use (imm_use_iterator *imm)
436 ssa_use_operand_t *ptr;
437 use_operand_p old;
439 old = imm->imm_use;
440 /* If the next node following the iter_node is still the one referred to by
441 imm_use, then the list hasn't changed, go to the next node. */
442 if (imm->iter_node.next == imm->imm_use)
444 ptr = &(imm->iter_node);
445 /* Remove iternode from the list. */
446 delink_imm_use (ptr);
447 imm->imm_use = imm->imm_use->next;
448 if (! end_safe_imm_use_p (imm))
450 /* This isn't the end, link iternode before the next use. */
451 ptr->prev = imm->imm_use->prev;
452 ptr->next = imm->imm_use;
453 imm->imm_use->prev->next = ptr;
454 imm->imm_use->prev = ptr;
456 else
457 return old;
459 else
461 /* If the 'next' value after the iterator isn't the same as it was, then
462 a node has been deleted, so we simply proceed to the node following
463 where the iterator is in the list. */
464 imm->imm_use = imm->iter_node.next;
465 if (end_safe_imm_use_p (imm))
467 end_safe_imm_use_traverse (imm);
468 return old;
472 return imm->imm_use;
475 /* Return true is IMM has reached the end of the immediate use list. */
476 static inline bool
477 end_readonly_imm_use_p (imm_use_iterator *imm)
479 return (imm->imm_use == imm->end_p);
482 /* Initialize iterator IMM to process the list for VAR. */
483 static inline use_operand_p
484 first_readonly_imm_use (imm_use_iterator *imm, tree var)
486 gcc_assert (TREE_CODE (var) == SSA_NAME);
488 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
489 imm->imm_use = imm->end_p->next;
490 #ifdef ENABLE_CHECKING
491 imm->iter_node.next = imm->imm_use->next;
492 #endif
493 if (end_readonly_imm_use_p (imm))
494 return NULL_USE_OPERAND_P;
495 return imm->imm_use;
498 /* Bump IMM to the next use in the list. */
499 static inline use_operand_p
500 next_readonly_imm_use (imm_use_iterator *imm)
502 use_operand_p old = imm->imm_use;
504 #ifdef ENABLE_CHECKING
505 /* If this assertion fails, it indicates the 'next' pointer has changed
506 since we the last bump. This indicates that the list is being modified
507 via stmt changes, or SET_USE, or somesuch thing, and you need to be
508 using the SAFE version of the iterator. */
509 gcc_assert (imm->iter_node.next == old->next);
510 imm->iter_node.next = old->next->next;
511 #endif
513 imm->imm_use = old->next;
514 if (end_readonly_imm_use_p (imm))
515 return old;
516 return imm->imm_use;
519 /* Return true if VAR has no uses. */
520 static inline bool
521 has_zero_uses (tree var)
523 ssa_use_operand_t *ptr;
524 ptr = &(SSA_NAME_IMM_USE_NODE (var));
525 /* A single use means there is no items in the list. */
526 return (ptr == ptr->next);
529 /* Return true if VAR has a single use. */
530 static inline bool
531 has_single_use (tree var)
533 ssa_use_operand_t *ptr;
534 ptr = &(SSA_NAME_IMM_USE_NODE (var));
535 /* A single use means there is one item in the list. */
536 return (ptr != ptr->next && ptr == ptr->next->next);
539 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
540 to the use pointer and stmt of occurrence. */
541 static inline bool
542 single_imm_use (tree var, use_operand_p *use_p, tree *stmt)
544 ssa_use_operand_t *ptr;
546 ptr = &(SSA_NAME_IMM_USE_NODE (var));
547 if (ptr != ptr->next && ptr == ptr->next->next)
549 *use_p = ptr->next;
550 *stmt = ptr->next->stmt;
551 return true;
553 *use_p = NULL_USE_OPERAND_P;
554 *stmt = NULL_TREE;
555 return false;
558 /* Return the number of immediate uses of VAR. */
559 static inline unsigned int
560 num_imm_uses (tree var)
562 ssa_use_operand_t *ptr, *start;
563 unsigned int num;
565 start = &(SSA_NAME_IMM_USE_NODE (var));
566 num = 0;
567 for (ptr = start->next; ptr != start; ptr = ptr->next)
568 num++;
570 return num;
574 /* Return the tree pointer to by USE. */
575 static inline tree
576 get_use_from_ptr (use_operand_p use)
578 return *(use->use);
581 /* Return the tree pointer to by DEF. */
582 static inline tree
583 get_def_from_ptr (def_operand_p def)
585 return *def;
588 /* Return a def_operand_p pointer for the result of PHI. */
589 static inline def_operand_p
590 get_phi_result_ptr (tree phi)
592 return &(PHI_RESULT_TREE (phi));
595 /* Return a use_operand_p pointer for argument I of phinode PHI. */
596 static inline use_operand_p
597 get_phi_arg_def_ptr (tree phi, int i)
599 return &(PHI_ARG_IMM_USE_NODE (phi,i));
603 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
604 no addresses. */
605 static inline bitmap
606 addresses_taken (tree stmt)
608 stmt_ann_t ann = stmt_ann (stmt);
609 return ann ? ann->addresses_taken : NULL;
612 /* Return the PHI nodes for basic block BB, or NULL if there are no
613 PHI nodes. */
614 static inline tree
615 phi_nodes (basic_block bb)
617 return bb->phi_nodes;
620 /* Set list of phi nodes of a basic block BB to L. */
622 static inline void
623 set_phi_nodes (basic_block bb, tree l)
625 tree phi;
627 bb->phi_nodes = l;
628 for (phi = l; phi; phi = PHI_CHAIN (phi))
629 set_bb_for_stmt (phi, bb);
632 /* Return the phi argument which contains the specified use. */
634 static inline int
635 phi_arg_index_from_use (use_operand_p use)
637 struct phi_arg_d *element, *root;
638 int index;
639 tree phi;
641 /* Since the use is the first thing in a PHI argument element, we can
642 calculate its index based on casting it to an argument, and performing
643 pointer arithmetic. */
645 phi = USE_STMT (use);
646 gcc_assert (TREE_CODE (phi) == PHI_NODE);
648 element = (struct phi_arg_d *)use;
649 root = &(PHI_ARG_ELT (phi, 0));
650 index = element - root;
652 #ifdef ENABLE_CHECKING
653 /* Make sure the calculation doesn't have any leftover bytes. If it does,
654 then imm_use is likely not the first element in phi_arg_d. */
655 gcc_assert (
656 (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
657 gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
658 #endif
660 return index;
663 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
665 static inline void
666 set_is_used (tree var)
668 var_ann_t ann = get_var_ann (var);
669 ann->used = 1;
673 /* ----------------------------------------------------------------------- */
675 /* Return true if T is an executable statement. */
676 static inline bool
677 is_exec_stmt (tree t)
679 return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
683 /* Return true if this stmt can be the target of a control transfer stmt such
684 as a goto. */
685 static inline bool
686 is_label_stmt (tree t)
688 if (t)
689 switch (TREE_CODE (t))
691 case LABEL_DECL:
692 case LABEL_EXPR:
693 case CASE_LABEL_EXPR:
694 return true;
695 default:
696 return false;
698 return false;
701 /* PHI nodes should contain only ssa_names and invariants. A test
702 for ssa_name is definitely simpler; don't let invalid contents
703 slip in in the meantime. */
705 static inline bool
706 phi_ssa_name_p (tree t)
708 if (TREE_CODE (t) == SSA_NAME)
709 return true;
710 #ifdef ENABLE_CHECKING
711 gcc_assert (is_gimple_min_invariant (t));
712 #endif
713 return false;
716 /* ----------------------------------------------------------------------- */
718 /* Return a block_stmt_iterator that points to beginning of basic
719 block BB. */
720 static inline block_stmt_iterator
721 bsi_start (basic_block bb)
723 block_stmt_iterator bsi;
724 if (bb->stmt_list)
725 bsi.tsi = tsi_start (bb->stmt_list);
726 else
728 gcc_assert (bb->index < NUM_FIXED_BLOCKS);
729 bsi.tsi.ptr = NULL;
730 bsi.tsi.container = NULL;
732 bsi.bb = bb;
733 return bsi;
736 /* Return a block statement iterator that points to the first non-label
737 block BB. */
739 static inline block_stmt_iterator
740 bsi_after_labels (basic_block bb)
742 block_stmt_iterator bsi;
743 tree_stmt_iterator next;
745 bsi.bb = bb;
747 if (!bb->stmt_list)
749 gcc_assert (bb->index < NUM_FIXED_BLOCKS);
750 bsi.tsi.ptr = NULL;
751 bsi.tsi.container = NULL;
752 return bsi;
755 bsi.tsi = tsi_start (bb->stmt_list);
756 if (tsi_end_p (bsi.tsi))
757 return bsi;
759 next = bsi.tsi;
760 tsi_next (&next);
762 while (!tsi_end_p (next)
763 && TREE_CODE (tsi_stmt (next)) == LABEL_EXPR)
765 bsi.tsi = next;
766 tsi_next (&next);
769 return bsi;
772 /* Return a block statement iterator that points to the end of basic
773 block BB. */
774 static inline block_stmt_iterator
775 bsi_last (basic_block bb)
777 block_stmt_iterator bsi;
778 if (bb->stmt_list)
779 bsi.tsi = tsi_last (bb->stmt_list);
780 else
782 gcc_assert (bb->index < NUM_FIXED_BLOCKS);
783 bsi.tsi.ptr = NULL;
784 bsi.tsi.container = NULL;
786 bsi.bb = bb;
787 return bsi;
790 /* Return true if block statement iterator I has reached the end of
791 the basic block. */
792 static inline bool
793 bsi_end_p (block_stmt_iterator i)
795 return tsi_end_p (i.tsi);
798 /* Modify block statement iterator I so that it is at the next
799 statement in the basic block. */
800 static inline void
801 bsi_next (block_stmt_iterator *i)
803 tsi_next (&i->tsi);
806 /* Modify block statement iterator I so that it is at the previous
807 statement in the basic block. */
808 static inline void
809 bsi_prev (block_stmt_iterator *i)
811 tsi_prev (&i->tsi);
814 /* Return the statement that block statement iterator I is currently
815 at. */
816 static inline tree
817 bsi_stmt (block_stmt_iterator i)
819 return tsi_stmt (i.tsi);
822 /* Return a pointer to the statement that block statement iterator I
823 is currently at. */
824 static inline tree *
825 bsi_stmt_ptr (block_stmt_iterator i)
827 return tsi_stmt_ptr (i.tsi);
830 /* Returns the loop of the statement STMT. */
832 static inline struct loop *
833 loop_containing_stmt (tree stmt)
835 basic_block bb = bb_for_stmt (stmt);
836 if (!bb)
837 return NULL;
839 return bb->loop_father;
842 /* Return true if VAR is a clobbered by function calls. */
843 static inline bool
844 is_call_clobbered (tree var)
846 return is_global_var (var)
847 || bitmap_bit_p (call_clobbered_vars, DECL_UID (var));
850 /* Mark variable VAR as being clobbered by function calls. */
851 static inline void
852 mark_call_clobbered (tree var)
854 /* If VAR is a memory tag, then we need to consider it a global
855 variable. This is because the pointer that VAR represents has
856 been found to point to either an arbitrary location or to a known
857 location in global memory. */
858 if (MTAG_P (var) && TREE_CODE (var) != STRUCT_FIELD_TAG)
859 MTAG_GLOBAL (var) = 1;
860 bitmap_set_bit (call_clobbered_vars, DECL_UID (var));
861 ssa_call_clobbered_cache_valid = false;
862 ssa_ro_call_cache_valid = false;
865 /* Clear the call-clobbered attribute from variable VAR. */
866 static inline void
867 clear_call_clobbered (tree var)
869 if (MTAG_P (var) && TREE_CODE (var) != STRUCT_FIELD_TAG)
870 MTAG_GLOBAL (var) = 0;
871 bitmap_clear_bit (call_clobbered_vars, DECL_UID (var));
872 ssa_call_clobbered_cache_valid = false;
873 ssa_ro_call_cache_valid = false;
876 /* Mark variable VAR as being non-addressable. */
877 static inline void
878 mark_non_addressable (tree var)
880 bitmap_clear_bit (call_clobbered_vars, DECL_UID (var));
881 TREE_ADDRESSABLE (var) = 0;
882 ssa_call_clobbered_cache_valid = false;
883 ssa_ro_call_cache_valid = false;
886 /* Return the common annotation for T. Return NULL if the annotation
887 doesn't already exist. */
888 static inline tree_ann_t
889 tree_ann (tree t)
891 return t->common.ann;
894 /* Return a common annotation for T. Create the constant annotation if it
895 doesn't exist. */
896 static inline tree_ann_t
897 get_tree_ann (tree t)
899 tree_ann_t ann = tree_ann (t);
900 return (ann) ? ann : create_tree_ann (t);
903 /* ----------------------------------------------------------------------- */
905 /* The following set of routines are used to iterator over various type of
906 SSA operands. */
908 /* Return true if PTR is finished iterating. */
909 static inline bool
910 op_iter_done (ssa_op_iter *ptr)
912 return ptr->done;
915 /* Get the next iterator use value for PTR. */
916 static inline use_operand_p
917 op_iter_next_use (ssa_op_iter *ptr)
919 use_operand_p use_p;
920 #ifdef ENABLE_CHECKING
921 gcc_assert (ptr->iter_type == ssa_op_iter_use);
922 #endif
923 if (ptr->uses)
925 use_p = USE_OP_PTR (ptr->uses);
926 ptr->uses = ptr->uses->next;
927 return use_p;
929 if (ptr->vuses)
931 use_p = VUSE_OP_PTR (ptr->vuses);
932 ptr->vuses = ptr->vuses->next;
933 return use_p;
935 if (ptr->mayuses)
937 use_p = MAYDEF_OP_PTR (ptr->mayuses);
938 ptr->mayuses = ptr->mayuses->next;
939 return use_p;
941 if (ptr->mustkills)
943 use_p = MUSTDEF_KILL_PTR (ptr->mustkills);
944 ptr->mustkills = ptr->mustkills->next;
945 return use_p;
947 if (ptr->phi_i < ptr->num_phi)
949 return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
951 ptr->done = true;
952 return NULL_USE_OPERAND_P;
955 /* Get the next iterator def value for PTR. */
956 static inline def_operand_p
957 op_iter_next_def (ssa_op_iter *ptr)
959 def_operand_p def_p;
960 #ifdef ENABLE_CHECKING
961 gcc_assert (ptr->iter_type == ssa_op_iter_def);
962 #endif
963 if (ptr->defs)
965 def_p = DEF_OP_PTR (ptr->defs);
966 ptr->defs = ptr->defs->next;
967 return def_p;
969 if (ptr->mustdefs)
971 def_p = MUSTDEF_RESULT_PTR (ptr->mustdefs);
972 ptr->mustdefs = ptr->mustdefs->next;
973 return def_p;
975 if (ptr->maydefs)
977 def_p = MAYDEF_RESULT_PTR (ptr->maydefs);
978 ptr->maydefs = ptr->maydefs->next;
979 return def_p;
981 ptr->done = true;
982 return NULL_DEF_OPERAND_P;
985 /* Get the next iterator tree value for PTR. */
986 static inline tree
987 op_iter_next_tree (ssa_op_iter *ptr)
989 tree val;
990 #ifdef ENABLE_CHECKING
991 gcc_assert (ptr->iter_type == ssa_op_iter_tree);
992 #endif
993 if (ptr->uses)
995 val = USE_OP (ptr->uses);
996 ptr->uses = ptr->uses->next;
997 return val;
999 if (ptr->vuses)
1001 val = VUSE_OP (ptr->vuses);
1002 ptr->vuses = ptr->vuses->next;
1003 return val;
1005 if (ptr->mayuses)
1007 val = MAYDEF_OP (ptr->mayuses);
1008 ptr->mayuses = ptr->mayuses->next;
1009 return val;
1011 if (ptr->mustkills)
1013 val = MUSTDEF_KILL (ptr->mustkills);
1014 ptr->mustkills = ptr->mustkills->next;
1015 return val;
1017 if (ptr->defs)
1019 val = DEF_OP (ptr->defs);
1020 ptr->defs = ptr->defs->next;
1021 return val;
1023 if (ptr->mustdefs)
1025 val = MUSTDEF_RESULT (ptr->mustdefs);
1026 ptr->mustdefs = ptr->mustdefs->next;
1027 return val;
1029 if (ptr->maydefs)
1031 val = MAYDEF_RESULT (ptr->maydefs);
1032 ptr->maydefs = ptr->maydefs->next;
1033 return val;
1036 ptr->done = true;
1037 return NULL_TREE;
1042 /* This functions clears the iterator PTR, and marks it done. This is normally
1043 used to prevent warnings in the compile about might be uninitialized
1044 components. */
1046 static inline void
1047 clear_and_done_ssa_iter (ssa_op_iter *ptr)
1049 ptr->defs = NULL;
1050 ptr->uses = NULL;
1051 ptr->vuses = NULL;
1052 ptr->maydefs = NULL;
1053 ptr->mayuses = NULL;
1054 ptr->mustdefs = NULL;
1055 ptr->mustkills = NULL;
1056 ptr->iter_type = ssa_op_iter_none;
1057 ptr->phi_i = 0;
1058 ptr->num_phi = 0;
1059 ptr->phi_stmt = NULL_TREE;
1060 ptr->done = true;
1063 /* Initialize the iterator PTR to the virtual defs in STMT. */
1064 static inline void
1065 op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
1067 #ifdef ENABLE_CHECKING
1068 gcc_assert (stmt_ann (stmt));
1069 #endif
1071 ptr->defs = (flags & SSA_OP_DEF) ? DEF_OPS (stmt) : NULL;
1072 ptr->uses = (flags & SSA_OP_USE) ? USE_OPS (stmt) : NULL;
1073 ptr->vuses = (flags & SSA_OP_VUSE) ? VUSE_OPS (stmt) : NULL;
1074 ptr->maydefs = (flags & SSA_OP_VMAYDEF) ? MAYDEF_OPS (stmt) : NULL;
1075 ptr->mayuses = (flags & SSA_OP_VMAYUSE) ? MAYDEF_OPS (stmt) : NULL;
1076 ptr->mustdefs = (flags & SSA_OP_VMUSTDEF) ? MUSTDEF_OPS (stmt) : NULL;
1077 ptr->mustkills = (flags & SSA_OP_VMUSTKILL) ? MUSTDEF_OPS (stmt) : NULL;
1078 ptr->done = false;
1080 ptr->phi_i = 0;
1081 ptr->num_phi = 0;
1082 ptr->phi_stmt = NULL_TREE;
1085 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1086 the first use. */
1087 static inline use_operand_p
1088 op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
1090 gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0);
1091 op_iter_init (ptr, stmt, flags);
1092 ptr->iter_type = ssa_op_iter_use;
1093 return op_iter_next_use (ptr);
1096 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1097 the first def. */
1098 static inline def_operand_p
1099 op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1101 gcc_assert ((flags & (SSA_OP_ALL_USES | SSA_OP_VIRTUAL_KILLS)) == 0);
1102 op_iter_init (ptr, stmt, flags);
1103 ptr->iter_type = ssa_op_iter_def;
1104 return op_iter_next_def (ptr);
1107 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1108 the first operand as a tree. */
1109 static inline tree
1110 op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1112 op_iter_init (ptr, stmt, flags);
1113 ptr->iter_type = ssa_op_iter_tree;
1114 return op_iter_next_tree (ptr);
1117 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1118 KILL and DEF. */
1119 static inline void
1120 op_iter_next_maymustdef (use_operand_p *use, def_operand_p *def,
1121 ssa_op_iter *ptr)
1123 #ifdef ENABLE_CHECKING
1124 gcc_assert (ptr->iter_type == ssa_op_iter_maymustdef);
1125 #endif
1126 if (ptr->mayuses)
1128 *def = MAYDEF_RESULT_PTR (ptr->mayuses);
1129 *use = MAYDEF_OP_PTR (ptr->mayuses);
1130 ptr->mayuses = ptr->mayuses->next;
1131 return;
1134 if (ptr->mustkills)
1136 *def = MUSTDEF_RESULT_PTR (ptr->mustkills);
1137 *use = MUSTDEF_KILL_PTR (ptr->mustkills);
1138 ptr->mustkills = ptr->mustkills->next;
1139 return;
1142 *def = NULL_DEF_OPERAND_P;
1143 *use = NULL_USE_OPERAND_P;
1144 ptr->done = true;
1145 return;
1149 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1150 in USE and DEF. */
1151 static inline void
1152 op_iter_init_maydef (ssa_op_iter *ptr, tree stmt, use_operand_p *use,
1153 def_operand_p *def)
1155 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1157 op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1158 ptr->iter_type = ssa_op_iter_maymustdef;
1159 op_iter_next_maymustdef (use, def, ptr);
1163 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1164 in KILL and DEF. */
1165 static inline void
1166 op_iter_init_mustdef (ssa_op_iter *ptr, tree stmt, use_operand_p *kill,
1167 def_operand_p *def)
1169 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1171 op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL);
1172 ptr->iter_type = ssa_op_iter_maymustdef;
1173 op_iter_next_maymustdef (kill, def, ptr);
1176 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1177 in KILL and DEF. */
1178 static inline void
1179 op_iter_init_must_and_may_def (ssa_op_iter *ptr, tree stmt,
1180 use_operand_p *kill, def_operand_p *def)
1182 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1184 op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL|SSA_OP_VMAYUSE);
1185 ptr->iter_type = ssa_op_iter_maymustdef;
1186 op_iter_next_maymustdef (kill, def, ptr);
1190 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1191 return NULL. */
1192 static inline tree
1193 single_ssa_tree_operand (tree stmt, int flags)
1195 tree var;
1196 ssa_op_iter iter;
1198 var = op_iter_init_tree (&iter, stmt, flags);
1199 if (op_iter_done (&iter))
1200 return NULL_TREE;
1201 op_iter_next_tree (&iter);
1202 if (op_iter_done (&iter))
1203 return var;
1204 return NULL_TREE;
1208 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1209 return NULL. */
1210 static inline use_operand_p
1211 single_ssa_use_operand (tree stmt, int flags)
1213 use_operand_p var;
1214 ssa_op_iter iter;
1216 var = op_iter_init_use (&iter, stmt, flags);
1217 if (op_iter_done (&iter))
1218 return NULL_USE_OPERAND_P;
1219 op_iter_next_use (&iter);
1220 if (op_iter_done (&iter))
1221 return var;
1222 return NULL_USE_OPERAND_P;
1227 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1228 return NULL. */
1229 static inline def_operand_p
1230 single_ssa_def_operand (tree stmt, int flags)
1232 def_operand_p var;
1233 ssa_op_iter iter;
1235 var = op_iter_init_def (&iter, stmt, flags);
1236 if (op_iter_done (&iter))
1237 return NULL_DEF_OPERAND_P;
1238 op_iter_next_def (&iter);
1239 if (op_iter_done (&iter))
1240 return var;
1241 return NULL_DEF_OPERAND_P;
1245 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1246 return NULL. */
1247 static inline bool
1248 zero_ssa_operands (tree stmt, int flags)
1250 ssa_op_iter iter;
1252 op_iter_init_tree (&iter, stmt, flags);
1253 return op_iter_done (&iter);
1257 /* Return the number of operands matching FLAGS in STMT. */
1258 static inline int
1259 num_ssa_operands (tree stmt, int flags)
1261 ssa_op_iter iter;
1262 tree t;
1263 int num = 0;
1265 FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
1266 num++;
1267 return num;
1271 /* Delink all immediate_use information for STMT. */
1272 static inline void
1273 delink_stmt_imm_use (tree stmt)
1275 ssa_op_iter iter;
1276 use_operand_p use_p;
1278 if (ssa_operands_active ())
1279 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter,
1280 (SSA_OP_ALL_USES | SSA_OP_ALL_KILLS))
1281 delink_imm_use (use_p);
1285 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1286 in STMT2. TRUE is returned if they are the same. STMTs can be NULL. */
1287 static inline bool
1288 compare_ssa_operands_equal (tree stmt1, tree stmt2, int flags)
1290 ssa_op_iter iter1, iter2;
1291 tree op1 = NULL_TREE;
1292 tree op2 = NULL_TREE;
1293 bool look1, look2;
1295 if (stmt1 == stmt2)
1296 return true;
1298 look1 = stmt1 && stmt_ann (stmt1);
1299 look2 = stmt2 && stmt_ann (stmt2);
1301 if (look1)
1303 op1 = op_iter_init_tree (&iter1, stmt1, flags);
1304 if (!look2)
1305 return op_iter_done (&iter1);
1307 else
1308 clear_and_done_ssa_iter (&iter1);
1310 if (look2)
1312 op2 = op_iter_init_tree (&iter2, stmt2, flags);
1313 if (!look1)
1314 return op_iter_done (&iter2);
1316 else
1317 clear_and_done_ssa_iter (&iter2);
1319 while (!op_iter_done (&iter1) && !op_iter_done (&iter2))
1321 if (op1 != op2)
1322 return false;
1323 op1 = op_iter_next_tree (&iter1);
1324 op2 = op_iter_next_tree (&iter2);
1327 return (op_iter_done (&iter1) && op_iter_done (&iter2));
1331 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1332 Otherwise return NULL_DEF_OPERAND_P. */
1333 static inline tree
1334 single_phi_def (tree stmt, int flags)
1336 tree def = PHI_RESULT (stmt);
1337 if ((flags & SSA_OP_DEF) && is_gimple_reg (def))
1338 return def;
1339 if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
1340 return def;
1341 return NULL_TREE;
1344 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
1345 be either SSA_OP_USES or SAS_OP_VIRTUAL_USES. */
1346 static inline use_operand_p
1347 op_iter_init_phiuse (ssa_op_iter *ptr, tree phi, int flags)
1349 tree phi_def = PHI_RESULT (phi);
1350 int comp;
1352 clear_and_done_ssa_iter (ptr);
1353 ptr->done = false;
1355 gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
1357 comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1359 /* If the PHI node doesn't the operand type we care about, we're done. */
1360 if ((flags & comp) == 0)
1362 ptr->done = true;
1363 return NULL_USE_OPERAND_P;
1366 ptr->phi_stmt = phi;
1367 ptr->num_phi = PHI_NUM_ARGS (phi);
1368 ptr->iter_type = ssa_op_iter_use;
1369 return op_iter_next_use (ptr);
1373 /* Start an iterator for a PHI definition. */
1375 static inline def_operand_p
1376 op_iter_init_phidef (ssa_op_iter *ptr, tree phi, int flags)
1378 tree phi_def = PHI_RESULT (phi);
1379 int comp;
1381 clear_and_done_ssa_iter (ptr);
1382 ptr->done = false;
1384 gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
1386 comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
1388 /* If the PHI node doesn't the operand type we care about, we're done. */
1389 if ((flags & comp) == 0)
1391 ptr->done = true;
1392 return NULL_USE_OPERAND_P;
1395 ptr->iter_type = ssa_op_iter_def;
1396 /* The first call to op_iter_next_def will terminate the iterator since
1397 all the fields are NULL. Simply return the result here as the first and
1398 therefore only result. */
1399 return PHI_RESULT_PTR (phi);
1404 /* Return true if VAR cannot be modified by the program. */
1406 static inline bool
1407 unmodifiable_var_p (tree var)
1409 if (TREE_CODE (var) == SSA_NAME)
1410 var = SSA_NAME_VAR (var);
1412 if (MTAG_P (var))
1413 return TREE_READONLY (var) && (TREE_STATIC (var) || MTAG_GLOBAL (var));
1415 return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1418 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it. */
1420 static inline bool
1421 array_ref_contains_indirect_ref (tree ref)
1423 gcc_assert (TREE_CODE (ref) == ARRAY_REF);
1425 do {
1426 ref = TREE_OPERAND (ref, 0);
1427 } while (handled_component_p (ref));
1429 return TREE_CODE (ref) == INDIRECT_REF;
1432 /* Return true if REF, a handled component reference, has an ARRAY_REF
1433 somewhere in it. */
1435 static inline bool
1436 ref_contains_array_ref (tree ref)
1438 gcc_assert (handled_component_p (ref));
1440 do {
1441 if (TREE_CODE (ref) == ARRAY_REF)
1442 return true;
1443 ref = TREE_OPERAND (ref, 0);
1444 } while (handled_component_p (ref));
1446 return false;
1449 /* Given a variable VAR, lookup and return a pointer to the list of
1450 subvariables for it. */
1452 static inline subvar_t *
1453 lookup_subvars_for_var (tree var)
1455 var_ann_t ann = var_ann (var);
1456 gcc_assert (ann);
1457 return &ann->subvars;
1460 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1461 NULL, if there are no subvariables. */
1463 static inline subvar_t
1464 get_subvars_for_var (tree var)
1466 subvar_t subvars;
1468 gcc_assert (SSA_VAR_P (var));
1470 if (TREE_CODE (var) == SSA_NAME)
1471 subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
1472 else
1473 subvars = *(lookup_subvars_for_var (var));
1474 return subvars;
1477 /* Return the subvariable of VAR at offset OFFSET. */
1479 static inline tree
1480 get_subvar_at (tree var, unsigned HOST_WIDE_INT offset)
1482 subvar_t sv;
1484 for (sv = get_subvars_for_var (var); sv; sv = sv->next)
1485 if (sv->offset == offset)
1486 return sv->var;
1488 return NULL_TREE;
1491 /* Return true if V is a tree that we can have subvars for.
1492 Normally, this is any aggregate type, however, due to implementation
1493 limitations ATM, we exclude array types as well. Also complex
1494 types which are not gimple registers can have subvars. */
1496 static inline bool
1497 var_can_have_subvars (tree v)
1499 /* Non decls or memory tags can never have subvars. */
1500 if (!DECL_P (v) || MTAG_P (v))
1501 return false;
1503 /* Aggregates besides arrays can have subvars. */
1504 if (AGGREGATE_TYPE_P (TREE_TYPE (v))
1505 && TREE_CODE (TREE_TYPE (v)) != ARRAY_TYPE)
1506 return true;
1508 /* Complex types variables which are not also a gimple register can
1509 have subvars. */
1510 if (TREE_CODE (TREE_TYPE (v)) == COMPLEX_TYPE
1511 && !DECL_COMPLEX_GIMPLE_REG_P (v))
1512 return true;
1514 return false;
1518 /* Return true if OFFSET and SIZE define a range that overlaps with some
1519 portion of the range of SV, a subvar. If there was an exact overlap,
1520 *EXACT will be set to true upon return. */
1522 static inline bool
1523 overlap_subvar (unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT size,
1524 subvar_t sv, bool *exact)
1526 /* There are three possible cases of overlap.
1527 1. We can have an exact overlap, like so:
1528 |offset, offset + size |
1529 |sv->offset, sv->offset + sv->size |
1531 2. We can have offset starting after sv->offset, like so:
1533 |offset, offset + size |
1534 |sv->offset, sv->offset + sv->size |
1536 3. We can have offset starting before sv->offset, like so:
1538 |offset, offset + size |
1539 |sv->offset, sv->offset + sv->size|
1542 if (exact)
1543 *exact = false;
1544 if (offset == sv->offset && size == sv->size)
1546 if (exact)
1547 *exact = true;
1548 return true;
1550 else if (offset >= sv->offset && offset < (sv->offset + sv->size))
1552 return true;
1554 else if (offset < sv->offset && (size > sv->offset - offset))
1556 return true;
1558 return false;
1562 #endif /* _TREE_FLOW_INLINE_H */