2005-04-08 Kelley Cook <kcook@gcc.gnu.org>
[official-gcc.git] / gcc / tree-flow-inline.h
blob169dce2f402428602a9acbb2a8b60651894532e5
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, 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 static inline void
176 get_stmt_operands (tree stmt ATTRIBUTE_UNUSED)
178 #ifdef ENABLE_CHECKING
179 stmt_ann_t ann;
181 /* The optimizers cannot handle statements that are nothing but a
182 _DECL. This indicates a bug in the gimplifier. */
183 gcc_assert (!SSA_VAR_P (stmt));
185 /* Ignore error statements. */
186 if (TREE_CODE (stmt) == ERROR_MARK)
187 return;
189 ann = get_stmt_ann (stmt);
190 gcc_assert (!ann->modified);
192 return;
193 #endif
196 /* Return true if T is marked as modified, false otherwise. */
197 static inline bool
198 stmt_modified_p (tree t)
200 stmt_ann_t ann = stmt_ann (t);
202 /* Note that if the statement doesn't yet have an annotation, we consider it
203 modified. This will force the next call to update_stmt_operands to scan
204 the statement. */
205 return ann ? ann->modified : true;
208 /* Delink an immediate_uses node from its chain. */
209 static inline void
210 delink_imm_use (ssa_imm_use_t *linknode)
212 /* Return if this node is not in a list. */
213 if (linknode->prev == NULL)
214 return;
216 linknode->prev->next = linknode->next;
217 linknode->next->prev = linknode->prev;
218 linknode->prev = NULL;
219 linknode->next = NULL;
222 /* Link ssa_imm_use node LINKNODE into the chain for LIST. */
223 static inline void
224 link_imm_use_to_list (ssa_imm_use_t *linknode, ssa_imm_use_t *list)
226 /* Link the new node at the head of the list. If we are in the process of
227 traversing the list, we wont visit any new nodes added to it. */
228 linknode->prev = list;
229 linknode->next = list->next;
230 list->next->prev = linknode;
231 list->next = linknode;
234 /* Link ssa_imm_use node LINKNODE into the chain for DEF. */
235 static inline void
236 link_imm_use (ssa_imm_use_t *linknode, tree def)
238 ssa_imm_use_t *root;
240 if (!def || TREE_CODE (def) != SSA_NAME)
241 linknode->prev = NULL;
242 else
244 root = &(SSA_NAME_IMM_USE_NODE (def));
245 #ifdef ENABLE_CHECKING
246 if (linknode->use)
247 gcc_assert (*(linknode->use) == def);
248 #endif
249 link_imm_use_to_list (linknode, root);
253 /* Set the value of a use pointed by USE to VAL. */
254 static inline void
255 set_ssa_use_from_ptr (use_operand_p use, tree val)
257 delink_imm_use (use);
258 *(use->use) = val;
259 link_imm_use (use, val);
262 /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occuring
263 in STMT. */
264 static inline void
265 link_imm_use_stmt (ssa_imm_use_t *linknode, tree def, tree stmt)
267 if (stmt)
268 link_imm_use (linknode, def);
269 else
270 link_imm_use (linknode, NULL);
271 linknode->stmt = stmt;
274 /* Relink a new node in place of an old node in the list. */
275 static inline void
276 relink_imm_use (ssa_imm_use_t *node, ssa_imm_use_t *old)
278 #ifdef ENABLE_CHECKING
279 /* The node one had better be in the same list. */
280 if (*(old->use) != *(node->use))
281 abort ();
282 #endif
283 node->prev = old->prev;
284 node->next = old->next;
285 if (old->prev)
287 old->prev->next = node;
288 old->next->prev = node;
289 /* Remove the old node from the list. */
290 old->prev = NULL;
295 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occuring
296 in STMT. */
297 static inline void
298 relink_imm_use_stmt (ssa_imm_use_t *linknode, ssa_imm_use_t *old, tree stmt)
300 if (stmt)
301 relink_imm_use (linknode, old);
302 else
303 link_imm_use (linknode, NULL);
304 linknode->stmt = stmt;
307 /* Finished the traverse of an immediate use list IMM by removing it from
308 the list. */
309 static inline void
310 end_safe_imm_use_traverse (imm_use_iterator *imm)
312 delink_imm_use (&(imm->iter_node));
315 /* Return true if IMM is at the end of the list. */
316 static inline bool
317 end_safe_imm_use_p (imm_use_iterator *imm)
319 return (imm->imm_use == imm->end_p);
322 /* Initialize iterator IMM to process the list for VAR. */
323 static inline use_operand_p
324 first_safe_imm_use (imm_use_iterator *imm, tree var)
326 /* Set up and link the iterator node into the linked list for VAR. */
327 imm->iter_node.use = NULL;
328 imm->iter_node.stmt = NULL_TREE;
329 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
330 /* Check if there are 0 elements. */
331 if (imm->end_p->next == imm->end_p)
333 imm->imm_use = imm->end_p;
334 return NULL_USE_OPERAND_P;
337 link_imm_use (&(imm->iter_node), var);
338 imm->imm_use = imm->iter_node.next;
339 return imm->imm_use;
342 /* Bump IMM to then next use in the list. */
343 static inline use_operand_p
344 next_safe_imm_use (imm_use_iterator *imm)
346 ssa_imm_use_t *ptr;
347 use_operand_p old;
349 old = imm->imm_use;
350 /* If the next node following the iter_node is still the one referred to by
351 imm_use, then the list hasn't changed, go to the next node. */
352 if (imm->iter_node.next == imm->imm_use)
354 ptr = &(imm->iter_node);
355 /* Remove iternode from the list. */
356 delink_imm_use (ptr);
357 imm->imm_use = imm->imm_use->next;
358 if (! end_safe_imm_use_p (imm))
360 /* This isnt the end, link iternode before the next use. */
361 ptr->prev = imm->imm_use->prev;
362 ptr->next = imm->imm_use;
363 imm->imm_use->prev->next = ptr;
364 imm->imm_use->prev = ptr;
366 else
367 return old;
369 else
371 /* If the 'next' value after the iterator isn't the same as it was, then
372 a node has been deleted, so we simply proceed to the node following
373 where the iterator is in the list. */
374 imm->imm_use = imm->iter_node.next;
375 if (end_safe_imm_use_p (imm))
377 end_safe_imm_use_traverse (imm);
378 return old;
382 return imm->imm_use;
385 /* Return true is IMM has reached the end of the immediate use list. */
386 static inline bool
387 end_readonly_imm_use_p (imm_use_iterator *imm)
389 return (imm->imm_use == imm->end_p);
392 /* Initialize iterator IMM to process the list for VAR. */
393 static inline use_operand_p
394 first_readonly_imm_use (imm_use_iterator *imm, tree var)
396 gcc_assert (TREE_CODE (var) == SSA_NAME);
398 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
399 imm->imm_use = imm->end_p->next;
400 #ifdef ENABLE_CHECKING
401 imm->iter_node.next = imm->imm_use->next;
402 #endif
403 if (end_readonly_imm_use_p (imm))
404 return NULL_USE_OPERAND_P;
405 return imm->imm_use;
408 /* Bump IMM to then next use in the list. */
409 static inline use_operand_p
410 next_readonly_imm_use (imm_use_iterator *imm)
412 use_operand_p old = imm->imm_use;
414 #ifdef ENABLE_CHECKING
415 /* If this assertion fails, it indicates the 'next' pointer has changed
416 since we the last bump. This indicates that the list is being modified
417 via stmt changes, or SET_USE, or somesuch thing, and you need to be
418 using the SAFE version of the iterator. */
419 gcc_assert (imm->iter_node.next == old->next);
420 imm->iter_node.next = old->next->next;
421 #endif
423 imm->imm_use = old->next;
424 if (end_readonly_imm_use_p (imm))
425 return old;
426 return imm->imm_use;
429 /* Return true if VAR has no uses. */
430 static inline bool
431 has_zero_uses (tree var)
433 ssa_imm_use_t *ptr;
434 ptr = &(SSA_NAME_IMM_USE_NODE (var));
435 /* A single use means there is no items in the list. */
436 return (ptr == ptr->next);
439 /* Return true if VAR has a single use. */
440 static inline bool
441 has_single_use (tree var)
443 ssa_imm_use_t *ptr;
444 ptr = &(SSA_NAME_IMM_USE_NODE (var));
445 /* A single use means there is one item in the list. */
446 return (ptr != ptr->next && ptr == ptr->next->next);
449 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
450 to the use pointer and stmt of occurrence. */
451 static inline bool
452 single_imm_use (tree var, use_operand_p *use_p, tree *stmt)
454 ssa_imm_use_t *ptr;
456 ptr = &(SSA_NAME_IMM_USE_NODE (var));
457 if (ptr != ptr->next && ptr == ptr->next->next)
459 *use_p = ptr->next;
460 *stmt = ptr->next->stmt;
461 return true;
463 *use_p = NULL_USE_OPERAND_P;
464 *stmt = NULL_TREE;
465 return false;
468 /* Return the number of immediate uses of VAR. */
469 static inline unsigned int
470 num_imm_uses (tree var)
472 ssa_imm_use_t *ptr, *start;
473 unsigned int num;
475 start = &(SSA_NAME_IMM_USE_NODE (var));
476 num = 0;
477 for (ptr = start->next; ptr != start; ptr = ptr->next)
478 num++;
480 return num;
483 /* Return the definitions present in ANN, a statement annotation.
484 Return NULL if this annotation contains no definitions. */
485 static inline def_optype
486 get_def_ops (stmt_ann_t ann)
488 return ann ? ann->operands.def_ops : NULL;
491 /* Return the uses present in ANN, a statement annotation.
492 Return NULL if this annotation contains no uses. */
493 static inline use_optype
494 get_use_ops (stmt_ann_t ann)
496 return ann ? ann->operands.use_ops : NULL;
499 /* Return the virtual may-defs present in ANN, a statement
500 annotation.
501 Return NULL if this annotation contains no virtual may-defs. */
502 static inline v_may_def_optype
503 get_v_may_def_ops (stmt_ann_t ann)
505 return ann ? ann->operands.v_may_def_ops : NULL;
508 /* Return the virtual uses present in ANN, a statement annotation.
509 Return NULL if this annotation contains no virtual uses. */
510 static inline vuse_optype
511 get_vuse_ops (stmt_ann_t ann)
513 return ann ? ann->operands.vuse_ops : NULL;
516 /* Return the virtual must-defs present in ANN, a statement
517 annotation. Return NULL if this annotation contains no must-defs.*/
518 static inline v_must_def_optype
519 get_v_must_def_ops (stmt_ann_t ann)
521 return ann ? ann->operands.v_must_def_ops : NULL;
524 /* Return the tree pointer to by USE. */
525 static inline tree
526 get_use_from_ptr (use_operand_p use)
528 return *(use->use);
531 /* Return the tree pointer to by DEF. */
532 static inline tree
533 get_def_from_ptr (def_operand_p def)
535 return *(def.def);
538 /* Return a pointer to the tree that is at INDEX in the USES array. */
539 static inline use_operand_p
540 get_use_op_ptr (use_optype uses, unsigned int index)
542 gcc_assert (index < uses->num_uses);
543 return &(uses->uses[index]);
546 /* Return a def_operand_p pointer for element INDEX of DEFS. */
547 static inline def_operand_p
548 get_def_op_ptr (def_optype defs, unsigned int index)
550 gcc_assert (index < defs->num_defs);
551 return defs->defs[index];
554 /* Return the def_operand_p that is the V_MAY_DEF_RESULT for the V_MAY_DEF
555 at INDEX in the V_MAY_DEFS array. */
556 static inline def_operand_p
557 get_v_may_def_result_ptr(v_may_def_optype v_may_defs, unsigned int index)
559 def_operand_p op;
560 gcc_assert (index < v_may_defs->num_v_may_defs);
561 op.def = &(v_may_defs->v_may_defs[index].def);
562 return op;
565 /* Return a use_operand_p that is the V_MAY_DEF_OP for the V_MAY_DEF at
566 INDEX in the V_MAY_DEFS array. */
567 static inline use_operand_p
568 get_v_may_def_op_ptr(v_may_def_optype v_may_defs, unsigned int index)
570 gcc_assert (index < v_may_defs->num_v_may_defs);
571 return &(v_may_defs->v_may_defs[index].imm_use);
574 /* Return a use_operand_p that is at INDEX in the VUSES array. */
575 static inline use_operand_p
576 get_vuse_op_ptr(vuse_optype vuses, unsigned int index)
578 gcc_assert (index < vuses->num_vuses);
579 return &(vuses->vuses[index].imm_use);
582 /* Return a def_operand_p that is the V_MUST_DEF_RESULT for the
583 V_MUST_DEF at INDEX in the V_MUST_DEFS array. */
584 static inline def_operand_p
585 get_v_must_def_result_ptr (v_must_def_optype v_must_defs, unsigned int index)
587 def_operand_p op;
588 gcc_assert (index < v_must_defs->num_v_must_defs);
589 op.def = &(v_must_defs->v_must_defs[index].def);
590 return op;
593 /* Return a use_operand_p that is the V_MUST_DEF_KILL for the
594 V_MUST_DEF at INDEX in the V_MUST_DEFS array. */
595 static inline use_operand_p
596 get_v_must_def_kill_ptr (v_must_def_optype v_must_defs, unsigned int index)
598 gcc_assert (index < v_must_defs->num_v_must_defs);
599 return &(v_must_defs->v_must_defs[index].imm_use);
602 /* Return a def_operand_p pointer for the result of PHI. */
603 static inline def_operand_p
604 get_phi_result_ptr (tree phi)
606 def_operand_p op;
607 op.def = &(PHI_RESULT_TREE (phi));
608 return op;
611 /* Return a use_operand_p pointer for argument I of phinode PHI. */
612 static inline use_operand_p
613 get_phi_arg_def_ptr (tree phi, int i)
615 return &(PHI_ARG_IMM_USE_NODE (phi,i));
618 /* Delink all immediate_use information for STMT. */
619 static inline void
620 delink_stmt_imm_use (tree stmt)
622 unsigned int x;
623 use_optype uses = STMT_USE_OPS (stmt);
624 vuse_optype vuses = STMT_VUSE_OPS (stmt);
625 v_may_def_optype v_may_defs = STMT_V_MAY_DEF_OPS (stmt);
626 v_must_def_optype v_must_defs = STMT_V_MUST_DEF_OPS (stmt);
628 for (x = 0; x < NUM_USES (uses); x++)
629 delink_imm_use (&(uses->uses[x]));
631 for (x = 0; x < NUM_VUSES (vuses); x++)
632 delink_imm_use (&(vuses->vuses[x].imm_use));
634 for (x = 0; x < NUM_V_MAY_DEFS (v_may_defs); x++)
635 delink_imm_use (&(v_may_defs->v_may_defs[x].imm_use));
637 for (x = 0; x < NUM_V_MUST_DEFS (v_must_defs); x++)
638 delink_imm_use (&(v_must_defs->v_must_defs[x].imm_use));
642 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
643 no addresses. */
644 static inline bitmap
645 addresses_taken (tree stmt)
647 stmt_ann_t ann = stmt_ann (stmt);
648 return ann ? ann->addresses_taken : NULL;
651 /* Return the basic_block annotation for BB. */
652 static inline bb_ann_t
653 bb_ann (basic_block bb)
655 return (bb_ann_t)bb->tree_annotations;
658 /* Return the PHI nodes for basic block BB, or NULL if there are no
659 PHI nodes. */
660 static inline tree
661 phi_nodes (basic_block bb)
663 return bb_ann (bb)->phi_nodes;
666 /* Set list of phi nodes of a basic block BB to L. */
668 static inline void
669 set_phi_nodes (basic_block bb, tree l)
671 tree phi;
673 bb_ann (bb)->phi_nodes = l;
674 for (phi = l; phi; phi = PHI_CHAIN (phi))
675 set_bb_for_stmt (phi, bb);
678 /* Return the phi argument which contains the specified use. */
680 static inline int
681 phi_arg_index_from_use (use_operand_p use)
683 struct phi_arg_d *element, *root;
684 int index;
685 tree phi;
687 /* Since the use is the first thing in a PHI argument element, we can
688 calculate its index based on casting it to an argument, and performing
689 pointer arithmetic. */
691 phi = USE_STMT (use);
692 gcc_assert (TREE_CODE (phi) == PHI_NODE);
694 element = (struct phi_arg_d *)use;
695 root = &(PHI_ARG_ELT (phi, 0));
696 index = element - root;
698 #ifdef ENABLE_CHECKING
699 /* Make sure the calculation doesn't have any leftover bytes. If it does,
700 then imm_use is likely not the first element in phi_arg_d. */
701 gcc_assert (
702 (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
703 gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
704 #endif
706 return index;
709 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
711 static inline void
712 set_is_used (tree var)
714 var_ann_t ann = get_var_ann (var);
715 ann->used = 1;
719 /* ----------------------------------------------------------------------- */
721 /* Return true if T is an executable statement. */
722 static inline bool
723 is_exec_stmt (tree t)
725 return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
729 /* Return true if this stmt can be the target of a control transfer stmt such
730 as a goto. */
731 static inline bool
732 is_label_stmt (tree t)
734 if (t)
735 switch (TREE_CODE (t))
737 case LABEL_DECL:
738 case LABEL_EXPR:
739 case CASE_LABEL_EXPR:
740 return true;
741 default:
742 return false;
744 return false;
747 /* Set the default definition for VAR to DEF. */
748 static inline void
749 set_default_def (tree var, tree def)
751 var_ann_t ann = get_var_ann (var);
752 ann->default_def = def;
755 /* Return the default definition for variable VAR, or NULL if none
756 exists. */
757 static inline tree
758 default_def (tree var)
760 var_ann_t ann = var_ann (var);
761 return ann ? ann->default_def : NULL_TREE;
764 /* PHI nodes should contain only ssa_names and invariants. A test
765 for ssa_name is definitely simpler; don't let invalid contents
766 slip in in the meantime. */
768 static inline bool
769 phi_ssa_name_p (tree t)
771 if (TREE_CODE (t) == SSA_NAME)
772 return true;
773 #ifdef ENABLE_CHECKING
774 gcc_assert (is_gimple_min_invariant (t));
775 #endif
776 return false;
779 /* ----------------------------------------------------------------------- */
781 /* Return a block_stmt_iterator that points to beginning of basic
782 block BB. */
783 static inline block_stmt_iterator
784 bsi_start (basic_block bb)
786 block_stmt_iterator bsi;
787 if (bb->stmt_list)
788 bsi.tsi = tsi_start (bb->stmt_list);
789 else
791 gcc_assert (bb->index < 0);
792 bsi.tsi.ptr = NULL;
793 bsi.tsi.container = NULL;
795 bsi.bb = bb;
796 return bsi;
799 /* Return a block statement iterator that points to the last label in
800 block BB. */
802 static inline block_stmt_iterator
803 bsi_after_labels (basic_block bb)
805 block_stmt_iterator bsi;
806 tree_stmt_iterator next;
808 bsi.bb = bb;
810 if (!bb->stmt_list)
812 gcc_assert (bb->index < 0);
813 bsi.tsi.ptr = NULL;
814 bsi.tsi.container = NULL;
815 return bsi;
818 bsi.tsi = tsi_start (bb->stmt_list);
819 if (tsi_end_p (bsi.tsi))
820 return bsi;
822 /* Ensure that there are some labels. The rationale is that we want
823 to insert after the bsi that is returned, and these insertions should
824 be placed at the start of the basic block. This would not work if the
825 first statement was not label; rather fail here than enable the user
826 proceed in wrong way. */
827 gcc_assert (TREE_CODE (tsi_stmt (bsi.tsi)) == LABEL_EXPR);
829 next = bsi.tsi;
830 tsi_next (&next);
832 while (!tsi_end_p (next)
833 && TREE_CODE (tsi_stmt (next)) == LABEL_EXPR)
835 bsi.tsi = next;
836 tsi_next (&next);
839 return bsi;
842 /* Return a block statement iterator that points to the end of basic
843 block BB. */
844 static inline block_stmt_iterator
845 bsi_last (basic_block bb)
847 block_stmt_iterator bsi;
848 if (bb->stmt_list)
849 bsi.tsi = tsi_last (bb->stmt_list);
850 else
852 gcc_assert (bb->index < 0);
853 bsi.tsi.ptr = NULL;
854 bsi.tsi.container = NULL;
856 bsi.bb = bb;
857 return bsi;
860 /* Return true if block statement iterator I has reached the end of
861 the basic block. */
862 static inline bool
863 bsi_end_p (block_stmt_iterator i)
865 return tsi_end_p (i.tsi);
868 /* Modify block statement iterator I so that it is at the next
869 statement in the basic block. */
870 static inline void
871 bsi_next (block_stmt_iterator *i)
873 tsi_next (&i->tsi);
876 /* Modify block statement iterator I so that it is at the previous
877 statement in the basic block. */
878 static inline void
879 bsi_prev (block_stmt_iterator *i)
881 tsi_prev (&i->tsi);
884 /* Return the statement that block statement iterator I is currently
885 at. */
886 static inline tree
887 bsi_stmt (block_stmt_iterator i)
889 return tsi_stmt (i.tsi);
892 /* Return a pointer to the statement that block statement iterator I
893 is currently at. */
894 static inline tree *
895 bsi_stmt_ptr (block_stmt_iterator i)
897 return tsi_stmt_ptr (i.tsi);
900 /* Returns the loop of the statement STMT. */
902 static inline struct loop *
903 loop_containing_stmt (tree stmt)
905 basic_block bb = bb_for_stmt (stmt);
906 if (!bb)
907 return NULL;
909 return bb->loop_father;
912 /* Return true if VAR is a clobbered by function calls. */
913 static inline bool
914 is_call_clobbered (tree var)
916 return is_global_var (var)
917 || bitmap_bit_p (call_clobbered_vars, var_ann (var)->uid);
920 /* Mark variable VAR as being clobbered by function calls. */
921 static inline void
922 mark_call_clobbered (tree var)
924 var_ann_t ann = var_ann (var);
925 /* If VAR is a memory tag, then we need to consider it a global
926 variable. This is because the pointer that VAR represents has
927 been found to point to either an arbitrary location or to a known
928 location in global memory. */
929 if (ann->mem_tag_kind != NOT_A_TAG && ann->mem_tag_kind != STRUCT_FIELD)
930 DECL_EXTERNAL (var) = 1;
931 bitmap_set_bit (call_clobbered_vars, ann->uid);
932 ssa_call_clobbered_cache_valid = false;
933 ssa_ro_call_cache_valid = false;
936 /* Clear the call-clobbered attribute from variable VAR. */
937 static inline void
938 clear_call_clobbered (tree var)
940 var_ann_t ann = var_ann (var);
941 if (ann->mem_tag_kind != NOT_A_TAG && ann->mem_tag_kind != STRUCT_FIELD)
942 DECL_EXTERNAL (var) = 0;
943 bitmap_clear_bit (call_clobbered_vars, ann->uid);
944 ssa_call_clobbered_cache_valid = false;
945 ssa_ro_call_cache_valid = false;
948 /* Mark variable VAR as being non-addressable. */
949 static inline void
950 mark_non_addressable (tree var)
952 bitmap_clear_bit (call_clobbered_vars, var_ann (var)->uid);
953 TREE_ADDRESSABLE (var) = 0;
954 ssa_call_clobbered_cache_valid = false;
955 ssa_ro_call_cache_valid = false;
958 /* Return the common annotation for T. Return NULL if the annotation
959 doesn't already exist. */
960 static inline tree_ann_t
961 tree_ann (tree t)
963 return t->common.ann;
966 /* Return a common annotation for T. Create the constant annotation if it
967 doesn't exist. */
968 static inline tree_ann_t
969 get_tree_ann (tree t)
971 tree_ann_t ann = tree_ann (t);
972 return (ann) ? ann : create_tree_ann (t);
975 /* ----------------------------------------------------------------------- */
977 /* The following set of routines are used to iterator over various type of
978 SSA operands. */
980 /* Return true if PTR is finished iterating. */
981 static inline bool
982 op_iter_done (ssa_op_iter *ptr)
984 return ptr->done;
987 /* Get the next iterator use value for PTR. */
988 static inline use_operand_p
989 op_iter_next_use (ssa_op_iter *ptr)
991 if (ptr->use_i < ptr->num_use)
993 return USE_OP_PTR (ptr->ops->use_ops, (ptr->use_i)++);
995 if (ptr->vuse_i < ptr->num_vuse)
997 return VUSE_OP_PTR (ptr->ops->vuse_ops, (ptr->vuse_i)++);
999 if (ptr->v_mayu_i < ptr->num_v_mayu)
1001 return V_MAY_DEF_OP_PTR (ptr->ops->v_may_def_ops,
1002 (ptr->v_mayu_i)++);
1004 if (ptr->v_mustu_i < ptr->num_v_mustu)
1006 return V_MUST_DEF_KILL_PTR (ptr->ops->v_must_def_ops,
1007 (ptr->v_mustu_i)++);
1009 ptr->done = true;
1010 return NULL_USE_OPERAND_P;
1013 /* Get the next iterator def value for PTR. */
1014 static inline def_operand_p
1015 op_iter_next_def (ssa_op_iter *ptr)
1017 if (ptr->def_i < ptr->num_def)
1019 return DEF_OP_PTR (ptr->ops->def_ops, (ptr->def_i)++);
1021 if (ptr->v_mustd_i < ptr->num_v_mustd)
1023 return V_MUST_DEF_RESULT_PTR (ptr->ops->v_must_def_ops,
1024 (ptr->v_mustd_i)++);
1026 if (ptr->v_mayd_i < ptr->num_v_mayd)
1028 return V_MAY_DEF_RESULT_PTR (ptr->ops->v_may_def_ops,
1029 (ptr->v_mayd_i)++);
1031 ptr->done = true;
1032 return NULL_DEF_OPERAND_P;
1035 /* Get the next iterator tree value for PTR. */
1036 static inline tree
1037 op_iter_next_tree (ssa_op_iter *ptr)
1039 if (ptr->use_i < ptr->num_use)
1041 return USE_OP (ptr->ops->use_ops, (ptr->use_i)++);
1043 if (ptr->vuse_i < ptr->num_vuse)
1045 return VUSE_OP (ptr->ops->vuse_ops, (ptr->vuse_i)++);
1047 if (ptr->v_mayu_i < ptr->num_v_mayu)
1049 return V_MAY_DEF_OP (ptr->ops->v_may_def_ops, (ptr->v_mayu_i)++);
1051 if (ptr->v_mustu_i < ptr->num_v_mustu)
1053 return V_MUST_DEF_KILL (ptr->ops->v_must_def_ops, (ptr->v_mustu_i)++);
1055 if (ptr->def_i < ptr->num_def)
1057 return DEF_OP (ptr->ops->def_ops, (ptr->def_i)++);
1059 if (ptr->v_mustd_i < ptr->num_v_mustd)
1061 return V_MUST_DEF_RESULT (ptr->ops->v_must_def_ops,
1062 (ptr->v_mustd_i)++);
1064 if (ptr->v_mayd_i < ptr->num_v_mayd)
1066 return V_MAY_DEF_RESULT (ptr->ops->v_may_def_ops,
1067 (ptr->v_mayd_i)++);
1069 ptr->done = true;
1070 return NULL;
1073 /* Initialize the iterator PTR to the virtual defs in STMT. */
1074 static inline void
1075 op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
1077 stmt_operands_p ops;
1078 stmt_ann_t ann = get_stmt_ann (stmt);
1080 ops = &(ann->operands);
1081 ptr->done = false;
1082 ptr->ops = ops;
1083 ptr->num_def = (flags & SSA_OP_DEF) ? NUM_DEFS (ops->def_ops) : 0;
1084 ptr->num_use = (flags & SSA_OP_USE) ? NUM_USES (ops->use_ops) : 0;
1085 ptr->num_vuse = (flags & SSA_OP_VUSE) ? NUM_VUSES (ops->vuse_ops) : 0;
1086 ptr->num_v_mayu = (flags & SSA_OP_VMAYUSE)
1087 ? NUM_V_MAY_DEFS (ops->v_may_def_ops) : 0;
1088 ptr->num_v_mayd = (flags & SSA_OP_VMAYDEF)
1089 ? NUM_V_MAY_DEFS (ops->v_may_def_ops) : 0;
1090 ptr->num_v_mustu = (flags & SSA_OP_VMUSTDEFKILL)
1091 ? NUM_V_MUST_DEFS (ops->v_must_def_ops) : 0;
1092 ptr->num_v_mustd = (flags & SSA_OP_VMUSTDEF)
1093 ? NUM_V_MUST_DEFS (ops->v_must_def_ops) : 0;
1094 ptr->def_i = 0;
1095 ptr->use_i = 0;
1096 ptr->vuse_i = 0;
1097 ptr->v_mayu_i = 0;
1098 ptr->v_mayd_i = 0;
1099 ptr->v_mustu_i = 0;
1100 ptr->v_mustd_i = 0;
1103 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1104 the first use. */
1105 static inline use_operand_p
1106 op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
1108 op_iter_init (ptr, stmt, flags);
1109 return op_iter_next_use (ptr);
1112 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1113 the first def. */
1114 static inline def_operand_p
1115 op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1117 op_iter_init (ptr, stmt, flags);
1118 return op_iter_next_def (ptr);
1121 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1122 the first operand as a tree. */
1123 static inline tree
1124 op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1126 op_iter_init (ptr, stmt, flags);
1127 return op_iter_next_tree (ptr);
1130 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1131 KILL and DEF. */
1132 static inline void
1133 op_iter_next_mustdef (use_operand_p *kill, def_operand_p *def, ssa_op_iter *ptr)
1135 if (ptr->v_mustu_i < ptr->num_v_mustu)
1137 *def = V_MUST_DEF_RESULT_PTR (ptr->ops->v_must_def_ops, ptr->v_mustu_i);
1138 *kill = V_MUST_DEF_KILL_PTR (ptr->ops->v_must_def_ops, (ptr->v_mustu_i)++);
1139 return;
1141 else
1143 *def = NULL_DEF_OPERAND_P;
1144 *kill = NULL_USE_OPERAND_P;
1146 ptr->done = true;
1147 return;
1149 /* Get the next iterator maydef value for PTR, returning the maydef values in
1150 USE and DEF. */
1151 static inline void
1152 op_iter_next_maydef (use_operand_p *use, def_operand_p *def, ssa_op_iter *ptr)
1154 if (ptr->v_mayu_i < ptr->num_v_mayu)
1156 *def = V_MAY_DEF_RESULT_PTR (ptr->ops->v_may_def_ops, ptr->v_mayu_i);
1157 *use = V_MAY_DEF_OP_PTR (ptr->ops->v_may_def_ops, (ptr->v_mayu_i)++);
1158 return;
1160 else
1162 *def = NULL_DEF_OPERAND_P;
1163 *use = NULL_USE_OPERAND_P;
1165 ptr->done = true;
1166 return;
1169 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1170 in USE and DEF. */
1171 static inline void
1172 op_iter_init_maydef (ssa_op_iter *ptr, tree stmt, use_operand_p *use,
1173 def_operand_p *def)
1175 op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1176 op_iter_next_maydef (use, def, ptr);
1179 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1180 in KILL and DEF. */
1181 static inline void
1182 op_iter_init_mustdef (ssa_op_iter *ptr, tree stmt, use_operand_p *kill,
1183 def_operand_p *def)
1185 op_iter_init (ptr, stmt, SSA_OP_VMUSTDEFKILL);
1186 op_iter_next_mustdef (kill, def, ptr);
1189 /* Return true if REF, a COMPONENT_REF, has an ARRAY_REF somewhere in it. */
1191 static inline bool
1192 ref_contains_array_ref (tree ref)
1194 while (handled_component_p (ref))
1196 if (TREE_CODE (ref) == ARRAY_REF)
1197 return true;
1198 ref = TREE_OPERAND (ref, 0);
1200 return false;
1203 /* Given a variable VAR, lookup and return a pointer to the list of
1204 subvariables for it. */
1206 static inline subvar_t *
1207 lookup_subvars_for_var (tree var)
1209 var_ann_t ann = var_ann (var);
1210 gcc_assert (ann);
1211 return &ann->subvars;
1214 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1215 NULL, if there are no subvariables. */
1217 static inline subvar_t
1218 get_subvars_for_var (tree var)
1220 subvar_t subvars;
1222 gcc_assert (SSA_VAR_P (var));
1224 if (TREE_CODE (var) == SSA_NAME)
1225 subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
1226 else
1227 subvars = *(lookup_subvars_for_var (var));
1228 return subvars;
1231 /* Return true if V is a tree that we can have subvars for.
1232 Normally, this is any aggregate type, however, due to implementation
1233 limitations ATM, we exclude array types as well. */
1235 static inline bool
1236 var_can_have_subvars (tree v)
1238 return (AGGREGATE_TYPE_P (TREE_TYPE (v)) &&
1239 TREE_CODE (TREE_TYPE (v)) != ARRAY_TYPE);
1243 /* Return true if OFFSET and SIZE define a range that overlaps with some
1244 portion of the range of SV, a subvar. If there was an exact overlap,
1245 *EXACT will be set to true upon return. */
1247 static inline bool
1248 overlap_subvar (HOST_WIDE_INT offset, HOST_WIDE_INT size,
1249 subvar_t sv, bool *exact)
1251 /* There are three possible cases of overlap.
1252 1. We can have an exact overlap, like so:
1253 |offset, offset + size |
1254 |sv->offset, sv->offset + sv->size |
1256 2. We can have offset starting after sv->offset, like so:
1258 |offset, offset + size |
1259 |sv->offset, sv->offset + sv->size |
1261 3. We can have offset starting before sv->offset, like so:
1263 |offset, offset + size |
1264 |sv->offset, sv->offset + sv->size|
1267 if (exact)
1268 *exact = false;
1269 if (offset == sv->offset && size == sv->size)
1271 if (exact)
1272 *exact = true;
1273 return true;
1275 else if (offset >= sv->offset && offset < (sv->offset + sv->size))
1277 return true;
1279 else if (offset < sv->offset && (offset + size > sv->offset))
1281 return true;
1283 return false;
1287 #endif /* _TREE_FLOW_INLINE_H */