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