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