Coverage Report

Created: 2017-06-28 17:40

/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
462k
{
31
462k
  int i;
32
462k
  struct isl_dim_map *dim_map;
33
462k
  dim_map = isl_alloc(ctx, struct isl_dim_map,
34
462k
      sizeof(struct isl_dim_map) + len * sizeof(struct isl_dim_map_entry));
35
462k
  if (!dim_map)
36
0
    return NULL;
37
462k
  dim_map->len = 1 + len;
38
462k
  dim_map->m[0].pos = 0;
39
462k
  dim_map->m[0].sgn = 1;
40
3.28M
  for (i = 0; 
i < len3.28M
;
++i2.81M
)
41
2.81M
    dim_map->m[1 + i].sgn = 0;
42
462k
  return dim_map;
43
462k
}
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.31k
{
50
5.31k
  int i;
51
5.31k
52
5.31k
  if (!dim_map)
53
0
    return;
54
5.31k
55
12.1k
  
for (i = 0; 5.31k
i < n12.1k
;
++i6.86k
)
{6.86k
56
6.86k
    unsigned d = 1 + dst_pos + dst_stride * i;
57
6.86k
    unsigned s = 1 + src_pos + src_stride * i;
58
6.86k
    dim_map->m[d].pos = s;
59
6.86k
    dim_map->m[d].sgn = sign;
60
6.86k
  }
61
5.31k
}
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
948k
{
67
948k
  int i;
68
948k
  unsigned src_pos;
69
948k
70
948k
  if (
!dim_map || 948k
!dim948k
)
71
0
    return;
72
948k
  
73
948k
  src_pos = 1 + isl_space_offset(dim, type);
74
2.26M
  for (i = 0; 
i < n2.26M
;
++i1.31M
)
{1.31M
75
1.31M
    dim_map->m[1 + dst_pos + i].pos = src_pos + first + i;
76
1.31M
    dim_map->m[1 + dst_pos + i].sgn = 1;
77
1.31M
  }
78
948k
}
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
806k
{
83
806k
  isl_dim_map_dim_range(dim_map, dim, type,
84
806k
            0, isl_space_dim(dim, type), dst_pos);
85
806k
}
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
289k
{
90
289k
  int i;
91
289k
  unsigned src_pos;
92
289k
93
289k
  if (
!dim_map || 289k
!bmap289k
)
94
0
    return;
95
289k
  
96
289k
  src_pos = 1 + isl_space_dim(bmap->dim, isl_dim_all);
97
301k
  for (i = 0; 
i < bmap->n_div301k
;
++i11.6k
)
{11.6k
98
11.6k
    dim_map->m[1 + dst_pos + i].pos = src_pos + i;
99
11.6k
    dim_map->m[1 + dst_pos + i].sgn = 1;
100
11.6k
  }
101
289k
}
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
984k
{
116
984k
  int i;
117
984k
118
10.7M
  for (i = 0; 
i < dim_map->len10.7M
;
++i9.72M
)
{9.72M
119
9.72M
    if (dim_map->m[i].sgn == 0)
120
2.16M
      isl_int_set_si(dst[i], 0);
121
7.55M
    else 
if (7.55M
dim_map->m[i].sgn > 07.55M
)
122
7.54M
      isl_int_set(dst[i], src[dim_map->m[i].pos]);
123
7.55M
    else
124
11.3k
      isl_int_neg(dst[i], src[dim_map->m[i].pos]);
125
9.72M
  }
126
984k
}
127
128
static void copy_div_dim_map(isl_int *dst, isl_int *src,
129
          struct isl_dim_map *dim_map)
130
12.3k
{
131
12.3k
  isl_int_set(dst[0], src[0]);
132
12.3k
  copy_constraint_dim_map(dst+1, src+1, dim_map);
133
12.3k
}
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
376k
{
139
376k
  int i;
140
376k
141
376k
  if (
!src || 376k
!dst376k
||
!dim_map376k
)
142
0
    goto error;
143
376k
144
843k
  
for (i = 0; 376k
i < src->n_eq843k
;
++i466k
)
{466k
145
466k
    int i1 = isl_basic_map_alloc_equality(dst);
146
466k
    if (i1 < 0)
147
0
      goto error;
148
466k
    copy_constraint_dim_map(dst->eq[i1], src->eq[i], dim_map);
149
466k
  }
150
376k
151
882k
  
for (i = 0; 376k
i < src->n_ineq882k
;
++i505k
)
{505k
152
505k
    int i1 = isl_basic_map_alloc_inequality(dst);
153
505k
    if (i1 < 0)
154
0
      goto error;
155
505k
    copy_constraint_dim_map(dst->ineq[i1], src->ineq[i], dim_map);
156
505k
  }
157
376k
158
388k
  
for (i = 0; 376k
i < src->n_div388k
;
++i12.3k
)
{12.3k
159
12.3k
    int i1 = isl_basic_map_alloc_div(dst);
160
12.3k
    if (i1 < 0)
161
0
      goto error;
162
12.3k
    copy_div_dim_map(dst->div[i1], src->div[i], dim_map);
163
12.3k
  }
164
376k
165
376k
  free(dim_map);
166
376k
  isl_basic_map_free(src);
167
376k
168
376k
  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
376k
}
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
995
{
180
995
  return isl_basic_map_add_constraints_dim_map(dst, src, dim_map);
181
995
}
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
86.7k
{
188
86.7k
  int i;
189
86.7k
  struct isl_dim_map *res;
190
86.7k
  int offset;
191
86.7k
192
86.7k
  if (!dim_map)
193
0
    return NULL;
194
86.7k
195
86.7k
  offset = isl_basic_map_offset(bmap, isl_dim_div);
196
86.7k
197
86.7k
  res = isl_dim_map_alloc(bmap->ctx, dim_map->len - 1 + bmap->n_div);
198
86.7k
  if (!res)
199
0
    return NULL;
200
86.7k
201
687k
  
for (i = 0; 86.7k
i < dim_map->len687k
;
++i600k
)
202
600k
    res->m[i] = dim_map->m[i];
203
87.4k
  for (i = 0; 
i < bmap->n_div87.4k
;
++i707
)
{707
204
707
    res->m[dim_map->len + i].pos = offset + i;
205
707
    res->m[dim_map->len + i].sgn = 1;
206
707
  }
207
86.7k
208
86.7k
  return res;
209
86.7k
}
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
84.8k
{
218
84.8k
  int i;
219
84.8k
  isl_ctx *ctx;
220
84.8k
  struct isl_dim_map *dim_map;
221
84.8k
222
84.8k
  if (!exp)
223
0
    return NULL;
224
84.8k
225
84.8k
  ctx = isl_space_get_ctx(exp->dim);
226
84.8k
  dim_map = isl_dim_map_alloc(ctx, isl_space_dim(exp->dim, isl_dim_all));
227
84.8k
  if (!dim_map)
228
0
    return NULL;
229
84.8k
230
458k
  
for (i = 0; 84.8k
i < exp->len458k
;
++i374k
)
{374k
231
374k
    dim_map->m[1 + exp->pos[i]].pos = 1 + i;
232
374k
    dim_map->m[1 + exp->pos[i]].sgn = 1;
233
374k
  }
234
84.8k
235
84.8k
  return dim_map;
236
84.8k
}