Coverage Report

Created: 2018-06-24 14:39

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/polly/lib/External/isl/isl_reordering.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2010      INRIA Saclay
3
 *
4
 * Use of this software is governed by the MIT license
5
 *
6
 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
7
 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
8
 * 91893 Orsay, France
9
 */
10
11
#include <isl_ctx_private.h>
12
#include <isl/id.h>
13
#include <isl_space_private.h>
14
#include <isl_reordering.h>
15
16
__isl_give isl_reordering *isl_reordering_alloc(isl_ctx *ctx, int len)
17
242k
{
18
242k
  isl_reordering *exp;
19
242k
20
242k
  exp = isl_alloc(ctx, struct isl_reordering,
21
242k
      sizeof(struct isl_reordering) + (len - 1) * sizeof(int));
22
242k
  if (!exp)
23
0
    return NULL;
24
242k
25
242k
  exp->ref = 1;
26
242k
  exp->len = len;
27
242k
  exp->space = NULL;
28
242k
29
242k
  return exp;
30
242k
}
31
32
__isl_give isl_reordering *isl_reordering_copy(__isl_keep isl_reordering *exp)
33
186k
{
34
186k
  if (!exp)
35
0
    return NULL;
36
186k
37
186k
  exp->ref++;
38
186k
  return exp;
39
186k
}
40
41
__isl_give isl_reordering *isl_reordering_dup(__isl_keep isl_reordering *r)
42
36.6k
{
43
36.6k
  int i;
44
36.6k
  isl_reordering *dup;
45
36.6k
46
36.6k
  if (!r)
47
0
    return NULL;
48
36.6k
49
36.6k
  dup = isl_reordering_alloc(isl_reordering_get_ctx(r), r->len);
50
36.6k
  if (!dup)
51
0
    return NULL;
52
36.6k
53
36.6k
  dup->space = isl_reordering_get_space(r);
54
36.6k
  if (!dup->space)
55
0
    return isl_reordering_free(dup);
56
124k
  
for (i = 0; 36.6k
i < dup->len;
++i87.9k
)
57
87.9k
    dup->pos[i] = r->pos[i];
58
36.6k
59
36.6k
  return dup;
60
36.6k
}
61
62
__isl_give isl_reordering *isl_reordering_cow(__isl_take isl_reordering *r)
63
123k
{
64
123k
  if (!r)
65
0
    return NULL;
66
123k
67
123k
  if (r->ref == 1)
68
86.7k
    return r;
69
36.6k
  r->ref--;
70
36.6k
  return isl_reordering_dup(r);
71
36.6k
}
72
73
__isl_null isl_reordering *isl_reordering_free(__isl_take isl_reordering *exp)
74
392k
{
75
392k
  if (!exp)
76
136
    return NULL;
77
392k
78
392k
  if (--exp->ref > 0)
79
149k
    return NULL;
80
242k
81
242k
  isl_space_free(exp->space);
82
242k
  free(exp);
83
242k
  return NULL;
84
242k
}
85
86
/* Return the isl_ctx to which "r" belongs.
87
 */
88
isl_ctx *isl_reordering_get_ctx(__isl_keep isl_reordering *r)
89
208k
{
90
208k
  return isl_space_get_ctx(isl_reordering_peek_space(r));
91
208k
}
92
93
/* Return the space of "r".
94
 */
95
__isl_keep isl_space *isl_reordering_peek_space(__isl_keep isl_reordering *r)
96
893k
{
97
893k
  if (!r)
98
0
    return NULL;
99
893k
  return r->space;
100
893k
}
101
102
/* Return a copy of the space of "r".
103
 */
104
__isl_give isl_space *isl_reordering_get_space(__isl_keep isl_reordering *r)
105
369k
{
106
369k
  return isl_space_copy(isl_reordering_peek_space(r));
107
369k
}
108
109
/* Construct a reordering that maps the parameters of "alignee"
110
 * to the corresponding parameters in a new dimension specification
111
 * that has the parameters of "aligner" first, followed by
112
 * any remaining parameters of "alignee" that do not occur in "aligner".
113
 */
114
__isl_give isl_reordering *isl_parameter_alignment_reordering(
115
  __isl_keep isl_space *alignee, __isl_keep isl_space *aligner)
