continue;
/* ...so are the sources */
- bi_foreach_src(I, s) {
- if (bi_is_ssa(I->src[s])) {
- progress |= !BITSET_TEST(deps, I->src[s].value);
- BITSET_SET(deps, I->src[s].value);
- }
+ bi_foreach_ssa_src(I, s) {
+ progress |= !BITSET_TEST(deps, I->src[s].value);
+ BITSET_SET(deps, I->src[s].value);
}
break;
bi_foreach_instr_global(ctx, I) {
if (!bi_instr_uses_helpers(I)) continue;
- bi_foreach_src(I, s) {
- if (bi_is_ssa(I->src[s]))
- BITSET_SET(deps, I->src[s].value);
- }
+ bi_foreach_ssa_src(I, s)
+ BITSET_SET(deps, I->src[s].value);
}
/* Propagate that up */
bool exec = false;
- bi_foreach_dest(I, d) {
- assert(bi_is_ssa(I->dest[d]));
+ bi_foreach_dest(I, d)
exec |= BITSET_TEST(deps, I->dest[d].value);
- }
I->skip = !exec;
}
void
bi_liveness_ins_update_ssa(BITSET_WORD *live, const bi_instr *I)
{
- bi_foreach_dest(I, d) {
- assert(I->dest[d].type == BI_INDEX_NORMAL);
+ bi_foreach_dest(I, d)
BITSET_CLEAR(live, I->dest[d].value);
- }
- bi_foreach_src(I, s) {
- if (I->src[s].type == BI_INDEX_NORMAL)
- BITSET_SET(live, I->src[s].value);
- }
+ bi_foreach_ssa_src(I, s)
+ BITSET_SET(live, I->src[s].value);
}
void
bi_foreach_instr_in_block(blk, I) {
if (I->op != BI_OPCODE_PHI) break;
- assert(I->dest[0].type == BI_INDEX_NORMAL);
BITSET_CLEAR(live, I->dest[0].value);
}
if (I->op != BI_OPCODE_PHI) break;
bi_index operand = I->src[bi_predecessor_index(blk, *pred)];
- if (operand.type == BI_INDEX_NORMAL)
+ if (bi_is_ssa(operand))
BITSET_SET(live, operand.value);
}
bi_foreach_instr_in_block(block, instr) {
/* Rewrite before trying to CSE anything so we converge
* locally in one iteration */
- bi_foreach_src(instr, s) {
+ bi_foreach_ssa_src(instr, s) {
if (bi_is_staging_src(instr, s))
continue;
- if (!bi_is_ssa(instr->src[s]))
- continue;
-
bi_index repl = replacement[instr->src[s].value];
if (!bi_is_null(repl))
instr->src[s] = bi_replace_index(instr->src[s], repl);
if (!needed)
continue;
- bi_foreach_src(I, s) {
- if (bi_is_ssa(I->src[s])) {
- progress |= !BITSET_TEST(mark, I->src[s].value);
- BITSET_SET(mark, I->src[s].value);
- }
+ bi_foreach_ssa_src(I, s) {
+ progress |= !BITSET_TEST(mark, I->src[s].value);
+ BITSET_SET(mark, I->src[s].value);
}
}
lut[I->dest[d].value] = I;
}
- bi_foreach_src(I, s) {
- if (!bi_is_ssa(I->src[s]))
- continue;
-
+ bi_foreach_ssa_src(I, s) {
bi_instr *mod = lut[I->src[s].value];
if (!mod)
BITSET_WORD *multiple = calloc(BITSET_WORDS(count), sizeof(*multiple));
bi_foreach_instr_global_rev(ctx, I) {
- bi_foreach_src(I, s) {
- if (bi_is_ssa(I->src[s])) {
- unsigned v = I->src[s].value;
-
- if (uses[v] && uses[v] != I)
- BITSET_SET(multiple, v);
- else
- uses[v] = I;
- }
+ bi_foreach_ssa_src(I, s) {
+ unsigned v = I->src[s].value;
+
+ if (uses[v] && uses[v] != I)
+ BITSET_SET(multiple, v);
+ else
+ uses[v] = I;
}
if (!I->nr_dests)
dag_init_node(dag, &node->dag);
/* Reads depend on writes, no other hazards in SSA */
- bi_foreach_src(I, s) {
- bi_index src = I->src[s];
-
- if (bi_is_ssa(src))
- add_dep(node, last_write[src.value]);
- }
-
- bi_foreach_dest(I, d) {
- assert(bi_is_ssa(I->dest[d]));
+ bi_foreach_ssa_src(I, s)
+ add_dep(node, last_write[I->src[s].value]);
+ bi_foreach_dest(I, d)
last_write[I->dest[d].value] = node;
- }
switch (bi_opcode_props[I->op].message) {
case BIFROST_MESSAGE_LOAD:
/* Destinations must be unique */
bi_foreach_dest(I, d) {
- assert(I->dest[d].type == BI_INDEX_NORMAL);
-
if (BITSET_TEST(live, I->dest[d].value))
delta -= bi_count_write_registers(I, d);
}
- bi_foreach_src(I, src) {
- if (I->src[src].type != BI_INDEX_NORMAL)
- continue;
-
+ bi_foreach_ssa_src(I, src) {
/* Filter duplicates */
bool dupe = false;
live[ins->dest[d].value] &= ~bi_writemask(ins, d);
}
- bi_foreach_src(ins, src) {
+ bi_foreach_ssa_src(ins, src) {
unsigned count = bi_count_read_registers(ins, src);
unsigned rmask = BITFIELD_MASK(count);
- uint8_t mask = (rmask << ins->src[src].offset);
- if (bi_is_ssa(ins->src[src]))
- live[ins->src[src].value] |= mask;
+ live[ins->src[src].value] |= (rmask << ins->src[src].offset);
}
}
/* Valhall needs >= 64-bit reads to be pair-aligned */
if (aligned_sr) {
- bi_foreach_src(ins, s) {
- if (bi_count_read_registers(ins, s) >= 2) {
- if (bi_is_ssa(ins->src[s]))
- l->affinity[ins->src[s].value] &= EVEN_BITS_MASK;
- }
+ bi_foreach_ssa_src(ins, s) {
+ if (bi_count_read_registers(ins, s) >= 2)
+ l->affinity[ins->src[s].value] &= EVEN_BITS_MASK;
}
}
}
bi_foreach_instr_global(ctx, I) {
- bi_foreach_src(I, s) {
- if (bi_is_ssa(I->src[s]) && I->src[s].value < first_reg && !bi_is_null(remap[I->src[s].value]))
+ bi_foreach_ssa_src(I, s) {
+ if (I->src[s].value < first_reg && !bi_is_null(remap[I->src[s].value]))
I->src[s] = bi_replace_index(I->src[s], remap[I->src[s].value]);
}
}
ctx->ssa_alloc = 0;
bi_foreach_instr_global(ctx, I) {
- bi_foreach_dest(I, d) {
+ bi_foreach_dest(I, d)
I->dest[d].value = find_or_allocate_temp(map, I->dest[d].value, &ctx->ssa_alloc);
- }
- bi_foreach_src(I, s) {
- if (I->src[s].type == BI_INDEX_NORMAL)
- I->src[s].value = find_or_allocate_temp(map, I->src[s].value, &ctx->ssa_alloc);
- }
+ bi_foreach_ssa_src(I, s)
+ I->src[s].value = find_or_allocate_temp(map, I->src[s].value, &ctx->ssa_alloc);
}
ralloc_free(map);
BITSET_WORD *multiple_uses = calloc(sizeof(BITSET_WORD), BITSET_WORDS(ctx->ssa_alloc));
bi_foreach_instr_global(ctx, I) {
- bi_foreach_src(I, s) {
- if (!bi_is_ssa(I->src[s]))
- continue;
-
+ bi_foreach_ssa_src(I, s) {
if (BITSET_TEST(used, I->src[s].value))
BITSET_SET(multiple_uses, I->src[s].value);
else
}
bi_foreach_instr_global(ctx, I) {
- bi_foreach_src(I, s) {
- if (!bi_is_ssa(I->src[s])) continue;
-
+ bi_foreach_ssa_src(I, s) {
unsigned v = I->src[s].value;
unsigned n = bi_count_read_registers(I, s);
#define bi_foreach_dest(ins, v) \
for (unsigned v = 0; v < ins->nr_dests; ++v)
+#define bi_foreach_ssa_src(ins, v) \
+ for (unsigned v = 0; v < ins->nr_srcs; ++v) \
+ if (ins->src[v].type == BI_INDEX_NORMAL)
+
#define bi_foreach_instr_and_src_in_tuple(tuple, ins, s) \
bi_foreach_instr_in_tuple(tuple, ins) \
bi_foreach_src(ins, s)