Coverage Report

Created: 2017-03-24 03:18

/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
348k
{
31
348k
  int i;
32
348k
  struct isl_dim_map *dim_map;
33
348k
  dim_map = isl_alloc(ctx, struct isl_dim_map,
34
348k
      sizeof(struct isl_dim_map) + len * sizeof(struct isl_dim_map_entry));
35
348k
  if (!dim_map)
36
0
    return NULL;
37
348k
  dim_map->len = 1 + len;
38
348k
  dim_map->m[0].pos = 0;
39
348k
  dim_map->m[0].sgn = 1;
40
2.50M
  for (i = 0; 
i < len2.50M
;
++i2.15M
)
41
2.15M
    dim_map->m[1 + i].sgn = 0;
42
348k
  return dim_map;
43
348k
}
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
632k
{
67
632k
  int i;
68
632k
  unsigned src_pos;
69
632k
70
632k
  if (
!dim_map || 632k
!dim632k
)
71
0
    return;
72
632k
  
73
632k
  src_pos = 1 + isl_space_offset(dim, type);
74
1.52M
  for (i = 0; 
i < n1.52M
;
++i887k
)
{887k
75
887k
    dim_map->m[1 + dst_pos + i].pos = src_pos + first + i;
76
887k
    dim_map->m[1 + dst_pos + i].sgn = 1;
77
887k
  }
78
632k
}
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
518k
{
83
518k
  isl_dim_map_dim_range(dim_map, dim, type,
84
518k
            0, isl_space_dim(dim, type), dst_pos);
85
518k
}
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
190k
{
90
190k
  int i;
91
190k
  unsigned src_pos;
92
190k
93
190k
  if (
!dim_map || 190k
!bmap190k
)
94
0
    return;
95
190k
  
96
190k
  src_pos = 1 + isl_space_dim(bmap->dim, isl_dim_all);
97
197k
  for (i = 0; 
i < bmap->n_div197k
;
++i7.13k
)
{7.13k
98
7.13k
    dim_map->m[1 + dst_pos + i].pos = src_pos + i;
99
7.13k
    dim_map->m[1 + dst_pos + i].sgn = 1;
100
7.13k
  }
101
190k
}
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
612k
{
116
612k
  int i;
117
612k
118
7.04M
  for (i = 0; 
i < dim_map->len7.04M
;
++i6.43M
)
{6.43M
119
6.43M
    if (dim_map->m[i].sgn == 0)
120
1.33M
      isl_int_set_si(dst[i], 0);
121
5.09M
    else 
if (5.09M
dim_map->m[i].sgn > 05.09M
)
122
5.08M
      isl_int_set(dst[i], src[dim_map->m[i].pos]);
123
5.09M
    else
124
11.3k
      isl_int_neg(dst[i], src[dim_map->m[i].pos]);
125
6.43M
  }
126
612k
}
127
128
static void copy_div_dim_map(isl_int *dst, isl_int *src,
129
          struct isl_dim_map *dim_map)
130
7.66k
{
131
7.66k
  isl_int_set(dst[0], src[0]);
132
7.66k
  copy_constraint_dim_map(dst+1, src+1, dim_map);
133
7.66k
}
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
270k
{
139
270k
  int i;
140
270k
141
270k
  if (
!src || 270k
!dst270k
||
!dim_map270k
)
142
0
    goto error;
143
270k
144
539k
  
for (i = 0; 270k
i < src->n_eq539k
;
++i268k
)
{268k
145
268k
    int i1 = isl_basic_map_alloc_equality(dst);
146
268k
    if (i1 < 0)
147
0
      goto error;
148
268k
    copy_constraint_dim_map(dst->eq[i1], src->eq[i], dim_map);
149
268k
  }
150
270k
151
606k
  
for (i = 0; 270k
i < src->n_ineq606k
;
++i336k
)
{336k
152
336k
    int i1 = isl_basic_map_alloc_inequality(dst);
153
336k
    if (i1 < 0)
154
0
      goto error;
155
336k
    copy_constraint_dim_map(dst->ineq[i1], src->ineq[i], dim_map);
156
336k
  }
157
270k
158
277k
  
for (i = 0; 270k
i < src->n_div277k
;
++i7.66k
)
{7.66k
159
7.66k
    int i1 = isl_basic_map_alloc_div(dst);
160
7.66k
    if (i1 < 0)
161
0
      goto error;
162
7.66k
    copy_div_dim_map(dst->div[i1], src->div[i], dim_map);
163
7.66k
  }
164
270k
165
270k
  free(dim_map);
166
270k
  isl_basic_map_free(src);
167
270k
168
270k
  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
270k
}
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
79.6k
{
188
79.6k
  int i;
189
79.6k
  struct isl_dim_map *res;
190
79.6k
  int offset;
191
79.6k
192
79.6k
  if (!dim_map)
193
0
    return NULL;
194
79.6k
195
79.6k
  offset = isl_basic_map_offset(bmap, isl_dim_div);
196
79.6k
197
79.6k
  res = isl_dim_map_alloc(bmap->ctx, dim_map->len - 1 + bmap->n_div);
198
79.6k
  if (!res)
199
0
    return NULL;
200
79.6k
201
649k
  
for (i = 0; 79.6k
i < dim_map->len649k
;
++i570k
)
202
570k
    res->m[i] = dim_map->m[i];
203
80.1k
  for (i = 0; 
i < bmap->n_div80.1k
;
++i535
)
{535
204
535
    res->m[dim_map->len + i].pos = offset + i;
205
535
    res->m[dim_map->len + i].sgn = 1;
206
535
  }
207
79.6k
208
79.6k
  return res;
209
79.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
77.7k
{
218
77.7k
  int i;
219
77.7k
  isl_ctx *ctx;
220
77.7k
  struct isl_dim_map *dim_map;
221
77.7k
222
77.7k
  if (!exp)
223
0
    return NULL;
224
77.7k
225
77.7k
  ctx = isl_space_get_ctx(exp->dim);
226
77.7k
  dim_map = isl_dim_map_alloc(ctx, isl_space_dim(exp->dim, isl_dim_all));
227
77.7k
  if (!dim_map)
228
0
    return NULL;
229
77.7k
230
438k
  
for (i = 0; 77.7k
i < exp->len438k
;
++i360k
)
{360k
231
360k
    dim_map->m[1 + exp->pos[i]].pos = 1 + i;
232
360k
    dim_map->m[1 + exp->pos[i]].sgn = 1;
233
360k
  }
234
77.7k
235
77.7k
  return dim_map;
236
77.7k
}