Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/polly/lib/External/isl/isl_id.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2008-2009 Katholieke Universiteit Leuven
3
 *
4
 * Use of this software is governed by the MIT license
5
 *
6
 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7
 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
8
 */
9
10
#include <string.h>
11
#include <isl_ctx_private.h>
12
#include <isl_id_private.h>
13
14
#undef BASE
15
#define BASE id
16
17
#include <isl_list_templ.c>
18
19
/* A special, static isl_id to use as domains (and ranges)
20
 * of sets and parameters domains.
21
 * The user should never get a hold on this isl_id.
22
 */
23
isl_id isl_id_none = {
24
  .ref = -1,
25
  .ctx = NULL,
26
  .name = "#none",
27
  .user = NULL
28
};
29
30
isl_ctx *isl_id_get_ctx(__isl_keep isl_id *id)
31
22.9k
{
32
22.9k
  return id ? id->ctx : NULL;
33
22.9k
}
34
35
void *isl_id_get_user(__isl_keep isl_id *id)
36
33.1k
{
37
33.1k
  return id ? id->user : NULL;
38
33.1k
}
39
40
const char *isl_id_get_name(__isl_keep isl_id *id)
41
14.0k
{
42
14.0k
  return id ? id->name : NULL;
43
14.0k
}
44
45
static __isl_give isl_id *id_alloc(isl_ctx *ctx, const char *name, void *user)
46
73.1k
{
47
71.4k
  const char *copy = name ? strdup(name) : NULL;
48
73.1k
  isl_id *id;
49
73.1k
50
73.1k
  if (
name && 73.1k
!copy71.4k
)
51
0
    return NULL;
52
73.1k
  
id = 73.1k
isl_calloc_type73.1k
(ctx, struct isl_id);
53
73.1k
  if (!id)
54
0
    goto error;
55
73.1k
56
73.1k
  id->ctx = ctx;
57
73.1k
  isl_ctx_ref(id->ctx);
58
73.1k
  id->ref = 1;
59
73.1k
  id->name = copy;
60
73.1k
  id->user = user;
61
73.1k
62
73.1k
  id->hash = isl_hash_init();
63
73.1k
  if (name)
64
71.4k
    id->hash = isl_hash_string(id->hash, name);
65
73.1k
  else
66
1.63k
    
id->hash = 1.63k
isl_hash_builtin1.63k
(id->hash, user);
67
73.1k
68
73.1k
  return id;
69
0
error:
70
0
  free((char *)copy);
71
0
  return NULL;
72
73.1k
}
73
74
uint32_t isl_id_get_hash(__isl_keep isl_id *id)
75
1.03k
{
76
1.03k
  return id ? 
id->hash1.03k
:
00
;
77
1.03k
}
78
79
struct isl_name_and_user {
80
  const char *name;
81
  void *user;
82
};
83
84
static int isl_id_has_name_and_user(const void *entry, const void *val)
85
251k
{
86
251k
  isl_id *id = (isl_id *)entry;
87
251k
  struct isl_name_and_user *nu = (struct isl_name_and_user *) val;
88
251k
89
251k
  if (id->user != nu->user)
90
243k
    return 0;
91
7.89k
  
if (7.89k
id->name == nu->name7.89k
)
92
720
    return 1;
93
7.17k
  
if (7.17k
!id->name || 7.17k
!nu->name7.17k
)
94
0
    return 0;
95
7.17k
96
7.17k
  return !strcmp(id->name, nu->name);
97
7.17k
}
98
99
__isl_give isl_id *isl_id_alloc(isl_ctx *ctx, const char *name, void *user)
100
81.0k
{
101
81.0k
  struct isl_hash_table_entry *entry;
102
81.0k
  uint32_t id_hash;
103
81.0k
  struct isl_name_and_user nu = { name, user };
104
81.0k
105
81.0k
  if (!ctx)
106
0
    return NULL;
107
81.0k
108
81.0k
  
id_hash = 81.0k
isl_hash_init81.0k
();
109
81.0k
  if (name)
110
78.6k
    id_hash = isl_hash_string(id_hash, name);
111
81.0k
  else
112
2.35k
    
id_hash = 2.35k
isl_hash_builtin2.35k
(id_hash, user);
113
81.0k
  entry = isl_hash_table_find(ctx, &ctx->id_table, id_hash,
114
81.0k
          isl_id_has_name_and_user, &nu, 1);
115
81.0k
  if (!entry)
116
0
    return NULL;
117
81.0k
  
if (81.0k
entry->data81.0k
)
118
7.89k
    return isl_id_copy(entry->data);
119
73.1k
  entry->data = id_alloc(ctx, name, user);
120
73.1k
  if (!entry->data)
121
0
    ctx->id_table.n--;
122
81.0k
  return entry->data;
123
81.0k
}
124
125
/* If the id has a negative refcount, then it is a static isl_id
126
 * which should not be changed.
127
 */
