indentation changed
[libfirm] / ir / ana / irloop_t.h
1 /*
2  * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief    Loop datastructure and access functions -- private stuff.
23  * @author   Goetz Lindenmaier
24  * @date     7.2002
25  * @version  $Id$
26  */
27 #ifndef FIRM_ANA_IRLOOP_T_H
28 #define FIRM_ANA_IRLOOP_T_H
29
30 #include "firm_common.h"
31 #include "irgraph_t.h"
32 #include "irnode_t.h"
33 #include "irloop.h"
34
35 /**
36  * Possible loop flags, can be or'ed.
37  */
38 typedef enum loop_flags {
39   loop_is_count_loop = 0x00000001,  /**< if set it's a counting loop */
40   loop_downto_loop   = 0x00000002,  /**< if set, it's a downto loop, else an upto loop */
41   loop_is_endless    = 0x00000004,  /**< if set, this is an endless loop */
42   loop_is_dead       = 0x00000008,  /**< if set, it's a dead loop ie will never be entered */
43   loop_wrap_around   = 0x00000010,  /**< this loop is NOT endless, because of wrap around */
44   loop_end_false     = 0x00000020,  /**< this loop end can't be computed "from compute_loop_info.c" */
45   do_loop            = 0x00000040,  /**< this is a do loop */
46   once               = 0x00000080,  /**< this is a do loop, with a false condition.It itarate once */
47 } loop_flags_t;
48
49 /**
50  * The loops data structure.
51  *
52  * The loops data structure represents circles in the intermediate
53  * representation.  It does not represent loops in the terms of a
54  * source program.
55  * Each ir_graph can contain one outermost loop data structure.
56  * loop is the entry point to the nested loops.
57  * The loop data structure contains a field indicating the depth of
58  * the loop within the nesting.  Further it contains a list of the
59  * loops with nesting depth -1.  Finally it contains a list of all
60  * nodes in the loop.
61  *
62  * @todo We could add a field pointing from a node to the containing loop,
63  * this would cost a lot of memory, though.
64  */
65 struct ir_loop {
66   firm_kind kind;                   /**< A type tag, set to k_ir_loop. */
67
68   struct ir_loop *outer_loop;       /**< The outer loop */
69   loop_element   *children;         /**< Mixed array: Contains sons and loop_nodes */
70   int depth;                        /**< Nesting depth */
71   int n_sons;                       /**< Number of ir_nodes in array "children" */
72   int n_nodes;                      /**< Number of loop_nodes in array "children" */
73   unsigned flags;                   /**< a set of loop_flags_t */
74   tarval  *loop_iter_start;         /**< counting loop: the start value */
75   tarval  *loop_iter_end;           /**< counting loop: the last value reached */
76   tarval  *loop_iter_increment;     /**< counting loop: the increment */
77   ir_node *loop_iter_variable;      /**< The iteration variable of counting loop.*/
78
79   /*
80   struct state_entry *mem_phis;
81   struct state_entry *states;
82
83   struct obset **oval;
84   struct loop_node *link;
85   */
86 #ifdef DEBUG_libfirm
87   long loop_nr;            /**< a unique node number for each loop node to make output
88                               readable. */
89   void *link;              /**< GL @@@ For debugging the analyses. */
90 #endif
91 };
92
93
94 /** Add a son loop to a father loop. */
95 void add_loop_son(ir_loop *loop, ir_loop *son);
96
97 /** Add a node to a loop. */
98 void add_loop_node(ir_loop *loop, ir_node *n);
99
100 /** Sets the loop a node belonging to. */
101 void set_irn_loop(ir_node *n, ir_loop *loop);
102
103 /* -------- INLINE functions -------- */
104
105 static INLINE int
106 _is_ir_loop(const void *thing) {
107   return (get_kind(thing) == k_ir_loop);
108 }
109
110 static INLINE void
111 _set_irg_loop(ir_graph *irg, ir_loop *loop) {
112   assert(irg);
113   irg->loop = loop;
114 }
115
116 static INLINE ir_loop *
117 _get_irg_loop(ir_graph *irg) {
118   assert(irg);
119   return irg->loop;
120 }
121
122 static INLINE ir_loop *
123 _get_loop_outer_loop(const ir_loop *loop) {
124   assert(_is_ir_loop(loop));
125   return loop->outer_loop;
126 }
127
128 static INLINE int
129 _get_loop_depth(const ir_loop *loop) {
130   assert(_is_ir_loop(loop));
131   return loop->depth;
132 }
133
134 static INLINE int
135 _get_loop_n_sons(const ir_loop *loop) {
136   assert(_is_ir_loop(loop));
137   return loop->n_sons;
138 }
139
140 /* Uses temporary information to get the loop */
141 static INLINE ir_loop *
142 _get_irn_loop(const ir_node *n) {
143   return n->loop;
144 }
145
146 #define is_ir_loop(thing)         _is_ir_loop(thing)
147 #define set_irg_loop(irg, loop)   _set_irg_loop(irg, loop)
148 #define get_irg_loop(irg)         _get_irg_loop(irg)
149 #define get_loop_outer_loop(loop) _get_loop_outer_loop(loop)
150 #define get_loop_depth(loop)      _get_loop_depth(loop)
151 #define get_loop_n_sons(loop)     _get_loop_n_sons(loop)
152 #define get_irn_loop(n)           _get_irn_loop(n)
153
154 #endif