verify: Clarify assertion message.
[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  */
26 #ifndef FIRM_ANA_IRLOOP_T_H
27 #define FIRM_ANA_IRLOOP_T_H
28
29 #include "firm_common.h"
30 #include "irgraph_t.h"
31 #include "irnode_t.h"
32 #include "irloop.h"
33
34 /**
35  * The loops data structure.
36  *
37  * The loops data structure represents circles in the intermediate
38  * representation.  It does not represent loops in the terms of a
39  * source program.
40  * Each ir_graph can contain one outermost loop data structure.
41  * loop is the entry point to the nested loops.
42  * The loop data structure contains a field indicating the depth of
43  * the loop within the nesting.  Further it contains a list of the
44  * loops with nesting depth -1.  Finally it contains a list of all
45  * nodes in the loop.
46  */
47 struct ir_loop {
48         firm_kind       kind;             /**< A type tag, set to k_ir_loop. */
49         unsigned        depth;            /**< Nesting depth */
50         struct ir_loop *outer_loop;       /**< The outer loop */
51         loop_element   *children;         /**< Mixed flexible array: Contains sons and loop_nodes */
52         void *link;                       /**< link field. */
53 #ifdef DEBUG_libfirm
54         long loop_nr;                     /**< A unique node number for each loop node to make output
55                                                readable. */
56 #endif
57 };
58
59 /**
60  * Allocates a new loop as son of father on the given obstack.
61  * If father is equal NULL, a new root loop is created.
62  */
63 ir_loop *alloc_loop(ir_loop *father, struct obstack *obst);
64
65 /** Add a son loop to a father loop. */
66 void add_loop_son(ir_loop *loop, ir_loop *son);
67
68 /** Add a node to a loop. */
69 void add_loop_node(ir_loop *loop, ir_node *n);
70
71 /** Add an IR graph to a loop. */
72 void add_loop_irg(ir_loop *loop, ir_graph *irg);
73
74 /** Sets the loop a node belonging to. */
75 void set_irn_loop(ir_node *n, ir_loop *loop);
76
77 /**
78  * Mature all loops by removing the flexible arrays of a loop tree
79  * and putting them on the given obstack.
80  */
81 void mature_loops(ir_loop *loop, struct obstack *obst);
82
83 /* -------- inline functions -------- */
84
85 static inline int _is_ir_loop(const void *thing)
86 {
87         return get_kind(thing) == k_ir_loop;
88 }
89
90 static inline void _set_irg_loop(ir_graph *irg, ir_loop *loop)
91 {
92         assert(irg);
93         irg->loop = loop;
94 }
95
96 static inline ir_loop *_get_irg_loop(const ir_graph *irg)
97 {
98         assert(irg);
99         return irg->loop;
100 }
101
102 static inline ir_loop *_get_loop_outer_loop(const ir_loop *loop)
103 {
104         assert(_is_ir_loop(loop));
105         return loop->outer_loop;
106 }
107
108 static inline unsigned _get_loop_depth(const ir_loop *loop)
109 {
110         assert(_is_ir_loop(loop));
111         return loop->depth;
112 }
113
114 /* Uses temporary information to get the loop */
115 static inline ir_loop *_get_irn_loop(const ir_node *n)
116 {
117         return n->loop;
118 }
119
120 #define is_ir_loop(thing)         _is_ir_loop(thing)
121 #define set_irg_loop(irg, loop)   _set_irg_loop(irg, loop)
122 #define get_irg_loop(irg)         _get_irg_loop(irg)
123 #define get_loop_outer_loop(loop) _get_loop_outer_loop(loop)
124 #define get_loop_depth(loop)      _get_loop_depth(loop)
125 #define get_irn_loop(n)           _get_irn_loop(n)
126
127 #endif