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