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