* ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
*/
+#include <isl/set.h>
+#include <isl/map.h>
#include <isl/flow.h>
/* A private structure to keep track of a mapping together with
* - n_must + n_may (<= max_source) sources
* - a function for determining the relative order of sources and sink
* The must sources are placed before the may sources.
+ *
+ * domain_map is an auxiliary map that maps the sink access relation
+ * to the domain of this access relation.
+ *
+ * restrict_sources is a callback that (if not NULL) will be called
+ * right before any lexicographical maximization.
*/
struct isl_access_info {
- struct isl_labeled_map sink;
- isl_access_level_before level_before;
- int max_source;
- int n_must;
- int n_may;
- struct isl_labeled_map source[1];
+ isl_map *domain_map;
+ struct isl_labeled_map sink;
+ isl_access_level_before level_before;
+ isl_access_restrict_sources restrict_sources;
+ int max_source;
+ int n_must;
+ int n_may;
+ struct isl_labeled_map source[1];
};
/* A structure containing the output of dependence analysis:
ctx = isl_map_get_ctx(sink);
isl_assert(ctx, max_source >= 0, goto error);
- acc = isl_alloc(ctx, struct isl_access_info,
+ acc = isl_calloc(ctx, struct isl_access_info,
sizeof(struct isl_access_info) +
(max_source - 1) * sizeof(struct isl_labeled_map));
if (!acc)
if (!acc)
return;
+ isl_map_free(acc->domain_map);
isl_map_free(acc->sink.map);
for (i = 0; i < acc->n_must + acc->n_may; ++i)
isl_map_free(acc->source[i].map);
free(acc);
}
+isl_ctx *isl_access_info_get_ctx(__isl_keep isl_access_info *acc)
+{
+ return acc ? isl_map_get_ctx(acc->sink.map) : NULL;
+}
+
+__isl_give isl_access_info *isl_access_info_set_restrict_sources(
+ __isl_take isl_access_info *acc, isl_access_restrict_sources fn)
+{
+ if (!acc)
+ return NULL;
+ acc->restrict_sources = fn;
+ return acc;
+}
+
/* Add another source to an isl_access_info structure, making
* sure the "must" sources are placed before the "may" sources.
* This function may be called at most max_source times on a
return NULL;
}
+/* Align the parameters of the two spaces if needed and then call
+ * isl_space_join.
+ */
+static __isl_give isl_space *space_align_and_join(__isl_take isl_space *left,
+ __isl_take isl_space *right)
+{
+ if (isl_space_match(left, isl_dim_param, right, isl_dim_param))
+ return isl_space_join(left, right);
+
+ left = isl_space_align_params(left, isl_space_copy(right));
+ right = isl_space_align_params(right, isl_space_copy(left));
+ return isl_space_join(left, right);
+}
+
/* Initialize an empty isl_flow structure corresponding to a given
* isl_access_info structure.
* For each must access, two dependences are created (initialized
dep->n_source = 2 * acc->n_must + acc->n_may;
for (i = 0; i < acc->n_must; ++i) {
- struct isl_dim *dim;
- dim = isl_dim_join(isl_map_get_dim(acc->source[i].map),
- isl_dim_reverse(isl_map_get_dim(acc->sink.map)));
+ isl_space *dim;
+ dim = space_align_and_join(
+ isl_map_get_space(acc->source[i].map),
+ isl_space_reverse(isl_map_get_space(acc->sink.map)));
dep->dep[2 * i].map = isl_map_empty(dim);
dep->dep[2 * i + 1].map = isl_map_copy(dep->dep[2 * i].map);
dep->dep[2 * i].data = acc->source[i].data;
goto error;
}
for (i = acc->n_must; i < acc->n_must + acc->n_may; ++i) {
- struct isl_dim *dim;
- dim = isl_dim_join(isl_map_get_dim(acc->source[i].map),
- isl_dim_reverse(isl_map_get_dim(acc->sink.map)));
+ isl_space *dim;
+ dim = space_align_and_join(
+ isl_map_get_space(acc->source[i].map),
+ isl_space_reverse(isl_map_get_space(acc->sink.map)));
dep->dep[acc->n_must + i].map = isl_map_empty(dim);
dep->dep[acc->n_must + i].data = acc->source[i].data;
dep->dep[acc->n_must + i].must = 0;
free(deps);
}
+isl_ctx *isl_flow_get_ctx(__isl_keep isl_flow *deps)
+{
+ return deps ? isl_set_get_ctx(deps->must_no_source) : NULL;
+}
+
/* Return a map that enforces that the domain iteration occurs after
* the range iteration at the given level.
* If level is odd, then the domain iteration should occur after
* be greater than the loop iterator of the range at the last
* of the level/2 shared loops, i.e., loop level/2 - 1.
*/
-static __isl_give isl_map *after_at_level(struct isl_dim *dim, int level)
+static __isl_give isl_map *after_at_level(__isl_take isl_space *dim, int level)
{
struct isl_basic_map *bmap;
return isl_map_from_basic_map(bmap);
}
+/* Check if the user has set acc->restrict_sources and if so
+ * intersect the range of "dep" with the result of a call to this function.
+ *
+ * Since the user expects a mapping from sink iterations to source iterations,
+ * whereas the domain of "dep" is a wrapped map, mapping sink iterations
+ * to accessed array elements, we first need to project out the accessed
+ * sink array elements by applying acc->domain_map.
+ */
+static __isl_give isl_map *restrict_sources(__isl_take isl_map *dep,
+ struct isl_access_info *acc, int source)
+{
+ isl_map *source_map;
+ isl_set *param;
+
+ if (!acc->restrict_sources)
+ return dep;
+
+ source_map = isl_map_copy(dep);
+ source_map = isl_map_apply_domain(source_map,
+ isl_map_copy(acc->domain_map));
+ param = acc->restrict_sources(source_map, acc->sink.data,
+ acc->source[source].data);
+ dep = isl_map_intersect_range(dep, param);
+ return dep;
+}
+
/* Compute the last iteration of must source j that precedes the sink
* at the given level for sink iterations in set_C.
* The subset of set_C for which no such iteration can be found is returned
write_map = isl_map_copy(acc->source[j].map);
write_map = isl_map_reverse(write_map);
dep_map = isl_map_apply_range(read_map, write_map);
- after = after_at_level(isl_map_get_dim(dep_map), level);
+ after = after_at_level(isl_map_get_space(dep_map), level);
dep_map = isl_map_intersect(dep_map, after);
+ dep_map = restrict_sources(dep_map, acc, j);
result = isl_map_partial_lexmax(dep_map, set_C, empty);
result = isl_map_reverse(result);
int k, int after_level,
struct isl_set **empty)
{
- struct isl_dim *dim;
+ isl_space *dim;
struct isl_set *set_C;
struct isl_map *read_map;
struct isl_map *write_map;
write_map = isl_map_reverse(write_map);
dep_map = isl_map_apply_range(read_map, write_map);
- dim = isl_dim_join(isl_map_get_dim(acc->source[k].map),
- isl_dim_reverse(isl_map_get_dim(acc->source[j].map)));
+ dim = space_align_and_join(isl_map_get_space(acc->source[k].map),
+ isl_space_reverse(isl_map_get_space(acc->source[j].map)));
after_write = after_at_level(dim, after_level);
after_write = isl_map_apply_range(after_write, old_map);
after_write = isl_map_reverse(after_write);
dep_map = isl_map_intersect(dep_map, after_write);
- before_read = after_at_level(isl_map_get_dim(dep_map), before_level);
+ before_read = after_at_level(isl_map_get_space(dep_map), before_level);
dep_map = isl_map_intersect(dep_map, before_read);
+ dep_map = restrict_sources(dep_map, acc, k);
result = isl_map_partial_lexmax(dep_map, set_C, empty);
result = isl_map_reverse(result);
write_map = isl_map_copy(acc->source[acc->n_must + j].map);
write_map = isl_map_reverse(write_map);
dep_map = isl_map_apply_range(read_map, write_map);
- after = after_at_level(isl_map_get_dim(dep_map), level);
+ after = after_at_level(isl_map_get_space(dep_map), level);
dep_map = isl_map_intersect(dep_map, after);
return isl_map_reverse(dep_map);
__isl_keep isl_map *old_map,
int j, int before_level, int k, int after_level)
{
- isl_dim *dim;
+ isl_space *dim;
isl_set *set_C;
isl_map *read_map;
isl_map *write_map;
write_map = isl_map_reverse(write_map);
dep_map = isl_map_apply_range(read_map, write_map);
- dim = isl_dim_join(isl_map_get_dim(acc->source[acc->n_must + j].map),
- isl_dim_reverse(isl_map_get_dim(acc->source[k].map)));
+ dim = isl_space_join(isl_map_get_space(acc->source[acc->n_must + j].map),
+ isl_space_reverse(isl_map_get_space(acc->source[k].map)));
after_write = after_at_level(dim, after_level);
after_write = isl_map_apply_range(after_write, old_map);
after_write = isl_map_reverse(after_write);
dep_map = isl_map_intersect(dep_map, after_write);
- before_read = after_at_level(isl_map_get_dim(dep_map), before_level);
+ before_read = after_at_level(isl_map_get_space(dep_map), before_level);
dep_map = isl_map_intersect(dep_map, before_read);
return isl_map_reverse(dep_map);
}
isl_set_copy(ran)));
T = isl_map_from_domain_and_range(
isl_set_universe(
- isl_dim_domain(isl_map_get_dim(must_rel[k]))),
+ isl_space_domain(isl_map_get_space(must_rel[k]))),
ran);
must_rel[k] = isl_map_subtract(must_rel[k], T);
}
* be overkill to use it.
*/
static __isl_give isl_flow *compute_mem_based_dependences(
- __isl_take isl_access_info *acc)
+ __isl_keep isl_access_info *acc)
{
int i;
isl_set *mustdo;
res = isl_flow_alloc(acc);
if (!res)
- goto error;
+ return NULL;
mustdo = isl_map_domain(isl_map_copy(acc->sink.map));
maydo = isl_set_copy(mustdo);
for (i = 0; i < acc->n_may; ++i) {
int plevel;
int is_before;
- isl_dim *dim;
+ isl_space *dim;
isl_map *before;
isl_map *dep;
is_before = plevel & 1;
plevel >>= 1;
- dim = isl_map_get_dim(res->dep[i].map);
+ dim = isl_map_get_space(res->dep[i].map);
if (is_before)
before = isl_map_lex_le_first(dim, plevel);
else
res->may_no_source = isl_set_subtract(maydo, isl_set_copy(mustdo));
res->must_no_source = mustdo;
- isl_access_info_free(acc);
-
return res;
-error:
- isl_access_info_free(acc);
- return NULL;
}
/* Compute dependences for the case where there is at least one
*
*/
static __isl_give isl_flow *compute_val_based_dependences(
- __isl_take isl_access_info *acc)
+ __isl_keep isl_access_info *acc)
{
isl_ctx *ctx;
isl_flow *res;
isl_map **must_rel = NULL;
isl_map **may_rel = NULL;
- acc = isl_access_info_sort_sources(acc);
if (!acc)
return NULL;
done:
res->must_no_source = mustdo;
res->may_no_source = maydo;
- isl_access_info_free(acc);
return res;
error:
- isl_access_info_free(acc);
isl_flow_free(res);
isl_set_free(mustdo);
isl_set_free(maydo);
__isl_give isl_flow *isl_access_info_compute_flow(__isl_take isl_access_info *acc)
{
int j;
- struct isl_flow *res;
- isl_map *domain_map = NULL;
+ struct isl_flow *res = NULL;
if (!acc)
return NULL;
- domain_map = isl_map_domain_map(isl_map_copy(acc->sink.map));
+ acc->domain_map = isl_map_domain_map(isl_map_copy(acc->sink.map));
acc->sink.map = isl_map_range_map(acc->sink.map);
if (!acc->sink.map)
goto error;
if (acc->n_must == 0)
res = compute_mem_based_dependences(acc);
- else
+ else {
+ acc = isl_access_info_sort_sources(acc);
res = compute_val_based_dependences(acc);
+ }
if (!res)
- return NULL;
+ goto error;
for (j = 0; j < res->n_source; ++j) {
res->dep[j].map = isl_map_apply_range(res->dep[j].map,
- isl_map_copy(domain_map));
+ isl_map_copy(acc->domain_map));
if (!res->dep[j].map)
- goto error2;
+ goto error;
}
if (!res->must_no_source || !res->may_no_source)
- goto error2;
+ goto error;
- isl_map_free(domain_map);
+ isl_access_info_free(acc);
return res;
error:
- isl_map_free(domain_map);
isl_access_info_free(acc);
- return NULL;
-error2:
- isl_map_free(domain_map);
isl_flow_free(res);
return NULL;
}
__isl_keep isl_map *map)
{
isl_ctx *ctx;
- isl_dim *dim;
+ isl_space *dim;
struct isl_sched_info *info;
int i, n;
if (!map)
return NULL;
- dim = isl_dim_unwrap(isl_dim_domain(isl_map_get_dim(map)));
+ dim = isl_space_unwrap(isl_space_domain(isl_map_get_space(map)));
if (!dim)
return NULL;
- n = isl_dim_size(dim, isl_dim_in);
- isl_dim_free(dim);
+ n = isl_space_dim(dim, isl_dim_in);
+ isl_space_free(dim);
ctx = isl_map_get_ctx(map);
info = isl_alloc_type(ctx, struct isl_sched_info);
int count;
int must;
- isl_dim *dim;
+ isl_space *dim;
struct isl_sched_info *sink_info;
struct isl_sched_info **source_info;
isl_access_info *accesses;
static int count_matching_array(__isl_take isl_map *map, void *user)
{
int eq;
- isl_dim *dim;
+ isl_space *dim;
struct isl_compute_flow_data *data;
data = (struct isl_compute_flow_data *)user;
- dim = isl_dim_range(isl_map_get_dim(map));
+ dim = isl_space_range(isl_map_get_space(map));
- eq = isl_dim_equal(dim, data->dim);
+ eq = isl_space_is_equal(dim, data->dim);
- isl_dim_free(dim);
+ isl_space_free(dim);
isl_map_free(map);
if (eq < 0)
static int collect_matching_array(__isl_take isl_map *map, void *user)
{
int eq;
- isl_dim *dim;
+ isl_space *dim;
struct isl_sched_info *info;
struct isl_compute_flow_data *data;
data = (struct isl_compute_flow_data *)user;
- dim = isl_dim_range(isl_map_get_dim(map));
+ dim = isl_space_range(isl_map_get_space(map));
- eq = isl_dim_equal(dim, data->dim);
+ eq = isl_space_is_equal(dim, data->dim);
- isl_dim_free(dim);
+ isl_space_free(dim);
if (eq < 0)
goto error;
data->sink_info = NULL;
data->source_info = NULL;
data->count = 0;
- data->dim = isl_dim_range(isl_map_get_dim(map));
+ data->dim = isl_space_range(isl_map_get_space(map));
if (isl_union_map_foreach_map(data->must_source,
&count_matching_array, data) < 0)
sched_info_free(data->source_info[i]);
free(data->source_info);
}
- isl_dim_free(data->dim);
+ isl_space_free(data->dim);
isl_map_free(map);
return 0;
sched_info_free(data->source_info[i]);
free(data->source_info);
}
- isl_dim_free(data->dim);
+ isl_space_free(data->dim);
isl_map_free(map);
return -1;
__isl_give isl_union_map **must_no_source,
__isl_give isl_union_map **may_no_source)
{
- isl_dim *dim;
+ isl_space *dim;
isl_union_map *range_map = NULL;
struct isl_compute_flow_data data;
sink = isl_union_map_align_params(sink,
- isl_union_map_get_dim(must_source));
+ isl_union_map_get_space(must_source));
sink = isl_union_map_align_params(sink,
- isl_union_map_get_dim(may_source));
+ isl_union_map_get_space(may_source));
sink = isl_union_map_align_params(sink,
- isl_union_map_get_dim(schedule));
- dim = isl_union_map_get_dim(sink);
- must_source = isl_union_map_align_params(must_source, isl_dim_copy(dim));
- may_source = isl_union_map_align_params(may_source, isl_dim_copy(dim));
- schedule = isl_union_map_align_params(schedule, isl_dim_copy(dim));
+ isl_union_map_get_space(schedule));
+ dim = isl_union_map_get_space(sink);
+ must_source = isl_union_map_align_params(must_source, isl_space_copy(dim));
+ may_source = isl_union_map_align_params(may_source, isl_space_copy(dim));
+ schedule = isl_union_map_align_params(schedule, isl_space_copy(dim));
schedule = isl_union_map_reverse(schedule);
range_map = isl_union_map_range_map(schedule);
data.must_source = must_source;
data.may_source = may_source;
data.must_dep = must_dep ?
- isl_union_map_empty(isl_dim_copy(dim)) : NULL;
- data.may_dep = may_dep ? isl_union_map_empty(isl_dim_copy(dim)) : NULL;
+ isl_union_map_empty(isl_space_copy(dim)) : NULL;
+ data.may_dep = may_dep ? isl_union_map_empty(isl_space_copy(dim)) : NULL;
data.must_no_source = must_no_source ?
- isl_union_map_empty(isl_dim_copy(dim)) : NULL;
+ isl_union_map_empty(isl_space_copy(dim)) : NULL;
data.may_no_source = may_no_source ?
- isl_union_map_empty(isl_dim_copy(dim)) : NULL;
+ isl_union_map_empty(isl_space_copy(dim)) : NULL;
- isl_dim_free(dim);
+ isl_space_free(dim);
if (isl_union_map_foreach_map(sink, &compute_flow, &data) < 0)
goto error;