2 * Copyright 2012 Ecole Normale Superieure
3 * Copyright 2017 Sven Verdoolaege
5 * Use of this software is governed by the MIT license
7 * Written by Sven Verdoolaege,
8 * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
11 #define xFN(TYPE,NAME) TYPE ## _ ## NAME
12 #define FN(TYPE,NAME) xFN(TYPE,NAME)
14 /* Drop the "n" domain dimensions starting at "first" from "obj",
15 * after checking that they do not appear in the affine expression.
17 static __isl_give TYPE
*FN(TYPE
,drop_domain
)(__isl_take TYPE
*obj
,
18 unsigned first
, unsigned n
)
22 involves
= FN(TYPE
,involves_dims
)(obj
, isl_dim_in
, first
, n
);
24 return FN(TYPE
,free
)(obj
);
26 isl_die(FN(TYPE
,get_ctx
)(obj
), isl_error_invalid
,
27 "affine expression involves some of the domain dimensions",
28 return FN(TYPE
,free
)(obj
));
29 return FN(TYPE
,drop_dims
)(obj
, isl_dim_in
, first
, n
);
32 /* Check that the domain of "obj" is a product.
34 static isl_stat
FN(TYPE
,check_domain_product
)(__isl_keep TYPE
*obj
)
38 is_product
= FN(TYPE
,domain_is_product
)(obj
);
40 return isl_stat_error
;
42 isl_die(FN(TYPE
,get_ctx
)(obj
), isl_error_invalid
,
43 "domain is not a product", return isl_stat_error
);
47 /* Given an affine function with a domain of the form [A -> B] that
48 * does not depend on B, return the same function on domain A.
50 __isl_give TYPE
*FN(TYPE
,domain_factor_domain
)(__isl_take TYPE
*obj
)
55 if (FN(TYPE
,check_domain_product
)(obj
) < 0)
56 return FN(TYPE
,free
)(obj
);
57 space
= FN(TYPE
,get_domain_space
)(obj
);
58 n
= isl_space_dim(space
, isl_dim_set
);
59 space
= isl_space_factor_domain(space
);
60 n_in
= isl_space_dim(space
, isl_dim_set
);
61 if (n
< 0 || n_in
< 0)
62 obj
= FN(TYPE
,free
)(obj
);
64 obj
= FN(TYPE
,drop_domain
)(obj
, n_in
, n
- n_in
);
65 obj
= FN(TYPE
,reset_domain_space
)(obj
, space
);