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