Coverage Report

Created: 2019-07-24 05:18

/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
244k
{
18
244k
  isl_reordering *exp;
19
244k
20
244k
  exp = isl_alloc(ctx, struct isl_reordering,
21
244k
      sizeof(struct isl_reordering) + (len - 1) * sizeof(int));
22
244k
  if (!exp)
23
0
    return NULL;
24
244k
25
244k
  exp->ref = 1;
26
244k
  exp->len = len;
27
244k
  exp->space = NULL;
28
244k
29
244k
  return exp;
30
244k
}
31
32
__isl_give isl_reordering *isl_reordering_copy(__isl_keep isl_reordering *exp)
33
188k
{
34
188k
  if (!exp)
35
0
    return NULL;
36
188k
37
188k
  exp->ref++;
38
188k
  return exp;
39
188k
}
40
41
__isl_give isl_reordering *isl_reordering_dup(__isl_keep isl_reordering *r)
42
36.7k
{
43
36.7k
  int i;
44
36.7k
  isl_reordering *dup;
45
36.7k
46
36.7k
  if (!r)
47
0
    return NULL;
48
36.7k
49
36.7k
  dup = isl_reordering_alloc(isl_reordering_get_ctx(r), r->len);
50
36.7k
  if (!dup)
51
0
    return NULL;
52
36.7k
53
36.7k
  dup->space = isl_reordering_get_space(r);
54
36.7k
  if (!dup->space)
55
0
    return isl_reordering_free(dup);
56
124k
  
for (i = 0; 36.7k
i < dup->len;
++i88.1k
)
57
88.1k
    dup->pos[i] = r->pos[i];
58
36.7k
59
36.7k
  return dup;
60
36.7k
}
61
62
__isl_give isl_reordering *isl_reordering_cow(__isl_take isl_reordering *r)
63
124k
{
64
124k
  if (!r)
65
0
    return NULL;
66
124k
67
124k
  if (r->ref == 1)
68
87.9k
    return r;
69
36.7k
  r->ref--;
70
36.7k
  return isl_reordering_dup(r);
71
36.7k
}
72
73
__isl_null isl_reordering *isl_reordering_free(__isl_take isl_reordering *exp)
74
396k
{
75
396k
  if (!exp)
76
136
    return NULL;
77
396k
78
396k
  if (--exp->ref > 0)
79
151k
    return NULL;
80
244k
81
244k
  isl_space_free(exp->space);
82
244k
  free(exp);
83
244k
  return NULL;
84
244k
}
85
86
/* Return the isl_ctx to which "r" belongs.
87
 */
88
isl_ctx *isl_reordering_get_ctx(__isl_keep isl_reordering *r)
89
210k
{
90
210k
  return isl_space_get_ctx(isl_reordering_peek_space(r));
91
210k
}
92
93
/* Return the space of "r".
94
 */
95
__isl_keep isl_space *isl_reordering_peek_space(__isl_keep isl_reordering *r)
96
902k
{
97
902k
  if (!r)
98
0
    return NULL;
99
902k
  return r->space;
100
902k
}
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
372k
{
106
372k
  return isl_space_copy(isl_reordering_peek_space(r));
107
372k
}
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
119k
{
117
119k
  int i, j;
118
119k
  isl_reordering *exp;
119
119k
120
119k
  if (!alignee || !aligner)
121
0
    return NULL;
122
119k
123
119k
  exp = isl_reordering_alloc(alignee->ctx, alignee->nparam);
124
119k
  if (!exp)
125
0
    return NULL;
126
119k
127
119k
  exp->space = isl_space_params(isl_space_copy(aligner));
128
119k
129
264k
  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
690k
    
for (j = 0; 144k
j < aligner->nparam;
++j545k
) {
136
633k
      isl_id *id_j;
137
633k
      id_j = isl_space_get_dim_id(aligner, isl_dim_param, j);
138
633k
      isl_id_free(id_j);
139
633k
      if (id_i == id_j)
140
87.9k
        break;
141
633k
    }
142
144k
    if (j < aligner->nparam) {
143
87.9k
      exp->pos[i] = j;
144
87.9k
      isl_id_free(id_i);
145
87.9k
    } else {
146
56.9k
      int pos;
147
56.9k
      pos = isl_space_dim(exp->space, isl_dim_param);
148
56.9k
      exp->space = isl_space_add_dims(exp->space,
149
56.9k
            isl_dim_param, 1);
150
56.9k
      exp->space = isl_space_set_dim_id(exp->space,
151
56.9k
            isl_dim_param, pos, id_i);
152
56.9k
      exp->pos[i] = pos;
153
56.9k
    }
154
144k
  }
155
119k
156
119k
  if (!exp->space)
157
0
    return isl_reordering_free(exp);
158
119k
  return exp;
159
0
error:
160
0
  isl_reordering_free(exp);
161
0
  return NULL;
162
119k
}
163
164
__isl_give isl_reordering *isl_reordering_extend(__isl_take isl_reordering *exp,
165
  unsigned extra)
166
134k
{
167
134k
  int i;
168
134k
  isl_ctx *ctx;
169
134k
  isl_space *space;
170
134k
  isl_reordering *res;
171
134k
  int offset;
172
134k
173
134k
  if (!exp)
174
0
    return NULL;
175
134k
  if (extra == 0)
176
46.6k
    return exp;
177
88.2k
178
88.2k
  ctx = isl_reordering_get_ctx(exp);
179
88.2k
  space = isl_reordering_peek_space(exp);
180
88.2k
  offset = isl_space_dim(space, isl_dim_all) - exp->len;
181
88.2k
  res = isl_reordering_alloc(ctx, exp->len + extra);
182
88.2k
  if (!res)
183
0
    goto error;
184
88.2k
  res->space = isl_reordering_get_space(exp);
185
264k
  for (i = 0; i < exp->len; 
++i175k
)
186
175k
    res->pos[i] = exp->pos[i];
187
303k
  for (i = exp->len; i < res->len; 
++i215k
)
188
215k
    res->pos[i] = offset + i;
189
88.2k
190
88.2k
  isl_reordering_free(exp);
191
88.2k
192
88.2k
  return res;
193
0
error:
194
0
  isl_reordering_free(exp);
195
0
  return NULL;
196
88.2k
}
197
198
__isl_give isl_reordering *isl_reordering_extend_space(
199
  __isl_take isl_reordering *exp, __isl_take isl_space *space)
200
124k
{
201
124k
  isl_space *exp_space;
202
124k
  isl_reordering *res;
203
124k
204
124k
  if (!exp || !space)
205
0
    goto error;
206
124k
207
124k
  res = isl_reordering_extend(isl_reordering_copy(exp),
208
124k
        isl_space_dim(space, isl_dim_all) - exp->len);
209
124k
  res = isl_reordering_cow(res);
210
124k
  if (!res)
211
0
    goto error;
212
124k
  isl_space_free(res->space);
213
124k
  exp_space = isl_reordering_peek_space(exp);
214
124k
  res->space = isl_space_replace_params(space, exp_space);
215
124k
216
124k
  isl_reordering_free(exp);
217
124k
218
124k
  if (!res->space)
219
0
    return isl_reordering_free(res);
220
124k
221
124k
  return res;
222
0
error:
223
0
  isl_reordering_free(exp);
224
0
  isl_space_free(space);
225
0
  return NULL;
226
124k
}
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
}