2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief Entry point to the representation of procedure code -- internal header.
23 * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
26 #ifndef FIRM_IR_IRGRAPH_T_H
27 #define FIRM_IR_IRGRAPH_T_H
29 #include "firm_types.h"
32 #include "firm_common_t.h"
35 #include "pseudo_irg.h"
38 #include "iredgekinds.h"
46 /** Suffix that is added to every frame type. */
47 #define FRAME_TP_SUFFIX "frame_tp"
50 * Initializes the graph construction module.
52 void firm_init_irgraph(void);
55 * Set the number of locals for a given graph.
57 * @param irg the graph
58 * @param n_loc number of locals
60 void irg_set_nloc(ir_graph *res, int n_loc);
63 * Internal constructor that does not add to irp_irgs or the like.
65 ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc);
68 * Make a rudimentary ir graph for the constant code.
69 * Must look like a correct irg, spare everything else.
71 ir_graph *new_const_code_irg(void);
74 * Create a new graph that is a copy of a given one.
75 * Uses the link fields of the original graphs.
77 * @param irg The graph that must be copied.
79 ir_graph *create_irg_copy(ir_graph *irg);
82 * Set the op_pin_state_pinned state of a graph.
84 * @param irg the IR graph
85 * @param p new pin state
87 void set_irg_pinned(ir_graph *irg, op_pin_state p);
89 /** Returns the obstack associated with the graph. */
90 struct obstack *get_irg_obstack(const ir_graph *irg);
93 * Returns true if the node n is allocated on the storage of graph irg.
95 * @param irg the IR graph
96 * @param n the IR node
98 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n);
100 /*-------------------------------------------------------------------*/
101 /* inline functions for graphs */
102 /*-------------------------------------------------------------------*/
105 _is_ir_graph(const void *thing) {
106 return (get_kind(thing) == k_ir_graph);
109 /** Returns the start block of a graph. */
110 static inline ir_node *
111 _get_irg_start_block(const ir_graph *irg) {
112 return get_irn_intra_n(irg->anchor, anchor_start_block);
116 _set_irg_start_block(ir_graph *irg, ir_node *node) {
117 set_irn_n(irg->anchor, anchor_start_block, node);
120 static inline ir_node *
121 _get_irg_start(const ir_graph *irg) {
122 return get_irn_intra_n(irg->anchor, anchor_start);
126 _set_irg_start(ir_graph *irg, ir_node *node) {
127 set_irn_n(irg->anchor, anchor_start, node);
130 static inline ir_node *
131 _get_irg_end_block(const ir_graph *irg) {
132 return get_irn_intra_n(irg->anchor, anchor_end_block);
136 _set_irg_end_block(ir_graph *irg, ir_node *node) {
137 set_irn_n(irg->anchor, -1, node);
138 set_irn_n(irg->anchor, anchor_end_block, node);
141 static inline ir_node *
142 _get_irg_end(const ir_graph *irg) {
143 return get_irn_intra_n(irg->anchor, anchor_end);
147 _set_irg_end(ir_graph *irg, ir_node *node) {
148 set_irn_n(irg->anchor, anchor_end, node);
151 static inline ir_node *
152 _get_irg_end_reg(const ir_graph *irg) {
153 return get_irn_intra_n(irg->anchor, anchor_end_reg);
157 _set_irg_end_reg(ir_graph *irg, ir_node *node) {
158 set_irn_n(irg->anchor, anchor_end_reg, node);
161 static inline ir_node *
162 _get_irg_end_except(const ir_graph *irg) {
163 return get_irn_intra_n(irg->anchor, anchor_end_except);
167 _set_irg_end_except(ir_graph *irg, ir_node *node) {
168 set_irn_n(irg->anchor, anchor_end_except, node);
171 static inline ir_node *
172 _get_irg_initial_exec(const ir_graph *irg) {
173 return get_irn_intra_n(irg->anchor, anchor_initial_exec);
177 _set_irg_initial_exec(ir_graph *irg, ir_node *node) {
178 set_irn_n(irg->anchor, anchor_initial_exec, node);
181 static inline ir_node *
182 _get_irg_frame(const ir_graph *irg) {
183 return get_irn_intra_n(irg->anchor, anchor_frame);
187 _set_irg_frame(ir_graph *irg, ir_node *node) {
188 set_irn_n(irg->anchor, anchor_frame, node);
191 static inline ir_node *
192 _get_irg_tls(const ir_graph *irg) {
193 return get_irn_intra_n(irg->anchor, anchor_tls);
197 _set_irg_tls(ir_graph *irg, ir_node *node) {
198 set_irn_n(irg->anchor, anchor_tls, node);
201 static inline ir_node *
202 _get_irg_initial_mem(const ir_graph *irg) {
203 return get_irn_intra_n(irg->anchor, anchor_initial_mem);
207 _set_irg_initial_mem(ir_graph *irg, ir_node *node) {
208 set_irn_n(irg->anchor, anchor_initial_mem, node);
211 static inline ir_node *
212 _get_irg_args(const ir_graph *irg) {
213 return get_irn_intra_n(irg->anchor, anchor_args);
217 _set_irg_args(ir_graph *irg, ir_node *node) {
218 set_irn_n(irg->anchor, anchor_args, node);
221 static inline ir_node *
222 _get_irg_bad(const ir_graph *irg) {
223 return get_irn_intra_n(irg->anchor, anchor_bad);
227 _set_irg_bad(ir_graph *irg, ir_node *node) {
228 set_irn_n(irg->anchor, anchor_bad, node);
231 static inline ir_node *
232 _get_irg_no_mem(const ir_graph *irg) {
233 return get_irn_intra_n(irg->anchor, anchor_no_mem);
237 _set_irg_no_mem(ir_graph *irg, ir_node *node) {
238 set_irn_n(irg->anchor, anchor_no_mem, node);
241 static inline ir_node *
242 _get_irg_current_block(const ir_graph *irg) {
243 return irg->current_block;
247 _set_irg_current_block(ir_graph *irg, ir_node *node) {
248 irg->current_block = node;
251 static inline ir_entity *
252 _get_irg_entity(const ir_graph *irg) {
253 assert(irg && irg->ent);
258 _set_irg_entity(ir_graph *irg, ir_entity *ent) {
262 static inline ir_type *
263 _get_irg_frame_type(ir_graph *irg) {
264 assert(irg && irg->frame_type);
265 return irg->frame_type = skip_tid(irg->frame_type);
269 _set_irg_frame_type(ir_graph *irg, ir_type *ftp) {
270 assert(is_frame_type(ftp));
271 irg->frame_type = ftp;
274 static inline struct obstack *
275 _get_irg_obstack(const ir_graph *irg) {
280 static inline irg_phase_state
281 _get_irg_phase_state(const ir_graph *irg) {
282 return irg->phase_state;
286 _set_irg_phase_state(ir_graph *irg, irg_phase_state state) {
287 irg->phase_state = state;
290 static inline op_pin_state
291 _get_irg_pinned(const ir_graph *irg) {
292 return irg->irg_pinned_state;
295 static inline irg_outs_state
296 _get_irg_outs_state(const ir_graph *irg) {
297 return irg->outs_state;
301 _set_irg_outs_inconsistent(ir_graph *irg) {
302 if (irg->outs_state == outs_consistent)
303 irg->outs_state = outs_inconsistent;
306 static inline irg_extblk_state
307 _get_irg_extblk_state(const ir_graph *irg) {
308 return irg->extblk_state;
312 _set_irg_extblk_inconsistent(ir_graph *irg) {
313 if (irg->extblk_state == extblk_valid)
314 irg->extblk_state = extblk_invalid;
317 static inline irg_dom_state
318 _get_irg_dom_state(const ir_graph *irg) {
319 return irg->dom_state;
322 static inline irg_dom_state
323 _get_irg_postdom_state(const ir_graph *irg) {
324 return irg->pdom_state;
328 _set_irg_doms_inconsistent(ir_graph *irg) {
329 if (irg->dom_state != dom_none)
330 irg->dom_state = dom_inconsistent;
331 if (irg->pdom_state != dom_none)
332 irg->pdom_state = dom_inconsistent;
335 static inline irg_loopinfo_state
336 _get_irg_loopinfo_state(const ir_graph *irg) {
337 return irg->loopinfo_state;
341 _set_irg_loopinfo_state(ir_graph *irg, irg_loopinfo_state s) {
342 irg->loopinfo_state = s;
346 _set_irg_loopinfo_inconsistent(ir_graph *irg) {
347 irg->loopinfo_state &= ~loopinfo_valid;
351 _set_irg_pinned(ir_graph *irg, op_pin_state p) {
352 irg->irg_pinned_state = p;
355 static inline irg_callee_info_state
356 _get_irg_callee_info_state(const ir_graph *irg) {
357 return irg->callee_info_state;
361 _set_irg_callee_info_state(ir_graph *irg, irg_callee_info_state s) {
362 irg_callee_info_state irp_state = get_irp_callee_info_state();
364 irg->callee_info_state = s;
366 /* I could compare ... but who knows? */
367 if ((irp_state == irg_callee_info_consistent) ||
368 ((irp_state == irg_callee_info_inconsistent) && (s == irg_callee_info_none)))
369 set_irp_callee_info_state(s);
372 static inline irg_inline_property
373 _get_irg_inline_property(const ir_graph *irg) {
374 return irg->inline_property;
378 _set_irg_inline_property(ir_graph *irg, irg_inline_property s) {
379 irg->inline_property = s;
382 static inline unsigned
383 _get_irg_additional_properties(const ir_graph *irg) {
384 if (irg->additional_properties & mtp_property_inherited)
385 return get_method_additional_properties(get_entity_type(irg->ent));
386 return irg->additional_properties;
390 _set_irg_additional_properties(ir_graph *irg, unsigned mask) {
391 irg->additional_properties = mask & ~mtp_property_inherited;
395 _set_irg_additional_property(ir_graph *irg, mtp_additional_property flag) {
396 unsigned prop = irg->additional_properties;
398 if (prop & mtp_property_inherited)
399 prop = get_method_additional_properties(get_entity_type(irg->ent));
400 irg->additional_properties = prop | flag;
404 _set_irg_link(ir_graph *irg, void *thing) {
409 _get_irg_link(const ir_graph *irg) {
413 static inline ir_visited_t
414 _get_irg_visited(const ir_graph *irg) {
418 static inline ir_visited_t
419 _get_irg_block_visited(const ir_graph *irg) {
420 return irg->block_visited;
424 _set_irg_block_visited(ir_graph *irg, ir_visited_t visited) {
425 irg->block_visited = visited;
429 _inc_irg_block_visited(ir_graph *irg) {
430 ++irg->block_visited;
434 _dec_irg_block_visited(ir_graph *irg) {
435 --irg->block_visited;
438 static inline unsigned
439 _get_irg_estimated_node_cnt(const ir_graph *irg) {
440 return irg->estimated_node_count;
443 /* Return the floating point model of this graph. */
444 static inline unsigned
445 _get_irg_fp_model(const ir_graph *irg) {
446 return irg->fp_model;
449 static inline void _set_irg_state(ir_graph *irg, ir_graph_state_t state)
454 static inline void _clear_irg_state(ir_graph *irg, ir_graph_state_t state)
456 irg->state &= ~state;
459 static inline int _is_irg_state(const ir_graph *irg, ir_graph_state_t state)
461 return (irg->state & state) == state;
465 * Allocates a new idx in the irg for the node and adds the irn to the idx -> irn map.
466 * @param irg The graph.
467 * @param irn The node.
468 * @return The index allocated for the node.
470 static inline unsigned irg_register_node_idx(ir_graph *irg, ir_node *irn) {
471 unsigned idx = irg->last_node_idx++;
472 if (idx >= (unsigned)ARR_LEN(irg->idx_irn_map))
473 ARR_RESIZE(ir_node *, irg->idx_irn_map, idx + 1);
475 irg->idx_irn_map[idx] = irn;
480 * Kill a node from the irg. BEWARE: this kills
481 * all later created nodes.
484 irg_kill_node(ir_graph *irg, ir_node *n) {
485 unsigned idx = get_irn_idx(n);
486 assert(idx + 1 == irg->last_node_idx);
488 if (idx + 1 == irg->last_node_idx)
489 --irg->last_node_idx;
490 irg->idx_irn_map[idx] = NULL;
491 obstack_free(irg->obst, n);
495 * Get the node for an index.
496 * @param irg The graph.
497 * @param idx The index you want the node for.
498 * @return The node with that index or NULL, if there is no node with that index.
499 * @note The node you got might be dead.
501 static inline ir_node *
502 _get_idx_irn(ir_graph *irg, unsigned idx) {
503 assert(idx < (unsigned) ARR_LEN(irg->idx_irn_map));
504 return irg->idx_irn_map[idx];
508 * Return the number of anchors in this graph.
511 get_irg_n_anchors(const ir_graph *irg) {
512 return get_irn_arity(irg->anchor);
516 * Return anchor for given index
518 static inline ir_node *
519 get_irg_anchor(const ir_graph *irg, int idx) {
520 return get_irn_intra_n(irg->anchor, idx);
524 * Set anchor for given index
527 set_irg_anchor(ir_graph *irg, int idx, ir_node *irn) {
528 set_irn_n(irg->anchor, idx, irn);
531 #ifdef INTERPROCEDURAL_VIEW
532 extern int firm_interprocedural_view;
535 _get_interprocedural_view(void) {
536 return firm_interprocedural_view;
539 #define get_interprocedural_view() _get_interprocedural_view()
542 #define is_ir_graph(thing) _is_ir_graph(thing)
543 #define get_irg_start_block(irg) _get_irg_start_block(irg)
544 #define set_irg_start_block(irg, node) _set_irg_start_block(irg, node)
545 #define get_irg_start(irg) _get_irg_start(irg)
546 #define set_irg_start(irg, node) _set_irg_start(irg, node)
547 #define get_irg_end_block(irg) _get_irg_end_block(irg)
548 #define set_irg_end_block(irg, node) _set_irg_end_block(irg, node)
549 #define get_irg_end(irg) _get_irg_end(irg)
550 #define set_irg_end(irg, node) _set_irg_end(irg, node)
551 #define get_irg_end_reg(irg) _get_irg_end_reg(irg)
552 #define set_irg_end_reg(irg, node) _set_irg_end_reg(irg, node)
553 #define get_irg_end_except(irg) _get_irg_end_except(irg)
554 #define set_irg_end_except(irg, node) _set_irg_end_except(irg, node)
555 #define get_irg_initial_exec(irg) _get_irg_initial_exec(irg)
556 #define set_irg_initial_exec(irg, node) _set_irg_initial_exec(irg, node)
557 #define get_irg_frame(irg) _get_irg_frame(irg)
558 #define set_irg_frame(irg, node) _set_irg_frame(irg, node)
559 #define get_irg_tls(irg) _get_irg_tls(irg)
560 #define set_irg_tls(irg, node) _set_irg_tls(irg, node)
561 #define get_irg_initial_mem(irg) _get_irg_initial_mem(irg)
562 #define set_irg_initial_mem(irg, node) _set_irg_initial_mem(irg, node)
563 #define get_irg_args(irg) _get_irg_args(irg)
564 #define set_irg_args(irg, node) _set_irg_args(irg, node)
565 #define get_irg_bad(irg) _get_irg_bad(irg)
566 #define set_irg_bad(irg, node) _set_irg_bad(irg, node)
567 #define get_irg_no_mem(irg) _get_irg_no_mem(irg)
568 #define set_irn_no_mem(irg, node) _set_irn_no_mem(irg, node)
569 #define get_irg_current_block(irg) _get_irg_current_block(irg)
570 #define set_irg_current_block(irg, node) _set_irg_current_block(irg, node)
571 #define get_irg_entity(irg) _get_irg_entity(irg)
572 #define set_irg_entity(irg, ent) _set_irg_entity(irg, ent)
573 #define get_irg_frame_type(irg) _get_irg_frame_type(irg)
574 #define set_irg_frame_type(irg, ftp) _set_irg_frame_type(irg, ftp)
575 #define get_irg_obstack(irg) _get_irg_obstack(irg)
576 #define get_irg_phase_state(irg) _get_irg_phase_state(irg)
577 #define set_irg_phase_state(irg, state) _set_irg_phase_state(irg, state)
578 #define get_irg_pinned(irg) _get_irg_pinned(irg)
579 #define get_irg_outs_state(irg) _get_irg_outs_state(irg)
580 #define set_irg_outs_inconsistent(irg) _set_irg_outs_inconsistent(irg)
581 #define get_irg_extblk_state(irg) _get_irg_extblk_state(irg)
582 #define set_irg_extblk_inconsistent(irg) _set_irg_extblk_inconsistent(irg)
583 #define get_irg_dom_state(irg) _get_irg_dom_state(irg)
584 #define get_irg_postdom_state(irg) _get_irg_postdom_state(irg)
585 #define set_irg_doms_inconsistent(irg) _set_irg_doms_inconsistent(irg)
586 #define get_irg_loopinfo_state(irg) _get_irg_loopinfo_state(irg)
587 #define set_irg_loopinfo_state(irg, s) _set_irg_loopinfo_state(irg, s)
588 #define set_irg_loopinfo_inconsistent(irg) _set_irg_loopinfo_inconsistent(irg)
589 #define set_irg_pinned(irg, p) _set_irg_pinned(irg, p)
590 #define get_irg_callee_info_state(irg) _get_irg_callee_info_state(irg)
591 #define set_irg_callee_info_state(irg, s) _set_irg_callee_info_state(irg, s)
592 #define get_irg_inline_property(irg) _get_irg_inline_property(irg)
593 #define set_irg_inline_property(irg, s) _set_irg_inline_property(irg, s)
594 #define get_irg_additional_properties(irg) _get_irg_additional_properties(irg)
595 #define set_irg_additional_properties(irg, m) _set_irg_additional_properties(irg, m)
596 #define set_irg_additional_property(irg, f) _set_irg_additional_property(irg, f)
597 #define set_irg_link(irg, thing) _set_irg_link(irg, thing)
598 #define get_irg_link(irg) _get_irg_link(irg)
599 #define get_irg_visited(irg) _get_irg_visited(irg)
600 #define get_irg_block_visited(irg) _get_irg_block_visited(irg)
601 #define set_irg_block_visited(irg, v) _set_irg_block_visited(irg, v)
602 #define inc_irg_block_visited(irg) _inc_irg_block_visited(irg)
603 #define dec_irg_block_visited(irg) _dec_irg_block_visited(irg)
604 #define get_irg_estimated_node_cnt(irg) _get_irg_estimated_node_cnt(irg)
605 #define get_irg_fp_model(irg) _get_irg_fp_model(irg)
606 #define get_idx_irn(irg, idx) _get_idx_irn(irg, idx)
607 #define set_irg_state(irg, state) _set_irg_state(irg, state)
608 #define clear_irg_state(irg, state) _clear_irg_state(irg, state)
609 #define is_irg_state(irg, state) _is_irg_state(irg, state)