5 #define SCHED_INITIAL_GRANULARITY (1 << 14)
13 typedef unsigned int sched_timestep_t;
15 extern size_t sched_irn_data_offset;
18 * The schedule structure which is present at each ir node.
20 typedef struct _sched_info_t {
21 struct list_head list; /**< The list head to list the nodes in a schedule. */
22 sched_timestep_t time_step; /**< If a is after b in a schedule, its time step is
25 int scheduled : 1; /**< 1, if the node is in the schedule of the block, 0 else. */
28 #define _sched_entry(list_head) (list_entry(list_head, sched_info_t, list))
30 #define get_irn_sched_info(irn) get_irn_data(irn, sched_info_t, sched_irn_data_offset)
31 #define get_sched_info_irn(sched_info) get_irn_data_base(sched_info, sched_irn_data_offset)
34 * Init the scheduling stuff.
35 * To be called from the central backend initialization routine.
37 void be_sched_init(void);
40 * Get the time step of an irn in a schedule.
41 * @param irn The node.
42 * @return The time step in the schedule.
44 static INLINE int _sched_get_time_step(const ir_node *irn)
46 return get_irn_sched_info(irn)->time_step;
50 * Checks, if a node is to appear in a schedule. Such nodes either
51 * consume real data (mode datab) or produce such.
52 * @param irn The node to check for.
53 * @return 1, if the node consumes/produces data, false if not.
55 static INLINE int to_appear_in_schedule(ir_node *irn)
59 for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
60 ir_node *op = get_irn_n(irn, i);
61 if(mode_is_datab(get_irn_mode(op)))
65 return mode_is_datab(get_irn_mode(irn));
69 * Check, if an ir_node has a scheduling successor.
70 * @param irn The ir node.
71 * @return 1, if the node has a scheduling successor, 0 if not.
73 static INLINE int _sched_has_next(const ir_node *irn)
75 const ir_node *block = is_Block(irn) ? irn : get_nodes_block(irn);
76 const sched_info_t *info = get_irn_sched_info(irn);
77 const sched_info_t *block_info = get_irn_sched_info(block);
78 return info->list.next != &block_info->list;
82 * Check, if an ir_node has a scheduling predecessor.
83 * @param irn The ir node.
84 * @return 1, if the node has a scheduling predecessor, 0 if not.
86 static INLINE int _sched_has_prev(const ir_node *irn)
88 const ir_node *block = is_Block(irn) ? irn : get_nodes_block(irn);
89 const sched_info_t *info = get_irn_sched_info(irn);
90 const sched_info_t *block_info = get_irn_sched_info(block);
91 return info->list.prev != &block_info->list;
95 * Get the scheduling successor of a node.
96 * @param irn The node.
97 * @return The next ir node in the schedule or the block, if the node has no next node.
99 static INLINE ir_node *_sched_next(const ir_node *irn)
101 const sched_info_t *info = get_irn_sched_info(irn);
102 return get_sched_info_irn(_sched_entry(info->list.next));
106 * Get the scheduling predecessor of a node.
107 * @param irn The node.
108 * @return The next ir node in the schedule or the block, if the node has no predecessor.
111 static INLINE ir_node *_sched_prev(const ir_node *irn)
113 const sched_info_t *info = get_irn_sched_info(irn);
114 return get_sched_info_irn(_sched_entry(info->list.prev));
118 * Get the first node in a block schedule.
119 * @param block The block of which to get the schedule.
120 * @return The first node in the schedule or the block itself
121 * if there is no node in the schedule.
123 static INLINE ir_node *_sched_first(const ir_node *block)
125 assert(is_Block(block) && "Need a block here");
126 return _sched_next(block);
130 * Get the last node in a schedule.
131 * @param block The block to get the schedule for.
132 * @return The last ir node in a schedule, or the block itself
133 * if there is no node in the schedule.
135 static INLINE ir_node *_sched_last(const ir_node *block)
137 assert(is_Block(block) && "Need a block here");
138 return _sched_prev(block);
142 * Reassign the time steps in the schedule.
143 * @param block The schedule to update.
145 void sched_renumber(const ir_node *block);
147 static INLINE void _sched_set_time_stamp(ir_node *irn)
149 sched_info_t *inf = get_irn_sched_info(irn);
150 sched_timestep_t before_ts = _sched_entry(inf->list.prev)->time_step;
151 sched_timestep_t after_ts = _sched_entry(inf->list.next)->time_step;
154 * If we are the last, we can give us a big time step,
155 * else we have to compute our time step from our
158 if(before_ts >= after_ts)
159 inf->time_step = before_ts + SCHED_INITIAL_GRANULARITY;
161 sched_timestep_t ts = (before_ts + after_ts) / 2;
164 * If the resolution went out, we have to renumber
167 if(ts == before_ts || ts == after_ts)
168 sched_renumber(get_nodes_block(irn));
175 * Add a node to a block schedule.
176 * @param block The block to whose schedule the node shall be added to.
177 * @param irn The node to add.
178 * @return The given node.
180 static INLINE ir_node *_sched_add_before(ir_node *before, ir_node *irn)
182 sched_info_t *info = get_irn_sched_info(irn);
183 list_add_tail(&info->list, &get_irn_sched_info(before)->list);
184 _sched_set_time_stamp(irn);
190 * Add a node to a block schedule.
191 * @param block The block to whose schedule the node shall be added to.
192 * @param irn The node to add.
193 * @return The given node.
195 static INLINE ir_node *_sched_add_after(ir_node *after, ir_node *irn)
197 sched_info_t *info = get_irn_sched_info(irn);
198 list_add(&info->list, &get_irn_sched_info(after)->list);
199 _sched_set_time_stamp(irn);
205 * Check, if thenode is scheduled.
206 * @param irn The node.
207 * @return 1, if the node is scheduled, 0 if not.
209 static INLINE int _sched_is_scheduled(const ir_node *irn)
211 return get_irn_sched_info(irn)->scheduled;
215 * Compare two nodes according to their position in the schedule.
216 * @param a The first node.
217 * @param b The second node.
218 * @return A number smaller, equals to or larger than 0, if a is
219 * before, the same, or after b in the schedule.
221 static INLINE int _sched_cmp(const ir_node *a, const ir_node *b)
223 assert(_sched_is_scheduled(a) && _sched_is_scheduled(b));
224 assert(get_nodes_block(a) == get_nodes_block(b));
226 return get_irn_sched_info(a)->time_step - get_irn_sched_info(b)->time_step;
231 * @param block The block whose schedule to verify.
232 * @return 1, if the schedule is proper, 0 if not.
234 extern int sched_verify(const ir_node *block);
237 * Verify the schedules in all blocks of the irg.
238 * @param irg The program graph.
239 * @return 1, if all schedules were right, 0 if not.
241 extern int sched_verify_irg(ir_graph *irg);
244 #define sched_get_time_step(irn) _sched_get_time_step(irn)
245 #define sched_has_succ(irn) _sched_has_succ(irn)
246 #define sched_has_prev(irn) _sched_has_prev(irn)
247 #define sched_succ(irn) _sched_succ(irn)
248 #define sched_prev(irn) _sched_prev(irn)
249 #define sched_first(irn) _sched_first(irn)
250 #define sched_last(irn) _sched_last(irn)
251 #define sched_add_before(before, irn) _sched_add_before(before, irn)
252 #define sched_add_after(after, irn) _sched_add_after(after, irn)
253 #define sched_is_scheduled(irn) _sched_is_scheduled(irn)
254 #define sched_cmp(a, b) _sched_cmp(a, b)