2005-04-29 Jim Tison <jtison@us.ibm.com>
[official-gcc.git] / gcc / tree-flow-inline.h
blob87a243daa3c09f93dbd4d01437635d523d451a55
1 /* Inline functions for tree-flow.h
2 Copyright (C) 2001, 2003, 2005 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, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, 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 the variable annotation for T, which must be a _DECL node.
29 Return NULL if the variable annotation doesn't already exist. */
30 static inline var_ann_t
31 var_ann (tree t)
33 gcc_assert (t);
34 gcc_assert (DECL_P (t));
35 gcc_assert (!t->common.ann || t->common.ann->common.type == VAR_ANN);
37 return (var_ann_t) t->common.ann;
40 /* Return the variable annotation for T, which must be a _DECL node.
41 Create the variable annotation if it doesn't exist. */
42 static inline var_ann_t
43 get_var_ann (tree var)
45 var_ann_t ann = var_ann (var);
46 return (ann) ? ann : create_var_ann (var);
49 /* Return the statement annotation for T, which must be a statement
50 node. Return NULL if the statement annotation doesn't exist. */
51 static inline stmt_ann_t
52 stmt_ann (tree t)
54 #ifdef ENABLE_CHECKING
55 gcc_assert (is_gimple_stmt (t));
56 #endif
57 return (stmt_ann_t) t->common.ann;
60 /* Return the statement annotation for T, which must be a statement
61 node. Create the statement annotation if it doesn't exist. */
62 static inline stmt_ann_t
63 get_stmt_ann (tree stmt)
65 stmt_ann_t ann = stmt_ann (stmt);
66 return (ann) ? ann : create_stmt_ann (stmt);
70 /* Return the annotation type for annotation ANN. */
71 static inline enum tree_ann_type
72 ann_type (tree_ann_t ann)
74 return ann->common.type;
77 /* Return the basic block for statement T. */
78 static inline basic_block
79 bb_for_stmt (tree t)
81 stmt_ann_t ann;
83 if (TREE_CODE (t) == PHI_NODE)
84 return PHI_BB (t);
86 ann = stmt_ann (t);
87 return ann ? ann->bb : NULL;
90 /* Return the may_aliases varray for variable VAR, or NULL if it has
91 no may aliases. */
92 static inline varray_type
93 may_aliases (tree var)
95 var_ann_t ann = var_ann (var);
96 return ann ? ann->may_aliases : NULL;
99 /* Return the line number for EXPR, or return -1 if we have no line
100 number information for it. */
101 static inline int
102 get_lineno (tree expr)
104 if (expr == NULL_TREE)
105 return -1;
107 if (TREE_CODE (expr) == COMPOUND_EXPR)
108 expr = TREE_OPERAND (expr, 0);
110 if (! EXPR_HAS_LOCATION (expr))
111 return -1;
113 return EXPR_LINENO (expr);
116 /* Return the file name for EXPR, or return "???" if we have no
117 filename information. */
118 static inline const char *
119 get_filename (tree expr)
121 const char *filename;
122 if (expr == NULL_TREE)
123 return "???";
125 if (TREE_CODE (expr) == COMPOUND_EXPR)
126 expr = TREE_OPERAND (expr, 0);
128 if (EXPR_HAS_LOCATION (expr) && (filename = EXPR_FILENAME (expr)))
129 return filename;
130 else
131 return "???";
134 /* Return true if T is a noreturn call. */
135 static inline bool
136 noreturn_call_p (tree t)
138 tree call = get_call_expr_in (t);
139 return call != 0 && (call_expr_flags (call) & ECF_NORETURN) != 0;
142 /* Mark statement T as modified. */
143 static inline void
144 mark_stmt_modified (tree t)
146 stmt_ann_t ann;
147 if (TREE_CODE (t) == PHI_NODE)
148 return;
150 ann = stmt_ann (t);
151 if (ann == NULL)
152 ann = create_stmt_ann (t);
153 else if (noreturn_call_p (t))
154 VEC_safe_push (tree, gc, modified_noreturn_calls, t);
155 ann->modified = 1;
158 /* Mark statement T as modified, and update it. */
159 static inline void
160 update_stmt (tree t)
162 if (TREE_CODE (t) == PHI_NODE)
163 return;
164 mark_stmt_modified (t);
165 update_stmt_operands (t);
168 static inline void
169 update_stmt_if_modified (tree t)
171 if (stmt_modified_p (t))
172 update_stmt_operands (t);
175 /* Return true if T is marked as modified, false otherwise. */
176 static inline bool
177 stmt_modified_p (tree t)
179 stmt_ann_t ann = stmt_ann (t);
181 /* Note that if the statement doesn't yet have an annotation, we consider it
182 modified. This will force the next call to update_stmt_operands to scan
183 the statement. */
184 return ann ? ann->modified : true;
187 /* Delink an immediate_uses node from its chain. */
188 static inline void
189 delink_imm_use (ssa_imm_use_t *linknode)
191 /* Return if this node is not in a list. */
192 if (linknode->prev == NULL)
193 return;
195 linknode->prev->next = linknode->next;
196 linknode->next->prev = linknode->prev;
197 linknode->prev = NULL;
198 linknode->next = NULL;
201 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
202 static inline void
203 link_imm_use_to_list (ssa_imm_use_t *linknode, ssa_imm_use_t *list)
205 /* Link the new node at the head of the list. If we are in the process of
206 traversing the list, we wont visit any new nodes added to it. */
207 linknode->prev = list;
208 linknode->next = list->next;
209 list->next->prev = linknode;
210 list->next = linknode;
213 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
214 static inline void
215 link_imm_use (ssa_imm_use_t *linknode, tree def)
217 ssa_imm_use_t *root;
219 if (!def || TREE_CODE (def) != SSA_NAME)
220 linknode->prev = NULL;
221 else
223 root = &(SSA_NAME_IMM_USE_NODE (def));
224 #ifdef ENABLE_CHECKING
225 if (linknode->use)
226 gcc_assert (*(linknode->use) == def);
227 #endif
228 link_imm_use_to_list (linknode, root);
232 /* Set the value of a use pointed by USE to VAL. */
233 static inline void
234 set_ssa_use_from_ptr (use_operand_p use, tree val)
236 delink_imm_use (use);
237 *(use->use) = val;
238 link_imm_use (use, val);
241 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occuring
242 in STMT. */
243 static inline void
244 link_imm_use_stmt (ssa_imm_use_t *linknode, tree def, tree stmt)
246 if (stmt)
247 link_imm_use (linknode, def);
248 else
249 link_imm_use (linknode, NULL);
250 linknode->stmt = stmt;
253 /* Relink a new node in place of an old node in the list. */
254 static inline void
255 relink_imm_use (ssa_imm_use_t *node, ssa_imm_use_t *old)
257 /* The node one had better be in the same list. */
258 gcc_assert (*(old->use) == *(node->use));
259 node->prev = old->prev;
260 node->next = old->next;
261 if (old->prev)
263 old->prev->next = node;
264 old->next->prev = node;
265 /* Remove the old node from the list. */
266 old->prev = NULL;
270 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occuring
271 in STMT. */
272 static inline void
273 relink_imm_use_stmt (ssa_imm_use_t *linknode, ssa_imm_use_t *old, tree stmt)
275 if (stmt)
276 relink_imm_use (linknode, old);
277 else
278 link_imm_use (linknode, NULL);
279 linknode->stmt = stmt;
282 /* Finished the traverse of an immediate use list IMM by removing it from
283 the list. */
284 static inline void
285 end_safe_imm_use_traverse (imm_use_iterator *imm)
287 delink_imm_use (&(imm->iter_node));
290 /* Return true if IMM is at the end of the list. */
291 static inline bool
292 end_safe_imm_use_p (imm_use_iterator *imm)
294 return (imm->imm_use == imm->end_p);
297 /* Initialize iterator IMM to process the list for VAR. */
298 static inline use_operand_p
299 first_safe_imm_use (imm_use_iterator *imm, tree var)
301 /* Set up and link the iterator node into the linked list for VAR. */
302 imm->iter_node.use = NULL;
303 imm->iter_node.stmt = NULL_TREE;
304 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
305 /* Check if there are 0 elements. */
306 if (imm->end_p->next == imm->end_p)
308 imm->imm_use = imm->end_p;
309 return NULL_USE_OPERAND_P;
312 link_imm_use (&(imm->iter_node), var);
313 imm->imm_use = imm->iter_node.next;
314 return imm->imm_use;
317 /* Bump IMM to then next use in the list. */
318 static inline use_operand_p
319 next_safe_imm_use (imm_use_iterator *imm)
321 ssa_imm_use_t *ptr;
322 use_operand_p old;
324 old = imm->imm_use;
325 /* If the next node following the iter_node is still the one referred to by
326 imm_use, then the list hasn't changed, go to the next node. */
327 if (imm->iter_node.next == imm->imm_use)
329 ptr = &(imm->iter_node);
330 /* Remove iternode from the list. */
331 delink_imm_use (ptr);
332 imm->imm_use = imm->imm_use->next;
333 if (! end_safe_imm_use_p (imm))
335 /* This isnt the end, link iternode before the next use. */
336 ptr->prev = imm->imm_use->prev;
337 ptr->next = imm->imm_use;
338 imm->imm_use->prev->next = ptr;
339 imm->imm_use->prev = ptr;
341 else
342 return old;
344 else
346 /* If the 'next' value after the iterator isn't the same as it was, then
347 a node has been deleted, so we simply proceed to the node following
348 where the iterator is in the list. */
349 imm->imm_use = imm->iter_node.next;
350 if (end_safe_imm_use_p (imm))
352 end_safe_imm_use_traverse (imm);
353 return old;
357 return imm->imm_use;
360 /* Return true is IMM has reached the end of the immediate use list. */
361 static inline bool
362 end_readonly_imm_use_p (imm_use_iterator *imm)
364 return (imm->imm_use == imm->end_p);
367 /* Initialize iterator IMM to process the list for VAR. */
368 static inline use_operand_p
369 first_readonly_imm_use (imm_use_iterator *imm, tree var)
371 gcc_assert (TREE_CODE (var) == SSA_NAME);
373 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
374 imm->imm_use = imm->end_p->next;
375 #ifdef ENABLE_CHECKING
376 imm->iter_node.next = imm->imm_use->next;
377 #endif
378 if (end_readonly_imm_use_p (imm))
379 return NULL_USE_OPERAND_P;
380 return imm->imm_use;
383 /* Bump IMM to then next use in the list. */
384 static inline use_operand_p
385 next_readonly_imm_use (imm_use_iterator *imm)
387 use_operand_p old = imm->imm_use;
389 #ifdef ENABLE_CHECKING
390 /* If this assertion fails, it indicates the 'next' pointer has changed
391 since we the last bump. This indicates that the list is being modified
392 via stmt changes, or SET_USE, or somesuch thing, and you need to be
393 using the SAFE version of the iterator. */
394 gcc_assert (imm->iter_node.next == old->next);
395 imm->iter_node.next = old->next->next;
396 #endif
398 imm->imm_use = old->next;
399 if (end_readonly_imm_use_p (imm))
400 return old;
401 return imm->imm_use;
404 /* Return true if VAR has no uses. */
405 static inline bool
406 has_zero_uses (tree var)
408 ssa_imm_use_t *ptr;
409 ptr = &(SSA_NAME_IMM_USE_NODE (var));
410 /* A single use means there is no items in the list. */
411 return (ptr == ptr->next);
414 /* Return true if VAR has a single use. */
415 static inline bool
416 has_single_use (tree var)
418 ssa_imm_use_t *ptr;
419 ptr = &(SSA_NAME_IMM_USE_NODE (var));
420 /* A single use means there is one item in the list. */
421 return (ptr != ptr->next && ptr == ptr->next->next);
424 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
425 to the use pointer and stmt of occurrence. */
426 static inline bool
427 single_imm_use (tree var, use_operand_p *use_p, tree *stmt)
429 ssa_imm_use_t *ptr;
431 ptr = &(SSA_NAME_IMM_USE_NODE (var));
432 if (ptr != ptr->next && ptr == ptr->next->next)
434 *use_p = ptr->next;
435 *stmt = ptr->next->stmt;
436 return true;
438 *use_p = NULL_USE_OPERAND_P;
439 *stmt = NULL_TREE;
440 return false;
443 /* Return the number of immediate uses of VAR. */
444 static inline unsigned int
445 num_imm_uses (tree var)
447 ssa_imm_use_t *ptr, *start;
448 unsigned int num;
450 start = &(SSA_NAME_IMM_USE_NODE (var));
451 num = 0;
452 for (ptr = start->next; ptr != start; ptr = ptr->next)
453 num++;
455 return num;
458 /* Return the definitions present in ANN, a statement annotation.
459 Return NULL if this annotation contains no definitions. */
460 static inline def_optype
461 get_def_ops (stmt_ann_t ann)
463 return ann ? ann->operands.def_ops : NULL;
466 /* Return the uses present in ANN, a statement annotation.
467 Return NULL if this annotation contains no uses. */
468 static inline use_optype
469 get_use_ops (stmt_ann_t ann)
471 return ann ? ann->operands.use_ops : NULL;
474 /* Return the virtual may-defs present in ANN, a statement
475 annotation.
476 Return NULL if this annotation contains no virtual may-defs. */
477 static inline v_may_def_optype
478 get_v_may_def_ops (stmt_ann_t ann)
480 return ann ? ann->operands.v_may_def_ops : NULL;
483 /* Return the virtual uses present in ANN, a statement annotation.
484 Return NULL if this annotation contains no virtual uses. */
485 static inline vuse_optype
486 get_vuse_ops (stmt_ann_t ann)
488 return ann ? ann->operands.vuse_ops : NULL;
491 /* Return the virtual must-defs present in ANN, a statement
492 annotation. Return NULL if this annotation contains no must-defs.*/
493 static inline v_must_def_optype
494 get_v_must_def_ops (stmt_ann_t ann)
496 return ann ? ann->operands.v_must_def_ops : NULL;
499 /* Return the tree pointer to by USE. */
500 static inline tree
501 get_use_from_ptr (use_operand_p use)
503 return *(use->use);
506 /* Return the tree pointer to by DEF. */
507 static inline tree
508 get_def_from_ptr (def_operand_p def)
510 return *(def.def);
513 /* Return a pointer to the tree that is at INDEX in the USES array. */
514 static inline use_operand_p
515 get_use_op_ptr (use_optype uses, unsigned int index)
517 gcc_assert (index < uses->num_uses);
518 return &(uses->uses[index]);
521 /* Return a def_operand_p pointer for element INDEX of DEFS. */
522 static inline def_operand_p
523 get_def_op_ptr (def_optype defs, unsigned int index)
525 gcc_assert (index < defs->num_defs);
526 return defs->defs[index];
529 /* Return the def_operand_p that is the V_MAY_DEF_RESULT for the V_MAY_DEF
530 at INDEX in the V_MAY_DEFS array. */
531 static inline def_operand_p
532 get_v_may_def_result_ptr(v_may_def_optype v_may_defs, unsigned int index)
534 def_operand_p op;
535 gcc_assert (index < v_may_defs->num_v_may_defs);
536 op.def = &(v_may_defs->v_may_defs[index].def);
537 return op;
540 /* Return a use_operand_p that is the V_MAY_DEF_OP for the V_MAY_DEF at
541 INDEX in the V_MAY_DEFS array. */
542 static inline use_operand_p
543 get_v_may_def_op_ptr(v_may_def_optype v_may_defs, unsigned int index)
545 gcc_assert (index < v_may_defs->num_v_may_defs);
546 return &(v_may_defs->v_may_defs[index].imm_use);
549 /* Return a use_operand_p that is at INDEX in the VUSES array. */
550 static inline use_operand_p
551 get_vuse_op_ptr(vuse_optype vuses, unsigned int index)
553 gcc_assert (index < vuses->num_vuses);
554 return &(vuses->vuses[index].imm_use);
557 /* Return a def_operand_p that is the V_MUST_DEF_RESULT for the
558 V_MUST_DEF at INDEX in the V_MUST_DEFS array. */
559 static inline def_operand_p
560 get_v_must_def_result_ptr (v_must_def_optype v_must_defs, unsigned int index)
562 def_operand_p op;
563 gcc_assert (index < v_must_defs->num_v_must_defs);
564 op.def = &(v_must_defs->v_must_defs[index].def);
565 return op;
568 /* Return a use_operand_p that is the V_MUST_DEF_KILL for the
569 V_MUST_DEF at INDEX in the V_MUST_DEFS array. */
570 static inline use_operand_p
571 get_v_must_def_kill_ptr (v_must_def_optype v_must_defs, unsigned int index)
573 gcc_assert (index < v_must_defs->num_v_must_defs);
574 return &(v_must_defs->v_must_defs[index].imm_use);
577 /* Return a def_operand_p pointer for the result of PHI. */
578 static inline def_operand_p
579 get_phi_result_ptr (tree phi)
581 def_operand_p op;
582 op.def = &(PHI_RESULT_TREE (phi));
583 return op;
586 /* Return a use_operand_p pointer for argument I of phinode PHI. */
587 static inline use_operand_p
588 get_phi_arg_def_ptr (tree phi, int i)
590 return &(PHI_ARG_IMM_USE_NODE (phi,i));
593 /* Delink all immediate_use information for STMT. */
594 static inline void
595 delink_stmt_imm_use (tree stmt)
597 unsigned int x;
598 use_optype uses = STMT_USE_OPS (stmt);
599 vuse_optype vuses = STMT_VUSE_OPS (stmt);
600 v_may_def_optype v_may_defs = STMT_V_MAY_DEF_OPS (stmt);
601 v_must_def_optype v_must_defs = STMT_V_MUST_DEF_OPS (stmt);
603 for (x = 0; x < NUM_USES (uses); x++)
604 delink_imm_use (&(uses->uses[x]));
606 for (x = 0; x < NUM_VUSES (vuses); x++)
607 delink_imm_use (&(vuses->vuses[x].imm_use));
609 for (x = 0; x < NUM_V_MAY_DEFS (v_may_defs); x++)
610 delink_imm_use (&(v_may_defs->v_may_defs[x].imm_use));
612 for (x = 0; x < NUM_V_MUST_DEFS (v_must_defs); x++)
613 delink_imm_use (&(v_must_defs->v_must_defs[x].imm_use));
617 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
618 no addresses. */
619 static inline bitmap
620 addresses_taken (tree stmt)
622 stmt_ann_t ann = stmt_ann (stmt);
623 return ann ? ann->addresses_taken : NULL;
626 /* Return the basic_block annotation for BB. */
627 static inline bb_ann_t
628 bb_ann (basic_block bb)
630 return (bb_ann_t)bb->tree_annotations;
633 /* Return the PHI nodes for basic block BB, or NULL if there are no
634 PHI nodes. */
635 static inline tree
636 phi_nodes (basic_block bb)
638 return bb_ann (bb)->phi_nodes;
641 /* Set list of phi nodes of a basic block BB to L. */
643 static inline void
644 set_phi_nodes (basic_block bb, tree l)
646 tree phi;
648 bb_ann (bb)->phi_nodes = l;
649 for (phi = l; phi; phi = PHI_CHAIN (phi))
650 set_bb_for_stmt (phi, bb);
653 /* Return the phi argument which contains the specified use. */
655 static inline int
656 phi_arg_index_from_use (use_operand_p use)
658 struct phi_arg_d *element, *root;
659 int index;
660 tree phi;
662 /* Since the use is the first thing in a PHI argument element, we can
663 calculate its index based on casting it to an argument, and performing
664 pointer arithmetic. */
666 phi = USE_STMT (use);
667 gcc_assert (TREE_CODE (phi) == PHI_NODE);
669 element = (struct phi_arg_d *)use;
670 root = &(PHI_ARG_ELT (phi, 0));
671 index = element - root;
673 #ifdef ENABLE_CHECKING
674 /* Make sure the calculation doesn't have any leftover bytes. If it does,
675 then imm_use is likely not the first element in phi_arg_d. */
676 gcc_assert (
677 (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
678 gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
679 #endif
681 return index;
684 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
686 static inline void
687 set_is_used (tree var)
689 var_ann_t ann = get_var_ann (var);
690 ann->used = 1;
694 /* ----------------------------------------------------------------------- */
696 /* Return true if T is an executable statement. */
697 static inline bool
698 is_exec_stmt (tree t)
700 return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
704 /* Return true if this stmt can be the target of a control transfer stmt such
705 as a goto. */
706 static inline bool
707 is_label_stmt (tree t)
709 if (t)
710 switch (TREE_CODE (t))
712 case LABEL_DECL:
713 case LABEL_EXPR:
714 case CASE_LABEL_EXPR:
715 return true;
716 default:
717 return false;
719 return false;
722 /* Set the default definition for VAR to DEF. */
723 static inline void
724 set_default_def (tree var, tree def)
726 var_ann_t ann = get_var_ann (var);
727 ann->default_def = def;
730 /* Return the default definition for variable VAR, or NULL if none
731 exists. */
732 static inline tree
733 default_def (tree var)
735 var_ann_t ann = var_ann (var);
736 return ann ? ann->default_def : NULL_TREE;
739 /* PHI nodes should contain only ssa_names and invariants. A test
740 for ssa_name is definitely simpler; don't let invalid contents
741 slip in in the meantime. */
743 static inline bool
744 phi_ssa_name_p (tree t)
746 if (TREE_CODE (t) == SSA_NAME)
747 return true;
748 #ifdef ENABLE_CHECKING
749 gcc_assert (is_gimple_min_invariant (t));
750 #endif
751 return false;
754 /* ----------------------------------------------------------------------- */
756 /* Return a block_stmt_iterator that points to beginning of basic
757 block BB. */
758 static inline block_stmt_iterator
759 bsi_start (basic_block bb)
761 block_stmt_iterator bsi;
762 if (bb->stmt_list)
763 bsi.tsi = tsi_start (bb->stmt_list);
764 else
766 gcc_assert (bb->index < 0);
767 bsi.tsi.ptr = NULL;
768 bsi.tsi.container = NULL;
770 bsi.bb = bb;
771 return bsi;
774 /* Return a block statement iterator that points to the last label in
775 block BB. */
777 static inline block_stmt_iterator
778 bsi_after_labels (basic_block bb)
780 block_stmt_iterator bsi;
781 tree_stmt_iterator next;
783 bsi.bb = bb;
785 if (!bb->stmt_list)
787 gcc_assert (bb->index < 0);
788 bsi.tsi.ptr = NULL;
789 bsi.tsi.container = NULL;
790 return bsi;
793 bsi.tsi = tsi_start (bb->stmt_list);
794 if (tsi_end_p (bsi.tsi))
795 return bsi;
797 /* Ensure that there are some labels. The rationale is that we want
798 to insert after the bsi that is returned, and these insertions should
799 be placed at the start of the basic block. This would not work if the
800 first statement was not label; rather fail here than enable the user
801 proceed in wrong way. */
802 gcc_assert (TREE_CODE (tsi_stmt (bsi.tsi)) == LABEL_EXPR);
804 next = bsi.tsi;
805 tsi_next (&next);
807 while (!tsi_end_p (next)
808 && TREE_CODE (tsi_stmt (next)) == LABEL_EXPR)
810 bsi.tsi = next;
811 tsi_next (&next);
814 return bsi;
817 /* Return a block statement iterator that points to the end of basic
818 block BB. */
819 static inline block_stmt_iterator
820 bsi_last (basic_block bb)
822 block_stmt_iterator bsi;
823 if (bb->stmt_list)
824 bsi.tsi = tsi_last (bb->stmt_list);
825 else
827 gcc_assert (bb->index < 0);
828 bsi.tsi.ptr = NULL;
829 bsi.tsi.container = NULL;
831 bsi.bb = bb;
832 return bsi;
835 /* Return true if block statement iterator I has reached the end of
836 the basic block. */
837 static inline bool
838 bsi_end_p (block_stmt_iterator i)
840 return tsi_end_p (i.tsi);
843 /* Modify block statement iterator I so that it is at the next
844 statement in the basic block. */
845 static inline void
846 bsi_next (block_stmt_iterator *i)
848 tsi_next (&i->tsi);
851 /* Modify block statement iterator I so that it is at the previous
852 statement in the basic block. */
853 static inline void
854 bsi_prev (block_stmt_iterator *i)
856 tsi_prev (&i->tsi);
859 /* Return the statement that block statement iterator I is currently
860 at. */
861 static inline tree
862 bsi_stmt (block_stmt_iterator i)
864 return tsi_stmt (i.tsi);
867 /* Return a pointer to the statement that block statement iterator I
868 is currently at. */
869 static inline tree *
870 bsi_stmt_ptr (block_stmt_iterator i)
872 return tsi_stmt_ptr (i.tsi);
875 /* Returns the loop of the statement STMT. */
877 static inline struct loop *
878 loop_containing_stmt (tree stmt)
880 basic_block bb = bb_for_stmt (stmt);
881 if (!bb)
882 return NULL;
884 return bb->loop_father;
887 /* Return true if VAR is a clobbered by function calls. */
888 static inline bool
889 is_call_clobbered (tree var)
891 return is_global_var (var)
892 || bitmap_bit_p (call_clobbered_vars, var_ann (var)->uid);
895 /* Mark variable VAR as being clobbered by function calls. */
896 static inline void
897 mark_call_clobbered (tree var)
899 var_ann_t ann = var_ann (var);
900 /* If VAR is a memory tag, then we need to consider it a global
901 variable. This is because the pointer that VAR represents has
902 been found to point to either an arbitrary location or to a known
903 location in global memory. */
904 if (ann->mem_tag_kind != NOT_A_TAG && ann->mem_tag_kind != STRUCT_FIELD)
905 DECL_EXTERNAL (var) = 1;
906 bitmap_set_bit (call_clobbered_vars, ann->uid);
907 ssa_call_clobbered_cache_valid = false;
908 ssa_ro_call_cache_valid = false;
911 /* Clear the call-clobbered attribute from variable VAR. */
912 static inline void
913 clear_call_clobbered (tree var)
915 var_ann_t ann = var_ann (var);
916 if (ann->mem_tag_kind != NOT_A_TAG && ann->mem_tag_kind != STRUCT_FIELD)
917 DECL_EXTERNAL (var) = 0;
918 bitmap_clear_bit (call_clobbered_vars, ann->uid);
919 ssa_call_clobbered_cache_valid = false;
920 ssa_ro_call_cache_valid = false;
923 /* Mark variable VAR as being non-addressable. */
924 static inline void
925 mark_non_addressable (tree var)
927 bitmap_clear_bit (call_clobbered_vars, var_ann (var)->uid);
928 TREE_ADDRESSABLE (var) = 0;
929 ssa_call_clobbered_cache_valid = false;
930 ssa_ro_call_cache_valid = false;
933 /* Return the common annotation for T. Return NULL if the annotation
934 doesn't already exist. */
935 static inline tree_ann_t
936 tree_ann (tree t)
938 return t->common.ann;
941 /* Return a common annotation for T. Create the constant annotation if it
942 doesn't exist. */
943 static inline tree_ann_t
944 get_tree_ann (tree t)
946 tree_ann_t ann = tree_ann (t);
947 return (ann) ? ann : create_tree_ann (t);
950 /* ----------------------------------------------------------------------- */
952 /* The following set of routines are used to iterator over various type of
953 SSA operands. */
955 /* Return true if PTR is finished iterating. */
956 static inline bool
957 op_iter_done (ssa_op_iter *ptr)
959 return ptr->done;
962 /* Get the next iterator use value for PTR. */
963 static inline use_operand_p
964 op_iter_next_use (ssa_op_iter *ptr)
966 if (ptr->use_i < ptr->num_use)
968 return USE_OP_PTR (ptr->ops->use_ops, (ptr->use_i)++);
970 if (ptr->vuse_i < ptr->num_vuse)
972 return VUSE_OP_PTR (ptr->ops->vuse_ops, (ptr->vuse_i)++);
974 if (ptr->v_mayu_i < ptr->num_v_mayu)
976 return V_MAY_DEF_OP_PTR (ptr->ops->v_may_def_ops,
977 (ptr->v_mayu_i)++);
979 if (ptr->v_mustu_i < ptr->num_v_mustu)
981 return V_MUST_DEF_KILL_PTR (ptr->ops->v_must_def_ops,
982 (ptr->v_mustu_i)++);
984 ptr->done = true;
985 return NULL_USE_OPERAND_P;
988 /* Get the next iterator def value for PTR. */
989 static inline def_operand_p
990 op_iter_next_def (ssa_op_iter *ptr)
992 if (ptr->def_i < ptr->num_def)
994 return DEF_OP_PTR (ptr->ops->def_ops, (ptr->def_i)++);
996 if (ptr->v_mustd_i < ptr->num_v_mustd)
998 return V_MUST_DEF_RESULT_PTR (ptr->ops->v_must_def_ops,
999 (ptr->v_mustd_i)++);
1001 if (ptr->v_mayd_i < ptr->num_v_mayd)
1003 return V_MAY_DEF_RESULT_PTR (ptr->ops->v_may_def_ops,
1004 (ptr->v_mayd_i)++);
1006 ptr->done = true;
1007 return NULL_DEF_OPERAND_P;
1010 /* Get the next iterator tree value for PTR. */
1011 static inline tree
1012 op_iter_next_tree (ssa_op_iter *ptr)
1014 if (ptr->use_i < ptr->num_use)
1016 return USE_OP (ptr->ops->use_ops, (ptr->use_i)++);
1018 if (ptr->vuse_i < ptr->num_vuse)
1020 return VUSE_OP (ptr->ops->vuse_ops, (ptr->vuse_i)++);
1022 if (ptr->v_mayu_i < ptr->num_v_mayu)
1024 return V_MAY_DEF_OP (ptr->ops->v_may_def_ops, (ptr->v_mayu_i)++);
1026 if (ptr->v_mustu_i < ptr->num_v_mustu)
1028 return V_MUST_DEF_KILL (ptr->ops->v_must_def_ops, (ptr->v_mustu_i)++);
1030 if (ptr->def_i < ptr->num_def)
1032 return DEF_OP (ptr->ops->def_ops, (ptr->def_i)++);
1034 if (ptr->v_mustd_i < ptr->num_v_mustd)
1036 return V_MUST_DEF_RESULT (ptr->ops->v_must_def_ops,
1037 (ptr->v_mustd_i)++);
1039 if (ptr->v_mayd_i < ptr->num_v_mayd)
1041 return V_MAY_DEF_RESULT (ptr->ops->v_may_def_ops,
1042 (ptr->v_mayd_i)++);
1044 ptr->done = true;
1045 return NULL;
1048 /* Initialize the iterator PTR to the virtual defs in STMT. */
1049 static inline void
1050 op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
1052 stmt_operands_p ops;
1053 stmt_ann_t ann = get_stmt_ann (stmt);
1055 ops = &(ann->operands);
1056 ptr->done = false;
1057 ptr->ops = ops;
1058 ptr->num_def = (flags & SSA_OP_DEF) ? NUM_DEFS (ops->def_ops) : 0;
1059 ptr->num_use = (flags & SSA_OP_USE) ? NUM_USES (ops->use_ops) : 0;
1060 ptr->num_vuse = (flags & SSA_OP_VUSE) ? NUM_VUSES (ops->vuse_ops) : 0;
1061 ptr->num_v_mayu = (flags & SSA_OP_VMAYUSE)
1062 ? NUM_V_MAY_DEFS (ops->v_may_def_ops) : 0;
1063 ptr->num_v_mayd = (flags & SSA_OP_VMAYDEF)
1064 ? NUM_V_MAY_DEFS (ops->v_may_def_ops) : 0;
1065 ptr->num_v_mustu = (flags & SSA_OP_VMUSTDEFKILL)
1066 ? NUM_V_MUST_DEFS (ops->v_must_def_ops) : 0;
1067 ptr->num_v_mustd = (flags & SSA_OP_VMUSTDEF)
1068 ? NUM_V_MUST_DEFS (ops->v_must_def_ops) : 0;
1069 ptr->def_i = 0;
1070 ptr->use_i = 0;
1071 ptr->vuse_i = 0;
1072 ptr->v_mayu_i = 0;
1073 ptr->v_mayd_i = 0;
1074 ptr->v_mustu_i = 0;
1075 ptr->v_mustd_i = 0;
1078 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1079 the first use. */
1080 static inline use_operand_p
1081 op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
1083 op_iter_init (ptr, stmt, flags);
1084 return op_iter_next_use (ptr);
1087 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1088 the first def. */
1089 static inline def_operand_p
1090 op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1092 op_iter_init (ptr, stmt, flags);
1093 return op_iter_next_def (ptr);
1096 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1097 the first operand as a tree. */
1098 static inline tree
1099 op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1101 op_iter_init (ptr, stmt, flags);
1102 return op_iter_next_tree (ptr);
1105 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1106 KILL and DEF. */
1107 static inline void
1108 op_iter_next_mustdef (use_operand_p *kill, def_operand_p *def, ssa_op_iter *ptr)
1110 if (ptr->v_mustu_i < ptr->num_v_mustu)
1112 *def = V_MUST_DEF_RESULT_PTR (ptr->ops->v_must_def_ops, ptr->v_mustu_i);
1113 *kill = V_MUST_DEF_KILL_PTR (ptr->ops->v_must_def_ops, (ptr->v_mustu_i)++);
1114 return;
1116 else
1118 *def = NULL_DEF_OPERAND_P;
1119 *kill = NULL_USE_OPERAND_P;
1121 ptr->done = true;
1122 return;
1125 /* Get the next iterator maydef value for PTR, returning the maydef values in
1126 USE and DEF. */
1127 static inline void
1128 op_iter_next_maydef (use_operand_p *use, def_operand_p *def, ssa_op_iter *ptr)
1130 if (ptr->v_mayu_i < ptr->num_v_mayu)
1132 *def = V_MAY_DEF_RESULT_PTR (ptr->ops->v_may_def_ops, ptr->v_mayu_i);
1133 *use = V_MAY_DEF_OP_PTR (ptr->ops->v_may_def_ops, (ptr->v_mayu_i)++);
1134 return;
1136 else
1138 *def = NULL_DEF_OPERAND_P;
1139 *use = NULL_USE_OPERAND_P;
1141 ptr->done = true;
1142 return;
1145 /* Get the next iterator mustdef or maydef value for PTR, returning the
1146 mustdef or maydef values in KILL and DEF. */
1147 static inline void
1148 op_iter_next_must_and_may_def (use_operand_p *kill,
1149 def_operand_p *def,
1150 ssa_op_iter *ptr)
1152 if (ptr->v_mustu_i < ptr->num_v_mustu)
1154 *def = V_MUST_DEF_RESULT_PTR (ptr->ops->v_must_def_ops, ptr->v_mustu_i);
1155 *kill = V_MUST_DEF_KILL_PTR (ptr->ops->v_must_def_ops, (ptr->v_mustu_i)++);
1156 return;
1158 else if (ptr->v_mayu_i < ptr->num_v_mayu)
1160 *def = V_MAY_DEF_RESULT_PTR (ptr->ops->v_may_def_ops, ptr->v_mayu_i);
1161 *kill = V_MAY_DEF_OP_PTR (ptr->ops->v_may_def_ops, (ptr->v_mayu_i)++);
1162 return;
1164 else
1166 *def = NULL_DEF_OPERAND_P;
1167 *kill = NULL_USE_OPERAND_P;
1169 ptr->done = true;
1170 return;
1173 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1174 in USE and DEF. */
1175 static inline void
1176 op_iter_init_maydef (ssa_op_iter *ptr, tree stmt, use_operand_p *use,
1177 def_operand_p *def)
1179 op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1180 op_iter_next_maydef (use, def, ptr);
1184 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1185 in KILL and DEF. */
1186 static inline void
1187 op_iter_init_mustdef (ssa_op_iter *ptr, tree stmt, use_operand_p *kill,
1188 def_operand_p *def)
1190 op_iter_init (ptr, stmt, SSA_OP_VMUSTDEFKILL);
1191 op_iter_next_mustdef (kill, def, ptr);
1194 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1195 in KILL and DEF. */
1196 static inline void
1197 op_iter_init_must_and_may_def (ssa_op_iter *ptr, tree stmt,
1198 use_operand_p *kill, def_operand_p *def)
1200 op_iter_init (ptr, stmt, SSA_OP_VMUSTDEFKILL | SSA_OP_VMAYUSE);
1201 op_iter_next_must_and_may_def (kill, def, ptr);
1204 /* Return true if VAR cannot be modified by the program. */
1206 static inline bool
1207 unmodifiable_var_p (tree var)
1209 if (TREE_CODE (var) == SSA_NAME)
1210 var = SSA_NAME_VAR (var);
1211 return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1214 /* Return true if REF, a COMPONENT_REF, has an ARRAY_REF somewhere in it. */
1216 static inline bool
1217 ref_contains_array_ref (tree ref)
1219 while (handled_component_p (ref))
1221 if (TREE_CODE (ref) == ARRAY_REF)
1222 return true;
1223 ref = TREE_OPERAND (ref, 0);
1225 return false;
1228 /* Given a variable VAR, lookup and return a pointer to the list of
1229 subvariables for it. */
1231 static inline subvar_t *
1232 lookup_subvars_for_var (tree var)
1234 var_ann_t ann = var_ann (var);
1235 gcc_assert (ann);
1236 return &ann->subvars;
1239 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1240 NULL, if there are no subvariables. */
1242 static inline subvar_t
1243 get_subvars_for_var (tree var)
1245 subvar_t subvars;
1247 gcc_assert (SSA_VAR_P (var));
1249 if (TREE_CODE (var) == SSA_NAME)
1250 subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
1251 else
1252 subvars = *(lookup_subvars_for_var (var));
1253 return subvars;
1256 /* Return true if V is a tree that we can have subvars for.
1257 Normally, this is any aggregate type, however, due to implementation
1258 limitations ATM, we exclude array types as well. */
1260 static inline bool
1261 var_can_have_subvars (tree v)
1263 return (AGGREGATE_TYPE_P (TREE_TYPE (v)) &&
1264 TREE_CODE (TREE_TYPE (v)) != ARRAY_TYPE);
1268 /* Return true if OFFSET and SIZE define a range that overlaps with some
1269 portion of the range of SV, a subvar. If there was an exact overlap,
1270 *EXACT will be set to true upon return. */
1272 static inline bool
1273 overlap_subvar (HOST_WIDE_INT offset, HOST_WIDE_INT size,
1274 subvar_t sv, bool *exact)
1276 /* There are three possible cases of overlap.
1277 1. We can have an exact overlap, like so:
1278 |offset, offset + size |
1279 |sv->offset, sv->offset + sv->size |
1281 2. We can have offset starting after sv->offset, like so:
1283 |offset, offset + size |
1284 |sv->offset, sv->offset + sv->size |
1286 3. We can have offset starting before sv->offset, like so:
1288 |offset, offset + size |
1289 |sv->offset, sv->offset + sv->size|
1292 if (exact)
1293 *exact = false;
1294 if (offset == sv->offset && size == sv->size)
1296 if (exact)
1297 *exact = true;
1298 return true;
1300 else if (offset >= sv->offset && offset < (sv->offset + sv->size))
1302 return true;
1304 else if (offset < sv->offset && (offset + size > sv->offset))
1306 return true;
1308 return false;
1312 #endif /* _TREE_FLOW_INLINE_H */