PR other/16240
[official-gcc.git] / gcc / tree-flow-inline.h
blob722259d3970d3a6af59d6abed56dcf8519bf590a
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)
10 any later version.
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
31 var_ann (tree t)
33 #if defined ENABLE_CHECKING
34 if (t == NULL_TREE
35 || !DECL_P (t)
36 || (t->common.ann
37 && t->common.ann->common.type != VAR_ANN))
38 abort ();
39 #endif
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
56 stmt_ann (tree t)
58 #if defined ENABLE_CHECKING
59 if (!is_gimple_stmt (t))
60 abort ();
61 #endif
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
85 bb_for_stmt (tree t)
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
92 no may aliases. */
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. */
101 static inline bool
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. */
109 static inline void
110 set_has_hidden_use (tree var)
112 var_ann_t ann = var_ann (var);
113 if (ann == NULL)
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. */
120 static inline int
121 get_lineno (tree expr)
123 if (expr == NULL_TREE)
124 return -1;
126 if (TREE_CODE (expr) == COMPOUND_EXPR)
127 expr = TREE_OPERAND (expr, 0);
129 if (! EXPR_LOCUS (expr))
130 return -1;
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)
141 return "???";
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);
148 else
149 return "???";
152 /* Mark statement T as modified. */
153 static inline void
154 modify_stmt (tree t)
156 stmt_ann_t ann = stmt_ann (t);
157 if (ann == NULL)
158 ann = create_stmt_ann (t);
159 ann->modified = 1;
162 /* Mark statement T as unmodified. */
163 static inline void
164 unmodify_stmt (tree t)
166 stmt_ann_t ann = stmt_ann (t);
167 if (ann == NULL)
168 ann = create_stmt_ann (t);
169 ann->modified = 0;
172 /* Return true if T is marked as modified, false otherwise. */
173 static inline bool
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
180 statement. */
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
201 annotation.
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. */
226 static inline tree
227 get_use_from_ptr (use_operand_p use)
229 return *(use.use);
232 /* Return the tree pointer to by DEF. */
233 static inline tree
234 get_def_from_ptr (def_operand_p def)
236 return *(def.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)
245 abort();
246 #endif
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)
256 abort();
257 #endif
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)
267 def_operand_p op;
268 #ifdef ENABLE_CHECKING
269 if (index >= v_may_defs->num_v_may_defs)
270 abort();
271 #endif
272 op.def = &(v_may_defs->v_may_defs[index * 2]);
273 return op;
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)
281 use_operand_p op;
282 #ifdef ENABLE_CHECKING
283 if (index >= v_may_defs->num_v_may_defs)
284 abort();
285 #endif
286 op.use = &(v_may_defs->v_may_defs[index * 2 + 1]);
287 return op;
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)
294 use_operand_p op;
295 #ifdef ENABLE_CHECKING
296 if (index >= vuses->num_vuses)
297 abort();
298 #endif
299 op.use = &(vuses->vuses[index]);
300 return op;
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)
308 def_operand_p op;
309 #ifdef ENABLE_CHECKING
310 if (index >= v_must_defs->num_v_must_defs)
311 abort();
312 #endif
313 op.def = &(v_must_defs->v_must_defs[index]);
314 return op;
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)
321 def_operand_p op;
322 op.def = &(PHI_RESULT_TREE (phi));
323 return op;
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)
330 use_operand_p op;
331 op.use = &(PHI_ARG_DEF_TREE (phi, i));
332 return op;
335 /* Mark the beginning of changes to the SSA operands for STMT. */
336 static inline void
337 start_ssa_stmt_operands (tree stmt ATTRIBUTE_UNUSED)
339 #ifdef ENABLE_CHECKING
340 verify_start_operands (stmt);
341 #endif
344 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
345 no addresses. */
346 static inline bitmap
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
354 not computed. */
355 static dataflow_t
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. */
364 static inline int
365 num_immediate_uses (dataflow_t df)
367 varray_type imm;
369 if (!df)
370 return 0;
372 imm = df->immediate_uses;
373 if (!imm)
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. */
380 static inline tree
381 immediate_use (dataflow_t df, int num)
383 if (!df)
384 return NULL_TREE;
386 #ifdef ENABLE_CHECKING
387 if (num >= num_immediate_uses (df))
388 abort ();
389 #endif
390 if (num < 2)
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
403 PHI nodes. */
404 static inline tree
405 phi_nodes (basic_block bb)
407 if (bb->index < 0)
408 return NULL;
409 return bb_ann (bb)->phi_nodes;
412 /* Set list of phi nodes of a basic block BB to L. */
414 static inline void
415 set_phi_nodes (basic_block bb, tree l)
417 tree phi;
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. */
425 static inline int
426 phi_arg_from_edge (tree phi, edge e)
428 int i;
429 #if defined ENABLE_CHECKING
430 if (!phi || TREE_CODE (phi) != PHI_NODE)
431 abort();
432 #endif
434 for (i = 0; i < PHI_NUM_ARGS (phi); i++)
435 if (PHI_ARG_EDGE (phi, i) == e)
436 return i;
438 return -1;
441 /* ----------------------------------------------------------------------- */
443 /* Return true if T is an executable statement. */
444 static inline bool
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
452 as a goto. */
453 static inline bool
454 is_label_stmt (tree t)
456 if (t)
457 switch (TREE_CODE (t))
459 case LABEL_DECL:
460 case LABEL_EXPR:
461 case CASE_LABEL_EXPR:
462 return true;
463 default:
464 return false;
466 return false;
469 /* Return true if we may propagate ORIG into DEST, false otherwise. */
470 static inline bool
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
482 like:
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;
488 [ ... ]
489 T.660 = T.647;
490 is = T.660; <-- This ought to be type-casted
491 is.662 = is;
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;
498 struct _ffename *ns;
499 [ ... ]
500 if (n == ns)
501 goto lab;
503 lab:
504 return 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
508 to do. */
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)
517 return false;
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))
529 return true;
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))
535 abort ();
536 #endif
539 /* We have a "copy" from something like a constant into a virtual
540 operand. Reject these. */
541 return false;
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. */
551 static inline void
552 set_default_def (tree var, tree def)
554 var_ann_t ann = var_ann (var);
555 if (ann == NULL)
556 ann = create_var_ann (var);
557 ann->default_def = def;
560 /* Return the default definition for variable VAR, or NULL if none
561 exists. */
562 static inline tree
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. */
573 static inline bool
574 phi_ssa_name_p (tree t)
576 if (TREE_CODE (t) == SSA_NAME)
577 return true;
578 #ifdef ENABLE_CHECKING
579 if (!is_gimple_min_invariant (t))
580 abort ();
581 #endif
582 return false;
585 /* ----------------------------------------------------------------------- */
587 /* Return a block_stmt_iterator that points to beginning of basic
588 block BB. */
589 static inline block_stmt_iterator
590 bsi_start (basic_block bb)
592 block_stmt_iterator bsi;
593 if (bb->stmt_list)
594 bsi.tsi = tsi_start (bb->stmt_list);
595 else
597 #ifdef ENABLE_CHECKING
598 if (bb->index >= 0)
599 abort ();
600 #endif
601 bsi.tsi.ptr = NULL;
602 bsi.tsi.container = NULL;
604 bsi.bb = bb;
605 return bsi;
608 /* Return a block statement iterator that points to the last label in
609 block BB. */
611 static inline block_stmt_iterator
612 bsi_after_labels (basic_block bb)
614 block_stmt_iterator bsi;
615 tree_stmt_iterator next;
617 bsi.bb = bb;
619 if (!bb->stmt_list)
621 #ifdef ENABLE_CHECKING
622 if (bb->index >= 0)
623 abort ();
624 #endif
625 bsi.tsi.ptr = NULL;
626 bsi.tsi.container = NULL;
627 return bsi;
630 bsi.tsi = tsi_start (bb->stmt_list);
631 if (tsi_end_p (bsi.tsi))
632 return bsi;
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)
640 abort ();
642 next = bsi.tsi;
643 tsi_next (&next);
645 while (!tsi_end_p (next)
646 && TREE_CODE (tsi_stmt (next)) == LABEL_EXPR)
648 bsi.tsi = next;
649 tsi_next (&next);
652 return bsi;
655 /* Return a block statement iterator that points to the end of basic
656 block BB. */
657 static inline block_stmt_iterator
658 bsi_last (basic_block bb)
660 block_stmt_iterator bsi;
661 if (bb->stmt_list)
662 bsi.tsi = tsi_last (bb->stmt_list);
663 else
665 #ifdef ENABLE_CHECKING
666 if (bb->index >= 0)
667 abort ();
668 #endif
669 bsi.tsi.ptr = NULL;
670 bsi.tsi.container = NULL;
672 bsi.bb = bb;
673 return bsi;
676 /* Return true if block statement iterator I has reached the end of
677 the basic block. */
678 static inline bool
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. */
686 static inline void
687 bsi_next (block_stmt_iterator *i)
689 tsi_next (&i->tsi);
692 /* Modify block statement iterator I so that it is at the previous
693 statement in the basic block. */
694 static inline void
695 bsi_prev (block_stmt_iterator *i)
697 tsi_prev (&i->tsi);
700 /* Return the statement that block statement iterator I is currently
701 at. */
702 static inline tree
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
709 is currently at. */
710 static inline tree *
711 bsi_stmt_ptr (block_stmt_iterator i)
713 return tsi_stmt_ptr (i.tsi);
716 /* Return true if VAR may be aliased. */
717 static inline bool
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. */
725 static inline bool
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. */
733 static inline void
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. */
743 static inline void
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
754 tree_ann (tree t)
756 return t->common.ann;
759 /* Return a common annotation for T. Create the constant annotation if it
760 doesn't exist. */
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 */