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);
54 /* Return the constant annotation for T, which must be a _CST node.
55 Return NULL if the constant annotation doesn't already exist. */
56 static inline cst_ann_t
59 #if defined ENABLE_CHECKING
60 if (TREE_CODE_CLASS (TREE_CODE (t)) != 'c'
62 && t->common.ann->common.type != CST_ANN))
66 return (cst_ann_t) t->common.ann;
69 /* Return the constant annotation for T, which must be a _CST node.
70 Create the constant annotation if it doesn't exist. */
71 static inline cst_ann_t
72 get_cst_ann (tree var)
74 cst_ann_t ann = cst_ann (var);
75 return (ann) ? ann : create_cst_ann (var);
78 /* Return the expression annotation for T, which must be an expression
79 node. Return NULL if the expression annotation doesn't already
81 static inline expr_ann_t
84 #if defined ENABLE_CHECKING
87 && t->common.ann->common.type != EXPR_ANN))
91 return (expr_ann_t) t->common.ann;
94 /* Return the expression annotation for T, which must be an expression
95 node. Create the expression annotation if it doesn't exist. */
96 static inline expr_ann_t
99 expr_ann_t ann = expr_ann (t);
100 return (ann) ? ann : create_expr_ann (t);
103 /* Return the statement annotation for T, which must be a statement
104 node. Return NULL if the statement annotation doesn't exist. */
105 static inline stmt_ann_t
108 #if defined ENABLE_CHECKING
109 if (!is_gimple_stmt (t))
113 return (stmt_ann_t) t->common.ann;
116 /* Return the statement annotation for T, which must be a statement
117 node. Create the statement annotation if it doesn't exist. */
118 static inline stmt_ann_t
119 get_stmt_ann (tree stmt)
121 stmt_ann_t ann = stmt_ann (stmt);
122 return (ann) ? ann : create_stmt_ann (stmt);
126 /* Return the annotation type for annotation ANN. */
127 static inline enum tree_ann_type
128 ann_type (tree_ann ann)
130 return ann->common.type;
133 /* Return the basic block for statement T. */
134 static inline basic_block
137 stmt_ann_t ann = stmt_ann (t);
138 return ann ? ann->bb : NULL;
141 /* Return the may_aliases varray for variable VAR, or NULL if it has
143 static inline varray_type
144 may_aliases (tree var)
146 var_ann_t ann = var_ann (var);
147 return ann ? ann->may_aliases : NULL;
150 /* Return true if VAR has a hidden use, false if it does not. */
152 has_hidden_use (tree var)
154 var_ann_t ann = var_ann (var);
155 return ann ? ann->has_hidden_use : false;
158 /* Set the hidden use flag on VAR. */
160 set_has_hidden_use (tree var)
162 var_ann_t ann = var_ann (var);
164 ann = create_var_ann (var);
165 ann->has_hidden_use = 1;
168 /* Return the line number for EXPR, or return -1 if we have no line
169 number information for it. */
171 get_lineno (tree expr)
173 if (expr == NULL_TREE)
176 if (TREE_CODE (expr) == COMPOUND_EXPR)
177 expr = TREE_OPERAND (expr, 0);
179 if (! EXPR_LOCUS (expr))
182 return EXPR_LINENO (expr);
185 /* Return the file name for EXPR, or return "???" if we have no
186 filename information. */
187 static inline const char *
188 get_filename (tree expr)
190 if (expr == NULL_TREE)
193 if (TREE_CODE (expr) == COMPOUND_EXPR)
194 expr = TREE_OPERAND (expr, 0);
196 if (EXPR_LOCUS (expr) && EXPR_FILENAME (expr))
197 return EXPR_FILENAME (expr);
202 /* Mark statement T as modified. */
206 stmt_ann_t ann = stmt_ann (t);
208 ann = create_stmt_ann (t);
212 /* Mark statement T as unmodified. */
214 unmodify_stmt (tree t)
216 stmt_ann_t ann = stmt_ann (t);
218 ann = create_stmt_ann (t);
222 /* Return true if T is marked as modified, false otherwise. */
224 stmt_modified_p (tree t)
226 stmt_ann_t ann = stmt_ann (t);
228 /* Note that if the statement doesn't yet have an annotation, we consider it
229 modified. This will force the next call to get_stmt_operands to scan the
231 return ann ? ann->modified : true;
234 /* Return the definitions present in ANN, a statement annotation.
235 Return NULL if this annotation contains no definitions. */
236 static inline def_optype
237 get_def_ops (stmt_ann_t ann)
239 return ann ? ann->def_ops : NULL;
242 /* Return the uses present in ANN, a statement annotation.
243 Return NULL if this annotation contains no uses. */
244 static inline use_optype
245 get_use_ops (stmt_ann_t ann)
247 return ann ? ann->use_ops : NULL;
250 /* Return the virtual may-defs present in ANN, a statement
252 Return NULL if this annotation contains no virtual may-defs. */
253 static inline v_may_def_optype
254 get_v_may_def_ops (stmt_ann_t ann)
256 return ann ? ann->v_may_def_ops : NULL;
259 /* Return the virtual uses present in ANN, a statement annotation.
260 Return NULL if this annotation contains no virtual uses. */
261 static inline vuse_optype
262 get_vuse_ops (stmt_ann_t ann)
264 return ann ? ann->vuse_ops : NULL;
267 /* Return the virtual must-defs present in ANN, a statement
268 annotation. Return NULL if this annotation contains no must-defs.*/
269 static inline v_must_def_optype
270 get_v_must_def_ops (stmt_ann_t ann)
272 return ann ? ann->v_must_def_ops : NULL;
275 /* Return a pointer to the tree that is at INDEX in the USES array. */
277 get_use_op_ptr (use_optype uses, unsigned int index)
279 #ifdef ENABLE_CHECKING
280 if (index >= uses->num_uses)
283 return uses->uses[index];
286 /* Return a pointer to the tree that is at INDEX in the DEFS array. */
288 get_def_op_ptr (def_optype defs, unsigned int index)
290 #ifdef ENABLE_CHECKING
291 if (index >= defs->num_defs)
294 return defs->defs[index];
298 /* Return a pointer to the tree that is the V_MAY_DEF_RESULT for the V_MAY_DEF
299 at INDEX in the V_MAY_DEFS array. */
301 get_v_may_def_result_ptr(v_may_def_optype v_may_defs, unsigned int index)
303 #ifdef ENABLE_CHECKING
304 if (index >= v_may_defs->num_v_may_defs)
307 return &(v_may_defs->v_may_defs[index * 2]);
310 /* Return a pointer to the tree that is the V_MAY_DEF_OP for the V_MAY_DEF at
311 INDEX in the V_MAY_DEFS array. */
313 get_v_may_def_op_ptr(v_may_def_optype v_may_defs, unsigned int index)
315 #ifdef ENABLE_CHECKING
316 if (index >= v_may_defs->num_v_may_defs)
319 return &(v_may_defs->v_may_defs[index * 2 + 1]);
322 /* Return a pointer to the tree that is at INDEX in the VUSES array. */
324 get_vuse_op_ptr(vuse_optype vuses, unsigned int index)
326 #ifdef ENABLE_CHECKING
327 if (index >= vuses->num_vuses)
330 return &(vuses->vuses[index]);
333 /* Return a pointer to the tree that is the V_MUST_DEF_OP for the
334 V_MUST_DEF at INDEX in the V_MUST_DEFS array. */
336 get_v_must_def_op_ptr (v_must_def_optype v_must_defs, unsigned int index)
338 #ifdef ENABLE_CHECKING
339 if (index >= v_must_defs->num_v_must_defs)
342 return &(v_must_defs->v_must_defs[index]);
345 /* Mark the beginning of changes to the SSA operands for STMT. */
347 start_ssa_stmt_operands (tree stmt ATTRIBUTE_UNUSED)
349 #ifdef ENABLE_CHECKING
350 verify_start_operands (stmt);
354 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
357 addresses_taken (tree stmt)
359 stmt_ann_t ann = stmt_ann (stmt);
360 return ann ? ann->addresses_taken : NULL;
363 /* Return the immediate uses of STMT, or NULL if this information is
366 get_immediate_uses (tree stmt)
368 stmt_ann_t ann = stmt_ann (stmt);
369 return ann ? ann->df : NULL;
372 /* Return the number of immediate uses present in the dataflow
373 information at DF. */
375 num_immediate_uses (dataflow_t df)
382 imm = df->immediate_uses;
384 return df->uses[1] ? 2 : 1;
386 return VARRAY_ACTIVE_SIZE (imm) + 2;
389 /* Return the tree that is at NUM in the immediate use DF array. */
391 immediate_use (dataflow_t df, int num)
396 #ifdef ENABLE_CHECKING
397 if (num >= num_immediate_uses (df))
401 return df->uses[num];
402 return VARRAY_TREE (df->immediate_uses, num - 2);
405 /* Return the basic_block annotation for BB. */
406 static inline bb_ann_t
407 bb_ann (basic_block bb)
409 return (bb_ann_t)bb->tree_annotations;
412 /* Return the PHI nodes for basic block BB, or NULL if there are no
415 phi_nodes (basic_block bb)
419 return bb_ann (bb)->phi_nodes;
422 /* Set list of phi nodes of a basic block BB to L. */
425 set_phi_nodes (basic_block bb, tree l)
429 bb_ann (bb)->phi_nodes = l;
430 for (phi = l; phi; phi = TREE_CHAIN (phi))
431 set_bb_for_stmt (phi, bb);
434 /* Return the phi index number for an edge. */
436 phi_arg_from_edge (tree phi, edge e)
439 #if defined ENABLE_CHECKING
440 if (!phi || TREE_CODE (phi) != PHI_NODE)
444 for (i = 0; i < PHI_NUM_ARGS (phi); i++)
445 if (PHI_ARG_EDGE (phi, i) == e)
452 /* Return the phi argument number for an edge. */
453 static inline struct phi_arg_d *
454 phi_element_for_edge (tree phi, edge e)
458 i = phi_arg_from_edge (phi, e);
460 return &(PHI_ARG_ELT (phi, i));
462 return (struct phi_arg_d *)NULL;
465 /* ----------------------------------------------------------------------- */
467 /* Return true if T is an executable statement. */
469 is_exec_stmt (tree t)
471 return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
475 /* Return true if this stmt can be the target of a control transfer stmt such
478 is_label_stmt (tree t)
481 switch (TREE_CODE (t))
485 case CASE_LABEL_EXPR:
493 /* Return true if we may propagate ORIG into DEST, false otherwise. */
495 may_propagate_copy (tree dest, tree orig)
497 /* FIXME. GIMPLE is allowing pointer assignments and comparisons of
498 pointers that have different alias sets. This means that these
499 pointers will have different memory tags associated to them.
501 If we allow copy propagation in these cases, statements de-referencing
502 the new pointer will now have a reference to a different memory tag
503 with potentially incorrect SSA information.
505 This was showing up in libjava/java/util/zip/ZipFile.java with code
508 struct java.io.BufferedInputStream *T.660;
509 struct java.io.BufferedInputStream *T.647;
510 struct java.io.InputStream *is;
511 struct java.io.InputStream *is.662;
514 is = T.660; <-- This ought to be type-casted
517 Also, f/name.c exposed a similar problem with a COND_EXPR predicate
518 that was causing DOM to generate and equivalence with two pointers of
519 alias-incompatible types:
521 struct _ffename_space *n;
530 I think that GIMPLE should emit the appropriate type-casts. For the
531 time being, blocking copy-propagation in these cases is the safe thing
533 if (TREE_CODE (dest) == SSA_NAME
534 && TREE_CODE (orig) == SSA_NAME
535 && POINTER_TYPE_P (TREE_TYPE (dest))
536 && POINTER_TYPE_P (TREE_TYPE (orig)))
538 tree mt_dest = var_ann (SSA_NAME_VAR (dest))->type_mem_tag;
539 tree mt_orig = var_ann (SSA_NAME_VAR (orig))->type_mem_tag;
540 if (mt_dest && mt_orig && mt_dest != mt_orig)
544 /* If the destination is a SSA_NAME for a virtual operand, then we have
545 some special cases to handle. */
546 if (TREE_CODE (dest) == SSA_NAME && !is_gimple_reg (dest))
548 /* If both operands are SSA_NAMEs referring to virtual operands, then
549 we can always propagate. */
550 if (TREE_CODE (orig) == SSA_NAME)
552 if (!is_gimple_reg (orig))
555 #ifdef ENABLE_CHECKING
556 /* If we have one real and one virtual operand, then something has
557 gone terribly wrong. */
558 if (is_gimple_reg (orig))
563 /* We have a "copy" from something like a constant into a virtual
564 operand. Reject these. */
568 return (!SSA_NAME_OCCURS_IN_ABNORMAL_PHI (dest)
569 && (TREE_CODE (orig) != SSA_NAME
570 || !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (orig))
571 && !DECL_HARD_REGISTER (SSA_NAME_VAR (dest)));
574 /* Set the default definition for VAR to DEF. */
576 set_default_def (tree var, tree def)
578 var_ann_t ann = var_ann (var);
580 ann = create_var_ann (var);
581 ann->default_def = def;
584 /* Return the default definition for variable VAR, or NULL if none
587 default_def (tree var)
589 var_ann_t ann = var_ann (var);
590 return ann ? ann->default_def : NULL_TREE;
593 /* PHI nodes should contain only ssa_names and invariants. A test
594 for ssa_name is definitely simpler; don't let invalid contents
595 slip in in the meantime. */
598 phi_ssa_name_p (tree t)
600 if (TREE_CODE (t) == SSA_NAME)
602 #ifdef ENABLE_CHECKING
603 if (!is_gimple_min_invariant (t))
609 /* ----------------------------------------------------------------------- */
611 /* Return a block_stmt_iterator that points to beginning of basic
613 static inline block_stmt_iterator
614 bsi_start (basic_block bb)
616 block_stmt_iterator bsi;
618 bsi.tsi = tsi_start (bb->stmt_list);
621 #ifdef ENABLE_CHECKING
626 bsi.tsi.container = NULL;
632 /* Return a block statement iterator that points to the end of basic
634 static inline block_stmt_iterator
635 bsi_last (basic_block bb)
637 block_stmt_iterator bsi;
639 bsi.tsi = tsi_last (bb->stmt_list);
642 #ifdef ENABLE_CHECKING
647 bsi.tsi.container = NULL;
653 /* Return true if block statement iterator I has reached the end of
656 bsi_end_p (block_stmt_iterator i)
658 return tsi_end_p (i.tsi);
661 /* Modify block statement iterator I so that it is at the next
662 statement in the basic block. */
664 bsi_next (block_stmt_iterator *i)
669 /* Modify block statement iterator I so that it is at the previous
670 statement in the basic block. */
672 bsi_prev (block_stmt_iterator *i)
677 /* Return the statement that block statement iterator I is currently
680 bsi_stmt (block_stmt_iterator i)
682 return tsi_stmt (i.tsi);
685 /* Return a pointer to the statement that block statement iterator I
688 bsi_stmt_ptr (block_stmt_iterator i)
690 return tsi_stmt_ptr (i.tsi);
693 /* Return true if VAR may be aliased. */
695 may_be_aliased (tree var)
697 return (TREE_ADDRESSABLE (var)
698 || decl_function_context (var) != current_function_decl);
701 /* Return true if VAR is a clobbered by function calls. */
703 is_call_clobbered (tree var)
705 return needs_to_live_in_memory (var)
706 || bitmap_bit_p (call_clobbered_vars, var_ann (var)->uid);
709 /* Mark variable VAR as being clobbered by function calls. */
711 mark_call_clobbered (tree var)
713 var_ann_t ann = var_ann (var);
714 /* Call-clobbered variables need to live in memory. */
715 DECL_NEEDS_TO_LIVE_IN_MEMORY_INTERNAL (var) = 1;
716 bitmap_set_bit (call_clobbered_vars, ann->uid);
719 /* Mark variable VAR as being non-addressable. */
721 mark_non_addressable (tree var)
723 bitmap_clear_bit (call_clobbered_vars, var_ann (var)->uid);
724 DECL_NEEDS_TO_LIVE_IN_MEMORY_INTERNAL (var) = 0;
725 TREE_ADDRESSABLE (var) = 0;
728 #endif /* _TREE_FLOW_INLINE_H */