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"
35 #include <libcore/lc_bitset.h>
39 #include "besched_t.h"
44 #include "bespillremat.h"
46 #include "bepressurestat.h"
48 #include "bechordal_t.h"
56 typedef struct _spill_cost_t {
57 const be_chordal_env_t *chordal_env;
59 DEBUG_ONLY(firm_dbg_module_t *dbg);
63 execution_frequency(const be_chordal_env_t * chordal_env, const ir_node * irn)
66 #ifndef EXECFREQ_LOOPDEPH
67 return get_block_execfreq(chordal_env->exec_freq, get_block(irn)) + FUDGE;
70 return exp(get_loop_depth(get_irn_loop(irn)) * log(10)) + FUDGE;
72 return exp(get_loop_depth(get_irn_loop(get_nodes_block(irn))) * log(10)) + FUDGE;
78 get_cost(const be_chordal_env_t * chordal_env, const ir_node * irn)
80 if(be_is_Spill(irn)) {
82 } else if(be_is_Reload(irn)){
85 return arch_get_op_estimated_cost(chordal_env->birg->main_env->arch_env, irn);
91 walker_cost_collector(ir_node * irn, void * data)
93 spill_cost_t *sc = data;
96 if( (be_is_Reload(irn) && chordal_has_class(sc->chordal_env, irn)) ||
97 (be_is_Spill(irn) && chordal_has_class(sc->chordal_env, get_irn_n(irn,1)))) {
99 freq = execution_frequency(sc->chordal_env, irn);
100 cost = get_cost(sc->chordal_env, irn);
102 DBG((sc->dbg, LEVEL_2, "%+F has cost %g with execfreq %g ->\t %g\n", irn, cost, freq, cost*freq));
104 sc->cost += cost*freq;
109 get_irg_spill_cost(const be_chordal_env_t * chordal_env)
112 char problem_name[256];
114 ir_snprintf(problem_name, sizeof(problem_name), "%F_%s", chordal_env->irg, chordal_env->cls->name);
117 sc.chordal_env = chordal_env;
118 FIRM_DBG_REGISTER(sc.dbg, "firm.be.ra.spillcost");
120 DBG((sc.dbg, LEVEL_2, "computing spill costs for %s\n", problem_name));
121 irg_walk_graph(chordal_env->irg, walker_cost_collector, NULL, &sc);
122 DBG((sc.dbg, LEVEL_1, "spill costs for %s: %g\n", problem_name, sc.cost));
123 DBG((sc.dbg, LEVEL_2, "\n"));