irgraph: Put the obstack into ir_graph instead of delegating it.
[libfirm] / ir / ir / irgraph.c
1 /*
2  * Copyright (C) 1995-2011 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  */
25 #include "config.h"
26
27 #include <string.h>
28 #include <stddef.h>
29
30 #include "xmalloc.h"
31 #include "ircons_t.h"
32 #include "irgraph_t.h"
33 #include "irprog_t.h"
34 #include "irgraph_t.h"
35 #include "irnode_t.h"
36 #include "iropt_t.h"
37 #include "irflag_t.h"
38 #include "array.h"
39 #include "irgmod.h"
40 #include "irouts.h"
41 #include "irhooks.h"
42 #include "irtools.h"
43 #include "util.h"
44 #include "irgwalk.h"
45 #include "irbackedge_t.h"
46 #include "iredges_t.h"
47 #include "type_t.h"
48 #include "irmemory.h"
49 #include "iroptimize.h"
50 #include "irgopt.h"
51
52 #define INITIAL_IDX_IRN_MAP_SIZE 1024
53 /** Suffix that is added to every frame type. */
54 #define FRAME_TP_SUFFIX "frame_tp"
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 {
71         return current_ir_graph;
72 }
73
74 void set_current_ir_graph(ir_graph *graph)
75 {
76         current_ir_graph = graph;
77 }
78
79 /** contains the suffix for frame type names */
80 static ident *frame_type_suffix = NULL;
81
82 void firm_init_irgraph(void)
83 {
84         frame_type_suffix = new_id_from_str(FRAME_TP_SUFFIX);
85         forbid_new_data   = 1;
86 }
87
88 /**
89  * Allocate a new IR graph.
90  * This function respects the registered graph data. The only reason for
91  * this function is, that there are two locations, where graphs are
92  * allocated (new_r_ir_graph, new_const_code_irg).
93  * @return Memory for a new graph.
94  */
95 static ir_graph *alloc_graph(void)
96 {
97         ir_graph *res;
98         size_t   size = sizeof(ir_graph) + additional_graph_data_size;
99         char     *ptr = XMALLOCNZ(char, size);
100
101         res = (ir_graph *)(ptr + additional_graph_data_size);
102         res->kind = k_ir_graph;
103
104         /* initialize the idx->node map. */
105         res->idx_irn_map = NEW_ARR_F(ir_node *, INITIAL_IDX_IRN_MAP_SIZE);
106         memset(res->idx_irn_map, 0, INITIAL_IDX_IRN_MAP_SIZE * sizeof(res->idx_irn_map[0]));
107
108         return res;
109 }
110
111 /**
112  * Frees an allocated IR graph
113  */
114 static void free_graph(ir_graph *irg)
115 {
116         char           *ptr = (char *)irg;
117         ir_edge_kind_t  i;
118
119         for (i = EDGE_KIND_FIRST; i < EDGE_KIND_LAST; ++i)
120                 edges_deactivate_kind(irg, i);
121         DEL_ARR_F(irg->idx_irn_map);
122         free(ptr - additional_graph_data_size);
123 }
124
125 void irg_set_nloc(ir_graph *res, int n_loc)
126 {
127         assert(irg_is_constrained(res, IR_GRAPH_CONSTRAINT_CONSTRUCTION));
128
129         res->n_loc = n_loc + 1;     /* number of local variables that are never
130                                        dereferenced in this graph plus one for
131                                        the store. This is not the number of
132                                        parameters to the procedure!  */
133
134         if (res->loc_descriptions) {
135                 xfree(res->loc_descriptions);
136                 res->loc_descriptions = NULL;
137         }
138 }
139
140 ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc)
141 {
142         ir_graph *res;
143         ir_node  *first_block;
144         ir_node  *start, *start_block, *initial_mem, *projX;
145
146         res = alloc_graph();
147
148         /* inform statistics here, as blocks will be already build on this graph */
149         hook_new_graph(res, ent);
150
151         /*-- initialized for each graph. --*/
152         res->kind = k_ir_graph;
153         obstack_init(&res->obst);
154
155         /* graphs are in construction mode by default */
156         add_irg_constraints(res, IR_GRAPH_CONSTRAINT_CONSTRUCTION);
157         irg_set_nloc(res, n_loc);
158
159         /* descriptions will be allocated on demand */
160         res->loc_descriptions = NULL;
161
162         res->visited       = 0; /* visited flag, for the ir walker */
163         res->block_visited = 0; /* visited flag, for the 'block'-walker */
164
165         res->last_node_idx = 0;
166
167         new_identities(res);
168
169         res->irg_pinned_state    = op_pin_state_pinned;
170         res->typeinfo_state      = ir_typeinfo_none;
171         set_irp_typeinfo_inconsistent();           /* there is a new graph with typeinfo_none. */
172         res->callee_info_state   = irg_callee_info_none;
173         res->class_cast_state    = ir_class_casts_transitive;
174         res->fp_model            = fp_model_precise;
175         res->mem_disambig_opt    = aa_opt_inherited;
176
177         /*-- Type information for the procedure of the graph --*/
178         res->ent = ent;
179         set_entity_irg(ent, res);
180
181         /*--  a class type so that it can contain "inner" methods as in Pascal. --*/
182         res->frame_type = new_type_frame();
183
184         /* the Anchor node must be created first */
185         res->anchor = new_r_Anchor(res);
186
187         /*-- Nodes needed in every graph --*/
188         set_irg_end_block(res, new_r_immBlock(res));
189         set_irg_end(res, new_r_End(res, 0, NULL));
190
191         start_block = new_r_Block_noopt(res, 0, NULL);
192         set_irg_start_block(res, start_block);
193         set_irg_no_mem     (res, new_r_NoMem(res));
194         start = new_r_Start(res);
195         set_irg_start      (res, start);
196
197         /* Proj results of start node */
198         projX                   = new_r_Proj(start, mode_X, pn_Start_X_initial_exec);
199         set_irg_initial_exec    (res, projX);
200         set_irg_frame           (res, new_r_Proj(start, mode_P_data, pn_Start_P_frame_base));
201         set_irg_args            (res, new_r_Proj(start, mode_T,      pn_Start_T_args));
202         initial_mem             = new_r_Proj(start, mode_M, pn_Start_M);
203         set_irg_initial_mem(res, initial_mem);
204
205         res->index       = get_irp_new_irg_idx();
206 #ifdef DEBUG_libfirm
207         res->graph_nr    = get_irp_new_node_nr();
208 #endif
209
210         set_r_cur_block(res, start_block);
211         set_r_store(res, initial_mem);
212
213         /*-- Make a block to start with --*/
214         first_block = new_r_Block(res, 1, &projX);
215         set_r_cur_block(res, first_block);
216
217         res->method_execution_frequency = -1.0;
218
219         return res;
220 }
221
222 ir_graph *new_ir_graph(ir_entity *ent, int n_loc)
223 {
224         ir_graph *res = new_r_ir_graph(ent, n_loc);
225         add_irp_irg(res);          /* remember this graph global. */
226         return res;
227 }
228
229 ir_graph *new_const_code_irg(void)
230 {
231         ir_graph *res = alloc_graph();
232         ir_node  *body_block;
233         ir_node  *end;
234         ir_node  *end_block;
235         ir_node  *no_mem;
236         ir_node  *projX;
237         ir_node  *start_block;
238         ir_node  *start;
239
240         /* inform statistics here, as blocks will be already build on this graph */
241         hook_new_graph(res, NULL);
242
243         res->n_loc         = 1; /* Only the memory. */
244         res->visited       = 0; /* visited flag, for the ir walker */
245         res->block_visited = 0; /* visited flag, for the 'block'-walker */
246         obstack_init(&res->obst);
247
248         res->last_node_idx = 0;
249
250         res->irg_pinned_state = op_pin_state_pinned;
251         res->fp_model         = fp_model_precise;
252
253         /* value table for global value numbering for optimizing use in iropt.c */
254         new_identities(res);
255         res->ent         = NULL;
256         res->frame_type  = NULL;
257
258         add_irg_constraints(res, IR_GRAPH_CONSTRAINT_CONSTRUCTION);
259
260         /* the Anchor node must be created first */
261         res->anchor = new_r_Anchor(res);
262
263         /* -- The end block -- */
264         end_block = new_r_Block_noopt(res, 0, NULL);
265         set_irg_end_block(res, end_block);
266         end = new_r_End(res, 0, NULL);
267         set_irg_end(res, end);
268
269         /* -- The start block -- */
270         start_block = new_r_Block_noopt(res, 0, NULL);
271         set_irg_start_block(res, start_block);
272         no_mem = new_r_NoMem(res);
273         set_irg_no_mem(res, no_mem);
274         start = new_r_Start(res);
275         set_irg_start(res, start);
276
277         /* Proj results of start node */
278         set_irg_initial_mem(res, new_r_Proj(start, mode_M, pn_Start_M));
279         projX = new_r_Proj(start, mode_X, pn_Start_X_initial_exec);
280
281         body_block = new_r_Block(res, 1, &projX);
282
283         set_r_cur_block(res, body_block);
284
285         /* Set the visited flag high enough that the blocks will never be visited. */
286         set_irn_visited(body_block, -1);
287         set_Block_block_visited(body_block, -1);
288         set_Block_block_visited(start_block, -1);
289         set_irn_visited(start_block, -1);
290
291         return res;
292 }
293
294 /**
295  * Pre-Walker: Copies blocks and nodes from the original method graph
296  * to the copied graph.
297  *
298  * @param n    A node from the original method graph.
299  * @param env  The copied graph.
300  */
301 static void copy_all_nodes(ir_node *node, void *env)
302 {
303         ir_graph *irg      = (ir_graph*)env;
304         ir_node  *new_node = irn_copy_into_irg(node, irg);
305
306         set_irn_link(node, new_node);
307
308         /* fix access to entities on the stack frame */
309         if (is_Sel(new_node)) {
310                 ir_entity *ent = get_Sel_entity(new_node);
311                 ir_type   *tp  = get_entity_owner(ent);
312
313                 if (is_frame_type(tp)) {
314                         /* replace by the copied entity */
315                         ent = (ir_entity*)get_entity_link(ent);
316
317                         assert(is_entity(ent));
318                         assert(get_entity_owner(ent) == get_irg_frame_type(irg));
319                         set_Sel_entity(new_node, ent);
320                 }
321         }
322 }
323
324 /**
325  * Post-walker: Set the predecessors of the copied nodes.
326  * The copied nodes are set as link of their original nodes. The links of
327  * "irn" predecessors are the predecessors of copied node.
328  */
329 static void rewire(ir_node *irn, void *env)
330 {
331         (void) env;
332         irn_rewire_inputs(irn);
333 }
334
335 static ir_node *get_new_node(const ir_node *old_node)
336 {
337         return (ir_node*) get_irn_link(old_node);
338 }
339
340 ir_graph *create_irg_copy(ir_graph *irg)
341 {
342         ir_graph *res;
343
344         res = alloc_graph();
345
346         res->n_loc = 0;
347         res->visited = 0;       /* visited flag, for the ir walker */
348         res->block_visited = 0; /* visited flag, for the 'block'-walker */
349         obstack_init(&res->obst);
350
351         res->last_node_idx = 0;
352
353         res->irg_pinned_state = irg->irg_pinned_state;
354         res->fp_model         = irg->fp_model;
355
356         new_identities(res);
357
358         /* clone the frame type here for safety */
359         irp_reserve_resources(irp, IRP_RESOURCE_ENTITY_LINK);
360         res->frame_type  = clone_frame_type(irg->frame_type);
361
362         ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
363
364         /* copy all nodes from the graph irg to the new graph res */
365         irg_walk_anchors(irg, copy_all_nodes, rewire, res);
366
367         /* copy the Anchor node */
368         res->anchor = get_new_node(irg->anchor);
369
370         /* -- The end block -- */
371         set_irg_end_block (res, get_new_node(get_irg_end_block(irg)));
372         set_irg_end       (res, get_new_node(get_irg_end(irg)));
373
374         /* -- The start block -- */
375         set_irg_start_block(res, get_new_node(get_irg_start_block(irg)));
376         set_irg_no_mem     (res, get_new_node(get_irg_no_mem(irg)));
377         set_irg_start      (res, get_new_node(get_irg_start(irg)));
378
379         /* Proj results of start node */
380         set_irg_initial_mem(res, get_new_node(get_irg_initial_mem(irg)));
381
382         ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
383         irp_free_resources(irp, IRP_RESOURCE_ENTITY_LINK);
384
385         return res;
386 }
387
388 void free_ir_graph(ir_graph *irg)
389 {
390         assert(is_ir_graph(irg));
391
392         remove_irp_irg(irg);
393         confirm_irg_properties(irg, IR_GRAPH_PROPERTIES_NONE);
394
395         hook_free_graph(irg);
396         free_irg_outs(irg);
397         del_identities(irg);
398         if (irg->ent) {
399                 set_entity_irg(irg->ent, NULL);  /* not set in const code irg */
400         }
401
402         free_End(get_irg_end(irg));
403         obstack_free(&irg->obst, NULL);
404         if (irg->loc_descriptions)
405                 free(irg->loc_descriptions);
406         irg->kind = k_BAD;
407         free_graph(irg);
408 }
409
410 int (is_ir_graph)(const void *thing)
411 {
412         return is_ir_graph_(thing);
413 }
414
415 #ifdef DEBUG_libfirm
416 long get_irg_graph_nr(const ir_graph *irg)
417 {
418         return irg->graph_nr;
419 }
420 #else
421 long get_irg_graph_nr(const ir_graph *irg)
422 {
423         return PTR_TO_INT(irg);
424 }
425 #endif
426
427 size_t get_irg_idx(const ir_graph *irg)
428 {
429         return irg->index;
430 }
431
432 ir_node *(get_idx_irn)(const ir_graph *irg, unsigned idx)
433 {
434         return get_idx_irn_(irg, idx);
435 }
436
437 ir_node *(get_irg_start_block)(const ir_graph *irg)
438 {
439         return get_irg_start_block_(irg);
440 }
441
442 void (set_irg_start_block)(ir_graph *irg, ir_node *node)
443 {
444         set_irg_start_block_(irg, node);
445 }
446
447 ir_node *(get_irg_start)(const ir_graph *irg)
448 {
449         return get_irg_start_(irg);
450 }
451
452 void (set_irg_start)(ir_graph *irg, ir_node *node)
453 {
454         set_irg_start_(irg, node);
455 }
456
457 ir_node *(get_irg_end_block)(const ir_graph *irg)
458 {
459         return get_irg_end_block_(irg);
460 }
461
462 void (set_irg_end_block)(ir_graph *irg, ir_node *node)
463 {
464         set_irg_end_block_(irg, node);
465 }
466
467 ir_node *(get_irg_end)(const ir_graph *irg)
468 {
469         return get_irg_end_(irg);
470 }
471
472 void (set_irg_end)(ir_graph *irg, ir_node *node)
473 {
474         set_irg_end_(irg, node);
475 }
476
477 ir_node *(get_irg_initial_exec)(const ir_graph *irg)
478 {
479         return get_irg_initial_exec_(irg);
480 }
481
482 void (set_irg_initial_exec)(ir_graph *irg, ir_node *node)
483 {
484         set_irg_initial_exec_(irg, node);
485 }
486
487 ir_node *(get_irg_frame)(const ir_graph *irg)
488 {
489         return get_irg_frame_(irg);
490 }
491
492 void (set_irg_frame)(ir_graph *irg, ir_node *node)
493 {
494         set_irg_frame_(irg, node);
495 }
496
497 ir_node *(get_irg_initial_mem)(const ir_graph *irg)
498 {
499         return get_irg_initial_mem_(irg);
500 }
501
502 void (set_irg_initial_mem)(ir_graph *irg, ir_node *node)
503 {
504         set_irg_initial_mem_(irg, node);
505 }
506
507 ir_node *(get_irg_args)(const ir_graph *irg)
508 {
509         return get_irg_args_(irg);
510 }
511
512 void (set_irg_args)(ir_graph *irg, ir_node *node)
513 {
514         set_irg_args_(irg, node);
515 }
516
517 ir_node *(get_irg_no_mem)(const ir_graph *irg)
518 {
519         return get_irg_no_mem_(irg);
520 }
521
522 void (set_irg_no_mem)(ir_graph *irg, ir_node *node)
523 {
524         set_irg_no_mem_(irg, node);
525 }
526
527 ir_entity *(get_irg_entity)(const ir_graph *irg)
528 {
529         return get_irg_entity_(irg);
530 }
531
532 void (set_irg_entity)(ir_graph *irg, ir_entity *ent)
533 {
534         set_irg_entity_(irg, ent);
535 }
536
537 ir_type *(get_irg_frame_type)(ir_graph *irg)
538 {
539         return get_irg_frame_type_(irg);
540 }
541
542 void (set_irg_frame_type)(ir_graph *irg, ir_type *ftp)
543 {
544         set_irg_frame_type_(irg, ftp);
545 }
546
547 int get_irg_n_locs(ir_graph *irg)
548 {
549         return irg->n_loc - 1;
550 }
551
552 int node_is_in_irgs_storage(const ir_graph *irg, const ir_node *n)
553 {
554         /* Check whether the ir_node pointer is on the obstack.
555          * A more sophisticated check would test the "whole" ir_node. */
556         for (struct _obstack_chunk const *p = irg->obst.chunk; p; p = p->prev) {
557                 if (((char *)p->contents <= (char *)n) && ((char *)n < (char *)p->limit))
558                         return 1;
559         }
560
561         return 0;
562 }
563
564 op_pin_state (get_irg_pinned)(const ir_graph *irg)
565 {
566         return get_irg_pinned_(irg);
567 }
568
569 irg_callee_info_state (get_irg_callee_info_state)(const ir_graph *irg)
570 {
571         return get_irg_callee_info_state_(irg);
572 }
573
574 void (set_irg_callee_info_state)(ir_graph *irg, irg_callee_info_state s)
575 {
576         set_irg_callee_info_state_(irg, s);
577 }
578
579 void (set_irg_link)(ir_graph *irg, void *thing)
580 {
581         set_irg_link_(irg, thing);
582 }
583
584 void *(get_irg_link)(const ir_graph *irg)
585 {
586         return get_irg_link_(irg);
587 }
588
589 ir_visited_t (get_irg_visited)(const ir_graph *irg)
590 {
591         return get_irg_visited_(irg);
592 }
593
594 /** maximum visited flag content of all ir_graph visited fields. */
595 static ir_visited_t max_irg_visited = 0;
596
597 void set_irg_visited(ir_graph *irg, ir_visited_t visited)
598 {
599         irg->visited = visited;
600         if (irg->visited > max_irg_visited) {
601                 max_irg_visited = irg->visited;
602         }
603 }
604
605 void inc_irg_visited(ir_graph *irg)
606 {
607         ++irg->visited;
608         if (irg->visited > max_irg_visited) {
609                 max_irg_visited = irg->visited;
610         }
611 }
612
613 ir_visited_t get_max_irg_visited(void)
614 {
615         return max_irg_visited;
616 }
617
618 void set_max_irg_visited(int val)
619 {
620         max_irg_visited = val;
621 }
622
623 ir_visited_t inc_max_irg_visited(void)
624 {
625 #ifndef NDEBUG
626         size_t i;
627         for (i = 0; i < get_irp_n_irgs(); i++)
628                 assert(max_irg_visited >= get_irg_visited(get_irp_irg(i)));
629 #endif
630         return ++max_irg_visited;
631 }
632
633 ir_visited_t (get_irg_block_visited)(const ir_graph *irg)
634 {
635         return get_irg_block_visited_(irg);
636 }
637
638 void (set_irg_block_visited)(ir_graph *irg, ir_visited_t visited)
639 {
640         set_irg_block_visited_(irg, visited);
641 }
642
643 void (inc_irg_block_visited)(ir_graph *irg)
644 {
645   inc_irg_block_visited_(irg);
646 }
647
648 unsigned (get_irg_fp_model)(const ir_graph *irg)
649 {
650         return get_irg_fp_model_(irg);
651 }
652
653 void set_irg_fp_model(ir_graph *irg, unsigned model)
654 {
655         irg->fp_model = model;
656 }
657
658 void set_irg_loc_description(ir_graph *irg, int n, void *description)
659 {
660         assert(0 <= n && n < irg->n_loc);
661
662         if (! irg->loc_descriptions)
663                 irg->loc_descriptions = XMALLOCNZ(void*, irg->n_loc);
664
665         irg->loc_descriptions[n] = description;
666 }
667
668 void *get_irg_loc_description(ir_graph *irg, int n)
669 {
670         assert(0 <= n && n < irg->n_loc);
671         return irg->loc_descriptions ? irg->loc_descriptions[n] : NULL;
672 }
673
674 #ifndef NDEBUG
675 void ir_reserve_resources(ir_graph *irg, ir_resources_t resources)
676 {
677         assert((irg->reserved_resources & resources) == 0);
678         irg->reserved_resources |= resources;
679 }
680
681 void ir_free_resources(ir_graph *irg, ir_resources_t resources)
682 {
683         assert((irg->reserved_resources & resources) == resources);
684         irg->reserved_resources &= ~resources;
685 }
686
687 ir_resources_t ir_resources_reserved(const ir_graph *irg)
688 {
689         return irg->reserved_resources;
690 }
691 #endif
692
693 unsigned get_irg_last_idx(const ir_graph *irg)
694 {
695         return irg->last_node_idx;
696 }
697
698 size_t register_additional_graph_data(size_t size)
699 {
700         assert(!forbid_new_data && "Too late to register additional node data");
701
702         if (forbid_new_data)
703                 return 0;
704
705         return additional_graph_data_size += size;
706 }
707
708 void add_irg_constraints(ir_graph *irg, ir_graph_constraints_t constraints)
709 {
710         irg->constraints |= constraints;
711 }
712
713 void clear_irg_constraints(ir_graph *irg, ir_graph_constraints_t constraints)
714 {
715         irg->constraints &= ~constraints;
716 }
717
718 int (irg_is_constrained)(const ir_graph *irg, ir_graph_constraints_t constraints)
719 {
720         return irg_is_constrained_(irg, constraints);
721 }
722
723 void (add_irg_properties)(ir_graph *irg, ir_graph_properties_t props)
724 {
725         add_irg_properties_(irg, props);
726 }
727
728 void (clear_irg_properties)(ir_graph *irg, ir_graph_properties_t props)
729 {
730         clear_irg_properties_(irg, props);
731 }
732
733 int (irg_has_properties)(const ir_graph *irg, ir_graph_properties_t props)
734 {
735         return irg_has_properties_(irg, props);
736 }
737
738 typedef void (*assure_property_func)(ir_graph *irg);
739
740 void assure_irg_properties(ir_graph *irg, ir_graph_properties_t props)
741 {
742         static struct {
743                 ir_graph_properties_t property;
744                 assure_property_func  func;
745         } property_functions[] = {
746                 { IR_GRAPH_PROPERTY_ONE_RETURN,               normalize_one_return },
747                 { IR_GRAPH_PROPERTY_MANY_RETURNS,             normalize_n_returns },
748                 { IR_GRAPH_PROPERTY_NO_CRITICAL_EDGES,        remove_critical_cf_edges },
749                 { IR_GRAPH_PROPERTY_NO_UNREACHABLE_CODE,      remove_unreachable_code },
750                 { IR_GRAPH_PROPERTY_NO_BADS,                  remove_bads },
751                 { IR_GRAPH_PROPERTY_NO_TUPLES,                remove_tuples },
752                 { IR_GRAPH_PROPERTY_CONSISTENT_DOMINANCE,     assure_doms },
753                 { IR_GRAPH_PROPERTY_CONSISTENT_POSTDOMINANCE, assure_postdoms },
754                 { IR_GRAPH_PROPERTY_CONSISTENT_OUT_EDGES,     assure_edges },
755                 { IR_GRAPH_PROPERTY_CONSISTENT_OUTS,          assure_irg_outs },
756                 { IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO,      assure_loopinfo },
757                 { IR_GRAPH_PROPERTY_CONSISTENT_ENTITY_USAGE,  assure_irg_entity_usage_computed },
758                 { IR_GRAPH_PROPERTY_CONSISTENT_DOMINANCE_FRONTIERS, ir_compute_dominance_frontiers },
759         };
760         size_t i;
761         for (i = 0; i < ARRAY_SIZE(property_functions); ++i) {
762                 ir_graph_properties_t missing = props & ~irg->properties;
763                 if (missing & property_functions[i].property)
764                         property_functions[i].func(irg);
765         }
766         assert((props & ~irg->properties) == IR_GRAPH_PROPERTIES_NONE);
767 }
768
769 void confirm_irg_properties(ir_graph *irg, ir_graph_properties_t props)
770 {
771         clear_irg_properties(irg, ~props);
772         if (! (props & IR_GRAPH_PROPERTY_CONSISTENT_OUT_EDGES))
773                 edges_deactivate(irg);
774         if (! (props & IR_GRAPH_PROPERTY_CONSISTENT_OUTS)
775             && (irg->properties & IR_GRAPH_PROPERTY_CONSISTENT_OUTS))
776             free_irg_outs(irg);
777         if (! (props & IR_GRAPH_PROPERTY_CONSISTENT_DOMINANCE_FRONTIERS))
778                 ir_free_dominance_frontiers(irg);
779 }