-/** vim: set sw=4 ts=4:
- * @file beprofile.c
- * @date 2006-04-06
- * @author Adam M. Szalkowski
- * @cvs-id $Id$
+/*
+ * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
*
- * Code instrumentation and execution count profiling
+ * This file is part of libFirm.
*
- * Copyright (C) 2006 Universitaet Karlsruhe
- * Released under the GPL
+ * This file may be distributed and/or modified under the terms of the
+ * GNU General Public License version 2 as published by the Free Software
+ * Foundation and appearing in the file LICENSE.GPL included in the
+ * packaging of this file.
+ *
+ * Licensees holding valid libFirm Professional Edition licenses may use
+ * this file in accordance with the libFirm Commercial License.
+ * Agreement provided with the Software.
+ *
+ * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
+ */
+
+/**
+ * @file
+ * @brief Code instrumentation and execution count profiling.
+ * @author Adam M. Szalkowski
+ * @date 06.04.2006
+ * @version $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include "list.h"
#include "pmap.h"
-#include "entity.h"
#include "irprintf.h"
#include "irgwalk.h"
#include "irdump_t.h"
#include "iredges.h"
#include "execfreq.h"
#include "irvrfy.h"
-#include "type.h"
+#include "typerep.h"
#include "be_t.h"
#include "belive_t.h"
#include "besched_t.h"
#include "beirgmod.h"
-#include "bearch.h"
+#include "bearch_t.h"
#include "beabi.h"
#include "benode_t.h"
#include "beutil.h"
static int
cmp_execcount(const void * a, const void * b, size_t size)
{
+ (void) size;
return ((execcount_t*)a)->block != ((execcount_t*)b)->block;
}
block_counter(ir_node * bb, void * data)
{
unsigned int *count = data;
+ (void) bb;
*count = *count + 1;
}
ir_node *cnst;
/**
- * We can't instrument the start and end block as there are no real
- * instructions in these blocks
+ * We can't instrument the end block as there are no real instructions there
*/
- if(bb == start_block || bb == get_irg_end_block(irg))
+ if(bb == get_irg_end_block(irg))
return;
unknown = new_r_Unknown(irg, mode_M);
}
typedef struct fix_env {
- ir_node *start_block;
ir_node *end_block;
} fix_env;
int arity = get_Block_n_cfgpreds(bb);
/* start and end block are not instrumented, skip! */
- if (bb == env->start_block || bb == env->end_block)
+ if (bb == env->end_block)
return;
- if (arity == 1) {
+ if (bb == get_irg_start_block(get_irn_irg(bb))) {
+ mem = new_NoMem();
+ } else if (arity == 1) {
mem = get_irn_link(get_Block_cfgpred_block(bb, 0));
} else {
int n;
be_profile_instrument(const char *filename, unsigned flags)
{
int n, i;
- unsigned int n_blocks = 0;
+ int n_blocks = 0;
ir_entity *bblock_id;
ir_entity *bblock_counts;
ir_entity *ent_filename;
ir_type *loc_type = NULL;
ir_type *charptr_type;
ir_type *gtp;
+ ir_node *start_block;
tarval **tarval_array;
tarval **tarval_string;
tarval *tv;
backend */
uint_type = new_type_primitive(IDENT("__uint"), mode_Iu);
set_type_alignment_bytes(uint_type, get_type_size_bytes(uint_type));
+
array_type = new_type_array(IDENT("__block_info_array"), 1, uint_type);
set_array_bounds_int(array_type, 0, 0, n_blocks);
+ set_type_size_bytes(array_type, n_blocks * get_mode_size_bytes(mode_Iu));
+ set_type_alignment_bytes(array_type, get_mode_size_bytes(mode_Iu));
+ set_type_state(array_type, layout_fixed);
character_type = new_type_primitive(IDENT("__char"), mode_Bs);
string_type = new_type_array(IDENT("__filename"), 1, character_type);
set_array_bounds_int(string_type, 0, 0, filename_len);
+ set_type_size_bytes(string_type, filename_len);
+ set_type_alignment_bytes(string_type, 1);
+ set_type_state(string_type, layout_fixed);
gtp = get_glob_type();
wd.symconst = new_r_SymConst(irg, get_irg_start_block(irg), sym, symconst_addr_ent);
irg_block_walk_graph(irg, block_id_walker, NULL, &wd);
- env.start_block = get_irg_start_block(irg);
+ start_block = get_irg_start_block(irg);
env.end_block = get_irg_end_block(irg);
- set_irn_link(env.start_block, get_irg_no_mem(irg));
irg_block_walk_graph(irg, fix_ssa, NULL, &env);
for (i = get_Block_n_cfgpreds(endbb) - 1; i >= 0; --i) {
ir_node *node = skip_Proj(get_Block_cfgpred(endbb, i));
static void
profile_node_info(void *ctx, FILE *f, const ir_node *irn)
{
+ (void) ctx;
if(is_Block(irn)) {
fprintf(f, "profiled execution count: %u\n", be_profile_get_block_execcount(irn));
}
ir_exec_freq *be_create_execfreqs_from_profile(ir_graph *irg)
{
- ir_node *block2 = NULL;
ir_node *start_block;
- const ir_edge_t *edge;
initialize_execfreq_env_t env;
unsigned count;
env.irg = irg;
env.execfreqs = create_execfreq(irg);
-
- // find the successor to the start block
start_block = get_irg_start_block(irg);
- foreach_block_succ(start_block, edge) {
- ir_node *succ = get_edge_src_irn(edge);
- if(succ != start_block) {
- block2 = succ;
- break;
- }
- }
- assert(block2 != NULL);
- count = be_profile_get_block_execcount(block2);
+ count = be_profile_get_block_execcount(start_block);
if(count == 0) {
// the function was never executed, so fallback to estimated freqs
free_execfreq(env.execfreqs);