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 /* Return true if we may propagate ORIG into DEST, false otherwise. */
472 may_propagate_copy (tree dest, tree orig)
474 /* FIXME. GIMPLE is allowing pointer assignments and comparisons of
475 pointers that have different alias sets. This means that these
476 pointers will have different memory tags associated to them.
478 If we allow copy propagation in these cases, statements de-referencing
479 the new pointer will now have a reference to a different memory tag
480 with potentially incorrect SSA information.
482 This was showing up in libjava/java/util/zip/ZipFile.java with code
485 struct java.io.BufferedInputStream *T.660;
486 struct java.io.BufferedInputStream *T.647;
487 struct java.io.InputStream *is;
488 struct java.io.InputStream *is.662;
491 is = T.660; <-- This ought to be type-casted
494 Also, f/name.c exposed a similar problem with a COND_EXPR predicate
495 that was causing DOM to generate and equivalence with two pointers of
496 alias-incompatible types:
498 struct _ffename_space *n;
507 I think that GIMPLE should emit the appropriate type-casts. For the
508 time being, blocking copy-propagation in these cases is the safe thing
510 if (TREE_CODE (dest) == SSA_NAME
511 && TREE_CODE (orig) == SSA_NAME
512 && POINTER_TYPE_P (TREE_TYPE (dest))
513 && POINTER_TYPE_P (TREE_TYPE (orig)))
515 tree mt_dest = var_ann (SSA_NAME_VAR (dest))->type_mem_tag;
516 tree mt_orig = var_ann (SSA_NAME_VAR (orig))->type_mem_tag;
517 if (mt_dest && mt_orig && mt_dest != mt_orig)
521 /* If the destination is a SSA_NAME for a virtual operand, then we have
522 some special cases to handle. */
523 if (TREE_CODE (dest) == SSA_NAME && !is_gimple_reg (dest))
525 /* If both operands are SSA_NAMEs referring to virtual operands, then
526 we can always propagate. */
527 if (TREE_CODE (orig) == SSA_NAME)
529 if (!is_gimple_reg (orig))
532 #ifdef ENABLE_CHECKING
533 /* If we have one real and one virtual operand, then something has
534 gone terribly wrong. */
535 if (is_gimple_reg (orig))
540 /* We have a "copy" from something like a constant into a virtual
541 operand. Reject these. */
545 /* If ORIG flows in from an abnormal edge, it cannot be propagated. */
546 if (TREE_CODE (orig) == SSA_NAME
547 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (orig))
550 /* If DEST is an SSA_NAME that flows from an abnormal edge or if it
551 represents a hard register, then it cannot be replaced. */
552 if (TREE_CODE (dest) == SSA_NAME
553 && (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (dest)
554 || DECL_HARD_REGISTER (SSA_NAME_VAR (dest))))
557 /* Anything else is OK. */
561 /* Set the default definition for VAR to DEF. */
563 set_default_def (tree var, tree def)
565 var_ann_t ann = var_ann (var);
567 ann = create_var_ann (var);
568 ann->default_def = def;
571 /* Return the default definition for variable VAR, or NULL if none
574 default_def (tree var)
576 var_ann_t ann = var_ann (var);
577 return ann ? ann->default_def : NULL_TREE;
580 /* PHI nodes should contain only ssa_names and invariants. A test
581 for ssa_name is definitely simpler; don't let invalid contents
582 slip in in the meantime. */
585 phi_ssa_name_p (tree t)
587 if (TREE_CODE (t) == SSA_NAME)
589 #ifdef ENABLE_CHECKING
590 if (!is_gimple_min_invariant (t))
596 /* ----------------------------------------------------------------------- */
598 /* Return a block_stmt_iterator that points to beginning of basic
600 static inline block_stmt_iterator
601 bsi_start (basic_block bb)
603 block_stmt_iterator bsi;
605 bsi.tsi = tsi_start (bb->stmt_list);
608 #ifdef ENABLE_CHECKING
613 bsi.tsi.container = NULL;
619 /* Return a block statement iterator that points to the last label in
622 static inline block_stmt_iterator
623 bsi_after_labels (basic_block bb)
625 block_stmt_iterator bsi;
626 tree_stmt_iterator next;
632 #ifdef ENABLE_CHECKING
637 bsi.tsi.container = NULL;
641 bsi.tsi = tsi_start (bb->stmt_list);
642 if (tsi_end_p (bsi.tsi))
645 /* Ensure that there are some labels. The rationale is that we want
646 to insert after the bsi that is returned, and these insertions should
647 be placed at the start of the basic block. This would not work if the
648 first statement was not label; rather fail here than enable the user
649 proceed in wrong way. */
650 if (TREE_CODE (tsi_stmt (bsi.tsi)) != LABEL_EXPR)
656 while (!tsi_end_p (next)
657 && TREE_CODE (tsi_stmt (next)) == LABEL_EXPR)
666 /* Return a block statement iterator that points to the end of basic
668 static inline block_stmt_iterator
669 bsi_last (basic_block bb)
671 block_stmt_iterator bsi;
673 bsi.tsi = tsi_last (bb->stmt_list);
676 #ifdef ENABLE_CHECKING
681 bsi.tsi.container = NULL;
687 /* Return true if block statement iterator I has reached the end of
690 bsi_end_p (block_stmt_iterator i)
692 return tsi_end_p (i.tsi);
695 /* Modify block statement iterator I so that it is at the next
696 statement in the basic block. */
698 bsi_next (block_stmt_iterator *i)
703 /* Modify block statement iterator I so that it is at the previous
704 statement in the basic block. */
706 bsi_prev (block_stmt_iterator *i)
711 /* Return the statement that block statement iterator I is currently
714 bsi_stmt (block_stmt_iterator i)
716 return tsi_stmt (i.tsi);
719 /* Return a pointer to the statement that block statement iterator I
722 bsi_stmt_ptr (block_stmt_iterator i)
724 return tsi_stmt_ptr (i.tsi);
727 /* Return true if VAR may be aliased. */
729 may_be_aliased (tree var)
731 return (TREE_ADDRESSABLE (var)
732 || decl_function_context (var) != current_function_decl);
735 /* Return true if VAR is a clobbered by function calls. */
737 is_call_clobbered (tree var)
739 return needs_to_live_in_memory (var)
740 || bitmap_bit_p (call_clobbered_vars, var_ann (var)->uid);
743 /* Mark variable VAR as being clobbered by function calls. */
745 mark_call_clobbered (tree var)
747 var_ann_t ann = var_ann (var);
748 /* Call-clobbered variables need to live in memory. */
749 DECL_NEEDS_TO_LIVE_IN_MEMORY_INTERNAL (var) = 1;
750 bitmap_set_bit (call_clobbered_vars, ann->uid);
753 /* Mark variable VAR as being non-addressable. */
755 mark_non_addressable (tree var)
757 bitmap_clear_bit (call_clobbered_vars, var_ann (var)->uid);
758 DECL_NEEDS_TO_LIVE_IN_MEMORY_INTERNAL (var) = 0;
759 TREE_ADDRESSABLE (var) = 0;
762 /* Return the common annotation for T. Return NULL if the annotation
763 doesn't already exist. */
764 static inline tree_ann_t
767 return t->common.ann;
770 /* Return a common annotation for T. Create the constant annotation if it
772 static inline tree_ann_t
773 get_tree_ann (tree t)
775 tree_ann_t ann = tree_ann (t);
776 return (ann) ? ann : create_tree_ann (t);
779 #endif /* _TREE_FLOW_INLINE_H */