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_LOCUS (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 if (expr
== NULL_TREE
)
143 if (TREE_CODE (expr
) == COMPOUND_EXPR
)
144 expr
= TREE_OPERAND (expr
, 0);
146 if (EXPR_LOCUS (expr
) && EXPR_FILENAME (expr
))
147 return EXPR_FILENAME (expr
);
152 /* Mark statement T as modified. */
156 stmt_ann_t ann
= stmt_ann (t
);
158 ann
= create_stmt_ann (t
);
162 /* Mark statement T as unmodified. */
164 unmodify_stmt (tree t
)
166 stmt_ann_t ann
= stmt_ann (t
);
168 ann
= create_stmt_ann (t
);
172 /* Return true if T is marked as modified, false otherwise. */
174 stmt_modified_p (tree t
)
176 stmt_ann_t ann
= stmt_ann (t
);
178 /* Note that if the statement doesn't yet have an annotation, we consider it
179 modified. This will force the next call to get_stmt_operands to scan the
181 return ann
? ann
->modified
: true;
184 /* Return the definitions present in ANN, a statement annotation.
185 Return NULL if this annotation contains no definitions. */
186 static inline def_optype
187 get_def_ops (stmt_ann_t ann
)
189 return ann
? ann
->def_ops
: NULL
;
192 /* Return the uses present in ANN, a statement annotation.
193 Return NULL if this annotation contains no uses. */
194 static inline use_optype
195 get_use_ops (stmt_ann_t ann
)
197 return ann
? ann
->use_ops
: NULL
;
200 /* Return the virtual may-defs present in ANN, a statement
202 Return NULL if this annotation contains no virtual may-defs. */
203 static inline v_may_def_optype
204 get_v_may_def_ops (stmt_ann_t ann
)
206 return ann
? ann
->v_may_def_ops
: NULL
;
209 /* Return the virtual uses present in ANN, a statement annotation.
210 Return NULL if this annotation contains no virtual uses. */
211 static inline vuse_optype
212 get_vuse_ops (stmt_ann_t ann
)
214 return ann
? ann
->vuse_ops
: NULL
;
217 /* Return the virtual must-defs present in ANN, a statement
218 annotation. Return NULL if this annotation contains no must-defs.*/
219 static inline v_must_def_optype
220 get_v_must_def_ops (stmt_ann_t ann
)
222 return ann
? ann
->v_must_def_ops
: NULL
;
225 /* Return the tree pointer to by USE. */
227 get_use_from_ptr (use_operand_p use
)
232 /* Return the tree pointer to by DEF. */
234 get_def_from_ptr (def_operand_p def
)
239 /* Return a pointer to the tree that is at INDEX in the USES array. */
240 static inline use_operand_p
241 get_use_op_ptr (use_optype uses
, unsigned int index
)
243 #ifdef ENABLE_CHECKING
244 if (index
>= uses
->num_uses
)
247 return uses
->uses
[index
];
250 /* Return a def_operand_p pointer for element INDEX of DEFS. */
251 static inline def_operand_p
252 get_def_op_ptr (def_optype defs
, unsigned int index
)
254 #ifdef ENABLE_CHECKING
255 if (index
>= defs
->num_defs
)
258 return defs
->defs
[index
];
262 /* Return the def_operand_p that is the V_MAY_DEF_RESULT for the V_MAY_DEF
263 at INDEX in the V_MAY_DEFS array. */
264 static inline def_operand_p
265 get_v_may_def_result_ptr(v_may_def_optype v_may_defs
, unsigned int index
)
268 #ifdef ENABLE_CHECKING
269 if (index
>= v_may_defs
->num_v_may_defs
)
272 op
.def
= &(v_may_defs
->v_may_defs
[index
* 2]);
276 /* Return a use_operand_p that is the V_MAY_DEF_OP for the V_MAY_DEF at
277 INDEX in the V_MAY_DEFS array. */
278 static inline use_operand_p
279 get_v_may_def_op_ptr(v_may_def_optype v_may_defs
, unsigned int index
)
282 #ifdef ENABLE_CHECKING
283 if (index
>= v_may_defs
->num_v_may_defs
)
286 op
.use
= &(v_may_defs
->v_may_defs
[index
* 2 + 1]);
290 /* Return a use_operand_p that is at INDEX in the VUSES array. */
291 static inline use_operand_p
292 get_vuse_op_ptr(vuse_optype vuses
, unsigned int index
)
295 #ifdef ENABLE_CHECKING
296 if (index
>= vuses
->num_vuses
)
299 op
.use
= &(vuses
->vuses
[index
]);
303 /* Return a def_operand_p that is the V_MUST_DEF_OP for the
304 V_MUST_DEF at INDEX in the V_MUST_DEFS array. */
305 static inline def_operand_p
306 get_v_must_def_op_ptr (v_must_def_optype v_must_defs
, unsigned int index
)
309 #ifdef ENABLE_CHECKING
310 if (index
>= v_must_defs
->num_v_must_defs
)
313 op
.def
= &(v_must_defs
->v_must_defs
[index
]);
317 /* Return a def_operand_p pointer for the result of PHI. */
318 static inline def_operand_p
319 get_phi_result_ptr (tree phi
)
322 op
.def
= &(PHI_RESULT_TREE (phi
));
326 /* Return a use_operand_p pointer for argument I of phinode PHI. */
327 static inline use_operand_p
328 get_phi_arg_def_ptr (tree phi
, int i
)
331 op
.use
= &(PHI_ARG_DEF_TREE (phi
, i
));
335 /* Mark the beginning of changes to the SSA operands for STMT. */
337 start_ssa_stmt_operands (tree stmt ATTRIBUTE_UNUSED
)
339 #ifdef ENABLE_CHECKING
340 verify_start_operands (stmt
);
344 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
347 addresses_taken (tree stmt
)
349 stmt_ann_t ann
= stmt_ann (stmt
);
350 return ann
? ann
->addresses_taken
: NULL
;
353 /* Return the immediate uses of STMT, or NULL if this information is
356 get_immediate_uses (tree stmt
)
358 stmt_ann_t ann
= stmt_ann (stmt
);
359 return ann
? ann
->df
: NULL
;
362 /* Return the number of immediate uses present in the dataflow
363 information at DF. */
365 num_immediate_uses (dataflow_t df
)
372 imm
= df
->immediate_uses
;
374 return df
->uses
[1] ? 2 : 1;
376 return VARRAY_ACTIVE_SIZE (imm
) + 2;
379 /* Return the tree that is at NUM in the immediate use DF array. */
381 immediate_use (dataflow_t df
, int num
)
386 #ifdef ENABLE_CHECKING
387 if (num
>= num_immediate_uses (df
))
391 return df
->uses
[num
];
392 return VARRAY_TREE (df
->immediate_uses
, num
- 2);
395 /* Return the basic_block annotation for BB. */
396 static inline bb_ann_t
397 bb_ann (basic_block bb
)
399 return (bb_ann_t
)bb
->tree_annotations
;
402 /* Return the PHI nodes for basic block BB, or NULL if there are no
405 phi_nodes (basic_block bb
)
409 return bb_ann (bb
)->phi_nodes
;
412 /* Set list of phi nodes of a basic block BB to L. */
415 set_phi_nodes (basic_block bb
, tree l
)
419 bb_ann (bb
)->phi_nodes
= l
;
420 for (phi
= l
; phi
; phi
= PHI_CHAIN (phi
))
421 set_bb_for_stmt (phi
, bb
);
424 /* Return the phi index number for an edge. */
426 phi_arg_from_edge (tree phi
, edge e
)
429 #if defined ENABLE_CHECKING
430 if (!phi
|| TREE_CODE (phi
) != PHI_NODE
)
434 for (i
= 0; i
< PHI_NUM_ARGS (phi
); i
++)
435 if (PHI_ARG_EDGE (phi
, i
) == e
)
441 /* ----------------------------------------------------------------------- */
443 /* Return true if T is an executable statement. */
445 is_exec_stmt (tree t
)
447 return (t
&& !IS_EMPTY_STMT (t
) && t
!= error_mark_node
);
451 /* Return true if this stmt can be the target of a control transfer stmt such
454 is_label_stmt (tree t
)
457 switch (TREE_CODE (t
))
461 case CASE_LABEL_EXPR
:
469 /* Return true if we may propagate ORIG into DEST, false otherwise. */
471 may_propagate_copy (tree dest
, tree orig
)
473 /* FIXME. GIMPLE is allowing pointer assignments and comparisons of
474 pointers that have different alias sets. This means that these
475 pointers will have different memory tags associated to them.
477 If we allow copy propagation in these cases, statements de-referencing
478 the new pointer will now have a reference to a different memory tag
479 with potentially incorrect SSA information.
481 This was showing up in libjava/java/util/zip/ZipFile.java with code
484 struct java.io.BufferedInputStream *T.660;
485 struct java.io.BufferedInputStream *T.647;
486 struct java.io.InputStream *is;
487 struct java.io.InputStream *is.662;
490 is = T.660; <-- This ought to be type-casted
493 Also, f/name.c exposed a similar problem with a COND_EXPR predicate
494 that was causing DOM to generate and equivalence with two pointers of
495 alias-incompatible types:
497 struct _ffename_space *n;
506 I think that GIMPLE should emit the appropriate type-casts. For the
507 time being, blocking copy-propagation in these cases is the safe thing
509 if (TREE_CODE (dest
) == SSA_NAME
510 && TREE_CODE (orig
) == SSA_NAME
511 && POINTER_TYPE_P (TREE_TYPE (dest
))
512 && POINTER_TYPE_P (TREE_TYPE (orig
)))
514 tree mt_dest
= var_ann (SSA_NAME_VAR (dest
))->type_mem_tag
;
515 tree mt_orig
= var_ann (SSA_NAME_VAR (orig
))->type_mem_tag
;
516 if (mt_dest
&& mt_orig
&& mt_dest
!= mt_orig
)
520 /* If the destination is a SSA_NAME for a virtual operand, then we have
521 some special cases to handle. */
522 if (TREE_CODE (dest
) == SSA_NAME
&& !is_gimple_reg (dest
))
524 /* If both operands are SSA_NAMEs referring to virtual operands, then
525 we can always propagate. */
526 if (TREE_CODE (orig
) == SSA_NAME
)
528 if (!is_gimple_reg (orig
))
531 #ifdef ENABLE_CHECKING
532 /* If we have one real and one virtual operand, then something has
533 gone terribly wrong. */
534 if (is_gimple_reg (orig
))
539 /* We have a "copy" from something like a constant into a virtual
540 operand. Reject these. */
544 return (!SSA_NAME_OCCURS_IN_ABNORMAL_PHI (dest
)
545 && (TREE_CODE (orig
) != SSA_NAME
546 || !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (orig
))
547 && !DECL_HARD_REGISTER (SSA_NAME_VAR (dest
)));
550 /* Set the default definition for VAR to DEF. */
552 set_default_def (tree var
, tree def
)
554 var_ann_t ann
= var_ann (var
);
556 ann
= create_var_ann (var
);
557 ann
->default_def
= def
;
560 /* Return the default definition for variable VAR, or NULL if none
563 default_def (tree var
)
565 var_ann_t ann
= var_ann (var
);
566 return ann
? ann
->default_def
: NULL_TREE
;
569 /* PHI nodes should contain only ssa_names and invariants. A test
570 for ssa_name is definitely simpler; don't let invalid contents
571 slip in in the meantime. */
574 phi_ssa_name_p (tree t
)
576 if (TREE_CODE (t
) == SSA_NAME
)
578 #ifdef ENABLE_CHECKING
579 if (!is_gimple_min_invariant (t
))
585 /* ----------------------------------------------------------------------- */
587 /* Return a block_stmt_iterator that points to beginning of basic
589 static inline block_stmt_iterator
590 bsi_start (basic_block bb
)
592 block_stmt_iterator bsi
;
594 bsi
.tsi
= tsi_start (bb
->stmt_list
);
597 #ifdef ENABLE_CHECKING
602 bsi
.tsi
.container
= NULL
;
608 /* Return a block statement iterator that points to the last label in
611 static inline block_stmt_iterator
612 bsi_after_labels (basic_block bb
)
614 block_stmt_iterator bsi
;
615 tree_stmt_iterator next
;
621 #ifdef ENABLE_CHECKING
626 bsi
.tsi
.container
= NULL
;
630 bsi
.tsi
= tsi_start (bb
->stmt_list
);
631 if (tsi_end_p (bsi
.tsi
))
634 /* Ensure that there are some labels. The rationale is that we want
635 to insert after the bsi that is returned, and these insertions should
636 be placed at the start of the basic block. This would not work if the
637 first statement was not label; rather fail here than enable the user
638 proceed in wrong way. */
639 if (TREE_CODE (tsi_stmt (bsi
.tsi
)) != LABEL_EXPR
)
645 while (!tsi_end_p (next
)
646 && TREE_CODE (tsi_stmt (next
)) == LABEL_EXPR
)
655 /* Return a block statement iterator that points to the end of basic
657 static inline block_stmt_iterator
658 bsi_last (basic_block bb
)
660 block_stmt_iterator bsi
;
662 bsi
.tsi
= tsi_last (bb
->stmt_list
);
665 #ifdef ENABLE_CHECKING
670 bsi
.tsi
.container
= NULL
;
676 /* Return true if block statement iterator I has reached the end of
679 bsi_end_p (block_stmt_iterator i
)
681 return tsi_end_p (i
.tsi
);
684 /* Modify block statement iterator I so that it is at the next
685 statement in the basic block. */
687 bsi_next (block_stmt_iterator
*i
)
692 /* Modify block statement iterator I so that it is at the previous
693 statement in the basic block. */
695 bsi_prev (block_stmt_iterator
*i
)
700 /* Return the statement that block statement iterator I is currently
703 bsi_stmt (block_stmt_iterator i
)
705 return tsi_stmt (i
.tsi
);
708 /* Return a pointer to the statement that block statement iterator I
711 bsi_stmt_ptr (block_stmt_iterator i
)
713 return tsi_stmt_ptr (i
.tsi
);
716 /* Return true if VAR may be aliased. */
718 may_be_aliased (tree var
)
720 return (TREE_ADDRESSABLE (var
)
721 || decl_function_context (var
) != current_function_decl
);
724 /* Return true if VAR is a clobbered by function calls. */
726 is_call_clobbered (tree var
)
728 return needs_to_live_in_memory (var
)
729 || bitmap_bit_p (call_clobbered_vars
, var_ann (var
)->uid
);
732 /* Mark variable VAR as being clobbered by function calls. */
734 mark_call_clobbered (tree var
)
736 var_ann_t ann
= var_ann (var
);
737 /* Call-clobbered variables need to live in memory. */
738 DECL_NEEDS_TO_LIVE_IN_MEMORY_INTERNAL (var
) = 1;
739 bitmap_set_bit (call_clobbered_vars
, ann
->uid
);
742 /* Mark variable VAR as being non-addressable. */
744 mark_non_addressable (tree var
)
746 bitmap_clear_bit (call_clobbered_vars
, var_ann (var
)->uid
);
747 DECL_NEEDS_TO_LIVE_IN_MEMORY_INTERNAL (var
) = 0;
748 TREE_ADDRESSABLE (var
) = 0;
751 /* Return the common annotation for T. Return NULL if the annotation
752 doesn't already exist. */
753 static inline tree_ann_t
756 return t
->common
.ann
;
759 /* Return a common annotation for T. Create the constant annotation if it
761 static inline tree_ann_t
762 get_tree_ann (tree t
)
764 tree_ann_t ann
= tree_ann (t
);
765 return (ann
) ? ann
: create_tree_ann (t
);
768 #endif /* _TREE_FLOW_INLINE_H */