From b066af497f81084767b7702dd471457b44aa79b6 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Mon, 5 May 2014 14:54:40 +0200 Subject: [PATCH] isl_schedule_node.c: update_ancestors: allow modification of ancestors This will be useful for the isl_schedule_node_group function, introduced in the next commit, which needs to modify the ancestors to refer to the group instead of the original domain. Signed-off-by: Sven Verdoolaege --- isl_schedule_node.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/isl_schedule_node.c b/isl_schedule_node.c index b4791fd6..016f7f80 100644 --- a/isl_schedule_node.c +++ b/isl_schedule_node.c @@ -1813,20 +1813,32 @@ error: * to the current tree position by node->tree and continue updating * the ancestors in the same way until the root is reached. * + * If "fn" is not NULL, then it is called on each ancestor as we move up + * the tree so that it can modify the ancestor before it is added + * to the list of ancestors of the modified node. + * The additional "pos" argument records the position + * of the "tree" argument in the original schedule tree. + * * If "node" originally points to a leaf of the schedule tree, then make sure * that in the end it points to a leaf in the updated schedule tree. */ static __isl_give isl_schedule_node *update_ancestors( - __isl_take isl_schedule_node *node) + __isl_take isl_schedule_node *node, + __isl_give isl_schedule_tree *(*fn)(__isl_take isl_schedule_tree *tree, + __isl_keep isl_schedule_node *pos, void *user), void *user) { int i, n; int is_leaf; isl_ctx *ctx; isl_schedule_tree *tree; + isl_schedule_node *pos = NULL; + + if (fn) + pos = isl_schedule_node_copy(node); node = isl_schedule_node_cow(node); if (!node) - return NULL; + return isl_schedule_node_free(pos); ctx = isl_schedule_node_get_ctx(node); n = isl_schedule_tree_list_n_schedule_tree(node->ancestors); @@ -1839,12 +1851,19 @@ static __isl_give isl_schedule_node *update_ancestors( node->ancestors, i); parent = isl_schedule_tree_replace_child(parent, node->child_pos[i], tree); + if (fn) { + pos = isl_schedule_node_parent(pos); + parent = fn(parent, pos, user); + } node->ancestors = isl_schedule_tree_list_set_schedule_tree( node->ancestors, i, isl_schedule_tree_copy(parent)); tree = parent; } + if (fn) + isl_schedule_node_free(pos); + is_leaf = isl_schedule_tree_is_leaf(node->tree); node->schedule = isl_schedule_set_root(node->schedule, tree); if (is_leaf) { @@ -1878,7 +1897,7 @@ __isl_give isl_schedule_node *isl_schedule_node_graft_tree( isl_schedule_tree_free(pos->tree); pos->tree = tree; - return update_ancestors(pos); + return update_ancestors(pos, NULL, NULL); error: isl_schedule_node_free(pos); isl_schedule_tree_free(tree); -- 2.11.4.GIT