bearch: Disallow passing Projs to get_irn_ops().
[libfirm] / ir / be / beschedtrivial.c
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief       Trivial node selector.
9  * @author      Sebastian Hack
10  * @date        29.08.2006
11  */
12 #include "config.h"
13
14 #include <stdlib.h>
15
16 #include "irgraph.h"
17 #include "irnode.h"
18 #include "irnodeset.h"
19
20 #include "bearch.h"
21 #include "belistsched.h"
22 #include "bemodule.h"
23 #include "besched.h"
24
25 /**
26  * The trivial selector:
27  * Just assure that branches are executed last, otherwise select
28  * the first node ready.
29  */
30 static ir_node *trivial_select(void *block_env, ir_nodeset_t *ready_set)
31 {
32         (void)block_env;
33
34         /* assure that branches and constants are executed last */
35         foreach_ir_nodeset(ready_set, irn, iter) {
36                 if (!is_cfop(irn)) {
37                         return irn;
38                 }
39         }
40
41         /* at last: schedule branches */
42         return ir_nodeset_first(ready_set);
43 }
44
45 static void *trivial_init_graph(ir_graph *irg)
46 {
47         (void)irg;
48         return NULL;
49 }
50
51 static void *trivial_init_block(void *graph_env, ir_node *block)
52 {
53         (void)graph_env;
54         (void)block;
55         return NULL;
56 }
57
58 static void sched_trivial(ir_graph *irg)
59 {
60         static const list_sched_selector_t trivial_selector = {
61                 trivial_init_graph,
62                 trivial_init_block,
63                 trivial_select,
64                 NULL,                /* node_ready */
65                 NULL,                /* node_selected */
66                 NULL,                /* finish_block */
67                 NULL                 /* finish_graph */
68         };
69         be_list_sched_graph(irg, &trivial_selector);
70 }
71
72 BE_REGISTER_MODULE_CONSTRUCTOR(be_init_sched_trivial)
73 void be_init_sched_trivial(void)
74 {
75         be_register_scheduler("trivial", sched_trivial);
76 }