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