tree-flow-inline.h (stmt_ann): Remove use of is_essa_node.
[platform/upstream/gcc.git] / gcc / tree-flow-inline.h
1 /* Inline functions for tree-flow.h
2    Copyright (C) 2001, 2003 Free Software Foundation, Inc.
3    Contributed by Diego Novillo <dnovillo@redhat.com>
4
5 This file is part of GCC.
6
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.
11
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.
16
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.  */
21
22 #ifndef _TREE_FLOW_INLINE_H
23 #define _TREE_FLOW_INLINE_H 1
24
25 /* Inline functions for manipulating various data structures defined in
26    tree-flow.h.  See tree-flow.h for documentation.  */
27
28 static inline var_ann_t
29 var_ann (tree t)
30 {
31 #if defined ENABLE_CHECKING
32   if (t == NULL_TREE
33       || !DECL_P (t)
34       || (t->common.ann
35           && t->common.ann->common.type != VAR_ANN))
36     abort ();
37 #endif
38
39   return (var_ann_t) t->common.ann;
40 }
41
42 static inline var_ann_t
43 get_var_ann (tree var)
44 {
45   var_ann_t ann = var_ann (var);
46   return (ann) ? ann : create_var_ann (var);
47 }
48
49
50 static inline cst_ann_t
51 cst_ann (tree t)
52 {
53 #if defined ENABLE_CHECKING
54   if (TREE_CODE_CLASS (TREE_CODE (t)) != 'c'
55       || (t->common.ann
56           && t->common.ann->common.type != CST_ANN))
57     abort ();
58 #endif
59
60   return (cst_ann_t) t->common.ann;
61 }
62
63 static inline cst_ann_t
64 get_cst_ann (tree var)
65 {
66   cst_ann_t ann = cst_ann (var);
67   return (ann) ? ann : create_cst_ann (var);
68 }
69
70 static inline expr_ann_t
71 expr_ann (tree t)
72 {
73 #if defined ENABLE_CHECKING
74   if (!EXPR_P (t)
75       || (t->common.ann
76           && t->common.ann->common.type != EXPR_ANN))
77     abort ();
78 #endif
79
80   return (expr_ann_t) t->common.ann;
81 }
82
83 static inline expr_ann_t
84 get_expr_ann (tree var)
85 {
86   expr_ann_t ann = expr_ann (var);
87   return (ann) ? ann : create_expr_ann (var);
88 }
89
90 static inline stmt_ann_t
91 stmt_ann (tree t)
92 {
93 #if defined ENABLE_CHECKING
94   if (!is_gimple_stmt (t))
95     abort ();
96 #endif
97
98   return (stmt_ann_t) t->common.ann;
99 }
100
101 static inline stmt_ann_t
102 get_stmt_ann (tree stmt)
103 {
104   stmt_ann_t ann = stmt_ann (stmt);
105   return (ann) ? ann : create_stmt_ann (stmt);
106 }
107
108
109 static inline enum tree_ann_type
110 ann_type (tree_ann ann)
111 {
112   return ann->common.type;
113 }
114
115 static inline basic_block
116 bb_for_stmt (tree t)
117 {
118   stmt_ann_t ann = stmt_ann (t);
119   return ann ? ann->bb : NULL;
120 }
121
122 static inline varray_type
123 may_aliases (tree var)
124 {
125   var_ann_t ann = var_ann (var);
126   return ann ? ann->may_aliases : NULL;
127 }
128
129 static inline bool
130 has_hidden_use (tree var)
131 {
132   var_ann_t ann = var_ann (var);
133   return ann ? ann->has_hidden_use : false;
134 }
135
136 static inline void
137 set_has_hidden_use (tree var)
138 {
139   var_ann_t ann = var_ann (var);
140   if (ann == NULL)
141     ann = create_var_ann (var);
142   ann->has_hidden_use = 1;
143 }
144
145 static inline int
146 get_lineno (tree expr)
147 {
148   if (expr == NULL_TREE)
149     return -1;
150
151   if (TREE_CODE (expr) == COMPOUND_EXPR)
152     expr = TREE_OPERAND (expr, 0);
153
154   if (! EXPR_LOCUS (expr))
155     return -1;
156
157   return EXPR_LINENO (expr);
158 }
159
160 static inline const char *
161 get_filename (tree expr)
162 {
163   if (expr == NULL_TREE)
164     return "???";
165
166   if (TREE_CODE (expr) == COMPOUND_EXPR)
167     expr = TREE_OPERAND (expr, 0);
168
169   if (EXPR_LOCUS (expr) && EXPR_FILENAME (expr))
170     return EXPR_FILENAME (expr);
171   else
172     return "???";
173 }
174
175 static inline void
176 modify_stmt (tree t)
177 {
178   stmt_ann_t ann = stmt_ann (t);
179   if (ann == NULL)
180     ann = create_stmt_ann (t);
181   ann->modified = 1;
182 }
183
184 static inline void
185 unmodify_stmt (tree t)
186 {
187   stmt_ann_t ann = stmt_ann (t);
188   if (ann == NULL)
189     ann = create_stmt_ann (t);
190   ann->modified = 0;
191 }
192
193 static inline bool
194 stmt_modified_p (tree t)
195 {
196   stmt_ann_t ann = stmt_ann (t);
197
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
200      statement.  */
201   return ann ? ann->modified : true;
202 }
203
204 static inline def_optype
205 get_def_ops (stmt_ann_t ann)
206 {
207   return ann ? ann->def_ops : NULL;
208 }
209
210 static inline use_optype
211 get_use_ops (stmt_ann_t ann)
212 {
213   return ann ? ann->use_ops : NULL;
214 }
215
216 static inline v_may_def_optype
217 get_v_may_def_ops (stmt_ann_t ann)
218 {
219   return ann ? ann->v_may_def_ops : NULL;
220 }
221
222 static inline vuse_optype
223 get_vuse_ops (stmt_ann_t ann)
224 {
225   return ann ? ann->vuse_ops : NULL;
226 }
227
228 static inline v_must_def_optype
229 get_v_must_def_ops (stmt_ann_t ann)
230 {
231   return ann ? ann->v_must_def_ops : NULL;
232 }
233
234 static inline tree *
235 get_use_op_ptr (use_optype uses, unsigned int index)
236 {
237 #ifdef ENABLE_CHECKING
238   if (index >= uses->num_uses)
239     abort();
240 #endif
241   return uses->uses[index];
242 }
243
244 static inline tree *
245 get_def_op_ptr (def_optype defs, unsigned int index)
246 {
247 #ifdef ENABLE_CHECKING
248   if (index >= defs->num_defs)
249     abort();
250 #endif
251   return defs->defs[index];
252 }
253
254 static inline tree *
255 get_v_may_def_result_ptr(v_may_def_optype v_may_defs, unsigned int index)
256 {
257 #ifdef ENABLE_CHECKING
258   if (index >= v_may_defs->num_v_may_defs)
259     abort();
260 #endif
261   return &(v_may_defs->v_may_defs[index * 2]);
262 }
263
264 static inline tree *
265 get_v_may_def_op_ptr(v_may_def_optype v_may_defs, unsigned int index)
266 {
267 #ifdef ENABLE_CHECKING
268   if (index >= v_may_defs->num_v_may_defs)
269     abort();
270 #endif
271   return &(v_may_defs->v_may_defs[index * 2 + 1]);
272 }
273
274 static inline tree *
275 get_vuse_op_ptr(vuse_optype vuses, unsigned int index)
276 {
277 #ifdef ENABLE_CHECKING
278   if (index >= vuses->num_vuses)
279     abort();
280 #endif
281   return &(vuses->vuses[index]);
282 }
283
284 static inline tree *
285 get_v_must_def_op_ptr (v_must_def_optype v_must_defs, unsigned int index)
286 {
287 #ifdef ENABLE_CHECKING
288   if (index >= v_must_defs->num_v_must_defs)
289     abort();
290 #endif
291   return &(v_must_defs->v_must_defs[index]);
292 }
293
294 static inline void
295 start_ssa_stmt_operands (tree stmt ATTRIBUTE_UNUSED)
296 {
297 #ifdef ENABLE_CHECKING
298   verify_start_operands (stmt);
299 #endif
300 }
301
302 static inline bitmap
303 addresses_taken (tree stmt)
304 {
305   stmt_ann_t ann = stmt_ann (stmt);
306   return ann ? ann->addresses_taken : NULL;
307 }
308
309 static dataflow_t
310 get_immediate_uses (tree stmt)
311 {
312   stmt_ann_t ann = stmt_ann (stmt);
313   return ann ? ann->df : NULL;
314 }
315
316 static inline int
317 num_immediate_uses (dataflow_t df)
318 {
319   varray_type imm;
320
321   if (!df)
322     return 0;
323
324   imm = df->immediate_uses;
325   if (!imm)
326     return df->uses[1] ? 2 : 1;
327
328   return VARRAY_ACTIVE_SIZE (imm) + 2;
329 }
330
331 static inline tree
332 immediate_use (dataflow_t df, int num)
333 {
334   if (!df)
335     return NULL_TREE;
336
337 #ifdef ENABLE_CHECKING
338   if (num >= num_immediate_uses (df))
339     abort ();
340 #endif
341   if (num < 2)
342     return df->uses[num];
343   return VARRAY_TREE (df->immediate_uses, num - 2);
344 }
345
346 static inline bb_ann_t
347 bb_ann (basic_block bb)
348 {
349   return (bb_ann_t)bb->tree_annotations;
350 }
351
352 static inline tree
353 phi_nodes (basic_block bb)
354 {
355   if (bb->index < 0)
356     return NULL;
357   return bb_ann (bb)->phi_nodes;
358 }
359
360 /* Set list of phi nodes of a basic block BB to L.  */
361
362 static inline void
363 set_phi_nodes (basic_block bb, tree l)
364 {
365   tree phi;
366
367   bb_ann (bb)->phi_nodes = l;
368   for (phi = l; phi; phi = TREE_CHAIN (phi))
369     set_bb_for_stmt (phi, bb);
370 }
371
372 /* Return the phi index number for an edge.  */
373 static inline int
374 phi_arg_from_edge (tree phi, edge e)
375 {
376   int i;
377 #if defined ENABLE_CHECKING
378   if (!phi || TREE_CODE (phi) != PHI_NODE)
379     abort();
380 #endif
381
382   for (i = 0; i < PHI_NUM_ARGS (phi); i++)
383     if (PHI_ARG_EDGE (phi, i) == e)
384       return i;
385
386   return -1;
387 }
388
389
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)
393 {
394   int i;
395
396   i = phi_arg_from_edge (phi, e);
397   if (i != -1)
398     return &(PHI_ARG_ELT (phi, i));
399   else
400     return (struct phi_arg_d *)NULL;
401 }
402
403 /*  -----------------------------------------------------------------------  */
404
405 static inline bool
406 is_exec_stmt (tree t)
407 {
408   return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
409 }
410
411
412 /* Return true if this stmt can be the target of a control transfer stmt such
413    as a goto.  */
414 static inline bool
415 is_label_stmt (tree t)
416 {
417   if (t)
418     switch (TREE_CODE (t))
419       {
420         case LABEL_DECL:
421         case LABEL_EXPR:
422         case CASE_LABEL_EXPR:
423           return true;
424         default:
425           return false;
426       }
427   return false;
428 }
429
430 static inline bool
431 may_propagate_copy (tree dest, tree orig)
432 {
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.
436      
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.
440
441      This was showing up in libjava/java/util/zip/ZipFile.java with code
442      like:
443
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;
448         [ ... ]
449         T.660 = T.647;
450         is = T.660;     <-- This ought to be type-casted
451         is.662 = is;
452
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:
456
457         struct _ffename_space *n;
458         struct _ffename *ns;
459         [ ... ]
460         if (n == ns)
461           goto lab;
462         ...
463         lab:
464         return n;
465
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
468      to do.  */
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)))
473     {
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)
477         return false;
478     }
479
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))
483     {
484       /* If both operands are SSA_NAMEs referring to virtual operands, then
485          we can always propagate.  */
486       if (TREE_CODE (orig) == SSA_NAME)
487         {
488           if (!is_gimple_reg (orig))
489             return true;
490
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))
495             abort ();
496 #endif
497         }
498
499       /* We have a "copy" from something like a constant into a virtual
500          operand.  Reject these.  */
501       return false;
502     }
503
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)));
508 }
509
510 static inline void
511 set_default_def (tree var, tree def)
512 {
513   var_ann_t ann = var_ann (var);
514   if (ann == NULL)
515     ann = create_var_ann (var);
516   ann->default_def = def;
517 }
518
519 static inline tree
520 default_def (tree var)
521 {
522   var_ann_t ann = var_ann (var);
523   return ann ? ann->default_def : NULL_TREE;
524 }
525
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.  */
529
530 static inline bool
531 phi_ssa_name_p (tree t)
532 {
533   if (TREE_CODE (t) == SSA_NAME)
534     return true;
535 #ifdef ENABLE_CHECKING
536   if (!is_gimple_min_invariant (t))
537     abort ();
538 #endif
539   return false;
540 }
541
542 /*  -----------------------------------------------------------------------  */
543
544 static inline block_stmt_iterator
545 bsi_start (basic_block bb)
546 {
547   block_stmt_iterator bsi;
548   if (bb->stmt_list)
549     bsi.tsi = tsi_start (bb->stmt_list);
550   else
551     {
552 #ifdef ENABLE_CHECKING
553       if (bb->index >= 0)
554         abort ();
555 #endif
556       bsi.tsi.ptr = NULL;
557       bsi.tsi.container = NULL;
558     }
559   bsi.bb = bb;
560   return bsi;
561 }
562
563 static inline block_stmt_iterator
564 bsi_last (basic_block bb)
565 {
566   block_stmt_iterator bsi;
567   if (bb->stmt_list)
568     bsi.tsi = tsi_last (bb->stmt_list);
569   else
570     {
571 #ifdef ENABLE_CHECKING
572       if (bb->index >= 0)
573         abort ();
574 #endif
575       bsi.tsi.ptr = NULL;
576       bsi.tsi.container = NULL;
577     }
578   bsi.bb = bb;
579   return bsi;
580 }
581
582 static inline bool
583 bsi_end_p (block_stmt_iterator i)
584 {
585   return tsi_end_p (i.tsi);
586 }
587
588 static inline void
589 bsi_next (block_stmt_iterator *i)
590 {
591   tsi_next (&i->tsi);
592 }
593
594 static inline void
595 bsi_prev (block_stmt_iterator *i)
596 {
597   tsi_prev (&i->tsi);
598 }
599
600 static inline tree
601 bsi_stmt (block_stmt_iterator i)
602 {
603   return tsi_stmt (i.tsi);
604 }
605
606 static inline tree *
607 bsi_stmt_ptr (block_stmt_iterator i)
608 {
609   return tsi_stmt_ptr (i.tsi);
610 }
611
612 static inline bool
613 may_be_aliased (tree var)
614 {
615   return (TREE_ADDRESSABLE (var)
616           || decl_function_context (var) != current_function_decl);
617 }
618
619 static inline bool
620 is_call_clobbered (tree var)
621 {
622   return needs_to_live_in_memory (var)
623          || bitmap_bit_p (call_clobbered_vars, var_ann (var)->uid);
624 }
625
626 static inline void
627 mark_call_clobbered (tree var)
628 {
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);
633 }
634
635 static inline void
636 mark_non_addressable (tree var)
637 {
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;
641 }
642
643 #endif /* _TREE_FLOW_INLINE_H  */