From ec80c86ca289b1cb499e9936f219233120a7ac02 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Tue, 8 Oct 2013 12:02:08 +0200 Subject: [PATCH] add isl_schedule_node_delete Signed-off-by: Sven Verdoolaege --- doc/user.pod | 11 +++++++++++ include/isl/schedule_node.h | 2 ++ isl_schedule_node.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/doc/user.pod b/doc/user.pod index b9f814a7..98a43b6f 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -7560,6 +7560,17 @@ a child of a set or sequence node. __isl_give isl_schedule_node *isl_schedule_node_cut( __isl_take isl_schedule_node *node); +The following function removes a single node +from a schedule tree and returns a pointer to the child +of the node, now located at the position of the original node +or to a leaf node at that position if there was no child. +It is not allowed to remove the root of a schedule tree, +a set or sequence node or a child of a set or sequence node. + + #include + __isl_give isl_schedule_node *isl_schedule_node_delete( + __isl_take isl_schedule_node *node); + The following function resets the user pointers on all parameter and tuple identifiers referenced by the given schedule node. diff --git a/include/isl/schedule_node.h b/include/isl/schedule_node.h index e616dbf4..f9f82a36 100644 --- a/include/isl/schedule_node.h +++ b/include/isl/schedule_node.h @@ -131,6 +131,8 @@ __isl_give isl_schedule_node *isl_schedule_node_insert_set( __isl_give isl_schedule_node *isl_schedule_node_cut( __isl_take isl_schedule_node *node); +__isl_give isl_schedule_node *isl_schedule_node_delete( + __isl_take isl_schedule_node *node); __isl_give isl_schedule_node *isl_schedule_node_reset_user( __isl_take isl_schedule_node *node); diff --git a/isl_schedule_node.c b/isl_schedule_node.c index 72e28c1b..c1d8fa8f 100644 --- a/isl_schedule_node.c +++ b/isl_schedule_node.c @@ -1661,6 +1661,50 @@ __isl_give isl_schedule_node *isl_schedule_node_cut( return isl_schedule_node_graft_tree(node, leaf); } +/* Remove a single node from the schedule tree, attaching the child + * of "node" directly to its parent. + * Return a pointer to this former child or to the leaf the position + * of the original node if there was no child. + * It is not allowed to remove the root of a schedule tree, + * a set or sequence node or a child of a set or sequence node. + */ +__isl_give isl_schedule_node *isl_schedule_node_delete( + __isl_take isl_schedule_node *node) +{ + int n; + isl_schedule_tree *tree; + enum isl_schedule_node_type type; + + if (!node) + return NULL; + + if (isl_schedule_node_get_tree_depth(node) == 0) + isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid, + "cannot delete root node", + return isl_schedule_node_free(node)); + n = isl_schedule_node_n_children(node); + if (n != 1) + isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid, + "can only delete node with a single child", + return isl_schedule_node_free(node)); + type = isl_schedule_node_get_parent_type(node); + if (type == isl_schedule_node_sequence || type == isl_schedule_node_set) + isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid, + "cannot delete child of set or sequence", + return isl_schedule_node_free(node)); + + tree = isl_schedule_node_get_tree(node); + if (!tree || isl_schedule_tree_has_children(tree)) { + tree = isl_schedule_tree_child(tree, 0); + } else { + isl_schedule_tree_free(tree); + tree = isl_schedule_node_get_leaf(node); + } + node = isl_schedule_node_graft_tree(node, tree); + + return node; +} + /* Reset the user pointer on all identifiers of parameters and tuples * in the schedule node "node". */ -- 2.11.4.GIT