5 #define SCHED_INITIAL_GRANULARITY (1 << 14)
13 typedef unsigned int sched_timestep_t;
15 extern size_t sched_irn_data_offset;
17 typedef struct _sched_info_t {
18 struct list_head list;
19 sched_timestep_t time_step;
22 #define _sched_entry(list_head) (list_entry(list_head, sched_info_t, list))
24 #define get_irn_sched_info(irn) get_irn_data(irn, sched_info_t, sched_irn_data_offset)
25 #define get_sched_info_irn(sched_info) get_irn_data_base(sched_info, sched_irn_data_offset)
28 * Init the scheduling stuff.
29 * To be called from the central backend initialization routine.
31 void be_sched_init(void);
34 * Get the time step of an irn in a schedule.
35 * @param irn The node.
36 * @return The time step in the schedule.
38 static INLINE int _sched_get_time_step(const ir_node *irn)
40 return get_irn_sched_info(irn)->time_step;
44 * Check, if an ir_node has a scheduling successor.
45 * @param irn The ir node.
46 * @return 1, if the node has a scheduling successor, 0 if not.
48 static INLINE int _sched_has_succ(const ir_node *irn)
50 const sched_info_t *info = get_irn_sched_info(irn);
51 const sched_info_t *block_info = get_irn_sched_info(get_nodes_block(irn));
52 return info->list.next != &block_info->list;
56 * Check, if an ir_node has a scheduling predecessor.
57 * @param irn The ir node.
58 * @return 1, if the node has a scheduling predecessor, 0 if not.
60 static INLINE int _sched_has_prev(const ir_node *irn)
62 const sched_info_t *info = get_irn_sched_info(irn);
63 const sched_info_t *block_info = get_irn_sched_info(get_nodes_block(irn));
64 return info->list.prev != &block_info->list;
68 * Get the scheduling successor of a node.
69 * @param irn The node.
70 * @return The next ir node in the schedule or NULL, if this node has no
73 static INLINE ir_node *_sched_succ(const ir_node *irn)
75 const sched_info_t *info = get_irn_sched_info(irn);
76 return _sched_has_succ(irn) ? get_sched_info_irn(_sched_entry(info->list.next)) : NULL;
80 * Get the scheduling predecessor of a node.
81 * @param irn The node.
82 * @return The next ir node in the schedule or NULL, if this node has no
85 static INLINE ir_node *_sched_prev(const ir_node *irn)
87 const sched_info_t *info = get_irn_sched_info(irn);
88 return _sched_has_prev(irn) ? get_sched_info_irn(_sched_entry(info->list.prev)) : NULL;
92 * Get the first node in a block schedule.
93 * @param block The block of which to get the schedule.
94 * @return The first node in the schedule or NULL if there is none.
96 static INLINE ir_node *_sched_first(const ir_node *block)
98 const sched_info_t *info = get_irn_sched_info(block);
99 assert(is_Block(block) && "Need a block here");
100 return !list_empty(&info->list) ? get_sched_info_irn(_sched_entry(info->list.next)) : NULL;
104 * Get the last node in a schedule.
105 * @param block The block to get the schedule for.
106 * @return The last ir node in a schedule, or NULL if no schedule exists
109 static INLINE ir_node *_sched_last(const ir_node *block)
111 const sched_info_t *info = get_irn_sched_info(block);
112 assert(is_Block(block) && "Need a block here");
113 return !list_empty(&info->list) ? get_sched_info_irn(_sched_entry(info->list.prev)) : NULL;
117 * Reassign the time steps in the schedule.
118 * @param block The schedule to update.
120 void sched_renumber(const ir_node *block);
122 static INLINE void _sched_set_time_stamp(ir_node *irn)
124 sched_info_t *inf = get_irn_sched_info(irn);
125 sched_timestep_t before_ts = _sched_entry(inf->list.prev)->time_step;
126 sched_timestep_t after_ts = _sched_entry(inf->list.next)->time_step;
129 * If we are the last, we can give us a big time step,
130 * else we have to compute our time step from our
134 inf->time_step = before_ts + SCHED_INITIAL_GRANULARITY;
136 sched_timestep_t ts = (before_ts + after_ts) / 2;
139 * If the resolution went out, we have to renumber
142 if(ts == before_ts || ts == after_ts)
143 sched_renumber(get_nodes_block(irn));
148 * Add a node to a block schedule.
149 * @param block The block to whose schedule the node shall be added to.
150 * @param irn The node to add.
151 * @return The given node.
153 static INLINE ir_node *_sched_add_before(ir_node *before, ir_node *irn)
155 list_add_tail(&get_irn_sched_info(irn)->list, &get_irn_sched_info(before)->list);
156 _sched_set_time_stamp(irn);
161 * Add a node to a block schedule.
162 * @param block The block to whose schedule the node shall be added to.
163 * @param irn The node to add.
164 * @return The given node.
166 static INLINE ir_node *_sched_add_after(ir_node *after, ir_node *irn)
168 list_add(&get_irn_sched_info(irn)->list, &get_irn_sched_info(after)->list);
169 _sched_set_time_stamp(irn);
175 * @param block The block whose schedule to verify.
176 * @return 1, if the schedule is proper, 0 if not.
178 extern int sched_verify(const ir_node *block);
181 * Verify the schedules in all blocks of the irg.
182 * @param irg The program graph.
183 * @return 1, if all schedules were right, 0 if not.
185 extern int sched_verify_irg(ir_graph *irg);
187 #define sched_get_time_step(irn) _sched_get_time_step(irn)
188 #define sched_has_succ(irn) _sched_has_succ(irn)
189 #define sched_has_prev(irn) _sched_has_prev(irn)
190 #define sched_succ(irn) _sched_succ(irn)
191 #define sched_prev(irn) _sched_prev(irn)
192 #define sched_first(irn) _sched_first(irn)
193 #define sched_last(irn) _sched_last(irn)
194 #define sched_add_before(before, irn) _sched_add_before(before, irn)
195 #define sched_add_after(after, irn) _sched_add_after(after, irn)