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