renamed structures containing settings to ir_settings_*_t and place them in firm_types.h
[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_root(succ, block)) {
395                         mark_root_node(env, succ);
396                         set_irn_link(succ, root);
397                         root = succ;
398                 }
399                 else
400                         set_irn_link(succ, MARK);
401         }
402
403         /* Second step: calculate the pre-order list. */
404         preord = NULL;
405         for (curr = root; curr; curr = irn) {
406                 irn = get_irn_link(curr);
407                 DBG((env->dbg, LEVEL_2, "   DAG root %+F\n", curr));
408                 descent(curr, block, &preord, env, 0);
409         }
410         root = preord;
411
412         /* Third step: calculate the Delay. Note that our
413         * list is now in pre-order, starting at root
414         */
415         for (cur_pos = 0, curr = root; curr; curr = get_irn_link(curr), cur_pos++) {
416                 sched_timestep_t d;
417
418                 if (arch_irn_class_is(env->arch_env, curr, branch)) {
419                         /* assure, that branches can be executed last */
420                         d = 0;
421                 }
422                 else {
423                         if (is_root_node(env, curr))
424                                 d = exectime(env, curr);
425                         else {
426                                 d = 0;
427                                 foreach_out_edge(curr, edge) {
428                                         ir_node *n = get_edge_src_irn(edge);
429
430                                         if (get_nodes_block(n) == block) {
431                                                 sched_timestep_t ld;
432
433                                                 ld = latency(env, curr, 1, n, 0) + get_irn_delay(env, n);
434                                                 d = ld > d ? ld : d;
435                                         }
436                                 }
437                         }
438                 }
439                 set_irn_delay(env, curr, d);
440                 DB((env->dbg, LEVEL_2, "\t%+F delay %u\n", curr, d));
441
442                 /* set the etime of all nodes to 0 */
443                 set_irn_etime(env, curr, 0);
444
445                 set_irn_preorder(env, curr, cur_pos);
446         }
447 }
448
449 /**
450  * This functions gets called after a node finally has been made ready.
451  */
452 static void trace_node_ready(void *data, ir_node *irn, ir_node *pred) {
453         trace_env_t *env = data;
454         sched_timestep_t etime_p, etime;
455
456         etime = env->curr_time;
457         if (pred) {
458                 etime_p = get_irn_etime(env, pred);
459                 etime  += latency(env, pred, 1, irn, 0);
460                 etime   = etime_p > etime ? etime_p : etime;
461         }
462
463         set_irn_etime(env, irn, etime);
464         DB((env->dbg, LEVEL_2, "\tset etime of %+F to %u\n", irn, etime));
465 }
466
467 /**
468  * Update the current time after irn has been selected.
469  */
470 static void trace_update_time(void *data, ir_node *irn) {
471         trace_env_t *env = data;
472         if (is_Phi(irn) || get_irn_opcode(irn) == iro_Start) {
473                 env->curr_time += get_irn_etime(env, irn);
474         }
475         else {
476                 env->curr_time += exectime(env, irn);
477         }
478 }
479
480 /**
481  * Allocates memory and initializes trace scheduling environment.
482  * @param birg   The backend irg object
483  * @return The environment
484  */
485 static trace_env_t *trace_init(const arch_env_t *arch_env, ir_graph *irg) {
486         trace_env_t *env = xcalloc(1, sizeof(*env));
487         int         nn   = get_irg_last_idx(irg);
488
489         env->arch_env   = arch_env;
490         env->curr_time  = 0;
491         env->sched_info = NEW_ARR_F(trace_irn_t, nn);
492         env->liveness   = be_liveness(irg);
493         FIRM_DBG_REGISTER(env->dbg, "firm.be.sched.trace");
494
495         be_liveness_assure_chk(env->liveness);
496         memset(env->sched_info, 0, nn * sizeof(*(env->sched_info)));
497
498         return env;
499 }
500
501 /**
502  * Frees all memory allocated for trace scheduling environment.
503  * @param env  The environment
504  */
505 static void trace_free(void *data) {
506         trace_env_t *env = data;
507         be_liveness_free(env->liveness);
508         DEL_ARR_F(env->sched_info);
509         free(env);
510 }
511
512 /**
513  * Simple selector. Just assure that jumps are scheduled last.
514  */
515 static ir_node *basic_selection(const arch_env_t *arch_env, ir_nodeset_t *ready_set) {
516         ir_node *irn = NULL;
517         ir_nodeset_iterator_t iter;
518
519         /* assure that branches and constants are executed last */
520         foreach_ir_nodeset(ready_set, irn, iter) {
521                 if (! arch_irn_class_is(arch_env, irn, branch)) {
522                         return irn;
523                 }
524         }
525
526         /* at last: schedule branches */
527         irn = get_nodeset_node(ready_set);
528
529         return irn;
530 }
531
532 /**
533 * The muchnik selector.
534 */
535 static ir_node *muchnik_select(void *block_env, ir_nodeset_t *ready_set, ir_nodeset_t *live_set)
536 {
537         trace_env_t *env = block_env;
538         ir_nodeset_t mcands, ecands;
539         ir_nodeset_iterator_t iter;
540         sched_timestep_t max_delay = 0;
541         ir_node *irn;
542         (void) live_set;
543
544         /* calculate the max delay of all candidates */
545         foreach_ir_nodeset(ready_set, irn, iter) {
546                 sched_timestep_t d = get_irn_delay(env, irn);
547
548                 max_delay = d > max_delay ? d : max_delay;
549         }
550
551         ir_nodeset_init_size(&mcands, 8);
552         ir_nodeset_init_size(&ecands, 8);
553
554         /* build mcands and ecands */
555         foreach_ir_nodeset(ready_set, irn, iter) {
556                 if (get_irn_delay(env, irn) == max_delay) {
557                         ir_nodeset_insert(&mcands, irn);
558                         if (get_irn_etime(env, irn) <= env->curr_time)
559                                 ir_nodeset_insert(&ecands, irn);
560                 }
561         }
562
563         /* select a node */
564         if (ir_nodeset_size(&mcands) == 1) {
565                 irn = get_nodeset_node(&mcands);
566                 DB((env->dbg, LEVEL_3, "\tirn = %+F, mcand = 1, max_delay = %u\n", irn, max_delay));
567         }
568         else {
569                 int cnt = ir_nodeset_size(&ecands);
570                 if (cnt == 1) {
571                         irn = get_nodeset_node(&ecands);
572
573                         if (arch_irn_class_is(env->arch_env, irn, branch)) {
574                                 /* BEWARE: don't select a JUMP if others are still possible */
575                                 goto force_mcands;
576                         }
577                         DB((env->dbg, LEVEL_3, "\tirn = %+F, ecand = 1, max_delay = %u\n", irn, max_delay));
578                 }
579                 else if (cnt > 1) {
580                         DB((env->dbg, LEVEL_3, "\tecand = %d, max_delay = %u\n", cnt, max_delay));
581                         irn = basic_selection(env->arch_env, &ecands);
582                 }
583                 else {
584 force_mcands:
585                         DB((env->dbg, LEVEL_3, "\tmcand = %d\n", ir_nodeset_size(&mcands)));
586                         irn = basic_selection(env->arch_env, &mcands);
587                 }
588         }
589
590         return irn;
591 }
592
593 static void *muchnik_init_graph(const list_sched_selector_t *vtab, const arch_env_t *arch_env, ir_graph *irg)
594 {
595         trace_env_t *env  = trace_init(arch_env, irg);
596         env->selector     = vtab;
597         env->selector_env = (void*) arch_env;
598         return (void *)env;
599 }
600
601 static void *muchnik_init_block(void *graph_env, ir_node *bl)
602 {
603         trace_preprocess_block(graph_env, bl);
604         return graph_env;
605 }
606
607 static const list_sched_selector_t muchnik_selector_struct = {
608         muchnik_init_graph,
609         muchnik_init_block,
610         muchnik_select,
611         NULL,                /* to_appear_in_schedule */
612         trace_node_ready,    /* node_ready */
613         trace_update_time,   /* node_selected */
614         NULL,                /* exectime */
615         NULL,                /* latency */
616         NULL,                /* finish_block */
617         trace_free           /* finish_graph */
618 };
619
620 const list_sched_selector_t *muchnik_selector = &muchnik_selector_struct;
621
622 /**
623  * Execute the heuristic function.
624  */
625 static ir_node *heuristic_select(void *block_env, ir_nodeset_t *ns, ir_nodeset_t *lv)
626 {
627         trace_env_t *trace_env   = block_env;
628         ir_node     *irn, *cand  = NULL;
629         int         max_prio     = INT_MIN;
630         int         cur_prio     = INT_MIN;
631         int         cur_pressure = ir_nodeset_size(lv);
632         int         reg_fact, cand_reg_fact;
633         ir_nodeset_iterator_t iter;
634
635         /* prefer instructions which can be scheduled early */
636 #define PRIO_TIME        3
637         /* prefer instructions with lots of successors */
638 #define PRIO_NUMSUCCS    8
639         /* prefer instructions with long critical path */
640 #define PRIO_LEVEL      12
641         /* prefer instructions coming early in preorder */
642 #define PRIO_PREORD      8
643         /* weight of current register pressure */
644 #define PRIO_CUR_PRESS  20
645         /* weight of register pressure difference */
646 #define PRIO_CHG_PRESS   8
647
648         /* priority based selection, heuristic inspired by mueller diss */
649         foreach_ir_nodeset(ns, irn, iter) {
650                 /* make sure that branches are scheduled last */
651                 if (! arch_irn_class_is(trace_env->arch_env, irn, branch)) {
652                         int rdiff = get_irn_reg_diff(trace_env, irn);
653                         int sign  = rdiff < 0;
654                         int chg   = (rdiff < 0 ? -rdiff : rdiff) << PRIO_CHG_PRESS;
655
656                         /* reg_fact = chg << cur_pressure; */
657                         reg_fact = chg * cur_pressure;
658                         if (reg_fact < chg)
659                                 reg_fact = INT_MAX - 2;
660                         reg_fact = sign ? -reg_fact : reg_fact;
661
662                         cur_prio = (get_irn_critical_path_len(trace_env, irn) << PRIO_LEVEL)
663                                 //- (get_irn_delay(trace_env, irn) << PRIO_LEVEL)
664                                 + (get_irn_num_user(trace_env, irn) << PRIO_NUMSUCCS)
665                                 - (get_irn_etime(trace_env, irn) << PRIO_TIME)
666                                 //- ((get_irn_reg_diff(trace_env, irn) >> PRIO_CHG_PRESS) << ((cur_pressure >> PRIO_CUR_PRESS) - 3))
667                                 - reg_fact
668                                 + (get_irn_preorder(trace_env, irn) << PRIO_PREORD); /* high preorder means early schedule */
669                         if (cur_prio > max_prio) {
670                                 cand          = irn;
671                                 max_prio      = cur_prio;
672                                 cand_reg_fact = reg_fact;
673                         }
674
675                         DBG((trace_env->dbg, LEVEL_4, "checked NODE %+F\n", irn));
676                         DBG((trace_env->dbg, LEVEL_4, "\tpriority: %d\n", cur_prio));
677                         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));
678                         DBG((trace_env->dbg, LEVEL_4, "\tdelay:    %d (%d)\n", get_irn_delay(trace_env, irn), get_irn_delay(trace_env, irn) << PRIO_LEVEL));
679                         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));
680                         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)));
681                         DBG((trace_env->dbg, LEVEL_4, "\tpreorder: %d (%d)\n", get_irn_preorder(trace_env, irn), get_irn_preorder(trace_env, irn) << PRIO_PREORD));
682                         DBG((trace_env->dbg, LEVEL_4, "\treg diff: %d (%d)\n", get_irn_reg_diff(trace_env, irn), 0 - reg_fact));
683                         DBG((trace_env->dbg, LEVEL_4, "\tpressure: %d\n", cur_pressure));
684                 }
685         }
686
687         if (cand) {
688                 DBG((trace_env->dbg, LEVEL_4, "heuristic selected %+F:\n", cand));
689         }
690         else {
691                 cand = basic_selection(trace_env->arch_env, ns);
692         }
693
694         return cand;
695 }
696
697 static const list_sched_selector_t heuristic_selector_struct = {
698         muchnik_init_graph,
699         muchnik_init_block,
700         heuristic_select,
701         NULL,                /* to_appear_in_schedule */
702         trace_node_ready,    /* node_ready */
703         trace_update_time,   /* node_selected */
704         NULL,                /* exectime */
705         NULL,                /* latency */
706         NULL,                /* finish_block */
707         trace_free           /* finish_graph */
708 };
709
710 const list_sched_selector_t *heuristic_selector = &heuristic_selector_struct;