isl_map_transitive_closure: break early if input map doesn't compose with itself
[platform/upstream/isl.git] / isl_pw_templ.c
index f682897..ea556f6 100644 (file)
@@ -178,8 +178,8 @@ __isl_give PW *FN(PW,add)(__isl_take PW *pw1, __isl_take PW *pw2)
                                continue;
                        }
 
-                       sum = FN(EL,ADD)(FN(EL,copy)(pw1->p[i].FIELD),
-                                        FN(EL,copy)(pw2->p[j].FIELD));
+                       sum = ADD(common, FN(EL,copy)(pw1->p[i].FIELD),
+                                         FN(EL,copy)(pw2->p[j].FIELD));
 
                        res = FN(PW,add_piece)(res, common, sum);
                }
@@ -418,3 +418,89 @@ int FN(PW,involves_dims)(__isl_keep PW *pw, enum isl_dim_type type,
        }
        return 0;
 }
+
+__isl_give PW *FN(PW,drop_dims)(__isl_take PW *pw,
+       enum isl_dim_type type, unsigned first, unsigned n)
+{
+       int i;
+
+       if (!pw)
+               return NULL;
+       if (n == 0)
+               return pw;
+
+       pw = FN(PW,cow)(pw);
+       if (!pw)
+               return NULL;
+       pw->dim = isl_dim_drop(pw->dim, type, first, n);
+       if (!pw->dim)
+               goto error;
+       for (i = 0; i < pw->n; ++i) {
+               pw->p[i].set = isl_set_drop(pw->p[i].set, type, first, n);
+               if (!pw->p[i].set)
+                       goto error;
+               pw->p[i].FIELD = FN(EL,drop_dims)(pw->p[i].FIELD, type, first, n);
+               if (!pw->p[i].FIELD)
+                       goto error;
+       }
+
+       return pw;
+error:
+       FN(PW,free)(pw);
+       return NULL;
+}
+
+__isl_give PW *FN(PW,fix_dim)(__isl_take PW *pw,
+       enum isl_dim_type type, unsigned pos, isl_int v)
+{
+       int i;
+
+       if (!pw)
+               return NULL;
+
+       pw = FN(PW,cow)(pw);
+       if (!pw)
+               return NULL;
+       for (i = 0; i < pw->n; ++i) {
+               pw->p[i].set = isl_set_fix(pw->p[i].set, type, pos, v);
+               if (!pw->p[i].set)
+                       goto error;
+       }
+
+       return pw;
+error:
+       FN(PW,free)(pw);
+       return NULL;
+}
+
+unsigned FN(PW,dim)(__isl_keep PW *pw, enum isl_dim_type type)
+{
+       return pw ? isl_dim_size(pw->dim, type) : 0;
+}
+
+__isl_give PW *FN(PW,split_dims)(__isl_take PW *pw,
+       enum isl_dim_type type, unsigned first, unsigned n)
+{
+       int i;
+
+       if (!pw)
+               return NULL;
+       if (n == 0)
+               return pw;
+
+       pw = FN(PW,cow)(pw);
+       if (!pw)
+               return NULL;
+       if (!pw->dim)
+               goto error;
+       for (i = 0; i < pw->n; ++i) {
+               pw->p[i].set = isl_set_split_dims(pw->p[i].set, type, first, n);
+               if (!pw->p[i].set)
+                       goto error;
+       }
+
+       return pw;
+error:
+       FN(PW,free)(pw);
+       return NULL;
+}