Daily bump.
[official-gcc.git] / gcc / tree-flow-inline.h
blob1074f680caad2db76caa9f78d694f273821f32bf
1 /* Inline functions for tree-flow.h
2 Copyright (C) 2001, 2003, 2005, 2006, 2007 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 3, 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 COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef _TREE_FLOW_INLINE_H
22 #define _TREE_FLOW_INLINE_H 1
24 /* Inline functions for manipulating various data structures defined in
25 tree-flow.h. See tree-flow.h for documentation. */
27 /* Return true when gimple SSA form was built.
28 gimple_in_ssa_p is queried by gimplifier in various early stages before SSA
29 infrastructure is initialized. Check for presence of the datastructures
30 at first place. */
31 static inline bool
32 gimple_in_ssa_p (const struct function *fun)
34 return fun && fun->gimple_df && fun->gimple_df->in_ssa_p;
37 /* 'true' after aliases have been computed (see compute_may_aliases). */
38 static inline bool
39 gimple_aliases_computed_p (const struct function *fun)
41 gcc_assert (fun && fun->gimple_df);
42 return fun->gimple_df->aliases_computed_p;
45 /* Addressable variables in the function. If bit I is set, then
46 REFERENCED_VARS (I) has had its address taken. Note that
47 CALL_CLOBBERED_VARS and ADDRESSABLE_VARS are not related. An
48 addressable variable is not necessarily call-clobbered (e.g., a
49 local addressable whose address does not escape) and not all
50 call-clobbered variables are addressable (e.g., a local static
51 variable). */
52 static inline bitmap
53 gimple_addressable_vars (const struct function *fun)
55 gcc_assert (fun && fun->gimple_df);
56 return fun->gimple_df->addressable_vars;
59 /* Call clobbered variables in the function. If bit I is set, then
60 REFERENCED_VARS (I) is call-clobbered. */
61 static inline bitmap
62 gimple_call_clobbered_vars (const struct function *fun)
64 gcc_assert (fun && fun->gimple_df);
65 return fun->gimple_df->call_clobbered_vars;
68 /* Array of all variables referenced in the function. */
69 static inline htab_t
70 gimple_referenced_vars (const struct function *fun)
72 if (!fun->gimple_df)
73 return NULL;
74 return fun->gimple_df->referenced_vars;
77 /* Artificial variable used to model the effects of function calls. */
78 static inline tree
79 gimple_global_var (const struct function *fun)
81 gcc_assert (fun && fun->gimple_df);
82 return fun->gimple_df->global_var;
85 /* Artificial variable used to model the effects of nonlocal
86 variables. */
87 static inline tree
88 gimple_nonlocal_all (const struct function *fun)
90 gcc_assert (fun && fun->gimple_df);
91 return fun->gimple_df->nonlocal_all;
94 /* Hashtable of variables annotations. Used for static variables only;
95 local variables have direct pointer in the tree node. */
96 static inline htab_t
97 gimple_var_anns (const struct function *fun)
99 return fun->gimple_df->var_anns;
102 /* Initialize the hashtable iterator HTI to point to hashtable TABLE */
104 static inline void *
105 first_htab_element (htab_iterator *hti, htab_t table)
107 hti->htab = table;
108 hti->slot = table->entries;
109 hti->limit = hti->slot + htab_size (table);
112 PTR x = *(hti->slot);
113 if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
114 break;
115 } while (++(hti->slot) < hti->limit);
117 if (hti->slot < hti->limit)
118 return *(hti->slot);
119 return NULL;
122 /* Return current non-empty/deleted slot of the hashtable pointed to by HTI,
123 or NULL if we have reached the end. */
125 static inline bool
126 end_htab_p (const htab_iterator *hti)
128 if (hti->slot >= hti->limit)
129 return true;
130 return false;
133 /* Advance the hashtable iterator pointed to by HTI to the next element of the
134 hashtable. */
136 static inline void *
137 next_htab_element (htab_iterator *hti)
139 while (++(hti->slot) < hti->limit)
141 PTR x = *(hti->slot);
142 if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
143 return x;
145 return NULL;
148 /* Initialize ITER to point to the first referenced variable in the
149 referenced_vars hashtable, and return that variable. */
151 static inline tree
152 first_referenced_var (referenced_var_iterator *iter)
154 return (tree) first_htab_element (&iter->hti,
155 gimple_referenced_vars (cfun));
158 /* Return true if we have hit the end of the referenced variables ITER is
159 iterating through. */
161 static inline bool
162 end_referenced_vars_p (const referenced_var_iterator *iter)
164 return end_htab_p (&iter->hti);
167 /* Make ITER point to the next referenced_var in the referenced_var hashtable,
168 and return that variable. */
170 static inline tree
171 next_referenced_var (referenced_var_iterator *iter)
173 return (tree) next_htab_element (&iter->hti);
176 /* Fill up VEC with the variables in the referenced vars hashtable. */
178 static inline void
179 fill_referenced_var_vec (VEC (tree, heap) **vec)
181 referenced_var_iterator rvi;
182 tree var;
183 *vec = NULL;
184 FOR_EACH_REFERENCED_VAR (var, rvi)
185 VEC_safe_push (tree, heap, *vec, var);
188 /* Return the variable annotation for T, which must be a _DECL node.
189 Return NULL if the variable annotation doesn't already exist. */
190 static inline var_ann_t
191 var_ann (const_tree t)
193 gcc_assert (t);
194 gcc_assert (DECL_P (t));
195 gcc_assert (TREE_CODE (t) != FUNCTION_DECL);
196 if (!MTAG_P (t) && (TREE_STATIC (t) || DECL_EXTERNAL (t)))
198 struct static_var_ann_d *sann
199 = ((struct static_var_ann_d *)
200 htab_find_with_hash (gimple_var_anns (cfun), t, DECL_UID (t)));
201 if (!sann)
202 return NULL;
203 gcc_assert (sann->ann.common.type == VAR_ANN);
204 return &sann->ann;
206 gcc_assert (!t->base.ann
207 || t->base.ann->common.type == VAR_ANN);
209 return (var_ann_t) t->base.ann;
212 /* Return the variable annotation for T, which must be a _DECL node.
213 Create the variable annotation if it doesn't exist. */
214 static inline var_ann_t
215 get_var_ann (tree var)
217 var_ann_t ann = var_ann (var);
218 return (ann) ? ann : create_var_ann (var);
221 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
222 Return NULL if the function annotation doesn't already exist. */
223 static inline function_ann_t
224 function_ann (const_tree t)
226 gcc_assert (t);
227 gcc_assert (TREE_CODE (t) == FUNCTION_DECL);
228 gcc_assert (!t->base.ann
229 || t->base.ann->common.type == FUNCTION_ANN);
231 return (function_ann_t) t->base.ann;
234 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
235 Create the function annotation if it doesn't exist. */
236 static inline function_ann_t
237 get_function_ann (tree var)
239 function_ann_t ann = function_ann (var);
240 gcc_assert (!var->base.ann || var->base.ann->common.type == FUNCTION_ANN);
241 return (ann) ? ann : create_function_ann (var);
244 /* Return true if T has a statement annotation attached to it. */
246 static inline bool
247 has_stmt_ann (tree t)
249 #ifdef ENABLE_CHECKING
250 gcc_assert (is_gimple_stmt (t));
251 #endif
252 return t->base.ann && t->base.ann->common.type == STMT_ANN;
255 /* Return the statement annotation for T, which must be a statement
256 node. Return NULL if the statement annotation doesn't exist. */
257 static inline stmt_ann_t
258 stmt_ann (tree t)
260 #ifdef ENABLE_CHECKING
261 gcc_assert (is_gimple_stmt (t));
262 #endif
263 gcc_assert (!t->base.ann || t->base.ann->common.type == STMT_ANN);
264 return (stmt_ann_t) t->base.ann;
267 /* Return the statement annotation for T, which must be a statement
268 node. Create the statement annotation if it doesn't exist. */
269 static inline stmt_ann_t
270 get_stmt_ann (tree stmt)
272 stmt_ann_t ann = stmt_ann (stmt);
273 return (ann) ? ann : create_stmt_ann (stmt);
276 /* Return the annotation type for annotation ANN. */
277 static inline enum tree_ann_type
278 ann_type (tree_ann_t ann)
280 return ann->common.type;
283 /* Return the basic block for statement T. */
284 static inline basic_block
285 bb_for_stmt (tree t)
287 stmt_ann_t ann;
289 if (TREE_CODE (t) == PHI_NODE)
290 return PHI_BB (t);
292 ann = stmt_ann (t);
293 return ann ? ann->bb : NULL;
296 /* Return the may_aliases bitmap for variable VAR, or NULL if it has
297 no may aliases. */
298 static inline bitmap
299 may_aliases (const_tree var)
301 return MTAG_ALIASES (var);
304 /* Return the line number for EXPR, or return -1 if we have no line
305 number information for it. */
306 static inline int
307 get_lineno (const_tree expr)
309 if (expr == NULL_TREE)
310 return -1;
312 if (TREE_CODE (expr) == COMPOUND_EXPR)
313 expr = TREE_OPERAND (expr, 0);
315 if (! EXPR_HAS_LOCATION (expr))
316 return -1;
318 return EXPR_LINENO (expr);
321 /* Return true if T is a noreturn call. */
322 static inline bool
323 noreturn_call_p (tree t)
325 tree call = get_call_expr_in (t);
326 return call != 0 && (call_expr_flags (call) & ECF_NORETURN) != 0;
329 /* Mark statement T as modified. */
330 static inline void
331 mark_stmt_modified (tree t)
333 stmt_ann_t ann;
334 if (TREE_CODE (t) == PHI_NODE)
335 return;
337 ann = stmt_ann (t);
338 if (ann == NULL)
339 ann = create_stmt_ann (t);
340 else if (noreturn_call_p (t) && cfun->gimple_df)
341 VEC_safe_push (tree, gc, MODIFIED_NORETURN_CALLS (cfun), t);
342 ann->modified = 1;
345 /* Mark statement T as modified, and update it. */
346 static inline void
347 update_stmt (tree t)
349 if (TREE_CODE (t) == PHI_NODE)
350 return;
351 mark_stmt_modified (t);
352 update_stmt_operands (t);
355 static inline void
356 update_stmt_if_modified (tree t)
358 if (stmt_modified_p (t))
359 update_stmt_operands (t);
362 /* Return true if T is marked as modified, false otherwise. */
363 static inline bool
364 stmt_modified_p (tree t)
366 stmt_ann_t ann = stmt_ann (t);
368 /* Note that if the statement doesn't yet have an annotation, we consider it
369 modified. This will force the next call to update_stmt_operands to scan
370 the statement. */
371 return ann ? ann->modified : true;
374 /* Delink an immediate_uses node from its chain. */
375 static inline void
376 delink_imm_use (ssa_use_operand_t *linknode)
378 /* Return if this node is not in a list. */
379 if (linknode->prev == NULL)
380 return;
382 linknode->prev->next = linknode->next;
383 linknode->next->prev = linknode->prev;
384 linknode->prev = NULL;
385 linknode->next = NULL;
388 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
389 static inline void
390 link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
392 /* Link the new node at the head of the list. If we are in the process of
393 traversing the list, we won't visit any new nodes added to it. */
394 linknode->prev = list;
395 linknode->next = list->next;
396 list->next->prev = linknode;
397 list->next = linknode;
400 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
401 static inline void
402 link_imm_use (ssa_use_operand_t *linknode, tree def)
404 ssa_use_operand_t *root;
406 if (!def || TREE_CODE (def) != SSA_NAME)
407 linknode->prev = NULL;
408 else
410 root = &(SSA_NAME_IMM_USE_NODE (def));
411 #ifdef ENABLE_CHECKING
412 if (linknode->use)
413 gcc_assert (*(linknode->use) == def);
414 #endif
415 link_imm_use_to_list (linknode, root);
419 /* Set the value of a use pointed to by USE to VAL. */
420 static inline void
421 set_ssa_use_from_ptr (use_operand_p use, tree val)
423 delink_imm_use (use);
424 *(use->use) = val;
425 link_imm_use (use, val);
428 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
429 in STMT. */
430 static inline void
431 link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, tree stmt)
433 if (stmt)
434 link_imm_use (linknode, def);
435 else
436 link_imm_use (linknode, NULL);
437 linknode->stmt = stmt;
440 /* Relink a new node in place of an old node in the list. */
441 static inline void
442 relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
444 /* The node one had better be in the same list. */
445 gcc_assert (*(old->use) == *(node->use));
446 node->prev = old->prev;
447 node->next = old->next;
448 if (old->prev)
450 old->prev->next = node;
451 old->next->prev = node;
452 /* Remove the old node from the list. */
453 old->prev = NULL;
457 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
458 in STMT. */
459 static inline void
460 relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old, tree stmt)
462 if (stmt)
463 relink_imm_use (linknode, old);
464 else
465 link_imm_use (linknode, NULL);
466 linknode->stmt = stmt;
470 /* Return true is IMM has reached the end of the immediate use list. */
471 static inline bool
472 end_readonly_imm_use_p (const imm_use_iterator *imm)
474 return (imm->imm_use == imm->end_p);
477 /* Initialize iterator IMM to process the list for VAR. */
478 static inline use_operand_p
479 first_readonly_imm_use (imm_use_iterator *imm, tree var)
481 gcc_assert (TREE_CODE (var) == SSA_NAME);
483 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
484 imm->imm_use = imm->end_p->next;
485 #ifdef ENABLE_CHECKING
486 imm->iter_node.next = imm->imm_use->next;
487 #endif
488 if (end_readonly_imm_use_p (imm))
489 return NULL_USE_OPERAND_P;
490 return imm->imm_use;
493 /* Bump IMM to the next use in the list. */
494 static inline use_operand_p
495 next_readonly_imm_use (imm_use_iterator *imm)
497 use_operand_p old = imm->imm_use;
499 #ifdef ENABLE_CHECKING
500 /* If this assertion fails, it indicates the 'next' pointer has changed
501 since the last bump. This indicates that the list is being modified
502 via stmt changes, or SET_USE, or somesuch thing, and you need to be
503 using the SAFE version of the iterator. */
504 gcc_assert (imm->iter_node.next == old->next);
505 imm->iter_node.next = old->next->next;
506 #endif
508 imm->imm_use = old->next;
509 if (end_readonly_imm_use_p (imm))
510 return old;
511 return imm->imm_use;
514 /* Return true if VAR has no uses. */
515 static inline bool
516 has_zero_uses (const_tree var)
518 const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
519 /* A single use means there is no items in the list. */
520 return (ptr == ptr->next);
523 /* Return true if VAR has a single use. */
524 static inline bool
525 has_single_use (const_tree var)
527 const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
528 /* A single use means there is one item in the list. */
529 return (ptr != ptr->next && ptr == ptr->next->next);
533 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
534 to the use pointer and stmt of occurrence. */
535 static inline bool
536 single_imm_use (const_tree var, use_operand_p *use_p, tree *stmt)
538 const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
539 if (ptr != ptr->next && ptr == ptr->next->next)
541 *use_p = ptr->next;
542 *stmt = ptr->next->stmt;
543 return true;
545 *use_p = NULL_USE_OPERAND_P;
546 *stmt = NULL_TREE;
547 return false;
550 /* Return the number of immediate uses of VAR. */
551 static inline unsigned int
552 num_imm_uses (const_tree var)
554 const ssa_use_operand_t *const start = &(SSA_NAME_IMM_USE_NODE (var));
555 const ssa_use_operand_t *ptr;
556 unsigned int num = 0;
558 for (ptr = start->next; ptr != start; ptr = ptr->next)
559 num++;
561 return num;
564 /* Return the tree pointer to by USE. */
565 static inline tree
566 get_use_from_ptr (use_operand_p use)
568 return *(use->use);
571 /* Return the tree pointer to by DEF. */
572 static inline tree
573 get_def_from_ptr (def_operand_p def)
575 return *def;
578 /* Return a def_operand_p pointer for the result of PHI. */
579 static inline def_operand_p
580 get_phi_result_ptr (tree phi)
582 return &(PHI_RESULT_TREE (phi));
585 /* Return a use_operand_p pointer for argument I of phinode PHI. */
586 static inline use_operand_p
587 get_phi_arg_def_ptr (tree phi, int i)
589 return &(PHI_ARG_IMM_USE_NODE (phi,i));
593 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
594 no addresses. */
595 static inline bitmap
596 addresses_taken (tree stmt)
598 stmt_ann_t ann = stmt_ann (stmt);
599 return ann ? ann->addresses_taken : NULL;
602 /* Return the PHI nodes for basic block BB, or NULL if there are no
603 PHI nodes. */
604 static inline tree
605 phi_nodes (const_basic_block bb)
607 gcc_assert (!(bb->flags & BB_RTL));
608 if (!bb->il.tree)
609 return NULL;
610 return bb->il.tree->phi_nodes;
613 /* Return pointer to the list of PHI nodes for basic block BB. */
615 static inline tree *
616 phi_nodes_ptr (basic_block bb)
618 gcc_assert (!(bb->flags & BB_RTL));
619 return &bb->il.tree->phi_nodes;
622 /* Set list of phi nodes of a basic block BB to L. */
624 static inline void
625 set_phi_nodes (basic_block bb, tree l)
627 tree phi;
629 gcc_assert (!(bb->flags & BB_RTL));
630 bb->il.tree->phi_nodes = l;
631 for (phi = l; phi; phi = PHI_CHAIN (phi))
632 set_bb_for_stmt (phi, bb);
635 /* Return the phi argument which contains the specified use. */
637 static inline int
638 phi_arg_index_from_use (use_operand_p use)
640 struct phi_arg_d *element, *root;
641 int index;
642 tree phi;
644 /* Since the use is the first thing in a PHI argument element, we can
645 calculate its index based on casting it to an argument, and performing
646 pointer arithmetic. */
648 phi = USE_STMT (use);
649 gcc_assert (TREE_CODE (phi) == PHI_NODE);
651 element = (struct phi_arg_d *)use;
652 root = &(PHI_ARG_ELT (phi, 0));
653 index = element - root;
655 #ifdef ENABLE_CHECKING
656 /* Make sure the calculation doesn't have any leftover bytes. If it does,
657 then imm_use is likely not the first element in phi_arg_d. */
658 gcc_assert (
659 (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
660 gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
661 #endif
663 return index;
666 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
668 static inline void
669 set_is_used (tree var)
671 var_ann_t ann = get_var_ann (var);
672 ann->used = 1;
676 /* Return true if T (assumed to be a DECL) is a global variable. */
678 static inline bool
679 is_global_var (const_tree t)
681 if (MTAG_P (t))
682 return (TREE_STATIC (t) || MTAG_GLOBAL (t));
683 else
684 return (TREE_STATIC (t) || DECL_EXTERNAL (t));
687 /* PHI nodes should contain only ssa_names and invariants. A test
688 for ssa_name is definitely simpler; don't let invalid contents
689 slip in in the meantime. */
691 static inline bool
692 phi_ssa_name_p (const_tree t)
694 if (TREE_CODE (t) == SSA_NAME)
695 return true;
696 #ifdef ENABLE_CHECKING
697 gcc_assert (is_gimple_min_invariant (t));
698 #endif
699 return false;
702 /* ----------------------------------------------------------------------- */
704 /* Returns the list of statements in BB. */
706 static inline tree
707 bb_stmt_list (const_basic_block bb)
709 gcc_assert (!(bb->flags & BB_RTL));
710 return bb->il.tree->stmt_list;
713 /* Sets the list of statements in BB to LIST. */
715 static inline void
716 set_bb_stmt_list (basic_block bb, tree list)
718 gcc_assert (!(bb->flags & BB_RTL));
719 bb->il.tree->stmt_list = list;
722 /* Return a block_stmt_iterator that points to beginning of basic
723 block BB. */
724 static inline block_stmt_iterator
725 bsi_start (basic_block bb)
727 block_stmt_iterator bsi;
728 if (bb->index < NUM_FIXED_BLOCKS)
730 bsi.tsi.ptr = NULL;
731 bsi.tsi.container = NULL;
733 else
734 bsi.tsi = tsi_start (bb_stmt_list (bb));
735 bsi.bb = bb;
736 return bsi;
739 /* Return a block statement iterator that points to the first non-label
740 statement in block BB. */
742 static inline block_stmt_iterator
743 bsi_after_labels (basic_block bb)
745 block_stmt_iterator bsi = bsi_start (bb);
747 while (!bsi_end_p (bsi) && TREE_CODE (bsi_stmt (bsi)) == LABEL_EXPR)
748 bsi_next (&bsi);
750 return bsi;
753 /* Return a block statement iterator that points to the end of basic
754 block BB. */
755 static inline block_stmt_iterator
756 bsi_last (basic_block bb)
758 block_stmt_iterator bsi;
760 if (bb->index < NUM_FIXED_BLOCKS)
762 bsi.tsi.ptr = NULL;
763 bsi.tsi.container = NULL;
765 else
766 bsi.tsi = tsi_last (bb_stmt_list (bb));
767 bsi.bb = bb;
768 return bsi;
771 /* Return true if block statement iterator I has reached the end of
772 the basic block. */
773 static inline bool
774 bsi_end_p (block_stmt_iterator i)
776 return tsi_end_p (i.tsi);
779 /* Modify block statement iterator I so that it is at the next
780 statement in the basic block. */
781 static inline void
782 bsi_next (block_stmt_iterator *i)
784 tsi_next (&i->tsi);
787 /* Modify block statement iterator I so that it is at the previous
788 statement in the basic block. */
789 static inline void
790 bsi_prev (block_stmt_iterator *i)
792 tsi_prev (&i->tsi);
795 /* Return the statement that block statement iterator I is currently
796 at. */
797 static inline tree
798 bsi_stmt (block_stmt_iterator i)
800 return tsi_stmt (i.tsi);
803 /* Return a pointer to the statement that block statement iterator I
804 is currently at. */
805 static inline tree *
806 bsi_stmt_ptr (block_stmt_iterator i)
808 return tsi_stmt_ptr (i.tsi);
811 /* Returns the loop of the statement STMT. */
813 static inline struct loop *
814 loop_containing_stmt (tree stmt)
816 basic_block bb = bb_for_stmt (stmt);
817 if (!bb)
818 return NULL;
820 return bb->loop_father;
824 /* Return the memory partition tag associated with symbol SYM. */
826 static inline tree
827 memory_partition (tree sym)
829 tree tag;
831 /* MPTs belong to their own partition. */
832 if (TREE_CODE (sym) == MEMORY_PARTITION_TAG)
833 return sym;
835 gcc_assert (!is_gimple_reg (sym));
836 tag = get_var_ann (sym)->mpt;
838 #if defined ENABLE_CHECKING
839 if (tag)
840 gcc_assert (TREE_CODE (tag) == MEMORY_PARTITION_TAG);
841 #endif
843 return tag;
846 /* Return true if NAME is a memory factoring SSA name (i.e., an SSA
847 name for a memory partition. */
849 static inline bool
850 factoring_name_p (const_tree name)
852 return TREE_CODE (SSA_NAME_VAR (name)) == MEMORY_PARTITION_TAG;
855 /* Return true if VAR is a clobbered by function calls. */
856 static inline bool
857 is_call_clobbered (const_tree var)
859 if (!MTAG_P (var))
860 return var_ann (var)->call_clobbered;
861 else
862 return bitmap_bit_p (gimple_call_clobbered_vars (cfun), DECL_UID (var));
865 /* Mark variable VAR as being clobbered by function calls. */
866 static inline void
867 mark_call_clobbered (tree var, unsigned int escape_type)
869 var_ann (var)->escape_mask |= escape_type;
870 if (!MTAG_P (var))
871 var_ann (var)->call_clobbered = true;
872 bitmap_set_bit (gimple_call_clobbered_vars (cfun), DECL_UID (var));
875 /* Clear the call-clobbered attribute from variable VAR. */
876 static inline void
877 clear_call_clobbered (tree var)
879 var_ann_t ann = var_ann (var);
880 ann->escape_mask = 0;
881 if (MTAG_P (var) && TREE_CODE (var) != STRUCT_FIELD_TAG)
882 MTAG_GLOBAL (var) = 0;
883 if (!MTAG_P (var))
884 var_ann (var)->call_clobbered = false;
885 bitmap_clear_bit (gimple_call_clobbered_vars (cfun), DECL_UID (var));
888 /* Return the common annotation for T. Return NULL if the annotation
889 doesn't already exist. */
890 static inline tree_ann_common_t
891 tree_common_ann (const_tree t)
893 /* Watch out static variables with unshared annotations. */
894 if (DECL_P (t) && TREE_CODE (t) == VAR_DECL)
895 return &var_ann (t)->common;
896 return &t->base.ann->common;
899 /* Return a common annotation for T. Create the constant annotation if it
900 doesn't exist. */
901 static inline tree_ann_common_t
902 get_tree_common_ann (tree t)
904 tree_ann_common_t ann = tree_common_ann (t);
905 return (ann) ? ann : create_tree_common_ann (t);
908 /* ----------------------------------------------------------------------- */
910 /* The following set of routines are used to iterator over various type of
911 SSA operands. */
913 /* Return true if PTR is finished iterating. */
914 static inline bool
915 op_iter_done (const ssa_op_iter *ptr)
917 return ptr->done;
920 /* Get the next iterator use value for PTR. */
921 static inline use_operand_p
922 op_iter_next_use (ssa_op_iter *ptr)
924 use_operand_p use_p;
925 #ifdef ENABLE_CHECKING
926 gcc_assert (ptr->iter_type == ssa_op_iter_use);
927 #endif
928 if (ptr->uses)
930 use_p = USE_OP_PTR (ptr->uses);
931 ptr->uses = ptr->uses->next;
932 return use_p;
934 if (ptr->vuses)
936 use_p = VUSE_OP_PTR (ptr->vuses, ptr->vuse_index);
937 if (++(ptr->vuse_index) >= VUSE_NUM (ptr->vuses))
939 ptr->vuse_index = 0;
940 ptr->vuses = ptr->vuses->next;
942 return use_p;
944 if (ptr->mayuses)
946 use_p = VDEF_OP_PTR (ptr->mayuses, ptr->mayuse_index);
947 if (++(ptr->mayuse_index) >= VDEF_NUM (ptr->mayuses))
949 ptr->mayuse_index = 0;
950 ptr->mayuses = ptr->mayuses->next;
952 return use_p;
954 if (ptr->phi_i < ptr->num_phi)
956 return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
958 ptr->done = true;
959 return NULL_USE_OPERAND_P;
962 /* Get the next iterator def value for PTR. */
963 static inline def_operand_p
964 op_iter_next_def (ssa_op_iter *ptr)
966 def_operand_p def_p;
967 #ifdef ENABLE_CHECKING
968 gcc_assert (ptr->iter_type == ssa_op_iter_def);
969 #endif
970 if (ptr->defs)
972 def_p = DEF_OP_PTR (ptr->defs);
973 ptr->defs = ptr->defs->next;
974 return def_p;
976 if (ptr->vdefs)
978 def_p = VDEF_RESULT_PTR (ptr->vdefs);
979 ptr->vdefs = ptr->vdefs->next;
980 return def_p;
982 ptr->done = true;
983 return NULL_DEF_OPERAND_P;
986 /* Get the next iterator tree value for PTR. */
987 static inline tree
988 op_iter_next_tree (ssa_op_iter *ptr)
990 tree val;
991 #ifdef ENABLE_CHECKING
992 gcc_assert (ptr->iter_type == ssa_op_iter_tree);
993 #endif
994 if (ptr->uses)
996 val = USE_OP (ptr->uses);
997 ptr->uses = ptr->uses->next;
998 return val;
1000 if (ptr->vuses)
1002 val = VUSE_OP (ptr->vuses, ptr->vuse_index);
1003 if (++(ptr->vuse_index) >= VUSE_NUM (ptr->vuses))
1005 ptr->vuse_index = 0;
1006 ptr->vuses = ptr->vuses->next;
1008 return val;
1010 if (ptr->mayuses)
1012 val = VDEF_OP (ptr->mayuses, ptr->mayuse_index);
1013 if (++(ptr->mayuse_index) >= VDEF_NUM (ptr->mayuses))
1015 ptr->mayuse_index = 0;
1016 ptr->mayuses = ptr->mayuses->next;
1018 return val;
1020 if (ptr->defs)
1022 val = DEF_OP (ptr->defs);
1023 ptr->defs = ptr->defs->next;
1024 return val;
1026 if (ptr->vdefs)
1028 val = VDEF_RESULT (ptr->vdefs);
1029 ptr->vdefs = ptr->vdefs->next;
1030 return val;
1033 ptr->done = true;
1034 return NULL_TREE;
1039 /* This functions clears the iterator PTR, and marks it done. This is normally
1040 used to prevent warnings in the compile about might be uninitialized
1041 components. */
1043 static inline void
1044 clear_and_done_ssa_iter (ssa_op_iter *ptr)
1046 ptr->defs = NULL;
1047 ptr->uses = NULL;
1048 ptr->vuses = NULL;
1049 ptr->vdefs = NULL;
1050 ptr->mayuses = NULL;
1051 ptr->iter_type = ssa_op_iter_none;
1052 ptr->phi_i = 0;
1053 ptr->num_phi = 0;
1054 ptr->phi_stmt = NULL_TREE;
1055 ptr->done = true;
1056 ptr->vuse_index = 0;
1057 ptr->mayuse_index = 0;
1060 /* Initialize the iterator PTR to the virtual defs in STMT. */
1061 static inline void
1062 op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
1064 #ifdef ENABLE_CHECKING
1065 gcc_assert (stmt_ann (stmt));
1066 #endif
1068 ptr->defs = (flags & SSA_OP_DEF) ? DEF_OPS (stmt) : NULL;
1069 ptr->uses = (flags & SSA_OP_USE) ? USE_OPS (stmt) : NULL;
1070 ptr->vuses = (flags & SSA_OP_VUSE) ? VUSE_OPS (stmt) : NULL;
1071 ptr->vdefs = (flags & SSA_OP_VDEF) ? VDEF_OPS (stmt) : NULL;
1072 ptr->mayuses = (flags & SSA_OP_VMAYUSE) ? VDEF_OPS (stmt) : NULL;
1073 ptr->done = false;
1075 ptr->phi_i = 0;
1076 ptr->num_phi = 0;
1077 ptr->phi_stmt = NULL_TREE;
1078 ptr->vuse_index = 0;
1079 ptr->mayuse_index = 0;
1082 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1083 the first use. */
1084 static inline use_operand_p
1085 op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
1087 gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0);
1088 op_iter_init (ptr, stmt, flags);
1089 ptr->iter_type = ssa_op_iter_use;
1090 return op_iter_next_use (ptr);
1093 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1094 the first def. */
1095 static inline def_operand_p
1096 op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1098 gcc_assert ((flags & SSA_OP_ALL_USES) == 0);
1099 op_iter_init (ptr, stmt, flags);
1100 ptr->iter_type = ssa_op_iter_def;
1101 return op_iter_next_def (ptr);
1104 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1105 the first operand as a tree. */
1106 static inline tree
1107 op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1109 op_iter_init (ptr, stmt, flags);
1110 ptr->iter_type = ssa_op_iter_tree;
1111 return op_iter_next_tree (ptr);
1114 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1115 KILL and DEF. */
1116 static inline void
1117 op_iter_next_vdef (vuse_vec_p *use, def_operand_p *def,
1118 ssa_op_iter *ptr)
1120 #ifdef ENABLE_CHECKING
1121 gcc_assert (ptr->iter_type == ssa_op_iter_vdef);
1122 #endif
1123 if (ptr->mayuses)
1125 *def = VDEF_RESULT_PTR (ptr->mayuses);
1126 *use = VDEF_VECT (ptr->mayuses);
1127 ptr->mayuses = ptr->mayuses->next;
1128 return;
1131 *def = NULL_DEF_OPERAND_P;
1132 *use = NULL;
1133 ptr->done = true;
1134 return;
1138 static inline void
1139 op_iter_next_mustdef (use_operand_p *use, def_operand_p *def,
1140 ssa_op_iter *ptr)
1142 vuse_vec_p vp;
1143 op_iter_next_vdef (&vp, def, ptr);
1144 if (vp != NULL)
1146 gcc_assert (VUSE_VECT_NUM_ELEM (*vp) == 1);
1147 *use = VUSE_ELEMENT_PTR (*vp, 0);
1149 else
1150 *use = NULL_USE_OPERAND_P;
1153 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1154 in USE and DEF. */
1155 static inline void
1156 op_iter_init_vdef (ssa_op_iter *ptr, tree stmt, vuse_vec_p *use,
1157 def_operand_p *def)
1159 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1161 op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1162 ptr->iter_type = ssa_op_iter_vdef;
1163 op_iter_next_vdef (use, def, ptr);
1167 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1168 return NULL. */
1169 static inline tree
1170 single_ssa_tree_operand (tree stmt, int flags)
1172 tree var;
1173 ssa_op_iter iter;
1175 var = op_iter_init_tree (&iter, stmt, flags);
1176 if (op_iter_done (&iter))
1177 return NULL_TREE;
1178 op_iter_next_tree (&iter);
1179 if (op_iter_done (&iter))
1180 return var;
1181 return NULL_TREE;
1185 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1186 return NULL. */
1187 static inline use_operand_p
1188 single_ssa_use_operand (tree stmt, int flags)
1190 use_operand_p var;
1191 ssa_op_iter iter;
1193 var = op_iter_init_use (&iter, stmt, flags);
1194 if (op_iter_done (&iter))
1195 return NULL_USE_OPERAND_P;
1196 op_iter_next_use (&iter);
1197 if (op_iter_done (&iter))
1198 return var;
1199 return NULL_USE_OPERAND_P;
1204 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1205 return NULL. */
1206 static inline def_operand_p
1207 single_ssa_def_operand (tree stmt, int flags)
1209 def_operand_p var;
1210 ssa_op_iter iter;
1212 var = op_iter_init_def (&iter, stmt, flags);
1213 if (op_iter_done (&iter))
1214 return NULL_DEF_OPERAND_P;
1215 op_iter_next_def (&iter);
1216 if (op_iter_done (&iter))
1217 return var;
1218 return NULL_DEF_OPERAND_P;
1222 /* Return true if there are zero operands in STMT matching the type
1223 given in FLAGS. */
1224 static inline bool
1225 zero_ssa_operands (tree stmt, int flags)
1227 ssa_op_iter iter;
1229 op_iter_init_tree (&iter, stmt, flags);
1230 return op_iter_done (&iter);
1234 /* Return the number of operands matching FLAGS in STMT. */
1235 static inline int
1236 num_ssa_operands (tree stmt, int flags)
1238 ssa_op_iter iter;
1239 tree t;
1240 int num = 0;
1242 FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
1243 num++;
1244 return num;
1248 /* Delink all immediate_use information for STMT. */
1249 static inline void
1250 delink_stmt_imm_use (tree stmt)
1252 ssa_op_iter iter;
1253 use_operand_p use_p;
1255 if (ssa_operands_active ())
1256 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_ALL_USES)
1257 delink_imm_use (use_p);
1261 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1262 in STMT2. TRUE is returned if they are the same. STMTs can be NULL. */
1263 static inline bool
1264 compare_ssa_operands_equal (tree stmt1, tree stmt2, int flags)
1266 ssa_op_iter iter1, iter2;
1267 tree op1 = NULL_TREE;
1268 tree op2 = NULL_TREE;
1269 bool look1, look2;
1271 if (stmt1 == stmt2)
1272 return true;
1274 look1 = stmt1 && stmt_ann (stmt1);
1275 look2 = stmt2 && stmt_ann (stmt2);
1277 if (look1)
1279 op1 = op_iter_init_tree (&iter1, stmt1, flags);
1280 if (!look2)
1281 return op_iter_done (&iter1);
1283 else
1284 clear_and_done_ssa_iter (&iter1);
1286 if (look2)
1288 op2 = op_iter_init_tree (&iter2, stmt2, flags);
1289 if (!look1)
1290 return op_iter_done (&iter2);
1292 else
1293 clear_and_done_ssa_iter (&iter2);
1295 while (!op_iter_done (&iter1) && !op_iter_done (&iter2))
1297 if (op1 != op2)
1298 return false;
1299 op1 = op_iter_next_tree (&iter1);
1300 op2 = op_iter_next_tree (&iter2);
1303 return (op_iter_done (&iter1) && op_iter_done (&iter2));
1307 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1308 Otherwise return NULL_DEF_OPERAND_P. */
1309 static inline tree
1310 single_phi_def (tree stmt, int flags)
1312 tree def = PHI_RESULT (stmt);
1313 if ((flags & SSA_OP_DEF) && is_gimple_reg (def))
1314 return def;
1315 if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
1316 return def;
1317 return NULL_TREE;
1320 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
1321 be either SSA_OP_USES or SSA_OP_VIRTUAL_USES. */
1322 static inline use_operand_p
1323 op_iter_init_phiuse (ssa_op_iter *ptr, tree phi, int flags)
1325 tree phi_def = PHI_RESULT (phi);
1326 int comp;
1328 clear_and_done_ssa_iter (ptr);
1329 ptr->done = false;
1331 gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
1333 comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1335 /* If the PHI node doesn't the operand type we care about, we're done. */
1336 if ((flags & comp) == 0)
1338 ptr->done = true;
1339 return NULL_USE_OPERAND_P;
1342 ptr->phi_stmt = phi;
1343 ptr->num_phi = PHI_NUM_ARGS (phi);
1344 ptr->iter_type = ssa_op_iter_use;
1345 return op_iter_next_use (ptr);
1349 /* Start an iterator for a PHI definition. */
1351 static inline def_operand_p
1352 op_iter_init_phidef (ssa_op_iter *ptr, tree phi, int flags)
1354 tree phi_def = PHI_RESULT (phi);
1355 int comp;
1357 clear_and_done_ssa_iter (ptr);
1358 ptr->done = false;
1360 gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
1362 comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
1364 /* If the PHI node doesn't the operand type we care about, we're done. */
1365 if ((flags & comp) == 0)
1367 ptr->done = true;
1368 return NULL_USE_OPERAND_P;
1371 ptr->iter_type = ssa_op_iter_def;
1372 /* The first call to op_iter_next_def will terminate the iterator since
1373 all the fields are NULL. Simply return the result here as the first and
1374 therefore only result. */
1375 return PHI_RESULT_PTR (phi);
1378 /* Return true is IMM has reached the end of the immediate use stmt list. */
1380 static inline bool
1381 end_imm_use_stmt_p (const imm_use_iterator *imm)
1383 return (imm->imm_use == imm->end_p);
1386 /* Finished the traverse of an immediate use stmt list IMM by removing the
1387 placeholder node from the list. */
1389 static inline void
1390 end_imm_use_stmt_traverse (imm_use_iterator *imm)
1392 delink_imm_use (&(imm->iter_node));
1395 /* Immediate use traversal of uses within a stmt require that all the
1396 uses on a stmt be sequentially listed. This routine is used to build up
1397 this sequential list by adding USE_P to the end of the current list
1398 currently delimited by HEAD and LAST_P. The new LAST_P value is
1399 returned. */
1401 static inline use_operand_p
1402 move_use_after_head (use_operand_p use_p, use_operand_p head,
1403 use_operand_p last_p)
1405 gcc_assert (USE_FROM_PTR (use_p) == USE_FROM_PTR (head));
1406 /* Skip head when we find it. */
1407 if (use_p != head)
1409 /* If use_p is already linked in after last_p, continue. */
1410 if (last_p->next == use_p)
1411 last_p = use_p;
1412 else
1414 /* Delink from current location, and link in at last_p. */
1415 delink_imm_use (use_p);
1416 link_imm_use_to_list (use_p, last_p);
1417 last_p = use_p;
1420 return last_p;
1424 /* This routine will relink all uses with the same stmt as HEAD into the list
1425 immediately following HEAD for iterator IMM. */
1427 static inline void
1428 link_use_stmts_after (use_operand_p head, imm_use_iterator *imm)
1430 use_operand_p use_p;
1431 use_operand_p last_p = head;
1432 tree head_stmt = USE_STMT (head);
1433 tree use = USE_FROM_PTR (head);
1434 ssa_op_iter op_iter;
1435 int flag;
1437 /* Only look at virtual or real uses, depending on the type of HEAD. */
1438 flag = (is_gimple_reg (use) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1440 if (TREE_CODE (head_stmt) == PHI_NODE)
1442 FOR_EACH_PHI_ARG (use_p, head_stmt, op_iter, flag)
1443 if (USE_FROM_PTR (use_p) == use)
1444 last_p = move_use_after_head (use_p, head, last_p);
1446 else
1448 FOR_EACH_SSA_USE_OPERAND (use_p, head_stmt, op_iter, flag)
1449 if (USE_FROM_PTR (use_p) == use)
1450 last_p = move_use_after_head (use_p, head, last_p);
1452 /* LInk iter node in after last_p. */
1453 if (imm->iter_node.prev != NULL)
1454 delink_imm_use (&imm->iter_node);
1455 link_imm_use_to_list (&(imm->iter_node), last_p);
1458 /* Initialize IMM to traverse over uses of VAR. Return the first statement. */
1459 static inline tree
1460 first_imm_use_stmt (imm_use_iterator *imm, tree var)
1462 gcc_assert (TREE_CODE (var) == SSA_NAME);
1464 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
1465 imm->imm_use = imm->end_p->next;
1466 imm->next_imm_name = NULL_USE_OPERAND_P;
1468 /* iter_node is used as a marker within the immediate use list to indicate
1469 where the end of the current stmt's uses are. Initialize it to NULL
1470 stmt and use, which indicates a marker node. */
1471 imm->iter_node.prev = NULL_USE_OPERAND_P;
1472 imm->iter_node.next = NULL_USE_OPERAND_P;
1473 imm->iter_node.stmt = NULL_TREE;
1474 imm->iter_node.use = NULL_USE_OPERAND_P;
1476 if (end_imm_use_stmt_p (imm))
1477 return NULL_TREE;
1479 link_use_stmts_after (imm->imm_use, imm);
1481 return USE_STMT (imm->imm_use);
1484 /* Bump IMM to the next stmt which has a use of var. */
1486 static inline tree
1487 next_imm_use_stmt (imm_use_iterator *imm)
1489 imm->imm_use = imm->iter_node.next;
1490 if (end_imm_use_stmt_p (imm))
1492 if (imm->iter_node.prev != NULL)
1493 delink_imm_use (&imm->iter_node);
1494 return NULL_TREE;
1497 link_use_stmts_after (imm->imm_use, imm);
1498 return USE_STMT (imm->imm_use);
1501 /* This routine will return the first use on the stmt IMM currently refers
1502 to. */
1504 static inline use_operand_p
1505 first_imm_use_on_stmt (imm_use_iterator *imm)
1507 imm->next_imm_name = imm->imm_use->next;
1508 return imm->imm_use;
1511 /* Return TRUE if the last use on the stmt IMM refers to has been visited. */
1513 static inline bool
1514 end_imm_use_on_stmt_p (const imm_use_iterator *imm)
1516 return (imm->imm_use == &(imm->iter_node));
1519 /* Bump to the next use on the stmt IMM refers to, return NULL if done. */
1521 static inline use_operand_p
1522 next_imm_use_on_stmt (imm_use_iterator *imm)
1524 imm->imm_use = imm->next_imm_name;
1525 if (end_imm_use_on_stmt_p (imm))
1526 return NULL_USE_OPERAND_P;
1527 else
1529 imm->next_imm_name = imm->imm_use->next;
1530 return imm->imm_use;
1534 /* Return true if VAR cannot be modified by the program. */
1536 static inline bool
1537 unmodifiable_var_p (const_tree var)
1539 if (TREE_CODE (var) == SSA_NAME)
1540 var = SSA_NAME_VAR (var);
1542 if (MTAG_P (var))
1543 return TREE_READONLY (var) && (TREE_STATIC (var) || MTAG_GLOBAL (var));
1545 return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1548 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it. */
1550 static inline bool
1551 array_ref_contains_indirect_ref (const_tree ref)
1553 gcc_assert (TREE_CODE (ref) == ARRAY_REF);
1555 do {
1556 ref = TREE_OPERAND (ref, 0);
1557 } while (handled_component_p (ref));
1559 return TREE_CODE (ref) == INDIRECT_REF;
1562 /* Return true if REF, a handled component reference, has an ARRAY_REF
1563 somewhere in it. */
1565 static inline bool
1566 ref_contains_array_ref (const_tree ref)
1568 gcc_assert (handled_component_p (ref));
1570 do {
1571 if (TREE_CODE (ref) == ARRAY_REF)
1572 return true;
1573 ref = TREE_OPERAND (ref, 0);
1574 } while (handled_component_p (ref));
1576 return false;
1579 /* Given a variable VAR, lookup and return a pointer to the list of
1580 subvariables for it. */
1582 static inline subvar_t *
1583 lookup_subvars_for_var (const_tree var)
1585 var_ann_t ann = var_ann (var);
1586 gcc_assert (ann);
1587 return &ann->subvars;
1590 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1591 NULL, if there are no subvariables. */
1593 static inline subvar_t
1594 get_subvars_for_var (tree var)
1596 subvar_t subvars;
1598 gcc_assert (SSA_VAR_P (var));
1600 if (TREE_CODE (var) == SSA_NAME)
1601 subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
1602 else
1603 subvars = *(lookup_subvars_for_var (var));
1604 return subvars;
1607 /* Return the subvariable of VAR at offset OFFSET. */
1609 static inline tree
1610 get_subvar_at (tree var, unsigned HOST_WIDE_INT offset)
1612 subvar_t sv = get_subvars_for_var (var);
1613 int low, high;
1615 low = 0;
1616 high = VEC_length (tree, sv) - 1;
1617 while (low <= high)
1619 int mid = (low + high) / 2;
1620 tree subvar = VEC_index (tree, sv, mid);
1621 if (SFT_OFFSET (subvar) == offset)
1622 return subvar;
1623 else if (SFT_OFFSET (subvar) < offset)
1624 low = mid + 1;
1625 else
1626 high = mid - 1;
1629 return NULL_TREE;
1633 /* Return the first subvariable in SV that overlaps [offset, offset + size[.
1634 NULL_TREE is returned, if there is no overlapping subvariable, else *I
1635 is set to the index in the SV vector of the first overlap. */
1637 static inline tree
1638 get_first_overlapping_subvar (subvar_t sv, unsigned HOST_WIDE_INT offset,
1639 unsigned HOST_WIDE_INT size, unsigned int *i)
1641 int low = 0;
1642 int high = VEC_length (tree, sv) - 1;
1643 int mid;
1644 tree subvar;
1646 if (low > high)
1647 return NULL_TREE;
1649 /* Binary search for offset. */
1652 mid = (low + high) / 2;
1653 subvar = VEC_index (tree, sv, mid);
1654 if (SFT_OFFSET (subvar) == offset)
1656 *i = mid;
1657 return subvar;
1659 else if (SFT_OFFSET (subvar) < offset)
1660 low = mid + 1;
1661 else
1662 high = mid - 1;
1664 while (low <= high);
1666 /* As we didn't find a subvar with offset, adjust to return the
1667 first overlapping one. */
1668 if (SFT_OFFSET (subvar) < offset
1669 && SFT_OFFSET (subvar) + SFT_SIZE (subvar) <= offset)
1671 mid += 1;
1672 if ((unsigned)mid >= VEC_length (tree, sv))
1673 return NULL_TREE;
1674 subvar = VEC_index (tree, sv, mid);
1676 else if (SFT_OFFSET (subvar) > offset
1677 && size <= SFT_OFFSET (subvar) - offset)
1679 mid -= 1;
1680 if (mid < 0)
1681 return NULL_TREE;
1682 subvar = VEC_index (tree, sv, mid);
1685 if (overlap_subvar (offset, size, subvar, NULL))
1687 *i = mid;
1688 return subvar;
1691 return NULL_TREE;
1695 /* Return true if V is a tree that we can have subvars for.
1696 Normally, this is any aggregate type. Also complex
1697 types which are not gimple registers can have subvars. */
1699 static inline bool
1700 var_can_have_subvars (const_tree v)
1702 /* Volatile variables should never have subvars. */
1703 if (TREE_THIS_VOLATILE (v))
1704 return false;
1706 /* Non decls or memory tags can never have subvars. */
1707 if (!DECL_P (v) || MTAG_P (v))
1708 return false;
1710 /* Aggregates can have subvars. */
1711 if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
1712 return true;
1714 /* Complex types variables which are not also a gimple register can
1715 have subvars. */
1716 if (TREE_CODE (TREE_TYPE (v)) == COMPLEX_TYPE
1717 && !DECL_GIMPLE_REG_P (v))
1718 return true;
1720 return false;
1724 /* Return true if OFFSET and SIZE define a range that overlaps with some
1725 portion of the range of SV, a subvar. If there was an exact overlap,
1726 *EXACT will be set to true upon return. */
1728 static inline bool
1729 overlap_subvar (unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT size,
1730 const_tree sv, bool *exact)
1732 /* There are three possible cases of overlap.
1733 1. We can have an exact overlap, like so:
1734 |offset, offset + size |
1735 |sv->offset, sv->offset + sv->size |
1737 2. We can have offset starting after sv->offset, like so:
1739 |offset, offset + size |
1740 |sv->offset, sv->offset + sv->size |
1742 3. We can have offset starting before sv->offset, like so:
1744 |offset, offset + size |
1745 |sv->offset, sv->offset + sv->size|
1748 if (exact)
1749 *exact = false;
1750 if (offset == SFT_OFFSET (sv) && size == SFT_SIZE (sv))
1752 if (exact)
1753 *exact = true;
1754 return true;
1756 else if (offset >= SFT_OFFSET (sv)
1757 && offset < (SFT_OFFSET (sv) + SFT_SIZE (sv)))
1759 return true;
1761 else if (offset < SFT_OFFSET (sv)
1762 && (size > SFT_OFFSET (sv) - offset))
1764 return true;
1766 return false;
1770 /* Return the memory tag associated with symbol SYM. */
1772 static inline tree
1773 symbol_mem_tag (tree sym)
1775 tree tag = get_var_ann (sym)->symbol_mem_tag;
1777 #if defined ENABLE_CHECKING
1778 if (tag)
1779 gcc_assert (TREE_CODE (tag) == SYMBOL_MEMORY_TAG);
1780 #endif
1782 return tag;
1786 /* Set the memory tag associated with symbol SYM. */
1788 static inline void
1789 set_symbol_mem_tag (tree sym, tree tag)
1791 #if defined ENABLE_CHECKING
1792 if (tag)
1793 gcc_assert (TREE_CODE (tag) == SYMBOL_MEMORY_TAG);
1794 #endif
1796 get_var_ann (sym)->symbol_mem_tag = tag;
1799 /* Get the value handle of EXPR. This is the only correct way to get
1800 the value handle for a "thing". If EXPR does not have a value
1801 handle associated, it returns NULL_TREE.
1802 NB: If EXPR is min_invariant, this function is *required* to return
1803 EXPR. */
1805 static inline tree
1806 get_value_handle (tree expr)
1808 if (TREE_CODE (expr) == SSA_NAME)
1809 return SSA_NAME_VALUE (expr);
1810 else if (DECL_P (expr) || TREE_CODE (expr) == TREE_LIST
1811 || TREE_CODE (expr) == CONSTRUCTOR)
1813 tree_ann_common_t ann = tree_common_ann (expr);
1814 return ((ann) ? ann->value_handle : NULL_TREE);
1816 else if (is_gimple_min_invariant (expr))
1817 return expr;
1818 else if (EXPR_P (expr))
1820 tree_ann_common_t ann = tree_common_ann (expr);
1821 return ((ann) ? ann->value_handle : NULL_TREE);
1823 else
1824 gcc_unreachable ();
1827 /* Accessor to tree-ssa-operands.c caches. */
1828 static inline struct ssa_operands *
1829 gimple_ssa_operands (const struct function *fun)
1831 return &fun->gimple_df->ssa_operands;
1834 /* Map describing reference statistics for function FN. */
1835 static inline struct mem_ref_stats_d *
1836 gimple_mem_ref_stats (const struct function *fn)
1838 return &fn->gimple_df->mem_ref_stats;
1840 #endif /* _TREE_FLOW_INLINE_H */