Remove pointless local variables.
[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 #include "irphase.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->outs_state          = outs_none;
190         res->dom_state           = dom_none;
191         res->pdom_state          = dom_none;
192         res->typeinfo_state      = ir_typeinfo_none;
193         set_irp_typeinfo_inconsistent();           /* there is a new graph with typeinfo_none. */
194         res->callee_info_state   = irg_callee_info_none;
195         res->loopinfo_state      = loopinfo_none;
196         res->class_cast_state    = ir_class_casts_transitive;
197         res->extblk_state        = ir_extblk_info_none;
198         res->execfreq_state      = exec_freq_none;
199         res->fp_model            = fp_model_precise;
200         res->entity_usage_state  = ir_entity_usage_not_computed;
201         res->mem_disambig_opt    = aa_opt_inherited;
202
203         /*-- Type information for the procedure of the graph --*/
204         res->ent = ent;
205         set_entity_irg(ent, res);
206
207         /*--  a class type so that it can contain "inner" methods as in Pascal. --*/
208         res->frame_type = new_type_frame();
209
210         /* the Anchor node must be created first */
211         res->anchor = new_r_Anchor(res);
212
213         /*-- Nodes needed in every graph --*/
214         set_irg_end_block (res, new_r_immBlock(res));
215         set_irg_end(res, new_r_End(res, 0, NULL));
216
217         start_block = new_r_Block_noopt(res, 0, NULL);
218         set_irg_start_block(res, start_block);
219         set_irg_bad        (res, new_r_Bad(res));
220         set_irg_no_mem     (res, new_r_NoMem(res));
221         start = new_r_Start(res);
222         set_irg_start      (res, start);
223
224         /* Proj results of start node */
225         projX                   = new_r_Proj(start, mode_X, pn_Start_X_initial_exec);
226         set_irg_initial_exec    (res, projX);
227         set_irg_frame           (res, new_r_Proj(start, mode_P_data, pn_Start_P_frame_base));
228         set_irg_args            (res, new_r_Proj(start, mode_T,      pn_Start_T_args));
229         initial_mem             = new_r_Proj(start, mode_M, pn_Start_M);
230         set_irg_initial_mem(res, initial_mem);
231
232         res->index       = get_irp_new_irg_idx();
233 #ifdef DEBUG_libfirm
234         res->graph_nr    = get_irp_new_node_nr();
235 #endif
236
237         set_r_cur_block(res, start_block);
238         set_r_store(res, initial_mem);
239
240         /*-- Make a block to start with --*/
241         first_block = new_r_immBlock(res);
242         set_r_cur_block(res, first_block);
243         add_immBlock_pred(first_block, projX);
244
245         res->method_execution_frequency = -1.0;
246         res->estimated_node_count       = 0;
247
248         return res;
249 }
250
251 ir_graph *new_ir_graph(ir_entity *ent, int n_loc)
252 {
253         ir_graph *res = new_r_ir_graph(ent, n_loc);
254         add_irp_irg(res);          /* remember this graph global. */
255         return res;
256 }
257
258 /* Make a rudimentary IR graph for the constant code.
259    Must look like a correct irg, spare everything else. */
260 ir_graph *new_const_code_irg(void)
261 {
262         ir_graph *res = alloc_graph();
263         ir_node  *bad;
264         ir_node  *body_block;
265         ir_node  *end;
266         ir_node  *end_block;
267         ir_node  *no_mem;
268         ir_node  *projX;
269         ir_node  *start_block;
270         ir_node  *start;
271
272         /* inform statistics here, as blocks will be already build on this graph */
273         hook_new_graph(res, NULL);
274
275         res->n_loc         = 1; /* Only the memory. */
276         res->visited       = 0; /* visited flag, for the ir walker */
277         res->block_visited = 0; /* visited flag, for the 'block'-walker */
278         res->obst          = XMALLOC(struct obstack);
279         obstack_init(res->obst);
280         res->extbb_obst = NULL;
281
282         res->last_node_idx = 0;
283
284         res->phase_state      = phase_building;
285         res->irg_pinned_state = op_pin_state_pinned;
286         res->extblk_state     = ir_extblk_info_none;
287         res->fp_model         = fp_model_precise;
288
289         /* value table for global value numbering for optimizing use in iropt.c */
290         new_identities(res);
291         res->ent         = NULL;
292         res->frame_type  = NULL;
293
294         /* the Anchor node must be created first */
295         res->anchor = new_r_Anchor(res);
296
297         /* -- The end block -- */
298         end_block = new_r_Block_noopt(res, 0, NULL);
299         set_irg_end_block(res, end_block);
300         end = new_r_End(res, 0, NULL);
301         set_irg_end(res, end);
302
303         /* -- The start block -- */
304         start_block = new_r_Block_noopt(res, 0, NULL);
305         set_irg_start_block(res, start_block);
306         bad = new_r_Bad(res);
307         set_irg_bad(res, bad);
308         no_mem = new_r_NoMem(res);
309         set_irg_no_mem(res, no_mem);
310         start = new_r_Start(res);
311         set_irg_start(res, start);
312
313         /* Proj results of start node */
314         set_irg_initial_mem(res, new_r_Proj(start, mode_M, pn_Start_M));
315         projX = new_r_Proj(start, mode_X, pn_Start_X_initial_exec);
316
317         body_block = new_r_Block(res, 1, &projX);
318
319         set_r_cur_block(res, body_block);
320
321         /* Set the visited flag high enough that the blocks will never be visited. */
322         set_irn_visited(body_block, -1);
323         set_Block_block_visited(body_block, -1);
324         set_Block_block_visited(start_block, -1);
325         set_irn_visited(start_block, -1);
326         set_irn_visited(bad, -1);
327         set_irn_visited(no_mem, -1);
328
329         return res;
330 }
331
332 /**
333  * Pre-Walker: Copies blocks and nodes from the original method graph
334  * to the copied graph.
335  *
336  * @param n    A node from the original method graph.
337  * @param env  The copied graph.
338  */
339 static void copy_all_nodes(ir_node *node, void *env)
340 {
341         ir_graph *irg      = (ir_graph*)env;
342         ir_node  *new_node = irn_copy_into_irg(node, irg);
343
344         set_irn_link(node, new_node);
345
346         /* fix access to entities on the stack frame */
347         if (is_Sel(new_node)) {
348                 ir_entity *ent = get_Sel_entity(new_node);
349                 ir_type   *tp  = get_entity_owner(ent);
350
351                 if (is_frame_type(tp)) {
352                         /* replace by the copied entity */
353                         ent = (ir_entity*)get_entity_link(ent);
354
355                         assert(is_entity(ent));
356                         assert(get_entity_owner(ent) == get_irg_frame_type(irg));
357                         set_Sel_entity(new_node, ent);
358                 }
359         }
360 }
361
362 /**
363  * Post-walker: Set the predecessors of the copied nodes.
364  * The copied nodes are set as link of their original nodes. The links of
365  * "irn" predecessors are the predecessors of copied node.
366  */
367 static void rewire(ir_node *irn, void *env)
368 {
369         (void) env;
370         irn_rewire_inputs(irn);
371 }
372
373 static ir_node *get_new_node(const ir_node *old_node)
374 {
375         return (ir_node*) get_irn_link(old_node);
376 }
377
378 /*
379  * Create a new graph that is a copy of a given one.
380  */
381 ir_graph *create_irg_copy(ir_graph *irg)
382 {
383         ir_graph *res;
384
385         res = alloc_graph();
386
387         res->n_loc = 0;
388         res->visited = 0;       /* visited flag, for the ir walker */
389         res->block_visited = 0; /* visited flag, for the 'block'-walker */
390         res->obst       = XMALLOC(struct obstack);
391         obstack_init(res->obst);
392         res->extbb_obst = NULL;
393
394         res->last_node_idx = 0;
395
396         res->phase_state      = irg->phase_state;
397         res->irg_pinned_state = irg->irg_pinned_state;
398         res->extblk_state     = ir_extblk_info_none;
399         res->fp_model         = irg->fp_model;
400
401         new_identities(res);
402
403         /* clone the frame type here for safety */
404         irp_reserve_resources(irp, IR_RESOURCE_ENTITY_LINK);
405         res->frame_type  = clone_frame_type(irg->frame_type);
406
407         res->phase_state = irg->phase_state;
408
409         ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
410
411         /* copy all nodes from the graph irg to the new graph res */
412         irg_walk_anchors(irg, copy_all_nodes, rewire, res);
413
414         /* copy the Anchor node */
415         res->anchor = get_new_node(irg->anchor);
416
417         /* -- The end block -- */
418         set_irg_end_block (res, get_new_node(get_irg_end_block(irg)));
419         set_irg_end       (res, get_new_node(get_irg_end(irg)));
420
421         /* -- The start block -- */
422         set_irg_start_block(res, get_new_node(get_irg_start_block(irg)));
423         set_irg_bad        (res, get_new_node(get_irg_bad(irg)));
424         set_irg_no_mem     (res, get_new_node(get_irg_no_mem(irg)));
425         set_irg_start      (res, get_new_node(get_irg_start(irg)));
426
427         /* Proj results of start node */
428         set_irg_initial_mem(res, get_new_node(get_irg_initial_mem(irg)));
429
430         /* Copy the node count estimation. Would be strange if this
431            is different from the original one. */
432         res->estimated_node_count = irg->estimated_node_count;
433
434         ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
435         irp_free_resources(irp, IR_RESOURCE_ENTITY_LINK);
436
437         return res;
438 }
439
440 /* Frees the passed irgraph.
441    Deallocates all nodes in this graph and the ir_graph structure.
442    Sets the field irgraph in the corresponding entity to NULL.
443    Does not remove the irgraph from the list in irprog (requires
444    inefficient search, call remove_irp_irg by hand).
445    Does not free types, entities or modes that are used only by this
446    graph, nor the entity standing for this graph. */
447 void free_ir_graph(ir_graph *irg)
448 {
449         assert(is_ir_graph(irg));
450
451         edges_deactivate(irg);
452
453         hook_free_graph(irg);
454         if (irg->outs_state != outs_none)
455                 free_irg_outs(irg);
456         if (irg->frame_type)
457                 free_type(irg->frame_type);
458         del_identities(irg);
459         if (irg->ent) {
460                 set_entity_irg(irg->ent, NULL);  /* not set in const code irg */
461         }
462
463         free_End(get_irg_end(irg));
464         obstack_free(irg->obst,NULL);
465         free(irg->obst);
466         if (irg->loc_descriptions)
467                 free(irg->loc_descriptions);
468         irg->kind = k_BAD;
469         free_graph(irg);
470 }
471
472 /* access routines for all ir_graph attributes:
473    templates:
474    {attr type} get_irg_{attribute name} (ir_graph *irg);
475    void set_irg_{attr name} (ir_graph *irg, {attr type} {attr}); */
476
477 int (is_ir_graph)(const void *thing)
478 {
479         return _is_ir_graph(thing);
480 }
481
482 #ifdef DEBUG_libfirm
483 /* Outputs a unique number for this node */
484 long get_irg_graph_nr(const ir_graph *irg)
485 {
486         return irg->graph_nr;
487 }
488 #else
489 long get_irg_graph_nr(const ir_graph *irg)
490 {
491         return PTR_TO_INT(irg);
492 }
493 #endif
494
495 size_t get_irg_idx(const ir_graph *irg)
496 {
497         return irg->index;
498 }
499
500 ir_node *(get_idx_irn)(ir_graph *irg, unsigned idx)
501 {
502         return _get_idx_irn(irg, idx);
503 }
504
505 ir_node *(get_irg_start_block)(const ir_graph *irg)
506 {
507         return _get_irg_start_block(irg);
508 }
509
510 void (set_irg_start_block)(ir_graph *irg, ir_node *node)
511 {
512         _set_irg_start_block(irg, node);
513 }
514
515 ir_node *(get_irg_start)(const ir_graph *irg)
516 {
517         return _get_irg_start(irg);
518 }
519
520 void (set_irg_start)(ir_graph *irg, ir_node *node)
521 {
522         _set_irg_start(irg, node);
523 }
524
525 ir_node *(get_irg_end_block)(const ir_graph *irg)
526 {
527         return _get_irg_end_block(irg);
528 }
529
530 void (set_irg_end_block)(ir_graph *irg, ir_node *node)
531 {
532   _set_irg_end_block(irg, node);
533 }
534
535 ir_node *(get_irg_end)(const ir_graph *irg)
536 {
537         return _get_irg_end(irg);
538 }
539
540 void (set_irg_end)(ir_graph *irg, ir_node *node)
541 {
542         _set_irg_end(irg, node);
543 }
544
545 ir_node *(get_irg_initial_exec)(const ir_graph *irg)
546 {
547         return _get_irg_initial_exec(irg);
548 }
549
550 void (set_irg_initial_exec)(ir_graph *irg, ir_node *node)
551 {
552         _set_irg_initial_exec(irg, node);
553 }
554
555 ir_node *(get_irg_frame)(const ir_graph *irg)
556 {
557         return _get_irg_frame(irg);
558 }
559
560 void (set_irg_frame)(ir_graph *irg, ir_node *node)
561 {
562         _set_irg_frame(irg, node);
563 }
564
565 ir_node *(get_irg_initial_mem)(const ir_graph *irg)
566 {
567         return _get_irg_initial_mem(irg);
568 }
569
570 void (set_irg_initial_mem)(ir_graph *irg, ir_node *node)
571 {
572         _set_irg_initial_mem(irg, node);
573 }
574
575 ir_node *(get_irg_args)(const ir_graph *irg)
576 {
577         return _get_irg_args(irg);
578 }
579
580 void (set_irg_args)(ir_graph *irg, ir_node *node)
581 {
582         _set_irg_args(irg, node);
583 }
584
585 ir_node *(get_irg_bad)(const ir_graph *irg)
586 {
587         return _get_irg_bad(irg);
588 }
589
590 void (set_irg_bad)(ir_graph *irg, ir_node *node)
591 {
592         _set_irg_bad(irg, node);
593 }
594
595 ir_node *(get_irg_no_mem)(const ir_graph *irg)
596 {
597         return _get_irg_no_mem(irg);
598 }
599
600 void (set_irg_no_mem)(ir_graph *irg, ir_node *node)
601 {
602         _set_irg_no_mem(irg, node);
603 }
604
605 ir_entity *(get_irg_entity)(const ir_graph *irg)
606 {
607         return _get_irg_entity(irg);
608 }
609
610 void (set_irg_entity)(ir_graph *irg, ir_entity *ent)
611 {
612         _set_irg_entity(irg, ent);
613 }
614
615 ir_type *(get_irg_frame_type)(ir_graph *irg)
616 {
617         return _get_irg_frame_type(irg);
618 }
619
620 void (set_irg_frame_type)(ir_graph *irg, ir_type *ftp)
621 {
622         _set_irg_frame_type(irg, ftp);
623 }
624
625 /* Returns the value parameter type of an IR graph. */
626 ir_type *get_irg_value_param_type(ir_graph *irg)
627 {
628         ir_entity *ent = get_irg_entity(irg);
629         ir_type   *mtp = get_entity_type(ent);
630         return get_method_value_param_type(mtp);
631 }
632
633 int get_irg_n_locs(ir_graph *irg)
634 {
635         return irg->n_loc - 1;
636 }
637
638 /* Returns the obstack associated with the graph. */
639 struct obstack *
640 (get_irg_obstack)(const ir_graph *irg) {
641         return _get_irg_obstack(irg);
642 }
643
644 /*
645  * Returns true if the node n is allocated on the storage of graph irg.
646  *
647  * Implementation is GLIBC specific as is uses the internal _obstack_chunk implementation.
648  */
649 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n)
650 {
651         struct _obstack_chunk *p;
652
653         /*
654          * checks weather the ir_node pointer is on the obstack.
655          * A more sophisticated check would test the "whole" ir_node
656          */
657         for (p = irg->obst->chunk; p; p = p->prev) {
658                 if (((char *)p->contents <= (char *)n) && ((char *)n < (char *)p->limit))
659                         return 1;
660         }
661
662         return 0;
663 }
664
665 irg_phase_state (get_irg_phase_state)(const ir_graph *irg)
666 {
667         return _get_irg_phase_state(irg);
668 }
669
670 void (set_irg_phase_state)(ir_graph *irg, irg_phase_state state)
671 {
672         _set_irg_phase_state(irg, state);
673 }
674
675 op_pin_state (get_irg_pinned)(const ir_graph *irg)
676 {
677         return _get_irg_pinned(irg);
678 }
679
680 irg_outs_state (get_irg_outs_state)(const ir_graph *irg)
681 {
682         return _get_irg_outs_state(irg);
683 }
684
685 void (set_irg_outs_inconsistent)(ir_graph *irg)
686 {
687         _set_irg_outs_inconsistent(irg);
688 }
689
690 irg_extblk_info_state (get_irg_extblk_state)(const ir_graph *irg)
691 {
692         return _get_irg_extblk_state(irg);
693 }
694
695 void (set_irg_extblk_inconsistent)(ir_graph *irg)
696 {
697         _set_irg_extblk_inconsistent(irg);
698 }
699
700 irg_dom_state (get_irg_dom_state)(const ir_graph *irg)
701 {
702         return _get_irg_dom_state(irg);
703 }
704
705 irg_dom_state (get_irg_postdom_state)(const ir_graph *irg)
706 {
707         return _get_irg_postdom_state(irg);
708 }
709
710 void (set_irg_doms_inconsistent)(ir_graph *irg)
711 {
712         _set_irg_doms_inconsistent(irg);
713 }
714
715 irg_loopinfo_state (get_irg_loopinfo_state)(const ir_graph *irg)
716 {
717         return _get_irg_loopinfo_state(irg);
718 }
719
720 void (set_irg_loopinfo_state)(ir_graph *irg, irg_loopinfo_state s)
721 {
722         _set_irg_loopinfo_state(irg, s);
723 }
724
725 void (set_irg_loopinfo_inconsistent)(ir_graph *irg)
726 {
727         _set_irg_loopinfo_inconsistent(irg);
728 }
729
730 void set_irp_loopinfo_inconsistent(void)
731 {
732         size_t i, n;
733         for (i = 0, n = get_irp_n_irgs(); i < n; ++i) {
734                 set_irg_loopinfo_inconsistent(get_irp_irg(i));
735         }
736 }
737
738
739
740 void (set_irg_pinned)(ir_graph *irg, op_pin_state p)
741 {
742         _set_irg_pinned(irg, p);
743 }
744
745 irg_callee_info_state (get_irg_callee_info_state)(const ir_graph *irg)
746 {
747         return _get_irg_callee_info_state(irg);
748 }
749
750 void (set_irg_callee_info_state)(ir_graph *irg, irg_callee_info_state s)
751 {
752         _set_irg_callee_info_state(irg, s);
753 }
754
755 irg_inline_property (get_irg_inline_property)(const ir_graph *irg)
756 {
757         return _get_irg_inline_property(irg);
758 }
759
760 void (set_irg_inline_property)(ir_graph *irg, irg_inline_property s)
761 {
762         _set_irg_inline_property(irg, s);
763 }
764
765 mtp_additional_properties (get_irg_additional_properties)(const ir_graph *irg)
766 {
767         return _get_irg_additional_properties(irg);
768 }
769
770 void (set_irg_additional_properties)(ir_graph *irg, mtp_additional_properties property_mask)
771 {
772         _set_irg_additional_properties(irg, property_mask);
773 }
774
775 void (add_irg_additional_properties)(ir_graph *irg, mtp_additional_properties flag)
776 {
777         _add_irg_additional_properties(irg, flag);
778 }
779
780 void (set_irg_link)(ir_graph *irg, void *thing)
781 {
782         _set_irg_link(irg, thing);
783 }
784
785 void *(get_irg_link)(const ir_graph *irg)
786 {
787         return _get_irg_link(irg);
788 }
789
790 ir_visited_t (get_irg_visited)(const ir_graph *irg)
791 {
792         return _get_irg_visited(irg);
793 }
794
795 /** maximum visited flag content of all ir_graph visited fields. */
796 static ir_visited_t max_irg_visited = 0;
797
798 void set_irg_visited(ir_graph *irg, ir_visited_t visited)
799 {
800         irg->visited = visited;
801         if (irg->visited > max_irg_visited) {
802                 max_irg_visited = irg->visited;
803         }
804 }
805
806 void inc_irg_visited(ir_graph *irg)
807 {
808         ++irg->visited;
809         if (irg->visited > max_irg_visited) {
810                 max_irg_visited = irg->visited;
811         }
812 }
813
814 ir_visited_t get_max_irg_visited(void)
815 {
816         return max_irg_visited;
817 }
818
819 void set_max_irg_visited(int val)
820 {
821         max_irg_visited = val;
822 }
823
824 ir_visited_t inc_max_irg_visited(void)
825 {
826 #ifndef NDEBUG
827         size_t i;
828         for (i = 0; i < get_irp_n_irgs(); i++)
829                 assert(max_irg_visited >= get_irg_visited(get_irp_irg(i)));
830 #endif
831         return ++max_irg_visited;
832 }
833
834 ir_visited_t (get_irg_block_visited)(const ir_graph *irg)
835 {
836         return _get_irg_block_visited(irg);
837 }
838
839 void (set_irg_block_visited)(ir_graph *irg, ir_visited_t visited)
840 {
841         _set_irg_block_visited(irg, visited);
842 }
843
844 void (inc_irg_block_visited)(ir_graph *irg)
845 {
846   _inc_irg_block_visited(irg);
847 }
848
849 /* Return the floating point model of this graph. */
850 unsigned (get_irg_fp_model)(const ir_graph *irg)
851 {
852         return _get_irg_fp_model(irg);
853 }
854
855 /* Sets the floating point model for this graph. */
856 void set_irg_fp_model(ir_graph *irg, unsigned model)
857 {
858         irg->fp_model = model;
859 }
860
861 /* set a description for local value n */
862 void set_irg_loc_description(ir_graph *irg, int n, void *description)
863 {
864         assert(0 <= n && n < irg->n_loc);
865
866         if (! irg->loc_descriptions)
867                 irg->loc_descriptions = XMALLOCNZ(void*, irg->n_loc);
868
869         irg->loc_descriptions[n] = description;
870 }
871
872 /* get the description for local value n */
873 void *get_irg_loc_description(ir_graph *irg, int n)
874 {
875         assert(0 <= n && n < irg->n_loc);
876         return irg->loc_descriptions ? irg->loc_descriptions[n] : NULL;
877 }
878
879 void irg_register_phase(ir_graph *irg, ir_phase_id id, ir_phase *phase)
880 {
881         assert(id <= PHASE_LAST);
882         assert(irg->phases[id] == NULL);
883         irg->phases[id] = phase;
884 }
885
886 void irg_invalidate_phases(ir_graph *irg)
887 {
888         int p;
889         for (p = 0; p <= PHASE_LAST; ++p) {
890                 ir_phase *phase = irg->phases[p];
891                 if (phase == NULL)
892                         continue;
893
894                 phase_free(phase);
895                 irg->phases[p] = NULL;
896         }
897 }
898
899 #ifndef NDEBUG
900 void ir_reserve_resources(ir_graph *irg, ir_resources_t resources)
901 {
902         assert((resources & ~IR_RESOURCE_LOCAL_MASK) == 0);
903         assert((irg->reserved_resources & resources) == 0);
904         irg->reserved_resources |= resources;
905 }
906
907 void ir_free_resources(ir_graph *irg, ir_resources_t resources)
908 {
909         assert((irg->reserved_resources & resources) == resources);
910         irg->reserved_resources &= ~resources;
911 }
912
913 ir_resources_t ir_resources_reserved(const ir_graph *irg)
914 {
915         return irg->reserved_resources;
916 }
917 #endif /* NDEBUG */
918
919 /* Returns a estimated node count of the irg. */
920 unsigned (get_irg_estimated_node_cnt)(const ir_graph *irg)
921 {
922         return _get_irg_estimated_node_cnt(irg);
923 }
924
925 /* Returns the last irn index for this graph. */
926 unsigned get_irg_last_idx(const ir_graph *irg)
927 {
928         return irg->last_node_idx;
929 }
930
931 /* register additional space in an IR graph */
932 size_t register_additional_graph_data(size_t size)
933 {
934         assert(!forbid_new_data && "Too late to register additional node data");
935
936         if (forbid_new_data)
937                 return 0;
938
939         return additional_graph_data_size += size;
940 }
941
942 void (set_irg_state)(ir_graph *irg, ir_graph_state_t state)
943 {
944         _set_irg_state(irg, state);
945 }
946
947 void (clear_irg_state)(ir_graph *irg, ir_graph_state_t state)
948 {
949         _clear_irg_state(irg, state);
950 }
951
952 int (is_irg_state)(const ir_graph *irg, ir_graph_state_t state)
953 {
954         return _is_irg_state(irg, state);
955 }