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