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