PR preprocessor/15185, PR preprocessor/20989:
[official-gcc.git] / gcc / tree-flow-inline.h
bloba2d3e62d371a3dff4939f7f2cf79782701f3f73a
1 /* Inline functions for tree-flow.h
2 Copyright (C) 2001, 2003, 2005, 2006 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 /* Return true when gimple SSA form was built.
29 gimple_in_ssa_p is queried by gimplifier in various early stages before SSA
30 infrastructure is initialized. Check for presence of the datastructures
31 at first place. */
32 static inline bool
33 gimple_in_ssa_p (struct function *fun)
35 return fun && fun->gimple_df && fun->gimple_df->in_ssa_p;
38 /* 'true' after aliases have been computed (see compute_may_aliases). */
39 static inline bool
40 gimple_aliases_computed_p (struct function *fun)
42 gcc_assert (fun && fun->gimple_df);
43 return fun->gimple_df->aliases_computed_p;
46 /* Addressable variables in the function. If bit I is set, then
47 REFERENCED_VARS (I) has had its address taken. Note that
48 CALL_CLOBBERED_VARS and ADDRESSABLE_VARS are not related. An
49 addressable variable is not necessarily call-clobbered (e.g., a
50 local addressable whose address does not escape) and not all
51 call-clobbered variables are addressable (e.g., a local static
52 variable). */
53 static inline bitmap
54 gimple_addressable_vars (struct function *fun)
56 gcc_assert (fun && fun->gimple_df);
57 return fun->gimple_df->addressable_vars;
60 /* Call clobbered variables in the function. If bit I is set, then
61 REFERENCED_VARS (I) is call-clobbered. */
62 static inline bitmap
63 gimple_call_clobbered_vars (struct function *fun)
65 gcc_assert (fun && fun->gimple_df);
66 return fun->gimple_df->call_clobbered_vars;
69 /* Array of all variables referenced in the function. */
70 static inline htab_t
71 gimple_referenced_vars (struct function *fun)
73 if (!fun->gimple_df)
74 return NULL;
75 return fun->gimple_df->referenced_vars;
78 /* Artificial variable used to model the effects of function calls. */
79 static inline tree
80 gimple_global_var (struct function *fun)
82 gcc_assert (fun && fun->gimple_df);
83 return fun->gimple_df->global_var;
86 /* Artificial variable used to model the effects of nonlocal
87 variables. */
88 static inline tree
89 gimple_nonlocal_all (struct function *fun)
91 gcc_assert (fun && fun->gimple_df);
92 return fun->gimple_df->nonlocal_all;
95 /* Hashtable of variables annotations. Used for static variables only;
96 local variables have direct pointer in the tree node. */
97 static inline htab_t
98 gimple_var_anns (struct function *fun)
100 return fun->gimple_df->var_anns;
103 /* Initialize the hashtable iterator HTI to point to hashtable TABLE */
105 static inline void *
106 first_htab_element (htab_iterator *hti, htab_t table)
108 hti->htab = table;
109 hti->slot = table->entries;
110 hti->limit = hti->slot + htab_size (table);
113 PTR x = *(hti->slot);
114 if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
115 break;
116 } while (++(hti->slot) < hti->limit);
118 if (hti->slot < hti->limit)
119 return *(hti->slot);
120 return NULL;
123 /* Return current non-empty/deleted slot of the hashtable pointed to by HTI,
124 or NULL if we have reached the end. */
126 static inline bool
127 end_htab_p (htab_iterator *hti)
129 if (hti->slot >= hti->limit)
130 return true;
131 return false;
134 /* Advance the hashtable iterator pointed to by HTI to the next element of the
135 hashtable. */
137 static inline void *
138 next_htab_element (htab_iterator *hti)
140 while (++(hti->slot) < hti->limit)
142 PTR x = *(hti->slot);
143 if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
144 return x;
146 return NULL;
149 /* Initialize ITER to point to the first referenced variable in the
150 referenced_vars hashtable, and return that variable. */
152 static inline tree
153 first_referenced_var (referenced_var_iterator *iter)
155 struct int_tree_map *itm;
156 itm = (struct int_tree_map *) first_htab_element (&iter->hti,
157 gimple_referenced_vars
158 (cfun));
159 if (!itm)
160 return NULL;
161 return itm->to;
164 /* Return true if we have hit the end of the referenced variables ITER is
165 iterating through. */
167 static inline bool
168 end_referenced_vars_p (referenced_var_iterator *iter)
170 return end_htab_p (&iter->hti);
173 /* Make ITER point to the next referenced_var in the referenced_var hashtable,
174 and return that variable. */
176 static inline tree
177 next_referenced_var (referenced_var_iterator *iter)
179 struct int_tree_map *itm;
180 itm = (struct int_tree_map *) next_htab_element (&iter->hti);
181 if (!itm)
182 return NULL;
183 return itm->to;
186 /* Fill up VEC with the variables in the referenced vars hashtable. */
188 static inline void
189 fill_referenced_var_vec (VEC (tree, heap) **vec)
191 referenced_var_iterator rvi;
192 tree var;
193 *vec = NULL;
194 FOR_EACH_REFERENCED_VAR (var, rvi)
195 VEC_safe_push (tree, heap, *vec, var);
198 /* Return the variable annotation for T, which must be a _DECL node.
199 Return NULL if the variable annotation doesn't already exist. */
200 static inline var_ann_t
201 var_ann (tree t)
203 gcc_assert (t);
204 gcc_assert (DECL_P (t));
205 gcc_assert (TREE_CODE (t) != FUNCTION_DECL);
206 if (!MTAG_P (t) && (TREE_STATIC (t) || DECL_EXTERNAL (t)))
208 struct static_var_ann_d *sann
209 = ((struct static_var_ann_d *)
210 htab_find_with_hash (gimple_var_anns (cfun), t, DECL_UID (t)));
211 if (!sann)
212 return NULL;
213 gcc_assert (sann->ann.common.type = VAR_ANN);
214 return &sann->ann;
216 gcc_assert (!t->base.ann
217 || t->base.ann->common.type == VAR_ANN);
219 return (var_ann_t) t->base.ann;
222 /* Return the variable annotation for T, which must be a _DECL node.
223 Create the variable annotation if it doesn't exist. */
224 static inline var_ann_t
225 get_var_ann (tree var)
227 var_ann_t ann = var_ann (var);
228 return (ann) ? ann : create_var_ann (var);
231 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
232 Return NULL if the function annotation doesn't already exist. */
233 static inline function_ann_t
234 function_ann (tree t)
236 gcc_assert (t);
237 gcc_assert (TREE_CODE (t) == FUNCTION_DECL);
238 gcc_assert (!t->base.ann
239 || t->base.ann->common.type == FUNCTION_ANN);
241 return (function_ann_t) t->base.ann;
244 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
245 Create the function annotation if it doesn't exist. */
246 static inline function_ann_t
247 get_function_ann (tree var)
249 function_ann_t ann = function_ann (var);
250 gcc_assert (!var->base.ann || var->base.ann->common.type == FUNCTION_ANN);
251 return (ann) ? ann : create_function_ann (var);
254 /* Return true if T has a statement annotation attached to it. */
256 static inline bool
257 has_stmt_ann (tree t)
259 #ifdef ENABLE_CHECKING
260 gcc_assert (is_gimple_stmt (t));
261 #endif
262 return t->base.ann && t->base.ann->common.type == STMT_ANN;
265 /* Return the statement annotation for T, which must be a statement
266 node. Return NULL if the statement annotation doesn't exist. */
267 static inline stmt_ann_t
268 stmt_ann (tree t)
270 #ifdef ENABLE_CHECKING
271 gcc_assert (is_gimple_stmt (t));
272 #endif
273 gcc_assert (!t->base.ann || t->base.ann->common.type == STMT_ANN);
274 return (stmt_ann_t) t->base.ann;
277 /* Return the statement annotation for T, which must be a statement
278 node. Create the statement annotation if it doesn't exist. */
279 static inline stmt_ann_t
280 get_stmt_ann (tree stmt)
282 stmt_ann_t ann = stmt_ann (stmt);
283 return (ann) ? ann : create_stmt_ann (stmt);
286 /* Return the annotation type for annotation ANN. */
287 static inline enum tree_ann_type
288 ann_type (tree_ann_t ann)
290 return ann->common.type;
293 /* Return the basic block for statement T. */
294 static inline basic_block
295 bb_for_stmt (tree t)
297 stmt_ann_t ann;
299 if (TREE_CODE (t) == PHI_NODE)
300 return PHI_BB (t);
302 ann = stmt_ann (t);
303 return ann ? ann->bb : NULL;
306 /* Return the may_aliases varray for variable VAR, or NULL if it has
307 no may aliases. */
308 static inline VEC(tree, gc) *
309 may_aliases (tree var)
311 var_ann_t ann = var_ann (var);
312 return ann ? ann->may_aliases : NULL;
315 /* Return the line number for EXPR, or return -1 if we have no line
316 number information for it. */
317 static inline int
318 get_lineno (tree expr)
320 if (expr == NULL_TREE)
321 return -1;
323 if (TREE_CODE (expr) == COMPOUND_EXPR)
324 expr = TREE_OPERAND (expr, 0);
326 if (! EXPR_HAS_LOCATION (expr))
327 return -1;
329 return EXPR_LINENO (expr);
332 /* Return the file name for EXPR, or return "???" if we have no
333 filename information. */
334 static inline const char *
335 get_filename (tree expr)
337 const char *filename;
338 if (expr == NULL_TREE)
339 return "???";
341 if (TREE_CODE (expr) == COMPOUND_EXPR)
342 expr = TREE_OPERAND (expr, 0);
344 if (EXPR_HAS_LOCATION (expr) && (filename = EXPR_FILENAME (expr)))
345 return filename;
346 else
347 return "???";
350 /* Return true if T is a noreturn call. */
351 static inline bool
352 noreturn_call_p (tree t)
354 tree call = get_call_expr_in (t);
355 return call != 0 && (call_expr_flags (call) & ECF_NORETURN) != 0;
358 /* Mark statement T as modified. */
359 static inline void
360 mark_stmt_modified (tree t)
362 stmt_ann_t ann;
363 if (TREE_CODE (t) == PHI_NODE)
364 return;
366 ann = stmt_ann (t);
367 if (ann == NULL)
368 ann = create_stmt_ann (t);
369 else if (noreturn_call_p (t) && cfun->gimple_df)
370 VEC_safe_push (tree, gc, MODIFIED_NORETURN_CALLS (cfun), t);
371 ann->modified = 1;
374 /* Mark statement T as modified, and update it. */
375 static inline void
376 update_stmt (tree t)
378 if (TREE_CODE (t) == PHI_NODE)
379 return;
380 mark_stmt_modified (t);
381 update_stmt_operands (t);
384 static inline void
385 update_stmt_if_modified (tree t)
387 if (stmt_modified_p (t))
388 update_stmt_operands (t);
391 /* Return true if T is marked as modified, false otherwise. */
392 static inline bool
393 stmt_modified_p (tree t)
395 stmt_ann_t ann = stmt_ann (t);
397 /* Note that if the statement doesn't yet have an annotation, we consider it
398 modified. This will force the next call to update_stmt_operands to scan
399 the statement. */
400 return ann ? ann->modified : true;
403 /* Delink an immediate_uses node from its chain. */
404 static inline void
405 delink_imm_use (ssa_use_operand_t *linknode)
407 /* Return if this node is not in a list. */
408 if (linknode->prev == NULL)
409 return;
411 linknode->prev->next = linknode->next;
412 linknode->next->prev = linknode->prev;
413 linknode->prev = NULL;
414 linknode->next = NULL;
417 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
418 static inline void
419 link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
421 /* Link the new node at the head of the list. If we are in the process of
422 traversing the list, we won't visit any new nodes added to it. */
423 linknode->prev = list;
424 linknode->next = list->next;
425 list->next->prev = linknode;
426 list->next = linknode;
429 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
430 static inline void
431 link_imm_use (ssa_use_operand_t *linknode, tree def)
433 ssa_use_operand_t *root;
435 if (!def || TREE_CODE (def) != SSA_NAME)
436 linknode->prev = NULL;
437 else
439 root = &(SSA_NAME_IMM_USE_NODE (def));
440 #ifdef ENABLE_CHECKING
441 if (linknode->use)
442 gcc_assert (*(linknode->use) == def);
443 #endif
444 link_imm_use_to_list (linknode, root);
448 /* Set the value of a use pointed to by USE to VAL. */
449 static inline void
450 set_ssa_use_from_ptr (use_operand_p use, tree val)
452 delink_imm_use (use);
453 *(use->use) = val;
454 link_imm_use (use, val);
457 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
458 in STMT. */
459 static inline void
460 link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, tree stmt)
462 if (stmt)
463 link_imm_use (linknode, def);
464 else
465 link_imm_use (linknode, NULL);
466 linknode->stmt = stmt;
469 /* Relink a new node in place of an old node in the list. */
470 static inline void
471 relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
473 /* The node one had better be in the same list. */
474 gcc_assert (*(old->use) == *(node->use));
475 node->prev = old->prev;
476 node->next = old->next;
477 if (old->prev)
479 old->prev->next = node;
480 old->next->prev = node;
481 /* Remove the old node from the list. */
482 old->prev = NULL;
486 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
487 in STMT. */
488 static inline void
489 relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old, tree stmt)
491 if (stmt)
492 relink_imm_use (linknode, old);
493 else
494 link_imm_use (linknode, NULL);
495 linknode->stmt = stmt;
499 /* Return true is IMM has reached the end of the immediate use list. */
500 static inline bool
501 end_readonly_imm_use_p (imm_use_iterator *imm)
503 return (imm->imm_use == imm->end_p);
506 /* Initialize iterator IMM to process the list for VAR. */
507 static inline use_operand_p
508 first_readonly_imm_use (imm_use_iterator *imm, tree var)
510 gcc_assert (TREE_CODE (var) == SSA_NAME);
512 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
513 imm->imm_use = imm->end_p->next;
514 #ifdef ENABLE_CHECKING
515 imm->iter_node.next = imm->imm_use->next;
516 #endif
517 if (end_readonly_imm_use_p (imm))
518 return NULL_USE_OPERAND_P;
519 return imm->imm_use;
522 /* Bump IMM to the next use in the list. */
523 static inline use_operand_p
524 next_readonly_imm_use (imm_use_iterator *imm)
526 use_operand_p old = imm->imm_use;
528 #ifdef ENABLE_CHECKING
529 /* If this assertion fails, it indicates the 'next' pointer has changed
530 since we the last bump. This indicates that the list is being modified
531 via stmt changes, or SET_USE, or somesuch thing, and you need to be
532 using the SAFE version of the iterator. */
533 gcc_assert (imm->iter_node.next == old->next);
534 imm->iter_node.next = old->next->next;
535 #endif
537 imm->imm_use = old->next;
538 if (end_readonly_imm_use_p (imm))
539 return old;
540 return imm->imm_use;
543 /* Return true if VAR has no uses. */
544 static inline bool
545 has_zero_uses (tree var)
547 ssa_use_operand_t *ptr;
548 ptr = &(SSA_NAME_IMM_USE_NODE (var));
549 /* A single use means there is no items in the list. */
550 return (ptr == ptr->next);
553 /* Return true if VAR has a single use. */
554 static inline bool
555 has_single_use (tree var)
557 ssa_use_operand_t *ptr;
558 ptr = &(SSA_NAME_IMM_USE_NODE (var));
559 /* A single use means there is one item in the list. */
560 return (ptr != ptr->next && ptr == ptr->next->next);
564 /* If VAR has only a single immediate use, return true. */
565 static inline bool
566 single_imm_use_p (tree var)
568 ssa_use_operand_t *ptr;
570 ptr = &(SSA_NAME_IMM_USE_NODE (var));
571 return (ptr != ptr->next && ptr == ptr->next->next);
575 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
576 to the use pointer and stmt of occurrence. */
577 static inline bool
578 single_imm_use (tree var, use_operand_p *use_p, tree *stmt)
580 ssa_use_operand_t *ptr;
582 ptr = &(SSA_NAME_IMM_USE_NODE (var));
583 if (ptr != ptr->next && ptr == ptr->next->next)
585 *use_p = ptr->next;
586 *stmt = ptr->next->stmt;
587 return true;
589 *use_p = NULL_USE_OPERAND_P;
590 *stmt = NULL_TREE;
591 return false;
594 /* Return the number of immediate uses of VAR. */
595 static inline unsigned int
596 num_imm_uses (tree var)
598 ssa_use_operand_t *ptr, *start;
599 unsigned int num;
601 start = &(SSA_NAME_IMM_USE_NODE (var));
602 num = 0;
603 for (ptr = start->next; ptr != start; ptr = ptr->next)
604 num++;
606 return num;
609 /* Return true if VAR has no immediate uses. */
610 static inline bool
611 zero_imm_uses_p (tree var)
613 ssa_use_operand_t *ptr = &(SSA_NAME_IMM_USE_NODE (var));
614 return (ptr == ptr->next);
617 /* Return the tree pointer to by USE. */
618 static inline tree
619 get_use_from_ptr (use_operand_p use)
621 return *(use->use);
624 /* Return the tree pointer to by DEF. */
625 static inline tree
626 get_def_from_ptr (def_operand_p def)
628 return *def;
631 /* Return a def_operand_p pointer for the result of PHI. */
632 static inline def_operand_p
633 get_phi_result_ptr (tree phi)
635 return &(PHI_RESULT_TREE (phi));
638 /* Return a use_operand_p pointer for argument I of phinode PHI. */
639 static inline use_operand_p
640 get_phi_arg_def_ptr (tree phi, int i)
642 return &(PHI_ARG_IMM_USE_NODE (phi,i));
646 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
647 no addresses. */
648 static inline bitmap
649 addresses_taken (tree stmt)
651 stmt_ann_t ann = stmt_ann (stmt);
652 return ann ? ann->addresses_taken : NULL;
655 /* Return the PHI nodes for basic block BB, or NULL if there are no
656 PHI nodes. */
657 static inline tree
658 phi_nodes (basic_block bb)
660 return bb->phi_nodes;
663 /* Set list of phi nodes of a basic block BB to L. */
665 static inline void
666 set_phi_nodes (basic_block bb, tree l)
668 tree phi;
670 bb->phi_nodes = l;
671 for (phi = l; phi; phi = PHI_CHAIN (phi))
672 set_bb_for_stmt (phi, bb);
675 /* Return the phi argument which contains the specified use. */
677 static inline int
678 phi_arg_index_from_use (use_operand_p use)
680 struct phi_arg_d *element, *root;
681 int index;
682 tree phi;
684 /* Since the use is the first thing in a PHI argument element, we can
685 calculate its index based on casting it to an argument, and performing
686 pointer arithmetic. */
688 phi = USE_STMT (use);
689 gcc_assert (TREE_CODE (phi) == PHI_NODE);
691 element = (struct phi_arg_d *)use;
692 root = &(PHI_ARG_ELT (phi, 0));
693 index = element - root;
695 #ifdef ENABLE_CHECKING
696 /* Make sure the calculation doesn't have any leftover bytes. If it does,
697 then imm_use is likely not the first element in phi_arg_d. */
698 gcc_assert (
699 (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
700 gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
701 #endif
703 return index;
706 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
708 static inline void
709 set_is_used (tree var)
711 var_ann_t ann = get_var_ann (var);
712 ann->used = 1;
715 /* Return true if T is an executable statement. */
716 static inline bool
717 is_exec_stmt (tree t)
719 return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
723 /* Return true if this stmt can be the target of a control transfer stmt such
724 as a goto. */
725 static inline bool
726 is_label_stmt (tree t)
728 if (t)
729 switch (TREE_CODE (t))
731 case LABEL_DECL:
732 case LABEL_EXPR:
733 case CASE_LABEL_EXPR:
734 return true;
735 default:
736 return false;
738 return false;
741 /* PHI nodes should contain only ssa_names and invariants. A test
742 for ssa_name is definitely simpler; don't let invalid contents
743 slip in in the meantime. */
745 static inline bool
746 phi_ssa_name_p (tree t)
748 if (TREE_CODE (t) == SSA_NAME)
749 return true;
750 #ifdef ENABLE_CHECKING
751 gcc_assert (is_gimple_min_invariant (t));
752 #endif
753 return false;
756 /* ----------------------------------------------------------------------- */
758 /* Return a block_stmt_iterator that points to beginning of basic
759 block BB. */
760 static inline block_stmt_iterator
761 bsi_start (basic_block bb)
763 block_stmt_iterator bsi;
764 if (bb->stmt_list)
765 bsi.tsi = tsi_start (bb->stmt_list);
766 else
768 gcc_assert (bb->index < NUM_FIXED_BLOCKS);
769 bsi.tsi.ptr = NULL;
770 bsi.tsi.container = NULL;
772 bsi.bb = bb;
773 return bsi;
776 /* Return a block statement iterator that points to the first non-label
777 statement in block BB. */
779 static inline block_stmt_iterator
780 bsi_after_labels (basic_block bb)
782 block_stmt_iterator bsi = bsi_start (bb);
784 while (!bsi_end_p (bsi) && TREE_CODE (bsi_stmt (bsi)) == LABEL_EXPR)
785 bsi_next (&bsi);
787 return bsi;
790 /* Return a block statement iterator that points to the end of basic
791 block BB. */
792 static inline block_stmt_iterator
793 bsi_last (basic_block bb)
795 block_stmt_iterator bsi;
796 if (bb->stmt_list)
797 bsi.tsi = tsi_last (bb->stmt_list);
798 else
800 gcc_assert (bb->index < NUM_FIXED_BLOCKS);
801 bsi.tsi.ptr = NULL;
802 bsi.tsi.container = NULL;
804 bsi.bb = bb;
805 return bsi;
808 /* Return true if block statement iterator I has reached the end of
809 the basic block. */
810 static inline bool
811 bsi_end_p (block_stmt_iterator i)
813 return tsi_end_p (i.tsi);
816 /* Modify block statement iterator I so that it is at the next
817 statement in the basic block. */
818 static inline void
819 bsi_next (block_stmt_iterator *i)
821 tsi_next (&i->tsi);
824 /* Modify block statement iterator I so that it is at the previous
825 statement in the basic block. */
826 static inline void
827 bsi_prev (block_stmt_iterator *i)
829 tsi_prev (&i->tsi);
832 /* Return the statement that block statement iterator I is currently
833 at. */
834 static inline tree
835 bsi_stmt (block_stmt_iterator i)
837 return tsi_stmt (i.tsi);
840 /* Return a pointer to the statement that block statement iterator I
841 is currently at. */
842 static inline tree *
843 bsi_stmt_ptr (block_stmt_iterator i)
845 return tsi_stmt_ptr (i.tsi);
848 /* Returns the loop of the statement STMT. */
850 static inline struct loop *
851 loop_containing_stmt (tree stmt)
853 basic_block bb = bb_for_stmt (stmt);
854 if (!bb)
855 return NULL;
857 return bb->loop_father;
861 /* Return the memory partition tag associated with symbol SYM. */
863 static inline tree
864 memory_partition (tree sym)
866 tree tag;
868 /* MPTs belong to their own partition. */
869 if (TREE_CODE (sym) == MEMORY_PARTITION_TAG)
870 return sym;
872 gcc_assert (!is_gimple_reg (sym));
873 tag = get_var_ann (sym)->mpt;
875 #if defined ENABLE_CHECKING
876 if (tag)
877 gcc_assert (TREE_CODE (tag) == MEMORY_PARTITION_TAG);
878 #endif
880 return tag;
884 /* Set MPT to be the memory partition associated with symbol SYM. */
886 static inline void
887 set_memory_partition (tree sym, tree mpt)
889 #if defined ENABLE_CHECKING
890 if (mpt)
891 gcc_assert (TREE_CODE (mpt) == MEMORY_PARTITION_TAG
892 && !is_gimple_reg (sym));
893 #endif
894 var_ann (sym)->mpt = mpt;
895 if (mpt)
897 bitmap_set_bit (MPT_SYMBOLS (mpt), DECL_UID (sym));
899 /* MPT inherits the call-clobbering attributes from SYM. */
900 if (is_call_clobbered (sym))
902 MTAG_GLOBAL (mpt) = 1;
903 mark_call_clobbered (mpt, ESCAPE_IS_GLOBAL);
908 /* Return true if NAME is a memory factoring SSA name (i.e., an SSA
909 name for a memory partition. */
911 static inline bool
912 factoring_name_p (tree name)
914 return TREE_CODE (SSA_NAME_VAR (name)) == MEMORY_PARTITION_TAG;
917 /* Return true if VAR is a clobbered by function calls. */
918 static inline bool
919 is_call_clobbered (tree var)
921 if (!MTAG_P (var))
922 return var_ann (var)->call_clobbered;
923 else
924 return bitmap_bit_p (gimple_call_clobbered_vars (cfun), DECL_UID (var));
927 /* Mark variable VAR as being clobbered by function calls. */
928 static inline void
929 mark_call_clobbered (tree var, unsigned int escape_type)
931 var_ann (var)->escape_mask |= escape_type;
932 if (!MTAG_P (var))
933 var_ann (var)->call_clobbered = true;
934 bitmap_set_bit (gimple_call_clobbered_vars (cfun), DECL_UID (var));
937 /* Clear the call-clobbered attribute from variable VAR. */
938 static inline void
939 clear_call_clobbered (tree var)
941 var_ann_t ann = var_ann (var);
942 ann->escape_mask = 0;
943 if (MTAG_P (var) && TREE_CODE (var) != STRUCT_FIELD_TAG)
944 MTAG_GLOBAL (var) = 0;
945 if (!MTAG_P (var))
946 var_ann (var)->call_clobbered = false;
947 bitmap_clear_bit (gimple_call_clobbered_vars (cfun), DECL_UID (var));
950 /* Return the common annotation for T. Return NULL if the annotation
951 doesn't already exist. */
952 static inline tree_ann_common_t
953 tree_common_ann (tree t)
955 /* Watch out static variables with unshared annotations. */
956 if (DECL_P (t) && TREE_CODE (t) == VAR_DECL)
957 return &var_ann (t)->common;
958 return &t->base.ann->common;
961 /* Return a common annotation for T. Create the constant annotation if it
962 doesn't exist. */
963 static inline tree_ann_common_t
964 get_tree_common_ann (tree t)
966 tree_ann_common_t ann = tree_common_ann (t);
967 return (ann) ? ann : create_tree_common_ann (t);
970 /* ----------------------------------------------------------------------- */
972 /* The following set of routines are used to iterator over various type of
973 SSA operands. */
975 /* Return true if PTR is finished iterating. */
976 static inline bool
977 op_iter_done (ssa_op_iter *ptr)
979 return ptr->done;
982 /* Get the next iterator use value for PTR. */
983 static inline use_operand_p
984 op_iter_next_use (ssa_op_iter *ptr)
986 use_operand_p use_p;
987 #ifdef ENABLE_CHECKING
988 gcc_assert (ptr->iter_type == ssa_op_iter_use);
989 #endif
990 if (ptr->uses)
992 use_p = USE_OP_PTR (ptr->uses);
993 ptr->uses = ptr->uses->next;
994 return use_p;
996 if (ptr->vuses)
998 use_p = VUSE_OP_PTR (ptr->vuses, ptr->vuse_index);
999 if (++(ptr->vuse_index) >= VUSE_NUM (ptr->vuses))
1001 ptr->vuse_index = 0;
1002 ptr->vuses = ptr->vuses->next;
1004 return use_p;
1006 if (ptr->mayuses)
1008 use_p = VDEF_OP_PTR (ptr->mayuses, ptr->mayuse_index);
1009 if (++(ptr->mayuse_index) >= VDEF_NUM (ptr->mayuses))
1011 ptr->mayuse_index = 0;
1012 ptr->mayuses = ptr->mayuses->next;
1014 return use_p;
1016 if (ptr->phi_i < ptr->num_phi)
1018 return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
1020 ptr->done = true;
1021 return NULL_USE_OPERAND_P;
1024 /* Get the next iterator def value for PTR. */
1025 static inline def_operand_p
1026 op_iter_next_def (ssa_op_iter *ptr)
1028 def_operand_p def_p;
1029 #ifdef ENABLE_CHECKING
1030 gcc_assert (ptr->iter_type == ssa_op_iter_def);
1031 #endif
1032 if (ptr->defs)
1034 def_p = DEF_OP_PTR (ptr->defs);
1035 ptr->defs = ptr->defs->next;
1036 return def_p;
1038 if (ptr->vdefs)
1040 def_p = VDEF_RESULT_PTR (ptr->vdefs);
1041 ptr->vdefs = ptr->vdefs->next;
1042 return def_p;
1044 ptr->done = true;
1045 return NULL_DEF_OPERAND_P;
1048 /* Get the next iterator tree value for PTR. */
1049 static inline tree
1050 op_iter_next_tree (ssa_op_iter *ptr)
1052 tree val;
1053 #ifdef ENABLE_CHECKING
1054 gcc_assert (ptr->iter_type == ssa_op_iter_tree);
1055 #endif
1056 if (ptr->uses)
1058 val = USE_OP (ptr->uses);
1059 ptr->uses = ptr->uses->next;
1060 return val;
1062 if (ptr->vuses)
1064 val = VUSE_OP (ptr->vuses, ptr->vuse_index);
1065 if (++(ptr->vuse_index) >= VUSE_NUM (ptr->vuses))
1067 ptr->vuse_index = 0;
1068 ptr->vuses = ptr->vuses->next;
1070 return val;
1072 if (ptr->mayuses)
1074 val = VDEF_OP (ptr->mayuses, ptr->mayuse_index);
1075 if (++(ptr->mayuse_index) >= VDEF_NUM (ptr->mayuses))
1077 ptr->mayuse_index = 0;
1078 ptr->mayuses = ptr->mayuses->next;
1080 return val;
1082 if (ptr->defs)
1084 val = DEF_OP (ptr->defs);
1085 ptr->defs = ptr->defs->next;
1086 return val;
1088 if (ptr->vdefs)
1090 val = VDEF_RESULT (ptr->vdefs);
1091 ptr->vdefs = ptr->vdefs->next;
1092 return val;
1095 ptr->done = true;
1096 return NULL_TREE;
1101 /* This functions clears the iterator PTR, and marks it done. This is normally
1102 used to prevent warnings in the compile about might be uninitialized
1103 components. */
1105 static inline void
1106 clear_and_done_ssa_iter (ssa_op_iter *ptr)
1108 ptr->defs = NULL;
1109 ptr->uses = NULL;
1110 ptr->vuses = NULL;
1111 ptr->vdefs = NULL;
1112 ptr->mayuses = NULL;
1113 ptr->iter_type = ssa_op_iter_none;
1114 ptr->phi_i = 0;
1115 ptr->num_phi = 0;
1116 ptr->phi_stmt = NULL_TREE;
1117 ptr->done = true;
1118 ptr->vuse_index = 0;
1119 ptr->mayuse_index = 0;
1122 /* Initialize the iterator PTR to the virtual defs in STMT. */
1123 static inline void
1124 op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
1126 #ifdef ENABLE_CHECKING
1127 gcc_assert (stmt_ann (stmt));
1128 #endif
1130 ptr->defs = (flags & SSA_OP_DEF) ? DEF_OPS (stmt) : NULL;
1131 ptr->uses = (flags & SSA_OP_USE) ? USE_OPS (stmt) : NULL;
1132 ptr->vuses = (flags & SSA_OP_VUSE) ? VUSE_OPS (stmt) : NULL;
1133 ptr->vdefs = (flags & SSA_OP_VDEF) ? VDEF_OPS (stmt) : NULL;
1134 ptr->mayuses = (flags & SSA_OP_VMAYUSE) ? VDEF_OPS (stmt) : NULL;
1135 ptr->done = false;
1137 ptr->phi_i = 0;
1138 ptr->num_phi = 0;
1139 ptr->phi_stmt = NULL_TREE;
1140 ptr->vuse_index = 0;
1141 ptr->mayuse_index = 0;
1144 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1145 the first use. */
1146 static inline use_operand_p
1147 op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
1149 gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0);
1150 op_iter_init (ptr, stmt, flags);
1151 ptr->iter_type = ssa_op_iter_use;
1152 return op_iter_next_use (ptr);
1155 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1156 the first def. */
1157 static inline def_operand_p
1158 op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1160 gcc_assert ((flags & SSA_OP_ALL_USES) == 0);
1161 op_iter_init (ptr, stmt, flags);
1162 ptr->iter_type = ssa_op_iter_def;
1163 return op_iter_next_def (ptr);
1166 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1167 the first operand as a tree. */
1168 static inline tree
1169 op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1171 op_iter_init (ptr, stmt, flags);
1172 ptr->iter_type = ssa_op_iter_tree;
1173 return op_iter_next_tree (ptr);
1176 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1177 KILL and DEF. */
1178 static inline void
1179 op_iter_next_vdef (vuse_vec_p *use, def_operand_p *def,
1180 ssa_op_iter *ptr)
1182 #ifdef ENABLE_CHECKING
1183 gcc_assert (ptr->iter_type == ssa_op_iter_vdef);
1184 #endif
1185 if (ptr->mayuses)
1187 *def = VDEF_RESULT_PTR (ptr->mayuses);
1188 *use = VDEF_VECT (ptr->mayuses);
1189 ptr->mayuses = ptr->mayuses->next;
1190 return;
1193 *def = NULL_DEF_OPERAND_P;
1194 *use = NULL;
1195 ptr->done = true;
1196 return;
1200 static inline void
1201 op_iter_next_mustdef (use_operand_p *use, def_operand_p *def,
1202 ssa_op_iter *ptr)
1204 vuse_vec_p vp;
1205 op_iter_next_vdef (&vp, def, ptr);
1206 if (vp != NULL)
1208 gcc_assert (VUSE_VECT_NUM_ELEM (*vp) == 1);
1209 *use = VUSE_ELEMENT_PTR (*vp, 0);
1211 else
1212 *use = NULL_USE_OPERAND_P;
1215 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1216 in USE and DEF. */
1217 static inline void
1218 op_iter_init_vdef (ssa_op_iter *ptr, tree stmt, vuse_vec_p *use,
1219 def_operand_p *def)
1221 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1223 op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1224 ptr->iter_type = ssa_op_iter_vdef;
1225 op_iter_next_vdef (use, def, ptr);
1229 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1230 return NULL. */
1231 static inline tree
1232 single_ssa_tree_operand (tree stmt, int flags)
1234 tree var;
1235 ssa_op_iter iter;
1237 var = op_iter_init_tree (&iter, stmt, flags);
1238 if (op_iter_done (&iter))
1239 return NULL_TREE;
1240 op_iter_next_tree (&iter);
1241 if (op_iter_done (&iter))
1242 return var;
1243 return NULL_TREE;
1247 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1248 return NULL. */
1249 static inline use_operand_p
1250 single_ssa_use_operand (tree stmt, int flags)
1252 use_operand_p var;
1253 ssa_op_iter iter;
1255 var = op_iter_init_use (&iter, stmt, flags);
1256 if (op_iter_done (&iter))
1257 return NULL_USE_OPERAND_P;
1258 op_iter_next_use (&iter);
1259 if (op_iter_done (&iter))
1260 return var;
1261 return NULL_USE_OPERAND_P;
1266 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1267 return NULL. */
1268 static inline def_operand_p
1269 single_ssa_def_operand (tree stmt, int flags)
1271 def_operand_p var;
1272 ssa_op_iter iter;
1274 var = op_iter_init_def (&iter, stmt, flags);
1275 if (op_iter_done (&iter))
1276 return NULL_DEF_OPERAND_P;
1277 op_iter_next_def (&iter);
1278 if (op_iter_done (&iter))
1279 return var;
1280 return NULL_DEF_OPERAND_P;
1284 /* Return true if there are zero operands in STMT matching the type
1285 given in FLAGS. */
1286 static inline bool
1287 zero_ssa_operands (tree stmt, int flags)
1289 ssa_op_iter iter;
1291 op_iter_init_tree (&iter, stmt, flags);
1292 return op_iter_done (&iter);
1296 /* Return the number of operands matching FLAGS in STMT. */
1297 static inline int
1298 num_ssa_operands (tree stmt, int flags)
1300 ssa_op_iter iter;
1301 tree t;
1302 int num = 0;
1304 FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
1305 num++;
1306 return num;
1310 /* Delink all immediate_use information for STMT. */
1311 static inline void
1312 delink_stmt_imm_use (tree stmt)
1314 ssa_op_iter iter;
1315 use_operand_p use_p;
1317 if (ssa_operands_active ())
1318 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_ALL_USES)
1319 delink_imm_use (use_p);
1323 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1324 in STMT2. TRUE is returned if they are the same. STMTs can be NULL. */
1325 static inline bool
1326 compare_ssa_operands_equal (tree stmt1, tree stmt2, int flags)
1328 ssa_op_iter iter1, iter2;
1329 tree op1 = NULL_TREE;
1330 tree op2 = NULL_TREE;
1331 bool look1, look2;
1333 if (stmt1 == stmt2)
1334 return true;
1336 look1 = stmt1 && stmt_ann (stmt1);
1337 look2 = stmt2 && stmt_ann (stmt2);
1339 if (look1)
1341 op1 = op_iter_init_tree (&iter1, stmt1, flags);
1342 if (!look2)
1343 return op_iter_done (&iter1);
1345 else
1346 clear_and_done_ssa_iter (&iter1);
1348 if (look2)
1350 op2 = op_iter_init_tree (&iter2, stmt2, flags);
1351 if (!look1)
1352 return op_iter_done (&iter2);
1354 else
1355 clear_and_done_ssa_iter (&iter2);
1357 while (!op_iter_done (&iter1) && !op_iter_done (&iter2))
1359 if (op1 != op2)
1360 return false;
1361 op1 = op_iter_next_tree (&iter1);
1362 op2 = op_iter_next_tree (&iter2);
1365 return (op_iter_done (&iter1) && op_iter_done (&iter2));
1369 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1370 Otherwise return NULL_DEF_OPERAND_P. */
1371 static inline tree
1372 single_phi_def (tree stmt, int flags)
1374 tree def = PHI_RESULT (stmt);
1375 if ((flags & SSA_OP_DEF) && is_gimple_reg (def))
1376 return def;
1377 if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
1378 return def;
1379 return NULL_TREE;
1382 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
1383 be either SSA_OP_USES or SSA_OP_VIRTUAL_USES. */
1384 static inline use_operand_p
1385 op_iter_init_phiuse (ssa_op_iter *ptr, tree phi, int flags)
1387 tree phi_def = PHI_RESULT (phi);
1388 int comp;
1390 clear_and_done_ssa_iter (ptr);
1391 ptr->done = false;
1393 gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
1395 comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1397 /* If the PHI node doesn't the operand type we care about, we're done. */
1398 if ((flags & comp) == 0)
1400 ptr->done = true;
1401 return NULL_USE_OPERAND_P;
1404 ptr->phi_stmt = phi;
1405 ptr->num_phi = PHI_NUM_ARGS (phi);
1406 ptr->iter_type = ssa_op_iter_use;
1407 return op_iter_next_use (ptr);
1411 /* Start an iterator for a PHI definition. */
1413 static inline def_operand_p
1414 op_iter_init_phidef (ssa_op_iter *ptr, tree phi, int flags)
1416 tree phi_def = PHI_RESULT (phi);
1417 int comp;
1419 clear_and_done_ssa_iter (ptr);
1420 ptr->done = false;
1422 gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
1424 comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
1426 /* If the PHI node doesn't the operand type we care about, we're done. */
1427 if ((flags & comp) == 0)
1429 ptr->done = true;
1430 return NULL_USE_OPERAND_P;
1433 ptr->iter_type = ssa_op_iter_def;
1434 /* The first call to op_iter_next_def will terminate the iterator since
1435 all the fields are NULL. Simply return the result here as the first and
1436 therefore only result. */
1437 return PHI_RESULT_PTR (phi);
1440 /* Return true is IMM has reached the end of the immediate use stmt list. */
1442 static inline bool
1443 end_imm_use_stmt_p (imm_use_iterator *imm)
1445 return (imm->imm_use == imm->end_p);
1448 /* Finished the traverse of an immediate use stmt list IMM by removing the
1449 placeholder node from the list. */
1451 static inline void
1452 end_imm_use_stmt_traverse (imm_use_iterator *imm)
1454 delink_imm_use (&(imm->iter_node));
1457 /* Immediate use traversal of uses within a stmt require that all the
1458 uses on a stmt be sequentially listed. This routine is used to build up
1459 this sequential list by adding USE_P to the end of the current list
1460 currently delimited by HEAD and LAST_P. The new LAST_P value is
1461 returned. */
1463 static inline use_operand_p
1464 move_use_after_head (use_operand_p use_p, use_operand_p head,
1465 use_operand_p last_p)
1467 gcc_assert (USE_FROM_PTR (use_p) == USE_FROM_PTR (head));
1468 /* Skip head when we find it. */
1469 if (use_p != head)
1471 /* If use_p is already linked in after last_p, continue. */
1472 if (last_p->next == use_p)
1473 last_p = use_p;
1474 else
1476 /* Delink from current location, and link in at last_p. */
1477 delink_imm_use (use_p);
1478 link_imm_use_to_list (use_p, last_p);
1479 last_p = use_p;
1482 return last_p;
1486 /* This routine will relink all uses with the same stmt as HEAD into the list
1487 immediately following HEAD for iterator IMM. */
1489 static inline void
1490 link_use_stmts_after (use_operand_p head, imm_use_iterator *imm)
1492 use_operand_p use_p;
1493 use_operand_p last_p = head;
1494 tree head_stmt = USE_STMT (head);
1495 tree use = USE_FROM_PTR (head);
1496 ssa_op_iter op_iter;
1497 int flag;
1499 /* Only look at virtual or real uses, depending on the type of HEAD. */
1500 flag = (is_gimple_reg (use) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1502 if (TREE_CODE (head_stmt) == PHI_NODE)
1504 FOR_EACH_PHI_ARG (use_p, head_stmt, op_iter, flag)
1505 if (USE_FROM_PTR (use_p) == use)
1506 last_p = move_use_after_head (use_p, head, last_p);
1508 else
1510 FOR_EACH_SSA_USE_OPERAND (use_p, head_stmt, op_iter, flag)
1511 if (USE_FROM_PTR (use_p) == use)
1512 last_p = move_use_after_head (use_p, head, last_p);
1514 /* LInk iter node in after last_p. */
1515 if (imm->iter_node.prev != NULL)
1516 delink_imm_use (&imm->iter_node);
1517 link_imm_use_to_list (&(imm->iter_node), last_p);
1520 /* Initialize IMM to traverse over uses of VAR. Return the first statement. */
1521 static inline tree
1522 first_imm_use_stmt (imm_use_iterator *imm, tree var)
1524 gcc_assert (TREE_CODE (var) == SSA_NAME);
1526 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
1527 imm->imm_use = imm->end_p->next;
1528 imm->next_imm_name = NULL_USE_OPERAND_P;
1530 /* iter_node is used as a marker within the immediate use list to indicate
1531 where the end of the current stmt's uses are. Initialize it to NULL
1532 stmt and use, which indicates a marker node. */
1533 imm->iter_node.prev = NULL_USE_OPERAND_P;
1534 imm->iter_node.next = NULL_USE_OPERAND_P;
1535 imm->iter_node.stmt = NULL_TREE;
1536 imm->iter_node.use = NULL_USE_OPERAND_P;
1538 if (end_imm_use_stmt_p (imm))
1539 return NULL_TREE;
1541 link_use_stmts_after (imm->imm_use, imm);
1543 return USE_STMT (imm->imm_use);
1546 /* Bump IMM to the next stmt which has a use of var. */
1548 static inline tree
1549 next_imm_use_stmt (imm_use_iterator *imm)
1551 imm->imm_use = imm->iter_node.next;
1552 if (end_imm_use_stmt_p (imm))
1554 if (imm->iter_node.prev != NULL)
1555 delink_imm_use (&imm->iter_node);
1556 return NULL_TREE;
1559 link_use_stmts_after (imm->imm_use, imm);
1560 return USE_STMT (imm->imm_use);
1564 /* This routine will return the first use on the stmt IMM currently refers
1565 to. */
1567 static inline use_operand_p
1568 first_imm_use_on_stmt (imm_use_iterator *imm)
1570 imm->next_imm_name = imm->imm_use->next;
1571 return imm->imm_use;
1574 /* Return TRUE if the last use on the stmt IMM refers to has been visited. */
1576 static inline bool
1577 end_imm_use_on_stmt_p (imm_use_iterator *imm)
1579 return (imm->imm_use == &(imm->iter_node));
1582 /* Bump to the next use on the stmt IMM refers to, return NULL if done. */
1584 static inline use_operand_p
1585 next_imm_use_on_stmt (imm_use_iterator *imm)
1587 imm->imm_use = imm->next_imm_name;
1588 if (end_imm_use_on_stmt_p (imm))
1589 return NULL_USE_OPERAND_P;
1590 else
1592 imm->next_imm_name = imm->imm_use->next;
1593 return imm->imm_use;
1597 /* Return true if VAR cannot be modified by the program. */
1599 static inline bool
1600 unmodifiable_var_p (tree var)
1602 if (TREE_CODE (var) == SSA_NAME)
1603 var = SSA_NAME_VAR (var);
1605 if (MTAG_P (var))
1606 return TREE_READONLY (var) && (TREE_STATIC (var) || MTAG_GLOBAL (var));
1608 return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1611 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it. */
1613 static inline bool
1614 array_ref_contains_indirect_ref (tree ref)
1616 gcc_assert (TREE_CODE (ref) == ARRAY_REF);
1618 do {
1619 ref = TREE_OPERAND (ref, 0);
1620 } while (handled_component_p (ref));
1622 return TREE_CODE (ref) == INDIRECT_REF;
1625 /* Return true if REF, a handled component reference, has an ARRAY_REF
1626 somewhere in it. */
1628 static inline bool
1629 ref_contains_array_ref (tree ref)
1631 gcc_assert (handled_component_p (ref));
1633 do {
1634 if (TREE_CODE (ref) == ARRAY_REF)
1635 return true;
1636 ref = TREE_OPERAND (ref, 0);
1637 } while (handled_component_p (ref));
1639 return false;
1642 /* Given a variable VAR, lookup and return a pointer to the list of
1643 subvariables for it. */
1645 static inline subvar_t *
1646 lookup_subvars_for_var (tree var)
1648 var_ann_t ann = var_ann (var);
1649 gcc_assert (ann);
1650 return &ann->subvars;
1653 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1654 NULL, if there are no subvariables. */
1656 static inline subvar_t
1657 get_subvars_for_var (tree var)
1659 subvar_t subvars;
1661 gcc_assert (SSA_VAR_P (var));
1663 if (TREE_CODE (var) == SSA_NAME)
1664 subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
1665 else
1666 subvars = *(lookup_subvars_for_var (var));
1667 return subvars;
1670 /* Return the subvariable of VAR at offset OFFSET. */
1672 static inline tree
1673 get_subvar_at (tree var, unsigned HOST_WIDE_INT offset)
1675 subvar_t sv;
1677 for (sv = get_subvars_for_var (var); sv; sv = sv->next)
1678 if (SFT_OFFSET (sv->var) == offset)
1679 return sv->var;
1681 return NULL_TREE;
1684 /* Return true if V is a tree that we can have subvars for.
1685 Normally, this is any aggregate type. Also complex
1686 types which are not gimple registers can have subvars. */
1688 static inline bool
1689 var_can_have_subvars (tree v)
1691 /* Volatile variables should never have subvars. */
1692 if (TREE_THIS_VOLATILE (v))
1693 return false;
1695 /* Non decls or memory tags can never have subvars. */
1696 if (!DECL_P (v) || MTAG_P (v))
1697 return false;
1699 /* Aggregates can have subvars. */
1700 if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
1701 return true;
1703 /* Complex types variables which are not also a gimple register can
1704 have subvars. */
1705 if (TREE_CODE (TREE_TYPE (v)) == COMPLEX_TYPE
1706 && !DECL_GIMPLE_REG_P (v))
1707 return true;
1709 return false;
1713 /* Return true if OFFSET and SIZE define a range that overlaps with some
1714 portion of the range of SV, a subvar. If there was an exact overlap,
1715 *EXACT will be set to true upon return. */
1717 static inline bool
1718 overlap_subvar (unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT size,
1719 tree sv, bool *exact)
1721 /* There are three possible cases of overlap.
1722 1. We can have an exact overlap, like so:
1723 |offset, offset + size |
1724 |sv->offset, sv->offset + sv->size |
1726 2. We can have offset starting after sv->offset, like so:
1728 |offset, offset + size |
1729 |sv->offset, sv->offset + sv->size |
1731 3. We can have offset starting before sv->offset, like so:
1733 |offset, offset + size |
1734 |sv->offset, sv->offset + sv->size|
1737 if (exact)
1738 *exact = false;
1739 if (offset == SFT_OFFSET (sv) && size == SFT_SIZE (sv))
1741 if (exact)
1742 *exact = true;
1743 return true;
1745 else if (offset >= SFT_OFFSET (sv)
1746 && offset < (SFT_OFFSET (sv) + SFT_SIZE (sv)))
1748 return true;
1750 else if (offset < SFT_OFFSET (sv)
1751 && (size > SFT_OFFSET (sv) - offset))
1753 return true;
1755 return false;
1759 /* Return the memory tag associated with symbol SYM. */
1761 static inline tree
1762 symbol_mem_tag (tree sym)
1764 tree tag = get_var_ann (sym)->symbol_mem_tag;
1766 #if defined ENABLE_CHECKING
1767 if (tag)
1768 gcc_assert (TREE_CODE (tag) == SYMBOL_MEMORY_TAG);
1769 #endif
1771 return tag;
1775 /* Set the memory tag associated with symbol SYM. */
1777 static inline void
1778 set_symbol_mem_tag (tree sym, tree tag)
1780 #if defined ENABLE_CHECKING
1781 if (tag)
1782 gcc_assert (TREE_CODE (tag) == SYMBOL_MEMORY_TAG);
1783 #endif
1785 get_var_ann (sym)->symbol_mem_tag = tag;
1788 /* Get the value handle of EXPR. This is the only correct way to get
1789 the value handle for a "thing". If EXPR does not have a value
1790 handle associated, it returns NULL_TREE.
1791 NB: If EXPR is min_invariant, this function is *required* to return
1792 EXPR. */
1794 static inline tree
1795 get_value_handle (tree expr)
1797 if (TREE_CODE (expr) == SSA_NAME)
1798 return SSA_NAME_VALUE (expr);
1799 else if (DECL_P (expr) || TREE_CODE (expr) == TREE_LIST
1800 || TREE_CODE (expr) == CONSTRUCTOR)
1802 tree_ann_common_t ann = tree_common_ann (expr);
1803 return ((ann) ? ann->value_handle : NULL_TREE);
1805 else if (is_gimple_min_invariant (expr))
1806 return expr;
1807 else if (EXPR_P (expr))
1809 tree_ann_common_t ann = tree_common_ann (expr);
1810 return ((ann) ? ann->value_handle : NULL_TREE);
1812 else
1813 gcc_unreachable ();
1816 /* Accessor to tree-ssa-operands.c caches. */
1817 static inline struct ssa_operands *
1818 gimple_ssa_operands (struct function *fun)
1820 return &fun->gimple_df->ssa_operands;
1822 #endif /* _TREE_FLOW_INLINE_H */