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