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