add isl_map_reaching_path_lengths
authorSven Verdoolaege <skimo@kotnet.org>
Thu, 22 Jul 2010 11:30:34 +0000 (13:30 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Sat, 24 Jul 2010 10:50:41 +0000 (12:50 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
doc/user.pod
include/isl_map.h
isl_transitive_closure.c

index 8bb1044..abeaa36 100644 (file)
@@ -1020,6 +1020,25 @@ then C<*exact> is set to C<1>.
 The current implementation only produces exact results for particular
 cases of piecewise translations (i.e., piecewise uniform dependences).
 
+=item * Reaching path lengths
+
+       __isl_give isl_map *isl_map_reaching_path_lengths(
+               __isl_take isl_map *map, int *exact);
+
+Compute a relation that maps each element in the range of C<map>
+to the lengths of all paths composed of edges in C<map> that
+end up in the given element.
+The result may be an overapproximation.  If the result is known to be exact,
+then C<*exact> is set to C<1>.
+To compute the I<maximal> path length, the resulting relation
+should be postprocessed by C<isl_map_lexmax>.
+In particular, if the input relation is a dependence relation
+(mapping sources to sinks), then the maximal path length corresponds
+to the free schedule.
+Note, however, that C<isl_map_lexmax> expects the maximum to be
+finite, so if the path lengths are unbounded (possibly due to
+the overapproximation), then you will get an error message.
+
 =back
 
 =head2 Binary Operations
index bcb6581..e2fc38f 100644 (file)
@@ -397,6 +397,8 @@ __isl_give isl_map *isl_set_lifting(__isl_take isl_set *set);
 
 __isl_give isl_map *isl_map_power(__isl_take isl_map *map, unsigned param,
        int *exact);
+__isl_give isl_map *isl_map_reaching_path_lengths(__isl_take isl_map *map,
+       int *exact);
 __isl_give isl_map *isl_map_transitive_closure(__isl_take isl_map *map,
        int *exact);
 
index 7e65915..8adb934 100644 (file)
@@ -2040,6 +2040,54 @@ error:
        return NULL;
 }
 
+/* Compute a relation that maps each element in the range of the input
+ * relation to the lengths of all paths composed of edges in the input
+ * relation that end up in the given range element.
+ * The result may be an overapproximation, in which case *exact is set to 0.
+ * The resulting relation is very similar to the power relation.
+ * The difference are that the domain has been projected out, the
+ * range has become the domain and the exponent is the range instead
+ * of a parameter.
+ */
+__isl_give isl_map *isl_map_reaching_path_lengths(__isl_take isl_map *map,
+       int *exact)
+{
+       isl_dim *dim;
+       isl_map *diff;
+       unsigned d;
+       unsigned param;
+
+       if (!map)
+               return NULL;
+
+       d = isl_map_dim(map, isl_dim_in);
+       param = isl_map_dim(map, isl_dim_param);
+
+       map = isl_map_compute_divs(map);
+       map = isl_map_coalesce(map);
+
+       if (isl_map_fast_is_empty(map)) {
+               if (exact)
+                       *exact = 1;
+               map = isl_map_project_out(map, isl_dim_out, 0, d);
+               map = isl_map_add(map, isl_dim_out, 1);
+               return map;
+       }
+
+       map = map_power(map, exact, 0);
+
+       map = isl_map_add(map, isl_dim_param, 1);
+       dim = isl_map_get_dim(map);
+       diff = equate_parameter_to_length(dim, param);
+       map = isl_map_intersect(map, diff);
+       map = isl_map_project_out(map, isl_dim_in, 0, d + 1);
+       map = isl_map_project_out(map, isl_dim_out, d, 1);
+       map = isl_map_reverse(map);
+       map = isl_map_move_dims(map, isl_dim_out, 0, isl_dim_param, param, 1);
+
+       return map;
+}
+
 /* Check whether equality i of bset is a pure stride constraint
  * on a single dimensions, i.e., of the form
  *