irloop: remove get_loop_son, get_loop_node
[libfirm] / ir / ana / irloop_t.h
1 /*
2  * Copyright (C) 1995-2008 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 iterate exactly once. */
47         loop_outer_loop    = 0x00000100   /**< if set, this loop has child loops (is a no leaf). */
48 } loop_flags_t;
49
50 /**
51  * The loops data structure.
52  *
53  * The loops data structure represents circles in the intermediate
54  * representation.  It does not represent loops in the terms of a
55  * source program.
56  * Each ir_graph can contain one outermost loop data structure.
57  * loop is the entry point to the nested loops.
58  * The loop data structure contains a field indicating the depth of
59  * the loop within the nesting.  Further it contains a list of the
60  * loops with nesting depth -1.  Finally it contains a list of all
61  * nodes in the loop.
62  */
63 struct ir_loop {
64         firm_kind       kind;             /**< A type tag, set to k_ir_loop. */
65         unsigned        depth;            /**< Nesting depth */
66         unsigned        flags;            /**< a set of loop_flags_t */
67         struct ir_loop *outer_loop;       /**< The outer loop */
68         loop_element   *children;         /**< Mixed flexible array: Contains sons and loop_nodes */
69         ir_tarval      *loop_iter_start;  /**< counting loop: the start value */
70         ir_tarval      *loop_iter_end;    /**< counting loop: the last value reached */
71         ir_tarval      *loop_iter_increment; /**< counting loop: the increment */
72         ir_node        *loop_iter_variable;  /**< The iteration variable of counting loop.*/
73
74         void *link;                       /**< link field. */
75 #ifdef DEBUG_libfirm
76         long loop_nr;                     /**< A unique node number for each loop node to make output
77                                                readable. */
78 #endif
79 };
80
81 /**
82  * Allocates a new loop as son of father on the given obstack.
83  * If father is equal NULL, a new root loop is created.
84  */
85 ir_loop *alloc_loop(ir_loop *father, struct obstack *obst);
86
87 /** Add a son loop to a father loop. */
88 void add_loop_son(ir_loop *loop, ir_loop *son);
89
90 /** Add a node to a loop. */
91 void add_loop_node(ir_loop *loop, ir_node *n);
92
93 /** Add an IR graph to a loop. */
94 void add_loop_irg(ir_loop *loop, ir_graph *irg);
95
96 /** Sets the loop a node belonging to. */
97 void set_irn_loop(ir_node *n, ir_loop *loop);
98
99 /**
100  * Mature all loops by removing the flexible arrays of a loop tree
101  * and putting them on the given obstack.
102  */
103 void mature_loops(ir_loop *loop, struct obstack *obst);
104
105 /* -------- inline functions -------- */
106
107 static inline int _is_ir_loop(const void *thing)
108 {
109         return get_kind(thing) == k_ir_loop;
110 }
111
112 static inline void _set_irg_loop(ir_graph *irg, ir_loop *loop)
113 {
114         assert(irg);
115         irg->loop = loop;
116 }
117
118 static inline ir_loop *_get_irg_loop(const ir_graph *irg)
119 {
120         assert(irg);
121         return irg->loop;
122 }
123
124 static inline ir_loop *_get_loop_outer_loop(const ir_loop *loop)
125 {
126         assert(_is_ir_loop(loop));
127         return loop->outer_loop;
128 }
129
130 static inline unsigned _get_loop_depth(const ir_loop *loop)
131 {
132         assert(_is_ir_loop(loop));
133         return loop->depth;
134 }
135
136 /* Uses temporary information to get the loop */
137 static inline ir_loop *_get_irn_loop(const ir_node *n)
138 {
139         return n->loop;
140 }
141
142 #define is_ir_loop(thing)         _is_ir_loop(thing)
143 #define set_irg_loop(irg, loop)   _set_irg_loop(irg, loop)
144 #define get_irg_loop(irg)         _get_irg_loop(irg)
145 #define get_loop_outer_loop(loop) _get_loop_outer_loop(loop)
146 #define get_loop_depth(loop)      _get_loop_depth(loop)
147 #define get_irn_loop(n)           _get_irn_loop(n)
148
149 #endif