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