mie: select: track all side-effect-chains in a graph; support combining them all

This commit is contained in:
2025-11-15 22:37:35 +00:00
parent ec8a1a72a3
commit 4d1918bb77
4 changed files with 170 additions and 20 deletions

View File

@@ -62,6 +62,43 @@ void mie_select_graph_destroy(struct mie_select_graph *graph)
free(graph);
}
static enum mie_status update_chain_ends(
struct mie_select_graph *graph, struct mie_select_value *new_chain)
{
struct mie_select_node *new_node = new_chain->v_node;
b_queue_entry *entry = b_queue_first(&graph->g_chain_ends);
while (entry) {
struct mie_select_chain_end *end
= b_unbox(struct mie_select_chain_end, entry, c_entry);
struct mie_select_node *value_node = end->c_value.v_node;
for (size_t i = 0; i < new_node->n_nr_operands; i++) {
struct mie_select_node *operand_node
= new_node->n_operands[i].u_value.v_node;
if (value_node == operand_node) {
memcpy(&end->c_value, new_chain, sizeof *new_chain);
return MIE_SUCCESS;
}
}
entry = b_queue_next(entry);
}
struct mie_select_chain_end *end = malloc(sizeof *end);
if (!end) {
return MIE_ERR_NO_MEMORY;
}
memset(end, 0x0, sizeof *end);
memcpy(&end->c_value, new_chain, sizeof *new_chain);
b_queue_push_back(&graph->g_chain_ends, &end->c_entry);
return MIE_SUCCESS;
}
enum mie_status mie_select_graph_get_node(
struct mie_select_graph *graph, const struct mie_target *target,
unsigned int op, struct mie_select_value **operands, size_t nr_operands,
@@ -87,9 +124,18 @@ enum mie_status mie_select_graph_get_node(
node->n_target = target;
for (size_t i = 0; i < nr_values; i++) {
if (values[i]->t_id == MIE_TYPE_OTHER) {
graph->g_last_chain.v_node = node;
graph->g_last_chain.v_index = i;
if (values[i]->t_id != MIE_TYPE_OTHER) {
continue;
}
struct mie_select_value chain = {
.v_node = node,
.v_index = i,
};
enum mie_status status = update_chain_ends(graph, &chain);
if (status != MIE_SUCCESS) {
return status;
}
}