116
118k
{
117
118k
  int i, j;
118
118k
  isl_reordering *exp;
119
118k
120
118k
  if (!alignee || !aligner)
121
0
    return NULL;
122
118k
123
118k
  exp = isl_reordering_alloc(alignee->ctx, alignee->nparam);
124
118k
  if (!exp)
125
0
    return NULL;
126
118k
127
118k
  exp->space = isl_space_params(isl_space_copy(aligner));
128
118k
129
262k
  for (i = 0; i < alignee->nparam; 
++i144k
) {
130
144k
    isl_id *id_i;
131
144k
    id_i = isl_space_get_dim_id(alignee, isl_dim_param, i);
132
144k
    if (!id_i)
133
144k
      
isl_die0
(alignee->ctx, isl_error_invalid,
134
144k
        "cannot align unnamed parameters", goto error);
135
689k
    
for (j = 0; 144k
j < aligner->nparam;
++j544k
) {
136
632k
      isl_id *id_j;
137
632k
      id_j = isl_space_get_dim_id(aligner, isl_dim_param, j);
138
632k
      isl_id_free(id_j);
139
632k
      if (id_i == id_j)
140
87.4k
        break;
141
632k
    }
142
144k
    if (j < aligner->nparam) {
143
87.4k
      exp->pos[i] = j;
144
87.4k
      isl_id_free(id_i);
145
87.4k
    } else {
146
56.7k
      int pos;
147
56.7k
      pos = isl_space_dim(exp->space, isl_dim_param);
148
56.7k
      exp->space = isl_space_add_dims(exp->space,
149
56.7k
            isl_dim_param, 1);
150
56.7k
      exp->space = isl_space_set_dim_id(exp->space,
151
56.7k
            isl_dim_param, pos, id_i);
152
56.7k
      exp->pos[i] = pos;
153
56.7k
    }
154
144k
  }
155
118k
156
118k
  if (!exp->space)
157
0
    return isl_reordering_free(exp);
158
118k
  return exp;
159
0
error:
160
0
  isl_reordering_free(exp);
161
0
  return NULL;
162
118k
}
163
164
__isl_give isl_reordering *isl_reordering_extend(__isl_take isl_reordering *exp,
165
  unsigned extra)
166
133k
{
167
133k
  int i;
168
133k
  isl_ctx *ctx;
169
133k
  isl_space *space;
170
133k
  isl_reordering *res;
171
133k
  int offset;
172
133k
173
133k
  if (!exp)
174
0
    return NULL;
175
133k
  if (extra == 0)
176
46.4k
    return exp;
177
87.0k
178
87.0k
  ctx = isl_reordering_get_ctx(exp);
179
87.0k
  space = isl_reordering_peek_space(exp);
180
87.0k
  offset = isl_space_dim(space, isl_dim_all) - exp->len;
181
87.0k
  res = isl_reordering_alloc(ctx, exp->len + extra);
182
87.0k
  if (!res)
183
0
    goto error;
184
87.0k
  res->space = isl_reordering_get_space(exp);
185
262k
  for (i = 0; i < exp->len; 
++i175k
)
186
175k
    res->pos[i] = exp->pos[i];
187
298k
  for (i = exp->len; i < res->len; 
++i211k
)
188
211k
    res->pos[i] = offset + i;
189
87.0k
190
87.0k
  isl_reordering_free(exp);
191
87.0k
192
87.0k
  return res;
193
0
error:
194
0
  isl_reordering_free(exp);
195
0
  return NULL;
196
87.0k
}
197
198
__isl_give isl_reordering *isl_reordering_extend_space(
199
  __isl_take isl_reordering *exp, __isl_take isl_space *space)
200
123k
{
201
123k
  isl_space *exp_space;
202
123k
  isl_reordering *res;
203
123k
204
123k
  if (!exp || !space)
205
0
    goto error;
206
123k
207
123k
  res = isl_reordering_extend(isl_reordering_copy(exp),
208
123k
        isl_space_dim(space, isl_dim_all) - exp->len);
209
123k
  res = isl_reordering_cow(res);
210
123k
  if (!res)
211
0
    goto error;
212
123k
  isl_space_free(res->space);
213
123k
  exp_space = isl_reordering_peek_space(exp);
214
123k
  res->space = isl_space_replace_params(space, exp_space);
215
123k
216
123k
  isl_reordering_free(exp);
217
123k
218
123k
  if (!res->space)
219
0
    return isl_reordering_free(res);
220
123k
221
123k
  return res;
222
0
error:
223
0
  isl_reordering_free(exp);
224
0
  isl_space_free(space);
225
0
  return NULL;
226
123k
}
227
228
void isl_reordering_dump(__isl_keep isl_reordering *exp)
229
0
{
230
0
  int i;
231
0
232
0
  isl_space_dump(exp->space);
233
0
  for (i = 0; i < exp->len; ++i)
234
0
    fprintf(stderr, "%d -> %d; ", i, exp->pos[i]);
235
0
  fprintf(stderr, "\n");
236
0
}