use ir_nodeset in scheduler
[libfirm] / ir / be / beschedtrivial.c
1 /**
2  * Trivial node selector.
3  * @author Christian Wuerdig
4  * @date   29.08.2006
5  * @cvs-id $Id$
6  */
7 #ifdef HAVE_CONFIG_H
8 #include <config.h>
9 #endif
10
11 #include <stdlib.h>
12
13 #include "besched_t.h"
14 #include "belistsched.h"
15
16 /**
17  * The trivial selector:
18  * Just assure that branches are executed last, otherwise select
19  * the first node ready.
20  */
21 static ir_node *trivial_select(void *block_env, ir_nodeset_t *ready_set, ir_nodeset_t *live_set)
22 {
23         const arch_env_t *arch_env = block_env;
24         ir_node          *irn      = NULL;
25         ir_nodeset_iterator_t iter;
26
27         /* assure that branches and constants are executed last */
28         foreach_ir_nodeset(ready_set, irn, iter) {
29                 if (! arch_irn_class_is(arch_env, irn, branch)) {
30                         return irn;
31                 }
32         }
33
34         /* at last: schedule branches */
35         ir_nodeset_iterator_init(&iter, ready_set);
36         irn = ir_nodeset_iterator_next(&iter);
37
38         return irn;
39 }
40
41 static void *trivial_init_graph(const list_sched_selector_t *vtab, const arch_env_t *arch_env, ir_graph *irg)
42 {
43         return (void *)arch_env;
44 }
45
46 static void *trivial_init_block(void *graph_env, ir_node *bl)
47 {
48         return graph_env;
49 }
50
51 static const list_sched_selector_t trivial_selector_struct = {
52         trivial_init_graph,
53         trivial_init_block,
54         trivial_select,
55         NULL,                /* to_appear_in_schedule */
56         NULL,                /* node_ready */
57         NULL,                /* node_selected */
58         NULL,                /* exectime */
59         NULL,                /* latency */
60         NULL,                /* finish_block */
61         NULL                 /* finish_graph */
62 };
63
64 const list_sched_selector_t *trivial_selector = &trivial_selector_struct;