bestack: remove unnecessary keep edges from IncSP nodes
[libfirm] / ir / be / beschedtrivial.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       Trivial node selector.
23  * @author      Sebastian Hack
24  * @date        29.08.2006
25  * @version     $Id$
26  */
27 #include "config.h"
28
29 #include <stdlib.h>
30
31 #include "irgraph.h"
32 #include "irnode.h"
33 #include "irnodeset.h"
34
35 #include "bearch.h"
36 #include "belistsched.h"
37 #include "bemodule.h"
38 #include "besched.h"
39
40 /**
41  * The trivial selector:
42  * Just assure that branches are executed last, otherwise select
43  * the first node ready.
44  */
45 static ir_node *trivial_select(void *block_env, ir_nodeset_t *ready_set)
46 {
47         ir_node               *irn;
48         ir_nodeset_iterator_t  iter;
49         (void)block_env;
50
51         /* assure that branches and constants are executed last */
52         foreach_ir_nodeset(ready_set, irn, iter) {
53                 if (!is_cfop(irn)) {
54                         return irn;
55                 }
56         }
57
58         /* at last: schedule branches */
59         ir_nodeset_iterator_init(&iter, ready_set);
60         irn = ir_nodeset_iterator_next(&iter);
61
62         return irn;
63 }
64
65 static void *trivial_init_graph(ir_graph *irg)
66 {
67         (void)irg;
68         return NULL;
69 }
70
71 static void *trivial_init_block(void *graph_env, ir_node *block)
72 {
73         (void)graph_env;
74         (void)block;
75         return NULL;
76 }
77
78 static void sched_trivial(ir_graph *irg)
79 {
80         static const list_sched_selector_t trivial_selector = {
81                 trivial_init_graph,
82                 trivial_init_block,
83                 trivial_select,
84                 NULL,                /* node_ready */
85                 NULL,                /* node_selected */
86                 NULL,                /* finish_block */
87                 NULL                 /* finish_graph */
88         };
89         be_list_sched_graph(irg, &trivial_selector);
90 }
91
92 BE_REGISTER_MODULE_CONSTRUCTOR(be_init_sched_trivial);
93 void be_init_sched_trivial(void)
94 {
95         be_register_scheduler("trivial", sched_trivial);
96 }