Privatize SSA variables into gimple_df.
[official-gcc.git] / gcc / tree-flow-inline.h
blobae937b1c9b93c610d89dd140556f05c509df4d5e
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->common.ann || t->common.ann->common.type == VAR_ANN);
199 return (var_ann_t) t->common.ann;
202 /* Return the variable annotation for T, which must be a _DECL node.
203 Create the variable annotation if it doesn't exist. */
204 static inline var_ann_t
205 get_var_ann (tree var)
207 var_ann_t ann = var_ann (var);
208 return (ann) ? ann : create_var_ann (var);
211 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
212 Return NULL if the function annotation doesn't already exist. */
213 static inline function_ann_t
214 function_ann (tree t)
216 gcc_assert (t);
217 gcc_assert (TREE_CODE (t) == FUNCTION_DECL);
218 gcc_assert (!t->common.ann || t->common.ann->common.type == FUNCTION_ANN);
220 return (function_ann_t) t->common.ann;
223 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
224 Create the function annotation if it doesn't exist. */
225 static inline function_ann_t
226 get_function_ann (tree var)
228 function_ann_t ann = function_ann (var);
229 gcc_assert (!var->common.ann || var->common.ann->common.type == FUNCTION_ANN);
230 return (ann) ? ann : create_function_ann (var);
233 /* Return true if T has a statement annotation attached to it. */
235 static inline bool
236 has_stmt_ann (tree t)
238 #ifdef ENABLE_CHECKING
239 gcc_assert (is_gimple_stmt (t));
240 #endif
241 return t->common.ann && t->common.ann->common.type == STMT_ANN;
244 /* Return the statement annotation for T, which must be a statement
245 node. Return NULL if the statement annotation doesn't exist. */
246 static inline stmt_ann_t
247 stmt_ann (tree t)
249 #ifdef ENABLE_CHECKING
250 gcc_assert (is_gimple_stmt (t));
251 #endif
252 gcc_assert (!t->common.ann || t->common.ann->common.type == STMT_ANN);
253 return (stmt_ann_t) t->common.ann;
256 /* Return the statement annotation for T, which must be a statement
257 node. Create the statement annotation if it doesn't exist. */
258 static inline stmt_ann_t
259 get_stmt_ann (tree stmt)
261 stmt_ann_t ann = stmt_ann (stmt);
262 return (ann) ? ann : create_stmt_ann (stmt);
265 /* Return the annotation type for annotation ANN. */
266 static inline enum tree_ann_type
267 ann_type (tree_ann_t ann)
269 return ann->common.type;
272 /* Return the basic block for statement T. */
273 static inline basic_block
274 bb_for_stmt (tree t)
276 stmt_ann_t ann;
278 if (TREE_CODE (t) == PHI_NODE)
279 return PHI_BB (t);
281 ann = stmt_ann (t);
282 return ann ? ann->bb : NULL;
285 /* Return the may_aliases varray for variable VAR, or NULL if it has
286 no may aliases. */
287 static inline VEC(tree, gc) *
288 may_aliases (tree var)
290 var_ann_t ann = var_ann (var);
291 return ann ? ann->may_aliases : NULL;
294 /* Return the line number for EXPR, or return -1 if we have no line
295 number information for it. */
296 static inline int
297 get_lineno (tree expr)
299 if (expr == NULL_TREE)
300 return -1;
302 if (TREE_CODE (expr) == COMPOUND_EXPR)
303 expr = TREE_OPERAND (expr, 0);
305 if (! EXPR_HAS_LOCATION (expr))
306 return -1;
308 return EXPR_LINENO (expr);
311 /* Return the file name for EXPR, or return "???" if we have no
312 filename information. */
313 static inline const char *
314 get_filename (tree expr)
316 const char *filename;
317 if (expr == NULL_TREE)
318 return "???";
320 if (TREE_CODE (expr) == COMPOUND_EXPR)
321 expr = TREE_OPERAND (expr, 0);
323 if (EXPR_HAS_LOCATION (expr) && (filename = EXPR_FILENAME (expr)))
324 return filename;
325 else
326 return "???";
329 /* Return true if T is a noreturn call. */
330 static inline bool
331 noreturn_call_p (tree t)
333 tree call = get_call_expr_in (t);
334 return call != 0 && (call_expr_flags (call) & ECF_NORETURN) != 0;
337 /* Mark statement T as modified. */
338 static inline void
339 mark_stmt_modified (tree t)
341 stmt_ann_t ann;
342 if (TREE_CODE (t) == PHI_NODE)
343 return;
345 ann = stmt_ann (t);
346 if (ann == NULL)
347 ann = create_stmt_ann (t);
348 else if (noreturn_call_p (t) && cfun->gimple_df)
349 VEC_safe_push (tree, gc, MODIFIED_NORETURN_CALLS (cfun), t);
350 ann->modified = 1;
353 /* Mark statement T as modified, and update it. */
354 static inline void
355 update_stmt (tree t)
357 if (TREE_CODE (t) == PHI_NODE)
358 return;
359 mark_stmt_modified (t);
360 update_stmt_operands (t);
363 static inline void
364 update_stmt_if_modified (tree t)
366 if (stmt_modified_p (t))
367 update_stmt_operands (t);
370 /* Return true if T is marked as modified, false otherwise. */
371 static inline bool
372 stmt_modified_p (tree t)
374 stmt_ann_t ann = stmt_ann (t);
376 /* Note that if the statement doesn't yet have an annotation, we consider it
377 modified. This will force the next call to update_stmt_operands to scan
378 the statement. */
379 return ann ? ann->modified : true;
382 /* Delink an immediate_uses node from its chain. */
383 static inline void
384 delink_imm_use (ssa_use_operand_t *linknode)
386 /* Return if this node is not in a list. */
387 if (linknode->prev == NULL)
388 return;
390 linknode->prev->next = linknode->next;
391 linknode->next->prev = linknode->prev;
392 linknode->prev = NULL;
393 linknode->next = NULL;
396 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
397 static inline void
398 link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
400 /* Link the new node at the head of the list. If we are in the process of
401 traversing the list, we won't visit any new nodes added to it. */
402 linknode->prev = list;
403 linknode->next = list->next;
404 list->next->prev = linknode;
405 list->next = linknode;
408 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
409 static inline void
410 link_imm_use (ssa_use_operand_t *linknode, tree def)
412 ssa_use_operand_t *root;
414 if (!def || TREE_CODE (def) != SSA_NAME)
415 linknode->prev = NULL;
416 else
418 root = &(SSA_NAME_IMM_USE_NODE (def));
419 #ifdef ENABLE_CHECKING
420 if (linknode->use)
421 gcc_assert (*(linknode->use) == def);
422 #endif
423 link_imm_use_to_list (linknode, root);
427 /* Set the value of a use pointed to by USE to VAL. */
428 static inline void
429 set_ssa_use_from_ptr (use_operand_p use, tree val)
431 delink_imm_use (use);
432 *(use->use) = val;
433 link_imm_use (use, val);
436 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
437 in STMT. */
438 static inline void
439 link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, tree stmt)
441 if (stmt)
442 link_imm_use (linknode, def);
443 else
444 link_imm_use (linknode, NULL);
445 linknode->stmt = stmt;
448 /* Relink a new node in place of an old node in the list. */
449 static inline void
450 relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
452 /* The node one had better be in the same list. */
453 gcc_assert (*(old->use) == *(node->use));
454 node->prev = old->prev;
455 node->next = old->next;
456 if (old->prev)
458 old->prev->next = node;
459 old->next->prev = node;
460 /* Remove the old node from the list. */
461 old->prev = NULL;
465 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
466 in STMT. */
467 static inline void
468 relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old, tree stmt)
470 if (stmt)
471 relink_imm_use (linknode, old);
472 else
473 link_imm_use (linknode, NULL);
474 linknode->stmt = stmt;
478 /* Return true is IMM has reached the end of the immediate use list. */
479 static inline bool
480 end_readonly_imm_use_p (imm_use_iterator *imm)
482 return (imm->imm_use == imm->end_p);
485 /* Initialize iterator IMM to process the list for VAR. */
486 static inline use_operand_p
487 first_readonly_imm_use (imm_use_iterator *imm, tree var)
489 gcc_assert (TREE_CODE (var) == SSA_NAME);
491 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
492 imm->imm_use = imm->end_p->next;
493 #ifdef ENABLE_CHECKING
494 imm->iter_node.next = imm->imm_use->next;
495 #endif
496 if (end_readonly_imm_use_p (imm))
497 return NULL_USE_OPERAND_P;
498 return imm->imm_use;
501 /* Bump IMM to the next use in the list. */
502 static inline use_operand_p
503 next_readonly_imm_use (imm_use_iterator *imm)
505 use_operand_p old = imm->imm_use;
507 #ifdef ENABLE_CHECKING
508 /* If this assertion fails, it indicates the 'next' pointer has changed
509 since we the last bump. This indicates that the list is being modified
510 via stmt changes, or SET_USE, or somesuch thing, and you need to be
511 using the SAFE version of the iterator. */
512 gcc_assert (imm->iter_node.next == old->next);
513 imm->iter_node.next = old->next->next;
514 #endif
516 imm->imm_use = old->next;
517 if (end_readonly_imm_use_p (imm))
518 return old;
519 return imm->imm_use;
522 /* Return true if VAR has no uses. */
523 static inline bool
524 has_zero_uses (tree var)
526 ssa_use_operand_t *ptr;
527 ptr = &(SSA_NAME_IMM_USE_NODE (var));
528 /* A single use means there is no items in the list. */
529 return (ptr == ptr->next);
532 /* Return true if VAR has a single use. */
533 static inline bool
534 has_single_use (tree var)
536 ssa_use_operand_t *ptr;
537 ptr = &(SSA_NAME_IMM_USE_NODE (var));
538 /* A single use means there is one item in the list. */
539 return (ptr != ptr->next && ptr == ptr->next->next);
542 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
543 to the use pointer and stmt of occurrence. */
544 static inline bool
545 single_imm_use (tree var, use_operand_p *use_p, tree *stmt)
547 ssa_use_operand_t *ptr;
549 ptr = &(SSA_NAME_IMM_USE_NODE (var));
550 if (ptr != ptr->next && ptr == ptr->next->next)
552 *use_p = ptr->next;
553 *stmt = ptr->next->stmt;
554 return true;
556 *use_p = NULL_USE_OPERAND_P;
557 *stmt = NULL_TREE;
558 return false;
561 /* Return the number of immediate uses of VAR. */
562 static inline unsigned int
563 num_imm_uses (tree var)
565 ssa_use_operand_t *ptr, *start;
566 unsigned int num;
568 start = &(SSA_NAME_IMM_USE_NODE (var));
569 num = 0;
570 for (ptr = start->next; ptr != start; ptr = ptr->next)
571 num++;
573 return num;
577 /* Return the tree pointer to by USE. */
578 static inline tree
579 get_use_from_ptr (use_operand_p use)
581 return *(use->use);
584 /* Return the tree pointer to by DEF. */
585 static inline tree
586 get_def_from_ptr (def_operand_p def)
588 return *def;
591 /* Return a def_operand_p pointer for the result of PHI. */
592 static inline def_operand_p
593 get_phi_result_ptr (tree phi)
595 return &(PHI_RESULT_TREE (phi));
598 /* Return a use_operand_p pointer for argument I of phinode PHI. */
599 static inline use_operand_p
600 get_phi_arg_def_ptr (tree phi, int i)
602 return &(PHI_ARG_IMM_USE_NODE (phi,i));
606 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
607 no addresses. */
608 static inline bitmap
609 addresses_taken (tree stmt)
611 stmt_ann_t ann = stmt_ann (stmt);
612 return ann ? ann->addresses_taken : NULL;
615 /* Return the PHI nodes for basic block BB, or NULL if there are no
616 PHI nodes. */
617 static inline tree
618 phi_nodes (basic_block bb)
620 return bb->phi_nodes;
623 /* Set list of phi nodes of a basic block BB to L. */
625 static inline void
626 set_phi_nodes (basic_block bb, tree l)
628 tree phi;
630 bb->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 /* ----------------------------------------------------------------------- */
678 /* Return true if T is an executable statement. */
679 static inline bool
680 is_exec_stmt (tree t)
682 return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
686 /* Return true if this stmt can be the target of a control transfer stmt such
687 as a goto. */
688 static inline bool
689 is_label_stmt (tree t)
691 if (t)
692 switch (TREE_CODE (t))
694 case LABEL_DECL:
695 case LABEL_EXPR:
696 case CASE_LABEL_EXPR:
697 return true;
698 default:
699 return false;
701 return false;
704 /* PHI nodes should contain only ssa_names and invariants. A test
705 for ssa_name is definitely simpler; don't let invalid contents
706 slip in in the meantime. */
708 static inline bool
709 phi_ssa_name_p (tree t)
711 if (TREE_CODE (t) == SSA_NAME)
712 return true;
713 #ifdef ENABLE_CHECKING
714 gcc_assert (is_gimple_min_invariant (t));
715 #endif
716 return false;
719 /* ----------------------------------------------------------------------- */
721 /* Return a block_stmt_iterator that points to beginning of basic
722 block BB. */
723 static inline block_stmt_iterator
724 bsi_start (basic_block bb)
726 block_stmt_iterator bsi;
727 if (bb->stmt_list)
728 bsi.tsi = tsi_start (bb->stmt_list);
729 else
731 gcc_assert (bb->index < NUM_FIXED_BLOCKS);
732 bsi.tsi.ptr = NULL;
733 bsi.tsi.container = NULL;
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;
759 if (bb->stmt_list)
760 bsi.tsi = tsi_last (bb->stmt_list);
761 else
763 gcc_assert (bb->index < NUM_FIXED_BLOCKS);
764 bsi.tsi.ptr = NULL;
765 bsi.tsi.container = NULL;
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;
823 /* Return true if VAR is a clobbered by function calls. */
824 static inline bool
825 is_call_clobbered (tree var)
827 if (!MTAG_P (var))
828 return DECL_CALL_CLOBBERED (var);
829 else
830 return bitmap_bit_p (gimple_call_clobbered_vars (cfun), DECL_UID (var));
833 /* Mark variable VAR as being clobbered by function calls. */
834 static inline void
835 mark_call_clobbered (tree var, unsigned int escape_type)
837 var_ann (var)->escape_mask |= escape_type;
838 if (!MTAG_P (var))
839 DECL_CALL_CLOBBERED (var) = true;
840 bitmap_set_bit (gimple_call_clobbered_vars (cfun), DECL_UID (var));
843 /* Clear the call-clobbered attribute from variable VAR. */
844 static inline void
845 clear_call_clobbered (tree var)
847 var_ann_t ann = var_ann (var);
848 ann->escape_mask = 0;
849 if (MTAG_P (var) && TREE_CODE (var) != STRUCT_FIELD_TAG)
850 MTAG_GLOBAL (var) = 0;
851 if (!MTAG_P (var))
852 DECL_CALL_CLOBBERED (var) = false;
853 bitmap_clear_bit (gimple_call_clobbered_vars (cfun), DECL_UID (var));
856 /* Mark variable VAR as being non-addressable. */
857 static inline void
858 mark_non_addressable (tree var)
860 if (!MTAG_P (var))
861 DECL_CALL_CLOBBERED (var) = false;
862 bitmap_clear_bit (gimple_call_clobbered_vars (cfun), DECL_UID (var));
863 TREE_ADDRESSABLE (var) = 0;
866 /* Return the common annotation for T. Return NULL if the annotation
867 doesn't already exist. */
868 static inline tree_ann_common_t
869 tree_common_ann (tree t)
871 return &t->common.ann->common;
874 /* Return a common annotation for T. Create the constant annotation if it
875 doesn't exist. */
876 static inline tree_ann_common_t
877 get_tree_common_ann (tree t)
879 tree_ann_common_t ann = tree_common_ann (t);
880 return (ann) ? ann : create_tree_common_ann (t);
883 /* ----------------------------------------------------------------------- */
885 /* The following set of routines are used to iterator over various type of
886 SSA operands. */
888 /* Return true if PTR is finished iterating. */
889 static inline bool
890 op_iter_done (ssa_op_iter *ptr)
892 return ptr->done;
895 /* Get the next iterator use value for PTR. */
896 static inline use_operand_p
897 op_iter_next_use (ssa_op_iter *ptr)
899 use_operand_p use_p;
900 #ifdef ENABLE_CHECKING
901 gcc_assert (ptr->iter_type == ssa_op_iter_use);
902 #endif
903 if (ptr->uses)
905 use_p = USE_OP_PTR (ptr->uses);
906 ptr->uses = ptr->uses->next;
907 return use_p;
909 if (ptr->vuses)
911 use_p = VUSE_OP_PTR (ptr->vuses);
912 ptr->vuses = ptr->vuses->next;
913 return use_p;
915 if (ptr->mayuses)
917 use_p = MAYDEF_OP_PTR (ptr->mayuses);
918 ptr->mayuses = ptr->mayuses->next;
919 return use_p;
921 if (ptr->mustkills)
923 use_p = MUSTDEF_KILL_PTR (ptr->mustkills);
924 ptr->mustkills = ptr->mustkills->next;
925 return use_p;
927 if (ptr->phi_i < ptr->num_phi)
929 return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
931 ptr->done = true;
932 return NULL_USE_OPERAND_P;
935 /* Get the next iterator def value for PTR. */
936 static inline def_operand_p
937 op_iter_next_def (ssa_op_iter *ptr)
939 def_operand_p def_p;
940 #ifdef ENABLE_CHECKING
941 gcc_assert (ptr->iter_type == ssa_op_iter_def);
942 #endif
943 if (ptr->defs)
945 def_p = DEF_OP_PTR (ptr->defs);
946 ptr->defs = ptr->defs->next;
947 return def_p;
949 if (ptr->mustdefs)
951 def_p = MUSTDEF_RESULT_PTR (ptr->mustdefs);
952 ptr->mustdefs = ptr->mustdefs->next;
953 return def_p;
955 if (ptr->maydefs)
957 def_p = MAYDEF_RESULT_PTR (ptr->maydefs);
958 ptr->maydefs = ptr->maydefs->next;
959 return def_p;
961 ptr->done = true;
962 return NULL_DEF_OPERAND_P;
965 /* Get the next iterator tree value for PTR. */
966 static inline tree
967 op_iter_next_tree (ssa_op_iter *ptr)
969 tree val;
970 #ifdef ENABLE_CHECKING
971 gcc_assert (ptr->iter_type == ssa_op_iter_tree);
972 #endif
973 if (ptr->uses)
975 val = USE_OP (ptr->uses);
976 ptr->uses = ptr->uses->next;
977 return val;
979 if (ptr->vuses)
981 val = VUSE_OP (ptr->vuses);
982 ptr->vuses = ptr->vuses->next;
983 return val;
985 if (ptr->mayuses)
987 val = MAYDEF_OP (ptr->mayuses);
988 ptr->mayuses = ptr->mayuses->next;
989 return val;
991 if (ptr->mustkills)
993 val = MUSTDEF_KILL (ptr->mustkills);
994 ptr->mustkills = ptr->mustkills->next;
995 return val;
997 if (ptr->defs)
999 val = DEF_OP (ptr->defs);
1000 ptr->defs = ptr->defs->next;
1001 return val;
1003 if (ptr->mustdefs)
1005 val = MUSTDEF_RESULT (ptr->mustdefs);
1006 ptr->mustdefs = ptr->mustdefs->next;
1007 return val;
1009 if (ptr->maydefs)
1011 val = MAYDEF_RESULT (ptr->maydefs);
1012 ptr->maydefs = ptr->maydefs->next;
1013 return val;
1016 ptr->done = true;
1017 return NULL_TREE;
1022 /* This functions clears the iterator PTR, and marks it done. This is normally
1023 used to prevent warnings in the compile about might be uninitialized
1024 components. */
1026 static inline void
1027 clear_and_done_ssa_iter (ssa_op_iter *ptr)
1029 ptr->defs = NULL;
1030 ptr->uses = NULL;
1031 ptr->vuses = NULL;
1032 ptr->maydefs = NULL;
1033 ptr->mayuses = NULL;
1034 ptr->mustdefs = NULL;
1035 ptr->mustkills = NULL;
1036 ptr->iter_type = ssa_op_iter_none;
1037 ptr->phi_i = 0;
1038 ptr->num_phi = 0;
1039 ptr->phi_stmt = NULL_TREE;
1040 ptr->done = true;
1043 /* Initialize the iterator PTR to the virtual defs in STMT. */
1044 static inline void
1045 op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
1047 #ifdef ENABLE_CHECKING
1048 gcc_assert (stmt_ann (stmt));
1049 #endif
1051 ptr->defs = (flags & SSA_OP_DEF) ? DEF_OPS (stmt) : NULL;
1052 ptr->uses = (flags & SSA_OP_USE) ? USE_OPS (stmt) : NULL;
1053 ptr->vuses = (flags & SSA_OP_VUSE) ? VUSE_OPS (stmt) : NULL;
1054 ptr->maydefs = (flags & SSA_OP_VMAYDEF) ? MAYDEF_OPS (stmt) : NULL;
1055 ptr->mayuses = (flags & SSA_OP_VMAYUSE) ? MAYDEF_OPS (stmt) : NULL;
1056 ptr->mustdefs = (flags & SSA_OP_VMUSTDEF) ? MUSTDEF_OPS (stmt) : NULL;
1057 ptr->mustkills = (flags & SSA_OP_VMUSTKILL) ? MUSTDEF_OPS (stmt) : NULL;
1058 ptr->done = false;
1060 ptr->phi_i = 0;
1061 ptr->num_phi = 0;
1062 ptr->phi_stmt = NULL_TREE;
1065 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1066 the first use. */
1067 static inline use_operand_p
1068 op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
1070 gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0);
1071 op_iter_init (ptr, stmt, flags);
1072 ptr->iter_type = ssa_op_iter_use;
1073 return op_iter_next_use (ptr);
1076 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1077 the first def. */
1078 static inline def_operand_p
1079 op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1081 gcc_assert ((flags & (SSA_OP_ALL_USES | SSA_OP_VIRTUAL_KILLS)) == 0);
1082 op_iter_init (ptr, stmt, flags);
1083 ptr->iter_type = ssa_op_iter_def;
1084 return op_iter_next_def (ptr);
1087 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1088 the first operand as a tree. */
1089 static inline tree
1090 op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1092 op_iter_init (ptr, stmt, flags);
1093 ptr->iter_type = ssa_op_iter_tree;
1094 return op_iter_next_tree (ptr);
1097 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1098 KILL and DEF. */
1099 static inline void
1100 op_iter_next_maymustdef (use_operand_p *use, def_operand_p *def,
1101 ssa_op_iter *ptr)
1103 #ifdef ENABLE_CHECKING
1104 gcc_assert (ptr->iter_type == ssa_op_iter_maymustdef);
1105 #endif
1106 if (ptr->mayuses)
1108 *def = MAYDEF_RESULT_PTR (ptr->mayuses);
1109 *use = MAYDEF_OP_PTR (ptr->mayuses);
1110 ptr->mayuses = ptr->mayuses->next;
1111 return;
1114 if (ptr->mustkills)
1116 *def = MUSTDEF_RESULT_PTR (ptr->mustkills);
1117 *use = MUSTDEF_KILL_PTR (ptr->mustkills);
1118 ptr->mustkills = ptr->mustkills->next;
1119 return;
1122 *def = NULL_DEF_OPERAND_P;
1123 *use = NULL_USE_OPERAND_P;
1124 ptr->done = true;
1125 return;
1129 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1130 in USE and DEF. */
1131 static inline void
1132 op_iter_init_maydef (ssa_op_iter *ptr, tree stmt, use_operand_p *use,
1133 def_operand_p *def)
1135 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1137 op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1138 ptr->iter_type = ssa_op_iter_maymustdef;
1139 op_iter_next_maymustdef (use, def, ptr);
1143 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1144 in KILL and DEF. */
1145 static inline void
1146 op_iter_init_mustdef (ssa_op_iter *ptr, tree stmt, use_operand_p *kill,
1147 def_operand_p *def)
1149 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1151 op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL);
1152 ptr->iter_type = ssa_op_iter_maymustdef;
1153 op_iter_next_maymustdef (kill, def, ptr);
1156 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1157 in KILL and DEF. */
1158 static inline void
1159 op_iter_init_must_and_may_def (ssa_op_iter *ptr, tree stmt,
1160 use_operand_p *kill, def_operand_p *def)
1162 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1164 op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL|SSA_OP_VMAYUSE);
1165 ptr->iter_type = ssa_op_iter_maymustdef;
1166 op_iter_next_maymustdef (kill, def, ptr);
1170 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1171 return NULL. */
1172 static inline tree
1173 single_ssa_tree_operand (tree stmt, int flags)
1175 tree var;
1176 ssa_op_iter iter;
1178 var = op_iter_init_tree (&iter, stmt, flags);
1179 if (op_iter_done (&iter))
1180 return NULL_TREE;
1181 op_iter_next_tree (&iter);
1182 if (op_iter_done (&iter))
1183 return var;
1184 return NULL_TREE;
1188 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1189 return NULL. */
1190 static inline use_operand_p
1191 single_ssa_use_operand (tree stmt, int flags)
1193 use_operand_p var;
1194 ssa_op_iter iter;
1196 var = op_iter_init_use (&iter, stmt, flags);
1197 if (op_iter_done (&iter))
1198 return NULL_USE_OPERAND_P;
1199 op_iter_next_use (&iter);
1200 if (op_iter_done (&iter))
1201 return var;
1202 return NULL_USE_OPERAND_P;
1207 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1208 return NULL. */
1209 static inline def_operand_p
1210 single_ssa_def_operand (tree stmt, int flags)
1212 def_operand_p var;
1213 ssa_op_iter iter;
1215 var = op_iter_init_def (&iter, stmt, flags);
1216 if (op_iter_done (&iter))
1217 return NULL_DEF_OPERAND_P;
1218 op_iter_next_def (&iter);
1219 if (op_iter_done (&iter))
1220 return var;
1221 return NULL_DEF_OPERAND_P;
1225 /* Return true if there are zero operands in STMT matching the type
1226 given in FLAGS. */
1227 static inline bool
1228 zero_ssa_operands (tree stmt, int flags)
1230 ssa_op_iter iter;
1232 op_iter_init_tree (&iter, stmt, flags);
1233 return op_iter_done (&iter);
1237 /* Return the number of operands matching FLAGS in STMT. */
1238 static inline int
1239 num_ssa_operands (tree stmt, int flags)
1241 ssa_op_iter iter;
1242 tree t;
1243 int num = 0;
1245 FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
1246 num++;
1247 return num;
1251 /* Delink all immediate_use information for STMT. */
1252 static inline void
1253 delink_stmt_imm_use (tree stmt)
1255 ssa_op_iter iter;
1256 use_operand_p use_p;
1258 if (ssa_operands_active ())
1259 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter,
1260 (SSA_OP_ALL_USES | SSA_OP_ALL_KILLS))
1261 delink_imm_use (use_p);
1265 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1266 in STMT2. TRUE is returned if they are the same. STMTs can be NULL. */
1267 static inline bool
1268 compare_ssa_operands_equal (tree stmt1, tree stmt2, int flags)
1270 ssa_op_iter iter1, iter2;
1271 tree op1 = NULL_TREE;
1272 tree op2 = NULL_TREE;
1273 bool look1, look2;
1275 if (stmt1 == stmt2)
1276 return true;
1278 look1 = stmt1 && stmt_ann (stmt1);
1279 look2 = stmt2 && stmt_ann (stmt2);
1281 if (look1)
1283 op1 = op_iter_init_tree (&iter1, stmt1, flags);
1284 if (!look2)
1285 return op_iter_done (&iter1);
1287 else
1288 clear_and_done_ssa_iter (&iter1);
1290 if (look2)
1292 op2 = op_iter_init_tree (&iter2, stmt2, flags);
1293 if (!look1)
1294 return op_iter_done (&iter2);
1296 else
1297 clear_and_done_ssa_iter (&iter2);
1299 while (!op_iter_done (&iter1) && !op_iter_done (&iter2))
1301 if (op1 != op2)
1302 return false;
1303 op1 = op_iter_next_tree (&iter1);
1304 op2 = op_iter_next_tree (&iter2);
1307 return (op_iter_done (&iter1) && op_iter_done (&iter2));
1311 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1312 Otherwise return NULL_DEF_OPERAND_P. */
1313 static inline tree
1314 single_phi_def (tree stmt, int flags)
1316 tree def = PHI_RESULT (stmt);
1317 if ((flags & SSA_OP_DEF) && is_gimple_reg (def))
1318 return def;
1319 if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
1320 return def;
1321 return NULL_TREE;
1324 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
1325 be either SSA_OP_USES or SSA_OP_VIRTUAL_USES. */
1326 static inline use_operand_p
1327 op_iter_init_phiuse (ssa_op_iter *ptr, tree phi, int flags)
1329 tree phi_def = PHI_RESULT (phi);
1330 int comp;
1332 clear_and_done_ssa_iter (ptr);
1333 ptr->done = false;
1335 gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
1337 comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1339 /* If the PHI node doesn't the operand type we care about, we're done. */
1340 if ((flags & comp) == 0)
1342 ptr->done = true;
1343 return NULL_USE_OPERAND_P;
1346 ptr->phi_stmt = phi;
1347 ptr->num_phi = PHI_NUM_ARGS (phi);
1348 ptr->iter_type = ssa_op_iter_use;
1349 return op_iter_next_use (ptr);
1353 /* Start an iterator for a PHI definition. */
1355 static inline def_operand_p
1356 op_iter_init_phidef (ssa_op_iter *ptr, tree phi, int flags)
1358 tree phi_def = PHI_RESULT (phi);
1359 int comp;
1361 clear_and_done_ssa_iter (ptr);
1362 ptr->done = false;
1364 gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
1366 comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
1368 /* If the PHI node doesn't the operand type we care about, we're done. */
1369 if ((flags & comp) == 0)
1371 ptr->done = true;
1372 return NULL_USE_OPERAND_P;
1375 ptr->iter_type = ssa_op_iter_def;
1376 /* The first call to op_iter_next_def will terminate the iterator since
1377 all the fields are NULL. Simply return the result here as the first and
1378 therefore only result. */
1379 return PHI_RESULT_PTR (phi);
1382 /* Return true is IMM has reached the end of the immediate use stmt list. */
1384 static inline bool
1385 end_imm_use_stmt_p (imm_use_iterator *imm)
1387 return (imm->imm_use == imm->end_p);
1390 /* Finished the traverse of an immediate use stmt list IMM by removing the
1391 placeholder node from the list. */
1393 static inline void
1394 end_imm_use_stmt_traverse (imm_use_iterator *imm)
1396 delink_imm_use (&(imm->iter_node));
1399 /* Immediate use traversal of uses within a stmt require that all the
1400 uses on a stmt be sequentially listed. This routine is used to build up
1401 this sequential list by adding USE_P to the end of the current list
1402 currently delimited by HEAD and LAST_P. The new LAST_P value is
1403 returned. */
1405 static inline use_operand_p
1406 move_use_after_head (use_operand_p use_p, use_operand_p head,
1407 use_operand_p last_p)
1409 gcc_assert (USE_FROM_PTR (use_p) == USE_FROM_PTR (head));
1410 /* Skip head when we find it. */
1411 if (use_p != head)
1413 /* If use_p is already linked in after last_p, continue. */
1414 if (last_p->next == use_p)
1415 last_p = use_p;
1416 else
1418 /* Delink from current location, and link in at last_p. */
1419 delink_imm_use (use_p);
1420 link_imm_use_to_list (use_p, last_p);
1421 last_p = use_p;
1424 return last_p;
1428 /* This routine will relink all uses with the same stmt as HEAD into the list
1429 immediately following HEAD for iterator IMM. */
1431 static inline void
1432 link_use_stmts_after (use_operand_p head, imm_use_iterator *imm)
1434 use_operand_p use_p;
1435 use_operand_p last_p = head;
1436 tree head_stmt = USE_STMT (head);
1437 tree use = USE_FROM_PTR (head);
1438 ssa_op_iter op_iter;
1439 int flag;
1441 /* Only look at virtual or real uses, depending on the type of HEAD. */
1442 flag = (is_gimple_reg (use) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1444 if (TREE_CODE (head_stmt) == PHI_NODE)
1446 FOR_EACH_PHI_ARG (use_p, head_stmt, op_iter, flag)
1447 if (USE_FROM_PTR (use_p) == use)
1448 last_p = move_use_after_head (use_p, head, last_p);
1450 else
1452 FOR_EACH_SSA_USE_OPERAND (use_p, head_stmt, op_iter, flag)
1453 if (USE_FROM_PTR (use_p) == use)
1454 last_p = move_use_after_head (use_p, head, last_p);
1456 /* LInk iter node in after last_p. */
1457 if (imm->iter_node.prev != NULL)
1458 delink_imm_use (&imm->iter_node);
1459 link_imm_use_to_list (&(imm->iter_node), last_p);
1462 /* Initialize IMM to traverse over uses of VAR. Return the first statement. */
1463 static inline tree
1464 first_imm_use_stmt (imm_use_iterator *imm, tree var)
1466 gcc_assert (TREE_CODE (var) == SSA_NAME);
1468 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
1469 imm->imm_use = imm->end_p->next;
1470 imm->next_imm_name = NULL_USE_OPERAND_P;
1472 /* iter_node is used as a marker within the immediate use list to indicate
1473 where the end of the current stmt's uses are. Initialize it to NULL
1474 stmt and use, which indicates a marker node. */
1475 imm->iter_node.prev = NULL_USE_OPERAND_P;
1476 imm->iter_node.next = NULL_USE_OPERAND_P;
1477 imm->iter_node.stmt = NULL_TREE;
1478 imm->iter_node.use = NULL_USE_OPERAND_P;
1480 if (end_imm_use_stmt_p (imm))
1481 return NULL_TREE;
1483 link_use_stmts_after (imm->imm_use, imm);
1485 return USE_STMT (imm->imm_use);
1488 /* Bump IMM to the next stmt which has a use of var. */
1490 static inline tree
1491 next_imm_use_stmt (imm_use_iterator *imm)
1493 imm->imm_use = imm->iter_node.next;
1494 if (end_imm_use_stmt_p (imm))
1496 if (imm->iter_node.prev != NULL)
1497 delink_imm_use (&imm->iter_node);
1498 return NULL_TREE;
1501 link_use_stmts_after (imm->imm_use, imm);
1502 return USE_STMT (imm->imm_use);
1506 /* This routine will return the first use on the stmt IMM currently refers
1507 to. */
1509 static inline use_operand_p
1510 first_imm_use_on_stmt (imm_use_iterator *imm)
1512 imm->next_imm_name = imm->imm_use->next;
1513 return imm->imm_use;
1516 /* Return TRUE if the last use on the stmt IMM refers to has been visited. */
1518 static inline bool
1519 end_imm_use_on_stmt_p (imm_use_iterator *imm)
1521 return (imm->imm_use == &(imm->iter_node));
1524 /* Bump to the next use on the stmt IMM refers to, return NULL if done. */
1526 static inline use_operand_p
1527 next_imm_use_on_stmt (imm_use_iterator *imm)
1529 imm->imm_use = imm->next_imm_name;
1530 if (end_imm_use_on_stmt_p (imm))
1531 return NULL_USE_OPERAND_P;
1532 else
1534 imm->next_imm_name = imm->imm_use->next;
1535 return imm->imm_use;
1539 /* Return true if VAR cannot be modified by the program. */
1541 static inline bool
1542 unmodifiable_var_p (tree var)
1544 if (TREE_CODE (var) == SSA_NAME)
1545 var = SSA_NAME_VAR (var);
1547 if (MTAG_P (var))
1548 return TREE_READONLY (var) && (TREE_STATIC (var) || MTAG_GLOBAL (var));
1550 return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1553 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it. */
1555 static inline bool
1556 array_ref_contains_indirect_ref (tree ref)
1558 gcc_assert (TREE_CODE (ref) == ARRAY_REF);
1560 do {
1561 ref = TREE_OPERAND (ref, 0);
1562 } while (handled_component_p (ref));
1564 return TREE_CODE (ref) == INDIRECT_REF;
1567 /* Return true if REF, a handled component reference, has an ARRAY_REF
1568 somewhere in it. */
1570 static inline bool
1571 ref_contains_array_ref (tree ref)
1573 gcc_assert (handled_component_p (ref));
1575 do {
1576 if (TREE_CODE (ref) == ARRAY_REF)
1577 return true;
1578 ref = TREE_OPERAND (ref, 0);
1579 } while (handled_component_p (ref));
1581 return false;
1584 /* Given a variable VAR, lookup and return a pointer to the list of
1585 subvariables for it. */
1587 static inline subvar_t *
1588 lookup_subvars_for_var (tree var)
1590 var_ann_t ann = var_ann (var);
1591 gcc_assert (ann);
1592 return &ann->subvars;
1595 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1596 NULL, if there are no subvariables. */
1598 static inline subvar_t
1599 get_subvars_for_var (tree var)
1601 subvar_t subvars;
1603 gcc_assert (SSA_VAR_P (var));
1605 if (TREE_CODE (var) == SSA_NAME)
1606 subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
1607 else
1608 subvars = *(lookup_subvars_for_var (var));
1609 return subvars;
1612 /* Return the subvariable of VAR at offset OFFSET. */
1614 static inline tree
1615 get_subvar_at (tree var, unsigned HOST_WIDE_INT offset)
1617 subvar_t sv;
1619 for (sv = get_subvars_for_var (var); sv; sv = sv->next)
1620 if (SFT_OFFSET (sv->var) == offset)
1621 return sv->var;
1623 return NULL_TREE;
1626 /* Return true if V is a tree that we can have subvars for.
1627 Normally, this is any aggregate type. Also complex
1628 types which are not gimple registers can have subvars. */
1630 static inline bool
1631 var_can_have_subvars (tree v)
1633 /* Volatile variables should never have subvars. */
1634 if (TREE_THIS_VOLATILE (v))
1635 return false;
1637 /* Non decls or memory tags can never have subvars. */
1638 if (!DECL_P (v) || MTAG_P (v))
1639 return false;
1641 /* Aggregates can have subvars. */
1642 if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
1643 return true;
1645 /* Complex types variables which are not also a gimple register can
1646 have subvars. */
1647 if (TREE_CODE (TREE_TYPE (v)) == COMPLEX_TYPE
1648 && !DECL_COMPLEX_GIMPLE_REG_P (v))
1649 return true;
1651 return false;
1655 /* Return true if OFFSET and SIZE define a range that overlaps with some
1656 portion of the range of SV, a subvar. If there was an exact overlap,
1657 *EXACT will be set to true upon return. */
1659 static inline bool
1660 overlap_subvar (unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT size,
1661 tree sv, bool *exact)
1663 /* There are three possible cases of overlap.
1664 1. We can have an exact overlap, like so:
1665 |offset, offset + size |
1666 |sv->offset, sv->offset + sv->size |
1668 2. We can have offset starting after sv->offset, like so:
1670 |offset, offset + size |
1671 |sv->offset, sv->offset + sv->size |
1673 3. We can have offset starting before sv->offset, like so:
1675 |offset, offset + size |
1676 |sv->offset, sv->offset + sv->size|
1679 if (exact)
1680 *exact = false;
1681 if (offset == SFT_OFFSET (sv) && size == SFT_SIZE (sv))
1683 if (exact)
1684 *exact = true;
1685 return true;
1687 else if (offset >= SFT_OFFSET (sv)
1688 && offset < (SFT_OFFSET (sv) + SFT_SIZE (sv)))
1690 return true;
1692 else if (offset < SFT_OFFSET (sv)
1693 && (size > SFT_OFFSET (sv) - offset))
1695 return true;
1697 return false;
1701 /* Get the value handle of EXPR. This is the only correct way to get
1702 the value handle for a "thing". If EXPR does not have a value
1703 handle associated, it returns NULL_TREE.
1704 NB: If EXPR is min_invariant, this function is *required* to return
1705 EXPR. */
1707 static inline tree
1708 get_value_handle (tree expr)
1710 if (TREE_CODE (expr) == SSA_NAME)
1711 return SSA_NAME_VALUE (expr);
1712 else if (DECL_P (expr) || TREE_CODE (expr) == TREE_LIST
1713 || TREE_CODE (expr) == CONSTRUCTOR)
1715 tree_ann_common_t ann = tree_common_ann (expr);
1716 return ((ann) ? ann->value_handle : NULL_TREE);
1718 else if (is_gimple_min_invariant (expr))
1719 return expr;
1720 else if (EXPR_P (expr))
1722 tree_ann_common_t ann = tree_common_ann (expr);
1723 return ((ann) ? ann->value_handle : NULL_TREE);
1725 else
1726 gcc_unreachable ();
1729 #endif /* _TREE_FLOW_INLINE_H */