Coverage Report

Created: 2017-03-28 09:59

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