c4096777ec0d0e40ac0fa072ad77f6e468f1baa1
[libfirm] / ir / be / beblocksched.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       Block-scheduling strategies.
23  * @author      Matthias Braun, Christoph Mallon
24  * @date        27.09.2006
25  * @version     $Id$
26  */
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include "beblocksched.h"
32
33 #include <stdlib.h>
34
35 #include "array.h"
36 #include "pdeq.h"
37
38 #include "iredges.h"
39 #include "irgwalk.h"
40 #include "irnode_t.h"
41 #include "irgraph_t.h"
42 #include "irloop.h"
43 #include "irprintf.h"
44 #include "execfreq.h"
45 #include "irdump_t.h"
46 #include "irtools.h"
47 #include "debug.h"
48 #include "beirgmod.h"
49 #include "bemodule.h"
50 #include "be.h"
51
52 #ifdef WITH_ILP
53 #include <lpp/lpp.h>
54 #include <lpp/lpp_net.h>
55 #endif /* WITH_ILP */
56
57 DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
58
59 typedef enum _blocksched_algos_t {
60         BLOCKSCHED_NAIV, BLOCKSCHED_EXTBB, BLOCKSCHED_GREEDY, BLOCKSCHED_ILP
61 } blocksched_algos_t;
62
63 static int algo = BLOCKSCHED_GREEDY;
64
65
66 #ifdef WITH_LIBCORE
67
68 #include <libcore/lc_opts.h>
69 #include <libcore/lc_opts_enum.h>
70 #include <libcore/lc_timing.h>
71
72 static const lc_opt_enum_int_items_t blockschedalgo_items[] = {
73         { "naiv",       BLOCKSCHED_NAIV },
74         { "extbb",      BLOCKSCHED_EXTBB },
75         { "greedy", BLOCKSCHED_GREEDY },
76 #ifdef WITH_ILP
77         { "ilp",    BLOCKSCHED_ILP },
78 #endif /* WITH_ILP */
79         { NULL,     0 }
80 };
81
82 static lc_opt_enum_int_var_t algo_var = {
83         &algo, blockschedalgo_items
84 };
85
86 static const lc_opt_table_entry_t be_blocksched_options[] = {
87         LC_OPT_ENT_ENUM_INT ("algo", "the block scheduling algorithm", &algo_var),
88         LC_OPT_LAST
89 };
90 #endif /* WITH_LIBCORE */
91
92 /*
93  *   ____                   _
94  *  / ___|_ __ ___  ___  __| |_   _
95  * | |  _| '__/ _ \/ _ \/ _` | | | |
96  * | |_| | | |  __/  __/ (_| | |_| |
97  *  \____|_|  \___|\___|\__,_|\__, |
98  *                            |___/
99  */
100
101 typedef struct _blocksched_entry_t {
102         ir_node *block;
103         struct _blocksched_entry_t *next;
104         struct _blocksched_entry_t *prev;
105 } blocksched_entry_t;
106
107 typedef struct _edge_t {
108         ir_node *block;             /**< source block */
109         int     pos;                /**< number of cfg predecessor (target) */
110         double  execfreq;           /**< the frequency */
111         int     highest_execfreq;   /**< flag that indicates whether this edge is the edge with the highest
112                                                                      execfreq pointing away from this block */
113 } edge_t;
114
115 typedef struct _blocksched_env_t {
116         ir_graph       *irg;
117         struct obstack *obst;
118         ir_exec_freq   *execfreqs;
119         edge_t         *edges;
120         pdeq           *worklist;
121         int            blockcount;
122 } blocksched_env_t;
123
124 /**
125  * Collect cfg frequencies of all edges between blocks.
126  * Also determines edge with highest frequency.
127  */
128 static void collect_egde_frequency(ir_node *block, void *data)
129 {
130         blocksched_env_t   *env = data;
131         int                arity;
132         edge_t             edge;
133         blocksched_entry_t *entry;
134
135         entry        = obstack_alloc(env->obst, sizeof(entry[0]));
136         entry->block = block;
137         entry->next  = NULL;
138         entry->prev  = NULL;
139         set_irn_link(block, entry);
140
141         if (block == get_irg_start_block(env->irg))
142                 return;
143
144         arity = get_Block_n_cfgpreds(block);
145
146         if (arity == 1) {
147                 edge.block            = block;
148                 edge.pos              = 0;
149                 edge.execfreq         = get_block_execfreq(env->execfreqs, block);
150                 edge.highest_execfreq = 1;
151                 ARR_APP1(edge_t, env->edges, edge);
152         } else {
153                 int    i;
154                 double highest_execfreq = -1.0;
155                 int    highest_edge_num = -1;
156
157                 edge.block = block;
158                 for (i = 0; i < arity; ++i) {
159                         double  execfreq;
160                         ir_node *pred_block = get_Block_cfgpred_block(block, i);
161
162                         execfreq = get_block_execfreq(env->execfreqs, pred_block);
163
164                         edge.pos              = i;
165                         edge.execfreq         = execfreq;
166                         edge.highest_execfreq = 0;
167                         ARR_APP1(edge_t, env->edges, edge);
168
169                         if (execfreq > highest_execfreq) {
170                                 highest_execfreq = execfreq;
171                                 highest_edge_num = ARR_LEN(env->edges) - 1;
172                         }
173                 }
174
175                 if(highest_edge_num >= 0)
176                         env->edges[highest_edge_num].highest_execfreq = 1;
177         }
178 }
179
180 static int cmp_edges(const void *d1, const void *d2)
181 {
182         const edge_t *e1 = d1;
183         const edge_t *e2 = d2;
184
185         return QSORT_CMP(e2->execfreq, e1->execfreq);
186 }
187
188 static void coalesce_blocks(blocksched_env_t *env)
189 {
190         int i;
191         int edge_count = ARR_LEN(env->edges);
192
193         /* run1: only look at jumps */
194         for (i = 0; i < edge_count; ++i) {
195                 const edge_t *edge  = &env->edges[i];
196                 ir_node      *block = edge->block;
197                 ir_node      *pred_block;
198                 blocksched_entry_t *entry, *pred_entry;
199
200                 /* the block might have been removed already... */
201                 if (is_Bad(get_Block_cfgpred(block, 0)))
202                         continue;
203
204                 /* only check edge with highest frequency */
205                 if (! edge->highest_execfreq)
206                         continue;
207
208                 pred_block = get_Block_cfgpred_block(block, edge->pos);
209                 entry      = get_irn_link(block);
210                 pred_entry = get_irn_link(pred_block);
211
212                 if (pred_entry->next != NULL || entry->prev != NULL)
213                         continue;
214
215                 /* only coalesce jumps */
216                 if (get_block_succ_next(pred_block, get_block_succ_first(pred_block)) != NULL)
217                         continue;
218
219                 /* schedule the 2 blocks behind each other */
220                 DBG((dbg, LEVEL_1, "Coalesce (Jump) %+F -> %+F (%.3g)\n",
221                            pred_entry->block, entry->block, edge->execfreq));
222                 pred_entry->next = entry;
223                 entry->prev      = pred_entry;
224         }
225
226         /* run2: remaining edges */
227         for (i = 0; i < edge_count; ++i) {
228                 const edge_t *edge  = &env->edges[i];
229                 ir_node      *block = edge->block;
230                 ir_node      *pred_block;
231                 blocksched_entry_t *entry, *pred_entry;
232
233                 /* the block might have been removed already... */
234                 if (is_Bad(get_Block_cfgpred(block, 0)))
235                         continue;
236
237                 pred_block = get_Block_cfgpred_block(block, edge->pos);
238                 entry      = get_irn_link(block);
239                 pred_entry = get_irn_link(pred_block);
240
241                 /* is 1 of the blocks already attached to another block? */
242                 if (pred_entry->next != NULL || entry->prev != NULL)
243                         continue;
244
245                 /* schedule the 2 blocks behind each other */
246                 DBG((dbg, LEVEL_1, "Coalesce (CondJump) %+F -> %+F (%.3g)\n",
247                            pred_entry->block, entry->block, edge->execfreq));
248                 pred_entry->next = entry;
249                 entry->prev      = pred_entry;
250         }
251 }
252
253 static void pick_block_successor(blocksched_entry_t *entry, blocksched_env_t *env)
254 {
255         ir_node            *block = entry->block;
256         ir_node            *succ  = NULL;
257         blocksched_entry_t *succ_entry;
258         const ir_edge_t    *edge;
259         double             best_succ_execfreq;
260
261         if (irn_visited(block))
262                 return;
263
264         env->blockcount++;
265         mark_irn_visited(block);
266
267         DBG((dbg, LEVEL_1, "Pick succ of %+F\n", block));
268
269         /* put all successors into the worklist */
270         foreach_block_succ(block, edge) {
271                 ir_node *succ_block = get_edge_src_irn(edge);
272
273                 if (irn_visited(succ_block))
274                         continue;
275
276                 /* we only need to put the first of a series of already connected
277                  * blocks into the worklist */
278                 succ_entry = get_irn_link(succ_block);
279                 while (succ_entry->prev != NULL) {
280                         /* break cycles... */
281                         if (succ_entry->prev->block == succ_block) {
282                                 succ_entry->prev->next = NULL;
283                                 succ_entry->prev       = NULL;
284                                 break;
285                         }
286                         succ_entry = succ_entry->prev;
287                 };
288
289                 if (irn_visited(succ_entry->block))
290                         continue;
291
292                 DBG((dbg, LEVEL_1, "Put %+F into worklist\n", succ_entry->block));
293                 pdeq_putr(env->worklist, succ_entry->block);
294         }
295
296         if (entry->next != NULL) {
297                 pick_block_successor(entry->next, env);
298                 return;
299         }
300
301         DBG((dbg, LEVEL_1, "deciding...\n"));
302         best_succ_execfreq = -1;
303
304         /* no successor yet: pick the successor block with the highest execution
305          * frequency which has no predecessor yet */
306
307         foreach_block_succ(block, edge) {
308                 ir_node *succ_block = get_edge_src_irn(edge);
309                 double  execfreq;
310
311                 if (irn_visited(succ_block))
312                         continue;
313
314                 succ_entry = get_irn_link(succ_block);
315                 if (succ_entry->prev != NULL)
316                         continue;
317
318                 execfreq = get_block_execfreq(env->execfreqs, succ_block);
319                 if (execfreq > best_succ_execfreq) {
320                         best_succ_execfreq = execfreq;
321                         succ = succ_block;
322                 }
323         }
324
325         if (succ == NULL) {
326                 DBG((dbg, LEVEL_1, "pick from worklist\n"));
327
328                 do {
329                         if (pdeq_empty(env->worklist)) {
330                                 DBG((dbg, LEVEL_1, "worklist empty\n"));
331                                 return;
332                         }
333                         succ = pdeq_getl(env->worklist);
334                 } while (irn_visited(succ));
335         }
336
337         succ_entry       = get_irn_link(succ);
338         entry->next      = succ_entry;
339         succ_entry->prev = entry;
340
341         pick_block_successor(succ_entry, env);
342 }
343
344 static blocksched_entry_t *finish_block_schedule(blocksched_env_t *env)
345 {
346         ir_graph           *irg        = env->irg;
347         ir_node            *startblock = get_irg_start_block(irg);
348         blocksched_entry_t *entry      = get_irn_link(startblock);
349
350         set_using_visited(irg);
351         inc_irg_visited(irg);
352
353         env->worklist = new_pdeq();
354         pick_block_successor(entry, env);
355         assert(pdeq_empty(env->worklist));
356         del_pdeq(env->worklist);
357
358         clear_using_visited(irg);
359
360         return entry;
361 }
362
363 static ir_node **create_blocksched_array(blocksched_env_t *env, blocksched_entry_t *first,
364                                                                                 int count, struct obstack* obst)
365 {
366         int                i = 0;
367         ir_node            **block_list;
368         blocksched_entry_t *entry;
369         (void) env;
370
371         block_list = NEW_ARR_D(ir_node *, obst, count);
372         DBG((dbg, LEVEL_1, "Blockschedule:\n"));
373
374         for (entry = first; entry != NULL; entry = entry->next) {
375                 assert(i < count);
376                 block_list[i++] = entry->block;
377                 DBG((dbg, LEVEL_1, "\t%+F\n", entry->block));
378         }
379         assert(i == count);
380
381         return block_list;
382 }
383
384 static ir_node **create_block_schedule_greedy(ir_graph *irg, ir_exec_freq *execfreqs)
385 {
386         blocksched_env_t   env;
387         struct obstack     obst;
388         blocksched_entry_t *start_entry;
389         ir_node            **block_list;
390
391         obstack_init(&obst);
392
393         env.irg        = irg;
394         env.obst       = &obst;
395         env.execfreqs  = execfreqs;
396         env.edges      = NEW_ARR_F(edge_t, 0);
397         env.worklist   = NULL;
398         env.blockcount = 0;
399
400         // collect edge execution frequencies
401         irg_block_walk_graph(irg, collect_egde_frequency, NULL, &env);
402
403         // sort interblock edges by execution frequency
404         qsort(env.edges, ARR_LEN(env.edges), sizeof(env.edges[0]), cmp_edges);
405
406         (void)be_remove_empty_blocks(irg);
407
408         if (algo != BLOCKSCHED_NAIV)
409                 coalesce_blocks(&env);
410
411         start_entry = finish_block_schedule(&env);
412         block_list  = create_blocksched_array(&env, start_entry, env.blockcount, get_irg_obstack(irg));
413
414         DEL_ARR_F(env.edges);
415         obstack_free(&obst, NULL);
416
417         return block_list;
418 }
419
420 /*
421  *  ___ _     ____
422  * |_ _| |   |  _ \
423  *  | || |   | |_) |
424  *  | || |___|  __/
425  * |___|_____|_|
426  *
427  */
428
429 #ifdef WITH_ILP
430 typedef struct _ilp_edge_t {
431         ir_node *block;   /**< source block */
432         int     pos;      /**< number of cfg predecessor (target) */
433         int     ilpvar;
434 } ilp_edge_t;
435
436 typedef struct _blocksched_ilp_env_t {
437         blocksched_env_t env;
438         ilp_edge_t       *ilpedges;
439         lpp_t            *lpp;
440 } blocksched_ilp_env_t;
441
442 typedef struct _blocksched_ilp_entry_t {
443         ir_node *block;
444         struct _blocksched_entry_t *next;
445         struct _blocksched_entry_t *prev;
446
447         int out_cst;
448 } blocksched_ilp_entry_t;
449
450 static int add_ilp_edge(ir_node *block, int pos, double execfreq, blocksched_ilp_env_t *env)
451 {
452         char       name[64];
453         ilp_edge_t edge;
454         int        edgeidx = ARR_LEN(env->ilpedges);
455
456         snprintf(name, sizeof(name), "edge%d", edgeidx);
457
458         edge.block  = block;
459         edge.pos    = pos;
460         edge.ilpvar = lpp_add_var_default(env->lpp, name, lpp_binary, execfreq, 1.0);
461
462         ARR_APP1(ilp_edge_t, env->ilpedges, edge);
463         return edgeidx;
464 }
465
466 static void collect_egde_frequency_ilp(ir_node *block, void *data)
467 {
468         blocksched_ilp_env_t *env        = data;
469         ir_graph             *irg        = env->env.irg;
470         ir_node              *startblock = get_irg_start_block(irg);
471         int                  arity;
472         lpp_cst_t            cst;
473         char                 name[64];
474         int                  out_count;
475         blocksched_ilp_entry_t *entry;
476
477         snprintf(name, sizeof(name), "block_out_constr_%ld", get_irn_node_nr(block));
478         out_count = get_irn_n_edges_kind(block, EDGE_KIND_BLOCK);
479
480         entry          = obstack_alloc(env->env.obst, sizeof(entry[0]));
481         entry->block   = block;
482         entry->next    = NULL;
483         entry->prev    = NULL;
484         entry->out_cst = lpp_add_cst_uniq(env->lpp, name, lpp_greater, out_count - 1);
485         set_irn_link(block, entry);
486
487         if (block == startblock)
488                 return;
489
490         arity = get_irn_arity(block);
491         if (arity == 1) {
492                 double execfreq = get_block_execfreq(env->env.execfreqs, block);
493                 add_ilp_edge(block, 0, execfreq, env);
494         }
495         else {
496                 int i;
497                 int *edgenums = alloca(sizeof(edgenums[0]) * arity);
498
499                 snprintf(name, sizeof(name), "block_in_constr_%ld", get_irn_node_nr(block));
500                 cst = lpp_add_cst_uniq(env->lpp, name, lpp_greater, arity - 1);
501
502                 for (i = 0; i < arity; ++i) {
503                         double     execfreq;
504                         int        edgenum;
505                         ilp_edge_t *edge;
506                         ir_node    *pred_block = get_Block_cfgpred_block(block, i);
507
508                         execfreq = get_block_execfreq(env->env.execfreqs, pred_block);
509                         edgenum  = add_ilp_edge(block, i, execfreq, env);
510                         edge     = &env->ilpedges[edgenum];
511                         lpp_set_factor_fast(env->lpp, cst, edge->ilpvar, 1.0);
512                 }
513         }
514 }
515
516
517 static void coalesce_blocks_ilp(blocksched_ilp_env_t *env)
518 {
519         int  i;
520         int  edge_count = ARR_LEN(env->ilpedges);
521
522         /* complete out constraints */
523         for(i = 0; i < edge_count; ++i) {
524                 const ilp_edge_t *edge  = &env->ilpedges[i];
525                 ir_node          *block = edge->block;
526                 ir_node          *pred;
527                 blocksched_ilp_entry_t *entry;
528
529                 /* the block might have been removed already... */
530                 if (is_Bad(get_Block_cfgpred(block, 0)))
531                         continue;
532
533                 pred  = get_Block_cfgpred_block(block, edge->pos);
534                 entry = get_irn_link(pred);
535
536                 DBG((dbg, LEVEL_1, "Adding out cst to %+F from %+F,%d\n",
537                                   pred, block, edge->pos));
538                 lpp_set_factor_fast(env->lpp, entry->out_cst, edge->ilpvar, 1.0);
539         }
540
541 #if 0
542         {
543                 FILE *f;
544                 char fname[256];
545                 lpp_dump(env->lpp, "lpp.out");
546                 snprintf(fname, sizeof(fname), "lpp_%s.plain", get_irg_dump_name(env->env.irg));
547                 f = fopen(fname, "w");
548                 lpp_dump_plain(env->lpp, f);
549                 fclose(f);
550         }
551 #endif
552
553         //lpp_solve_net(env->lpp, main_env->options->ilp_server, main_env->options->ilp_solver);
554         lpp_solve_net(env->lpp, "i44pc52", "cplex");
555         assert(lpp_is_sol_valid(env->lpp));
556
557         /* Apply results to edges */
558         for (i = 0; i < edge_count; ++i) {
559                 const ilp_edge_t   *edge  = &env->ilpedges[i];
560                 ir_node            *block = edge->block;
561                 ir_node            *pred;
562                 int                is_jump;
563                 blocksched_entry_t *entry;
564                 blocksched_entry_t *pred_entry;
565
566                 /* the block might have been removed already... */
567                 if (is_Bad(get_Block_cfgpred(block, 0)))
568                         continue;
569
570                 is_jump = (int)lpp_get_var_sol(env->lpp, edge->ilpvar);
571                 if (is_jump)
572                         continue;
573
574                 pred       = get_Block_cfgpred_block(block, edge->pos);
575                 entry      = get_irn_link(block);
576                 pred_entry = get_irn_link(pred);
577
578                 assert(entry->prev == NULL && pred_entry->next == NULL);
579                 entry->prev      = pred_entry;
580                 pred_entry->next = entry;
581         }
582 }
583
584 static ir_node **create_block_schedule_ilp(ir_graph *irg, ir_exec_freq *execfreqs)
585 {
586         blocksched_ilp_env_t env;
587         struct obstack       obst;
588         blocksched_entry_t   *start_entry;
589         ir_node              **block_list;
590
591         obstack_init(&obst);
592
593         env.env.irg        = irg;
594         env.env.obst       = &obst;
595         env.env.execfreqs  = execfreqs;
596         env.env.worklist   = NULL;
597         env.env.blockcount = 0;
598         env.ilpedges       = NEW_ARR_F(ilp_edge_t, 0);
599
600         env.lpp = new_lpp("blockschedule", lpp_minimize);
601         lpp_set_time_limit(env.lpp, 20);
602         lpp_set_log(env.lpp, stdout);
603
604         irg_block_walk_graph(irg, collect_egde_frequency_ilp, NULL, &env);
605
606         (void)be_remove_empty_blocks(irg);
607         coalesce_blocks_ilp(&env);
608
609         start_entry = finish_block_schedule(&env.env);
610         block_list  = create_blocksched_array(&env.env, start_entry, env.env.blockcount, get_irg_obstack(irg));
611
612         DEL_ARR_F(env.ilpedges);
613         free_lpp(env.lpp);
614         obstack_free(&obst, NULL);
615
616         return block_list;
617 }
618 #endif /* WITH_ILP */
619
620 /*
621  *  _____      _   ____  ____
622  * | ____|_  _| |_| __ )| __ )
623  * |  _| \ \/ / __|  _ \|  _ \
624  * | |___ >  <| |_| |_) | |_) |
625  * |_____/_/\_\\__|____/|____/
626  *
627  */
628
629 /** A simple forward single linked list. */
630 typedef struct {
631         ir_node  *start;   /**< start of the list */
632         ir_node  *end;     /**< last block in the list */
633         unsigned n_blks;  /**< number of blocks in the list */
634 } anchor;
635
636 static void add_block(anchor *list, ir_node *block) {
637         if (list->start == NULL) {
638                 list->start = block;
639                 list->end   = block;
640         } else {
641                 set_irn_link(list->end, block);
642                 list->end = block;
643         }
644
645         list->n_blks++;
646 }
647
648 static void create_block_list(ir_node *leader_block, anchor *list) {
649         int             i;
650         const ir_edge_t *edge;
651         ir_node         *block = NULL;
652         ir_extblk       *extbb = get_Block_extbb(leader_block);
653
654         if (extbb_visited(extbb))
655                 return;
656         mark_extbb_visited(extbb);
657
658         for (i = 0; i < get_extbb_n_blocks(extbb); ++i) {
659                 block = get_extbb_block(extbb, i);
660                 add_block(list, block);
661         }
662
663         assert(block != NULL);
664
665         /* pick successor extbbs */
666         foreach_block_succ(block, edge) {
667                 ir_node *succ = get_edge_src_irn(edge);
668                 create_block_list(succ, list);
669         }
670
671         for (i = 0; i < get_extbb_n_blocks(extbb) - 1; ++i) {
672                 block = get_extbb_block(extbb, i);
673
674                 foreach_block_succ(block, edge) {
675                         ir_node *succ = get_edge_src_irn(edge);
676                         create_block_list(succ, list);
677                 }
678         }
679 }
680
681 void compute_extbb_execfreqs(ir_graph *irg, ir_exec_freq *execfreqs);
682
683 /*
684  * Calculates a block schedule. The schedule is stored as a linked
685  * list starting at the start_block of the irg.
686  */
687 static ir_node **create_extbb_block_schedule(ir_graph *irg, ir_exec_freq *execfreqs)
688 {
689         anchor list;
690         ir_node **blk_list, *b, *n;
691         unsigned i;
692
693         /* schedule extended basic blocks */
694         compute_extbb_execfreqs(irg, execfreqs);
695         //compute_extbb(irg);
696
697         list.start  = NULL;
698         list.end    = NULL;
699         list.n_blks = 0;
700
701         set_using_irn_link(irg);
702         set_using_visited(irg);
703         inc_irg_block_visited(irg);
704
705         create_block_list(get_irg_start_block(irg), &list);
706
707         /** create an array, so we can go forward and backward */
708         blk_list = NEW_ARR_D(ir_node *, irg->obst,list.n_blks);
709
710         for (i = 0, b = list.start; b; b = n, ++i) {
711                 n = get_irn_link(b);
712                 blk_list[i] = b;
713         }
714
715         clear_using_irn_link(irg);
716         clear_using_visited(irg);
717
718         return blk_list;
719 }
720
721 /*
722  *  __  __       _
723  * |  \/  | __ _(_)_ __
724  * | |\/| |/ _` | | '_ \
725  * | |  | | (_| | | | | |
726  * |_|  |_|\__,_|_|_| |_|
727  *
728  */
729 void be_init_blocksched(void)
730 {
731 #ifdef WITH_LIBCORE
732         lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
733         lc_opt_entry_t *blocksched_grp = lc_opt_get_grp(be_grp, "blocksched");
734
735         lc_opt_add_table(blocksched_grp, be_blocksched_options);
736 #endif
737         FIRM_DBG_REGISTER(dbg, "firm.be.blocksched");
738 }
739
740 BE_REGISTER_MODULE_CONSTRUCTOR(be_init_blocksched);
741
742 ir_node **be_create_block_schedule(ir_graph *irg, ir_exec_freq *execfreqs)
743 {
744         switch(algo) {
745         case BLOCKSCHED_GREEDY:
746         case BLOCKSCHED_NAIV:
747                 return create_block_schedule_greedy(irg, execfreqs);
748         case BLOCKSCHED_EXTBB:
749                 return create_extbb_block_schedule(irg, execfreqs);
750 #ifdef WITH_ILP
751         case BLOCKSCHED_ILP:
752                 return create_block_schedule_ilp(irg, execfreqs);
753 #endif /* WITH_ILP */
754         }
755
756         assert(0 && "unknown blocksched algo");
757         return NULL;
758 }