Coverage Report

Created: 2018-02-20 12:54

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/polly/lib/External/isl/isl_dim_map.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2008-2009 Katholieke Universiteit Leuven
3
 * Copyright 2010-2011 INRIA Saclay
4
 *
5
 * Use of this software is governed by the MIT license
6
 *
7
 * Written by Sven Verdoolaege, K.U.Leuven, Departement
8
 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
9
 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
10
 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France 
11
 */
12
13
#include <isl_map_private.h>
14
#include <isl_space_private.h>
15
#include <isl_dim_map.h>
16
#include <isl_reordering.h>
17
18
struct isl_dim_map_entry {
19
  int pos;
20
  int sgn;
21
};
22
23
/* Maps dst positions to src positions */
24
struct isl_dim_map {
25
  unsigned len;
26
  struct isl_dim_map_entry m[1];
27
};
28
29
__isl_give isl_dim_map *isl_dim_map_alloc(isl_ctx *ctx, unsigned len)
30
591k
{
31
591k
  int i;
32
591k
  struct isl_dim_map *dim_map;
33
591k
  dim_map = isl_alloc(ctx, struct isl_dim_map,
34
591k
      sizeof(struct isl_dim_map) + len * sizeof(struct isl_dim_map_entry));
35
591k
  if (!dim_map)
36
0
    return NULL;
37
591k
  dim_map->len = 1 + len;
38
591k
  dim_map->m[0].pos = 0;
39
591k
  dim_map->m[0].sgn = 1;
40
4.65M
  for (i = 0; i < len; 
++i4.06M
)
41
4.06M
    dim_map->m[1 + i].sgn = 0;
42
591k
  return dim_map;
43
591k
}
44
45
void isl_dim_map_range(__isl_keep isl_dim_map *dim_map,
46
  unsigned dst_pos, int dst_stride, unsigned src_pos, int src_stride,
47
  unsigned n, int sign)
48
5.50k
{
49
5.50k
  int i;
50
5.50k
51
5.50k
  if (!dim_map)
52
0
    return;
53
5.50k
54
12.6k
  
for (i = 0; 5.50k
i < n;
++i7.17k
) {
55
7.17k
    unsigned d = 1 + dst_pos + dst_stride * i;
56
7.17k
    unsigned s = 1 + src_pos + src_stride * i;
57
7.17k
    dim_map->m[d].pos = s;
58
7.17k
    dim_map->m[d].sgn = sign;
59
7.17k
  }
60
5.50k
}
61
62
void isl_dim_map_dim_range(__isl_keep isl_dim_map *dim_map,
63
  __isl_keep isl_space *dim, enum isl_dim_type type,
64
  unsigned first, unsigned n, unsigned dst_pos)
65
1.36M
{
66
1.36M
  int i;
67
1.36M
  unsigned src_pos;
68
1.36M
69
1.36M
  if (!dim_map || !dim)
70
0
    return;
71
1.36M
  
72
1.36M
  src_pos = 1 + isl_space_offset(dim, type);
73
3.61M
  for (i = 0; i < n; 
++i2.24M
) {
74
2.24M
    dim_map->m[1 + dst_pos + i].pos = src_pos + first + i;
75
2.24M
    dim_map->m[1 + dst_pos + i].sgn = 1;
76
2.24M
  }
77
1.36M
}
78
79
void isl_dim_map_dim(__isl_keep isl_dim_map *dim_map, __isl_keep isl_space *dim,
80
  enum isl_dim_type type, unsigned dst_pos)
81
1.18M
{
82
1.18M
  isl_dim_map_dim_range(dim_map, dim, type,
83
1.18M
            0, isl_space_dim(dim, type), dst_pos);
84
1.18M
}
85
86
void isl_dim_map_div(__isl_keep isl_dim_map *dim_map,
87
  __isl_keep isl_basic_map *bmap, unsigned dst_pos)
88
421k
{
89
421k
  int i;
90
421k
  unsigned src_pos;
91
421k
92
421k
  if (!dim_map || !bmap)
93
0
    return;
94
421k
  
95
421k
  src_pos = 1 + isl_space_dim(bmap->dim, isl_dim_all);
96
436k
  for (i = 0; i < bmap->n_div; 
++i14.4k
) {
97
14.4k
    dim_map->m[1 + dst_pos + i].pos = src_pos + i;
98
14.4k
    dim_map->m[1 + dst_pos + i].sgn = 1;
99
14.4k
  }
100
421k
}
101
102
void isl_dim_map_dump(struct isl_dim_map *dim_map)
103
0
{
104
0
  int i;
105
0
106
0
  for (i = 0; i < dim_map->len; ++i)
107
0
    fprintf(stderr, "%d -> %d * %d; ", i,
108
0
      dim_map->m[i].sgn, dim_map->m[i].pos);
109
0
  fprintf(stderr, "\n");
110
0
}
111
112
static void copy_constraint_dim_map(isl_int *dst, isl_int *src,
113
          struct isl_dim_map *dim_map)
