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