Commit 6da9f4a5 authored by Matthias Braun's avatar Matthias Braun
Browse files

bepeephole: use global register indices

This simplifies the code and should make it slightly faster
parent 52a59fbe
......@@ -48,39 +48,32 @@ DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
static const arch_env_t *arch_env;
static be_lv_t *lv;
static ir_node *current_node;
ir_node ***register_values;
ir_node **register_values;
static void clear_reg_value(ir_node *node)
{
const arch_register_t *reg;
const arch_register_class_t *cls;
unsigned reg_idx;
unsigned cls_idx;
const arch_register_t *reg;
unsigned reg_idx;
if (!mode_is_data(get_irn_mode(node)))
return;
reg = arch_get_irn_register(node);
reg = arch_get_irn_register(node);
if (reg == NULL) {
panic("No register assigned at %+F", node);
}
if (reg->type & arch_register_type_virtual)
return;
cls = arch_register_get_class(reg);
reg_idx = arch_register_get_index(reg);
cls_idx = arch_register_class_index(cls);
reg_idx = reg->global_index;
//assert(register_values[cls_idx][reg_idx] != NULL);
DB((dbg, LEVEL_1, "Clear Register %s\n", reg->name));
register_values[cls_idx][reg_idx] = NULL;
register_values[reg_idx] = NULL;
}
static void set_reg_value(ir_node *node)
{
const arch_register_t *reg;
const arch_register_class_t *cls;
unsigned reg_idx;
unsigned cls_idx;
const arch_register_t *reg;
unsigned reg_idx;
if (!mode_is_data(get_irn_mode(node)))
return;
......@@ -91,12 +84,10 @@ static void set_reg_value(ir_node *node)
}
if (reg->type & arch_register_type_virtual)
return;
cls = arch_register_get_class(reg);
reg_idx = arch_register_get_index(reg);
cls_idx = arch_register_class_index(cls);
reg_idx = reg->global_index;
DB((dbg, LEVEL_1, "Set Register %s: %+F\n", reg->name, node));
register_values[cls_idx][reg_idx] = node;
register_values[reg_idx] = node;
}
static void clear_defs(ir_node *node)
......@@ -141,11 +132,9 @@ void be_peephole_new_node(ir_node * nw)
static void be_peephole_before_exchange(const ir_node *old_node,
ir_node *new_node)
{
const arch_register_t *reg;
const arch_register_class_t *cls;
unsigned reg_idx;
unsigned cls_idx;
bool old_is_current = false;
const arch_register_t *reg;
unsigned reg_idx;
bool old_is_current = false;
DB((dbg, LEVEL_1, "About to exchange and kill %+F with %+F\n", old_node, new_node));
......@@ -175,12 +164,9 @@ static void be_peephole_before_exchange(const ir_node *old_node,
assert(reg == arch_get_irn_register(new_node) &&
"KILLING a node and replacing by different register is not allowed");
cls = arch_register_get_class(reg);
reg_idx = arch_register_get_index(reg);
cls_idx = arch_register_class_index(cls);
if (register_values[cls_idx][reg_idx] == old_node || old_is_current) {
register_values[cls_idx][reg_idx] = new_node;
reg_idx = reg->global_index;
if (register_values[reg_idx] == old_node || old_is_current) {
register_values[reg_idx] = new_node;
}
be_liveness_remove(lv, old_node);
......@@ -199,18 +185,11 @@ void be_peephole_exchange(ir_node *old, ir_node *nw)
*/
static void process_block(ir_node *block, void *data)
{
unsigned n_classes;
unsigned i;
int l;
(void) data;
/* construct initial register assignment */
n_classes = arch_env->n_register_classes;
for (i = 0; i < n_classes; ++i) {
const arch_register_class_t *cls = &arch_env->register_classes[i];
unsigned n_regs = arch_register_class_n_regs(cls);
memset(register_values[i], 0, sizeof(ir_node*) * n_regs);
}
memset(register_values, 0, sizeof(ir_node*) * arch_env->n_registers);
assert(lv->nodes && "live sets must be computed");
DB((dbg, LEVEL_1, "\nProcessing block %+F (from end)\n", block));
......@@ -299,9 +278,6 @@ ir_node *be_peephole_IncSP_IncSP(ir_node *node)
void be_peephole_opt(ir_graph *irg)
{
unsigned n_classes;
unsigned i;
/* we sometimes find BadE nodes in float apps like optest_float.c or
* kahansum.c for example... */
be_liveness_invalidate(be_get_irg_liveness(irg));
......@@ -310,19 +286,10 @@ void be_peephole_opt(ir_graph *irg)
arch_env = be_get_irg_arch_env(irg);
lv = be_get_irg_liveness(irg);
n_classes = arch_env->n_register_classes;
register_values = XMALLOCN(ir_node**, n_classes);
for (i = 0; i < n_classes; ++i) {
const arch_register_class_t *cls = &arch_env->register_classes[i];
unsigned n_regs = arch_register_class_n_regs(cls);
register_values[i] = XMALLOCN(ir_node*, n_regs);
}
register_values = XMALLOCN(ir_node*, arch_env->n_registers);
irg_block_walk_graph(irg, process_block, NULL, NULL);
for (i = 0; i < n_classes; ++i) {
xfree(register_values[i]);
}
xfree(register_values);
}
......
......@@ -29,20 +29,17 @@
#include "beirg.h"
#include "bearch.h"
extern ir_node ***register_values;
extern ir_node **register_values;
static inline ir_node *be_peephole_get_value(unsigned regclass_idx,
unsigned register_idx)
static inline ir_node *be_peephole_get_value(unsigned register_idx)
{
return register_values[regclass_idx][register_idx];
return register_values[register_idx];
}
static inline ir_node *be_peephole_get_reg_value(const arch_register_t *reg)
{
unsigned regclass_idx = arch_register_class_index(arch_register_get_class(reg));
unsigned register_idx = arch_register_get_index(reg);
return be_peephole_get_value(regclass_idx, register_idx);
unsigned register_idx = reg->global_index;
return be_peephole_get_value(register_idx);
}
/**
......
......@@ -849,7 +849,7 @@ static const arch_register_t *get_free_gp_reg(ir_graph *irg)
if (!rbitset_is_set(birg->allocatable_regs, reg->global_index))
continue;
if (be_peephole_get_value(CLASS_ia32_gp, i) == NULL)
if (be_peephole_get_value(reg->global_index) == NULL)
return reg;
}
......@@ -976,7 +976,7 @@ static void peephole_ia32_Const(ir_node *node)
if (ia32_cg_config.use_mov_0)
return;
/* xor destroys the flags, so no-one must be using them */
if (be_peephole_get_value(CLASS_ia32_flags, REG_FLAGS_EFLAGS) != NULL)
if (be_peephole_get_value(REG_EFLAGS) != NULL)
return;
reg = arch_get_irn_register(node);
......@@ -1066,7 +1066,7 @@ static void peephole_ia32_Lea(ir_node *node)
assert(is_ia32_Lea(node));
/* we can only do this if it is allowed to clobber the flags */
if (be_peephole_get_value(CLASS_ia32_flags, REG_FLAGS_EFLAGS) != NULL)
if (be_peephole_get_value(REG_EFLAGS) != NULL)
return;
base = get_irn_n(node, n_ia32_Lea_base);
......
Supports Markdown
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