680cafc5e7df77d31e0fee6548abac93d05ff61f
[libfirm] / ir / be / belistsched.h
1 /**
2  * Primitive list scheduling.
3  * @date 20.10.2004
4  * @author Sebastian Hack
5  */
6
7 #ifndef _FIRM_LIST_SCHED
8 #define _FIRM_LIST_SCHED
9
10 #include "firm_types.h"
11
12 #include "pset.h"
13 #include "pmap.h"
14 #include "list.h"
15
16 #include "bearch_t.h"
17
18 typedef struct _list_sched_selector_t list_sched_selector_t;
19
20 /**
21  * A selector interface which is used by the list schedule framework.
22  * You can implement your own list scheduler by implementing these
23  * functions.
24  */
25 struct _list_sched_selector_t {
26
27         /**
28          * Called before a graph is being scheduled.
29          * @param arch_env The architecture environment.
30          * @param irg      The graph.
31          * @return         The environment pointer that is passed to all other functions in this struct.
32          */
33         void *(*init_graph)(const list_sched_selector_t *vtab, const arch_env_t *arch_env, ir_graph *irg);
34
35         /**
36          * Called before scheduling starts on a block.
37          * @param graph_env The environment.
38          * @param block The block which is to be scheduled.
39          * @return A per-block pointer that is additionally passed to select.
40          */
41         void *(*init_block)(void *graph_env, ir_node *block);
42
43         /**
44          * The selection function.
45          * It picks one node out of the ready list to be scheduled next.
46          * The function does not have to delete the node from the ready set.
47          *
48          * @return block_env Some private information as returned by init_block().
49          * @param sched_head The schedule so far.
50          * @param curr_time The current time step which the picked node
51          * will be assigned to.
52          * @param ready_list A set containing all ready nodes. Pick one of these
53          * nodes.
54          * @return The chosen node.
55          */
56         ir_node *(*select)(void *block_env, pset *ready_set);
57
58         /**
59          * This function decides, if a node should appear in a schedule.
60          * @param block_env The block environment.
61          * @param irn       The node.
62          * @return 1, if the node should be scheduled, 0 if not.
63          */
64         int (*to_appear_in_schedule)(void *block_env, const ir_node *irn);
65
66         /**
67          * Called after a block has been scheduled.
68          * @param env The environment.
69          * @param block_env The per block environment as returned by init_block().
70          */
71         void (*finish_block)(void *block_env);
72
73         /**
74          * Called after a whole graph has been scheduled.
75          * @param env The environment.
76          */
77         void (*finish_graph)(void *env);
78
79 };
80
81
82 /**
83  * A trivial selector, that just selects the first ready node.
84  */
85 extern const list_sched_selector_t *trivial_selector;
86
87 /**
88  * A selector that tries to minimize the register pressure.
89  * @note Not really operational yet.
90  */
91 extern const list_sched_selector_t *reg_pressure_selector;
92
93 /**
94  * List schedule a graph.
95  * Each block in the graph gets a list head to its link field being the
96  * head of the schedule. You can walk this list using the functions in
97  * list.h.
98  * @param arch_env The architecture environment.
99  * @param irg      The graph to schedule.
100  */
101 void list_sched(const arch_env_t *arch_env, ir_graph *irg);
102
103 #endif /* _FIRM_LIST_SCHED */