Coverage Report

Created: 2017-04-27 19:33

/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
408k
{
31
408k
  int i;
32
408k
  struct isl_dim_map *dim_map;
33
408k
  dim_map = isl_alloc(ctx, struct isl_dim_map,
34
408k
      sizeof(struct isl_dim_map) + len * sizeof(struct isl_dim_map_entry));
35
408k
  if (!dim_map)
36
0
    return NULL;
37
408k
  dim_map->len = 1 + len;
38
408k
  dim_map->m[0].pos = 0;
39
408k
  dim_map->m[0].sgn = 1;
40
2.99M
  for (i = 0; 
i < len2.99M
;
++i2.58M
)
41
2.58M
    dim_map->m[1 + i].sgn = 0;
42
408k
  return dim_map;
43
408k
}
44
45
void isl_dim_map_range(__isl_keep isl_dim_map *dim_map,
46
  unsigned dst_pos, unsigned dst_stride,
47
  unsigned src_pos, unsigned src_stride,
48
  unsigned n, int sign)
49
5.23k
{
50
5.23k
  int i;
51
5.23k
52
5.23k
  if (!dim_map)
53
0
    return;
54
5.23k
55
12.0k
  
for (i = 0; 5.23k
i < n12.0k
;
++i6.80k
)
{6.80k
56
6.80k
    unsigned d = 1 + dst_pos + dst_stride * i;
57
6.80k
    unsigned s = 1 + src_pos + src_stride * i;
58
6.80k
    dim_map->m[d].pos = s;
59
6.80k
    dim_map->m[d].sgn = sign;
60
6.80k
  }
61
5.23k
}
62
63
void isl_dim_map_dim_range(__isl_keep isl_dim_map *dim_map,
64
  __isl_keep isl_space *dim, enum isl_dim_type type,
65
  unsigned first, unsigned n, unsigned dst_pos)
66
817k
{
67
817k
  int i;
68
817k
  unsigned src_pos;
69
817k
70
817k
  if (
!dim_map || 817k
!dim817k
)
71
0
    return;
72
817k
  
73
817k
  src_pos = 1 + isl_space_offset(dim, type);
74
1.99M
  for (i = 0; 
i < n1.99M
;
++i1.18M
)
{1.18M
75
1.18M
    dim_map->m[1 + dst_pos + i].pos = src_pos + first + i;
76
1.18M
    dim_map->m[1 + dst_pos + i].sgn = 1;
77
1.18M
  }
78
817k
}
79
80
void isl_dim_map_dim(__isl_keep isl_dim_map *dim_map, __isl_keep isl_space *dim,
81
  enum isl_dim_type type, unsigned dst_pos)
82
684k
{
83
684k
  isl_dim_map_dim_range(dim_map, dim, type,
84
684k
            0, isl_space_dim(dim, type), dst_pos);
85
684k
}
86
87
void isl_dim_map_div(__isl_keep isl_dim_map *dim_map,
88
  __isl_keep isl_basic_map *bmap, unsigned dst_pos)
89
248k
{
90
248k
  int i;
91
248k
  unsigned src_pos;
92
248k
93
248k
  if (
!dim_map || 248k
!bmap248k
)
94
0
    return;
95
248k
  
96
248k
  src_pos = 1 + isl_space_dim(bmap->dim, isl_dim_all);
97
257k
  for (i = 0; 
i < bmap->n_div257k
;
++i9.08k
)
{9.08k
98
9.08k
    dim_map->m[1 + dst_pos + i].pos = src_pos + i;
99
9.08k
    dim_map->m[1 + dst_pos + i].sgn = 1;
100
9.08k
  }
101
248k
}
102
103
void isl_dim_map_dump(struct isl_dim_map *dim_map)
104
0
{
105
0
  int i;
106
0
107
0
  for (i = 0; 
i < dim_map->len0
;
++i0
)
108
0
    fprintf(stderr, "%d -> %d * %d; ", i,
109
0
      dim_map->m[i].sgn, dim_map->m[i].pos);
110
0
  fprintf(stderr, "\n");
111
0
}
112
113
static void copy_constraint_dim_map(isl_int *dst, isl_int *src,
114
          struct isl_dim_map *dim_map)
115
857k
{
116
857k
  int i;
117
857k
118
9.67M
  for (i = 0; 
i < dim_map->len9.67M
;
++i8.81M
)
{8.81M
119
8.81M
    if (dim_map->m[i].sgn == 0)
120
1.95M
      isl_int_set_si(dst[i], 0);
121
6.86M
    else 
if (6.86M
dim_map->m[i].sgn > 06.86M
)
122
6.84M
      isl_int_set(dst[i], src[dim_map->m[i].pos]);
123
6.86M
    else
124
11.3k
      isl_int_neg(dst[i], src[dim_map->m[i].pos]);
125
8.81M
  }
126
857k
}
127
128
static void copy_div_dim_map(isl_int *dst, isl_int *src,
129
          struct isl_dim_map *dim_map)
