move pet_nested_extract_expr to nest.c
[pet.git] / filter.c
blob395f67a289790b8ee406059aadf54e4a1b217c1a
1 /*
2 * Copyright 2011 Leiden University. All rights reserved.
3 * Copyright 2012-2014 Ecole Normale Superieure. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials provided
15 * with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY LEIDEN UNIVERSITY ''AS IS'' AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LEIDEN UNIVERSITY OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * The views and conclusions contained in the software and documentation
30 * are those of the authors and should not be interpreted as
31 * representing official policies, either expressed or implied, of
32 * Leiden University.
35 #include "filter.h"
37 /* Construct a function that (upon precomposition) inserts
38 * a filter value with name "id" and value "satisfied"
39 * in the list of filter values embedded in the set space "space".
41 * If "space" does not contain any filter values yet, we first create
42 * a function that inserts 0 filter values, i.e.,
44 * [space -> []] -> space
46 * We can now assume that space is of the form [dom -> [filters]]
47 * We construct an identity mapping on dom and a mapping on filters
48 * that (upon precomposition) inserts the new filter
50 * dom -> dom
51 * [satisfied, filters] -> [filters]
53 * and then compute the cross product
55 * [dom -> [satisfied, filters]] -> [dom -> [filters]]
57 __isl_give isl_pw_multi_aff *pet_filter_insert_pma(__isl_take isl_space *space,
58 __isl_take isl_id *id, int satisfied)
60 isl_space *space2;
61 isl_multi_aff *ma;
62 isl_pw_multi_aff *pma0, *pma, *pma_dom, *pma_ran;
63 isl_set *dom;
65 if (isl_space_is_wrapping(space)) {
66 space2 = isl_space_map_from_set(isl_space_copy(space));
67 ma = isl_multi_aff_identity(space2);
68 space = isl_space_unwrap(space);
69 } else {
70 space = isl_space_from_domain(space);
71 ma = isl_multi_aff_domain_map(isl_space_copy(space));
74 space2 = isl_space_domain(isl_space_copy(space));
75 pma_dom = isl_pw_multi_aff_identity(isl_space_map_from_set(space2));
76 space = isl_space_range(space);
77 space = isl_space_insert_dims(space, isl_dim_set, 0, 1);
78 pma_ran = isl_pw_multi_aff_project_out_map(space, isl_dim_set, 0, 1);
79 pma_ran = isl_pw_multi_aff_set_dim_id(pma_ran, isl_dim_in, 0, id);
80 pma_ran = isl_pw_multi_aff_fix_si(pma_ran, isl_dim_in, 0, satisfied);
81 pma = isl_pw_multi_aff_product(pma_dom, pma_ran);
83 pma0 = isl_pw_multi_aff_from_multi_aff(ma);
84 pma = isl_pw_multi_aff_pullback_pw_multi_aff(pma0, pma);
86 return pma;