From 05c5b384bff463c16bb13f6f564c386d158c62c9 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 9 Jan 2014 17:01:03 +0100 Subject: [PATCH] add isl_schedule_node_get_ancestor_child_position Signed-off-by: Sven Verdoolaege --- doc/user.pod | 7 ++++++- include/isl/schedule_node.h | 3 +++ isl_schedule_node.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/doc/user.pod b/doc/user.pod index 69be8a6e..473a992f 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -7459,7 +7459,9 @@ is the node itself, the ancestor of generation 1 is its parent and so on. It is also possible to query the number of ancestors of a node, the position of the current node -within the children of its parent or to obtain a copy of a given +within the children of its parent, the position of the subtree +containing a node within the children of an ancestor +or to obtain a copy of a given child without destroying the current node. #include @@ -7467,6 +7469,9 @@ child without destroying the current node. __isl_keep isl_schedule_node *node); int isl_schedule_node_get_child_position( __isl_keep isl_schedule_node *node); + int isl_schedule_node_get_ancestor_child_position( + __isl_keep isl_schedule_node *node, + __isl_keep isl_schedule_node *ancestor); __isl_give isl_schedule_node *isl_schedule_node_get_child( __isl_keep isl_schedule_node *node, int pos); diff --git a/include/isl/schedule_node.h b/include/isl/schedule_node.h index cc11fc93..c685ddfc 100644 --- a/include/isl/schedule_node.h +++ b/include/isl/schedule_node.h @@ -43,6 +43,9 @@ int isl_schedule_node_has_previous_sibling(__isl_keep isl_schedule_node *node); int isl_schedule_node_has_next_sibling(__isl_keep isl_schedule_node *node); int isl_schedule_node_n_children(__isl_keep isl_schedule_node *node); int isl_schedule_node_get_child_position(__isl_keep isl_schedule_node *node); +int isl_schedule_node_get_ancestor_child_position( + __isl_keep isl_schedule_node *node, + __isl_keep isl_schedule_node *ancestor); __isl_give isl_schedule_node *isl_schedule_node_get_child( __isl_keep isl_schedule_node *node, int pos); diff --git a/isl_schedule_node.c b/isl_schedule_node.c index faec8a05..27d09d05 100644 --- a/isl_schedule_node.c +++ b/isl_schedule_node.c @@ -1629,6 +1629,41 @@ __isl_give isl_schedule_node *isl_schedule_node_align_params( return node; } +/* Return the position of the subtree containing "node" among the children + * of "ancestor". "node" is assumed to be a descendant of "ancestor". + * In particular, both nodes should point to the same schedule tree. + * + * Return -1 on error. + */ +int isl_schedule_node_get_ancestor_child_position( + __isl_keep isl_schedule_node *node, + __isl_keep isl_schedule_node *ancestor) +{ + int n1, n2; + isl_schedule_tree *tree; + + if (!node || !ancestor) + return -1; + + if (node->schedule != ancestor->schedule) + isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid, + "not a descendant", return -1); + + n1 = isl_schedule_node_get_tree_depth(ancestor); + n2 = isl_schedule_node_get_tree_depth(node); + + if (n1 >= n2) + isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid, + "not a descendant", return -1); + tree = isl_schedule_tree_list_get_schedule_tree(node->ancestors, n1); + isl_schedule_tree_free(tree); + if (tree != ancestor->tree) + isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid, + "not a descendant", return -1); + + return node->child_pos[n1]; +} + /* Print "node" to "p". */ __isl_give isl_printer *isl_printer_print_schedule_node( -- 2.11.4.GIT