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.
23 * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
33 #include "irgraph_t.h"
35 #include "irgraph_t.h"
45 #include "irbackedge_t.h"
46 #include "iredges_t.h"
51 #define INITIAL_IDX_IRN_MAP_SIZE 1024
54 * Indicates, whether additional data can be registered to graphs.
55 * If set to 1, this is not possible anymore.
57 static int forbid_new_data = 0;
60 * The amount of additional space for custom data to be allocated upon
61 * creating a new graph.
63 static size_t additional_graph_data_size = 0;
65 ir_graph *current_ir_graph;
66 ir_graph *get_current_ir_graph(void)
68 return current_ir_graph;
71 void set_current_ir_graph(ir_graph *graph)
73 current_ir_graph = graph;
76 /** contains the suffix for frame type names */
77 static ident *frame_type_suffix = NULL;
79 /* initialize the IR graph module */
80 void firm_init_irgraph(void)
82 frame_type_suffix = new_id_from_str(FRAME_TP_SUFFIX);
87 * Allocate a new IR graph.
88 * This function respects the registered graph data. The only reason for
89 * this function is, that there are two locations, where graphs are
90 * allocated (new_r_ir_graph, new_const_code_irg).
91 * @return Memory for a new graph.
93 static ir_graph *alloc_graph(void)
96 size_t size = sizeof(ir_graph) + additional_graph_data_size;
97 char *ptr = XMALLOCNZ(char, size);
99 res = (ir_graph *)(ptr + additional_graph_data_size);
100 res->kind = k_ir_graph;
102 /* initialize the idx->node map. */
103 res->idx_irn_map = NEW_ARR_F(ir_node *, INITIAL_IDX_IRN_MAP_SIZE);
104 memset(res->idx_irn_map, 0, INITIAL_IDX_IRN_MAP_SIZE * sizeof(res->idx_irn_map[0]));
110 * Frees an allocated IR graph
112 static void free_graph(ir_graph *irg)
114 char *ptr = (char *)irg;
117 for (i = 0; i < EDGE_KIND_LAST; ++i)
118 edges_deactivate_kind(irg, i);
119 DEL_ARR_F(irg->idx_irn_map);
120 free(ptr - additional_graph_data_size);
124 * Set the number of locals for a given graph.
126 * @param irg the graph
127 * @param n_loc number of locals
129 void irg_set_nloc(ir_graph *res, int n_loc)
131 assert(res->phase_state == phase_building);
133 if (get_opt_precise_exc_context()) {
134 res->n_loc = n_loc + 1 + 1; /* number of local variables that are never
135 dereferenced in this graph plus one for
136 the store plus one for links to fragile
137 operations. n_loc is not the number of
138 parameters to the procedure! */
140 res->n_loc = n_loc + 1; /* number of local variables that are never
141 dereferenced in this graph plus one for
142 the store. This is not the number of parameters
145 if (res->loc_descriptions) {
146 xfree(res->loc_descriptions);
147 res->loc_descriptions = NULL;
151 /* Allocates a list of nodes:
152 - The start block containing a start node and Proj nodes for it's four
153 results (X, M, P, Tuple).
154 - The end block containing an end node. This block is not matured after
155 new_ir_graph as predecessors need to be added to it.
156 - The current block, which is empty and also not matured.
157 Further it allocates several datastructures needed for graph construction
160 ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc)
163 ir_node *first_block;
164 ir_node *end, *start, *start_block, *initial_mem, *projX, *bad;
168 /* inform statistics here, as blocks will be already build on this graph */
169 hook_new_graph(res, ent);
171 current_ir_graph = res;
173 /*-- initialized for each graph. --*/
174 res->kind = k_ir_graph;
175 res->obst = XMALLOC(struct obstack);
176 obstack_init(res->obst);
178 res->phase_state = phase_building;
179 irg_set_nloc(res, n_loc);
181 /* descriptions will be allocated on demand */
182 res->loc_descriptions = NULL;
184 res->visited = 0; /* visited flag, for the ir walker */
185 res->block_visited = 0; /* visited flag, for the 'block'-walker */
187 res->extbb_obst = NULL;
189 res->last_node_idx = 0;
194 res->inline_property = irg_inline_any;
195 res->additional_properties = mtp_property_inherited; /* inherited from type */
197 res->irg_pinned_state = op_pin_state_pinned;
198 res->outs_state = outs_none;
199 res->dom_state = dom_none;
200 res->pdom_state = dom_none;
201 res->typeinfo_state = ir_typeinfo_none;
202 set_irp_typeinfo_inconsistent(); /* there is a new graph with typeinfo_none. */
203 res->callee_info_state = irg_callee_info_none;
204 res->loopinfo_state = loopinfo_none;
205 res->class_cast_state = ir_class_casts_transitive;
206 res->extblk_state = ir_extblk_info_none;
207 res->execfreq_state = exec_freq_none;
208 res->fp_model = fp_model_precise;
209 res->entity_usage_state = ir_entity_usage_not_computed;
210 res->mem_disambig_opt = aa_opt_inherited;
212 /*-- Type information for the procedure of the graph --*/
214 set_entity_irg(ent, res);
216 /*-- a class type so that it can contain "inner" methods as in Pascal. --*/
217 res->frame_type = new_type_frame();
219 /* the Anchor node must be created first */
220 res->anchor = new_Anchor(res);
222 /*-- Nodes needed in every graph --*/
223 set_irg_end_block (res, new_immBlock());
224 set_cur_block(get_irg_end_block(res));
226 set_irg_end (res, end);
228 start_block = new_immBlock();
229 set_cur_block(start_block);
230 set_irg_start_block(res, start_block);
231 bad = new_ir_node(NULL, res, start_block, op_Bad, mode_T, 0, NULL);
232 bad->attr.irg.irg = res;
233 set_irg_bad (res, bad);
234 set_irg_no_mem (res, new_ir_node(NULL, res, start_block, op_NoMem, mode_M, 0, NULL));
236 set_irg_start (res, start);
238 /* Proj results of start node */
239 projX = new_Proj(start, mode_X, pn_Start_X_initial_exec);
240 set_irg_initial_exec (res, projX);
241 set_irg_frame (res, new_Proj(start, mode_P_data, pn_Start_P_frame_base));
242 set_irg_tls (res, new_Proj(start, mode_P_data, pn_Start_P_tls));
243 set_irg_args (res, new_Proj(start, mode_T, pn_Start_T_args));
244 initial_mem = new_Proj(start, mode_M, pn_Start_M);
245 set_irg_initial_mem(res, initial_mem);
247 set_store(initial_mem);
249 res->index = get_irp_new_irg_idx();
251 res->graph_nr = get_irp_new_node_nr();
254 mature_immBlock(res->current_block);
256 /*-- Make a block to start with --*/
257 first_block = new_immBlock();
258 set_cur_block(first_block);
259 add_immBlock_pred(first_block, projX);
261 res->method_execution_frequency = -1.0;
262 res->estimated_node_count = 0;
267 ir_graph *new_ir_graph(ir_entity *ent, int n_loc)
269 ir_graph *res = new_r_ir_graph(ent, n_loc);
270 add_irp_irg(res); /* remember this graph global. */
274 /* Make a rudimentary IR graph for the constant code.
275 Must look like a correct irg, spare everything else. */
276 ir_graph *new_const_code_irg(void)
278 ir_graph *res = alloc_graph();
285 ir_node *start_block;
288 /* inform statistics here, as blocks will be already build on this graph */
289 hook_new_graph(res, NULL);
291 current_ir_graph = res;
292 res->n_loc = 1; /* Only the memory. */
293 res->visited = 0; /* visited flag, for the ir walker */
294 res->block_visited = 0; /* visited flag, for the 'block'-walker */
295 res->obst = XMALLOC(struct obstack);
296 obstack_init(res->obst);
297 res->extbb_obst = NULL;
299 res->last_node_idx = 0;
301 res->phase_state = phase_building;
302 res->irg_pinned_state = op_pin_state_pinned;
303 res->extblk_state = ir_extblk_info_none;
304 res->fp_model = fp_model_precise;
306 /* value table for global value numbering for optimizing use in iropt.c */
309 res->frame_type = NULL;
311 /* the Anchor node must be created first */
312 res->anchor = new_Anchor(res);
314 /* -- The end block -- */
315 end_block = new_immBlock();
316 set_irg_end_block(res, end_block);
317 set_cur_block(end_block);
319 set_irg_end (res, end);
320 mature_immBlock(end_block);
322 /* -- The start block -- */
323 start_block = new_immBlock();
324 set_cur_block(start_block);
325 set_irg_start_block(res, start_block);
326 bad = new_ir_node(NULL, res, start_block, op_Bad, mode_T, 0, NULL);
327 bad->attr.irg.irg = res;
328 set_irg_bad(res, bad);
329 no_mem = new_ir_node(NULL, res, start_block, op_NoMem, mode_M, 0, NULL);
330 set_irg_no_mem(res, no_mem);
332 set_irg_start(res, start);
334 /* Proj results of start node */
335 set_irg_initial_mem(res, new_Proj(start, mode_M, pn_Start_M));
336 projX = new_Proj(start, mode_X, pn_Start_X_initial_exec);
337 mature_immBlock(start_block);
339 body_block = new_immBlock();
340 add_immBlock_pred(body_block, projX);
341 mature_immBlock(body_block); /* mature the 'body' block for expressions */
342 set_cur_block(body_block);
344 /* Set the visited flag high enough that the blocks will never be visited. */
345 set_irn_visited(body_block, -1);
346 set_Block_block_visited(body_block, -1);
347 set_Block_block_visited(start_block, -1);
348 set_irn_visited(start_block, -1);
349 set_irn_visited(bad, -1);
350 set_irn_visited(no_mem, -1);
352 res->phase_state = phase_high;
358 * Pre-Walker: Copies blocks and nodes from the original method graph
359 * to the copied graph.
361 * @param n A node from the original method graph.
362 * @param env The copied graph.
364 static void copy_all_nodes(ir_node *node, void *env)
367 ir_node *new_node = irn_copy_into_irg(node, irg);
369 set_irn_link(node, new_node);
371 /* fix access to entities on the stack frame */
372 if (is_Sel(new_node)) {
373 ir_entity *ent = get_Sel_entity(new_node);
374 ir_type *tp = get_entity_owner(ent);
376 if (is_frame_type(tp)) {
377 /* replace by the copied entity */
378 ent = get_entity_link(ent);
380 assert(is_entity(ent));
381 assert(get_entity_owner(ent) == get_irg_frame_type(irg));
382 set_Sel_entity(new_node, ent);
388 * Post-walker: Set the predecessors of the copied nodes.
389 * The copied nodes are set as link of their original nodes. The links of
390 * "irn" predecessors are the predecessors of copied node.
392 static void rewire(ir_node *irn, void *env)
395 irn_rewire_inputs(irn);
398 static ir_node *get_new_node(const ir_node *old_node)
400 return (ir_node*) get_irn_link(old_node);
404 * Create a new graph that is a copy of a given one.
406 ir_graph *create_irg_copy(ir_graph *irg)
413 res->visited = 0; /* visited flag, for the ir walker */
414 res->block_visited = 0; /* visited flag, for the 'block'-walker */
415 res->obst = XMALLOC(struct obstack);
416 obstack_init(res->obst);
417 res->extbb_obst = NULL;
419 res->last_node_idx = 0;
421 res->phase_state = irg->phase_state;
422 res->irg_pinned_state = irg->irg_pinned_state;
423 res->extblk_state = ir_extblk_info_none;
424 res->fp_model = irg->fp_model;
428 /* clone the frame type here for safety */
429 irp_reserve_resources(irp, IR_RESOURCE_ENTITY_LINK);
430 res->frame_type = clone_frame_type(irg->frame_type);
432 res->phase_state = irg->phase_state;
434 ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
436 /* copy all nodes from the graph irg to the new graph res */
437 irg_walk_anchors(irg, copy_all_nodes, rewire, res);
439 /* copy the Anchor node */
440 res->anchor = get_new_node(irg->anchor);
442 /* -- The end block -- */
443 set_irg_end_block (res, get_new_node(get_irg_end_block(irg)));
444 set_irg_end (res, get_new_node(get_irg_end(irg)));
446 /* -- The start block -- */
447 set_irg_start_block(res, get_new_node(get_irg_start_block(irg)));
448 set_irg_bad (res, get_new_node(get_irg_bad(irg)));
449 set_irg_no_mem (res, get_new_node(get_irg_no_mem(irg)));
450 set_irg_start (res, get_new_node(get_irg_start(irg)));
452 /* Proj results of start node */
453 set_irg_initial_mem(res, get_new_node(get_irg_initial_mem(irg)));
455 /* Copy the node count estimation. Would be strange if this
456 is different from the original one. */
457 res->estimated_node_count = irg->estimated_node_count;
459 ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
460 irp_free_resources(irp, IR_RESOURCE_ENTITY_LINK);
465 /* Frees the passed irgraph.
466 Deallocates all nodes in this graph and the ir_graph structure.
467 Sets the field irgraph in the corresponding entity to NULL.
468 Does not remove the irgraph from the list in irprog (requires
469 inefficient search, call remove_irp_irg by hand).
470 Does not free types, entities or modes that are used only by this
471 graph, nor the entity standing for this graph. */
472 void free_ir_graph(ir_graph *irg)
474 assert(is_ir_graph(irg));
476 edges_deactivate(irg);
478 hook_free_graph(irg);
479 if (irg->outs_state != outs_none)
482 free_type(irg->frame_type);
485 set_entity_irg(irg->ent, NULL); /* not set in const code irg */
488 free_End(get_irg_end(irg));
489 obstack_free(irg->obst,NULL);
491 if (irg->loc_descriptions)
492 free(irg->loc_descriptions);
497 /* access routines for all ir_graph attributes:
499 {attr type} get_irg_{attribute name} (ir_graph *irg);
500 void set_irg_{attr name} (ir_graph *irg, {attr type} {attr}); */
502 int (is_ir_graph)(const void *thing)
504 return _is_ir_graph(thing);
508 /* Outputs a unique number for this node */
509 long get_irg_graph_nr(const ir_graph *irg)
511 return irg->graph_nr;
514 long get_irg_graph_nr(const ir_graph *irg)
516 return PTR_TO_INT(irg);
520 int get_irg_idx(const ir_graph *irg)
525 ir_node *(get_idx_irn)(ir_graph *irg, unsigned idx)
527 return _get_idx_irn(irg, idx);
530 ir_node *(get_irg_start_block)(const ir_graph *irg)
532 return _get_irg_start_block(irg);
535 void (set_irg_start_block)(ir_graph *irg, ir_node *node)
537 _set_irg_start_block(irg, node);
540 ir_node *(get_irg_start)(const ir_graph *irg)
542 return _get_irg_start(irg);
545 void (set_irg_start)(ir_graph *irg, ir_node *node)
547 _set_irg_start(irg, node);
550 ir_node *(get_irg_end_block)(const ir_graph *irg)
552 return _get_irg_end_block(irg);
555 void (set_irg_end_block)(ir_graph *irg, ir_node *node)
557 _set_irg_end_block(irg, node);
560 ir_node *(get_irg_end)(const ir_graph *irg)
562 return _get_irg_end(irg);
565 void (set_irg_end)(ir_graph *irg, ir_node *node)
567 _set_irg_end(irg, node);
570 ir_node *(get_irg_initial_exec)(const ir_graph *irg)
572 return _get_irg_initial_exec(irg);
575 void (set_irg_initial_exec)(ir_graph *irg, ir_node *node)
577 _set_irg_initial_exec(irg, node);
580 ir_node *(get_irg_frame)(const ir_graph *irg)
582 return _get_irg_frame(irg);
585 void (set_irg_frame)(ir_graph *irg, ir_node *node)
587 _set_irg_frame(irg, node);
590 ir_node *(get_irg_tls)(const ir_graph *irg)
592 return _get_irg_tls(irg);
595 void (set_irg_tls)(ir_graph *irg, ir_node *node)
597 _set_irg_tls(irg, node);
600 ir_node *(get_irg_initial_mem)(const ir_graph *irg)
602 return _get_irg_initial_mem(irg);
605 void (set_irg_initial_mem)(ir_graph *irg, ir_node *node)
607 _set_irg_initial_mem(irg, node);
610 ir_node *(get_irg_args)(const ir_graph *irg)
612 return _get_irg_args(irg);
615 void (set_irg_args)(ir_graph *irg, ir_node *node)
617 _set_irg_args(irg, node);
620 ir_node *(get_irg_bad)(const ir_graph *irg)
622 return _get_irg_bad(irg);
625 void (set_irg_bad)(ir_graph *irg, ir_node *node)
627 _set_irg_bad(irg, node);
630 ir_node *(get_irg_no_mem)(const ir_graph *irg)
632 return _get_irg_no_mem(irg);
635 void (set_irg_no_mem)(ir_graph *irg, ir_node *node)
637 _set_irg_no_mem(irg, node);
640 ir_node *(get_irg_current_block)(const ir_graph *irg)
642 return _get_irg_current_block(irg);
645 void (set_irg_current_block)(ir_graph *irg, ir_node *node)
647 _set_irg_current_block(irg, node);
650 ir_entity *(get_irg_entity)(const ir_graph *irg)
652 return _get_irg_entity(irg);
655 void (set_irg_entity)(ir_graph *irg, ir_entity *ent)
657 _set_irg_entity(irg, ent);
660 ir_type *(get_irg_frame_type)(ir_graph *irg)
662 return _get_irg_frame_type(irg);
665 void (set_irg_frame_type)(ir_graph *irg, ir_type *ftp)
667 _set_irg_frame_type(irg, ftp);
670 /* Returns the value parameter type of an IR graph. */
671 ir_type *get_irg_value_param_type(ir_graph *irg)
673 ir_entity *ent = get_irg_entity(irg);
674 ir_type *mtp = get_entity_type(ent);
675 return get_method_value_param_type(mtp);
678 int get_irg_n_locs(ir_graph *irg)
680 if (get_opt_precise_exc_context())
681 return irg->n_loc - 1 - 1;
683 return irg->n_loc - 1;
686 /* Returns the obstack associated with the graph. */
688 (get_irg_obstack)(const ir_graph *irg) {
689 return _get_irg_obstack(irg);
693 * Returns true if the node n is allocated on the storage of graph irg.
695 * Implementation is GLIBC specific as is uses the internal _obstack_chunk implementation.
697 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n)
699 struct _obstack_chunk *p;
702 * checks weather the ir_node pointer is on the obstack.
703 * A more sophisticated check would test the "whole" ir_node
705 for (p = irg->obst->chunk; p; p = p->prev) {
706 if (((char *)p->contents <= (char *)n) && ((char *)n < (char *)p->limit))
713 irg_phase_state (get_irg_phase_state)(const ir_graph *irg)
715 return _get_irg_phase_state(irg);
718 void (set_irg_phase_state)(ir_graph *irg, irg_phase_state state)
720 _set_irg_phase_state(irg, state);
723 op_pin_state (get_irg_pinned)(const ir_graph *irg)
725 return _get_irg_pinned(irg);
728 irg_outs_state (get_irg_outs_state)(const ir_graph *irg)
730 return _get_irg_outs_state(irg);
733 void (set_irg_outs_inconsistent)(ir_graph *irg)
735 _set_irg_outs_inconsistent(irg);
738 irg_extblk_state (get_irg_extblk_state)(const ir_graph *irg)
740 return _get_irg_extblk_state(irg);
743 void (set_irg_extblk_inconsistent)(ir_graph *irg)
745 _set_irg_extblk_inconsistent(irg);
748 irg_dom_state (get_irg_dom_state)(const ir_graph *irg)
750 return _get_irg_dom_state(irg);
753 irg_dom_state (get_irg_postdom_state)(const ir_graph *irg)
755 return _get_irg_postdom_state(irg);
758 void (set_irg_doms_inconsistent)(ir_graph *irg)
760 _set_irg_doms_inconsistent(irg);
763 irg_loopinfo_state (get_irg_loopinfo_state)(const ir_graph *irg)
765 return _get_irg_loopinfo_state(irg);
768 void (set_irg_loopinfo_state)(ir_graph *irg, irg_loopinfo_state s)
770 _set_irg_loopinfo_state(irg, s);
773 void (set_irg_loopinfo_inconsistent)(ir_graph *irg)
775 _set_irg_loopinfo_inconsistent(irg);
778 void set_irp_loopinfo_inconsistent(void)
781 for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
782 set_irg_loopinfo_inconsistent(get_irp_irg(i));
788 void (set_irg_pinned)(ir_graph *irg, op_pin_state p)
790 _set_irg_pinned(irg, p);
793 irg_callee_info_state (get_irg_callee_info_state)(const ir_graph *irg)
795 return _get_irg_callee_info_state(irg);
798 void (set_irg_callee_info_state)(ir_graph *irg, irg_callee_info_state s)
800 _set_irg_callee_info_state(irg, s);
803 irg_inline_property (get_irg_inline_property)(const ir_graph *irg)
805 return _get_irg_inline_property(irg);
808 void (set_irg_inline_property)(ir_graph *irg, irg_inline_property s)
810 _set_irg_inline_property(irg, s);
813 unsigned (get_irg_additional_properties)(const ir_graph *irg)
815 return _get_irg_additional_properties(irg);
818 void (set_irg_additional_properties)(ir_graph *irg, unsigned property_mask)
820 _set_irg_additional_properties(irg, property_mask);
823 void (set_irg_additional_property)(ir_graph *irg, mtp_additional_property flag)
825 _set_irg_additional_property(irg, flag);
828 void (set_irg_link)(ir_graph *irg, void *thing)
830 _set_irg_link(irg, thing);
833 void *(get_irg_link)(const ir_graph *irg)
835 return _get_irg_link(irg);
838 ir_visited_t (get_irg_visited)(const ir_graph *irg)
840 return _get_irg_visited(irg);
843 /** maximum visited flag content of all ir_graph visited fields. */
844 static ir_visited_t max_irg_visited = 0;
846 void set_irg_visited(ir_graph *irg, ir_visited_t visited)
848 irg->visited = visited;
849 if (irg->visited > max_irg_visited) {
850 max_irg_visited = irg->visited;
854 void inc_irg_visited(ir_graph *irg)
857 if (irg->visited > max_irg_visited) {
858 max_irg_visited = irg->visited;
862 ir_visited_t get_max_irg_visited(void)
864 return max_irg_visited;
867 void set_max_irg_visited(int val)
869 max_irg_visited = val;
872 ir_visited_t inc_max_irg_visited(void)
876 for (i = 0; i < get_irp_n_irgs(); i++)
877 assert(max_irg_visited >= get_irg_visited(get_irp_irg(i)));
879 return ++max_irg_visited;
882 ir_visited_t (get_irg_block_visited)(const ir_graph *irg)
884 return _get_irg_block_visited(irg);
887 void (set_irg_block_visited)(ir_graph *irg, ir_visited_t visited)
889 _set_irg_block_visited(irg, visited);
892 void (inc_irg_block_visited)(ir_graph *irg)
894 _inc_irg_block_visited(irg);
897 /* Return the floating point model of this graph. */
898 unsigned (get_irg_fp_model)(const ir_graph *irg)
900 return _get_irg_fp_model(irg);
903 /* Sets the floating point model for this graph. */
904 void set_irg_fp_model(ir_graph *irg, unsigned model)
906 irg->fp_model = model;
910 * walker Start->End: places Proj nodes into the same block
911 * as it's predecessors
916 static void normalize_proj_walker(ir_node *n, void *env)
920 ir_node *pred = get_Proj_pred(n);
921 ir_node *block = get_nodes_block(pred);
923 set_nodes_block(n, block);
927 /* move Proj nodes into the same block as its predecessors */
928 void normalize_proj_nodes(ir_graph *irg)
930 irg_walk_graph(irg, NULL, normalize_proj_walker, NULL);
931 set_irg_outs_inconsistent(irg);
934 /* set a description for local value n */
935 void set_irg_loc_description(ir_graph *irg, int n, void *description)
937 assert(0 <= n && n < irg->n_loc);
939 if (! irg->loc_descriptions)
940 irg->loc_descriptions = XMALLOCNZ(void*, irg->n_loc);
942 irg->loc_descriptions[n] = description;
945 /* get the description for local value n */
946 void *get_irg_loc_description(ir_graph *irg, int n)
948 assert(0 <= n && n < irg->n_loc);
949 return irg->loc_descriptions ? irg->loc_descriptions[n] : NULL;
952 void irg_register_phase(ir_graph *irg, ir_phase_id id, ir_phase *phase)
954 assert(id <= PHASE_LAST);
955 assert(irg->phases[id] == NULL);
956 irg->phases[id] = phase;
959 void irg_invalidate_phases(ir_graph *irg)
962 for (p = 0; p <= PHASE_LAST; ++p) {
963 ir_phase *phase = irg->phases[p];
968 irg->phases[p] = NULL;
973 void ir_reserve_resources(ir_graph *irg, ir_resources_t resources)
975 assert((resources & ~IR_RESOURCE_LOCAL_MASK) == 0);
976 assert((irg->reserved_resources & resources) == 0);
977 irg->reserved_resources |= resources;
980 void ir_free_resources(ir_graph *irg, ir_resources_t resources)
982 assert((irg->reserved_resources & resources) == resources);
983 irg->reserved_resources &= ~resources;
986 ir_resources_t ir_resources_reserved(const ir_graph *irg)
988 return irg->reserved_resources;
992 /* Returns a estimated node count of the irg. */
993 unsigned (get_irg_estimated_node_cnt)(const ir_graph *irg)
995 return _get_irg_estimated_node_cnt(irg);
998 /* Returns the last irn index for this graph. */
999 unsigned get_irg_last_idx(const ir_graph *irg)
1001 return irg->last_node_idx;
1004 /* register additional space in an IR graph */
1005 size_t register_additional_graph_data(size_t size)
1007 assert(!forbid_new_data && "Too late to register additional node data");
1009 if (forbid_new_data)
1012 return additional_graph_data_size += size;
1015 void (set_irg_state)(ir_graph *irg, ir_graph_state_t state)
1017 _set_irg_state(irg, state);
1020 void (clear_irg_state)(ir_graph *irg, ir_graph_state_t state)
1022 _clear_irg_state(irg, state);
1025 int (is_irg_state)(const ir_graph *irg, ir_graph_state_t state)
1027 return _is_irg_state(irg, state);