From e37f564c4c0efa17a7f48cf84da6bce9b4e792b7 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sat, 12 Oct 2013 16:25:51 +0200 Subject: [PATCH] add isl_schedule_node_cut Signed-off-by: Sven Verdoolaege --- doc/user.pod | 10 ++++++++++ include/isl/schedule_node.h | 3 +++ isl_schedule_node.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/doc/user.pod b/doc/user.pod index e35617e6..b9f814a7 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -7550,6 +7550,16 @@ It is the responsibility of the user to ensure that this does not lead to an infinite loop. It is safest to always return a pointer to the same position (same ancestors and child positions) as the input node. +The following function removes a node (along with its descendants) +from a schedule tree and returns a pointer to the leaf at the +same position in the updated tree. +It is not allowed to remove the root of a schedule tree or +a child of a set or sequence node. + + #include + __isl_give isl_schedule_node *isl_schedule_node_cut( + __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 ec7e9a3b..e616dbf4 100644 --- a/include/isl/schedule_node.h +++ b/include/isl/schedule_node.h @@ -129,6 +129,9 @@ __isl_give isl_schedule_node *isl_schedule_node_insert_set( __isl_take isl_schedule_node *node, __isl_take isl_union_set_list *filters); +__isl_give isl_schedule_node *isl_schedule_node_cut( + __isl_take isl_schedule_node *node); + __isl_give isl_schedule_node *isl_schedule_node_reset_user( __isl_take isl_schedule_node *node); __isl_give isl_schedule_node *isl_schedule_node_align_params( diff --git a/isl_schedule_node.c b/isl_schedule_node.c index b6aeef94..72e28c1b 100644 --- a/isl_schedule_node.c +++ b/isl_schedule_node.c @@ -1632,6 +1632,35 @@ __isl_give isl_schedule_node *isl_schedule_node_insert_set( isl_schedule_node_set, filters); } +/* Remove "node" from its schedule tree and return a pointer + * to the leaf at the same position in the updated schedule tree. + * + * It is not allowed to remove the root of a schedule tree or + * a child of a set or sequence node. + */ +__isl_give isl_schedule_node *isl_schedule_node_cut( + __isl_take isl_schedule_node *node) +{ + isl_schedule_tree *leaf; + enum isl_schedule_node_type parent_type; + + if (!node) + return NULL; + if (!isl_schedule_node_has_parent(node)) + isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid, + "cannot cut root", return isl_schedule_node_free(node)); + + parent_type = isl_schedule_node_get_parent_type(node); + if (parent_type == isl_schedule_node_set || + parent_type == isl_schedule_node_sequence) + isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid, + "cannot cut child of set or sequence", + return isl_schedule_node_free(node)); + + leaf = isl_schedule_node_get_leaf(node); + return isl_schedule_node_graft_tree(node, leaf); +} + /* Reset the user pointer on all identifiers of parameters and tuples * in the schedule node "node". */ -- 2.11.4.GIT