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