Coverage Report

Created: 2018-06-19 22:08

/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
618k
{
31
618k
  int i;
32
618k
  struct isl_dim_map *dim_map;
33
618k
  dim_map = isl_alloc(ctx, struct isl_dim_map,
34
618k
      sizeof(struct isl_dim_map) + len * sizeof(struct isl_dim_map_entry));
35
618k
  if (!dim_map)
36
0
    return NULL;
37
618k
  dim_map->len = 1 + len;
38
618k
  dim_map->m[0].pos = 0;
39
618k
  dim_map->m[0].sgn = 1;
40
4.99M
  for (i = 0; i < len; 
++i4.37M
)
41
4.37M
    dim_map->m[1 + i].sgn = 0;
42
618k
  return dim_map;
43
618k
}
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 < n;
++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.44M
{
66
1.44M
  int i;
67
1.44M
  unsigned src_pos;
68
1.44M
69
1.44M
  if (!dim_map || !dim)
70
0
    return;
71
1.44M
  
72
1.44M
  src_pos = 1 + isl_space_offset(dim, type);
73
3.90M
  for (i = 0; i < n; 
++i2.46M
) {
74
2.46M
    dim_map->m[1 + dst_pos + i].pos = src_pos + first + i;
75
2.46M
    dim_map->m[1 + dst_pos + i].sgn = 1;
76
2.46M
  }
77
1.44M
}
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.25M
{
82
1.25M
  isl_dim_map_dim_range(dim_map, dim, type,
83
1.25M
            0, isl_space_dim(dim, type), dst_pos);
84
1.25M
}
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
445k
{
89
445k
  int i;
90
445k
  unsigned src_pos;
91
445k
92
445k
  if (!dim_map || !bmap)
93
0
    return;
94
445k
  
95
445k
  src_pos = 1 + isl_space_dim(bmap->dim, isl_dim_all);
96
470k
  for (i = 0; i < bmap->n_div; 
++i25.0k
) {
97
25.0k
    dim_map->m[1 + dst_pos + i].pos = src_pos + i;
98
25.0k
    dim_map->m[1 + dst_pos + i].sgn = 1;
99
25.0k
  }
100
445k
}
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.71M
{
115
1.71M
  int i;
116
1.71M
117
23.1M
  for (i = 0; i < dim_map->len; 
++i21.3M
) {
118
21.3M
    if (dim_map->m[i].sgn == 0)
119
21.3M
      
isl_int_set_si4.00M
(dst[i], 0);
120
21.3M
    else 
if (17.3M
dim_map->m[i].sgn > 017.3M
)
121
17.3M
      
isl_int_set17.3M
(dst[i], src[dim_map->m[i].pos]);
122
17.3M
    else
123
17.3M
      
isl_int_neg10.9k
(dst[i], src[dim_map->m[i].pos]);
124
21.3M
  }
125
1.71M
}
126
127
static void copy_div_dim_map(isl_int *dst, isl_int *src,
128
          struct isl_dim_map *dim_map)
129
26.1k
{
130
26.1k
  isl_int_set(dst[0], src[0]);
131
26.1k
  copy_constraint_dim_map(dst+1, src+1, dim_map);
132
26.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
531k
{
138
531k
  int i;
139
531k
140
531k
  if (!src || !dst || !dim_map)
141
0
    goto error;
142
531k
143
1.36M
  
for (i = 0; 531k
i < src->n_eq;
++i837k
) {
144
837k
    int i1 = isl_basic_map_alloc_equality(dst);
145
837k
    if (i1 < 0)
146
0
      goto error;
147
837k
    copy_constraint_dim_map(dst->eq[i1], src->eq[i], dim_map);
148
837k
  }
149
531k
150
1.38M
  
for (i = 0; 531k
i < src->n_ineq;
++i853k
) {
151
853k
    int i1 = isl_basic_map_alloc_inequality(dst);
152
853k
    if (i1 < 0)
153
0
      goto error;
154
853k
    copy_constraint_dim_map(dst->ineq[i1], src->ineq[i], dim_map);
155
853k
  }
156
531k
157
558k
  
for (i = 0; 531k
i < src->n_div;
++i26.1k
) {
158
26.1k
    int i1 = isl_basic_map_alloc_div(dst);
159
26.1k
    if (i1 < 0)
160
0
      goto error;
161
26.1k
    copy_div_dim_map(dst->div[i1], src->div[i], dim_map);
162
26.1k
  }
163
531k
164
531k
  free(dim_map);
165
531k
  isl_basic_map_free(src);
166
531k
167
531k
  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
531k
}
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
87.1k
{
187
87.1k
  int i;
188
87.1k
  struct isl_dim_map *res;
189
87.1k
  int offset;
190
87.1k
191
87.1k
  if (!dim_map)
192
0
    return NULL;
193
87.1k
194
87.1k
  offset = isl_basic_map_offset(bmap, isl_dim_div);
195
87.1k
196
87.1k
  res = isl_dim_map_alloc(bmap->ctx, dim_map->len - 1 + bmap->n_div);
197
87.1k
  if (!res)
198
0
    return NULL;
199
87.1k
200
734k
  
for (i = 0; 87.1k
i < dim_map->len;
++i647k
)
201
647k
    res->m[i] = dim_map->m[i];
202
88.3k
  for (i = 0; i < bmap->n_div; 
++i1.18k
) {
203
1.18k
    res->m[dim_map->len + i].pos = offset + i;
204
1.18k
    res->m[dim_map->len + i].sgn = 1;
205
1.18k
  }
206
87.1k
207
87.1k
  return res;
208
87.1k
}
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
85.2k
{
217
85.2k
  int i;
218
85.2k
  isl_ctx *ctx;
219
85.2k
  isl_space *space;
220
85.2k
  struct isl_dim_map *dim_map;
221
85.2k
222
85.2k
  if (!exp)
223
0
    return NULL;
224
85.2k
225
85.2k
  ctx = isl_reordering_get_ctx(exp);
226
85.2k
  space = isl_reordering_peek_space(exp);
227
85.2k
  dim_map = isl_dim_map_alloc(ctx, isl_space_dim(space, isl_dim_all));
228
85.2k
  if (!dim_map)
229
0
    return NULL;
230
85.2k
231
420k
  
for (i = 0; 85.2k
i < exp->len;
++i335k
) {
232
335k
    dim_map->m[1 + exp->pos[i]].pos = 1 + i;
233
335k
    dim_map->m[1 + exp->pos[i]].sgn = 1;
234
335k
  }
235
85.2k
236
85.2k
  return dim_map;
237
85.2k
}