#include "irgwalk.h"
#include "irprintf.h"
#include "irdump_t.h"
+#include "iredges.h"
#include "set.h"
#include "array.h"
#include "benode_t.h"
+static int my_values_interfere(const ir_node *a, const ir_node *b);
+
typedef struct be_verify_register_pressure_env_t_ {
ir_graph *irg; /**< the irg to verify */
be_lv_t *lv; /**< Liveness information. */
/* check that all delay branches are filled (at least with NOPs) */
if (cfchange_found && delay_branches != 0) {
- ir_fprintf(stderr, "Not all delay slots filled after jump (%d/%d) in block %+F (%s)\n",
+ ir_fprintf(stderr, "Verify warning: Not all delay slots filled after jump (%d/%d) in block %+F (%s)\n",
block, get_irg_dump_name(env->irg));
env->problem_found = 1;
}
}
+static int should_be_scheduled(ir_node *node) {
+ if(is_Block(node))
+ return -1;
+
+ 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)
+ return 0;
+ }
+ if(is_Proj(node) && get_irn_mode(node) == mode_X)
+ return 0;
+ if(be_is_Keep(node) && get_irn_opcode(get_nodes_block(node)) == iro_Bad)
+ return 0;
+
+ switch(get_irn_opcode(node)) {
+ case iro_End:
+ case iro_NoMem:
+ case iro_Bad:
+ return 0;
+ default:
+ break;
+ }
+
+ return 1;
+}
+
+static void check_schedule(ir_node *node, void *data) {
+ be_verify_schedule_env_t *env = data;
+ int should_be;
+
+ should_be = should_be_scheduled(node);
+ if(should_be == -1)
+ return;
+
+ if(should_be ? !sched_is_scheduled(node) : sched_is_scheduled(node)) {
+ ir_fprintf(stderr, "Verify warning: Node %+F in block %+F(%s) should%s be scheduled\n",
+ node, get_nodes_block(node), get_irg_dump_name(env->irg), should_be ? "" : " not");
+ env->problem_found = 1;
+ }
+}
+
/**
* Start a walk over the irg and check schedule.
*/
env.irg = irg;
irg_block_walk_graph(irg, verify_schedule_walker, NULL, &env);
+ // check if all nodes are scheduled
+ irg_walk_graph(irg, check_schedule, NULL, &env);
return ! env.problem_found;
}
+//---------------------------------------------------------------------------
+
+
typedef struct _spill_t {
ir_node *spill;
} spill_t;
typedef struct {
- ir_graph *irg;
be_lv_t *lv;
+ ir_graph *irg;
set *spills;
ir_node **reloads;
int problem_found;
return s1->spill != s2->spill;
}
+static spill_t *find_spill(be_verify_spillslots_env_t *env, ir_node *node) {
+ spill_t spill;
+
+ spill.spill = node;
+ 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) {
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 check_entity(be_verify_spillslots_env_t *env, ir_node *node, 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 = be_get_frame_entity(node);
+ check_entity(env, node, spillent);
get_spill(env, node, ent);
if(spillent != ent) {
out = get_Proj_proj(node);
spillent = be_get_MemPerm_out_entity(memperm, out);
+ check_entity(env, memperm, spillent);
if(spillent != ent) {
ir_fprintf(stderr, "Verify warning: MemPerm %+F has different entity than reload %+F in block %+F(%s)\n",
node, reload, get_nodes_block(node), get_irg_dump_name(env->irg));
if(be_is_Reload(node)) {
ir_node *spill = get_irn_n(node, be_pos_Reload_mem);
entity* ent = be_get_frame_entity(node);
+ check_entity(env, node, ent);
collect(env, spill, node, ent);
ARR_APP1(ir_node*, env->reloads, node);
if(sp1->ent != sp2->ent)
continue;
- if(values_interfere(env->lv, sp1->spill, sp2->spill)) {
+ if(my_values_interfere(sp1->spill, sp2->spill)) {
ir_fprintf(stderr, "Verify warning: Spillslots for %+F in block %+F(%s) and %+F in block %+F(%s) interfere\n",
sp1->spill, get_nodes_block(sp1->spill), get_irg_dump_name(env->irg),
sp2->spill, get_nodes_block(sp2->spill), get_irg_dump_name(env->irg));
env->problem_found = 1;
+ my_values_interfere(sp1->spill, sp2->spill);
+ printf("Intf: %d\n", values_interfere(env->lv, sp1->spill, sp2->spill));
}
}
}
}
+static void check_lonely_spills(ir_node *node, void *data) {
+ be_verify_spillslots_env_t *env = data;
+
+ 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 = be_get_frame_entity(node);
+ check_entity(env, node, ent);
+ }
+
+ if(spill == NULL) {
+ ir_fprintf(stderr, "Verify warning: Node %+F in block %+F(%s) not connected to a reaload\n",
+ node, get_nodes_block(node), get_irg_dump_name(env->irg));
+ }
+ }
+}
+
int be_verify_spillslots(ir_graph *irg)
{
be_verify_spillslots_env_t env;
env.lv = be_liveness(irg);
irg_walk_graph(irg, collect_spills_walker, NULL, &env);
+ irg_walk_graph(irg, check_lonely_spills, NULL, &env);
check_spillslot_interference(&env);
+ be_liveness_free(env.lv);
DEL_ARR_F(env.reloads);
del_set(env.spills);
- be_liveness_free(env.lv);
return ! env.problem_found;
}
-/* Ideas for further verifiers:
- * - make sure that each use is dominated by its definition (except phi arguments)
+
+
+//---------------------------------------------------------------------------
+
+
+
+/**
+ * Check, if two values interfere.
+ * @param a The first value.
+ * @param b The second value.
+ * @return 1, if a and b interfere, 0 if not.
*/
+static int my_values_interfere(const ir_node *a, const ir_node *b)
+{
+ const ir_edge_t *edge;
+ ir_node *bb;
+ int a2b = value_dominates(a, b);
+ int b2a = value_dominates(b, a);
+
+ /* If there is no dominance relation, they do not interfere. */
+ if(!a2b && !b2a)
+ return 0;
+
+ /*
+ * Adjust a and b so, that a dominates b if
+ * a dominates b or vice versa.
+ */
+ if(b2a) {
+ const ir_node *t = a;
+ a = b;
+ b = t;
+ }
+
+ bb = get_nodes_block(b);
+
+ /*
+ * Look at all usages of a.
+ * If there's one usage of a in the block of b, then
+ * we check, if this use is dominated by b, if that's true
+ * a and b interfere. Note that b must strictly dominate the user,
+ * since if b is the last user of in the block, b and a do not
+ * interfere.
+ * Uses of a not in b's block can be disobeyed, because the
+ * check for a being live at the end of b's block is already
+ * performed.
+ */
+ foreach_out_edge(a, edge) {
+ const ir_node *user = get_edge_src_irn(edge);
+ if(b == user)
+ continue;
+
+ if(get_irn_opcode(user) == iro_End)
+ continue;
+
+ // in case of phi arguments we compare with the block the value comes from
+ if(is_Phi(user)) {
+ ir_node *phiblock = get_nodes_block(user);
+ if(phiblock == bb)
+ continue;
+ user = get_irn_n(phiblock, get_edge_src_pos(edge));
+ }
+
+ if(value_dominates(b, user))
+ return 1;
+ }
+
+ return 0;
+}