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