if (!is_load_coords) {
/* Clone varying loads for each block */
if (child->block != node->block) {
- child = ppir_node_clone(node->block, child);
+ ppir_node *new = ppir_node_clone(node->block, child);
+ /* If we clone it for every block and there is no user of
+ * the original load left, delete the original one. */
+ ppir_delete_if_orphan(node->block, child);
+ child = new;
comp->var_nodes[ns->ssa->index] = child;
}
break;
return &new_lnode->node;
}
+void
+ppir_delete_if_orphan(ppir_block *block, ppir_node *node)
+{
+ ppir_dest *dest = ppir_node_get_dest(node);
+ if (!dest)
+ return;
+
+ ppir_node_foreach_succ_safe(node, dep) {
+ ppir_node *succ = dep->succ;
+ for (int i = 0; i < ppir_node_get_src_num(succ); i++) {
+ ppir_src *src = ppir_node_get_src(succ, i);
+ if (!src)
+ continue;
+ if (ppir_node_target_equal(src, dest))
+ return;
+ }
+ }
+
+ ppir_node_delete(node);
+}
+
ppir_node *ppir_node_clone(ppir_block *block, ppir_node *node)
{
switch (node->op) {
void ppir_node_replace_child(ppir_node *parent, ppir_node *old_child, ppir_node *new_child);
void ppir_node_replace_all_succ(ppir_node *dst, ppir_node *src);
void ppir_node_replace_pred(ppir_dep *dep, ppir_node *new_pred);
+void ppir_delete_if_orphan(ppir_block *block, ppir_node *node);
ppir_dep *ppir_dep_for_pred(ppir_node *node, ppir_node *pred);
ppir_node *ppir_node_clone(ppir_block *block, ppir_node *node);
/* Assumes that node successors are in the same block */