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
22 * @brief ILP based instruction scheduling.
23 * @author Christian Wuerdig
27 * An ILP scheduler based on
28 * "ILP-based Instruction Scheduling for IA-64"
29 * by Daniel Kaestner and Sebastian Winkel
30 * extended with register pressure constraints by Christian Wuerdig
32 #ifndef FIRM_BE_BEILPSCHED_H
33 #define FIRM_BE_BEILPSCHED_H
38 typedef struct _ilp_sched_selector_t ilp_sched_selector_t;
39 typedef struct _ilp_sched_selector_if_t ilp_sched_selector_if_t;
42 * A selector interface which is used by the ILP schedule framework.
43 * These functions provide the ILP scheduler with necessary information
44 * from the backend or they pass back information to the backend about
45 * the state of scheduling.
47 struct _ilp_sched_selector_if_t {
50 * This function is called before the scheduling of the irg.
51 * @param self The this pointer.
52 * @param irg The irg being scheduled.
53 * @return An irg scheduling environment.
55 void *(*init_irg_ilp_schedule)(const void *self, ir_graph *irg);
58 * This functions is called after an irg has been scheduled.
59 * @param self The this pointer.
60 * @param irg The irg which has been scheduled.
61 * @param irg_env The irg scheduling environment.
63 void (*finish_irg_ilp_schedule)(const void *self, ir_graph *irg, void *irg_env);
66 * This function is called before the scheduling of a block starts.
67 * @param self The this pointer.
68 * @param block The block being scheduled.
69 * @return A block scheduling environment.
71 void *(*init_block_ilp_schedule)(const void *self, ir_node *block);
74 * This functions is called after a block has been scheduled.
75 * @param self The this pointer.
76 * @param block The block which has been scheduled.
77 * @param block_env The block scheduling environment.
79 void (*finish_block_ilp_schedule)(const void *self, ir_node *block, void *block_env);
82 * Calculates the latency of node @p irn.
83 * @param self The this pointer.
84 * @param irn The node.
85 * @param block_env The block scheduling environment.
86 * @return The latency in cycles of node @p irn.
88 unsigned (*latency)(const void *self, ir_node *irn, void *block_env);
91 * This function is called after a certain node has been scheduled.
92 * @param self The this pointer.
93 * @param irn The node which has been scheduled.
94 * @param cycle The cycle at which the node is scheduled.
95 * @param block_env The block scheduling environment.
97 void (*node_scheduled)(const void *self, ir_node *irn, unsigned cycle, void *block_env);
101 * The actual ILP schedule selector.
103 struct _ilp_sched_selector_t {
104 ilp_sched_selector_if_t *impl;
108 * Some helper macros.
110 #define BE_ILP_SCHED_CALL(func, self, obj, env) \
112 if ((self) && (self)->impl->func) \
113 (self)->impl->func((self), (obj), (env)); \
116 #define BE_ILP_SCHED_CALL2(func, self, obj, obj2, env) \
118 if ((self) && (self)->impl->func) \
119 (self)->impl->func((self), (obj), (obj2), (env)); \
122 #define BE_ILP_SCHED_CALL_ENVRET(func, self, obj, defret) \
123 ((self) && (self)->impl->func ? (self)->impl->func((self), (obj)) : (defret))
125 #define BE_ILP_SCHED_CALL_RET(func, self, obj, env, defret) \
126 ((self) && (self)->impl->func ? (self)->impl->func((self), (obj), (env)) : (defret))
129 * Convenience macros for all functions.
132 #define be_ilp_sched_init_irg_ilp_schedule(self, irg) \
133 BE_ILP_SCHED_CALL_ENVRET(init_irg_ilp_schedule, self, irg, NULL)
135 #define be_ilp_sched_finish_irg_ilp_schedule(self, irg, irg_env) \
136 BE_ILP_SCHED_CALL(finish_irg_ilp_schedule, self, irg, irg_env)
138 #define be_ilp_sched_init_block_ilp_schedule(self, block) \
139 BE_ILP_SCHED_CALL_ENVRET(init_block_ilp_schedule, self, block, NULL)
141 #define be_ilp_sched_finish_block_ilp_schedule(self, block, block_env) \
142 BE_ILP_SCHED_CALL(finish_block_ilp_schedule, self, block, block_env)
144 #define be_ilp_sched_latency(self, irn, block_env) \
145 BE_ILP_SCHED_CALL_RET(latency, self, irn, block_env, 0)
147 #define be_ilp_sched_node_scheduled(self, irn, cycle, block_env) \
148 BE_ILP_SCHED_CALL2(node_scheduled, self, irn, cycle, block_env)
151 * Perform ILP scheduling on given birg.
153 void be_ilp_sched(const be_irg_t *birg, be_options_t *be_opts);
155 #endif /* FIRM_BE_BEILPSCHED_H */