13 struct CachedCompilation {
22 static constexpr float kLoadFactor{.5f};
23 static constexpr int kInitialTableBits{7};
24 int log2_compilations_size{0};
25 CachedCompilation *compilations{
nullptr};
38 return (addr * (
uintptr_t)0x9E3779B97F4A7C15) >> (64 - bits);
40 return (addr * (
uintptr_t)0x9E3779B9) >> (32 - bits);
45 if (log2_compilations_size == 0) {
46 if (!resize_table(kInitialTableBits)) {
50 if ((count + 1) > (1 << log2_compilations_size) * kLoadFactor) {
51 if (!resize_table(log2_compilations_size + 1)) {
56 uintptr_t index = kernel_hash(entry.context, entry.kernel_id, log2_compilations_size);
57 for (
int i = 0;
i < (1 << log2_compilations_size);
i++) {
72 if (log2_compilations_size == 0) {
75 uintptr_t index = kernel_hash(context,
id, log2_compilations_size);
76 for (
int i = 0;
i < (1 << log2_compilations_size);
i++) {
95 if (
size_bits != log2_compilations_size) {
97 int old_size = (1 << log2_compilations_size);
104 CachedCompilation *
old_table = compilations;
123 template<
typename FreeModuleT>
124 void release_context_already_locked(
void *user_context,
bool all,
ContextT context,
FreeModuleT &f) {
129 for (
int i = 0;
i < (1 << log2_compilations_size);
i++) {
130 if (compilations[
i].kernel_id > kInvalidId &&
131 (all || (compilations[
i].context == context)) &&
132 compilations[
i].use_count == 0) {
133 debug(user_context) <<
"Releasing cached compilation: " << compilations[
i].module_state
134 <<
" id " << compilations[
i].kernel_id
135 <<
" context " << compilations[
i].context <<
"\n";
136 f(compilations[
i].module_state);
137 compilations[
i].module_state =
nullptr;
138 compilations[
i].kernel_id = kDeletedId;
146 ScopedMutexLock lock_guard(&mutex);
150 if (find_internal(context,
id,
mod_ptr, 0)) {
157 template<
typename FreeModuleT>
159 ScopedMutexLock lock_guard(&mutex);
161 release_context_already_locked(user_context, all, context, f);
164 template<
typename FreeModuleT>
166 ScopedMutexLock lock_guard(&mutex);
168 release_context_already_locked(user_context,
false, context, f);
171 template<
typename FreeModuleT>
173 ScopedMutexLock lock_guard(&mutex);
175 release_context_already_locked(user_context,
true,
nullptr, f);
179 compilations =
nullptr;
180 log2_compilations_size = 0;
189 ScopedMutexLock lock_guard(&mutex);
201 if (find_internal(context, *
id_ptr, mod, 1)) {
209 <<
" id " << *
id_ptr <<
" context " << context <<
"\n";
223 ScopedMutexLock lock_guard(&mutex);
227 bool result = find_internal(context,
id, mod, -1);
Internal::ConstantInterval cast(Type t, const Internal::ConstantInterval &a)
Cast operators for ConstantIntervals.