Coverage Report

Created: 2017-08-21 19:50

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