rename ir_phase to ir_nodemap and simplify interface
[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  * @version  $Id$
25  */
26 #include "config.h"
27
28 #include <string.h>
29 #include <stddef.h>
30
31 #include "xmalloc.h"
32 #include "ircons_t.h"
33 #include "irgraph_t.h"
34 #include "irprog_t.h"
35 #include "irgraph_t.h"
36 #include "irnode_t.h"
37 #include "iropt_t.h"
38 #include "irflag_t.h"
39 #include "array.h"
40 #include "irgmod.h"
41 #include "irouts.h"
42 #include "irhooks.h"
43 #include "irtools.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         set_irn_visited(no_mem, -1);
314
315         return res;
316 }
317
318 /**
319  * Pre-Walker: Copies blocks and nodes from the original method graph
320  * to the copied graph.
321  *
322  * @param n    A node from the original method graph.
323  * @param env  The copied graph.
324  */
325 static void copy_all_nodes(ir_node *node, void *env)
326 {
327         ir_graph *irg      = (ir_graph*)env;
328         ir_node  *new_node = irn_copy_into_irg(node, irg);
329
330         set_irn_link(node, new_node);
331
332         /* fix access to entities on the stack frame */
333         if (is_Sel(new_node)) {
334                 ir_entity *ent = get_Sel_entity(new_node);
335                 ir_type   *tp  = get_entity_owner(ent);
336
337                 if (is_frame_type(tp)) {
338                         /* replace by the copied entity */
339                         ent = (ir_entity*)get_entity_link(ent);
340
341                         assert(is_entity(ent));
342                         assert(get_entity_owner(ent) == get_irg_frame_type(irg));
343                         set_Sel_entity(new_node, ent);
344                 }
345         }
346 }
347
348 /**
349  * Post-walker: Set the predecessors of the copied nodes.
350  * The copied nodes are set as link of their original nodes. The links of
351  * "irn" predecessors are the predecessors of copied node.
352  */
353 static void rewire(ir_node *irn, void *env)
354 {
355         (void) env;
356         irn_rewire_inputs(irn);
357 }
358
359 static ir_node *get_new_node(const ir_node *old_node)
360 {
361         return (ir_node*) get_irn_link(old_node);
362 }
363
364 /*
365  * Create a new graph that is a copy of a given one.
366  */
367 ir_graph *create_irg_copy(ir_graph *irg)
368 {
369         ir_graph *res;
370
371         res = alloc_graph();
372
373         res->n_loc = 0;
374         res->visited = 0;       /* visited flag, for the ir walker */
375         res->block_visited = 0; /* visited flag, for the 'block'-walker */
376         res->obst       = XMALLOC(struct obstack);
377         obstack_init(res->obst);
378         res->extbb_obst = NULL;
379
380         res->last_node_idx = 0;
381
382         res->phase_state      = irg->phase_state;
383         res->irg_pinned_state = irg->irg_pinned_state;
384         res->fp_model         = irg->fp_model;
385
386         new_identities(res);
387
388         /* clone the frame type here for safety */
389         irp_reserve_resources(irp, IRP_RESOURCE_ENTITY_LINK);
390         res->frame_type  = clone_frame_type(irg->frame_type);
391
392         res->phase_state = irg->phase_state;
393
394         ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
395
396         /* copy all nodes from the graph irg to the new graph res */
397         irg_walk_anchors(irg, copy_all_nodes, rewire, res);
398
399         /* copy the Anchor node */
400         res->anchor = get_new_node(irg->anchor);
401
402         /* -- The end block -- */
403         set_irg_end_block (res, get_new_node(get_irg_end_block(irg)));
404         set_irg_end       (res, get_new_node(get_irg_end(irg)));
405
406         /* -- The start block -- */
407         set_irg_start_block(res, get_new_node(get_irg_start_block(irg)));
408         set_irg_no_mem     (res, get_new_node(get_irg_no_mem(irg)));
409         set_irg_start      (res, get_new_node(get_irg_start(irg)));
410
411         /* Proj results of start node */
412         set_irg_initial_mem(res, get_new_node(get_irg_initial_mem(irg)));
413
414         /* Copy the node count estimation. Would be strange if this
415            is different from the original one. */
416         res->estimated_node_count = irg->estimated_node_count;
417
418         ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
419         irp_free_resources(irp, IRP_RESOURCE_ENTITY_LINK);
420
421         return res;
422 }
423
424 /* Frees the passed irgraph.
425    Deallocates all nodes in this graph and the ir_graph structure.
426    Sets the field irgraph in the corresponding entity to NULL.
427    Does not remove the irgraph from the list in irprog (requires
428    inefficient search, call remove_irp_irg by hand).
429    Does not free types, entities or modes that are used only by this
430    graph, nor the entity standing for this graph. */
431 void free_ir_graph(ir_graph *irg)
432 {
433         assert(is_ir_graph(irg));
434
435         edges_deactivate(irg);
436
437         hook_free_graph(irg);
438         free_irg_outs(irg);
439         if (irg->frame_type)
440                 free_type(irg->frame_type);
441         del_identities(irg);
442         if (irg->ent) {
443                 set_entity_irg(irg->ent, NULL);  /* not set in const code irg */
444         }
445
446         free_End(get_irg_end(irg));
447         obstack_free(irg->obst,NULL);
448         free(irg->obst);
449         if (irg->loc_descriptions)
450                 free(irg->loc_descriptions);
451         irg->kind = k_BAD;
452         free_graph(irg);
453 }
454
455 /* access routines for all ir_graph attributes:
456    templates:
457    {attr type} get_irg_{attribute name} (ir_graph *irg);
458    void set_irg_{attr name} (ir_graph *irg, {attr type} {attr}); */
459
460 int (is_ir_graph)(const void *thing)
461 {
462         return _is_ir_graph(thing);
463 }
464
465 #ifdef DEBUG_libfirm
466 /* Outputs a unique number for this node */
467 long get_irg_graph_nr(const ir_graph *irg)
468 {
469         return irg->graph_nr;
470 }
471 #else
472 long get_irg_graph_nr(const ir_graph *irg)
473 {
474         return PTR_TO_INT(irg);
475 }
476 #endif
477
478 size_t get_irg_idx(const ir_graph *irg)
479 {
480         return irg->index;
481 }
482
483 ir_node *(get_idx_irn)(const ir_graph *irg, unsigned idx)
484 {
485         return _get_idx_irn(irg, idx);
486 }
487
488 ir_node *(get_irg_start_block)(const ir_graph *irg)
489 {
490         return _get_irg_start_block(irg);
491 }
492
493 void (set_irg_start_block)(ir_graph *irg, ir_node *node)
494 {
495         _set_irg_start_block(irg, node);
496 }
497
498 ir_node *(get_irg_start)(const ir_graph *irg)
499 {
500         return _get_irg_start(irg);
501 }
502
503 void (set_irg_start)(ir_graph *irg, ir_node *node)
504 {
505         _set_irg_start(irg, node);
506 }
507
508 ir_node *(get_irg_end_block)(const ir_graph *irg)
509 {
510         return _get_irg_end_block(irg);
511 }
512
513 void (set_irg_end_block)(ir_graph *irg, ir_node *node)
514 {
515   _set_irg_end_block(irg, node);
516 }
517
518 ir_node *(get_irg_end)(const ir_graph *irg)
519 {
520         return _get_irg_end(irg);
521 }
522
523 void (set_irg_end)(ir_graph *irg, ir_node *node)
524 {
525         _set_irg_end(irg, node);
526 }
527
528 ir_node *(get_irg_initial_exec)(const ir_graph *irg)
529 {
530         return _get_irg_initial_exec(irg);
531 }
532
533 void (set_irg_initial_exec)(ir_graph *irg, ir_node *node)
534 {
535         _set_irg_initial_exec(irg, node);
536 }
537
538 ir_node *(get_irg_frame)(const ir_graph *irg)
539 {
540         return _get_irg_frame(irg);
541 }
542
543 void (set_irg_frame)(ir_graph *irg, ir_node *node)
544 {
545         _set_irg_frame(irg, node);
546 }
547
548 ir_node *(get_irg_initial_mem)(const ir_graph *irg)
549 {
550         return _get_irg_initial_mem(irg);
551 }
552
553 void (set_irg_initial_mem)(ir_graph *irg, ir_node *node)
554 {
555         _set_irg_initial_mem(irg, node);
556 }
557
558 ir_node *(get_irg_args)(const ir_graph *irg)
559 {
560         return _get_irg_args(irg);
561 }
562
563 void (set_irg_args)(ir_graph *irg, ir_node *node)
564 {
565         _set_irg_args(irg, node);
566 }
567
568 ir_node *(get_irg_no_mem)(const ir_graph *irg)
569 {
570         return _get_irg_no_mem(irg);
571 }
572
573 void (set_irg_no_mem)(ir_graph *irg, ir_node *node)
574 {
575         _set_irg_no_mem(irg, node);
576 }
577
578 ir_entity *(get_irg_entity)(const ir_graph *irg)
579 {
580         return _get_irg_entity(irg);
581 }
582
583 void (set_irg_entity)(ir_graph *irg, ir_entity *ent)
584 {
585         _set_irg_entity(irg, ent);
586 }
587
588 ir_type *(get_irg_frame_type)(ir_graph *irg)
589 {
590         return _get_irg_frame_type(irg);
591 }
592
593 void (set_irg_frame_type)(ir_graph *irg, ir_type *ftp)
594 {
595         _set_irg_frame_type(irg, ftp);
596 }
597
598 int get_irg_n_locs(ir_graph *irg)
599 {
600         return irg->n_loc - 1;
601 }
602
603 /* Returns the obstack associated with the graph. */
604 struct obstack *
605 (get_irg_obstack)(const ir_graph *irg) {
606         return _get_irg_obstack(irg);
607 }
608
609 /*
610  * Returns true if the node n is allocated on the storage of graph irg.
611  *
612  * Implementation is GLIBC specific as is uses the internal _obstack_chunk implementation.
613  */
614 int node_is_in_irgs_storage(const ir_graph *irg, const ir_node *n)
615 {
616         struct _obstack_chunk *p;
617
618         /*
619          * checks weather the ir_node pointer is on the obstack.
620          * A more sophisticated check would test the "whole" ir_node
621          */
622         for (p = irg->obst->chunk; p; p = p->prev) {
623                 if (((char *)p->contents <= (char *)n) && ((char *)n < (char *)p->limit))
624                         return 1;
625         }
626
627         return 0;
628 }
629
630 irg_phase_state (get_irg_phase_state)(const ir_graph *irg)
631 {
632         return _get_irg_phase_state(irg);
633 }
634
635 void (set_irg_phase_state)(ir_graph *irg, irg_phase_state state)
636 {
637         _set_irg_phase_state(irg, state);
638 }
639
640 op_pin_state (get_irg_pinned)(const ir_graph *irg)
641 {
642         return _get_irg_pinned(irg);
643 }
644
645 void (set_irg_pinned)(ir_graph *irg, op_pin_state p)
646 {
647         _set_irg_pinned(irg, p);
648 }
649
650 irg_callee_info_state (get_irg_callee_info_state)(const ir_graph *irg)
651 {
652         return _get_irg_callee_info_state(irg);
653 }
654
655 void (set_irg_callee_info_state)(ir_graph *irg, irg_callee_info_state s)
656 {
657         _set_irg_callee_info_state(irg, s);
658 }
659
660 irg_inline_property (get_irg_inline_property)(const ir_graph *irg)
661 {
662         return _get_irg_inline_property(irg);
663 }
664
665 void (set_irg_inline_property)(ir_graph *irg, irg_inline_property s)
666 {
667         _set_irg_inline_property(irg, s);
668 }
669
670 mtp_additional_properties (get_irg_additional_properties)(const ir_graph *irg)
671 {
672         return _get_irg_additional_properties(irg);
673 }
674
675 void (set_irg_additional_properties)(ir_graph *irg, mtp_additional_properties property_mask)
676 {
677         _set_irg_additional_properties(irg, property_mask);
678 }
679
680 void (add_irg_additional_properties)(ir_graph *irg, mtp_additional_properties flag)
681 {
682         _add_irg_additional_properties(irg, flag);
683 }
684
685 void (set_irg_link)(ir_graph *irg, void *thing)
686 {
687         _set_irg_link(irg, thing);
688 }
689
690 void *(get_irg_link)(const ir_graph *irg)
691 {
692         return _get_irg_link(irg);
693 }
694
695 ir_visited_t (get_irg_visited)(const ir_graph *irg)
696 {
697         return _get_irg_visited(irg);
698 }
699
700 /** maximum visited flag content of all ir_graph visited fields. */
701 static ir_visited_t max_irg_visited = 0;
702
703 void set_irg_visited(ir_graph *irg, ir_visited_t visited)
704 {
705         irg->visited = visited;
706         if (irg->visited > max_irg_visited) {
707                 max_irg_visited = irg->visited;
708         }
709 }
710
711 void inc_irg_visited(ir_graph *irg)
712 {
713         ++irg->visited;
714         if (irg->visited > max_irg_visited) {
715                 max_irg_visited = irg->visited;
716         }
717 }
718
719 ir_visited_t get_max_irg_visited(void)
720 {
721         return max_irg_visited;
722 }
723
724 void set_max_irg_visited(int val)
725 {
726         max_irg_visited = val;
727 }
728
729 ir_visited_t inc_max_irg_visited(void)
730 {
731 #ifndef NDEBUG
732         size_t i;
733         for (i = 0; i < get_irp_n_irgs(); i++)
734                 assert(max_irg_visited >= get_irg_visited(get_irp_irg(i)));
735 #endif
736         return ++max_irg_visited;
737 }
738
739 ir_visited_t (get_irg_block_visited)(const ir_graph *irg)
740 {
741         return _get_irg_block_visited(irg);
742 }
743
744 void (set_irg_block_visited)(ir_graph *irg, ir_visited_t visited)
745 {
746         _set_irg_block_visited(irg, visited);
747 }
748
749 void (inc_irg_block_visited)(ir_graph *irg)
750 {
751   _inc_irg_block_visited(irg);
752 }
753
754 /* Return the floating point model of this graph. */
755 unsigned (get_irg_fp_model)(const ir_graph *irg)
756 {
757         return _get_irg_fp_model(irg);
758 }
759
760 /* Sets the floating point model for this graph. */
761 void set_irg_fp_model(ir_graph *irg, unsigned model)
762 {
763         irg->fp_model = model;
764 }
765
766 /* set a description for local value n */
767 void set_irg_loc_description(ir_graph *irg, int n, void *description)
768 {
769         assert(0 <= n && n < irg->n_loc);
770
771         if (! irg->loc_descriptions)
772                 irg->loc_descriptions = XMALLOCNZ(void*, irg->n_loc);
773
774         irg->loc_descriptions[n] = description;
775 }
776
777 /* get the description for local value n */
778 void *get_irg_loc_description(ir_graph *irg, int n)
779 {
780         assert(0 <= n && n < irg->n_loc);
781         return irg->loc_descriptions ? irg->loc_descriptions[n] : NULL;
782 }
783
784 #ifndef NDEBUG
785 void ir_reserve_resources(ir_graph *irg, ir_resources_t resources)
786 {
787         assert((irg->reserved_resources & resources) == 0);
788         irg->reserved_resources |= resources;
789 }
790
791 void ir_free_resources(ir_graph *irg, ir_resources_t resources)
792 {
793         assert((irg->reserved_resources & resources) == resources);
794         irg->reserved_resources &= ~resources;
795 }
796
797 ir_resources_t ir_resources_reserved(const ir_graph *irg)
798 {
799         return irg->reserved_resources;
800 }
801 #endif /* NDEBUG */
802
803 /* Returns a estimated node count of the irg. */
804 unsigned (get_irg_estimated_node_cnt)(const ir_graph *irg)
805 {
806         return _get_irg_estimated_node_cnt(irg);
807 }
808
809 /* Returns the last irn index for this graph. */
810 unsigned get_irg_last_idx(const ir_graph *irg)
811 {
812         return irg->last_node_idx;
813 }
814
815 /* register additional space in an IR graph */
816 size_t register_additional_graph_data(size_t size)
817 {
818         assert(!forbid_new_data && "Too late to register additional node data");
819
820         if (forbid_new_data)
821                 return 0;
822
823         return additional_graph_data_size += size;
824 }
825
826 void (set_irg_state)(ir_graph *irg, ir_graph_state_t state)
827 {
828         _set_irg_state(irg, state);
829 }
830
831 void (clear_irg_state)(ir_graph *irg, ir_graph_state_t state)
832 {
833         _clear_irg_state(irg, state);
834 }
835
836 int (is_irg_state)(const ir_graph *irg, ir_graph_state_t state)
837 {
838         return _is_irg_state(irg, state);
839 }