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