2006-12-16 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
[official-gcc.git] / gcc / tree-flow-inline.h
blobe2b4f9791405cc2085c431999c5a25560aa6a149
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;
94 /* Initialize the hashtable iterator HTI to point to hashtable TABLE */
96 static inline void *
97 first_htab_element (htab_iterator *hti, htab_t table)
99 hti->htab = table;
100 hti->slot = table->entries;
101 hti->limit = hti->slot + htab_size (table);
104 PTR x = *(hti->slot);
105 if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
106 break;
107 } while (++(hti->slot) < hti->limit);
109 if (hti->slot < hti->limit)
110 return *(hti->slot);
111 return NULL;
114 /* Return current non-empty/deleted slot of the hashtable pointed to by HTI,
115 or NULL if we have reached the end. */
117 static inline bool
118 end_htab_p (htab_iterator *hti)
120 if (hti->slot >= hti->limit)
121 return true;
122 return false;
125 /* Advance the hashtable iterator pointed to by HTI to the next element of the
126 hashtable. */
128 static inline void *
129 next_htab_element (htab_iterator *hti)
131 while (++(hti->slot) < hti->limit)
133 PTR x = *(hti->slot);
134 if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
135 return x;
137 return NULL;
140 /* Initialize ITER to point to the first referenced variable in the
141 referenced_vars hashtable, and return that variable. */
143 static inline tree
144 first_referenced_var (referenced_var_iterator *iter)
146 struct int_tree_map *itm;
147 itm = (struct int_tree_map *) first_htab_element (&iter->hti,
148 gimple_referenced_vars
149 (cfun));
150 if (!itm)
151 return NULL;
152 return itm->to;
155 /* Return true if we have hit the end of the referenced variables ITER is
156 iterating through. */
158 static inline bool
159 end_referenced_vars_p (referenced_var_iterator *iter)
161 return end_htab_p (&iter->hti);
164 /* Make ITER point to the next referenced_var in the referenced_var hashtable,
165 and return that variable. */
167 static inline tree
168 next_referenced_var (referenced_var_iterator *iter)
170 struct int_tree_map *itm;
171 itm = (struct int_tree_map *) next_htab_element (&iter->hti);
172 if (!itm)
173 return NULL;
174 return itm->to;
177 /* Fill up VEC with the variables in the referenced vars hashtable. */
179 static inline void
180 fill_referenced_var_vec (VEC (tree, heap) **vec)
182 referenced_var_iterator rvi;
183 tree var;
184 *vec = NULL;
185 FOR_EACH_REFERENCED_VAR (var, rvi)
186 VEC_safe_push (tree, heap, *vec, var);
189 /* Return the variable annotation for T, which must be a _DECL node.
190 Return NULL if the variable annotation doesn't already exist. */
191 static inline var_ann_t
192 var_ann (tree t)
194 gcc_assert (t);
195 gcc_assert (DECL_P (t));
196 gcc_assert (TREE_CODE (t) != FUNCTION_DECL);
197 gcc_assert (!t->base.ann
198 || t->base.ann->common.type == VAR_ANN);
200 return (var_ann_t) t->base.ann;
203 /* Return the variable annotation for T, which must be a _DECL node.
204 Create the variable annotation if it doesn't exist. */
205 static inline var_ann_t
206 get_var_ann (tree var)
208 var_ann_t ann = var_ann (var);
209 return (ann) ? ann : create_var_ann (var);
212 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
213 Return NULL if the function annotation doesn't already exist. */
214 static inline function_ann_t
215 function_ann (tree t)
217 gcc_assert (t);
218 gcc_assert (TREE_CODE (t) == FUNCTION_DECL);
219 gcc_assert (!t->base.ann
220 || t->base.ann->common.type == FUNCTION_ANN);
222 return (function_ann_t) t->base.ann;
225 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
226 Create the function annotation if it doesn't exist. */
227 static inline function_ann_t
228 get_function_ann (tree var)
230 function_ann_t ann = function_ann (var);
231 gcc_assert (!var->base.ann || var->base.ann->common.type == FUNCTION_ANN);
232 return (ann) ? ann : create_function_ann (var);
235 /* Return true if T has a statement annotation attached to it. */
237 static inline bool
238 has_stmt_ann (tree t)
240 #ifdef ENABLE_CHECKING
241 gcc_assert (is_gimple_stmt (t));
242 #endif
243 return t->base.ann && t->base.ann->common.type == STMT_ANN;
246 /* Return the statement annotation for T, which must be a statement
247 node. Return NULL if the statement annotation doesn't exist. */
248 static inline stmt_ann_t
249 stmt_ann (tree t)
251 #ifdef ENABLE_CHECKING
252 gcc_assert (is_gimple_stmt (t));
253 #endif
254 gcc_assert (!t->base.ann || t->base.ann->common.type == STMT_ANN);
255 return (stmt_ann_t) t->base.ann;
258 /* Return the statement annotation for T, which must be a statement
259 node. Create the statement annotation if it doesn't exist. */
260 static inline stmt_ann_t
261 get_stmt_ann (tree stmt)
263 stmt_ann_t ann = stmt_ann (stmt);
264 return (ann) ? ann : create_stmt_ann (stmt);
267 /* Return the annotation type for annotation ANN. */
268 static inline enum tree_ann_type
269 ann_type (tree_ann_t ann)
271 return ann->common.type;
274 /* Return the basic block for statement T. */
275 static inline basic_block
276 bb_for_stmt (tree t)
278 stmt_ann_t ann;
280 if (TREE_CODE (t) == PHI_NODE)
281 return PHI_BB (t);
283 ann = stmt_ann (t);
284 return ann ? ann->bb : NULL;
287 /* Return the may_aliases varray for variable VAR, or NULL if it has
288 no may aliases. */
289 static inline VEC(tree, gc) *
290 may_aliases (tree var)
292 var_ann_t ann = var_ann (var);
293 return ann ? ann->may_aliases : NULL;
296 /* Return the line number for EXPR, or return -1 if we have no line
297 number information for it. */
298 static inline int
299 get_lineno (tree expr)
301 if (expr == NULL_TREE)
302 return -1;
304 if (TREE_CODE (expr) == COMPOUND_EXPR)
305 expr = TREE_OPERAND (expr, 0);
307 if (! EXPR_HAS_LOCATION (expr))
308 return -1;
310 return EXPR_LINENO (expr);
313 /* Return the file name for EXPR, or return "???" if we have no
314 filename information. */
315 static inline const char *
316 get_filename (tree expr)
318 const char *filename;
319 if (expr == NULL_TREE)
320 return "???";
322 if (TREE_CODE (expr) == COMPOUND_EXPR)
323 expr = TREE_OPERAND (expr, 0);
325 if (EXPR_HAS_LOCATION (expr) && (filename = EXPR_FILENAME (expr)))
326 return filename;
327 else
328 return "???";
331 /* Return true if T is a noreturn call. */
332 static inline bool
333 noreturn_call_p (tree t)
335 tree call = get_call_expr_in (t);
336 return call != 0 && (call_expr_flags (call) & ECF_NORETURN) != 0;
339 /* Mark statement T as modified. */
340 static inline void
341 mark_stmt_modified (tree t)
343 stmt_ann_t ann;
344 if (TREE_CODE (t) == PHI_NODE)
345 return;
347 ann = stmt_ann (t);
348 if (ann == NULL)
349 ann = create_stmt_ann (t);
350 else if (noreturn_call_p (t) && cfun->gimple_df)
351 VEC_safe_push (tree, gc, MODIFIED_NORETURN_CALLS (cfun), t);
352 ann->modified = 1;
355 /* Mark statement T as modified, and update it. */
356 static inline void
357 update_stmt (tree t)
359 if (TREE_CODE (t) == PHI_NODE)
360 return;
361 mark_stmt_modified (t);
362 update_stmt_operands (t);
365 static inline void
366 update_stmt_if_modified (tree t)
368 if (stmt_modified_p (t))
369 update_stmt_operands (t);
372 /* Return true if T is marked as modified, false otherwise. */
373 static inline bool
374 stmt_modified_p (tree t)
376 stmt_ann_t ann = stmt_ann (t);
378 /* Note that if the statement doesn't yet have an annotation, we consider it
379 modified. This will force the next call to update_stmt_operands to scan
380 the statement. */
381 return ann ? ann->modified : true;
384 /* Delink an immediate_uses node from its chain. */
385 static inline void
386 delink_imm_use (ssa_use_operand_t *linknode)
388 /* Return if this node is not in a list. */
389 if (linknode->prev == NULL)
390 return;
392 linknode->prev->next = linknode->next;
393 linknode->next->prev = linknode->prev;
394 linknode->prev = NULL;
395 linknode->next = NULL;
398 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
399 static inline void
400 link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
402 /* Link the new node at the head of the list. If we are in the process of
403 traversing the list, we won't visit any new nodes added to it. */
404 linknode->prev = list;
405 linknode->next = list->next;
406 list->next->prev = linknode;
407 list->next = linknode;
410 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
411 static inline void
412 link_imm_use (ssa_use_operand_t *linknode, tree def)
414 ssa_use_operand_t *root;
416 if (!def || TREE_CODE (def) != SSA_NAME)
417 linknode->prev = NULL;
418 else
420 root = &(SSA_NAME_IMM_USE_NODE (def));
421 #ifdef ENABLE_CHECKING
422 if (linknode->use)
423 gcc_assert (*(linknode->use) == def);
424 #endif
425 link_imm_use_to_list (linknode, root);
429 /* Set the value of a use pointed to by USE to VAL. */
430 static inline void
431 set_ssa_use_from_ptr (use_operand_p use, tree val)
433 delink_imm_use (use);
434 *(use->use) = val;
435 link_imm_use (use, val);
438 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
439 in STMT. */
440 static inline void
441 link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, tree stmt)
443 if (stmt)
444 link_imm_use (linknode, def);
445 else
446 link_imm_use (linknode, NULL);
447 linknode->stmt = stmt;
450 /* Relink a new node in place of an old node in the list. */
451 static inline void
452 relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
454 /* The node one had better be in the same list. */
455 gcc_assert (*(old->use) == *(node->use));
456 node->prev = old->prev;
457 node->next = old->next;
458 if (old->prev)
460 old->prev->next = node;
461 old->next->prev = node;
462 /* Remove the old node from the list. */
463 old->prev = NULL;
467 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
468 in STMT. */
469 static inline void
470 relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old, tree stmt)
472 if (stmt)
473 relink_imm_use (linknode, old);
474 else
475 link_imm_use (linknode, NULL);
476 linknode->stmt = stmt;
480 /* Return true is IMM has reached the end of the immediate use list. */
481 static inline bool
482 end_readonly_imm_use_p (imm_use_iterator *imm)
484 return (imm->imm_use == imm->end_p);
487 /* Initialize iterator IMM to process the list for VAR. */
488 static inline use_operand_p
489 first_readonly_imm_use (imm_use_iterator *imm, tree var)
491 gcc_assert (TREE_CODE (var) == SSA_NAME);
493 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
494 imm->imm_use = imm->end_p->next;
495 #ifdef ENABLE_CHECKING
496 imm->iter_node.next = imm->imm_use->next;
497 #endif
498 if (end_readonly_imm_use_p (imm))
499 return NULL_USE_OPERAND_P;
500 return imm->imm_use;
503 /* Bump IMM to the next use in the list. */
504 static inline use_operand_p
505 next_readonly_imm_use (imm_use_iterator *imm)
507 use_operand_p old = imm->imm_use;
509 #ifdef ENABLE_CHECKING
510 /* If this assertion fails, it indicates the 'next' pointer has changed
511 since we the last bump. This indicates that the list is being modified
512 via stmt changes, or SET_USE, or somesuch thing, and you need to be
513 using the SAFE version of the iterator. */
514 gcc_assert (imm->iter_node.next == old->next);
515 imm->iter_node.next = old->next->next;
516 #endif
518 imm->imm_use = old->next;
519 if (end_readonly_imm_use_p (imm))
520 return old;
521 return imm->imm_use;
524 /* Return true if VAR has no uses. */
525 static inline bool
526 has_zero_uses (tree var)
528 ssa_use_operand_t *ptr;
529 ptr = &(SSA_NAME_IMM_USE_NODE (var));
530 /* A single use means there is no items in the list. */
531 return (ptr == ptr->next);
534 /* Return true if VAR has a single use. */
535 static inline bool
536 has_single_use (tree var)
538 ssa_use_operand_t *ptr;
539 ptr = &(SSA_NAME_IMM_USE_NODE (var));
540 /* A single use means there is one item in the list. */
541 return (ptr != ptr->next && ptr == ptr->next->next);
545 /* If VAR has only a single immediate use, return true. */
546 static inline bool
547 single_imm_use_p (tree var)
549 ssa_use_operand_t *ptr;
551 ptr = &(SSA_NAME_IMM_USE_NODE (var));
552 return (ptr != ptr->next && ptr == ptr->next->next);
556 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
557 to the use pointer and stmt of occurrence. */
558 static inline bool
559 single_imm_use (tree var, use_operand_p *use_p, tree *stmt)
561 ssa_use_operand_t *ptr;
563 ptr = &(SSA_NAME_IMM_USE_NODE (var));
564 if (ptr != ptr->next && ptr == ptr->next->next)
566 *use_p = ptr->next;
567 *stmt = ptr->next->stmt;
568 return true;
570 *use_p = NULL_USE_OPERAND_P;
571 *stmt = NULL_TREE;
572 return false;
575 /* Return the number of immediate uses of VAR. */
576 static inline unsigned int
577 num_imm_uses (tree var)
579 ssa_use_operand_t *ptr, *start;
580 unsigned int num;
582 start = &(SSA_NAME_IMM_USE_NODE (var));
583 num = 0;
584 for (ptr = start->next; ptr != start; ptr = ptr->next)
585 num++;
587 return num;
590 /* Return true if VAR has no immediate uses. */
591 static inline bool
592 zero_imm_uses_p (tree var)
594 ssa_use_operand_t *ptr = &(SSA_NAME_IMM_USE_NODE (var));
595 return (ptr == ptr->next);
598 /* Return the tree pointer to by USE. */
599 static inline tree
600 get_use_from_ptr (use_operand_p use)
602 return *(use->use);
605 /* Return the tree pointer to by DEF. */
606 static inline tree
607 get_def_from_ptr (def_operand_p def)
609 return *def;
612 /* Return a def_operand_p pointer for the result of PHI. */
613 static inline def_operand_p
614 get_phi_result_ptr (tree phi)
616 return &(PHI_RESULT_TREE (phi));
619 /* Return a use_operand_p pointer for argument I of phinode PHI. */
620 static inline use_operand_p
621 get_phi_arg_def_ptr (tree phi, int i)
623 return &(PHI_ARG_IMM_USE_NODE (phi,i));
627 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
628 no addresses. */
629 static inline bitmap
630 addresses_taken (tree stmt)
632 stmt_ann_t ann = stmt_ann (stmt);
633 return ann ? ann->addresses_taken : NULL;
636 /* Return the PHI nodes for basic block BB, or NULL if there are no
637 PHI nodes. */
638 static inline tree
639 phi_nodes (basic_block bb)
641 return bb->phi_nodes;
644 /* Set list of phi nodes of a basic block BB to L. */
646 static inline void
647 set_phi_nodes (basic_block bb, tree l)
649 tree phi;
651 bb->phi_nodes = l;
652 for (phi = l; phi; phi = PHI_CHAIN (phi))
653 set_bb_for_stmt (phi, bb);
656 /* Return the phi argument which contains the specified use. */
658 static inline int
659 phi_arg_index_from_use (use_operand_p use)
661 struct phi_arg_d *element, *root;
662 int index;
663 tree phi;
665 /* Since the use is the first thing in a PHI argument element, we can
666 calculate its index based on casting it to an argument, and performing
667 pointer arithmetic. */
669 phi = USE_STMT (use);
670 gcc_assert (TREE_CODE (phi) == PHI_NODE);
672 element = (struct phi_arg_d *)use;
673 root = &(PHI_ARG_ELT (phi, 0));
674 index = element - root;
676 #ifdef ENABLE_CHECKING
677 /* Make sure the calculation doesn't have any leftover bytes. If it does,
678 then imm_use is likely not the first element in phi_arg_d. */
679 gcc_assert (
680 (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
681 gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
682 #endif
684 return index;
687 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
689 static inline void
690 set_is_used (tree var)
692 var_ann_t ann = get_var_ann (var);
693 ann->used = 1;
696 /* Return true if T is an executable statement. */
697 static inline bool
698 is_exec_stmt (tree t)
700 return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
704 /* Return true if this stmt can be the target of a control transfer stmt such
705 as a goto. */
706 static inline bool
707 is_label_stmt (tree t)
709 if (t)
710 switch (TREE_CODE (t))
712 case LABEL_DECL:
713 case LABEL_EXPR:
714 case CASE_LABEL_EXPR:
715 return true;
716 default:
717 return false;
719 return false;
722 /* PHI nodes should contain only ssa_names and invariants. A test
723 for ssa_name is definitely simpler; don't let invalid contents
724 slip in in the meantime. */
726 static inline bool
727 phi_ssa_name_p (tree t)
729 if (TREE_CODE (t) == SSA_NAME)
730 return true;
731 #ifdef ENABLE_CHECKING
732 gcc_assert (is_gimple_min_invariant (t));
733 #endif
734 return false;
737 /* ----------------------------------------------------------------------- */
739 /* Return a block_stmt_iterator that points to beginning of basic
740 block BB. */
741 static inline block_stmt_iterator
742 bsi_start (basic_block bb)
744 block_stmt_iterator bsi;
745 if (bb->stmt_list)
746 bsi.tsi = tsi_start (bb->stmt_list);
747 else
749 gcc_assert (bb->index < NUM_FIXED_BLOCKS);
750 bsi.tsi.ptr = NULL;
751 bsi.tsi.container = NULL;
753 bsi.bb = bb;
754 return bsi;
757 /* Return a block statement iterator that points to the first non-label
758 statement in block BB. */
760 static inline block_stmt_iterator
761 bsi_after_labels (basic_block bb)
763 block_stmt_iterator bsi = bsi_start (bb);
765 while (!bsi_end_p (bsi) && TREE_CODE (bsi_stmt (bsi)) == LABEL_EXPR)
766 bsi_next (&bsi);
768 return bsi;
771 /* Return a block statement iterator that points to the end of basic
772 block BB. */
773 static inline block_stmt_iterator
774 bsi_last (basic_block bb)
776 block_stmt_iterator bsi;
777 if (bb->stmt_list)
778 bsi.tsi = tsi_last (bb->stmt_list);
779 else
781 gcc_assert (bb->index < NUM_FIXED_BLOCKS);
782 bsi.tsi.ptr = NULL;
783 bsi.tsi.container = NULL;
785 bsi.bb = bb;
786 return bsi;
789 /* Return true if block statement iterator I has reached the end of
790 the basic block. */
791 static inline bool
792 bsi_end_p (block_stmt_iterator i)
794 return tsi_end_p (i.tsi);
797 /* Modify block statement iterator I so that it is at the next
798 statement in the basic block. */
799 static inline void
800 bsi_next (block_stmt_iterator *i)
802 tsi_next (&i->tsi);
805 /* Modify block statement iterator I so that it is at the previous
806 statement in the basic block. */
807 static inline void
808 bsi_prev (block_stmt_iterator *i)
810 tsi_prev (&i->tsi);
813 /* Return the statement that block statement iterator I is currently
814 at. */
815 static inline tree
816 bsi_stmt (block_stmt_iterator i)
818 return tsi_stmt (i.tsi);
821 /* Return a pointer to the statement that block statement iterator I
822 is currently at. */
823 static inline tree *
824 bsi_stmt_ptr (block_stmt_iterator i)
826 return tsi_stmt_ptr (i.tsi);
829 /* Returns the loop of the statement STMT. */
831 static inline struct loop *
832 loop_containing_stmt (tree stmt)
834 basic_block bb = bb_for_stmt (stmt);
835 if (!bb)
836 return NULL;
838 return bb->loop_father;
842 /* Return the memory partition tag associated with symbol SYM. */
844 static inline tree
845 memory_partition (tree sym)
847 tree tag;
849 /* MPTs belong to their own partition. */
850 if (TREE_CODE (sym) == MEMORY_PARTITION_TAG)
851 return sym;
853 gcc_assert (!is_gimple_reg (sym));
854 tag = get_var_ann (sym)->mpt;
856 #if defined ENABLE_CHECKING
857 if (tag)
858 gcc_assert (TREE_CODE (tag) == MEMORY_PARTITION_TAG);
859 #endif
861 return tag;
865 /* Set MPT to be the memory partition associated with symbol SYM. */
867 static inline void
868 set_memory_partition (tree sym, tree mpt)
870 #if defined ENABLE_CHECKING
871 if (mpt)
872 gcc_assert (TREE_CODE (mpt) == MEMORY_PARTITION_TAG
873 && !is_gimple_reg (sym));
874 #endif
875 var_ann (sym)->mpt = mpt;
876 if (mpt)
878 bitmap_set_bit (MPT_SYMBOLS (mpt), DECL_UID (sym));
880 /* MPT inherits the call-clobbering attributes from SYM. */
881 if (is_call_clobbered (sym))
883 MTAG_GLOBAL (mpt) = 1;
884 mark_call_clobbered (mpt, ESCAPE_IS_GLOBAL);
889 /* Return true if NAME is a memory factoring SSA name (i.e., an SSA
890 name for a memory partition. */
892 static inline bool
893 factoring_name_p (tree name)
895 return TREE_CODE (SSA_NAME_VAR (name)) == MEMORY_PARTITION_TAG;
898 /* Return true if VAR is a clobbered by function calls. */
899 static inline bool
900 is_call_clobbered (tree var)
902 if (!MTAG_P (var))
903 return DECL_CALL_CLOBBERED (var);
904 else
905 return bitmap_bit_p (gimple_call_clobbered_vars (cfun), DECL_UID (var));
908 /* Mark variable VAR as being clobbered by function calls. */
909 static inline void
910 mark_call_clobbered (tree var, unsigned int escape_type)
912 var_ann (var)->escape_mask |= escape_type;
913 if (!MTAG_P (var))
914 DECL_CALL_CLOBBERED (var) = true;
915 bitmap_set_bit (gimple_call_clobbered_vars (cfun), DECL_UID (var));
918 /* Clear the call-clobbered attribute from variable VAR. */
919 static inline void
920 clear_call_clobbered (tree var)
922 var_ann_t ann = var_ann (var);
923 ann->escape_mask = 0;
924 if (MTAG_P (var) && TREE_CODE (var) != STRUCT_FIELD_TAG)
925 MTAG_GLOBAL (var) = 0;
926 if (!MTAG_P (var))
927 DECL_CALL_CLOBBERED (var) = false;
928 bitmap_clear_bit (gimple_call_clobbered_vars (cfun), DECL_UID (var));
931 /* Return the common annotation for T. Return NULL if the annotation
932 doesn't already exist. */
933 static inline tree_ann_common_t
934 tree_common_ann (tree t)
936 return &t->base.ann->common;
939 /* Return a common annotation for T. Create the constant annotation if it
940 doesn't exist. */
941 static inline tree_ann_common_t
942 get_tree_common_ann (tree t)
944 tree_ann_common_t ann = tree_common_ann (t);
945 return (ann) ? ann : create_tree_common_ann (t);
948 /* ----------------------------------------------------------------------- */
950 /* The following set of routines are used to iterator over various type of
951 SSA operands. */
953 /* Return true if PTR is finished iterating. */
954 static inline bool
955 op_iter_done (ssa_op_iter *ptr)
957 return ptr->done;
960 /* Get the next iterator use value for PTR. */
961 static inline use_operand_p
962 op_iter_next_use (ssa_op_iter *ptr)
964 use_operand_p use_p;
965 #ifdef ENABLE_CHECKING
966 gcc_assert (ptr->iter_type == ssa_op_iter_use);
967 #endif
968 if (ptr->uses)
970 use_p = USE_OP_PTR (ptr->uses);
971 ptr->uses = ptr->uses->next;
972 return use_p;
974 if (ptr->vuses)
976 use_p = VUSE_OP_PTR (ptr->vuses, ptr->vuse_index);
977 if (++(ptr->vuse_index) >= VUSE_NUM (ptr->vuses))
979 ptr->vuse_index = 0;
980 ptr->vuses = ptr->vuses->next;
982 return use_p;
984 if (ptr->mayuses)
986 use_p = VDEF_OP_PTR (ptr->mayuses, ptr->mayuse_index);
987 if (++(ptr->mayuse_index) >= VDEF_NUM (ptr->mayuses))
989 ptr->mayuse_index = 0;
990 ptr->mayuses = ptr->mayuses->next;
992 return use_p;
994 if (ptr->phi_i < ptr->num_phi)
996 return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
998 ptr->done = true;
999 return NULL_USE_OPERAND_P;
1002 /* Get the next iterator def value for PTR. */
1003 static inline def_operand_p
1004 op_iter_next_def (ssa_op_iter *ptr)
1006 def_operand_p def_p;
1007 #ifdef ENABLE_CHECKING
1008 gcc_assert (ptr->iter_type == ssa_op_iter_def);
1009 #endif
1010 if (ptr->defs)
1012 def_p = DEF_OP_PTR (ptr->defs);
1013 ptr->defs = ptr->defs->next;
1014 return def_p;
1016 if (ptr->vdefs)
1018 def_p = VDEF_RESULT_PTR (ptr->vdefs);
1019 ptr->vdefs = ptr->vdefs->next;
1020 return def_p;
1022 ptr->done = true;
1023 return NULL_DEF_OPERAND_P;
1026 /* Get the next iterator tree value for PTR. */
1027 static inline tree
1028 op_iter_next_tree (ssa_op_iter *ptr)
1030 tree val;
1031 #ifdef ENABLE_CHECKING
1032 gcc_assert (ptr->iter_type == ssa_op_iter_tree);
1033 #endif
1034 if (ptr->uses)
1036 val = USE_OP (ptr->uses);
1037 ptr->uses = ptr->uses->next;
1038 return val;
1040 if (ptr->vuses)
1042 val = VUSE_OP (ptr->vuses, ptr->vuse_index);
1043 if (++(ptr->vuse_index) >= VUSE_NUM (ptr->vuses))
1045 ptr->vuse_index = 0;
1046 ptr->vuses = ptr->vuses->next;
1048 return val;
1050 if (ptr->mayuses)
1052 val = VDEF_OP (ptr->mayuses, ptr->mayuse_index);
1053 if (++(ptr->mayuse_index) >= VDEF_NUM (ptr->mayuses))
1055 ptr->mayuse_index = 0;
1056 ptr->mayuses = ptr->mayuses->next;
1058 return val;
1060 if (ptr->defs)
1062 val = DEF_OP (ptr->defs);
1063 ptr->defs = ptr->defs->next;
1064 return val;
1066 if (ptr->vdefs)
1068 val = VDEF_RESULT (ptr->vdefs);
1069 ptr->vdefs = ptr->vdefs->next;
1070 return val;
1073 ptr->done = true;
1074 return NULL_TREE;
1079 /* This functions clears the iterator PTR, and marks it done. This is normally
1080 used to prevent warnings in the compile about might be uninitialized
1081 components. */
1083 static inline void
1084 clear_and_done_ssa_iter (ssa_op_iter *ptr)
1086 ptr->defs = NULL;
1087 ptr->uses = NULL;
1088 ptr->vuses = NULL;
1089 ptr->vdefs = NULL;
1090 ptr->mayuses = NULL;
1091 ptr->iter_type = ssa_op_iter_none;
1092 ptr->phi_i = 0;
1093 ptr->num_phi = 0;
1094 ptr->phi_stmt = NULL_TREE;
1095 ptr->done = true;
1096 ptr->vuse_index = 0;
1097 ptr->mayuse_index = 0;
1100 /* Initialize the iterator PTR to the virtual defs in STMT. */
1101 static inline void
1102 op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
1104 #ifdef ENABLE_CHECKING
1105 gcc_assert (stmt_ann (stmt));
1106 #endif
1108 ptr->defs = (flags & SSA_OP_DEF) ? DEF_OPS (stmt) : NULL;
1109 ptr->uses = (flags & SSA_OP_USE) ? USE_OPS (stmt) : NULL;
1110 ptr->vuses = (flags & SSA_OP_VUSE) ? VUSE_OPS (stmt) : NULL;
1111 ptr->vdefs = (flags & SSA_OP_VDEF) ? VDEF_OPS (stmt) : NULL;
1112 ptr->mayuses = (flags & SSA_OP_VMAYUSE) ? VDEF_OPS (stmt) : NULL;
1113 ptr->done = false;
1115 ptr->phi_i = 0;
1116 ptr->num_phi = 0;
1117 ptr->phi_stmt = NULL_TREE;
1118 ptr->vuse_index = 0;
1119 ptr->mayuse_index = 0;
1122 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1123 the first use. */
1124 static inline use_operand_p
1125 op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
1127 gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0);
1128 op_iter_init (ptr, stmt, flags);
1129 ptr->iter_type = ssa_op_iter_use;
1130 return op_iter_next_use (ptr);
1133 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1134 the first def. */
1135 static inline def_operand_p
1136 op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1138 gcc_assert ((flags & SSA_OP_ALL_USES) == 0);
1139 op_iter_init (ptr, stmt, flags);
1140 ptr->iter_type = ssa_op_iter_def;
1141 return op_iter_next_def (ptr);
1144 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1145 the first operand as a tree. */
1146 static inline tree
1147 op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1149 op_iter_init (ptr, stmt, flags);
1150 ptr->iter_type = ssa_op_iter_tree;
1151 return op_iter_next_tree (ptr);
1154 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1155 KILL and DEF. */
1156 static inline void
1157 op_iter_next_vdef (vuse_vec_p *use, def_operand_p *def,
1158 ssa_op_iter *ptr)
1160 #ifdef ENABLE_CHECKING
1161 gcc_assert (ptr->iter_type == ssa_op_iter_vdef);
1162 #endif
1163 if (ptr->mayuses)
1165 *def = VDEF_RESULT_PTR (ptr->mayuses);
1166 *use = VDEF_VECT (ptr->mayuses);
1167 ptr->mayuses = ptr->mayuses->next;
1168 return;
1171 *def = NULL_DEF_OPERAND_P;
1172 *use = NULL;
1173 ptr->done = true;
1174 return;
1178 static inline void
1179 op_iter_next_mustdef (use_operand_p *use, def_operand_p *def,
1180 ssa_op_iter *ptr)
1182 vuse_vec_p vp;
1183 op_iter_next_vdef (&vp, def, ptr);
1184 if (vp != NULL)
1186 gcc_assert (VUSE_VECT_NUM_ELEM (*vp) == 1);
1187 *use = VUSE_ELEMENT_PTR (*vp, 0);
1189 else
1190 *use = NULL_USE_OPERAND_P;
1193 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1194 in USE and DEF. */
1195 static inline void
1196 op_iter_init_vdef (ssa_op_iter *ptr, tree stmt, vuse_vec_p *use,
1197 def_operand_p *def)
1199 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1201 op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1202 ptr->iter_type = ssa_op_iter_vdef;
1203 op_iter_next_vdef (use, def, ptr);
1207 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1208 return NULL. */
1209 static inline tree
1210 single_ssa_tree_operand (tree stmt, int flags)
1212 tree var;
1213 ssa_op_iter iter;
1215 var = op_iter_init_tree (&iter, stmt, flags);
1216 if (op_iter_done (&iter))
1217 return NULL_TREE;
1218 op_iter_next_tree (&iter);
1219 if (op_iter_done (&iter))
1220 return var;
1221 return NULL_TREE;
1225 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1226 return NULL. */
1227 static inline use_operand_p
1228 single_ssa_use_operand (tree stmt, int flags)
1230 use_operand_p var;
1231 ssa_op_iter iter;
1233 var = op_iter_init_use (&iter, stmt, flags);
1234 if (op_iter_done (&iter))
1235 return NULL_USE_OPERAND_P;
1236 op_iter_next_use (&iter);
1237 if (op_iter_done (&iter))
1238 return var;
1239 return NULL_USE_OPERAND_P;
1244 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1245 return NULL. */
1246 static inline def_operand_p
1247 single_ssa_def_operand (tree stmt, int flags)
1249 def_operand_p var;
1250 ssa_op_iter iter;
1252 var = op_iter_init_def (&iter, stmt, flags);
1253 if (op_iter_done (&iter))
1254 return NULL_DEF_OPERAND_P;
1255 op_iter_next_def (&iter);
1256 if (op_iter_done (&iter))
1257 return var;
1258 return NULL_DEF_OPERAND_P;
1262 /* Return true if there are zero operands in STMT matching the type
1263 given in FLAGS. */
1264 static inline bool
1265 zero_ssa_operands (tree stmt, int flags)
1267 ssa_op_iter iter;
1269 op_iter_init_tree (&iter, stmt, flags);
1270 return op_iter_done (&iter);
1274 /* Return the number of operands matching FLAGS in STMT. */
1275 static inline int
1276 num_ssa_operands (tree stmt, int flags)
1278 ssa_op_iter iter;
1279 tree t;
1280 int num = 0;
1282 FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
1283 num++;
1284 return num;
1288 /* Delink all immediate_use information for STMT. */
1289 static inline void
1290 delink_stmt_imm_use (tree stmt)
1292 ssa_op_iter iter;
1293 use_operand_p use_p;
1295 if (ssa_operands_active ())
1296 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_ALL_USES)
1297 delink_imm_use (use_p);
1301 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1302 in STMT2. TRUE is returned if they are the same. STMTs can be NULL. */
1303 static inline bool
1304 compare_ssa_operands_equal (tree stmt1, tree stmt2, int flags)
1306 ssa_op_iter iter1, iter2;
1307 tree op1 = NULL_TREE;
1308 tree op2 = NULL_TREE;
1309 bool look1, look2;
1311 if (stmt1 == stmt2)
1312 return true;
1314 look1 = stmt1 && stmt_ann (stmt1);
1315 look2 = stmt2 && stmt_ann (stmt2);
1317 if (look1)
1319 op1 = op_iter_init_tree (&iter1, stmt1, flags);
1320 if (!look2)
1321 return op_iter_done (&iter1);
1323 else
1324 clear_and_done_ssa_iter (&iter1);
1326 if (look2)
1328 op2 = op_iter_init_tree (&iter2, stmt2, flags);
1329 if (!look1)
1330 return op_iter_done (&iter2);
1332 else
1333 clear_and_done_ssa_iter (&iter2);
1335 while (!op_iter_done (&iter1) && !op_iter_done (&iter2))
1337 if (op1 != op2)
1338 return false;
1339 op1 = op_iter_next_tree (&iter1);
1340 op2 = op_iter_next_tree (&iter2);
1343 return (op_iter_done (&iter1) && op_iter_done (&iter2));
1347 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1348 Otherwise return NULL_DEF_OPERAND_P. */
1349 static inline tree
1350 single_phi_def (tree stmt, int flags)
1352 tree def = PHI_RESULT (stmt);
1353 if ((flags & SSA_OP_DEF) && is_gimple_reg (def))
1354 return def;
1355 if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
1356 return def;
1357 return NULL_TREE;
1360 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
1361 be either SSA_OP_USES or SSA_OP_VIRTUAL_USES. */
1362 static inline use_operand_p
1363 op_iter_init_phiuse (ssa_op_iter *ptr, tree phi, int flags)
1365 tree phi_def = PHI_RESULT (phi);
1366 int comp;
1368 clear_and_done_ssa_iter (ptr);
1369 ptr->done = false;
1371 gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
1373 comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1375 /* If the PHI node doesn't the operand type we care about, we're done. */
1376 if ((flags & comp) == 0)
1378 ptr->done = true;
1379 return NULL_USE_OPERAND_P;
1382 ptr->phi_stmt = phi;
1383 ptr->num_phi = PHI_NUM_ARGS (phi);
1384 ptr->iter_type = ssa_op_iter_use;
1385 return op_iter_next_use (ptr);
1389 /* Start an iterator for a PHI definition. */
1391 static inline def_operand_p
1392 op_iter_init_phidef (ssa_op_iter *ptr, tree phi, int flags)
1394 tree phi_def = PHI_RESULT (phi);
1395 int comp;
1397 clear_and_done_ssa_iter (ptr);
1398 ptr->done = false;
1400 gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
1402 comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
1404 /* If the PHI node doesn't the operand type we care about, we're done. */
1405 if ((flags & comp) == 0)
1407 ptr->done = true;
1408 return NULL_USE_OPERAND_P;
1411 ptr->iter_type = ssa_op_iter_def;
1412 /* The first call to op_iter_next_def will terminate the iterator since
1413 all the fields are NULL. Simply return the result here as the first and
1414 therefore only result. */
1415 return PHI_RESULT_PTR (phi);
1418 /* Return true is IMM has reached the end of the immediate use stmt list. */
1420 static inline bool
1421 end_imm_use_stmt_p (imm_use_iterator *imm)
1423 return (imm->imm_use == imm->end_p);
1426 /* Finished the traverse of an immediate use stmt list IMM by removing the
1427 placeholder node from the list. */
1429 static inline void
1430 end_imm_use_stmt_traverse (imm_use_iterator *imm)
1432 delink_imm_use (&(imm->iter_node));
1435 /* Immediate use traversal of uses within a stmt require that all the
1436 uses on a stmt be sequentially listed. This routine is used to build up
1437 this sequential list by adding USE_P to the end of the current list
1438 currently delimited by HEAD and LAST_P. The new LAST_P value is
1439 returned. */
1441 static inline use_operand_p
1442 move_use_after_head (use_operand_p use_p, use_operand_p head,
1443 use_operand_p last_p)
1445 gcc_assert (USE_FROM_PTR (use_p) == USE_FROM_PTR (head));
1446 /* Skip head when we find it. */
1447 if (use_p != head)
1449 /* If use_p is already linked in after last_p, continue. */
1450 if (last_p->next == use_p)
1451 last_p = use_p;
1452 else
1454 /* Delink from current location, and link in at last_p. */
1455 delink_imm_use (use_p);
1456 link_imm_use_to_list (use_p, last_p);
1457 last_p = use_p;
1460 return last_p;
1464 /* This routine will relink all uses with the same stmt as HEAD into the list
1465 immediately following HEAD for iterator IMM. */
1467 static inline void
1468 link_use_stmts_after (use_operand_p head, imm_use_iterator *imm)
1470 use_operand_p use_p;
1471 use_operand_p last_p = head;
1472 tree head_stmt = USE_STMT (head);
1473 tree use = USE_FROM_PTR (head);
1474 ssa_op_iter op_iter;
1475 int flag;
1477 /* Only look at virtual or real uses, depending on the type of HEAD. */
1478 flag = (is_gimple_reg (use) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1480 if (TREE_CODE (head_stmt) == PHI_NODE)
1482 FOR_EACH_PHI_ARG (use_p, head_stmt, op_iter, flag)
1483 if (USE_FROM_PTR (use_p) == use)
1484 last_p = move_use_after_head (use_p, head, last_p);
1486 else
1488 FOR_EACH_SSA_USE_OPERAND (use_p, head_stmt, op_iter, flag)
1489 if (USE_FROM_PTR (use_p) == use)
1490 last_p = move_use_after_head (use_p, head, last_p);
1492 /* LInk iter node in after last_p. */
1493 if (imm->iter_node.prev != NULL)
1494 delink_imm_use (&imm->iter_node);
1495 link_imm_use_to_list (&(imm->iter_node), last_p);
1498 /* Initialize IMM to traverse over uses of VAR. Return the first statement. */
1499 static inline tree
1500 first_imm_use_stmt (imm_use_iterator *imm, tree var)
1502 gcc_assert (TREE_CODE (var) == SSA_NAME);
1504 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
1505 imm->imm_use = imm->end_p->next;
1506 imm->next_imm_name = NULL_USE_OPERAND_P;
1508 /* iter_node is used as a marker within the immediate use list to indicate
1509 where the end of the current stmt's uses are. Initialize it to NULL
1510 stmt and use, which indicates a marker node. */
1511 imm->iter_node.prev = NULL_USE_OPERAND_P;
1512 imm->iter_node.next = NULL_USE_OPERAND_P;
1513 imm->iter_node.stmt = NULL_TREE;
1514 imm->iter_node.use = NULL_USE_OPERAND_P;
1516 if (end_imm_use_stmt_p (imm))
1517 return NULL_TREE;
1519 link_use_stmts_after (imm->imm_use, imm);
1521 return USE_STMT (imm->imm_use);
1524 /* Bump IMM to the next stmt which has a use of var. */
1526 static inline tree
1527 next_imm_use_stmt (imm_use_iterator *imm)
1529 imm->imm_use = imm->iter_node.next;
1530 if (end_imm_use_stmt_p (imm))
1532 if (imm->iter_node.prev != NULL)
1533 delink_imm_use (&imm->iter_node);
1534 return NULL_TREE;
1537 link_use_stmts_after (imm->imm_use, imm);
1538 return USE_STMT (imm->imm_use);
1542 /* This routine will return the first use on the stmt IMM currently refers
1543 to. */
1545 static inline use_operand_p
1546 first_imm_use_on_stmt (imm_use_iterator *imm)
1548 imm->next_imm_name = imm->imm_use->next;
1549 return imm->imm_use;
1552 /* Return TRUE if the last use on the stmt IMM refers to has been visited. */
1554 static inline bool
1555 end_imm_use_on_stmt_p (imm_use_iterator *imm)
1557 return (imm->imm_use == &(imm->iter_node));
1560 /* Bump to the next use on the stmt IMM refers to, return NULL if done. */
1562 static inline use_operand_p
1563 next_imm_use_on_stmt (imm_use_iterator *imm)
1565 imm->imm_use = imm->next_imm_name;
1566 if (end_imm_use_on_stmt_p (imm))
1567 return NULL_USE_OPERAND_P;
1568 else
1570 imm->next_imm_name = imm->imm_use->next;
1571 return imm->imm_use;
1575 /* Return true if VAR cannot be modified by the program. */
1577 static inline bool
1578 unmodifiable_var_p (tree var)
1580 if (TREE_CODE (var) == SSA_NAME)
1581 var = SSA_NAME_VAR (var);
1583 if (MTAG_P (var))
1584 return TREE_READONLY (var) && (TREE_STATIC (var) || MTAG_GLOBAL (var));
1586 return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1589 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it. */
1591 static inline bool
1592 array_ref_contains_indirect_ref (tree ref)
1594 gcc_assert (TREE_CODE (ref) == ARRAY_REF);
1596 do {
1597 ref = TREE_OPERAND (ref, 0);
1598 } while (handled_component_p (ref));
1600 return TREE_CODE (ref) == INDIRECT_REF;
1603 /* Return true if REF, a handled component reference, has an ARRAY_REF
1604 somewhere in it. */
1606 static inline bool
1607 ref_contains_array_ref (tree ref)
1609 gcc_assert (handled_component_p (ref));
1611 do {
1612 if (TREE_CODE (ref) == ARRAY_REF)
1613 return true;
1614 ref = TREE_OPERAND (ref, 0);
1615 } while (handled_component_p (ref));
1617 return false;
1620 /* Given a variable VAR, lookup and return a pointer to the list of
1621 subvariables for it. */
1623 static inline subvar_t *
1624 lookup_subvars_for_var (tree var)
1626 var_ann_t ann = var_ann (var);
1627 gcc_assert (ann);
1628 return &ann->subvars;
1631 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1632 NULL, if there are no subvariables. */
1634 static inline subvar_t
1635 get_subvars_for_var (tree var)
1637 subvar_t subvars;
1639 gcc_assert (SSA_VAR_P (var));
1641 if (TREE_CODE (var) == SSA_NAME)
1642 subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
1643 else
1644 subvars = *(lookup_subvars_for_var (var));
1645 return subvars;
1648 /* Return the subvariable of VAR at offset OFFSET. */
1650 static inline tree
1651 get_subvar_at (tree var, unsigned HOST_WIDE_INT offset)
1653 subvar_t sv;
1655 for (sv = get_subvars_for_var (var); sv; sv = sv->next)
1656 if (SFT_OFFSET (sv->var) == offset)
1657 return sv->var;
1659 return NULL_TREE;
1662 /* Return true if V is a tree that we can have subvars for.
1663 Normally, this is any aggregate type. Also complex
1664 types which are not gimple registers can have subvars. */
1666 static inline bool
1667 var_can_have_subvars (tree v)
1669 /* Volatile variables should never have subvars. */
1670 if (TREE_THIS_VOLATILE (v))
1671 return false;
1673 /* Non decls or memory tags can never have subvars. */
1674 if (!DECL_P (v) || MTAG_P (v))
1675 return false;
1677 /* Aggregates can have subvars. */
1678 if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
1679 return true;
1681 /* Complex types variables which are not also a gimple register can
1682 have subvars. */
1683 if (TREE_CODE (TREE_TYPE (v)) == COMPLEX_TYPE
1684 && !DECL_GIMPLE_REG_P (v))
1685 return true;
1687 return false;
1691 /* Return true if OFFSET and SIZE define a range that overlaps with some
1692 portion of the range of SV, a subvar. If there was an exact overlap,
1693 *EXACT will be set to true upon return. */
1695 static inline bool
1696 overlap_subvar (unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT size,
1697 tree sv, bool *exact)
1699 /* There are three possible cases of overlap.
1700 1. We can have an exact overlap, like so:
1701 |offset, offset + size |
1702 |sv->offset, sv->offset + sv->size |
1704 2. We can have offset starting after sv->offset, like so:
1706 |offset, offset + size |
1707 |sv->offset, sv->offset + sv->size |
1709 3. We can have offset starting before sv->offset, like so:
1711 |offset, offset + size |
1712 |sv->offset, sv->offset + sv->size|
1715 if (exact)
1716 *exact = false;
1717 if (offset == SFT_OFFSET (sv) && size == SFT_SIZE (sv))
1719 if (exact)
1720 *exact = true;
1721 return true;
1723 else if (offset >= SFT_OFFSET (sv)
1724 && offset < (SFT_OFFSET (sv) + SFT_SIZE (sv)))
1726 return true;
1728 else if (offset < SFT_OFFSET (sv)
1729 && (size > SFT_OFFSET (sv) - offset))
1731 return true;
1733 return false;
1737 /* Return the memory tag associated with symbol SYM. */
1739 static inline tree
1740 symbol_mem_tag (tree sym)
1742 tree tag = get_var_ann (sym)->symbol_mem_tag;
1744 #if defined ENABLE_CHECKING
1745 if (tag)
1746 gcc_assert (TREE_CODE (tag) == SYMBOL_MEMORY_TAG);
1747 #endif
1749 return tag;
1753 /* Set the memory tag associated with symbol SYM. */
1755 static inline void
1756 set_symbol_mem_tag (tree sym, tree tag)
1758 #if defined ENABLE_CHECKING
1759 if (tag)
1760 gcc_assert (TREE_CODE (tag) == SYMBOL_MEMORY_TAG);
1761 #endif
1763 get_var_ann (sym)->symbol_mem_tag = tag;
1766 /* Get the value handle of EXPR. This is the only correct way to get
1767 the value handle for a "thing". If EXPR does not have a value
1768 handle associated, it returns NULL_TREE.
1769 NB: If EXPR is min_invariant, this function is *required* to return
1770 EXPR. */
1772 static inline tree
1773 get_value_handle (tree expr)
1775 if (TREE_CODE (expr) == SSA_NAME)
1776 return SSA_NAME_VALUE (expr);
1777 else if (DECL_P (expr) || TREE_CODE (expr) == TREE_LIST
1778 || TREE_CODE (expr) == CONSTRUCTOR)
1780 tree_ann_common_t ann = tree_common_ann (expr);
1781 return ((ann) ? ann->value_handle : NULL_TREE);
1783 else if (is_gimple_min_invariant (expr))
1784 return expr;
1785 else if (EXPR_P (expr))
1787 tree_ann_common_t ann = tree_common_ann (expr);
1788 return ((ann) ? ann->value_handle : NULL_TREE);
1790 else
1791 gcc_unreachable ();
1794 /* Accessor to tree-ssa-operands.c caches. */
1795 static inline struct ssa_operands *
1796 gimple_ssa_operands (struct function *fun)
1798 return &fun->gimple_df->ssa_operands;
1800 #endif /* _TREE_FLOW_INLINE_H */