replaced inline by __inline to allow to be compiled in gcc and msvc modes
[libfirm] / ir / be / beprofile.c
1 /*
2  * Copyright (C) 1995-2007 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       Code instrumentation and execution count profiling.
23  * @author      Adam M. Szalkowski
24  * @date        06.04.2006
25  * @version     $Id$
26  */
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include <math.h>
32
33 #include "hashptr.h"
34 #include "debug.h"
35 #include "obst.h"
36 #include "set.h"
37 #include "list.h"
38 #include "pmap.h"
39
40 #include "irprintf.h"
41 #include "irgwalk.h"
42 #include "irdump_t.h"
43 #include "irnode_t.h"
44 #include "ircons_t.h"
45 #include "irloop_t.h"
46 #include "iredges.h"
47 #include "execfreq.h"
48 #include "irvrfy.h"
49 #include "typerep.h"
50
51 #include "be_t.h"
52 #include "belive_t.h"
53 #include "besched_t.h"
54 #include "beirgmod.h"
55 #include "bearch_t.h"
56 #include "beabi.h"
57 #include "benode_t.h"
58 #include "beutil.h"
59 #include "ircons.h"
60 #include "irhooks.h"
61 #include "iredges.h"
62
63 #include "bechordal_t.h"
64
65 #include "beprofile.h"
66
67 /** An entry in the id-to-location map */
68 typedef struct loc_entry {
69         ir_entity    *fname;   /**< the entity holding the file name */
70         unsigned int lineno;   /**< line number */
71 } loc_entry;
72
73 typedef struct _block_id_walker_data_t {
74         tarval         **array;    /**< the entity the holds the block counts */
75         unsigned int   id;         /**< current block id number */
76         ir_node        *symconst;  /**< the SymConst representing array */
77         pmap           *fname_map; /**< set containing all found filenames */
78         loc_entry      *locs;      /**< locations */
79         ir_type        *tp_char;   /**< the character type */
80         unsigned       flags;      /**< profile flags */
81 } block_id_walker_data_t;
82
83 typedef struct _execcount_t {
84         unsigned int block;
85         unsigned int count;
86 } execcount_t;
87
88 static int
89 cmp_execcount(const void * a, const void * b, size_t size)
90 {
91         return ((execcount_t*)a)->block != ((execcount_t*)b)->block;
92 }
93
94 static void
95 block_counter(ir_node * bb, void * data)
96 {
97         unsigned int  *count = data;
98         *count = *count + 1;
99 }
100
101 static unsigned int
102 count_blocks(ir_graph * irg)
103 {
104         unsigned int count = 0;
105
106         irg_block_walk_graph(irg, block_counter, NULL, &count);
107         return count;
108 }
109
110 /* keep the execcounts here because they are only read once per compiler run */
111 static set * profile = NULL;
112 static hook_entry_t hook;
113
114 /**
115  * Instrument a block with code needed for profiling
116  */
117 static void
118 instrument_block(ir_node * bb, ir_node * address, unsigned int id)
119 {
120         ir_graph *irg = get_irn_irg(bb);
121         ir_node  *start_block = get_irg_start_block(irg);
122         ir_node  *load, *store, *offset, *add, *projm, *proji, *unknown;
123         ir_node  *cnst;
124
125         /**
126          * We can't instrument the start and end block as there are no real
127          * instructions in these blocks
128          */
129         if(bb == start_block || bb == get_irg_end_block(irg))
130                 return;
131
132         unknown = new_r_Unknown(irg, mode_M);
133         cnst    = new_r_Const_long(irg, start_block, mode_Iu, get_mode_size_bytes(mode_Iu) * id);
134         offset  = new_r_Add(irg, bb, address, cnst, mode_P);
135         load    = new_r_Load(irg, bb, unknown, offset, mode_Iu);
136         projm   = new_r_Proj(irg, bb, load, mode_M, pn_Load_M);
137         proji   = new_r_Proj(irg, bb, load, mode_Iu, pn_Load_res);
138         cnst    = new_r_Const_long(irg, start_block, mode_Iu, 1);
139         add     = new_r_Add(irg, bb, proji, cnst, mode_Iu);
140         store   = new_r_Store(irg, bb, projm, offset, add);
141         projm   = new_r_Proj(irg, bb, store, mode_M, pn_Store_M);
142         set_irn_link(bb, projm);
143         set_irn_link(projm, load);
144 }
145
146 typedef struct fix_env {
147         ir_node *start_block;
148         ir_node *end_block;
149 } fix_env;
150
151 /**
152  * SSA Construction for instrumentation code memory
153  */
154 static void
155 fix_ssa(ir_node * bb, void * data)
156 {
157         fix_env *env = data;
158         ir_node *mem;
159         int     arity = get_Block_n_cfgpreds(bb);
160
161         /* start and end block are not instrumented, skip! */
162         if (bb == env->start_block || bb == env->end_block)
163                 return;
164
165         if (arity == 1) {
166                 mem = get_irn_link(get_Block_cfgpred_block(bb, 0));
167         } else {
168                 int n;
169                 ir_node **ins;
170                 ir_graph *irg = current_ir_graph;
171
172                 NEW_ARR_A(ir_node*, ins, arity);
173                 for (n = arity - 1; n >= 0; --n) {
174                         ins[n] = get_irn_link(get_Block_cfgpred_block(bb, n));
175                 }
176                 mem = new_r_Phi(irg, bb, arity, ins, mode_M);
177         }
178         set_Load_mem(get_irn_link(get_irn_link(bb)), mem);
179 }
180
181
182 /**
183  * Generates a new irg which calls the initializer
184  *
185  * Pseudocode:
186  *       void __firmprof_initializer(void) { __init_firmprof(ent_filename, bblock_id, bblock_counts, n_blocks); }
187  */
188 static ir_graph *
189 gen_initializer_irg(ir_entity * ent_filename, ir_entity * bblock_id, ir_entity * bblock_counts, int n_blocks)
190 {
191         ir_node *start_block;
192
193         ir_node   *ins[4];
194         ident     *name = new_id_from_str("__firmprof_initializer");
195         ir_entity *ent  = new_entity(get_glob_type(), name, new_type_method(name, 0, 0));
196         ir_node   *ret, *call, *symconst;
197         symconst_symbol sym;
198
199         ident     *init_name = new_id_from_str("__init_firmprof");
200         ir_type   *init_type = new_type_method(init_name, 4, 0);
201         ir_type   *uint, *uintptr, *string;
202         ir_entity *init_ent;
203         ir_graph  *irg;
204         ir_node   *bb;
205         ir_type   *empty_frame_type;
206
207         set_entity_ld_ident(ent, name);
208
209         uint    = new_type_primitive(new_id_from_str("__uint"), mode_Iu);
210         uintptr = new_type_pointer(new_id_from_str("__uintptr"), uint, mode_P);
211         string  = new_type_pointer(new_id_from_str("__charptr"), new_type_primitive(new_id_from_str("__char"), mode_Bs), mode_P);
212
213         set_method_param_type(init_type, 0, string);
214         set_method_param_type(init_type, 1, uintptr);
215         set_method_param_type(init_type, 2, uintptr);
216         set_method_param_type(init_type, 3, uint);
217         init_ent = new_entity(get_glob_type(), init_name, init_type);
218         set_entity_ld_ident(init_ent, init_name);
219
220         irg = new_ir_graph(ent, 0);
221         empty_frame_type = get_irg_frame_type(irg);
222         set_type_size_bytes(empty_frame_type, 0);
223
224         bb = get_cur_block();
225
226         start_block = get_irg_start_block(irg);
227
228         sym.entity_p = init_ent;
229         symconst     = new_r_SymConst(irg, start_block, sym, symconst_addr_ent);
230
231         sym.entity_p = ent_filename;
232         ins[0] = new_r_SymConst(irg, start_block, sym, symconst_addr_ent);
233         sym.entity_p = bblock_id;
234         ins[1] = new_r_SymConst(irg, start_block, sym, symconst_addr_ent);
235         sym.entity_p = bblock_counts;
236         ins[2] = new_r_SymConst(irg, start_block, sym, symconst_addr_ent);
237         ins[3] = new_r_Const_long(irg, start_block, mode_Iu, n_blocks);
238
239         call = new_r_Call(irg, bb, get_irg_initial_mem(irg), symconst, 4, ins, init_type);
240         ret = new_r_Return(irg, bb, new_r_Proj(irg, bb, call, mode_M, pn_Call_M_regular), 0, NULL);
241         mature_immBlock(bb);
242
243         add_immBlock_pred(get_irg_end_block(irg), ret);
244         mature_immBlock(get_irg_end_block(irg));
245
246         irg_finalize_cons(irg);
247
248         return irg;
249 }
250
251 /**
252  * Create the location data for the given debug info.
253  */
254 static void create_location_data(dbg_info *dbg, block_id_walker_data_t *wd)
255 {
256         unsigned lineno;
257         const char *fname = be_retrieve_dbg_info(dbg, &lineno);
258
259         if (fname) {
260                 pmap_entry *entry = pmap_find(wd->fname_map, (void *)fname);
261                 ir_entity  *ent;
262
263                 if (! entry) {
264                         static unsigned nr = 0;
265                         ident   *id;
266                         char    buf[128];
267                         ir_type *arr;
268                         int     i, len = strlen(fname) + 1;
269                         tarval  **tarval_string;
270
271                         snprintf(buf, sizeof(buf), "firm_name_arr.%d", nr);
272                         arr = new_type_array(new_id_from_str(buf), 1, wd->tp_char);
273                         set_array_bounds_int(arr, 0, 0, len);
274
275                         snprintf(buf, sizeof(buf), "__firm_name.%d", nr++);
276                         id = new_id_from_str(buf);
277                         ent = new_entity(get_glob_type(), id, arr);
278                         set_entity_ld_ident(ent, id);
279
280                         pmap_insert(wd->fname_map, (void *)fname, ent);
281
282                         /* initialize file name string constant */
283                         tarval_string = alloca(sizeof(*tarval_string) * (len));
284                         for (i = 0; i < len; ++i) {
285                                 tarval_string[i] = new_tarval_from_long(fname[i], mode_Bs);
286                         }
287                         set_entity_variability(ent, variability_constant);
288                         set_array_entity_values(ent, tarval_string, len);
289                 } else {
290                         ent = entry->value;
291                 }
292                 wd->locs[wd->id].fname  = ent;
293                 wd->locs[wd->id].lineno = lineno;
294         } else {
295                 wd->locs[wd->id].fname  = NULL;
296                 wd->locs[wd->id].lineno = 0;
297         }
298 }
299
300 /**
301  * Walker: assigns an ID to every block.
302  * Builds the string table
303  */
304 static void
305 block_id_walker(ir_node * bb, void * data)
306 {
307         block_id_walker_data_t *wd = data;
308
309         wd->array[wd->id] = new_tarval_from_long(get_irn_node_nr(bb), mode_Iu);
310         instrument_block(bb, wd->symconst, wd->id);
311
312         if (wd->flags & profile_with_locations) {
313                 dbg_info *dbg = get_irn_dbg_info(bb);
314                 create_location_data(dbg, wd);
315         }
316         ++wd->id;
317 }
318
319 #define IDENT(x)        new_id_from_chars(x, sizeof(x) - 1)
320
321 ir_graph *
322 be_profile_instrument(const char *filename, unsigned flags)
323 {
324         int n, i;
325         int n_blocks = 0;
326         ir_entity *bblock_id;
327         ir_entity *bblock_counts;
328         ir_entity *ent_filename;
329         ir_entity *ent_locations = NULL;
330         ir_entity *loc_lineno = NULL;
331         ir_entity *loc_name = NULL;
332         ir_entity *ent;
333         ir_type *array_type;
334         ir_type *uint_type;
335         ir_type *string_type;
336         ir_type *character_type;
337         ir_type *loc_type = NULL;
338         ir_type *charptr_type;
339         ir_type *gtp;
340         tarval **tarval_array;
341         tarval **tarval_string;
342         tarval *tv;
343         int filename_len = strlen(filename)+1;
344         ident *cur_ident;
345         int align_l, align_n, size;
346         ir_graph *rem;
347         block_id_walker_data_t  wd;
348         symconst_symbol sym;
349
350         /* count the number of block first */
351         for (n = get_irp_n_irgs() - 1; n >= 0; --n) {
352                 ir_graph *irg = get_irp_irg(n);
353
354                 n_blocks += count_blocks(irg);
355         }
356
357         /* create all the necessary types and entities. Note that the
358            types must have a fixed layout, because we already running in the
359            backend */
360         uint_type      = new_type_primitive(IDENT("__uint"), mode_Iu);
361         set_type_alignment_bytes(uint_type, get_type_size_bytes(uint_type));
362         array_type     = new_type_array(IDENT("__block_info_array"), 1, uint_type);
363         set_array_bounds_int(array_type, 0, 0, n_blocks);
364
365         character_type = new_type_primitive(IDENT("__char"), mode_Bs);
366         string_type    = new_type_array(IDENT("__filename"), 1, character_type);
367         set_array_bounds_int(string_type, 0, 0, filename_len);
368
369         gtp            = get_glob_type();
370
371         cur_ident      = IDENT("__FIRMPROF__BLOCK_IDS");
372         bblock_id      = new_entity(gtp, cur_ident, array_type);
373         set_entity_ld_ident(bblock_id, cur_ident);
374         set_entity_variability(bblock_id, variability_initialized);
375
376         cur_ident      = IDENT("__FIRMPROF__BLOCK_COUNTS");
377         bblock_counts  = new_entity(gtp, cur_ident, array_type);
378         set_entity_ld_ident(bblock_counts, cur_ident);
379         set_entity_variability(bblock_counts, variability_initialized);
380
381         cur_ident      = IDENT("__FIRMPROF__FILE_NAME");
382         ent_filename   = new_entity(gtp, cur_ident, string_type);
383         set_entity_ld_ident(ent_filename, cur_ident);
384
385         if (flags & profile_with_locations) {
386                 loc_type       = new_type_struct(IDENT("__location"));
387                 loc_lineno     = new_entity(loc_type, IDENT("lineno"), uint_type);
388                 align_l        = get_type_alignment_bytes(uint_type);
389                 size           = get_type_size_bytes(uint_type);
390                 set_entity_offset(loc_lineno, 0);
391
392                 charptr_type   = new_type_pointer(IDENT("__charptr"), character_type, mode_P_data);
393                 align_n        = get_type_size_bytes(charptr_type);
394                 set_type_alignment_bytes(charptr_type, align_n);
395                 loc_name       = new_entity(loc_type, IDENT("name"), charptr_type);
396                 size           = (size + align_n - 1) & -align_n;
397                 set_entity_offset(loc_name, size);
398                 size          += align_n;
399
400                 if (align_n > align_l)
401                         align_l = align_n;
402                 size = (size + align_l - 1) & -align_l;
403                 set_type_size_bytes(loc_type, size);
404                 set_type_state(loc_type, layout_fixed);
405
406                 loc_type = new_type_array(IDENT("__locarray"), 1, loc_type);
407                 set_array_bounds_int(string_type, 0, 0, n_blocks);
408
409                 cur_ident      = IDENT("__FIRMPROF__LOCATIONS");
410                 ent_locations   = new_entity(gtp, cur_ident, loc_type);
411                 set_entity_ld_ident(ent_locations, cur_ident);
412         }
413
414         /* initialize count array */
415         NEW_ARR_A(tarval *, tarval_array, n_blocks);
416         tv = get_tarval_null(mode_Iu);
417         for (i = 0; i < n_blocks; ++i) {
418                 tarval_array[i] = tv;
419         }
420         set_array_entity_values(bblock_counts, tarval_array, n_blocks);
421
422         /* initialize function name string constant */
423         tarval_string = alloca(sizeof(*tarval_string) * (filename_len));
424         for (i = 0; i < filename_len; ++i) {
425                 tarval_string[i] = new_tarval_from_long(filename[i], mode_Bs);
426         }
427         set_entity_variability(ent_filename, variability_constant);
428         set_array_entity_values(ent_filename, tarval_string, filename_len);
429
430         /* initialize block id array and instrument blocks */
431         wd.array     = tarval_array;
432         wd.id        = 0;
433         wd.tp_char   = character_type;
434         wd.flags     = flags;
435         if (flags & profile_with_locations) {
436                 wd.fname_map = pmap_create();
437                 NEW_ARR_A(loc_entry, wd.locs, n_blocks);
438         }
439
440         for (n = get_irp_n_irgs() - 1; n >= 0; --n) {
441                 ir_graph      *irg = get_irp_irg(n);
442                 int            i;
443                 ir_node       *endbb = get_irg_end_block(irg);
444                 fix_env       env;
445
446                 set_current_ir_graph(irg);
447
448                 /* generate a symbolic constant pointing to the count array */
449                 sym.entity_p = bblock_counts;
450                 wd.symconst  = new_r_SymConst(irg, get_irg_start_block(irg), sym, symconst_addr_ent);
451
452                 irg_block_walk_graph(irg, block_id_walker, NULL, &wd);
453                 env.start_block = get_irg_start_block(irg);
454                 env.end_block   = get_irg_end_block(irg);
455                 set_irn_link(env.start_block, get_irg_no_mem(irg));
456                 irg_block_walk_graph(irg, fix_ssa, NULL, &env);
457                 for (i = get_Block_n_cfgpreds(endbb) - 1; i >= 0; --i) {
458                         ir_node *node = skip_Proj(get_Block_cfgpred(endbb, i));
459                         ir_node *bb   = get_Block_cfgpred_block(endbb, i);
460                         ir_node *sync;
461                         ir_node *ins[2];
462
463                         switch (get_irn_opcode(node)) {
464                         case iro_Return:
465                                 ins[0] = get_irn_link(bb);
466                                 ins[1] = get_Return_mem(node);
467                                 sync   = new_r_Sync(irg, bb, 2, ins);
468                                 set_Return_mem(node, sync);
469                                 break;
470                         case iro_Raise:
471                                 ins[0] = get_irn_link(bb);
472                                 ins[1] = get_Raise_mem(node);
473                                 sync   = new_r_Sync(irg, bb, 2, ins);
474                                 set_Raise_mem(node, sync);
475                                 break;
476                         default:
477                                 /* a fragile's op exception. There should be another path to End,
478                                    so ignore it */
479                                 assert(is_fragile_op(node) && "unexpected End control flow predecessor");
480                         }
481                 }
482         }
483         set_array_entity_values(bblock_id, tarval_array, n_blocks);
484
485         if (flags & profile_with_locations) {
486                 /* build the initializer for the locations */
487                 rem = current_ir_graph;
488                 current_ir_graph = get_const_code_irg();
489                 ent = get_array_element_entity(loc_type);
490                 set_entity_variability(ent_locations, variability_constant);
491                 for (i = 0; i < n_blocks; ++i) {
492                         compound_graph_path *path;
493                         tarval *tv;
494                         ir_node *n;
495
496                         /* lineno */
497                         path = new_compound_graph_path(loc_type, 2);
498                         set_compound_graph_path_array_index(path, 0, i);
499                         set_compound_graph_path_node(path, 0, ent);
500                         set_compound_graph_path_node(path, 1, loc_lineno);
501                         tv = new_tarval_from_long(wd.locs[i].lineno, mode_Iu);
502                         add_compound_ent_value_w_path(ent_locations, new_Const(mode_Iu, tv), path);
503
504                         /* name */
505                         path = new_compound_graph_path(loc_type, 2);
506                         set_compound_graph_path_array_index(path, 0, i);
507                         set_compound_graph_path_node(path, 0, ent);
508                         set_compound_graph_path_node(path, 1, loc_name);
509                         if (wd.locs[i].fname) {
510                                 sym.entity_p = wd.locs[i].fname;
511                                 n = new_SymConst(sym, symconst_addr_ent);
512                         } else {
513                                 n = new_Const(mode_P_data, get_mode_null(mode_P_data));
514                         }
515                         add_compound_ent_value_w_path(ent_locations, n, path);
516                 }
517                 pmap_destroy(wd.fname_map);
518         }
519         return gen_initializer_irg(ent_filename, bblock_id, bblock_counts, n_blocks);
520 }
521
522 static void
523 profile_node_info(void *ctx, FILE *f, const ir_node *irn)
524 {
525         if(is_Block(irn)) {
526                 fprintf(f, "profiled execution count: %u\n", be_profile_get_block_execcount(irn));
527         }
528 }
529
530 static void
531 register_vcg_hook(void)
532 {
533         memset(&hook, 0, sizeof(hook));
534         hook.hook._hook_node_info = profile_node_info;
535         register_hook(hook_node_info, &hook);
536 }
537
538 static void
539 unregister_vcg_hook(void)
540 {
541         unregister_hook(hook_node_info, &hook);
542 }
543
544 /**
545  * Reads the corresponding profile info file if it exists and returns a
546  * profile info struct
547  */
548 void
549 be_profile_read(const char *filename)
550 {
551         FILE   *f;
552         char    buf[8];
553         size_t  ret;
554
555         f = fopen(filename, "r");
556         if(f == NULL) {
557                 return;
558         }
559         printf("found profile data '%s'.\n", filename);
560
561         /* check magic */
562         ret = fread(buf, 8, 1, f);
563         if(ret == 0 || strncmp(buf, "firmprof", 8) != 0) {
564                 return;
565         }
566
567         if(profile) be_profile_free();
568         profile = new_set(cmp_execcount, 16);
569
570         do {
571                 execcount_t  query;
572                 ret = fread(&query, sizeof(unsigned int), 2, f);
573
574                 if(ret != 2) break;
575
576                 set_insert(profile, &query, sizeof(query), query.block);
577         } while(1);
578
579         fclose(f);
580         register_vcg_hook();
581 }
582
583 /**
584  * Frees the profile info
585  */
586 void
587 be_profile_free(void)
588 {
589         if(profile) {
590                 unregister_vcg_hook();
591                 del_set(profile);
592         }
593 }
594
595 /**
596  * Tells whether profile module has acquired data
597  */
598 int
599 be_profile_has_data(void)
600 {
601         return (profile != NULL);
602 }
603
604 /**
605  * Get block execution count as determined be profiling
606  */
607 unsigned int
608 be_profile_get_block_execcount(const ir_node *block)
609 {
610         execcount_t *ec, query;
611
612         if(!profile)
613                 return 1;
614
615         query.block = get_irn_node_nr(block);
616         ec = set_find(profile, &query, sizeof(query), get_irn_node_nr(block));
617
618         if(ec != NULL) {
619                 return ec->count;
620         } else {
621                 ir_fprintf(stderr, "Warning: Profile contains no data for %+F\n",
622                            block);
623                 return 1;
624         }
625 }
626
627 typedef struct _intialize_execfreq_env_t {
628         ir_graph *irg;
629         ir_exec_freq *execfreqs;
630         double freq_factor;
631 } initialize_execfreq_env_t;
632
633 // minimal execution frequency (an execfreq of 0 confuses algos)
634 static const double MIN_EXECFREQ = 0.00001;
635
636 static void initialize_execfreq(ir_node *block, void *data) {
637         initialize_execfreq_env_t *env = data;
638         double freq;
639
640         if(block == get_irg_start_block(env->irg)
641            || block == get_irg_end_block(env->irg)) {
642                 freq = 1.0;
643         } else {
644                 freq = be_profile_get_block_execcount(block);
645                 freq *= env->freq_factor;
646                 if(freq < MIN_EXECFREQ)
647                         freq = MIN_EXECFREQ;
648         }
649
650         set_execfreq(env->execfreqs, block, freq);
651 }
652
653 ir_exec_freq *be_create_execfreqs_from_profile(ir_graph *irg)
654 {
655         ir_node *block2 = NULL;
656         ir_node *start_block;
657         const ir_edge_t *edge;
658         initialize_execfreq_env_t env;
659         unsigned count;
660
661         env.irg = irg;
662         env.execfreqs = create_execfreq(irg);
663
664         // find the successor to the start block
665         start_block = get_irg_start_block(irg);
666         foreach_block_succ(start_block, edge) {
667                 ir_node *succ = get_edge_src_irn(edge);
668                 if(succ != start_block) {
669                         block2 = succ;
670                         break;
671                 }
672         }
673         assert(block2 != NULL);
674
675         count = be_profile_get_block_execcount(block2);
676         if(count == 0) {
677                 // the function was never executed, so fallback to estimated freqs
678                 free_execfreq(env.execfreqs);
679
680                 return compute_execfreq(irg, 10);
681         }
682
683         env.freq_factor = 1.0 / count;
684         irg_block_walk_graph(irg, initialize_execfreq, NULL, &env);
685
686         return env.execfreqs;
687 }