Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/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
207k
{
17
207k
  isl_reordering *exp;
18
207k
19
207k
  exp = isl_alloc(ctx, struct isl_reordering,
20
207k
      sizeof(struct isl_reordering) + (len - 1) * sizeof(int));
21
207k
  if (!exp)
22
0
    return NULL;
23
207k
24
207k
  exp->ref = 1;
25
207k
  exp->len = len;
26
207k
  exp->dim = NULL;
27
207k
28
207k
  return exp;
29
207k
}
30
31
__isl_give isl_reordering *isl_reordering_copy(__isl_keep isl_reordering *exp)
32
161k
{
33
161k
  if (!exp)
34
0
    return NULL;
35
161k
36
161k
  exp->ref++;
37
161k
  return exp;
38
161k
}
39
40
__isl_give isl_reordering *isl_reordering_dup(__isl_keep isl_reordering *r)
41
32.2k
{
42
32.2k
  int i;
43
32.2k
  isl_reordering *dup;
44
32.2k
45
32.2k
  if (!r)
46
0
    return NULL;
47
32.2k
48
32.2k
  dup = isl_reordering_alloc(r->dim->ctx, r->len);
49
32.2k
  if (!dup)
50
0
    return NULL;
51
32.2k
52
32.2k
  dup->dim = isl_space_copy(r->dim);
53
32.2k
  if (!dup->dim)
54
0
    return isl_reordering_free(dup);
55
119k
  
for (i = 0; 32.2k
i < dup->len119k
;
++i87.6k
)
56
87.6k
    dup->pos[i] = r->pos[i];
57
32.2k
58
32.2k
  return dup;
59
32.2k
}
60
61
__isl_give isl_reordering *isl_reordering_cow(__isl_take isl_reordering *r)
62
105k
{
63
105k
  if (!r)
64
0
    return NULL;
65
105k
66
105k
  
if (105k
r->ref == 1105k
)
67
73.5k
    return r;
68
32.2k
  r->ref--;
69
32.2k
  return isl_reordering_dup(r);
70
32.2k
}
71
72
void *isl_reordering_free(__isl_take isl_reordering *exp)
73
337k
{
74
337k
  if (!exp)
75
317
    return NULL;
76
337k
77
337k
  
if (337k
--exp->ref > 0337k
)
78
129k
    return NULL;
79
207k
80
207k
  isl_space_free(exp->dim);
81
207k
  free(exp);
82
207k
  return NULL;
83
207k
}
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
101k
{
93
101k
  int i, j;
94
101k
  isl_reordering *exp;
95
101k
96
101k
  if (
!alignee || 101k
!aligner101k
)
97
1
    return NULL;
98
101k
99
101k
  exp = isl_reordering_alloc(alignee->ctx, alignee->nparam);
100
101k
  if (!exp)
101
0
    return NULL;
102
101k
103
101k
  exp->dim = isl_space_copy(aligner);
104
101k
105
244k
  for (i = 0; 
i < alignee->nparam244k
;
++i143k
) {
106
143k
    isl_id *id_i;
107
143k
    id_i = isl_space_get_dim_id(alignee, isl_dim_param, i);
108
143k
    if (!id_i)
109
0
      isl_die(alignee->ctx, isl_error_invalid,
110
143k
        "cannot align unnamed parameters", goto error);
111
694k
    
for (j = 0; 143k
j < aligner->nparam694k
;
++j551k
) {
112
638k
      isl_id *id_j;
113
638k
      id_j = isl_space_get_dim_id(aligner, isl_dim_param, j);
114
638k
      isl_id_free(id_j);
115
638k
      if (id_i == id_j)
116
86.9k
        break;
117
638k
    }
118
143k
    if (
j < aligner->nparam143k
) {
119
86.9k
      exp->pos[i] = j;
120
86.9k
      isl_id_free(id_i);
121
143k
    } else {
122
56.0k
      int pos;
123
56.0k
      pos = isl_space_dim(exp->dim, isl_dim_param);
124
56.0k
      exp->dim = isl_space_add_dims(exp->dim, isl_dim_param, 1);
125
56.0k
      exp->dim = isl_space_set_dim_id(exp->dim,
126
56.0k
            isl_dim_param, pos, id_i);
127
56.0k
      exp->pos[i] = pos;
128
56.0k
    }
129
143k
  }
130
101k
131
101k
  
if (101k
!exp->dim101k
)
132
0
    return isl_reordering_free(exp);
133
101k
  return exp;
134
0
error:
135
0
  isl_reordering_free(exp);
136
0
  return NULL;
137
101k
}
138
139
__isl_give isl_reordering *isl_reordering_extend(__isl_take isl_reordering *exp,
140
  unsigned extra)
141
115k
{
142
115k
  int i;
143
115k
  isl_reordering *res;
144
115k
  int offset;
145
115k
146
115k
  if (!exp)
147
0
    return NULL;
148
115k
  
if (115k
extra == 0115k
)
149
41.5k
    return exp;
150
73.8k
151
73.8k
  offset = isl_space_dim(exp->dim, isl_dim_all) - exp->len;
152
73.8k
  res = isl_reordering_alloc(exp->dim->ctx, exp->len + extra);
153
73.8k
  if (!res)
154
0
    goto error;
155
73.8k
  res->dim = isl_space_copy(exp->dim);
156
213k
  for (i = 0; 
i < exp->len213k
;
++i140k
)
157
140k
    res->pos[i] = exp->pos[i];
158
224k
  for (i = exp->len; 
i < res->len224k
;
++i151k
)
159
151k
    res->pos[i] = offset + i;
160
73.8k
161
73.8k
  isl_reordering_free(exp);
162
73.8k
163
73.8k
  return res;
164
0
error:
165
0
  isl_reordering_free(exp);
166
0
  return NULL;
167
115k
}
168
169
__isl_give isl_reordering *isl_reordering_extend_space(
170
  __isl_take isl_reordering *exp, __isl_take isl_space *dim)
171
105k
{
172
105k
  isl_reordering *res;
173
105k
174
105k
  if (
!exp || 105k
!dim105k
)
175
1
    goto error;
176
105k
177
105k
  res = isl_reordering_extend(isl_reordering_copy(exp),
178
105k
            isl_space_dim(dim, isl_dim_all) - exp->len);
179
105k
  res = isl_reordering_cow(res);
180
105k
  if (!res)
181
0
    goto error;
182
105k
  isl_space_free(res->dim);
183
105k
  res->dim = isl_space_replace(dim, isl_dim_param, exp->dim);
184
105k
185
105k
  isl_reordering_free(exp);
186
105k
187
105k
  if (!res->dim)
188
0
    return isl_reordering_free(res);
189
105k
190
105k
  return res;
191
1
error:
192
1
  isl_reordering_free(exp);
193
1
  isl_space_free(dim);
194
1
  return NULL;
195
105k
}
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->len0
;
++i0
)
203
0
    fprintf(stderr, "%d -> %d; ", i, exp->pos[i]);
204
0
  fprintf(stderr, "\n");
205
0
}