isl_space_extend_domain_with_range: handle ranges with a nested space
authorSven Verdoolaege <skimo@kotnet.org>
Fri, 20 Jul 2012 17:41:17 +0000 (19:41 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Fri, 27 Jul 2012 16:20:08 +0000 (18:20 +0200)
The original code would only take into account the number of dimensions
and the tuple name.

Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_space.c
isl_test.c

index 2f5385b..ac4cd41 100644 (file)
@@ -1836,16 +1836,36 @@ error:
  * with as domain the given space and as range the range of "model".
  */
 __isl_give isl_space *isl_space_extend_domain_with_range(
-       __isl_take isl_space *domain, __isl_take isl_space *model)
+       __isl_take isl_space *space, __isl_take isl_space *model)
 {
-       isl_space *space;
+       if (!model)
+               goto error;
 
-       space = isl_space_from_domain(domain);
+       space = isl_space_from_domain(space);
        space = isl_space_add_dims(space, isl_dim_out,
                                    isl_space_dim(model, isl_dim_out));
        if (isl_space_has_tuple_id(model, isl_dim_out))
                space = isl_space_set_tuple_id(space, isl_dim_out,
                                isl_space_get_tuple_id(model, isl_dim_out));
+       if (!space)
+               goto error;
+       if (model->nested[1]) {
+               isl_space *nested = isl_space_copy(model->nested[1]);
+               int n_nested, n_space;
+               nested = isl_space_align_params(nested, isl_space_copy(space));
+               n_nested = isl_space_dim(nested, isl_dim_param);
+               n_space = isl_space_dim(space, isl_dim_param);
+               if (n_nested > n_space)
+                       nested = isl_space_drop_dims(nested, isl_dim_param,
+                                               n_space, n_nested - n_space);
+               if (!nested)
+                       goto error;
+               space->nested[1] = nested;
+       }
        isl_space_free(model);
        return space;
+error:
+       isl_space_free(model);
+       isl_space_free(space);
+       return NULL;
 }
index 22871c1..05c8364 100644 (file)
@@ -12,7 +12,7 @@
 #include <limits.h>
 #include <isl_ctx_private.h>
 #include <isl_map_private.h>
-#include <isl/aff.h>
+#include <isl_aff_private.h>
 #include <isl/set.h>
 #include <isl/flow.h>
 #include <isl/constraint.h>
@@ -2980,10 +2980,42 @@ int test_eliminate(isl_ctx *ctx)
        return 0;
 }
 
+int test_align_parameters(isl_ctx *ctx)
+{
+       const char *str;
+       isl_space *space;
+       isl_multi_aff *ma1, *ma2;
+       int equal;
+
+       str = "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
+       ma1 = isl_multi_aff_read_from_str(ctx, str);
+
+       space = isl_space_params_alloc(ctx, 1);
+       space = isl_space_set_dim_name(space, isl_dim_param, 0, "N");
+       ma1 = isl_multi_aff_align_params(ma1, space);
+
+       str = "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
+       ma2 = isl_multi_aff_read_from_str(ctx, str);
+
+       equal = isl_multi_aff_plain_is_equal(ma1, ma2);
+
+       isl_multi_aff_free(ma1);
+       isl_multi_aff_free(ma2);
+
+       if (equal < 0)
+               return -1;
+       if (!equal)
+               isl_die(ctx, isl_error_unknown,
+                       "result not as expected", return -1);
+
+       return 0;
+}
+
 struct {
        const char *name;
        int (*fn)(isl_ctx *ctx);
 } tests [] = {
+       { "align parameters", &test_align_parameters },
        { "eliminate", &test_eliminate },
        { "div", &test_div },
        { "slice", &test_slice },