OSDN Git Service

* gimple-low.c (expand_var_p): Don't look at TREE_ADDRESSABLE,
[pf3gnuchains/gcc-fork.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 /* 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)
32 {
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
40
41   return (var_ann_t) t->common.ann;
42 }
43
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)
48 {
49   var_ann_t ann = var_ann (var);
50   return (ann) ? ann : create_var_ann (var);
51 }
52
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)
57 {
58 #if defined ENABLE_CHECKING
59   if (!is_gimple_stmt (t))
60     abort ();
61 #endif
62
63   return (stmt_ann_t) t->common.ann;
64 }
65
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)
70 {
71   stmt_ann_t ann = stmt_ann (stmt);
72   return (ann) ? ann : create_stmt_ann (stmt);
73 }
74
75
76 /* Return the annotation type for annotation ANN.  */
77 static inline enum tree_ann_type
78 ann_type (tree_ann_t ann)
79 {
80   return ann->common.type;
81 }
82
83 /* Return the basic block for statement T.  */
84 static inline basic_block
85 bb_for_stmt (tree t)
86 {
87   stmt_ann_t ann = stmt_ann (t);
88   return ann ? ann->bb : NULL;
89 }
90
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)
95 {
96   var_ann_t ann = var_ann (var);
97   return ann ? ann->may_aliases : NULL;
98 }
99
100 /* Return the line number for EXPR, or return -1 if we have no line
101    number information for it.  */
102 static inline int
103 get_lineno (tree expr)
104 {
105   if (expr == NULL_TREE)
106     return -1;
107
108   if (TREE_CODE (expr) == COMPOUND_EXPR)
109     expr = TREE_OPERAND (expr, 0);
110
111   if (! EXPR_HAS_LOCATION (expr))
112     return -1;
113
114   return EXPR_LINENO (expr);
115 }
116
117 /* Return the file name for EXPR, or return "???" if we have no
118    filename information.  */
119 static inline const char *
120 get_filename (tree expr)
121 {
122   const char *filename;
123   if (expr == NULL_TREE)
124     return "???";
125
126   if (TREE_CODE (expr) == COMPOUND_EXPR)
127     expr = TREE_OPERAND (expr, 0);
128
129   if (EXPR_HAS_LOCATION (expr) && (filename = EXPR_FILENAME (expr)))
130     return filename;
131   else
132     return "???";
133 }
134
135 /* Mark statement T as modified.  */
136 static inline void
137 modify_stmt (tree t)
138 {
139   stmt_ann_t ann = stmt_ann (t);
140   if (ann == NULL)
141     ann = create_stmt_ann (t);
142   ann->modified = 1;
143 }
144
145 /* Mark statement T as unmodified.  */
146 static inline void
147 unmodify_stmt (tree t)
148 {
149   stmt_ann_t ann = stmt_ann (t);
150   if (ann == NULL)
151     ann = create_stmt_ann (t);
152   ann->modified = 0;
153 }
154
155 /* Return true if T is marked as modified, false otherwise.  */
156 static inline bool
157 stmt_modified_p (tree t)
158 {
159   stmt_ann_t ann = stmt_ann (t);
160
161   /* Note that if the statement doesn't yet have an annotation, we consider it
162      modified.  This will force the next call to get_stmt_operands to scan the
163      statement.  */
164   return ann ? ann->modified : true;
165 }
166
167 /* Return the definitions present in ANN, a statement annotation.
168    Return NULL if this annotation contains no definitions.  */
169 static inline def_optype
170 get_def_ops (stmt_ann_t ann)
171 {
172   return ann ? ann->def_ops : NULL;
173 }
174
175 /* Return the uses present in ANN, a statement annotation.
176    Return NULL if this annotation contains no uses.  */
177 static inline use_optype
178 get_use_ops (stmt_ann_t ann)
179 {
180   return ann ? ann->use_ops : NULL;
181 }
182
183 /* Return the virtual may-defs present in ANN, a statement
184    annotation.
185    Return NULL if this annotation contains no virtual may-defs.  */
186 static inline v_may_def_optype
187 get_v_may_def_ops (stmt_ann_t ann)
188 {
189   return ann ? ann->v_may_def_ops : NULL;
190 }
191
192 /* Return the virtual uses present in ANN, a statement annotation.
193    Return NULL if this annotation contains no virtual uses.  */
194 static inline vuse_optype
195 get_vuse_ops (stmt_ann_t ann)
196 {
197   return ann ? ann->vuse_ops : NULL;
198 }
199
200 /* Return the virtual must-defs present in ANN, a statement
201    annotation.  Return NULL if this annotation contains no must-defs.*/
202 static inline v_must_def_optype
203 get_v_must_def_ops (stmt_ann_t ann)
204 {
205   return ann ? ann->v_must_def_ops : NULL;
206 }
207
208 /* Return the tree pointer to by USE.  */ 
209 static inline tree
210 get_use_from_ptr (use_operand_p use)
211
212   return *(use.use);
213
214
215 /* Return the tree pointer to by DEF.  */
216 static inline tree
217 get_def_from_ptr (def_operand_p def)
218 {
219   return *(def.def);
220 }
221
222 /* Return a pointer to the tree that is at INDEX in the USES array.  */
223 static inline use_operand_p
224 get_use_op_ptr (use_optype uses, unsigned int index)
225 {
226 #ifdef ENABLE_CHECKING
227   if (index >= uses->num_uses)
228     abort();
229 #endif
230   return uses->uses[index];
231 }
232
233 /* Return a def_operand_p pointer for element INDEX of DEFS.  */
234 static inline def_operand_p
235 get_def_op_ptr (def_optype defs, unsigned int index)
236 {
237 #ifdef ENABLE_CHECKING
238   if (index >= defs->num_defs)
239     abort();
240 #endif
241   return defs->defs[index];
242 }
243
244
245 /* Return the def_operand_p that is the V_MAY_DEF_RESULT for the V_MAY_DEF
246    at INDEX in the V_MAY_DEFS array.  */
247 static inline def_operand_p
248 get_v_may_def_result_ptr(v_may_def_optype v_may_defs, unsigned int index)
249 {
250   def_operand_p op;
251 #ifdef ENABLE_CHECKING
252   if (index >= v_may_defs->num_v_may_defs)
253     abort();
254 #endif
255   op.def = &(v_may_defs->v_may_defs[index * 2]);
256   return op;
257 }
258
259 /* Return a use_operand_p that is the V_MAY_DEF_OP for the V_MAY_DEF at
260    INDEX in the V_MAY_DEFS array.  */
261 static inline use_operand_p
262 get_v_may_def_op_ptr(v_may_def_optype v_may_defs, unsigned int index)
263 {
264   use_operand_p op;
265 #ifdef ENABLE_CHECKING
266   if (index >= v_may_defs->num_v_may_defs)
267     abort();
268 #endif
269   op.use = &(v_may_defs->v_may_defs[index * 2 + 1]);
270   return op;
271 }
272
273 /* Return a use_operand_p that is at INDEX in the VUSES array.  */
274 static inline use_operand_p
275 get_vuse_op_ptr(vuse_optype vuses, unsigned int index)
276 {
277   use_operand_p op;
278 #ifdef ENABLE_CHECKING
279   if (index >= vuses->num_vuses)
280     abort();
281 #endif
282   op.use = &(vuses->vuses[index]);
283   return op;
284 }
285
286 /* Return a def_operand_p that is the V_MUST_DEF_OP for the
287    V_MUST_DEF at INDEX in the V_MUST_DEFS array.  */
288 static inline def_operand_p
289 get_v_must_def_op_ptr (v_must_def_optype v_must_defs, unsigned int index)
290 {
291   def_operand_p op;
292 #ifdef ENABLE_CHECKING
293   if (index >= v_must_defs->num_v_must_defs)
294     abort();
295 #endif
296   op.def = &(v_must_defs->v_must_defs[index]);
297   return op;
298 }
299
300 /* Return a def_operand_p pointer for the result of PHI.  */
301 static inline def_operand_p
302 get_phi_result_ptr (tree phi)
303 {
304   def_operand_p op;
305   op.def = &(PHI_RESULT_TREE (phi));
306   return op;
307 }
308
309 /* Return a use_operand_p pointer for argument I of phinode PHI.  */
310 static inline use_operand_p
311 get_phi_arg_def_ptr (tree phi, int i)
312 {
313   use_operand_p op;
314   op.use = &(PHI_ARG_DEF_TREE (phi, i));
315   return op;
316 }
317  
318 /* Mark the beginning of changes to the SSA operands for STMT.  */
319 static inline void
320 start_ssa_stmt_operands (tree stmt ATTRIBUTE_UNUSED)
321 {
322 #ifdef ENABLE_CHECKING
323   verify_start_operands (stmt);
324 #endif
325 }
326
327 /* Return the bitmap of addresses taken by STMT, or NULL if it takes
328    no addresses.  */
329 static inline bitmap
330 addresses_taken (tree stmt)
331 {
332   stmt_ann_t ann = stmt_ann (stmt);
333   return ann ? ann->addresses_taken : NULL;
334 }
335
336 /* Return the immediate uses of STMT, or NULL if this information is
337    not computed.  */
338 static dataflow_t
339 get_immediate_uses (tree stmt)
340 {
341   stmt_ann_t ann = stmt_ann (stmt);
342   return ann ? ann->df : NULL;
343 }
344
345 /* Return the number of immediate uses present in the dataflow
346    information at DF.  */
347 static inline int
348 num_immediate_uses (dataflow_t df)
349 {
350   varray_type imm;
351
352   if (!df)
353     return 0;
354
355   imm = df->immediate_uses;
356   if (!imm)
357     return df->uses[1] ? 2 : 1;
358
359   return VARRAY_ACTIVE_SIZE (imm) + 2;
360 }
361
362 /* Return the tree that is at NUM in the immediate use DF array.  */
363 static inline tree
364 immediate_use (dataflow_t df, int num)
365 {
366   if (!df)
367     return NULL_TREE;
368
369 #ifdef ENABLE_CHECKING
370   if (num >= num_immediate_uses (df))
371     abort ();
372 #endif
373   if (num < 2)
374     return df->uses[num];
375   return VARRAY_TREE (df->immediate_uses, num - 2);
376 }
377
378 /* Return the basic_block annotation for BB.  */
379 static inline bb_ann_t
380 bb_ann (basic_block bb)
381 {
382   return (bb_ann_t)bb->tree_annotations;
383 }
384
385 /* Return the PHI nodes for basic block BB, or NULL if there are no
386    PHI nodes.  */
387 static inline tree
388 phi_nodes (basic_block bb)
389 {
390   if (bb->index < 0)
391     return NULL;
392   return bb_ann (bb)->phi_nodes;
393 }
394
395 /* Set list of phi nodes of a basic block BB to L.  */
396
397 static inline void
398 set_phi_nodes (basic_block bb, tree l)
399 {
400   tree phi;
401
402   bb_ann (bb)->phi_nodes = l;
403   for (phi = l; phi; phi = PHI_CHAIN (phi))
404     set_bb_for_stmt (phi, bb);
405 }
406
407 /* Return the phi index number for an edge.  */
408 static inline int
409 phi_arg_from_edge (tree phi, edge e)
410 {
411   int i;
412 #if defined ENABLE_CHECKING
413   if (!phi || TREE_CODE (phi) != PHI_NODE)
414     abort();
415 #endif
416
417   for (i = 0; i < PHI_NUM_ARGS (phi); i++)
418     if (PHI_ARG_EDGE (phi, i) == e)
419       return i;
420
421   return -1;
422 }
423
424 /* Mark VAR as used, so that it'll be preserved during rtl expansion.  */
425
426 static inline void
427 set_is_used (tree var)
428 {
429   var_ann_t ann = get_var_ann (var);
430   ann->used = 1;
431 }
432
433
434 /*  -----------------------------------------------------------------------  */
435
436 /* Return true if T is an executable statement.  */
437 static inline bool
438 is_exec_stmt (tree t)
439 {
440   return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
441 }
442
443
444 /* Return true if this stmt can be the target of a control transfer stmt such
445    as a goto.  */
446 static inline bool
447 is_label_stmt (tree t)
448 {
449   if (t)
450     switch (TREE_CODE (t))
451       {
452         case LABEL_DECL:
453         case LABEL_EXPR:
454         case CASE_LABEL_EXPR:
455           return true;
456         default:
457           return false;
458       }
459   return false;
460 }
461
462 /* Set the default definition for VAR to DEF.  */
463 static inline void
464 set_default_def (tree var, tree def)
465 {
466   var_ann_t ann = get_var_ann (var);
467   ann->default_def = def;
468 }
469
470 /* Return the default definition for variable VAR, or NULL if none
471    exists.  */
472 static inline tree
473 default_def (tree var)
474 {
475   var_ann_t ann = var_ann (var);
476   return ann ? ann->default_def : NULL_TREE;
477 }
478
479 /* PHI nodes should contain only ssa_names and invariants.  A test
480    for ssa_name is definitely simpler; don't let invalid contents
481    slip in in the meantime.  */
482
483 static inline bool
484 phi_ssa_name_p (tree t)
485 {
486   if (TREE_CODE (t) == SSA_NAME)
487     return true;
488 #ifdef ENABLE_CHECKING
489   if (!is_gimple_min_invariant (t))
490     abort ();
491 #endif
492   return false;
493 }
494
495 /*  -----------------------------------------------------------------------  */
496
497 /* Return a block_stmt_iterator that points to beginning of basic
498    block BB.  */
499 static inline block_stmt_iterator
500 bsi_start (basic_block bb)
501 {
502   block_stmt_iterator bsi;
503   if (bb->stmt_list)
504     bsi.tsi = tsi_start (bb->stmt_list);
505   else
506     {
507 #ifdef ENABLE_CHECKING
508       if (bb->index >= 0)
509         abort ();
510 #endif
511       bsi.tsi.ptr = NULL;
512       bsi.tsi.container = NULL;
513     }
514   bsi.bb = bb;
515   return bsi;
516 }
517
518 /* Return a block statement iterator that points to the last label in
519    block BB.  */
520
521 static inline block_stmt_iterator
522 bsi_after_labels (basic_block bb)
523 {
524   block_stmt_iterator bsi;
525   tree_stmt_iterator next;
526
527   bsi.bb = bb;
528
529   if (!bb->stmt_list)
530     {
531 #ifdef ENABLE_CHECKING
532       if (bb->index >= 0)
533         abort ();
534 #endif
535       bsi.tsi.ptr = NULL;
536       bsi.tsi.container = NULL;
537       return bsi;
538     }
539
540   bsi.tsi = tsi_start (bb->stmt_list);
541   if (tsi_end_p (bsi.tsi))
542     return bsi;
543
544   /* Ensure that there are some labels.  The rationale is that we want
545      to insert after the bsi that is returned, and these insertions should
546      be placed at the start of the basic block.  This would not work if the
547      first statement was not label; rather fail here than enable the user
548      proceed in wrong way.  */
549   if (TREE_CODE (tsi_stmt (bsi.tsi)) != LABEL_EXPR)
550     abort ();
551
552   next = bsi.tsi;
553   tsi_next (&next);
554
555   while (!tsi_end_p (next)
556          && TREE_CODE (tsi_stmt (next)) == LABEL_EXPR)
557     {
558       bsi.tsi = next;
559       tsi_next (&next);
560     }
561
562   return bsi;
563 }
564
565 /* Return a block statement iterator that points to the end of basic
566    block BB.  */
567 static inline block_stmt_iterator
568 bsi_last (basic_block bb)
569 {
570   block_stmt_iterator bsi;
571   if (bb->stmt_list)
572     bsi.tsi = tsi_last (bb->stmt_list);
573   else
574     {
575 #ifdef ENABLE_CHECKING
576       if (bb->index >= 0)
577         abort ();
578 #endif
579       bsi.tsi.ptr = NULL;
580       bsi.tsi.container = NULL;
581     }
582   bsi.bb = bb;
583   return bsi;
584 }
585
586 /* Return true if block statement iterator I has reached the end of
587    the basic block.  */
588 static inline bool
589 bsi_end_p (block_stmt_iterator i)
590 {
591   return tsi_end_p (i.tsi);
592 }
593
594 /* Modify block statement iterator I so that it is at the next
595    statement in the basic block.  */
596 static inline void
597 bsi_next (block_stmt_iterator *i)
598 {
599   tsi_next (&i->tsi);
600 }
601
602 /* Modify block statement iterator I so that it is at the previous
603    statement in the basic block.  */
604 static inline void
605 bsi_prev (block_stmt_iterator *i)
606 {
607   tsi_prev (&i->tsi);
608 }
609
610 /* Return the statement that block statement iterator I is currently
611    at.  */
612 static inline tree
613 bsi_stmt (block_stmt_iterator i)
614 {
615   return tsi_stmt (i.tsi);
616 }
617
618 /* Return a pointer to the statement that block statement iterator I
619    is currently at.  */
620 static inline tree *
621 bsi_stmt_ptr (block_stmt_iterator i)
622 {
623   return tsi_stmt_ptr (i.tsi);
624 }
625
626 /* Returns the loop of the statement STMT.  */
627
628 static inline struct loop *
629 loop_containing_stmt (tree stmt)
630 {
631   basic_block bb = bb_for_stmt (stmt);
632   if (!bb)
633     return NULL;
634
635   return bb->loop_father;
636 }
637
638 /* Return true if VAR may be aliased.  */
639 static inline bool
640 may_be_aliased (tree var)
641 {
642   return (TREE_ADDRESSABLE (var)
643           || decl_function_context (var) != current_function_decl);
644 }
645
646 /* Return true if VAR is a clobbered by function calls.  */
647 static inline bool
648 is_call_clobbered (tree var)
649 {
650   return needs_to_live_in_memory (var)
651          || bitmap_bit_p (call_clobbered_vars, var_ann (var)->uid);
652 }
653
654 /* Mark variable VAR as being clobbered by function calls.  */
655 static inline void
656 mark_call_clobbered (tree var)
657 {
658   var_ann_t ann = var_ann (var);
659   /* Call-clobbered variables need to live in memory.  */
660   DECL_NEEDS_TO_LIVE_IN_MEMORY_INTERNAL (var) = 1;
661   bitmap_set_bit (call_clobbered_vars, ann->uid);
662 }
663
664 /* Mark variable VAR as being non-addressable.  */
665 static inline void
666 mark_non_addressable (tree var)
667 {
668   bitmap_clear_bit (call_clobbered_vars, var_ann (var)->uid);
669   DECL_NEEDS_TO_LIVE_IN_MEMORY_INTERNAL (var) = 0;
670   TREE_ADDRESSABLE (var) = 0;
671 }
672
673 /* Return the common annotation for T.  Return NULL if the annotation
674    doesn't already exist.  */
675 static inline tree_ann_t
676 tree_ann (tree t)
677 {
678   return t->common.ann;
679 }
680
681 /* Return a common annotation for T.  Create the constant annotation if it
682    doesn't exist.  */
683 static inline tree_ann_t
684 get_tree_ann (tree t)
685 {
686   tree_ann_t ann = tree_ann (t);
687   return (ann) ? ann : create_tree_ann (t);
688 }
689
690 #endif /* _TREE_FLOW_INLINE_H  */