Coverage Report

Created: 2017-04-29 12:21

/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
15.8k
{
32
15.8k
  return id ? id->ctx : NULL;
33
15.8k
}
34
35
void *isl_id_get_user(__isl_keep isl_id *id)
36
19.7k
{
37
19.7k
  return id ? id->user : NULL;
38
19.7k
}
39
40
const char *isl_id_get_name(__isl_keep isl_id *id)
41
8.37k
{
42
8.37k
  return id ? id->name : NULL;
43
8.37k
}
44
45
static __isl_give isl_id *id_alloc(isl_ctx *ctx, const char *name, void *user)
46
59.6k
{
47
58.3k
  const char *copy = name ? strdup(name) : NULL;
48
59.6k
  isl_id *id;
49
59.6k
50
59.6k
  if (
name && 59.6k
!copy58.3k
)
51
0
    return NULL;
52
59.6k
  
id = 59.6k
isl_calloc_type59.6k
(ctx, struct isl_id);
53
59.6k
  if (!id)
54
0
    goto error;
55
59.6k
56
59.6k
  id->ctx = ctx;
57
59.6k
  isl_ctx_ref(id->ctx);
58
59.6k
  id->ref = 1;
59
59.6k
  id->name = copy;
60
59.6k
  id->user = user;
61
59.6k
62
59.6k
  id->hash = isl_hash_init();
63
59.6k
  if (name)
64
58.3k
    id->hash = isl_hash_string(id->hash, name);
65
59.6k
  else
66
1.33k
    
id->hash = 1.33k
isl_hash_builtin1.33k
(id->hash, user);
67
59.6k
68
59.6k
  return id;
69
0
error:
70
0
  free((char *)copy);
71
0
  return NULL;
72
59.6k
}
73
74
uint32_t isl_id_get_hash(__isl_keep isl_id *id)
75
638
{
76
638
  return id ? 
id->hash638
:
00
;
77
638
}
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
55.0k
{
86
55.0k
  isl_id *id = (isl_id *)entry;
87
55.0k
  struct isl_name_and_user *nu = (struct isl_name_and_user *) val;
88
55.0k
89
55.0k
  if (id->user != nu->user)
90
48.9k
    return 0;
91
6.14k
  
if (6.14k
id->name == nu->name6.14k
)
92
580
    return 1;
93
5.56k
  
if (5.56k
!id->name || 5.56k
!nu->name5.56k
)
94
0
    return 0;
95
5.56k
96
5.56k
  return !strcmp(id->name, nu->name);
97
5.56k
}
98
99
__isl_give isl_id *isl_id_alloc(isl_ctx *ctx, const char *name, void *user)
100
65.7k
{
101
65.7k
  struct isl_hash_table_entry *entry;
102
65.7k
  uint32_t id_hash;
103
65.7k
  struct isl_name_and_user nu = { name, user };
104
65.7k
105
65.7k
  if (!ctx)
106
0
    return NULL;
107
65.7k
108
65.7k
  
id_hash = 65.7k
isl_hash_init65.7k
();
109
65.7k
  if (name)
110
63.8k
    id_hash = isl_hash_string(id_hash, name);
111
65.7k
  else
112
1.91k
    
id_hash = 1.91k
isl_hash_builtin1.91k
(id_hash, user);
113
65.7k
  entry = isl_hash_table_find(ctx, &ctx->id_table, id_hash,
114
65.7k
          isl_id_has_name_and_user, &nu, 1);
115
65.7k
  if (!entry)
116
0
    return NULL;
117
65.7k
  
if (65.7k
entry->data65.7k
)
118
6.14k
    return isl_id_copy(entry->data);
119
59.6k
  entry->data = id_alloc(ctx, name, user);
120
59.6k
  if (!entry->data)
121
0
    ctx->id_table.n--;
122
59.6k
  return entry->data;
123
65.7k
}
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
10.3M
{
130
10.3M
  if (!id)
131
16.6k
    return NULL;
132
10.3M
133
10.3M
  
if (10.3M
id->ref < 010.3M
)
134
1.23M
    return id;
135
10.3M
136
9.13M
  id->ref++;
137
9.13M
  return id;
138
10.3M
}
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.53M
{
148
4.53M
  if (id1 == id2)
149
4.53M
    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
)
{0
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
62.0k
{
169
62.0k
  return entry == name;
170
62.0k
}
171
172
uint32_t isl_hash_id(uint32_t hash, __isl_keep isl_id *id)
173
1.63M
{
174
1.63M
  if (id)
175
1.28M
    isl_hash_hash(hash, id->hash);
176
1.63M
177
1.63M
  return hash;
178
1.63M
}
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.47k
{
185
1.47k
  if (!id)
186
0
    return NULL;
187
1.47k
188
1.47k
  id->free_user = free_user;
189
1.47k
190
1.47k
  return id;
191
1.47k
}
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
20.1M
{
198
20.1M
  struct isl_hash_table_entry *entry;
199
20.1M
200
20.1M
  if (!id)
201
8.55M
    return NULL;
202
20.1M
203
11.5M
  
if (11.5M
id->ref < 011.5M
)
204
2.38M
    return NULL;
205
11.5M
206
9.19M
  
if (9.19M
--id->ref > 09.19M
)
207
9.13M
    return NULL;
208
9.19M
209
59.6k
  entry = isl_hash_table_find(id->ctx, &id->ctx->id_table, id->hash,
210
59.6k
          isl_id_eq, id, 0);
211
59.6k
  if (!entry)
212
0
    isl_die(id->ctx, isl_error_unknown,
213
59.6k
      "unable to find id", (void)0);
214
59.6k
  else
215
59.6k
    isl_hash_table_remove(id->ctx, &id->ctx->id_table, entry);
216
59.6k
217
59.6k
  if (id->free_user)
218
1.47k
    id->free_user(id->user);
219
59.6k
220
59.6k
  free((char *)id->name);
221
59.6k
  isl_ctx_deref(id->ctx);
222
59.6k
  free(id);
223
59.6k
224
59.6k
  return NULL;
225
9.19M
}
226
227
__isl_give isl_printer *isl_printer_print_id(__isl_take isl_printer *p,
228
  __isl_keep isl_id *id)
229
0
{
230
0
  if (!id)
231
0
    goto error;
232
0
233
0
  
if (0
id->name0
)
234
0
    p = isl_printer_print_str(p, id->name);
235
0
  if (
id->user0
)
{0
236
0
    char buffer[50];
237
0
    snprintf(buffer, sizeof(buffer), "@%p", id->user);
238
0
    p = isl_printer_print_str(p, buffer);
239
0
  }
240
0
  return p;
241
0
error:
242
0
  isl_printer_free(p);
243
0
  return NULL;
244
0
}