2 * Copyright (C) 1995-2010 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 data structures for scheduling nodes in basic blocks.
23 * @author Sebastian Hack, Matthias Braun
25 #ifndef FIRM_BE_BESCHED_H
26 #define FIRM_BE_BESCHED_H
37 static sched_info_t *get_irn_sched_info(const ir_node *node)
39 return &be_get_info(skip_Proj_const(node))->sched_info;
43 * Check, if the node is scheduled.
44 * Block nodes are reported as scheduled as they mark the begin and end
45 * of the scheduling list.
46 * @param irn The node.
47 * @return 1, if the node is scheduled, 0 if not.
49 static inline bool sched_is_scheduled(const ir_node *irn)
51 return get_irn_sched_info(irn)->next != NULL;
55 * Returns the time step of a node. Each node in a block has a timestep
56 * unique to that block. A node schedule before another node has a lower
57 * timestep than this node.
58 * @param irn The node.
59 * @return The time step in the schedule.
61 static inline sched_timestep_t sched_get_time_step(const ir_node *irn)
63 assert(sched_is_scheduled(irn));
64 return get_irn_sched_info(irn)->time_step;
67 static inline bool sched_is_end(const ir_node *node)
69 return is_Block(node);
72 static inline bool sched_is_begin(const ir_node *node)
74 return is_Block(node);
78 * Get the scheduling successor of a node.
79 * @param irn The node.
80 * @return The next ir node in the schedule or the block, if the node has no next node.
82 static inline ir_node *sched_next(const ir_node *irn)
84 const sched_info_t *info = get_irn_sched_info(irn);
89 * Get the scheduling predecessor of a node.
90 * @param irn The node.
91 * @return The next ir node in the schedule or the block, if the node has no predecessor.
94 static inline ir_node *sched_prev(const ir_node *irn)
96 const sched_info_t *info = get_irn_sched_info(irn);
101 * Get the first node in a block schedule.
102 * @param block The block of which to get the schedule.
103 * @return The first node in the schedule or the block itself
104 * if there is no node in the schedule.
106 static inline ir_node *sched_first(const ir_node *block)
108 assert(is_Block(block) && "Need a block here");
109 return sched_next(block);
113 * Get the last node in a schedule.
114 * @param block The block to get the schedule for.
115 * @return The last ir node in a schedule, or the block itself
116 * if there is no node in the schedule.
118 static inline ir_node *sched_last(const ir_node *block)
120 assert(is_Block(block) && "Need a block here");
121 return sched_prev(block);
125 * Add a node to a block schedule.
126 * @param irn The node to add.
127 * @return The given node.
129 void sched_add_before(ir_node *before, ir_node *irn);
133 * Add a node to a block schedule.
134 * @param irn The node to add.
135 * @return The given node.
137 void sched_add_after(ir_node *after, ir_node *irn);
139 static inline void sched_init_block(ir_node *block)
141 sched_info_t *info = get_irn_sched_info(block);
142 assert(info->next == NULL && info->time_step == 0);
147 static inline void sched_reset(ir_node *node)
149 sched_info_t *info = get_irn_sched_info(node);
155 * Remove a node from the scheduled.
156 * @param irn The node.
158 void sched_remove(ir_node *irn);
161 * Checks, if one node is scheduled before another.
163 * @param n2 Another node.
164 * @return true, if n1 is in front of n2 in the schedule, false else.
165 * @note Both nodes must be in the same block.
167 static inline bool sched_comes_after(const ir_node *n1, const ir_node *n2)
169 assert(sched_is_scheduled(n1));
170 assert(sched_is_scheduled(n2));
171 assert((is_Block(n1) ? n1 : get_nodes_block(n1)) == (is_Block(n2) ? n2 : get_nodes_block(n2)));
172 return sched_get_time_step(n1) < sched_get_time_step(n2);
175 #define sched_foreach_from(from, irn) \
176 for (ir_node *irn = from; !sched_is_end(irn); irn = sched_next(irn))
178 #define sched_foreach_reverse_from(from, irn) \
179 for (ir_node *irn = from; !sched_is_begin(irn); irn = sched_prev(irn))
182 * A shorthand macro for iterating over a schedule.
183 * @param block The block.
184 * @param irn A ir node pointer used as an iterator.
186 #define sched_foreach(block,irn) \
187 sched_foreach_from(sched_first(block), irn)
190 * A shorthand macro for reversely iterating over a schedule.
191 * @param block The block.
192 * @param irn A ir node pointer used as an iterator.
194 #define sched_foreach_reverse(block,irn) \
195 sched_foreach_reverse_from(sched_last(block), irn)
198 * Type for a function scheduling a graph
200 typedef void (*schedule_func) (ir_graph *irg);
203 * Register new scheduling algorithm
205 void be_register_scheduler(const char *name, schedule_func func);
208 * schedule a graph with the currenty selected scheduler.
210 void be_schedule_graph(ir_graph *irg);