* Copyright 2010 INRIA Saclay
* Copyright 2012 Universiteit Leiden
*
- * Use of this software is governed by the GNU LGPLv2.1 license
+ * Use of this software is governed by the MIT license
*
* Written by Sven Verdoolaege, Leiden Institute of Advanced Computer Science,
* Universiteit Leiden, Niels Bohrweg 1, 2333 CA Leiden, The Netherlands
#include <isl/set.h>
#include <isl/map.h>
#include <isl/flow.h>
-#include <isl_qsort.h>
+#include <isl_sort.h>
enum isl_restriction_type {
isl_restriction_type_empty,
isl_set *sink;
};
-/* Create a restriction that doesn't restrict anything.
+/* Create a restriction of the given type.
*/
-__isl_give isl_restriction *isl_restriction_none(__isl_keep isl_map *source_map)
+static __isl_give isl_restriction *isl_restriction_alloc(
+ __isl_take isl_map *source_map, enum isl_restriction_type type)
{
isl_ctx *ctx;
isl_restriction *restr;
ctx = isl_map_get_ctx(source_map);
restr = isl_calloc_type(ctx, struct isl_restriction);
if (!restr)
- return NULL;
+ goto error;
- restr->type = isl_restriction_type_none;
+ restr->type = type;
+ isl_map_free(source_map);
return restr;
+error:
+ isl_map_free(source_map);
+ return NULL;
+}
+
+/* Create a restriction that doesn't restrict anything.
+ */
+__isl_give isl_restriction *isl_restriction_none(__isl_take isl_map *source_map)
+{
+ return isl_restriction_alloc(source_map, isl_restriction_type_none);
}
/* Create a restriction that removes everything.
*/
__isl_give isl_restriction *isl_restriction_empty(
- __isl_keep isl_map *source_map)
+ __isl_take isl_map *source_map)
{
- isl_ctx *ctx;
- isl_restriction *restr;
-
- if (!source_map)
- return NULL;
-
- ctx = isl_map_get_ctx(source_map);
- restr = isl_calloc_type(ctx, struct isl_restriction);
- if (!restr)
- return NULL;
-
- restr->type = isl_restriction_type_empty;
-
- return restr;
+ return isl_restriction_alloc(source_map, isl_restriction_type_empty);
}
/* Create a restriction on the input of the maximization problem
return NULL;
}
+isl_ctx *isl_restriction_get_ctx(__isl_keep isl_restriction *restr)
+{
+ return restr ? isl_set_get_ctx(restr->source) : NULL;
+}
+
/* A private structure to keep track of a mapping together with
* a user-specified identifier and a boolean indicating whether
* the map represents a must or may access/dependence.
/* Free the given isl_access_info structure.
*/
-void isl_access_info_free(__isl_take isl_access_info *acc)
+void *isl_access_info_free(__isl_take isl_access_info *acc)
{
int i;
if (!acc)
- return;
+ return NULL;
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);
+ return NULL;
}
isl_ctx *isl_access_info_get_ctx(__isl_keep isl_access_info *acc)
isl_ctx *ctx;
if (!acc)
- return NULL;
+ goto error;
ctx = isl_map_get_ctx(acc->sink.map);
isl_assert(ctx, acc->n_must + acc->n_may < acc->max_source, goto error);
if (acc->n_must <= 1)
return acc;
- isl_quicksort(acc->source, acc->n_must, sizeof(struct isl_labeled_map),
- access_sort_cmp, acc);
+ if (isl_sort(acc->source, acc->n_must, sizeof(struct isl_labeled_map),
+ access_sort_cmp, acc) < 0)
+ return isl_access_info_free(acc);
return acc;
}