summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMaximilian Stemmer-Grabow <mail@mxsg.de>2021-05-07 12:53:30 +0200
committerAndreas Fried <andreas.fried@kit.edu>2021-12-02 12:57:28 +0100
commitc461c7591b87a0ffc563e2aadaae93d95cd0942a (patch)
tree3156a299d06bc6c2e9d1791b57736dfa5175567d
parent480f593807cf97d451415e50d3fc77df7e1621f5 (diff)
Move scaling of compression-related affinity edges to copy opt heuristic
-rw-r--r--ir/be/becopyheur4.c31
-rw-r--r--ir/be/becopyopt.c51
2 files changed, 48 insertions, 34 deletions
diff --git a/ir/be/becopyheur4.c b/ir/be/becopyheur4.c
index 7c758ae..cb8fa92 100644
--- a/ir/be/becopyheur4.c
+++ b/ir/be/becopyheur4.c
@@ -54,8 +54,9 @@ static firm_dbg_module_t *dbg = NULL;
#endif
static unsigned last_chunk_id;
-static int recolor_limit = 7;
-static double dislike_influence = 0.1;
+static int recolor_limit = 7;
+static double dislike_influence = 0.1;
+static double compression_cost_scale = 0.1;
typedef struct col_cost_t {
unsigned col;
@@ -83,9 +84,11 @@ typedef struct aff_chunk_t {
* An affinity edge.
*/
typedef struct aff_edge_t {
- const ir_node *src; /**< Source node. */
- const ir_node *tgt; /**< Target node. */
- int weight; /**< The weight of this edge. */
+ const ir_node *src; /**< Source node. */
+ const ir_node *tgt; /**< Target node. */
+ int weight; /**< The weight of this edge. */
+ double original_weight; /**< The unscaled weight of this edge. */
+ aff_edge_type_t edge_type; /**< The type of affinity this edge describes. */
} aff_edge_t;
/* main coalescing environment */
@@ -118,6 +121,17 @@ typedef struct co_mst_irn_t {
bool fixed:1; /**< the color is fixed */
} co_mst_irn_t;
+static double scaled_edge_weight(const aff_edge_t * edge)
+{
+ double result = (double)edge->original_weight;
+
+ // Scale the weight down in case it is a compression-related edge
+ if(edge->edge_type == aff_edge_compression) {
+ result *= compression_cost_scale;
+ }
+ return result;
+}
+
/**
* In case there is no phase information for irn, initialize it.
*/
@@ -612,7 +626,10 @@ static void build_affinity_chunks(co_mst_env_t *env)
* these weights are pure hackery ;-).
* It's not chriswue's fault but mine.
*/
- edge.weight = neigh->costs;
+
+ edge.original_weight = neigh->costs;
+ edge.weight = MAX(1, edge.original_weight * compression_cost_scale);
+
ARR_APP1(aff_edge_t, edges, edge);
}
}
@@ -622,7 +639,7 @@ static void build_affinity_chunks(co_mst_env_t *env)
/* now: sort edges and build the affinity chunks */
QSORT_ARR(edges, cmp_aff_edge);
for (size_t i = 0, len = ARR_LEN(edges); i < len; ++i) {
- DBG((dbg, LEVEL_1, "edge (%u,%u) %f\n", edges[i].src->node_idx, edges[i].tgt->node_idx, edges[i].weight));
+ DBG((dbg, LEVEL_1, "edge (%u,%u) %f (original %f)\n", edges[i].src->node_idx, edges[i].tgt->node_idx, edges[i].weight, edges[i].original_weight));
aff_chunk_absorb(env, edges[i].src, edges[i].tgt);
}
diff --git a/ir/be/becopyopt.c b/ir/be/becopyopt.c
index 80d746d..6b82a22 100644
--- a/ir/be/becopyopt.c
+++ b/ir/be/becopyopt.c
@@ -599,34 +599,31 @@ static inline void add_edges(copy_opt_t *co, ir_node *n1, ir_node *n2, int costs
}
}
-#define COMPRESSION_COST_SCALE 0.1
-
-static void add_compression_req_edges(ir_node* irn, copy_opt_t *copyopt_env)
+static void add_compression_req_edges(ir_node *irn, copy_opt_t *copyopt_env)
{
- compression_reqs_fct_t comp_req_fct = copyopt_env->get_compression_reqs;
- if(!comp_req_fct) {
- // No compression requirements have been set, so we bail
- return;
- }
-
- int requirement = comp_req_fct(irn);
-
- switch(requirement) {
- case comp_req_2addr:
- case comp_req_2addr_register_subset: {
- // TODO This should be implemented in a way that allows other inputs to be associated.
- ir_node *src = get_irn_n(irn, 0);
-
- // TODO Should these costs be dependent on the dynamic costs which may be returned by get_costs?
- // TODO How do we allow for more fine-grained control over the costs in cases where the costs are low?
- int weight = MAX(1, (int)(copyopt_env->get_costs(irn, 0) * COMPRESSION_COST_SCALE));
- add_edges(copyopt_env, irn, src, weight, aff_edge_compression);
-
- break;
- }
- default:
- return;
- }
+ compression_reqs_fct_t comp_req_fct = copyopt_env->get_compression_reqs;
+ if (!comp_req_fct) {
+ // No compression requirements have been set, so we bail
+ return;
+ }
+
+ int requirement = comp_req_fct(irn);
+
+ switch (requirement) {
+ case comp_req_2addr:
+ case comp_req_2addr_register_subset: {
+ // TODO This should be implemented in a way that allows other inputs to be associated.
+ ir_node *src = get_irn_n(irn, 0);
+
+ // TODO Should these costs be dependent on the dynamic costs which may be returned by get_costs?
+ int weight = copyopt_env->get_costs(irn, 0);
+ add_edges(copyopt_env, irn, src, weight, aff_edge_compression);
+
+ break;
+ }
+ default:
+ return;
+ }
}
static void build_graph_walker(ir_node *irn, void *env)