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 /** Suffix that is added to every frame type. */
44 #define FRAME_TP_SUFFIX "frame_tp"
47 * Initializes the graph construction module.
49 void firm_init_irgraph(void);
52 * Set the number of locals for a given graph.
54 * @param irg the graph
55 * @param n_loc number of locals
57 void irg_set_nloc(ir_graph *res, int n_loc);
60 * Internal constructor that does not add to irp_irgs or the like.
62 ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc);
65 * Make a rudimentary ir graph for the constant code.
66 * Must look like a correct irg, spare everything else.
68 ir_graph *new_const_code_irg(void);
71 * Create a new graph that is a copy of a given one.
72 * Uses the link fields of the original graphs.
74 * @param irg The graph that must be copied.
76 ir_graph *create_irg_copy(ir_graph *irg);
79 * Set the op_pin_state_pinned state of a graph.
81 * @param irg the IR graph
82 * @param p new pin state
84 void set_irg_pinned(ir_graph *irg, op_pin_state p);
86 /** Returns the obstack associated with the graph. */
87 struct obstack *get_irg_obstack(const ir_graph *irg);
90 * Returns true if the node n is allocated on the storage of graph irg.
92 * @param irg the IR graph
93 * @param n the IR node
95 int node_is_in_irgs_storage(const ir_graph *irg, const ir_node *n);
97 /*-------------------------------------------------------------------*/
98 /* inline functions for graphs */
99 /*-------------------------------------------------------------------*/
101 static inline int is_ir_graph_(const void *thing)
103 return (get_kind(thing) == k_ir_graph);
106 /** Returns the start block of a graph. */
107 static inline ir_node *get_irg_start_block_(const ir_graph *irg)
109 return get_irn_n(irg->anchor, anchor_start_block);
112 static inline void set_irg_start_block_(ir_graph *irg, ir_node *node)
114 set_irn_n(irg->anchor, anchor_start_block, node);
117 static inline ir_node *get_irg_start_(const ir_graph *irg)
119 return get_irn_n(irg->anchor, anchor_start);
122 static inline void set_irg_start_(ir_graph *irg, ir_node *node)
124 set_irn_n(irg->anchor, anchor_start, node);
127 static inline ir_node *get_irg_end_block_(const ir_graph *irg)
129 return get_irn_n(irg->anchor, anchor_end_block);
132 static inline void set_irg_end_block_(ir_graph *irg, ir_node *node)
134 set_irn_n(irg->anchor, anchor_end_block, node);
137 static inline ir_node *get_irg_end_(const ir_graph *irg)
139 return get_irn_n(irg->anchor, anchor_end);
142 static inline void set_irg_end_(ir_graph *irg, ir_node *node)
144 set_irn_n(irg->anchor, anchor_end, node);
147 static inline ir_node *get_irg_initial_exec_(const ir_graph *irg)
149 return get_irn_n(irg->anchor, anchor_initial_exec);
152 static inline void set_irg_initial_exec_(ir_graph *irg, ir_node *node)
154 set_irn_n(irg->anchor, anchor_initial_exec, node);
157 static inline ir_node *get_irg_frame_(const ir_graph *irg)
159 return get_irn_n(irg->anchor, anchor_frame);
162 static inline void set_irg_frame_(ir_graph *irg, ir_node *node)
164 set_irn_n(irg->anchor, anchor_frame, node);
167 static inline ir_node *get_irg_initial_mem_(const ir_graph *irg)
169 return get_irn_n(irg->anchor, anchor_initial_mem);
172 static inline void set_irg_initial_mem_(ir_graph *irg, ir_node *node)
174 set_irn_n(irg->anchor, anchor_initial_mem, node);
177 static inline ir_node *get_irg_args_(const ir_graph *irg)
179 return get_irn_n(irg->anchor, anchor_args);
182 static inline void set_irg_args_(ir_graph *irg, ir_node *node)
184 set_irn_n(irg->anchor, anchor_args, node);
187 static inline ir_node *get_irg_no_mem_(const ir_graph *irg)
189 return get_irn_n(irg->anchor, anchor_no_mem);
192 static inline void set_irg_no_mem_(ir_graph *irg, ir_node *node)
194 set_irn_n(irg->anchor, anchor_no_mem, node);
197 static inline ir_entity *get_irg_entity_(const ir_graph *irg)
202 static inline void set_irg_entity_(ir_graph *irg, ir_entity *ent)
207 static inline ir_type *get_irg_frame_type_(ir_graph *irg)
209 assert(irg->frame_type);
210 return irg->frame_type;
213 static inline void set_irg_frame_type_(ir_graph *irg, ir_type *ftp)
215 assert(is_frame_type(ftp));
216 irg->frame_type = ftp;
219 static inline struct obstack *get_irg_obstack_(const ir_graph *irg)
225 static inline irg_phase_state get_irg_phase_state_(const ir_graph *irg)
227 return irg->phase_state;
230 static inline void set_irg_phase_state_(ir_graph *irg, irg_phase_state state)
232 irg->phase_state = state;
235 static inline op_pin_state get_irg_pinned_(const ir_graph *irg)
237 return irg->irg_pinned_state;
240 static inline void set_irg_pinned_(ir_graph *irg, op_pin_state p)
242 irg->irg_pinned_state = p;
245 static inline irg_callee_info_state get_irg_callee_info_state_(const ir_graph *irg)
247 return irg->callee_info_state;
250 static inline void set_irg_callee_info_state_(ir_graph *irg, irg_callee_info_state s)
252 irg_callee_info_state irp_state = get_irp_callee_info_state();
254 irg->callee_info_state = s;
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);
262 static inline void set_irg_link_(ir_graph *irg, void *thing)
267 static inline void *get_irg_link_(const ir_graph *irg)
272 static inline ir_visited_t get_irg_visited_(const ir_graph *irg)
277 static inline ir_visited_t get_irg_block_visited_(const ir_graph *irg)
279 return irg->block_visited;
282 static inline void set_irg_block_visited_(ir_graph *irg, ir_visited_t visited)
284 irg->block_visited = visited;
287 static inline void inc_irg_block_visited_(ir_graph *irg)
289 ++irg->block_visited;
292 static inline void dec_irg_block_visited_(ir_graph *irg)
294 --irg->block_visited;
297 static inline unsigned get_irg_estimated_node_cnt_(const ir_graph *irg)
299 return irg->estimated_node_count;
302 /* Return the floating point model of this graph. */
303 static inline unsigned get_irg_fp_model_(const ir_graph *irg)
305 return irg->fp_model;
308 static inline int irg_is_constrained_(const ir_graph *irg,
309 ir_graph_constraints_t constraints)
311 return (irg->constraints & constraints) == constraints;
314 static inline void add_irg_properties_(ir_graph *irg,
315 ir_graph_properties_t props)
317 irg->properties |= props;
320 static inline void clear_irg_properties_(ir_graph *irg,
321 ir_graph_properties_t props)
323 irg->properties &= ~props;
326 static inline int irg_has_properties_(const ir_graph *irg,
327 ir_graph_properties_t props)
329 return (irg->properties & props) == props;
333 * Allocates a new idx in the irg for the node and adds the irn to the idx -> irn map.
334 * @param irg The graph.
335 * @param irn The node.
336 * @return The index allocated for the node.
338 static inline unsigned irg_register_node_idx(ir_graph *irg, ir_node *irn)
340 unsigned idx = irg->last_node_idx++;
341 if (idx >= (unsigned)ARR_LEN(irg->idx_irn_map))
342 ARR_RESIZE(ir_node *, irg->idx_irn_map, idx + 1);
344 irg->idx_irn_map[idx] = irn;
349 * Kill a node from the irg. BEWARE: this kills
350 * all later created nodes.
352 static inline void irg_kill_node(ir_graph *irg, ir_node *n)
354 unsigned idx = get_irn_idx(n);
355 assert(idx + 1 == irg->last_node_idx);
357 if (idx + 1 == irg->last_node_idx)
358 --irg->last_node_idx;
359 irg->idx_irn_map[idx] = NULL;
360 obstack_free(irg->obst, n);
364 * Get the node for an index.
365 * @param irg The graph.
366 * @param idx The index you want the node for.
367 * @return The node with that index or NULL, if there is no node with that index.
368 * @note The node you got might be dead.
370 static inline ir_node *get_idx_irn_(const ir_graph *irg, unsigned idx)
372 assert(idx < (unsigned) ARR_LEN(irg->idx_irn_map));
373 return irg->idx_irn_map[idx];
377 * Return the number of anchors in this graph.
379 static inline int get_irg_n_anchors(const ir_graph *irg)
381 return get_irn_arity(irg->anchor);
385 * Return anchor for given index
387 static inline ir_node *get_irg_anchor(const ir_graph *irg, int idx)
389 return get_irn_n(irg->anchor, idx);
393 * Set anchor for given index
395 static inline void set_irg_anchor(ir_graph *irg, int idx, ir_node *irn)
397 set_irn_n(irg->anchor, idx, irn);
401 #define is_ir_graph(thing) is_ir_graph_(thing)
402 #define get_irg_start_block(irg) get_irg_start_block_(irg)
403 #define set_irg_start_block(irg, node) set_irg_start_block_(irg, node)
404 #define get_irg_start(irg) get_irg_start_(irg)
405 #define set_irg_start(irg, node) set_irg_start_(irg, node)
406 #define get_irg_end_block(irg) get_irg_end_block_(irg)
407 #define set_irg_end_block(irg, node) set_irg_end_block_(irg, node)
408 #define get_irg_end(irg) get_irg_end_(irg)
409 #define set_irg_end(irg, node) set_irg_end_(irg, node)
410 #define get_irg_initial_exec(irg) get_irg_initial_exec_(irg)
411 #define set_irg_initial_exec(irg, node) set_irg_initial_exec_(irg, node)
412 #define get_irg_frame(irg) get_irg_frame_(irg)
413 #define set_irg_frame(irg, node) set_irg_frame_(irg, node)
414 #define get_irg_initial_mem(irg) get_irg_initial_mem_(irg)
415 #define set_irg_initial_mem(irg, node) set_irg_initial_mem_(irg, node)
416 #define get_irg_args(irg) get_irg_args_(irg)
417 #define set_irg_args(irg, node) set_irg_args_(irg, node)
418 #define get_irg_no_mem(irg) get_irg_no_mem_(irg)
419 #define set_irn_no_mem(irg, node) set_irn_no_mem_(irg, node)
420 #define get_irg_entity(irg) get_irg_entity_(irg)
421 #define set_irg_entity(irg, ent) set_irg_entity_(irg, ent)
422 #define get_irg_frame_type(irg) get_irg_frame_type_(irg)
423 #define set_irg_frame_type(irg, ftp) set_irg_frame_type_(irg, ftp)
424 #define get_irg_obstack(irg) get_irg_obstack_(irg)
425 #define get_irg_phase_state(irg) get_irg_phase_state_(irg)
426 #define set_irg_phase_state(irg, state) set_irg_phase_state_(irg, state)
427 #define get_irg_pinned(irg) get_irg_pinned_(irg)
428 #define set_irg_pinned(irg, p) set_irg_pinned_(irg, p)
429 #define get_irg_callee_info_state(irg) get_irg_callee_info_state_(irg)
430 #define set_irg_callee_info_state(irg, s) set_irg_callee_info_state_(irg, s)
431 #define get_irg_additional_properties(irg) get_irg_additional_properties_(irg)
432 #define set_irg_additional_properties(irg, m) set_irg_additional_properties_(irg, m)
433 #define set_irg_additional_property(irg, f) set_irg_additional_property_(irg, f)
434 #define set_irg_link(irg, thing) set_irg_link_(irg, thing)
435 #define get_irg_link(irg) get_irg_link_(irg)
436 #define get_irg_visited(irg) get_irg_visited_(irg)
437 #define get_irg_block_visited(irg) get_irg_block_visited_(irg)
438 #define set_irg_block_visited(irg, v) set_irg_block_visited_(irg, v)
439 #define inc_irg_block_visited(irg) inc_irg_block_visited_(irg)
440 #define dec_irg_block_visited(irg) dec_irg_block_visited_(irg)
441 #define get_irg_estimated_node_cnt(irg) get_irg_estimated_node_cnt_(irg)
442 #define get_irg_fp_model(irg) get_irg_fp_model_(irg)
443 #define get_idx_irn(irg, idx) get_idx_irn_(irg, idx)
444 #define irg_is_constrained(irg, constraints) irg_is_constrained_(irg, constraints)
445 #define add_irg_properties(irg, props) add_irg_properties_(irg, props)
446 #define clear_irg_properties(irg, props) clear_irg_properties_(irg, props)
447 #define irg_has_properties(irg, props) irg_has_properties_(irg, props)