BugFix: equivalent_node_Bound() was too greedy, reduced to a safe minimum (now mostly...
[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 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #ifdef HAVE_STRING_H
31 # include <string.h>
32 #endif
33 #ifdef HAVE_STDDEF_H
34 # include <stddef.h>
35 #endif
36
37 #include "xmalloc.h"
38 #include "ircons_t.h"
39 #include "irgraph_t.h"
40 #include "irprog_t.h"
41 #include "irnode_t.h"
42 #include "iropt_t.h"
43 #include "irflag_t.h"
44 #include "array.h"
45 #include "irgmod.h"
46 #include "irouts.h"
47 #include "irhooks.h"
48 #include "irtools.h"
49 #include "irgwalk.h"
50 #include "iredges_t.h"
51 #include "type_t.h"
52 #include "irmemory.h"
53
54 #define INITIAL_IDX_IRN_MAP_SIZE 1024
55
56 /**
57  * Indicates, whether additional data can be registered to graphs.
58  * If set to 1, this is not possible anymore.
59  */
60 static int forbid_new_data = 0;
61
62 /**
63  * The amount of additional space for custom data to be allocated upon
64  * creating a new graph.
65  */
66 static size_t additional_graph_data_size = 0;
67
68 ir_graph *current_ir_graph;
69 ir_graph *get_current_ir_graph(void) {
70         return current_ir_graph;
71 }
72
73 void set_current_ir_graph(ir_graph *graph) {
74         current_ir_graph = graph;
75 }
76
77 #ifdef INTERPROCEDURAL_VIEW
78 int firm_interprocedural_view = 0;
79
80 int (get_interprocedural_view)(void) {
81         return _get_interprocedural_view();
82 }
83
84 void (set_interprocedural_view)(int state) {
85         firm_interprocedural_view = state;
86
87         /* set function vectors for faster access */
88         if (state) {
89                 _get_irn_arity = _get_irn_inter_arity;
90                 _get_irn_n     = _get_irn_inter_n;
91         }
92         else {
93                 _get_irn_arity = _get_irn_intra_arity;
94                 _get_irn_n     = _get_irn_intra_n;
95         }
96 }
97 #endif
98
99 /** contains the suffix for frame type names */
100 static ident *frame_type_suffix = NULL;
101
102 /* initialize the IR graph module */
103 void firm_init_irgraph(void) {
104         frame_type_suffix = new_id_from_str(FRAME_TP_SUFFIX);
105         forbid_new_data   = 1;
106 }
107
108 /**
109  * Allocate a new IR graph.
110  * This function respects the registered graph data. The only reason for
111  * this function is, that there are two locations, where graphs are
112  * allocated (new_r_ir_graph, new_const_code_irg).
113  * @return Memory for a new graph.
114  */
115 static ir_graph *alloc_graph(void) {
116         size_t size = sizeof(ir_graph) + additional_graph_data_size;
117         char *ptr = xmalloc(size);
118         memset(ptr, 0, size);
119
120         return (ir_graph *) (ptr + additional_graph_data_size);
121 }
122
123 /**
124  * Frees an allocated IR graph
125  */
126 static void free_graph(ir_graph *irg) {
127         char *ptr = (char *)irg;
128         free(ptr - additional_graph_data_size);
129 }
130
131 #if USE_EXPLICIT_PHI_IN_STACK
132 /* really defined in ircons.c */
133 typedef struct Phi_in_stack Phi_in_stack;
134 Phi_in_stack *new_Phi_in_stack();
135 void free_Phi_in_stack(Phi_in_stack *s);
136 #endif
137
138 /* Allocates a list of nodes:
139     - The start block containing a start node and Proj nodes for it's four
140       results (X, M, P, Tuple).
141     - The end block containing an end node. This block is not matured after
142       new_ir_graph as predecessors need to be added to it.
143     - The current block, which is empty and also not matured.
144    Further it allocates several datastructures needed for graph construction
145    and optimization.
146 */
147 ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc) {
148         ir_graph *res;
149         ir_node  *first_block;
150         ir_node  *end, *start, *start_block, *initial_mem, *projX;
151
152         res = alloc_graph();
153         res->kind = k_ir_graph;
154
155         //edges_init_graph_kind(res, EDGE_KIND_NORMAL);
156         //edges_init_graph_kind(res, EDGE_KIND_BLOCK);
157
158         /* initialize the idx->node map. */
159         res->idx_irn_map = NEW_ARR_F(ir_node *, INITIAL_IDX_IRN_MAP_SIZE);
160         memset(res->idx_irn_map, 0, INITIAL_IDX_IRN_MAP_SIZE * sizeof(res->idx_irn_map[0]));
161
162         /* inform statistics here, as blocks will be already build on this graph */
163         hook_new_graph(res, ent);
164
165         current_ir_graph = res;
166
167         /*-- initialized for each graph. --*/
168         if (get_opt_precise_exc_context()) {
169                 res->n_loc = n_loc + 1 + 1; /* number of local variables that are never
170                                dereferenced in this graph plus one for
171                                the store plus one for links to fragile
172                                operations.  n_loc is not the number of
173                                parameters to the procedure!  */
174         } else {
175                 res->n_loc = n_loc + 1;  /* number of local variables that are never
176                             dereferenced in this graph plus one for
177                             the store. This is not the number of parameters
178                             to the procedure!  */
179         }
180
181         /* descriptions will be allocated on demand */
182         res->loc_descriptions = NULL;
183
184         res->visited       = 0; /* visited flag, for the ir walker */
185         res->block_visited = 0; /* visited flag, for the 'block'-walker */
186
187 #if USE_EXPLICIT_PHI_IN_STACK
188         res->Phi_in_stack = new_Phi_in_stack();  /* A stack needed for automatic Phi
189                                                     generation */
190 #endif
191         res->kind = k_ir_graph;
192         res->obst = xmalloc (sizeof(*res->obst));
193         obstack_init(res->obst);
194         res->extbb_obst = NULL;
195
196         res->last_node_idx = 0;
197
198         res->value_table = new_identities (); /* value table for global value
199                                                  numbering for optimizing use in iropt.c */
200         res->outs = NULL;
201
202         res->inline_property       = irg_inline_any;
203         res->additional_properties = mtp_property_inherited;  /* inherited from type */
204
205         res->phase_state         = phase_building;
206         res->irg_pinned_state    = op_pin_state_pinned;
207         res->outs_state          = outs_none;
208         res->dom_state           = dom_none;
209         res->pdom_state          = dom_none;
210         res->typeinfo_state      = ir_typeinfo_none;
211         set_irp_typeinfo_inconsistent();           /* there is a new graph with typeinfo_none. */
212         res->callee_info_state   = irg_callee_info_none;
213         res->loopinfo_state      = loopinfo_none;
214         res->class_cast_state    = ir_class_casts_transitive;
215         res->extblk_state        = ir_extblk_info_none;
216         res->execfreq_state      = exec_freq_none;
217         res->fp_model            = fp_model_precise;
218         res->adr_taken_state     = ir_address_taken_not_computed;
219         res->mem_disambig_opt    = aa_opt_inherited;
220
221         /*-- Type information for the procedure of the graph --*/
222         res->ent = ent;
223         set_entity_irg(ent, res);
224
225         /*--  a class type so that it can contain "inner" methods as in Pascal. --*/
226         res->frame_type = new_type_frame(mangle(get_entity_ident(ent), frame_type_suffix));
227
228         /* the Anchor node must be created first */
229         res->anchor = new_Anchor(res);
230
231         /*-- Nodes needed in every graph --*/
232         set_irg_end_block (res, new_immBlock());
233         end               = new_End();
234         set_irg_end       (res, end);
235         set_irg_end_reg   (res, end);
236         set_irg_end_except(res, end);
237
238         start_block = new_immBlock();
239         set_irg_start_block(res, start_block);
240         set_irg_bad        (res, new_ir_node(NULL, res, start_block, op_Bad, mode_T, 0, NULL));
241         set_irg_no_mem     (res, new_ir_node(NULL, res, start_block, op_NoMem, mode_M, 0, NULL));
242         start = new_Start();
243         set_irg_start      (res, start);
244
245         /* Proj results of start node */
246         projX                   = new_Proj(start, mode_X, pn_Start_X_initial_exec);
247         set_irg_frame           (res, new_Proj(start, mode_P_data, pn_Start_P_frame_base));
248         set_irg_globals         (res, new_Proj(start, mode_P_data, pn_Start_P_globals));
249         set_irg_tls             (res, new_Proj(start, mode_P_data, pn_Start_P_tls));
250         set_irg_args            (res, new_Proj(start, mode_T,      pn_Start_T_args));
251         set_irg_value_param_base(res, new_Proj(start, mode_P_data, pn_Start_P_value_arg_base));
252         initial_mem             = new_Proj(start, mode_M, pn_Start_M);
253         set_irg_initial_mem(res, initial_mem);
254
255         add_immBlock_pred(start_block, projX);
256         set_store(initial_mem);
257
258         res->index       = get_irp_new_irg_idx();
259 #ifdef DEBUG_libfirm
260         res->graph_nr    = get_irp_new_node_nr();
261 #endif
262
263         /*
264          * The code generation needs it. leave it in now.
265          * Use of this edge is matter of discussion, unresolved. Also possible:
266          * add_immBlock_pred(res->start_block, res->start_block), but invalid typed.
267          */
268         mature_immBlock(res->current_block);
269
270         /*-- Make a block to start with --*/
271         first_block = new_immBlock();
272         add_immBlock_pred(first_block, projX);
273
274         res->method_execution_frequency = -1.0;
275         res->estimated_node_count       = 0;
276
277         return res;
278 }
279
280
281 ir_graph *
282 new_ir_graph(ir_entity *ent, int n_loc) {
283         ir_graph *res = new_r_ir_graph(ent, n_loc);
284         add_irp_irg(res);          /* remember this graph global. */
285         return res;
286 }
287
288 /* Make a rudimentary IR graph for the constant code.
289    Must look like a correct irg, spare everything else. */
290 ir_graph *new_const_code_irg(void) {
291         ir_graph *res;
292         ir_node  *end, *start_block, *start, *projX;
293
294         res = alloc_graph();
295
296         /* initialize the idx->node map. */
297         res->idx_irn_map = NEW_ARR_F(ir_node *, INITIAL_IDX_IRN_MAP_SIZE);
298         memset(res->idx_irn_map, 0, INITIAL_IDX_IRN_MAP_SIZE * sizeof(res->idx_irn_map[0]));
299
300         /* inform statistics here, as blocks will be already build on this graph */
301         hook_new_graph(res, NULL);
302
303         current_ir_graph = res;
304         res->n_loc = 1;         /* Only the memory. */
305         res->visited = 0;       /* visited flag, for the ir walker */
306         res->block_visited = 0; /* visited flag, for the 'block'-walker */
307 #if USE_EXPLICIT_PHI_IN_STACK
308         res->Phi_in_stack = NULL;
309 #endif
310         res->kind = k_ir_graph;
311         res->obst      = xmalloc (sizeof(*res->obst));
312         obstack_init (res->obst);
313         res->extbb_obst = NULL;
314
315         res->last_node_idx = 0;
316
317         res->phase_state      = phase_building;
318         res->irg_pinned_state = op_pin_state_pinned;
319         res->extblk_state     = ir_extblk_info_none;
320         res->fp_model         = fp_model_precise;
321
322         res->value_table = new_identities (); /* value table for global value
323                                            numbering for optimizing use in
324                                            iropt.c */
325         res->ent = NULL;
326         res->frame_type  = NULL;
327
328         /* the Anchor node must be created first */
329         res->anchor = new_Anchor(res);
330
331         /* -- The end block -- */
332         set_irg_end_block (res, new_immBlock());
333         end = new_End();
334         set_irg_end       (res, end);
335         set_irg_end_reg   (res, end);
336         set_irg_end_except(res, end);
337         mature_immBlock(get_cur_block());  /* mature the end block */
338
339         /* -- The start block -- */
340         start_block        = new_immBlock();
341         set_irg_start_block(res, start_block);
342         set_irg_bad        (res, new_ir_node (NULL, res, start_block, op_Bad, mode_T, 0, NULL));
343         set_irg_no_mem     (res, new_ir_node (NULL, res, start_block, op_NoMem, mode_M, 0, NULL));
344         start              = new_Start();
345         set_irg_start      (res, start);
346
347         /* Proj results of start node */
348         set_irg_initial_mem(res, new_Proj(start, mode_M, pn_Start_M));
349         projX = new_Proj(start, mode_X, pn_Start_X_initial_exec);
350         add_immBlock_pred(start_block, projX);
351         mature_immBlock  (start_block);  /* mature the start block */
352
353         add_immBlock_pred(new_immBlock(), projX);
354         mature_immBlock  (get_cur_block());   /* mature the 'body' block for expressions */
355
356         /* Set the visited flag high enough that the blocks will never be visited. */
357         set_irn_visited(get_cur_block(), -1);
358         set_Block_block_visited(get_cur_block(), -1);
359         set_Block_block_visited(start_block, -1);
360         set_irn_visited(start_block, -1);
361         set_irn_visited(get_irg_bad(res), -1);
362         set_irn_visited(get_irg_no_mem(res), -1);
363
364         res->phase_state = phase_high;
365
366         return res;
367 }
368
369 /* Defined in iropt.c */
370 void  del_identities (pset *value_table);
371
372 /* Frees the passed irgraph.
373    Deallocates all nodes in this graph and the ir_graph structure.
374    Sets the field irgraph in the corresponding entity to NULL.
375    Does not remove the irgraph from the list in irprog (requires
376    inefficient search, call remove_irp_irg by hand).
377    Does not free types, entities or modes that are used only by this
378    graph, nor the entity standing for this graph. */
379 void free_ir_graph (ir_graph *irg) {
380         assert(is_ir_graph(irg));
381
382         hook_free_graph(irg);
383         if (irg->outs_state != outs_none) free_irg_outs(irg);
384         if (irg->frame_type)  free_type(irg->frame_type);
385         if (irg->value_table) del_identities(irg->value_table);
386         if (irg->ent) {
387                 ir_peculiarity pec = get_entity_peculiarity (irg->ent);
388                 set_entity_peculiarity (irg->ent, peculiarity_description);
389                 set_entity_irg(irg->ent, NULL);  /* not set in const code irg */
390                 set_entity_peculiarity (irg->ent, pec);
391         }
392
393         free_End(get_irg_end(irg));
394         obstack_free(irg->obst,NULL);
395         free(irg->obst);
396 #if USE_EXPLICIT_PHI_IN_STACK
397         free_Phi_in_stack(irg->Phi_in_stack);
398 #endif
399         if (irg->loc_descriptions)
400                 free(irg->loc_descriptions);
401         irg->kind = k_BAD;
402         free_graph(irg);
403 }
404
405 /* access routines for all ir_graph attributes:
406    templates:
407    {attr type} get_irg_{attribute name} (ir_graph *irg);
408    void set_irg_{attr name} (ir_graph *irg, {attr type} {attr}); */
409
410 int
411 (is_ir_graph)(const void *thing) {
412         return _is_ir_graph(thing);
413 }
414
415 #ifdef DEBUG_libfirm
416 /* Outputs a unique number for this node */
417 long get_irg_graph_nr(const ir_graph *irg) {
418         return irg->graph_nr;
419 }
420 #endif
421
422 int get_irg_idx(const ir_graph *irg) {
423         return irg->index;
424 }
425
426 ir_node *
427 (get_irg_start_block)(const ir_graph *irg) {
428         return _get_irg_start_block(irg);
429 }
430
431 void
432 (set_irg_start_block)(ir_graph *irg, ir_node *node) {
433         _set_irg_start_block(irg, node);
434 }
435
436 ir_node *
437 (get_irg_start)(const ir_graph *irg) {
438         return _get_irg_start(irg);
439 }
440
441 void
442 (set_irg_start)(ir_graph *irg, ir_node *node) {
443         _set_irg_start(irg, node);
444 }
445
446 ir_node *
447 (get_irg_end_block)(const ir_graph *irg) {
448         return _get_irg_end_block(irg);
449 }
450
451 void
452 (set_irg_end_block)(ir_graph *irg, ir_node *node) {
453   _set_irg_end_block(irg, node);
454 }
455
456 ir_node *
457 (get_irg_end)(const ir_graph *irg) {
458         return _get_irg_end(irg);
459 }
460
461 void
462 (set_irg_end)(ir_graph *irg, ir_node *node) {
463         _set_irg_end(irg, node);
464 }
465
466 ir_node *
467 (get_irg_end_reg)(const ir_graph *irg) {
468         return _get_irg_end_reg(irg);
469 }
470
471 void
472 (set_irg_end_reg)(ir_graph *irg, ir_node *node) {
473         _set_irg_end_reg(irg, node);
474 }
475
476 ir_node *
477 (get_irg_end_except)(const ir_graph *irg) {
478         return _get_irg_end_except(irg);
479 }
480
481 void
482 (set_irg_end_except)(ir_graph *irg, ir_node *node) {
483         assert(get_irn_op(node) == op_EndExcept || get_irn_op(node) == op_End);
484         _set_irg_end_except(irg, node);
485 }
486
487 ir_node *
488 (get_irg_frame)(const ir_graph *irg) {
489         return _get_irg_frame(irg);
490 }
491
492 void
493 (set_irg_frame)(ir_graph *irg, ir_node *node) {
494         _set_irg_frame(irg, node);
495 }
496
497 ir_node *
498 (get_irg_globals)(const ir_graph *irg) {
499   return _get_irg_globals(irg);
500 }
501
502 void
503 (set_irg_globals)(ir_graph *irg, ir_node *node) {
504         _set_irg_globals(irg, node);
505 }
506
507 ir_node *
508 (get_irg_tls)(const ir_graph *irg) {
509         return _get_irg_tls(irg);
510 }
511
512 void
513 (set_irg_tls)(ir_graph *irg, ir_node *node) {
514         _set_irg_tls(irg, node);
515 }
516
517 ir_node *
518 (get_irg_initial_mem)(const ir_graph *irg) {
519         return _get_irg_initial_mem(irg);
520 }
521
522 void
523 (set_irg_initial_mem)(ir_graph *irg, ir_node *node) {
524         _set_irg_initial_mem(irg, node);
525 }
526
527 ir_node *
528 (get_irg_args)(const ir_graph *irg) {
529         return _get_irg_args(irg);
530 }
531
532 void
533 (set_irg_args)(ir_graph *irg, ir_node *node) {
534         _set_irg_args(irg, node);
535 }
536
537 ir_node *
538 (get_irg_value_param_base)(const ir_graph *irg) {
539         return _get_irg_value_param_base(irg);
540 }
541
542 void
543 (set_irg_value_param_base)(ir_graph *irg, ir_node *node) {
544         _set_irg_value_param_base(irg, node);
545 }
546
547 ir_node *
548 (get_irg_bad)(const ir_graph *irg) {
549         return _get_irg_bad(irg);
550 }
551
552 void
553 (set_irg_bad)(ir_graph *irg, ir_node *node) {
554         _set_irg_bad(irg, node);
555 }
556
557 ir_node *
558 (get_irg_no_mem)(const ir_graph *irg) {
559         return _get_irg_no_mem(irg);
560 }
561
562 void
563 (set_irg_no_mem)(ir_graph *irg, ir_node *node) {
564         _set_irg_no_mem(irg, node);
565 }
566
567 ir_node *
568 (get_irg_current_block)(const ir_graph *irg) {
569         return _get_irg_current_block(irg);
570 }
571
572 void
573 (set_irg_current_block)(ir_graph *irg, ir_node *node) {
574         _set_irg_current_block(irg, node);
575 }
576
577 ir_entity *
578 (get_irg_entity)(const ir_graph *irg) {
579         return _get_irg_entity(irg);
580 }
581
582 void
583 (set_irg_entity)(ir_graph *irg, ir_entity *ent) {
584         _set_irg_entity(irg, ent);
585 }
586
587 ir_type *
588 (get_irg_frame_type)(ir_graph *irg) {
589         return _get_irg_frame_type(irg);
590 }
591
592 void
593 (set_irg_frame_type)(ir_graph *irg, ir_type *ftp) {
594         _set_irg_frame_type(irg, ftp);
595 }
596
597 int
598 get_irg_n_locs(ir_graph *irg) {
599         if (get_opt_precise_exc_context())
600                 return irg->n_loc - 1 - 1;
601         else
602                 return irg->n_loc - 1;
603 }
604
605 void
606 set_irg_n_loc(ir_graph *irg, int n_loc) {
607         if (get_opt_precise_exc_context())
608                 irg->n_loc = n_loc + 1 + 1;
609         else
610                 irg->n_loc = n_loc + 1;
611 }
612
613
614
615 /* Returns the obstack associated with the graph. */
616 struct obstack *
617 (get_irg_obstack)(const ir_graph *irg) {
618         return _get_irg_obstack(irg);
619 }
620
621 /*
622  * Returns true if the node n is allocated on the storage of graph irg.
623  *
624  * Implementation is GLIBC specific as is uses the internal _obstack_chunk implementation.
625  */
626 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n) {
627         struct _obstack_chunk *p;
628
629         /*
630          * checks weather the ir_node pointer is on the obstack.
631          * A more sophisticated check would test the "whole" ir_node
632          */
633         for (p = irg->obst->chunk; p; p = p->prev) {
634                 if (((char *)p->contents <= (char *)n) && ((char *)n < (char *)p->limit))
635                         return 1;
636         }
637
638         return 0;
639 }
640
641 irg_phase_state
642 (get_irg_phase_state)(const ir_graph *irg) {
643         return _get_irg_phase_state(irg);
644 }
645
646 void
647 (set_irg_phase_state)(ir_graph *irg, irg_phase_state state) {
648         _set_irg_phase_state(irg, state);
649 }
650
651 op_pin_state
652 (get_irg_pinned)(const ir_graph *irg) {
653         return _get_irg_pinned(irg);
654 }
655
656 irg_outs_state
657 (get_irg_outs_state)(const ir_graph *irg) {
658         return _get_irg_outs_state(irg);
659 }
660
661 void
662 (set_irg_outs_inconsistent)(ir_graph *irg) {
663         _set_irg_outs_inconsistent(irg);
664 }
665
666 irg_extblk_state
667 (get_irg_extblk_state)(const ir_graph *irg) {
668         return _get_irg_extblk_state(irg);
669 }
670
671 void
672 (set_irg_extblk_inconsistent)(ir_graph *irg) {
673         _set_irg_extblk_inconsistent(irg);
674 }
675
676 irg_dom_state
677 (get_irg_dom_state)(const ir_graph *irg) {
678         return _get_irg_dom_state(irg);
679 }
680
681 irg_dom_state
682 (get_irg_postdom_state)(const ir_graph *irg) {
683         return _get_irg_postdom_state(irg);
684 }
685
686 void
687 (set_irg_doms_inconsistent)(ir_graph *irg) {
688         _set_irg_doms_inconsistent(irg);
689 }
690
691 irg_loopinfo_state
692 (get_irg_loopinfo_state)(const ir_graph *irg) {
693         return _get_irg_loopinfo_state(irg);
694 }
695
696 void
697 (set_irg_loopinfo_state)(ir_graph *irg, irg_loopinfo_state s) {
698         _set_irg_loopinfo_state(irg, s);
699 }
700
701 void
702 (set_irg_loopinfo_inconsistent)(ir_graph *irg) {
703         _set_irg_loopinfo_inconsistent(irg);
704 }
705
706 void set_irp_loopinfo_inconsistent(void) {
707         int i;
708         for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
709                 set_irg_loopinfo_inconsistent(get_irp_irg(i));
710         }
711 }
712
713
714
715 void
716 (set_irg_pinned)(ir_graph *irg, op_pin_state p) {
717         _set_irg_pinned(irg, p);
718 }
719
720 irg_callee_info_state
721 (get_irg_callee_info_state)(const ir_graph *irg) {
722         return _get_irg_callee_info_state(irg);
723 }
724
725 void
726 (set_irg_callee_info_state)(ir_graph *irg, irg_callee_info_state s) {
727         _set_irg_callee_info_state(irg, s);
728 }
729
730 irg_inline_property
731 (get_irg_inline_property)(const ir_graph *irg) {
732         return _get_irg_inline_property(irg);
733 }
734
735 void
736 (set_irg_inline_property)(ir_graph *irg, irg_inline_property s) {
737         _set_irg_inline_property(irg, s);
738 }
739
740 unsigned
741 (get_irg_additional_properties)(const ir_graph *irg) {
742         return _get_irg_additional_properties(irg);
743 }
744
745 void
746 (set_irg_additional_properties)(ir_graph *irg, unsigned property_mask) {
747         _set_irg_additional_properties(irg, property_mask);
748 }
749
750 void
751 (set_irg_additional_property)(ir_graph *irg, mtp_additional_property flag) {
752         _set_irg_additional_property(irg, flag);
753 }
754
755 void
756 (set_irg_link)(ir_graph *irg, void *thing) {
757         _set_irg_link(irg, thing);
758 }
759
760 void *
761 (get_irg_link)(const ir_graph *irg) {
762         return _get_irg_link(irg);
763 }
764
765 /** maximum visited flag content of all ir_graph visited fields. */
766 static unsigned long max_irg_visited = 0;
767
768 unsigned long
769 (get_irg_visited)(const ir_graph *irg) {
770         return _get_irg_visited(irg);
771 }
772
773 void
774 set_irg_visited(ir_graph *irg, unsigned long visited) {
775         irg->visited = visited;
776         if (irg->visited > max_irg_visited) {
777                 max_irg_visited = irg->visited;
778         }
779 }
780
781 void
782 inc_irg_visited(ir_graph *irg) {
783         if (++irg->visited > max_irg_visited) {
784                 max_irg_visited = irg->visited;
785         }
786 }
787
788 unsigned long
789 get_max_irg_visited(void) {
790         /*
791         int i;
792         for(i = 0; i < get_irp_n_irgs(); i++)
793         assert(max_irg_visited >= get_irg_visited(get_irp_irg(i)));
794          */
795         return max_irg_visited;
796 }
797
798 void set_max_irg_visited(int val) {
799         max_irg_visited = val;
800 }
801
802 unsigned long
803 inc_max_irg_visited(void) {
804         /*
805         int i;
806         for(i = 0; i < get_irp_n_irgs(); i++)
807         assert(max_irg_visited >= get_irg_visited(get_irp_irg(i)));
808         */
809         return ++max_irg_visited;
810 }
811
812 unsigned long
813 (get_irg_block_visited)(const ir_graph *irg) {
814         return _get_irg_block_visited(irg);
815 }
816
817 void
818 (set_irg_block_visited)(ir_graph *irg, unsigned long visited) {
819         _set_irg_block_visited(irg, visited);
820 }
821
822 void
823 (inc_irg_block_visited)(ir_graph *irg) {
824   _inc_irg_block_visited(irg);
825 }
826
827 /* Return the floating point model of this graph. */
828 unsigned (get_irg_fp_model)(const ir_graph *irg) {
829         return _get_irg_fp_model(irg);
830 }
831
832 /* Sets the floating point model for this graph. */
833 void set_irg_fp_model(ir_graph *irg, unsigned model) {
834         irg->fp_model = model;
835 }
836
837 /**
838  * walker Start->End: places Proj nodes into the same block
839  * as it's predecessors
840  *
841  * @param n    the node
842  * @param env  ignored
843  */
844 static void normalize_proj_walker(ir_node *n, void *env) {
845         (void) env;
846         if (is_Proj(n)) {
847                 ir_node *pred  = get_Proj_pred(n);
848                 ir_node *block = get_nodes_block(pred);
849
850                 set_nodes_block(n, block);
851         }
852 }
853
854 /* move Proj nodes into the same block as its predecessors */
855 void normalize_proj_nodes(ir_graph *irg) {
856         irg_walk_graph(irg, NULL, normalize_proj_walker, NULL);
857         set_irg_outs_inconsistent(irg);
858 }
859
860 /* set a description for local value n */
861 void set_irg_loc_description(ir_graph *irg, int n, void *description) {
862         assert(0 <= n && n < irg->n_loc);
863
864         if (! irg->loc_descriptions)
865                 irg->loc_descriptions = xcalloc(sizeof(*irg->loc_descriptions), irg->n_loc);
866
867         irg->loc_descriptions[n] = description;
868 }
869
870 /* get the description for local value n */
871 void *get_irg_loc_description(ir_graph *irg, int n) {
872         assert(0 <= n && n < irg->n_loc);
873         return irg->loc_descriptions ? irg->loc_descriptions[n] : NULL;
874 }
875
876 #ifndef NDEBUG
877 void set_using_block_visited(ir_graph *irg) {
878         assert(irg->using_block_visited == 0);
879         irg->using_block_visited = 1;
880 }
881
882 void clear_using_block_visited(ir_graph *irg) {
883         assert(irg->using_block_visited == 1);
884         irg->using_block_visited = 0;
885 }
886
887 int using_block_visited(const ir_graph *irg) {
888         return irg->using_block_visited;
889 }
890
891
892 void set_using_visited(ir_graph *irg) {
893         assert(irg->using_visited == 0);
894         irg->using_visited = 1;
895 }
896
897 void clear_using_visited(ir_graph *irg) {
898         assert(irg->using_visited == 1);
899         irg->using_visited = 0;
900 }
901
902 int using_visited(const ir_graph *irg) {
903         return irg->using_visited;
904 }
905
906
907 void set_using_irn_link(ir_graph *irg) {
908         assert(irg->using_irn_link == 0);
909         irg->using_irn_link = 1;
910 }
911
912 void clear_using_irn_link(ir_graph *irg) {
913         assert(irg->using_irn_link == 1);
914         irg->using_irn_link = 0;
915 }
916
917 int using_irn_link(const ir_graph *irg) {
918         return irg->using_irn_link;
919 }
920 #endif
921
922 /* Returns a estimated node count of the irg. */
923 unsigned (get_irg_estimated_node_cnt)(const ir_graph *irg) {
924         return _get_irg_estimated_node_cnt(irg);
925 }
926
927 /* Returns the last irn index for this graph. */
928 unsigned get_irg_last_idx(const ir_graph *irg) {
929         return irg->last_node_idx;
930 }
931
932 /* register additional space in an IR graph */
933 size_t register_additional_graph_data(size_t size) {
934         assert(!forbid_new_data && "Too late to register additional node data");
935
936         if (forbid_new_data)
937                 return 0;
938
939         return additional_graph_data_size += size;
940 }