130
9.63k
{
131
9.63k
  isl_int_set(dst[0], src[0]);
132
9.63k
  copy_constraint_dim_map(dst+1, src+1, dim_map);
133
9.63k
}
134
135
__isl_give isl_basic_map *isl_basic_map_add_constraints_dim_map(
136
  __isl_take isl_basic_map *dst, __isl_take isl_basic_map *src,
137
  __isl_take isl_dim_map *dim_map)
138
328k
{
139
328k
  int i;
140
328k
141
328k
  if (
!src || 328k
!dst328k
||
!dim_map328k
)
142
0
    goto error;
143
328k
144
730k
  
for (i = 0; 328k
i < src->n_eq730k
;
++i401k
)
{401k
145
401k
    int i1 = isl_basic_map_alloc_equality(dst);
146
401k
    if (i1 < 0)
147
0
      goto error;
148
401k
    copy_constraint_dim_map(dst->eq[i1], src->eq[i], dim_map);
149
401k
  }
150
328k
151
774k
  
for (i = 0; 328k
i < src->n_ineq774k
;
++i445k
)
{445k
152
445k
    int i1 = isl_basic_map_alloc_inequality(dst);
153
445k
    if (i1 < 0)
154
0
      goto error;
155
445k
    copy_constraint_dim_map(dst->ineq[i1], src->ineq[i], dim_map);
156
445k
  }
157
328k
158
338k
  
for (i = 0; 328k
i < src->n_div338k
;
++i9.63k
)
{9.63k
159
9.63k
    int i1 = isl_basic_map_alloc_div(dst);
160
9.63k
    if (i1 < 0)
161
0
      goto error;
162
9.63k
    copy_div_dim_map(dst->div[i1], src->div[i], dim_map);
163
9.63k
  }
164
328k
165
328k
  free(dim_map);
166
328k
  isl_basic_map_free(src);
167
328k
168
328k
  return dst;
169
0
error:
170
0
  free(dim_map);
171
0
  isl_basic_map_free(src);
172
0
  isl_basic_map_free(dst);
173
0
  return NULL;
174
328k
}
175
176
__isl_give isl_basic_set *isl_basic_set_add_constraints_dim_map(
177
  __isl_take isl_basic_set *dst, __isl_take isl_basic_set *src,
178
  __isl_take isl_dim_map *dim_map)
179
982
{
180
982
  return isl_basic_map_add_constraints_dim_map(dst, src, dim_map);
181
982
}
182
183
/* Extend the given dim_map with mappings for the divs in bmap.
184
 */
185
__isl_give isl_dim_map *isl_dim_map_extend(__isl_keep isl_dim_map *dim_map,
186
  __isl_keep isl_basic_map *bmap)
187
80.6k
{
188
80.6k
  int i;
189
80.6k
  struct isl_dim_map *res;
190
80.6k
  int offset;
191
80.6k
192
80.6k
  if (!dim_map)
193
0
    return NULL;
194
80.6k
195
80.6k
  offset = isl_basic_map_offset(bmap, isl_dim_div);
196
80.6k
197
80.6k
  res = isl_dim_map_alloc(bmap->ctx, dim_map->len - 1 + bmap->n_div);
198
80.6k
  if (!res)
199
0
    return NULL;
200
80.6k
201
658k
  
for (i = 0; 80.6k
i < dim_map->len658k
;
++i577k
)
202
577k
    res->m[i] = dim_map->m[i];
203
81.2k
  for (i = 0; 
i < bmap->n_div81.2k
;
++i554
)
{554
204
554
    res->m[dim_map->len + i].pos = offset + i;
205
554
    res->m[dim_map->len + i].sgn = 1;
206
554
  }
207
80.6k
208
80.6k
  return res;
209
80.6k
}
210
211
/* Extract a dim_map from a reordering.
212
 * We essentially need to reverse the mapping, and add an offset
213
 * of 1 for the constant term.
214
 */
215
__isl_give isl_dim_map *isl_dim_map_from_reordering(
216
  __isl_keep isl_reordering *exp)
217
78.6k
{
218
78.6k
  int i;
219
78.6k
  isl_ctx *ctx;
220
78.6k
  struct isl_dim_map *dim_map;
221
78.6k
222
78.6k
  if (!exp)
223
0
    return NULL;
224
78.6k
225
78.6k
  ctx = isl_space_get_ctx(exp->dim);
226
78.6k
  dim_map = isl_dim_map_alloc(ctx, isl_space_dim(exp->dim, isl_dim_all));
227
78.6k
  if (!dim_map)
228
0
    return NULL;
229
78.6k
230
443k
  
for (i = 0; 78.6k
i < exp->len443k
;
++i364k
)
{364k
231
364k
    dim_map->m[1 + exp->pos[i]].pos = 1 + i;
232
364k
    dim_map->m[1 + exp->pos[i]].sgn = 1;
233
364k
  }
234
78.6k
235
78.6k
  return dim_map;
236
78.6k
}