Update my e-mail address for new employer.
[official-gcc.git] / gcc / tree-flow-inline.h
blobdc4b2d16a515a6facdf8a5230a66dabeef08d2cc
1 /* Inline functions for tree-flow.h
2 Copyright (C) 2001, 2003, 2005, 2006 Free Software Foundation, Inc.
3 Contributed by Diego Novillo <dnovillo@redhat.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 #ifndef _TREE_FLOW_INLINE_H
23 #define _TREE_FLOW_INLINE_H 1
25 /* Inline functions for manipulating various data structures defined in
26 tree-flow.h. See tree-flow.h for documentation. */
28 /* Return true when gimple SSA form was built.
29 gimple_in_ssa_p is queried by gimplifier in various early stages before SSA
30 infrastructure is initialized. Check for presence of the datastructures
31 at first place. */
32 static inline bool
33 gimple_in_ssa_p (struct function *fun)
35 return fun && fun->gimple_df && fun->gimple_df->in_ssa_p;
38 /* 'true' after aliases have been computed (see compute_may_aliases). */
39 static inline bool
40 gimple_aliases_computed_p (struct function *fun)
42 gcc_assert (fun && fun->gimple_df);
43 return fun->gimple_df->aliases_computed_p;
46 /* Addressable variables in the function. If bit I is set, then
47 REFERENCED_VARS (I) has had its address taken. Note that
48 CALL_CLOBBERED_VARS and ADDRESSABLE_VARS are not related. An
49 addressable variable is not necessarily call-clobbered (e.g., a
50 local addressable whose address does not escape) and not all
51 call-clobbered variables are addressable (e.g., a local static
52 variable). */
53 static inline bitmap
54 gimple_addressable_vars (struct function *fun)
56 gcc_assert (fun && fun->gimple_df);
57 return fun->gimple_df->addressable_vars;
60 /* Call clobbered variables in the function. If bit I is set, then
61 REFERENCED_VARS (I) is call-clobbered. */
62 static inline bitmap
63 gimple_call_clobbered_vars (struct function *fun)
65 gcc_assert (fun && fun->gimple_df);
66 return fun->gimple_df->call_clobbered_vars;
69 /* Array of all variables referenced in the function. */
70 static inline htab_t
71 gimple_referenced_vars (struct function *fun)
73 if (!fun->gimple_df)
74 return NULL;
75 return fun->gimple_df->referenced_vars;
78 /* Artificial variable used to model the effects of function calls. */
79 static inline tree
80 gimple_global_var (struct function *fun)
82 gcc_assert (fun && fun->gimple_df);
83 return fun->gimple_df->global_var;
86 /* Artificial variable used to model the effects of nonlocal
87 variables. */
88 static inline tree
89 gimple_nonlocal_all (struct function *fun)
91 gcc_assert (fun && fun->gimple_df);
92 return fun->gimple_df->nonlocal_all;
95 /* Hashtable of variables annotations. Used for static variables only;
96 local variables have direct pointer in the tree node. */
97 static inline htab_t
98 gimple_var_anns (struct function *fun)
100 return fun->gimple_df->var_anns;
103 /* Initialize the hashtable iterator HTI to point to hashtable TABLE */
105 static inline void *
106 first_htab_element (htab_iterator *hti, htab_t table)
108 hti->htab = table;
109 hti->slot = table->entries;
110 hti->limit = hti->slot + htab_size (table);
113 PTR x = *(hti->slot);
114 if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
115 break;
116 } while (++(hti->slot) < hti->limit);
118 if (hti->slot < hti->limit)
119 return *(hti->slot);
120 return NULL;
123 /* Return current non-empty/deleted slot of the hashtable pointed to by HTI,
124 or NULL if we have reached the end. */
126 static inline bool
127 end_htab_p (htab_iterator *hti)
129 if (hti->slot >= hti->limit)
130 return true;
131 return false;
134 /* Advance the hashtable iterator pointed to by HTI to the next element of the
135 hashtable. */
137 static inline void *
138 next_htab_element (htab_iterator *hti)
140 while (++(hti->slot) < hti->limit)
142 PTR x = *(hti->slot);
143 if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
144 return x;
146 return NULL;
149 /* Initialize ITER to point to the first referenced variable in the
150 referenced_vars hashtable, and return that variable. */
152 static inline tree
153 first_referenced_var (referenced_var_iterator *iter)
155 struct int_tree_map *itm;
156 itm = (struct int_tree_map *) first_htab_element (&iter->hti,
157 gimple_referenced_vars
158 (cfun));
159 if (!itm)
160 return NULL;
161 return itm->to;
164 /* Return true if we have hit the end of the referenced variables ITER is
165 iterating through. */
167 static inline bool
168 end_referenced_vars_p (referenced_var_iterator *iter)
170 return end_htab_p (&iter->hti);
173 /* Make ITER point to the next referenced_var in the referenced_var hashtable,
174 and return that variable. */
176 static inline tree
177 next_referenced_var (referenced_var_iterator *iter)
179 struct int_tree_map *itm;
180 itm = (struct int_tree_map *) next_htab_element (&iter->hti);
181 if (!itm)
182 return NULL;
183 return itm->to;
186 /* Fill up VEC with the variables in the referenced vars hashtable. */
188 static inline void
189 fill_referenced_var_vec (VEC (tree, heap) **vec)
191 referenced_var_iterator rvi;
192 tree var;
193 *vec = NULL;
194 FOR_EACH_REFERENCED_VAR (var, rvi)
195 VEC_safe_push (tree, heap, *vec, var);
198 /* Return the variable annotation for T, which must be a _DECL node.
199 Return NULL if the variable annotation doesn't already exist. */
200 static inline var_ann_t
201 var_ann (tree t)
203 gcc_assert (t);
204 gcc_assert (DECL_P (t));
205 gcc_assert (TREE_CODE (t) != FUNCTION_DECL);
206 if (!MTAG_P (t) && (TREE_STATIC (t) || DECL_EXTERNAL (t)))
208 struct static_var_ann_d *sann
209 = ((struct static_var_ann_d *)
210 htab_find_with_hash (gimple_var_anns (cfun), t, DECL_UID (t)));
211 if (!sann)
212 return NULL;
213 gcc_assert (sann->ann.common.type = VAR_ANN);
214 return &sann->ann;
216 gcc_assert (!t->base.ann
217 || t->base.ann->common.type == VAR_ANN);
219 return (var_ann_t) t->base.ann;
222 /* Return the variable annotation for T, which must be a _DECL node.
223 Create the variable annotation if it doesn't exist. */
224 static inline var_ann_t
225 get_var_ann (tree var)
227 var_ann_t ann = var_ann (var);
228 return (ann) ? ann : create_var_ann (var);
231 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
232 Return NULL if the function annotation doesn't already exist. */
233 static inline function_ann_t
234 function_ann (tree t)
236 gcc_assert (t);
237 gcc_assert (TREE_CODE (t) == FUNCTION_DECL);
238 gcc_assert (!t->base.ann
239 || t->base.ann->common.type == FUNCTION_ANN);
241 return (function_ann_t) t->base.ann;
244 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
245 Create the function annotation if it doesn't exist. */
246 static inline function_ann_t
247 get_function_ann (tree var)
249 function_ann_t ann = function_ann (var);
250 gcc_assert (!var->base.ann || var->base.ann->common.type == FUNCTION_ANN);
251 return (ann) ? ann : create_function_ann (var);
254 /* Return true if T has a statement annotation attached to it. */
256 static inline bool
257 has_stmt_ann (tree t)
259 #ifdef ENABLE_CHECKING
260 gcc_assert (is_gimple_stmt (t));
261 #endif
262 return t->base.ann && t->base.ann->common.type == STMT_ANN;
265 /* Return the statement annotation for T, which must be a statement
266 node. Return NULL if the statement annotation doesn't exist. */
267 static inline stmt_ann_t
268 stmt_ann (tree t)
270 #ifdef ENABLE_CHECKING
271 gcc_assert (is_gimple_stmt (t));
272 #endif
273 gcc_assert (!t->base.ann || t->base.ann->common.type == STMT_ANN);
274 return (stmt_ann_t) t->base.ann;
277 /* Return the statement annotation for T, which must be a statement
278 node. Create the statement annotation if it doesn't exist. */
279 static inline stmt_ann_t
280 get_stmt_ann (tree stmt)
282 stmt_ann_t ann = stmt_ann (stmt);
283 return (ann) ? ann : create_stmt_ann (stmt);
286 /* Return the annotation type for annotation ANN. */
287 static inline enum tree_ann_type
288 ann_type (tree_ann_t ann)
290 return ann->common.type;
293 /* Return the basic block for statement T. */
294 static inline basic_block
295 bb_for_stmt (tree t)
297 stmt_ann_t ann;
299 if (TREE_CODE (t) == PHI_NODE)
300 return PHI_BB (t);
302 ann = stmt_ann (t);
303 return ann ? ann->bb : NULL;
306 /* Return the may_aliases bitmap for variable VAR, or NULL if it has
307 no may aliases. */
308 static inline bitmap
309 may_aliases (tree var)
311 return MTAG_ALIASES (var);
314 /* Return the line number for EXPR, or return -1 if we have no line
315 number information for it. */
316 static inline int
317 get_lineno (tree expr)
319 if (expr == NULL_TREE)
320 return -1;
322 if (TREE_CODE (expr) == COMPOUND_EXPR)
323 expr = TREE_OPERAND (expr, 0);
325 if (! EXPR_HAS_LOCATION (expr))
326 return -1;
328 return EXPR_LINENO (expr);
331 /* Return the file name for EXPR, or return "???" if we have no
332 filename information. */
333 static inline const char *
334 get_filename (tree expr)
336 const char *filename;
337 if (expr == NULL_TREE)
338 return "???";
340 if (TREE_CODE (expr) == COMPOUND_EXPR)
341 expr = TREE_OPERAND (expr, 0);
343 if (EXPR_HAS_LOCATION (expr) && (filename = EXPR_FILENAME (expr)))
344 return filename;
345 else
346 return "???";
349 /* Return true if T is a noreturn call. */
350 static inline bool
351 noreturn_call_p (tree t)
353 tree call = get_call_expr_in (t);
354 return call != 0 && (call_expr_flags (call) & ECF_NORETURN) != 0;
357 /* Mark statement T as modified. */
358 static inline void
359 mark_stmt_modified (tree t)
361 stmt_ann_t ann;
362 if (TREE_CODE (t) == PHI_NODE)
363 return;
365 ann = stmt_ann (t);
366 if (ann == NULL)
367 ann = create_stmt_ann (t);
368 else if (noreturn_call_p (t) && cfun->gimple_df)
369 VEC_safe_push (tree, gc, MODIFIED_NORETURN_CALLS (cfun), t);
370 ann->modified = 1;
373 /* Mark statement T as modified, and update it. */
374 static inline void
375 update_stmt (tree t)
377 if (TREE_CODE (t) == PHI_NODE)
378 return;
379 mark_stmt_modified (t);
380 update_stmt_operands (t);
383 static inline void
384 update_stmt_if_modified (tree t)
386 if (stmt_modified_p (t))
387 update_stmt_operands (t);
390 /* Return true if T is marked as modified, false otherwise. */
391 static inline bool
392 stmt_modified_p (tree t)
394 stmt_ann_t ann = stmt_ann (t);
396 /* Note that if the statement doesn't yet have an annotation, we consider it
397 modified. This will force the next call to update_stmt_operands to scan
398 the statement. */
399 return ann ? ann->modified : true;
402 /* Delink an immediate_uses node from its chain. */
403 static inline void
404 delink_imm_use (ssa_use_operand_t *linknode)
406 /* Return if this node is not in a list. */
407 if (linknode->prev == NULL)
408 return;
410 linknode->prev->next = linknode->next;
411 linknode->next->prev = linknode->prev;
412 linknode->prev = NULL;
413 linknode->next = NULL;
416 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
417 static inline void
418 link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
420 /* Link the new node at the head of the list. If we are in the process of
421 traversing the list, we won't visit any new nodes added to it. */
422 linknode->prev = list;
423 linknode->next = list->next;
424 list->next->prev = linknode;
425 list->next = linknode;
428 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
429 static inline void
430 link_imm_use (ssa_use_operand_t *linknode, tree def)
432 ssa_use_operand_t *root;
434 if (!def || TREE_CODE (def) != SSA_NAME)
435 linknode->prev = NULL;
436 else
438 root = &(SSA_NAME_IMM_USE_NODE (def));
439 #ifdef ENABLE_CHECKING
440 if (linknode->use)
441 gcc_assert (*(linknode->use) == def);
442 #endif
443 link_imm_use_to_list (linknode, root);
447 /* Set the value of a use pointed to by USE to VAL. */
448 static inline void
449 set_ssa_use_from_ptr (use_operand_p use, tree val)
451 delink_imm_use (use);
452 *(use->use) = val;
453 link_imm_use (use, val);
456 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
457 in STMT. */
458 static inline void
459 link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, tree stmt)
461 if (stmt)
462 link_imm_use (linknode, def);
463 else
464 link_imm_use (linknode, NULL);
465 linknode->stmt = stmt;
468 /* Relink a new node in place of an old node in the list. */
469 static inline void
470 relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
472 /* The node one had better be in the same list. */
473 gcc_assert (*(old->use) == *(node->use));
474 node->prev = old->prev;
475 node->next = old->next;
476 if (old->prev)
478 old->prev->next = node;
479 old->next->prev = node;
480 /* Remove the old node from the list. */
481 old->prev = NULL;
485 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
486 in STMT. */
487 static inline void
488 relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old, tree stmt)
490 if (stmt)
491 relink_imm_use (linknode, old);
492 else
493 link_imm_use (linknode, NULL);
494 linknode->stmt = stmt;
498 /* Return true is IMM has reached the end of the immediate use list. */
499 static inline bool
500 end_readonly_imm_use_p (imm_use_iterator *imm)
502 return (imm->imm_use == imm->end_p);
505 /* Initialize iterator IMM to process the list for VAR. */
506 static inline use_operand_p
507 first_readonly_imm_use (imm_use_iterator *imm, tree var)
509 gcc_assert (TREE_CODE (var) == SSA_NAME);
511 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
512 imm->imm_use = imm->end_p->next;
513 #ifdef ENABLE_CHECKING
514 imm->iter_node.next = imm->imm_use->next;
515 #endif
516 if (end_readonly_imm_use_p (imm))
517 return NULL_USE_OPERAND_P;
518 return imm->imm_use;
521 /* Bump IMM to the next use in the list. */
522 static inline use_operand_p
523 next_readonly_imm_use (imm_use_iterator *imm)
525 use_operand_p old = imm->imm_use;
527 #ifdef ENABLE_CHECKING
528 /* If this assertion fails, it indicates the 'next' pointer has changed
529 since we the last bump. This indicates that the list is being modified
530 via stmt changes, or SET_USE, or somesuch thing, and you need to be
531 using the SAFE version of the iterator. */
532 gcc_assert (imm->iter_node.next == old->next);
533 imm->iter_node.next = old->next->next;
534 #endif
536 imm->imm_use = old->next;
537 if (end_readonly_imm_use_p (imm))
538 return old;
539 return imm->imm_use;
542 /* Return true if VAR has no uses. */
543 static inline bool
544 has_zero_uses (tree var)
546 ssa_use_operand_t *ptr;
547 ptr = &(SSA_NAME_IMM_USE_NODE (var));
548 /* A single use means there is no items in the list. */
549 return (ptr == ptr->next);
552 /* Return true if VAR has a single use. */
553 static inline bool
554 has_single_use (tree var)
556 ssa_use_operand_t *ptr;
557 ptr = &(SSA_NAME_IMM_USE_NODE (var));
558 /* A single use means there is one item in the list. */
559 return (ptr != ptr->next && ptr == ptr->next->next);
563 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
564 to the use pointer and stmt of occurrence. */
565 static inline bool
566 single_imm_use (tree var, use_operand_p *use_p, tree *stmt)
568 ssa_use_operand_t *ptr;
570 ptr = &(SSA_NAME_IMM_USE_NODE (var));
571 if (ptr != ptr->next && ptr == ptr->next->next)
573 *use_p = ptr->next;
574 *stmt = ptr->next->stmt;
575 return true;
577 *use_p = NULL_USE_OPERAND_P;
578 *stmt = NULL_TREE;
579 return false;
582 /* Return the number of immediate uses of VAR. */
583 static inline unsigned int
584 num_imm_uses (tree var)
586 ssa_use_operand_t *ptr, *start;
587 unsigned int num;
589 start = &(SSA_NAME_IMM_USE_NODE (var));
590 num = 0;
591 for (ptr = start->next; ptr != start; ptr = ptr->next)
592 num++;
594 return num;
597 /* Return the tree pointer to by USE. */
598 static inline tree
599 get_use_from_ptr (use_operand_p use)
601 return *(use->use);
604 /* Return the tree pointer to by DEF. */
605 static inline tree
606 get_def_from_ptr (def_operand_p def)
608 return *def;
611 /* Return a def_operand_p pointer for the result of PHI. */
612 static inline def_operand_p
613 get_phi_result_ptr (tree phi)
615 return &(PHI_RESULT_TREE (phi));
618 /* Return a use_operand_p pointer for argument I of phinode PHI. */
619 static inline use_operand_p
620 get_phi_arg_def_ptr (tree phi, int i)
622 return &(PHI_ARG_IMM_USE_NODE (phi,i));
626 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
627 no addresses. */
628 static inline bitmap
629 addresses_taken (tree stmt)
631 stmt_ann_t ann = stmt_ann (stmt);
632 return ann ? ann->addresses_taken : NULL;
635 /* Return the PHI nodes for basic block BB, or NULL if there are no
636 PHI nodes. */
637 static inline tree
638 phi_nodes (basic_block bb)
640 gcc_assert (!(bb->flags & BB_RTL));
641 if (!bb->il.tree)
642 return NULL;
643 return bb->il.tree->phi_nodes;
646 /* Return pointer to the list of PHI nodes for basic block BB. */
648 static inline tree *
649 phi_nodes_ptr (basic_block bb)
651 gcc_assert (!(bb->flags & BB_RTL));
652 return &bb->il.tree->phi_nodes;
655 /* Set list of phi nodes of a basic block BB to L. */
657 static inline void
658 set_phi_nodes (basic_block bb, tree l)
660 tree phi;
662 gcc_assert (!(bb->flags & BB_RTL));
663 bb->il.tree->phi_nodes = l;
664 for (phi = l; phi; phi = PHI_CHAIN (phi))
665 set_bb_for_stmt (phi, bb);
668 /* Return the phi argument which contains the specified use. */
670 static inline int
671 phi_arg_index_from_use (use_operand_p use)
673 struct phi_arg_d *element, *root;
674 int index;
675 tree phi;
677 /* Since the use is the first thing in a PHI argument element, we can
678 calculate its index based on casting it to an argument, and performing
679 pointer arithmetic. */
681 phi = USE_STMT (use);
682 gcc_assert (TREE_CODE (phi) == PHI_NODE);
684 element = (struct phi_arg_d *)use;
685 root = &(PHI_ARG_ELT (phi, 0));
686 index = element - root;
688 #ifdef ENABLE_CHECKING
689 /* Make sure the calculation doesn't have any leftover bytes. If it does,
690 then imm_use is likely not the first element in phi_arg_d. */
691 gcc_assert (
692 (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
693 gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
694 #endif
696 return index;
699 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
701 static inline void
702 set_is_used (tree var)
704 var_ann_t ann = get_var_ann (var);
705 ann->used = 1;
708 /* Return true if T is an executable statement. */
709 static inline bool
710 is_exec_stmt (tree t)
712 return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
716 /* Return true if this stmt can be the target of a control transfer stmt such
717 as a goto. */
718 static inline bool
719 is_label_stmt (tree t)
721 if (t)
722 switch (TREE_CODE (t))
724 case LABEL_DECL:
725 case LABEL_EXPR:
726 case CASE_LABEL_EXPR:
727 return true;
728 default:
729 return false;
731 return false;
734 /* Return true if T (assumed to be a DECL) is a global variable. */
736 static inline bool
737 is_global_var (tree t)
739 if (MTAG_P (t))
740 return (TREE_STATIC (t) || MTAG_GLOBAL (t));
741 else
742 return (TREE_STATIC (t) || DECL_EXTERNAL (t));
745 /* PHI nodes should contain only ssa_names and invariants. A test
746 for ssa_name is definitely simpler; don't let invalid contents
747 slip in in the meantime. */
749 static inline bool
750 phi_ssa_name_p (tree t)
752 if (TREE_CODE (t) == SSA_NAME)
753 return true;
754 #ifdef ENABLE_CHECKING
755 gcc_assert (is_gimple_min_invariant (t));
756 #endif
757 return false;
760 /* ----------------------------------------------------------------------- */
762 /* Returns the list of statements in BB. */
764 static inline tree
765 bb_stmt_list (basic_block bb)
767 gcc_assert (!(bb->flags & BB_RTL));
768 return bb->il.tree->stmt_list;
771 /* Sets the list of statements in BB to LIST. */
773 static inline void
774 set_bb_stmt_list (basic_block bb, tree list)
776 gcc_assert (!(bb->flags & BB_RTL));
777 bb->il.tree->stmt_list = list;
780 /* Return a block_stmt_iterator that points to beginning of basic
781 block BB. */
782 static inline block_stmt_iterator
783 bsi_start (basic_block bb)
785 block_stmt_iterator bsi;
786 if (bb->index < NUM_FIXED_BLOCKS)
788 bsi.tsi.ptr = NULL;
789 bsi.tsi.container = NULL;
791 else
792 bsi.tsi = tsi_start (bb_stmt_list (bb));
793 bsi.bb = bb;
794 return bsi;
797 /* Return a block statement iterator that points to the first non-label
798 statement in block BB. */
800 static inline block_stmt_iterator
801 bsi_after_labels (basic_block bb)
803 block_stmt_iterator bsi = bsi_start (bb);
805 while (!bsi_end_p (bsi) && TREE_CODE (bsi_stmt (bsi)) == LABEL_EXPR)
806 bsi_next (&bsi);
808 return bsi;
811 /* Return a block statement iterator that points to the end of basic
812 block BB. */
813 static inline block_stmt_iterator
814 bsi_last (basic_block bb)
816 block_stmt_iterator bsi;
818 if (bb->index < NUM_FIXED_BLOCKS)
820 bsi.tsi.ptr = NULL;
821 bsi.tsi.container = NULL;
823 else
824 bsi.tsi = tsi_last (bb_stmt_list (bb));
825 bsi.bb = bb;
826 return bsi;
829 /* Return true if block statement iterator I has reached the end of
830 the basic block. */
831 static inline bool
832 bsi_end_p (block_stmt_iterator i)
834 return tsi_end_p (i.tsi);
837 /* Modify block statement iterator I so that it is at the next
838 statement in the basic block. */
839 static inline void
840 bsi_next (block_stmt_iterator *i)
842 tsi_next (&i->tsi);
845 /* Modify block statement iterator I so that it is at the previous
846 statement in the basic block. */
847 static inline void
848 bsi_prev (block_stmt_iterator *i)
850 tsi_prev (&i->tsi);
853 /* Return the statement that block statement iterator I is currently
854 at. */
855 static inline tree
856 bsi_stmt (block_stmt_iterator i)
858 return tsi_stmt (i.tsi);
861 /* Return a pointer to the statement that block statement iterator I
862 is currently at. */
863 static inline tree *
864 bsi_stmt_ptr (block_stmt_iterator i)
866 return tsi_stmt_ptr (i.tsi);
869 /* Returns the loop of the statement STMT. */
871 static inline struct loop *
872 loop_containing_stmt (tree stmt)
874 basic_block bb = bb_for_stmt (stmt);
875 if (!bb)
876 return NULL;
878 return bb->loop_father;
882 /* Return the memory partition tag associated with symbol SYM. */
884 static inline tree
885 memory_partition (tree sym)
887 tree tag;
889 /* MPTs belong to their own partition. */
890 if (TREE_CODE (sym) == MEMORY_PARTITION_TAG)
891 return sym;
893 gcc_assert (!is_gimple_reg (sym));
894 tag = get_var_ann (sym)->mpt;
896 #if defined ENABLE_CHECKING
897 if (tag)
898 gcc_assert (TREE_CODE (tag) == MEMORY_PARTITION_TAG);
899 #endif
901 return tag;
904 /* Return true if NAME is a memory factoring SSA name (i.e., an SSA
905 name for a memory partition. */
907 static inline bool
908 factoring_name_p (tree name)
910 return TREE_CODE (SSA_NAME_VAR (name)) == MEMORY_PARTITION_TAG;
913 /* Return true if VAR is a clobbered by function calls. */
914 static inline bool
915 is_call_clobbered (tree var)
917 if (!MTAG_P (var))
918 return var_ann (var)->call_clobbered;
919 else
920 return bitmap_bit_p (gimple_call_clobbered_vars (cfun), DECL_UID (var));
923 /* Mark variable VAR as being clobbered by function calls. */
924 static inline void
925 mark_call_clobbered (tree var, unsigned int escape_type)
927 var_ann (var)->escape_mask |= escape_type;
928 if (!MTAG_P (var))
929 var_ann (var)->call_clobbered = true;
930 bitmap_set_bit (gimple_call_clobbered_vars (cfun), DECL_UID (var));
933 /* Clear the call-clobbered attribute from variable VAR. */
934 static inline void
935 clear_call_clobbered (tree var)
937 var_ann_t ann = var_ann (var);
938 ann->escape_mask = 0;
939 if (MTAG_P (var) && TREE_CODE (var) != STRUCT_FIELD_TAG)
940 MTAG_GLOBAL (var) = 0;
941 if (!MTAG_P (var))
942 var_ann (var)->call_clobbered = false;
943 bitmap_clear_bit (gimple_call_clobbered_vars (cfun), DECL_UID (var));
946 /* Return the common annotation for T. Return NULL if the annotation
947 doesn't already exist. */
948 static inline tree_ann_common_t
949 tree_common_ann (tree t)
951 /* Watch out static variables with unshared annotations. */
952 if (DECL_P (t) && TREE_CODE (t) == VAR_DECL)
953 return &var_ann (t)->common;
954 return &t->base.ann->common;
957 /* Return a common annotation for T. Create the constant annotation if it
958 doesn't exist. */
959 static inline tree_ann_common_t
960 get_tree_common_ann (tree t)
962 tree_ann_common_t ann = tree_common_ann (t);
963 return (ann) ? ann : create_tree_common_ann (t);
966 /* ----------------------------------------------------------------------- */
968 /* The following set of routines are used to iterator over various type of
969 SSA operands. */
971 /* Return true if PTR is finished iterating. */
972 static inline bool
973 op_iter_done (ssa_op_iter *ptr)
975 return ptr->done;
978 /* Get the next iterator use value for PTR. */
979 static inline use_operand_p
980 op_iter_next_use (ssa_op_iter *ptr)
982 use_operand_p use_p;
983 #ifdef ENABLE_CHECKING
984 gcc_assert (ptr->iter_type == ssa_op_iter_use);
985 #endif
986 if (ptr->uses)
988 use_p = USE_OP_PTR (ptr->uses);
989 ptr->uses = ptr->uses->next;
990 return use_p;
992 if (ptr->vuses)
994 use_p = VUSE_OP_PTR (ptr->vuses, ptr->vuse_index);
995 if (++(ptr->vuse_index) >= VUSE_NUM (ptr->vuses))
997 ptr->vuse_index = 0;
998 ptr->vuses = ptr->vuses->next;
1000 return use_p;
1002 if (ptr->mayuses)
1004 use_p = VDEF_OP_PTR (ptr->mayuses, ptr->mayuse_index);
1005 if (++(ptr->mayuse_index) >= VDEF_NUM (ptr->mayuses))
1007 ptr->mayuse_index = 0;
1008 ptr->mayuses = ptr->mayuses->next;
1010 return use_p;
1012 if (ptr->phi_i < ptr->num_phi)
1014 return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
1016 ptr->done = true;
1017 return NULL_USE_OPERAND_P;
1020 /* Get the next iterator def value for PTR. */
1021 static inline def_operand_p
1022 op_iter_next_def (ssa_op_iter *ptr)
1024 def_operand_p def_p;
1025 #ifdef ENABLE_CHECKING
1026 gcc_assert (ptr->iter_type == ssa_op_iter_def);
1027 #endif
1028 if (ptr->defs)
1030 def_p = DEF_OP_PTR (ptr->defs);
1031 ptr->defs = ptr->defs->next;
1032 return def_p;
1034 if (ptr->vdefs)
1036 def_p = VDEF_RESULT_PTR (ptr->vdefs);
1037 ptr->vdefs = ptr->vdefs->next;
1038 return def_p;
1040 ptr->done = true;
1041 return NULL_DEF_OPERAND_P;
1044 /* Get the next iterator tree value for PTR. */
1045 static inline tree
1046 op_iter_next_tree (ssa_op_iter *ptr)
1048 tree val;
1049 #ifdef ENABLE_CHECKING
1050 gcc_assert (ptr->iter_type == ssa_op_iter_tree);
1051 #endif
1052 if (ptr->uses)
1054 val = USE_OP (ptr->uses);
1055 ptr->uses = ptr->uses->next;
1056 return val;
1058 if (ptr->vuses)
1060 val = VUSE_OP (ptr->vuses, ptr->vuse_index);
1061 if (++(ptr->vuse_index) >= VUSE_NUM (ptr->vuses))
1063 ptr->vuse_index = 0;
1064 ptr->vuses = ptr->vuses->next;
1066 return val;
1068 if (ptr->mayuses)
1070 val = VDEF_OP (ptr->mayuses, ptr->mayuse_index);
1071 if (++(ptr->mayuse_index) >= VDEF_NUM (ptr->mayuses))
1073 ptr->mayuse_index = 0;
1074 ptr->mayuses = ptr->mayuses->next;
1076 return val;
1078 if (ptr->defs)
1080 val = DEF_OP (ptr->defs);
1081 ptr->defs = ptr->defs->next;
1082 return val;
1084 if (ptr->vdefs)
1086 val = VDEF_RESULT (ptr->vdefs);
1087 ptr->vdefs = ptr->vdefs->next;
1088 return val;
1091 ptr->done = true;
1092 return NULL_TREE;
1097 /* This functions clears the iterator PTR, and marks it done. This is normally
1098 used to prevent warnings in the compile about might be uninitialized
1099 components. */
1101 static inline void
1102 clear_and_done_ssa_iter (ssa_op_iter *ptr)
1104 ptr->defs = NULL;
1105 ptr->uses = NULL;
1106 ptr->vuses = NULL;
1107 ptr->vdefs = NULL;
1108 ptr->mayuses = NULL;
1109 ptr->iter_type = ssa_op_iter_none;
1110 ptr->phi_i = 0;
1111 ptr->num_phi = 0;
1112 ptr->phi_stmt = NULL_TREE;
1113 ptr->done = true;
1114 ptr->vuse_index = 0;
1115 ptr->mayuse_index = 0;
1118 /* Initialize the iterator PTR to the virtual defs in STMT. */
1119 static inline void
1120 op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
1122 #ifdef ENABLE_CHECKING
1123 gcc_assert (stmt_ann (stmt));
1124 #endif
1126 ptr->defs = (flags & SSA_OP_DEF) ? DEF_OPS (stmt) : NULL;
1127 ptr->uses = (flags & SSA_OP_USE) ? USE_OPS (stmt) : NULL;
1128 ptr->vuses = (flags & SSA_OP_VUSE) ? VUSE_OPS (stmt) : NULL;
1129 ptr->vdefs = (flags & SSA_OP_VDEF) ? VDEF_OPS (stmt) : NULL;
1130 ptr->mayuses = (flags & SSA_OP_VMAYUSE) ? VDEF_OPS (stmt) : NULL;
1131 ptr->done = false;
1133 ptr->phi_i = 0;
1134 ptr->num_phi = 0;
1135 ptr->phi_stmt = NULL_TREE;
1136 ptr->vuse_index = 0;
1137 ptr->mayuse_index = 0;
1140 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1141 the first use. */
1142 static inline use_operand_p
1143 op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
1145 gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0);
1146 op_iter_init (ptr, stmt, flags);
1147 ptr->iter_type = ssa_op_iter_use;
1148 return op_iter_next_use (ptr);
1151 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1152 the first def. */
1153 static inline def_operand_p
1154 op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1156 gcc_assert ((flags & SSA_OP_ALL_USES) == 0);
1157 op_iter_init (ptr, stmt, flags);
1158 ptr->iter_type = ssa_op_iter_def;
1159 return op_iter_next_def (ptr);
1162 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1163 the first operand as a tree. */
1164 static inline tree
1165 op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1167 op_iter_init (ptr, stmt, flags);
1168 ptr->iter_type = ssa_op_iter_tree;
1169 return op_iter_next_tree (ptr);
1172 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1173 KILL and DEF. */
1174 static inline void
1175 op_iter_next_vdef (vuse_vec_p *use, def_operand_p *def,
1176 ssa_op_iter *ptr)
1178 #ifdef ENABLE_CHECKING
1179 gcc_assert (ptr->iter_type == ssa_op_iter_vdef);
1180 #endif
1181 if (ptr->mayuses)
1183 *def = VDEF_RESULT_PTR (ptr->mayuses);
1184 *use = VDEF_VECT (ptr->mayuses);
1185 ptr->mayuses = ptr->mayuses->next;
1186 return;
1189 *def = NULL_DEF_OPERAND_P;
1190 *use = NULL;
1191 ptr->done = true;
1192 return;
1196 static inline void
1197 op_iter_next_mustdef (use_operand_p *use, def_operand_p *def,
1198 ssa_op_iter *ptr)
1200 vuse_vec_p vp;
1201 op_iter_next_vdef (&vp, def, ptr);
1202 if (vp != NULL)
1204 gcc_assert (VUSE_VECT_NUM_ELEM (*vp) == 1);
1205 *use = VUSE_ELEMENT_PTR (*vp, 0);
1207 else
1208 *use = NULL_USE_OPERAND_P;
1211 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1212 in USE and DEF. */
1213 static inline void
1214 op_iter_init_vdef (ssa_op_iter *ptr, tree stmt, vuse_vec_p *use,
1215 def_operand_p *def)
1217 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1219 op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1220 ptr->iter_type = ssa_op_iter_vdef;
1221 op_iter_next_vdef (use, def, ptr);
1225 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1226 return NULL. */
1227 static inline tree
1228 single_ssa_tree_operand (tree stmt, int flags)
1230 tree var;
1231 ssa_op_iter iter;
1233 var = op_iter_init_tree (&iter, stmt, flags);
1234 if (op_iter_done (&iter))
1235 return NULL_TREE;
1236 op_iter_next_tree (&iter);
1237 if (op_iter_done (&iter))
1238 return var;
1239 return NULL_TREE;
1243 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1244 return NULL. */
1245 static inline use_operand_p
1246 single_ssa_use_operand (tree stmt, int flags)
1248 use_operand_p var;
1249 ssa_op_iter iter;
1251 var = op_iter_init_use (&iter, stmt, flags);
1252 if (op_iter_done (&iter))
1253 return NULL_USE_OPERAND_P;
1254 op_iter_next_use (&iter);
1255 if (op_iter_done (&iter))
1256 return var;
1257 return NULL_USE_OPERAND_P;
1262 /* If there is a single operand in STMT matching FLAGS, return it. Otherwise
1263 return NULL. */
1264 static inline def_operand_p
1265 single_ssa_def_operand (tree stmt, int flags)
1267 def_operand_p var;
1268 ssa_op_iter iter;
1270 var = op_iter_init_def (&iter, stmt, flags);
1271 if (op_iter_done (&iter))
1272 return NULL_DEF_OPERAND_P;
1273 op_iter_next_def (&iter);
1274 if (op_iter_done (&iter))
1275 return var;
1276 return NULL_DEF_OPERAND_P;
1280 /* Return true if there are zero operands in STMT matching the type
1281 given in FLAGS. */
1282 static inline bool
1283 zero_ssa_operands (tree stmt, int flags)
1285 ssa_op_iter iter;
1287 op_iter_init_tree (&iter, stmt, flags);
1288 return op_iter_done (&iter);
1292 /* Return the number of operands matching FLAGS in STMT. */
1293 static inline int
1294 num_ssa_operands (tree stmt, int flags)
1296 ssa_op_iter iter;
1297 tree t;
1298 int num = 0;
1300 FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
1301 num++;
1302 return num;
1306 /* Delink all immediate_use information for STMT. */
1307 static inline void
1308 delink_stmt_imm_use (tree stmt)
1310 ssa_op_iter iter;
1311 use_operand_p use_p;
1313 if (ssa_operands_active ())
1314 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_ALL_USES)
1315 delink_imm_use (use_p);
1319 /* This routine will compare all the operands matching FLAGS in STMT1 to those
1320 in STMT2. TRUE is returned if they are the same. STMTs can be NULL. */
1321 static inline bool
1322 compare_ssa_operands_equal (tree stmt1, tree stmt2, int flags)
1324 ssa_op_iter iter1, iter2;
1325 tree op1 = NULL_TREE;
1326 tree op2 = NULL_TREE;
1327 bool look1, look2;
1329 if (stmt1 == stmt2)
1330 return true;
1332 look1 = stmt1 && stmt_ann (stmt1);
1333 look2 = stmt2 && stmt_ann (stmt2);
1335 if (look1)
1337 op1 = op_iter_init_tree (&iter1, stmt1, flags);
1338 if (!look2)
1339 return op_iter_done (&iter1);
1341 else
1342 clear_and_done_ssa_iter (&iter1);
1344 if (look2)
1346 op2 = op_iter_init_tree (&iter2, stmt2, flags);
1347 if (!look1)
1348 return op_iter_done (&iter2);
1350 else
1351 clear_and_done_ssa_iter (&iter2);
1353 while (!op_iter_done (&iter1) && !op_iter_done (&iter2))
1355 if (op1 != op2)
1356 return false;
1357 op1 = op_iter_next_tree (&iter1);
1358 op2 = op_iter_next_tree (&iter2);
1361 return (op_iter_done (&iter1) && op_iter_done (&iter2));
1365 /* If there is a single DEF in the PHI node which matches FLAG, return it.
1366 Otherwise return NULL_DEF_OPERAND_P. */
1367 static inline tree
1368 single_phi_def (tree stmt, int flags)
1370 tree def = PHI_RESULT (stmt);
1371 if ((flags & SSA_OP_DEF) && is_gimple_reg (def))
1372 return def;
1373 if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
1374 return def;
1375 return NULL_TREE;
1378 /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should
1379 be either SSA_OP_USES or SSA_OP_VIRTUAL_USES. */
1380 static inline use_operand_p
1381 op_iter_init_phiuse (ssa_op_iter *ptr, tree phi, int flags)
1383 tree phi_def = PHI_RESULT (phi);
1384 int comp;
1386 clear_and_done_ssa_iter (ptr);
1387 ptr->done = false;
1389 gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
1391 comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1393 /* If the PHI node doesn't the operand type we care about, we're done. */
1394 if ((flags & comp) == 0)
1396 ptr->done = true;
1397 return NULL_USE_OPERAND_P;
1400 ptr->phi_stmt = phi;
1401 ptr->num_phi = PHI_NUM_ARGS (phi);
1402 ptr->iter_type = ssa_op_iter_use;
1403 return op_iter_next_use (ptr);
1407 /* Start an iterator for a PHI definition. */
1409 static inline def_operand_p
1410 op_iter_init_phidef (ssa_op_iter *ptr, tree phi, int flags)
1412 tree phi_def = PHI_RESULT (phi);
1413 int comp;
1415 clear_and_done_ssa_iter (ptr);
1416 ptr->done = false;
1418 gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
1420 comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
1422 /* If the PHI node doesn't the operand type we care about, we're done. */
1423 if ((flags & comp) == 0)
1425 ptr->done = true;
1426 return NULL_USE_OPERAND_P;
1429 ptr->iter_type = ssa_op_iter_def;
1430 /* The first call to op_iter_next_def will terminate the iterator since
1431 all the fields are NULL. Simply return the result here as the first and
1432 therefore only result. */
1433 return PHI_RESULT_PTR (phi);
1436 /* Return true is IMM has reached the end of the immediate use stmt list. */
1438 static inline bool
1439 end_imm_use_stmt_p (imm_use_iterator *imm)
1441 return (imm->imm_use == imm->end_p);
1444 /* Finished the traverse of an immediate use stmt list IMM by removing the
1445 placeholder node from the list. */
1447 static inline void
1448 end_imm_use_stmt_traverse (imm_use_iterator *imm)
1450 delink_imm_use (&(imm->iter_node));
1453 /* Immediate use traversal of uses within a stmt require that all the
1454 uses on a stmt be sequentially listed. This routine is used to build up
1455 this sequential list by adding USE_P to the end of the current list
1456 currently delimited by HEAD and LAST_P. The new LAST_P value is
1457 returned. */
1459 static inline use_operand_p
1460 move_use_after_head (use_operand_p use_p, use_operand_p head,
1461 use_operand_p last_p)
1463 gcc_assert (USE_FROM_PTR (use_p) == USE_FROM_PTR (head));
1464 /* Skip head when we find it. */
1465 if (use_p != head)
1467 /* If use_p is already linked in after last_p, continue. */
1468 if (last_p->next == use_p)
1469 last_p = use_p;
1470 else
1472 /* Delink from current location, and link in at last_p. */
1473 delink_imm_use (use_p);
1474 link_imm_use_to_list (use_p, last_p);
1475 last_p = use_p;
1478 return last_p;
1482 /* This routine will relink all uses with the same stmt as HEAD into the list
1483 immediately following HEAD for iterator IMM. */
1485 static inline void
1486 link_use_stmts_after (use_operand_p head, imm_use_iterator *imm)
1488 use_operand_p use_p;
1489 use_operand_p last_p = head;
1490 tree head_stmt = USE_STMT (head);
1491 tree use = USE_FROM_PTR (head);
1492 ssa_op_iter op_iter;
1493 int flag;
1495 /* Only look at virtual or real uses, depending on the type of HEAD. */
1496 flag = (is_gimple_reg (use) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1498 if (TREE_CODE (head_stmt) == PHI_NODE)
1500 FOR_EACH_PHI_ARG (use_p, head_stmt, op_iter, flag)
1501 if (USE_FROM_PTR (use_p) == use)
1502 last_p = move_use_after_head (use_p, head, last_p);
1504 else
1506 FOR_EACH_SSA_USE_OPERAND (use_p, head_stmt, op_iter, flag)
1507 if (USE_FROM_PTR (use_p) == use)
1508 last_p = move_use_after_head (use_p, head, last_p);
1510 /* LInk iter node in after last_p. */
1511 if (imm->iter_node.prev != NULL)
1512 delink_imm_use (&imm->iter_node);
1513 link_imm_use_to_list (&(imm->iter_node), last_p);
1516 /* Initialize IMM to traverse over uses of VAR. Return the first statement. */
1517 static inline tree
1518 first_imm_use_stmt (imm_use_iterator *imm, tree var)
1520 gcc_assert (TREE_CODE (var) == SSA_NAME);
1522 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
1523 imm->imm_use = imm->end_p->next;
1524 imm->next_imm_name = NULL_USE_OPERAND_P;
1526 /* iter_node is used as a marker within the immediate use list to indicate
1527 where the end of the current stmt's uses are. Initialize it to NULL
1528 stmt and use, which indicates a marker node. */
1529 imm->iter_node.prev = NULL_USE_OPERAND_P;
1530 imm->iter_node.next = NULL_USE_OPERAND_P;
1531 imm->iter_node.stmt = NULL_TREE;
1532 imm->iter_node.use = NULL_USE_OPERAND_P;
1534 if (end_imm_use_stmt_p (imm))
1535 return NULL_TREE;
1537 link_use_stmts_after (imm->imm_use, imm);
1539 return USE_STMT (imm->imm_use);
1542 /* Bump IMM to the next stmt which has a use of var. */
1544 static inline tree
1545 next_imm_use_stmt (imm_use_iterator *imm)
1547 imm->imm_use = imm->iter_node.next;
1548 if (end_imm_use_stmt_p (imm))
1550 if (imm->iter_node.prev != NULL)
1551 delink_imm_use (&imm->iter_node);
1552 return NULL_TREE;
1555 link_use_stmts_after (imm->imm_use, imm);
1556 return USE_STMT (imm->imm_use);
1560 /* This routine will return the first use on the stmt IMM currently refers
1561 to. */
1563 static inline use_operand_p
1564 first_imm_use_on_stmt (imm_use_iterator *imm)
1566 imm->next_imm_name = imm->imm_use->next;
1567 return imm->imm_use;
1570 /* Return TRUE if the last use on the stmt IMM refers to has been visited. */
1572 static inline bool
1573 end_imm_use_on_stmt_p (imm_use_iterator *imm)
1575 return (imm->imm_use == &(imm->iter_node));
1578 /* Bump to the next use on the stmt IMM refers to, return NULL if done. */
1580 static inline use_operand_p
1581 next_imm_use_on_stmt (imm_use_iterator *imm)
1583 imm->imm_use = imm->next_imm_name;
1584 if (end_imm_use_on_stmt_p (imm))
1585 return NULL_USE_OPERAND_P;
1586 else
1588 imm->next_imm_name = imm->imm_use->next;
1589 return imm->imm_use;
1593 /* Return true if VAR cannot be modified by the program. */
1595 static inline bool
1596 unmodifiable_var_p (tree var)
1598 if (TREE_CODE (var) == SSA_NAME)
1599 var = SSA_NAME_VAR (var);
1601 if (MTAG_P (var))
1602 return TREE_READONLY (var) && (TREE_STATIC (var) || MTAG_GLOBAL (var));
1604 return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1607 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it. */
1609 static inline bool
1610 array_ref_contains_indirect_ref (tree ref)
1612 gcc_assert (TREE_CODE (ref) == ARRAY_REF);
1614 do {
1615 ref = TREE_OPERAND (ref, 0);
1616 } while (handled_component_p (ref));
1618 return TREE_CODE (ref) == INDIRECT_REF;
1621 /* Return true if REF, a handled component reference, has an ARRAY_REF
1622 somewhere in it. */
1624 static inline bool
1625 ref_contains_array_ref (tree ref)
1627 gcc_assert (handled_component_p (ref));
1629 do {
1630 if (TREE_CODE (ref) == ARRAY_REF)
1631 return true;
1632 ref = TREE_OPERAND (ref, 0);
1633 } while (handled_component_p (ref));
1635 return false;
1638 /* Given a variable VAR, lookup and return a pointer to the list of
1639 subvariables for it. */
1641 static inline subvar_t *
1642 lookup_subvars_for_var (tree var)
1644 var_ann_t ann = var_ann (var);
1645 gcc_assert (ann);
1646 return &ann->subvars;
1649 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1650 NULL, if there are no subvariables. */
1652 static inline subvar_t
1653 get_subvars_for_var (tree var)
1655 subvar_t subvars;
1657 gcc_assert (SSA_VAR_P (var));
1659 if (TREE_CODE (var) == SSA_NAME)
1660 subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
1661 else
1662 subvars = *(lookup_subvars_for_var (var));
1663 return subvars;
1666 /* Return the subvariable of VAR at offset OFFSET. */
1668 static inline tree
1669 get_subvar_at (tree var, unsigned HOST_WIDE_INT offset)
1671 subvar_t sv;
1673 for (sv = get_subvars_for_var (var); sv; sv = sv->next)
1674 if (SFT_OFFSET (sv->var) == offset)
1675 return sv->var;
1677 return NULL_TREE;
1680 /* Return true if V is a tree that we can have subvars for.
1681 Normally, this is any aggregate type. Also complex
1682 types which are not gimple registers can have subvars. */
1684 static inline bool
1685 var_can_have_subvars (tree v)
1687 /* Volatile variables should never have subvars. */
1688 if (TREE_THIS_VOLATILE (v))
1689 return false;
1691 /* Non decls or memory tags can never have subvars. */
1692 if (!DECL_P (v) || MTAG_P (v))
1693 return false;
1695 /* Aggregates can have subvars. */
1696 if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
1697 return true;
1699 /* Complex types variables which are not also a gimple register can
1700 have subvars. */
1701 if (TREE_CODE (TREE_TYPE (v)) == COMPLEX_TYPE
1702 && !DECL_GIMPLE_REG_P (v))
1703 return true;
1705 return false;
1709 /* Return true if OFFSET and SIZE define a range that overlaps with some
1710 portion of the range of SV, a subvar. If there was an exact overlap,
1711 *EXACT will be set to true upon return. */
1713 static inline bool
1714 overlap_subvar (unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT size,
1715 tree sv, bool *exact)
1717 /* There are three possible cases of overlap.
1718 1. We can have an exact overlap, like so:
1719 |offset, offset + size |
1720 |sv->offset, sv->offset + sv->size |
1722 2. We can have offset starting after sv->offset, like so:
1724 |offset, offset + size |
1725 |sv->offset, sv->offset + sv->size |
1727 3. We can have offset starting before sv->offset, like so:
1729 |offset, offset + size |
1730 |sv->offset, sv->offset + sv->size|
1733 if (exact)
1734 *exact = false;
1735 if (offset == SFT_OFFSET (sv) && size == SFT_SIZE (sv))
1737 if (exact)
1738 *exact = true;
1739 return true;
1741 else if (offset >= SFT_OFFSET (sv)
1742 && offset < (SFT_OFFSET (sv) + SFT_SIZE (sv)))
1744 return true;
1746 else if (offset < SFT_OFFSET (sv)
1747 && (size > SFT_OFFSET (sv) - offset))
1749 return true;
1751 return false;
1755 /* Return the memory tag associated with symbol SYM. */
1757 static inline tree
1758 symbol_mem_tag (tree sym)
1760 tree tag = get_var_ann (sym)->symbol_mem_tag;
1762 #if defined ENABLE_CHECKING
1763 if (tag)
1764 gcc_assert (TREE_CODE (tag) == SYMBOL_MEMORY_TAG);
1765 #endif
1767 return tag;
1771 /* Set the memory tag associated with symbol SYM. */
1773 static inline void
1774 set_symbol_mem_tag (tree sym, tree tag)
1776 #if defined ENABLE_CHECKING
1777 if (tag)
1778 gcc_assert (TREE_CODE (tag) == SYMBOL_MEMORY_TAG);
1779 #endif
1781 get_var_ann (sym)->symbol_mem_tag = tag;
1784 /* Get the value handle of EXPR. This is the only correct way to get
1785 the value handle for a "thing". If EXPR does not have a value
1786 handle associated, it returns NULL_TREE.
1787 NB: If EXPR is min_invariant, this function is *required* to return
1788 EXPR. */
1790 static inline tree
1791 get_value_handle (tree expr)
1793 if (TREE_CODE (expr) == SSA_NAME)
1794 return SSA_NAME_VALUE (expr);
1795 else if (DECL_P (expr) || TREE_CODE (expr) == TREE_LIST
1796 || TREE_CODE (expr) == CONSTRUCTOR)
1798 tree_ann_common_t ann = tree_common_ann (expr);
1799 return ((ann) ? ann->value_handle : NULL_TREE);
1801 else if (is_gimple_min_invariant (expr))
1802 return expr;
1803 else if (EXPR_P (expr))
1805 tree_ann_common_t ann = tree_common_ann (expr);
1806 return ((ann) ? ann->value_handle : NULL_TREE);
1808 else
1809 gcc_unreachable ();
1812 /* Accessor to tree-ssa-operands.c caches. */
1813 static inline struct ssa_operands *
1814 gimple_ssa_operands (struct function *fun)
1816 return &fun->gimple_df->ssa_operands;
1819 /* Map describing reference statistics for function FN. */
1820 static inline struct mem_ref_stats_d *
1821 gimple_mem_ref_stats (struct function *fn)
1823 return &fn->gimple_df->mem_ref_stats;
1825 #endif /* _TREE_FLOW_INLINE_H */