be_lower_for_target is now a simple function in the public API
[libfirm] / ir / stat / pattern.c
index d8fb9c8..fa8fcde 100644 (file)
@@ -29,6 +29,7 @@
 #include <stdlib.h>
 #include <limits.h>
 
+#include "pattern.h"
 #include "ident.h"
 #include "irnode_t.h"
 #include "irgwalk.h"
@@ -38,6 +39,7 @@
 #include "counter.h"
 #include "pattern_dmp.h"
 #include "hashptr.h"
+#include "error.h"
 
 #ifdef FIRM_STATISTICS
 
@@ -52,13 +54,13 @@ typedef pset pset_pattern_entry_t;
 typedef unsigned char BYTE;
 
 /** Maximum size of the pattern store. */
-#define PATTERN_STORE_SIZE     2048
+#define PATTERN_STORE_SIZE    2048
 
 
 /**
  * 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. */
@@ -87,7 +89,7 @@ enum vlc_code_t {
 /*
  * 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. */
@@ -107,7 +109,7 @@ enum options_t {
 /**
  * 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. */
@@ -143,8 +145,8 @@ static int pattern_count_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;
+       const pattern_entry_t *e1 = (const pattern_entry_t*)elt;
+       const pattern_entry_t *e2 = (const pattern_entry_t*)key;
        int diff = e1->len - e2->len;
 
        if (diff)
@@ -330,9 +332,7 @@ static unsigned get_code(CODE_BUFFER *buf)
                return code;
        }  /* if */
        /* should not happen */
-       assert(0 && "Wrong code in buffer");
-
-       return 0;
+       panic("Wrong code in buffer");
 }  /* get_code */
 
 /**
@@ -367,7 +367,7 @@ static BYTE next_tag(CODE_BUFFER *buf)
 /**
  * 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. */
@@ -378,7 +378,7 @@ typedef struct _codec_enc_t {
 /**
  * An address entry.
  */
-typedef struct _addr_entry_t {
+typedef struct addr_entry_t {
        void *addr;     /**< the address */
        unsigned id;    /**< associated ID */
 } addr_entry_t;
@@ -388,13 +388,25 @@ typedef struct _addr_entry_t {
  */
 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;
+       const addr_entry_t *e1 = (const addr_entry_t*)p1;
+       const addr_entry_t *e2 = (const addr_entry_t*)p2;
        (void) size;
 
        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.
  *
@@ -407,7 +419,7 @@ static int _encode_node(ir_node *node, int max_depth, codec_env_t *env)
        int i, preds;
        int res, depth;
 
-       ir_opcode code = get_irn_opcode(node);
+       unsigned code = get_irn_opcode(node);
 
        /* insert the node into our ID map */
        entry.addr = node;
@@ -434,7 +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)
-                       put_code(env->buf, stat_find_mode_index(mode));
+                       put_code(env->buf, find_mode_index(mode));
                else
                        put_tag(env->buf, VLC_TAG_EMPTY);
        }  /* if */
@@ -442,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) {
-                       tarval *tv = get_Const_tarval(node);
+                       ir_tarval *tv = get_Const_tarval(node);
 
                        if (tarval_is_long(tv)) {
                                long v = get_tarval_long(tv);
@@ -647,7 +659,7 @@ static void decode_node(BYTE *b, unsigned len, pattern_dumper_t *dump)
 /**
  * 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;
 
@@ -674,14 +686,14 @@ static pattern_entry_t *pattern_get_entry(CODE_BUFFER *buf, pset *set)
 
        hash = buf_hash(buf);
 
-       elem = pset_find(set, key, hash);
+       elem = (pattern_entry_t*)pset_find(set, key, hash);
        if (elem != NULL) {
                obstack_free(&status->obst, key);
                return elem;
        }  /* if */
 
        cnt_clr(&key->count);
-       return pset_insert(set, key, hash);
+       return (pattern_entry_t*)pset_insert(set, key, hash);
 }  /* pattern_get_entry */
 
 /**
@@ -710,7 +722,7 @@ static void count_pattern(CODE_BUFFER *buf, int depth)
  */
 static void calc_nodes_pattern(ir_node *node, void *ctx)
 {
-       pattern_env_t   *env = ctx;
+       pattern_env_t   *env = (pattern_env_t*)ctx;
        BYTE            buffer[PATTERN_STORE_SIZE];
        CODE_BUFFER     buf;
        int             depth;
@@ -747,9 +759,9 @@ static void store_pattern(const char *fname)
        fwrite("FPS1", 4, 1, f);
        fwrite(&count, sizeof(count), 1, f);
 
-       for (i = 0, entry = pset_first(status->pattern_hash);
+       for (i = 0, entry = (pattern_entry_t*)pset_first(status->pattern_hash);
             entry && i < count;
-            entry = pset_next(status->pattern_hash), ++i) {
+            entry = (pattern_entry_t*)pset_next(status->pattern_hash), ++i) {
                fwrite(entry, offsetof(pattern_entry_t, buf) + entry->len, 1, f);
        }  /* for */
        fclose(f);
@@ -824,9 +836,9 @@ static void pattern_output(const char *fname)
        dump = new_vcg_dumper(fname, 100);
 
        pattern_arr = XMALLOCN(pattern_entry_t*, count);
-       for (i = 0, entry = pset_first(status->pattern_hash);
+       for (i = 0, entry = (pattern_entry_t*)pset_first(status->pattern_hash);
             entry && i < count;
-            entry = pset_next(status->pattern_hash), ++i) {
+            entry = (pattern_entry_t*)pset_next(status->pattern_hash), ++i) {
                pattern_arr[i] =  entry;
        }  /* for */
        assert(count == i);