microsoft/compiler: ralloc incoming phi-values
Reserving 127 incoming values for every phi instruction is neither robust nor memory efficient. Let's ralloc this array instead when filling it. This way, we only pay for what we use here. Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15519>
This commit is contained in:
parent
d8b5d45dc1
commit
d752c4bc7c
|
@ -163,7 +163,7 @@ struct dxil_instr_phi {
|
|||
struct dxil_phi_src {
|
||||
const struct dxil_value *value;
|
||||
unsigned block;
|
||||
} incoming[127];
|
||||
} *incoming;
|
||||
size_t num_incoming;
|
||||
};
|
||||
|
||||
|
|
|
@ -2736,13 +2736,14 @@ dxil_emit_phi(struct dxil_module *m, const struct dxil_type *type)
|
|||
return NULL;
|
||||
|
||||
instr->phi.type = type;
|
||||
instr->phi.incoming = NULL;
|
||||
instr->phi.num_incoming = 0;
|
||||
instr->has_value = true;
|
||||
|
||||
return instr;
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
dxil_phi_set_incoming(struct dxil_instr *instr,
|
||||
const struct dxil_value *incoming_values[],
|
||||
const unsigned incoming_blocks[],
|
||||
|
@ -2750,7 +2751,13 @@ dxil_phi_set_incoming(struct dxil_instr *instr,
|
|||
{
|
||||
assert(instr->type == INSTR_PHI);
|
||||
assert(num_incoming > 0);
|
||||
assert(num_incoming < ARRAY_SIZE(instr->phi.incoming));
|
||||
assert(instr->phi.incoming == NULL);
|
||||
|
||||
instr->phi.incoming = ralloc_array(instr, struct dxil_phi_src,
|
||||
num_incoming);
|
||||
if (!instr->phi.incoming)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < num_incoming; ++i) {
|
||||
assert(incoming_values[i]);
|
||||
assert(types_equal(incoming_values[i]->type, instr->phi.type));
|
||||
|
@ -2759,6 +2766,7 @@ dxil_phi_set_incoming(struct dxil_instr *instr,
|
|||
instr->phi.incoming[i].block = incoming_blocks[i];
|
||||
}
|
||||
instr->phi.num_incoming = num_incoming;
|
||||
return true;
|
||||
}
|
||||
|
||||
static struct dxil_instr *
|
||||
|
|
|
@ -437,7 +437,7 @@ dxil_instr_get_return_value(struct dxil_instr *instr);
|
|||
struct dxil_instr *
|
||||
dxil_emit_phi(struct dxil_module *m, const struct dxil_type *type);
|
||||
|
||||
void
|
||||
bool
|
||||
dxil_phi_set_incoming(struct dxil_instr *instr,
|
||||
const struct dxil_value *incoming_values[],
|
||||
const unsigned incoming_blocks[],
|
||||
|
|
|
@ -4434,7 +4434,7 @@ emit_phi(struct ntd_context *ctx, nir_phi_instr *instr)
|
|||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
static bool
|
||||
fixup_phi(struct ntd_context *ctx, nir_phi_instr *instr,
|
||||
struct phi_block *vphi)
|
||||
{
|
||||
|
@ -4451,8 +4451,11 @@ fixup_phi(struct ntd_context *ctx, nir_phi_instr *instr,
|
|||
blocks[num_incoming] = src->pred->index;
|
||||
++num_incoming;
|
||||
}
|
||||
dxil_phi_set_incoming(vphi->comp[i], values, blocks, num_incoming);
|
||||
if (!dxil_phi_set_incoming(vphi->comp[i], values, blocks,
|
||||
num_incoming))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static unsigned
|
||||
|
@ -5207,8 +5210,9 @@ emit_function(struct ntd_context *ctx, nir_function *func)
|
|||
return false;
|
||||
|
||||
hash_table_foreach(ctx->phis, entry) {
|
||||
fixup_phi(ctx, (nir_phi_instr *)entry->key,
|
||||
(struct phi_block *)entry->data);
|
||||
if (!fixup_phi(ctx, (nir_phi_instr *)entry->key,
|
||||
(struct phi_block *)entry->data))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!dxil_emit_ret_void(&ctx->mod))
|
||||
|
|
Loading…
Reference in New Issue