/**
* Start a walk over the irg and check the register pressure.
*/
-int be_verify_register_pressure(const arch_env_t *arch_env, const arch_register_class_t *cls, ir_graph *irg) {
+int be_verify_register_pressure(const be_irg_t *birg, const arch_register_class_t *cls, ir_graph *irg) {
be_verify_register_pressure_env_t env;
env.lv = be_liveness(irg);
env.irg = irg;
- env.arch_env = arch_env;
+ env.arch_env = birg->main_env->arch_env;
env.cls = cls;
- env.registers_available = arch_count_non_ignore_regs(arch_env, cls);
+ env.registers_available = env.cls->n_regs - be_put_ignore_regs(birg, env.cls, NULL);
env.problem_found = 0;
irg_block_walk_graph(irg, verify_liveness_walker, NULL, &env);
int cfchange_found = 0;
// TODO ask arch about delay branches
int delay_branches = 0;
- pset *uses = pset_new_ptr_default();
/*
* Tests for the following things:
}
// 3. Check for uses
- if(pset_find_ptr(uses, node)) {
- ir_fprintf(stderr, "Verify Warning: Value %+F used before it was defined in block %+F (%s)\n",
- node, block, get_irg_dump_name(env->irg));
- env->problem_found = 1;
- }
if(!is_Phi(node)) {
+ int nodetime = sched_get_time_step(node);
for(i = 0, arity = get_irn_arity(node); i < arity; ++i) {
- pset_insert_ptr(uses, get_irn_n(node, i));
+ ir_node *arg = get_irn_n(node, i);
+ if(get_nodes_block(arg) != block
+ || !sched_is_scheduled(arg))
+ continue;
+
+ if(sched_get_time_step(arg) >= nodetime) {
+ ir_fprintf(stderr, "Verify Warning: Value %+F used by %+F before it was defined in block %+F (%s)\n",
+ arg, node, block, get_irg_dump_name(env->irg));
+ env->problem_found = 1;
+ }
}
}
+
+ // 4. check for dead nodes
+ if(get_irn_n_edges(node) == 0) {
+ ir_fprintf(stderr, "Verify warning: Node %+F is dead but scheduled in block %+F (%s)\n",
+ node, block, get_irg_dump_name(env->irg));
+ env->problem_found = 1;
+ }
}
- del_pset(uses);
/* check that all delay branches are filled (at least with NOPs) */
if (cfchange_found && delay_branches != 0) {
if(get_irn_mode(node) == mode_M) {
if(is_Proj(node))
return -1;
- if(is_Phi(node) || is_Sync(node) || get_irn_opcode(node) == iro_Pin)
+ if(is_Phi(node) || is_Sync(node) || is_Pin(node))
return 0;
}
if(is_Proj(node) && get_irn_mode(node) == mode_X)
case iro_End:
case iro_NoMem:
case iro_Bad:
+ case iro_Unknown:
return 0;
default:
break;
typedef struct _spill_t {
ir_node *spill;
- entity *ent;
+ ir_entity *ent;
} spill_t;
typedef struct {
return set_find(env->spills, &spill, sizeof(spill), HASH_PTR(node));
}
-static spill_t *get_spill(be_verify_spillslots_env_t *env, ir_node *node, entity *ent) {
+static spill_t *get_spill(be_verify_spillslots_env_t *env, ir_node *node, ir_entity *ent) {
spill_t spill, *res;
int hash = HASH_PTR(node);
return result;
}
-static void collect(be_verify_spillslots_env_t *env, ir_node *node, ir_node *reload, entity* ent);
+static void collect(be_verify_spillslots_env_t *env, ir_node *node, ir_node *reload, ir_entity* ent);
-static void check_entity(be_verify_spillslots_env_t *env, ir_node *node, entity *ent) {
+static void check_entity(be_verify_spillslots_env_t *env, ir_node *node, ir_entity *ent) {
if(ent == NULL) {
ir_fprintf(stderr, "Verify warning: Node %+F in block %+F(%s) should have an entity assigned\n",
node, get_nodes_block(node), get_irg_dump_name(env->irg));
}
}
-static void collect_spill(be_verify_spillslots_env_t *env, ir_node *node, ir_node *reload, entity* ent) {
- entity *spillent = arch_get_frame_entity(env->arch_env, node);
+static void collect_spill(be_verify_spillslots_env_t *env, ir_node *node, ir_node *reload, ir_entity* ent) {
+ ir_entity *spillent = arch_get_frame_entity(env->arch_env, node);
check_entity(env, node, spillent);
get_spill(env, node, ent);
}
}
-static void collect_memperm(be_verify_spillslots_env_t *env, ir_node *node, ir_node *reload, entity* ent) {
+static void collect_memperm(be_verify_spillslots_env_t *env, ir_node *node, ir_node *reload, ir_entity* ent) {
int i, arity;
spill_t spill, *res;
int hash = HASH_PTR(node);
int out;
ir_node* memperm;
- entity *spillent;
+ ir_entity *spillent;
assert(is_Proj(node));
for(i = 0, arity = be_get_MemPerm_entity_arity(memperm); i < arity; ++i) {
ir_node* arg = get_irn_n(memperm, i + 1);
- entity* argent = be_get_MemPerm_in_entity(memperm, i);
+ ir_entity* argent = be_get_MemPerm_in_entity(memperm, i);
collect(env, arg, memperm, argent);
}
}
-static void collect_memphi(be_verify_spillslots_env_t *env, ir_node *node, ir_node *reload, entity *ent) {
+static void collect_memphi(be_verify_spillslots_env_t *env, ir_node *node, ir_node *reload, ir_entity *ent) {
int i, arity;
spill_t spill, *res;
int hash = HASH_PTR(node);
}
}
-static void collect(be_verify_spillslots_env_t *env, ir_node *node, ir_node *reload, entity* ent) {
+static void collect(be_verify_spillslots_env_t *env, ir_node *node, ir_node *reload, ir_entity* ent) {
if(be_is_Spill(node)) {
collect_spill(env, node, reload, ent);
} else if(is_Proj(node)) {
if(arch_irn_class_is(arch_env, node, reload)) {
ir_node *spill = get_memory_edge(node);
+ ir_entity *ent;
+
if(spill == NULL) {
ir_fprintf(stderr, "Verify warning: No spill attached to reload %+F in block %+F(%s)\n",
node, get_nodes_block(node), get_irg_dump_name(env->irg));
env->problem_found = 1;
return;
}
- entity* ent = arch_get_frame_entity(env->arch_env, node);
+ ent = arch_get_frame_entity(env->arch_env, node);
check_entity(env, node, ent);
collect(env, spill, node, ent);
if(be_is_Spill(node) || (is_Proj(node) && be_is_MemPerm(get_Proj_pred(node)))) {
spill_t *spill = find_spill(env, node);
if(be_is_Spill(node)) {
- entity *ent = arch_get_frame_entity(env->arch_env, node);
+ ir_entity *ent = arch_get_frame_entity(env->arch_env, node);
check_entity(env, node, ent);
}
int problem_found;
} be_verify_register_allocation_env_t;
-static void check_register_allocation(be_verify_register_allocation_env_t *env,
- const arch_register_class_t *regclass, pset *nodes) {
- const arch_env_t *arch_env = env->arch_env;
- ir_node *node;
+static void check_register_constraints(ir_node *node, be_verify_register_allocation_env_t *env) {
+ const arch_env_t *arch_env = env->arch_env;
+ const arch_register_t *reg;
+ int i, arity;
- bitset_t *registers = bitset_alloca(arch_register_class_n_regs(regclass));
+ /* verify output register */
+ if (arch_get_irn_reg_class(arch_env, node, -1) != NULL) {
+ reg = arch_get_irn_register(arch_env, node);
+ if (reg == NULL) {
+ ir_fprintf(stderr, "Verify warning: Node %+F in block %+F(%s) should have a register assigned\n",
+ node, get_nodes_block(node), get_irg_dump_name(env->irg));
+ env->problem_found = 1;
+ }
+ else if (! arch_register_type_is(reg, joker) && !arch_reg_is_allocatable(arch_env, node, -1, reg)) {
+ ir_fprintf(stderr, "Verify warning: Register %s assigned as output of %+F not allowed (register constraint) in block %+F(%s)\n",
+ reg->name, node, get_nodes_block(node), get_irg_dump_name(env->irg));
+ env->problem_found = 1;
+ }
+ }
- foreach_pset(nodes, node) {
- const arch_register_t *reg;
- if(arch_get_irn_reg_class(arch_env, node, -1) != regclass)
+ /* verify input register */
+ arity = get_irn_arity(node);
+ for (i = 0; i < arity; ++i) {
+ ir_node *pred = get_irn_n(node, i);
+
+ if (is_Bad(pred)) {
+ ir_fprintf(stderr, "Verify warning: %+F in block %+F(%s) has Bad as input %d\n",
+ node, get_nodes_block(node), get_irg_dump_name(env->irg), i);
+ env->problem_found = 1;
continue;
+ }
- reg = arch_get_irn_register(arch_env, node);
- if(reg == NULL) {
+ if (arch_get_irn_reg_class(arch_env, node, i) == NULL)
+ continue;
+
+ reg = arch_get_irn_register(arch_env, pred);
+ if (reg == NULL) {
ir_fprintf(stderr, "Verify warning: Node %+F in block %+F(%s) should have a register assigned\n",
- node, get_nodes_block(node), get_irg_dump_name(env->irg));
+ pred, get_nodes_block(pred), get_irg_dump_name(env->irg));
env->problem_found = 1;
continue;
}
- if(bitset_is_set(registers, reg->index)) {
- ir_fprintf(stderr, "Verify warning: Register %s assigned more than once at node %+F in block %+F(%s)\n",
- reg->name, node, get_nodes_block(node), get_irg_dump_name(env->irg));
+ else if (! arch_register_type_is(reg, joker) && ! arch_reg_is_allocatable(arch_env, node, i, reg)) {
+ ir_fprintf(stderr, "Verify warning: Register %s as input %d of %+F not allowed (register constraint) in block %+F(%s)\n",
+ reg->name, i, node, get_nodes_block(node), get_irg_dump_name(env->irg));
env->problem_found = 1;
+ }
+ }
+}
+
+static void check_register_allocation(be_verify_register_allocation_env_t *env,
+ const arch_register_class_t *regclass, pset *nodes) {
+ const arch_env_t *arch_env = env->arch_env;
+ const arch_register_t *reg = NULL;
+ int fail = 0;
+ bitset_t *registers = bitset_alloca(arch_register_class_n_regs(regclass));
+ ir_node *node;
+
+ foreach_pset(nodes, node) {
+ if (arch_get_irn_reg_class(arch_env, node, -1) != regclass)
+ continue;
+
+ reg = arch_get_irn_register(arch_env, node);
+
+ /* this problem is already reported in 'check_register_constraints' */
+ if (! reg)
continue;
+
+ if (bitset_is_set(registers, reg->index)) {
+ pset_break(nodes);
+ fail = 1;
+ break;
}
bitset_set(registers, reg->index);
}
+
+ if (fail) {
+ ir_fprintf(stderr, "Verify warning: Register %s assigned more than once in block %+F(%s)\n",
+ reg->name, get_nodes_block(node), get_irg_dump_name(env->irg));
+ env->problem_found = 1;
+
+ foreach_pset(nodes, node) {
+ if (arch_get_irn_register(arch_env, node) == reg) {
+ ir_fprintf(stderr, " at node %+F\n", node);
+ }
+ }
+ }
}
static void verify_block_register_allocation(ir_node *block, void *data) {
be_liveness_transfer(env->arch_env, regclass, node, live_nodes);
check_register_allocation(env, regclass, live_nodes);
+ check_register_constraints(node, env);
}
del_pset(live_nodes);
return !env.problem_found;
}
+
+
+
+//---------------------------------------------------------------------------
+
+
+
+typedef struct _verify_out_dead_nodes_env {
+ ir_graph *irg;
+ bitset_t *reachable;
+ int problem_found;
+} verify_out_dead_nodes_env;
+
+static void check_out_edges(ir_node *node, verify_out_dead_nodes_env *env) {
+ ir_graph *irg = env->irg;
+ const ir_edge_t* edge;
+
+ if(irn_visited(node))
+ return;
+ mark_irn_visited(node);
+
+ foreach_out_edge(node, edge) {
+ ir_node* src = get_edge_src_irn(edge);
+
+ if(!bitset_is_set(env->reachable, get_irn_idx(src))) {
+ if(src != get_irg_globals(irg)
+ && src != get_irg_tls(irg)) {
+ ir_fprintf(stderr,
+ "Verify warning: Node %+F in block %+F(%s) only reachable through out edges from %+F\n",
+ src, get_nodes_block(src), get_irg_dump_name(irg), node);
+ env->problem_found = 1;
+ }
+ continue;
+ }
+
+ if(!is_Block(src)) {
+ check_out_edges(src, env);
+ }
+ }
+}
+
+static void set_reachable(ir_node *node, void* data)
+{
+ bitset_t* reachable = data;
+ bitset_set(reachable, get_irn_idx(node));
+}
+
+int be_verify_out_edges(ir_graph *irg) {
+ verify_out_dead_nodes_env env;
+ env.irg = irg;
+ env.reachable = bitset_alloca(get_irg_last_idx(irg));
+ env.problem_found = 0;
+
+ irg_walk_graph(irg, set_reachable, NULL, env.reachable);
+ inc_irg_visited(irg);
+ check_out_edges(get_irg_start(irg), &env);
+
+ return !env.problem_found;
+}