rename popcnt to popcount; avoid inline assembly in favor of gcc builtin functions
[libfirm] / include / libfirm / irextbb.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.
23  * @author  Michael Beck
24  * @date    5.2005
25  * @version $Id$
26  */
27 #ifndef FIRM_ANA_IREXTBB_H
28 #define FIRM_ANA_IREXTBB_H
29
30 #include "firm_types.h"
31 #include "execfreq.h"
32
33 /** Flags for extended basic block state. */
34 typedef enum {
35   ir_extblk_info_none    = 0,  /**< No extended basic block information is constructed. Default. */
36   ir_extblk_info_valid   = 1,  /**< Extended basic block information is valid. */
37   ir_extblk_info_invalid = 2   /**< Extended basic block information is constructed but invalid. */
38 } irg_extblk_info_state;
39
40 /* type of callback function for ir_graph walk */
41 #ifndef _EXTBB_WALK_FUNC_TYPEDEF_
42 #define _EXTBB_WALK_FUNC_TYPEDEF_
43 /**
44  * The type of a walk function.  Does not use the link field.
45  *
46  * @param blk  - the extended basic block that is just visited
47  * @param env  - an environment pointer passed by the walk functions
48  */
49 typedef void extbb_walk_func(ir_extblk *blk, void *env);
50 #endif
51
52 /**
53  * Checks whether a pointer points to a extended basic block.
54  * Intern version for libFirm.
55  */
56 int is_ir_extbb(const void *thing);
57
58 /**
59  * Compute the extended basic blocks for a graph.
60  */
61 void compute_extbb(ir_graph *irg);
62
63 /**
64  * Compute the extended basic blocks for a graph based on execution frequencies.
65  */
66 void compute_extbb_execfreqs(ir_graph *irg, ir_exec_freq *execfreqs);
67
68 /**
69  * free all extended block info.
70  */
71 void free_extbb(ir_graph *irg);
72
73 /**
74  * Return the extended block of a node.
75  *
76  * @param node  the node
77  */
78 ir_extblk *get_nodes_extbb(const ir_node *node);
79
80 /**
81  * Gets the visited counter of an extended block.
82  *
83  * @param blk  the extended basic block
84  */
85 ir_visited_t get_extbb_visited(const ir_extblk *blk);
86
87 /**
88  * Sets the visited counter of an extended block.
89  *
90  * @param blk      the extended basic block
91  * @param visited  new value for the visited counter
92  */
93 void set_extbb_visited(ir_extblk *blk, ir_visited_t visited);
94
95 /**
96  * Mark an extended block as visited in a graph.
97  * Uses the block visit flag.
98  *
99  * @param blk  the extended basic block
100  */
101 void mark_extbb_visited(ir_extblk *blk);
102
103 /**
104  * Returns non-zero if an extended was visited.
105  * Uses the block visit flag.
106  *
107  * @param blk  the extended basic block
108  */
109 int extbb_visited(const ir_extblk *blk);
110
111 /**
112  * Returns non-zero if an extended block was NOT visited.
113  * Uses the block visit flag.
114  *
115  * @param blk  the extended basic block
116  */
117 int extbb_not_visited(const ir_extblk *blk);
118
119 /**
120  * Returns the link field of an extended block.
121  *
122  * @param blk  the extended basic block
123  */
124 void *get_extbb_link(const ir_extblk *blk);
125
126 /**
127  * Sets the link field of an extended block.
128  *
129  * @param blk  the extended basic block
130  * @param link the new link value
131  */
132 void set_extbb_link(ir_extblk *blk, void *link);
133
134 /**
135  * Return the number of basic blocks of an extended block.
136  *
137  * @param blk  the extended basic block
138  */
139 int get_extbb_n_blocks(const ir_extblk *blk);
140
141 /**
142  * Return the i'th basic block of an extended block.
143  *
144  * @param blk  the extended basic block
145  * @param pos  the position
146  */
147 ir_node *get_extbb_block(const ir_extblk *blk, int pos);
148
149 /**
150  * Return the leader basic block of an extended block.
151  *
152  * @param blk  the extended basic block
153  */
154 ir_node *get_extbb_leader(const ir_extblk *blk);
155
156 /**
157  * Return the node number of an extended block.
158  * Its the block number of the leader block
159  *
160  * @param blk  the extended basic block
161  */
162 long get_extbb_node_nr(const ir_extblk *blk);
163
164 /**
165  * Walks only over Extended Basic Block nodes in the graph.
166  *
167  * @param blk  - the start extended block node
168  * @param pre  - walker function, executed before the predecessor of a node are visited
169  * @param post - walker function, executed after the predecessor of a node are visited
170  * @param env  - environment, passed to pre and post
171  *
172  * This function Walks only over Block nodes in the graph. Has it's own visited
173  * flag, so that it can be interleaved with the other walker.
174  * If a none block is passed, starts at the block this node belongs to.
175  * If end is passed also visits kept alive blocks. Does not use the link field.
176  */
177 void irg_extblock_walk(ir_extblk *blk, extbb_walk_func *pre, extbb_walk_func *post, void *env);
178
179 /**
180  * Walks only over reachable Extended Basic Block nodes in the graph.
181  * Ensures, that the extended block containing the End node is visited last
182  * and the block containing Start visited first (in post order).
183  *
184  * @param irg  - the irg graph
185  * @param pre  - walker function, executed before the predecessor of a block are visited
186  * @param post - walker function, executed after the predecessor of a block are visited
187  * @param env  - environment, passed to pre and post
188  */
189 void irg_extblock_walk_graph(ir_graph *irg, extbb_walk_func *pre, extbb_walk_func *post, void *env);
190
191 #endif