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