* tree-ssa-phiopt.c, config/arm/arm.c, config/fr30/fr30.md,
[official-gcc.git] / gcc / tree-flow-inline.h
blobf41448bc0e94e5b6da1635e784d8f8597cf9e072
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 /* 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 #ifdef ENABLE_CHECKING
258 /* The node one had better be in the same list. */
259 if (*(old->use) != *(node->use))
260 abort ();
261 #endif
262 node->prev = old->prev;
263 node->next = old->next;
264 if (old->prev)
266 old->prev->next = node;
267 old->next->prev = node;
268 /* Remove the old node from the list. */
269 old->prev = NULL;
274 /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occuring
275 in STMT. */
276 static inline void
277 relink_imm_use_stmt (ssa_imm_use_t *linknode, ssa_imm_use_t *old, tree stmt)
279 if (stmt)
280 relink_imm_use (linknode, old);
281 else
282 link_imm_use (linknode, NULL);
283 linknode->stmt = stmt;
286 /* Finished the traverse of an immediate use list IMM by removing it from
287 the list. */
288 static inline void
289 end_safe_imm_use_traverse (imm_use_iterator *imm)
291 delink_imm_use (&(imm->iter_node));
294 /* Return true if IMM is at the end of the list. */
295 static inline bool
296 end_safe_imm_use_p (imm_use_iterator *imm)
298 return (imm->imm_use == imm->end_p);
301 /* Initialize iterator IMM to process the list for VAR. */
302 static inline use_operand_p
303 first_safe_imm_use (imm_use_iterator *imm, tree var)
305 /* Set up and link the iterator node into the linked list for VAR. */
306 imm->iter_node.use = NULL;
307 imm->iter_node.stmt = NULL_TREE;
308 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
309 /* Check if there are 0 elements. */
310 if (imm->end_p->next == imm->end_p)
312 imm->imm_use = imm->end_p;
313 return NULL_USE_OPERAND_P;
316 link_imm_use (&(imm->iter_node), var);
317 imm->imm_use = imm->iter_node.next;
318 return imm->imm_use;
321 /* Bump IMM to then next use in the list. */
322 static inline use_operand_p
323 next_safe_imm_use (imm_use_iterator *imm)
325 ssa_imm_use_t *ptr;
326 use_operand_p old;
328 old = imm->imm_use;
329 /* If the next node following the iter_node is still the one referred to by
330 imm_use, then the list hasn't changed, go to the next node. */
331 if (imm->iter_node.next == imm->imm_use)
333 ptr = &(imm->iter_node);
334 /* Remove iternode from the list. */
335 delink_imm_use (ptr);
336 imm->imm_use = imm->imm_use->next;
337 if (! end_safe_imm_use_p (imm))
339 /* This isnt the end, link iternode before the next use. */
340 ptr->prev = imm->imm_use->prev;
341 ptr->next = imm->imm_use;
342 imm->imm_use->prev->next = ptr;
343 imm->imm_use->prev = ptr;
345 else
346 return old;
348 else
350 /* If the 'next' value after the iterator isn't the same as it was, then
351 a node has been deleted, so we simply proceed to the node following
352 where the iterator is in the list. */
353 imm->imm_use = imm->iter_node.next;
354 if (end_safe_imm_use_p (imm))
356 end_safe_imm_use_traverse (imm);
357 return old;
361 return imm->imm_use;
364 /* Return true is IMM has reached the end of the immediate use list. */
365 static inline bool
366 end_readonly_imm_use_p (imm_use_iterator *imm)
368 return (imm->imm_use == imm->end_p);
371 /* Initialize iterator IMM to process the list for VAR. */
372 static inline use_operand_p
373 first_readonly_imm_use (imm_use_iterator *imm, tree var)
375 gcc_assert (TREE_CODE (var) == SSA_NAME);
377 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
378 imm->imm_use = imm->end_p->next;
379 #ifdef ENABLE_CHECKING
380 imm->iter_node.next = imm->imm_use->next;
381 #endif
382 if (end_readonly_imm_use_p (imm))
383 return NULL_USE_OPERAND_P;
384 return imm->imm_use;
387 /* Bump IMM to then next use in the list. */
388 static inline use_operand_p
389 next_readonly_imm_use (imm_use_iterator *imm)
391 use_operand_p old = imm->imm_use;
393 #ifdef ENABLE_CHECKING
394 /* If this assertion fails, it indicates the 'next' pointer has changed
395 since we the last bump. This indicates that the list is being modified
396 via stmt changes, or SET_USE, or somesuch thing, and you need to be
397 using the SAFE version of the iterator. */
398 gcc_assert (imm->iter_node.next == old->next);
399 imm->iter_node.next = old->next->next;
400 #endif
402 imm->imm_use = old->next;
403 if (end_readonly_imm_use_p (imm))
404 return old;
405 return imm->imm_use;
408 /* Return true if VAR has no uses. */
409 static inline bool
410 has_zero_uses (tree var)
412 ssa_imm_use_t *ptr;
413 ptr = &(SSA_NAME_IMM_USE_NODE (var));
414 /* A single use means there is no items in the list. */
415 return (ptr == ptr->next);
418 /* Return true if VAR has a single use. */
419 static inline bool
420 has_single_use (tree var)
422 ssa_imm_use_t *ptr;
423 ptr = &(SSA_NAME_IMM_USE_NODE (var));
424 /* A single use means there is one item in the list. */
425 return (ptr != ptr->next && ptr == ptr->next->next);
428 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
429 to the use pointer and stmt of occurrence. */
430 static inline bool
431 single_imm_use (tree var, use_operand_p *use_p, tree *stmt)
433 ssa_imm_use_t *ptr;
435 ptr = &(SSA_NAME_IMM_USE_NODE (var));
436 if (ptr != ptr->next && ptr == ptr->next->next)
438 *use_p = ptr->next;
439 *stmt = ptr->next->stmt;
440 return true;
442 *use_p = NULL_USE_OPERAND_P;
443 *stmt = NULL_TREE;
444 return false;
447 /* Return the number of immediate uses of VAR. */
448 static inline unsigned int
449 num_imm_uses (tree var)
451 ssa_imm_use_t *ptr, *start;
452 unsigned int num;
454 start = &(SSA_NAME_IMM_USE_NODE (var));
455 num = 0;
456 for (ptr = start->next; ptr != start; ptr = ptr->next)
457 num++;
459 return num;
462 /* Return the definitions present in ANN, a statement annotation.
463 Return NULL if this annotation contains no definitions. */
464 static inline def_optype
465 get_def_ops (stmt_ann_t ann)
467 return ann ? ann->operands.def_ops : NULL;
470 /* Return the uses present in ANN, a statement annotation.
471 Return NULL if this annotation contains no uses. */
472 static inline use_optype
473 get_use_ops (stmt_ann_t ann)
475 return ann ? ann->operands.use_ops : NULL;
478 /* Return the virtual may-defs present in ANN, a statement
479 annotation.
480 Return NULL if this annotation contains no virtual may-defs. */
481 static inline v_may_def_optype
482 get_v_may_def_ops (stmt_ann_t ann)
484 return ann ? ann->operands.v_may_def_ops : NULL;
487 /* Return the virtual uses present in ANN, a statement annotation.
488 Return NULL if this annotation contains no virtual uses. */
489 static inline vuse_optype
490 get_vuse_ops (stmt_ann_t ann)
492 return ann ? ann->operands.vuse_ops : NULL;
495 /* Return the virtual must-defs present in ANN, a statement
496 annotation. Return NULL if this annotation contains no must-defs.*/
497 static inline v_must_def_optype
498 get_v_must_def_ops (stmt_ann_t ann)
500 return ann ? ann->operands.v_must_def_ops : NULL;
503 /* Return the tree pointer to by USE. */
504 static inline tree
505 get_use_from_ptr (use_operand_p use)
507 return *(use->use);
510 /* Return the tree pointer to by DEF. */
511 static inline tree
512 get_def_from_ptr (def_operand_p def)
514 return *(def.def);
517 /* Return a pointer to the tree that is at INDEX in the USES array. */
518 static inline use_operand_p
519 get_use_op_ptr (use_optype uses, unsigned int index)
521 gcc_assert (index < uses->num_uses);
522 return &(uses->uses[index]);
525 /* Return a def_operand_p pointer for element INDEX of DEFS. */
526 static inline def_operand_p
527 get_def_op_ptr (def_optype defs, unsigned int index)
529 gcc_assert (index < defs->num_defs);
530 return defs->defs[index];
533 /* Return the def_operand_p that is the V_MAY_DEF_RESULT for the V_MAY_DEF
534 at INDEX in the V_MAY_DEFS array. */
535 static inline def_operand_p
536 get_v_may_def_result_ptr(v_may_def_optype v_may_defs, unsigned int index)
538 def_operand_p op;
539 gcc_assert (index < v_may_defs->num_v_may_defs);
540 op.def = &(v_may_defs->v_may_defs[index].def);
541 return op;
544 /* Return a use_operand_p that is the V_MAY_DEF_OP for the V_MAY_DEF at
545 INDEX in the V_MAY_DEFS array. */
546 static inline use_operand_p
547 get_v_may_def_op_ptr(v_may_def_optype v_may_defs, unsigned int index)
549 gcc_assert (index < v_may_defs->num_v_may_defs);
550 return &(v_may_defs->v_may_defs[index].imm_use);
553 /* Return a use_operand_p that is at INDEX in the VUSES array. */
554 static inline use_operand_p
555 get_vuse_op_ptr(vuse_optype vuses, unsigned int index)
557 gcc_assert (index < vuses->num_vuses);
558 return &(vuses->vuses[index].imm_use);
561 /* Return a def_operand_p that is the V_MUST_DEF_RESULT for the
562 V_MUST_DEF at INDEX in the V_MUST_DEFS array. */
563 static inline def_operand_p
564 get_v_must_def_result_ptr (v_must_def_optype v_must_defs, unsigned int index)
566 def_operand_p op;
567 gcc_assert (index < v_must_defs->num_v_must_defs);
568 op.def = &(v_must_defs->v_must_defs[index].def);
569 return op;
572 /* Return a use_operand_p that is the V_MUST_DEF_KILL for the
573 V_MUST_DEF at INDEX in the V_MUST_DEFS array. */
574 static inline use_operand_p
575 get_v_must_def_kill_ptr (v_must_def_optype v_must_defs, unsigned int index)
577 gcc_assert (index < v_must_defs->num_v_must_defs);
578 return &(v_must_defs->v_must_defs[index].imm_use);
581 /* Return a def_operand_p pointer for the result of PHI. */
582 static inline def_operand_p
583 get_phi_result_ptr (tree phi)
585 def_operand_p op;
586 op.def = &(PHI_RESULT_TREE (phi));
587 return op;
590 /* Return a use_operand_p pointer for argument I of phinode PHI. */
591 static inline use_operand_p
592 get_phi_arg_def_ptr (tree phi, int i)
594 return &(PHI_ARG_IMM_USE_NODE (phi,i));
597 /* Delink all immediate_use information for STMT. */
598 static inline void
599 delink_stmt_imm_use (tree stmt)
601 unsigned int x;
602 use_optype uses = STMT_USE_OPS (stmt);
603 vuse_optype vuses = STMT_VUSE_OPS (stmt);
604 v_may_def_optype v_may_defs = STMT_V_MAY_DEF_OPS (stmt);
605 v_must_def_optype v_must_defs = STMT_V_MUST_DEF_OPS (stmt);
607 for (x = 0; x < NUM_USES (uses); x++)
608 delink_imm_use (&(uses->uses[x]));
610 for (x = 0; x < NUM_VUSES (vuses); x++)
611 delink_imm_use (&(vuses->vuses[x].imm_use));
613 for (x = 0; x < NUM_V_MAY_DEFS (v_may_defs); x++)
614 delink_imm_use (&(v_may_defs->v_may_defs[x].imm_use));
616 for (x = 0; x < NUM_V_MUST_DEFS (v_must_defs); x++)
617 delink_imm_use (&(v_must_defs->v_must_defs[x].imm_use));
621 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
622 no addresses. */
623 static inline bitmap
624 addresses_taken (tree stmt)
626 stmt_ann_t ann = stmt_ann (stmt);
627 return ann ? ann->addresses_taken : NULL;
630 /* Return the basic_block annotation for BB. */
631 static inline bb_ann_t
632 bb_ann (basic_block bb)
634 return (bb_ann_t)bb->tree_annotations;
637 /* Return the PHI nodes for basic block BB, or NULL if there are no
638 PHI nodes. */
639 static inline tree
640 phi_nodes (basic_block bb)
642 return bb_ann (bb)->phi_nodes;
645 /* Set list of phi nodes of a basic block BB to L. */
647 static inline void
648 set_phi_nodes (basic_block bb, tree l)
650 tree phi;
652 bb_ann (bb)->phi_nodes = l;
653 for (phi = l; phi; phi = PHI_CHAIN (phi))
654 set_bb_for_stmt (phi, bb);
657 /* Return the phi argument which contains the specified use. */
659 static inline int
660 phi_arg_index_from_use (use_operand_p use)
662 struct phi_arg_d *element, *root;
663 int index;
664 tree phi;
666 /* Since the use is the first thing in a PHI argument element, we can
667 calculate its index based on casting it to an argument, and performing
668 pointer arithmetic. */
670 phi = USE_STMT (use);
671 gcc_assert (TREE_CODE (phi) == PHI_NODE);
673 element = (struct phi_arg_d *)use;
674 root = &(PHI_ARG_ELT (phi, 0));
675 index = element - root;
677 #ifdef ENABLE_CHECKING
678 /* Make sure the calculation doesn't have any leftover bytes. If it does,
679 then imm_use is likely not the first element in phi_arg_d. */
680 gcc_assert (
681 (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
682 gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
683 #endif
685 return index;
688 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
690 static inline void
691 set_is_used (tree var)
693 var_ann_t ann = get_var_ann (var);
694 ann->used = 1;
698 /* ----------------------------------------------------------------------- */
700 /* Return true if T is an executable statement. */
701 static inline bool
702 is_exec_stmt (tree t)
704 return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
708 /* Return true if this stmt can be the target of a control transfer stmt such
709 as a goto. */
710 static inline bool
711 is_label_stmt (tree t)
713 if (t)
714 switch (TREE_CODE (t))
716 case LABEL_DECL:
717 case LABEL_EXPR:
718 case CASE_LABEL_EXPR:
719 return true;
720 default:
721 return false;
723 return false;
726 /* Set the default definition for VAR to DEF. */
727 static inline void
728 set_default_def (tree var, tree def)
730 var_ann_t ann = get_var_ann (var);
731 ann->default_def = def;
734 /* Return the default definition for variable VAR, or NULL if none
735 exists. */
736 static inline tree
737 default_def (tree var)
739 var_ann_t ann = var_ann (var);
740 return ann ? ann->default_def : NULL_TREE;
743 /* PHI nodes should contain only ssa_names and invariants. A test
744 for ssa_name is definitely simpler; don't let invalid contents
745 slip in in the meantime. */
747 static inline bool
748 phi_ssa_name_p (tree t)
750 if (TREE_CODE (t) == SSA_NAME)
751 return true;
752 #ifdef ENABLE_CHECKING
753 gcc_assert (is_gimple_min_invariant (t));
754 #endif
755 return false;
758 /* ----------------------------------------------------------------------- */
760 /* Return a block_stmt_iterator that points to beginning of basic
761 block BB. */
762 static inline block_stmt_iterator
763 bsi_start (basic_block bb)
765 block_stmt_iterator bsi;
766 if (bb->stmt_list)
767 bsi.tsi = tsi_start (bb->stmt_list);
768 else
770 gcc_assert (bb->index < 0);
771 bsi.tsi.ptr = NULL;
772 bsi.tsi.container = NULL;
774 bsi.bb = bb;
775 return bsi;
778 /* Return a block statement iterator that points to the last label in
779 block BB. */
781 static inline block_stmt_iterator
782 bsi_after_labels (basic_block bb)
784 block_stmt_iterator bsi;
785 tree_stmt_iterator next;
787 bsi.bb = bb;
789 if (!bb->stmt_list)
791 gcc_assert (bb->index < 0);
792 bsi.tsi.ptr = NULL;
793 bsi.tsi.container = NULL;
794 return bsi;
797 bsi.tsi = tsi_start (bb->stmt_list);
798 if (tsi_end_p (bsi.tsi))
799 return bsi;
801 /* Ensure that there are some labels. The rationale is that we want
802 to insert after the bsi that is returned, and these insertions should
803 be placed at the start of the basic block. This would not work if the
804 first statement was not label; rather fail here than enable the user
805 proceed in wrong way. */
806 gcc_assert (TREE_CODE (tsi_stmt (bsi.tsi)) == LABEL_EXPR);
808 next = bsi.tsi;
809 tsi_next (&next);
811 while (!tsi_end_p (next)
812 && TREE_CODE (tsi_stmt (next)) == LABEL_EXPR)
814 bsi.tsi = next;
815 tsi_next (&next);
818 return bsi;
821 /* Return a block statement iterator that points to the end of basic
822 block BB. */
823 static inline block_stmt_iterator
824 bsi_last (basic_block bb)
826 block_stmt_iterator bsi;
827 if (bb->stmt_list)
828 bsi.tsi = tsi_last (bb->stmt_list);
829 else
831 gcc_assert (bb->index < 0);
832 bsi.tsi.ptr = NULL;
833 bsi.tsi.container = NULL;
835 bsi.bb = bb;
836 return bsi;
839 /* Return true if block statement iterator I has reached the end of
840 the basic block. */
841 static inline bool
842 bsi_end_p (block_stmt_iterator i)
844 return tsi_end_p (i.tsi);
847 /* Modify block statement iterator I so that it is at the next
848 statement in the basic block. */
849 static inline void
850 bsi_next (block_stmt_iterator *i)
852 tsi_next (&i->tsi);
855 /* Modify block statement iterator I so that it is at the previous
856 statement in the basic block. */
857 static inline void
858 bsi_prev (block_stmt_iterator *i)
860 tsi_prev (&i->tsi);
863 /* Return the statement that block statement iterator I is currently
864 at. */
865 static inline tree
866 bsi_stmt (block_stmt_iterator i)
868 return tsi_stmt (i.tsi);
871 /* Return a pointer to the statement that block statement iterator I
872 is currently at. */
873 static inline tree *
874 bsi_stmt_ptr (block_stmt_iterator i)
876 return tsi_stmt_ptr (i.tsi);
879 /* Returns the loop of the statement STMT. */
881 static inline struct loop *
882 loop_containing_stmt (tree stmt)
884 basic_block bb = bb_for_stmt (stmt);
885 if (!bb)
886 return NULL;
888 return bb->loop_father;
891 /* Return true if VAR is a clobbered by function calls. */
892 static inline bool
893 is_call_clobbered (tree var)
895 return is_global_var (var)
896 || bitmap_bit_p (call_clobbered_vars, var_ann (var)->uid);
899 /* Mark variable VAR as being clobbered by function calls. */
900 static inline void
901 mark_call_clobbered (tree var)
903 var_ann_t ann = var_ann (var);
904 /* If VAR is a memory tag, then we need to consider it a global
905 variable. This is because the pointer that VAR represents has
906 been found to point to either an arbitrary location or to a known
907 location in global memory. */
908 if (ann->mem_tag_kind != NOT_A_TAG && ann->mem_tag_kind != STRUCT_FIELD)
909 DECL_EXTERNAL (var) = 1;
910 bitmap_set_bit (call_clobbered_vars, ann->uid);
911 ssa_call_clobbered_cache_valid = false;
912 ssa_ro_call_cache_valid = false;
915 /* Clear the call-clobbered attribute from variable VAR. */
916 static inline void
917 clear_call_clobbered (tree var)
919 var_ann_t ann = var_ann (var);
920 if (ann->mem_tag_kind != NOT_A_TAG && ann->mem_tag_kind != STRUCT_FIELD)
921 DECL_EXTERNAL (var) = 0;
922 bitmap_clear_bit (call_clobbered_vars, ann->uid);
923 ssa_call_clobbered_cache_valid = false;
924 ssa_ro_call_cache_valid = false;
927 /* Mark variable VAR as being non-addressable. */
928 static inline void
929 mark_non_addressable (tree var)
931 bitmap_clear_bit (call_clobbered_vars, var_ann (var)->uid);
932 TREE_ADDRESSABLE (var) = 0;
933 ssa_call_clobbered_cache_valid = false;
934 ssa_ro_call_cache_valid = false;
937 /* Return the common annotation for T. Return NULL if the annotation
938 doesn't already exist. */
939 static inline tree_ann_t
940 tree_ann (tree t)
942 return t->common.ann;
945 /* Return a common annotation for T. Create the constant annotation if it
946 doesn't exist. */
947 static inline tree_ann_t
948 get_tree_ann (tree t)
950 tree_ann_t ann = tree_ann (t);
951 return (ann) ? ann : create_tree_ann (t);
954 /* ----------------------------------------------------------------------- */
956 /* The following set of routines are used to iterator over various type of
957 SSA operands. */
959 /* Return true if PTR is finished iterating. */
960 static inline bool
961 op_iter_done (ssa_op_iter *ptr)
963 return ptr->done;
966 /* Get the next iterator use value for PTR. */
967 static inline use_operand_p
968 op_iter_next_use (ssa_op_iter *ptr)
970 if (ptr->use_i < ptr->num_use)
972 return USE_OP_PTR (ptr->ops->use_ops, (ptr->use_i)++);
974 if (ptr->vuse_i < ptr->num_vuse)
976 return VUSE_OP_PTR (ptr->ops->vuse_ops, (ptr->vuse_i)++);
978 if (ptr->v_mayu_i < ptr->num_v_mayu)
980 return V_MAY_DEF_OP_PTR (ptr->ops->v_may_def_ops,
981 (ptr->v_mayu_i)++);
983 if (ptr->v_mustu_i < ptr->num_v_mustu)
985 return V_MUST_DEF_KILL_PTR (ptr->ops->v_must_def_ops,
986 (ptr->v_mustu_i)++);
988 ptr->done = true;
989 return NULL_USE_OPERAND_P;
992 /* Get the next iterator def value for PTR. */
993 static inline def_operand_p
994 op_iter_next_def (ssa_op_iter *ptr)
996 if (ptr->def_i < ptr->num_def)
998 return DEF_OP_PTR (ptr->ops->def_ops, (ptr->def_i)++);
1000 if (ptr->v_mustd_i < ptr->num_v_mustd)
1002 return V_MUST_DEF_RESULT_PTR (ptr->ops->v_must_def_ops,
1003 (ptr->v_mustd_i)++);
1005 if (ptr->v_mayd_i < ptr->num_v_mayd)
1007 return V_MAY_DEF_RESULT_PTR (ptr->ops->v_may_def_ops,
1008 (ptr->v_mayd_i)++);
1010 ptr->done = true;
1011 return NULL_DEF_OPERAND_P;
1014 /* Get the next iterator tree value for PTR. */
1015 static inline tree
1016 op_iter_next_tree (ssa_op_iter *ptr)
1018 if (ptr->use_i < ptr->num_use)
1020 return USE_OP (ptr->ops->use_ops, (ptr->use_i)++);
1022 if (ptr->vuse_i < ptr->num_vuse)
1024 return VUSE_OP (ptr->ops->vuse_ops, (ptr->vuse_i)++);
1026 if (ptr->v_mayu_i < ptr->num_v_mayu)
1028 return V_MAY_DEF_OP (ptr->ops->v_may_def_ops, (ptr->v_mayu_i)++);
1030 if (ptr->v_mustu_i < ptr->num_v_mustu)
1032 return V_MUST_DEF_KILL (ptr->ops->v_must_def_ops, (ptr->v_mustu_i)++);
1034 if (ptr->def_i < ptr->num_def)
1036 return DEF_OP (ptr->ops->def_ops, (ptr->def_i)++);
1038 if (ptr->v_mustd_i < ptr->num_v_mustd)
1040 return V_MUST_DEF_RESULT (ptr->ops->v_must_def_ops,
1041 (ptr->v_mustd_i)++);
1043 if (ptr->v_mayd_i < ptr->num_v_mayd)
1045 return V_MAY_DEF_RESULT (ptr->ops->v_may_def_ops,
1046 (ptr->v_mayd_i)++);
1048 ptr->done = true;
1049 return NULL;
1052 /* Initialize the iterator PTR to the virtual defs in STMT. */
1053 static inline void
1054 op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
1056 stmt_operands_p ops;
1057 stmt_ann_t ann = get_stmt_ann (stmt);
1059 ops = &(ann->operands);
1060 ptr->done = false;
1061 ptr->ops = ops;
1062 ptr->num_def = (flags & SSA_OP_DEF) ? NUM_DEFS (ops->def_ops) : 0;
1063 ptr->num_use = (flags & SSA_OP_USE) ? NUM_USES (ops->use_ops) : 0;
1064 ptr->num_vuse = (flags & SSA_OP_VUSE) ? NUM_VUSES (ops->vuse_ops) : 0;
1065 ptr->num_v_mayu = (flags & SSA_OP_VMAYUSE)
1066 ? NUM_V_MAY_DEFS (ops->v_may_def_ops) : 0;
1067 ptr->num_v_mayd = (flags & SSA_OP_VMAYDEF)
1068 ? NUM_V_MAY_DEFS (ops->v_may_def_ops) : 0;
1069 ptr->num_v_mustu = (flags & SSA_OP_VMUSTDEFKILL)
1070 ? NUM_V_MUST_DEFS (ops->v_must_def_ops) : 0;
1071 ptr->num_v_mustd = (flags & SSA_OP_VMUSTDEF)
1072 ? NUM_V_MUST_DEFS (ops->v_must_def_ops) : 0;
1073 ptr->def_i = 0;
1074 ptr->use_i = 0;
1075 ptr->vuse_i = 0;
1076 ptr->v_mayu_i = 0;
1077 ptr->v_mayd_i = 0;
1078 ptr->v_mustu_i = 0;
1079 ptr->v_mustd_i = 0;
1082 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
1083 the first use. */
1084 static inline use_operand_p
1085 op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
1087 op_iter_init (ptr, stmt, flags);
1088 return op_iter_next_use (ptr);
1091 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
1092 the first def. */
1093 static inline def_operand_p
1094 op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1096 op_iter_init (ptr, stmt, flags);
1097 return op_iter_next_def (ptr);
1100 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1101 the first operand as a tree. */
1102 static inline tree
1103 op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1105 op_iter_init (ptr, stmt, flags);
1106 return op_iter_next_tree (ptr);
1109 /* Get the next iterator mustdef value for PTR, returning the mustdef values in
1110 KILL and DEF. */
1111 static inline void
1112 op_iter_next_mustdef (use_operand_p *kill, def_operand_p *def, ssa_op_iter *ptr)
1114 if (ptr->v_mustu_i < ptr->num_v_mustu)
1116 *def = V_MUST_DEF_RESULT_PTR (ptr->ops->v_must_def_ops, ptr->v_mustu_i);
1117 *kill = V_MUST_DEF_KILL_PTR (ptr->ops->v_must_def_ops, (ptr->v_mustu_i)++);
1118 return;
1120 else
1122 *def = NULL_DEF_OPERAND_P;
1123 *kill = NULL_USE_OPERAND_P;
1125 ptr->done = true;
1126 return;
1128 /* Get the next iterator maydef value for PTR, returning the maydef values in
1129 USE and DEF. */
1130 static inline void
1131 op_iter_next_maydef (use_operand_p *use, def_operand_p *def, ssa_op_iter *ptr)
1133 if (ptr->v_mayu_i < ptr->num_v_mayu)
1135 *def = V_MAY_DEF_RESULT_PTR (ptr->ops->v_may_def_ops, ptr->v_mayu_i);
1136 *use = V_MAY_DEF_OP_PTR (ptr->ops->v_may_def_ops, (ptr->v_mayu_i)++);
1137 return;
1139 else
1141 *def = NULL_DEF_OPERAND_P;
1142 *use = NULL_USE_OPERAND_P;
1144 ptr->done = true;
1145 return;
1148 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1149 in USE and DEF. */
1150 static inline void
1151 op_iter_init_maydef (ssa_op_iter *ptr, tree stmt, use_operand_p *use,
1152 def_operand_p *def)
1154 op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1155 op_iter_next_maydef (use, def, ptr);
1158 /* Return true if VAR cannot be modified by the program. */
1160 static inline bool
1161 unmodifiable_var_p (tree var)
1163 if (TREE_CODE (var) == SSA_NAME)
1164 var = SSA_NAME_VAR (var);
1165 return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1169 /* Initialize iterator PTR to the operands in STMT. Return the first operands
1170 in KILL and DEF. */
1171 static inline void
1172 op_iter_init_mustdef (ssa_op_iter *ptr, tree stmt, use_operand_p *kill,
1173 def_operand_p *def)
1175 op_iter_init (ptr, stmt, SSA_OP_VMUSTDEFKILL);
1176 op_iter_next_mustdef (kill, def, ptr);
1179 /* Return true if REF, a COMPONENT_REF, has an ARRAY_REF somewhere in it. */
1181 static inline bool
1182 ref_contains_array_ref (tree ref)
1184 while (handled_component_p (ref))
1186 if (TREE_CODE (ref) == ARRAY_REF)
1187 return true;
1188 ref = TREE_OPERAND (ref, 0);
1190 return false;
1193 /* Given a variable VAR, lookup and return a pointer to the list of
1194 subvariables for it. */
1196 static inline subvar_t *
1197 lookup_subvars_for_var (tree var)
1199 var_ann_t ann = var_ann (var);
1200 gcc_assert (ann);
1201 return &ann->subvars;
1204 /* Given a variable VAR, return a linked list of subvariables for VAR, or
1205 NULL, if there are no subvariables. */
1207 static inline subvar_t
1208 get_subvars_for_var (tree var)
1210 subvar_t subvars;
1212 gcc_assert (SSA_VAR_P (var));
1214 if (TREE_CODE (var) == SSA_NAME)
1215 subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
1216 else
1217 subvars = *(lookup_subvars_for_var (var));
1218 return subvars;
1221 /* Return true if V is a tree that we can have subvars for.
1222 Normally, this is any aggregate type, however, due to implementation
1223 limitations ATM, we exclude array types as well. */
1225 static inline bool
1226 var_can_have_subvars (tree v)
1228 return (AGGREGATE_TYPE_P (TREE_TYPE (v)) &&
1229 TREE_CODE (TREE_TYPE (v)) != ARRAY_TYPE);
1233 /* Return true if OFFSET and SIZE define a range that overlaps with some
1234 portion of the range of SV, a subvar. If there was an exact overlap,
1235 *EXACT will be set to true upon return. */
1237 static inline bool
1238 overlap_subvar (HOST_WIDE_INT offset, HOST_WIDE_INT size,
1239 subvar_t sv, bool *exact)
1241 /* There are three possible cases of overlap.
1242 1. We can have an exact overlap, like so:
1243 |offset, offset + size |
1244 |sv->offset, sv->offset + sv->size |
1246 2. We can have offset starting after sv->offset, like so:
1248 |offset, offset + size |
1249 |sv->offset, sv->offset + sv->size |
1251 3. We can have offset starting before sv->offset, like so:
1253 |offset, offset + size |
1254 |sv->offset, sv->offset + sv->size|
1257 if (exact)
1258 *exact = false;
1259 if (offset == sv->offset && size == sv->size)
1261 if (exact)
1262 *exact = true;
1263 return true;
1265 else if (offset >= sv->offset && offset < (sv->offset + sv->size))
1267 return true;
1269 else if (offset < sv->offset && (offset + size > sv->offset))
1271 return true;
1273 return false;
1277 #endif /* _TREE_FLOW_INLINE_H */