Some more cleanup: Put the return type and other specifiers on the same line as the...
[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  * @version  $Id$
25  */
26 #ifndef FIRM_IR_IRGRAPH_T_H
27 #define FIRM_IR_IRGRAPH_T_H
28
29 #include "firm_types.h"
30 #include "irgraph.h"
31
32 #include "irtypes.h"
33 #include "irprog.h"
34 #include "pseudo_irg.h"
35 #include "type_t.h"
36 #include "entity_t.h"
37 #include "iredgekinds.h"
38
39 #include "irloop.h"
40
41 #include "obst.h"
42 #include "pset.h"
43 #include "set.h"
44
45 /** Suffix that is added to every frame type. */
46 #define FRAME_TP_SUFFIX "frame_tp"
47
48 /**
49  * Initializes the graph construction module.
50  */
51 void firm_init_irgraph(void);
52
53 /**
54  * Set the number of locals for a given graph.
55  *
56  * @param irg    the graph
57  * @param n_loc  number of locals
58  */
59 void irg_set_nloc(ir_graph *res, int n_loc);
60
61 /**
62  * Internal constructor that does not add to irp_irgs or the like.
63  */
64 ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc);
65
66 /**
67  * Make a rudimentary ir graph for the constant code.
68  * Must look like a correct irg, spare everything else.
69  */
70 ir_graph *new_const_code_irg(void);
71
72 /**
73  * Create a new graph that is a copy of a given one.
74  * Uses the link fields of the original graphs.
75  *
76  * @param irg  The graph that must be copied.
77  */
78 ir_graph *create_irg_copy(ir_graph *irg);
79
80 /**
81  * Set the op_pin_state_pinned state of a graph.
82  *
83  * @param irg     the IR graph
84  * @param p       new pin state
85  */
86 void set_irg_pinned(ir_graph *irg, op_pin_state p);
87
88 /** Returns the obstack associated with the graph. */
89 struct obstack *get_irg_obstack(const ir_graph *irg);
90
91 /**
92  * Returns true if the node n is allocated on the storage of graph irg.
93  *
94  * @param irg   the IR graph
95  * @param n the IR node
96  */
97 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n);
98
99 /*-------------------------------------------------------------------*/
100 /* inline functions for graphs                                       */
101 /*-------------------------------------------------------------------*/
102
103 static inline int _is_ir_graph(const void *thing)
104 {
105         return (get_kind(thing) == k_ir_graph);
106 }
107
108 /** Returns the start block of a graph. */
109 static inline ir_node *_get_irg_start_block(const ir_graph *irg)
110 {
111         return get_irn_intra_n(irg->anchor, anchor_start_block);
112 }
113
114 static inline void _set_irg_start_block(ir_graph *irg, ir_node *node)
115 {
116         set_irn_n(irg->anchor, anchor_start_block, node);
117 }
118
119 static inline ir_node *_get_irg_start(const ir_graph *irg)
120 {
121         return get_irn_intra_n(irg->anchor, anchor_start);
122 }
123
124 static inline void _set_irg_start(ir_graph *irg, ir_node *node)
125 {
126         set_irn_n(irg->anchor, anchor_start, node);
127 }
128
129 static inline ir_node *_get_irg_end_block(const ir_graph *irg)
130 {
131         return get_irn_intra_n(irg->anchor, anchor_end_block);
132 }
133
134 static inline void _set_irg_end_block(ir_graph *irg, ir_node *node)
135 {
136         set_irn_n(irg->anchor, -1, node);
137         set_irn_n(irg->anchor, anchor_end_block, node);
138 }
139
140 static inline ir_node *_get_irg_end(const ir_graph *irg)
141 {
142         return get_irn_intra_n(irg->anchor, anchor_end);
143 }
144
145 static inline void _set_irg_end(ir_graph *irg, ir_node *node)
146 {
147         set_irn_n(irg->anchor, anchor_end, node);
148 }
149
150 static inline ir_node *_get_irg_end_reg(const ir_graph *irg)
151 {
152         return get_irn_intra_n(irg->anchor, anchor_end_reg);
153 }
154
155 static inline void _set_irg_end_reg(ir_graph *irg, ir_node *node)
156 {
157         set_irn_n(irg->anchor, anchor_end_reg, node);
158 }
159
160 static inline ir_node *_get_irg_end_except(const ir_graph *irg)
161 {
162         return get_irn_intra_n(irg->anchor, anchor_end_except);
163 }
164
165 static inline void _set_irg_end_except(ir_graph *irg, ir_node *node)
166 {
167         set_irn_n(irg->anchor, anchor_end_except, node);
168 }
169
170 static inline ir_node *_get_irg_initial_exec(const ir_graph *irg)
171 {
172         return get_irn_intra_n(irg->anchor, anchor_initial_exec);
173 }
174
175 static inline void _set_irg_initial_exec(ir_graph *irg, ir_node *node)
176 {
177         set_irn_n(irg->anchor, anchor_initial_exec, node);
178 }
179
180 static inline ir_node *_get_irg_frame(const ir_graph *irg)
181 {
182         return get_irn_intra_n(irg->anchor, anchor_frame);
183 }
184
185 static inline void _set_irg_frame(ir_graph *irg, ir_node *node)
186 {
187         set_irn_n(irg->anchor, anchor_frame, node);
188 }
189
190 static inline ir_node *_get_irg_tls(const ir_graph *irg)
191 {
192         return get_irn_intra_n(irg->anchor, anchor_tls);
193 }
194
195 static inline void _set_irg_tls(ir_graph *irg, ir_node *node)
196 {
197         set_irn_n(irg->anchor, anchor_tls, node);
198 }
199
200 static inline ir_node *_get_irg_initial_mem(const ir_graph *irg)
201 {
202         return get_irn_intra_n(irg->anchor, anchor_initial_mem);
203 }
204
205 static inline void _set_irg_initial_mem(ir_graph *irg, ir_node *node)
206 {
207         set_irn_n(irg->anchor, anchor_initial_mem, node);
208 }
209
210 static inline ir_node *_get_irg_args(const ir_graph *irg)
211 {
212         return get_irn_intra_n(irg->anchor, anchor_args);
213 }
214
215 static inline void _set_irg_args(ir_graph *irg, ir_node *node)
216 {
217         set_irn_n(irg->anchor, anchor_args, node);
218 }
219
220 static inline ir_node *_get_irg_bad(const ir_graph *irg)
221 {
222         return get_irn_intra_n(irg->anchor, anchor_bad);
223 }
224
225 static inline void _set_irg_bad(ir_graph *irg, ir_node *node)
226 {
227         set_irn_n(irg->anchor, anchor_bad, node);
228 }
229
230 static inline ir_node * _get_irg_no_mem(const ir_graph *irg)
231 {
232         return get_irn_intra_n(irg->anchor, anchor_no_mem);
233 }
234
235 static inline void _set_irg_no_mem(ir_graph *irg, ir_node *node)
236 {
237         set_irn_n(irg->anchor, anchor_no_mem, node);
238 }
239
240 static inline ir_node *_get_irg_current_block(const ir_graph *irg)
241 {
242         return irg->current_block;
243 }
244
245 static inline void _set_irg_current_block(ir_graph *irg, ir_node *node)
246 {
247         irg->current_block = node;
248 }
249
250 static inline ir_entity *_get_irg_entity(const ir_graph *irg)
251 {
252         assert(irg);
253         return irg->ent;
254 }
255
256 static inline void _set_irg_entity(ir_graph *irg, ir_entity *ent)
257 {
258         irg->ent = ent;
259 }
260
261 static inline ir_type *_get_irg_frame_type(ir_graph *irg)
262 {
263         assert(irg->frame_type);
264         return irg->frame_type;
265 }
266
267 static inline void _set_irg_frame_type(ir_graph *irg, ir_type *ftp)
268 {
269         assert(is_frame_type(ftp));
270         irg->frame_type = ftp;
271 }
272
273 static inline struct obstack *_get_irg_obstack(const ir_graph *irg)
274 {
275         return irg->obst;
276 }
277
278
279 static inline irg_phase_state _get_irg_phase_state(const ir_graph *irg)
280 {
281         return irg->phase_state;
282 }
283
284 static inline void _set_irg_phase_state(ir_graph *irg, irg_phase_state state)
285 {
286         irg->phase_state = state;
287 }
288
289 static inline op_pin_state _get_irg_pinned(const ir_graph *irg)
290 {
291         return irg->irg_pinned_state;
292 }
293
294 static inline irg_outs_state _get_irg_outs_state(const ir_graph *irg)
295 {
296         return irg->outs_state;
297 }
298
299 static inline void _set_irg_outs_inconsistent(ir_graph *irg)
300 {
301         if (irg->outs_state == outs_consistent)
302                 irg->outs_state = outs_inconsistent;
303 }
304
305 static inline irg_extblk_state _get_irg_extblk_state(const ir_graph *irg)
306 {
307   return irg->extblk_state;
308 }
309
310 static inline void _set_irg_extblk_inconsistent(ir_graph *irg)
311 {
312         if (irg->extblk_state == extblk_valid)
313                 irg->extblk_state = extblk_invalid;
314 }
315
316 static inline irg_dom_state _get_irg_dom_state(const ir_graph *irg)
317 {
318         return irg->dom_state;
319 }
320
321 static inline irg_dom_state _get_irg_postdom_state(const ir_graph *irg)
322 {
323         return irg->pdom_state;
324 }
325
326 static inline void _set_irg_doms_inconsistent(ir_graph *irg)
327 {
328         if (irg->dom_state != dom_none)
329                 irg->dom_state = dom_inconsistent;
330         if (irg->pdom_state != dom_none)
331                 irg->pdom_state = dom_inconsistent;
332 }
333
334 static inline irg_loopinfo_state _get_irg_loopinfo_state(const ir_graph *irg)
335 {
336         return irg->loopinfo_state;
337 }
338
339 static inline void _set_irg_loopinfo_state(ir_graph *irg, irg_loopinfo_state s)
340 {
341   irg->loopinfo_state = s;
342 }
343
344 static inline void _set_irg_loopinfo_inconsistent(ir_graph *irg)
345 {
346         irg->loopinfo_state &= ~loopinfo_valid;
347 }
348
349 static inline void _set_irg_pinned(ir_graph *irg, op_pin_state p)
350 {
351         irg->irg_pinned_state = p;
352 }
353
354 static inline irg_callee_info_state _get_irg_callee_info_state(const ir_graph *irg)
355 {
356         return irg->callee_info_state;
357 }
358
359 static inline void _set_irg_callee_info_state(ir_graph *irg, irg_callee_info_state s)
360 {
361         irg_callee_info_state irp_state = get_irp_callee_info_state();
362
363         irg->callee_info_state = s;
364
365         /* I could compare ... but who knows? */
366         if ((irp_state == irg_callee_info_consistent)  ||
367             ((irp_state == irg_callee_info_inconsistent) && (s == irg_callee_info_none)))
368                 set_irp_callee_info_state(s);
369 }
370
371 static inline irg_inline_property _get_irg_inline_property(const ir_graph *irg)
372 {
373         return irg->inline_property;
374 }
375
376 static inline void _set_irg_inline_property(ir_graph *irg, irg_inline_property s)
377 {
378         irg->inline_property = s;
379 }
380
381 static inline unsigned _get_irg_additional_properties(const ir_graph *irg)
382 {
383         if (irg->additional_properties & mtp_property_inherited)
384                 return get_method_additional_properties(get_entity_type(irg->ent));
385         return irg->additional_properties;
386 }
387
388 static inline void _set_irg_additional_properties(ir_graph *irg, unsigned mask)
389 {
390         irg->additional_properties = mask & ~mtp_property_inherited;
391 }
392
393 static inline void _set_irg_additional_property(ir_graph *irg, mtp_additional_property flag)
394 {
395         unsigned prop = irg->additional_properties;
396
397         if (prop & mtp_property_inherited)
398                 prop = get_method_additional_properties(get_entity_type(irg->ent));
399         irg->additional_properties = prop | flag;
400 }
401
402 static inline void _set_irg_link(ir_graph *irg, void *thing)
403 {
404         irg->link = thing;
405 }
406
407 static inline void *_get_irg_link(const ir_graph *irg)
408 {
409         return irg->link;
410 }
411
412 static inline ir_visited_t _get_irg_visited(const ir_graph *irg)
413 {
414         return irg->visited;
415 }
416
417 static inline ir_visited_t _get_irg_block_visited(const ir_graph *irg)
418 {
419         return irg->block_visited;
420 }
421
422 static inline void _set_irg_block_visited(ir_graph *irg, ir_visited_t visited)
423 {
424         irg->block_visited = visited;
425 }
426
427 static inline void _inc_irg_block_visited(ir_graph *irg)
428 {
429         ++irg->block_visited;
430 }
431
432 static inline void _dec_irg_block_visited(ir_graph *irg)
433 {
434         --irg->block_visited;
435 }
436
437 static inline unsigned _get_irg_estimated_node_cnt(const ir_graph *irg)
438 {
439         return irg->estimated_node_count;
440 }
441
442 /* Return the floating point model of this graph. */
443 static inline unsigned _get_irg_fp_model(const ir_graph *irg)
444 {
445         return irg->fp_model;
446 }
447
448 static inline void _set_irg_state(ir_graph *irg, ir_graph_state_t state)
449 {
450         irg->state |= state;
451 }
452
453 static inline void _clear_irg_state(ir_graph *irg, ir_graph_state_t state)
454 {
455         irg->state &= ~state;
456 }
457
458 static inline int _is_irg_state(const ir_graph *irg, ir_graph_state_t state)
459 {
460         return (irg->state & state) == state;
461 }
462
463 /**
464  * Allocates a new idx in the irg for the node and adds the irn to the idx -> irn map.
465  * @param irg The graph.
466  * @param irn The node.
467  * @return    The index allocated for the node.
468  */
469 static inline unsigned irg_register_node_idx(ir_graph *irg, ir_node *irn) {
470         unsigned idx = irg->last_node_idx++;
471         if (idx >= (unsigned)ARR_LEN(irg->idx_irn_map))
472                 ARR_RESIZE(ir_node *, irg->idx_irn_map, idx + 1);
473
474         irg->idx_irn_map[idx] = irn;
475         return idx;
476 }
477
478 /**
479  * Kill a node from the irg. BEWARE: this kills
480  * all later created nodes.
481  */
482 static inline void irg_kill_node(ir_graph *irg, ir_node *n)
483 {
484         unsigned idx = get_irn_idx(n);
485         assert(idx + 1 == irg->last_node_idx);
486
487         if (idx + 1 == irg->last_node_idx)
488                 --irg->last_node_idx;
489         irg->idx_irn_map[idx] = NULL;
490         obstack_free(irg->obst, n);
491 }
492
493 /**
494  * Get the node for an index.
495  * @param irg The graph.
496  * @param idx The index you want the node for.
497  * @return    The node with that index or NULL, if there is no node with that index.
498  * @note      The node you got might be dead.
499  */
500 static inline ir_node *_get_idx_irn(ir_graph *irg, unsigned idx)
501 {
502         assert(idx < (unsigned) ARR_LEN(irg->idx_irn_map));
503         return irg->idx_irn_map[idx];
504 }
505
506 /**
507  * Return the number of anchors in this graph.
508  */
509 static inline int get_irg_n_anchors(const ir_graph *irg)
510 {
511         return get_irn_arity(irg->anchor);
512 }
513
514 /**
515  * Return anchor for given index
516  */
517 static inline ir_node *get_irg_anchor(const ir_graph *irg, int idx)
518 {
519         return get_irn_intra_n(irg->anchor, idx);
520 }
521
522 /**
523  * Set anchor for given index
524  */
525 static inline void set_irg_anchor(ir_graph *irg, int idx, ir_node *irn)
526 {
527         set_irn_n(irg->anchor, idx, irn);
528 }
529
530 #ifdef INTERPROCEDURAL_VIEW
531 extern int firm_interprocedural_view;
532
533 static inline int _get_interprocedural_view(void)
534 {
535         return firm_interprocedural_view;
536 }
537
538 #define get_interprocedural_view()            _get_interprocedural_view()
539 #endif
540
541 #define is_ir_graph(thing)                    _is_ir_graph(thing)
542 #define get_irg_start_block(irg)              _get_irg_start_block(irg)
543 #define set_irg_start_block(irg, node)        _set_irg_start_block(irg, node)
544 #define get_irg_start(irg)                    _get_irg_start(irg)
545 #define set_irg_start(irg, node)              _set_irg_start(irg, node)
546 #define get_irg_end_block(irg)                _get_irg_end_block(irg)
547 #define set_irg_end_block(irg, node)          _set_irg_end_block(irg, node)
548 #define get_irg_end(irg)                      _get_irg_end(irg)
549 #define set_irg_end(irg, node)                _set_irg_end(irg, node)
550 #define get_irg_end_reg(irg)                  _get_irg_end_reg(irg)
551 #define set_irg_end_reg(irg, node)            _set_irg_end_reg(irg, node)
552 #define get_irg_end_except(irg)               _get_irg_end_except(irg)
553 #define set_irg_end_except(irg, node)         _set_irg_end_except(irg, node)
554 #define get_irg_initial_exec(irg)             _get_irg_initial_exec(irg)
555 #define set_irg_initial_exec(irg, node)       _set_irg_initial_exec(irg, node)
556 #define get_irg_frame(irg)                    _get_irg_frame(irg)
557 #define set_irg_frame(irg, node)              _set_irg_frame(irg, node)
558 #define get_irg_tls(irg)                      _get_irg_tls(irg)
559 #define set_irg_tls(irg, node)                _set_irg_tls(irg, node)
560 #define get_irg_initial_mem(irg)              _get_irg_initial_mem(irg)
561 #define set_irg_initial_mem(irg, node)        _set_irg_initial_mem(irg, node)
562 #define get_irg_args(irg)                     _get_irg_args(irg)
563 #define set_irg_args(irg, node)               _set_irg_args(irg, node)
564 #define get_irg_bad(irg)                      _get_irg_bad(irg)
565 #define set_irg_bad(irg, node)                _set_irg_bad(irg, node)
566 #define get_irg_no_mem(irg)                   _get_irg_no_mem(irg)
567 #define set_irn_no_mem(irg, node)             _set_irn_no_mem(irg, node)
568 #define get_irg_current_block(irg)            _get_irg_current_block(irg)
569 #define set_irg_current_block(irg, node)      _set_irg_current_block(irg, node)
570 #define get_irg_entity(irg)                   _get_irg_entity(irg)
571 #define set_irg_entity(irg, ent)              _set_irg_entity(irg, ent)
572 #define get_irg_frame_type(irg)               _get_irg_frame_type(irg)
573 #define set_irg_frame_type(irg, ftp)          _set_irg_frame_type(irg, ftp)
574 #define get_irg_obstack(irg)                  _get_irg_obstack(irg)
575 #define get_irg_phase_state(irg)              _get_irg_phase_state(irg)
576 #define set_irg_phase_state(irg, state)       _set_irg_phase_state(irg, state)
577 #define get_irg_pinned(irg)                   _get_irg_pinned(irg)
578 #define get_irg_outs_state(irg)               _get_irg_outs_state(irg)
579 #define set_irg_outs_inconsistent(irg)        _set_irg_outs_inconsistent(irg)
580 #define get_irg_extblk_state(irg)             _get_irg_extblk_state(irg)
581 #define set_irg_extblk_inconsistent(irg)      _set_irg_extblk_inconsistent(irg)
582 #define get_irg_dom_state(irg)                _get_irg_dom_state(irg)
583 #define get_irg_postdom_state(irg)            _get_irg_postdom_state(irg)
584 #define set_irg_doms_inconsistent(irg)        _set_irg_doms_inconsistent(irg)
585 #define get_irg_loopinfo_state(irg)           _get_irg_loopinfo_state(irg)
586 #define set_irg_loopinfo_state(irg, s)        _set_irg_loopinfo_state(irg, s)
587 #define set_irg_loopinfo_inconsistent(irg)    _set_irg_loopinfo_inconsistent(irg)
588 #define set_irg_pinned(irg, p)                _set_irg_pinned(irg, p)
589 #define get_irg_callee_info_state(irg)        _get_irg_callee_info_state(irg)
590 #define set_irg_callee_info_state(irg, s)     _set_irg_callee_info_state(irg, s)
591 #define get_irg_inline_property(irg)          _get_irg_inline_property(irg)
592 #define set_irg_inline_property(irg, s)       _set_irg_inline_property(irg, s)
593 #define get_irg_additional_properties(irg)    _get_irg_additional_properties(irg)
594 #define set_irg_additional_properties(irg, m) _set_irg_additional_properties(irg, m)
595 #define set_irg_additional_property(irg, f)   _set_irg_additional_property(irg, f)
596 #define set_irg_link(irg, thing)              _set_irg_link(irg, thing)
597 #define get_irg_link(irg)                     _get_irg_link(irg)
598 #define get_irg_visited(irg)                  _get_irg_visited(irg)
599 #define get_irg_block_visited(irg)            _get_irg_block_visited(irg)
600 #define set_irg_block_visited(irg, v)         _set_irg_block_visited(irg, v)
601 #define inc_irg_block_visited(irg)            _inc_irg_block_visited(irg)
602 #define dec_irg_block_visited(irg)            _dec_irg_block_visited(irg)
603 #define get_irg_estimated_node_cnt(irg)       _get_irg_estimated_node_cnt(irg)
604 #define get_irg_fp_model(irg)                 _get_irg_fp_model(irg)
605 #define get_idx_irn(irg, idx)                 _get_idx_irn(irg, idx)
606 #define set_irg_state(irg, state)             _set_irg_state(irg, state)
607 #define clear_irg_state(irg, state)           _clear_irg_state(irg, state)
608 #define is_irg_state(irg, state)              _is_irg_state(irg, state)
609
610 #endif