Coverage Report

Created: 2017-11-21 16:49

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/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
10.1k
{
32
10.1k
  return id ? id->ctx : NULL;
33
10.1k
}
34
35
void *isl_id_get_user(__isl_keep isl_id *id)
36
10.8k
{
37
10.8k
  return id ? id->user : NULL;
38
10.8k
}
39
40
const char *isl_id_get_name(__isl_keep isl_id *id)
41
7.11k
{
42
7.11k
  return id ? id->name : NULL;
43
7.11k
}
44
45
static __isl_give isl_id *id_alloc(isl_ctx *ctx, const char *name, void *user)
46
26.4k
{
47
26.4k
  const char *copy = name ? 
strdup(name)25.9k
: NULL;
48
26.4k
  isl_id *id;
49
26.4k
50
26.4k
  if (name && 
!copy25.9k
)
51
0
    return NULL;
52
26.4k
  id = isl_calloc_type(ctx, struct isl_id);
53
26.4k
  if (!id)
54
0
    goto error;
55
26.4k
56
26.4k
  id->ctx = ctx;
57
26.4k
  isl_ctx_ref(id->ctx);
58
26.4k
  id->ref = 1;
59
26.4k
  id->name = copy;
60
26.4k
  id->user = user;
61
26.4k
62
26.4k
  id->hash = isl_hash_init();
63
26.4k
  if (name)
64
25.9k
    id->hash = isl_hash_string(id->hash, name);
65
560
  else
66
560
    id->hash = isl_hash_builtin(id->hash, user);
67
26.4k
68
26.4k
  return id;
69
0
error:
70
0
  free((char *)copy);
71
0
  return NULL;
72
26.4k
}
73
74
uint32_t isl_id_get_hash(__isl_keep isl_id *id)
75
491
{
76
491
  return id ? id->hash : 
00
;
77
491
}
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
205k
{
86
205k
  isl_id *id = (isl_id *)entry;
87
205k
  struct isl_name_and_user *nu = (struct isl_name_and_user *) val;
88
205k
89
205k
  if (id->user != nu->user)
90
203k
    return 0;
91
1.99k
  if (id->name == nu->name)
92
255
    return 1;
93
1.73k
  if (!id->name || !nu->name)
94
0
    return 0;
95
1.73k
96
1.73k
  return !strcmp(id->name, nu->name);
97
1.73k
}
98
99
__isl_give isl_id *isl_id_alloc(isl_ctx *ctx, const char *name, void *user)
100
28.4k
{
101
28.4k
  struct isl_hash_table_entry *entry;
102
28.4k
  uint32_t id_hash;
103
28.4k
  struct isl_name_and_user nu = { name, user };
104
28.4k
105
28.4k
  if (!ctx)
106
0
    return NULL;
107
28.4k
108
28.4k
  id_hash = isl_hash_init();
109
28.4k
  if (name)
110
27.6k
    id_hash = isl_hash_string(id_hash, name);
111
815
  else
112
815
    id_hash = isl_hash_builtin(id_hash, user);
113
28.4k
  entry = isl_hash_table_find(ctx, &ctx->id_table, id_hash,
114
28.4k
          isl_id_has_name_and_user, &nu, 1);
115
28.4k
  if (!entry)
116
0
    return NULL;
117
28.4k
  if (entry->data)
118
1.99k
    return isl_id_copy(entry->data);
119
26.4k
  entry->data = id_alloc(ctx, name, user);
120
26.4k
  if (!entry->data)
121
0
    ctx->id_table.n--;
122
28.4k
  return entry->data;
123
28.4k
}
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
8.30M
{
130
8.30M
  if (!id)
131
5.93k
    return NULL;
132
8.30M
133
8.30M
  if (id->ref < 0)
134
605k
    return id;
135
7.69M
136
7.69M
  id->ref++;
137
7.69M
  return id;
138
7.69M
}
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
3.86M
{
148
3.86M
  if (id1 == id2)
149
3.86M
    return 0;
150
0
  if (!id1)
151
0
    return -1;
152
0
  if (!id2)
153
0
    return 1;
154
0
  if (!id1->name != !id2->name)
155
0
    return !id1->name - !id2->name;
156
0
  if (id1->name) {
157
0
    int cmp = strcmp(id1->name, id2->name);
158
0
    if (cmp != 0)
159
0
      return cmp;
160
0
  }
161
0
  if (id1->user < id2->user)
162
0
    return -1;
163
0
  else
164
0
    return 1;
165
3.86M
}
166
167
static int isl_id_eq(const void *entry, const void *name)
168
52.7k
{
169
52.7k
  return entry == name;
170
52.7k
}
171
172
uint32_t isl_hash_id(uint32_t hash, __isl_keep isl_id *id)
173
826k
{
174
826k
  if (id)
175
826k
    
isl_hash_hash546k
(hash, id->hash);
176
826k
177
826k
  return hash;
178
826k
}
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
1.21k
{
185
1.21k
  if (!id)
186
0
    return NULL;
187
1.21k
188
1.21k
  id->free_user = free_user;
189
1.21k
190
1.21k
  return id;
191
1.21k
}
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
13.8M
{
198
13.8M
  struct isl_hash_table_entry *entry;
199
13.8M
200
13.8M
  if (!id)
201
4.84M
    return NULL;
202
9.02M
203
9.02M
  if (id->ref < 0)
204
1.30M
    return NULL;
205
7.72M
206
7.72M
  if (--id->ref > 0)
207
7.69M
    return NULL;
208
26.4k
209
26.4k
  entry = isl_hash_table_find(id->ctx, &id->ctx->id_table, id->hash,
210
26.4k
          isl_id_eq, id, 0);
211
26.4k
  if (!entry)
212
26.4k
    
isl_die0
(id->ctx, isl_error_unknown,
213
26.4k
      "unable to find id", (void)0);
214
26.4k
  else
215
26.4k
    isl_hash_table_remove(id->ctx, &id->ctx->id_table, entry);
216
26.4k
217
26.4k
  if (id->free_user)
218
1.21k
    id->free_user(id->user);
219
13.8M
220
13.8M
  free((char *)id->name);
221
13.8M
  isl_ctx_deref(id->ctx);
222
13.8M
  free(id);
223
13.8M
224
13.8M
  return NULL;
225
13.8M
}
226
227
__isl_give isl_printer *isl_printer_print_id(__isl_take isl_printer *p,
228
  __isl_keep isl_id *id)
229
4
{
230
4
  if (!id)
231
0
    goto error;
232
4
233
4
  if (id->name)
234
4
    p = isl_printer_print_str(p, id->name);
235
4
  if (id->user) {
236
4
    char buffer[50];
237
4
    snprintf(buffer, sizeof(buffer), "@%p", id->user);
238
4
    p = isl_printer_print_str(p, buffer);
239
4
  }
240
4
  return p;
241
0
error:
242
0
  isl_printer_free(p);
243
0
  return NULL;
244
4
}