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
33 #if defined ENABLE_CHECKING
37 && t
->common
.ann
->common
.type
!= VAR_ANN
))
41 return (var_ann_t
) t
->common
.ann
;
44 /* Return the variable annotation for T, which must be a _DECL node.
45 Create the variable annotation if it doesn't exist. */
46 static inline var_ann_t
47 get_var_ann (tree var
)
49 var_ann_t ann
= var_ann (var
);
50 return (ann
) ? ann
: create_var_ann (var
);
53 /* Return the statement annotation for T, which must be a statement
54 node. Return NULL if the statement annotation doesn't exist. */
55 static inline stmt_ann_t
58 #if defined ENABLE_CHECKING
59 if (!is_gimple_stmt (t
))
63 return (stmt_ann_t
) t
->common
.ann
;
66 /* Return the statement annotation for T, which must be a statement
67 node. Create the statement annotation if it doesn't exist. */
68 static inline stmt_ann_t
69 get_stmt_ann (tree stmt
)
71 stmt_ann_t ann
= stmt_ann (stmt
);
72 return (ann
) ? ann
: create_stmt_ann (stmt
);
76 /* Return the annotation type for annotation ANN. */
77 static inline enum tree_ann_type
78 ann_type (tree_ann_t ann
)
80 return ann
->common
.type
;
83 /* Return the basic block for statement T. */
84 static inline basic_block
87 stmt_ann_t ann
= stmt_ann (t
);
88 return ann
? ann
->bb
: NULL
;
91 /* Return the may_aliases varray for variable VAR, or NULL if it has
93 static inline varray_type
94 may_aliases (tree var
)
96 var_ann_t ann
= var_ann (var
);
97 return ann
? ann
->may_aliases
: NULL
;
100 /* Return the line number for EXPR, or return -1 if we have no line
101 number information for it. */
103 get_lineno (tree expr
)
105 if (expr
== NULL_TREE
)
108 if (TREE_CODE (expr
) == COMPOUND_EXPR
)
109 expr
= TREE_OPERAND (expr
, 0);
111 if (! EXPR_HAS_LOCATION (expr
))
114 return EXPR_LINENO (expr
);
117 /* Return the file name for EXPR, or return "???" if we have no
118 filename information. */
119 static inline const char *
120 get_filename (tree expr
)
122 const char *filename
;
123 if (expr
== NULL_TREE
)
126 if (TREE_CODE (expr
) == COMPOUND_EXPR
)
127 expr
= TREE_OPERAND (expr
, 0);
129 if (EXPR_HAS_LOCATION (expr
) && (filename
= EXPR_FILENAME (expr
)))
135 /* Mark statement T as modified. */
139 stmt_ann_t ann
= stmt_ann (t
);
141 ann
= create_stmt_ann (t
);
145 /* Mark statement T as unmodified. */
147 unmodify_stmt (tree t
)
149 stmt_ann_t ann
= stmt_ann (t
);
151 ann
= create_stmt_ann (t
);
155 /* Return true if T is marked as modified, false otherwise. */
157 stmt_modified_p (tree t
)
159 stmt_ann_t ann
= stmt_ann (t
);
161 /* Note that if the statement doesn't yet have an annotation, we consider it
162 modified. This will force the next call to get_stmt_operands to scan the
164 return ann
? ann
->modified
: true;
167 /* Return the definitions present in ANN, a statement annotation.
168 Return NULL if this annotation contains no definitions. */
169 static inline def_optype
170 get_def_ops (stmt_ann_t ann
)
172 return ann
? ann
->operands
.def_ops
: NULL
;
175 /* Return the uses present in ANN, a statement annotation.
176 Return NULL if this annotation contains no uses. */
177 static inline use_optype
178 get_use_ops (stmt_ann_t ann
)
180 return ann
? ann
->operands
.use_ops
: NULL
;
183 /* Return the virtual may-defs present in ANN, a statement
185 Return NULL if this annotation contains no virtual may-defs. */
186 static inline v_may_def_optype
187 get_v_may_def_ops (stmt_ann_t ann
)
189 return ann
? ann
->operands
.v_may_def_ops
: NULL
;
192 /* Return the virtual uses present in ANN, a statement annotation.
193 Return NULL if this annotation contains no virtual uses. */
194 static inline vuse_optype
195 get_vuse_ops (stmt_ann_t ann
)
197 return ann
? ann
->operands
.vuse_ops
: NULL
;
200 /* Return the virtual must-defs present in ANN, a statement
201 annotation. Return NULL if this annotation contains no must-defs.*/
202 static inline v_must_def_optype
203 get_v_must_def_ops (stmt_ann_t ann
)
205 return ann
? ann
->operands
.v_must_def_ops
: NULL
;
208 /* Return the tree pointer to by USE. */
210 get_use_from_ptr (use_operand_p use
)
215 /* Return the tree pointer to by DEF. */
217 get_def_from_ptr (def_operand_p def
)
222 /* Return a pointer to the tree that is at INDEX in the USES array. */
223 static inline use_operand_p
224 get_use_op_ptr (use_optype uses
, unsigned int index
)
226 #ifdef ENABLE_CHECKING
227 if (index
>= uses
->num_uses
)
230 return uses
->uses
[index
];
233 /* Return a def_operand_p pointer for element INDEX of DEFS. */
234 static inline def_operand_p
235 get_def_op_ptr (def_optype defs
, unsigned int index
)
237 #ifdef ENABLE_CHECKING
238 if (index
>= defs
->num_defs
)
241 return defs
->defs
[index
];
245 /* Return the def_operand_p that is the V_MAY_DEF_RESULT for the V_MAY_DEF
246 at INDEX in the V_MAY_DEFS array. */
247 static inline def_operand_p
248 get_v_may_def_result_ptr(v_may_def_optype v_may_defs
, unsigned int index
)
251 #ifdef ENABLE_CHECKING
252 if (index
>= v_may_defs
->num_v_may_defs
)
255 op
.def
= &(v_may_defs
->v_may_defs
[index
].def
);
259 /* Return a use_operand_p that is the V_MAY_DEF_OP for the V_MAY_DEF at
260 INDEX in the V_MAY_DEFS array. */
261 static inline use_operand_p
262 get_v_may_def_op_ptr(v_may_def_optype v_may_defs
, unsigned int index
)
265 #ifdef ENABLE_CHECKING
266 if (index
>= v_may_defs
->num_v_may_defs
)
269 op
.use
= &(v_may_defs
->v_may_defs
[index
].use
);
273 /* Return a use_operand_p that is at INDEX in the VUSES array. */
274 static inline use_operand_p
275 get_vuse_op_ptr(vuse_optype vuses
, unsigned int index
)
278 #ifdef ENABLE_CHECKING
279 if (index
>= vuses
->num_vuses
)
282 op
.use
= &(vuses
->vuses
[index
]);
286 /* Return a def_operand_p that is the V_MUST_DEF_OP for the
287 V_MUST_DEF at INDEX in the V_MUST_DEFS array. */
288 static inline def_operand_p
289 get_v_must_def_op_ptr (v_must_def_optype v_must_defs
, unsigned int index
)
292 #ifdef ENABLE_CHECKING
293 if (index
>= v_must_defs
->num_v_must_defs
)
296 op
.def
= &(v_must_defs
->v_must_defs
[index
]);
300 /* Return a def_operand_p pointer for the result of PHI. */
301 static inline def_operand_p
302 get_phi_result_ptr (tree phi
)
305 op
.def
= &(PHI_RESULT_TREE (phi
));
309 /* Return a use_operand_p pointer for argument I of phinode PHI. */
310 static inline use_operand_p
311 get_phi_arg_def_ptr (tree phi
, int i
)
314 op
.use
= &(PHI_ARG_DEF_TREE (phi
, i
));
318 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
321 addresses_taken (tree stmt
)
323 stmt_ann_t ann
= stmt_ann (stmt
);
324 return ann
? ann
->addresses_taken
: NULL
;
327 /* Return the immediate uses of STMT, or NULL if this information is
330 get_immediate_uses (tree stmt
)
332 stmt_ann_t ann
= stmt_ann (stmt
);
333 return ann
? ann
->df
: NULL
;
336 /* Return the number of immediate uses present in the dataflow
337 information at DF. */
339 num_immediate_uses (dataflow_t df
)
346 imm
= df
->immediate_uses
;
348 return df
->uses
[1] ? 2 : 1;
350 return VARRAY_ACTIVE_SIZE (imm
) + 2;
353 /* Return the tree that is at NUM in the immediate use DF array. */
355 immediate_use (dataflow_t df
, int num
)
360 #ifdef ENABLE_CHECKING
361 if (num
>= num_immediate_uses (df
))
365 return df
->uses
[num
];
366 return VARRAY_TREE (df
->immediate_uses
, num
- 2);
369 /* Return the basic_block annotation for BB. */
370 static inline bb_ann_t
371 bb_ann (basic_block bb
)
373 return (bb_ann_t
)bb
->tree_annotations
;
376 /* Return the PHI nodes for basic block BB, or NULL if there are no
379 phi_nodes (basic_block bb
)
383 return bb_ann (bb
)->phi_nodes
;
386 /* Set list of phi nodes of a basic block BB to L. */
389 set_phi_nodes (basic_block bb
, tree l
)
393 bb_ann (bb
)->phi_nodes
= l
;
394 for (phi
= l
; phi
; phi
= PHI_CHAIN (phi
))
395 set_bb_for_stmt (phi
, bb
);
398 /* Return the phi index number for an edge. */
400 phi_arg_from_edge (tree phi
, edge e
)
403 #if defined ENABLE_CHECKING
404 if (!phi
|| TREE_CODE (phi
) != PHI_NODE
)
408 for (i
= 0; i
< PHI_NUM_ARGS (phi
); i
++)
409 if (PHI_ARG_EDGE (phi
, i
) == e
)
415 /* Mark VAR as used, so that it'll be preserved during rtl expansion. */
418 set_is_used (tree var
)
420 var_ann_t ann
= get_var_ann (var
);
425 /* ----------------------------------------------------------------------- */
427 /* Return true if T is an executable statement. */
429 is_exec_stmt (tree t
)
431 return (t
&& !IS_EMPTY_STMT (t
) && t
!= error_mark_node
);
435 /* Return true if this stmt can be the target of a control transfer stmt such
438 is_label_stmt (tree t
)
441 switch (TREE_CODE (t
))
445 case CASE_LABEL_EXPR
:
453 /* Set the default definition for VAR to DEF. */
455 set_default_def (tree var
, tree def
)
457 var_ann_t ann
= get_var_ann (var
);
458 ann
->default_def
= def
;
461 /* Return the default definition for variable VAR, or NULL if none
464 default_def (tree var
)
466 var_ann_t ann
= var_ann (var
);
467 return ann
? ann
->default_def
: NULL_TREE
;
470 /* PHI nodes should contain only ssa_names and invariants. A test
471 for ssa_name is definitely simpler; don't let invalid contents
472 slip in in the meantime. */
475 phi_ssa_name_p (tree t
)
477 if (TREE_CODE (t
) == SSA_NAME
)
479 #ifdef ENABLE_CHECKING
480 if (!is_gimple_min_invariant (t
))
486 /* ----------------------------------------------------------------------- */
488 /* Return a block_stmt_iterator that points to beginning of basic
490 static inline block_stmt_iterator
491 bsi_start (basic_block bb
)
493 block_stmt_iterator bsi
;
495 bsi
.tsi
= tsi_start (bb
->stmt_list
);
498 #ifdef ENABLE_CHECKING
503 bsi
.tsi
.container
= NULL
;
509 /* Return a block statement iterator that points to the last label in
512 static inline block_stmt_iterator
513 bsi_after_labels (basic_block bb
)
515 block_stmt_iterator bsi
;
516 tree_stmt_iterator next
;
522 #ifdef ENABLE_CHECKING
527 bsi
.tsi
.container
= NULL
;
531 bsi
.tsi
= tsi_start (bb
->stmt_list
);
532 if (tsi_end_p (bsi
.tsi
))
535 /* Ensure that there are some labels. The rationale is that we want
536 to insert after the bsi that is returned, and these insertions should
537 be placed at the start of the basic block. This would not work if the
538 first statement was not label; rather fail here than enable the user
539 proceed in wrong way. */
540 if (TREE_CODE (tsi_stmt (bsi
.tsi
)) != LABEL_EXPR
)
546 while (!tsi_end_p (next
)
547 && TREE_CODE (tsi_stmt (next
)) == LABEL_EXPR
)
556 /* Return a block statement iterator that points to the end of basic
558 static inline block_stmt_iterator
559 bsi_last (basic_block bb
)
561 block_stmt_iterator bsi
;
563 bsi
.tsi
= tsi_last (bb
->stmt_list
);
566 #ifdef ENABLE_CHECKING
571 bsi
.tsi
.container
= NULL
;
577 /* Return true if block statement iterator I has reached the end of
580 bsi_end_p (block_stmt_iterator i
)
582 return tsi_end_p (i
.tsi
);
585 /* Modify block statement iterator I so that it is at the next
586 statement in the basic block. */
588 bsi_next (block_stmt_iterator
*i
)
593 /* Modify block statement iterator I so that it is at the previous
594 statement in the basic block. */
596 bsi_prev (block_stmt_iterator
*i
)
601 /* Return the statement that block statement iterator I is currently
604 bsi_stmt (block_stmt_iterator i
)
606 return tsi_stmt (i
.tsi
);
609 /* Return a pointer to the statement that block statement iterator I
612 bsi_stmt_ptr (block_stmt_iterator i
)
614 return tsi_stmt_ptr (i
.tsi
);
617 /* Returns the loop of the statement STMT. */
619 static inline struct loop
*
620 loop_containing_stmt (tree stmt
)
622 basic_block bb
= bb_for_stmt (stmt
);
626 return bb
->loop_father
;
629 /* Return true if VAR is a clobbered by function calls. */
631 is_call_clobbered (tree var
)
633 return is_global_var (var
)
634 || bitmap_bit_p (call_clobbered_vars
, var_ann (var
)->uid
);
637 /* Mark variable VAR as being clobbered by function calls. */
639 mark_call_clobbered (tree var
)
641 var_ann_t ann
= var_ann (var
);
642 /* If VAR is a memory tag, then we need to consider it a global
643 variable. This is because the pointer that VAR represents has
644 been found to point to either an arbitrary location or to a known
645 location in global memory. */
646 if (ann
->mem_tag_kind
!= NOT_A_TAG
)
647 DECL_EXTERNAL (var
) = 1;
648 bitmap_set_bit (call_clobbered_vars
, ann
->uid
);
651 /* Mark variable VAR as being non-addressable. */
653 mark_non_addressable (tree var
)
655 bitmap_clear_bit (call_clobbered_vars
, var_ann (var
)->uid
);
656 TREE_ADDRESSABLE (var
) = 0;
659 /* Return the common annotation for T. Return NULL if the annotation
660 doesn't already exist. */
661 static inline tree_ann_t
664 return t
->common
.ann
;
667 /* Return a common annotation for T. Create the constant annotation if it
669 static inline tree_ann_t
670 get_tree_ann (tree t
)
672 tree_ann_t ann
= tree_ann (t
);
673 return (ann
) ? ann
: create_tree_ann (t
);
676 #endif /* _TREE_FLOW_INLINE_H */