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
25 #ifndef FIRM_IR_IRGRAPH_T_H
26 #define FIRM_IR_IRGRAPH_T_H
28 #include "firm_types.h"
35 #include "iredgekinds.h"
43 #define is_ir_graph(thing) is_ir_graph_(thing)
44 #define get_irg_start_block(irg) get_irg_start_block_(irg)
45 #define set_irg_start_block(irg, node) set_irg_start_block_(irg, node)
46 #define get_irg_start(irg) get_irg_start_(irg)
47 #define set_irg_start(irg, node) set_irg_start_(irg, node)
48 #define get_irg_end_block(irg) get_irg_end_block_(irg)
49 #define set_irg_end_block(irg, node) set_irg_end_block_(irg, node)
50 #define get_irg_end(irg) get_irg_end_(irg)
51 #define set_irg_end(irg, node) set_irg_end_(irg, node)
52 #define get_irg_initial_exec(irg) get_irg_initial_exec_(irg)
53 #define set_irg_initial_exec(irg, node) set_irg_initial_exec_(irg, node)
54 #define get_irg_frame(irg) get_irg_frame_(irg)
55 #define set_irg_frame(irg, node) set_irg_frame_(irg, node)
56 #define get_irg_initial_mem(irg) get_irg_initial_mem_(irg)
57 #define set_irg_initial_mem(irg, node) set_irg_initial_mem_(irg, node)
58 #define get_irg_args(irg) get_irg_args_(irg)
59 #define set_irg_args(irg, node) set_irg_args_(irg, node)
60 #define get_irg_no_mem(irg) get_irg_no_mem_(irg)
61 #define set_irn_no_mem(irg, node) set_irn_no_mem_(irg, node)
62 #define get_irg_entity(irg) get_irg_entity_(irg)
63 #define set_irg_entity(irg, ent) set_irg_entity_(irg, ent)
64 #define get_irg_frame_type(irg) get_irg_frame_type_(irg)
65 #define set_irg_frame_type(irg, ftp) set_irg_frame_type_(irg, ftp)
66 #define get_irg_pinned(irg) get_irg_pinned_(irg)
67 #define get_irg_callee_info_state(irg) get_irg_callee_info_state_(irg)
68 #define set_irg_callee_info_state(irg, s) set_irg_callee_info_state_(irg, s)
69 #define get_irg_additional_properties(irg) get_irg_additional_properties_(irg)
70 #define set_irg_additional_properties(irg, m) set_irg_additional_properties_(irg, m)
71 #define set_irg_additional_property(irg, f) set_irg_additional_property_(irg, f)
72 #define set_irg_link(irg, thing) set_irg_link_(irg, thing)
73 #define get_irg_link(irg) get_irg_link_(irg)
74 #define get_irg_visited(irg) get_irg_visited_(irg)
75 #define get_irg_block_visited(irg) get_irg_block_visited_(irg)
76 #define set_irg_block_visited(irg, v) set_irg_block_visited_(irg, v)
77 #define inc_irg_block_visited(irg) inc_irg_block_visited_(irg)
78 #define dec_irg_block_visited(irg) dec_irg_block_visited_(irg)
79 #define get_irg_fp_model(irg) get_irg_fp_model_(irg)
80 #define get_idx_irn(irg, idx) get_idx_irn_(irg, idx)
81 #define irg_is_constrained(irg, constraints) irg_is_constrained_(irg, constraints)
82 #define add_irg_properties(irg, props) add_irg_properties_(irg, props)
83 #define clear_irg_properties(irg, props) clear_irg_properties_(irg, props)
84 #define irg_has_properties(irg, props) irg_has_properties_(irg, props)
87 * Initializes the graph construction module.
89 void firm_init_irgraph(void);
92 * Set the number of locals for a given graph.
94 * @param irg the graph
95 * @param n_loc number of locals
97 void irg_set_nloc(ir_graph *res, int n_loc);
100 * Internal constructor that does not add to irp_irgs or the like.
102 ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc);
105 * Make a rudimentary ir graph for the constant code.
106 * Must look like a correct irg, spare everything else.
108 ir_graph *new_const_code_irg(void);
111 * Create a new graph that is a copy of a given one.
112 * Uses the link fields of the original graphs.
114 * @param irg The graph that must be copied.
116 ir_graph *create_irg_copy(ir_graph *irg);
119 * Set the op_pin_state_pinned state of a graph.
121 * @param irg the IR graph
122 * @param p new pin state
124 static inline void set_irg_pinned(ir_graph *irg, op_pin_state p)
126 irg->irg_pinned_state = p;
129 /** Returns the obstack associated with the graph. */
130 static inline struct obstack *get_irg_obstack(const ir_graph *irg)
132 assert(obstack_object_size(irg->obst) == 0);
139 * Returns true if the node n is allocated on the storage of graph irg.
141 * @param irg the IR graph
142 * @param n the IR node
144 int node_is_in_irgs_storage(const ir_graph *irg, const ir_node *n);
146 /*-------------------------------------------------------------------*/
147 /* inline functions for graphs */
148 /*-------------------------------------------------------------------*/
150 static inline int is_ir_graph_(const void *thing)
152 return (get_kind(thing) == k_ir_graph);
155 /** Returns the start block of a graph. */
156 static inline ir_node *get_irg_start_block_(const ir_graph *irg)
158 return get_irn_n(irg->anchor, anchor_start_block);
161 static inline void set_irg_start_block_(ir_graph *irg, ir_node *node)
163 set_irn_n(irg->anchor, anchor_start_block, node);
166 static inline ir_node *get_irg_start_(const ir_graph *irg)
168 return get_irn_n(irg->anchor, anchor_start);
171 static inline void set_irg_start_(ir_graph *irg, ir_node *node)
173 set_irn_n(irg->anchor, anchor_start, node);
176 static inline ir_node *get_irg_end_block_(const ir_graph *irg)
178 return get_irn_n(irg->anchor, anchor_end_block);
181 static inline void set_irg_end_block_(ir_graph *irg, ir_node *node)
183 set_irn_n(irg->anchor, anchor_end_block, node);
186 static inline ir_node *get_irg_end_(const ir_graph *irg)
188 return get_irn_n(irg->anchor, anchor_end);
191 static inline void set_irg_end_(ir_graph *irg, ir_node *node)
193 set_irn_n(irg->anchor, anchor_end, node);
196 static inline ir_node *get_irg_initial_exec_(const ir_graph *irg)
198 return get_irn_n(irg->anchor, anchor_initial_exec);
201 static inline void set_irg_initial_exec_(ir_graph *irg, ir_node *node)
203 set_irn_n(irg->anchor, anchor_initial_exec, node);
206 static inline ir_node *get_irg_frame_(const ir_graph *irg)
208 return get_irn_n(irg->anchor, anchor_frame);
211 static inline void set_irg_frame_(ir_graph *irg, ir_node *node)
213 set_irn_n(irg->anchor, anchor_frame, node);
216 static inline ir_node *get_irg_initial_mem_(const ir_graph *irg)
218 return get_irn_n(irg->anchor, anchor_initial_mem);
221 static inline void set_irg_initial_mem_(ir_graph *irg, ir_node *node)
223 set_irn_n(irg->anchor, anchor_initial_mem, node);
226 static inline ir_node *get_irg_args_(const ir_graph *irg)
228 return get_irn_n(irg->anchor, anchor_args);
231 static inline void set_irg_args_(ir_graph *irg, ir_node *node)
233 set_irn_n(irg->anchor, anchor_args, node);
236 static inline ir_node *get_irg_no_mem_(const ir_graph *irg)
238 return get_irn_n(irg->anchor, anchor_no_mem);
241 static inline void set_irg_no_mem_(ir_graph *irg, ir_node *node)
243 set_irn_n(irg->anchor, anchor_no_mem, node);
246 static inline ir_entity *get_irg_entity_(const ir_graph *irg)
251 static inline void set_irg_entity_(ir_graph *irg, ir_entity *ent)
256 static inline ir_type *get_irg_frame_type_(ir_graph *irg)
258 assert(irg->frame_type);
259 return irg->frame_type;
262 static inline void set_irg_frame_type_(ir_graph *irg, ir_type *ftp)
264 assert(is_frame_type(ftp));
265 irg->frame_type = ftp;
268 static inline op_pin_state get_irg_pinned_(const ir_graph *irg)
270 return irg->irg_pinned_state;
273 static inline irg_callee_info_state get_irg_callee_info_state_(const ir_graph *irg)
275 return irg->callee_info_state;
278 static inline void set_irg_callee_info_state_(ir_graph *irg, irg_callee_info_state s)
280 irg_callee_info_state irp_state = get_irp_callee_info_state();
282 irg->callee_info_state = s;
284 /* I could compare ... but who knows? */
285 if ((irp_state == irg_callee_info_consistent) ||
286 ((irp_state == irg_callee_info_inconsistent) && (s == irg_callee_info_none)))
287 set_irp_callee_info_state(s);
290 static inline void set_irg_link_(ir_graph *irg, void *thing)
295 static inline void *get_irg_link_(const ir_graph *irg)
300 static inline ir_visited_t get_irg_visited_(const ir_graph *irg)
305 static inline ir_visited_t get_irg_block_visited_(const ir_graph *irg)
307 return irg->block_visited;
310 static inline void set_irg_block_visited_(ir_graph *irg, ir_visited_t visited)
312 irg->block_visited = visited;
315 static inline void inc_irg_block_visited_(ir_graph *irg)
317 ++irg->block_visited;
320 static inline void dec_irg_block_visited_(ir_graph *irg)
322 --irg->block_visited;
325 /* Return the floating point model of this graph. */
326 static inline unsigned get_irg_fp_model_(const ir_graph *irg)
328 return irg->fp_model;
331 static inline int irg_is_constrained_(const ir_graph *irg,
332 ir_graph_constraints_t constraints)
334 return (irg->constraints & constraints) == constraints;
337 static inline void add_irg_properties_(ir_graph *irg,
338 ir_graph_properties_t props)
340 irg->properties |= props;
343 static inline void clear_irg_properties_(ir_graph *irg,
344 ir_graph_properties_t props)
346 irg->properties &= ~props;
349 static inline int irg_has_properties_(const ir_graph *irg,
350 ir_graph_properties_t props)
352 return (irg->properties & props) == props;
356 * Allocates a new idx in the irg for the node and adds the irn to the idx -> irn map.
357 * @param irg The graph.
358 * @param irn The node.
359 * @return The index allocated for the node.
361 static inline unsigned irg_register_node_idx(ir_graph *irg, ir_node *irn)
363 unsigned idx = irg->last_node_idx++;
364 if (idx >= (unsigned)ARR_LEN(irg->idx_irn_map))
365 ARR_RESIZE(ir_node *, irg->idx_irn_map, idx + 1);
367 irg->idx_irn_map[idx] = irn;
372 * Kill a node from the irg. BEWARE: this kills
373 * all later created nodes.
375 static inline void irg_kill_node(ir_graph *irg, ir_node *n)
377 unsigned idx = get_irn_idx(n);
378 assert(idx + 1 == irg->last_node_idx);
380 if (idx + 1 == irg->last_node_idx)
381 --irg->last_node_idx;
382 irg->idx_irn_map[idx] = NULL;
383 obstack_free(irg->obst, n);
387 * Get the node for an index.
388 * @param irg The graph.
389 * @param idx The index you want the node for.
390 * @return The node with that index or NULL, if there is no node with that index.
391 * @note The node you got might be dead.
393 static inline ir_node *get_idx_irn_(const ir_graph *irg, unsigned idx)
395 assert(idx < (unsigned) ARR_LEN(irg->idx_irn_map));
396 return irg->idx_irn_map[idx];
400 * Return the number of anchors in this graph.
402 static inline int get_irg_n_anchors(const ir_graph *irg)
404 return get_irn_arity(irg->anchor);
408 * Return anchor for given index
410 static inline ir_node *get_irg_anchor(const ir_graph *irg, int idx)
412 return get_irn_n(irg->anchor, idx);
416 * Set anchor for given index
418 static inline void set_irg_anchor(ir_graph *irg, int idx, ir_node *irn)
420 set_irn_n(irg->anchor, idx, irn);