Coverage Report

Created: 2017-11-21 16:49

/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
66.3k
{
17
66.3k
  isl_reordering *exp;
18
66.3k
19
66.3k
  exp = isl_alloc(ctx, struct isl_reordering,
20
66.3k
      sizeof(struct isl_reordering) + (len - 1) * sizeof(int));
21
66.3k
  if (!exp)
22
0
    return NULL;
23
66.3k
24
66.3k
  exp->ref = 1;
25
66.3k
  exp->len = len;
26
66.3k
  exp->dim = NULL;
27
66.3k
28
66.3k
  return exp;
29
66.3k
}
30
31
__isl_give isl_reordering *isl_reordering_copy(__isl_keep isl_reordering *exp)
32
47.2k
{
33
47.2k
  if (!exp)
34
0
    return NULL;
35
47.2k
36
47.2k
  exp->ref++;
37
47.2k
  return exp;
38
47.2k
}
39
40
__isl_give isl_reordering *isl_reordering_dup(__isl_keep isl_reordering *r)
41
6.33k
{
42
6.33k
  int i;
43
6.33k
  isl_reordering *dup;
44
6.33k
45
6.33k
  if (!r)
46
0
    return NULL;
47
6.33k
48
6.33k
  dup = isl_reordering_alloc(r->dim->ctx, r->len);
49
6.33k
  if (!dup)
50
0
    return NULL;
51
6.33k
52
6.33k
  dup->dim = isl_space_copy(r->dim);
53
6.33k
  if (!dup->dim)
54
0
    return isl_reordering_free(dup);
55
11.9k
  
for (i = 0; 6.33k
i < dup->len;
++i5.56k
)
56
6.33k
    
dup->pos[i] = r->pos[i]5.56k
;
57
6.33k
58
6.33k
  return dup;
59
6.33k
}
60
61
__isl_give isl_reordering *isl_reordering_cow(__isl_take isl_reordering *r)
62
32.6k
{
63
32.6k
  if (!r)
64
0
    return NULL;
65
32.6k
66
32.6k
  if (r->ref == 1)
67
26.3k
    return r;
68
6.33k
  r->ref--;
69
6.33k
  return isl_reordering_dup(r);
70
6.33k
}
71
72
void *isl_reordering_free(__isl_take isl_reordering *exp)
73
107k
{
74
107k
  if (!exp)
75
76
    return NULL;
76
107k
77
107k
  if (--exp->ref > 0)
78
40.9k
    return NULL;
79
66.3k
80
66.3k
  isl_space_free(exp->dim);
81
66.3k
  free(exp);
82
66.3k
  return NULL;
83
66.3k
}
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
33.6k
{
93
33.6k
  int i, j;
94
33.6k
  isl_reordering *exp;
95
33.6k
96
33.6k
  if (!alignee || !aligner)
97
0
    return NULL;
98
33.6k
99
33.6k
  exp = isl_reordering_alloc(alignee->ctx, alignee->nparam);
100
33.6k
  if (!exp)
101
0
    return NULL;
102
33.6k
103
33.6k
  exp->dim = isl_space_copy(aligner);
104
33.6k
105
107k
  for (i = 0; i < alignee->nparam; 
++i73.8k
) {
106
73.8k
    isl_id *id_i;
107
73.8k
    id_i = isl_space_get_dim_id(alignee, isl_dim_param, i);
108
73.8k
    if (!id_i)
109
73.8k
      
isl_die0
(alignee->ctx, isl_error_invalid,
110
73.8k
        "cannot align unnamed parameters", goto error);
111
522k
    
for (j = 0; 73.8k
j < aligner->nparam;
++j448k
) {
112
489k
      isl_id *id_j;
113
489k
      id_j = isl_space_get_dim_id(aligner, isl_dim_param, j);
114
489k
      isl_id_free(id_j);
115
489k
      if (id_i == id_j)
116
41.1k
        break;
117
489k
    }
118
73.8k
    if (j < aligner->nparam) {
119
41.1k
      exp->pos[i] = j;
120
41.1k
      isl_id_free(id_i);
121
41.1k
    } else {
122
32.6k
      int pos;
123
32.6k
      pos = isl_space_dim(exp->dim, isl_dim_param);
124
32.6k
      exp->dim = isl_space_add_dims(exp->dim, isl_dim_param, 1);
125
32.6k
      exp->dim = isl_space_set_dim_id(exp->dim,
126
32.6k
            isl_dim_param, pos, id_i);
127
32.6k
      exp->pos[i] = pos;
128
32.6k
    }
129
73.8k
  }
130
33.6k
131
33.6k
  if (!exp->dim)
132
0
    return isl_reordering_free(exp);
133
33.6k
  return exp;
134
0
error:
135
0
  isl_reordering_free(exp);
136
0
  return NULL;
137
33.6k
}
138
139
__isl_give isl_reordering *isl_reordering_extend(__isl_take isl_reordering *exp,
140
  unsigned extra)
141
35.4k
{
142
35.4k
  int i;
143
35.4k
  isl_reordering *res;
144
35.4k
  int offset;
145
35.4k
146
35.4k
  if (!exp)
147
0
    return NULL;
148
35.4k
  if (extra == 0)
149
9.05k
    return exp;
150
26.3k
151
26.3k
  offset = isl_space_dim(exp->dim, isl_dim_all) - exp->len;
152
26.3k
  res = isl_reordering_alloc(exp->dim->ctx, exp->len + extra);
153
26.3k
  if (!res)
154
0
    goto error;
155
26.3k
  res->dim = isl_space_copy(exp->dim);
156
112k
  for (i = 0; i < exp->len; 
++i86.2k
)
157
86.2k
    res->pos[i] = exp->pos[i];
158
90.5k
  for (i = exp->len; i < res->len; 
++i64.1k
)
159
64.1k
    res->pos[i] = offset + i;
160
26.3k
161
26.3k
  isl_reordering_free(exp);
162
26.3k
163
26.3k
  return res;
164
0
error:
165
0
  isl_reordering_free(exp);
166
0
  return NULL;
167
35.4k
}
168
169
__isl_give isl_reordering *isl_reordering_extend_space(
170
  __isl_take isl_reordering *exp, __isl_take isl_space *dim)
171
32.6k
{
172
32.6k
  isl_reordering *res;
173
32.6k
174
32.6k
  if (!exp || !dim)
175
0
    goto error;
176
32.6k
177
32.6k
  res = isl_reordering_extend(isl_reordering_copy(exp),
178
32.6k
            isl_space_dim(dim, isl_dim_all) - exp->len);
179
32.6k
  res = isl_reordering_cow(res);
180
32.6k
  if (!res)
181
0
    goto error;
182
32.6k
  isl_space_free(res->dim);
183
32.6k
  res->dim = isl_space_replace(dim, isl_dim_param, exp->dim);
184
32.6k
185
32.6k
  isl_reordering_free(exp);
186
32.6k
187
32.6k
  if (!res->dim)
188
0
    return isl_reordering_free(res);
189
32.6k
190
32.6k
  return res;
191
0
error:
192
0
  isl_reordering_free(exp);
193
0
  isl_space_free(dim);
194
0
  return NULL;
195
32.6k
}
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
}