simplified code
[libfirm] / ir / be / beschedtrivial.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       Trivial node selector.
23  * @author      Sebastian Hack
24  * @date        29.08.2006
25  * @version     $Id$
26  */
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include <stdlib.h>
32
33 #include "irgraph.h"
34 #include "irnode.h"
35 #include "irnodeset.h"
36
37 #include "bearch.h"
38 #include "belistsched.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                                ir_nodeset_t *live_set)
47 {
48         const arch_env_t *arch_env = block_env;
49         ir_node          *irn      = NULL;
50         ir_nodeset_iterator_t iter;
51         (void) live_set;
52
53         /* assure that branches and constants are executed last */
54         foreach_ir_nodeset(ready_set, irn, iter) {
55                 if (! arch_irn_class_is(arch_env, irn, branch)) {
56                         return irn;
57                 }
58         }
59
60         /* at last: schedule branches */
61         ir_nodeset_iterator_init(&iter, ready_set);
62         irn = ir_nodeset_iterator_next(&iter);
63
64         return irn;
65 }
66
67 static void *trivial_init_graph(const list_sched_selector_t *vtab,
68                                 const arch_env_t *arch_env, ir_graph *irg)
69 {
70         (void) vtab;
71         (void) irg;
72         return (void *)arch_env;
73 }
74
75 static void *trivial_init_block(void *graph_env, ir_node *block)
76 {
77         (void) block;
78         return graph_env;
79 }
80
81 static const list_sched_selector_t trivial_selector_struct = {
82         trivial_init_graph,
83         trivial_init_block,
84         trivial_select,
85         NULL,                /* to_appear_in_schedule */
86         NULL,                /* node_ready */
87         NULL,                /* node_selected */
88         NULL,                /* exectime */
89         NULL,                /* latency */
90         NULL,                /* finish_block */
91         NULL                 /* finish_graph */
92 };
93
94 const list_sched_selector_t *trivial_selector = &trivial_selector_struct;