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 static inline var_ann_t
31 #if defined ENABLE_CHECKING
35 && t
->common
.ann
->common
.type
!= VAR_ANN
))
39 return (var_ann_t
) t
->common
.ann
;
42 static inline var_ann_t
43 get_var_ann (tree var
)
45 var_ann_t ann
= var_ann (var
);
46 return (ann
) ? ann
: create_var_ann (var
);
49 static inline stmt_ann_t
52 #if defined ENABLE_CHECKING
53 if (!is_gimple_stmt (t
) && !is_essa_node (t
))
57 return (stmt_ann_t
) t
->common
.ann
;
60 static inline stmt_ann_t
61 get_stmt_ann (tree stmt
)
63 stmt_ann_t ann
= stmt_ann (stmt
);
64 return (ann
) ? ann
: create_stmt_ann (stmt
);
67 static inline ssa_name_ann_t
70 #if defined ENABLE_CHECKING
72 || TREE_CODE (t
) != SSA_NAME
74 && t
->common
.ann
->common
.type
!= SSA_NAME_ANN
))
78 return (ssa_name_ann_t
) t
->common
.ann
;
81 static inline ssa_name_ann_t
82 get_ssa_name_ann (tree var
)
84 ssa_name_ann_t ann
= ssa_name_ann (var
);
85 return (ann
) ? ann
: create_ssa_name_ann (var
);
89 static inline enum tree_ann_type
90 ann_type (tree_ann ann
)
92 return ann
->common
.type
;
95 static inline basic_block
98 stmt_ann_t ann
= stmt_ann (t
);
99 return ann
? ann
->bb
: NULL
;
102 static inline varray_type
103 may_aliases (tree var
)
105 var_ann_t ann
= var_ann (var
);
106 return ann
? ann
->may_aliases
: NULL
;
110 has_hidden_use (tree var
)
112 var_ann_t ann
= var_ann (var
);
113 return ann
? ann
->has_hidden_use
: false;
117 set_has_hidden_use (tree var
)
119 var_ann_t ann
= var_ann (var
);
121 ann
= create_var_ann (var
);
122 ann
->has_hidden_use
= 1;
126 get_lineno (tree expr
)
128 if (expr
== NULL_TREE
)
131 if (TREE_CODE (expr
) == COMPOUND_EXPR
)
132 expr
= TREE_OPERAND (expr
, 0);
134 if (! EXPR_LOCUS (expr
))
137 return EXPR_LINENO (expr
);
140 static inline const char *
141 get_filename (tree expr
)
143 if (expr
== NULL_TREE
)
146 if (TREE_CODE (expr
) == COMPOUND_EXPR
)
147 expr
= TREE_OPERAND (expr
, 0);
149 if (EXPR_LOCUS (expr
) && EXPR_FILENAME (expr
))
150 return EXPR_FILENAME (expr
);
158 stmt_ann_t ann
= stmt_ann (t
);
160 ann
= create_stmt_ann (t
);
165 unmodify_stmt (tree t
)
167 stmt_ann_t ann
= stmt_ann (t
);
169 ann
= create_stmt_ann (t
);
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 static inline def_optype
185 get_def_ops (stmt_ann_t ann
)
187 return ann
? ann
->def_ops
: NULL
;
190 static inline use_optype
191 get_use_ops (stmt_ann_t ann
)
193 return ann
? ann
->use_ops
: NULL
;
196 static inline vdef_optype
197 get_vdef_ops (stmt_ann_t ann
)
199 return ann
? ann
->vdef_ops
: NULL
;
202 static inline vuse_optype
203 get_vuse_ops (stmt_ann_t ann
)
205 return ann
? ann
->vuse_ops
: NULL
;
209 get_use_op_ptr (use_optype uses
, unsigned int index
)
211 #ifdef ENABLE_CHECKING
212 if (index
>= uses
->num_uses
)
215 return uses
->uses
[index
];
219 get_def_op_ptr (def_optype defs
, unsigned int index
)
221 #ifdef ENABLE_CHECKING
222 if (index
>= defs
->num_defs
)
225 return defs
->defs
[index
];
229 get_vdef_result_ptr(vdef_optype vdefs
, unsigned int index
)
231 #ifdef ENABLE_CHECKING
232 if (index
>= vdefs
->num_vdefs
)
235 return &(vdefs
->vdefs
[index
* 2]);
239 get_vdef_op_ptr(vdef_optype vdefs
, unsigned int index
)
241 #ifdef ENABLE_CHECKING
242 if (index
>= vdefs
->num_vdefs
)
245 return &(vdefs
->vdefs
[index
* 2 + 1]);
249 get_vuse_op_ptr(vuse_optype vuses
, unsigned int index
)
251 #ifdef ENABLE_CHECKING
252 if (index
>= vuses
->num_vuses
)
255 return &(vuses
->vuses
[index
]);
259 start_ssa_stmt_operands (tree stmt ATTRIBUTE_UNUSED
)
261 #ifdef ENABLE_CHECKING
262 verify_start_operands (stmt
);
267 addresses_taken (tree stmt
)
269 stmt_ann_t ann
= stmt_ann (stmt
);
270 return ann
? ann
->addresses_taken
: NULL
;
274 get_immediate_uses (tree stmt
)
276 stmt_ann_t ann
= stmt_ann (stmt
);
277 return ann
? ann
->df
: NULL
;
281 num_immediate_uses (dataflow_t df
)
288 imm
= df
->immediate_uses
;
290 return df
->uses
[1] ? 2 : 1;
292 return VARRAY_ACTIVE_SIZE (imm
) + 2;
296 immediate_use (dataflow_t df
, int num
)
298 #ifdef ENABLE_CHECKING
299 if (num
>= num_immediate_uses (df
))
303 return df
->uses
[num
];
304 return VARRAY_TREE (df
->immediate_uses
, num
- 2);
307 static inline bb_ann_t
308 bb_ann (basic_block bb
)
310 return (bb_ann_t
)bb
->tree_annotations
;
314 phi_nodes (basic_block bb
)
318 return bb_ann (bb
)->phi_nodes
;
321 /* Set list of phi nodes of a basic block BB to L. */
324 set_phi_nodes (basic_block bb
, tree l
)
328 bb_ann (bb
)->phi_nodes
= l
;
329 for (phi
= l
; phi
; phi
= TREE_CHAIN (phi
))
330 set_bb_for_stmt (phi
, bb
);
333 /* Return the phi index number for an edge. */
335 phi_arg_from_edge (tree phi
, edge e
)
338 #if defined ENABLE_CHECKING
339 if (!phi
|| TREE_CODE (phi
) != PHI_NODE
)
343 for (i
= 0; i
< PHI_NUM_ARGS (phi
); i
++)
344 if (PHI_ARG_EDGE (phi
, i
) == e
)
351 /* Return the phi argument number for an edge. */
352 static inline struct phi_arg_d
*
353 phi_element_for_edge (tree phi
, edge e
)
357 i
= phi_arg_from_edge (phi
, e
);
359 return &(PHI_ARG_ELT (phi
, i
));
361 return (struct phi_arg_d
*)NULL
;
364 /* ----------------------------------------------------------------------- */
367 is_exec_stmt (tree t
)
369 return (t
&& !IS_EMPTY_STMT (t
) && t
!= error_mark_node
);
373 /* Return true if this stmt can be the target of a control transfer stmt such
376 is_label_stmt (tree t
)
379 switch (TREE_CODE (t
))
383 case CASE_LABEL_EXPR
:
392 may_propagate_copy (tree dest
, tree orig
)
394 /* FIXME. GIMPLE is allowing pointer assignments and comparisons of
395 pointers that have different alias sets. This means that these
396 pointers will have different memory tags associated to them.
398 If we allow copy propagation in these cases, statements de-referencing
399 the new pointer will now have a reference to a different memory tag
400 with potentially incorrect SSA information.
402 This was showing up in libjava/java/util/zip/ZipFile.java with code
405 struct java.io.BufferedInputStream *T.660;
406 struct java.io.BufferedInputStream *T.647;
407 struct java.io.InputStream *is;
408 struct java.io.InputStream *is.662;
411 is = T.660; <-- This ought to be type-casted
414 Also, f/name.c exposed a similar problem with a COND_EXPR predicate
415 that was causing DOM to generate and equivalence with two pointers of
416 alias-incompatible types:
418 struct _ffename_space *n;
427 I think that GIMPLE should emit the appropriate type-casts. For the
428 time being, blocking copy-propagation in these cases is the safe thing
430 if (TREE_CODE (dest
) == SSA_NAME
431 && TREE_CODE (orig
) == SSA_NAME
432 && POINTER_TYPE_P (TREE_TYPE (dest
))
433 && POINTER_TYPE_P (TREE_TYPE (orig
)))
435 tree mt_dest
= var_ann (SSA_NAME_VAR (dest
))->type_mem_tag
;
436 tree mt_orig
= var_ann (SSA_NAME_VAR (orig
))->type_mem_tag
;
437 if (mt_dest
&& mt_orig
&& mt_dest
!= mt_orig
)
441 /* If the destination is a SSA_NAME for a virtual operand, then we have
442 some special cases to handle. */
443 if (TREE_CODE (dest
) == SSA_NAME
&& !is_gimple_reg (dest
))
445 /* If both operands are SSA_NAMEs referring to virtual operands, then
446 we can always propagate. */
447 if (TREE_CODE (orig
) == SSA_NAME
)
449 if (!is_gimple_reg (orig
))
452 #ifdef ENABLE_CHECKING
453 /* If we have one real and one virtual operand, then something has
454 gone terribly wrong. */
455 if (is_gimple_reg (orig
))
460 /* We have a "copy" from something like a constant into a virtual
461 operand. Reject these. */
465 return (!SSA_NAME_OCCURS_IN_ABNORMAL_PHI (dest
)
466 && (TREE_CODE (orig
) != SSA_NAME
467 || !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (orig
))
468 && !DECL_HARD_REGISTER (SSA_NAME_VAR (dest
)));
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
;
481 default_def (tree var
)
483 var_ann_t ann
= var_ann (var
);
484 return ann
? ann
->default_def
: NULL_TREE
;
487 /* PHI nodes should contain only ssa_names and invariants. A test
488 for ssa_name is definitely simpler; don't let invalid contents
489 slip in in the meantime. */
492 phi_ssa_name_p (tree t
)
494 if (TREE_CODE (t
) == SSA_NAME
)
496 #ifdef ENABLE_CHECKING
497 if (!is_gimple_min_invariant (t
))
503 /* ----------------------------------------------------------------------- */
505 static inline block_stmt_iterator
506 bsi_start (basic_block bb
)
508 block_stmt_iterator bsi
;
510 bsi
.tsi
= tsi_start (bb
->stmt_list
);
513 #ifdef ENABLE_CHECKING
518 bsi
.tsi
.container
= NULL
;
524 static inline block_stmt_iterator
525 bsi_last (basic_block bb
)
527 block_stmt_iterator bsi
;
529 bsi
.tsi
= tsi_last (bb
->stmt_list
);
532 #ifdef ENABLE_CHECKING
537 bsi
.tsi
.container
= NULL
;
544 bsi_end_p (block_stmt_iterator i
)
546 return tsi_end_p (i
.tsi
);
550 bsi_next (block_stmt_iterator
*i
)
556 bsi_prev (block_stmt_iterator
*i
)
562 bsi_stmt (block_stmt_iterator i
)
564 return tsi_stmt (i
.tsi
);
568 bsi_stmt_ptr (block_stmt_iterator i
)
570 return tsi_stmt_ptr (i
.tsi
);
574 may_be_aliased (tree var
)
576 return (TREE_ADDRESSABLE (var
)
577 || decl_function_context (var
) != current_function_decl
);
581 is_call_clobbered (tree var
)
583 return needs_to_live_in_memory (var
)
584 || bitmap_bit_p (call_clobbered_vars
, var_ann (var
)->uid
);
588 mark_call_clobbered (tree var
)
590 var_ann_t ann
= var_ann (var
);
591 /* Call-clobbered variables need to live in memory. */
592 DECL_NEEDS_TO_LIVE_IN_MEMORY_INTERNAL (var
) = 1;
593 bitmap_set_bit (call_clobbered_vars
, ann
->uid
);
597 mark_non_addressable (tree var
)
599 bitmap_clear_bit (call_clobbered_vars
, var_ann (var
)->uid
);
600 DECL_NEEDS_TO_LIVE_IN_MEMORY_INTERNAL (var
) = 0;
601 TREE_ADDRESSABLE (var
) = 0;
604 #endif /* _TREE_FLOW_INLINE_H */