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