-/**
- * Environment for each of the chordal register allocator phases
- */
-typedef struct _env_t {
- struct obstack obst; /**< An obstack for temporary storage. */
- ir_graph *irg; /**< The graph the reg alloc is running on. */
-#ifdef BUILD_GRAPH
- set *nodes; /**< The interference graph nodes. */
- set *edges; /**< The interference graph edges. */
-#endif
-
- bitset_t *live; /**< A liveness bitset. */
- bitset_t *colors; /**< The color mask. */
- bitset_t *in_colors; /**< Colors used by live in values. */
- int colors_n; /**< The number of colors. */
- const arch_env_t *arch_env; /**< The arch interface environment. */
- const arch_register_class_t *cls; /**< The current register class. */
- void *data; /**< Some pointer, to which different
- phases can attach data to. */
-} env_t;
-
-
-typedef struct _be_chordal_dump_params_t {
- int x_dist;
- int y_dist;
- double font_scale;
-} be_chordal_dump_params_t;
-
-static const be_chordal_dump_params_t dump_params = {
- 10,
- 10,
- 4
-};
-
-#ifdef DUMP_INTERVALS
-
-static INLINE void intv_filename(char *s, size_t n,
- const env_t *env, ir_node *block)
-{
- ir_snprintf(s, n, "intv_%F_%s_bl%N.eps",
- env->irg, env->cls->name, block);
-}
-
-static void draw_interval_graph(const env_t *env,
- ir_node *block, const be_chordal_dump_params_t *params)
-{
- int i;
- int x_dist = params->x_dist;
- int y_dist = params->y_dist;
- ir_graph *irg = env->irg;
- struct list_head *border_head = get_block_border_head(block);
-
- FILE *f;
- char buf[1024];
-
- intv_filename(buf, sizeof(buf), env, block);
-
- if((f = fopen(buf, "wt")) != NULL) {
- border_t *b;
- int *seen = xcalloc(get_graph_node_count(irg), sizeof(seen[0]));
- int last_pos = list_empty(border_head) ? 0 : list_entry(border_head->prev, border_t, list)->step;
- int max_col = 0;
-
- list_for_each_entry_reverse(border_t, b, border_head, list) {
- const ir_node *irn = b->irn;
- int col = get_irn_color(irn);
- max_col = max_col > col ? max_col : col;
- }
-
- fprintf(f, "%%!PS-Adobe-2.0\n");
- fprintf(f, "%%%%BoundingBox: -10 -10 %d %d\n",
- x_dist * last_pos + x_dist, y_dist * max_col + y_dist);
- fprintf(f, "/mainfont /Courier findfont %f scalefont def\n", params->font_scale);
- fprintf(f, "mainfont setfont\n");
- fprintf(f, "0.2 setlinewidth\n");
-
- for(i = 0; i <= last_pos; ++i) {
- fprintf(f, "0 0 0 setrgbcolor\n");
- fprintf(f, "%d %d moveto\n", i * x_dist, -2);
- fprintf(f, "%d %d lineto\n", i * x_dist, max_col * y_dist + 2);
- fprintf(f, "stroke\n");
- }
- fprintf(f, "0.5 setlinewidth\n");
-
- list_for_each_entry_reverse(border_t, b, border_head, list) {
- const ir_node *irn = b->irn;
- int nr = get_irn_graph_nr(irn);
-
- if(b->is_def)
- seen[nr] = b->step;
- else {
- int col = get_irn_color(irn);
-
- int pos = last_pos - seen[nr];
- int end_pos = last_pos - b->step;
- int live_in = is_live_in(block, irn);
- int live_end = is_live_end(block, irn);
- int y_val = y_dist * col;
-
- int red = 0;
- int green = live_end;
- int blue = live_in;
-
- fprintf(f, "0 0 0 setrgbcolor\n");
- fprintf(f, "%d %d moveto\n", x_dist * pos + 2, y_val + 2);
- ir_fprintf(f, "(%n/%d%s) show\n", irn, nr, is_phi_operand(irn) ? "*" : "");
- fprintf(f, "%d %d %d setrgbcolor\n", red, green, blue);
- fprintf(f, "%d %d moveto\n", x_dist * pos, y_val);
- fprintf(f, "%d %d lineto\n", (x_dist * end_pos) - 5, y_val);
- fprintf(f, "stroke\n");
- }
- }
-
- free(seen);
- fclose(f);
- }
-}
-
-static void dump_block(ir_node *bl, void *data)
-{
- const env_t *env = data;
- FILE *f = env->data;
- char buf[128];
-
- draw_interval_graph(env, bl, &dump_params);
-
- intv_filename(buf, sizeof(buf), env, bl);
- ir_fprintf(f, "\tb%N [shape=\"epsf\" shapefile=\"%s\"];\n", bl, buf);
-}
-
-static void dump_edges(ir_node *bl, void *data)
-{
- const env_t *env = data;
- FILE *f = env->data;
- int i, n;
- ir_node *dom;
-
-#if 0
- for(i = 0, n = get_irn_arity(bl); i < n; ++i) {
- ir_node *pred = get_irn_n(bl, i);
- ir_fprintf(f, "\tb%N -> b%N;\n", get_nodes_block(pred), bl);
- }
-#endif
-
- for(dom = get_Block_dominated_first(bl); dom;
- dom = get_Block_dominated_next(dom)) {
-
- ir_fprintf(f, "\tb%N -> b%N;\n", dom, bl);
- }
-}
-
-static void dump_intv_cfg(env_t *env)
-{
- FILE *f;
- char buf[128];
-
- ir_snprintf(buf, sizeof(buf), "intv_cfg_%s_%F.dot",
- env->cls->name, env->irg);
-
- if((f = fopen(buf, "wt")) != NULL) {
- void *old_data = env->data;
-
- env->data = f;
- ir_fprintf(f, "digraph G {\n");
- ir_fprintf(f, "\tgraph [rankdir=\"LR\", ordering=\"out\"];\n");
- dom_tree_walk_irg(env->irg, dump_block, dump_edges, env);
- // irg_block_walk_graph(env->irg, dump_block, dump_edges, env);
- ir_fprintf(f, "}\n");
- fclose(f);
-
- env->data = old_data;
- }
-}
-
-#endif
-