pet.cc: pet_foreach_scop_in_C_source: return isl_stat
[pet.git] / filter.c
blob3830ff2e65ade6430ce4f4ac2609c908370a5152
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;
64 if (isl_space_is_wrapping(space)) {
65 space2 = isl_space_map_from_set(isl_space_copy(space));
66 ma = isl_multi_aff_identity(space2);
67 space = isl_space_unwrap(space);
68 } else {
69 space = isl_space_from_domain(space);
70 ma = isl_multi_aff_domain_map(isl_space_copy(space));
73 space2 = isl_space_domain(isl_space_copy(space));
74 pma_dom = isl_pw_multi_aff_identity(isl_space_map_from_set(space2));
75 space = isl_space_range(space);
76 space = isl_space_insert_dims(space, isl_dim_set, 0, 1);
77 pma_ran = isl_pw_multi_aff_project_out_map(space, isl_dim_set, 0, 1);
78 pma_ran = isl_pw_multi_aff_set_dim_id(pma_ran, isl_dim_in, 0, id);
79 pma_ran = isl_pw_multi_aff_fix_si(pma_ran, isl_dim_in, 0, satisfied);
80 pma = isl_pw_multi_aff_product(pma_dom, pma_ran);
82 pma0 = isl_pw_multi_aff_from_multi_aff(ma);
83 pma = isl_pw_multi_aff_pullback_pw_multi_aff(pma0, pma);
85 return pma;