0a12e91a7ed6eaa8a88c10a1c826b4d1c7a4ed8b
[libfirm] / ir / be / beschedtrace.c
1 /*
2  * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief       Implements a trace scheduler as presented in Muchnik[TM].
23  * @author      Michael Beck
24  * @date        28.08.2006
25  * @version     $Id$
26  */
27 #include "config.h"
28
29 #include <stdlib.h>
30
31 #include "iredges_t.h"
32
33 #include "besched.h"
34 #include "belistsched.h"
35 #include "benode.h"
36 #include "belive.h"
37 #include "bemodule.h"
38
39 /* we need a special mark */
40 static char _mark;
41 #define MARK &_mark
42
43 typedef struct trace_irn {
44         sched_timestep_t delay;      /**< The delay for this node if already calculated, else 0. */
45         sched_timestep_t etime;      /**< The earliest time of this node. */
46         unsigned num_user;           /**< The number real users (mode datab) of this node */
47         int      reg_diff;           /**< The difference of num(out registers) - num(in registers) */
48         int      preorder;           /**< The pre-order position */
49         unsigned critical_path_len;  /**< The weighted length of the longest critical path */
50         unsigned is_root       : 1;  /**< is a root node of a block */
51 } trace_irn_t;
52
53 typedef struct trace_env {
54         trace_irn_t      *sched_info;               /**< trace scheduling information about the nodes */
55         sched_timestep_t curr_time;                 /**< current time of the scheduler */
56         be_lv_t          *liveness;                 /**< The liveness for the irg */
57         DEBUG_ONLY(firm_dbg_module_t *dbg;)
58 } trace_env_t;
59
60 /**
61  * Returns a random node from a nodeset
62  */
63 static ir_node *get_nodeset_node(const ir_nodeset_t *nodeset)
64 {
65         ir_nodeset_iterator_t iter;
66
67         ir_nodeset_iterator_init(&iter, nodeset);
68         return ir_nodeset_iterator_next(&iter);
69 }
70
71 /**
72  * Returns non-zero if the node is a root node
73  */
74 static inline unsigned is_root_node(trace_env_t *env, ir_node *n)
75 {
76         unsigned const idx = get_irn_idx(n);
77
78         assert(idx < ARR_LEN(env->sched_info));
79         return env->sched_info[idx].is_root;
80 }
81
82 /**
83  * Mark a node as root node
84  */
85 static inline void mark_root_node(trace_env_t *env, ir_node *n)
86 {
87         unsigned const idx = get_irn_idx(n);
88
89         assert(idx < ARR_LEN(env->sched_info));
90         env->sched_info[idx].is_root = 1;
91 }
92
93 /**
94  * Get the current delay.
95  */
96 static inline sched_timestep_t get_irn_delay(trace_env_t *env, ir_node *n)
97 {
98         unsigned const idx = get_irn_idx(n);
99
100         assert(idx < ARR_LEN(env->sched_info));
101         return env->sched_info[idx].delay;
102 }
103
104 /**
105  * Set the current delay.
106  */
107 static inline void set_irn_delay(trace_env_t *env, ir_node *n, sched_timestep_t delay)
108 {
109         unsigned const idx = get_irn_idx(n);
110
111         assert(idx < ARR_LEN(env->sched_info));
112         env->sched_info[idx].delay = delay;
113 }
114
115 /**
116  * Get the current etime.
117  */
118 static inline sched_timestep_t get_irn_etime(trace_env_t *env, ir_node *n)
119 {
120         unsigned const idx = get_irn_idx(n);
121
122         assert(idx < ARR_LEN(env->sched_info));
123         return env->sched_info[idx].etime;
124 }
125
126 /**
127  * Set the current etime.
128  */
129 static inline void set_irn_etime(trace_env_t *env, ir_node *n, sched_timestep_t etime)
130 {
131         unsigned const idx = get_irn_idx(n);
132
133         assert(idx < ARR_LEN(env->sched_info));
134         env->sched_info[idx].etime = etime;
135 }
136
137 /**
138  * Get the number of users.
139  */
140 static inline unsigned get_irn_num_user(trace_env_t *env, ir_node *n)
141 {
142         unsigned const idx = get_irn_idx(n);
143
144         assert(idx < ARR_LEN(env->sched_info));
145         return env->sched_info[idx].num_user;
146 }
147
148 /**
149  * Set the number of users.
150  */
151 static inline void set_irn_num_user(trace_env_t *env, ir_node *n, unsigned num_user)
152 {
153         unsigned const idx = get_irn_idx(n);
154
155         assert(idx < ARR_LEN(env->sched_info));
156         env->sched_info[idx].num_user = num_user;
157 }
158
159 /**
160  * Get the register difference.
161  */
162 static inline int get_irn_reg_diff(trace_env_t *env, ir_node *n)
163 {
164         unsigned const idx = get_irn_idx(n);
165
166         assert(idx < ARR_LEN(env->sched_info));
167         return env->sched_info[idx].reg_diff;
168 }
169
170 /**
171  * Set the register difference.
172  */
173 static inline void set_irn_reg_diff(trace_env_t *env, ir_node *n, int reg_diff)
174 {
175         unsigned const idx = get_irn_idx(n);
176
177         assert(idx < ARR_LEN(env->sched_info));
178         env->sched_info[idx].reg_diff = reg_diff;
179 }
180
181 /**
182  * Get the pre-order position.
183  */
184 static inline int get_irn_preorder(trace_env_t *env, ir_node *n)
185 {
186         unsigned const idx = get_irn_idx(n);
187
188         assert(idx < ARR_LEN(env->sched_info));
189         return env->sched_info[idx].preorder;
190 }
191
192 /**
193  * Set the pre-order position.
194  */
195 static inline void set_irn_preorder(trace_env_t *env, ir_node *n, int pos)
196 {
197         unsigned const idx = get_irn_idx(n);
198
199         assert(idx < ARR_LEN(env->sched_info));
200         env->sched_info[idx].preorder = pos;
201 }
202
203 /**
204  * Get the pre-order position.
205  */
206 static inline unsigned get_irn_critical_path_len(trace_env_t *env, ir_node *n)
207 {
208         unsigned const idx = get_irn_idx(n);
209
210         assert(idx < ARR_LEN(env->sched_info));
211         return env->sched_info[idx].critical_path_len;
212 }
213
214 /**
215  * Set the pre-order position.
216  */
217 static inline void set_irn_critical_path_len(trace_env_t *env, ir_node *n, unsigned len)
218 {
219         unsigned const idx = get_irn_idx(n);
220
221         assert(idx < ARR_LEN(env->sched_info));
222         env->sched_info[idx].critical_path_len = len;
223 }
224
225 /**
226  * returns the exec-time for node n.
227  */
228 static sched_timestep_t exectime(trace_env_t *env, ir_node *n)
229 {
230         (void) env;
231         if (be_is_Keep(n) || is_Proj(n))
232                 return 0;
233 #if 0
234         if (env->selector->exectime)
235                 return env->selector->exectime(env->selector_env, n);
236 #endif
237         return 1;
238 }
239
240 /**
241  * Calculates the latency for between two ops
242  */
243 static sched_timestep_t latency(trace_env_t *env, ir_node *pred, int pred_cycle, ir_node *curr, int curr_cycle)
244 {
245         (void) pred_cycle;
246         (void) curr_cycle;
247         /* a Keep hides a root */
248         if (be_is_Keep(curr))
249                 return exectime(env, pred);
250
251         /* Proj's are executed immediately */
252         if (is_Proj(curr))
253                 return 0;
254
255         /* predecessors Proj's must be skipped */
256         if (is_Proj(pred))
257                 pred = get_Proj_pred(pred);
258
259 #if 0
260         if (env->selector->latency)
261                 return env->selector->latency(env->selector_env, pred, pred_cycle, curr, curr_cycle);
262 #endif
263
264         return 1;
265 }
266
267 /**
268  * Returns the number of users of a node having mode datab.
269  */
270 static int get_num_successors(ir_node *irn)
271 {
272         int sum = 0;
273         const ir_edge_t *edge;
274
275         if (get_irn_mode(irn) == mode_T) {
276                 /* for mode_T nodes: count the users of all Projs */
277                 foreach_out_edge(irn, edge) {
278                         ir_node *proj = get_edge_src_irn(edge);
279                         ir_mode *mode = get_irn_mode(proj);
280
281                         if (mode == mode_T)
282                                 sum += get_num_successors(proj);
283                         else if (mode_is_datab(mode))
284                                 sum += get_irn_n_edges(proj);
285                 }
286         }
287         else {
288                 /* do not count keep-alive edges */
289                 foreach_out_edge(irn, edge) {
290                         if (get_irn_opcode(get_edge_src_irn(edge)) != iro_End)
291                                 sum++;
292                 }
293         }
294
295         return sum;
296 }
297
298 /**
299  * Returns the difference of regs_output - regs_input;
300  */
301 static int get_reg_difference(trace_env_t *env, ir_node *irn)
302 {
303         int num_out = 0;
304         int num_in  = 0;
305         int i;
306         ir_node *block = get_nodes_block(irn);
307
308         if (be_is_Call(irn)) {
309                 /* we want calls preferred */
310                 return -5;
311         }
312
313         if (get_irn_mode(irn) == mode_T) {
314                 /* mode_T nodes: num out regs == num Projs with mode datab */
315                 const ir_edge_t *edge;
316                 foreach_out_edge(irn, edge) {
317                         ir_node *proj = get_edge_src_irn(edge);
318                         if (mode_is_datab(get_irn_mode(proj)))
319                                 num_out++;
320                 }
321         }
322         else
323                 num_out = 1;
324
325         /* num in regs: number of ins with mode datab and not ignore */
326         for (i = get_irn_arity(irn) - 1; i >= 0; i--) {
327                 ir_node *in = get_irn_n(irn, i);
328
329                 if (!mode_is_datab(get_irn_mode(in)))
330                         continue;
331
332                 if (arch_irn_is_ignore(in))
333                         continue;
334
335                 if (be_is_live_end(env->liveness, block, in))
336                         continue;
337
338                 num_in++;
339         }
340
341         return num_out - num_in;
342 }
343
344 /**
345  * descent into a dag and create a pre-order list.
346  */
347 static void descent(ir_node *root, ir_node *block, ir_node **list, trace_env_t *env, unsigned path_len)
348 {
349         int i;
350
351         if (! is_Phi(root)) {
352                 path_len += exectime(env, root);
353                 if (get_irn_critical_path_len(env, root) < path_len) {
354                         set_irn_critical_path_len(env, root, path_len);
355                 }
356                 /* calculate number of users (needed for heuristic) */
357                 set_irn_num_user(env, root, get_num_successors(root));
358
359                 /* calculate register difference (needed for heuristic) */
360                 set_irn_reg_diff(env, root, get_reg_difference(env, root));
361
362                 /* Phi nodes always leave the block */
363                 for (i = get_irn_arity(root) - 1; i >= 0; --i) {
364                         ir_node *pred = get_irn_n(root, i);
365
366                         DBG((env->dbg, LEVEL_3, "   node %+F\n", pred));
367
368                         /* Blocks may happen as predecessors of End nodes */
369                         if (is_Block(pred))
370                                 continue;
371
372                         /* already seen nodes are not marked */
373                         if (get_irn_link(pred) != MARK)
374                                 continue;
375
376                         /* don't leave our block */
377                         if (get_nodes_block(pred) != block)
378                                 continue;
379
380                         set_irn_link(pred, NULL);
381
382                         descent(pred, block, list, env, path_len);
383                 }
384         }
385         set_irn_link(root, *list);
386         *list = root;
387 }
388
389 /**
390  * Returns non-zero if root is a root in the block block.
391  */
392 static int is_root(ir_node *root, ir_node *block)
393 {
394         const ir_edge_t *edge;
395
396         foreach_out_edge(root, edge) {
397                 ir_node *succ = get_edge_src_irn(edge);
398
399                 if (is_Block(succ))
400                         continue;
401                 /* Phi nodes are always in "another block */
402                 if (is_Phi(succ))
403                         continue;
404                 if (get_nodes_block(succ) == block)
405                         return 0;
406         }
407         return 1;
408 }
409
410 /**
411  * Performs initial block calculations for trace scheduling.
412  */
413 static void trace_preprocess_block(trace_env_t *env, ir_node *block)
414 {
415         ir_node *root = NULL, *preord = NULL;
416         ir_node *curr, *irn;
417         int cur_pos;
418         const ir_edge_t *edge;
419
420         /* First step: Find the root set. */
421         foreach_out_edge(block, edge) {
422                 ir_node *succ = get_edge_src_irn(edge);
423
424                 if (is_Anchor(succ)) {
425                         /* ignore a keep alive edge */
426                         continue;
427                 }
428                 if (is_root(succ, block)) {
429                         mark_root_node(env, succ);
430                         set_irn_link(succ, root);
431                         root = succ;
432                 }
433                 else
434                         set_irn_link(succ, MARK);
435         }
436
437         /* Second step: calculate the pre-order list. */
438         preord = NULL;
439         for (curr = root; curr; curr = irn) {
440                 irn = (ir_node*)get_irn_link(curr);
441                 DBG((env->dbg, LEVEL_2, "   DAG root %+F\n", curr));
442                 descent(curr, block, &preord, env, 0);
443         }
444         root = preord;
445
446         /* Third step: calculate the Delay. Note that our
447         * list is now in pre-order, starting at root
448         */
449         for (cur_pos = 0, curr = root; curr; curr = (ir_node*)get_irn_link(curr), cur_pos++) {
450                 sched_timestep_t d;
451
452                 if (is_cfop(curr)) {
453                         /* assure, that branches can be executed last */
454                         d = 0;
455                 }
456                 else {
457                         if (is_root_node(env, curr))
458                                 d = exectime(env, curr);
459                         else {
460                                 d = 0;
461                                 foreach_out_edge(curr, edge) {
462                                         ir_node *n = get_edge_src_irn(edge);
463
464                                         if (get_nodes_block(n) == block) {
465                                                 sched_timestep_t ld;
466
467                                                 ld = latency(env, curr, 1, n, 0) + get_irn_delay(env, n);
468                                                 d = ld > d ? ld : d;
469                                         }
470                                 }
471                         }
472                 }
473                 set_irn_delay(env, curr, d);
474                 DB((env->dbg, LEVEL_2, "\t%+F delay %u\n", curr, d));
475
476                 /* set the etime of all nodes to 0 */
477                 set_irn_etime(env, curr, 0);
478
479                 set_irn_preorder(env, curr, cur_pos);
480         }
481 }
482
483 /**
484  * This functions gets called after a node finally has been made ready.
485  */
486 static void trace_node_ready(void *data, ir_node *irn, ir_node *pred)
487 {
488         trace_env_t *env = (trace_env_t*)data;
489         sched_timestep_t etime_p, etime;
490
491         etime = env->curr_time;
492         if (pred) {
493                 etime_p = get_irn_etime(env, pred);
494                 etime  += latency(env, pred, 1, irn, 0);
495                 etime   = etime_p > etime ? etime_p : etime;
496         }
497
498         set_irn_etime(env, irn, etime);
499         DB((env->dbg, LEVEL_2, "\tset etime of %+F to %u\n", irn, etime));
500 }
501
502 /**
503  * Update the current time after irn has been selected.
504  */
505 static void trace_update_time(void *data, ir_node *irn)
506 {
507         trace_env_t *env = (trace_env_t*)data;
508         if (is_Phi(irn) || get_irn_opcode(irn) == beo_Start) {
509                 env->curr_time += get_irn_etime(env, irn);
510         }
511         else {
512                 env->curr_time += exectime(env, irn);
513         }
514 }
515
516 /**
517  * Allocates memory and initializes trace scheduling environment.
518  * @param irg   The backend irg object
519  * @return The environment
520  */
521 static trace_env_t *trace_init(ir_graph *irg)
522 {
523         trace_env_t *env = XMALLOCZ(trace_env_t);
524         int         nn   = get_irg_last_idx(irg);
525
526         env->curr_time  = 0;
527         env->sched_info = NEW_ARR_F(trace_irn_t, nn);
528         env->liveness   = be_liveness(irg);
529         FIRM_DBG_REGISTER(env->dbg, "firm.be.sched.trace");
530
531         be_liveness_assure_chk(env->liveness);
532         memset(env->sched_info, 0, nn * sizeof(*(env->sched_info)));
533
534         return env;
535 }
536
537 /**
538  * Frees all memory allocated for trace scheduling environment.
539  * @param env  The environment
540  */
541 static void trace_free(void *data)
542 {
543         trace_env_t *env = (trace_env_t*)data;
544         be_liveness_free(env->liveness);
545         DEL_ARR_F(env->sched_info);
546         free(env);
547 }
548
549 /**
550  * Simple selector. Just assure that jumps are scheduled last.
551  */
552 static ir_node *basic_selection(ir_nodeset_t *ready_set)
553 {
554         ir_node *irn = NULL;
555         ir_nodeset_iterator_t iter;
556
557         /* assure that branches and constants are executed last */
558         foreach_ir_nodeset(ready_set, irn, iter) {
559                 if (!is_cfop(irn)) {
560                         return irn;
561                 }
562         }
563
564         /* at last: schedule branches */
565         irn = get_nodeset_node(ready_set);
566
567         return irn;
568 }
569
570 /**
571 * The muchnik selector.
572 */
573 static ir_node *muchnik_select(void *block_env, ir_nodeset_t *ready_set)
574 {
575         trace_env_t *env = (trace_env_t*)block_env;
576         ir_nodeset_t mcands, ecands;
577         ir_nodeset_iterator_t iter;
578         sched_timestep_t max_delay = 0;
579         ir_node *irn;
580
581         /* calculate the max delay of all candidates */
582         foreach_ir_nodeset(ready_set, irn, iter) {
583                 sched_timestep_t d = get_irn_delay(env, irn);
584
585                 max_delay = d > max_delay ? d : max_delay;
586         }
587
588         ir_nodeset_init_size(&mcands, 8);
589         ir_nodeset_init_size(&ecands, 8);
590
591         /* build mcands and ecands */
592         foreach_ir_nodeset(ready_set, irn, iter) {
593                 if (get_irn_delay(env, irn) == max_delay) {
594                         ir_nodeset_insert(&mcands, irn);
595                         if (get_irn_etime(env, irn) <= env->curr_time)
596                                 ir_nodeset_insert(&ecands, irn);
597                 }
598         }
599
600         /* select a node */
601         if (ir_nodeset_size(&mcands) == 1) {
602                 irn = get_nodeset_node(&mcands);
603                 DB((env->dbg, LEVEL_3, "\tirn = %+F, mcand = 1, max_delay = %u\n", irn, max_delay));
604         }
605         else {
606                 size_t cnt = ir_nodeset_size(&ecands);
607                 if (cnt == 1) {
608                         irn = get_nodeset_node(&ecands);
609
610                         if (is_cfop(irn)) {
611                                 /* BEWARE: don't select a JUMP if others are still possible */
612                                 goto force_mcands;
613                         }
614                         DB((env->dbg, LEVEL_3, "\tirn = %+F, ecand = 1, max_delay = %u\n", irn, max_delay));
615                 }
616                 else if (cnt > 1) {
617                         DB((env->dbg, LEVEL_3, "\tecand = %zu, max_delay = %u\n", cnt, max_delay));
618                         irn = basic_selection(&ecands);
619                 }
620                 else {
621 force_mcands:
622                         DB((env->dbg, LEVEL_3, "\tmcand = %zu\n", ir_nodeset_size(&mcands)));
623                         irn = basic_selection(&mcands);
624                 }
625         }
626
627         return irn;
628 }
629
630 static void *muchnik_init_graph(ir_graph *irg)
631 {
632         trace_env_t *env  = trace_init(irg);
633         return (void *)env;
634 }
635
636 static void *muchnik_init_block(void *graph_env, ir_node *bl)
637 {
638         trace_env_t *env = (trace_env_t*) graph_env;
639         trace_preprocess_block(env, bl);
640         return graph_env;
641 }
642
643 static void sched_muchnik(ir_graph *irg)
644 {
645         static const list_sched_selector_t muchnik_selector = {
646                 muchnik_init_graph,
647                 muchnik_init_block,
648                 muchnik_select,
649                 trace_node_ready,    /* node_ready */
650                 trace_update_time,   /* node_selected */
651                 NULL,                /* finish_block */
652                 trace_free           /* finish_graph */
653         };
654         be_list_sched_graph(irg, &muchnik_selector);
655 }
656
657 /**
658  * Execute the heuristic function.
659  */
660 static ir_node *heuristic_select(void *block_env, ir_nodeset_t *ns)
661 {
662         trace_env_t *trace_env   = (trace_env_t*)block_env;
663         ir_node     *irn, *cand  = NULL;
664         int         max_prio     = INT_MIN;
665         int         cur_prio     = INT_MIN;
666         int         reg_fact, cand_reg_fact;
667         ir_nodeset_iterator_t iter;
668         /* Note: register pressure calculation needs an overhaul, you need correct
669          * tracking for each register class indidually and weight by each class
670         int         cur_pressure = ir_nodeset_size(lv); */
671         int         cur_pressure = 1;
672
673         /* prefer instructions which can be scheduled early */
674 #define PRIO_TIME        3
675         /* prefer instructions with lots of successors */
676 #define PRIO_NUMSUCCS    8
677         /* prefer instructions with long critical path */
678 #define PRIO_LEVEL      12
679         /* prefer instructions coming early in preorder */
680 #define PRIO_PREORD      8
681         /* weight of current register pressure */
682 #define PRIO_CUR_PRESS  20
683         /* weight of register pressure difference */
684 #define PRIO_CHG_PRESS   8
685
686         /* priority based selection, heuristic inspired by mueller diss */
687         foreach_ir_nodeset(ns, irn, iter) {
688                 /* make sure that branches are scheduled last */
689                 if (!is_cfop(irn)) {
690                         int rdiff = get_irn_reg_diff(trace_env, irn);
691                         int sign  = rdiff < 0;
692                         int chg   = (rdiff < 0 ? -rdiff : rdiff) << PRIO_CHG_PRESS;
693
694                         reg_fact = chg * cur_pressure;
695                         if (reg_fact < chg)
696                                 reg_fact = INT_MAX - 2;
697                         reg_fact = sign ? -reg_fact : reg_fact;
698
699                         cur_prio = (get_irn_critical_path_len(trace_env, irn) << PRIO_LEVEL)
700                                 //- (get_irn_delay(trace_env, irn) << PRIO_LEVEL)
701                                 + (get_irn_num_user(trace_env, irn) << PRIO_NUMSUCCS)
702                                 - (get_irn_etime(trace_env, irn) << PRIO_TIME)
703                                 //- ((get_irn_reg_diff(trace_env, irn) >> PRIO_CHG_PRESS) << ((cur_pressure >> PRIO_CUR_PRESS) - 3))
704                                 - reg_fact
705                                 + (get_irn_preorder(trace_env, irn) << PRIO_PREORD); /* high preorder means early schedule */
706                         if (cur_prio > max_prio) {
707                                 cand          = irn;
708                                 max_prio      = cur_prio;
709                                 cand_reg_fact = reg_fact;
710                         }
711
712                         DBG((trace_env->dbg, LEVEL_4, "checked NODE %+F\n", irn));
713                         DBG((trace_env->dbg, LEVEL_4, "\tpriority: %d\n", cur_prio));
714                         DBG((trace_env->dbg, LEVEL_4, "\tpath len: %d (%d)\n", get_irn_critical_path_len(trace_env, irn), get_irn_critical_path_len(trace_env, irn) << PRIO_LEVEL));
715                         DBG((trace_env->dbg, LEVEL_4, "\tdelay:    %d (%d)\n", get_irn_delay(trace_env, irn), get_irn_delay(trace_env, irn) << PRIO_LEVEL));
716                         DBG((trace_env->dbg, LEVEL_4, "\t#user:    %d (%d)\n", get_irn_num_user(trace_env, irn), get_irn_num_user(trace_env, irn) << PRIO_NUMSUCCS));
717                         DBG((trace_env->dbg, LEVEL_4, "\tetime:    %d (%d)\n", get_irn_etime(trace_env, irn), 0 - (get_irn_etime(trace_env, irn) << PRIO_TIME)));
718                         DBG((trace_env->dbg, LEVEL_4, "\tpreorder: %d (%d)\n", get_irn_preorder(trace_env, irn), get_irn_preorder(trace_env, irn) << PRIO_PREORD));
719                         DBG((trace_env->dbg, LEVEL_4, "\treg diff: %d (%d)\n", get_irn_reg_diff(trace_env, irn), 0 - reg_fact));
720                         DBG((trace_env->dbg, LEVEL_4, "\tpressure: %d\n", cur_pressure));
721                 }
722         }
723
724         if (cand) {
725                 DBG((trace_env->dbg, LEVEL_4, "heuristic selected %+F:\n", cand));
726         }
727         else {
728                 cand = basic_selection(ns);
729         }
730
731         return cand;
732 }
733
734 static void sched_heuristic(ir_graph *irg)
735 {
736         static const list_sched_selector_t heuristic_selector = {
737                 muchnik_init_graph,
738                 muchnik_init_block,
739                 heuristic_select,
740                 trace_node_ready,    /* node_ready */
741                 trace_update_time,   /* node_selected */
742                 NULL,                /* finish_block */
743                 trace_free           /* finish_graph */
744         };
745         be_list_sched_graph(irg, &heuristic_selector);
746 }
747
748 BE_REGISTER_MODULE_CONSTRUCTOR(be_init_sched_trace)
749 void be_init_sched_trace(void)
750 {
751         be_register_scheduler("heur", sched_heuristic);
752         be_register_scheduler("muchnik", sched_muchnik);
753 }