Commit 8848eae0 authored by Matthias Braun's avatar Matthias Braun
Browse files

- Added a few asserts to the besched API, so you can't schedule a node

  that is already scheduled
parent 2ac21713
......@@ -32,6 +32,8 @@ FIRM_IMPL1(sched_first, ir_node *, const ir_node *)
FIRM_IMPL1(sched_last, ir_node *, const ir_node *)
FIRM_IMPL2(sched_add_after, ir_node *, ir_node *, ir_node *)
FIRM_IMPL2(sched_add_before, ir_node *, ir_node *, ir_node *)
FIRM_IMPL1(sched_init_block, void, ir_node *)
FIRM_IMPL1(sched_reset, void, ir_node *)
FIRM_IMPL2(sched_comes_after, int, const ir_node *, const ir_node *)
FIRM_IMPL1_VOID(sched_remove, ir_node *)
......
......@@ -10,8 +10,6 @@
#include "firm_types.h"
#include "execfreq.h"
void be_sched_dump(FILE *f, ir_graph *irg);
int sched_get_time_step(const ir_node *irn);
......@@ -23,13 +21,10 @@ ir_node *sched_first(const ir_node *block);
ir_node *sched_last(const ir_node *block);
ir_node *sched_add_before(ir_node *before, ir_node *irn);
ir_node *sched_add_after(ir_node *before, ir_node *irn);
void sched_init_block(ir_node *block);
void sched_reset(ir_node *node);
void sched_remove(ir_node *irn);
/**
* Returns the first block of a graphs block schedule.
*/
ir_node *sched_irg_first(const ir_graph *irg);
#define sched_is_end(irn) is_Block(irn)
#define sched_is_begin(irn) is_Block(irn)
......@@ -55,19 +50,6 @@ ir_node *sched_irg_first(const ir_graph *irg);
#define sched_foreach_reverse(block,irn) \
sched_foreach_reverse_from(sched_last(block), irn)
/**
* Calculates a block schedule. The schedule is returned as
* an array allocated on the irg's obstack.
*
* @param irg the graph to be scheduled
*
* @return A list of all blocks in schedule order. This list is
* allocated on irg's obstack and is freed if the graph is destroyed.
*
* This function implements a simple extended block scheduling algorithm.
*/
ir_node **sched_create_block_schedule(ir_graph *irg, ir_exec_freq *execfreqs);
/**
* Removes dead nodes from schedule
* @param irg the graph
......
......@@ -25,7 +25,7 @@ typedef struct _sched_info_t {
struct list_head list; /**< The list head to list the nodes in a schedule. */
sched_timestep_t time_step; /**< If a is after b in a schedule, its time step is
larger than b's. */
unsigned scheduled : 1; /**< 1, if the node is in the schedule of the block, 0 else. */
unsigned scheduled : 1; /**< 1, if the node is in the schedule of the block, 0 else. */
} sched_info_t;
#define _sched_entry(list_head) (list_entry(list_head, sched_info_t, list))
......@@ -85,7 +85,7 @@ static INLINE int to_appear_in_schedule(const ir_node *irn)
*/
static INLINE int _sched_has_next(const ir_node *irn)
{
const ir_node *block = is_Block(irn) ? irn : get_nodes_block(irn);
const ir_node *block = is_Block(irn) ? irn : get_nodes_block(irn);
const sched_info_t *info = get_irn_sched_info(irn);
const sched_info_t *block_info = get_irn_sched_info(block);
return info->list.next != &block_info->list;
......@@ -98,7 +98,7 @@ static INLINE int _sched_has_next(const ir_node *irn)
*/
static INLINE int _sched_has_prev(const ir_node *irn)
{
const ir_node *block = is_Block(irn) ? irn : get_nodes_block(irn);
const ir_node *block = is_Block(irn) ? irn : get_nodes_block(irn);
const sched_info_t *info = get_irn_sched_info(irn);
const sched_info_t *block_info = get_irn_sched_info(block);
return info->list.prev != &block_info->list;
......@@ -159,29 +159,29 @@ void sched_renumber(const ir_node *block);
static INLINE void _sched_set_time_stamp(ir_node *irn)
{
sched_info_t *inf = get_irn_sched_info(irn);
sched_timestep_t before_ts = _sched_entry(inf->list.prev)->time_step;
sched_timestep_t after_ts = _sched_entry(inf->list.next)->time_step;
/*
* If we are the last, we can give us a big time step,
* else we have to compute our time step from our
* neighbours.
*/
if(before_ts >= after_ts)
inf->time_step = before_ts + SCHED_INITIAL_GRANULARITY;
else {
sched_timestep_t ts = (before_ts + after_ts) / 2;
/*
* If the resolution went out, we have to renumber
* this block.
*/
if(ts == before_ts || ts == after_ts)
sched_renumber(get_nodes_block(irn));
else
inf->time_step = ts;
}
sched_info_t *inf = get_irn_sched_info(irn);
sched_timestep_t before_ts = _sched_entry(inf->list.prev)->time_step;
sched_timestep_t after_ts = _sched_entry(inf->list.next)->time_step;
/*
* If we are the last, we can give us a big time step,
* else we have to compute our time step from our
* neighbours.
*/
if(before_ts >= after_ts)
inf->time_step = before_ts + SCHED_INITIAL_GRANULARITY;
else {
sched_timestep_t ts = (before_ts + after_ts) / 2;
/*
* If the resolution went out, we have to renumber
* this block.
*/
if(ts == before_ts || ts == after_ts)
sched_renumber(get_nodes_block(irn));
else
inf->time_step = ts;
}
}
/**
......@@ -192,6 +192,7 @@ static INLINE void _sched_set_time_stamp(ir_node *irn)
*/
static INLINE ir_node *_sched_add_before(ir_node *before, ir_node *irn)
{
assert(_sched_is_scheduled(before) && !_sched_is_scheduled(irn));
sched_info_t *info = get_irn_sched_info(irn);
list_add_tail(&info->list, &get_irn_sched_info(before)->list);
_sched_set_time_stamp(irn);
......@@ -207,6 +208,7 @@ static INLINE ir_node *_sched_add_before(ir_node *before, ir_node *irn)
*/
static INLINE ir_node *_sched_add_after(ir_node *after, ir_node *irn)
{
assert(_sched_is_scheduled(after) && !_sched_is_scheduled(irn));
sched_info_t *info = get_irn_sched_info(irn);
list_add(&info->list, &get_irn_sched_info(after)->list);
_sched_set_time_stamp(irn);
......@@ -214,6 +216,20 @@ static INLINE ir_node *_sched_add_after(ir_node *after, ir_node *irn)
return irn;
}
static INLINE void _sched_init_block(ir_node *block)
{
sched_info_t *info = get_irn_sched_info(block);
assert(info->scheduled == 0 && info->time_step == 0);
INIT_LIST_HEAD(&info->list);
info->scheduled = 1;
}
static INLINE void _sched_reset(ir_node *node)
{
sched_info_t *info = get_irn_sched_info(node);
info->scheduled = 0;
}
/**
* Remove a node from the scheduled.
* @param irn The node.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment