*** empty log message ***
[libfirm] / ir / be / bechordal.c
1 /**
2  * Chordal register allocation.
3  * @author Sebastian Hack
4  * @date 8.12.2004
5  *
6  * Copyright (C) Universitaet Karlsruhe
7  * Released under the GPL
8  */
9
10 #ifdef HAVE_CONFIG_H
11 #include "config.h"
12 #endif
13
14 #ifdef HAVE_MALLOC_H
15 #include <malloc.h>
16 #endif
17
18 #ifdef HAVE_ALLOCA_H
19 #include <alloca.h>
20 #endif
21
22 #include <ctype.h>
23
24 #include "obst.h"
25 #include "pset.h"
26 #include "list.h"
27 #include "bitset.h"
28 #include "iterator.h"
29 #include "bipartite.h"
30
31 #include "irmode_t.h"
32 #include "irgraph_t.h"
33 #include "irprintf_t.h"
34 #include "irgwalk.h"
35 #include "irdump.h"
36 #include "irdom.h"
37 #include "debug.h"
38 #include "xmalloc.h"
39
40 #include "beutil.h"
41 #include "besched.h"
42 #include "benumb_t.h"
43 #include "besched_t.h"
44 #include "belive_t.h"
45 #include "benode_t.h"
46 #include "bearch.h"
47 #include "beifg.h"
48
49 #include "bechordal_t.h"
50 #include "bechordal_draw.h"
51
52 #define DBG_LEVEL SET_LEVEL_0
53 #define DBG_LEVEL_CHECK SET_LEVEL_0
54
55 #define NO_COLOR (-1)
56
57 #define DUMP_INTERVALS
58
59 typedef struct _be_chordal_alloc_env_t {
60         be_chordal_env_t *chordal_env;
61
62         pset *pre_colored;    /**< Set of precolored nodes. */
63         bitset_t *live;                         /**< A liveness bitset. */
64         bitset_t *colors;                       /**< The color mask. */
65         bitset_t *valid_colors;     /**< A mask of colors which shall be considered during allocation.
66                                                                      Registers with the ignore bit on, must not be considered. */
67         bitset_t *in_colors;        /**< Colors used by live in values. */
68         int colors_n;               /**< The number of colors. */
69 } be_chordal_alloc_env_t;
70
71 #include "fourcc.h"
72
73 /* Make a fourcc for border checking. */
74 #define BORDER_FOURCC                           FOURCC('B', 'O', 'R', 'D')
75
76 static void check_border_list(struct list_head *head)
77 {
78   border_t *x;
79   list_for_each_entry(border_t, x, head, list) {
80     assert(x->magic == BORDER_FOURCC);
81   }
82 }
83
84 static void check_heads(be_chordal_env_t *env)
85 {
86   pmap_entry *ent;
87   for(ent = pmap_first(env->border_heads); ent; ent = pmap_next(env->border_heads)) {
88     /* ir_printf("checking border list of block %+F\n", ent->key); */
89     check_border_list(ent->value);
90   }
91 }
92
93
94 /**
95  * Add an interval border to the list of a block's list
96  * of interval border.
97  * @note You always have to create the use before the def.
98  * @param env The environment.
99  * @param head The list head to enqueue the borders.
100  * @param irn The node (value) the border belongs to.
101  * @param pressure The pressure at this point in time.
102  * @param step A time step for the border.
103  * @param is_def Is the border a use or a def.
104  * @return The created border.
105  */
106 static INLINE border_t *border_add(be_chordal_env_t *env, struct list_head *head,
107                         ir_node *irn, unsigned step, unsigned pressure,
108                         unsigned is_def, unsigned is_real)
109 {
110         border_t *b;
111
112         if(!is_def) {
113                 border_t *def;
114
115                 b = obstack_alloc(&env->obst, sizeof(*b));
116
117                 /* also allocate the def and tie it to the use. */
118                 def = obstack_alloc(&env->obst, sizeof(*def));
119                 memset(def, 0, sizeof(*def));
120                 b->other_end = def;
121                 def->other_end = b;
122
123                 /*
124                  * Set the link field of the irn to the def.
125                  * This strongly relies on the fact, that the use is always
126                  * made before the def.
127                  */
128                 set_irn_link(irn, def);
129
130                 b->magic = BORDER_FOURCC;
131                 def->magic = BORDER_FOURCC;
132         }
133
134         /*
135          * If the def is encountered, the use was made and so was the
136          * the def node (see the code above). It was placed into the
137          * link field of the irn, so we can get it there.
138          */
139         else {
140                 b = get_irn_link(irn);
141
142                 assert(b && b->magic == BORDER_FOURCC && "Illegal border encountered");
143         }
144
145         b->pressure = pressure;
146         b->is_def = is_def;
147         b->is_real = is_real;
148         b->irn = irn;
149         b->step = step;
150         list_add_tail(&b->list, head);
151         DBG((env->dbg, LEVEL_5, "\t\t%s adding %+F, step: %d\n", is_def ? "def" : "use", irn, step));
152
153
154         return b;
155 }
156
157 /**
158  * Check, if an irn is of the register class currently under processing.
159  * @param env The chordal environment.
160  * @param irn The node.
161  * @return 1, if the node is of that register class, 0 if not.
162  */
163 static INLINE int has_reg_class(const be_chordal_env_t *env, const ir_node *irn)
164 {
165         // return arch_irn_has_reg_class(env->main_env->arch_env, irn, -1, env->cls);
166         return arch_irn_consider_in_reg_alloc(env->main_env->arch_env, env->cls, irn);
167 }
168
169 #define has_limited_constr(req, irn) \
170         (arch_get_register_req(arch_env, (req), irn, -1) && (req)->type == arch_register_req_type_limited)
171
172 typedef struct _operand_t operand_t;
173
174 struct _operand_t {
175         ir_node *irn;
176         ir_node *carrier;
177         operand_t *partner;
178         int pos;
179         arch_register_req_t req;
180 };
181
182 typedef struct {
183         operand_t *ops;
184         int n_ops;
185         int use_start;
186         ir_node *next_insn;
187         unsigned has_constraints : 1;
188 } insn_t;
189
190 static insn_t *scan_insn(be_chordal_env_t *env, ir_node *irn, struct obstack *obst)
191 {
192         const arch_env_t *arch_env = env->main_env->arch_env;
193         operand_t o;
194         insn_t *insn;
195         int i, n;
196
197         insn = obstack_alloc(obst, sizeof(insn[0]));
198         memset(insn, 0, sizeof(insn[0]));
199
200         insn->next_insn = sched_next(irn);
201         if(get_irn_mode(irn) == mode_T) {
202                 ir_node *p;
203
204                 for(p = sched_next(irn); is_Proj(p); p = sched_next(p)) {
205                         if(arch_irn_consider_in_reg_alloc(arch_env, env->cls, p)) {
206                                 o.carrier = p;
207                                 o.irn     = irn;
208                                 o.pos     = -(get_Proj_proj(p) + 1);
209                                 o.partner = NULL;
210                                 arch_get_register_req(arch_env, &o.req, p, -1);
211                                 obstack_grow(obst, &o, sizeof(o));
212                                 insn->n_ops++;
213                                 insn->has_constraints |= arch_register_req_is(&o.req, limited);
214                         }
215                 }
216
217                 insn->next_insn = p;
218         }
219
220         else if(arch_irn_consider_in_reg_alloc(arch_env, env->cls, irn)) {
221                 o.carrier = irn;
222                 o.irn     = irn;
223                 o.pos     = -1;
224                 o.partner = NULL;
225                 arch_get_register_req(arch_env, &o.req, irn, -1);
226                 obstack_grow(obst, &o, sizeof(o));
227                 insn->n_ops++;
228                 insn->has_constraints |= arch_register_req_is(&o.req, limited);
229         }
230
231         insn->use_start = insn->n_ops;
232
233         for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
234                 ir_node *op = get_irn_n(irn, i);
235
236                 if(arch_irn_consider_in_reg_alloc(arch_env, env->cls, op)) {
237                         o.carrier = op;
238                         o.irn     = irn;
239                         o.pos     = i;
240                         o.partner = NULL;
241                         arch_get_register_req(arch_env, &o.req, irn, i);
242                         obstack_grow(obst, &o, sizeof(o));
243                         insn->n_ops++;
244                         insn->has_constraints |= arch_register_req_is(&o.req, limited);
245                 }
246         }
247
248         insn->ops = obstack_finish(obst);
249         return insn;
250 }
251
252 static operand_t *find_unpaired_use(insn_t *insn, const operand_t *op, int can_be_constrained)
253 {
254         int i;
255         operand_t *res = NULL;
256
257         for(i = insn->use_start; i < insn->n_ops; ++i) {
258                 operand_t *op = &insn->ops[i];
259                 int has_constraint = arch_register_req_is(&op->req, limited);
260
261                 if(!values_interfere(op->carrier, op->irn) && !op->partner && (!has_constraint || can_be_constrained)) {
262                         if(arch_register_req_is(&op->req, should_be_same) && op->req.other_same == op->carrier)
263                                 return op;
264                         else
265                                 res = op;
266                 }
267         }
268
269         return res;
270 }
271
272 static void pair_up_operands(insn_t *insn)
273 {
274         firm_dbg_module_t *dbg = firm_dbg_register("firm.be.chordal.constr");
275         int i;
276
277         for(i = 0; i < insn->use_start; ++i) {
278                 operand_t *op      = &insn->ops[i];
279                 int has_constraint = arch_register_req_is(&op->req, limited);
280                 operand_t *partner = find_unpaired_use(insn, op, !has_constraint);
281
282                 if(partner) {
283                         op->partner = partner;
284                         partner->partner = op;
285                 }
286         }
287 }
288
289 static ir_node *handle_constraints(be_chordal_alloc_env_t *alloc_env, ir_node *irn)
290 {
291         be_chordal_env_t *env  = alloc_env->chordal_env;
292         void *base             = obstack_base(&env->obst);
293         insn_t *insn           = scan_insn(env, irn, &env->obst);
294         ir_node *res           = insn->next_insn;
295
296         if(insn->has_constraints) {
297                 firm_dbg_module_t *dbg = firm_dbg_register("firm.be.chordal.constr");
298                 const arch_env_t *aenv = env->main_env->arch_env;
299                 int n_regs             = env->cls->n_regs;
300                 bitset_t *bs           = bitset_alloca(n_regs);
301                 ir_node **alloc_nodes  = alloca(n_regs * sizeof(alloc_nodes[0]));
302                 bipartite_t *bp        = bipartite_new(n_regs, n_regs);
303                 int *assignment        = alloca(n_regs * sizeof(assignment[0]));
304                 pmap *partners         = pmap_create();
305
306                 int i, n_alloc;
307                 long col;
308                 const ir_edge_t *edge;
309                 ir_node *perm = insert_Perm_after(aenv, env->cls, env->dom_front, sched_prev(irn));
310
311                 /* Registers are propagated by insert_Perm_after(). Clean them here! */
312                 if(perm) {
313                         foreach_out_edge(perm, edge) {
314                                 ir_node *proj = get_edge_src_irn(edge);
315                                 arch_set_irn_register(aenv, proj, NULL);
316                         }
317                 }
318
319
320                 be_liveness(env->irg);
321                 insn = scan_insn(env, irn, &env->obst);
322
323                 DBG((dbg, LEVEL_1, "handling constraints for %+F\n", irn));
324
325                 /*
326                  * If there was no Perm made, nothing was alive in this register class.
327                  * This means, that the node has no operands, thus no input constraints.
328                  * so it had output constraints. The other results then can be assigned freeliy.
329                  */
330
331                 pair_up_operands(insn);
332
333                 for(i = 0, n_alloc = 0; i < insn->n_ops; ++i) {
334                         operand_t *op = &insn->ops[i];
335                         if(arch_register_req_is(&op->req, limited)) {
336                                 pmap_insert(partners, op->carrier, op->partner ? op->partner->carrier : NULL);
337                                 alloc_nodes[n_alloc] = op->carrier;
338
339                                 DBG((dbg, LEVEL_2, "\tassociating %+F and %+F\n", op->carrier, pmap_get(partners, op->carrier)));
340
341                                 bitset_clear_all(bs);
342                                 op->req.limited(op->req.limited_env, bs);
343                                 bitset_and(bs, alloc_env->valid_colors);
344
345                                 DBG((dbg, LEVEL_2, "\tallowed registers for %+F: %B\n", op->carrier, bs));
346
347                                 bitset_foreach(bs, col)
348                                         bipartite_add(bp, n_alloc, col);
349
350                                 n_alloc++;
351                         }
352                 }
353
354                 if(perm) {
355                         foreach_out_edge(perm, edge) {
356                                 ir_node *proj = get_edge_src_irn(edge);
357
358                                 assert(is_Proj(proj));
359
360                                 if(values_interfere(proj, irn)) {
361                                         assert(n_alloc < n_regs);
362                                         alloc_nodes[n_alloc] = proj;
363                                         pmap_insert(partners, proj, NULL);
364
365                                         bitset_clear_all(bs);
366                                         arch_get_allocatable_regs(aenv, proj, -1, bs);
367                                         bitset_and(bs, alloc_env->valid_colors);
368                                         bitset_foreach(bs, col)
369                                                 bipartite_add(bp, n_alloc, col);
370
371                                         n_alloc++;
372                                 }
373                         }
374                 }
375
376                 bipartite_matching(bp, assignment);
377
378
379                 for(i = 0; i < n_alloc; ++i) {
380                         int j;
381                         ir_node *nodes[2];
382                         const arch_register_t *reg;
383
384                         assert(assignment[i] >= 0 && "there must have been a register assigned");
385                         reg = arch_register_for_index(env->cls, assignment[i]);
386
387                         nodes[0] = alloc_nodes[i];
388                         nodes[1] = pmap_get(partners, alloc_nodes[i]);
389
390                         for(j = 0; j < 2; ++j) {
391                                 if(!nodes[j])
392                                         continue;
393
394                                 arch_set_irn_register(aenv, nodes[j], reg);
395                                 pset_hinsert_ptr(alloc_env->pre_colored, nodes[j]);
396                                 DBG((dbg, LEVEL_2, "\tsetting %+F to register %s\n", nodes[j], reg->name));
397                         }
398                 }
399
400
401                 if(perm) {
402                         bitset_clear_all(bs);
403                         foreach_out_edge(perm, edge) {
404                                 ir_node *proj              = get_edge_src_irn(edge);
405                                 const arch_register_t *reg = arch_get_irn_register(aenv, proj);
406
407                                 if(reg != NULL)
408                                         bitset_set(bs, reg->index);
409                         }
410
411                         // bitset_or(bs, alloc_env->ignore_colors);
412                         foreach_out_edge(perm, edge) {
413                                 ir_node *proj              = get_edge_src_irn(edge);
414                                 const arch_register_t *reg = arch_get_irn_register(aenv, proj);
415
416                                 DBG((dbg, LEVEL_2, "\tchecking reg of %+F: %s\n", proj, reg ? reg->name : "<none>"));
417
418                                 if(reg == NULL) {
419                                         col = bitset_next_clear(bs, 0);
420                                         reg = arch_register_for_index(env->cls, col);
421                                         bitset_set(bs, reg->index);
422                                         arch_set_irn_register(aenv, proj, reg);
423                                         pset_insert_ptr(alloc_env->pre_colored, proj);
424                                         DBG((dbg, LEVEL_2, "\tsetting %+F to register %s\n", proj, reg->name));
425                                 }
426                         }
427                 }
428
429                 pmap_destroy(partners);
430         }
431
432         obstack_free(&env->obst, base);
433         return res;
434 }
435
436 /**
437  * Handle constraint nodes in each basic block.
438  * be_insert_constr_perms() inserts Perm nodes which perm
439  * over all values live at the constrained node right in front
440  * of the constrained node. These Perms signal a constrained node.
441  * For further comments, refer to handle_constraints_at_perm().
442  */
443 static void constraints(ir_node *bl, void *data)
444 {
445         firm_dbg_module_t *dbg      = firm_dbg_register("firm.be.chordal.constr");
446         be_chordal_alloc_env_t *env = data;
447         arch_env_t *arch_env        = env->chordal_env->main_env->arch_env;
448         ir_node *irn;
449
450         for(irn = sched_first(bl); !sched_is_end(irn);) {
451                 irn = handle_constraints(env, irn);
452         }
453 }
454
455 /**
456  * Annotate the register pressure to the nodes and compute
457  * the liveness intervals.
458  * @param block The block to do it for.
459  * @param env_ptr The environment.
460  */
461 static void pressure(ir_node *block, void *env_ptr)
462 {
463 /* Convenience macro for a def */
464 #define border_def(irn, step, real) \
465         border_add(env, head, irn, step, pressure--, 1, real)
466
467 /* Convenience macro for a use */
468 #define border_use(irn, step, real) \
469         border_add(env, head, irn, step, ++pressure, 0, real)
470
471         be_chordal_alloc_env_t *alloc_env = env_ptr;
472         be_chordal_env_t *env             = alloc_env->chordal_env;
473         const arch_env_t *arch_env        = env->main_env->arch_env;
474         bitset_t *live                    = alloc_env->live;
475         firm_dbg_module_t *dbg            = env->dbg;
476         ir_node *irn;
477
478         int i, n;
479         unsigned step = 0;
480         unsigned pressure = 0;
481         struct list_head *head;
482         pset *live_in = put_live_in(block, pset_new_ptr_default());
483         pset *live_end = put_live_end(block, pset_new_ptr_default());
484
485         DBG((dbg, LEVEL_1, "Computing pressure in block %+F\n", block));
486         bitset_clear_all(live);
487
488         /* Set up the border list in the block info */
489         head = obstack_alloc(&env->obst, sizeof(*head));
490         INIT_LIST_HEAD(head);
491         assert(pmap_get(env->border_heads, block) == NULL);
492         pmap_insert(env->border_heads, block, head);
493
494         /*
495          * Make final uses of all values live out of the block.
496          * They are necessary to build up real intervals.
497          */
498         for(irn = pset_first(live_end); irn; irn = pset_next(live_end)) {
499                 if(has_reg_class(env, irn)) {
500                         DBG((dbg, LEVEL_3, "\tMaking live: %+F/%d\n", irn, get_irn_graph_nr(irn)));
501                         bitset_set(live, get_irn_graph_nr(irn));
502                         border_use(irn, step, 0);
503                 }
504         }
505         ++step;
506
507         /*
508          * Determine the last uses of a value inside the block, since they are
509          * relevant for the interval borders.
510          */
511         sched_foreach_reverse(block, irn) {
512                 DBG((dbg, LEVEL_1, "\tinsn: %+F, pressure: %d\n", irn, pressure));
513                 DBG((dbg, LEVEL_2, "\tlive: %b\n", live));
514
515                 /*
516                  * If the node defines some value, which can put into a
517                  * register of the current class, make a border for it.
518                  */
519                 if(has_reg_class(env, irn)) {
520                         int nr = get_irn_graph_nr(irn);
521
522                         bitset_clear(live, nr);
523                         border_def(irn, step, 1);
524                 }
525
526                 /*
527                  * If the node is no phi node we can examine the uses.
528                  */
529                 if(!is_Phi(irn)) {
530                         for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
531                                 ir_node *op = get_irn_n(irn, i);
532
533                                 if(has_reg_class(env, op)) {
534                                         int nr = get_irn_graph_nr(op);
535
536                                         DBG((dbg, LEVEL_4, "\t\tpos: %d, use: %+F\n", i, op));
537
538                                         if(!bitset_is_set(live, nr)) {
539                                                 border_use(op, step, 1);
540                                                 bitset_set(live, nr);
541                                         }
542                                 }
543                         }
544                 }
545                 ++step;
546         }
547
548         /*
549          * Add initial defs for all values live in.
550          */
551         for(irn = pset_first(live_in); irn; irn = pset_next(live_in)) {
552                 if(has_reg_class(env, irn)) {
553
554                         /* Mark the value live in. */
555                         bitset_set(live, get_irn_graph_nr(irn));
556
557                         /* Add the def */
558                         border_def(irn, step, 0);
559                 }
560         }
561
562
563   del_pset(live_in);
564   del_pset(live_end);
565 }
566
567 static void assign(ir_node *block, void *env_ptr)
568 {
569         be_chordal_alloc_env_t *alloc_env = env_ptr;
570         be_chordal_env_t *env       = alloc_env->chordal_env;
571         firm_dbg_module_t *dbg      = env->dbg;
572         bitset_t *live              = alloc_env->live;
573         bitset_t *colors            = alloc_env->colors;
574         bitset_t *in_colors         = alloc_env->in_colors;
575         const arch_env_t *arch_env  = env->main_env->arch_env;
576
577         const ir_node *irn;
578         border_t *b;
579         struct list_head *head = get_block_border_head(env, block);
580         pset *live_in = put_live_in(block, pset_new_ptr_default());
581
582         bitset_clear_all(live);
583         bitset_clear_all(in_colors);
584
585         bitset_copy(colors, alloc_env->valid_colors);
586         bitset_flip_all(colors);
587
588         DBG((dbg, LEVEL_4, "Assigning colors for block %+F\n", block));
589         DBG((dbg, LEVEL_4, "\tusedef chain for block\n"));
590         list_for_each_entry(border_t, b, head, list) {
591                 DBG((dbg, LEVEL_4, "\t%s %+F/%d\n", b->is_def ? "def" : "use",
592                                         b->irn, get_irn_graph_nr(b->irn)));
593         }
594
595         /*
596          * Add initial defs for all values live in.
597          * Since their colors have already been assigned (The dominators were
598          * allocated before), we have to mark their colors as used also.
599          */
600         for(irn = pset_first(live_in); irn; irn = pset_next(live_in)) {
601                 if(has_reg_class(env, irn)) {
602                         const arch_register_t *reg = arch_get_irn_register(arch_env, irn);
603                         int col;
604
605                         assert(reg && "Node must have been assigned a register");
606                         col = arch_register_get_index(reg);
607
608                         /* Mark the color of the live in value as used. */
609                         bitset_set(colors, col);
610                         bitset_set(in_colors, col);
611
612                         /* Mark the value live in. */
613                         bitset_set(live, get_irn_graph_nr(irn));
614                 }
615         }
616
617         /*
618          * Mind that the sequence of defs from back to front defines a perfect
619          * elimination order. So, coloring the definitions from first to last
620          * will work.
621          */
622         list_for_each_entry_reverse(border_t, b, head, list) {
623                 ir_node *irn = b->irn;
624                 int nr = get_irn_graph_nr(irn);
625
626                 /*
627                  * Assign a color, if it is a local def. Global defs already have a
628                  * color.
629                  */
630                 if(b->is_def && !is_live_in(block, irn)) {
631                         const arch_register_t *reg;
632                         int col = NO_COLOR;
633
634                         if(pset_find_ptr(alloc_env->pre_colored, irn)) {
635                                 reg = arch_get_irn_register(arch_env, irn);
636                                 col = reg->index;
637                                 assert(!bitset_is_set(colors, col) && "pre-colored register must be free");
638                         }
639
640                         else {
641                                 col = bitset_next_clear(colors, 0);
642                                 reg = arch_register_for_index(env->cls, col);
643                                 assert(arch_get_irn_register(arch_env, irn) == NULL && "This node must not have been assigned a register yet");
644                         }
645
646                         bitset_set(colors, col);
647                         arch_set_irn_register(arch_env, irn, reg);
648
649                         DBG((dbg, LEVEL_1, "\tassigning register %s(%d) to %+F\n",
650             arch_register_get_name(reg), col, irn));
651
652                         assert(!bitset_is_set(live, nr) && "Value's definition must not have been encountered");
653                         bitset_set(live, nr);
654                 }
655
656                 /* Clear the color upon a use. */
657                 else if(!b->is_def) {
658                         const arch_register_t *reg = arch_get_irn_register(arch_env, irn);
659                         int col;
660
661                         assert(reg && "Register must have been assigned");
662
663                         col = arch_register_get_index(reg);
664                         assert(bitset_is_set(live, nr) && "Cannot have a non live use");
665
666                         bitset_clear(colors, col);
667                         bitset_clear(live, nr);
668                 }
669         }
670
671         del_pset(live_in);
672 }
673
674 void be_ra_chordal_color(be_chordal_env_t *chordal_env)
675 {
676         be_chordal_alloc_env_t env;
677         char buf[256];
678
679         int colors_n          = arch_register_class_n_regs(chordal_env->cls);
680         ir_graph *irg         = chordal_env->irg;
681
682
683         if(get_irg_dom_state(irg) != dom_consistent)
684                 compute_doms(irg);
685
686         env.chordal_env   = chordal_env;
687         env.colors_n      = colors_n;
688         env.colors        = bitset_malloc(colors_n);
689         env.valid_colors  = bitset_malloc(colors_n);
690         env.in_colors     = bitset_malloc(colors_n);
691         env.pre_colored   = pset_new_ptr_default();
692
693         arch_put_non_ignore_regs(chordal_env->main_env->arch_env, chordal_env->cls, env.valid_colors);
694
695         /* Handle register targeting constraints */
696         dom_tree_walk_irg(irg, constraints, NULL, &env);
697
698 #if 0
699         if(chordal_env->opts->dump_flags & BE_CH_DUMP_CONSTR) {
700                 snprintf(buf, sizeof(buf), "-%s-constr", chordal_env->cls->name);
701                 dump_ir_block_graph_sched(chordal_env->irg, buf);
702         }
703 #endif
704
705         be_numbering(irg);
706         env.live = bitset_malloc(get_graph_node_count(chordal_env->irg));
707
708         /* First, determine the pressure */
709         dom_tree_walk_irg(irg, pressure, NULL, &env);
710
711         /* Assign the colors */
712         dom_tree_walk_irg(irg, assign, NULL, &env);
713
714         be_numbering_done(irg);
715
716 #if 0
717         if(chordal_env->opts->dump_flags & BE_CH_DUMP_TREE_INTV) {
718         plotter_t *plotter;
719
720                 ir_snprintf(buf, sizeof(buf), "ifg_%s_%F.eps", chordal_env->cls->name, irg);
721         plotter = new_plotter_ps(buf);
722         draw_interval_tree(&draw_chordal_def_opts, chordal_env, plotter);
723         plotter_free(plotter);
724         }
725 #endif
726
727         free(env.live);
728         free(env.colors);
729         free(env.in_colors);
730         free(env.valid_colors);
731
732         del_pset(env.pre_colored);
733 }