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