128
__isl_give isl_id *isl_id_copy(isl_id *id)
129
16.7M
{
130
16.7M
  if (!id)
131
14.5k
    return NULL;
132
16.7M
133
16.7M
  
if (16.7M
id->ref < 016.7M
)
134
1.68M
    return id;
135
15.0M
136
15.0M
  id->ref++;
137
15.0M
  return id;
138
15.0M
}
139
140
/* Compare two isl_ids.
141
 *
142
 * The order is fairly arbitrary.  We do keep the comparison of
143
 * the user pointers as a last resort since these pointer values
144
 * may not be stable across different systems or even different runs.
145
 */
146
int isl_id_cmp(__isl_keep isl_id *id1, __isl_keep isl_id *id2)
147
4.87M
{
148
4.87M
  if (id1 == id2)
149
4.87M
    return 0;
150
0
  
if (0
!id10
)
151
0
    return -1;
152
0
  
if (0
!id20
)
153
0
    return 1;
154
0
  
if (0
!id1->name != !id2->name0
)
155
0
    return !id1->name - !id2->name;
156
0
  
if (0
id1->name0
) {
157
0
    int cmp = strcmp(id1->name, id2->name);
158
0
    if (cmp != 0)
159
0
      return cmp;
160
0
  }
161
0
  
if (0
id1->user < id2->user0
)
162
0
    return -1;
163
0
  else
164
0
    return 1;
165
0
}
166
167
static int isl_id_eq(const void *entry, const void *name)
168
100k
{
169
100k
  return entry == name;
170
100k
}
171
172
uint32_t isl_hash_id(uint32_t hash, __isl_keep isl_id *id)
173
2.13M
{
174
2.13M
  if (id)
175
1.51M
    isl_hash_hash(hash, id->hash);
176
2.13M
177
2.13M
  return hash;
178
2.13M
}
179
180
/* Replace the free_user callback by "free_user".
181
 */
182
__isl_give isl_id *isl_id_set_free_user(__isl_take isl_id *id,
183
  void (*free_user)(void *user))
184
2.30k
{
185
2.30k
  if (!id)
186
0
    return NULL;
187
2.30k
188
2.30k
  id->free_user = free_user;
189
2.30k
190
2.30k
  return id;
191
2.30k
}
192
193
/* If the id has a negative refcount, then it is a static isl_id
194
 * and should not be freed.
195
 */
196
__isl_null isl_id *isl_id_free(__isl_take isl_id *id)
197
31.4M
{
198
31.4M
  struct isl_hash_table_entry *entry;
199
31.4M
200
31.4M
  if (!id)
201
12.8M
    return NULL;
202
18.5M
203
18.5M
  
if (18.5M
id->ref < 018.5M
)
204
3.46M
    return NULL;
205
15.1M
206
15.1M
  
if (15.1M
--id->ref > 015.1M
)
207
15.0M
    return NULL;
208
72.8k
209
72.8k
  entry = isl_hash_table_find(id->ctx, &id->ctx->id_table, id->hash,
210
72.8k
          isl_id_eq, id, 0);
211
72.8k
  if (!entry)
212
0
    isl_die(id->ctx, isl_error_unknown,
213
72.8k
      "unable to find id", (void)0);
214
72.8k
  else
215
72.8k
    isl_hash_table_remove(id->ctx, &id->ctx->id_table, entry);
216
72.8k
217
72.8k
  if (id->free_user)
218
2.30k
    id->free_user(id->user);
219
31.4M
220
31.4M
  free((char *)id->name);
221
31.4M
  isl_ctx_deref(id->ctx);
222
31.4M
  free(id);
223
31.4M
224
31.4M
  return NULL;
225
31.4M
}
226
227
__isl_give isl_printer *isl_printer_print_id(__isl_take isl_printer *p,
228
  __isl_keep isl_id *id)
229
14
{
230
14
  if (!id)
231
0
    goto error;
232
14
233
14
  
if (14
id->name14
)
234
14
    p = isl_printer_print_str(p, id->name);
235
14
  if (
id->user14
) {
236
14
    char buffer[50];
237
14
    snprintf(buffer, sizeof(buffer), "@%p", id->user);
238
14
    p = isl_printer_print_str(p, buffer);
239
14
  }
240
14
  return p;
241
0
error:
242
0
  isl_printer_free(p);
243
0
  return NULL;
244
14
}