Add crude tests for bool simplifications.
[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         res->index       = get_irp_new_irg_idx();
259 #ifdef DEBUG_libfirm
260         res->graph_nr    = get_irp_new_node_nr();
261 #endif
262         res->proj_args   = NULL;
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 #endif
422
423 int get_irg_idx(const ir_graph *irg) {
424         return irg->index;
425 }
426
427 ir_node *
428 (get_irg_start_block)(const ir_graph *irg) {
429         return _get_irg_start_block(irg);
430 }
431
432 void
433 (set_irg_start_block)(ir_graph *irg, ir_node *node) {
434         _set_irg_start_block(irg, node);
435 }
436
437 ir_node *
438 (get_irg_start)(const ir_graph *irg) {
439         return _get_irg_start(irg);
440 }
441
442 void
443 (set_irg_start)(ir_graph *irg, ir_node *node) {
444         _set_irg_start(irg, node);
445 }
446
447 ir_node *
448 (get_irg_end_block)(const ir_graph *irg) {
449         return _get_irg_end_block(irg);
450 }
451
452 void
453 (set_irg_end_block)(ir_graph *irg, ir_node *node) {
454   _set_irg_end_block(irg, node);
455 }
456
457 ir_node *
458 (get_irg_end)(const ir_graph *irg) {
459         return _get_irg_end(irg);
460 }
461
462 void
463 (set_irg_end)(ir_graph *irg, ir_node *node) {
464         _set_irg_end(irg, node);
465 }
466
467 ir_node *
468 (get_irg_end_reg)(const ir_graph *irg) {
469         return _get_irg_end_reg(irg);
470 }
471
472 void
473 (set_irg_end_reg)(ir_graph *irg, ir_node *node) {
474         _set_irg_end_reg(irg, node);
475 }
476
477 ir_node *
478 (get_irg_end_except)(const ir_graph *irg) {
479         return _get_irg_end_except(irg);
480 }
481
482 void
483 (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         _set_irg_end_except(irg, 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         if (get_opt_precise_exc_context())
611                 return irg->n_loc - 1 - 1;
612         else
613                 return irg->n_loc - 1;
614 }
615
616 void
617 set_irg_n_loc(ir_graph *irg, int n_loc) {
618         if (get_opt_precise_exc_context())
619                 irg->n_loc = n_loc + 1 + 1;
620         else
621                 irg->n_loc = n_loc + 1;
622 }
623
624
625
626 /* Returns the obstack associated with the graph. */
627 struct obstack *
628 (get_irg_obstack)(const ir_graph *irg) {
629         return _get_irg_obstack(irg);
630 }
631
632 /*
633  * Returns true if the node n is allocated on the storage of graph irg.
634  *
635  * Implementation is GLIBC specific as is uses the internal _obstack_chunk implementation.
636  */
637 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n) {
638         struct _obstack_chunk *p;
639
640         /*
641          * checks weather the ir_node pointer is on the obstack.
642          * A more sophisticated check would test the "whole" ir_node
643          */
644         for (p = irg->obst->chunk; p; p = p->prev) {
645                 if (((char *)p->contents <= (char *)n) && ((char *)n < (char *)p->limit))
646                         return 1;
647         }
648
649         return 0;
650 }
651
652 irg_phase_state
653 (get_irg_phase_state)(const ir_graph *irg) {
654         return _get_irg_phase_state(irg);
655 }
656
657 void
658 (set_irg_phase_state)(ir_graph *irg, irg_phase_state state) {
659         _set_irg_phase_state(irg, state);
660 }
661
662 op_pin_state
663 (get_irg_pinned)(const ir_graph *irg) {
664         return _get_irg_pinned(irg);
665 }
666
667 irg_outs_state
668 (get_irg_outs_state)(const ir_graph *irg) {
669         return _get_irg_outs_state(irg);
670 }
671
672 void
673 (set_irg_outs_inconsistent)(ir_graph *irg) {
674         _set_irg_outs_inconsistent(irg);
675 }
676
677 irg_extblk_state
678 (get_irg_extblk_state)(const ir_graph *irg) {
679         return _get_irg_extblk_state(irg);
680 }
681
682 void
683 (set_irg_extblk_inconsistent)(ir_graph *irg) {
684         _set_irg_extblk_inconsistent(irg);
685 }
686
687 irg_dom_state
688 (get_irg_dom_state)(const ir_graph *irg) {
689         return _get_irg_dom_state(irg);
690 }
691
692 irg_dom_state
693 (get_irg_postdom_state)(const ir_graph *irg) {
694         return _get_irg_postdom_state(irg);
695 }
696
697 void
698 (set_irg_doms_inconsistent)(ir_graph *irg) {
699         _set_irg_doms_inconsistent(irg);
700 }
701
702 irg_loopinfo_state
703 (get_irg_loopinfo_state)(const ir_graph *irg) {
704         return _get_irg_loopinfo_state(irg);
705 }
706
707 void
708 (set_irg_loopinfo_state)(ir_graph *irg, irg_loopinfo_state s) {
709         _set_irg_loopinfo_state(irg, s);
710 }
711
712 void
713 (set_irg_loopinfo_inconsistent)(ir_graph *irg) {
714         _set_irg_loopinfo_inconsistent(irg);
715 }
716
717 void set_irp_loopinfo_inconsistent(void) {
718         int i;
719         for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
720                 set_irg_loopinfo_inconsistent(get_irp_irg(i));
721         }
722 }
723
724
725
726 void
727 (set_irg_pinned)(ir_graph *irg, op_pin_state p) {
728         _set_irg_pinned(irg, p);
729 }
730
731 irg_callee_info_state
732 (get_irg_callee_info_state)(const ir_graph *irg) {
733         return _get_irg_callee_info_state(irg);
734 }
735
736 void
737 (set_irg_callee_info_state)(ir_graph *irg, irg_callee_info_state s) {
738         _set_irg_callee_info_state(irg, s);
739 }
740
741 irg_inline_property
742 (get_irg_inline_property)(const ir_graph *irg) {
743         return _get_irg_inline_property(irg);
744 }
745
746 void
747 (set_irg_inline_property)(ir_graph *irg, irg_inline_property s) {
748         _set_irg_inline_property(irg, s);
749 }
750
751 unsigned
752 (get_irg_additional_properties)(const ir_graph *irg) {
753         return _get_irg_additional_properties(irg);
754 }
755
756 void
757 (set_irg_additional_properties)(ir_graph *irg, unsigned property_mask) {
758         _set_irg_additional_properties(irg, property_mask);
759 }
760
761 void
762 (set_irg_additional_property)(ir_graph *irg, mtp_additional_property flag) {
763         _set_irg_additional_property(irg, flag);
764 }
765
766 void
767 (set_irg_link)(ir_graph *irg, void *thing) {
768         _set_irg_link(irg, thing);
769 }
770
771 void *
772 (get_irg_link)(const ir_graph *irg) {
773         return _get_irg_link(irg);
774 }
775
776 /** maximum visited flag content of all ir_graph visited fields. */
777 static unsigned long max_irg_visited = 0;
778
779 unsigned long
780 (get_irg_visited)(const ir_graph *irg) {
781         return _get_irg_visited(irg);
782 }
783
784 void
785 set_irg_visited(ir_graph *irg, unsigned long visited) {
786         irg->visited = visited;
787         if (irg->visited > max_irg_visited) {
788                 max_irg_visited = irg->visited;
789         }
790 }
791
792 void
793 inc_irg_visited(ir_graph *irg) {
794         if (++irg->visited > max_irg_visited) {
795                 max_irg_visited = irg->visited;
796         }
797 }
798
799 unsigned long
800 get_max_irg_visited(void) {
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         int i;
817         for(i = 0; i < get_irp_n_irgs(); i++)
818         assert(max_irg_visited >= get_irg_visited(get_irp_irg(i)));
819         */
820         return ++max_irg_visited;
821 }
822
823 unsigned long
824 (get_irg_block_visited)(const ir_graph *irg) {
825         return _get_irg_block_visited(irg);
826 }
827
828 void
829 (set_irg_block_visited)(ir_graph *irg, unsigned long visited) {
830         _set_irg_block_visited(irg, visited);
831 }
832
833 void
834 (inc_irg_block_visited)(ir_graph *irg) {
835   _inc_irg_block_visited(irg);
836 }
837
838 /* Return the floating point model of this graph. */
839 unsigned (get_irg_fp_model)(const ir_graph *irg) {
840         return _get_irg_fp_model(irg);
841 }
842
843 /* Sets the floating point model for this graph. */
844 void set_irg_fp_model(ir_graph *irg, unsigned model) {
845         irg->fp_model = model;
846 }
847
848 /**
849  * walker Start->End: places Proj nodes into the same block
850  * as it's predecessors
851  *
852  * @param n    the node
853  * @param env  ignored
854  */
855 static void normalize_proj_walker(ir_node *n, void *env) {
856         (void) env;
857         if (is_Proj(n)) {
858                 ir_node *pred  = get_Proj_pred(n);
859                 ir_node *block = get_nodes_block(pred);
860
861                 set_nodes_block(n, block);
862         }
863 }
864
865 /* move Proj nodes into the same block as its predecessors */
866 void normalize_proj_nodes(ir_graph *irg) {
867         irg_walk_graph(irg, NULL, normalize_proj_walker, NULL);
868         set_irg_outs_inconsistent(irg);
869 }
870
871 /* set a description for local value n */
872 void set_irg_loc_description(ir_graph *irg, int n, void *description) {
873         assert(0 <= n && n < irg->n_loc);
874
875         if (! irg->loc_descriptions)
876                 irg->loc_descriptions = xcalloc(sizeof(*irg->loc_descriptions), irg->n_loc);
877
878         irg->loc_descriptions[n] = description;
879 }
880
881 /* get the description for local value n */
882 void *get_irg_loc_description(ir_graph *irg, int n) {
883         assert(0 <= n && n < irg->n_loc);
884         return irg->loc_descriptions ? irg->loc_descriptions[n] : NULL;
885 }
886
887 #ifndef NDEBUG
888 void set_using_block_visited(ir_graph *irg) {
889         assert(irg->using_block_visited == 0);
890         irg->using_block_visited = 1;
891 }
892
893 void clear_using_block_visited(ir_graph *irg) {
894         assert(irg->using_block_visited == 1);
895         irg->using_block_visited = 0;
896 }
897
898 int using_block_visited(const ir_graph *irg) {
899         return irg->using_block_visited;
900 }
901
902
903 void set_using_visited(ir_graph *irg) {
904         assert(irg->using_visited == 0);
905         irg->using_visited = 1;
906 }
907
908 void clear_using_visited(ir_graph *irg) {
909         assert(irg->using_visited == 1);
910         irg->using_visited = 0;
911 }
912
913 int using_visited(const ir_graph *irg) {
914         return irg->using_visited;
915 }
916
917
918 void set_using_irn_link(ir_graph *irg) {
919         assert(irg->using_irn_link == 0);
920         irg->using_irn_link = 1;
921 }
922
923 void clear_using_irn_link(ir_graph *irg) {
924         assert(irg->using_irn_link == 1);
925         irg->using_irn_link = 0;
926 }
927
928 int using_irn_link(const ir_graph *irg) {
929         return irg->using_irn_link;
930 }
931 #endif
932
933 /* Returns a estimated node count of the irg. */
934 unsigned (get_irg_estimated_node_cnt)(const ir_graph *irg) {
935         return _get_irg_estimated_node_cnt(irg);
936 }
937
938 /* Returns the last irn index for this graph. */
939 unsigned get_irg_last_idx(const ir_graph *irg) {
940         return irg->last_node_idx;
941 }
942
943 /* register additional space in an IR graph */
944 size_t register_additional_graph_data(size_t size) {
945         assert(!forbid_new_data && "Too late to register additional node data");
946
947         if (forbid_new_data)
948                 return 0;
949
950         return additional_graph_data_size += size;
951 }