Coverage Report

Created: 2017-04-27 19:33

/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
174k
{
17
174k
  isl_reordering *exp;
18
174k
19
174k
  exp = isl_alloc(ctx, struct isl_reordering,
20
174k
      sizeof(struct isl_reordering) + (len - 1) * sizeof(int));
21
174k
  if (!exp)
22
0
    return NULL;
23
174k
24
174k
  exp->ref = 1;
25
174k
  exp->len = len;
26
174k
  exp->dim = NULL;
27
174k
28
174k
  return exp;
29
174k
}
30
31
__isl_give isl_reordering *isl_reordering_copy(__isl_keep isl_reordering *exp)
32
154k
{
33
154k
  if (!exp)
34
0
    return NULL;
35
154k
36
154k
  exp->ref++;
37
154k
  return exp;
38
154k
}
39
40
__isl_give isl_reordering *isl_reordering_dup(__isl_keep isl_reordering *r)
41
34.4k
{
42
34.4k
  int i;
43
34.4k
  isl_reordering *dup;
44
34.4k
45
34.4k
  if (!r)
46
0
    return NULL;
47
34.4k
48
34.4k
  dup = isl_reordering_alloc(r->dim->ctx, r->len);
49
34.4k
  if (!dup)
50
0
    return NULL;
51
34.4k
52
34.4k
  dup->dim = isl_space_copy(r->dim);
53
34.4k
  if (!dup->dim)
54
0
    return isl_reordering_free(dup);
55
187k
  
for (i = 0; 34.4k
i < dup->len187k
;
++i153k
)
56
153k
    dup->pos[i] = r->pos[i];
57
34.4k
58
34.4k
  return dup;
59
34.4k
}
60
61
__isl_give isl_reordering *isl_reordering_cow(__isl_take isl_reordering *r)
62
95.6k
{
63
95.6k
  if (!r)
64
0
    return NULL;
65
95.6k
66
95.6k
  
if (95.6k
r->ref == 195.6k
)
67
61.1k
    return r;
68
34.4k
  r->ref--;
69
34.4k
  return isl_reordering_dup(r);
70
95.6k
}
71
72
void *isl_reordering_free(__isl_take isl_reordering *exp)
73
295k
{
74
295k
  if (!exp)
75
284
    return NULL;
76
295k
77
295k
  
if (295k
--exp->ref > 0295k
)
78
120k
    return NULL;
79
295k
80
174k
  isl_space_free(exp->dim);
81
174k
  free(exp);
82
174k
  return NULL;
83
295k
}
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
79.1k
{
93
79.1k
  int i, j;
94
79.1k
  isl_reordering *exp;
95
79.1k
96
79.1k
  if (
!alignee || 79.1k
!aligner79.1k
)
97
0
    return NULL;
98
79.1k
99
79.1k
  exp = isl_reordering_alloc(alignee->ctx, alignee->nparam);
100
79.1k
  if (!exp)
101
0
    return NULL;
102
79.1k
103
79.1k
  exp->dim = isl_space_copy(aligner);
104
79.1k
105
208k
  for (i = 0; 
i < alignee->nparam208k
;
++i129k
)
{129k
106
129k
    isl_id *id_i;
107
129k
    id_i = isl_space_get_dim_id(alignee, isl_dim_param, i);
108
129k
    if (!id_i)
109
0
      isl_die(alignee->ctx, isl_error_invalid,
110
129k
        "cannot align unnamed parameters", goto error);
111
711k
    
for (j = 0; 129k
j < aligner->nparam711k
;
++j582k
)
{673k
112
673k
      isl_id *id_j;
113
673k
      id_j = isl_space_get_dim_id(aligner, isl_dim_param, j);
114
673k
      isl_id_free(id_j);
115
673k
      if (id_i == id_j)
116
91.1k
        break;
117
673k
    }
118
129k
    if (
j < aligner->nparam129k
)
{91.1k
119
91.1k
      exp->pos[i] = j;
120
91.1k
      isl_id_free(id_i);
121
38.2k
    } else {
122
38.2k
      int pos;
123
38.2k
      pos = isl_space_dim(exp->dim, isl_dim_param);
124
38.2k
      exp->dim = isl_space_add_dims(exp->dim, isl_dim_param, 1);
125
38.2k
      exp->dim = isl_space_set_dim_id(exp->dim,
126
38.2k
            isl_dim_param, pos, id_i);
127
38.2k
      exp->pos[i] = pos;
128
38.2k
    }
129
129k
  }
130
79.1k
131
79.1k
  
if (79.1k
!exp->dim79.1k
)
132
0
    return isl_reordering_free(exp);
133
79.1k
  return exp;
134
0
error:
135
0
  isl_reordering_free(exp);
136
0
  return NULL;
137
79.1k
}
138
139
__isl_give isl_reordering *isl_reordering_extend(__isl_take isl_reordering *exp,
140
  unsigned extra)
141
103k
{
142
103k
  int i;
143
103k
  isl_reordering *res;
144
103k
  int offset;
145
103k
146
103k
  if (!exp)
147
0
    return NULL;
148
103k
  
if (103k
extra == 0103k
)
149
41.9k
    return exp;
150
103k
151
61.3k
  offset = isl_space_dim(exp->dim, isl_dim_all) - exp->len;
152
61.3k
  res = isl_reordering_alloc(exp->dim->ctx, exp->len + extra);
153
61.3k
  if (!res)
154
0
    goto error;
155
61.3k
  res->dim = isl_space_copy(exp->dim);
156
213k
  for (i = 0; 
i < exp->len213k
;
++i152k
)
157
152k
    res->pos[i] = exp->pos[i];
158
184k
  for (i = exp->len; 
i < res->len184k
;
++i123k
)
159
123k
    res->pos[i] = offset + i;
160
61.3k
161
61.3k
  isl_reordering_free(exp);
162
61.3k
163
61.3k
  return res;
164
0
error:
165
0
  isl_reordering_free(exp);
166
0
  return NULL;
167
61.3k
}
168
169
__isl_give isl_reordering *isl_reordering_extend_space(
170
  __isl_take isl_reordering *exp, __isl_take isl_space *dim)
171
95.6k
{
172
95.6k
  isl_reordering *res;
173
95.6k
174
95.6k
  if (
!exp || 95.6k
!dim95.6k
)
175
0
    goto error;
176
95.6k
177
95.6k
  res = isl_reordering_extend(isl_reordering_copy(exp),
178
95.6k
            isl_space_dim(dim, isl_dim_all) - exp->len);
179
95.6k
  res = isl_reordering_cow(res);
180
95.6k
  if (!res)
181
0
    goto error;
182
95.6k
  isl_space_free(res->dim);
183
95.6k
  res->dim = isl_space_replace(dim, isl_dim_param, exp->dim);
184
95.6k
185
95.6k
  isl_reordering_free(exp);
186
95.6k
187
95.6k
  if (!res->dim)
188
0
    return isl_reordering_free(res);
189
95.6k
190
95.6k
  return res;
191
0
error:
192
0
  isl_reordering_free(exp);
193
0
  isl_space_free(dim);
194
0
  return NULL;
195
95.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->len0
;
++i0
)
203
0
    fprintf(stderr, "%d -> %d; ", i, exp->pos[i]);
204
0
  fprintf(stderr, "\n");
205
0
}