Further push size_t.
[libfirm] / ir / be / becopystat.c
index c7e6652..d3447c4 100644 (file)
@@ -61,23 +61,23 @@ enum vals_t {
        I_BLOCKS,
 
        /* phi nodes */
-       I_PHI_CNT,                      /* number of phi nodes */
-       I_PHI_ARG_CNT,          /* number of arguments of phis */
-       I_PHI_ARG_SELF,         /* number of arguments of phis being the phi itself */
-       I_PHI_ARG_CONST,        /* number of arguments of phis being consts */
-       I_PHI_ARG_PRED,         /* ... being defined in a cf-pred */
-       I_PHI_ARG_GLOB,         /* ... being defined elsewhere */
+       I_PHI_CNT,          /* number of phi nodes */
+       I_PHI_ARG_CNT,      /* number of arguments of phis */
+       I_PHI_ARG_SELF,     /* number of arguments of phis being the phi itself */
+       I_PHI_ARG_CONST,    /* number of arguments of phis being consts */
+       I_PHI_ARG_PRED,     /* ... being defined in a cf-pred */
+       I_PHI_ARG_GLOB,     /* ... being defined elsewhere */
        I_PHI_ARITY_S,
        I_PHI_ARITY_E    = I_PHI_ARITY_S+MAX_ARITY,
 
        /* copy nodes */
-       I_CPY_CNT,                      /* number of copynodes */
+       I_CPY_CNT,          /* number of copynodes */
 
        /* phi classes */
-       I_CLS_CNT,                      /* number of phi classes */
-       I_CLS_IF_FREE,          /* number of pc having no interference */
-       I_CLS_IF_MAX,           /* number of possible interferences in all classes */
-       I_CLS_IF_CNT,           /* number of actual interferences in all classes */
+       I_CLS_CNT,          /* number of phi classes */
+       I_CLS_IF_FREE,      /* number of pc having no interference */
+       I_CLS_IF_MAX,       /* number of possible interferences in all classes */
+       I_CLS_IF_CNT,       /* number of actual interferences in all classes */
        I_CLS_SIZE_S,
        I_CLS_SIZE_E = I_CLS_SIZE_S+MAX_CLS_SIZE,
        I_CLS_PHIS_S,
@@ -87,20 +87,20 @@ enum vals_t {
        /* all of them are external set */
 
        /* ilp values */
-       I_HEUR_TIME,            /* solving time in milli seconds */
-       I_ILP_TIME,                     /* solving time in milli seconds */
+       I_HEUR_TIME,        /* solving time in milli seconds */
+       I_ILP_TIME,         /* solving time in milli seconds */
        I_ILP_VARS,
        I_ILP_CSTR,
-       I_ILP_ITER,                     /* number of simplex iterations */
+       I_ILP_ITER,         /* number of simplex iterations */
 
        /* copy instructions */
-       I_COPIES_MAX,           /* max possible costs of copies*/
-       I_COPIES_INIT,          /* number of copies in initial allocation */
-       I_COPIES_HEUR,          /* number of copies after heuristic */
-       I_COPIES_5SEC,          /* number of copies after ilp with max n sec */
-       I_COPIES_30SEC,         /* number of copies after ilp with max n sec */
-       I_COPIES_OPT,           /* number of copies after ilp */
-       I_COPIES_IF,            /* number of copies inevitable due to root-arg-interf */
+       I_COPIES_MAX,       /* max possible costs of copies*/
+       I_COPIES_INIT,      /* number of copies in initial allocation */
+       I_COPIES_HEUR,      /* number of copies after heuristic */
+       I_COPIES_5SEC,      /* number of copies after ilp with max n sec */
+       I_COPIES_30SEC,     /* number of copies after ilp with max n sec */
+       I_COPIES_OPT,       /* number of copies after ilp */
+       I_COPIES_IF,        /* number of copies inevitable due to root-arg-interf */
 
        ASIZE
 };
@@ -113,26 +113,35 @@ int curr_vals[ASIZE];
 static ir_nodeset_t *all_phi_nodes;
 static ir_nodeset_t *all_copy_nodes;
 
-void be_init_copystat(void) {
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_copystat)
+void be_init_copystat(void)
+{
        FIRM_DBG_REGISTER(dbg, "firm.be.copystat");
 
        all_phi_nodes  = ir_nodeset_new(64);
        all_copy_nodes = ir_nodeset_new(64);
        memset(curr_vals, 0, sizeof(curr_vals));
 }
-BE_REGISTER_MODULE_CONSTRUCTOR(be_init_copystat);
 
-void be_quit_copystat(void) {
-       ir_nodeset_del(all_phi_nodes);
-       ir_nodeset_del(all_copy_nodes);
+BE_REGISTER_MODULE_DESTRUCTOR(be_quit_copystat)
+void be_quit_copystat(void)
+{
+       if (all_phi_nodes != NULL) {
+               ir_nodeset_del(all_phi_nodes);
+               all_phi_nodes = NULL;
+       }
+       if (all_copy_nodes != NULL) {
+               ir_nodeset_del(all_copy_nodes);
+               all_copy_nodes = NULL;
+       }
 }
-BE_REGISTER_MODULE_DESTRUCTOR(be_quit_copystat);
 
 /**
  * @return 1 if the block at pos @p pos removed a critical edge
- *                0 else
+ *         0 else
  */
-static inline int was_edge_critical(const ir_node *bl, int pos) {
+static inline int was_edge_critical(const ir_node *bl, int pos)
+{
        const ir_edge_t *edge;
        const ir_node *bl_at_pos, *bl_before;
        assert(is_Block(bl));
@@ -152,49 +161,79 @@ static inline int was_edge_critical(const ir_node *bl, int pos) {
        return get_block_succ_next(bl_before, edge) ? 1 : 0;
 }
 
-void copystat_add_max_costs(int costs) {
+void copystat_add_max_costs(int costs)
+{
        curr_vals[I_COPIES_MAX] += costs;
 }
-void copystat_add_inevit_costs(int costs) {
+void copystat_add_inevit_costs(int costs)
+{
        curr_vals[I_COPIES_IF] += costs;
 }
-void copystat_add_init_costs(int costs) {
+void copystat_add_init_costs(int costs)
+{
        curr_vals[I_COPIES_INIT] += costs;
 }
-void copystat_add_heur_costs(int costs) {
+void copystat_add_heur_costs(int costs)
+{
        curr_vals[I_COPIES_HEUR] += costs;
 }
-void copystat_add_ilp_5_sec_costs(int costs) {
-       curr_vals[I_COPIES_5SEC] += costs;
-}
-void copystat_add_ilp_30_sec_costs(int costs) {
-       curr_vals[I_COPIES_30SEC] += costs;
-}
-void copystat_add_opt_costs(int costs) {
+void copystat_add_opt_costs(int costs)
+{
        curr_vals[I_COPIES_OPT] += costs;
 }
-void copystat_add_heur_time(int time) {
+void copystat_add_heur_time(int time)
+{
        curr_vals[I_HEUR_TIME] += time;
 }
 
 #ifdef WITH_ILP
 
-void copystat_add_ilp_time(int time) {
+void copystat_add_ilp_5_sec_costs(int costs)
+{
+       curr_vals[I_COPIES_5SEC] += costs;
+}
+void copystat_add_ilp_30_sec_costs(int costs)
+{
+       curr_vals[I_COPIES_30SEC] += costs;
+}
+void copystat_add_ilp_time(int time)
+{
        curr_vals[I_ILP_TIME] += time;
 }
-void copystat_add_ilp_vars(int vars) {
+void copystat_add_ilp_vars(int vars)
+{
        curr_vals[I_ILP_VARS] += vars;
 }
-void copystat_add_ilp_csts(int csts) {
+void copystat_add_ilp_csts(int csts)
+{
        curr_vals[I_ILP_CSTR] += csts;
 }
-void copystat_add_ilp_iter(int iters) {
+void copystat_add_ilp_iter(int iters)
+{
        curr_vals[I_ILP_ITER] += iters;
 }
 
 #endif /* WITH_ILP */
 
-void copystat_dump(ir_graph *irg) {
+/**
+ * Opens a file named base.ext with the mode mode.
+ */
+static FILE *be_ffopen(const char *base, const char *ext, const char *mode)
+{
+       FILE *out;
+       char buf[1024];
+
+       snprintf(buf, sizeof(buf), "%s.%s", base, ext);
+       buf[sizeof(buf) - 1] = '\0';
+       if (! (out = fopen(buf, mode))) {
+               fprintf(stderr, "Cannot open file %s in mode %s\n", buf, mode);
+               return NULL;
+       }
+       return out;
+}
+
+void copystat_dump(ir_graph *irg)
+{
        int i;
        char buf[1024];
        FILE *out;
@@ -203,7 +242,7 @@ void copystat_dump(ir_graph *irg) {
        buf[sizeof(buf) - 1] = '\0';
        out = be_ffopen(buf, "stat", "wt");
 
-       fprintf(out, "%d\n", ASIZE);
+       fprintf(out, "%d\n", (int)ASIZE);
        for (i = 0; i < ASIZE; i++) {
 #if 0
                if (i >= I_PHI_ARITY_S && i <= I_PHI_ARITY_E)
@@ -218,7 +257,8 @@ void copystat_dump(ir_graph *irg) {
        fclose(out);
 }
 
-void copystat_dump_pretty(ir_graph *irg) {
+void copystat_dump_pretty(ir_graph *irg)
+{
        int i;
        char buf[1024];
        FILE *out;