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 true if VAR has a hidden use, false if it does not. */
102 has_hidden_use (tree var)
104 var_ann_t ann = var_ann (var);
105 return ann ? ann->has_hidden_use : false;
108 /* Set the hidden use flag on VAR. */
110 set_has_hidden_use (tree var)
112 var_ann_t ann = var_ann (var);
114 ann = create_var_ann (var);
115 ann->has_hidden_use = 1;
118 /* Return the line number for EXPR, or return -1 if we have no line
119 number information for it. */
121 get_lineno (tree expr)
123 if (expr == NULL_TREE)
126 if (TREE_CODE (expr) == COMPOUND_EXPR)
127 expr = TREE_OPERAND (expr, 0);
129 if (! EXPR_HAS_LOCATION (expr))
132 return EXPR_LINENO (expr);
135 /* Return the file name for EXPR, or return "???" if we have no
136 filename information. */
137 static inline const char *
138 get_filename (tree expr)
140 const char *filename;
141 if (expr == NULL_TREE)
144 if (TREE_CODE (expr) == COMPOUND_EXPR)
145 expr = TREE_OPERAND (expr, 0);
147 if (EXPR_HAS_LOCATION (expr) && (filename = EXPR_FILENAME (expr)))
153 /* Mark statement T as modified. */
157 stmt_ann_t ann = stmt_ann (t);
159 ann = create_stmt_ann (t);
163 /* Mark statement T as unmodified. */
165 unmodify_stmt (tree t)
167 stmt_ann_t ann = stmt_ann (t);
169 ann = create_stmt_ann (t);
173 /* Return true if T is marked as modified, false otherwise. */
175 stmt_modified_p (tree t)
177 stmt_ann_t ann = stmt_ann (t);
179 /* Note that if the statement doesn't yet have an annotation, we consider it
180 modified. This will force the next call to get_stmt_operands to scan the
182 return ann ? ann->modified : true;
185 /* Return the definitions present in ANN, a statement annotation.
186 Return NULL if this annotation contains no definitions. */
187 static inline def_optype
188 get_def_ops (stmt_ann_t ann)
190 return ann ? ann->def_ops : NULL;
193 /* Return the uses present in ANN, a statement annotation.
194 Return NULL if this annotation contains no uses. */
195 static inline use_optype
196 get_use_ops (stmt_ann_t ann)
198 return ann ? ann->use_ops : NULL;
201 /* Return the virtual may-defs present in ANN, a statement
203 Return NULL if this annotation contains no virtual may-defs. */
204 static inline v_may_def_optype
205 get_v_may_def_ops (stmt_ann_t ann)
207 return ann ? ann->v_may_def_ops : NULL;
210 /* Return the virtual uses present in ANN, a statement annotation.
211 Return NULL if this annotation contains no virtual uses. */
212 static inline vuse_optype
213 get_vuse_ops (stmt_ann_t ann)
215 return ann ? ann->vuse_ops : NULL;
218 /* Return the virtual must-defs present in ANN, a statement
219 annotation. Return NULL if this annotation contains no must-defs.*/
220 static inline v_must_def_optype
221 get_v_must_def_ops (stmt_ann_t ann)
223 return ann ? ann->v_must_def_ops : NULL;
226 /* Return the tree pointer to by USE. */
228 get_use_from_ptr (use_operand_p use)
233 /* Return the tree pointer to by DEF. */
235 get_def_from_ptr (def_operand_p def)
240 /* Return a pointer to the tree that is at INDEX in the USES array. */
241 static inline use_operand_p
242 get_use_op_ptr (use_optype uses, unsigned int index)
244 #ifdef ENABLE_CHECKING
245 if (index >= uses->num_uses)
248 return uses->uses[index];
251 /* Return a def_operand_p pointer for element INDEX of DEFS. */
252 static inline def_operand_p
253 get_def_op_ptr (def_optype defs, unsigned int index)
255 #ifdef ENABLE_CHECKING
256 if (index >= defs->num_defs)
259 return defs->defs[index];
263 /* Return the def_operand_p that is the V_MAY_DEF_RESULT for the V_MAY_DEF
264 at INDEX in the V_MAY_DEFS array. */
265 static inline def_operand_p
266 get_v_may_def_result_ptr(v_may_def_optype v_may_defs, unsigned int index)
269 #ifdef ENABLE_CHECKING
270 if (index >= v_may_defs->num_v_may_defs)
273 op.def = &(v_may_defs->v_may_defs[index * 2]);
277 /* Return a use_operand_p that is the V_MAY_DEF_OP for the V_MAY_DEF at
278 INDEX in the V_MAY_DEFS array. */
279 static inline use_operand_p
280 get_v_may_def_op_ptr(v_may_def_optype v_may_defs, unsigned int index)
283 #ifdef ENABLE_CHECKING
284 if (index >= v_may_defs->num_v_may_defs)
287 op.use = &(v_may_defs->v_may_defs[index * 2 + 1]);
291 /* Return a use_operand_p that is at INDEX in the VUSES array. */
292 static inline use_operand_p
293 get_vuse_op_ptr(vuse_optype vuses, unsigned int index)
296 #ifdef ENABLE_CHECKING
297 if (index >= vuses->num_vuses)
300 op.use = &(vuses->vuses[index]);
304 /* Return a def_operand_p that is the V_MUST_DEF_OP for the
305 V_MUST_DEF at INDEX in the V_MUST_DEFS array. */
306 static inline def_operand_p
307 get_v_must_def_op_ptr (v_must_def_optype v_must_defs, unsigned int index)
310 #ifdef ENABLE_CHECKING
311 if (index >= v_must_defs->num_v_must_defs)
314 op.def = &(v_must_defs->v_must_defs[index]);
318 /* Return a def_operand_p pointer for the result of PHI. */
319 static inline def_operand_p
320 get_phi_result_ptr (tree phi)
323 op.def = &(PHI_RESULT_TREE (phi));
327 /* Return a use_operand_p pointer for argument I of phinode PHI. */
328 static inline use_operand_p
329 get_phi_arg_def_ptr (tree phi, int i)
332 op.use = &(PHI_ARG_DEF_TREE (phi, i));
336 /* Mark the beginning of changes to the SSA operands for STMT. */
338 start_ssa_stmt_operands (tree stmt ATTRIBUTE_UNUSED)
340 #ifdef ENABLE_CHECKING
341 verify_start_operands (stmt);
345 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
348 addresses_taken (tree stmt)
350 stmt_ann_t ann = stmt_ann (stmt);
351 return ann ? ann->addresses_taken : NULL;
354 /* Return the immediate uses of STMT, or NULL if this information is
357 get_immediate_uses (tree stmt)
359 stmt_ann_t ann = stmt_ann (stmt);
360 return ann ? ann->df : NULL;
363 /* Return the number of immediate uses present in the dataflow
364 information at DF. */
366 num_immediate_uses (dataflow_t df)
373 imm = df->immediate_uses;
375 return df->uses[1] ? 2 : 1;
377 return VARRAY_ACTIVE_SIZE (imm) + 2;
380 /* Return the tree that is at NUM in the immediate use DF array. */
382 immediate_use (dataflow_t df, int num)
387 #ifdef ENABLE_CHECKING
388 if (num >= num_immediate_uses (df))
392 return df->uses[num];
393 return VARRAY_TREE (df->immediate_uses, num - 2);
396 /* Return the basic_block annotation for BB. */
397 static inline bb_ann_t
398 bb_ann (basic_block bb)
400 return (bb_ann_t)bb->tree_annotations;
403 /* Return the PHI nodes for basic block BB, or NULL if there are no
406 phi_nodes (basic_block bb)
410 return bb_ann (bb)->phi_nodes;
413 /* Set list of phi nodes of a basic block BB to L. */
416 set_phi_nodes (basic_block bb, tree l)
420 bb_ann (bb)->phi_nodes = l;
421 for (phi = l; phi; phi = PHI_CHAIN (phi))
422 set_bb_for_stmt (phi, bb);
425 /* Return the phi index number for an edge. */
427 phi_arg_from_edge (tree phi, edge e)
430 #if defined ENABLE_CHECKING
431 if (!phi || TREE_CODE (phi) != PHI_NODE)
435 for (i = 0; i < PHI_NUM_ARGS (phi); i++)
436 if (PHI_ARG_EDGE (phi, i) == e)
442 /* ----------------------------------------------------------------------- */
444 /* Return true if T is an executable statement. */
446 is_exec_stmt (tree t)
448 return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
452 /* Return true if this stmt can be the target of a control transfer stmt such
455 is_label_stmt (tree t)
458 switch (TREE_CODE (t))
462 case CASE_LABEL_EXPR:
470 /* Set the default definition for VAR to DEF. */
472 set_default_def (tree var, tree def)
474 var_ann_t ann = var_ann (var);
476 ann = create_var_ann (var);
477 ann->default_def = def;
480 /* Return the default definition for variable VAR, or NULL if none
483 default_def (tree var)
485 var_ann_t ann = var_ann (var);
486 return ann ? ann->default_def : NULL_TREE;
489 /* PHI nodes should contain only ssa_names and invariants. A test
490 for ssa_name is definitely simpler; don't let invalid contents
491 slip in in the meantime. */
494 phi_ssa_name_p (tree t)
496 if (TREE_CODE (t) == SSA_NAME)
498 #ifdef ENABLE_CHECKING
499 if (!is_gimple_min_invariant (t))
505 /* ----------------------------------------------------------------------- */
507 /* Return a block_stmt_iterator that points to beginning of basic
509 static inline block_stmt_iterator
510 bsi_start (basic_block bb)
512 block_stmt_iterator bsi;
514 bsi.tsi = tsi_start (bb->stmt_list);
517 #ifdef ENABLE_CHECKING
522 bsi.tsi.container = NULL;
528 /* Return a block statement iterator that points to the last label in
531 static inline block_stmt_iterator
532 bsi_after_labels (basic_block bb)
534 block_stmt_iterator bsi;
535 tree_stmt_iterator next;
541 #ifdef ENABLE_CHECKING
546 bsi.tsi.container = NULL;
550 bsi.tsi = tsi_start (bb->stmt_list);
551 if (tsi_end_p (bsi.tsi))
554 /* Ensure that there are some labels. The rationale is that we want
555 to insert after the bsi that is returned, and these insertions should
556 be placed at the start of the basic block. This would not work if the
557 first statement was not label; rather fail here than enable the user
558 proceed in wrong way. */
559 if (TREE_CODE (tsi_stmt (bsi.tsi)) != LABEL_EXPR)
565 while (!tsi_end_p (next)
566 && TREE_CODE (tsi_stmt (next)) == LABEL_EXPR)
575 /* Return a block statement iterator that points to the end of basic
577 static inline block_stmt_iterator
578 bsi_last (basic_block bb)
580 block_stmt_iterator bsi;
582 bsi.tsi = tsi_last (bb->stmt_list);
585 #ifdef ENABLE_CHECKING
590 bsi.tsi.container = NULL;
596 /* Return true if block statement iterator I has reached the end of
599 bsi_end_p (block_stmt_iterator i)
601 return tsi_end_p (i.tsi);
604 /* Modify block statement iterator I so that it is at the next
605 statement in the basic block. */
607 bsi_next (block_stmt_iterator *i)
612 /* Modify block statement iterator I so that it is at the previous
613 statement in the basic block. */
615 bsi_prev (block_stmt_iterator *i)
620 /* Return the statement that block statement iterator I is currently
623 bsi_stmt (block_stmt_iterator i)
625 return tsi_stmt (i.tsi);
628 /* Return a pointer to the statement that block statement iterator I
631 bsi_stmt_ptr (block_stmt_iterator i)
633 return tsi_stmt_ptr (i.tsi);
636 /* Returns the loop of the statement STMT. */
638 static inline struct loop *
639 loop_containing_stmt (tree stmt)
641 basic_block bb = bb_for_stmt (stmt);
645 return bb->loop_father;
648 /* Return true if VAR may be aliased. */
650 may_be_aliased (tree var)
652 return (TREE_ADDRESSABLE (var)
653 || decl_function_context (var) != current_function_decl);
656 /* Return true if VAR is a clobbered by function calls. */
658 is_call_clobbered (tree var)
660 return needs_to_live_in_memory (var)
661 || bitmap_bit_p (call_clobbered_vars, var_ann (var)->uid);
664 /* Mark variable VAR as being clobbered by function calls. */
666 mark_call_clobbered (tree var)
668 var_ann_t ann = var_ann (var);
669 /* Call-clobbered variables need to live in memory. */
670 DECL_NEEDS_TO_LIVE_IN_MEMORY_INTERNAL (var) = 1;
671 bitmap_set_bit (call_clobbered_vars, ann->uid);
674 /* Mark variable VAR as being non-addressable. */
676 mark_non_addressable (tree var)
678 bitmap_clear_bit (call_clobbered_vars, var_ann (var)->uid);
679 DECL_NEEDS_TO_LIVE_IN_MEMORY_INTERNAL (var) = 0;
680 TREE_ADDRESSABLE (var) = 0;
683 /* Return the common annotation for T. Return NULL if the annotation
684 doesn't already exist. */
685 static inline tree_ann_t
688 return t->common.ann;
691 /* Return a common annotation for T. Create the constant annotation if it
693 static inline tree_ann_t
694 get_tree_ann (tree t)
696 tree_ann_t ann = tree_ann (t);
697 return (ann) ? ann : create_tree_ann (t);
700 #endif /* _TREE_FLOW_INLINE_H */