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