we want to visit NoMem in the const code irg
[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         if (irg->frame_type)
439                 free_type(irg->frame_type);
440         del_identities(irg);
441         if (irg->ent) {
442                 set_entity_irg(irg->ent, NULL);  /* not set in const code irg */
443         }
444
445         free_End(get_irg_end(irg));
446         obstack_free(irg->obst,NULL);
447         free(irg->obst);
448         if (irg->loc_descriptions)
449                 free(irg->loc_descriptions);
450         irg->kind = k_BAD;
451         free_graph(irg);
452 }
453
454 /* access routines for all ir_graph attributes:
455    templates:
456    {attr type} get_irg_{attribute name} (ir_graph *irg);
457    void set_irg_{attr name} (ir_graph *irg, {attr type} {attr}); */
458
459 int (is_ir_graph)(const void *thing)
460 {
461         return is_ir_graph_(thing);
462 }
463
464 #ifdef DEBUG_libfirm
465 /* Outputs a unique number for this node */
466 long get_irg_graph_nr(const ir_graph *irg)
467 {
468         return irg->graph_nr;
469 }
470 #else
471 long get_irg_graph_nr(const ir_graph *irg)
472 {
473         return PTR_TO_INT(irg);
474 }
475 #endif
476
477 size_t get_irg_idx(const ir_graph *irg)
478 {
479         return irg->index;
480 }
481
482 ir_node *(get_idx_irn)(const ir_graph *irg, unsigned idx)
483 {
484         return get_idx_irn_(irg, idx);
485 }
486
487 ir_node *(get_irg_start_block)(const ir_graph *irg)
488 {
489         return get_irg_start_block_(irg);
490 }
491
492 void (set_irg_start_block)(ir_graph *irg, ir_node *node)
493 {
494         set_irg_start_block_(irg, node);
495 }
496
497 ir_node *(get_irg_start)(const ir_graph *irg)
498 {
499         return get_irg_start_(irg);
500 }
501
502 void (set_irg_start)(ir_graph *irg, ir_node *node)
503 {
504         set_irg_start_(irg, node);
505 }
506
507 ir_node *(get_irg_end_block)(const ir_graph *irg)
508 {
509         return get_irg_end_block_(irg);
510 }
511
512 void (set_irg_end_block)(ir_graph *irg, ir_node *node)
513 {
514         set_irg_end_block_(irg, node);
515 }
516
517 ir_node *(get_irg_end)(const ir_graph *irg)
518 {
519         return get_irg_end_(irg);
520 }
521
522 void (set_irg_end)(ir_graph *irg, ir_node *node)
523 {
524         set_irg_end_(irg, node);
525 }
526
527 ir_node *(get_irg_initial_exec)(const ir_graph *irg)
528 {
529         return get_irg_initial_exec_(irg);
530 }
531
532 void (set_irg_initial_exec)(ir_graph *irg, ir_node *node)
533 {
534         set_irg_initial_exec_(irg, node);
535 }
536
537 ir_node *(get_irg_frame)(const ir_graph *irg)
538 {
539         return get_irg_frame_(irg);
540 }
541
542 void (set_irg_frame)(ir_graph *irg, ir_node *node)
543 {
544         set_irg_frame_(irg, node);
545 }
546
547 ir_node *(get_irg_initial_mem)(const ir_graph *irg)
548 {
549         return get_irg_initial_mem_(irg);
550 }
551
552 void (set_irg_initial_mem)(ir_graph *irg, ir_node *node)
553 {
554         set_irg_initial_mem_(irg, node);
555 }
556
557 ir_node *(get_irg_args)(const ir_graph *irg)
558 {
559         return get_irg_args_(irg);
560 }
561
562 void (set_irg_args)(ir_graph *irg, ir_node *node)
563 {
564         set_irg_args_(irg, node);
565 }
566
567 ir_node *(get_irg_no_mem)(const ir_graph *irg)
568 {
569         return get_irg_no_mem_(irg);
570 }
571
572 void (set_irg_no_mem)(ir_graph *irg, ir_node *node)
573 {
574         set_irg_no_mem_(irg, node);
575 }
576
577 ir_entity *(get_irg_entity)(const ir_graph *irg)
578 {
579         return get_irg_entity_(irg);
580 }
581
582 void (set_irg_entity)(ir_graph *irg, ir_entity *ent)
583 {
584         set_irg_entity_(irg, ent);
585 }
586
587 ir_type *(get_irg_frame_type)(ir_graph *irg)
588 {
589         return get_irg_frame_type_(irg);
590 }
591
592 void (set_irg_frame_type)(ir_graph *irg, ir_type *ftp)
593 {
594         set_irg_frame_type_(irg, ftp);
595 }
596
597 int get_irg_n_locs(ir_graph *irg)
598 {
599         return irg->n_loc - 1;
600 }
601
602 /* Returns the obstack associated with the graph. */
603 struct obstack *(get_irg_obstack)(const ir_graph *irg)
604 {
605         return get_irg_obstack_(irg);
606 }
607
608 /*
609  * Returns true if the node n is allocated on the storage of graph irg.
610  *
611  * Implementation is GLIBC specific as is uses the internal _obstack_chunk implementation.
612  */
613 int node_is_in_irgs_storage(const ir_graph *irg, const ir_node *n)
614 {
615         struct _obstack_chunk *p;
616
617         /*
618          * checks weather the ir_node pointer is on the obstack.
619          * A more sophisticated check would test the "whole" ir_node
620          */
621         for (p = irg->obst->chunk; p; p = p->prev) {
622                 if (((char *)p->contents <= (char *)n) && ((char *)n < (char *)p->limit))
623                         return 1;
624         }
625
626         return 0;
627 }
628
629 irg_phase_state (get_irg_phase_state)(const ir_graph *irg)
630 {
631         return get_irg_phase_state_(irg);
632 }
633
634 void (set_irg_phase_state)(ir_graph *irg, irg_phase_state state)
635 {
636         set_irg_phase_state_(irg, state);
637 }
638
639 op_pin_state (get_irg_pinned)(const ir_graph *irg)
640 {
641         return get_irg_pinned_(irg);
642 }
643
644 void (set_irg_pinned)(ir_graph *irg, op_pin_state p)
645 {
646         set_irg_pinned_(irg, p);
647 }
648
649 irg_callee_info_state (get_irg_callee_info_state)(const ir_graph *irg)
650 {
651         return get_irg_callee_info_state_(irg);
652 }
653
654 void (set_irg_callee_info_state)(ir_graph *irg, irg_callee_info_state s)
655 {
656         set_irg_callee_info_state_(irg, s);
657 }
658
659 irg_inline_property (get_irg_inline_property)(const ir_graph *irg)
660 {
661         return get_irg_inline_property_(irg);
662 }
663
664 void (set_irg_inline_property)(ir_graph *irg, irg_inline_property s)
665 {
666         set_irg_inline_property_(irg, s);
667 }
668
669 mtp_additional_properties (get_irg_additional_properties)(const ir_graph *irg)
670 {
671         return get_irg_additional_properties_(irg);
672 }
673
674 void (set_irg_additional_properties)(ir_graph *irg, mtp_additional_properties property_mask)
675 {
676         set_irg_additional_properties_(irg, property_mask);
677 }
678
679 void (add_irg_additional_properties)(ir_graph *irg, mtp_additional_properties flag)
680 {
681         add_irg_additional_properties_(irg, flag);
682 }
683
684 void (set_irg_link)(ir_graph *irg, void *thing)
685 {
686         set_irg_link_(irg, thing);
687 }
688
689 void *(get_irg_link)(const ir_graph *irg)
690 {
691         return get_irg_link_(irg);
692 }
693
694 ir_visited_t (get_irg_visited)(const ir_graph *irg)
695 {
696         return get_irg_visited_(irg);
697 }
698
699 /** maximum visited flag content of all ir_graph visited fields. */
700 static ir_visited_t max_irg_visited = 0;
701
702 void set_irg_visited(ir_graph *irg, ir_visited_t visited)
703 {
704         irg->visited = visited;
705         if (irg->visited > max_irg_visited) {
706                 max_irg_visited = irg->visited;
707         }
708 }
709
710 void inc_irg_visited(ir_graph *irg)
711 {
712         ++irg->visited;
713         if (irg->visited > max_irg_visited) {
714                 max_irg_visited = irg->visited;
715         }
716 }
717
718 ir_visited_t get_max_irg_visited(void)
719 {
720         return max_irg_visited;
721 }
722
723 void set_max_irg_visited(int val)
724 {
725         max_irg_visited = val;
726 }
727
728 ir_visited_t inc_max_irg_visited(void)
729 {
730 #ifndef NDEBUG
731         size_t i;
732         for (i = 0; i < get_irp_n_irgs(); i++)
733                 assert(max_irg_visited >= get_irg_visited(get_irp_irg(i)));
734 #endif
735         return ++max_irg_visited;
736 }
737
738 ir_visited_t (get_irg_block_visited)(const ir_graph *irg)
739 {
740         return get_irg_block_visited_(irg);
741 }
742
743 void (set_irg_block_visited)(ir_graph *irg, ir_visited_t visited)
744 {
745         set_irg_block_visited_(irg, visited);
746 }
747
748 void (inc_irg_block_visited)(ir_graph *irg)
749 {
750   inc_irg_block_visited_(irg);
751 }
752
753 /* Return the floating point model of this graph. */
754 unsigned (get_irg_fp_model)(const ir_graph *irg)
755 {
756         return get_irg_fp_model_(irg);
757 }
758
759 /* Sets the floating point model for this graph. */
760 void set_irg_fp_model(ir_graph *irg, unsigned model)
761 {
762         irg->fp_model = model;
763 }
764
765 /* set a description for local value n */
766 void set_irg_loc_description(ir_graph *irg, int n, void *description)
767 {
768         assert(0 <= n && n < irg->n_loc);
769
770         if (! irg->loc_descriptions)
771                 irg->loc_descriptions = XMALLOCNZ(void*, irg->n_loc);
772
773         irg->loc_descriptions[n] = description;
774 }
775
776 /* get the description for local value n */
777 void *get_irg_loc_description(ir_graph *irg, int n)
778 {
779         assert(0 <= n && n < irg->n_loc);
780         return irg->loc_descriptions ? irg->loc_descriptions[n] : NULL;
781 }
782
783 #ifndef NDEBUG
784 void ir_reserve_resources(ir_graph *irg, ir_resources_t resources)
785 {
786         assert((irg->reserved_resources & resources) == 0);
787         irg->reserved_resources |= resources;
788 }
789
790 void ir_free_resources(ir_graph *irg, ir_resources_t resources)
791 {
792         assert((irg->reserved_resources & resources) == resources);
793         irg->reserved_resources &= ~resources;
794 }
795
796 ir_resources_t ir_resources_reserved(const ir_graph *irg)
797 {
798         return irg->reserved_resources;
799 }
800 #endif /* NDEBUG */
801
802 /* Returns a estimated node count of the irg. */
803 unsigned (get_irg_estimated_node_cnt)(const ir_graph *irg)
804 {
805         return get_irg_estimated_node_cnt_(irg);
806 }
807
808 /* Returns the last irn index for this graph. */
809 unsigned get_irg_last_idx(const ir_graph *irg)
810 {
811         return irg->last_node_idx;
812 }
813
814 /* register additional space in an IR graph */
815 size_t register_additional_graph_data(size_t size)
816 {
817         assert(!forbid_new_data && "Too late to register additional node data");
818
819         if (forbid_new_data)
820                 return 0;
821
822         return additional_graph_data_size += size;
823 }
824
825 void (set_irg_state)(ir_graph *irg, ir_graph_state_t state)
826 {
827         set_irg_state_(irg, state);
828 }
829
830 void (clear_irg_state)(ir_graph *irg, ir_graph_state_t state)
831 {
832         clear_irg_state_(irg, state);
833 }
834
835 int (is_irg_state)(const ir_graph *irg, ir_graph_state_t state)
836 {
837         return is_irg_state_(irg, state);
838 }