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