114
1.53M
{
115
1.53M
  int i;
116
1.53M
117
19.9M
  for (i = 0; i < dim_map->len; 
++i18.3M
) {
118
18.3M
    if (dim_map->m[i].sgn == 0)
119
18.3M
      
isl_int_set_si3.36M
(dst[i], 0);
120
18.3M
    else 
if (15.0M
dim_map->m[i].sgn > 015.0M
)
121
15.0M
      
isl_int_set15.0M
(dst[i], src[dim_map->m[i].pos]);
122
15.0M
    else
123
15.0M
      
isl_int_neg10.9k
(dst[i], src[dim_map->m[i].pos]);
124
18.3M
  }
125
1.53M
}
126
127
static void copy_div_dim_map(isl_int *dst, isl_int *src,
128
          struct isl_dim_map *dim_map)
129
15.1k
{
130
15.1k
  isl_int_set(dst[0], src[0]);
131
15.1k
  copy_constraint_dim_map(dst+1, src+1, dim_map);
132
15.1k
}
133
134
__isl_give isl_basic_map *isl_basic_map_add_constraints_dim_map(
135
  __isl_take isl_basic_map *dst, __isl_take isl_basic_map *src,
136
  __isl_take isl_dim_map *dim_map)
137
506k
{
138
506k
  int i;
139
506k
140
506k
  if (!src || !dst || !dim_map)
141
0
    goto error;
142
506k
143
1.24M
  
for (i = 0; 506k
i < src->n_eq;
++i734k
) {
144
734k
    int i1 = isl_basic_map_alloc_equality(dst);
145
734k
    if (i1 < 0)
146
0
      goto error;
147
734k
    copy_constraint_dim_map(dst->eq[i1], src->eq[i], dim_map);
148
734k
  }
149
506k
150
1.29M
  
for (i = 0; 506k
i < src->n_ineq;
++i785k
) {
151
785k
    int i1 = isl_basic_map_alloc_inequality(dst);
152
785k
    if (i1 < 0)
153
0
      goto error;
154
785k
    copy_constraint_dim_map(dst->ineq[i1], src->ineq[i], dim_map);
155
785k
  }
156
506k
157
521k
  
for (i = 0; 506k
i < src->n_div;
++i15.1k
) {
158
15.1k
    int i1 = isl_basic_map_alloc_div(dst);
159
15.1k
    if (i1 < 0)
160
0
      goto error;
161
15.1k
    copy_div_dim_map(dst->div[i1], src->div[i], dim_map);
162
15.1k
  }
163
506k
164
506k
  free(dim_map);
165
506k
  isl_basic_map_free(src);
166
506k
167
506k
  return dst;
168
0
error:
169
0
  free(dim_map);
170
0
  isl_basic_map_free(src);
171
0
  isl_basic_map_free(dst);
172
0
  return NULL;
173
506k
}
174
175
__isl_give isl_basic_set *isl_basic_set_add_constraints_dim_map(
176
  __isl_take isl_basic_set *dst, __isl_take isl_basic_set *src,
177
  __isl_take isl_dim_map *dim_map)
178
1.04k
{
179
1.04k
  return isl_basic_map_add_constraints_dim_map(dst, src, dim_map);
180
1.04k
}
181
182
/* Extend the given dim_map with mappings for the divs in bmap.
183
 */
184
__isl_give isl_dim_map *isl_dim_map_extend(__isl_keep isl_dim_map *dim_map,
185
  __isl_keep isl_basic_map *bmap)
186
85.5k
{
187
85.5k
  int i;
188
85.5k
  struct isl_dim_map *res;
189
85.5k
  int offset;
190
85.5k
191
85.5k
  if (!dim_map)
192
0
    return NULL;
193
85.5k
194
85.5k
  offset = isl_basic_map_offset(bmap, isl_dim_div);
195
85.5k
196
85.5k
  res = isl_dim_map_alloc(bmap->ctx, dim_map->len - 1 + bmap->n_div);
197
85.5k
  if (!res)
198
0
    return NULL;
199
85.5k
200
729k
  
for (i = 0; 85.5k
i < dim_map->len;
++i643k
)
201
643k
    res->m[i] = dim_map->m[i];
202
86.2k
  for (i = 0; i < bmap->n_div; 
++i715
) {
203
715
    res->m[dim_map->len + i].pos = offset + i;
204
715
    res->m[dim_map->len + i].sgn = 1;
205
715
  }
206
85.5k
207
85.5k
  return res;
208
85.5k
}
209
210
/* Extract a dim_map from a reordering.
211
 * We essentially need to reverse the mapping, and add an offset
212
 * of 1 for the constant term.
213
 */
214
__isl_give isl_dim_map *isl_dim_map_from_reordering(
215
  __isl_keep isl_reordering *exp)
216
83.7k
{
217
83.7k
  int i;
218
83.7k
  isl_ctx *ctx;
219
83.7k
  struct isl_dim_map *dim_map;
220
83.7k
221
83.7k
  if (!exp)
222
0
    return NULL;
223
83.7k
224
83.7k
  ctx = isl_space_get_ctx(exp->dim);
225
83.7k
  dim_map = isl_dim_map_alloc(ctx, isl_space_dim(exp->dim, isl_dim_all));
226
83.7k
  if (!dim_map)
227
0
    return NULL;
228
83.7k
229
417k
  
for (i = 0; 83.7k
i < exp->len;
++i333k
) {
230
333k
    dim_map->m[1 + exp->pos[i]].pos = 1 + i;
231
333k
    dim_map->m[1 + exp->pos[i]].sgn = 1;
232
333k
  }
233
83.7k
234
83.7k
  return dim_map;
235
83.7k
}