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