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