Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/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
585k
{
31
585k
  int i;
32
585k
  struct isl_dim_map *dim_map;
33
585k
  dim_map = isl_alloc(ctx, struct isl_dim_map,
34
585k
      sizeof(struct isl_dim_map) + len * sizeof(struct isl_dim_map_entry));
35
585k
  if (!dim_map)
36
0
    return NULL;
37
585k
  dim_map->len = 1 + len;
38
585k
  dim_map->m[0].pos = 0;
39
585k
  dim_map->m[0].sgn = 1;
40
4.60M
  for (i = 0; 
i < len4.60M
;
++i4.02M
)
41
4.02M
    dim_map->m[1 + i].sgn = 0;
42
585k
  return dim_map;
43
585k
}
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.48k
{
49
5.48k
  int i;
50
5.48k
51
5.48k
  if (!dim_map)
52
0
    return;
53
5.48k
54
12.6k
  
for (i = 0; 5.48k
i < n12.6k
;
++i7.14k
) {
55
7.14k
    unsigned d = 1 + dst_pos + dst_stride * i;
56
7.14k
    unsigned s = 1 + src_pos + src_stride * i;
57
7.14k
    dim_map->m[d].pos = s;
58
7.14k
    dim_map->m[d].sgn = sign;
59
7.14k
  }
60
5.48k
}
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 || 1.36M
!dim1.36M
)
70
0
    return;
71
1.36M
  
72
1.36M
  src_pos = 1 + isl_space_offset(dim, type);
73
3.63M
  for (i = 0; 
i < n3.63M
;
++i2.27M
) {
74
2.27M
    dim_map->m[1 + dst_pos + i].pos = src_pos + first + i;
75
2.27M
    dim_map->m[1 + dst_pos + i].sgn = 1;
76
2.27M
  }
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.17M
{
82
1.17M
  isl_dim_map_dim_range(dim_map, dim, type,
83
1.17M
            0, isl_space_dim(dim, type), dst_pos);
84
1.17M
}
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
419k
{
89
419k
  int i;
90
419k
  unsigned src_pos;
91
419k
92
419k
  if (
!dim_map || 419k
!bmap419k
)
93
0
    return;
94
419k
  
95
419k
  src_pos = 1 + isl_space_dim(bmap->dim, isl_dim_all);
96
433k
  for (i = 0; 
i < bmap->n_div433k
;
++i13.8k
) {
97
13.8k
    dim_map->m[1 + dst_pos + i].pos = src_pos + i;
98
13.8k
    dim_map->m[1 + dst_pos + i].sgn = 1;
99
13.8k
  }
100
419k
}
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->len0
;
++i0
)
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.58M
{
115
1.58M
  int i;
116
1.58M
117
20.3M
  for (i = 0; 
i < dim_map->len20.3M
;
++i18.7M
) {
118
18.7M
    if (dim_map->m[i].sgn == 0)
119
3.34M
      isl_int_set_si(dst[i], 0);
120
15.4M
    else 
if (15.4M
dim_map->m[i].sgn > 015.4M
)
121
15.4M
      isl_int_set(dst[i], src[dim_map->m[i].pos]);
122
15.4M
    else
123
10.9k
      isl_int_neg(dst[i], src[dim_map->m[i].pos]);
124
18.7M
  }
125
1.58M
}
126
127
static void copy_div_dim_map(isl_int *dst, isl_int *src,
128
          struct isl_dim_map *dim_map)
129
14.5k
{
130
14.5k
  isl_int_set(dst[0], src[0]);
131
14.5k
  copy_constraint_dim_map(dst+1, src+1, dim_map);
132
14.5k
}
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
503k
{
138
503k
  int i;
139
503k
140
503k
  if (
!src || 503k
!dst503k
||
!dim_map503k
)
141
0
    goto error;
142
503k
143
1.27M
  
for (i = 0; 503k
i < src->n_eq1.27M
;
++i767k
) {
144
767k
    int i1 = isl_basic_map_alloc_equality(dst);
145
767k
    if (i1 < 0)
146
0
      goto error;
147
767k
    copy_constraint_dim_map(dst->eq[i1], src->eq[i], dim_map);
148
767k
  }
149
503k
150
1.30M
  
for (i = 0; 503k
i < src->n_ineq1.30M
;
++i800k
) {
151
800k
    int i1 = isl_basic_map_alloc_inequality(dst);
152
800k
    if (i1 < 0)
153
0
      goto error;
154
800k
    copy_constraint_dim_map(dst->ineq[i1], src->ineq[i], dim_map);
155
800k
  }
156
503k
157
517k
  
for (i = 0; 503k
i < src->n_div517k
;
++i14.5k
) {
158
14.5k
    int i1 = isl_basic_map_alloc_div(dst);
159
14.5k
    if (i1 < 0)
160
0
      goto error;
161
14.5k
    copy_div_dim_map(dst->div[i1], src->div[i], dim_map);
162
14.5k
  }
163
503k
164
503k
  free(dim_map);
165
503k
  isl_basic_map_free(src);
166
503k
167
503k
  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
503k
}
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.03k
{
179
1.03k
  return isl_basic_map_add_constraints_dim_map(dst, src, dim_map);
180
1.03k
}
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
83.7k
{
187
83.7k
  int i;
188
83.7k
  struct isl_dim_map *res;
189
83.7k
  int offset;
190
83.7k
191
83.7k
  if (!dim_map)
192
0
    return NULL;
193
83.7k
194
83.7k
  offset = isl_basic_map_offset(bmap, isl_dim_div);
195
83.7k
196
83.7k
  res = isl_dim_map_alloc(bmap->ctx, dim_map->len - 1 + bmap->n_div);
197
83.7k
  if (!res)
198
0
    return NULL;
199
83.7k
200
714k
  
for (i = 0; 83.7k
i < dim_map->len714k
;
++i630k
)
201
630k
    res->m[i] = dim_map->m[i];
202
84.4k
  for (i = 0; 
i < bmap->n_div84.4k
;
++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
83.7k
207
83.7k
  return res;
208
83.7k
}
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
80.6k
{
217
80.6k
  int i;
218
80.6k
  isl_ctx *ctx;
219
80.6k
  struct isl_dim_map *dim_map;
220
80.6k
221
80.6k
  if (!exp)
222
0
    return NULL;
223
80.6k
224
80.6k
  ctx = isl_space_get_ctx(exp->dim);
225
80.6k
  dim_map = isl_dim_map_alloc(ctx, isl_space_dim(exp->dim, isl_dim_all));
226
80.6k
  if (!dim_map)
227
0
    return NULL;
228
80.6k
229
376k
  
for (i = 0; 80.6k
i < exp->len376k
;
++i295k
) {
230
295k
    dim_map->m[1 + exp->pos[i]].pos = 1 + i;
231
295k
    dim_map->m[1 + exp->pos[i]].sgn = 1;
232
295k
  }
233
80.6k
234
80.6k
  return dim_map;
235
80.6k
}