fallback to list scheduler when ILP fails
[libfirm] / ir / be / beilpsched.h
1 #ifndef _BEILPSCHED_H_
2 #define _BEILPSCHED_H_
3
4 #include "firm_config.h"
5
6 #include "bemachine.h"
7 #include "beirg.h"
8
9 typedef struct _ilp_sched_selector_t    ilp_sched_selector_t;
10 typedef struct _ilp_sched_selector_if_t ilp_sched_selector_if_t;
11
12 /**
13  * A selector interface which is used by the ILP schedule framework.
14  * These functions provide the ILP scheduler with necessary information
15  * from the backend or they pass back information to the backend about
16  * the state of scheduling.
17  */
18 struct _ilp_sched_selector_if_t {
19
20         /**
21          * This function is called before the scheduling of the irg.
22          * @param self    The this pointer.
23          * @param irg     The irg being scheduled.
24          * @return An irg scheduling environment.
25          */
26         void *(*init_irg_ilp_schedule)(const void *self, ir_graph *irg);
27
28         /**
29          * This functions is called after an irg has been scheduled.
30          * @param self    The this pointer.
31          * @param irg     The irg which has been scheduled.
32          * @param irg_env The irg scheduling environment.
33          */
34         void (*finish_irg_ilp_schedule)(const void *self, ir_graph *irg, void *irg_env);
35
36         /**
37          * This function is called before the scheduling of a block starts.
38          * @param self       The this pointer.
39          * @param block      The block being scheduled.
40          * @return A block scheduling environment.
41          */
42         void *(*init_block_ilp_schedule)(const void *self, ir_node *block);
43
44         /**
45          * This functions is called after a block has been scheduled.
46          * @param self      The this pointer.
47          * @param block     The block which has been scheduled.
48          * @param block_env The block scheduling environment.
49          */
50         void (*finish_block_ilp_schedule)(const void *self, ir_node *block, void *block_env);
51
52         /**
53          * Calculates the latency of node @p irn.
54          * @param self       The this pointer.
55          * @param irn        The node.
56          * @param block_env  The block scheduling environment.
57          * @return The latency in cycles of node @p irn.
58          */
59         unsigned (*latency)(const void *self, ir_node *irn, void *block_env);
60
61         /**
62          * This function is called after a certain node has been scheduled.
63          * @param self       The this pointer.
64          * @param irn        The node which has been scheduled.
65          * @param cycle      The cycle at which the node is scheduled.
66          * @param block_env  The block scheduling environment.
67          */
68         void (*node_scheduled)(const void *self, ir_node *irn, unsigned cycle, void *block_env);
69 };
70
71 /**
72  * The actual ILP schedule selector.
73  */
74 struct _ilp_sched_selector_t {
75         ilp_sched_selector_if_t *impl;
76 };
77
78 /**
79  * Some helper macros.
80  */
81 #define BE_ILP_SCHED_CALL(func, self, obj, env)       \
82         do {                                              \
83                 if ((self) && (self)->impl->func)             \
84                         (self)->impl->func((self), (obj), (env)); \
85         } while (0)
86
87 #define BE_ILP_SCHED_CALL2(func, self, obj, obj2, env)        \
88         do {                                                      \
89                 if ((self) && (self)->impl->func)                     \
90                         (self)->impl->func((self), (obj), (obj2), (env)); \
91         } while (0)
92
93 #define BE_ILP_SCHED_CALL_ENVRET(func, self, obj, defret) \
94         ((self) && (self)->impl->func ? (self)->impl->func((self), (obj)) : (defret))
95
96 #define BE_ILP_SCHED_CALL_RET(func, self, obj, env, defret) \
97         ((self) && (self)->impl->func ? (self)->impl->func((self), (obj), (env)) : (defret))
98
99 /**
100  * Convenience macros for all functions.
101  */
102
103 #define be_ilp_sched_init_irg_ilp_schedule(self, irg) \
104         BE_ILP_SCHED_CALL_ENVRET(init_irg_ilp_schedule, self, irg, NULL)
105
106 #define be_ilp_sched_finish_irg_ilp_schedule(self, irg, irg_env) \
107         BE_ILP_SCHED_CALL(finish_irg_ilp_schedule, self, irg, irg_env)
108
109 #define be_ilp_sched_init_block_ilp_schedule(self, block) \
110         BE_ILP_SCHED_CALL_ENVRET(init_block_ilp_schedule, self, block, NULL)
111
112 #define be_ilp_sched_finish_block_ilp_schedule(self, block, block_env) \
113         BE_ILP_SCHED_CALL(finish_block_ilp_schedule, self, block, block_env)
114
115 #define be_ilp_sched_latency(self, irn, block_env) \
116         BE_ILP_SCHED_CALL_RET(latency, self, irn, block_env, 0)
117
118 #define be_ilp_sched_node_scheduled(self, irn, cycle, block_env) \
119         BE_ILP_SCHED_CALL2(node_scheduled, self, irn, cycle, block_env)
120
121 /**
122  * Perform ILP scheduling on given birg.
123  */
124 void be_ilp_sched(const be_irg_t *birg, be_options_t *be_opts);
125
126 #endif /* _BEILPSCHED_H_ */