Changed phase node initializer to take const ir_node
[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 /**
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
38 typedef struct _ilp_sched_selector_t    ilp_sched_selector_t;
39 typedef struct _ilp_sched_selector_if_t ilp_sched_selector_if_t;
40
41 /**
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.
46  */
47 struct _ilp_sched_selector_if_t {
48
49         /**
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.
54          */
55         void *(*init_irg_ilp_schedule)(const void *self, ir_graph *irg);
56
57         /**
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.
62          */
63         void (*finish_irg_ilp_schedule)(const void *self, ir_graph *irg, void *irg_env);
64
65         /**
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.
70          */
71         void *(*init_block_ilp_schedule)(const void *self, ir_node *block);
72
73         /**
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.
78          */
79         void (*finish_block_ilp_schedule)(const void *self, ir_node *block, void *block_env);
80
81         /**
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.
87          */
88         unsigned (*latency)(const void *self, ir_node *irn, void *block_env);
89
90         /**
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.
96          */
97         void (*node_scheduled)(const void *self, const ir_node *irn, unsigned cycle, void *block_env);
98 };
99
100 /**
101  * The actual ILP schedule selector.
102  */
103 struct _ilp_sched_selector_t {
104         ilp_sched_selector_if_t *impl;
105 };
106
107 /**
108  * Some helper macros.
109  */
110 #define BE_ILP_SCHED_CALL(func, self, obj, env)       \
111         do {                                              \
112                 if ((self) && (self)->impl->func)             \
113                         (self)->impl->func((self), (obj), (env)); \
114         } while (0)
115
116 #define BE_ILP_SCHED_CALL2(func, self, obj, obj2, env)        \
117         do {                                                      \
118                 if ((self) && (self)->impl->func)                     \
119                         (self)->impl->func((self), (obj), (obj2), (env)); \
120         } while (0)
121
122 #define BE_ILP_SCHED_CALL_ENVRET(func, self, obj, defret) \
123         ((self) && (self)->impl->func ? (self)->impl->func((self), (obj)) : (defret))
124
125 #define BE_ILP_SCHED_CALL_RET(func, self, obj, env, defret) \
126         ((self) && (self)->impl->func ? (self)->impl->func((self), (obj), (env)) : (defret))
127
128 /**
129  * Convenience macros for all functions.
130  */
131
132 #define be_ilp_sched_init_irg_ilp_schedule(self, irg) \
133         BE_ILP_SCHED_CALL_ENVRET(init_irg_ilp_schedule, self, irg, NULL)
134
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)
137
138 #define be_ilp_sched_init_block_ilp_schedule(self, block) \
139         BE_ILP_SCHED_CALL_ENVRET(init_block_ilp_schedule, self, block, NULL)
140
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)
143
144 #define be_ilp_sched_latency(self, irn, block_env) \
145         BE_ILP_SCHED_CALL_RET(latency, self, irn, block_env, 0)
146
147 #define be_ilp_sched_node_scheduled(self, irn, cycle, block_env) \
148         BE_ILP_SCHED_CALL2(node_scheduled, self, irn, cycle, block_env)
149
150 /**
151  * Perform ILP scheduling on given birg.
152  */
153 void be_ilp_sched(const be_irg_t *birg, be_options_t *be_opts);
154
155 #endif /* FIRM_BE_BEILPSCHED_H */