becopyheur4: Clean up co_mst_irn_init().
[libfirm] / ir / ir / irgraph_t.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief    Entry point to the representation of procedure code -- internal header.
9  * @author   Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
10  */
11 #ifndef FIRM_IR_IRGRAPH_T_H
12 #define FIRM_IR_IRGRAPH_T_H
13
14 #include "firm_types.h"
15 #include "irgraph.h"
16
17 #include "irtypes.h"
18 #include "irprog.h"
19 #include "type_t.h"
20 #include "entity_t.h"
21 #include "iredgekinds.h"
22
23 #include "irloop.h"
24
25 #include "obst.h"
26 #include "pset.h"
27 #include "set.h"
28
29 #define is_ir_graph(thing)                    is_ir_graph_(thing)
30 #define get_irg_start_block(irg)              get_irg_start_block_(irg)
31 #define set_irg_start_block(irg, node)        set_irg_start_block_(irg, node)
32 #define get_irg_start(irg)                    get_irg_start_(irg)
33 #define set_irg_start(irg, node)              set_irg_start_(irg, node)
34 #define get_irg_end_block(irg)                get_irg_end_block_(irg)
35 #define set_irg_end_block(irg, node)          set_irg_end_block_(irg, node)
36 #define get_irg_end(irg)                      get_irg_end_(irg)
37 #define set_irg_end(irg, node)                set_irg_end_(irg, node)
38 #define get_irg_initial_exec(irg)             get_irg_initial_exec_(irg)
39 #define set_irg_initial_exec(irg, node)       set_irg_initial_exec_(irg, node)
40 #define get_irg_frame(irg)                    get_irg_frame_(irg)
41 #define set_irg_frame(irg, node)              set_irg_frame_(irg, node)
42 #define get_irg_initial_mem(irg)              get_irg_initial_mem_(irg)
43 #define set_irg_initial_mem(irg, node)        set_irg_initial_mem_(irg, node)
44 #define get_irg_args(irg)                     get_irg_args_(irg)
45 #define set_irg_args(irg, node)               set_irg_args_(irg, node)
46 #define get_irg_no_mem(irg)                   get_irg_no_mem_(irg)
47 #define set_irn_no_mem(irg, node)             set_irn_no_mem_(irg, node)
48 #define get_irg_entity(irg)                   get_irg_entity_(irg)
49 #define set_irg_entity(irg, ent)              set_irg_entity_(irg, ent)
50 #define get_irg_frame_type(irg)               get_irg_frame_type_(irg)
51 #define set_irg_frame_type(irg, ftp)          set_irg_frame_type_(irg, ftp)
52 #define get_irg_pinned(irg)                   get_irg_pinned_(irg)
53 #define get_irg_callee_info_state(irg)        get_irg_callee_info_state_(irg)
54 #define set_irg_callee_info_state(irg, s)     set_irg_callee_info_state_(irg, s)
55 #define get_irg_additional_properties(irg)    get_irg_additional_properties_(irg)
56 #define set_irg_additional_properties(irg, m) set_irg_additional_properties_(irg, m)
57 #define set_irg_additional_property(irg, f)   set_irg_additional_property_(irg, f)
58 #define set_irg_link(irg, thing)              set_irg_link_(irg, thing)
59 #define get_irg_link(irg)                     get_irg_link_(irg)
60 #define get_irg_visited(irg)                  get_irg_visited_(irg)
61 #define get_irg_block_visited(irg)            get_irg_block_visited_(irg)
62 #define set_irg_block_visited(irg, v)         set_irg_block_visited_(irg, v)
63 #define inc_irg_block_visited(irg)            inc_irg_block_visited_(irg)
64 #define dec_irg_block_visited(irg)            dec_irg_block_visited_(irg)
65 #define get_irg_fp_model(irg)                 get_irg_fp_model_(irg)
66 #define get_idx_irn(irg, idx)                 get_idx_irn_(irg, idx)
67 #define irg_is_constrained(irg, constraints)  irg_is_constrained_(irg, constraints)
68 #define add_irg_properties(irg, props)        add_irg_properties_(irg, props)
69 #define clear_irg_properties(irg, props)      clear_irg_properties_(irg, props)
70 #define irg_has_properties(irg, props)        irg_has_properties_(irg, props)
71
72 /**
73  * Initializes the graph construction module.
74  */
75 void firm_init_irgraph(void);
76
77 /**
78  * Set the number of locals for a given graph.
79  *
80  * @param irg    the graph
81  * @param n_loc  number of locals
82  */
83 void irg_set_nloc(ir_graph *res, int n_loc);
84
85 /**
86  * Internal constructor that does not add to irp_irgs or the like.
87  */
88 ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc);
89
90 /**
91  * Make a rudimentary ir graph for the constant code.
92  * Must look like a correct irg, spare everything else.
93  */
94 ir_graph *new_const_code_irg(void);
95
96 /**
97  * Create a new graph that is a copy of a given one.
98  * Uses the link fields of the original graphs.
99  *
100  * @param irg  The graph that must be copied.
101  */
102 ir_graph *create_irg_copy(ir_graph *irg);
103
104 /**
105  * Set the op_pin_state_pinned state of a graph.
106  *
107  * @param irg     the IR graph
108  * @param p       new pin state
109  */
110 static inline void set_irg_pinned(ir_graph *irg, op_pin_state p)
111 {
112         irg->irg_pinned_state = p;
113 }
114
115 /** Returns the obstack associated with the graph. */
116 static inline struct obstack *get_irg_obstack(ir_graph *const irg)
117 {
118         assert(obstack_object_size(&irg->obst) == 0);
119         return &irg->obst;
120 }
121
122
123
124 /**
125  * Returns true if the node n is allocated on the storage of graph irg.
126  *
127  * @param irg   the IR graph
128  * @param n the IR node
129  */
130 int node_is_in_irgs_storage(const ir_graph *irg, const ir_node *n);
131
132 /*-------------------------------------------------------------------*/
133 /* inline functions for graphs                                       */
134 /*-------------------------------------------------------------------*/
135
136 static inline int is_ir_graph_(const void *thing)
137 {
138         return (get_kind(thing) == k_ir_graph);
139 }
140
141 /** Returns the start block of a graph. */
142 static inline ir_node *get_irg_start_block_(const ir_graph *irg)
143 {
144         return get_irn_n(irg->anchor, anchor_start_block);
145 }
146
147 static inline void set_irg_start_block_(ir_graph *irg, ir_node *node)
148 {
149         set_irn_n(irg->anchor, anchor_start_block, node);
150 }
151
152 static inline ir_node *get_irg_start_(const ir_graph *irg)
153 {
154         return get_irn_n(irg->anchor, anchor_start);
155 }
156
157 static inline void set_irg_start_(ir_graph *irg, ir_node *node)
158 {
159         set_irn_n(irg->anchor, anchor_start, node);
160 }
161
162 static inline ir_node *get_irg_end_block_(const ir_graph *irg)
163 {
164         return get_irn_n(irg->anchor, anchor_end_block);
165 }
166
167 static inline void set_irg_end_block_(ir_graph *irg, ir_node *node)
168 {
169         set_irn_n(irg->anchor, anchor_end_block, node);
170 }
171
172 static inline ir_node *get_irg_end_(const ir_graph *irg)
173 {
174         return get_irn_n(irg->anchor, anchor_end);
175 }
176
177 static inline void set_irg_end_(ir_graph *irg, ir_node *node)
178 {
179         set_irn_n(irg->anchor, anchor_end, node);
180 }
181
182 static inline ir_node *get_irg_initial_exec_(const ir_graph *irg)
183 {
184         return get_irn_n(irg->anchor, anchor_initial_exec);
185 }
186
187 static inline void set_irg_initial_exec_(ir_graph *irg, ir_node *node)
188 {
189         set_irn_n(irg->anchor, anchor_initial_exec, node);
190 }
191
192 static inline ir_node *get_irg_frame_(const ir_graph *irg)
193 {
194         return get_irn_n(irg->anchor, anchor_frame);
195 }
196
197 static inline void set_irg_frame_(ir_graph *irg, ir_node *node)
198 {
199         set_irn_n(irg->anchor, anchor_frame, node);
200 }
201
202 static inline ir_node *get_irg_initial_mem_(const ir_graph *irg)
203 {
204         return get_irn_n(irg->anchor, anchor_initial_mem);
205 }
206
207 static inline void set_irg_initial_mem_(ir_graph *irg, ir_node *node)
208 {
209         set_irn_n(irg->anchor, anchor_initial_mem, node);
210 }
211
212 static inline ir_node *get_irg_args_(const ir_graph *irg)
213 {
214         return get_irn_n(irg->anchor, anchor_args);
215 }
216
217 static inline void set_irg_args_(ir_graph *irg, ir_node *node)
218 {
219         set_irn_n(irg->anchor, anchor_args, node);
220 }
221
222 static inline ir_node *get_irg_no_mem_(const ir_graph *irg)
223 {
224         return get_irn_n(irg->anchor, anchor_no_mem);
225 }
226
227 static inline void set_irg_no_mem_(ir_graph *irg, ir_node *node)
228 {
229         set_irn_n(irg->anchor, anchor_no_mem, node);
230 }
231
232 static inline ir_entity *get_irg_entity_(const ir_graph *irg)
233 {
234         return irg->ent;
235 }
236
237 static inline void set_irg_entity_(ir_graph *irg, ir_entity *ent)
238 {
239         irg->ent = ent;
240 }
241
242 static inline ir_type *get_irg_frame_type_(ir_graph *irg)
243 {
244         assert(irg->frame_type);
245         return irg->frame_type;
246 }
247
248 static inline void set_irg_frame_type_(ir_graph *irg, ir_type *ftp)
249 {
250         assert(is_frame_type(ftp));
251         irg->frame_type = ftp;
252 }
253
254 static inline op_pin_state get_irg_pinned_(const ir_graph *irg)
255 {
256         return irg->irg_pinned_state;
257 }
258
259 static inline irg_callee_info_state get_irg_callee_info_state_(const ir_graph *irg)
260 {
261         return irg->callee_info_state;
262 }
263
264 static inline void set_irg_callee_info_state_(ir_graph *irg, irg_callee_info_state s)
265 {
266         irg_callee_info_state irp_state = get_irp_callee_info_state();
267
268         irg->callee_info_state = s;
269
270         /* I could compare ... but who knows? */
271         if ((irp_state == irg_callee_info_consistent)  ||
272             ((irp_state == irg_callee_info_inconsistent) && (s == irg_callee_info_none)))
273                 set_irp_callee_info_state(s);
274 }
275
276 static inline void set_irg_link_(ir_graph *irg, void *thing)
277 {
278         irg->link = thing;
279 }
280
281 static inline void *get_irg_link_(const ir_graph *irg)
282 {
283         return irg->link;
284 }
285
286 static inline ir_visited_t get_irg_visited_(const ir_graph *irg)
287 {
288         return irg->visited;
289 }
290
291 static inline ir_visited_t get_irg_block_visited_(const ir_graph *irg)
292 {
293         return irg->block_visited;
294 }
295
296 static inline void set_irg_block_visited_(ir_graph *irg, ir_visited_t visited)
297 {
298         irg->block_visited = visited;
299 }
300
301 static inline void inc_irg_block_visited_(ir_graph *irg)
302 {
303         ++irg->block_visited;
304 }
305
306 static inline void dec_irg_block_visited_(ir_graph *irg)
307 {
308         --irg->block_visited;
309 }
310
311 /* Return the floating point model of this graph. */
312 static inline unsigned get_irg_fp_model_(const ir_graph *irg)
313 {
314         return irg->fp_model;
315 }
316
317 static inline int irg_is_constrained_(const ir_graph *irg,
318                                       ir_graph_constraints_t constraints)
319 {
320         return (irg->constraints & constraints) == constraints;
321 }
322
323 static inline void add_irg_properties_(ir_graph *irg,
324                                        ir_graph_properties_t props)
325 {
326         irg->properties |= props;
327 }
328
329 static inline void clear_irg_properties_(ir_graph *irg,
330                                     ir_graph_properties_t props)
331 {
332         irg->properties &= ~props;
333 }
334
335 static inline int irg_has_properties_(const ir_graph *irg,
336                                       ir_graph_properties_t props)
337 {
338         return (irg->properties & props) == props;
339 }
340
341 /**
342  * Allocates a new idx in the irg for the node and adds the irn to the idx -> irn map.
343  * @param irg The graph.
344  * @param irn The node.
345  * @return    The index allocated for the node.
346  */
347 static inline unsigned irg_register_node_idx(ir_graph *irg, ir_node *irn)
348 {
349         unsigned idx = irg->last_node_idx++;
350         if (idx >= (unsigned)ARR_LEN(irg->idx_irn_map))
351                 ARR_RESIZE(ir_node *, irg->idx_irn_map, idx + 1);
352
353         irg->idx_irn_map[idx] = irn;
354         return idx;
355 }
356
357 /**
358  * Kill a node from the irg. BEWARE: this kills
359  * all later created nodes.
360  */
361 static inline void irg_kill_node(ir_graph *irg, ir_node *n)
362 {
363         unsigned idx = get_irn_idx(n);
364         assert(idx + 1 == irg->last_node_idx);
365
366         if (idx + 1 == irg->last_node_idx)
367                 --irg->last_node_idx;
368         irg->idx_irn_map[idx] = NULL;
369         obstack_free(&irg->obst, n);
370 }
371
372 /**
373  * Get the node for an index.
374  * @param irg The graph.
375  * @param idx The index you want the node for.
376  * @return    The node with that index or NULL, if there is no node with that index.
377  * @note      The node you got might be dead.
378  */
379 static inline ir_node *get_idx_irn_(const ir_graph *irg, unsigned idx)
380 {
381         assert(idx < (unsigned) ARR_LEN(irg->idx_irn_map));
382         return irg->idx_irn_map[idx];
383 }
384
385 /**
386  * Return the number of anchors in this graph.
387  */
388 static inline int get_irg_n_anchors(const ir_graph *irg)
389 {
390         return get_irn_arity(irg->anchor);
391 }
392
393 /**
394  * Return anchor for given index
395  */
396 static inline ir_node *get_irg_anchor(const ir_graph *irg, int idx)
397 {
398         return get_irn_n(irg->anchor, idx);
399 }
400
401 /**
402  * Set anchor for given index
403  */
404 static inline void set_irg_anchor(ir_graph *irg, int idx, ir_node *irn)
405 {
406         set_irn_n(irg->anchor, idx, irn);
407 }
408
409 #endif