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