summaryrefslogtreecommitdiffhomepage
path: root/ir/be/besched.c
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2011-03-02 14:20:57 +0100
committerMatthias Braun <matze@braunis.de>2011-03-04 14:17:12 +0100
commit7a2c7fed8fdbe29fa0b6e1901865a901f71a6c5f (patch)
treeda4b17428cec22d3b10774f59d869c895263edaf /ir/be/besched.c
parent4520b859eab8301352d6e9ecd05556796bb2a771 (diff)
cleanup besched header
Diffstat (limited to 'ir/be/besched.c')
-rw-r--r--ir/be/besched.c236
1 files changed, 73 insertions, 163 deletions
diff --git a/ir/be/besched.c b/ir/be/besched.c
index 21bebf7..7a0c078 100644
--- a/ir/be/besched.c
+++ b/ir/be/besched.c
@@ -44,33 +44,9 @@
#include "belistsched.h"
#include "belive.h"
-size_t sched_irn_data_offset = 0;
+#define SCHED_INITIAL_GRANULARITY (1 << 14)
-static void block_sched_dumper(ir_node *block, void *env)
-{
- FILE *f = (FILE*)env;
- const ir_node *curr;
-
- ir_fprintf(f, "%+F:\n", block);
-
- sched_foreach(block, curr) {
- sched_info_t *info = get_irn_sched_info(curr);
- ir_fprintf(f, "\t%6d: %+F\n", info->time_step, curr);
- }
-}
-
-void be_sched_dump(FILE *f, ir_graph *irg)
-{
- irg_block_walk_graph(irg, block_sched_dumper, NULL, f);
-}
-
-BE_REGISTER_MODULE_CONSTRUCTOR(be_init_sched);
-void be_init_sched(void)
-{
- sched_irn_data_offset = firm_register_additional_node_data(sizeof(sched_info_t));
-}
-
-void sched_renumber(const ir_node *block)
+static void sched_renumber(const ir_node *block)
{
ir_node *irn;
sched_info_t *inf;
@@ -83,159 +59,93 @@ void sched_renumber(const ir_node *block)
}
}
-int sched_skip_cf_predicator(const ir_node *irn, void *data)
-{
- (void)data;
- return is_cfop(irn);
-}
-
-int sched_skip_phi_predicator(const ir_node *irn, void *data)
-{
- (void) data;
- return is_Phi(irn);
-}
-
-/* Skip nodes in a schedule. */
-ir_node *sched_skip(ir_node *from, int forward, sched_predicator_t *predicator, void *data)
-{
- const ir_node *bl = get_block_const(from);
- ir_node *curr;
-
- if (forward) {
- if (is_Block(from))
- from = sched_next(from);
- for (curr = from; curr != bl && predicator(curr, data); curr = sched_next(curr)) {
+static inline void sched_set_time_stamp(const ir_node *irn)
+{
+ sched_info_t *info = get_irn_sched_info(irn);
+ const sched_info_t *prev_info = get_irn_sched_info(info->prev);
+ const sched_info_t *next_info = get_irn_sched_info(info->next);
+ sched_timestep_t before_ts = prev_info->time_step;
+ sched_timestep_t after_ts = next_info->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) {
+ info->time_step = before_ts + SCHED_INITIAL_GRANULARITY;
+ /* overflow? */
+ if (info->time_step <= before_ts) {
+ sched_renumber(get_nodes_block(irn));
}
} else {
- if (is_Block(from))
- from = sched_prev(from);
- for (curr = from; curr != bl && predicator(curr, data); curr = sched_prev(curr)) {
- }
- }
-
- return curr;
-}
-
-//---------------------------------------------------------------------------
-
-typedef struct remove_dead_nodes_env_t_ {
- bitset_t *reachable;
- ir_graph *irg;
- be_lv_t *lv;
-} remove_dead_nodes_env_t;
-
-/**
- * Post-walker: remember all visited nodes in a bitset.
- */
-static void mark_dead_nodes_walker(ir_node *node, void *data)
-{
- remove_dead_nodes_env_t *env = (remove_dead_nodes_env_t*) data;
- bitset_set(env->reachable, get_irn_idx(node));
-}
-
-/**
- * Post-block-walker:
- * Walk through the schedule of every block and remove all dead nodes from it.
- */
-static void remove_dead_nodes_walker(ir_node *block, void *data)
-{
- remove_dead_nodes_env_t *env = (remove_dead_nodes_env_t*) data;
- ir_node *node, *next;
-
- for (node = sched_first(block); ! sched_is_end(node); node = next) {
- /* get next node now, as after calling sched_remove it will be invalid */
- next = sched_next(node);
-
- if (bitset_is_set(env->reachable, get_irn_idx(node)))
- continue;
-
- if (env->lv)
- be_liveness_remove(env->lv, node);
- sched_remove(node);
- kill_node(node);
+ 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
+ info->time_step = ts;
}
}
-void be_remove_dead_nodes_from_schedule(ir_graph *irg)
+void sched_add_before(ir_node *before, ir_node *irn)
{
- remove_dead_nodes_env_t env;
- env.reachable = bitset_alloca(get_irg_last_idx(irg));
- env.lv = be_get_irg_liveness(irg);
- env.irg = irg;
+ sched_info_t *info = get_irn_sched_info(irn);
+ ir_node *next = before;
+ sched_info_t *next_info = get_irn_sched_info(next);
+ ir_node *prev = next_info->prev;
+ sched_info_t *prev_info = get_irn_sched_info(prev);
+ assert(sched_is_scheduled(before));
+ assert(!sched_is_scheduled(irn));
+ assert(!is_Proj(before));
+ assert(!is_Proj(irn));
- // mark all reachable nodes
- irg_walk_graph(irg, mark_dead_nodes_walker, NULL, &env);
-
- // walk schedule and remove non-marked nodes
- irg_block_walk_graph(irg, remove_dead_nodes_walker, NULL, &env);
+ info->prev = prev;
+ info->next = next;
+ prev_info->next = irn;
+ next_info->prev = irn;
+ sched_set_time_stamp(irn);
}
-int (sched_get_time_step)(const ir_node *node)
+void sched_add_after(ir_node *after, ir_node *irn)
{
- return _sched_get_time_step(node);
-}
+ sched_info_t *info = get_irn_sched_info(irn);
+ ir_node *prev = after;
+ sched_info_t *prev_info = get_irn_sched_info(prev);
+ ir_node *next = prev_info->next;
+ sched_info_t *next_info = get_irn_sched_info(next);
+ assert(sched_is_scheduled(after));
+ assert(!sched_is_scheduled(irn));
+ assert(!is_Proj(after));
+ assert(!is_Proj(irn));
-int (sched_has_next)(const ir_node *node)
-{
- return _sched_has_next(node);
+ info->prev = prev;
+ info->next = next;
+ prev_info->next = irn;
+ next_info->prev = irn;
+ sched_set_time_stamp(irn);
}
-int (sched_has_prev)(const ir_node *node)
+void sched_remove(ir_node *irn)
{
- return _sched_has_prev(node);
-}
+ sched_info_t *info = get_irn_sched_info(irn);
+ ir_node *prev = info->prev;
+ ir_node *next = info->next;
+ sched_info_t *prev_info = get_irn_sched_info(prev);
+ sched_info_t *next_info = get_irn_sched_info(next);
+ assert(sched_is_scheduled(irn));
-ir_node *(sched_next)(const ir_node *node)
-{
- return _sched_next(node);
+ prev_info->next = next;
+ next_info->prev = prev;
+ info->next = NULL;
+ info->prev = NULL;
}
-ir_node *(sched_prev)(const ir_node *node)
-{
- return _sched_prev(node);
-}
-
-int (sched_is_scheduled)(const ir_node *node)
-{
- return _sched_is_scheduled(node);
-}
-
-ir_node *(sched_first)(const ir_node *node)
-{
- return _sched_first(node);
-}
-
-ir_node *(sched_last)(const ir_node *node)
-{
- return _sched_last(node);
-}
-
-void (sched_add_after)(ir_node *after, ir_node *node)
-{
- _sched_add_after(after, node);
-}
-
-void (sched_add_before)(ir_node *before, ir_node *node)
-{
- _sched_add_before(before, node);
-}
-
-void (sched_init_block)(ir_node *block)
-{
- _sched_init_block(block);
-}
-
-void (sched_remove)(ir_node *node)
-{
- _sched_remove(node);
-}
-
-void (sched_reset)(ir_node *node)
-{
- _sched_reset(node);
-}
-
-int (sched_comes_after)(const ir_node *n1, const ir_node *n2)
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_sched);
+void be_init_sched(void)
{
- return _sched_comes_after(n1, n2);
}