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