From de70e6faa04444a1ea6e8f5f72e7b6ce00dcec7e Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 24 Feb 2025 15:33:35 +0000 Subject: [PATCH] Use more type hashes where possible --- src/llvm_backend.hpp | 14 +++++++------- src/name_canonicalization.hpp | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/llvm_backend.hpp b/src/llvm_backend.hpp index 3617c267f..d0f68b73e 100644 --- a/src/llvm_backend.hpp +++ b/src/llvm_backend.hpp @@ -160,11 +160,11 @@ struct lbModule { AstFile *file; // possibly associated char const *module_name; - PtrMap types; // mutex: types_mutex + PtrMap types; // mutex: types_mutex PtrMap struct_field_remapping; // Key: LLVMTypeRef or Type *, mutex: types_mutex - PtrMap func_raw_types; // mutex: func_raw_types_mutex - RecursiveMutex types_mutex; - RecursiveMutex func_raw_types_mutex; + PtrMap func_raw_types; // mutex: func_raw_types_mutex + RecursiveMutex types_mutex; + RecursiveMutex func_raw_types_mutex; i32 internal_type_level; RwMutex values_mutex; @@ -178,7 +178,7 @@ struct lbModule { StringMap const_strings; - PtrMap function_type_map; + PtrMap function_type_map; StringMap gen_procs; // key is the canonicalized name @@ -201,8 +201,8 @@ struct lbModule { StringMap objc_classes; StringMap objc_selectors; - PtrMap map_cell_info_map; // address of runtime.Map_Info - PtrMap map_info_map; // address of runtime.Map_Cell_Info + PtrMap map_cell_info_map; // address of runtime.Map_Info + PtrMap map_info_map; // address of runtime.Map_Cell_Info PtrMap exact_value_compound_literal_addr_map; // Key: Ast_CompoundLit diff --git a/src/name_canonicalization.hpp b/src/name_canonicalization.hpp index e289ed5b2..304aff42e 100644 --- a/src/name_canonicalization.hpp +++ b/src/name_canonicalization.hpp @@ -109,3 +109,20 @@ gb_internal TypeInfoPair *type_set_retrieve(TypeSet *s, Type *ptr); gb_internal TypeSetIterator begin(TypeSet &set) noexcept; gb_internal TypeSetIterator end(TypeSet &set) noexcept; + + +template +gb_internal gb_inline V *map_get(PtrMap *h, Type *key) { + return map_get(h, type_hash_canonical_type(key)); +} +template +gb_internal gb_inline void map_set(PtrMap *h, Type *key, V const &value) { + map_set(h, type_hash_canonical_type(key), value); +} + +template +gb_internal gb_inline V &map_must_get(PtrMap *h, Type *key) { + V *ptr = map_get(h, type_hash_canonical_type(key)); + GB_ASSERT(ptr != nullptr); + return *ptr; +} \ No newline at end of file