From 9820a7c6191e8454b970cb83bb30a88ba7889e73 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 28 Aug 2014 14:27:30 +0200 Subject: [PATCH] add isl_schedule_node_band_scale_down Signed-off-by: Sven Verdoolaege --- doc/user.pod | 8 ++++++-- include/isl/schedule_node.h | 2 ++ isl_schedule_band.c | 22 ++++++++++++++++++++++ isl_schedule_band.h | 2 ++ isl_schedule_node.c | 22 ++++++++++++++++++++++ isl_schedule_tree.c | 27 +++++++++++++++++++++++++++ isl_schedule_tree.h | 2 ++ 7 files changed, 83 insertions(+), 2 deletions(-) diff --git a/doc/user.pod b/doc/user.pod index 298a8dd9..d65f1b3a 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -7515,14 +7515,18 @@ two filter nodes are merged into one. These functions insert a new sequence or set node with the given filters as children. -The partial schedule of a band node can be scaled using -the following function. +The partial schedule of a band node can be scaled (down) using +the following functions. #include __isl_give isl_schedule_node * isl_schedule_node_band_scale( __isl_take isl_schedule_node *node, __isl_take isl_multi_val *mv); + __isl_give isl_schedule_node * + isl_schedule_node_band_scale_down( + __isl_take isl_schedule_node *node, + __isl_take isl_multi_val *mv); The spaces of the two arguments need to match. After scaling, the partial schedule is replaced by its greatest diff --git a/include/isl/schedule_node.h b/include/isl/schedule_node.h index 49c3c0cd..c9f39aa1 100644 --- a/include/isl/schedule_node.h +++ b/include/isl/schedule_node.h @@ -68,6 +68,8 @@ int isl_options_get_tile_shift_point_loops(isl_ctx *ctx); __isl_give isl_schedule_node *isl_schedule_node_band_scale( __isl_take isl_schedule_node *node, __isl_take isl_multi_val *mv); +__isl_give isl_schedule_node *isl_schedule_node_band_scale_down( + __isl_take isl_schedule_node *node, __isl_take isl_multi_val *mv); __isl_give isl_schedule_node *isl_schedule_node_band_tile( __isl_take isl_schedule_node *node, __isl_take isl_multi_val *sizes); __isl_give isl_schedule_node *isl_schedule_node_band_split( diff --git a/isl_schedule_band.c b/isl_schedule_band.c index 5d189002..aae32f39 100644 --- a/isl_schedule_band.c +++ b/isl_schedule_band.c @@ -255,6 +255,28 @@ error: return NULL; } +/* Divide the partial schedule of "band" by the factors in "mv". + * Replace the result by its greatest integer part to ensure + * that the schedule is always integral. + */ +__isl_give isl_schedule_band *isl_schedule_band_scale_down( + __isl_take isl_schedule_band *band, __isl_take isl_multi_val *mv) +{ + band = isl_schedule_band_cow(band); + if (!band || !mv) + goto error; + band->mupa = isl_multi_union_pw_aff_scale_down_multi_val(band->mupa, + mv); + band->mupa = isl_multi_union_pw_aff_floor(band->mupa); + if (!band->mupa) + return isl_schedule_band_free(band); + return band; +error: + isl_schedule_band_free(band); + isl_multi_val_free(mv); + return NULL; +} + /* Given the schedule of a band, construct the corresponding * schedule for the tile loops based on the given tile sizes * and return the result. diff --git a/isl_schedule_band.h b/isl_schedule_band.h index 50f3dd8f..1a476e3c 100644 --- a/isl_schedule_band.h +++ b/isl_schedule_band.h @@ -50,6 +50,8 @@ __isl_give isl_schedule_band *isl_schedule_band_set_permutable( __isl_give isl_schedule_band *isl_schedule_band_scale( __isl_take isl_schedule_band *band, __isl_take isl_multi_val *mv); +__isl_give isl_schedule_band *isl_schedule_band_scale_down( + __isl_take isl_schedule_band *band, __isl_take isl_multi_val *mv); __isl_give isl_schedule_band *isl_schedule_band_tile( __isl_take isl_schedule_band *band, __isl_take isl_multi_val *sizes); __isl_give isl_schedule_band *isl_schedule_band_point( diff --git a/isl_schedule_node.c b/isl_schedule_node.c index 41367359..2feacd62 100644 --- a/isl_schedule_node.c +++ b/isl_schedule_node.c @@ -965,6 +965,28 @@ error: return NULL; } +/* Divide the partial schedule of the band node "node" + * by the factors in "mv". + */ +__isl_give isl_schedule_node *isl_schedule_node_band_scale_down( + __isl_take isl_schedule_node *node, __isl_take isl_multi_val *mv) +{ + isl_schedule_tree *tree; + + if (!node || !mv) + goto error; + if (check_space_multi_val(node, mv) < 0) + goto error; + + tree = isl_schedule_node_get_tree(node); + tree = isl_schedule_tree_band_scale_down(tree, mv); + return isl_schedule_node_graft_tree(node, tree); +error: + isl_multi_val_free(mv); + isl_schedule_node_free(node); + return NULL; +} + /* Tile "node" with tile sizes "sizes". * * The current node is replaced by two nested nodes corresponding diff --git a/isl_schedule_tree.c b/isl_schedule_tree.c index f8184191..5a0858b5 100644 --- a/isl_schedule_tree.c +++ b/isl_schedule_tree.c @@ -1068,6 +1068,33 @@ error: return NULL; } +/* Divide the partial schedule of the band root node of "tree" + * by the factors in "mv". + */ +__isl_give isl_schedule_tree *isl_schedule_tree_band_scale_down( + __isl_take isl_schedule_tree *tree, __isl_take isl_multi_val *mv) +{ + if (!tree || !mv) + goto error; + if (tree->type != isl_schedule_node_band) + isl_die(isl_schedule_tree_get_ctx(tree), isl_error_invalid, + "not a band node", goto error); + + tree = isl_schedule_tree_cow(tree); + if (!tree) + goto error; + + tree->band = isl_schedule_band_scale_down(tree->band, mv); + if (!tree->band) + return isl_schedule_tree_free(tree); + + return tree; +error: + isl_schedule_tree_free(tree); + isl_multi_val_free(mv); + return NULL; +} + /* Tile the band root node of "tree" with tile sizes "sizes". * * We duplicate the band node, change the schedule of one of them diff --git a/isl_schedule_tree.h b/isl_schedule_tree.h index 9dcd5a22..923d15a5 100644 --- a/isl_schedule_tree.h +++ b/isl_schedule_tree.h @@ -106,6 +106,8 @@ __isl_give isl_schedule_tree *isl_schedule_tree_insert_filter( __isl_give isl_schedule_tree *isl_schedule_tree_band_scale( __isl_take isl_schedule_tree *tree, __isl_take isl_multi_val *mv); +__isl_give isl_schedule_tree *isl_schedule_tree_band_scale_down( + __isl_take isl_schedule_tree *tree, __isl_take isl_multi_val *mv); __isl_give isl_schedule_tree *isl_schedule_tree_band_tile( __isl_take isl_schedule_tree *tree, __isl_take isl_multi_val *sizes); __isl_give isl_schedule_tree *isl_schedule_tree_band_split( -- 2.11.4.GIT