* sv.po, zh_CN.po: Update.
[official-gcc.git] / gcc / tree-flow-inline.h
blob4874c77f686c3f45709dabde9f24b6b6822014d7
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 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 = first_htab_element (&iter->hti, referenced_vars);
82 if (!itm)
83 return NULL;
84 return itm->to;
87 /* Return true if we have hit the end of the referenced variables ITER is
88 iterating through. */
90 static inline bool
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. */
99 static inline tree
100 next_referenced_var (referenced_var_iterator *iter)
102 struct int_tree_map *itm;
103 itm = next_htab_element (&iter->hti);
104 if (!itm)
105 return NULL;
106 return itm->to;
109 /* Return the variable annotation for T, which must be a _DECL node.
110 Return NULL if the variable annotation doesn't already exist. */
111 static inline var_ann_t
112 var_ann (tree t)
114 gcc_assert (t);
115 gcc_assert (DECL_P (t));
116 gcc_assert (!t->common.ann || t->common.ann->common.type == VAR_ANN);
118 return (var_ann_t) t->common.ann;
121 /* Return the variable annotation for T, which must be a _DECL node.
122 Create the variable annotation if it doesn't exist. */
123 static inline var_ann_t
124 get_var_ann (tree var)
126 var_ann_t ann = var_ann (var);
127 return (ann) ? ann : create_var_ann (var);
130 /* Return the statement annotation for T, which must be a statement
131 node. Return NULL if the statement annotation doesn't exist. */
132 static inline stmt_ann_t
133 stmt_ann (tree t)
135 #ifdef ENABLE_CHECKING
136 gcc_assert (is_gimple_stmt (t));
137 #endif
138 return (stmt_ann_t) t->common.ann;
141 /* Return the statement annotation for T, which must be a statement
142 node. Create the statement annotation if it doesn't exist. */
143 static inline stmt_ann_t
144 get_stmt_ann (tree stmt)
146 stmt_ann_t ann = stmt_ann (stmt);
147 return (ann) ? ann : create_stmt_ann (stmt);
150 /* Return the annotation type for annotation ANN. */
151 static inline enum tree_ann_type
152 ann_type (tree_ann_t ann)
154 return ann->common.type;
157 /* Return the basic block for statement T. */
158 static inline basic_block
159 bb_for_stmt (tree t)
161 stmt_ann_t ann;
163 if (TREE_CODE (t) == PHI_NODE)
164 return PHI_BB (t);
166 ann = stmt_ann (t);
167 return ann ? ann->bb : NULL;
170 /* Return the may_aliases varray for variable VAR, or NULL if it has
171 no may aliases. */
172 static inline varray_type
173 may_aliases (tree var)
175 var_ann_t ann = var_ann (var);
176 return ann ? ann->may_aliases : NULL;
179 /* Return the line number for EXPR, or return -1 if we have no line
180 number information for it. */
181 static inline int
182 get_lineno (tree expr)
184 if (expr == NULL_TREE)
185 return -1;
187 if (TREE_CODE (expr) == COMPOUND_EXPR)
188 expr = TREE_OPERAND (expr, 0);
190 if (! EXPR_HAS_LOCATION (expr))
191 return -1;
193 return EXPR_LINENO (expr);
196 /* Return the file name for EXPR, or return "???" if we have no
197 filename information. */
198 static inline const char *
199 get_filename (tree expr)
201 const char *filename;
202 if (expr == NULL_TREE)
203 return "???";
205 if (TREE_CODE (expr) == COMPOUND_EXPR)
206 expr = TREE_OPERAND (expr, 0);
208 if (EXPR_HAS_LOCATION (expr) && (filename = EXPR_FILENAME (expr)))
209 return filename;
210 else
211 return "???";
214 /* Return true if T is a noreturn call. */
215 static inline bool
216 noreturn_call_p (tree t)
218 tree call = get_call_expr_in (t);
219 return call != 0 && (call_expr_flags (call) & ECF_NORETURN) != 0;
222 /* Mark statement T as modified. */
223 static inline void
224 mark_stmt_modified (tree t)
226 stmt_ann_t ann;
227 if (TREE_CODE (t) == PHI_NODE)
228 return;
230 ann = stmt_ann (t);
231 if (ann == NULL)
232 ann = create_stmt_ann (t);
233 else if (noreturn_call_p (t))
234 VEC_safe_push (tree, gc, modified_noreturn_calls, t);
235 ann->modified = 1;
238 /* Mark statement T as modified, and update it. */
239 static inline void
240 update_stmt (tree t)
242 if (TREE_CODE (t) == PHI_NODE)
243 return;
244 mark_stmt_modified (t);
245 update_stmt_operands (t);
248 static inline void
249 update_stmt_if_modified (tree t)
251 if (stmt_modified_p (t))
252 update_stmt_operands (t);
255 /* Return true if T is marked as modified, false otherwise. */
256 static inline bool
257 stmt_modified_p (tree t)
259 stmt_ann_t ann = stmt_ann (t);
261 /* Note that if the statement doesn't yet have an annotation, we consider it
262 modified. This will force the next call to update_stmt_operands to scan
263 the statement. */
264 return ann ? ann->modified : true;
267 /* Delink an immediate_uses node from its chain. */
268 static inline void
269 delink_imm_use (ssa_use_operand_t *linknode)
271 /* Return if this node is not in a list. */
272 if (linknode->prev == NULL)
273 return;
275 linknode->prev->next = linknode->next;
276 linknode->next->prev = linknode->prev;
277 linknode->prev = NULL;
278 linknode->next = NULL;
281 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
282 static inline void
283 link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
285 /* Link the new node at the head of the list. If we are in the process of
286 traversing the list, we won't visit any new nodes added to it. */
287 linknode->prev = list;
288 linknode->next = list->next;
289 list->next->prev = linknode;
290 list->next = linknode;
293 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
294 static inline void
295 link_imm_use (ssa_use_operand_t *linknode, tree def)
297 ssa_use_operand_t *root;
299 if (!def || TREE_CODE (def) != SSA_NAME)
300 linknode->prev = NULL;
301 else
303 root = &(SSA_NAME_IMM_USE_NODE (def));
304 #ifdef ENABLE_CHECKING
305 if (linknode->use)
306 gcc_assert (*(linknode->use) == def);
307 #endif
308 link_imm_use_to_list (linknode, root);
312 /* Set the value of a use pointed by USE to VAL. */
313 static inline void
314 set_ssa_use_from_ptr (use_operand_p use, tree val)
316 delink_imm_use (use);
317 *(use->use) = val;
318 link_imm_use (use, val);
321 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
322 in STMT. */
323 static inline void
324 link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, tree stmt)
326 if (stmt)
327 link_imm_use (linknode, def);
328 else
329 link_imm_use (linknode, NULL);
330 linknode->stmt = stmt;
333 /* Relink a new node in place of an old node in the list. */
334 static inline void
335 relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
337 /* The node one had better be in the same list. */
338 gcc_assert (*(old->use) == *(node->use));
339 node->prev = old->prev;
340 node->next = old->next;
341 if (old->prev)
343 old->prev->next = node;
344 old->next->prev = node;
345 /* Remove the old node from the list. */
346 old->prev = NULL;
350 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
351 in STMT. */
352 static inline void
353 relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old, tree stmt)
355 if (stmt)
356 relink_imm_use (linknode, old);
357 else
358 link_imm_use (linknode, NULL);
359 linknode->stmt = stmt;
362 /* Finished the traverse of an immediate use list IMM by removing it from
363 the list. */
364 static inline void
365 end_safe_imm_use_traverse (imm_use_iterator *imm)
367 delink_imm_use (&(imm->iter_node));
370 /* Return true if IMM is at the end of the list. */
371 static inline bool
372 end_safe_imm_use_p (imm_use_iterator *imm)
374 return (imm->imm_use == imm->end_p);
377 /* Initialize iterator IMM to process the list for VAR. */
378 static inline use_operand_p
379 first_safe_imm_use (imm_use_iterator *imm, tree var)
381 /* Set up and link the iterator node into the linked list for VAR. */
382 imm->iter_node.use = NULL;
383 imm->iter_node.stmt = NULL_TREE;
384 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
385 /* Check if there are 0 elements. */
386 if (imm->end_p->next == imm->end_p)
388 imm->imm_use = imm->end_p;
389 return NULL_USE_OPERAND_P;
392 link_imm_use (&(imm->iter_node), var);
393 imm->imm_use = imm->iter_node.next;
394 return imm->imm_use;
397 /* Bump IMM to the next use in the list. */
398 static inline use_operand_p
399 next_safe_imm_use (imm_use_iterator *imm)
401 ssa_use_operand_t *ptr;
402 use_operand_p old;
404 old = imm->imm_use;
405 /* If the next node following the iter_node is still the one referred to by
406 imm_use, then the list hasn't changed, go to the next node. */
407 if (imm->iter_node.next == imm->imm_use)
409 ptr = &(imm->iter_node);
410 /* Remove iternode from the list. */
411 delink_imm_use (ptr);
412 imm->imm_use = imm->imm_use->next;
413 if (! end_safe_imm_use_p (imm))
415 /* This isn't the end, link iternode before the next use. */
416 ptr->prev = imm->imm_use->prev;
417 ptr->next = imm->imm_use;
418 imm->imm_use->prev->next = ptr;
419 imm->imm_use->prev = ptr;
421 else
422 return old;
424 else
426 /* If the 'next' value after the iterator isn't the same as it was, then
427 a node has been deleted, so we simply proceed to the node following
428 where the iterator is in the list. */
429 imm->imm_use = imm->iter_node.next;
430 if (end_safe_imm_use_p (imm))
432 end_safe_imm_use_traverse (imm);
433 return old;
437 return imm->imm_use;
440 /* Return true is IMM has reached the end of the immediate use list. */
441 static inline bool
442 end_readonly_imm_use_p (imm_use_iterator *imm)
444 return (imm->imm_use == imm->end_p);
447 /* Initialize iterator IMM to process the list for VAR. */
448 static inline use_operand_p
449 first_readonly_imm_use (imm_use_iterator *imm, tree var)
451 gcc_assert (TREE_CODE (var) == SSA_NAME);
453 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
454 imm->imm_use = imm->end_p->next;
455 #ifdef ENABLE_CHECKING
456 imm->iter_node.next = imm->imm_use->next;
457 #endif
458 if (end_readonly_imm_use_p (imm))
459 return NULL_USE_OPERAND_P;
460 return imm->imm_use;
463 /* Bump IMM to the next use in the list. */
464 static inline use_operand_p
465 next_readonly_imm_use (imm_use_iterator *imm)
467 use_operand_p old = imm->imm_use;
469 #ifdef ENABLE_CHECKING
470 /* If this assertion fails, it indicates the 'next' pointer has changed
471 since we the last bump. This indicates that the list is being modified
472 via stmt changes, or SET_USE, or somesuch thing, and you need to be
473 using the SAFE version of the iterator. */
474 gcc_assert (imm->iter_node.next == old->next);
475 imm->iter_node.next = old->next->next;
476 #endif
478 imm->imm_use = old->next;
479 if (end_readonly_imm_use_p (imm))
480 return old;
481 return imm->imm_use;
484 /* Return true if VAR has no uses. */
485 static inline bool
486 has_zero_uses (tree var)
488 ssa_use_operand_t *ptr;
489 ptr = &(SSA_NAME_IMM_USE_NODE (var));
490 /* A single use means there is no items in the list. */
491 return (ptr == ptr->next);
494 /* Return true if VAR has a single use. */
495 static inline bool
496 has_single_use (tree var)
498 ssa_use_operand_t *ptr;
499 ptr = &(SSA_NAME_IMM_USE_NODE (var));
500 /* A single use means there is one item in the list. */
501 return (ptr != ptr->next && ptr == ptr->next->next);
504 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
505 to the use pointer and stmt of occurrence. */
506 static inline bool
507 single_imm_use (tree var, use_operand_p *use_p, tree *stmt)
509 ssa_use_operand_t *ptr;
511 ptr = &(SSA_NAME_IMM_USE_NODE (var));
512 if (ptr != ptr->next && ptr == ptr->next->next)
514 *use_p = ptr->next;
515 *stmt = ptr->next->stmt;
516 return true;
518 *use_p = NULL_USE_OPERAND_P;
519 *stmt = NULL_TREE;
520 return false;
523 /* Return the number of immediate uses of VAR. */
524 static inline unsigned int
525 num_imm_uses (tree var)
527 ssa_use_operand_t *ptr, *start;
528 unsigned int num;
530 start = &(SSA_NAME_IMM_USE_NODE (var));
531 num = 0;
532 for (ptr = start->next; ptr != start; ptr = ptr->next)
533 num++;
535 return num;
539 /* Return the tree pointer to by USE. */
540 static inline tree
541 get_use_from_ptr (use_operand_p use)
543 return *(use->use);
546 /* Return the tree pointer to by DEF. */
547 static inline tree
548 get_def_from_ptr (def_operand_p def)
550 return *def;
553 /* Return a def_operand_p pointer for the result of PHI. */
554 static inline def_operand_p
555 get_phi_result_ptr (tree phi)
557 return &(PHI_RESULT_TREE (phi));
560 /* Return a use_operand_p pointer for argument I of phinode PHI. */
561 static inline use_operand_p
562 get_phi_arg_def_ptr (tree phi, int i)
564 return &(PHI_ARG_IMM_USE_NODE (phi,i));
568 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
569 no addresses. */
570 static inline bitmap
571 addresses_taken (tree stmt)
573 stmt_ann_t ann = stmt_ann (stmt);
574 return ann ? ann->addresses_taken : NULL;
577 /* Return the PHI nodes for basic block BB, or NULL if there are no
578 PHI nodes. */
579 static inline tree
580 phi_nodes (basic_block bb)
582 return bb->phi_nodes;
585 /* Set list of phi nodes of a basic block BB to L. */
587 static inline void
588 set_phi_nodes (basic_block bb, tree l)
590 tree phi;
592 bb->phi_nodes = l;
593 for (phi = l; phi; phi = PHI_CHAIN (phi))
594 set_bb_for_stmt (phi, bb);
597 /* Return the phi argument which contains the specified use. */
599 static inline int
600 phi_arg_index_from_use (use_operand_p use)
602 struct phi_arg_d *element, *root;
603 int index;
604 tree phi;
606 /* Since the use is the first thing in a PHI argument element, we can
607 calculate its index based on casting it to an argument, and performing
608 pointer arithmetic. */
610 phi = USE_STMT (use);
611 gcc_assert (TREE_CODE (phi) == PHI_NODE);
613 element = (struct phi_arg_d *)use;
614 root = &(PHI_ARG_ELT (phi, 0));
615 index = element - root;
617 #ifdef ENABLE_CHECKING
618 /* Make sure the calculation doesn't have any leftover bytes. If it does,
619 then imm_use is likely not the first element in phi_arg_d. */
620 gcc_assert (
621 (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
622 gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
623 #endif
625 return index;
628 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
630 static inline void
631 set_is_used (tree var)
633 var_ann_t ann = get_var_ann (var);
634 ann->used = 1;
638 /* ----------------------------------------------------------------------- */
640 /* Return true if T is an executable statement. */
641 static inline bool
642 is_exec_stmt (tree t)
644 return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
648 /* Return true if this stmt can be the target of a control transfer stmt such
649 as a goto. */
650 static inline bool
651 is_label_stmt (tree t)
653 if (t)
654 switch (TREE_CODE (t))
656 case LABEL_DECL:
657 case LABEL_EXPR:
658 case CASE_LABEL_EXPR:
659 return true;
660 default:
661 return false;
663 return false;
666 /* Set the default definition for VAR to DEF. */
667 static inline void
668 set_default_def (tree var, tree def)
670 var_ann_t ann = get_var_ann (var);
671 ann->default_def = def;
674 /* Return the default definition for variable VAR, or NULL if none
675 exists. */
676 static inline tree
677 default_def (tree var)
679 var_ann_t ann = var_ann (var);
680 return ann ? ann->default_def : NULL_TREE;
683 /* PHI nodes should contain only ssa_names and invariants. A test
684 for ssa_name is definitely simpler; don't let invalid contents
685 slip in in the meantime. */
687 static inline bool
688 phi_ssa_name_p (tree t)
690 if (TREE_CODE (t) == SSA_NAME)
691 return true;
692 #ifdef ENABLE_CHECKING
693 gcc_assert (is_gimple_min_invariant (t));
694 #endif
695 return false;
698 /* ----------------------------------------------------------------------- */
700 /* Return a block_stmt_iterator that points to beginning of basic
701 block BB. */
702 static inline block_stmt_iterator
703 bsi_start (basic_block bb)
705 block_stmt_iterator bsi;
706 if (bb->stmt_list)
707 bsi.tsi = tsi_start (bb->stmt_list);
708 else
710 gcc_assert (bb->index < 0);
711 bsi.tsi.ptr = NULL;
712 bsi.tsi.container = NULL;
714 bsi.bb = bb;
715 return bsi;
718 /* Return a block statement iterator that points to the last label in
719 block BB. */
721 static inline block_stmt_iterator
722 bsi_after_labels (basic_block bb)
724 block_stmt_iterator bsi;
725 tree_stmt_iterator next;
727 bsi.bb = bb;
729 if (!bb->stmt_list)
731 gcc_assert (bb->index < 0);
732 bsi.tsi.ptr = NULL;
733 bsi.tsi.container = NULL;
734 return bsi;
737 bsi.tsi = tsi_start (bb->stmt_list);
738 if (tsi_end_p (bsi.tsi))
739 return bsi;
741 /* Ensure that there are some labels. The rationale is that we want
742 to insert after the bsi that is returned, and these insertions should
743 be placed at the start of the basic block. This would not work if the
744 first statement was not label; rather fail here than enable the user
745 proceed in wrong way. */
746 gcc_assert (TREE_CODE (tsi_stmt (bsi.tsi)) == LABEL_EXPR);
748 next = bsi.tsi;
749 tsi_next (&next);
751 while (!tsi_end_p (next)
752 && TREE_CODE (tsi_stmt (next)) == LABEL_EXPR)
754 bsi.tsi = next;
755 tsi_next (&next);
758 return bsi;
761 /* Return a block statement iterator that points to the end of basic
762 block BB. */
763 static inline block_stmt_iterator
764 bsi_last (basic_block bb)
766 block_stmt_iterator bsi;
767 if (bb->stmt_list)
768 bsi.tsi = tsi_last (bb->stmt_list);
769 else
771 gcc_assert (bb->index < 0);
772 bsi.tsi.ptr = NULL;
773 bsi.tsi.container = NULL;
775 bsi.bb = bb;
776 return bsi;
779 /* Return true if block statement iterator I has reached the end of
780 the basic block. */
781 static inline bool
782 bsi_end_p (block_stmt_iterator i)
784 return tsi_end_p (i.tsi);
787 /* Modify block statement iterator I so that it is at the next
788 statement in the basic block. */
789 static inline void
790 bsi_next (block_stmt_iterator *i)
792 tsi_next (&i->tsi);
795 /* Modify block statement iterator I so that it is at the previous
796 statement in the basic block. */
797 static inline void
798 bsi_prev (block_stmt_iterator *i)
800 tsi_prev (&i->tsi);
803 /* Return the statement that block statement iterator I is currently
804 at. */
805 static inline tree
806 bsi_stmt (block_stmt_iterator i)
808 return tsi_stmt (i.tsi);
811 /* Return a pointer to the statement that block statement iterator I
812 is currently at. */
813 static inline tree *
814 bsi_stmt_ptr (block_stmt_iterator i)
816 return tsi_stmt_ptr (i.tsi);
819 /* Returns the loop of the statement STMT. */
821 static inline struct loop *
822 loop_containing_stmt (tree stmt)
824 basic_block bb = bb_for_stmt (stmt);
825 if (!bb)
826 return NULL;
828 return bb->loop_father;
831 /* Return true if VAR is a clobbered by function calls. */
832 static inline bool
833 is_call_clobbered (tree var)
835 return is_global_var (var)
836 || bitmap_bit_p (call_clobbered_vars, DECL_UID (var));
839 /* Mark variable VAR as being clobbered by function calls. */
840 static inline void
841 mark_call_clobbered (tree var)
843 var_ann_t ann = var_ann (var);
844 /* If VAR is a memory tag, then we need to consider it a global
845 variable. This is because the pointer that VAR represents has
846 been found to point to either an arbitrary location or to a known
847 location in global memory. */
848 if (ann->mem_tag_kind != NOT_A_TAG && ann->mem_tag_kind != STRUCT_FIELD)
849 DECL_EXTERNAL (var) = 1;
850 bitmap_set_bit (call_clobbered_vars, DECL_UID (var));
851 ssa_call_clobbered_cache_valid = false;
852 ssa_ro_call_cache_valid = false;
855 /* Clear the call-clobbered attribute from variable VAR. */
856 static inline void
857 clear_call_clobbered (tree var)
859 var_ann_t ann = var_ann (var);
860 if (ann->mem_tag_kind != NOT_A_TAG && ann->mem_tag_kind != STRUCT_FIELD)
861 DECL_EXTERNAL (var) = 0;
862 bitmap_clear_bit (call_clobbered_vars, DECL_UID (var));
863 ssa_call_clobbered_cache_valid = false;
864 ssa_ro_call_cache_valid = false;
867 /* Mark variable VAR as being non-addressable. */
868 static inline void
869 mark_non_addressable (tree var)
871 bitmap_clear_bit (call_clobbered_vars, DECL_UID (var));
872 TREE_ADDRESSABLE (var) = 0;
873 ssa_call_clobbered_cache_valid = false;
874 ssa_ro_call_cache_valid = false;
877 /* Return the common annotation for T. Return NULL if the annotation
878 doesn't already exist. */
879 static inline tree_ann_t
880 tree_ann (tree t)
882 return t->common.ann;
885 /* Return a common annotation for T. Create the constant annotation if it
886 doesn't exist. */
887 static inline tree_ann_t
888 get_tree_ann (tree t)
890 tree_ann_t ann = tree_ann (t);
891 return (ann) ? ann : create_tree_ann (t);
894 /* ----------------------------------------------------------------------- */
896 /* The following set of routines are used to iterator over various type of
897 SSA operands. */
899 /* Return true if PTR is finished iterating. */
900 static inline bool
901 op_iter_done (ssa_op_iter *ptr)
903 return ptr->done;
906 /* Get the next iterator use value for PTR. */
907 static inline use_operand_p
908 op_iter_next_use (ssa_op_iter *ptr)
910 use_operand_p use_p;
911 #ifdef ENABLE_CHECKING
912 gcc_assert (ptr->iter_type == ssa_op_iter_use);
913 #endif
914 if (ptr->uses)
916 use_p = USE_OP_PTR (ptr->uses);
917 ptr->uses = ptr->uses->next;
918 return use_p;
920 if (ptr->vuses)
922 use_p = VUSE_OP_PTR (ptr->vuses);
923 ptr->vuses = ptr->vuses->next;
924 return use_p;
926 if (ptr->mayuses)
928 use_p = MAYDEF_OP_PTR (ptr->mayuses);
929 ptr->mayuses = ptr->mayuses->next;
930 return use_p;
932 if (ptr->mustkills)
934 use_p = MUSTDEF_KILL_PTR (ptr->mustkills);
935 ptr->mustkills = ptr->mustkills->next;
936 return use_p;
938 if (ptr->phi_i < ptr->num_phi)
940 return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
942 ptr->done = true;
943 return NULL_USE_OPERAND_P;
946 /* Get the next iterator def value for PTR. */
947 static inline def_operand_p
948 op_iter_next_def (ssa_op_iter *ptr)
950 def_operand_p def_p;
951 #ifdef ENABLE_CHECKING
952 gcc_assert (ptr->iter_type == ssa_op_iter_def);
953 #endif
954 if (ptr->defs)
956 def_p = DEF_OP_PTR (ptr->defs);
957 ptr->defs = ptr->defs->next;
958 return def_p;
960 if (ptr->mustdefs)
962 def_p = MUSTDEF_RESULT_PTR (ptr->mustdefs);
963 ptr->mustdefs = ptr->mustdefs->next;
964 return def_p;
966 if (ptr->maydefs)
968 def_p = MAYDEF_RESULT_PTR (ptr->maydefs);
969 ptr->maydefs = ptr->maydefs->next;
970 return def_p;
972 ptr->done = true;
973 return NULL_DEF_OPERAND_P;
976 /* Get the next iterator tree value for PTR. */
977 static inline tree
978 op_iter_next_tree (ssa_op_iter *ptr)
980 tree val;
981 #ifdef ENABLE_CHECKING
982 gcc_assert (ptr->iter_type == ssa_op_iter_tree);
983 #endif
984 if (ptr->uses)
986 val = USE_OP (ptr->uses);
987 ptr->uses = ptr->uses->next;
988 return val;
990 if (ptr->vuses)
992 val = VUSE_OP (ptr->vuses);
993 ptr->vuses = ptr->vuses->next;
994 return val;
996 if (ptr->mayuses)
998 val = MAYDEF_OP (ptr->mayuses);
999 ptr->mayuses = ptr->mayuses->next;
1000 return val;
1002 if (ptr->mustkills)
1004 val = MUSTDEF_KILL (ptr->mustkills);
1005 ptr->mustkills = ptr->mustkills->next;
1006 return val;
1008 if (ptr->defs)
1010 val = DEF_OP (ptr->defs);
1011 ptr->defs = ptr->defs->next;
1012 return val;
1014 if (ptr->mustdefs)
1016 val = MUSTDEF_RESULT (ptr->mustdefs);
1017 ptr->mustdefs = ptr->mustdefs->next;
1018 return val;
1020 if (ptr->maydefs)
1022 val = MAYDEF_RESULT (ptr->maydefs);
1023 ptr->maydefs = ptr->maydefs->next;
1024 return val;
1027 ptr->done = true;
1028 return NULL_TREE;
1033 /* This functions clears the iterator PTR, and marks it done. This is normally
1034 used to prevent warnings in the compile about might be uninitailzied
1035 components. */
1037 static inline void
1038 clear_and_done_ssa_iter (ssa_op_iter *ptr)
1040 ptr->defs = NULL;
1041 ptr->uses = NULL;
1042 ptr->vuses = NULL;
1043 ptr->maydefs = NULL;
1044 ptr->mayuses = NULL;
1045 ptr->mustdefs = NULL;
1046 ptr->mustkills = NULL;
1047 ptr->iter_type = ssa_op_iter_none;
1048 ptr->phi_i = 0;
1049 ptr->num_phi = 0;
1050 ptr->phi_stmt = NULL_TREE;
1051 ptr->done = true;
1054 /* Initialize the iterator PTR to the virtual defs in STMT. */
1055 static inline void
1056 op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
1058 #ifdef ENABLE_CHECKING
1059 gcc_assert (stmt_ann (stmt));
1060 #endif
1062 ptr->defs = (flags & SSA_OP_DEF) ? DEF_OPS (stmt) : NULL;
1063 ptr->uses = (flags & SSA_OP_USE) ? USE_OPS (stmt) : NULL;
1064 ptr->vuses = (flags & SSA_OP_VUSE) ? VUSE_OPS (stmt) : NULL;
1065 ptr->maydefs = (flags & SSA_OP_VMAYDEF) ? MAYDEF_OPS (stmt) : NULL;
1066 ptr->mayuses = (flags & SSA_OP_VMAYUSE) ? MAYDEF_OPS (stmt) : NULL;
1067 ptr->mustdefs = (flags & SSA_OP_VMUSTDEF) ? MUSTDEF_OPS (stmt) : NULL;
1068 ptr->mustkills = (flags & SSA_OP_VMUSTKILL) ? MUSTDEF_OPS (stmt) : NULL;
1069 ptr->done = false;
1071 ptr->phi_i = 0;
1072 ptr->num_phi = 0;
1073 ptr->phi_stmt = NULL_TREE;
1076 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1077 the first use. */
1078 static inline use_operand_p
1079 op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
1081 gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0);
1082 op_iter_init (ptr, stmt, flags);
1083 ptr->iter_type = ssa_op_iter_use;
1084 return op_iter_next_use (ptr);
1087 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1088 the first def. */
1089 static inline def_operand_p
1090 op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1092 gcc_assert ((flags & (SSA_OP_ALL_USES | SSA_OP_VIRTUAL_KILLS)) == 0);
1093 op_iter_init (ptr, stmt, flags);
1094 ptr->iter_type = ssa_op_iter_def;
1095 return op_iter_next_def (ptr);
1098 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1099 the first operand as a tree. */
1100 static inline tree
1101 op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1103 op_iter_init (ptr, stmt, flags);
1104 ptr->iter_type = ssa_op_iter_tree;
1105 return op_iter_next_tree (ptr);
1108 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1109 KILL and DEF. */
1110 static inline void
1111 op_iter_next_maymustdef (use_operand_p *use, def_operand_p *def,
1112 ssa_op_iter *ptr)
1114 #ifdef ENABLE_CHECKING
1115 gcc_assert (ptr->iter_type == ssa_op_iter_maymustdef);
1116 #endif
1117 if (ptr->mayuses)
1119 *def = MAYDEF_RESULT_PTR (ptr->mayuses);
1120 *use = MAYDEF_OP_PTR (ptr->mayuses);
1121 ptr->mayuses = ptr->mayuses->next;
1122 return;
1125 if (ptr->mustkills)
1127 *def = MUSTDEF_RESULT_PTR (ptr->mustkills);
1128 *use = MUSTDEF_KILL_PTR (ptr->mustkills);
1129 ptr->mustkills = ptr->mustkills->next;
1130 return;
1133 *def = NULL_DEF_OPERAND_P;
1134 *use = NULL_USE_OPERAND_P;
1135 ptr->done = true;
1136 return;
1140 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1141 in USE and DEF. */
1142 static inline void
1143 op_iter_init_maydef (ssa_op_iter *ptr, tree stmt, use_operand_p *use,
1144 def_operand_p *def)
1146 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1148 op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1149 ptr->iter_type = ssa_op_iter_maymustdef;
1150 op_iter_next_maymustdef (use, 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_mustdef (ssa_op_iter *ptr, tree stmt, use_operand_p *kill,
1158 def_operand_p *def)
1160 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1162 op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL);
1163 ptr->iter_type = ssa_op_iter_maymustdef;
1164 op_iter_next_maymustdef (kill, def, ptr);
1167 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1168 in KILL and DEF. */
1169 static inline void
1170 op_iter_init_must_and_may_def (ssa_op_iter *ptr, tree stmt,
1171 use_operand_p *kill, def_operand_p *def)
1173 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1175 op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL|SSA_OP_VMAYUSE);
1176 ptr->iter_type = ssa_op_iter_maymustdef;
1177 op_iter_next_maymustdef (kill, def, ptr);
1181 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1182 return NULL. PTR is the iterator to use. */
1183 static inline tree
1184 single_ssa_tree_operand (tree stmt, int flags)
1186 tree var;
1187 ssa_op_iter iter;
1189 var = op_iter_init_tree (&iter, stmt, flags);
1190 if (op_iter_done (&iter))
1191 return NULL_TREE;
1192 op_iter_next_tree (&iter);
1193 if (op_iter_done (&iter))
1194 return var;
1195 return NULL_TREE;
1199 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1200 return NULL. PTR is the iterator to use. */
1201 static inline use_operand_p
1202 single_ssa_use_operand (tree stmt, int flags)
1204 use_operand_p var;
1205 ssa_op_iter iter;
1207 var = op_iter_init_use (&iter, stmt, flags);
1208 if (op_iter_done (&iter))
1209 return NULL_USE_OPERAND_P;
1210 op_iter_next_use (&iter);
1211 if (op_iter_done (&iter))
1212 return var;
1213 return NULL_USE_OPERAND_P;
1218 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1219 return NULL. PTR is the iterator to use. */
1220 static inline def_operand_p
1221 single_ssa_def_operand (tree stmt, int flags)
1223 def_operand_p var;
1224 ssa_op_iter iter;
1226 var = op_iter_init_def (&iter, stmt, flags);
1227 if (op_iter_done (&iter))
1228 return NULL_DEF_OPERAND_P;
1229 op_iter_next_def (&iter);
1230 if (op_iter_done (&iter))
1231 return var;
1232 return NULL_DEF_OPERAND_P;
1236 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1237 return NULL. PTR is the iterator to use. */
1238 static inline bool
1239 zero_ssa_operands (tree stmt, int flags)
1241 ssa_op_iter iter;
1243 op_iter_init_tree (&iter, stmt, flags);
1244 return op_iter_done (&iter);
1248 /* Return the number of operands matching FLAGS in STMT. */
1249 static inline int
1250 num_ssa_operands (tree stmt, int flags)
1252 ssa_op_iter iter;
1253 tree t;
1254 int num = 0;
1256 FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
1257 num++;
1258 return num;
1262 /* Delink all immediate_use information for STMT. */
1263 static inline void
1264 delink_stmt_imm_use (tree stmt)
1266 ssa_op_iter iter;
1267 use_operand_p use_p;
1269 if (ssa_operands_active ())
1270 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter,
1271 (SSA_OP_ALL_USES | SSA_OP_ALL_KILLS))
1272 delink_imm_use (use_p);
1276 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1277 in STMT2. TRUE is returned if they are the same. STMTs can be NULL. */
1278 static inline bool
1279 compare_ssa_operands_equal (tree stmt1, tree stmt2, int flags)
1281 ssa_op_iter iter1, iter2;
1282 tree op1 = NULL_TREE;
1283 tree op2 = NULL_TREE;
1284 bool look1, look2;
1286 if (stmt1 == stmt2)
1287 return true;
1289 look1 = stmt1 && stmt_ann (stmt1);
1290 look2 = stmt2 && stmt_ann (stmt2);
1292 if (look1)
1294 op1 = op_iter_init_tree (&iter1, stmt1, flags);
1295 if (!look2)
1296 return op_iter_done (&iter1);
1298 else
1299 clear_and_done_ssa_iter (&iter1);
1301 if (look2)
1303 op2 = op_iter_init_tree (&iter2, stmt2, flags);
1304 if (!look1)
1305 return op_iter_done (&iter2);
1307 else
1308 clear_and_done_ssa_iter (&iter2);
1310 while (!op_iter_done (&iter1) && !op_iter_done (&iter2))
1312 if (op1 != op2)
1313 return false;
1314 op1 = op_iter_next_tree (&iter1);
1315 op2 = op_iter_next_tree (&iter2);
1318 return (op_iter_done (&iter1) && op_iter_done (&iter2));
1322 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1323 Otherwise return NULL_DEF_OPERAND_P. */
1324 static inline tree
1325 single_phi_def (tree stmt, int flags)
1327 tree def = PHI_RESULT (stmt);
1328 if ((flags & SSA_OP_DEF) && is_gimple_reg (def))
1329 return def;
1330 if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
1331 return def;
1332 return NULL_TREE;
1335 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
1336 be either SSA_OP_USES or SAS_OP_VIRTUAL_USES. */
1337 static inline use_operand_p
1338 op_iter_init_phiuse (ssa_op_iter *ptr, tree phi, int flags)
1340 tree phi_def = PHI_RESULT (phi);
1341 int comp;
1343 clear_and_done_ssa_iter (ptr);
1344 ptr->done = false;
1346 gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
1348 comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1350 /* If the PHI node doesn't the operand type we care about, we're done. */
1351 if ((flags & comp) == 0)
1353 ptr->done = true;
1354 return NULL_USE_OPERAND_P;
1357 ptr->phi_stmt = phi;
1358 ptr->num_phi = PHI_NUM_ARGS (phi);
1359 ptr->iter_type = ssa_op_iter_use;
1360 return op_iter_next_use (ptr);
1364 /* Start an iterator for a PHI definition. */
1366 static inline def_operand_p
1367 op_iter_init_phidef (ssa_op_iter *ptr, tree phi, int flags)
1369 tree phi_def = PHI_RESULT (phi);
1370 int comp;
1372 clear_and_done_ssa_iter (ptr);
1373 ptr->done = false;
1375 gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
1377 comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
1379 /* If the PHI node doesn't the operand type we care about, we're done. */
1380 if ((flags & comp) == 0)
1382 ptr->done = true;
1383 return NULL_USE_OPERAND_P;
1386 ptr->iter_type = ssa_op_iter_def;
1387 /* The first call to op_iter_next_def will terminate the iterator since
1388 all the fields are NULL. Simply return the result here as the first and
1389 therefore only result. */
1390 return PHI_RESULT_PTR (phi);
1395 /* Return true if VAR cannot be modified by the program. */
1397 static inline bool
1398 unmodifiable_var_p (tree var)
1400 if (TREE_CODE (var) == SSA_NAME)
1401 var = SSA_NAME_VAR (var);
1402 return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1405 /* Return true if REF, a COMPONENT_REF, has an ARRAY_REF somewhere in it. */
1407 static inline bool
1408 ref_contains_array_ref (tree ref)
1410 while (handled_component_p (ref))
1412 if (TREE_CODE (ref) == ARRAY_REF)
1413 return true;
1414 ref = TREE_OPERAND (ref, 0);
1416 return false;
1419 /* Given a variable VAR, lookup and return a pointer to the list of
1420 subvariables for it. */
1422 static inline subvar_t *
1423 lookup_subvars_for_var (tree var)
1425 var_ann_t ann = var_ann (var);
1426 gcc_assert (ann);
1427 return &ann->subvars;
1430 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1431 NULL, if there are no subvariables. */
1433 static inline subvar_t
1434 get_subvars_for_var (tree var)
1436 subvar_t subvars;
1438 gcc_assert (SSA_VAR_P (var));
1440 if (TREE_CODE (var) == SSA_NAME)
1441 subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
1442 else
1443 subvars = *(lookup_subvars_for_var (var));
1444 return subvars;
1447 /* Return the subvariable of VAR at offset OFFSET. */
1449 static inline tree
1450 get_subvar_at (tree var, unsigned HOST_WIDE_INT offset)
1452 subvar_t sv;
1454 for (sv = get_subvars_for_var (var); sv; sv = sv->next)
1455 if (sv->offset == offset)
1456 return sv->var;
1458 return NULL_TREE;
1461 /* Return true if V is a tree that we can have subvars for.
1462 Normally, this is any aggregate type, however, due to implementation
1463 limitations ATM, we exclude array types as well. */
1465 static inline bool
1466 var_can_have_subvars (tree v)
1468 return (AGGREGATE_TYPE_P (TREE_TYPE (v)) &&
1469 TREE_CODE (TREE_TYPE (v)) != ARRAY_TYPE);
1473 /* Return true if OFFSET and SIZE define a range that overlaps with some
1474 portion of the range of SV, a subvar. If there was an exact overlap,
1475 *EXACT will be set to true upon return. */
1477 static inline bool
1478 overlap_subvar (unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT size,
1479 subvar_t sv, bool *exact)
1481 /* There are three possible cases of overlap.
1482 1. We can have an exact overlap, like so:
1483 |offset, offset + size |
1484 |sv->offset, sv->offset + sv->size |
1486 2. We can have offset starting after sv->offset, like so:
1488 |offset, offset + size |
1489 |sv->offset, sv->offset + sv->size |
1491 3. We can have offset starting before sv->offset, like so:
1493 |offset, offset + size |
1494 |sv->offset, sv->offset + sv->size|
1497 if (exact)
1498 *exact = false;
1499 if (offset == sv->offset && size == sv->size)
1501 if (exact)
1502 *exact = true;
1503 return true;
1505 else if (offset >= sv->offset && offset < (sv->offset + sv->size))
1507 return true;
1509 else if (offset < sv->offset && (offset + size > sv->offset))
1511 return true;
1513 return false;
1517 #endif /* _TREE_FLOW_INLINE_H */