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