From a64d31c140434be1088a62cfa41eeeccf6ecbaed Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sun, 13 Jul 2014 10:55:03 +0200 Subject: [PATCH] add isl_schedule_node_ancestor Signed-off-by: Sven Verdoolaege --- doc/user.pod | 6 ++++++ include/isl/schedule_node.h | 2 ++ isl_schedule_node.c | 42 +++++++++++++++++++++++++++++++++--------- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/doc/user.pod b/doc/user.pod index 66b34d87..a9d76847 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -7430,6 +7430,9 @@ exists. __isl_keep isl_schedule_node *node); __isl_give isl_schedule_node *isl_schedule_node_parent( __isl_take isl_schedule_node *node); + __isl_give isl_schedule_node *isl_schedule_node_ancestor( + __isl_take isl_schedule_node *node, + int generation); int isl_schedule_node_n_children( __isl_keep isl_schedule_node *node); __isl_give isl_schedule_node *isl_schedule_node_child( @@ -7449,6 +7452,9 @@ exists. isl_schedule_node_next_sibling( __isl_take isl_schedule_node *node); +For C, the ancestor of generation 0 +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 diff --git a/include/isl/schedule_node.h b/include/isl/schedule_node.h index a445be0f..7c9d2f36 100644 --- a/include/isl/schedule_node.h +++ b/include/isl/schedule_node.h @@ -48,6 +48,8 @@ __isl_give isl_schedule_node *isl_schedule_node_get_child( __isl_give isl_schedule_node *isl_schedule_node_parent( __isl_take isl_schedule_node *node); +__isl_give isl_schedule_node *isl_schedule_node_ancestor( + __isl_take isl_schedule_node *node, int generation); __isl_give isl_schedule_node *isl_schedule_node_child( __isl_take isl_schedule_node *node, int pos); __isl_give isl_schedule_node *isl_schedule_node_first_child( diff --git a/isl_schedule_node.c b/isl_schedule_node.c index 10af6fb8..b769e466 100644 --- a/isl_schedule_node.c +++ b/isl_schedule_node.c @@ -677,33 +677,57 @@ int isl_schedule_node_n_children(__isl_keep isl_schedule_node *node) return n; } -/* Move the "node" pointer to the parent of the node it currently points to. +/* Move the "node" pointer to the ancestor of the given generation + * of the node it currently points to, where generation 0 is the node + * itself and generation 1 is its parent. */ -__isl_give isl_schedule_node *isl_schedule_node_parent( - __isl_take isl_schedule_node *node) +__isl_give isl_schedule_node *isl_schedule_node_ancestor( + __isl_take isl_schedule_node *node, int generation) { int n; isl_schedule_tree *tree; - node = isl_schedule_node_cow(node); if (!node) return NULL; - if (!isl_schedule_node_has_parent(node)) + if (generation == 0) + return node; + n = isl_schedule_node_get_tree_depth(node); + if (n < 0) + return isl_schedule_node_free(node); + if (generation < 0 || generation > n) isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid, - "node has no parent", + "generation out of bounds", return isl_schedule_node_free(node)); - n = isl_schedule_tree_list_n_schedule_tree(node->ancestors); - tree = isl_schedule_tree_list_get_schedule_tree(node->ancestors, n - 1); + node = isl_schedule_node_cow(node); + if (!node) + return NULL; + + tree = isl_schedule_tree_list_get_schedule_tree(node->ancestors, + n - generation); isl_schedule_tree_free(node->tree); node->tree = tree; node->ancestors = isl_schedule_tree_list_drop(node->ancestors, - n - 1, 1); + n - generation, generation); if (!node->ancestors || !node->tree) return isl_schedule_node_free(node); return node; } +/* Move the "node" pointer to the parent of the node it currently points to. + */ +__isl_give isl_schedule_node *isl_schedule_node_parent( + __isl_take isl_schedule_node *node) +{ + if (!node) + return NULL; + if (!isl_schedule_node_has_parent(node)) + isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid, + "node has no parent", + return isl_schedule_node_free(node)); + return isl_schedule_node_ancestor(node, 1); +} + /* Move the "node" pointer to the child at position "pos" of the node * it currently points to. */ -- 2.11.4.GIT