-
Notifications
You must be signed in to change notification settings - Fork 26
/
isl_domain_factor_templ.c
67 lines (60 loc) · 1.92 KB
/
isl_domain_factor_templ.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* Copyright 2012 Ecole Normale Superieure
* Copyright 2017 Sven Verdoolaege
*
* Use of this software is governed by the MIT license
*
* Written by Sven Verdoolaege,
* Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
*/
#define xFN(TYPE,NAME) TYPE ## _ ## NAME
#define FN(TYPE,NAME) xFN(TYPE,NAME)
/* Drop the "n" domain dimensions starting at "first" from "obj",
* after checking that they do not appear in the affine expression.
*/
static __isl_give TYPE *FN(TYPE,drop_domain)(__isl_take TYPE *obj,
unsigned first, unsigned n)
{
isl_bool involves;
involves = FN(TYPE,involves_dims)(obj, isl_dim_in, first, n);
if (involves < 0)
return FN(TYPE,free)(obj);
if (involves)
isl_die(FN(TYPE,get_ctx)(obj), isl_error_invalid,
"affine expression involves some of the domain dimensions",
return FN(TYPE,free)(obj));
return FN(TYPE,drop_dims)(obj, isl_dim_in, first, n);
}
/* Check that the domain of "obj" is a product.
*/
static isl_stat FN(TYPE,check_domain_product)(__isl_keep TYPE *obj)
{
isl_bool is_product;
is_product = FN(TYPE,domain_is_product)(obj);
if (is_product < 0)
return isl_stat_error;
if (!is_product)
isl_die(FN(TYPE,get_ctx)(obj), isl_error_invalid,
"domain is not a product", return isl_stat_error);
return isl_stat_ok;
}
/* Given an affine function with a domain of the form [A -> B] that
* does not depend on B, return the same function on domain A.
*/
__isl_give TYPE *FN(TYPE,domain_factor_domain)(__isl_take TYPE *obj)
{
isl_space *space;
isl_size n, n_in;
if (FN(TYPE,check_domain_product)(obj) < 0)
return FN(TYPE,free)(obj);
space = FN(TYPE,get_domain_space)(obj);
n = isl_space_dim(space, isl_dim_set);
space = isl_space_factor_domain(space);
n_in = isl_space_dim(space, isl_dim_set);
if (n < 0 || n_in < 0)
obj = FN(TYPE,free)(obj);
else
obj = FN(TYPE,drop_domain)(obj, n_in, n - n_in);
obj = FN(TYPE,reset_domain_space)(obj, space);
return obj;
}