Coverage Report

Created: 2018-02-20 23:11

/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_space_private.h>
13
#include <isl_reordering.h>
14
15
__isl_give isl_reordering *isl_reordering_alloc(isl_ctx *ctx, int len)
16
214k
{
17
214k
  isl_reordering *exp;
18
214k
19
214k
  exp = isl_alloc(ctx, struct isl_reordering,
20
214k
      sizeof(struct isl_reordering) + (len - 1) * sizeof(int));
21
214k
  if (!exp)
22
0
    return NULL;
23
214k
24
214k
  exp->ref = 1;
25
214k
  exp->len = len;
26
214k
  exp->dim = NULL;
27
214k
28
214k
  return exp;
29
214k
}
30
31
__isl_give isl_reordering *isl_reordering_copy(__isl_keep isl_reordering *exp)
32
168k
{
33
168k
  if (!exp)
34
0
    return NULL;
35
168k
36
168k
  exp->ref++;
37
168k
  return exp;
38
168k
}
39
40
__isl_give isl_reordering *isl_reordering_dup(__isl_keep isl_reordering *r)
41
33.1k
{
42
33.1k
  int i;
43
33.1k
  isl_reordering *dup;
44
33.1k
45
33.1k
  if (!r)
46
0
    return NULL;
47
33.1k
48
33.1k
  dup = isl_reordering_alloc(r->dim->ctx, r->len);
49
33.1k
  if (!dup)
50
0
    return NULL;
51
33.1k
52
33.1k
  dup->dim = isl_space_copy(r->dim);
53
33.1k
  if (!dup->dim)
54
0
    return isl_reordering_free(dup);
55
121k
  
for (i = 0; 33.1k
i < dup->len;
++i88.0k
)
56
88.0k
    dup->pos[i] = r->pos[i];
57
33.1k
58
33.1k
  return dup;
59
33.1k
}
60
61
__isl_give isl_reordering *isl_reordering_cow(__isl_take isl_reordering *r)
62
109k
{
63
109k
  if (!r)
64
0
    return NULL;
65
109k
66
109k
  if (r->ref == 1)
67
76.7k
    return r;
68
33.1k
  r->ref--;
69
33.1k
  return isl_reordering_dup(r);
70
33.1k
}
71
72
void *isl_reordering_free(__isl_take isl_reordering *exp)
73
350k
{
74
350k
  if (!exp)
75
374
    return NULL;
76
350k
77
350k
  if (--exp->ref > 0)
78
135k
    return NULL;
79
214k
80
214k
  isl_space_free(exp->dim);
81
214k
  free(exp);
82
214k
  return NULL;
83
214k
}
84
85
/* Construct a reordering that maps the parameters of "alignee"
86
 * to the corresponding parameters in a new dimension specification
87
 * that has the parameters of "aligner" first, followed by
88
 * any remaining parameters of "alignee" that do not occur in "aligner".
89
 */
90
__isl_give isl_reordering *isl_parameter_alignment_reordering(
91
  __isl_keep isl_space *alignee, __isl_keep isl_space *aligner)
