Add irn_visited_else_mark(), which combines irn_visited() and mark_irn_visited().
[libfirm] / ir / ana / irextbb_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   Extended basis block support -- private header
23  * @author  Michael Beck
24  * @date    5.2005
25  * @version $Id$
26  */
27 #ifndef FIRM_ANA_IREXTBB_T_H
28 #define FIRM_ANA_IREXTBB_T_H
29
30 #include "irgraph_t.h"
31 #include "irextbb.h"
32 #include "irtools.h"
33
34 /**
35  * An extended block.
36  */
37 struct _ir_extblk {
38   firm_kind kind;        /**< k_ir_extblk */
39   ir_visited_t visited;  /**< visited flag */
40   ir_node  **blks;       /**< blocks belonging to this extended block */
41   void *link;            /**< private link field */
42 };
43
44 /**
45  * Checks whether a pointer points to a extended basic block.
46  * Intern version for libFirm.
47  */
48 static INLINE int
49 _is_ir_extbb (const void *thing) {
50   return (get_kind(thing) == k_ir_extblk);
51 }
52
53 /**
54  * Gets the visited counter of an extended block.
55  * Internal version for libFirm.
56  */
57 static INLINE ir_visited_t
58 _get_extbb_visited(const ir_extblk *blk) {
59   assert(blk);
60   return blk->visited;
61 }
62
63 /**
64  * Sets the visited counter of an extended block.
65  * Internal version for libFirm.
66  */
67 static INLINE void
68 _set_extbb_visited(ir_extblk *blk, ir_visited_t visited) {
69   assert(blk);
70   blk->visited = visited;
71 }
72
73 /**
74  * Mark an extended block as visited in a graph.
75  * Internal version for libFirm.
76  */
77 static INLINE void
78 _mark_extbb_visited(ir_extblk *blk) {
79   assert(blk);
80   blk->visited = current_ir_graph->block_visited;
81 }
82
83 /**
84  * Returns non-zero if an extended was visited.
85  * Internal version for libFirm.
86  */
87 static INLINE int
88 _extbb_visited(const ir_extblk *blk) {
89   assert(blk);
90   return blk->visited >= current_ir_graph->block_visited;
91 }
92
93 /**
94  * Returns non-zero if an extended block was NOT visited.
95  * Internal version for libFirm.
96  */
97 static INLINE int
98 _extbb_not_visited(const ir_extblk *blk) {
99   assert(blk);
100   return blk->visited < current_ir_graph->block_visited;
101 }
102
103 /**
104  * Returns the link field of an extended block.
105  * Internal version for libFirm.
106  */
107 static INLINE void *
108 _get_extbb_link(const ir_extblk *blk) {
109   assert(blk);
110   return blk->link;
111 }
112
113 /**
114  * Sets the link field of an extended block.
115  * Internal version for libFirm.
116  */
117 static INLINE void
118 _set_extbb_link(ir_extblk *blk, void *link) {
119   assert(blk);
120   blk->link = link;
121 }
122
123 /**
124  * Return the number of basis blocks of an extended block
125  */
126 static INLINE int
127 _get_extbb_n_blocks(const ir_extblk *blk) {
128   assert(blk);
129   return ARR_LEN(blk->blks);
130 }
131
132 /**
133  * Return the i'th basis block of an extended block
134  */
135 static INLINE ir_node *
136 _get_extbb_block(ir_extblk *blk, int pos)
137 {
138   assert(blk && 0 <= pos && pos < _get_extbb_n_blocks(blk));
139   return blk->blks[pos];
140 }
141
142 /**
143  * Return the leader basis block of an extended block
144  */
145 static INLINE ir_node *
146 _get_extbb_leader(ir_extblk *blk)
147 {
148   return blk->blks[0];
149 }
150
151 #define is_ir_extbb(thing)        _is_ir_extbb(thing)
152 #define get_extbb_visited(blk)    _get_extbb_visited(blk)
153 #define set_extbb_visited(blk, v) _set_extbb_visited(blk, v)
154 #define mark_extbb_visited(blk)   _mark_extbb_visited(blk)
155 #define extbb_visited(blk)        _extbb_visited(blk)
156 #define extbb_not_visited(blk)    _extbb_not_visited(blk)
157 #define get_extbb_link(blk)       _get_extbb_link(blk)
158 #define set_extbb_link(blk, link) _set_extbb_link(blk, link)
159 #define get_extbb_n_blocks(blk)   _get_extbb_n_blocks(blk)
160 #define get_extbb_leader(blk)     _get_extbb_leader(blk)
161
162 #endif