1 /* Inline functions for tree-flow.h
2 Copyright (C) 2001, 2003 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)
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
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
54 #ifdef ENABLE_CHECKING
55 gcc_assert (is_gimple_stmt (t
));
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
83 if (TREE_CODE (t
) == PHI_NODE
)
87 return ann
? ann
->bb
: NULL
;
90 /* Return the may_aliases varray for variable VAR, or NULL if it has
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. */
102 get_lineno (tree expr
)
104 if (expr
== NULL_TREE
)
107 if (TREE_CODE (expr
) == COMPOUND_EXPR
)
108 expr
= TREE_OPERAND (expr
, 0);
110 if (! EXPR_HAS_LOCATION (expr
))
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
)
125 if (TREE_CODE (expr
) == COMPOUND_EXPR
)
126 expr
= TREE_OPERAND (expr
, 0);
128 if (EXPR_HAS_LOCATION (expr
) && (filename
= EXPR_FILENAME (expr
)))
134 /* Mark statement T as modified. */
138 stmt_ann_t ann
= stmt_ann (t
);
140 ann
= create_stmt_ann (t
);
144 /* Mark statement T as unmodified. */
146 unmodify_stmt (tree t
)
148 stmt_ann_t ann
= stmt_ann (t
);
150 ann
= create_stmt_ann (t
);
154 /* Return true if T is marked as modified, false otherwise. */
156 stmt_modified_p (tree t
)
158 stmt_ann_t ann
= stmt_ann (t
);
160 /* Note that if the statement doesn't yet have an annotation, we consider it
161 modified. This will force the next call to get_stmt_operands to scan the
163 return ann
? ann
->modified
: true;
166 /* Return the definitions present in ANN, a statement annotation.
167 Return NULL if this annotation contains no definitions. */
168 static inline def_optype
169 get_def_ops (stmt_ann_t ann
)
171 return ann
? ann
->operands
.def_ops
: NULL
;
174 /* Return the uses present in ANN, a statement annotation.
175 Return NULL if this annotation contains no uses. */
176 static inline use_optype
177 get_use_ops (stmt_ann_t ann
)
179 return ann
? ann
->operands
.use_ops
: NULL
;
182 /* Return the virtual may-defs present in ANN, a statement
184 Return NULL if this annotation contains no virtual may-defs. */
185 static inline v_may_def_optype
186 get_v_may_def_ops (stmt_ann_t ann
)
188 return ann
? ann
->operands
.v_may_def_ops
: NULL
;
191 /* Return the virtual uses present in ANN, a statement annotation.
192 Return NULL if this annotation contains no virtual uses. */
193 static inline vuse_optype
194 get_vuse_ops (stmt_ann_t ann
)
196 return ann
? ann
->operands
.vuse_ops
: NULL
;
199 /* Return the virtual must-defs present in ANN, a statement
200 annotation. Return NULL if this annotation contains no must-defs.*/
201 static inline v_must_def_optype
202 get_v_must_def_ops (stmt_ann_t ann
)
204 return ann
? ann
->operands
.v_must_def_ops
: NULL
;
207 /* Return the tree pointer to by USE. */
209 get_use_from_ptr (use_operand_p use
)
214 /* Return the tree pointer to by DEF. */
216 get_def_from_ptr (def_operand_p def
)
221 /* Return a pointer to the tree that is at INDEX in the USES array. */
222 static inline use_operand_p
223 get_use_op_ptr (use_optype uses
, unsigned int index
)
225 gcc_assert (index
< uses
->num_uses
);
226 return uses
->uses
[index
];
229 /* Return a def_operand_p pointer for element INDEX of DEFS. */
230 static inline def_operand_p
231 get_def_op_ptr (def_optype defs
, unsigned int index
)
233 gcc_assert (index
< defs
->num_defs
);
234 return defs
->defs
[index
];
238 /* Return the def_operand_p that is the V_MAY_DEF_RESULT for the V_MAY_DEF
239 at INDEX in the V_MAY_DEFS array. */
240 static inline def_operand_p
241 get_v_may_def_result_ptr(v_may_def_optype v_may_defs
, unsigned int index
)
244 gcc_assert (index
< v_may_defs
->num_v_may_defs
);
245 op
.def
= &(v_may_defs
->v_may_defs
[index
].def
);
249 /* Return a use_operand_p that is the V_MAY_DEF_OP for the V_MAY_DEF at
250 INDEX in the V_MAY_DEFS array. */
251 static inline use_operand_p
252 get_v_may_def_op_ptr(v_may_def_optype v_may_defs
, unsigned int index
)
255 gcc_assert (index
< v_may_defs
->num_v_may_defs
);
256 op
.use
= &(v_may_defs
->v_may_defs
[index
].use
);
260 /* Return a use_operand_p that is at INDEX in the VUSES array. */
261 static inline use_operand_p
262 get_vuse_op_ptr(vuse_optype vuses
, unsigned int index
)
265 gcc_assert (index
< vuses
->num_vuses
);
266 op
.use
= &(vuses
->vuses
[index
]);
270 /* Return a def_operand_p that is the V_MUST_DEF_OP for the
271 V_MUST_DEF at INDEX in the V_MUST_DEFS array. */
272 static inline def_operand_p
273 get_v_must_def_op_ptr (v_must_def_optype v_must_defs
, unsigned int index
)
276 gcc_assert (index
< v_must_defs
->num_v_must_defs
);
277 op
.def
= &(v_must_defs
->v_must_defs
[index
]);
281 /* Return a def_operand_p pointer for the result of PHI. */
282 static inline def_operand_p
283 get_phi_result_ptr (tree phi
)
286 op
.def
= &(PHI_RESULT_TREE (phi
));
290 /* Return a use_operand_p pointer for argument I of phinode PHI. */
291 static inline use_operand_p
292 get_phi_arg_def_ptr (tree phi
, int i
)
295 op
.use
= &(PHI_ARG_DEF_TREE (phi
, i
));
299 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
302 addresses_taken (tree stmt
)
304 stmt_ann_t ann
= stmt_ann (stmt
);
305 return ann
? ann
->addresses_taken
: NULL
;
308 /* Return the immediate uses of STMT, or NULL if this information is
311 get_immediate_uses (tree stmt
)
315 if (TREE_CODE (stmt
) == PHI_NODE
)
316 return PHI_DF (stmt
);
318 ann
= stmt_ann (stmt
);
319 return ann
? ann
->df
: NULL
;
322 /* Return the number of immediate uses present in the dataflow
323 information at DF. */
325 num_immediate_uses (dataflow_t df
)
332 imm
= df
->immediate_uses
;
334 return df
->uses
[1] ? 2 : 1;
336 return VARRAY_ACTIVE_SIZE (imm
) + 2;
339 /* Return the tree that is at NUM in the immediate use DF array. */
341 immediate_use (dataflow_t df
, int num
)
346 #ifdef ENABLE_CHECKING
347 gcc_assert (num
< num_immediate_uses (df
));
350 return df
->uses
[num
];
351 return VARRAY_TREE (df
->immediate_uses
, num
- 2);
354 /* Return the basic_block annotation for BB. */
355 static inline bb_ann_t
356 bb_ann (basic_block bb
)
358 return (bb_ann_t
)bb
->tree_annotations
;
361 /* Return the PHI nodes for basic block BB, or NULL if there are no
364 phi_nodes (basic_block bb
)
368 return bb_ann (bb
)->phi_nodes
;
371 /* Set list of phi nodes of a basic block BB to L. */
374 set_phi_nodes (basic_block bb
, tree l
)
378 bb_ann (bb
)->phi_nodes
= l
;
379 for (phi
= l
; phi
; phi
= PHI_CHAIN (phi
))
380 set_bb_for_stmt (phi
, bb
);
383 /* Return the phi index number for an edge. */
385 phi_arg_from_edge (tree phi
, edge e
)
389 gcc_assert (TREE_CODE (phi
) == PHI_NODE
);
391 for (i
= 0; i
< PHI_NUM_ARGS (phi
); i
++)
392 if (PHI_ARG_EDGE (phi
, i
) == e
)
398 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
401 set_is_used (tree var
)
403 var_ann_t ann
= get_var_ann (var
);
408 /* ----------------------------------------------------------------------- */
410 /* Return true if T is an executable statement. */
412 is_exec_stmt (tree t
)
414 return (t
&& !IS_EMPTY_STMT (t
) && t
!= error_mark_node
);
418 /* Return true if this stmt can be the target of a control transfer stmt such
421 is_label_stmt (tree t
)
424 switch (TREE_CODE (t
))
428 case CASE_LABEL_EXPR
:
436 /* Set the default definition for VAR to DEF. */
438 set_default_def (tree var
, tree def
)
440 var_ann_t ann
= get_var_ann (var
);
441 ann
->default_def
= def
;
444 /* Return the default definition for variable VAR, or NULL if none
447 default_def (tree var
)
449 var_ann_t ann
= var_ann (var
);
450 return ann
? ann
->default_def
: NULL_TREE
;
453 /* PHI nodes should contain only ssa_names and invariants. A test
454 for ssa_name is definitely simpler; don't let invalid contents
455 slip in in the meantime. */
458 phi_ssa_name_p (tree t
)
460 if (TREE_CODE (t
) == SSA_NAME
)
462 #ifdef ENABLE_CHECKING
463 gcc_assert (is_gimple_min_invariant (t
));
468 /* ----------------------------------------------------------------------- */
470 /* Return a block_stmt_iterator that points to beginning of basic
472 static inline block_stmt_iterator
473 bsi_start (basic_block bb
)
475 block_stmt_iterator bsi
;
477 bsi
.tsi
= tsi_start (bb
->stmt_list
);
480 gcc_assert (bb
->index
< 0);
482 bsi
.tsi
.container
= NULL
;
488 /* Return a block statement iterator that points to the last label in
491 static inline block_stmt_iterator
492 bsi_after_labels (basic_block bb
)
494 block_stmt_iterator bsi
;
495 tree_stmt_iterator next
;
501 gcc_assert (bb
->index
< 0);
503 bsi
.tsi
.container
= NULL
;
507 bsi
.tsi
= tsi_start (bb
->stmt_list
);
508 if (tsi_end_p (bsi
.tsi
))
511 /* Ensure that there are some labels. The rationale is that we want
512 to insert after the bsi that is returned, and these insertions should
513 be placed at the start of the basic block. This would not work if the
514 first statement was not label; rather fail here than enable the user
515 proceed in wrong way. */
516 gcc_assert (TREE_CODE (tsi_stmt (bsi
.tsi
)) == LABEL_EXPR
);
521 while (!tsi_end_p (next
)
522 && TREE_CODE (tsi_stmt (next
)) == LABEL_EXPR
)
531 /* Return a block statement iterator that points to the end of basic
533 static inline block_stmt_iterator
534 bsi_last (basic_block bb
)
536 block_stmt_iterator bsi
;
538 bsi
.tsi
= tsi_last (bb
->stmt_list
);
541 gcc_assert (bb
->index
< 0);
543 bsi
.tsi
.container
= NULL
;
549 /* Return true if block statement iterator I has reached the end of
552 bsi_end_p (block_stmt_iterator i
)
554 return tsi_end_p (i
.tsi
);
557 /* Modify block statement iterator I so that it is at the next
558 statement in the basic block. */
560 bsi_next (block_stmt_iterator
*i
)
565 /* Modify block statement iterator I so that it is at the previous
566 statement in the basic block. */
568 bsi_prev (block_stmt_iterator
*i
)
573 /* Return the statement that block statement iterator I is currently
576 bsi_stmt (block_stmt_iterator i
)
578 return tsi_stmt (i
.tsi
);
581 /* Return a pointer to the statement that block statement iterator I
584 bsi_stmt_ptr (block_stmt_iterator i
)
586 return tsi_stmt_ptr (i
.tsi
);
589 /* Returns the loop of the statement STMT. */
591 static inline struct loop
*
592 loop_containing_stmt (tree stmt
)
594 basic_block bb
= bb_for_stmt (stmt
);
598 return bb
->loop_father
;
601 /* Return true if VAR is a clobbered by function calls. */
603 is_call_clobbered (tree var
)
605 return is_global_var (var
)
606 || bitmap_bit_p (call_clobbered_vars
, var_ann (var
)->uid
);
609 /* Mark variable VAR as being clobbered by function calls. */
611 mark_call_clobbered (tree var
)
613 var_ann_t ann
= var_ann (var
);
614 /* If VAR is a memory tag, then we need to consider it a global
615 variable. This is because the pointer that VAR represents has
616 been found to point to either an arbitrary location or to a known
617 location in global memory. */
618 if (ann
->mem_tag_kind
!= NOT_A_TAG
)
619 DECL_EXTERNAL (var
) = 1;
620 bitmap_set_bit (call_clobbered_vars
, ann
->uid
);
623 /* Mark variable VAR as being non-addressable. */
625 mark_non_addressable (tree var
)
627 bitmap_clear_bit (call_clobbered_vars
, var_ann (var
)->uid
);
628 TREE_ADDRESSABLE (var
) = 0;
631 /* Return the common annotation for T. Return NULL if the annotation
632 doesn't already exist. */
633 static inline tree_ann_t
636 return t
->common
.ann
;
639 /* Return a common annotation for T. Create the constant annotation if it
641 static inline tree_ann_t
642 get_tree_ann (tree t
)
644 tree_ann_t ann
= tree_ann (t
);
645 return (ann
) ? ann
: create_tree_ann (t
);
648 /* ----------------------------------------------------------------------- */
650 /* The following set of routines are used to iterator over various type of
653 /* Return true if PTR is finished iterating. */
655 op_iter_done (ssa_op_iter
*ptr
)
660 /* Get the next iterator use value for PTR. */
661 static inline use_operand_p
662 op_iter_next_use (ssa_op_iter
*ptr
)
664 if (ptr
->use_i
< ptr
->num_use
)
666 return USE_OP_PTR (ptr
->ops
->use_ops
, (ptr
->use_i
)++);
668 if (ptr
->vuse_i
< ptr
->num_vuse
)
670 return VUSE_OP_PTR (ptr
->ops
->vuse_ops
, (ptr
->vuse_i
)++);
672 if (ptr
->v_mayu_i
< ptr
->num_v_mayu
)
674 return V_MAY_DEF_OP_PTR (ptr
->ops
->v_may_def_ops
,
678 return NULL_USE_OPERAND_P
;
681 /* Get the next iterator def value for PTR. */
682 static inline def_operand_p
683 op_iter_next_def (ssa_op_iter
*ptr
)
685 if (ptr
->def_i
< ptr
->num_def
)
687 return DEF_OP_PTR (ptr
->ops
->def_ops
, (ptr
->def_i
)++);
689 if (ptr
->v_must_i
< ptr
->num_v_must
)
691 return V_MUST_DEF_OP_PTR (ptr
->ops
->v_must_def_ops
,
694 if (ptr
->v_mayd_i
< ptr
->num_v_mayd
)
696 return V_MAY_DEF_RESULT_PTR (ptr
->ops
->v_may_def_ops
,
700 return NULL_DEF_OPERAND_P
;
703 /* Get the next iterator tree value for PTR. */
705 op_iter_next_tree (ssa_op_iter
*ptr
)
707 if (ptr
->use_i
< ptr
->num_use
)
709 return USE_OP (ptr
->ops
->use_ops
, (ptr
->use_i
)++);
711 if (ptr
->vuse_i
< ptr
->num_vuse
)
713 return VUSE_OP (ptr
->ops
->vuse_ops
, (ptr
->vuse_i
)++);
715 if (ptr
->v_mayu_i
< ptr
->num_v_mayu
)
717 return V_MAY_DEF_OP (ptr
->ops
->v_may_def_ops
, (ptr
->v_mayu_i
)++);
719 if (ptr
->def_i
< ptr
->num_def
)
721 return DEF_OP (ptr
->ops
->def_ops
, (ptr
->def_i
)++);
723 if (ptr
->v_must_i
< ptr
->num_v_must
)
725 return V_MUST_DEF_OP (ptr
->ops
->v_must_def_ops
,
728 if (ptr
->v_mayd_i
< ptr
->num_v_mayd
)
730 return V_MAY_DEF_RESULT (ptr
->ops
->v_may_def_ops
,
737 /* Initialize the iterator PTR to the virtual defs in STMT. */
739 op_iter_init (ssa_op_iter
*ptr
, tree stmt
, int flags
)
742 stmt_ann_t ann
= get_stmt_ann (stmt
);
744 ops
= &(ann
->operands
);
747 ptr
->num_def
= (flags
& SSA_OP_DEF
) ? NUM_DEFS (ops
->def_ops
) : 0;
748 ptr
->num_use
= (flags
& SSA_OP_USE
) ? NUM_USES (ops
->use_ops
) : 0;
749 ptr
->num_vuse
= (flags
& SSA_OP_VUSE
) ? NUM_VUSES (ops
->vuse_ops
) : 0;
750 ptr
->num_v_mayu
= (flags
& SSA_OP_VMAYUSE
)
751 ? NUM_V_MAY_DEFS (ops
->v_may_def_ops
) : 0;
752 ptr
->num_v_mayd
= (flags
& SSA_OP_VMAYDEF
)
753 ? NUM_V_MAY_DEFS (ops
->v_may_def_ops
) : 0;
754 ptr
->num_v_must
= (flags
& SSA_OP_VMUSTDEF
)
755 ? NUM_V_MUST_DEFS (ops
->v_must_def_ops
) : 0;
764 /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
766 static inline use_operand_p
767 op_iter_init_use (ssa_op_iter
*ptr
, tree stmt
, int flags
)
769 op_iter_init (ptr
, stmt
, flags
);
770 return op_iter_next_use (ptr
);
773 /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
775 static inline def_operand_p
776 op_iter_init_def (ssa_op_iter
*ptr
, tree stmt
, int flags
)
778 op_iter_init (ptr
, stmt
, flags
);
779 return op_iter_next_def (ptr
);
782 /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
783 the first operand as a tree. */
785 op_iter_init_tree (ssa_op_iter
*ptr
, tree stmt
, int flags
)
787 op_iter_init (ptr
, stmt
, flags
);
788 return op_iter_next_tree (ptr
);
791 /* Get the next iterator maydef value for PTR, returning the maydef values in
794 op_iter_next_maydef (use_operand_p
*use
, def_operand_p
*def
, ssa_op_iter
*ptr
)
796 if (ptr
->v_mayu_i
< ptr
->num_v_mayu
)
798 *def
= V_MAY_DEF_RESULT_PTR (ptr
->ops
->v_may_def_ops
, ptr
->v_mayu_i
);
799 *use
= V_MAY_DEF_OP_PTR (ptr
->ops
->v_may_def_ops
, (ptr
->v_mayu_i
)++);
804 *def
= NULL_DEF_OPERAND_P
;
805 *use
= NULL_USE_OPERAND_P
;
811 /* Initialize iterator PTR to the operands in STMT. Return the first operands
814 op_iter_init_maydef (ssa_op_iter
*ptr
, tree stmt
, use_operand_p
*use
,
817 op_iter_init (ptr
, stmt
, SSA_OP_VMAYUSE
);
818 op_iter_next_maydef (use
, def
, ptr
);
820 #endif /* _TREE_FLOW_INLINE_H */