#include "impl.h"
#include "irprintf.h"
#include "irgwalk.h"
-#include "irnode_t.h"
+#include "firm_types.h"
#include "irgraph_t.h"
#include "iredges_t.h"
#include "ircons.h"
#include "irextbb.h"
#include "debug.h"
+#include "bemodule.h"
#include "bearch.h"
#include "besched_t.h"
#include "beutil.h"
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_VOID(sched_init_block, ir_node *)
+FIRM_IMPL1_VOID(sched_reset, ir_node *)
FIRM_IMPL2(sched_comes_after, int, const ir_node *, const ir_node *)
FIRM_IMPL1_VOID(sched_remove, ir_node *)
static void block_sched_dumper(ir_node *block, void *env)
{
- FILE *f = env;
+ FILE *f = env;
const ir_node *curr;
ir_fprintf(f, "%+F:\n", block);
+
sched_foreach(block, curr) {
- sched_info_t *info = get_irn_sched_info(curr);
+ sched_info_t *info = get_irn_sched_info(curr);
ir_fprintf(f, "\t%6d: %+F\n", info->time_step, curr);
}
}
}
/* Init the scheduling stuff. */
-void be_sched_init(void)
+void be_init_sched(void)
{
sched_irn_data_offset = register_additional_node_data(sizeof(sched_info_t));
}
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_sched);
+
void sched_renumber(const ir_node *block)
{
ir_node *irn;
const ir_node *bl = get_block(from);
ir_node *curr;
- if (is_Block(from))
- from = forward ? sched_next(from) : sched_prev(from);
-
- for(curr = from; curr != bl && predicator(curr, data); curr = forward ? sched_next(curr) : sched_prev(curr));
+ if (forward) {
+ if (is_Block(from))
+ from = sched_next(from);
+ for (curr = from; curr != bl && predicator(curr, data); curr = sched_next(curr)) {
+ }
+ } else {
+ if (is_Block(from))
+ from = sched_prev(from);
+ for (curr = from; curr != bl && predicator(curr, data); curr = sched_prev(curr)) {
+ }
+ }
return curr;
}
bitset_t *reachable;
} 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;
+ ir_node *node, *next;
- for(node = sched_first(block); !sched_is_end(node); node = next) {
- int i, arity;
+ for (node = sched_first(block); ! sched_is_end(node); node = next) {
+ int i;
- // get next node now, as after calling sched_remove it will be invalid
+ /* 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)))
+ if (bitset_is_set(env->reachable, get_irn_idx(node)))
continue;
- arity = get_irn_arity(node);
- for(i = 0; i < arity; ++i)
- set_irn_n(node, i, new_r_Bad(env->irg));
-
sched_remove(node);
+
+ /* when a node is exchanged, it is turned into Bad, do not set ins for those */
+ if (is_Bad(node))
+ continue;
+
+ for (i = get_irn_arity(node) - 1; i >= 0; --i)
+ set_irn_n(node, i, new_r_Bad(env->irg));
}
}