@@ -2019,6 +2019,34 @@ __isl_give isl_id *isl_schedule_node_mark_get_id(
return isl_schedule_tree_mark_get_id(node->tree);
}
+/* Replace the child at position "pos" of the sequence node "node"
+ * by the children of sequence root node of "tree".
+ */
+__isl_give isl_schedule_node *isl_schedule_node_sequence_splice(
+ __isl_take isl_schedule_node *node, int pos,
+ __isl_take isl_schedule_tree *tree)
+{
+ isl_schedule_tree *node_tree;
+
+ if (!node || !tree)
+ goto error;
+ if (isl_schedule_node_get_type(node) != isl_schedule_node_sequence)
+ isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid,
+ "not a sequence node", goto error);
+ if (isl_schedule_tree_get_type(tree) != isl_schedule_node_sequence)
+ isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid,
+ "not a sequence node", goto error);
+ node_tree = isl_schedule_node_get_tree(node);
+ node_tree = isl_schedule_tree_sequence_splice(node_tree, pos, tree);
+ node = isl_schedule_node_graft_tree(node, node_tree);
+
+ return node;
+error:
+ isl_schedule_node_free(node);
+ isl_schedule_tree_free(tree);
+ return NULL;
+}
+
/* Update the ancestors of "node" to point to the tree that "node"
* now points to.
* That is, replace the child in the original parent that corresponds
return NULL;
}
+/* Given two trees with sequence roots, replace the child at position
+ * "pos" of "tree" with the children of "child".
+ */
+__isl_give isl_schedule_tree *isl_schedule_tree_sequence_splice(
+ __isl_take isl_schedule_tree *tree, int pos,
+ __isl_take isl_schedule_tree *child)
+{
+ int n;
+ isl_schedule_tree_list *list1, *list2;
+
+ tree = isl_schedule_tree_cow(tree);
+ if (!tree || !child)
+ goto error;
+ if (isl_schedule_tree_get_type(tree) != isl_schedule_node_sequence)
+ isl_die(isl_schedule_tree_get_ctx(tree), isl_error_invalid,
+ "not a sequence node", goto error);
+ n = isl_schedule_tree_n_children(tree);
+ if (pos < 0 || pos >= n)
+ isl_die(isl_schedule_tree_get_ctx(tree), isl_error_invalid,
+ "position out of bounds", goto error);
+ if (isl_schedule_tree_get_type(child) != isl_schedule_node_sequence)
+ isl_die(isl_schedule_tree_get_ctx(tree), isl_error_invalid,
+ "not a sequence node", goto error);
+
+ list1 = isl_schedule_tree_list_copy(tree->children);
+ list1 = isl_schedule_tree_list_drop(list1, pos, n - pos);
+ list2 = isl_schedule_tree_list_copy(tree->children);
+ list2 = isl_schedule_tree_list_drop(list2, 0, pos + 1);
+ list1 = isl_schedule_tree_list_concat(list1,
+ isl_schedule_tree_list_copy(child->children));
+ list1 = isl_schedule_tree_list_concat(list1, list2);
+
+ isl_schedule_tree_free(tree);
+ isl_schedule_tree_free(child);
+ return isl_schedule_tree_from_children(isl_schedule_node_sequence,
+ list1);
+error:
+ isl_schedule_tree_free(tree);
+ isl_schedule_tree_free(child);
+ return NULL;
+}
+
/* Tile the band root node of "tree" with tile sizes "sizes".
*
* We duplicate the band node, change the schedule of one of them
@@ -237,6 +237,9 @@ __isl_give isl_schedule_tree *isl_schedule_tree_drop_child(
__isl_give isl_schedule_tree *isl_schedule_tree_replace_child(
__isl_take isl_schedule_tree *tree, int pos,
__isl_take isl_schedule_tree *new_child);
+__isl_give isl_schedule_tree *isl_schedule_tree_sequence_splice(
+ __isl_take isl_schedule_tree *tree, int pos,
+ __isl_take isl_schedule_tree *child);
__isl_give isl_schedule_tree *isl_schedule_tree_reset_user(
__isl_take isl_schedule_tree *tree);