isl_stream: support compound tokens
[platform/upstream/isl.git] / isl_flow.c
index 0168553..128aee5 100644 (file)
@@ -13,6 +13,8 @@
  * 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
@@ -42,8 +44,8 @@ struct isl_access_info {
 
 /* A structure containing the output of dependence analysis:
  * - n_source dependences
- * - a subset of the sink for which definitely no source could be found
- * - a subset of the sink for which possibly no source could be found
+ * - a wrapped subset of the sink for which definitely no source could be found
+ * - a wrapped subset of the sink for which possibly no source could be found
  */
 struct isl_flow {
        isl_set                 *must_no_source;
@@ -100,6 +102,11 @@ void isl_access_info_free(__isl_take isl_access_info *acc)
        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;
+}
+
 /* 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
@@ -188,7 +195,7 @@ static int access_sort_cmp(const void *p1, const void *p2)
 
        h1 = isl_map_get_hash(i1->source_map);
        h2 = isl_map_get_hash(i2->source_map);
-       return h1 - h2;
+       return h1 > h2 ? 1 : h1 < h2 ? -1 : 0;
 }
 
 /* Sort the must source accesses in order of increasing number of shared
@@ -311,7 +318,7 @@ int isl_flow_foreach(__isl_keep isl_flow *deps,
                return -1;
 
        for (i = 0; i < deps->n_source; ++i) {
-               if (isl_map_fast_is_empty(deps->dep[i].map))
+               if (isl_map_plain_is_empty(deps->dep[i].map))
                        continue;
                if (fn(isl_map_copy(deps->dep[i].map), deps->dep[i].must,
                                deps->dep[i].data, user) < 0)
@@ -323,15 +330,15 @@ int isl_flow_foreach(__isl_keep isl_flow *deps,
 
 /* Return a copy of the subset of the sink for which no source could be found.
  */
-__isl_give isl_set *isl_flow_get_no_source(__isl_keep isl_flow *deps, int must)
+__isl_give isl_map *isl_flow_get_no_source(__isl_keep isl_flow *deps, int must)
 {
        if (!deps)
                return NULL;
        
        if (must)
-               return isl_set_copy(deps->must_no_source);
+               return isl_set_unwrap(isl_set_copy(deps->must_no_source));
        else
-               return isl_set_copy(deps->may_no_source);
+               return isl_set_unwrap(isl_set_copy(deps->may_no_source));
 }
 
 void isl_flow_free(__isl_take isl_flow *deps)
@@ -350,6 +357,11 @@ void isl_flow_free(__isl_take isl_flow *deps)
        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
@@ -475,7 +487,7 @@ static int intermediate_sources(__isl_keep isl_access_info *acc,
        int k, level;
        int depth = 2 * isl_map_dim(acc->source[j].map, isl_dim_in) + 1;
 
-       if (isl_map_fast_is_empty(temp_rel[j]))
+       if (isl_map_plain_is_empty(temp_rel[j]))
                return 0;
 
        for (k = j - 1; k >= 0; --k) {
@@ -498,7 +510,7 @@ static int intermediate_sources(__isl_keep isl_access_info *acc,
                        copy = isl_map_copy(temp_rel[j]);
                        T = last_later_source(acc, copy, j, sink_level, k,
                                              level, &trest);
-                       if (isl_map_fast_is_empty(T)) {
+                       if (isl_map_plain_is_empty(T)) {
                                isl_set_free(trest);
                                isl_map_free(T);
                                continue;
@@ -588,8 +600,8 @@ static __isl_give isl_map *all_intermediate_sources(
        for (k = 0; k < acc->n_must; ++k) {
                int plevel;
 
-               if (isl_map_fast_is_empty(may_rel[k]) &&
-                   isl_map_fast_is_empty(must_rel[k]))
+               if (isl_map_plain_is_empty(may_rel[k]) &&
+                   isl_map_plain_is_empty(must_rel[k]))
                        continue;
 
                plevel = acc->level_before(acc->source[k].data,
@@ -741,7 +753,7 @@ static __isl_give isl_flow *compute_val_based_dependences(
        maydo = isl_set_empty_like(mustdo);
        if (!mustdo || !maydo)
                goto error;
-       if (isl_set_fast_is_empty(mustdo))
+       if (isl_set_plain_is_empty(mustdo))
                goto done;
 
        must_rel = isl_alloc_array(ctx, struct isl_map *, acc->n_must);
@@ -777,8 +789,8 @@ static __isl_give isl_flow *compute_val_based_dependences(
 
                        intermediate_sources(acc, may_rel, j, level);
 
-                       if (isl_set_fast_is_empty(mustdo) &&
-                           isl_set_fast_is_empty(maydo))
+                       if (isl_set_plain_is_empty(mustdo) &&
+                           isl_set_plain_is_empty(maydo))
                                break;
                }
                for (j = j - 1; j >= 0; --j) {
@@ -828,8 +840,8 @@ static __isl_give isl_flow *compute_val_based_dependences(
                                                             may_rel[j]);
                }
 
-               if (isl_set_fast_is_empty(mustdo) &&
-                   isl_set_fast_is_empty(maydo))
+               if (isl_set_plain_is_empty(mustdo) &&
+                   isl_set_plain_is_empty(maydo))
                        break;
        }
 
@@ -894,10 +906,6 @@ __isl_give isl_flow *isl_access_info_compute_flow(__isl_take isl_access_info *ac
                if (!res->dep[j].map)
                        goto error2;
        }
-       res->must_no_source = isl_set_apply(res->must_no_source,
-                                       isl_map_copy(domain_map));
-       res->may_no_source = isl_set_apply(res->may_no_source,
-                                       isl_map_copy(domain_map));
        if (!res->must_no_source || !res->may_no_source)
                goto error2;
 
@@ -937,7 +945,7 @@ static void sched_info_free(__isl_take struct isl_sched_info *info)
  *
  *     [S -> D] -> A
  *
- * wiht S the schedule domain, D the iteration domain and A the data domain.
+ * with S the schedule domain, D the iteration domain and A the data domain.
  */
 static __isl_give struct isl_sched_info *sched_info_alloc(
        __isl_keep isl_map *map)
@@ -966,7 +974,7 @@ static __isl_give struct isl_sched_info *sched_info_alloc(
                goto error;
 
        for (i = 0; i < n; ++i)
-               info->is_cst[i] = isl_map_fast_is_fixed(map, isl_dim_in, i,
+               info->is_cst[i] = isl_map_plain_is_fixed(map, isl_dim_in, i,
                                                        &info->cst->el[i]);
 
        return info;
@@ -980,8 +988,8 @@ struct isl_compute_flow_data {
        isl_union_map *may_source;
        isl_union_map *must_dep;
        isl_union_map *may_dep;
-       isl_union_set *must_no_source;
-       isl_union_set *may_no_source;
+       isl_union_map *must_no_source;
+       isl_union_map *may_no_source;
 
        int count;
        int must;
@@ -1059,7 +1067,7 @@ error:
  * value and if moreover those values are different, then the previous
  * dimension is the last shared nesting level and the textual order
  * is determined based on the order of the fixed values.
- * If no such fixed values can be found, then we seet the shared
+ * If no such fixed values can be found, then we set the shared
  * nesting level to the minimal schedule dimension, with no textual ordering.
  */
 static int before(void *first, void *second)
@@ -1140,10 +1148,10 @@ static int compute_flow(__isl_take isl_map *map, void *user)
        if (!flow)
                goto error;
 
-       data->must_no_source = isl_union_set_union(data->must_no_source,
-                   isl_union_set_from_set(isl_set_copy(flow->must_no_source)));
-       data->may_no_source = isl_union_set_union(data->may_no_source,
-                   isl_union_set_from_set(isl_set_copy(flow->may_no_source)));
+       data->must_no_source = isl_union_map_union(data->must_no_source,
+                   isl_union_map_from_map(isl_flow_get_no_source(flow, 1)));
+       data->may_no_source = isl_union_map_union(data->may_no_source,
+                   isl_union_map_from_map(isl_flow_get_no_source(flow, 0)));
 
        for (i = 0; i < flow->n_source; ++i) {
                isl_union_map *dep;
@@ -1201,8 +1209,8 @@ int isl_union_map_compute_flow(__isl_take isl_union_map *sink,
        __isl_take isl_union_map *may_source,
        __isl_take isl_union_map *schedule,
        __isl_give isl_union_map **must_dep, __isl_give isl_union_map **may_dep,
-       __isl_give isl_union_set **must_no_source,
-       __isl_give isl_union_set **may_no_source)
+       __isl_give isl_union_map **must_no_source,
+       __isl_give isl_union_map **may_no_source)
 {
        isl_dim *dim;
        isl_union_map *range_map = NULL;
@@ -1233,9 +1241,9 @@ int isl_union_map_compute_flow(__isl_take isl_union_map *sink,
                isl_union_map_empty(isl_dim_copy(dim)) : NULL;
        data.may_dep = may_dep ? isl_union_map_empty(isl_dim_copy(dim)) : NULL;
        data.must_no_source = must_no_source ?
-               isl_union_set_empty(isl_dim_copy(dim)) : NULL;
+               isl_union_map_empty(isl_dim_copy(dim)) : NULL;
        data.may_no_source = may_no_source ?
-               isl_union_set_empty(isl_dim_copy(dim)) : NULL;
+               isl_union_map_empty(isl_dim_copy(dim)) : NULL;
 
        isl_dim_free(dim);
 
@@ -1261,13 +1269,13 @@ int isl_union_map_compute_flow(__isl_take isl_union_map *sink,
                *may_dep = data.may_dep;
        }
        if (must_no_source) {
-               data.must_no_source = isl_union_set_apply(data.must_no_source,
-                                       isl_union_map_copy(range_map));
+               data.must_no_source = isl_union_map_apply_domain(
+                       data.must_no_source, isl_union_map_copy(range_map));
                *must_no_source = data.must_no_source;
        }
        if (may_no_source) {
-               data.may_no_source = isl_union_set_apply(data.may_no_source,
-                                       isl_union_map_copy(range_map));
+               data.may_no_source = isl_union_map_apply_domain(
+                       data.may_no_source, isl_union_map_copy(range_map));
                *may_no_source = data.may_no_source;
        }
 
@@ -1281,8 +1289,8 @@ error:
        isl_union_map_free(may_source);
        isl_union_map_free(data.must_dep);
        isl_union_map_free(data.may_dep);
-       isl_union_set_free(data.must_no_source);
-       isl_union_set_free(data.may_no_source);
+       isl_union_map_free(data.must_no_source);
+       isl_union_map_free(data.may_no_source);
 
        if (must_dep)
                *must_dep = NULL;