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