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;
191 res->value_table = new_identities(); /* value table for global value
192 numbering for optimizing use in iropt.c */
195 res->inline_property = irg_inline_any;
196 res->additional_properties = mtp_property_inherited; /* inherited from type */
198 res->irg_pinned_state = op_pin_state_pinned;
199 res->outs_state = outs_none;
200 res->dom_state = dom_none;
201 res->pdom_state = dom_none;
202 res->typeinfo_state = ir_typeinfo_none;
203 set_irp_typeinfo_inconsistent(); /* there is a new graph with typeinfo_none. */
204 res->callee_info_state = irg_callee_info_none;
205 res->loopinfo_state = loopinfo_none;
206 res->class_cast_state = ir_class_casts_transitive;
207 res->extblk_state = ir_extblk_info_none;
208 res->execfreq_state = exec_freq_none;
209 res->fp_model = fp_model_precise;
210 res->entity_usage_state = ir_entity_usage_not_computed;
211 res->mem_disambig_opt = aa_opt_inherited;
213 /*-- Type information for the procedure of the graph --*/
215 set_entity_irg(ent, res);
217 /*-- a class type so that it can contain "inner" methods as in Pascal. --*/
218 res->frame_type = new_type_frame();
220 /* the Anchor node must be created first */
221 res->anchor = new_Anchor(res);
223 /*-- Nodes needed in every graph --*/
224 set_irg_end_block (res, new_immBlock());
225 set_cur_block(get_irg_end_block(res));
227 set_irg_end (res, end);
229 start_block = new_immBlock();
230 set_cur_block(start_block);
231 set_irg_start_block(res, start_block);
232 bad = new_ir_node(NULL, res, start_block, op_Bad, mode_T, 0, NULL);
233 bad->attr.irg.irg = res;
234 set_irg_bad (res, bad);
235 set_irg_no_mem (res, new_ir_node(NULL, res, start_block, op_NoMem, mode_M, 0, NULL));
237 set_irg_start (res, start);
239 /* Proj results of start node */
240 projX = new_Proj(start, mode_X, pn_Start_X_initial_exec);
241 set_irg_initial_exec (res, projX);
242 set_irg_frame (res, new_Proj(start, mode_P_data, pn_Start_P_frame_base));
243 set_irg_tls (res, new_Proj(start, mode_P_data, pn_Start_P_tls));
244 set_irg_args (res, new_Proj(start, mode_T, pn_Start_T_args));
245 initial_mem = new_Proj(start, mode_M, pn_Start_M);
246 set_irg_initial_mem(res, initial_mem);
248 set_store(initial_mem);
250 res->index = get_irp_new_irg_idx();
252 res->graph_nr = get_irp_new_node_nr();
255 mature_immBlock(res->current_block);
257 /*-- Make a block to start with --*/
258 first_block = new_immBlock();
259 set_cur_block(first_block);
260 add_immBlock_pred(first_block, projX);
262 res->method_execution_frequency = -1.0;
263 res->estimated_node_count = 0;
268 ir_graph *new_ir_graph(ir_entity *ent, int n_loc)
270 ir_graph *res = new_r_ir_graph(ent, n_loc);
271 add_irp_irg(res); /* remember this graph global. */
275 /* Make a rudimentary IR graph for the constant code.
276 Must look like a correct irg, spare everything else. */
277 ir_graph *new_const_code_irg(void)
279 ir_graph *res = alloc_graph();
286 ir_node *start_block;
289 /* inform statistics here, as blocks will be already build on this graph */
290 hook_new_graph(res, NULL);
292 current_ir_graph = res;
293 res->n_loc = 1; /* Only the memory. */
294 res->visited = 0; /* visited flag, for the ir walker */
295 res->block_visited = 0; /* visited flag, for the 'block'-walker */
296 res->obst = XMALLOC(struct obstack);
297 obstack_init(res->obst);
298 res->extbb_obst = NULL;
300 res->last_node_idx = 0;
302 res->phase_state = phase_building;
303 res->irg_pinned_state = op_pin_state_pinned;
304 res->extblk_state = ir_extblk_info_none;
305 res->fp_model = fp_model_precise;
307 /* value table for global value numbering for optimizing use in iropt.c */
308 res->value_table = new_identities();
310 res->frame_type = NULL;
312 /* the Anchor node must be created first */
313 res->anchor = new_Anchor(res);
315 /* -- The end block -- */
316 end_block = new_immBlock();
317 set_irg_end_block(res, end_block);
318 set_cur_block(end_block);
320 set_irg_end (res, end);
321 mature_immBlock(end_block);
323 /* -- The start block -- */
324 start_block = new_immBlock();
325 set_cur_block(start_block);
326 set_irg_start_block(res, start_block);
327 bad = new_ir_node(NULL, res, start_block, op_Bad, mode_T, 0, NULL);
328 bad->attr.irg.irg = res;
329 set_irg_bad(res, bad);
330 no_mem = new_ir_node(NULL, res, start_block, op_NoMem, mode_M, 0, NULL);
331 set_irg_no_mem(res, no_mem);
333 set_irg_start(res, start);
335 /* Proj results of start node */
336 set_irg_initial_mem(res, new_Proj(start, mode_M, pn_Start_M));
337 projX = new_Proj(start, mode_X, pn_Start_X_initial_exec);
338 mature_immBlock(start_block);
340 body_block = new_immBlock();
341 add_immBlock_pred(body_block, projX);
342 mature_immBlock(body_block); /* mature the 'body' block for expressions */
343 set_cur_block(body_block);
345 /* Set the visited flag high enough that the blocks will never be visited. */
346 set_irn_visited(body_block, -1);
347 set_Block_block_visited(body_block, -1);
348 set_Block_block_visited(start_block, -1);
349 set_irn_visited(start_block, -1);
350 set_irn_visited(bad, -1);
351 set_irn_visited(no_mem, -1);
353 res->phase_state = phase_high;
359 * Pre-Walker: Copies blocks and nodes from the original method graph
360 * to the copied graph.
362 * @param n A node from the original method graph.
363 * @param env The copied graph.
365 static void copy_all_nodes(ir_node *node, void *env)
368 ir_node *new_node = irn_copy_into_irg(node, irg);
370 set_irn_link(node, new_node);
372 /* fix access to entities on the stack frame */
373 if (is_Sel(new_node)) {
374 ir_entity *ent = get_Sel_entity(new_node);
375 ir_type *tp = get_entity_owner(ent);
377 if (is_frame_type(tp)) {
378 /* replace by the copied entity */
379 ent = get_entity_link(ent);
381 assert(is_entity(ent));
382 assert(get_entity_owner(ent) == get_irg_frame_type(irg));
383 set_Sel_entity(new_node, ent);
389 * Post-walker: Set the predecessors of the copied nodes.
390 * The copied nodes are set as link of their original nodes. The links of
391 * "irn" predecessors are the predecessors of copied node.
393 static void rewire(ir_node *irn, void *env)
396 irn_rewire_inputs(irn);
399 static ir_node *get_new_node(const ir_node *old_node)
401 return (ir_node*) get_irn_link(old_node);
405 * Create a new graph that is a copy of a given one.
407 ir_graph *create_irg_copy(ir_graph *irg)
414 res->visited = 0; /* visited flag, for the ir walker */
415 res->block_visited = 0; /* visited flag, for the 'block'-walker */
416 res->obst = XMALLOC(struct obstack);
417 obstack_init(res->obst);
418 res->extbb_obst = NULL;
420 res->last_node_idx = 0;
422 res->phase_state = irg->phase_state;
423 res->irg_pinned_state = irg->irg_pinned_state;
424 res->extblk_state = ir_extblk_info_none;
425 res->fp_model = irg->fp_model;
427 res->value_table = new_identities();
429 /* clone the frame type here for safety */
430 irp_reserve_resources(irp, IR_RESOURCE_ENTITY_LINK);
431 res->frame_type = clone_frame_type(irg->frame_type);
433 res->phase_state = irg->phase_state;
435 ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
437 /* copy all nodes from the graph irg to the new graph res */
438 irg_walk_anchors(irg, copy_all_nodes, rewire, res);
440 /* copy the Anchor node */
441 res->anchor = get_new_node(irg->anchor);
443 /* -- The end block -- */
444 set_irg_end_block (res, get_new_node(get_irg_end_block(irg)));
445 set_irg_end (res, get_new_node(get_irg_end(irg)));
447 /* -- The start block -- */
448 set_irg_start_block(res, get_new_node(get_irg_start_block(irg)));
449 set_irg_bad (res, get_new_node(get_irg_bad(irg)));
450 set_irg_no_mem (res, get_new_node(get_irg_no_mem(irg)));
451 set_irg_start (res, get_new_node(get_irg_start(irg)));
453 /* Proj results of start node */
454 set_irg_initial_mem(res, get_new_node(get_irg_initial_mem(irg)));
456 /* Copy the node count estimation. Would be strange if this
457 is different from the original one. */
458 res->estimated_node_count = irg->estimated_node_count;
460 ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
461 irp_free_resources(irp, IR_RESOURCE_ENTITY_LINK);
466 /* Frees the passed irgraph.
467 Deallocates all nodes in this graph and the ir_graph structure.
468 Sets the field irgraph in the corresponding entity to NULL.
469 Does not remove the irgraph from the list in irprog (requires
470 inefficient search, call remove_irp_irg by hand).
471 Does not free types, entities or modes that are used only by this
472 graph, nor the entity standing for this graph. */
473 void free_ir_graph(ir_graph *irg)
475 assert(is_ir_graph(irg));
477 edges_deactivate(irg);
479 hook_free_graph(irg);
480 if (irg->outs_state != outs_none)
483 free_type(irg->frame_type);
484 if (irg->value_table)
485 del_identities(irg->value_table);
487 set_entity_irg(irg->ent, NULL); /* not set in const code irg */
490 free_End(get_irg_end(irg));
491 obstack_free(irg->obst,NULL);
493 if (irg->loc_descriptions)
494 free(irg->loc_descriptions);
499 /* access routines for all ir_graph attributes:
501 {attr type} get_irg_{attribute name} (ir_graph *irg);
502 void set_irg_{attr name} (ir_graph *irg, {attr type} {attr}); */
504 int (is_ir_graph)(const void *thing)
506 return _is_ir_graph(thing);
510 /* Outputs a unique number for this node */
511 long get_irg_graph_nr(const ir_graph *irg)
513 return irg->graph_nr;
516 long get_irg_graph_nr(const ir_graph *irg)
518 return PTR_TO_INT(irg);
522 int get_irg_idx(const ir_graph *irg)
527 ir_node *(get_idx_irn)(ir_graph *irg, unsigned idx)
529 return _get_idx_irn(irg, idx);
532 ir_node *(get_irg_start_block)(const ir_graph *irg)
534 return _get_irg_start_block(irg);
537 void (set_irg_start_block)(ir_graph *irg, ir_node *node)
539 _set_irg_start_block(irg, node);
542 ir_node *(get_irg_start)(const ir_graph *irg)
544 return _get_irg_start(irg);
547 void (set_irg_start)(ir_graph *irg, ir_node *node)
549 _set_irg_start(irg, node);
552 ir_node *(get_irg_end_block)(const ir_graph *irg)
554 return _get_irg_end_block(irg);
557 void (set_irg_end_block)(ir_graph *irg, ir_node *node)
559 _set_irg_end_block(irg, node);
562 ir_node *(get_irg_end)(const ir_graph *irg)
564 return _get_irg_end(irg);
567 void (set_irg_end)(ir_graph *irg, ir_node *node)
569 _set_irg_end(irg, node);
572 ir_node *(get_irg_initial_exec)(const ir_graph *irg)
574 return _get_irg_initial_exec(irg);
577 void (set_irg_initial_exec)(ir_graph *irg, ir_node *node)
579 _set_irg_initial_exec(irg, node);
582 ir_node *(get_irg_frame)(const ir_graph *irg)
584 return _get_irg_frame(irg);
587 void (set_irg_frame)(ir_graph *irg, ir_node *node)
589 _set_irg_frame(irg, node);
592 ir_node *(get_irg_tls)(const ir_graph *irg)
594 return _get_irg_tls(irg);
597 void (set_irg_tls)(ir_graph *irg, ir_node *node)
599 _set_irg_tls(irg, node);
602 ir_node *(get_irg_initial_mem)(const ir_graph *irg)
604 return _get_irg_initial_mem(irg);
607 void (set_irg_initial_mem)(ir_graph *irg, ir_node *node)
609 _set_irg_initial_mem(irg, node);
612 ir_node *(get_irg_args)(const ir_graph *irg)
614 return _get_irg_args(irg);
617 void (set_irg_args)(ir_graph *irg, ir_node *node)
619 _set_irg_args(irg, node);
622 ir_node *(get_irg_bad)(const ir_graph *irg)
624 return _get_irg_bad(irg);
627 void (set_irg_bad)(ir_graph *irg, ir_node *node)
629 _set_irg_bad(irg, node);
632 ir_node *(get_irg_no_mem)(const ir_graph *irg)
634 return _get_irg_no_mem(irg);
637 void (set_irg_no_mem)(ir_graph *irg, ir_node *node)
639 _set_irg_no_mem(irg, node);
642 ir_node *(get_irg_current_block)(const ir_graph *irg)
644 return _get_irg_current_block(irg);
647 void (set_irg_current_block)(ir_graph *irg, ir_node *node)
649 _set_irg_current_block(irg, node);
652 ir_entity *(get_irg_entity)(const ir_graph *irg)
654 return _get_irg_entity(irg);
657 void (set_irg_entity)(ir_graph *irg, ir_entity *ent)
659 _set_irg_entity(irg, ent);
662 ir_type *(get_irg_frame_type)(ir_graph *irg)
664 return _get_irg_frame_type(irg);
667 void (set_irg_frame_type)(ir_graph *irg, ir_type *ftp)
669 _set_irg_frame_type(irg, ftp);
672 /* Returns the value parameter type of an IR graph. */
673 ir_type *get_irg_value_param_type(ir_graph *irg)
675 ir_entity *ent = get_irg_entity(irg);
676 ir_type *mtp = get_entity_type(ent);
677 return get_method_value_param_type(mtp);
680 int get_irg_n_locs(ir_graph *irg)
682 if (get_opt_precise_exc_context())
683 return irg->n_loc - 1 - 1;
685 return irg->n_loc - 1;
688 /* Returns the obstack associated with the graph. */
690 (get_irg_obstack)(const ir_graph *irg) {
691 return _get_irg_obstack(irg);
695 * Returns true if the node n is allocated on the storage of graph irg.
697 * Implementation is GLIBC specific as is uses the internal _obstack_chunk implementation.
699 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n)
701 struct _obstack_chunk *p;
704 * checks weather the ir_node pointer is on the obstack.
705 * A more sophisticated check would test the "whole" ir_node
707 for (p = irg->obst->chunk; p; p = p->prev) {
708 if (((char *)p->contents <= (char *)n) && ((char *)n < (char *)p->limit))
715 irg_phase_state (get_irg_phase_state)(const ir_graph *irg)
717 return _get_irg_phase_state(irg);
720 void (set_irg_phase_state)(ir_graph *irg, irg_phase_state state)
722 _set_irg_phase_state(irg, state);
725 op_pin_state (get_irg_pinned)(const ir_graph *irg)
727 return _get_irg_pinned(irg);
730 irg_outs_state (get_irg_outs_state)(const ir_graph *irg)
732 return _get_irg_outs_state(irg);
735 void (set_irg_outs_inconsistent)(ir_graph *irg)
737 _set_irg_outs_inconsistent(irg);
740 irg_extblk_state (get_irg_extblk_state)(const ir_graph *irg)
742 return _get_irg_extblk_state(irg);
745 void (set_irg_extblk_inconsistent)(ir_graph *irg)
747 _set_irg_extblk_inconsistent(irg);
750 irg_dom_state (get_irg_dom_state)(const ir_graph *irg)
752 return _get_irg_dom_state(irg);
755 irg_dom_state (get_irg_postdom_state)(const ir_graph *irg)
757 return _get_irg_postdom_state(irg);
760 void (set_irg_doms_inconsistent)(ir_graph *irg)
762 _set_irg_doms_inconsistent(irg);
765 irg_loopinfo_state (get_irg_loopinfo_state)(const ir_graph *irg)
767 return _get_irg_loopinfo_state(irg);
770 void (set_irg_loopinfo_state)(ir_graph *irg, irg_loopinfo_state s)
772 _set_irg_loopinfo_state(irg, s);
775 void (set_irg_loopinfo_inconsistent)(ir_graph *irg)
777 _set_irg_loopinfo_inconsistent(irg);
780 void set_irp_loopinfo_inconsistent(void)
783 for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
784 set_irg_loopinfo_inconsistent(get_irp_irg(i));
790 void (set_irg_pinned)(ir_graph *irg, op_pin_state p)
792 _set_irg_pinned(irg, p);
795 irg_callee_info_state (get_irg_callee_info_state)(const ir_graph *irg)
797 return _get_irg_callee_info_state(irg);
800 void (set_irg_callee_info_state)(ir_graph *irg, irg_callee_info_state s)
802 _set_irg_callee_info_state(irg, s);
805 irg_inline_property (get_irg_inline_property)(const ir_graph *irg)
807 return _get_irg_inline_property(irg);
810 void (set_irg_inline_property)(ir_graph *irg, irg_inline_property s)
812 _set_irg_inline_property(irg, s);
815 unsigned (get_irg_additional_properties)(const ir_graph *irg)
817 return _get_irg_additional_properties(irg);
820 void (set_irg_additional_properties)(ir_graph *irg, unsigned property_mask)
822 _set_irg_additional_properties(irg, property_mask);
825 void (set_irg_additional_property)(ir_graph *irg, mtp_additional_property flag)
827 _set_irg_additional_property(irg, flag);
830 void (set_irg_link)(ir_graph *irg, void *thing)
832 _set_irg_link(irg, thing);
835 void *(get_irg_link)(const ir_graph *irg)
837 return _get_irg_link(irg);
840 ir_visited_t (get_irg_visited)(const ir_graph *irg)
842 return _get_irg_visited(irg);
845 /** maximum visited flag content of all ir_graph visited fields. */
846 static ir_visited_t max_irg_visited = 0;
848 void set_irg_visited(ir_graph *irg, ir_visited_t visited)
850 irg->visited = visited;
851 if (irg->visited > max_irg_visited) {
852 max_irg_visited = irg->visited;
856 void inc_irg_visited(ir_graph *irg)
859 if (irg->visited > max_irg_visited) {
860 max_irg_visited = irg->visited;
864 ir_visited_t get_max_irg_visited(void)
866 return max_irg_visited;
869 void set_max_irg_visited(int val)
871 max_irg_visited = val;
874 ir_visited_t inc_max_irg_visited(void)
878 for (i = 0; i < get_irp_n_irgs(); i++)
879 assert(max_irg_visited >= get_irg_visited(get_irp_irg(i)));
881 return ++max_irg_visited;
884 ir_visited_t (get_irg_block_visited)(const ir_graph *irg)
886 return _get_irg_block_visited(irg);
889 void (set_irg_block_visited)(ir_graph *irg, ir_visited_t visited)
891 _set_irg_block_visited(irg, visited);
894 void (inc_irg_block_visited)(ir_graph *irg)
896 _inc_irg_block_visited(irg);
899 /* Return the floating point model of this graph. */
900 unsigned (get_irg_fp_model)(const ir_graph *irg)
902 return _get_irg_fp_model(irg);
905 /* Sets the floating point model for this graph. */
906 void set_irg_fp_model(ir_graph *irg, unsigned model)
908 irg->fp_model = model;
912 * walker Start->End: places Proj nodes into the same block
913 * as it's predecessors
918 static void normalize_proj_walker(ir_node *n, void *env)
922 ir_node *pred = get_Proj_pred(n);
923 ir_node *block = get_nodes_block(pred);
925 set_nodes_block(n, block);
929 /* move Proj nodes into the same block as its predecessors */
930 void normalize_proj_nodes(ir_graph *irg)
932 irg_walk_graph(irg, NULL, normalize_proj_walker, NULL);
933 set_irg_outs_inconsistent(irg);
936 /* set a description for local value n */
937 void set_irg_loc_description(ir_graph *irg, int n, void *description)
939 assert(0 <= n && n < irg->n_loc);
941 if (! irg->loc_descriptions)
942 irg->loc_descriptions = XMALLOCNZ(void*, irg->n_loc);
944 irg->loc_descriptions[n] = description;
947 /* get the description for local value n */
948 void *get_irg_loc_description(ir_graph *irg, int n)
950 assert(0 <= n && n < irg->n_loc);
951 return irg->loc_descriptions ? irg->loc_descriptions[n] : NULL;
954 void irg_register_phase(ir_graph *irg, ir_phase_id id, ir_phase *phase)
956 assert(id <= PHASE_LAST);
957 assert(irg->phases[id] == NULL);
958 irg->phases[id] = phase;
961 void irg_invalidate_phases(ir_graph *irg)
964 for (p = 0; p <= PHASE_LAST; ++p) {
965 ir_phase *phase = irg->phases[p];
970 irg->phases[p] = NULL;
975 void ir_reserve_resources(ir_graph *irg, ir_resources_t resources)
977 assert((resources & ~IR_RESOURCE_LOCAL_MASK) == 0);
978 assert((irg->reserved_resources & resources) == 0);
979 irg->reserved_resources |= resources;
982 void ir_free_resources(ir_graph *irg, ir_resources_t resources)
984 assert((irg->reserved_resources & resources) == resources);
985 irg->reserved_resources &= ~resources;
988 ir_resources_t ir_resources_reserved(const ir_graph *irg)
990 return irg->reserved_resources;
994 /* Returns a estimated node count of the irg. */
995 unsigned (get_irg_estimated_node_cnt)(const ir_graph *irg)
997 return _get_irg_estimated_node_cnt(irg);
1000 /* Returns the last irn index for this graph. */
1001 unsigned get_irg_last_idx(const ir_graph *irg)
1003 return irg->last_node_idx;
1006 /* register additional space in an IR graph */
1007 size_t register_additional_graph_data(size_t size)
1009 assert(!forbid_new_data && "Too late to register additional node data");
1011 if (forbid_new_data)
1014 return additional_graph_data_size += size;
1017 void (set_irg_state)(ir_graph *irg, ir_graph_state_t state)
1019 _set_irg_state(irg, state);
1022 void (clear_irg_state)(ir_graph *irg, ir_graph_state_t state)
1024 _clear_irg_state(irg, state);
1027 int (is_irg_state)(const ir_graph *irg, ir_graph_state_t state)
1029 return _is_irg_state(irg, state);