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 * A selector interface which is used by the list schedule framework.
40 * You can implement your own list scheduler by implementing these
43 struct list_sched_selector_t {
46 * Called before a graph is being scheduled.
49 * @param vtab The selector vtab.
50 * @param irg The backend graph.
51 * @return The environment pointer that is passed to all other functions in this struct.
53 void *(*init_graph)(const list_sched_selector_t *vtab, ir_graph *irg);
56 * Called before scheduling starts on a block.
59 * @param graph_env The environment.
60 * @param block The block which is to be scheduled.
61 * @return A per-block pointer that is additionally passed to select.
63 void *(*init_block)(void *graph_env, ir_node *block);
66 * The selection function.
67 * It picks one node out of the ready list to be scheduled next.
68 * The function does not have to delete the node from the ready set.
69 * MUST be implemented.
71 * @param block_env Some private information as returned by init_block().
72 * @param sched_head The schedule so far.
73 * @param ready_set A set containing all ready nodes. Pick one of these nodes.
74 * @param live_set A set containing all nodes currently alive.
75 * @return The chosen node.
77 ir_node *(*select)(void *block_env, ir_nodeset_t *ready_set,
78 ir_nodeset_t *live_set);
81 * This function gets executed after a node finally has been made ready.
84 * @param block_env The block environment.
85 * @param irn The node made ready.
86 * @param pred The previously scheduled node.
88 void (*node_ready)(void *block_env, ir_node *irn, ir_node *pred);
91 * This function gets executed after a node finally has been selected.
94 * @param block_env The block environment.
95 * @param irn The selected node.
97 void (*node_selected)(void *block_env, ir_node *irn);
100 * Returns the execution time of node irn.
103 * @param block_env The block environment.
104 * @param irn The selected node.
106 unsigned (*exectime)(void *block_env, const ir_node *irn);
109 * Calculates the latency of executing cycle curr_cycle of node curr in cycle pred_cycle
113 * @param block_env The block environment.
114 * @param pred The previous node.
115 * @param pred_cycle The previous node execution cycle.
116 * @param curr The current node.
117 * @param curr_cycle The current node execution cycle.
119 unsigned (*latency)(void *block_env, const ir_node *pred, int pred_cycle, const ir_node *curr, int curr_cycle);
122 * Called after a block has been scheduled.
125 * @param env The environment.
126 * @param block_env The per block environment as returned by init_block().
128 void (*finish_block)(void *block_env);
131 * Called after a whole graph has been scheduled.
134 * @param env The environment.
136 void (*finish_graph)(void *env);
141 * A trivial selector, that just selects the first ready node.
143 extern const list_sched_selector_t trivial_selector;
146 * A trivial selector that selects a pseudo-random-node (deterministic).
148 extern const list_sched_selector_t random_selector;
151 * A selector that tries to minimize the register pressure.
152 * @note Not really operational yet.
154 extern const list_sched_selector_t reg_pressure_selector;
157 * A selector based on trace scheduling as introduced by Muchnik[TM]
159 extern const list_sched_selector_t muchnik_selector;
162 * A selector based on trace scheduling as introduced by Muchnik[TM]
163 * but using the Mueller heuristic selector.
165 extern const list_sched_selector_t heuristic_selector;
168 * A selector based on the strong normal form theorem (ie minimizing
169 * the register pressure).
171 extern const list_sched_selector_t normal_selector;
174 * List schedule a graph.
175 * Each block in the graph gets a list head to its link field being the
176 * head of the schedule. You can walk this list using the functions in
179 * @param irg The backend irg.
181 void list_sched(ir_graph *irg);
184 * List schedule a block.
185 * Same as list_sched but only for a certain block (needed for ILP fallback).
187 void list_sched_single_block(ir_graph *irg, ir_node *block);