Added subst hook in dead node elimination
[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 *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->value_table = new_identities (); /* value table for global value
177                        numbering for optimizing use in
178                        iropt.c */
179   res->outs = NULL;
180
181   res->inline_property       = irg_inline_any;
182   res->additional_properties = mtp_property_inherited;  /* inherited from type */
183
184   res->phase_state         = phase_building;
185   res->irg_pinned_state    = op_pin_state_pinned;
186   res->outs_state          = outs_none;
187   res->dom_state           = dom_none;
188   res->pdom_state          = dom_none;
189   res->typeinfo_state      = ir_typeinfo_none;
190   set_irp_typeinfo_inconsistent();           /* there is a new graph with typeinfo_none. */
191   res->callee_info_state   = irg_callee_info_none;
192   res->loopinfo_state      = loopinfo_none;
193   res->execfreq_state      = exec_freq_none;
194   res->class_cast_state    = ir_class_casts_transitive;
195   res->extblk_state        = ir_extblk_info_none;
196
197   /*-- Type information for the procedure of the graph --*/
198   res->ent = ent;
199   set_entity_irg(ent, res);
200
201   /*--  a class type so that it can contain "inner" methods as in Pascal. --*/
202   res->frame_type = new_type_frame(mangle(get_entity_ident(ent), frame_type_suffix));
203
204   /*-- Nodes needed in every graph --*/
205   res->end_block  = new_immBlock();
206   res->end        = new_End();
207   res->end_reg    = res->end;
208   res->end_except = res->end;
209
210   res->start_block = new_immBlock();
211   res->start   = new_Start();
212   res->bad     = new_ir_node(NULL, res, res->start_block, op_Bad, mode_T, 0, NULL);
213   res->no_mem  = new_ir_node(NULL, res, res->start_block, op_NoMem, mode_M, 0, NULL);
214
215   /* Proj results of start node */
216   projX            = new_Proj (res->start, mode_X, pn_Start_X_initial_exec);
217   res->frame       = new_Proj (res->start, mode_P_data, pn_Start_P_frame_base);
218   res->globals     = new_Proj (res->start, mode_P_data, pn_Start_P_globals);
219   res->initial_mem = new_Proj (res->start, mode_M, pn_Start_M);
220   res->args        = new_Proj (res->start, mode_T, pn_Start_T_args);
221 #ifdef DEBUG_libfirm
222   res->graph_nr    = get_irp_new_node_nr();
223 #endif
224   res->proj_args   = NULL;
225
226   set_store(res->initial_mem);
227
228   add_immBlock_pred(res->start_block, projX);
229   /*
230    * The code generation needs it. leave it in now.
231    * Use of this edge is matter of discussion, unresolved. Also possible:
232    * add_immBlock_pred(res->start_block, res->start_block), but invalid typed.
233    */
234   mature_immBlock (res->current_block);
235
236   /*-- Make a block to start with --*/
237   first_block = new_immBlock();
238   add_immBlock_pred (first_block, projX);
239
240   res->method_execution_frequency = -1;
241   res->estimated_node_count       = 0;
242
243   return res;
244 }
245
246
247 ir_graph *
248 new_ir_graph (entity *ent, int n_loc)
249 {
250   ir_graph *res = new_r_ir_graph (ent, n_loc);
251   add_irp_irg(res);          /* remember this graph global. */
252   return res;
253 }
254
255 /* Make a rudimentary ir graph for the constant code.
256    Must look like a correct irg, spare everything else. */
257 ir_graph *new_const_code_irg(void) {
258   ir_graph *res;
259   ir_node *projX;
260
261   res = alloc_graph();
262
263   /* inform statistics here, as blocks will be already build on this graph */
264   hook_new_graph(res, NULL);
265
266   current_ir_graph = res;
267   res->n_loc = 1;       /* Only the memory. */
268   res->visited = 0;     /* visited flag, for the ir walker */
269   res->block_visited=0; /* visited flag, for the 'block'-walker */
270 #if USE_EXPLICIT_PHI_IN_STACK
271   res->Phi_in_stack = NULL;
272 #endif
273   res->kind = k_ir_graph;
274   res->obst      = xmalloc (sizeof(*res->obst));
275   obstack_init (res->obst);
276   res->extbb_obst = NULL;
277
278   res->phase_state      = phase_building;
279   res->irg_pinned_state = op_pin_state_pinned;
280   res->extblk_state     = ir_extblk_info_none;
281
282   res->value_table = new_identities (); /* value table for global value
283                        numbering for optimizing use in
284                        iropt.c */
285   res->ent = NULL;
286   res->frame_type  = NULL;
287
288   /* -- The end block -- */
289   res->end_block  = new_immBlock ();
290   res->end        = new_End ();
291   res->end_reg    = res->end;
292   res->end_except = res->end;
293   mature_immBlock(get_cur_block());  /* mature the end block */
294
295   /* -- The start block -- */
296   res->start_block = new_immBlock ();
297   res->bad     = new_ir_node (NULL, res, res->start_block, op_Bad, mode_T, 0, NULL);
298   res->no_mem  = new_ir_node (NULL, res, res->start_block, op_NoMem, mode_M, 0, NULL);
299   res->start   = new_Start ();
300   /* Proj results of start node */
301   res->initial_mem = new_Proj (res->start, mode_M, pn_Start_M);
302   projX            = new_Proj (res->start, mode_X, pn_Start_X_initial_exec);
303   add_immBlock_pred (res->start_block, projX);
304   mature_immBlock   (res->start_block);  /* mature the start block */
305
306   add_immBlock_pred (new_immBlock (), projX);
307   mature_immBlock   (get_cur_block());   /* mature the 'body' block for expressions */
308
309   /* Set the visited flag high enough that the blocks will never be visited. */
310   set_irn_visited(get_cur_block(), -1);
311   set_Block_block_visited(get_cur_block(), -1);
312   set_Block_block_visited(res->start_block, -1);
313   set_irn_visited(res->start_block, -1);
314   set_irn_visited(res->bad, -1);
315   set_irn_visited(res->no_mem, -1);
316
317   res->phase_state = phase_high;
318
319   return res;
320 }
321
322 /* Defined in iropt.c */
323 void  del_identities (pset *value_table);
324
325 /* Frees the passed irgraph.
326    Deallocates all nodes in this graph and the ir_graph structure.
327    Sets the field irgraph in the corresponding entity to NULL.
328    Does not remove the irgraph from the list in irprog (requires
329    inefficient search, call remove_irp_irg by hand).
330    Does not free types, entities or modes that are used only by this
331    graph, nor the entity standing for this graph. */
332 void free_ir_graph (ir_graph *irg) {
333   assert(is_ir_graph(irg));
334
335   hook_free_graph(irg);
336   if (irg->outs_state != outs_none) free_irg_outs(irg);
337   if (irg->frame_type)  free_type(irg->frame_type);
338   if (irg->value_table) del_identities(irg->value_table);
339   if (irg->ent) {
340     peculiarity pec = get_entity_peculiarity (irg->ent);
341     set_entity_peculiarity (irg->ent, peculiarity_description);
342     set_entity_irg(irg->ent, NULL);  /* not set in const code irg */
343     set_entity_peculiarity (irg->ent, pec);
344   }
345
346   free_End(irg->end);
347   obstack_free(irg->obst,NULL);
348   free(irg->obst);
349 #if USE_EXPLICIT_PHI_IN_STACK
350   free_Phi_in_stack(irg->Phi_in_stack);
351 #endif
352   if (irg->loc_descriptions)
353     free(irg->loc_descriptions);
354   irg->kind = k_BAD;
355   free_graph(irg);
356 }
357
358 /* access routines for all ir_graph attributes:
359    templates:
360    {attr type} get_irg_{attribute name} (ir_graph *irg);
361    void set_irg_{attr name} (ir_graph *irg, {attr type} {attr}); */
362
363 int
364 (is_ir_graph)(const void *thing) {
365   return _is_ir_graph(thing);
366 }
367
368 /* Outputs a unique number for this node */
369 long get_irg_graph_nr(ir_graph *irg) {
370   assert(irg);
371 #ifdef DEBUG_libfirm
372   return irg->graph_nr;
373 #else
374   return (long)PTR_TO_INT(irg);
375 #endif
376 }
377
378 ir_node *
379 (get_irg_start_block)(const ir_graph *irg) {
380   return _get_irg_start_block(irg);
381 }
382
383 void
384 (set_irg_start_block)(ir_graph *irg, ir_node *node) {
385   _set_irg_start_block(irg, node);
386 }
387
388 ir_node *
389 (get_irg_start)(const ir_graph *irg) {
390   return _get_irg_start(irg);
391 }
392
393 void
394 (set_irg_start)(ir_graph *irg, ir_node *node) {
395   _set_irg_start(irg, node);
396 }
397
398 ir_node *
399 (get_irg_end_block)(const ir_graph *irg) {
400   return _get_irg_end_block(irg);
401 }
402
403 void
404 (set_irg_end_block)(ir_graph *irg, ir_node *node) {
405   _set_irg_end_block(irg, node);
406 }
407
408 ir_node *
409 (get_irg_end)(const ir_graph *irg) {
410   return _get_irg_end(irg);
411 }
412
413 void
414 (set_irg_end)(ir_graph *irg, ir_node *node) {
415   _set_irg_end(irg, node);
416 }
417
418 ir_node *
419 (get_irg_end_reg)(const ir_graph *irg) {
420   return _get_irg_end_reg(irg);
421 }
422
423 void     set_irg_end_reg (ir_graph *irg, ir_node *node) {
424   assert(get_irn_op(node) == op_EndReg || get_irn_op(node) == op_End);
425   irg->end_reg = node;
426 }
427
428 ir_node *
429 (get_irg_end_except)(const ir_graph *irg) {
430   return _get_irg_end_except(irg);
431 }
432
433 void     set_irg_end_except (ir_graph *irg, ir_node *node) {
434   assert(get_irn_op(node) == op_EndExcept || get_irn_op(node) == op_End);
435   irg->end_except = node;
436 }
437
438 ir_node *
439 (get_irg_cstore)(const ir_graph *irg) {
440   return _get_irg_cstore(irg);
441 }
442
443 void
444 (set_irg_cstore)(ir_graph *irg, ir_node *node) {
445   _set_irg_cstore(irg, node);
446 }
447
448 ir_node *
449 (get_irg_frame)(const ir_graph *irg) {
450   return _get_irg_frame(irg);
451 }
452
453 void
454 (set_irg_frame)(ir_graph *irg, ir_node *node) {
455   _set_irg_frame(irg, node);
456 }
457
458 ir_node *
459 (get_irg_globals)(const ir_graph *irg) {
460   return _get_irg_globals(irg);
461 }
462
463 void
464 (set_irg_globals)(ir_graph *irg, ir_node *node) {
465   _set_irg_globals(irg, node);
466 }
467
468 ir_node *
469 (get_irg_initial_mem)(const ir_graph *irg) {
470   return _get_irg_initial_mem(irg);
471 }
472
473 void
474 (set_irg_initial_mem)(ir_graph *irg, ir_node *node) {
475   _set_irg_initial_mem(irg, node);
476 }
477
478 ir_node *
479 (get_irg_args)(const ir_graph *irg) {
480   return _get_irg_args(irg);
481 }
482
483 void
484 (set_irg_args)(ir_graph *irg, ir_node *node) {
485   _set_irg_args(irg, node);
486 }
487
488 ir_node **
489 (get_irg_proj_args) (const ir_graph *irg) {
490   return _get_irg_proj_args (irg);
491 }
492
493 void
494 (set_irg_proj_args) (ir_graph *irg, ir_node **nodes) {
495   _set_irg_proj_args (irg, nodes);
496 }
497
498 ir_node *
499 (get_irg_bad)(const ir_graph *irg) {
500   return _get_irg_bad(irg);
501 }
502
503 void
504 (set_irg_bad)(ir_graph *irg, ir_node *node) {
505   _set_irg_bad(irg, node);
506 }
507
508 ir_node *
509 (get_irg_no_mem)(const ir_graph *irg) {
510   return _get_irg_no_mem(irg);
511 }
512
513 void
514 (set_irg_no_mem)(ir_graph *irg, ir_node *node) {
515   _set_irg_no_mem(irg, node);
516 }
517
518 ir_node *
519 (get_irg_current_block)(const ir_graph *irg) {
520   return _get_irg_current_block(irg);
521 }
522
523 void
524 (set_irg_current_block)(ir_graph *irg, ir_node *node) {
525   _set_irg_current_block(irg, node);
526 }
527
528 entity *
529 (get_irg_entity)(const ir_graph *irg) {
530   return _get_irg_entity(irg);
531 }
532
533 void
534 (set_irg_entity)(ir_graph *irg, entity *ent) {
535   _set_irg_entity(irg, ent);
536 }
537
538 ir_type *
539 (get_irg_frame_type)(ir_graph *irg) {
540   return _get_irg_frame_type(irg);
541 }
542
543 void
544 (set_irg_frame_type)(ir_graph *irg, ir_type *ftp) {
545   _set_irg_frame_type(irg, ftp);
546 }
547
548 int
549 get_irg_n_locs (ir_graph *irg)
550 {
551   if (get_opt_precise_exc_context())
552     return irg->n_loc - 1 - 1;
553   else
554     return irg->n_loc - 1;
555 }
556
557 void
558 set_irg_n_loc (ir_graph *irg, int n_loc)
559 {
560   if (get_opt_precise_exc_context())
561     irg->n_loc = n_loc + 1 + 1;
562   else
563     irg->n_loc = n_loc + 1;
564 }
565
566
567
568 /* Returns the obstack associated with the graph. */
569 struct obstack *
570 (get_irg_obstack)(const ir_graph *irg) {
571   return _get_irg_obstack(irg);
572 }
573
574 /*
575  * Returns true if the node n is allocated on the storage of graph irg.
576  *
577  * Implementation is GLIBC specific as is uses the internal _obstack_chunk implementation.
578  */
579 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n)
580 {
581   struct _obstack_chunk *p;
582
583   /*
584    * checks weather the ir_node pointer is on the obstack.
585    * A more sophisticated check would test the "whole" ir_node
586    */
587   for (p = irg->obst->chunk; p; p = p->prev) {
588     if (((char *)p->contents <= (char *)n) && ((char *)n < (char *)p->limit))
589       return 1;
590   }
591
592   return 0;
593 }
594
595 irg_phase_state
596 (get_irg_phase_state)(const ir_graph *irg) {
597   return _get_irg_phase_state(irg);
598 }
599
600 void
601 (set_irg_phase_low)(ir_graph *irg) {
602   _set_irg_phase_low(irg);
603 }
604
605 op_pin_state
606 (get_irg_pinned)(const ir_graph *irg) {
607   return _get_irg_pinned(irg);
608 }
609
610 irg_outs_state
611 (get_irg_outs_state)(const ir_graph *irg) {
612   return _get_irg_outs_state(irg);
613 }
614
615 void
616 (set_irg_outs_inconsistent)(ir_graph *irg) {
617   _set_irg_outs_inconsistent(irg);
618 }
619
620 irg_dom_state
621 (get_irg_dom_state)(const ir_graph *irg) {
622   return _get_irg_dom_state(irg);
623 }
624
625 irg_dom_state
626 (get_irg_postdom_state)(const ir_graph *irg) {
627   return _get_irg_postdom_state(irg);
628 }
629
630 void
631 (set_irg_doms_inconsistent)(ir_graph *irg) {
632   _set_irg_doms_inconsistent(irg);
633 }
634
635 irg_loopinfo_state
636 (get_irg_loopinfo_state)(const ir_graph *irg) {
637   return _get_irg_loopinfo_state(irg);
638 }
639
640 void
641 (set_irg_loopinfo_state)(ir_graph *irg, irg_loopinfo_state s) {
642   _set_irg_loopinfo_state(irg, s);
643 }
644
645 void
646 (set_irg_loopinfo_inconsistent)(ir_graph *irg) {
647   _set_irg_loopinfo_inconsistent(irg);
648 }
649
650 void set_irp_loopinfo_inconsistent(void) {
651   int i, n_irgs = get_irp_n_irgs();
652   for (i = 0; i < n_irgs; ++i) {
653     set_irg_loopinfo_inconsistent(get_irp_irg(i));
654   }
655 }
656
657
658
659 void
660 (set_irg_pinned)(ir_graph *irg, op_pin_state p) {
661   _set_irg_pinned(irg, p);
662 }
663
664 irg_callee_info_state
665 (get_irg_callee_info_state)(const ir_graph *irg) {
666   return _get_irg_callee_info_state(irg);
667 }
668
669 void
670 (set_irg_callee_info_state)(ir_graph *irg, irg_callee_info_state s) {
671   _set_irg_callee_info_state(irg, s);
672 }
673
674 irg_inline_property
675 (get_irg_inline_property)(const ir_graph *irg) {
676   return _get_irg_inline_property(irg);
677 }
678
679 void
680 (set_irg_inline_property)(ir_graph *irg, irg_inline_property s) {
681   _set_irg_inline_property(irg, s);
682 }
683
684 unsigned
685 (get_irg_additional_properties)(const ir_graph *irg) {
686   return _get_irg_additional_properties(irg);
687 }
688
689 void
690 (set_irg_additional_properties)(ir_graph *irg, unsigned property_mask) {
691   _set_irg_additional_properties(irg, property_mask);
692 }
693
694 void
695 (set_irg_additional_property)(ir_graph *irg, mtp_additional_property flag) {
696   _set_irg_additional_property(irg, flag);
697 }
698
699 void
700 (set_irg_link)(ir_graph *irg, void *thing) {
701   _set_irg_link(irg, thing);
702 }
703
704 void *
705 (get_irg_link)(const ir_graph *irg) {
706   return _get_irg_link(irg);
707 }
708
709 /** maximum visited flag content of all ir_graph visited fields. */
710 static unsigned long max_irg_visited = 0;
711
712 unsigned long
713 (get_irg_visited)(const ir_graph *irg) {
714   return _get_irg_visited(irg);
715 }
716
717 void
718 set_irg_visited (ir_graph *irg, unsigned long visited)
719 {
720   irg->visited = visited;
721   if (irg->visited > max_irg_visited) {
722     max_irg_visited = irg->visited;
723   }
724 }
725
726 void
727 inc_irg_visited (ir_graph *irg)
728 {
729   if (++irg->visited > max_irg_visited) {
730     max_irg_visited = irg->visited;
731   }
732 }
733
734 unsigned long
735 get_max_irg_visited(void)
736 {
737   /*
738   int i;
739   for(i = 0; i < get_irp_n_irgs(); i++)
740   assert(max_irg_visited >= get_irg_visited(get_irp_irg(i)));
741    */
742   return max_irg_visited;
743 }
744
745 void set_max_irg_visited(int val) {
746   max_irg_visited = val;
747 }
748
749 unsigned long
750 inc_max_irg_visited(void)
751 {
752   /*
753   int i;
754   for(i = 0; i < get_irp_n_irgs(); i++)
755   assert(max_irg_visited >= get_irg_visited(get_irp_irg(i)));
756   */
757   max_irg_visited++;
758   return max_irg_visited;
759 }
760
761 unsigned long
762 (get_irg_block_visited)(const ir_graph *irg) {
763   return _get_irg_block_visited(irg);
764 }
765
766 void
767 (set_irg_block_visited)(ir_graph *irg, unsigned long visited) {
768   _set_irg_block_visited(irg, visited);
769 }
770
771 void
772 (inc_irg_block_visited)(ir_graph *irg) {
773   _inc_irg_block_visited(irg);
774 }
775
776
777 /**
778  * walker Start->End: places Proj nodes into the same block
779  * as it's predecessors
780  *
781  * @param n    the node
782  * @param env  ignored
783  */
784 static void normalize_proj_walker(ir_node *n, void *env)
785 {
786   if (is_Proj(n)) {
787     ir_node *pred  = get_Proj_pred(n);
788     ir_node *block = get_nodes_block(pred);
789
790     set_nodes_block(n, block);
791   }
792 }
793
794 /* move Proj nodes into the same block as its predecessors */
795 void normalize_proj_nodes(ir_graph *irg)
796 {
797   irg_walk_graph(irg, NULL, normalize_proj_walker, NULL);
798   set_irg_outs_inconsistent(irg);
799 }
800
801 /* set a description for local value n */
802 void set_irg_loc_description(ir_graph *irg, int n, void *description)
803 {
804   assert(0 <= n && n < irg->n_loc);
805
806   if (! irg->loc_descriptions)
807     irg->loc_descriptions = xcalloc(sizeof(*irg->loc_descriptions), irg->n_loc);
808
809   irg->loc_descriptions[n] = description;
810 }
811
812 /* get the description for local value n */
813 void *get_irg_loc_description(ir_graph *irg, int n)
814 {
815   assert(0 <= n && n < irg->n_loc);
816   return irg->loc_descriptions ? irg->loc_descriptions[n] : NULL;
817 }
818
819 /* Returns a estimated node count of the irg. */
820 unsigned (get_irg_estimated_node_cnt)(const ir_graph *irg) {
821   return _get_irg_estimated_node_cnt(irg);
822 }
823
824 /* register additional space in an IR graph */
825 size_t register_additional_graph_data(size_t size)
826 {
827   assert(!forbid_new_data && "Too late to register additional node data");
828
829   if (forbid_new_data)
830     return 0;
831
832   return additional_graph_data_size += size;
833 }