92
104k
{
93
104k
  int i, j;
94
104k
  isl_reordering *exp;
95
104k
96
104k
  if (!alignee || 
!aligner104k
)
97
2
    return NULL;
98
104k
99
104k
  exp = isl_reordering_alloc(alignee->ctx, alignee->nparam);
100
104k
  if (!exp)
101
0
    return NULL;
102
104k
103
104k
  exp->dim = isl_space_copy(aligner);
104
104k
105
249k
  for (i = 0; i < alignee->nparam; 
++i144k
) {
106
144k
    isl_id *id_i;
107
144k
    id_i = isl_space_get_dim_id(alignee, isl_dim_param, i);
108
144k
    if (!id_i)
109
144k
      
isl_die0
(alignee->ctx, isl_error_invalid,
110
144k
        "cannot align unnamed parameters", goto error);
111
695k
    
for (j = 0; 144k
j < aligner->nparam;
++j551k
) {
112
639k
      isl_id *id_j;
113
639k
      id_j = isl_space_get_dim_id(aligner, isl_dim_param, j);
114
639k
      isl_id_free(id_j);
115
639k
      if (id_i == id_j)
116
87.7k
        break;
117
639k
    }
118
144k
    if (j < aligner->nparam) {
119
87.7k
      exp->pos[i] = j;
120
87.7k
      isl_id_free(id_i);
121
87.7k
    } else {
122
56.6k
      int pos;
123
56.6k
      pos = isl_space_dim(exp->dim, isl_dim_param);
124
56.6k
      exp->dim = isl_space_add_dims(exp->dim, isl_dim_param, 1);
125
56.6k
      exp->dim = isl_space_set_dim_id(exp->dim,
126
56.6k
            isl_dim_param, pos, id_i);
127
56.6k
      exp->pos[i] = pos;
128
56.6k
    }
129
144k
  }
130
104k
131
104k
  if (!exp->dim)
132
0
    return isl_reordering_free(exp);
133
104k
  return exp;
134
0
error:
135
0
  isl_reordering_free(exp);
136
0
  return NULL;
137
104k
}
138
139
__isl_give isl_reordering *isl_reordering_extend(__isl_take isl_reordering *exp,
140
  unsigned extra)
141
119k
{
142
119k
  int i;
143
119k
  isl_reordering *res;
144
119k
  int offset;
145
119k
146
119k
  if (!exp)
147
0
    return NULL;
148
119k
  if (extra == 0)
149
42.7k
    return exp;
150
77.0k
151
77.0k
  offset = isl_space_dim(exp->dim, isl_dim_all) - exp->len;
152
77.0k
  res = isl_reordering_alloc(exp->dim->ctx, exp->len + extra);
153
77.0k
  if (!res)
154
0
    goto error;
155
77.0k
  res->dim = isl_space_copy(exp->dim);
156
251k
  for (i = 0; i < exp->len; 
++i174k
)
157
174k
    res->pos[i] = exp->pos[i];
158
233k
  for (i = exp->len; i < res->len; 
++i156k
)
159
156k
    res->pos[i] = offset + i;
160
77.0k
161
77.0k
  isl_reordering_free(exp);
162
77.0k
163
77.0k
  return res;
164
0
error:
165
0
  isl_reordering_free(exp);
166
0
  return NULL;
167
77.0k
}
168
169
__isl_give isl_reordering *isl_reordering_extend_space(
170
  __isl_take isl_reordering *exp, __isl_take isl_space *space)
171
109k
{
172
109k
  isl_reordering *res;
173
109k
174
109k
  if (!exp || 
!space109k
)
175
2
    goto error;
176
109k
177
109k
  res = isl_reordering_extend(isl_reordering_copy(exp),
178
109k
        isl_space_dim(space, isl_dim_all) - exp->len);
179
109k
  res = isl_reordering_cow(res);
180
109k
  if (!res)
181
0
    goto error;
182
109k
  isl_space_free(res->dim);
183
109k
  res->dim = isl_space_replace_params(space, exp->dim);
184
109k
185
109k
  isl_reordering_free(exp);
186
109k
187
109k
  if (!res->dim)
188
0
    return isl_reordering_free(res);
189
109k
190
109k
  return res;
191
2
error:
192
2
  isl_reordering_free(exp);
193
2
  isl_space_free(space);
194
2
  return NULL;
195
109k
}
196
197
void isl_reordering_dump(__isl_keep isl_reordering *exp)
198
0
{
199
0
  int i;
200
0
201
0
  isl_space_dump(exp->dim);
202
0
  for (i = 0; i < exp->len; ++i)
203
0
    fprintf(stderr, "%d -> %d; ", i, exp->pos[i]);
204
0
  fprintf(stderr, "\n");
205
0
}