Commit 2cc9db25 authored by Michael Beck's avatar Michael Beck
Browse files

updated Header

[r13542]
parent 02a879a0
......@@ -17,14 +17,11 @@
* PURPOSE.
*/
/*
* Project: libFIRM
* File name: ir/ir/firmstat.c
* Purpose: Statistics for Firm.
* Author: Michael Beck
* Created:
* CVS-ID: $Id$
* Copyright: (c) 2004 Universität Karlsruhe
/**
* @file
* @brief Statistic functions for constant counting.
* @author Michael Beck
* @version $Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
......@@ -37,110 +34,105 @@
* calculated the dual logarithm of |value|
*/
static unsigned log2abs(long value) {
unsigned res = 0;
if (value < 0)
value = -value;
if (value > 0xFFFF) {
res += 16;
value >>= 16;
}
if (value > 0xFF) {
res += 8;
value >>= 8;
}
if (value > 0xF) {
res += 4;
value >>= 4;
}
if (value > 3) {
res += 2;
value >>= 2;
}
if (value > 1) {
res += 1;
}
return res;
unsigned res = 0;
if (value < 0)
value = -value;
if (value > 0xFFFF) {
res += 16;
value >>= 16;
}
if (value > 0xFF) {
res += 8;
value >>= 8;
}
if (value > 0xF) {
res += 4;
value >>= 4;
}
if (value > 3) {
res += 2;
value >>= 2;
}
if (value > 1) {
res += 1;
}
return res;
}
/**
* classify the value of a float tarval
*/
static float_classify_t classify_float_value(tarval *tv)
{
ir_mode *mode = get_tarval_mode(tv);
static float_classify_t classify_float_value(tarval *tv) {
ir_mode *mode = get_tarval_mode(tv);
if (tv == get_mode_null(mode))
return STAT_FC_1;
else if (tv == get_mode_one(mode))
return STAT_FC_1;
if (tv == get_mode_null(mode))
return STAT_FC_1;
else if (tv == get_mode_one(mode))
return STAT_FC_1;
return STAT_FC_OTHER;
return STAT_FC_OTHER;
}
/* return a human readable name for an float classification */
const char *stat_fc_name(float_classify_t classification)
{
switch (classification) {
case STAT_FC_0: return "0.0";
case STAT_FC_1: return "1.0";
case STAT_FC_2: return "2.0";
case STAT_FC_0_5: return "0.5";
case STAT_FC_EXACT: return "exact";
case STAT_FC_OTHER: return "other";
default: return "<UNKNOWN>";
}
const char *stat_fc_name(float_classify_t classification) {
switch (classification) {
case STAT_FC_0: return "0.0";
case STAT_FC_1: return "1.0";
case STAT_FC_2: return "2.0";
case STAT_FC_0_5: return "0.5";
case STAT_FC_EXACT: return "exact";
case STAT_FC_OTHER: return "other";
default: return "<UNKNOWN>";
}
}
/* update info on Consts */
void stat_update_const(stat_info_t *status, ir_node *node, graph_entry_t *graph)
{
ir_mode *mode = get_irn_mode(node);
tarval *tv;
unsigned bits;
ir_mode *mode = get_irn_mode(node);
tarval *tv;
unsigned bits;
if (mode_is_int(mode)) {
tv = get_Const_tarval(node);
if (mode_is_int(mode)) {
tv = get_Const_tarval(node);
/* FIXME: */
if (! tarval_is_long(tv))
return;
/* FIXME: */
if (! tarval_is_long(tv))
return;
bits = log2abs(get_tarval_long(tv));
bits = log2abs(get_tarval_long(tv));
if (bits > ARR_SIZE(status->const_info.int_bits_count))
bits = ARR_SIZE(status->const_info.int_bits_count);
if (bits > ARR_SIZE(status->const_info.int_bits_count))
bits = ARR_SIZE(status->const_info.int_bits_count);
cnt_inc(&status->const_info.int_bits_count[bits]);
}
else if (mode_is_float(mode)) {
tv = get_Const_tarval(node);
cnt_inc(&status->const_info.int_bits_count[bits]);
} else if (mode_is_float(mode)) {
tv = get_Const_tarval(node);
cnt_inc(&status->const_info.floats[classify_float_value(tv)]);
}
else {
/* something different */
cnt_inc(&status->const_info.others);
}
cnt_inc(&status->const_info.floats[classify_float_value(tv)]);
} else {
/* something different */
cnt_inc(&status->const_info.others);
}
}
/* clears the const statistics for a new snapshot */
void stat_const_clear(stat_info_t *status)
{
int i;
void stat_const_clear(stat_info_t *status) {
int i;
for (i = 0; i < ARR_SIZE(status->const_info.int_bits_count); ++i)
cnt_clr(&status->const_info.int_bits_count[i]);
for (i = 0; i < ARR_SIZE(status->const_info.int_bits_count); ++i)
cnt_clr(&status->const_info.int_bits_count[i]);
for (i = 0; i < ARR_SIZE(status->const_info.floats); ++i)
cnt_clr(&status->const_info.floats[i]);
for (i = 0; i < ARR_SIZE(status->const_info.floats); ++i)
cnt_clr(&status->const_info.floats[i]);
cnt_clr(&status->const_info.others);
cnt_clr(&status->const_info.others);
}
/* initialize the Const statistic. */
void stat_init_const_cnt(stat_info_t *status)
{
void stat_init_const_cnt(stat_info_t *status) {
/* currently nothing */
}
......@@ -17,17 +17,14 @@
* PURPOSE.
*/
/*
* Project: libFIRM
* File name: ir/ir/counter.h
* Purpose: Statistics for Firm. Counter implementation.
* Author: Michael Beck
* Created:
* CVS-ID: $Id$
* Copyright: (c) 2004 Universität Karlsruhe
/**
* @file
* @brief Statistics for Firm. Counter implementation.
* @author Michael Beck
* @version $Id$
*/
#ifndef _COUNTER_H_
#define _COUNTER_H_
#ifndef FIRM_STAT_COUNTER_H
#define FIRM_STAT_COUNTER_H
#include <string.h>
#include <limits.h>
......@@ -200,4 +197,4 @@ static INLINE int cnt_gt(const counter_t *a, unsigned value)
return a->cnt[0] > value;
}
#endif /* _COUNTER_H_ */
#endif /* FIRM_STAT_COUNTER_H */
......@@ -17,16 +17,12 @@
* PURPOSE.
*/
/*
* Project: libFIRM
* File name: ir/ir/dags.c
* Purpose: Statistics for Firm. DAG's in graphs.
* Author: Michael Beck
* Created:
* CVS-ID: $Id$
* Copyright: (c) 2004 Universitt Karlsruhe
/**
* @file
* @brief Statistics for Firm. DAG's in graphs.
* @author Michael Beck
* @version $Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
......
......@@ -17,17 +17,14 @@
* PURPOSE.
*/
/*
* Project: libFIRM
* File name: ir/ir/dags.h
* Purpose: Statistics for Firm. DAG's in graphs.
* Author: Michael Beck
* Created:
* CVS-ID: $Id$
* Copyright: (c) 2004 Universität Karlsruhe
/**
* @file
* @brief Statistics for Firm. DAG's in graphs.
* @author Michael Beck
* @version $Id$
*/
#ifndef _DAGS_H_
#define _DAGS_H_
#ifndef FIRM_STAT_DAGS_H
#define FIRM_STAT_DAGS_H
#include "firmstat_t.h"
/*
......@@ -35,4 +32,4 @@
*/
void count_dags_in_graph(graph_entry_t *global, graph_entry_t *graph);
#endif /* _DAGS_H_ */
#endif /* FIRM_STAT_DAGS_H */
......@@ -17,14 +17,11 @@
* PURPOSE.
*/
/*
* Project: libFIRM
* File name: ir/ir/distrib.c
* Purpose: Statistics for Firm. Distribution tables.
* Author: Michael Beck
* Created:
* CVS-ID: $Id$
* Copyright: (c) 2004 Universität Karlsruhe
/**
* @file
* @brief Statistics for Firm. Distribution tables.
* @author Michael Beck
* @version $Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
......@@ -38,24 +35,21 @@
/**
* calculates a hash value for an address
*/
static unsigned addr_hash(const void *object)
{
static unsigned addr_hash(const void *object) {
return HASH_PTR(object);
}
/**
* calculates a hash value for an integer
*/
static unsigned int_hash(const void *object)
{
static unsigned int_hash(const void *object) {
return (unsigned)PTR_TO_INT(object);
}
/**
* compare function for integer distribution tables
*/
static int int_cmp_fun(const void *elt, const void *key)
{
static int int_cmp_fun(const void *elt, const void *key) {
const distrib_entry_t *p1 = elt;
const distrib_entry_t *p2 = key;
......@@ -65,8 +59,7 @@ static int int_cmp_fun(const void *elt, const void *key)
/*
* create a new distribution table
*/
distrib_tbl_t *stat_new_distrib_tbl(pset_cmp_fun cmp_func, distrib_hash_fun hash_func)
{
distrib_tbl_t *stat_new_distrib_tbl(pset_cmp_fun cmp_func, distrib_hash_fun hash_func) {
distrib_tbl_t *res;
res = xmalloc(sizeof(*res));
......@@ -84,8 +77,7 @@ distrib_tbl_t *stat_new_distrib_tbl(pset_cmp_fun cmp_func, distrib_hash_fun hash
/*
* create a new distribution table for an integer distribution
*/
distrib_tbl_t *stat_new_int_distrib_tbl(void)
{
distrib_tbl_t *stat_new_int_distrib_tbl(void) {
distrib_tbl_t *res = stat_new_distrib_tbl(int_cmp_fun, int_hash);
if (res)
......@@ -97,8 +89,7 @@ distrib_tbl_t *stat_new_int_distrib_tbl(void)
/*
* destroy a distribution table
*/
void stat_delete_distrib_tbl(distrib_tbl_t *tbl)
{
void stat_delete_distrib_tbl(distrib_tbl_t *tbl) {
if (tbl) {
/* free all entries */
obstack_free(&tbl->cnts, NULL);
......@@ -111,8 +102,7 @@ void stat_delete_distrib_tbl(distrib_tbl_t *tbl)
/**
* Returns the associates distrib_entry_t for an object
*/
static distrib_entry_t *distrib_get_entry(distrib_tbl_t *tbl, const void *object)
{
static distrib_entry_t *distrib_get_entry(distrib_tbl_t *tbl, const void *object) {
distrib_entry_t key;
distrib_entry_t *elem;
......@@ -135,8 +125,7 @@ static distrib_entry_t *distrib_get_entry(distrib_tbl_t *tbl, const void *object
/*
* adds a new object count into the distribution table
*/
void stat_add_distrib_tbl(distrib_tbl_t *tbl, const void *object, const counter_t *cnt)
{
void stat_add_distrib_tbl(distrib_tbl_t *tbl, const void *object, const counter_t *cnt) {
distrib_entry_t *elem = distrib_get_entry(tbl, object);
cnt_add(&elem->cnt, cnt);
......@@ -145,16 +134,14 @@ void stat_add_distrib_tbl(distrib_tbl_t *tbl, const void *object, const counter_
/*
* adds a new key count into the integer distribution table
*/
void stat_add_int_distrib_tbl(distrib_tbl_t *tbl, int key, const counter_t *cnt)
{
void stat_add_int_distrib_tbl(distrib_tbl_t *tbl, int key, const counter_t *cnt) {
stat_add_distrib_tbl(tbl, (const void *)key, cnt);
}
/*
* increases object count by one
*/
void stat_inc_distrib_tbl(distrib_tbl_t *tbl, const void *object)
{
void stat_inc_distrib_tbl(distrib_tbl_t *tbl, const void *object) {
distrib_entry_t *elem = distrib_get_entry(tbl, object);
cnt_inc(&elem->cnt);
......@@ -163,8 +150,7 @@ void stat_inc_distrib_tbl(distrib_tbl_t *tbl, const void *object)
/*
* increases key count by one
*/
void stat_inc_int_distrib_tbl(distrib_tbl_t *tbl, int key)
{
void stat_inc_int_distrib_tbl(distrib_tbl_t *tbl, int key) {
stat_inc_distrib_tbl(tbl, (const void *)key);
}
......@@ -172,8 +158,7 @@ void stat_inc_int_distrib_tbl(distrib_tbl_t *tbl, int key)
* inserts a new object with count 0 into the distribution table
* if object is already present, nothing happens
*/
void stat_insert_distrib_tbl(distrib_tbl_t *tbl, const void *object)
{
void stat_insert_distrib_tbl(distrib_tbl_t *tbl, const void *object) {
/* executed for side effect */
(void)distrib_get_entry(tbl, object);
}
......@@ -182,16 +167,14 @@ void stat_insert_distrib_tbl(distrib_tbl_t *tbl, const void *object)
* inserts a new key with count 0 into the integer distribution table
* if key is already present, nothing happens
*/
void stat_insert_int_distrib_tbl(distrib_tbl_t *tbl, int key)
{
void stat_insert_int_distrib_tbl(distrib_tbl_t *tbl, int key) {
stat_insert_distrib_tbl(tbl, (const void *)key);
}
/*
* returns the sum over all counters in a distribution table
*/
int stat_get_count_distrib_tbl(distrib_tbl_t *tbl)
{
int stat_get_count_distrib_tbl(distrib_tbl_t *tbl) {
distrib_entry_t *entry;
counter_t cnt = ZERO_CNT;
......@@ -203,8 +186,7 @@ int stat_get_count_distrib_tbl(distrib_tbl_t *tbl)
/*
* calculates the mean value of a distribution
*/
double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl)
{
double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl) {
distrib_entry_t *entry;
unsigned count;
double sum;
......@@ -234,8 +216,7 @@ double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl)
sum += cnt_to_dbl(&entry->cnt);
}
count = max - min + 1;
}
else {
} else {
sum = 0.0;
count = 0;
foreach_pset(tbl->hash_map, entry) {
......@@ -250,8 +231,7 @@ double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl)
/*
* calculates the average value of a distribution
*/
double stat_calc_avg_distrib_tbl(distrib_tbl_t *tbl)
{
double stat_calc_avg_distrib_tbl(distrib_tbl_t *tbl) {
distrib_entry_t *entry;
unsigned count = 0;
double sum = 0.0;
......@@ -264,8 +244,7 @@ double stat_calc_avg_distrib_tbl(distrib_tbl_t *tbl)
sum += cnt_to_dbl(&entry->cnt) * (int)entry->object;
count += cnt_to_uint(&entry->cnt);
}
}
else {
} else {
foreach_pset(tbl->hash_map, entry) {
sum += cnt_to_dbl(&entry->cnt);
++count;
......@@ -278,8 +257,7 @@ double stat_calc_avg_distrib_tbl(distrib_tbl_t *tbl)
/**
* iterates over all entries in a distribution table
*/
void stat_iterate_distrib_tbl(const distrib_tbl_t *tbl, eval_distrib_entry_fun eval, void *env)
{
void stat_iterate_distrib_tbl(const distrib_tbl_t *tbl, eval_distrib_entry_fun eval, void *env) {
distrib_entry_t *entry;
foreach_pset(tbl->hash_map, entry)
......
......@@ -17,16 +17,12 @@
* PURPOSE.
*/
/*
* Project: libFIRM
* File name: ir/ir/firmstat.c
* Purpose: Statistics for Firm.
* Author: Michael Beck
* Created:
* CVS-ID: $Id$
* Copyright: (c) 2004 Universitt Karlsruhe
/**
* @file
* @brief Statistics for Firm.
* @author Michael Beck
* @version $Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
......
......@@ -17,83 +17,77 @@
* PURPOSE.
*/
/*
* Project: libFIRM
* File name: ir/stat/firmstat.h
* Purpose: Statistics for Firm.
* Author: Michael Beck
* Created:
* CVS-ID: $Id$
* Copyright: (c) 2004 Universitt Karlsruhe
*/
#ifndef _FIRMSTAT_H_
#define _FIRMSTAT_H_
/**
* @file firmstat.h
* @file
* @brief Statistics for Firm.
* @author Michael Beck
* @version $Id$
*/
#ifndef FIRM_STAT_FIRMSTAT_H
#define FIRM_STAT_FIRMSTAT_H
#include "irhooks.h"
/**
* Statistic options, can be or'ed.
*/
enum firmstat_options_t {
FIRMSTAT_ENABLED = 0x00000001, /**< enable statistics */
FIRMSTAT_PATTERN_ENABLED = 0x00000002, /**< enable pattern calculation */
FIRMSTAT_COUNT_STRONG_OP = 0x00000004, /**< if set, count Mul/Div/Mod/DivMod by constant */
FIRMSTAT_COUNT_DAG = 0x00000008, /**< if set, count DAG statistics */
FIRMSTAT_COUNT_DELETED = 0x00000010, /**< if set, count deleted graphs */
FIRMSTAT_COUNT_SELS = 0x00000020, /**< if set, count Sel(Sel(..)) differently */
FIRMSTAT_COUNT_CONSTS = 0x00000040, /**< if set, count Const statistics */
FIRMSTAT_COUNT_EXTBB = 0x00000080, /**< if set, count extended Basic Block statistics */
FIRMSTAT_CSV_OUTPUT = 0x10000000 /**< CSV output of some mini-statistic */
FIRMSTAT_ENABLED = 0x00000001, /**< enable statistics */
FIRMSTAT_PATTERN_ENABLED = 0x00000002, /**< enable pattern calculation */
FIRMSTAT_COUNT_STRONG_OP = 0x00000004, /**< if set, count Mul/Div/Mod/DivMod by constant */
FIRMSTAT_COUNT_DAG = 0x00000008, /**< if set, count DAG statistics */
FIRMSTAT_COUNT_DELETED = 0x00000010, /**< if set, count deleted graphs */
FIRMSTAT_COUNT_SELS = 0x00000020, /**< if set, count Sel(Sel(..)) differently */
FIRMSTAT_COUNT_CONSTS = 0x00000040, /**< if set, count Const statistics */
FIRMSTAT_COUNT_EXTBB = 0x00000080, /**< if set, count extended Basic Block statistics */
FIRMSTAT_CSV_OUTPUT = 0x10000000 /**< CSV output of some mini-statistic */
};
/**
* Additional flags for statistics.
*/
enum firmstat_optimizations_t {
FS_OPT_NEUTRAL_0 = HOOK_OPT_LAST, /**< a op 0 = 0 op a = a */
FS_OPT_NEUTRAL_1, /**< a op 1 = 1 op a = a */
FS_OPT_ADD_A_A, /**< a + a = a * 2 */
FS_OPT_ADD_A_MINUS_B, /**< a + -b = a - b */
FS_OPT_ADD_SUB, /**< (a + x) - x = (a - x) + x */
FS_OPT_ADD_MUL_A_X_A, /**< a * x + a = a * (x + 1) */
FS_OPT_SUB_0_A, /**< 0 - a = -a */
FS_OPT_SUB_MUL_A_X_A, /**< a * x - a = a * (x - 1) */
FS_OPT_SUB_SUB_X_Y_Z, /**< (x - y) - z = x - (y + z) */
FS_OPT_MUL_MINUS_1, /**< a * -1 = -a */
FS_OPT_OR, /**< a | a = a | 0 = 0 | a = a */
FS_OPT_AND, /**< a & 0b1...1 = 0b1...1 & a = a & a = a */
FS_OPT_EOR_A_A, /**< a ^ a = 0 */
FS_OPT_EOR_TO_NOT_BOOL, /**< bool ^ 1 = !bool */
FS_OPT_EOR_TO_NOT, /**< x ^ 0b1..1 = ~x */
FS_OPT_NOT_CMP, /**< !(a cmp b) = a !cmp b */
FS_OPT_OR_SHFT_TO_ROT, /**< (x << c) | (x >> (bits - c)) == Rot(x, c) */
FS_OPT_REASSOC_SHIFT, /**< (x SHF c1) SHF c2 = x SHF (c1+c2) */
FS_OPT_CONV, /**< a Conv could be removed */
FS_OPT_CAST, /**< a Cast could be removed */
FS_OPT_MIN_MAX_EQ, /**< Min(a,a) = Max(a,a) = a */
FS_OPT_MUX_C, /**< Mux(C, f, t) = C ? t : f */
FS_OPT_MUX_EQ, /**< Mux(v, x, x) = x */
FS_OPT_MUX_TRANSFORM, /**< Mux(a, b, c) = b OR Mux(a,b, c) = c */
FS_OPT_MUX_TO_MIN, /**< Mux(a < b, a, b) = Min(a,b) */
FS_OPT_MUX_TO_MAX, /**< Mux(a > b, a, b) = Max(a,b) */
FS_OPT_MUX_TO_ABS, /**< Mux(a > b, a, b) = Abs(a,b) */
FS_OPT_MUX_TO_SHR, /**< Mux(a > b, a, b) = a >> b */
FS_OPT_CONST_PHI, /**< Constant evaluation on Phi */
FS_BE_IA32_LEA, /**< Lea was created */
FS_BE_IA32_LOAD_LEA, /**< Load merged with a Lea */
FS_BE_IA32_STORE_LEA, /**< Store merged with a Lea */
FS_BE_IA32_AM_S, /**< Source address mode node created */
FS_BE_IA32_AM_D, /**< Destination address mode node created */
FS_BE_IA32_CJMP, /**< CJmp created to save a cmp/test */
FS_BE_IA32_2ADDRCPY, /**< Copy created due to 2-Addresscode constraints */
FS_BE_IA32_SPILL2ST, /**< Created Store for a Spill */
FS_BE_IA32_RELOAD2LD, /**< Created Load for a Reload */
FS_BE_IA32_SUB2NEGADD, /**< Created Neg-Add for a Sub due to 2-Addresscode constraints */
FS_BE_IA32_LEA2ADD, /**< Transformed Lea back into Add */
FS_OPT_MAX
FS_OPT_NEUTRAL_0 = HOOK_OPT_LAST, /**< a op 0 = 0 op a = a */
FS_OPT_NEUTRAL_1, /**< a op 1 = 1 op a = a */
FS_OPT_ADD_A_A, /**< a + a = a * 2 */
FS_OPT_ADD_A_MINUS_B, /**< a + -b = a - b */
FS_OPT_ADD_SUB, /**< (a + x) - x = (a - x) + x */
FS_OPT_ADD_MUL_A_X_A, /**< a * x + a = a * (x + 1) */
FS_OPT_SUB_0_A, /**< 0 - a = -a */
FS_OPT_SUB_MUL_A_X_A, /**< a * x - a = a * (x - 1) */
FS_OPT_SUB_SUB_X_Y_Z, /**< (x - y) - z = x - (y + z) */
FS_OPT_MUL_MINUS_1, /**< a * -1 = -a */
FS_OPT_OR, /**< a | a = a | 0 = 0 | a = a */
FS_OPT_AND, /**< a & 0b1...1 = 0b1...1 & a = a & a = a */
FS_OPT_EOR_A_A, /**< a ^ a = 0 */
FS_OPT_EOR_TO_NOT_BOOL, /**< bool ^ 1 = !bool */
FS_OPT_EOR_TO_NOT, /**< x ^ 0b1..1 = ~x */
FS_OPT_NOT_CMP, /**< !(a cmp b) = a !cmp b */
FS_OPT_OR_SHFT_TO_ROT, /**< (x << c) | (x >> (bits - c)) == Rot(x, c) */
FS_OPT_REASSOC_SHIFT, /**< (x SHF c1) SHF c2 = x SHF (c1+c2) */
FS_OPT_CONV, /**< a Conv could be removed */
FS_OPT_CAST, /**< a Cast could be removed */
FS_OPT_MIN_MAX_EQ, /**< Min(a,a) = Max(a,a) = a */
FS_OPT_MUX_C, /**< Mux(C, f, t) = C ? t : f */
FS_OPT_MUX_EQ, /**< Mux(v, x, x) = x */
FS_OPT_MUX_TRANSFORM, /**< Mux(a, b, c) = b OR Mux(a,b, c) = c */
FS_OPT_MUX_TO_MIN, /**< Mux(a < b, a, b) = Min(a,b) */