Coverage Report

Created: 2017-08-18 19:41

/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
481k
{
31
481k
  int i;
32
481k
  struct isl_dim_map *dim_map;
33
481k
  dim_map = isl_alloc(ctx, struct isl_dim_map,
34
481k
      sizeof(struct isl_dim_map) + len * sizeof(struct isl_dim_map_entry));
35
481k
  if (!dim_map)
36
0
    return NULL;
37
481k
  dim_map->len = 1 + len;
38
481k
  dim_map->m[0].pos = 0;
39
481k
  dim_map->m[0].sgn = 1;
40
3.57M
  for (i = 0; 
i < len3.57M
;
++i3.09M
)
41
3.09M
    dim_map->m[1 + i].sgn = 0;
42
481k
  return dim_map;
43
481k
}
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.45k
{
49
5.45k
  int i;
50
5.45k
51
5.45k
  if (!dim_map)
52
0
    return;
53
5.45k
54
12.5k
  
for (i = 0; 5.45k
i < n12.5k
;
++i7.11k
)
{7.11k
55
7.11k
    unsigned d = 1 + dst_pos + dst_stride * i;
56
7.11k
    unsigned s = 1 + src_pos + src_stride * i;
57
7.11k
    dim_map->m[d].pos = s;
58
7.11k
    dim_map->m[d].sgn = sign;
59
7.11k
  }
60
5.45k
}
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.05M
{
66
1.05M
  int i;
67
1.05M
  unsigned src_pos;
68
1.05M
69
1.05M
  if (
!dim_map || 1.05M
!dim1.05M
)
70
0
    return;
71
1.05M
  
72
1.05M
  src_pos = 1 + isl_space_offset(dim, type);
73
2.61M
  for (i = 0; 
i < n2.61M
;
++i1.55M
)
{1.55M
74
1.55M
    dim_map->m[1 + dst_pos + i].pos = src_pos + first + i;
75
1.55M
    dim_map->m[1 + dst_pos + i].sgn = 1;
76
1.55M
  }
77
1.05M
}
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
894k
{
82
894k
  isl_dim_map_dim_range(dim_map, dim, type,
83
894k
            0, isl_space_dim(dim, type), dst_pos);
84
894k
}
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
321k
{
89
321k
  int i;
90
321k
  unsigned src_pos;
91
321k
92
321k
  if (
!dim_map || 321k
!bmap321k
)
93
0
    return;
94
321k
  
95
321k
  src_pos = 1 + isl_space_dim(bmap->dim, isl_dim_all);
96
334k
  for (i = 0; 
i < bmap->n_div334k
;
++i12.8k
)
{12.8k
97
12.8k
    dim_map->m[1 + dst_pos + i].pos = src_pos + i;
98
12.8k
    dim_map->m[1 + dst_pos + i].sgn = 1;
99
321k
  }
100
321k
}
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.16M
{
115
1.16M
  int i;
116
1.16M
117
15.1M
  for (i = 0; 
i < dim_map->len15.1M
;
++i13.9M
)
{13.9M
118
13.9M
    if (dim_map->m[i].sgn == 0)
119
2.50M
      isl_int_set_si(dst[i], 0);
120
11.4M
    else 
if (11.4M
dim_map->m[i].sgn > 011.4M
)
121
11.4M
      isl_int_set(dst[i], src[dim_map->m[i].pos]);
122
11.4M
    else
123
10.9k
      isl_int_neg(dst[i], src[dim_map->m[i].pos]);
124
13.9M
  }
125
1.16M
}
126
127
static void copy_div_dim_map(isl_int *dst, isl_int *src,
128
          struct isl_dim_map *dim_map)
129
13.5k
{
130
13.5k
  isl_int_set(dst[0], src[0]);
131
13.5k
  copy_constraint_dim_map(dst+1, src+1, dim_map);
132
13.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
401k
{
138
401k
  int i;
139
401k
140
401k
  if (
!src || 401k
!dst401k
||
!dim_map401k
)
141
0
    goto error;
142
401k
143
925k
  
for (i = 0; 401k
i < src->n_eq925k
;
++i523k
)
{523k
144
523k
    int i1 = isl_basic_map_alloc_equality(dst);
145
523k
    if (i1 < 0)
146
0
      goto error;
147
523k
    copy_constraint_dim_map(dst->eq[i1], src->eq[i], dim_map);
148
523k
  }
149
401k
150
1.03M
  
for (i = 0; 401k
i < src->n_ineq1.03M
;
++i631k
)
{631k
151
631k
    int i1 = isl_basic_map_alloc_inequality(dst);
152
631k
    if (i1 < 0)
153
0
      goto error;
154
631k
    copy_constraint_dim_map(dst->ineq[i1], src->ineq[i], dim_map);
155
631k
  }
156
401k
157
415k
  
for (i = 0; 401k
i < src->n_div415k
;
++i13.5k
)
{13.5k
158
13.5k
    int i1 = isl_basic_map_alloc_div(dst);
159
13.5k
    if (i1 < 0)
160
0
      goto error;
161
13.5k
    copy_div_dim_map(dst->div[i1], src->div[i], dim_map);
162
401k
  }
163
401k
164
401k
  free(dim_map);
165
401k
  isl_basic_map_free(src);
166
401k
167
401k
  return dst;
168
401k
error:
169
0
  free(dim_map);
170
0
  isl_basic_map_free(src);
171
0
  isl_basic_map_free(dst);
172
401k
  return NULL;
173
401k
}
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.02k
{
179
1.02k
  return isl_basic_map_add_constraints_dim_map(dst, src, dim_map);
180
1.02k
}
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
80.5k
{
187
80.5k
  int i;
188
80.5k
  struct isl_dim_map *res;
189
80.5k
  int offset;
190
80.5k
191
80.5k
  if (!dim_map)
192
0
    return NULL;
193
80.5k
194
80.5k
  offset = isl_basic_map_offset(bmap, isl_dim_div);
195
80.5k
196
80.5k
  res = isl_dim_map_alloc(bmap->ctx, dim_map->len - 1 + bmap->n_div);
197
80.5k
  if (!res)
198
0
    return NULL;
199
80.5k
200
698k
  
for (i = 0; 80.5k
i < dim_map->len698k
;
++i618k
)
201
618k
    res->m[i] = dim_map->m[i];
202
81.2k
  for (i = 0; 
i < bmap->n_div81.2k
;
++i711
)
{711
203
711
    res->m[dim_map->len + i].pos = offset + i;
204
711
    res->m[dim_map->len + i].sgn = 1;
205
80.5k
  }
206
80.5k
207
80.5k
  return res;
208
80.5k
}
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
77.6k
{
217
77.6k
  int i;
218
77.6k
  isl_ctx *ctx;
219
77.6k
  struct isl_dim_map *dim_map;
220
77.6k
221
77.6k
  if (!exp)
222
0
    return NULL;
223
77.6k
224
77.6k
  ctx = isl_space_get_ctx(exp->dim);
225
77.6k
  dim_map = isl_dim_map_alloc(ctx, isl_space_dim(exp->dim, isl_dim_all));
226
77.6k
  if (!dim_map)
227
0
    return NULL;
228
77.6k
229
367k
  
for (i = 0; 77.6k
i < exp->len367k
;
++i289k
)
{289k
230
289k
    dim_map->m[1 + exp->pos[i]].pos = 1 + i;
231
289k
    dim_map->m[1 + exp->pos[i]].sgn = 1;
232
289k
  }
233
77.6k
234
77.6k
  return dim_map;
235
77.6k
}