projects
/
libfirm
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
backend: put ignore regs into beirg
[libfirm]
/
ir
/
stat
/
pattern.c
diff --git
a/ir/stat/pattern.c
b/ir/stat/pattern.c
index
028dad3
..
20c8719
100644
(file)
--- a/
ir/stat/pattern.c
+++ b/
ir/stat/pattern.c
@@
-23,14
+23,13
@@
* @author Michael Beck
* @version $Id$
*/
* @author Michael Beck
* @version $Id$
*/
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "config.h"
#include <assert.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include <stdlib.h>
#include <limits.h>
+#include "pattern.h"
#include "ident.h"
#include "irnode_t.h"
#include "irgwalk.h"
#include "ident.h"
#include "irnode_t.h"
#include "irgwalk.h"
@@
-40,6
+39,7
@@
#include "counter.h"
#include "pattern_dmp.h"
#include "hashptr.h"
#include "counter.h"
#include "pattern_dmp.h"
#include "hashptr.h"
+#include "error.h"
#ifdef FIRM_STATISTICS
#ifdef FIRM_STATISTICS
@@
-54,13
+54,13
@@
typedef pset pset_pattern_entry_t;
typedef unsigned char BYTE;
/** Maximum size of the pattern store. */
typedef unsigned char BYTE;
/** Maximum size of the pattern store. */
-#define PATTERN_STORE_SIZE
2048
+#define PATTERN_STORE_SIZE 2048
/**
* The code buffer.
*/
/**
* The code buffer.
*/
-typedef struct
_
code_buf_t {
+typedef struct code_buf_t {
BYTE *next; /**< Next byte address to be written. */
BYTE *end; /**< End address of the buffer. */
BYTE *start; /**< Start address of the buffer. */
BYTE *next; /**< Next byte address to be written. */
BYTE *end; /**< End address of the buffer. */
BYTE *start; /**< Start address of the buffer. */
@@
-89,7
+89,7
@@
enum vlc_code_t {
/*
* An entry for holding one pattern.
*/
/*
* An entry for holding one pattern.
*/
-typedef struct
_
pattern_entry_t {
+typedef struct pattern_entry_t {
counter_t count; /**< Amount of pattern occurance. */
unsigned len; /**< The length of the VLC encoded buffer. */
BYTE buf[1]; /**< The buffer containing the VLC encoded pattern. */
counter_t count; /**< Amount of pattern occurance. */
unsigned len; /**< The length of the VLC encoded buffer. */
BYTE buf[1]; /**< The buffer containing the VLC encoded pattern. */
@@
-109,7
+109,7
@@
enum options_t {
/**
* Pattern info.
*/
/**
* Pattern info.
*/
-typedef struct
_
pattern_info_t {
+typedef struct pattern_info_t {
int enable; /**< If non-zero, this module is enabled. */
struct obstack obst; /**< An obstack containing the counters. */
HASH_MAP(pattern_entry_t) *pattern_hash; /**< A hash map containing the pattern. */
int enable; /**< If non-zero, this module is enabled. */
struct obstack obst; /**< An obstack containing the counters. */
HASH_MAP(pattern_entry_t) *pattern_hash; /**< A hash map containing the pattern. */
@@
-127,7
+127,8
@@
static pattern_info_t _status, *status = &_status;
/**
* Compare two pattern for its occurance counter.
*/
/**
* Compare two pattern for its occurance counter.
*/
-static int pattern_count_cmp(const void *elt, const void *key) {
+static int pattern_count_cmp(const void *elt, const void *key)
+{
int cmp;
pattern_entry_t **e1 = (pattern_entry_t **)elt;
int cmp;
pattern_entry_t **e1 = (pattern_entry_t **)elt;
@@
-142,7
+143,8
@@
static int pattern_count_cmp(const void *elt, const void *key) {
/**
* Compare two pattern for its pattern hash.
*/
/**
* Compare two pattern for its pattern hash.
*/
-static int pattern_cmp(const void *elt, const void *key) {
+static int pattern_cmp(const void *elt, const void *key)
+{
const pattern_entry_t *e1 = elt;
const pattern_entry_t *e2 = key;
int diff = e1->len - e2->len;
const pattern_entry_t *e1 = elt;
const pattern_entry_t *e2 = key;
int diff = e1->len - e2->len;
@@
-160,7
+162,8
@@
static int pattern_cmp(const void *elt, const void *key) {
* @param data a buffer address
* @param len the length of the data buffer
*/
* @param data a buffer address
* @param len the length of the data buffer
*/
-static void init_buf(CODE_BUFFER *buf, BYTE *data, unsigned len) {
+static void init_buf(CODE_BUFFER *buf, BYTE *data, unsigned len)
+{
buf->start =
buf->next = data;
buf->end = data + len;
buf->start =
buf->next = data;
buf->end = data + len;
@@
-176,7
+179,8
@@
static void init_buf(CODE_BUFFER *buf, BYTE *data, unsigned len) {
*
* The hash value for the buffer content is updated.
*/
*
* The hash value for the buffer content is updated.
*/
-static INLINE void put_byte(CODE_BUFFER *buf, BYTE byte) {
+static inline void put_byte(CODE_BUFFER *buf, BYTE byte)
+{
if (buf->next < buf->end) {
*buf->next++ = byte;
buf->hash = (buf->hash * 9) ^ byte;
if (buf->next < buf->end) {
*buf->next++ = byte;
buf->hash = (buf->hash * 9) ^ byte;
@@
-192,7
+196,8
@@
static INLINE void put_byte(CODE_BUFFER *buf, BYTE byte) {
*
* @return the length of the buffer content
*/
*
* @return the length of the buffer content
*/
-static unsigned buf_lenght(const CODE_BUFFER *buf) {
+static unsigned buf_lenght(const CODE_BUFFER *buf)
+{
return buf->next - buf->start;
} /* buf_lenght */
return buf->next - buf->start;
} /* buf_lenght */
@@
-203,7
+208,8
@@
static unsigned buf_lenght(const CODE_BUFFER *buf) {
*
* @return the start address of the buffer content
*/
*
* @return the start address of the buffer content
*/
-static const BYTE *buf_content(const CODE_BUFFER *buf) {
+static const BYTE *buf_content(const CODE_BUFFER *buf)
+{
return buf->start;
} /* buf_content */
return buf->start;
} /* buf_content */
@@
-214,7
+220,8
@@
static const BYTE *buf_content(const CODE_BUFFER *buf) {
*
* @return the hash value of the buffer content
*/
*
* @return the hash value of the buffer content
*/
-static unsigned buf_hash(const CODE_BUFFER *buf) {
+static unsigned buf_hash(const CODE_BUFFER *buf)
+{
return buf->hash;
} /* buf_hash */
return buf->hash;
} /* buf_hash */
@@
-223,7
+230,8
@@
static unsigned buf_hash(const CODE_BUFFER *buf) {
*
* @param buf the code buffer
*/
*
* @param buf the code buffer
*/
-static unsigned buf_overrun(const CODE_BUFFER *buf) {
+static unsigned buf_overrun(const CODE_BUFFER *buf)
+{
return buf->overrun;
} /* buf_overrun */
return buf->overrun;
} /* buf_overrun */
@@
-234,7
+242,8
@@
static unsigned buf_overrun(const CODE_BUFFER *buf) {
*
* @return the next byte from the code buffer
*/
*
* @return the next byte from the code buffer
*/
-static INLINE BYTE look_byte(CODE_BUFFER *buf) {
+static inline BYTE look_byte(CODE_BUFFER *buf)
+{
if (buf->next < buf->end)
return *buf->next;
return VLC_TAG_END;
if (buf->next < buf->end)
return *buf->next;
return VLC_TAG_END;
@@
-247,7
+256,8
@@
static INLINE BYTE look_byte(CODE_BUFFER *buf) {
*
* @return the next byte from the code buffer
*/
*
* @return the next byte from the code buffer
*/
-static INLINE BYTE get_byte(CODE_BUFFER *buf) {
+static inline BYTE get_byte(CODE_BUFFER *buf)
+{
if (buf->next < buf->end)
return *buf->next++;
return VLC_TAG_END;
if (buf->next < buf->end)
return *buf->next++;
return VLC_TAG_END;
@@
-261,7
+271,8
@@
static INLINE BYTE get_byte(CODE_BUFFER *buf) {
* @param buf the code buffer
* @param code the code to be written into the buffer
*/
* @param buf the code buffer
* @param code the code to be written into the buffer
*/
-static void put_code(CODE_BUFFER *buf, unsigned code) {
+static void put_code(CODE_BUFFER *buf, unsigned code)
+{
if (code < BITS(7)) {
put_byte(buf, VLC_7BIT | code);
} else if (code < BITS(6 + 8)) {
if (code < BITS(7)) {
put_byte(buf, VLC_7BIT | code);
} else if (code < BITS(6 + 8)) {
@@
-294,7
+305,8
@@
static void put_code(CODE_BUFFER *buf, unsigned code) {
*
* @return next 32bit value from the code buffer
*/
*
* @return next 32bit value from the code buffer
*/
-static unsigned get_code(CODE_BUFFER *buf) {
+static unsigned get_code(CODE_BUFFER *buf)
+{
unsigned code = get_byte(buf);
if (code < VLC_14BIT)
unsigned code = get_byte(buf);
if (code < VLC_14BIT)
@@
-320,9
+332,7
@@
static unsigned get_code(CODE_BUFFER *buf) {
return code;
} /* if */
/* should not happen */
return code;
} /* if */
/* should not happen */
- assert(0 && "Wrong code in buffer");
-
- return 0;
+ panic("Wrong code in buffer");
} /* get_code */
/**
} /* get_code */
/**
@@
-331,7
+341,8
@@
static unsigned get_code(CODE_BUFFER *buf) {
* @param buf the code buffer
* @param tag the tag to write to the code buffer
*/
* @param buf the code buffer
* @param tag the tag to write to the code buffer
*/
-static void put_tag(CODE_BUFFER *buf, BYTE tag) {
+static void put_tag(CODE_BUFFER *buf, BYTE tag)
+{
assert(tag >= VLC_TAG_FIRST && "invalid tag");
put_byte(buf, tag);
assert(tag >= VLC_TAG_FIRST && "invalid tag");
put_byte(buf, tag);
@@
-344,7
+355,8
@@
static void put_tag(CODE_BUFFER *buf, BYTE tag) {
*
* @return the next tag in the code buffer
*/
*
* @return the next tag in the code buffer
*/
-static BYTE next_tag(CODE_BUFFER *buf) {
+static BYTE next_tag(CODE_BUFFER *buf)
+{
BYTE b = look_byte(buf);
if (b >= VLC_TAG_FIRST)
BYTE b = look_byte(buf);
if (b >= VLC_TAG_FIRST)
@@
-355,7
+367,7
@@
static BYTE next_tag(CODE_BUFFER *buf) {
/**
* An Environment for the pattern encoder.
*/
/**
* An Environment for the pattern encoder.
*/
-typedef struct
_
codec_enc_t {
+typedef struct codec_enc_t {
CODE_BUFFER *buf; /**< The current code buffer. */
set *id_set; /**< A set containing all already seen Firm nodes. */
unsigned curr_id; /**< The current node id. */
CODE_BUFFER *buf; /**< The current code buffer. */
set *id_set; /**< A set containing all already seen Firm nodes. */
unsigned curr_id; /**< The current node id. */
@@
-366,7
+378,7
@@
typedef struct _codec_enc_t {
/**
* An address entry.
*/
/**
* An address entry.
*/
-typedef struct
_
addr_entry_t {
+typedef struct addr_entry_t {
void *addr; /**< the address */
unsigned id; /**< associated ID */
} addr_entry_t;
void *addr; /**< the address */
unsigned id; /**< associated ID */
} addr_entry_t;
@@
-374,7
+386,8
@@
typedef struct _addr_entry_t {
/**
* Compare two addresses.
*/
/**
* Compare two addresses.
*/
-static int addr_cmp(const void *p1, const void *p2, size_t size) {
+static int addr_cmp(const void *p1, const void *p2, size_t size)
+{
const addr_entry_t *e1 = p1;
const addr_entry_t *e2 = p2;
(void) size;
const addr_entry_t *e1 = p1;
const addr_entry_t *e2 = p2;
(void) size;
@@
-382,12
+395,25
@@
static int addr_cmp(const void *p1, const void *p2, size_t size) {
return e1->addr != e2->addr;
} /* addr_cmp */
return e1->addr != e2->addr;
} /* addr_cmp */
+static unsigned find_mode_index(const ir_mode *mode)
+{
+ int n = get_irp_n_modes();
+ int i;
+
+ for (i = 0; i < n; ++i) {
+ if (get_irp_mode(i) == mode)
+ return i;
+ }
+ return -1;
+}
+
/**
* Encodes an IR-node, recursive worker.
*
* @return reached depth
*/
/**
* Encodes an IR-node, recursive worker.
*
* @return reached depth
*/
-static int _encode_node(ir_node *node, int max_depth, codec_env_t *env) {
+static int _encode_node(ir_node *node, int max_depth, codec_env_t *env)
+{
addr_entry_t entry, *r_entry;
set_entry *s_entry;
int i, preds;
addr_entry_t entry, *r_entry;
set_entry *s_entry;
int i, preds;
@@
-420,8
+446,7
@@
static int _encode_node(ir_node *node, int max_depth, codec_env_t *env) {
ir_mode *mode = get_irn_mode(node);
if (mode)
ir_mode *mode = get_irn_mode(node);
if (mode)
- /* FIXME: not 64bit save */
- put_code(env->buf, (unsigned)mode);
+ put_code(env->buf, find_mode_index(mode));
else
put_tag(env->buf, VLC_TAG_EMPTY);
} /* if */
else
put_tag(env->buf, VLC_TAG_EMPTY);
} /* if */
@@
-429,7
+454,7
@@
static int _encode_node(ir_node *node, int max_depth, codec_env_t *env) {
/* do we need integer constants */
if (env->options & OPT_WITH_ICONST) {
if (code == iro_Const) {
/* do we need integer constants */
if (env->options & OPT_WITH_ICONST) {
if (code == iro_Const) {
- tarval *tv = get_Const_tarval(node);
+
ir_
tarval *tv = get_Const_tarval(node);
if (tarval_is_long(tv)) {
long v = get_tarval_long(tv);
if (tarval_is_long(tv)) {
long v = get_tarval_long(tv);
@@
-493,7
+518,8
@@
static int _encode_node(ir_node *node, int max_depth, codec_env_t *env) {
*
* @return The depth of the encoded graph (without cycles)
*/
*
* @return The depth of the encoded graph (without cycles)
*/
-static int encode_node(ir_node *node, CODE_BUFFER *buf, int max_depth) {
+static int encode_node(ir_node *node, CODE_BUFFER *buf, int max_depth)
+{
codec_env_t env;
int res;
codec_env_t env;
int res;
@@
-525,7
+551,8
@@
static int encode_node(ir_node *node, CODE_BUFFER *buf, int max_depth) {
/**
* Decode an IR-node, recursive walker.
*/
/**
* Decode an IR-node, recursive walker.
*/
-static void _decode_node(unsigned parent, int position, codec_env_t *env) {
+static void _decode_node(unsigned parent, int position, codec_env_t *env)
+{
unsigned code;
unsigned op_code;
unsigned mode_code = 0;
unsigned code;
unsigned op_code;
unsigned mode_code = 0;
@@
-607,7
+634,8
@@
static void _decode_node(unsigned parent, int position, codec_env_t *env) {
/**
* Decode an IR-node.
*/
/**
* Decode an IR-node.
*/
-static void decode_node(BYTE *b, unsigned len, pattern_dumper_t *dump) {
+static void decode_node(BYTE *b, unsigned len, pattern_dumper_t *dump)
+{
codec_env_t env;
CODE_BUFFER buf;
unsigned code, options = 0;
codec_env_t env;
CODE_BUFFER buf;
unsigned code, options = 0;
@@
-631,7
+659,7
@@
static void decode_node(BYTE *b, unsigned len, pattern_dumper_t *dump) {
/**
* The environment for the pattern calculation.
*/
/**
* The environment for the pattern calculation.
*/
-typedef struct
_
pattern_env {
+typedef struct pattern_env {
int max_depth; /**< maximum depth for pattern generation. */
} pattern_env_t;
int max_depth; /**< maximum depth for pattern generation. */
} pattern_env_t;
@@
-646,14
+674,13
@@
typedef struct _pattern_env {
* If the code content was never seen before, a new pattern_entry is created
* and returned.
*/
* If the code content was never seen before, a new pattern_entry is created
* and returned.
*/
-static pattern_entry_t *pattern_get_entry(CODE_BUFFER *buf, pset *set) {
+static pattern_entry_t *pattern_get_entry(CODE_BUFFER *buf, pset *set)
+{
pattern_entry_t *key, *elem;
unsigned len = buf_lenght(buf);
unsigned hash;
pattern_entry_t *key, *elem;
unsigned len = buf_lenght(buf);
unsigned hash;
- key = obstack_alloc(&status->obst, offsetof(pattern_entry_t, buf) + len);
- assert(key);
-
+ key = OALLOCF(&status->obst, pattern_entry_t, buf, len);
key->len = len;
memcpy(key->buf, buf_content(buf), len);
key->len = len;
memcpy(key->buf, buf_content(buf), len);
@@
-677,7
+704,8
@@
static pattern_entry_t *pattern_get_entry(CODE_BUFFER *buf, pset *set) {
*
* @note Single node patterns are ignored
*/
*
* @note Single node patterns are ignored
*/
-static void count_pattern(CODE_BUFFER *buf, int depth) {
+static void count_pattern(CODE_BUFFER *buf, int depth)
+{
pattern_entry_t *entry;
/* ignore single node pattern (i.e. constants) */
pattern_entry_t *entry;
/* ignore single node pattern (i.e. constants) */
@@
-692,7
+720,8
@@
static void count_pattern(CODE_BUFFER *buf, int depth) {
/**
* Pre-walker for nodes pattern calculation.
*/
/**
* Pre-walker for nodes pattern calculation.
*/
-static void calc_nodes_pattern(ir_node *node, void *ctx) {
+static void calc_nodes_pattern(ir_node *node, void *ctx)
+{
pattern_env_t *env = ctx;
BYTE buffer[PATTERN_STORE_SIZE];
CODE_BUFFER buf;
pattern_env_t *env = ctx;
BYTE buffer[PATTERN_STORE_SIZE];
CODE_BUFFER buf;
@@
-712,7
+741,8
@@
static void calc_nodes_pattern(ir_node *node, void *ctx) {
*
* @param fname filename for storage
*/
*
* @param fname filename for storage
*/
-static void store_pattern(const char *fname) {
+static void store_pattern(const char *fname)
+{
FILE *f;
pattern_entry_t *entry;
int i, count = pset_count(status->pattern_hash);
FILE *f;
pattern_entry_t *entry;
int i, count = pset_count(status->pattern_hash);
@@
-742,7
+772,8
@@
static void store_pattern(const char *fname) {
*
* @param fname filename
*/
*
* @param fname filename
*/
-static HASH_MAP(pattern_entry_t) *read_pattern(const char *fname) {
+static HASH_MAP(pattern_entry_t) *read_pattern(const char *fname)
+{
FILE *f;
pattern_entry_t *entry, tmp;
int i, count;
FILE *f;
pattern_entry_t *entry, tmp;
int i, count;
@@
-789,7
+820,8
@@
static HASH_MAP(pattern_entry_t) *read_pattern(const char *fname) {
*
* @param fname name of the VCG file to create
*/
*
* @param fname name of the VCG file to create
*/
-static void pattern_output(const char *fname) {
+static void pattern_output(const char *fname)
+{
pattern_entry_t *entry;
pattern_entry_t **pattern_arr;
pattern_dumper_t *dump;
pattern_entry_t *entry;
pattern_entry_t **pattern_arr;
pattern_dumper_t *dump;
@@
-803,7
+835,7
@@
static void pattern_output(const char *fname) {
/* creates a dumper */
dump = new_vcg_dumper(fname, 100);
/* creates a dumper */
dump = new_vcg_dumper(fname, 100);
- pattern_arr =
xmalloc(sizeof(*pattern_arr) *
count);
+ pattern_arr =
XMALLOCN(pattern_entry_t*,
count);
for (i = 0, entry = pset_first(status->pattern_hash);
entry && i < count;
entry = pset_next(status->pattern_hash), ++i) {
for (i = 0, entry = pset_first(status->pattern_hash);
entry && i < count;
entry = pset_next(status->pattern_hash), ++i) {
@@
-833,7
+865,8
@@
static void pattern_output(const char *fname) {
/*
* Calculates the pattern history.
*/
/*
* Calculates the pattern history.
*/
-void stat_calc_pattern_history(ir_graph *irg) {
+void stat_calc_pattern_history(ir_graph *irg)
+{
pattern_env_t env;
unsigned i;
pattern_env_t env;
unsigned i;
@@
-853,7
+886,8
@@
void stat_calc_pattern_history(ir_graph *irg) {
/*
* Initializes the pattern history.
*/
/*
* Initializes the pattern history.
*/
-void stat_init_pattern_history(int enable) {
+void stat_init_pattern_history(int enable)
+{
HASH_MAP(pattern_entry_t) *pattern_hash = NULL;
status->enable = enable;
HASH_MAP(pattern_entry_t) *pattern_hash = NULL;
status->enable = enable;
@@
-878,7
+912,8
@@
void stat_init_pattern_history(int enable) {
/*
* Finish the pattern history.
*/
/*
* Finish the pattern history.
*/
-void stat_finish_pattern_history(const char *fname) {
+void stat_finish_pattern_history(const char *fname)
+{
(void) fname;
if (! status->enable)
return;
(void) fname;
if (! status->enable)
return;