1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
/* Traits for hashable types.
Copyright (C) 2014-2015 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#ifndef hash_traits_h
#define hash_traits_h
/* Helpful type for removing with free. */
template <typename Type>
struct typed_free_remove
{
static inline void remove (Type *p);
};
/* Remove with free. */
template <typename Type>
inline void
typed_free_remove <Type>::remove (Type *p)
{
free (p);
}
/* Helpful type for a no-op remove. */
template <typename Type>
struct typed_noop_remove
{
static inline void remove (Type *p);
};
/* Remove doing nothing. */
template <typename Type>
inline void
typed_noop_remove <Type>::remove (Type *p ATTRIBUTE_UNUSED)
{
}
/* Pointer hash with a no-op remove method. */
template <typename Type>
struct pointer_hash : typed_noop_remove <Type>
{
typedef Type *value_type;
typedef Type *compare_type;
static inline hashval_t hash (const value_type &);
static inline bool equal (const value_type &existing,
const compare_type &candidate);
};
template <typename Type>
inline hashval_t
pointer_hash <Type>::hash (const value_type &candidate)
{
/* This is a really poor hash function, but it is what the current code uses,
so I am reusing it to avoid an additional axis in testing. */
return (hashval_t) ((intptr_t)candidate >> 3);
}
template <typename Type>
inline bool
pointer_hash <Type>::equal (const value_type &existing,
const compare_type &candidate)
{
return existing == candidate;
}
/* Hasher for entry in gc memory. */
template<typename T>
struct ggc_hasher
{
typedef T value_type;
typedef T compare_type;
static void remove (T) {}
static void
ggc_mx (T p)
{
extern void gt_ggc_mx (T &);
gt_ggc_mx (p);
}
static void
pch_nx (T &p)
{
extern void gt_pch_nx (T &);
gt_pch_nx (p);
}
static void
pch_nx (T &p, gt_pointer_operator op, void *cookie)
{
op (&p, cookie);
}
};
/* Hasher for cache entry in gc memory. */
template<typename T>
struct ggc_cache_hasher
{
typedef T value_type;
typedef T compare_type;
static void remove (T &) {}
/* Entries are weakly held because this is for caches. */
static void ggc_mx (T &) {}
static void
pch_nx (T &p)
{
extern void gt_pch_nx (T &);
gt_pch_nx (p);
}
static void
pch_nx (T &p, gt_pointer_operator op, void *cookie)
{
op (&p, cookie);
}
/* Clear out entries if they are about to be gc'd. */
static void
handle_cache_entry (T &e)
{
if (e != HTAB_EMPTY_ENTRY && e != HTAB_DELETED_ENTRY && !ggc_marked_p (e))
e = static_cast<T> (HTAB_DELETED_ENTRY);
}
};
#endif
|