Daily bump.
[official-gcc.git] / gcc / tree-flow-inline.h
blobf19faa1c4ff22adf73433531be733f9f48416424
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);
544 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
545 to the use pointer and stmt of occurrence. */
546 static inline bool
547 single_imm_use (tree var, use_operand_p *use_p, tree *stmt)
549 ssa_use_operand_t *ptr;
551 ptr = &(SSA_NAME_IMM_USE_NODE (var));
552 if (ptr != ptr->next && ptr == ptr->next->next)
554 *use_p = ptr->next;
555 *stmt = ptr->next->stmt;
556 return true;
558 *use_p = NULL_USE_OPERAND_P;
559 *stmt = NULL_TREE;
560 return false;
563 /* Return the number of immediate uses of VAR. */
564 static inline unsigned int
565 num_imm_uses (tree var)
567 ssa_use_operand_t *ptr, *start;
568 unsigned int num;
570 start = &(SSA_NAME_IMM_USE_NODE (var));
571 num = 0;
572 for (ptr = start->next; ptr != start; ptr = ptr->next)
573 num++;
575 return num;
579 /* Return the tree pointer to by USE. */
580 static inline tree
581 get_use_from_ptr (use_operand_p use)
583 return *(use->use);
586 /* Return the tree pointer to by DEF. */
587 static inline tree
588 get_def_from_ptr (def_operand_p def)
590 return *def;
593 /* Return a def_operand_p pointer for the result of PHI. */
594 static inline def_operand_p
595 get_phi_result_ptr (tree phi)
597 return &(PHI_RESULT_TREE (phi));
600 /* Return a use_operand_p pointer for argument I of phinode PHI. */
601 static inline use_operand_p
602 get_phi_arg_def_ptr (tree phi, int i)
604 return &(PHI_ARG_IMM_USE_NODE (phi,i));
608 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
609 no addresses. */
610 static inline bitmap
611 addresses_taken (tree stmt)
613 stmt_ann_t ann = stmt_ann (stmt);
614 return ann ? ann->addresses_taken : NULL;
617 /* Return the PHI nodes for basic block BB, or NULL if there are no
618 PHI nodes. */
619 static inline tree
620 phi_nodes (basic_block bb)
622 return bb->phi_nodes;
625 /* Set list of phi nodes of a basic block BB to L. */
627 static inline void
628 set_phi_nodes (basic_block bb, tree l)
630 tree phi;
632 bb->phi_nodes = l;
633 for (phi = l; phi; phi = PHI_CHAIN (phi))
634 set_bb_for_stmt (phi, bb);
637 /* Return the phi argument which contains the specified use. */
639 static inline int
640 phi_arg_index_from_use (use_operand_p use)
642 struct phi_arg_d *element, *root;
643 int index;
644 tree phi;
646 /* Since the use is the first thing in a PHI argument element, we can
647 calculate its index based on casting it to an argument, and performing
648 pointer arithmetic. */
650 phi = USE_STMT (use);
651 gcc_assert (TREE_CODE (phi) == PHI_NODE);
653 element = (struct phi_arg_d *)use;
654 root = &(PHI_ARG_ELT (phi, 0));
655 index = element - root;
657 #ifdef ENABLE_CHECKING
658 /* Make sure the calculation doesn't have any leftover bytes. If it does,
659 then imm_use is likely not the first element in phi_arg_d. */
660 gcc_assert (
661 (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
662 gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
663 #endif
665 return index;
668 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
670 static inline void
671 set_is_used (tree var)
673 var_ann_t ann = get_var_ann (var);
674 ann->used = 1;
678 /* ----------------------------------------------------------------------- */
680 /* Return true if T is an executable statement. */
681 static inline bool
682 is_exec_stmt (tree t)
684 return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
688 /* Return true if this stmt can be the target of a control transfer stmt such
689 as a goto. */
690 static inline bool
691 is_label_stmt (tree t)
693 if (t)
694 switch (TREE_CODE (t))
696 case LABEL_DECL:
697 case LABEL_EXPR:
698 case CASE_LABEL_EXPR:
699 return true;
700 default:
701 return false;
703 return false;
706 /* PHI nodes should contain only ssa_names and invariants. A test
707 for ssa_name is definitely simpler; don't let invalid contents
708 slip in in the meantime. */
710 static inline bool
711 phi_ssa_name_p (tree t)
713 if (TREE_CODE (t) == SSA_NAME)
714 return true;
715 #ifdef ENABLE_CHECKING
716 gcc_assert (is_gimple_min_invariant (t));
717 #endif
718 return false;
721 /* ----------------------------------------------------------------------- */
723 /* Return a block_stmt_iterator that points to beginning of basic
724 block BB. */
725 static inline block_stmt_iterator
726 bsi_start (basic_block bb)
728 block_stmt_iterator bsi;
729 if (bb->stmt_list)
730 bsi.tsi = tsi_start (bb->stmt_list);
731 else
733 gcc_assert (bb->index < NUM_FIXED_BLOCKS);
734 bsi.tsi.ptr = NULL;
735 bsi.tsi.container = NULL;
737 bsi.bb = bb;
738 return bsi;
741 /* Return a block statement iterator that points to the first non-label
742 statement in block BB. */
744 static inline block_stmt_iterator
745 bsi_after_labels (basic_block bb)
747 block_stmt_iterator bsi = bsi_start (bb);
749 while (!bsi_end_p (bsi) && TREE_CODE (bsi_stmt (bsi)) == LABEL_EXPR)
750 bsi_next (&bsi);
752 return bsi;
755 /* Return a block statement iterator that points to the end of basic
756 block BB. */
757 static inline block_stmt_iterator
758 bsi_last (basic_block bb)
760 block_stmt_iterator bsi;
761 if (bb->stmt_list)
762 bsi.tsi = tsi_last (bb->stmt_list);
763 else
765 gcc_assert (bb->index < NUM_FIXED_BLOCKS);
766 bsi.tsi.ptr = NULL;
767 bsi.tsi.container = NULL;
769 bsi.bb = bb;
770 return bsi;
773 /* Return true if block statement iterator I has reached the end of
774 the basic block. */
775 static inline bool
776 bsi_end_p (block_stmt_iterator i)
778 return tsi_end_p (i.tsi);
781 /* Modify block statement iterator I so that it is at the next
782 statement in the basic block. */
783 static inline void
784 bsi_next (block_stmt_iterator *i)
786 tsi_next (&i->tsi);
789 /* Modify block statement iterator I so that it is at the previous
790 statement in the basic block. */
791 static inline void
792 bsi_prev (block_stmt_iterator *i)
794 tsi_prev (&i->tsi);
797 /* Return the statement that block statement iterator I is currently
798 at. */
799 static inline tree
800 bsi_stmt (block_stmt_iterator i)
802 return tsi_stmt (i.tsi);
805 /* Return a pointer to the statement that block statement iterator I
806 is currently at. */
807 static inline tree *
808 bsi_stmt_ptr (block_stmt_iterator i)
810 return tsi_stmt_ptr (i.tsi);
813 /* Returns the loop of the statement STMT. */
815 static inline struct loop *
816 loop_containing_stmt (tree stmt)
818 basic_block bb = bb_for_stmt (stmt);
819 if (!bb)
820 return NULL;
822 return bb->loop_father;
825 /* Return true if VAR is a clobbered by function calls. */
826 static inline bool
827 is_call_clobbered (tree var)
829 if (!MTAG_P (var))
830 return DECL_CALL_CLOBBERED (var);
831 else
832 return bitmap_bit_p (gimple_call_clobbered_vars (cfun), DECL_UID (var));
835 /* Mark variable VAR as being clobbered by function calls. */
836 static inline void
837 mark_call_clobbered (tree var, unsigned int escape_type)
839 var_ann (var)->escape_mask |= escape_type;
840 if (!MTAG_P (var))
841 DECL_CALL_CLOBBERED (var) = true;
842 bitmap_set_bit (gimple_call_clobbered_vars (cfun), DECL_UID (var));
845 /* Clear the call-clobbered attribute from variable VAR. */
846 static inline void
847 clear_call_clobbered (tree var)
849 var_ann_t ann = var_ann (var);
850 ann->escape_mask = 0;
851 if (MTAG_P (var) && TREE_CODE (var) != STRUCT_FIELD_TAG)
852 MTAG_GLOBAL (var) = 0;
853 if (!MTAG_P (var))
854 DECL_CALL_CLOBBERED (var) = false;
855 bitmap_clear_bit (gimple_call_clobbered_vars (cfun), DECL_UID (var));
858 /* Mark variable VAR as being non-addressable. */
859 static inline void
860 mark_non_addressable (tree var)
862 if (!MTAG_P (var))
863 DECL_CALL_CLOBBERED (var) = false;
864 bitmap_clear_bit (gimple_call_clobbered_vars (cfun), DECL_UID (var));
865 TREE_ADDRESSABLE (var) = 0;
868 /* Return the common annotation for T. Return NULL if the annotation
869 doesn't already exist. */
870 static inline tree_ann_common_t
871 tree_common_ann (tree t)
873 return &t->base.ann->common;
876 /* Return a common annotation for T. Create the constant annotation if it
877 doesn't exist. */
878 static inline tree_ann_common_t
879 get_tree_common_ann (tree t)
881 tree_ann_common_t ann = tree_common_ann (t);
882 return (ann) ? ann : create_tree_common_ann (t);
885 /* ----------------------------------------------------------------------- */
887 /* The following set of routines are used to iterator over various type of
888 SSA operands. */
890 /* Return true if PTR is finished iterating. */
891 static inline bool
892 op_iter_done (ssa_op_iter *ptr)
894 return ptr->done;
897 /* Get the next iterator use value for PTR. */
898 static inline use_operand_p
899 op_iter_next_use (ssa_op_iter *ptr)
901 use_operand_p use_p;
902 #ifdef ENABLE_CHECKING
903 gcc_assert (ptr->iter_type == ssa_op_iter_use);
904 #endif
905 if (ptr->uses)
907 use_p = USE_OP_PTR (ptr->uses);
908 ptr->uses = ptr->uses->next;
909 return use_p;
911 if (ptr->vuses)
913 use_p = VUSE_OP_PTR (ptr->vuses);
914 ptr->vuses = ptr->vuses->next;
915 return use_p;
917 if (ptr->mayuses)
919 use_p = MAYDEF_OP_PTR (ptr->mayuses);
920 ptr->mayuses = ptr->mayuses->next;
921 return use_p;
923 if (ptr->mustkills)
925 use_p = MUSTDEF_KILL_PTR (ptr->mustkills);
926 ptr->mustkills = ptr->mustkills->next;
927 return use_p;
929 if (ptr->phi_i < ptr->num_phi)
931 return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
933 ptr->done = true;
934 return NULL_USE_OPERAND_P;
937 /* Get the next iterator def value for PTR. */
938 static inline def_operand_p
939 op_iter_next_def (ssa_op_iter *ptr)
941 def_operand_p def_p;
942 #ifdef ENABLE_CHECKING
943 gcc_assert (ptr->iter_type == ssa_op_iter_def);
944 #endif
945 if (ptr->defs)
947 def_p = DEF_OP_PTR (ptr->defs);
948 ptr->defs = ptr->defs->next;
949 return def_p;
951 if (ptr->mustdefs)
953 def_p = MUSTDEF_RESULT_PTR (ptr->mustdefs);
954 ptr->mustdefs = ptr->mustdefs->next;
955 return def_p;
957 if (ptr->maydefs)
959 def_p = MAYDEF_RESULT_PTR (ptr->maydefs);
960 ptr->maydefs = ptr->maydefs->next;
961 return def_p;
963 ptr->done = true;
964 return NULL_DEF_OPERAND_P;
967 /* Get the next iterator tree value for PTR. */
968 static inline tree
969 op_iter_next_tree (ssa_op_iter *ptr)
971 tree val;
972 #ifdef ENABLE_CHECKING
973 gcc_assert (ptr->iter_type == ssa_op_iter_tree);
974 #endif
975 if (ptr->uses)
977 val = USE_OP (ptr->uses);
978 ptr->uses = ptr->uses->next;
979 return val;
981 if (ptr->vuses)
983 val = VUSE_OP (ptr->vuses);
984 ptr->vuses = ptr->vuses->next;
985 return val;
987 if (ptr->mayuses)
989 val = MAYDEF_OP (ptr->mayuses);
990 ptr->mayuses = ptr->mayuses->next;
991 return val;
993 if (ptr->mustkills)
995 val = MUSTDEF_KILL (ptr->mustkills);
996 ptr->mustkills = ptr->mustkills->next;
997 return val;
999 if (ptr->defs)
1001 val = DEF_OP (ptr->defs);
1002 ptr->defs = ptr->defs->next;
1003 return val;
1005 if (ptr->mustdefs)
1007 val = MUSTDEF_RESULT (ptr->mustdefs);
1008 ptr->mustdefs = ptr->mustdefs->next;
1009 return val;
1011 if (ptr->maydefs)
1013 val = MAYDEF_RESULT (ptr->maydefs);
1014 ptr->maydefs = ptr->maydefs->next;
1015 return val;
1018 ptr->done = true;
1019 return NULL_TREE;
1024 /* This functions clears the iterator PTR, and marks it done. This is normally
1025 used to prevent warnings in the compile about might be uninitialized
1026 components. */
1028 static inline void
1029 clear_and_done_ssa_iter (ssa_op_iter *ptr)
1031 ptr->defs = NULL;
1032 ptr->uses = NULL;
1033 ptr->vuses = NULL;
1034 ptr->maydefs = NULL;
1035 ptr->mayuses = NULL;
1036 ptr->mustdefs = NULL;
1037 ptr->mustkills = NULL;
1038 ptr->iter_type = ssa_op_iter_none;
1039 ptr->phi_i = 0;
1040 ptr->num_phi = 0;
1041 ptr->phi_stmt = NULL_TREE;
1042 ptr->done = true;
1045 /* Initialize the iterator PTR to the virtual defs in STMT. */
1046 static inline void
1047 op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
1049 #ifdef ENABLE_CHECKING
1050 gcc_assert (stmt_ann (stmt));
1051 #endif
1053 ptr->defs = (flags & SSA_OP_DEF) ? DEF_OPS (stmt) : NULL;
1054 ptr->uses = (flags & SSA_OP_USE) ? USE_OPS (stmt) : NULL;
1055 ptr->vuses = (flags & SSA_OP_VUSE) ? VUSE_OPS (stmt) : NULL;
1056 ptr->maydefs = (flags & SSA_OP_VMAYDEF) ? MAYDEF_OPS (stmt) : NULL;
1057 ptr->mayuses = (flags & SSA_OP_VMAYUSE) ? MAYDEF_OPS (stmt) : NULL;
1058 ptr->mustdefs = (flags & SSA_OP_VMUSTDEF) ? MUSTDEF_OPS (stmt) : NULL;
1059 ptr->mustkills = (flags & SSA_OP_VMUSTKILL) ? MUSTDEF_OPS (stmt) : NULL;
1060 ptr->done = false;
1062 ptr->phi_i = 0;
1063 ptr->num_phi = 0;
1064 ptr->phi_stmt = NULL_TREE;
1067 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1068 the first use. */
1069 static inline use_operand_p
1070 op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
1072 gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0);
1073 op_iter_init (ptr, stmt, flags);
1074 ptr->iter_type = ssa_op_iter_use;
1075 return op_iter_next_use (ptr);
1078 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1079 the first def. */
1080 static inline def_operand_p
1081 op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1083 gcc_assert ((flags & (SSA_OP_ALL_USES | SSA_OP_VIRTUAL_KILLS)) == 0);
1084 op_iter_init (ptr, stmt, flags);
1085 ptr->iter_type = ssa_op_iter_def;
1086 return op_iter_next_def (ptr);
1089 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1090 the first operand as a tree. */
1091 static inline tree
1092 op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1094 op_iter_init (ptr, stmt, flags);
1095 ptr->iter_type = ssa_op_iter_tree;
1096 return op_iter_next_tree (ptr);
1099 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1100 KILL and DEF. */
1101 static inline void
1102 op_iter_next_maymustdef (use_operand_p *use, def_operand_p *def,
1103 ssa_op_iter *ptr)
1105 #ifdef ENABLE_CHECKING
1106 gcc_assert (ptr->iter_type == ssa_op_iter_maymustdef);
1107 #endif
1108 if (ptr->mayuses)
1110 *def = MAYDEF_RESULT_PTR (ptr->mayuses);
1111 *use = MAYDEF_OP_PTR (ptr->mayuses);
1112 ptr->mayuses = ptr->mayuses->next;
1113 return;
1116 if (ptr->mustkills)
1118 *def = MUSTDEF_RESULT_PTR (ptr->mustkills);
1119 *use = MUSTDEF_KILL_PTR (ptr->mustkills);
1120 ptr->mustkills = ptr->mustkills->next;
1121 return;
1124 *def = NULL_DEF_OPERAND_P;
1125 *use = NULL_USE_OPERAND_P;
1126 ptr->done = true;
1127 return;
1131 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1132 in USE and DEF. */
1133 static inline void
1134 op_iter_init_maydef (ssa_op_iter *ptr, tree stmt, use_operand_p *use,
1135 def_operand_p *def)
1137 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1139 op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1140 ptr->iter_type = ssa_op_iter_maymustdef;
1141 op_iter_next_maymustdef (use, def, ptr);
1145 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1146 in KILL and DEF. */
1147 static inline void
1148 op_iter_init_mustdef (ssa_op_iter *ptr, tree stmt, use_operand_p *kill,
1149 def_operand_p *def)
1151 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1153 op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL);
1154 ptr->iter_type = ssa_op_iter_maymustdef;
1155 op_iter_next_maymustdef (kill, def, ptr);
1158 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1159 in KILL and DEF. */
1160 static inline void
1161 op_iter_init_must_and_may_def (ssa_op_iter *ptr, tree stmt,
1162 use_operand_p *kill, def_operand_p *def)
1164 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1166 op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL|SSA_OP_VMAYUSE);
1167 ptr->iter_type = ssa_op_iter_maymustdef;
1168 op_iter_next_maymustdef (kill, def, ptr);
1172 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1173 return NULL. */
1174 static inline tree
1175 single_ssa_tree_operand (tree stmt, int flags)
1177 tree var;
1178 ssa_op_iter iter;
1180 var = op_iter_init_tree (&iter, stmt, flags);
1181 if (op_iter_done (&iter))
1182 return NULL_TREE;
1183 op_iter_next_tree (&iter);
1184 if (op_iter_done (&iter))
1185 return var;
1186 return NULL_TREE;
1190 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1191 return NULL. */
1192 static inline use_operand_p
1193 single_ssa_use_operand (tree stmt, int flags)
1195 use_operand_p var;
1196 ssa_op_iter iter;
1198 var = op_iter_init_use (&iter, stmt, flags);
1199 if (op_iter_done (&iter))
1200 return NULL_USE_OPERAND_P;
1201 op_iter_next_use (&iter);
1202 if (op_iter_done (&iter))
1203 return var;
1204 return NULL_USE_OPERAND_P;
1209 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1210 return NULL. */
1211 static inline def_operand_p
1212 single_ssa_def_operand (tree stmt, int flags)
1214 def_operand_p var;
1215 ssa_op_iter iter;
1217 var = op_iter_init_def (&iter, stmt, flags);
1218 if (op_iter_done (&iter))
1219 return NULL_DEF_OPERAND_P;
1220 op_iter_next_def (&iter);
1221 if (op_iter_done (&iter))
1222 return var;
1223 return NULL_DEF_OPERAND_P;
1227 /* Return true if there are zero operands in STMT matching the type
1228 given in FLAGS. */
1229 static inline bool
1230 zero_ssa_operands (tree stmt, int flags)
1232 ssa_op_iter iter;
1234 op_iter_init_tree (&iter, stmt, flags);
1235 return op_iter_done (&iter);
1239 /* Return the number of operands matching FLAGS in STMT. */
1240 static inline int
1241 num_ssa_operands (tree stmt, int flags)
1243 ssa_op_iter iter;
1244 tree t;
1245 int num = 0;
1247 FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
1248 num++;
1249 return num;
1253 /* Delink all immediate_use information for STMT. */
1254 static inline void
1255 delink_stmt_imm_use (tree stmt)
1257 ssa_op_iter iter;
1258 use_operand_p use_p;
1260 if (ssa_operands_active ())
1261 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter,
1262 (SSA_OP_ALL_USES | SSA_OP_ALL_KILLS))
1263 delink_imm_use (use_p);
1267 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1268 in STMT2. TRUE is returned if they are the same. STMTs can be NULL. */
1269 static inline bool
1270 compare_ssa_operands_equal (tree stmt1, tree stmt2, int flags)
1272 ssa_op_iter iter1, iter2;
1273 tree op1 = NULL_TREE;
1274 tree op2 = NULL_TREE;
1275 bool look1, look2;
1277 if (stmt1 == stmt2)
1278 return true;
1280 look1 = stmt1 && stmt_ann (stmt1);
1281 look2 = stmt2 && stmt_ann (stmt2);
1283 if (look1)
1285 op1 = op_iter_init_tree (&iter1, stmt1, flags);
1286 if (!look2)
1287 return op_iter_done (&iter1);
1289 else
1290 clear_and_done_ssa_iter (&iter1);
1292 if (look2)
1294 op2 = op_iter_init_tree (&iter2, stmt2, flags);
1295 if (!look1)
1296 return op_iter_done (&iter2);
1298 else
1299 clear_and_done_ssa_iter (&iter2);
1301 while (!op_iter_done (&iter1) && !op_iter_done (&iter2))
1303 if (op1 != op2)
1304 return false;
1305 op1 = op_iter_next_tree (&iter1);
1306 op2 = op_iter_next_tree (&iter2);
1309 return (op_iter_done (&iter1) && op_iter_done (&iter2));
1313 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1314 Otherwise return NULL_DEF_OPERAND_P. */
1315 static inline tree
1316 single_phi_def (tree stmt, int flags)
1318 tree def = PHI_RESULT (stmt);
1319 if ((flags & SSA_OP_DEF) && is_gimple_reg (def))
1320 return def;
1321 if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
1322 return def;
1323 return NULL_TREE;
1326 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
1327 be either SSA_OP_USES or SSA_OP_VIRTUAL_USES. */
1328 static inline use_operand_p
1329 op_iter_init_phiuse (ssa_op_iter *ptr, tree phi, int flags)
1331 tree phi_def = PHI_RESULT (phi);
1332 int comp;
1334 clear_and_done_ssa_iter (ptr);
1335 ptr->done = false;
1337 gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
1339 comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1341 /* If the PHI node doesn't the operand type we care about, we're done. */
1342 if ((flags & comp) == 0)
1344 ptr->done = true;
1345 return NULL_USE_OPERAND_P;
1348 ptr->phi_stmt = phi;
1349 ptr->num_phi = PHI_NUM_ARGS (phi);
1350 ptr->iter_type = ssa_op_iter_use;
1351 return op_iter_next_use (ptr);
1355 /* Start an iterator for a PHI definition. */
1357 static inline def_operand_p
1358 op_iter_init_phidef (ssa_op_iter *ptr, tree phi, int flags)
1360 tree phi_def = PHI_RESULT (phi);
1361 int comp;
1363 clear_and_done_ssa_iter (ptr);
1364 ptr->done = false;
1366 gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
1368 comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
1370 /* If the PHI node doesn't the operand type we care about, we're done. */
1371 if ((flags & comp) == 0)
1373 ptr->done = true;
1374 return NULL_USE_OPERAND_P;
1377 ptr->iter_type = ssa_op_iter_def;
1378 /* The first call to op_iter_next_def will terminate the iterator since
1379 all the fields are NULL. Simply return the result here as the first and
1380 therefore only result. */
1381 return PHI_RESULT_PTR (phi);
1384 /* Return true is IMM has reached the end of the immediate use stmt list. */
1386 static inline bool
1387 end_imm_use_stmt_p (imm_use_iterator *imm)
1389 return (imm->imm_use == imm->end_p);
1392 /* Finished the traverse of an immediate use stmt list IMM by removing the
1393 placeholder node from the list. */
1395 static inline void
1396 end_imm_use_stmt_traverse (imm_use_iterator *imm)
1398 delink_imm_use (&(imm->iter_node));
1401 /* Immediate use traversal of uses within a stmt require that all the
1402 uses on a stmt be sequentially listed. This routine is used to build up
1403 this sequential list by adding USE_P to the end of the current list
1404 currently delimited by HEAD and LAST_P. The new LAST_P value is
1405 returned. */
1407 static inline use_operand_p
1408 move_use_after_head (use_operand_p use_p, use_operand_p head,
1409 use_operand_p last_p)
1411 gcc_assert (USE_FROM_PTR (use_p) == USE_FROM_PTR (head));
1412 /* Skip head when we find it. */
1413 if (use_p != head)
1415 /* If use_p is already linked in after last_p, continue. */
1416 if (last_p->next == use_p)
1417 last_p = use_p;
1418 else
1420 /* Delink from current location, and link in at last_p. */
1421 delink_imm_use (use_p);
1422 link_imm_use_to_list (use_p, last_p);
1423 last_p = use_p;
1426 return last_p;
1430 /* This routine will relink all uses with the same stmt as HEAD into the list
1431 immediately following HEAD for iterator IMM. */
1433 static inline void
1434 link_use_stmts_after (use_operand_p head, imm_use_iterator *imm)
1436 use_operand_p use_p;
1437 use_operand_p last_p = head;
1438 tree head_stmt = USE_STMT (head);
1439 tree use = USE_FROM_PTR (head);
1440 ssa_op_iter op_iter;
1441 int flag;
1443 /* Only look at virtual or real uses, depending on the type of HEAD. */
1444 flag = (is_gimple_reg (use) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1446 if (TREE_CODE (head_stmt) == PHI_NODE)
1448 FOR_EACH_PHI_ARG (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 else
1454 FOR_EACH_SSA_USE_OPERAND (use_p, head_stmt, op_iter, flag)
1455 if (USE_FROM_PTR (use_p) == use)
1456 last_p = move_use_after_head (use_p, head, last_p);
1458 /* LInk iter node in after last_p. */
1459 if (imm->iter_node.prev != NULL)
1460 delink_imm_use (&imm->iter_node);
1461 link_imm_use_to_list (&(imm->iter_node), last_p);
1464 /* Initialize IMM to traverse over uses of VAR. Return the first statement. */
1465 static inline tree
1466 first_imm_use_stmt (imm_use_iterator *imm, tree var)
1468 gcc_assert (TREE_CODE (var) == SSA_NAME);
1470 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
1471 imm->imm_use = imm->end_p->next;
1472 imm->next_imm_name = NULL_USE_OPERAND_P;
1474 /* iter_node is used as a marker within the immediate use list to indicate
1475 where the end of the current stmt's uses are. Initialize it to NULL
1476 stmt and use, which indicates a marker node. */
1477 imm->iter_node.prev = NULL_USE_OPERAND_P;
1478 imm->iter_node.next = NULL_USE_OPERAND_P;
1479 imm->iter_node.stmt = NULL_TREE;
1480 imm->iter_node.use = NULL_USE_OPERAND_P;
1482 if (end_imm_use_stmt_p (imm))
1483 return NULL_TREE;
1485 link_use_stmts_after (imm->imm_use, imm);
1487 return USE_STMT (imm->imm_use);
1490 /* Bump IMM to the next stmt which has a use of var. */
1492 static inline tree
1493 next_imm_use_stmt (imm_use_iterator *imm)
1495 imm->imm_use = imm->iter_node.next;
1496 if (end_imm_use_stmt_p (imm))
1498 if (imm->iter_node.prev != NULL)
1499 delink_imm_use (&imm->iter_node);
1500 return NULL_TREE;
1503 link_use_stmts_after (imm->imm_use, imm);
1504 return USE_STMT (imm->imm_use);
1508 /* This routine will return the first use on the stmt IMM currently refers
1509 to. */
1511 static inline use_operand_p
1512 first_imm_use_on_stmt (imm_use_iterator *imm)
1514 imm->next_imm_name = imm->imm_use->next;
1515 return imm->imm_use;
1518 /* Return TRUE if the last use on the stmt IMM refers to has been visited. */
1520 static inline bool
1521 end_imm_use_on_stmt_p (imm_use_iterator *imm)
1523 return (imm->imm_use == &(imm->iter_node));
1526 /* Bump to the next use on the stmt IMM refers to, return NULL if done. */
1528 static inline use_operand_p
1529 next_imm_use_on_stmt (imm_use_iterator *imm)
1531 imm->imm_use = imm->next_imm_name;
1532 if (end_imm_use_on_stmt_p (imm))
1533 return NULL_USE_OPERAND_P;
1534 else
1536 imm->next_imm_name = imm->imm_use->next;
1537 return imm->imm_use;
1541 /* Return true if VAR cannot be modified by the program. */
1543 static inline bool
1544 unmodifiable_var_p (tree var)
1546 if (TREE_CODE (var) == SSA_NAME)
1547 var = SSA_NAME_VAR (var);
1549 if (MTAG_P (var))
1550 return TREE_READONLY (var) && (TREE_STATIC (var) || MTAG_GLOBAL (var));
1552 return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1555 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it. */
1557 static inline bool
1558 array_ref_contains_indirect_ref (tree ref)
1560 gcc_assert (TREE_CODE (ref) == ARRAY_REF);
1562 do {
1563 ref = TREE_OPERAND (ref, 0);
1564 } while (handled_component_p (ref));
1566 return TREE_CODE (ref) == INDIRECT_REF;
1569 /* Return true if REF, a handled component reference, has an ARRAY_REF
1570 somewhere in it. */
1572 static inline bool
1573 ref_contains_array_ref (tree ref)
1575 gcc_assert (handled_component_p (ref));
1577 do {
1578 if (TREE_CODE (ref) == ARRAY_REF)
1579 return true;
1580 ref = TREE_OPERAND (ref, 0);
1581 } while (handled_component_p (ref));
1583 return false;
1586 /* Given a variable VAR, lookup and return a pointer to the list of
1587 subvariables for it. */
1589 static inline subvar_t *
1590 lookup_subvars_for_var (tree var)
1592 var_ann_t ann = var_ann (var);
1593 gcc_assert (ann);
1594 return &ann->subvars;
1597 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1598 NULL, if there are no subvariables. */
1600 static inline subvar_t
1601 get_subvars_for_var (tree var)
1603 subvar_t subvars;
1605 gcc_assert (SSA_VAR_P (var));
1607 if (TREE_CODE (var) == SSA_NAME)
1608 subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
1609 else
1610 subvars = *(lookup_subvars_for_var (var));
1611 return subvars;
1614 /* Return the subvariable of VAR at offset OFFSET. */
1616 static inline tree
1617 get_subvar_at (tree var, unsigned HOST_WIDE_INT offset)
1619 subvar_t sv;
1621 for (sv = get_subvars_for_var (var); sv; sv = sv->next)
1622 if (SFT_OFFSET (sv->var) == offset)
1623 return sv->var;
1625 return NULL_TREE;
1628 /* Return true if V is a tree that we can have subvars for.
1629 Normally, this is any aggregate type. Also complex
1630 types which are not gimple registers can have subvars. */
1632 static inline bool
1633 var_can_have_subvars (tree v)
1635 /* Volatile variables should never have subvars. */
1636 if (TREE_THIS_VOLATILE (v))
1637 return false;
1639 /* Non decls or memory tags can never have subvars. */
1640 if (!DECL_P (v) || MTAG_P (v))
1641 return false;
1643 /* Aggregates can have subvars. */
1644 if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
1645 return true;
1647 /* Complex types variables which are not also a gimple register can
1648 have subvars. */
1649 if (TREE_CODE (TREE_TYPE (v)) == COMPLEX_TYPE
1650 && !DECL_COMPLEX_GIMPLE_REG_P (v))
1651 return true;
1653 return false;
1657 /* Return true if OFFSET and SIZE define a range that overlaps with some
1658 portion of the range of SV, a subvar. If there was an exact overlap,
1659 *EXACT will be set to true upon return. */
1661 static inline bool
1662 overlap_subvar (unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT size,
1663 tree sv, bool *exact)
1665 /* There are three possible cases of overlap.
1666 1. We can have an exact overlap, like so:
1667 |offset, offset + size |
1668 |sv->offset, sv->offset + sv->size |
1670 2. We can have offset starting after sv->offset, like so:
1672 |offset, offset + size |
1673 |sv->offset, sv->offset + sv->size |
1675 3. We can have offset starting before sv->offset, like so:
1677 |offset, offset + size |
1678 |sv->offset, sv->offset + sv->size|
1681 if (exact)
1682 *exact = false;
1683 if (offset == SFT_OFFSET (sv) && size == SFT_SIZE (sv))
1685 if (exact)
1686 *exact = true;
1687 return true;
1689 else if (offset >= SFT_OFFSET (sv)
1690 && offset < (SFT_OFFSET (sv) + SFT_SIZE (sv)))
1692 return true;
1694 else if (offset < SFT_OFFSET (sv)
1695 && (size > SFT_OFFSET (sv) - offset))
1697 return true;
1699 return false;
1703 /* Get the value handle of EXPR. This is the only correct way to get
1704 the value handle for a "thing". If EXPR does not have a value
1705 handle associated, it returns NULL_TREE.
1706 NB: If EXPR is min_invariant, this function is *required* to return
1707 EXPR. */
1709 static inline tree
1710 get_value_handle (tree expr)
1712 if (TREE_CODE (expr) == SSA_NAME)
1713 return SSA_NAME_VALUE (expr);
1714 else if (DECL_P (expr) || TREE_CODE (expr) == TREE_LIST
1715 || TREE_CODE (expr) == CONSTRUCTOR)
1717 tree_ann_common_t ann = tree_common_ann (expr);
1718 return ((ann) ? ann->value_handle : NULL_TREE);
1720 else if (is_gimple_min_invariant (expr))
1721 return expr;
1722 else if (EXPR_P (expr))
1724 tree_ann_common_t ann = tree_common_ann (expr);
1725 return ((ann) ? ann->value_handle : NULL_TREE);
1727 else
1728 gcc_unreachable ();
1731 /* Accessor to tree-ssa-operands.c caches. */
1732 static inline struct ssa_operands *
1733 gimple_ssa_operands (struct function *fun)
1735 return &fun->gimple_df->ssa_operands;
1737 #endif /* _TREE_FLOW_INLINE_H */