1 /** vim: set sw=4 ts=4:
4 * @author Adam M. Szalkowski
6 * Spill cost estimation
8 * Copyright (C) 2006 Universitaet Karlsruhe
9 * Released under the GPL
30 #include "phiclass_t.h"
36 #include <lpp/lpp_net.h>
37 #include <lpp/lpp_cplex.h>
38 //#include <lc_pset.h>
39 #include <libcore/lc_bitset.h>
43 #include "besched_t.h"
48 #include "bespillremat.h"
50 #include "bepressurestat.h"
52 #include "bechordal_t.h"
60 typedef struct _spill_cost_t {
61 const be_chordal_env_t *chordal_env;
63 DEBUG_ONLY(firm_dbg_module_t *dbg);
67 execution_frequency(const be_chordal_env_t * chordal_env, const ir_node * irn)
70 #ifndef EXECFREQ_LOOPDEPH
71 return get_block_execfreq(chordal_env->exec_freq, get_block(irn)) + FUDGE;
74 return exp(get_loop_depth(get_irn_loop(irn)) * log(10)) + FUDGE;
76 return exp(get_loop_depth(get_irn_loop(get_nodes_block(irn))) * log(10)) + FUDGE;
82 get_cost(const be_chordal_env_t * chordal_env, const ir_node * irn)
84 if(be_is_Spill(irn)) {
86 } else if(be_is_Reload(irn)){
89 return arch_get_op_estimated_cost(chordal_env->birg->main_env->arch_env, irn);
95 walker_cost_collector(ir_node * irn, void * data)
97 spill_cost_t *sc = data;
100 if( (be_is_Reload(irn) && chordal_has_class(sc->chordal_env, irn)) ||
101 (be_is_Spill(irn) && chordal_has_class(sc->chordal_env, get_irn_n(irn,1)))) {
103 freq = execution_frequency(sc->chordal_env, irn);
104 cost = get_cost(sc->chordal_env, irn);
106 DBG((sc->dbg, LEVEL_2, "%+F has cost %g with execfreq %g ->\t %g\n", irn, cost, freq, cost*freq));
108 sc->cost += cost*freq;
113 get_irg_spill_cost(const be_chordal_env_t * chordal_env)
116 char problem_name[256];
118 ir_snprintf(problem_name, sizeof(problem_name), "%F_%s", chordal_env->irg, chordal_env->cls->name);
121 sc.chordal_env = chordal_env;
122 FIRM_DBG_REGISTER(sc.dbg, "firm.be.ra.spillcost");
124 DBG((sc.dbg, LEVEL_2, "computing spill costs for %s\n", problem_name));
125 irg_walk_graph(chordal_env->irg, walker_cost_collector, NULL, &sc);
126 DBG((sc.dbg, LEVEL_1, "spill costs for %s: %g\n", problem_name, sc.cost));
127 DBG((sc.dbg, LEVEL_2, "\n"));