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);
50 static inline cst_ann_t
53 #if defined ENABLE_CHECKING
54 if (TREE_CODE_CLASS (TREE_CODE (t)) != 'c'
56 && t->common.ann->common.type != CST_ANN))
60 return (cst_ann_t) t->common.ann;
63 static inline cst_ann_t
64 get_cst_ann (tree var)
66 cst_ann_t ann = cst_ann (var);
67 return (ann) ? ann : create_cst_ann (var);
70 static inline expr_ann_t
73 #if defined ENABLE_CHECKING
76 && t->common.ann->common.type != EXPR_ANN))
80 return (expr_ann_t) t->common.ann;
83 static inline expr_ann_t
84 get_expr_ann (tree var)
86 expr_ann_t ann = expr_ann (var);
87 return (ann) ? ann : create_expr_ann (var);
90 static inline stmt_ann_t
93 #if defined ENABLE_CHECKING
94 if (!is_gimple_stmt (t))
98 return (stmt_ann_t) t->common.ann;
101 static inline stmt_ann_t
102 get_stmt_ann (tree stmt)
104 stmt_ann_t ann = stmt_ann (stmt);
105 return (ann) ? ann : create_stmt_ann (stmt);
109 static inline enum tree_ann_type
110 ann_type (tree_ann ann)
112 return ann->common.type;
115 static inline basic_block
118 stmt_ann_t ann = stmt_ann (t);
119 return ann ? ann->bb : NULL;
122 static inline varray_type
123 may_aliases (tree var)
125 var_ann_t ann = var_ann (var);
126 return ann ? ann->may_aliases : NULL;
130 has_hidden_use (tree var)
132 var_ann_t ann = var_ann (var);
133 return ann ? ann->has_hidden_use : false;
137 set_has_hidden_use (tree var)
139 var_ann_t ann = var_ann (var);
141 ann = create_var_ann (var);
142 ann->has_hidden_use = 1;
146 get_lineno (tree expr)
148 if (expr == NULL_TREE)
151 if (TREE_CODE (expr) == COMPOUND_EXPR)
152 expr = TREE_OPERAND (expr, 0);
154 if (! EXPR_LOCUS (expr))
157 return EXPR_LINENO (expr);
160 static inline const char *
161 get_filename (tree expr)
163 if (expr == NULL_TREE)
166 if (TREE_CODE (expr) == COMPOUND_EXPR)
167 expr = TREE_OPERAND (expr, 0);
169 if (EXPR_LOCUS (expr) && EXPR_FILENAME (expr))
170 return EXPR_FILENAME (expr);
178 stmt_ann_t ann = stmt_ann (t);
180 ann = create_stmt_ann (t);
185 unmodify_stmt (tree t)
187 stmt_ann_t ann = stmt_ann (t);
189 ann = create_stmt_ann (t);
194 stmt_modified_p (tree t)
196 stmt_ann_t ann = stmt_ann (t);
198 /* Note that if the statement doesn't yet have an annotation, we consider it
199 modified. This will force the next call to get_stmt_operands to scan the
201 return ann ? ann->modified : true;
204 static inline def_optype
205 get_def_ops (stmt_ann_t ann)
207 return ann ? ann->def_ops : NULL;
210 static inline use_optype
211 get_use_ops (stmt_ann_t ann)
213 return ann ? ann->use_ops : NULL;
216 static inline v_may_def_optype
217 get_v_may_def_ops (stmt_ann_t ann)
219 return ann ? ann->v_may_def_ops : NULL;
222 static inline vuse_optype
223 get_vuse_ops (stmt_ann_t ann)
225 return ann ? ann->vuse_ops : NULL;
228 static inline v_must_def_optype
229 get_v_must_def_ops (stmt_ann_t ann)
231 return ann ? ann->v_must_def_ops : NULL;
235 get_use_op_ptr (use_optype uses, unsigned int index)
237 #ifdef ENABLE_CHECKING
238 if (index >= uses->num_uses)
241 return uses->uses[index];
245 get_def_op_ptr (def_optype defs, unsigned int index)
247 #ifdef ENABLE_CHECKING
248 if (index >= defs->num_defs)
251 return defs->defs[index];
255 get_v_may_def_result_ptr(v_may_def_optype v_may_defs, unsigned int index)
257 #ifdef ENABLE_CHECKING
258 if (index >= v_may_defs->num_v_may_defs)
261 return &(v_may_defs->v_may_defs[index * 2]);
265 get_v_may_def_op_ptr(v_may_def_optype v_may_defs, unsigned int index)
267 #ifdef ENABLE_CHECKING
268 if (index >= v_may_defs->num_v_may_defs)
271 return &(v_may_defs->v_may_defs[index * 2 + 1]);
275 get_vuse_op_ptr(vuse_optype vuses, unsigned int index)
277 #ifdef ENABLE_CHECKING
278 if (index >= vuses->num_vuses)
281 return &(vuses->vuses[index]);
285 get_v_must_def_op_ptr (v_must_def_optype v_must_defs, unsigned int index)
287 #ifdef ENABLE_CHECKING
288 if (index >= v_must_defs->num_v_must_defs)
291 return &(v_must_defs->v_must_defs[index]);
295 start_ssa_stmt_operands (tree stmt ATTRIBUTE_UNUSED)
297 #ifdef ENABLE_CHECKING
298 verify_start_operands (stmt);
303 addresses_taken (tree stmt)
305 stmt_ann_t ann = stmt_ann (stmt);
306 return ann ? ann->addresses_taken : NULL;
310 get_immediate_uses (tree stmt)
312 stmt_ann_t ann = stmt_ann (stmt);
313 return ann ? ann->df : NULL;
317 num_immediate_uses (dataflow_t df)
324 imm = df->immediate_uses;
326 return df->uses[1] ? 2 : 1;
328 return VARRAY_ACTIVE_SIZE (imm) + 2;
332 immediate_use (dataflow_t df, int num)
337 #ifdef ENABLE_CHECKING
338 if (num >= num_immediate_uses (df))
342 return df->uses[num];
343 return VARRAY_TREE (df->immediate_uses, num - 2);
346 static inline bb_ann_t
347 bb_ann (basic_block bb)
349 return (bb_ann_t)bb->tree_annotations;
353 phi_nodes (basic_block bb)
357 return bb_ann (bb)->phi_nodes;
360 /* Set list of phi nodes of a basic block BB to L. */
363 set_phi_nodes (basic_block bb, tree l)
367 bb_ann (bb)->phi_nodes = l;
368 for (phi = l; phi; phi = TREE_CHAIN (phi))
369 set_bb_for_stmt (phi, bb);
372 /* Return the phi index number for an edge. */
374 phi_arg_from_edge (tree phi, edge e)
377 #if defined ENABLE_CHECKING
378 if (!phi || TREE_CODE (phi) != PHI_NODE)
382 for (i = 0; i < PHI_NUM_ARGS (phi); i++)
383 if (PHI_ARG_EDGE (phi, i) == e)
390 /* Return the phi argument number for an edge. */
391 static inline struct phi_arg_d *
392 phi_element_for_edge (tree phi, edge e)
396 i = phi_arg_from_edge (phi, e);
398 return &(PHI_ARG_ELT (phi, i));
400 return (struct phi_arg_d *)NULL;
403 /* ----------------------------------------------------------------------- */
406 is_exec_stmt (tree t)
408 return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
412 /* Return true if this stmt can be the target of a control transfer stmt such
415 is_label_stmt (tree t)
418 switch (TREE_CODE (t))
422 case CASE_LABEL_EXPR:
431 may_propagate_copy (tree dest, tree orig)
433 /* FIXME. GIMPLE is allowing pointer assignments and comparisons of
434 pointers that have different alias sets. This means that these
435 pointers will have different memory tags associated to them.
437 If we allow copy propagation in these cases, statements de-referencing
438 the new pointer will now have a reference to a different memory tag
439 with potentially incorrect SSA information.
441 This was showing up in libjava/java/util/zip/ZipFile.java with code
444 struct java.io.BufferedInputStream *T.660;
445 struct java.io.BufferedInputStream *T.647;
446 struct java.io.InputStream *is;
447 struct java.io.InputStream *is.662;
450 is = T.660; <-- This ought to be type-casted
453 Also, f/name.c exposed a similar problem with a COND_EXPR predicate
454 that was causing DOM to generate and equivalence with two pointers of
455 alias-incompatible types:
457 struct _ffename_space *n;
466 I think that GIMPLE should emit the appropriate type-casts. For the
467 time being, blocking copy-propagation in these cases is the safe thing
469 if (TREE_CODE (dest) == SSA_NAME
470 && TREE_CODE (orig) == SSA_NAME
471 && POINTER_TYPE_P (TREE_TYPE (dest))
472 && POINTER_TYPE_P (TREE_TYPE (orig)))
474 tree mt_dest = var_ann (SSA_NAME_VAR (dest))->type_mem_tag;
475 tree mt_orig = var_ann (SSA_NAME_VAR (orig))->type_mem_tag;
476 if (mt_dest && mt_orig && mt_dest != mt_orig)
480 /* If the destination is a SSA_NAME for a virtual operand, then we have
481 some special cases to handle. */
482 if (TREE_CODE (dest) == SSA_NAME && !is_gimple_reg (dest))
484 /* If both operands are SSA_NAMEs referring to virtual operands, then
485 we can always propagate. */
486 if (TREE_CODE (orig) == SSA_NAME)
488 if (!is_gimple_reg (orig))
491 #ifdef ENABLE_CHECKING
492 /* If we have one real and one virtual operand, then something has
493 gone terribly wrong. */
494 if (is_gimple_reg (orig))
499 /* We have a "copy" from something like a constant into a virtual
500 operand. Reject these. */
504 return (!SSA_NAME_OCCURS_IN_ABNORMAL_PHI (dest)
505 && (TREE_CODE (orig) != SSA_NAME
506 || !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (orig))
507 && !DECL_HARD_REGISTER (SSA_NAME_VAR (dest)));
511 set_default_def (tree var, tree def)
513 var_ann_t ann = var_ann (var);
515 ann = create_var_ann (var);
516 ann->default_def = def;
520 default_def (tree var)
522 var_ann_t ann = var_ann (var);
523 return ann ? ann->default_def : NULL_TREE;
526 /* PHI nodes should contain only ssa_names and invariants. A test
527 for ssa_name is definitely simpler; don't let invalid contents
528 slip in in the meantime. */
531 phi_ssa_name_p (tree t)
533 if (TREE_CODE (t) == SSA_NAME)
535 #ifdef ENABLE_CHECKING
536 if (!is_gimple_min_invariant (t))
542 /* ----------------------------------------------------------------------- */
544 static inline block_stmt_iterator
545 bsi_start (basic_block bb)
547 block_stmt_iterator bsi;
549 bsi.tsi = tsi_start (bb->stmt_list);
552 #ifdef ENABLE_CHECKING
557 bsi.tsi.container = NULL;
563 static inline block_stmt_iterator
564 bsi_last (basic_block bb)
566 block_stmt_iterator bsi;
568 bsi.tsi = tsi_last (bb->stmt_list);
571 #ifdef ENABLE_CHECKING
576 bsi.tsi.container = NULL;
583 bsi_end_p (block_stmt_iterator i)
585 return tsi_end_p (i.tsi);
589 bsi_next (block_stmt_iterator *i)
595 bsi_prev (block_stmt_iterator *i)
601 bsi_stmt (block_stmt_iterator i)
603 return tsi_stmt (i.tsi);
607 bsi_stmt_ptr (block_stmt_iterator i)
609 return tsi_stmt_ptr (i.tsi);
613 may_be_aliased (tree var)
615 return (TREE_ADDRESSABLE (var)
616 || decl_function_context (var) != current_function_decl);
620 is_call_clobbered (tree var)
622 return needs_to_live_in_memory (var)
623 || bitmap_bit_p (call_clobbered_vars, var_ann (var)->uid);
627 mark_call_clobbered (tree var)
629 var_ann_t ann = var_ann (var);
630 /* Call-clobbered variables need to live in memory. */
631 DECL_NEEDS_TO_LIVE_IN_MEMORY_INTERNAL (var) = 1;
632 bitmap_set_bit (call_clobbered_vars, ann->uid);
636 mark_non_addressable (tree var)
638 bitmap_clear_bit (call_clobbered_vars, var_ann (var)->uid);
639 DECL_NEEDS_TO_LIVE_IN_MEMORY_INTERNAL (var) = 0;
640 TREE_ADDRESSABLE (var) = 0;
643 #endif /* _TREE_FLOW_INLINE_H */