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