Prefer get_mode_null() over get_tarval_null().
[libfirm] / ir / ana / irmemory.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    Memory disambiguator
23  * @author   Michael Beck
24  * @date     27.12.2006
25  * @version  $Id$
26  */
27 #include "config.h"
28
29 #include <stdlib.h>
30 #include <stdbool.h>
31
32 #include "adt/pmap.h"
33 #include "irnode_t.h"
34 #include "irgraph_t.h"
35 #include "irprog_t.h"
36 #include "irmemory_t.h"
37 #include "irmemory.h"
38 #include "irflag.h"
39 #include "hashptr.h"
40 #include "irflag.h"
41 #include "irouts.h"
42 #include "irgwalk.h"
43 #include "irprintf.h"
44 #include "debug.h"
45 #include "error.h"
46 #include "typerep.h"
47 #include "irpass.h"
48
49 /** The debug handle. */
50 DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
51 DEBUG_ONLY(static firm_dbg_module_t *dbgcall = NULL;)
52
53 /** The source language specific language disambiguator function. */
54 static DISAMBIGUATOR_FUNC language_disambuigator = NULL;
55
56 /** The global memory disambiguator options. */
57 static unsigned global_mem_disamgig_opt = aa_opt_no_opt;
58
59 /* Returns a human readable name for an alias relation. */
60 const char *get_ir_alias_relation_name(ir_alias_relation rel)
61 {
62 #define X(a) case a: return #a
63         switch (rel) {
64         X(ir_no_alias);
65         X(ir_may_alias);
66         X(ir_sure_alias);
67         default: assert(0); return "UNKNOWN";
68         }
69 #undef X
70 }
71
72 /* Get the memory disambiguator options for a graph. */
73 unsigned get_irg_memory_disambiguator_options(const ir_graph *irg)
74 {
75         unsigned opt = irg->mem_disambig_opt;
76         if (opt & aa_opt_inherited)
77                 return global_mem_disamgig_opt;
78         return opt;
79 }  /* get_irg_memory_disambiguator_options */
80
81 /*  Set the memory disambiguator options for a graph. */
82 void set_irg_memory_disambiguator_options(ir_graph *irg, unsigned options)
83 {
84         irg->mem_disambig_opt = options & ~aa_opt_inherited;
85 }  /* set_irg_memory_disambiguator_options */
86
87 /* Set the global disambiguator options for all graphs not having local options. */
88 void set_irp_memory_disambiguator_options(unsigned options)
89 {
90         global_mem_disamgig_opt = options;
91 }  /* set_irp_memory_disambiguator_options */
92
93 /**
94  * Find the base address and entity of an Sel node.
95  *
96  * @param sel  the node
97  * @param pEnt after return points to the base entity.
98  *
99  * @return the base address.
100  */
101 static ir_node *find_base_adr(const ir_node *sel, ir_entity **pEnt)
102 {
103         ir_node *ptr = get_Sel_ptr(sel);
104
105         while (is_Sel(ptr)) {
106                 sel = ptr;
107                 ptr = get_Sel_ptr(sel);
108         }
109         *pEnt = get_Sel_entity(sel);
110         return ptr;
111 }  /* find_base_adr */
112
113 /**
114  * Check if a given Const node is greater or equal a given size.
115  *
116  * @param cns   a Const node
117  * @param size  a integer size
118  *
119  * @return ir_no_alias if the Const is greater, ir_may_alias else
120  */
121 static ir_alias_relation check_const(const ir_node *cns, int size)
122 {
123         tarval *tv = get_Const_tarval(cns);
124         tarval *tv_size;
125
126         if (size == 0)
127                 return tarval_is_null(tv) ? ir_may_alias : ir_no_alias;
128         tv_size = new_tarval_from_long(size, get_tarval_mode(tv));
129         return tarval_cmp(tv_size, tv) & (pn_Cmp_Eq|pn_Cmp_Lt) ? ir_no_alias : ir_may_alias;
130 }  /* check_const */
131
132 /**
133  * Treat idx1 and idx2 as integer indexes and check if they differ always more than size.
134  *
135  * @param idx1  a node representing the first index
136  * @param idx2  a node representing the second index
137  * @param size  an integer size
138  *
139  * @return ir_sure_alias iff idx1 == idx2
140  *         ir_no_alias iff they ALWAYS differ more than size
141  *         ir_may_alias else
142  */
143 static ir_alias_relation different_index(const ir_node *idx1, const ir_node *idx2, int size)
144 {
145         if (idx1 == idx2)
146                 return ir_sure_alias;
147         if (is_Const(idx1) && is_Const(idx2)) {
148                 /* both are const, we can compare them */
149                 tarval *tv1 = get_Const_tarval(idx1);
150                 tarval *tv2 = get_Const_tarval(idx2);
151                 tarval *tv, *tv_size;
152                 ir_mode *m1, *m2;
153
154                 if (size == 0)
155                         return tv1 == tv2 ? ir_sure_alias : ir_no_alias;
156
157                 /* arg, modes may be different */
158                 m1 = get_tarval_mode(tv1);
159                 m2 = get_tarval_mode(tv2);
160                 if (m1 != m2) {
161                         int size = get_mode_size_bits(m1) - get_mode_size_bits(m2);
162
163                         if (size < 0) {
164                                 /* m1 is a small mode, cast up */
165                                 m1 = mode_is_signed(m1) ? find_signed_mode(m2) : find_unsigned_mode(m2);
166                                 if (m1 == NULL) {
167                                         /* should NOT happen, but if it does we give up here */
168                                         return ir_may_alias;
169                                 }
170                                 tv1 = tarval_convert_to(tv1, m1);
171                         } else if (size > 0) {
172                                 /* m2 is a small mode, cast up */
173                                 m2 = mode_is_signed(m2) ? find_signed_mode(m1) : find_unsigned_mode(m1);
174                                 if (m2 == NULL) {
175                                         /* should NOT happen, but if it does we give up here */
176                                         return ir_may_alias;
177                                 }
178                                 tv2 = tarval_convert_to(tv2, m2);
179                         }
180                         /* here the size should be identical, check for signed */
181                         if (get_mode_sign(m1) != get_mode_sign(m2)) {
182                                 /* find the signed */
183                                 if (mode_is_signed(m2)) {
184                                         tarval *t = tv1;
185                                         ir_mode *tm = m1;
186                                         tv1 = tv2; m1 = m2;
187                                         tv2 = t;   m2 = tm;
188                                 }
189
190                                 /* m1 is now the signed one */
191                                 if (tarval_cmp(tv1, get_mode_null(m1)) & (pn_Cmp_Eq|pn_Cmp_Gt)) {
192                                         /* tv1 is signed, but >= 0, simply cast into unsigned */
193                                         tv1 = tarval_convert_to(tv1, m2);
194                                 } else {
195                                         tv_size = new_tarval_from_long(size, m2);
196
197                                         if (tarval_cmp(tv2, tv_size) & (pn_Cmp_Eq|pn_Cmp_Gt)) {
198                                                 /* tv1 is negative and tv2 >= tv_size, so the difference is bigger than size */
199                                                 return ir_no_alias;
200                                         }
201                                         /* tv_size > tv2, so we can subtract without overflow */
202                                         tv2 = tarval_sub(tv_size, tv2, NULL);
203
204                                         /* tv1 is < 0, so we can negate it */
205                                         tv1 = tarval_neg(tv1);
206
207                                         /* cast it into unsigned. for two-complement it does the right thing for MIN_INT */
208                                         tv1 = tarval_convert_to(tv1, m2);
209
210                                         /* now we can compare without overflow */
211                                         return tarval_cmp(tv1, tv2) & (pn_Cmp_Eq|pn_Cmp_Gt) ? ir_no_alias : ir_may_alias;
212                                 }
213                         }
214                 }
215                 if (tarval_cmp(tv1, tv2) == pn_Cmp_Gt) {
216                         tarval *t = tv1;
217                         tv1 = tv2;
218                         tv2 = t;
219                 }
220                 /* tv1 is now the "smaller" one */
221                 tv      = tarval_sub(tv2, tv1, NULL);
222                 tv_size = new_tarval_from_long(size, get_tarval_mode(tv));
223                 return tarval_cmp(tv_size, tv) & (pn_Cmp_Eq|pn_Cmp_Lt) ? ir_no_alias : ir_may_alias;
224         }
225
226         /* Note: we rely here on the fact that normalization puts constants on the RIGHT side */
227         if (is_Add(idx1)) {
228                 ir_node *l1 = get_Add_left(idx1);
229                 ir_node *r1 = get_Add_right(idx1);
230
231                 if (l1 == idx2) {
232                         /* x + c == y */
233                         if (is_Const(r1))
234                                 return check_const(r1, size);
235                 }
236                 if (is_Add(idx2)) {
237                         /* both are Adds, check if they are of x + a == x + b kind */
238                         ir_node *l2 = get_Add_left(idx2);
239                         ir_node *r2 = get_Add_right(idx2);
240
241                         if (l1 == l2)
242                                 return different_index(r1, r2, size);
243                         else if (l1 == r2)
244                                 return different_index(r1, l2, size);
245                         else if (r1 == r2)
246                                 return different_index(l1, l2, size);
247                         else if (r1 == l2)
248                                 return different_index(l1, r2, size);
249                 }
250         }
251         if (is_Add(idx2)) {
252                 ir_node *l2 = get_Add_left(idx2);
253                 ir_node *r2 = get_Add_right(idx2);
254
255                 if (l2 == idx1) {
256                         /* x + c == y */
257                         if (is_Const(r2))
258                                 return check_const(r2, size);
259                 }
260         }
261
262         if (is_Sub(idx1)) {
263                 ir_node *l1 = get_Sub_left(idx1);
264                 ir_node *r1 = get_Sub_right(idx1);
265
266                 if (l1 == idx2) {
267                         /* x - c == y */
268                         if (is_Const(r1))
269                                 return check_const(r1, size);
270                 }
271
272                 if (is_Sub(idx2)) {
273                         /* both are Subs, check if they are of x - a == x - b kind */
274                         ir_node *l2 = get_Sub_left(idx2);
275
276                         if (l1 == l2) {
277                                 ir_node *r2 = get_Sub_right(idx2);
278                                 return different_index(r1, r2, size);
279                         }
280                 }
281         }
282         if (is_Sub(idx2)) {
283                 ir_node *l2 = get_Sub_left(idx2);
284                 ir_node *r2 = get_Sub_right(idx2);
285
286                 if (l2 == idx1) {
287                         /* x - c == y */
288                         if (is_Const(r2))
289                                 return check_const(r2, size);
290                 }
291
292         }
293         return ir_may_alias;
294 }  /* different_index */
295
296 /**
297  * Two Sel addresses have the same base address, check if there offsets are
298  * different.
299  *
300  * @param adr1  The first address.
301  * @param adr2  The second address.
302  */
303 static ir_alias_relation different_sel_offsets(const ir_node *sel1, const ir_node *sel2)
304 {
305         /* seems to be broken */
306         (void) sel1;
307         (void) sel2;
308 #if 0
309         ir_entity *ent1 = get_Sel_entity(sel1);
310         ir_entity *ent2 = get_Sel_entity(sel2);
311         int i, check_arr = 0;
312
313         if (ent1 == ent2)
314                 check_arr = 1;
315         else {
316                 ir_type *tp1 = get_entity_type(ent1);
317                 ir_type *tp2 = get_entity_type(ent2);
318
319                 if (tp1 == tp2)
320                         check_arr = 1;
321                 else if (get_type_state(tp1) == layout_fixed && get_type_state(tp2) == layout_fixed &&
322                          get_type_size_bits(tp1) == get_type_size_bits(tp2))
323                         check_arr = 1;
324         }
325         if (check_arr) {
326                 /* we select an entity of same size, check for indexes */
327                 int n = get_Sel_n_indexs(sel1);
328                 int have_no = 0;
329
330                 if (n > 0 && n == get_Sel_n_indexs(sel2)) {
331                         /* same non-zero number of indexes, an array access, check */
332                         for (i = 0; i < n; ++i) {
333                                 ir_node *idx1 = get_Sel_index(sel1, i);
334                                 ir_node *idx2 = get_Sel_index(sel2, i);
335                                 ir_alias_relation res = different_index(idx1, idx2, 0); /* we can safely IGNORE the size here if it's at least >0 */
336
337                                 if (res == may_alias)
338                                         return may_alias;
339                                 else if (res == no_alias)
340                                         have_no = 1;
341                         }
342                         /* if we have at least one no_alias, there is no alias relation, else we have sure */
343                         return have_no > 0 ? no_alias : sure_alias;
344                 }
345         }
346 #else
347         (void) different_index;
348 #endif
349         return ir_may_alias;
350 }  /* different_sel_offsets */
351
352 /**
353  * Determine the alias relation by checking if adr1 and adr2 are pointer
354  * to different type.
355  *
356  * @param adr1    The first address.
357  * @param adr2    The second address.
358  */
359 static ir_alias_relation different_types(const ir_node *adr1, const ir_node *adr2)
360 {
361         ir_entity *ent1 = NULL, *ent2 = NULL;
362
363         if (is_Global(adr1))
364                 ent1 = get_Global_entity(adr1);
365         else if (is_Sel(adr1))
366                 ent1 = get_Sel_entity(adr1);
367
368         if (is_Global(adr2))
369                 ent2 = get_Global_entity(adr2);
370         else if (is_Sel(adr2))
371                 ent2 = get_Sel_entity(adr2);
372
373         if (ent1 != NULL && ent2 != NULL) {
374                 ir_type *tp1 = get_entity_type(ent1);
375                 ir_type *tp2 = get_entity_type(ent2);
376
377                 if (tp1 != tp2) {
378                         /* do deref until no pointer types are found */
379                         while (is_Pointer_type(tp1) && is_Pointer_type(tp2)) {
380                                 tp1 = get_pointer_points_to_type(tp1);
381                                 tp2 = get_pointer_points_to_type(tp2);
382                         }
383
384                         if (get_type_tpop(tp1) != get_type_tpop(tp2)) {
385                                 /* different type structure */
386                                 return ir_no_alias;
387                         }
388                         if (is_Class_type(tp1)) {
389                                 /* check class hierarchy */
390                                 if (! is_SubClass_of(tp1, tp2) &&
391                                         ! is_SubClass_of(tp2, tp1))
392                                         return ir_no_alias;
393                         } else {
394                                 /* different types */
395                                 return ir_no_alias;
396                         }
397                 }
398         }
399         return ir_may_alias;
400 }  /* different_types */
401
402 /**
403  * Returns non-zero if a node is a result on a malloc-like routine.
404  *
405  * @param node  the Proj node to test
406  */
407 static int is_malloc_Result(const ir_node *node)
408 {
409         node = get_Proj_pred(node);
410         if (! is_Proj(node))
411                 return 0;
412         node = get_Proj_pred(node);
413         if (! is_Call(node))
414                 return 0;
415         node = get_Call_ptr(node);
416         if (is_Global(node)) {
417                 ir_entity *ent = get_Global_entity(node);
418
419                 if (get_entity_additional_properties(ent) & mtp_property_malloc)
420                         return 1;
421                 return 0;
422         }
423         return 0;
424 }  /* is_malloc_Result */
425
426 /**
427  * Classify a base pointer.
428  *
429  * @param irg  the graph of the pointer
430  * @param irn  the node representing the base address
431  * @param ent  the base entity of the base address iff any
432  */
433 ir_storage_class_class_t classify_pointer(const ir_graph *irg, const ir_node *irn, const ir_entity *ent)
434 {
435         ir_storage_class_class_t res = ir_sc_pointer;
436         if (is_Global(irn)) {
437                 ir_entity *entity = get_Global_entity(irn);
438                 res = ir_sc_globalvar;
439                 if (! (get_entity_usage(entity) & ir_usage_address_taken))
440                         res |= ir_sc_modifier_nottaken;
441         } else if (irn == get_irg_frame(irg)) {
442                 res = ir_sc_localvar;
443                 if (ent != NULL && !(get_entity_usage(ent) & ir_usage_address_taken))
444                         res |= ir_sc_modifier_nottaken;
445         } else if (irn == get_irg_tls(irg)) {
446                 res = ir_sc_tls;
447                 if (ent != NULL && !(get_entity_usage(ent) & ir_usage_address_taken))
448                         res |= ir_sc_modifier_nottaken;
449         } else if (is_Proj(irn) && is_malloc_Result(irn)) {
450                 return ir_sc_malloced;
451         } else if (is_Const(irn)) {
452                 return ir_sc_globaladdr;
453         } else if (is_arg_Proj(irn)) {
454                 res |= ir_sc_modifier_argument;
455         }
456
457         return res;
458 }
459
460 /**
461  * If adr represents a Bitfield Sel, skip it
462  */
463 static const ir_node *skip_Bitfield_Sels(const ir_node *adr)
464 {
465         if (is_Sel(adr)) {
466                 ir_entity *ent     = get_Sel_entity(adr);
467                 ir_type   *bf_type = get_entity_type(ent);
468
469                 /* is it a bitfield type? */
470                 if (is_Primitive_type(bf_type) && get_primitive_base_type(bf_type) != NULL)
471                         adr = get_Sel_ptr(adr);
472         }
473         return adr;
474 }
475
476 /**
477  * Determine the alias relation between two addresses.
478  *
479  * @param irg    the graph of both memory operations
480  * @param addr1  pointer address of the first memory operation
481  * @param mode1  the mode of the accessed data through addr1
482  * @param addr2  pointer address of the second memory operation
483  * @param mode2  the mode of the accessed data through addr2
484  *
485  * @return found memory relation
486  */
487 static ir_alias_relation _get_alias_relation(
488         const ir_graph *irg,
489         const ir_node *adr1, const ir_mode *mode1,
490         const ir_node *adr2, const ir_mode *mode2)
491 {
492         ir_entity             *ent1, *ent2;
493         unsigned              options;
494         long                  offset1 = 0;
495         long                  offset2 = 0;
496         const ir_node         *base1;
497         const ir_node         *base2;
498         const ir_node         *orig_adr1 = adr1;
499         const ir_node         *orig_adr2 = adr2;
500         unsigned              mode_size;
501         ir_storage_class_class_t class1, class2, mod1, mod2;
502         int                   have_const_offsets;
503
504         if (! get_opt_alias_analysis())
505                 return ir_may_alias;
506
507         if (adr1 == adr2)
508                 return ir_sure_alias;
509
510         options = get_irg_memory_disambiguator_options(irg);
511
512         /* The Armageddon switch */
513         if (options & aa_opt_no_alias)
514                 return ir_no_alias;
515
516         /* do the addresses have constants offsets?
517          *  Note: nodes are normalized to have constants at right inputs,
518          *        sub X, C is normalized to add X, -C
519          */
520         have_const_offsets = 1;
521         while (is_Add(adr1)) {
522                 ir_node *add_right = get_Add_right(adr1);
523                 if (is_Const(add_right) && !mode_is_reference(get_irn_mode(add_right))) {
524                         tarval *tv  = get_Const_tarval(add_right);
525                         offset1    += get_tarval_long(tv);
526                         adr1        = get_Add_left(adr1);
527                 } else if (mode_is_reference(get_irn_mode(add_right))) {
528                         adr1 = add_right;
529                         have_const_offsets = 0;
530                 } else {
531                         adr1 = get_Add_left(adr1);
532                         have_const_offsets = 0;
533                 }
534         }
535         while (is_Add(adr2)) {
536                 ir_node *add_right = get_Add_right(adr2);
537                 if (is_Const(add_right) && !mode_is_reference(get_irn_mode(add_right))) {
538                         tarval *tv  = get_Const_tarval(add_right);
539                         offset2    += get_tarval_long(tv);
540                         adr2        = get_Add_left(adr2);
541                 } else if (mode_is_reference(get_irn_mode(add_right))) {
542                         adr2 = add_right;
543                         have_const_offsets = 0;
544                 } else {
545                         adr2 = get_Add_left(adr2);
546                         have_const_offsets = 0;
547                 }
548         }
549
550         mode_size = get_mode_size_bytes(mode1);
551         if (get_mode_size_bytes(mode2) > mode_size) {
552                 mode_size = get_mode_size_bytes(mode2);
553         }
554
555         /* same base address -> compare offsets if possible.
556          * FIXME: type long is not sufficient for this task ...
557          */
558         if (adr1 == adr2 && have_const_offsets) {
559                 if ((unsigned long)labs(offset2 - offset1) >= mode_size)
560                         return ir_no_alias;
561                 else
562                         return ir_sure_alias;
563         }
564
565         /*
566          * Bitfields can be constructed as Sels from its base address.
567          * As they have different entities, the disambiguator would find that they are
568          * alias free. While this is true for it's values, it is false for the addresses
569          * (strictly speaking, the Sel's are NOT the addresses of the bitfields).
570          * So, skip those bitfield selecting Sel's.
571          */
572         adr1 = skip_Bitfield_Sels(adr1);
573         adr2 = skip_Bitfield_Sels(adr2);
574
575         /* skip Sels */
576         base1 = adr1;
577         base2 = adr2;
578         ent1  = NULL;
579         ent2  = NULL;
580         if (is_Sel(adr1)) {
581                 base1 = find_base_adr(adr1, &ent1);
582         }
583         if (is_Sel(adr2)) {
584                 base2 = find_base_adr(adr2, &ent2);
585         }
586
587         /* same base address -> compare Sel entities */
588         if (base1 == base2 && ent1 != NULL && ent2 != NULL) {
589                 if (ent1 != ent2)
590                         return ir_no_alias;
591                 else if (have_const_offsets)
592                         return different_sel_offsets(adr1, adr2);
593         }
594
595         mod1 = classify_pointer(irg, base1, ent1);
596         mod2 = classify_pointer(irg, base2, ent2);
597
598         class1 = GET_BASE_SC(mod1);
599         class2 = GET_BASE_SC(mod2);
600
601         if (class1 == ir_sc_pointer || class2 == ir_sc_pointer) {
602                 /* swap pointer class to class1 */
603                 if (class2 == ir_sc_pointer) {
604                         ir_storage_class_class_t temp = mod1;
605                         mod1 = mod2;
606                         mod2 = temp;
607                         class1 = GET_BASE_SC(mod1);
608                         class2 = GET_BASE_SC(mod2);
609                 }
610                 /* a pointer and an object whose address was never taken */
611                 if (mod2 & ir_sc_modifier_nottaken) {
612                         return ir_no_alias;
613                 }
614                 if (mod1 & ir_sc_modifier_argument) {
615                         if ( (options & aa_opt_no_alias_args)
616                                         && (mod2 & ir_sc_modifier_argument))
617                                 return ir_no_alias;
618                         if ( (options & aa_opt_no_alias_args_global)
619                                         && (class2 == ir_sc_globalvar
620                                                 || class2 == ir_sc_tls
621                                                 || class2 == ir_sc_globaladdr))
622                                 return ir_no_alias;
623                 }
624         } else if (class1 != class2) {
625                 /* two objects from different memory spaces */
626                 return ir_no_alias;
627         } else {
628                 /* both classes are equal */
629                 if (class1 == ir_sc_globalvar) {
630                         ir_entity *entity1 = get_SymConst_entity(base1);
631                         ir_entity *entity2 = get_SymConst_entity(base2);
632                         if (entity1 != entity2)
633                                 return ir_no_alias;
634
635                         /* for some reason CSE didn't happen yet for the 2 SymConsts... */
636                         return ir_may_alias;
637                 } else if (class1 == ir_sc_globaladdr) {
638                         tarval *tv  = get_Const_tarval(base1);
639                         offset1    += get_tarval_long(tv);
640                         tv          = get_Const_tarval(base2);
641                         offset2    += get_tarval_long(tv);
642
643                         if ((unsigned long)labs(offset2 - offset1) >= mode_size)
644                                 return ir_no_alias;
645                         else
646                                 return ir_sure_alias;
647                 }
648         }
649
650         /* Type based alias analysis */
651         if (options & aa_opt_type_based) {
652                 ir_alias_relation rel;
653
654                 if (options & aa_opt_byte_type_may_alias) {
655                         if (get_mode_size_bits(mode1) == 8 || get_mode_size_bits(mode2) == 8) {
656                                 /* One of the modes address a byte. Assume a ir_may_alias and leave
657                                    the type based check. */
658                                 goto leave_type_based_alias;
659                         }
660                 }
661                 /* cheap check: If the mode sizes did not match, the types MUST be different */
662                 if (get_mode_size_bits(mode1) != get_mode_size_bits(mode2))
663                         return ir_no_alias;
664
665                 /* cheap test: if only one is a reference mode, no alias */
666                 if (mode_is_reference(mode1) != mode_is_reference(mode2))
667                         return ir_no_alias;
668
669                 /* cheap test: if arithmetic is different, no alias */
670                 if (get_mode_arithmetic(mode1) != get_mode_arithmetic(mode2))
671                         return ir_no_alias;
672
673                 /* try rule R5 */
674                 rel = different_types(orig_adr1, orig_adr2);
675                 if (rel != ir_may_alias)
676                         return rel;
677 leave_type_based_alias:;
678         }
679
680         /* do we have a language specific memory disambiguator? */
681         if (language_disambuigator != NULL) {
682                 ir_alias_relation rel = language_disambuigator(irg, orig_adr1, mode1, orig_adr2, mode2);
683                 if (rel != ir_may_alias)
684                         return rel;
685         }
686
687         /* access points-to information here */
688         return ir_may_alias;
689 }  /* _get_alias_relation */
690
691 /*
692  * Determine the alias relation between two addresses.
693  */
694 ir_alias_relation get_alias_relation(
695         const ir_graph *irg,
696         const ir_node *adr1, const ir_mode *mode1,
697         const ir_node *adr2, const ir_mode *mode2)
698 {
699         ir_alias_relation rel = _get_alias_relation(irg, adr1, mode1, adr2, mode2);
700         DB((dbg, LEVEL_1, "alias(%+F, %+F) = %s\n", adr1, adr2, get_ir_alias_relation_name(rel)));
701         return rel;
702 }  /* get_alias_relation */
703
704 /* Set a source language specific memory disambiguator function. */
705 void set_language_memory_disambiguator(DISAMBIGUATOR_FUNC func)
706 {
707         language_disambuigator = func;
708 }  /* set_language_memory_disambiguator */
709
710 /** The result cache for the memory disambiguator. */
711 static set *result_cache = NULL;
712
713 /** An entry in the relation cache. */
714 typedef struct mem_disambig_entry {
715         const ir_node     *adr1;    /**< The first address. */
716         const ir_mode     *mode1;   /**< The first address mode. */
717         const ir_node     *adr2;    /**< The second address. */
718         const ir_mode     *mode2;   /**< The second address mode. */
719         ir_alias_relation result;   /**< The alias relation result. */
720 } mem_disambig_entry;
721
722 #define HASH_ENTRY(adr1, adr2)  (HASH_PTR(adr1) ^ HASH_PTR(adr2))
723
724 /**
725  * Compare two relation cache entries.
726  */
727 static int cmp_mem_disambig_entry(const void *elt, const void *key, size_t size)
728 {
729         const mem_disambig_entry *p1 = elt;
730         const mem_disambig_entry *p2 = key;
731         (void) size;
732
733         return p1->adr1 == p2->adr1 && p1->adr2 == p2->adr2 &&
734                p1->mode1 == p2->mode1 && p1->mode2 == p2->mode2;
735 }  /* cmp_mem_disambig_entry */
736
737 /**
738  * Initialize the relation cache.
739  */
740 void mem_disambig_init(void)
741 {
742         result_cache = new_set(cmp_mem_disambig_entry, 8);
743 }  /* mem_disambig_init */
744
745 /*
746  * Determine the alias relation between two addresses.
747  */
748 ir_alias_relation get_alias_relation_ex(
749         const ir_graph *irg,
750         const ir_node *adr1, const ir_mode *mode1,
751         const ir_node *adr2, const ir_mode *mode2)
752 {
753         mem_disambig_entry key, *entry;
754
755         ir_fprintf(stderr, "%+F <-> %+F\n", adr1, adr2);
756
757         if (! get_opt_alias_analysis())
758                 return ir_may_alias;
759
760         if (get_irn_opcode(adr1) > get_irn_opcode(adr2)) {
761                 const ir_node *t = adr1;
762                 adr1 = adr2;
763                 adr2 = t;
764         }
765
766         key.adr1  = adr1;
767         key.adr2  = adr2;
768         key.mode1 = mode1;
769         key.mode2 = mode2;
770         entry = set_find(result_cache, &key, sizeof(key), HASH_ENTRY(adr1, adr2));
771         if (entry != NULL)
772                 return entry->result;
773
774         key.result = get_alias_relation(irg, adr1, mode1, adr2, mode2);
775
776         set_insert(result_cache, &key, sizeof(key), HASH_ENTRY(adr1, adr2));
777         return key.result;
778 }  /* get_alias_relation_ex */
779
780 /* Free the relation cache. */
781 void mem_disambig_term(void)
782 {
783         if (result_cache != NULL) {
784                 del_set(result_cache);
785                 result_cache = NULL;
786         }
787 }  /* mem_disambig_term */
788
789 /**
790  * Check the mode of a Load/Store with the mode of the entity
791  * that is accessed.
792  * If the mode of the entity and the Load/Store mode do not match, we
793  * have the bad reinterpret case:
794  *
795  * int i;
796  * char b = *(char *)&i;
797  *
798  * We do NOT count this as one value and return address_taken
799  * in that case.
800  * However, we support an often used case. If the mode is two-complement
801  * we allow casts between signed/unsigned.
802  *
803  * @param mode     the mode of the Load/Store
804  * @param ent_mode the mode of the accessed entity
805  *
806  * @return non-zero if the Load/Store is a hidden cast, zero else
807  */
808 static int is_hidden_cast(const ir_mode *mode, const ir_mode *ent_mode)
809 {
810         if (ent_mode == NULL)
811                 return false;
812
813         if (ent_mode != mode) {
814                 if (ent_mode == NULL ||
815                         get_mode_size_bits(ent_mode) != get_mode_size_bits(mode) ||
816                         get_mode_sort(ent_mode) != get_mode_sort(mode) ||
817                         get_mode_arithmetic(ent_mode) != irma_twos_complement ||
818                         get_mode_arithmetic(mode) != irma_twos_complement)
819                         return true;
820         }
821         return false;
822 }  /* is_hidden_cast */
823
824 /**
825  * Determine the usage state of a node (or its successor Sels).
826  *
827  * @param irn  the node
828  */
829 static ir_entity_usage determine_entity_usage(const ir_node *irn, ir_entity *entity)
830 {
831         int       i;
832         ir_mode   *emode, *mode;
833         ir_node   *value;
834         ir_type   *tp;
835         ir_entity_usage res = 0;
836
837         for (i = get_irn_n_outs(irn) - 1; i >= 0; --i) {
838                 ir_node *succ = get_irn_out(irn, i);
839
840                 switch (get_irn_opcode(succ)) {
841                 case iro_Load:
842                         /* beware: irn might be a Id node here, so irn might be not
843                            equal to get_Load_ptr(succ) */
844                         res |= ir_usage_read;
845
846                         /* check if this load is not a hidden conversion */
847                         mode  = get_Load_mode(succ);
848                         emode = get_type_mode(get_entity_type(entity));
849                         if (is_hidden_cast(mode, emode))
850                                 res |= ir_usage_reinterpret_cast;
851                         break;
852
853                 case iro_Store:
854                         /* check that the node is not the Store's value */
855                         if (irn == get_Store_value(succ)) {
856                                 res |= ir_usage_unknown;
857                         }
858                         if (irn == get_Store_ptr(succ)) {
859                                 res |= ir_usage_write;
860
861                                 /* check if this Store is not a hidden conversion */
862                                 value = get_Store_value(succ);
863                                 mode  = get_irn_mode(value);
864                                 emode = get_type_mode(get_entity_type(entity));
865                                 if (is_hidden_cast(mode, emode))
866                                         res |= ir_usage_reinterpret_cast;
867                         }
868                         assert(irn != get_Store_mem(succ));
869                         break;
870
871                 case iro_CopyB:
872                         /* CopyB are like Loads/Stores */
873                         tp  = get_entity_type(entity);
874                         if (tp != get_CopyB_type(succ)) {
875                                 /* bad, different types, might be a hidden conversion */
876                                 res |= ir_usage_reinterpret_cast;
877                         }
878                         if (irn == get_CopyB_dst(succ)) {
879                                 res |= ir_usage_write;
880                         } else {
881                                 assert(irn == get_CopyB_src(succ));
882                                 res |= ir_usage_read;
883                         }
884                         break;
885
886                 case iro_Add:
887                 case iro_Sub:
888                         /* Check the successor of irn. */
889                         res |= determine_entity_usage(succ, entity);
890                         break;
891                 case iro_Sel: {
892                         ir_entity *entity = get_Sel_entity(succ);
893                         /* this analysis can't handle unions correctly */
894                         if (is_Union_type(get_entity_owner(entity))) {
895                                 res |= ir_usage_unknown;
896                                 break;
897                         }
898                         /* Check the successor of irn. */
899                         res |= determine_entity_usage(succ, entity);
900                         break;
901                 }
902
903                 case iro_Call:
904                         if (irn == get_Call_ptr(succ)) {
905                                 /* TODO: we could check for reinterpret casts here...
906                                  * But I doubt anyone is interested in that bit for
907                                  * function entities and I'm too lazy to write the code now.
908                                  */
909                                 res |= ir_usage_read;
910                         } else {
911                                 assert(irn != get_Call_mem(succ));
912                                 res |= ir_usage_unknown;
913                         }
914                         break;
915
916                 /* skip identities */
917                 case iro_Id:
918                         res |= determine_entity_usage(succ, entity);
919                         break;
920
921                 /* skip tuples */
922                 case iro_Tuple: {
923                         int input_nr;
924                         for (input_nr = get_Tuple_n_preds(succ) - 1; input_nr >= 0;
925                                         --input_nr) {
926                                 ir_node *pred = get_Tuple_pred(succ, input_nr);
927                                 if (pred == irn) {
928                                         int k;
929                                         /* we found one input */
930                                         for (k = get_irn_n_outs(succ) - 1; k >= 0; --k) {
931                                                 ir_node *proj = get_irn_out(succ, k);
932
933                                                 if (is_Proj(proj) && get_Proj_proj(proj) == input_nr) {
934                                                         res |= determine_entity_usage(proj, entity);
935                                                         break;
936                                                 }
937                                         }
938                                 }
939                         }
940                         break;
941                 }
942
943                 default:
944                         /* another op, we don't know anything (we could do more advanced
945                          * things like a dataflow analysis here) */
946                         res |= ir_usage_unknown;
947                         break;
948                 }
949         }
950
951         return res;
952 }
953
954 /**
955  * Update the usage flags of all frame entities.
956  */
957 static void analyse_irg_entity_usage(ir_graph *irg)
958 {
959         ir_type *ft = get_irg_frame_type(irg);
960         ir_node *irg_frame;
961         int i, j, k, static_link_arg;
962
963         /* set initial state to not_taken, as this is the "smallest" state */
964         for (i = get_class_n_members(ft) - 1; i >= 0; --i) {
965                 ir_entity *ent = get_class_member(ft, i);
966
967                 /* methods can only be analyzed globally */
968                 if (! is_method_entity(ent)) {
969                         ir_entity_usage flags = 0;
970                         if (get_entity_linkage(ent) & IR_LINKAGE_HIDDEN_USER)
971                                 flags = ir_usage_unknown;
972                         set_entity_usage(ent, flags);
973                 }
974         }
975
976         assure_irg_outs(irg);
977
978         irg_frame = get_irg_frame(irg);
979
980         for (i = get_irn_n_outs(irg_frame) - 1; i >= 0; --i) {
981                 ir_node        *succ = get_irn_out(irg_frame, i);
982                 ir_entity      *entity;
983                 ir_entity_usage flags;
984
985                 if (!is_Sel(succ))
986                         continue;
987
988                 entity = get_Sel_entity(succ);
989                 flags  = get_entity_usage(entity);
990                 flags |= determine_entity_usage(succ, entity);
991                 set_entity_usage(entity, flags);
992         }
993
994         /* check inner functions accessing outer frame */
995         static_link_arg = 0;
996         for (i = get_class_n_members(ft) - 1; i >= 0; --i) {
997                 ir_entity *ent = get_class_member(ft, i);
998                 ir_graph  *inner_irg;
999                 ir_node   *args;
1000
1001                 if (! is_method_entity(ent))
1002                         continue;
1003
1004                 inner_irg = get_entity_irg(ent);
1005                 if (inner_irg == NULL)
1006                         continue;
1007
1008                 assure_irg_outs(inner_irg);
1009                 args = get_irg_args(inner_irg);
1010                 for (j = get_irn_n_outs(args) - 1; j >= 0; --j) {
1011                         ir_node *arg = get_irn_out(args, j);
1012
1013                         if (get_Proj_proj(arg) == static_link_arg) {
1014                                 for (k = get_irn_n_outs(arg) - 1; k >= 0; --k) {
1015                                         ir_node *succ = get_irn_out(arg, k);
1016
1017                                         if (is_Sel(succ)) {
1018                                                 ir_entity *entity = get_Sel_entity(succ);
1019
1020                                                 if (get_entity_owner(entity) == ft) {
1021                                                         /* found an access to the outer frame */
1022                                                         ir_entity_usage flags;
1023
1024                                                         flags  = get_entity_usage(entity);
1025                                                         flags |= determine_entity_usage(succ, entity);
1026                                                         set_entity_usage(entity, flags);
1027                                                 }
1028                                         }
1029                                 }
1030                         }
1031                 }
1032         }
1033
1034
1035         /* now computed */
1036         irg->entity_usage_state = ir_entity_usage_computed;
1037 }
1038
1039 ir_entity_usage_computed_state get_irg_entity_usage_state(const ir_graph *irg)
1040 {
1041         return irg->entity_usage_state;
1042 }
1043
1044 void set_irg_entity_usage_state(ir_graph *irg, ir_entity_usage_computed_state state)
1045 {
1046         irg->entity_usage_state = state;
1047 }
1048
1049 void assure_irg_entity_usage_computed(ir_graph *irg)
1050 {
1051         if (irg->entity_usage_state != ir_entity_usage_not_computed)
1052                 return;
1053
1054         analyse_irg_entity_usage(irg);
1055 }
1056
1057
1058 /**
1059  * Initialize the entity_usage flag for a global type like type.
1060  */
1061 static void init_entity_usage(ir_type *tp)
1062 {
1063         int i;
1064
1065         /* We have to be conservative: All external visible entities are unknown */
1066         for (i = get_compound_n_members(tp) - 1; i >= 0; --i) {
1067                 ir_entity       *ent  = get_compound_member(tp, i);
1068                 ir_entity_usage flags = ir_usage_none;
1069
1070                 if (entity_is_externally_visible(ent)) {
1071                         flags |= ir_usage_unknown;
1072                 }
1073                 set_entity_usage(ent, flags);
1074         }
1075 }
1076
1077 /**
1078  * Mark all entities used in the initializer as unknown usage.
1079  *
1080  * @param initializer  the initializer to check
1081  */
1082 static void check_initializer_nodes(ir_initializer_t *initializer)
1083 {
1084         unsigned i;
1085         ir_node  *n;
1086
1087         switch (initializer->kind) {
1088         case IR_INITIALIZER_CONST:
1089                 /* let's check if it's an address */
1090                 n = initializer->consti.value;
1091                 if (is_Global(n)) {
1092                         ir_entity *ent = get_Global_entity(n);
1093                         set_entity_usage(ent, ir_usage_unknown);
1094                 }
1095                 return;
1096         case IR_INITIALIZER_TARVAL:
1097         case IR_INITIALIZER_NULL:
1098                 return;
1099         case IR_INITIALIZER_COMPOUND:
1100                 for (i = 0; i < initializer->compound.n_initializers; ++i) {
1101                         ir_initializer_t *sub_initializer
1102                                 = initializer->compound.initializers[i];
1103                         check_initializer_nodes(sub_initializer);
1104                 }
1105                 return;
1106         }
1107         panic("invalid initializer found");
1108 }  /* check_initializer_nodes */
1109
1110 /**
1111  * Mark all entities used in the initializer for the given entity as unknown
1112  * usage.
1113  *
1114  * @param ent  the entity
1115  */
1116 static void check_initializer(ir_entity *ent)
1117 {
1118         ir_node *n;
1119         int i;
1120
1121         /* Beware: Methods are always initialized with "themself". This does not
1122          * count as a taken address.
1123          * TODO: this initialisation with "themself" is wrong and should be removed
1124          */
1125         if (is_Method_type(get_entity_type(ent)))
1126                 return;
1127
1128         if (ent->initializer != NULL) {
1129                 check_initializer_nodes(ent->initializer);
1130         } else if (entity_has_compound_ent_values(ent)) {
1131                 for (i = get_compound_ent_n_values(ent) - 1; i >= 0; --i) {
1132                         n = get_compound_ent_value(ent, i);
1133
1134                         /* let's check if it's an address */
1135                         if (is_Global(n)) {
1136                                 ir_entity *ent = get_Global_entity(n);
1137                                 set_entity_usage(ent, ir_usage_unknown);
1138                         }
1139                 }
1140         }
1141 }
1142
1143
1144 /**
1145  * Mark all entities used in initializers as unknown usage.
1146  *
1147  * @param tp  a compound type
1148  */
1149 static void check_initializers(ir_type *tp)
1150 {
1151         int i;
1152
1153         for (i = get_compound_n_members(tp) - 1; i >= 0; --i) {
1154                 ir_entity *ent = get_compound_member(tp, i);
1155
1156                 check_initializer(ent);
1157         }
1158 }  /* check_initializers */
1159
1160 #ifdef DEBUG_libfirm
1161 /**
1162  * Print the entity usage flags of all entities of a given type for debugging.
1163  *
1164  * @param tp  a compound type
1165  */
1166 static void print_entity_usage_flags(ir_type *tp)
1167 {
1168         int i;
1169         for (i = get_compound_n_members(tp) - 1; i >= 0; --i) {
1170                 ir_entity *ent = get_compound_member(tp, i);
1171                 ir_entity_usage flags = get_entity_usage(ent);
1172
1173                 if (flags == 0)
1174                         continue;
1175                 ir_printf("%+F:", ent);
1176                 if (flags & ir_usage_address_taken)
1177                         printf(" address_taken");
1178                 if (flags & ir_usage_read)
1179                         printf(" read");
1180                 if (flags & ir_usage_write)
1181                         printf(" write");
1182                 if (flags & ir_usage_reinterpret_cast)
1183                         printf(" reinterp_cast");
1184                 printf("\n");
1185         }
1186 }
1187 #endif /* DEBUG_libfirm */
1188
1189 /**
1190  * Post-walker: check for global entity address
1191  */
1192 static void check_global_address(ir_node *irn, void *env)
1193 {
1194         ir_node *tls = env;
1195         ir_entity *ent;
1196         ir_entity_usage flags;
1197
1198         if (is_Global(irn)) {
1199                 /* A global. */
1200                 ent = get_Global_entity(irn);
1201         } else if (is_Sel(irn) && get_Sel_ptr(irn) == tls) {
1202                 /* A TLS variable. */
1203                 ent = get_Sel_entity(irn);
1204         } else
1205                 return;
1206
1207         flags = get_entity_usage(ent);
1208         flags |= determine_entity_usage(irn, ent);
1209         set_entity_usage(ent, flags);
1210 }  /* check_global_address */
1211
1212 /**
1213  * Update the entity usage flags of all global entities.
1214  */
1215 static void analyse_irp_globals_entity_usage(void)
1216 {
1217         int i;
1218         ir_segment_t s;
1219
1220         for (s = IR_SEGMENT_FIRST; s <= IR_SEGMENT_LAST; ++s) {
1221                 ir_type *type = get_segment_type(s);
1222                 init_entity_usage(type);
1223         }
1224
1225         for (s = IR_SEGMENT_FIRST; s <= IR_SEGMENT_LAST; ++s) {
1226                 ir_type *type = get_segment_type(s);
1227                 check_initializers(type);
1228         }
1229
1230         for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
1231                 ir_graph *irg = get_irp_irg(i);
1232
1233                 assure_irg_outs(irg);
1234                 irg_walk_graph(irg, NULL, check_global_address, get_irg_tls(irg));
1235         }
1236
1237 #ifdef DEBUG_libfirm
1238         if (firm_dbg_get_mask(dbg) & LEVEL_1) {
1239                 ir_segment_t s;
1240                 for (s = IR_SEGMENT_FIRST; s <= IR_SEGMENT_LAST; ++s) {
1241                         print_entity_usage_flags(get_segment_type(s));
1242                 }
1243         }
1244 #endif /* DEBUG_libfirm */
1245
1246         /* now computed */
1247         irp->globals_entity_usage_state = ir_entity_usage_computed;
1248 }
1249
1250 /* Returns the current address taken state of the globals. */
1251 ir_entity_usage_computed_state get_irp_globals_entity_usage_state(void)
1252 {
1253         return irp->globals_entity_usage_state;
1254 }
1255
1256 /* Sets the current address taken state of the graph. */
1257 void set_irp_globals_entity_usage_state(ir_entity_usage_computed_state state)
1258 {
1259         irp->globals_entity_usage_state = state;
1260 }
1261
1262 /* Assure that the address taken flag is computed for the globals. */
1263 void assure_irp_globals_entity_usage_computed(void)
1264 {
1265         if (irp->globals_entity_usage_state != ir_entity_usage_not_computed)
1266                 return;
1267
1268         analyse_irp_globals_entity_usage();
1269 }
1270
1271 void firm_init_memory_disambiguator(void)
1272 {
1273         FIRM_DBG_REGISTER(dbg, "firm.ana.irmemory");
1274         FIRM_DBG_REGISTER(dbgcall, "firm.opt.cc");
1275 }
1276
1277
1278 /** Maps method types to cloned method types. */
1279 static pmap *mtp_map;
1280
1281 /**
1282  * Clone a method type if not already cloned.
1283  *
1284  * @param tp  the type to clone
1285  */
1286 static ir_type *clone_type_and_cache(ir_type *tp)
1287 {
1288         ir_type *res;
1289         pmap_entry *e = pmap_find(mtp_map, tp);
1290
1291         if (e)
1292                 return e->value;
1293
1294         res = clone_type_method(tp);
1295         pmap_insert(mtp_map, tp, res);
1296
1297         return res;
1298 }  /* clone_type_and_cache */
1299
1300 /**
1301  * Walker: clone all call types of Calls to methods having the
1302  * mtp_property_private property set.
1303  */
1304 static void update_calls_to_private(ir_node *call, void *env)
1305 {
1306         (void) env;
1307         if (is_Call(call)) {
1308                 ir_node *ptr = get_Call_ptr(call);
1309
1310                 if (is_SymConst(ptr)) {
1311                         ir_entity *ent = get_SymConst_entity(ptr);
1312                         ir_type *ctp = get_Call_type(call);
1313
1314                         if (get_entity_additional_properties(ent) & mtp_property_private) {
1315                                 if ((get_method_additional_properties(ctp) & mtp_property_private) == 0) {
1316                                         ctp = clone_type_and_cache(ctp);
1317                                         set_method_additional_property(ctp, mtp_property_private);
1318                                         set_Call_type(call, ctp);
1319                                         DB((dbgcall, LEVEL_1, "changed call to private method %+F using cloned type %+F\n", ent, ctp));
1320                                 }
1321                         }
1322                 }
1323         }
1324 }  /* update_calls_to_private */
1325
1326 /* Mark all private methods, i.e. those of which all call sites are known. */
1327 void mark_private_methods(void)
1328 {
1329         int i;
1330         int changed = 0;
1331
1332         assure_irp_globals_entity_usage_computed();
1333
1334         mtp_map = pmap_create();
1335
1336         /* first step: change the calling conventions of the local non-escaped entities */
1337         for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
1338                 ir_graph        *irg   = get_irp_irg(i);
1339                 ir_entity       *ent   = get_irg_entity(irg);
1340                 ir_entity_usage  flags = get_entity_usage(ent);
1341
1342                 if (!entity_is_externally_visible(ent) &&
1343                     !(flags & ir_usage_address_taken)) {
1344                         ir_type *mtp = get_entity_type(ent);
1345
1346                         set_entity_additional_property(ent, mtp_property_private);
1347                         DB((dbgcall, LEVEL_1, "found private method %+F\n", ent));
1348                         if ((get_method_additional_properties(mtp) & mtp_property_private) == 0) {
1349                                 /* need a new type */
1350                                 mtp = clone_type_and_cache(mtp);
1351                                 set_method_additional_property(mtp, mtp_property_private);
1352                                 set_entity_type(ent, mtp);
1353                                 DB((dbgcall, LEVEL_2, "changed entity type of %+F to %+F\n", ent, mtp));
1354                                 changed = 1;
1355                         }
1356                 }
1357         }
1358
1359         if (changed)
1360                 all_irg_walk(NULL, update_calls_to_private, NULL);
1361
1362         pmap_destroy(mtp_map);
1363 }  /* mark_private_methods */
1364
1365 /* create a pass for mark_private_methods() */
1366 ir_prog_pass_t *mark_private_methods_pass(const char *name)
1367 {
1368         return def_prog_pass(name ? name : "mark_private_methods", mark_private_methods);
1369 }  /* mark_private_methods_pass */