Coverage Report

Created: 2018-04-23 18:20

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