OSDN Git Service

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