2 * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
20 #ifndef _BEILPSCHED_H_
21 #define _BEILPSCHED_H_
23 #include "firm_config.h"
25 #include "bemachine.h"
28 typedef struct _ilp_sched_selector_t ilp_sched_selector_t;
29 typedef struct _ilp_sched_selector_if_t ilp_sched_selector_if_t;
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.
37 struct _ilp_sched_selector_if_t {
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.
45 void *(*init_irg_ilp_schedule)(const void *self, ir_graph *irg);
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.
53 void (*finish_irg_ilp_schedule)(const void *self, ir_graph *irg, void *irg_env);
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.
61 void *(*init_block_ilp_schedule)(const void *self, ir_node *block);
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.
69 void (*finish_block_ilp_schedule)(const void *self, ir_node *block, void *block_env);
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.
78 unsigned (*latency)(const void *self, ir_node *irn, void *block_env);
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.
87 void (*node_scheduled)(const void *self, ir_node *irn, unsigned cycle, void *block_env);
91 * The actual ILP schedule selector.
93 struct _ilp_sched_selector_t {
94 ilp_sched_selector_if_t *impl;
100 #define BE_ILP_SCHED_CALL(func, self, obj, env) \
102 if ((self) && (self)->impl->func) \
103 (self)->impl->func((self), (obj), (env)); \
106 #define BE_ILP_SCHED_CALL2(func, self, obj, obj2, env) \
108 if ((self) && (self)->impl->func) \
109 (self)->impl->func((self), (obj), (obj2), (env)); \
112 #define BE_ILP_SCHED_CALL_ENVRET(func, self, obj, defret) \
113 ((self) && (self)->impl->func ? (self)->impl->func((self), (obj)) : (defret))
115 #define BE_ILP_SCHED_CALL_RET(func, self, obj, env, defret) \
116 ((self) && (self)->impl->func ? (self)->impl->func((self), (obj), (env)) : (defret))
119 * Convenience macros for all functions.
122 #define be_ilp_sched_init_irg_ilp_schedule(self, irg) \
123 BE_ILP_SCHED_CALL_ENVRET(init_irg_ilp_schedule, self, irg, NULL)
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)
128 #define be_ilp_sched_init_block_ilp_schedule(self, block) \
129 BE_ILP_SCHED_CALL_ENVRET(init_block_ilp_schedule, self, block, NULL)
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)
134 #define be_ilp_sched_latency(self, irn, block_env) \
135 BE_ILP_SCHED_CALL_RET(latency, self, irn, block_env, 0)
137 #define be_ilp_sched_node_scheduled(self, irn, cycle, block_env) \
138 BE_ILP_SCHED_CALL2(node_scheduled, self, irn, cycle, block_env)
141 * Perform ILP scheduling on given birg.
143 void be_ilp_sched(const be_irg_t *birg, be_options_t *be_opts);
145 #endif /* _BEILPSCHED_H_ */