fix ir_finish, freeing of irps/irgs
[libfirm] / ir / ir / irgraph.c
1 /*
2  * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief    Entry point to the representation of procedure code.
23  * @author   Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
24  */
25 #include "config.h"
26
27 #include <string.h>
28 #include <stddef.h>
29
30 #include "xmalloc.h"
31 #include "ircons_t.h"
32 #include "irgraph_t.h"
33 #include "irprog_t.h"
34 #include "irgraph_t.h"
35 #include "irnode_t.h"
36 #include "iropt_t.h"
37 #include "irflag_t.h"
38 #include "array.h"
39 #include "irgmod.h"
40 #include "irouts.h"
41 #include "irhooks.h"
42 #include "irtools.h"
43 #include "util.h"
44 #include "irgwalk.h"
45 #include "irbackedge_t.h"
46 #include "iredges_t.h"
47 #include "type_t.h"
48 #include "irmemory.h"
49
50 #define INITIAL_IDX_IRN_MAP_SIZE 1024
51
52 /**
53  * Indicates, whether additional data can be registered to graphs.
54  * If set to 1, this is not possible anymore.
55  */
56 static int forbid_new_data = 0;
57
58 /**
59  * The amount of additional space for custom data to be allocated upon
60  * creating a new graph.
61  */
62 static size_t additional_graph_data_size = 0;
63
64 ir_graph *current_ir_graph;
65 ir_graph *get_current_ir_graph(void)
66 {
67         return current_ir_graph;
68 }
69
70 void set_current_ir_graph(ir_graph *graph)
71 {
72         current_ir_graph = graph;
73 }
74
75 /** contains the suffix for frame type names */
76 static ident *frame_type_suffix = NULL;
77
78 /* initialize the IR graph module */
79 void firm_init_irgraph(void)
80 {
81         frame_type_suffix = new_id_from_str(FRAME_TP_SUFFIX);
82         forbid_new_data   = 1;
83 }
84
85 /**
86  * Allocate a new IR graph.
87  * This function respects the registered graph data. The only reason for
88  * this function is, that there are two locations, where graphs are
89  * allocated (new_r_ir_graph, new_const_code_irg).
90  * @return Memory for a new graph.
91  */
92 static ir_graph *alloc_graph(void)
93 {
94         ir_graph *res;
95         size_t   size = sizeof(ir_graph) + additional_graph_data_size;
96         char     *ptr = XMALLOCNZ(char, size);
97
98         res = (ir_graph *)(ptr + additional_graph_data_size);
99         res->kind = k_ir_graph;
100
101         /* initialize the idx->node map. */
102         res->idx_irn_map = NEW_ARR_F(ir_node *, INITIAL_IDX_IRN_MAP_SIZE);
103         memset(res->idx_irn_map, 0, INITIAL_IDX_IRN_MAP_SIZE * sizeof(res->idx_irn_map[0]));
104
105         return res;
106 }
107
108 /**
109  * Frees an allocated IR graph
110  */
111 static void free_graph(ir_graph *irg)
112 {
113         char           *ptr = (char *)irg;
114         ir_edge_kind_t  i;
115
116         for (i = EDGE_KIND_FIRST; i < EDGE_KIND_LAST; ++i)
117                 edges_deactivate_kind(irg, i);
118         DEL_ARR_F(irg->idx_irn_map);
119         free(ptr - additional_graph_data_size);
120 }
121
122 /**
123  * Set the number of locals for a given graph.
124  *
125  * @param irg    the graph
126  * @param n_loc  number of locals
127  */
128 void irg_set_nloc(ir_graph *res, int n_loc)
129 {
130         assert(res->phase_state == phase_building);
131
132         res->n_loc = n_loc + 1;     /* number of local variables that are never
133                                        dereferenced in this graph plus one for
134                                        the store. This is not the number of
135                                        parameters to the procedure!  */
136
137         if (res->loc_descriptions) {
138                 xfree(res->loc_descriptions);
139                 res->loc_descriptions = NULL;
140         }
141 }
142
143 /* Allocates a list of nodes:
144     - The start block containing a start node and Proj nodes for its four
145       results (X, M, P, Tuple).
146     - The end block containing an end node. This block is not matured after
147       new_ir_graph as predecessors need to be added to it.
148     - The current block, which is empty and also not matured.
149    Further it allocates several datastructures needed for graph construction
150    and optimization.
151 */
152 ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc)
153 {
154         ir_graph *res;
155         ir_node  *first_block;
156         ir_node  *start, *start_block, *initial_mem, *projX;
157
158         res = alloc_graph();
159
160         /* inform statistics here, as blocks will be already build on this graph */
161         hook_new_graph(res, ent);
162
163         /*-- initialized for each graph. --*/
164         res->kind = k_ir_graph;
165         res->obst = XMALLOC(struct obstack);
166         obstack_init(res->obst);
167
168         res->phase_state = phase_building;
169         irg_set_nloc(res, n_loc);
170
171         /* descriptions will be allocated on demand */
172         res->loc_descriptions = NULL;
173
174         res->visited       = 0; /* visited flag, for the ir walker */
175         res->block_visited = 0; /* visited flag, for the 'block'-walker */
176
177         res->extbb_obst = NULL;
178
179         res->last_node_idx = 0;
180
181         new_identities(res);
182         res->outs = NULL;
183
184         res->inline_property       = irg_inline_any;
185         res->additional_properties = mtp_property_inherited;  /* inherited from type */
186
187         res->irg_pinned_state    = op_pin_state_pinned;
188         res->typeinfo_state      = ir_typeinfo_none;
189         set_irp_typeinfo_inconsistent();           /* there is a new graph with typeinfo_none. */
190         res->callee_info_state   = irg_callee_info_none;
191         res->class_cast_state    = ir_class_casts_transitive;
192         res->fp_model            = fp_model_precise;
193         res->mem_disambig_opt    = aa_opt_inherited;
194
195         /*-- Type information for the procedure of the graph --*/
196         res->ent = ent;
197         set_entity_irg(ent, res);
198
199         /*--  a class type so that it can contain "inner" methods as in Pascal. --*/
200         res->frame_type = new_type_frame();
201
202         /* the Anchor node must be created first */
203         res->anchor = new_r_Anchor(res);
204
205         /*-- Nodes needed in every graph --*/
206         set_irg_end_block (res, new_r_immBlock(res));
207         set_irg_end(res, new_r_End(res, 0, NULL));
208
209         start_block = new_r_Block_noopt(res, 0, NULL);
210         set_irg_start_block(res, start_block);
211         set_irg_no_mem     (res, new_r_NoMem(res));
212         start = new_r_Start(res);
213         set_irg_start      (res, start);
214
215         /* Proj results of start node */
216         projX                   = new_r_Proj(start, mode_X, pn_Start_X_initial_exec);
217         set_irg_initial_exec    (res, projX);
218         set_irg_frame           (res, new_r_Proj(start, mode_P_data, pn_Start_P_frame_base));
219         set_irg_args            (res, new_r_Proj(start, mode_T,      pn_Start_T_args));
220         initial_mem             = new_r_Proj(start, mode_M, pn_Start_M);
221         set_irg_initial_mem(res, initial_mem);
222
223         res->index       = get_irp_new_irg_idx();
224 #ifdef DEBUG_libfirm
225         res->graph_nr    = get_irp_new_node_nr();
226 #endif
227
228         set_r_cur_block(res, start_block);
229         set_r_store(res, initial_mem);
230
231         /*-- Make a block to start with --*/
232         first_block = new_r_immBlock(res);
233         set_r_cur_block(res, first_block);
234         add_immBlock_pred(first_block, projX);
235
236         res->method_execution_frequency = -1.0;
237         res->estimated_node_count       = 0;
238
239         return res;
240 }
241
242 ir_graph *new_ir_graph(ir_entity *ent, int n_loc)
243 {
244         ir_graph *res = new_r_ir_graph(ent, n_loc);
245         add_irp_irg(res);          /* remember this graph global. */
246         return res;
247 }
248
249 /* Make a rudimentary IR graph for the constant code.
250    Must look like a correct irg, spare everything else. */
251 ir_graph *new_const_code_irg(void)
252 {
253         ir_graph *res = alloc_graph();
254         ir_node  *body_block;
255         ir_node  *end;
256         ir_node  *end_block;
257         ir_node  *no_mem;
258         ir_node  *projX;
259         ir_node  *start_block;
260         ir_node  *start;
261
262         /* inform statistics here, as blocks will be already build on this graph */
263         hook_new_graph(res, NULL);
264
265         res->n_loc         = 1; /* Only the memory. */
266         res->visited       = 0; /* visited flag, for the ir walker */
267         res->block_visited = 0; /* visited flag, for the 'block'-walker */
268         res->obst          = XMALLOC(struct obstack);
269         obstack_init(res->obst);
270         res->extbb_obst = NULL;
271
272         res->last_node_idx = 0;
273
274         res->phase_state      = phase_building;
275         res->irg_pinned_state = op_pin_state_pinned;
276         res->fp_model         = fp_model_precise;
277
278         /* value table for global value numbering for optimizing use in iropt.c */
279         new_identities(res);
280         res->ent         = NULL;
281         res->frame_type  = NULL;
282
283         /* the Anchor node must be created first */
284         res->anchor = new_r_Anchor(res);
285
286         /* -- The end block -- */
287         end_block = new_r_Block_noopt(res, 0, NULL);
288         set_irg_end_block(res, end_block);
289         end = new_r_End(res, 0, NULL);
290         set_irg_end(res, end);
291
292         /* -- The start block -- */
293         start_block = new_r_Block_noopt(res, 0, NULL);
294         set_irg_start_block(res, start_block);
295         no_mem = new_r_NoMem(res);
296         set_irg_no_mem(res, no_mem);
297         start = new_r_Start(res);
298         set_irg_start(res, start);
299
300         /* Proj results of start node */
301         set_irg_initial_mem(res, new_r_Proj(start, mode_M, pn_Start_M));
302         projX = new_r_Proj(start, mode_X, pn_Start_X_initial_exec);
303
304         body_block = new_r_Block(res, 1, &projX);
305
306         set_r_cur_block(res, body_block);
307
308         /* Set the visited flag high enough that the blocks will never be visited. */
309         set_irn_visited(body_block, -1);
310         set_Block_block_visited(body_block, -1);
311         set_Block_block_visited(start_block, -1);
312         set_irn_visited(start_block, -1);
313
314         return res;
315 }
316
317 /**
318  * Pre-Walker: Copies blocks and nodes from the original method graph
319  * to the copied graph.
320  *
321  * @param n    A node from the original method graph.
322  * @param env  The copied graph.
323  */
324 static void copy_all_nodes(ir_node *node, void *env)
325 {
326         ir_graph *irg      = (ir_graph*)env;
327         ir_node  *new_node = irn_copy_into_irg(node, irg);
328
329         set_irn_link(node, new_node);
330
331         /* fix access to entities on the stack frame */
332         if (is_Sel(new_node)) {
333                 ir_entity *ent = get_Sel_entity(new_node);
334                 ir_type   *tp  = get_entity_owner(ent);
335
336                 if (is_frame_type(tp)) {
337                         /* replace by the copied entity */
338                         ent = (ir_entity*)get_entity_link(ent);
339
340                         assert(is_entity(ent));
341                         assert(get_entity_owner(ent) == get_irg_frame_type(irg));
342                         set_Sel_entity(new_node, ent);
343                 }
344         }
345 }
346
347 /**
348  * Post-walker: Set the predecessors of the copied nodes.
349  * The copied nodes are set as link of their original nodes. The links of
350  * "irn" predecessors are the predecessors of copied node.
351  */
352 static void rewire(ir_node *irn, void *env)
353 {
354         (void) env;
355         irn_rewire_inputs(irn);
356 }
357
358 static ir_node *get_new_node(const ir_node *old_node)
359 {
360         return (ir_node*) get_irn_link(old_node);
361 }
362
363 /*
364  * Create a new graph that is a copy of a given one.
365  */
366 ir_graph *create_irg_copy(ir_graph *irg)
367 {
368         ir_graph *res;
369
370         res = alloc_graph();
371
372         res->n_loc = 0;
373         res->visited = 0;       /* visited flag, for the ir walker */
374         res->block_visited = 0; /* visited flag, for the 'block'-walker */
375         res->obst       = XMALLOC(struct obstack);
376         obstack_init(res->obst);
377         res->extbb_obst = NULL;
378
379         res->last_node_idx = 0;
380
381         res->phase_state      = irg->phase_state;
382         res->irg_pinned_state = irg->irg_pinned_state;
383         res->fp_model         = irg->fp_model;
384
385         new_identities(res);
386
387         /* clone the frame type here for safety */
388         irp_reserve_resources(irp, IRP_RESOURCE_ENTITY_LINK);
389         res->frame_type  = clone_frame_type(irg->frame_type);
390
391         res->phase_state = irg->phase_state;
392
393         ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
394
395         /* copy all nodes from the graph irg to the new graph res */
396         irg_walk_anchors(irg, copy_all_nodes, rewire, res);
397
398         /* copy the Anchor node */
399         res->anchor = get_new_node(irg->anchor);
400
401         /* -- The end block -- */
402         set_irg_end_block (res, get_new_node(get_irg_end_block(irg)));
403         set_irg_end       (res, get_new_node(get_irg_end(irg)));
404
405         /* -- The start block -- */
406         set_irg_start_block(res, get_new_node(get_irg_start_block(irg)));
407         set_irg_no_mem     (res, get_new_node(get_irg_no_mem(irg)));
408         set_irg_start      (res, get_new_node(get_irg_start(irg)));
409
410         /* Proj results of start node */
411         set_irg_initial_mem(res, get_new_node(get_irg_initial_mem(irg)));
412
413         /* Copy the node count estimation. Would be strange if this
414            is different from the original one. */
415         res->estimated_node_count = irg->estimated_node_count;
416
417         ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
418         irp_free_resources(irp, IRP_RESOURCE_ENTITY_LINK);
419
420         return res;
421 }
422
423 /* Frees the passed irgraph.
424    Deallocates all nodes in this graph and the ir_graph structure.
425    Sets the field irgraph in the corresponding entity to NULL.
426    Does not remove the irgraph from the list in irprog (requires
427    inefficient search, call remove_irp_irg by hand).
428    Does not free types, entities or modes that are used only by this
429    graph, nor the entity standing for this graph. */
430 void free_ir_graph(ir_graph *irg)
431 {
432         assert(is_ir_graph(irg));
433
434         edges_deactivate(irg);
435
436         hook_free_graph(irg);
437         free_irg_outs(irg);
438         del_identities(irg);
439         if (irg->ent) {
440                 set_entity_irg(irg->ent, NULL);  /* not set in const code irg */
441         }
442
443         free_End(get_irg_end(irg));
444         obstack_free(irg->obst, NULL);
445         free(irg->obst);
446         if (irg->loc_descriptions)
447                 free(irg->loc_descriptions);
448         irg->kind = k_BAD;
449         free_graph(irg);
450 }
451
452 /* access routines for all ir_graph attributes:
453    templates:
454    {attr type} get_irg_{attribute name} (ir_graph *irg);
455    void set_irg_{attr name} (ir_graph *irg, {attr type} {attr}); */
456
457 int (is_ir_graph)(const void *thing)
458 {
459         return is_ir_graph_(thing);
460 }
461
462 #ifdef DEBUG_libfirm
463 /* Outputs a unique number for this node */
464 long get_irg_graph_nr(const ir_graph *irg)
465 {
466         return irg->graph_nr;
467 }
468 #else
469 long get_irg_graph_nr(const ir_graph *irg)
470 {
471         return PTR_TO_INT(irg);
472 }
473 #endif
474
475 size_t get_irg_idx(const ir_graph *irg)
476 {
477         return irg->index;
478 }
479
480 ir_node *(get_idx_irn)(const ir_graph *irg, unsigned idx)
481 {
482         return get_idx_irn_(irg, idx);
483 }
484
485 ir_node *(get_irg_start_block)(const ir_graph *irg)
486 {
487         return get_irg_start_block_(irg);
488 }
489
490 void (set_irg_start_block)(ir_graph *irg, ir_node *node)
491 {
492         set_irg_start_block_(irg, node);
493 }
494
495 ir_node *(get_irg_start)(const ir_graph *irg)
496 {
497         return get_irg_start_(irg);
498 }
499
500 void (set_irg_start)(ir_graph *irg, ir_node *node)
501 {
502         set_irg_start_(irg, node);
503 }
504
505 ir_node *(get_irg_end_block)(const ir_graph *irg)
506 {
507         return get_irg_end_block_(irg);
508 }
509
510 void (set_irg_end_block)(ir_graph *irg, ir_node *node)
511 {
512         set_irg_end_block_(irg, node);
513 }
514
515 ir_node *(get_irg_end)(const ir_graph *irg)
516 {
517         return get_irg_end_(irg);
518 }
519
520 void (set_irg_end)(ir_graph *irg, ir_node *node)
521 {
522         set_irg_end_(irg, node);
523 }
524
525 ir_node *(get_irg_initial_exec)(const ir_graph *irg)
526 {
527         return get_irg_initial_exec_(irg);
528 }
529
530 void (set_irg_initial_exec)(ir_graph *irg, ir_node *node)
531 {
532         set_irg_initial_exec_(irg, node);
533 }
534
535 ir_node *(get_irg_frame)(const ir_graph *irg)
536 {
537         return get_irg_frame_(irg);
538 }
539
540 void (set_irg_frame)(ir_graph *irg, ir_node *node)
541 {
542         set_irg_frame_(irg, node);
543 }
544
545 ir_node *(get_irg_initial_mem)(const ir_graph *irg)
546 {
547         return get_irg_initial_mem_(irg);
548 }
549
550 void (set_irg_initial_mem)(ir_graph *irg, ir_node *node)
551 {
552         set_irg_initial_mem_(irg, node);
553 }
554
555 ir_node *(get_irg_args)(const ir_graph *irg)
556 {
557         return get_irg_args_(irg);
558 }
559
560 void (set_irg_args)(ir_graph *irg, ir_node *node)
561 {
562         set_irg_args_(irg, node);
563 }
564
565 ir_node *(get_irg_no_mem)(const ir_graph *irg)
566 {
567         return get_irg_no_mem_(irg);
568 }
569
570 void (set_irg_no_mem)(ir_graph *irg, ir_node *node)
571 {
572         set_irg_no_mem_(irg, node);
573 }
574
575 ir_entity *(get_irg_entity)(const ir_graph *irg)
576 {
577         return get_irg_entity_(irg);
578 }
579
580 void (set_irg_entity)(ir_graph *irg, ir_entity *ent)
581 {
582         set_irg_entity_(irg, ent);
583 }
584
585 ir_type *(get_irg_frame_type)(ir_graph *irg)
586 {
587         return get_irg_frame_type_(irg);
588 }
589
590 void (set_irg_frame_type)(ir_graph *irg, ir_type *ftp)
591 {
592         set_irg_frame_type_(irg, ftp);
593 }
594
595 int get_irg_n_locs(ir_graph *irg)
596 {
597         return irg->n_loc - 1;
598 }
599
600 /* Returns the obstack associated with the graph. */
601 struct obstack *(get_irg_obstack)(const ir_graph *irg)
602 {
603         return get_irg_obstack_(irg);
604 }
605
606 /*
607  * Returns true if the node n is allocated on the storage of graph irg.
608  *
609  * Implementation is GLIBC specific as is uses the internal _obstack_chunk implementation.
610  */
611 int node_is_in_irgs_storage(const ir_graph *irg, const ir_node *n)
612 {
613         struct _obstack_chunk *p;
614
615         /*
616          * checks weather the ir_node pointer is on the obstack.
617          * A more sophisticated check would test the "whole" ir_node
618          */
619         for (p = irg->obst->chunk; p; p = p->prev) {
620                 if (((char *)p->contents <= (char *)n) && ((char *)n < (char *)p->limit))
621                         return 1;
622         }
623
624         return 0;
625 }
626
627 irg_phase_state (get_irg_phase_state)(const ir_graph *irg)
628 {
629         return get_irg_phase_state_(irg);
630 }
631
632 void (set_irg_phase_state)(ir_graph *irg, irg_phase_state state)
633 {
634         set_irg_phase_state_(irg, state);
635 }
636
637 op_pin_state (get_irg_pinned)(const ir_graph *irg)
638 {
639         return get_irg_pinned_(irg);
640 }
641
642 void (set_irg_pinned)(ir_graph *irg, op_pin_state p)
643 {
644         set_irg_pinned_(irg, p);
645 }
646
647 irg_callee_info_state (get_irg_callee_info_state)(const ir_graph *irg)
648 {
649         return get_irg_callee_info_state_(irg);
650 }
651
652 void (set_irg_callee_info_state)(ir_graph *irg, irg_callee_info_state s)
653 {
654         set_irg_callee_info_state_(irg, s);
655 }
656
657 irg_inline_property (get_irg_inline_property)(const ir_graph *irg)
658 {
659         return get_irg_inline_property_(irg);
660 }
661
662 void (set_irg_inline_property)(ir_graph *irg, irg_inline_property s)
663 {
664         set_irg_inline_property_(irg, s);
665 }
666
667 mtp_additional_properties (get_irg_additional_properties)(const ir_graph *irg)
668 {
669         return get_irg_additional_properties_(irg);
670 }
671
672 void (set_irg_additional_properties)(ir_graph *irg, mtp_additional_properties property_mask)
673 {
674         set_irg_additional_properties_(irg, property_mask);
675 }
676
677 void (add_irg_additional_properties)(ir_graph *irg, mtp_additional_properties flag)
678 {
679         add_irg_additional_properties_(irg, flag);
680 }
681
682 void (set_irg_link)(ir_graph *irg, void *thing)
683 {
684         set_irg_link_(irg, thing);
685 }
686
687 void *(get_irg_link)(const ir_graph *irg)
688 {
689         return get_irg_link_(irg);
690 }
691
692 ir_visited_t (get_irg_visited)(const ir_graph *irg)
693 {
694         return get_irg_visited_(irg);
695 }
696
697 /** maximum visited flag content of all ir_graph visited fields. */
698 static ir_visited_t max_irg_visited = 0;
699
700 void set_irg_visited(ir_graph *irg, ir_visited_t visited)
701 {
702         irg->visited = visited;
703         if (irg->visited > max_irg_visited) {
704                 max_irg_visited = irg->visited;
705         }
706 }
707
708 void inc_irg_visited(ir_graph *irg)
709 {
710         ++irg->visited;
711         if (irg->visited > max_irg_visited) {
712                 max_irg_visited = irg->visited;
713         }
714 }
715
716 ir_visited_t get_max_irg_visited(void)
717 {
718         return max_irg_visited;
719 }
720
721 void set_max_irg_visited(int val)
722 {
723         max_irg_visited = val;
724 }
725
726 ir_visited_t inc_max_irg_visited(void)
727 {
728 #ifndef NDEBUG
729         size_t i;
730         for (i = 0; i < get_irp_n_irgs(); i++)
731                 assert(max_irg_visited >= get_irg_visited(get_irp_irg(i)));
732 #endif
733         return ++max_irg_visited;
734 }
735
736 ir_visited_t (get_irg_block_visited)(const ir_graph *irg)
737 {
738         return get_irg_block_visited_(irg);
739 }
740
741 void (set_irg_block_visited)(ir_graph *irg, ir_visited_t visited)
742 {
743         set_irg_block_visited_(irg, visited);
744 }
745
746 void (inc_irg_block_visited)(ir_graph *irg)
747 {
748   inc_irg_block_visited_(irg);
749 }
750
751 /* Return the floating point model of this graph. */
752 unsigned (get_irg_fp_model)(const ir_graph *irg)
753 {
754         return get_irg_fp_model_(irg);
755 }
756
757 /* Sets the floating point model for this graph. */
758 void set_irg_fp_model(ir_graph *irg, unsigned model)
759 {
760         irg->fp_model = model;
761 }
762
763 /* set a description for local value n */
764 void set_irg_loc_description(ir_graph *irg, int n, void *description)
765 {
766         assert(0 <= n && n < irg->n_loc);
767
768         if (! irg->loc_descriptions)
769                 irg->loc_descriptions = XMALLOCNZ(void*, irg->n_loc);
770
771         irg->loc_descriptions[n] = description;
772 }
773
774 /* get the description for local value n */
775 void *get_irg_loc_description(ir_graph *irg, int n)
776 {
777         assert(0 <= n && n < irg->n_loc);
778         return irg->loc_descriptions ? irg->loc_descriptions[n] : NULL;
779 }
780
781 #ifndef NDEBUG
782 void ir_reserve_resources(ir_graph *irg, ir_resources_t resources)
783 {
784         assert((irg->reserved_resources & resources) == 0);
785         irg->reserved_resources |= resources;
786 }
787
788 void ir_free_resources(ir_graph *irg, ir_resources_t resources)
789 {
790         assert((irg->reserved_resources & resources) == resources);
791         irg->reserved_resources &= ~resources;
792 }
793
794 ir_resources_t ir_resources_reserved(const ir_graph *irg)
795 {
796         return irg->reserved_resources;
797 }
798 #endif /* NDEBUG */
799
800 /* Returns a estimated node count of the irg. */
801 unsigned (get_irg_estimated_node_cnt)(const ir_graph *irg)
802 {
803         return get_irg_estimated_node_cnt_(irg);
804 }
805
806 /* Returns the last irn index for this graph. */
807 unsigned get_irg_last_idx(const ir_graph *irg)
808 {
809         return irg->last_node_idx;
810 }
811
812 /* register additional space in an IR graph */
813 size_t register_additional_graph_data(size_t size)
814 {
815         assert(!forbid_new_data && "Too late to register additional node data");
816
817         if (forbid_new_data)
818                 return 0;
819
820         return additional_graph_data_size += size;
821 }
822
823 void (set_irg_state)(ir_graph *irg, ir_graph_state_t state)
824 {
825         set_irg_state_(irg, state);
826 }
827
828 void (clear_irg_state)(ir_graph *irg, ir_graph_state_t state)
829 {
830         clear_irg_state_(irg, state);
831 }
832
833 int (is_irg_state)(const ir_graph *irg, ir_graph_state_t state)
834 {
835         return is_irg_state_(irg, state);
836 }