Coverage Report

Created: 2017-11-23 03:11

/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
583k
{
31
583k
  int i;
32
583k
  struct isl_dim_map *dim_map;
33
583k
  dim_map = isl_alloc(ctx, struct isl_dim_map,
34
583k
      sizeof(struct isl_dim_map) + len * sizeof(struct isl_dim_map_entry));
35
583k
  if (!dim_map)
36
0
    return NULL;
37
583k
  dim_map->len = 1 + len;
38
583k
  dim_map->m[0].pos = 0;
39
583k
  dim_map->m[0].sgn = 1;
40
4.55M
  for (i = 0; i < len; 
++i3.97M
)
41
3.97M
    dim_map->m[1 + i].sgn = 0;
42
583k
  return dim_map;
43
583k
}
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.35M
{
66
1.35M
  int i;
67
1.35M
  unsigned src_pos;
68
1.35M
69
1.35M
  if (!dim_map || !dim)
70
0
    return;
71
1.35M
  
72
1.35M
  src_pos = 1 + isl_space_offset(dim, type);
73
3.57M
  for (i = 0; i < n; 
++i2.22M
) {
74
2.22M
    dim_map->m[1 + dst_pos + i].pos = src_pos + first + i;
75
2.22M
    dim_map->m[1 + dst_pos + i].sgn = 1;
76
2.22M
  }
77
1.35M
}
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.16M
{
82
1.16M
  isl_dim_map_dim_range(dim_map, dim, type,
83
1.16M
            0, isl_space_dim(dim, type), dst_pos);
84
1.16M
}
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
416k
{
89
416k
  int i;
90
416k
  unsigned src_pos;
91
416k
92
416k
  if (!dim_map || !bmap)
93
0
    return;
94
416k
  
95
416k
  src_pos = 1 + isl_space_dim(bmap->dim, isl_dim_all);
96
430k
  for (i = 0; i < bmap->n_div; 
++i14.0k
) {
97
14.0k
    dim_map->m[1 + dst_pos + i].pos = src_pos + i;
98
14.0k
    dim_map->m[1 + dst_pos + i].sgn = 1;
99
14.0k
  }
100
416k
}
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.51M
{
115
1.51M
  int i;
116
1.51M
117
19.7M
  for (i = 0; i < dim_map->len; 
++i18.2M
) {
118
18.2M
    if (dim_map->m[i].sgn == 0)
119
18.2M
      
isl_int_set_si3.32M
(dst[i], 0);
120
18.2M
    else 
if (14.9M
dim_map->m[i].sgn > 014.9M
)
121
14.9M
      
isl_int_set14.9M
(dst[i], src[dim_map->m[i].pos]);
122
14.9M
    else
123
14.9M
      
isl_int_neg10.9k
(dst[i], src[dim_map->m[i].pos]);
124
18.2M
  }
125
1.51M
}
126
127
static void copy_div_dim_map(isl_int *dst, isl_int *src,
128
          struct isl_dim_map *dim_map)
129
14.7k
{
130
14.7k
  isl_int_set(dst[0], src[0]);
131
14.7k
  copy_constraint_dim_map(dst+1, src+1, dim_map);
132
14.7k
}
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
500k
{
138
500k
  int i;
139
500k
140
500k
  if (!src || !dst || !dim_map)
141
0
    goto error;
142
500k
143
1.22M
  
for (i = 0; 500k
i < src->n_eq;
++i724k
) {
144
724k
    int i1 = isl_basic_map_alloc_equality(dst);
145
724k
    if (i1 < 0)
146
0
      goto error;
147
724k
    copy_constraint_dim_map(dst->eq[i1], src->eq[i], dim_map);
148
724k
  }
149
500k
150
1.27M
  
for (i = 0; 500k
i < src->n_ineq;
++i779k
) {
151
779k
    int i1 = isl_basic_map_alloc_inequality(dst);
152
779k
    if (i1 < 0)
153
0
      goto error;
154
779k
    copy_constraint_dim_map(dst->ineq[i1], src->ineq[i], dim_map);
155
779k
  }
156
500k
157
514k
  
for (i = 0; 500k
i < src->n_div;
++i14.7k
) {
158
14.7k
    int i1 = isl_basic_map_alloc_div(dst);
159
14.7k
    if (i1 < 0)
160
0
      goto error;
161
14.7k
    copy_div_dim_map(dst->div[i1], src->div[i], dim_map);
162
14.7k
  }
163
500k
164
500k
  free(dim_map);
165
500k
  isl_basic_map_free(src);
166
500k
167
500k
  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
500k
}
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
84.4k
{
187
84.4k
  int i;
188
84.4k
  struct isl_dim_map *res;
189
84.4k
  int offset;
190
84.4k
191
84.4k
  if (!dim_map)
192
0
    return NULL;
193
84.4k
194
84.4k
  offset = isl_basic_map_offset(bmap, isl_dim_div);
195
84.4k
196
84.4k
  res = isl_dim_map_alloc(bmap->ctx, dim_map->len - 1 + bmap->n_div);
197
84.4k
  if (!res)
198
0
    return NULL;
199
84.4k
200
716k
  
for (i = 0; 84.4k
i < dim_map->len;
++i631k
)
201
631k
    res->m[i] = dim_map->m[i];
202
85.1k
  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
84.4k
207
84.4k
  return res;
208
84.4k
}
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
81.8k
{
217
81.8k
  int i;
218
81.8k
  isl_ctx *ctx;
219
81.8k
  struct isl_dim_map *dim_map;
220
81.8k
221
81.8k
  if (!exp)
222
0
    return NULL;
223
81.8k
224
81.8k
  ctx = isl_space_get_ctx(exp->dim);
225
81.8k
  dim_map = isl_dim_map_alloc(ctx, isl_space_dim(exp->dim, isl_dim_all));
226
81.8k
  if (!dim_map)
227
0
    return NULL;
228
81.8k
229
378k
  
for (i = 0; 81.8k
i < exp->len;
++i296k
) {
230
296k
    dim_map->m[1 + exp->pos[i]].pos = 1 + i;
231
296k
    dim_map->m[1 + exp->pos[i]].sgn = 1;
232
296k
  }
233
81.8k
234
81.8k
  return dim_map;
235
81.8k
}