Add ALLOCAN() and ALLOCANZ().
[libfirm] / ir / be / belistsched.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       Primitive list scheduling with different node selectors.
23  * @author      Sebastian Hack
24  * @date        20.10.2004
25  * @version     $Id$
26  */
27 #ifndef FIRM_BE_BELISTSCHED_H
28 #define FIRM_BE_BELISTSCHED_H
29
30 #include "firm_types.h"
31 #include "irnodeset.h"
32
33 #include "be.h"
34 #include "bearch.h"
35 #include "beirg.h"
36
37 typedef struct _list_sched_selector_t list_sched_selector_t;
38
39 /**
40  * A selector interface which is used by the list schedule framework.
41  * You can implement your own list scheduler by implementing these
42  * functions.
43  */
44 struct _list_sched_selector_t {
45
46         /**
47          * Called before a graph is being scheduled.
48          * May be NULL.
49          *
50          * @param vtab     The selector vtab.
51          * @param birg     The backend graph.
52          * @return         The environment pointer that is passed to all other functions in this struct.
53          */
54         void *(*init_graph)(const list_sched_selector_t *vtab, const be_irg_t *birg);
55
56         /**
57          * Called before scheduling starts on a block.
58          * May be NULL.
59          *
60          * @param graph_env   The environment.
61          * @param block       The block which is to be scheduled.
62          * @return A per-block pointer that is additionally passed to select.
63          */
64         void *(*init_block)(void *graph_env, ir_node *block);
65
66         /**
67          * The selection function.
68          * It picks one node out of the ready list to be scheduled next.
69          * The function does not have to delete the node from the ready set.
70          * MUST be implemented.
71          *
72          * @param block_env   Some private information as returned by init_block().
73          * @param sched_head  The schedule so far.
74          * @param ready_set   A set containing all ready nodes. Pick one of these nodes.
75          * @param live_set    A set containing all nodes currently alive.
76          * @return The chosen node.
77          */
78         ir_node *(*select)(void *block_env, ir_nodeset_t *ready_set,
79                        ir_nodeset_t *live_set);
80
81         /**
82          * This function decides, if a node should appear in a schedule.
83          * May be NULL.
84          *
85          * @param block_env The block environment.
86          * @param irn       The node.
87          * @return 1, if the node should be scheduled, 0 if not.
88          */
89         int (*to_appear_in_schedule)(void *block_env, const ir_node *irn);
90
91         /**
92          * This function gets executed after a node finally has been made ready.
93          * May be NULL.
94          *
95          * @param block_env The block environment.
96          * @param irn       The node made ready.
97          * @param pred      The previously scheduled node.
98          */
99         void (*node_ready)(void *block_env, ir_node *irn, ir_node *pred);
100
101         /**
102          * This function gets executed after a node finally has been selected.
103          * May be NULL.
104          *
105          * @param block_env The block environment.
106          * @param irn       The selected node.
107          */
108         void (*node_selected)(void *block_env, ir_node *irn);
109
110         /**
111          * Returns the execution time of node irn.
112          * May be NULL.
113          *
114          * @param block_env The block environment.
115          * @param irn       The selected node.
116          */
117         unsigned (*exectime)(void *block_env, const ir_node *irn);
118
119         /**
120          * Calculates the latency of executing cycle curr_cycle of node curr in cycle pred_cycle
121          * of node pred.
122          * May be NULL.
123          *
124          * @param block_env   The block environment.
125          * @param pred        The previous node.
126          * @param pred_cycle  The previous node execution cycle.
127          * @param curr        The current node.
128          * @param curr_cycle  The current node execution cycle.
129          */
130         unsigned (*latency)(void *block_env, const ir_node *pred, int pred_cycle, const ir_node *curr, int curr_cycle);
131
132         /**
133          * Called after a block has been scheduled.
134          * May be NULL.
135          *
136          * @param env The environment.
137          * @param block_env The per block environment as returned by init_block().
138          */
139         void (*finish_block)(void *block_env);
140
141         /**
142          * Called after a whole graph has been scheduled.
143          * May be NULL.
144          *
145          * @param env The environment.
146          */
147         void (*finish_graph)(void *env);
148 };
149
150
151 /**
152  * A trivial selector, that just selects the first ready node.
153  */
154 extern const list_sched_selector_t trivial_selector;
155
156 /**
157  * A trivial selector that selects a pseudo-random-node (deterministic).
158  */
159 extern const list_sched_selector_t random_selector;
160
161 /**
162  * A selector that tries to minimize the register pressure.
163  * @note Not really operational yet.
164  */
165 extern const list_sched_selector_t reg_pressure_selector;
166
167 /**
168  * A selector based on trace scheduling as introduced by Muchnik[TM]
169  */
170 extern const list_sched_selector_t muchnik_selector;
171
172 /**
173  * A selector based on trace scheduling as introduced by Muchnik[TM]
174  * but using the Mueller heuristic selector.
175  */
176 extern const list_sched_selector_t heuristic_selector;
177
178 /**
179  * A selector based on the strong normal form theorem (ie minimizing
180  * the register pressure).
181  */
182 extern const list_sched_selector_t normal_selector;
183
184 /**
185  * List schedule a graph.
186  * Each block in the graph gets a list head to its link field being the
187  * head of the schedule. You can walk this list using the functions in
188  * list.h.
189  *
190  * @param birg    The backend irg.
191  * @param be_opts The backend options
192  */
193 void list_sched(be_irg_t *birg, be_options_t *be_opts);
194
195 /**
196  * List schedule a block.
197  * Same as list_sched but only for a certain block (needed for ILP fallback).
198  */
199 void list_sched_single_block(const be_irg_t *birg, ir_node *block, be_options_t *be_opts);
200
201 #endif /* FIRM_BE_BELISTSCHED_H */