add docu and prototype for find_value()
[libfirm] / ir / ana / irloop_t.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ana/irloop_t.h
4  * Purpose:     Loop datastructure and access functions -- private stuff.
5  * Author:      Goetz Lindenmaier
6  * Modified by:
7  * Created:     7.2002
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 2002-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 /**
14  * @file irloop_t.h
15  * Loop datastructure and access functions -- private stuff.
16  *
17  * @author Goetz Lindenmaier
18  */
19
20 #include "firm_common.h"
21 #include "irgraph_t.h"
22 #include "irnode_t.h"
23 #include "irloop.h"
24
25 #ifndef _IRLOOP_T_H_
26 #define _IRLOOP_T_H_
27
28 /**
29  * Possible loop flags, can be or'ed.
30  */
31 typedef enum loop_flags {
32   loop_is_count_loop = 0x00000001,  /**< if set it's a counting loop */
33   loop_downto_loop   = 0x00000002,  /**< if set, it's a downto loop, else an upto loop */
34   loop_is_endless    = 0x00000004,  /**< if set, this is an endless loop */
35   loop_is_dead       = 0x00000008,  /**< if set, it's a dead loop ie will never be entered */
36   loop_wrap_around   = 0x00000010,  /**< this loop is NOT endless, because of wrap around */
37   loop_end_false     = 0x00000020,  /**< this loop end can't be computed "from compute_loop_info.c" */
38   do_loop            = 0x00000040,  /**< this is a do loop */
39   once               = 0x00000080,  /**< this is a do loop, with a false condition.It itarate once */
40 } loop_flags_t;
41
42 /** The loops datastructure. */
43 struct ir_loop {
44   firm_kind kind;                   /**< A type tag, set to k_ir_loop. */
45
46   struct ir_loop *outer_loop;       /**< The outer loop */
47   loop_element   *children;         /**< Mixed array: Contains sons and loop_nodes */
48   int depth;                        /**< Nesting depth */
49   int n_sons;                       /**< Number of ir_nodes in array "children" */
50   int n_nodes;                      /**< Number of loop_nodes in array "children" */
51   unsigned flags;                   /**< a set of loop_flags_t */
52   tarval  *loop_iter_start;         /**< counting loop: the start value */
53   tarval  *loop_iter_end;           /**< counting loop: the last value reached */
54   tarval  *loop_iter_increment;     /**< counting loop: the increment */
55   ir_node *loop_iter_variable;      /**< The iteration variable of counting loop.*/
56
57   /*
58   struct state_entry *mem_phis;
59   struct state_entry *states;
60
61   struct obset **oval;
62   struct loop_node *link;
63   */
64 #ifdef DEBUG_libfirm
65   long loop_nr;            /**< a unique node number for each loop node to make output
66                               readable. */
67   void *link;              /**< GL @@@ For debugging the analyses. */
68 #endif
69 };
70
71
72 /** Add a son loop to a father loop. */
73 void add_loop_son(ir_loop *loop, ir_loop *son);
74
75 /** Add a node to a loop. */
76 void add_loop_node(ir_loop *loop, ir_node *n);
77
78 /** Sets the loop a node belonging to. */
79 void set_irn_loop(ir_node *n, ir_loop *loop);
80
81 /* -------- INLINE functions -------- */
82
83 static INLINE int
84 _is_ir_loop(const void *thing) {
85   return (get_kind(thing) == k_ir_loop);
86 }
87
88 static INLINE void
89 _set_irg_loop(ir_graph *irg, ir_loop *loop) {
90   assert(irg);
91   irg->loop = loop;
92 }
93
94 static INLINE ir_loop *
95 _get_irg_loop(ir_graph *irg) {
96   assert(irg);
97   return irg->loop;
98 }
99
100 static INLINE ir_loop *
101 _get_loop_outer_loop(const ir_loop *loop) {
102   assert(_is_ir_loop(loop));
103   return loop->outer_loop;
104 }
105
106 static INLINE int
107 _get_loop_depth(const ir_loop *loop) {
108   assert(_is_ir_loop(loop));
109   return loop->depth;
110 }
111
112 static INLINE int
113 _get_loop_n_sons(const ir_loop *loop) {
114   assert(_is_ir_loop(loop));
115   return loop->n_sons;
116 }
117
118 /* Uses temporary information to get the loop */
119 static INLINE ir_loop *
120 _get_irn_loop(const ir_node *n) {
121   return n->loop;
122 }
123
124
125 #define is_ir_loop(thing)         _is_ir_loop(thing)
126 #define set_irg_loop(irg, loop)   _set_irg_loop(irg, loop)
127 #define get_irg_loop(irg)         _get_irg_loop(irg)
128 #define get_loop_outer_loop(loop) _get_loop_outer_loop(loop)
129 #define get_loop_depth(loop)      _get_loop_depth(loop)
130 #define get_loop_n_sons(loop)     _get_loop_n_sons(loop)
131 #define get_irn_loop(n)           _get_irn_loop(n)
132
133 #endif /* _IRLOOP_T_H_ */