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