libFirm
irhooks.h
Go to the documentation of this file.
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 
25 #ifndef FIRM_IR_IRHOOKS_H
26 #define FIRM_IR_IRHOOKS_H
27 
28 #include "irop.h"
29 #include "irnode.h"
30 #include "irgraph.h"
31 #include "begin.h"
32 
36 typedef enum {
65  HOOK_OPT_LAST
67 
69 typedef enum if_result_t {
76  IF_RESULT_LAST
77 } if_result_t;
78 
82 typedef void (generic_func)(void);
83 
87 typedef struct hook_entry {
89  union {
91  void (*_hook_new_ir_op)(void *context, ir_op *op);
92 
94  void (*_hook_free_ir_op)(void *context, ir_op *op);
95 
97  void (*_hook_new_node)(void *context, ir_graph *graph, ir_node *node);
98 
100  void (*_hook_set_irn_n)(void *context, ir_node *src,
101  int pos, ir_node *tgt, ir_node *old_tgt);
102 
104  void (*_hook_replace)(void *context, ir_node *old_node, ir_node *new_node);
105 
107  void (*_hook_turn_into_id)(void *context, ir_node *node);
108 
110  void (*_hook_normalize)(void *context, ir_node *node);
111 
114  void (*_hook_new_graph)(void *context, ir_graph *irg, ir_entity *ent);
115 
117  void (*_hook_free_graph)(void *context, ir_graph *irg);
118 
120  void (*_hook_irg_walk)(void *context, ir_graph *irg, generic_func *pre, generic_func *post);
121 
123  void (*_hook_irg_walk_blkwise)(void *context, ir_graph *irg, generic_func *pre, generic_func *post);
124 
126  void (*_hook_irg_block_walk)(void *context, ir_graph *irg, ir_node *node, generic_func *pre, generic_func *post);
127 
129  void (*_hook_merge_nodes)(void *context, ir_node **new_node_array, int new_num_entries,
130  ir_node **old_node_array, int old_num_entries, hook_opt_kind opt);
131 
133  void (*_hook_reassociate)(void *context, int start);
134 
136  void (*_hook_lower)(void *context, ir_node *node);
137 
139  void (*_hook_inline)(void *context, ir_node *call, ir_graph *irg);
140 
142  void (*_hook_tail_rec)(void *context, ir_graph *irg, int n_calls);
143 
145  void (*_hook_strength_red)(void *context, ir_graph *irg, ir_node *node);
146 
148  void (*_hook_dead_node_elim)(void *context, ir_graph *irg, int start);
149 
151  void (*_hook_if_conversion)(void *context, ir_graph *irg, ir_node *phi, int pos, ir_node *mux, if_result_t reason);
152 
154  void (*_hook_func_call)(void *context, ir_graph *irg, ir_node *call);
155 
157  void (*_hook_arch_dep_replace_mul_with_shifts)(void *context, ir_node *irn);
158 
160  void (*_hook_arch_dep_replace_division_by_const)(void *context, ir_node *irn);
161 
163  void (*_hook_new_mode)(void *context, ir_mode *mode);
164 
166  void (*_hook_new_entity)(void *context, ir_entity *ent);
167 
169  void (*_hook_new_type)(void *context, ir_type *tp);
170 
172  void (*_hook_node_info)(void *context, FILE *f, const ir_node *n);
173  } hook;
176  void *context;
177 
179  struct hook_entry *next;
180 } hook_entry_t;
181 
185 typedef enum {
216 } hook_type_t;
217 
225 
233 
236 
241 #define hook_exec(what, args) do { \
242  hook_entry_t *_p; \
243  for (_p = hooks[what]; _p; _p = _p->next){ \
244  void *hook_ctx_ = _p->context; \
245  _p->hook._##what args; \
246  } \
247 } while (0)
248 
250 #define hook_new_ir_op(op) hook_exec(hook_new_ir_op, (hook_ctx_, op))
251 
252 #define hook_free_ir_op(op) hook_exec(hook_free_ir_op, (hook_ctx_, op))
253 
254 #define hook_new_node(graph, node) hook_exec(hook_new_node, (hook_ctx_, graph, node))
255 
256 #define hook_set_irn_n(src, pos, tgt, old_tgt) \
257  hook_exec(hook_set_irn_n, (hook_ctx_, src, pos, tgt, old_tgt))
258 
259 #define hook_replace(old, nw) hook_exec(hook_replace, (hook_ctx_, old, nw))
260 
261 #define hook_turn_into_id(node) hook_exec(hook_turn_into_id, (hook_ctx_, node))
262 
263 #define hook_normalize(node) hook_exec(hook_normalize, (hook_ctx_, node))
264 
265 #define hook_new_graph(irg, ent) hook_exec(hook_new_graph, (hook_ctx_, irg, ent))
266 
267 #define hook_free_graph(irg) hook_exec(hook_free_graph, (hook_ctx_, irg))
268 
269 #define hook_irg_walk(irg, pre, post) hook_exec(hook_irg_walk, (hook_ctx_, irg, pre, post))
270 
271 #define hook_irg_walk_blkwise(irg, pre, post) \
272  hook_exec(hook_irg_walk_blkwise, (hook_ctx_, irg, pre, post))
273 
274 #define hook_irg_block_walk(irg, node, pre, post) \
275  hook_exec(hook_irg_block_walk, (hook_ctx_, irg, node, pre, post))
276 
277 #define hook_merge_nodes(new_node_array, new_num_entries, old_node_array, old_num_entries, opt) \
278  hook_exec(hook_merge_nodes, (hook_ctx_, new_node_array, new_num_entries, old_node_array, old_num_entries, opt))
279 
280 #define hook_reassociate(start) hook_exec(hook_reassociate, (hook_ctx_, start))
281 
282 #define hook_lower(node) hook_exec(hook_lower, (hook_ctx_, node))
283 
284 #define hook_inline(call, irg) hook_exec(hook_inline, (hook_ctx_, call, irg))
285 
286 #define hook_tail_rec(irg, n_calls) hook_exec(hook_tail_rec, (hook_ctx_, irg, n_calls))
287 
288 #define hook_strength_red(irg, node) \
289  hook_exec(hook_strength_red, (hook_ctx_, irg, node))
290 
291 #define hook_dead_node_elim(irg, start) hook_exec(hook_dead_node_elim, (hook_ctx_, irg, start))
292 
293 #define hook_if_conversion(irg, phi, pos, mux, reason) \
294  hook_exec(hook_if_conversion, (hook_ctx_, irg, phi, pos, mux, reason))
295 
296 #define hook_func_call(irg, call) \
297  hook_exec(hook_func_call, (hook_ctx_, irg, call))
298 
299 #define hook_arch_dep_replace_mul_with_shifts(irn) \
300  hook_exec(hook_arch_dep_replace_mul_with_shifts, (hook_ctx_, irn))
301 
302 #define hook_arch_dep_replace_division_by_const(irn) \
303  hook_exec(hook_arch_dep_replace_division_by_const, (hook_ctx_, irn))
304 
305 #define hook_new_mode(mode) hook_exec(hook_new_mode, (hook_ctx_, mode))
306 
307 #define hook_new_entity(ent) hook_exec(hook_new_entity, (hook_ctx_, ent))
308 
309 #define hook_new_type(tp) hook_exec(hook_new_type, (hook_ctx_, tp))
310 
311 #define hook_node_info(F, node) hook_exec(hook_node_info, (hook_ctx_, F, node))
312 
313 #include "end.h"
314 
315 #endif