23edb1b574b5c858eccb2158080b1baf5998663f
[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 "benodesets.h"
13 #include "bearch_t.h"
14 #include "be_t.h"
15
16 typedef struct _list_sched_selector_t list_sched_selector_t;
17
18 /**
19  * A selector interface which is used by the list schedule framework.
20  * You can implement your own list scheduler by implementing these
21  * functions.
22  */
23 struct _list_sched_selector_t {
24
25         /**
26          * Called before a graph is being scheduled.
27          * @param arch_env The architecture environment.
28          * @param irg      The graph.
29          * @return         The environment pointer that is passed to all other functions in this struct.
30          */
31         void *(*init_graph)(const list_sched_selector_t *vtab, const arch_env_t *arch_env, ir_graph *irg);
32
33         /**
34          * Called before scheduling starts on a block.
35          * @param graph_env The environment.
36          * @param block The block which is to be scheduled.
37          * @return A per-block pointer that is additionally passed to select.
38          */
39         void *(*init_block)(void *graph_env, ir_node *block);
40
41         /**
42          * The selection function.
43          * It picks one node out of the ready list to be scheduled next.
44          * The function does not have to delete the node from the ready set.
45          *
46          * @return block_env Some private information as returned by init_block().
47          * @param sched_head The schedule so far.
48          * @param curr_time The current time step which the picked node
49          * will be assigned to.
50          * @param ready_list A set containing all ready nodes. Pick one of these
51          * nodes.
52          * @return The chosen node.
53          */
54         ir_node *(*select)(void *block_env, nodeset *ready_set);
55
56         /**
57          * This function decides, if a node should appear in a schedule.
58          * @param block_env The block environment.
59          * @param irn       The node.
60          * @return 1, if the node should be scheduled, 0 if not.
61          */
62         int (*to_appear_in_schedule)(void *block_env, const ir_node *irn);
63
64         /**
65          * Returns the execution time of node irn.
66          */
67         unsigned (*exectime)(void *block_env, const ir_node *irn);
68
69         /**
70          * Calculates the latency of executing cycle curr_cycle of node curr in cycle pred_cycle
71          * of node pred.
72          *
73          * @param block_env   The block environment.
74          * @param pred        The previous node.
75          * @param pred_cycle  The previous node execution cycle.
76          * @param curr        The current node.
77          * @param curr_cycle  The current node execution cycle.
78          */
79         unsigned (*latency)(void *block_env, const ir_node *pred, int pred_cycle, const ir_node *curr, int curr_cycle);
80
81         /**
82          * Called after a block has been scheduled.
83          * @param env The environment.
84          * @param block_env The per block environment as returned by init_block().
85          */
86         void (*finish_block)(void *block_env);
87
88         /**
89          * Called after a whole graph has been scheduled.
90          * @param env The environment.
91          */
92         void (*finish_graph)(void *env);
93
94 };
95
96
97 /**
98  * A trivial selector, that just selects the first ready node.
99  */
100 extern const list_sched_selector_t *trivial_selector;
101
102 /**
103  * A selector that tries to minimize the register pressure.
104  * @note Not really operational yet.
105  */
106 extern const list_sched_selector_t *reg_pressure_selector;
107
108 /**
109  * List schedule a graph.
110  * Each block in the graph gets a list head to its link field being the
111  * head of the schedule. You can walk this list using the functions in
112  * list.h.
113  * @param birg The backend irg.
114  */
115 void list_sched(const be_irg_t *birg, int disable_mris);
116
117 #endif /* _FIRM_LIST_SCHED */