2 * Copyright (C) 1995-2008 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 Primitive list scheduling with different node selectors.
23 * @author Sebastian Hack
27 #ifndef FIRM_BE_BELISTSCHED_H
28 #define FIRM_BE_BELISTSCHED_H
30 #include "firm_types.h"
31 #include "irnodeset.h"
39 * Checks, if a node is to appear in a schedule. Such nodes either
40 * consume real data (mode datab) or produce such.
41 * @param irn The node to check for.
42 * @return 1, if the node consumes/produces data, false if not.
44 static inline bool to_appear_in_schedule(const ir_node *irn)
46 switch(get_irn_opcode(irn)) {
60 return mode_is_data(get_irn_mode(irn));
62 return ! (arch_irn_get_flags(irn) & arch_irn_flags_not_scheduled);
67 * A selector interface which is used by the list schedule framework.
68 * You can implement your own list scheduler by implementing these
71 struct list_sched_selector_t {
74 * Called before a graph is being scheduled.
77 * @param vtab The selector vtab.
78 * @param irg The backend graph.
79 * @return The environment pointer that is passed to all other functions in this struct.
81 void *(*init_graph)(const list_sched_selector_t *vtab, ir_graph *irg);
84 * Called before scheduling starts on a block.
87 * @param graph_env The environment.
88 * @param block The block which is to be scheduled.
89 * @return A per-block pointer that is additionally passed to select.
91 void *(*init_block)(void *graph_env, ir_node *block);
94 * The selection function.
95 * It picks one node out of the ready list to be scheduled next.
96 * The function does not have to delete the node from the ready set.
97 * MUST be implemented.
99 * @param block_env Some private information as returned by init_block().
100 * @param sched_head The schedule so far.
101 * @param ready_set A set containing all ready nodes. Pick one of these nodes.
102 * @param live_set A set containing all nodes currently alive.
103 * @return The chosen node.
105 ir_node *(*select)(void *block_env, ir_nodeset_t *ready_set,
106 ir_nodeset_t *live_set);
109 * This function gets executed after a node finally has been made ready.
112 * @param block_env The block environment.
113 * @param irn The node made ready.
114 * @param pred The previously scheduled node.
116 void (*node_ready)(void *block_env, ir_node *irn, ir_node *pred);
119 * This function gets executed after a node finally has been selected.
122 * @param block_env The block environment.
123 * @param irn The selected node.
125 void (*node_selected)(void *block_env, ir_node *irn);
128 * Returns the execution time of node irn.
131 * @param block_env The block environment.
132 * @param irn The selected node.
134 unsigned (*exectime)(void *block_env, const ir_node *irn);
137 * Calculates the latency of executing cycle curr_cycle of node curr in cycle pred_cycle
141 * @param block_env The block environment.
142 * @param pred The previous node.
143 * @param pred_cycle The previous node execution cycle.
144 * @param curr The current node.
145 * @param curr_cycle The current node execution cycle.
147 unsigned (*latency)(void *block_env, const ir_node *pred, int pred_cycle, const ir_node *curr, int curr_cycle);
150 * Called after a block has been scheduled.
153 * @param env The environment.
154 * @param block_env The per block environment as returned by init_block().
156 void (*finish_block)(void *block_env);
159 * Called after a whole graph has been scheduled.
162 * @param env The environment.
164 void (*finish_graph)(void *env);
169 * A trivial selector, that just selects the first ready node.
171 extern const list_sched_selector_t trivial_selector;
174 * A trivial selector that selects a pseudo-random-node (deterministic).
176 extern const list_sched_selector_t random_selector;
179 * A selector that tries to minimize the register pressure.
180 * @note Not really operational yet.
182 extern const list_sched_selector_t reg_pressure_selector;
185 * A selector based on trace scheduling as introduced by Muchnik[TM]
187 extern const list_sched_selector_t muchnik_selector;
190 * A selector based on trace scheduling as introduced by Muchnik[TM]
191 * but using the Mueller heuristic selector.
193 extern const list_sched_selector_t heuristic_selector;
196 * A selector based on the strong normal form theorem (ie minimizing
197 * the register pressure).
199 extern const list_sched_selector_t normal_selector;
202 * List schedule a graph.
203 * Each block in the graph gets a list head to its link field being the
204 * head of the schedule. You can walk this list using the functions in
207 * @param irg The backend irg.
209 void list_sched(ir_graph *irg);