Coverage Report

Created: 2017-06-28 17:40

/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
194k
{
17
194k
  isl_reordering *exp;
18
194k
19
194k
  exp = isl_alloc(ctx, struct isl_reordering,
20
194k
      sizeof(struct isl_reordering) + (len - 1) * sizeof(int));
21
194k
  if (!exp)
22
0
    return NULL;
23
194k
24
194k
  exp->ref = 1;
25
194k
  exp->len = len;
26
194k
  exp->dim = NULL;
27
194k
28
194k
  return exp;
29
194k
}
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
38.4k
{
42
38.4k
  int i;
43
38.4k
  isl_reordering *dup;
44
38.4k
45
38.4k
  if (!r)
46
0
    return NULL;
47
38.4k
48
38.4k
  dup = isl_reordering_alloc(r->dim->ctx, r->len);
49
38.4k
  if (!dup)
50
0
    return NULL;
51
38.4k
52
38.4k
  dup->dim = isl_space_copy(r->dim);
53
38.4k
  if (!dup->dim)
54
0
    return isl_reordering_free(dup);
55
195k
  
for (i = 0; 38.4k
i < dup->len195k
;
++i157k
)
56
157k
    dup->pos[i] = r->pos[i];
57
38.4k
58
38.4k
  return dup;
59
38.4k
}
60
61
__isl_give isl_reordering *isl_reordering_cow(__isl_take isl_reordering *r)
62
104k
{
63
104k
  if (!r)
64
0
    return NULL;
65
104k
66
104k
  
if (104k
r->ref == 1104k
)
67
66.3k
    return r;
68
38.4k
  r->ref--;
69
38.4k
  return isl_reordering_dup(r);
70
104k
}
71
72
void *isl_reordering_free(__isl_take isl_reordering *exp)
73
324k
{
74
324k
  if (!exp)
75
304
    return NULL;
76
324k
77
324k
  
if (324k
--exp->ref > 0324k
)
78
129k
    return NULL;
79
324k
80
194k
  isl_space_free(exp->dim);
81
194k
  free(exp);
82
194k
  return NULL;
83
324k
}
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
89.2k
{
93
89.2k
  int i, j;
94
89.2k
  isl_reordering *exp;
95
89.2k
96
89.2k
  if (
!alignee || 89.2k
!aligner89.2k
)
97
0
    return NULL;
98
89.2k
99
89.2k
  exp = isl_reordering_alloc(alignee->ctx, alignee->nparam);
100
89.2k
  if (!exp)
101
0
    return NULL;
102
89.2k
103
89.2k
  exp->dim = isl_space_copy(aligner);
104
89.2k
105
225k
  for (i = 0; 
i < alignee->nparam225k
;
++i136k
)
{136k
106
136k
    isl_id *id_i;
107
136k
    id_i = isl_space_get_dim_id(alignee, isl_dim_param, i);
108
136k
    if (!id_i)
109
0
      isl_die(alignee->ctx, isl_error_invalid,
110
136k
        "cannot align unnamed parameters", goto error);
111
724k
    
for (j = 0; 136k
j < aligner->nparam724k
;
++j588k
)
{684k
112
684k
      isl_id *id_j;
113
684k
      id_j = isl_space_get_dim_id(aligner, isl_dim_param, j);
114
684k
      isl_id_free(id_j);
115
684k
      if (id_i == id_j)
116
95.9k
        break;
117
684k
    }
118
136k
    if (
j < aligner->nparam136k
)
{95.9k
119
95.9k
      exp->pos[i] = j;
120
95.9k
      isl_id_free(id_i);
121
40.7k
    } else {
122
40.7k
      int pos;
123
40.7k
      pos = isl_space_dim(exp->dim, isl_dim_param);
124
40.7k
      exp->dim = isl_space_add_dims(exp->dim, isl_dim_param, 1);
125
40.7k
      exp->dim = isl_space_set_dim_id(exp->dim,
126
40.7k
            isl_dim_param, pos, id_i);
127
40.7k
      exp->pos[i] = pos;
128
40.7k
    }
129
136k
  }
130
89.2k
131
89.2k
  
if (89.2k
!exp->dim89.2k
)
132
0
    return isl_reordering_free(exp);
133
89.2k
  return exp;
134
0
error:
135
0
  isl_reordering_free(exp);
136
0
  return NULL;
137
89.2k
}
138
139
__isl_give isl_reordering *isl_reordering_extend(__isl_take isl_reordering *exp,
140
  unsigned extra)
141
113k
{
142
113k
  int i;
143
113k
  isl_reordering *res;
144
113k
  int offset;
145
113k
146
113k
  if (!exp)
147
0
    return NULL;
148
113k
  
if (113k
extra == 0113k
)
149
46.8k
    return exp;
150
113k
151
66.6k
  offset = isl_space_dim(exp->dim, isl_dim_all) - exp->len;
152
66.6k
  res = isl_reordering_alloc(exp->dim->ctx, exp->len + extra);
153
66.6k
  if (!res)
154
0
    goto error;
155
66.6k
  res->dim = isl_space_copy(exp->dim);
156
223k
  for (i = 0; 
i < exp->len223k
;
++i156k
)
157
156k
    res->pos[i] = exp->pos[i];
158
198k
  for (i = exp->len; 
i < res->len198k
;
++i131k
)
159
131k
    res->pos[i] = offset + i;
160
66.6k
161
66.6k
  isl_reordering_free(exp);
162
66.6k
163
66.6k
  return res;
164
0
error:
165
0
  isl_reordering_free(exp);
166
0
  return NULL;
167
66.6k
}
168
169
__isl_give isl_reordering *isl_reordering_extend_space(
170
  __isl_take isl_reordering *exp, __isl_take isl_space *dim)
171
104k
{
172
104k
  isl_reordering *res;
173
104k
174
104k
  if (
!exp || 104k
!dim104k
)
175
0
    goto error;
176
104k
177
104k
  res = isl_reordering_extend(isl_reordering_copy(exp),
178
104k
            isl_space_dim(dim, isl_dim_all) - exp->len);
179
104k
  res = isl_reordering_cow(res);
180
104k
  if (!res)
181
0
    goto error;
182
104k
  isl_space_free(res->dim);
183
104k
  res->dim = isl_space_replace(dim, isl_dim_param, exp->dim);
184
104k
185
104k
  isl_reordering_free(exp);
186
104k
187
104k
  if (!res->dim)
188
0
    return isl_reordering_free(res);
189
104k
190
104k
  return res;
191
0
error:
192
0
  isl_reordering_free(exp);
193
0
  isl_space_free(dim);
194
0
  return NULL;
195
104k
}
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
}