Author: Alex Langford Date: 2023-06-08T15:13:55-07:00 New Revision: b1a7b7f6d55ed33166008a4d23d598582237b69d
URL: https://github.com/llvm/llvm-project/commit/b1a7b7f6d55ed33166008a4d23d598582237b69d DIFF: https://github.com/llvm/llvm-project/commit/b1a7b7f6d55ed33166008a4d23d598582237b69d.diff LOG: [lldb][NFCI] Refactor TypeSystemClang::GetBasicTypeEnumeration `TypeSystemClang::GetBasicTypeEnumeration(ConstString)` builds up a giant `UniqueCStringMap<lldb::BasicType>` which is effectively a vector whose elements are (ConstString, lldb::BasicType). Once sorted, we get to have fairly quick lookups (O(log n) on average). This is fine, but we can do better on average with an llvm::StringMap. This also allows us to simplify the initialization code for the lookup, no more `once_flag`! Additionally, I removed unused declarations of related functions from CompilerType and TypeSystemClang Differential Revision: https://reviews.llvm.org/D152315 Added: Modified: lldb/include/lldb/Symbol/CompilerType.h lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h Removed: ################################################################################ diff --git a/lldb/include/lldb/Symbol/CompilerType.h b/lldb/include/lldb/Symbol/CompilerType.h index 1d2244297cb0a..2d7092d2c93f8 100644 --- a/lldb/include/lldb/Symbol/CompilerType.h +++ b/lldb/include/lldb/Symbol/CompilerType.h @@ -344,8 +344,6 @@ class CompilerType { lldb::BasicType GetBasicTypeEnumeration() const; - static lldb::BasicType GetBasicTypeEnumeration(ConstString name); - /// If this type is an enumeration, iterate through all of its enumerators /// using a callback. If the callback returns true, keep iterating, else abort /// the iteration. diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index b7ecde9790e05..6506f118f8c65 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -864,70 +864,62 @@ TypeSystemClang::GetBuiltinTypeForEncodingAndBitSize(Encoding encoding, return CompilerType(); } -lldb::BasicType -TypeSystemClang::GetBasicTypeEnumeration(ConstString name) { - if (name) { - typedef UniqueCStringMap<lldb::BasicType> TypeNameToBasicTypeMap; - static TypeNameToBasicTypeMap g_type_map; - static llvm::once_flag g_once_flag; - llvm::call_once(g_once_flag, []() { +lldb::BasicType TypeSystemClang::GetBasicTypeEnumeration(llvm::StringRef name) { + static const llvm::StringMap<lldb::BasicType> g_type_map = { // "void" - g_type_map.Append(ConstString("void"), eBasicTypeVoid); + {"void", eBasicTypeVoid}, // "char" - g_type_map.Append(ConstString("char"), eBasicTypeChar); - g_type_map.Append(ConstString("signed char"), eBasicTypeSignedChar); - g_type_map.Append(ConstString("unsigned char"), eBasicTypeUnsignedChar); - g_type_map.Append(ConstString("wchar_t"), eBasicTypeWChar); - g_type_map.Append(ConstString("signed wchar_t"), eBasicTypeSignedWChar); - g_type_map.Append(ConstString("unsigned wchar_t"), - eBasicTypeUnsignedWChar); + {"char", eBasicTypeChar}, + {"signed char", eBasicTypeSignedChar}, + {"unsigned char", eBasicTypeUnsignedChar}, + {"wchar_t", eBasicTypeWChar}, + {"signed wchar_t", eBasicTypeSignedWChar}, + {"unsigned wchar_t", eBasicTypeUnsignedWChar}, + // "short" - g_type_map.Append(ConstString("short"), eBasicTypeShort); - g_type_map.Append(ConstString("short int"), eBasicTypeShort); - g_type_map.Append(ConstString("unsigned short"), eBasicTypeUnsignedShort); - g_type_map.Append(ConstString("unsigned short int"), - eBasicTypeUnsignedShort); + {"short", eBasicTypeShort}, + {"short int", eBasicTypeShort}, + {"unsigned short", eBasicTypeUnsignedShort}, + {"unsigned short int", eBasicTypeUnsignedShort}, // "int" - g_type_map.Append(ConstString("int"), eBasicTypeInt); - g_type_map.Append(ConstString("signed int"), eBasicTypeInt); - g_type_map.Append(ConstString("unsigned int"), eBasicTypeUnsignedInt); - g_type_map.Append(ConstString("unsigned"), eBasicTypeUnsignedInt); + {"int", eBasicTypeInt}, + {"signed int", eBasicTypeInt}, + {"unsigned int", eBasicTypeUnsignedInt}, + {"unsigned", eBasicTypeUnsignedInt}, // "long" - g_type_map.Append(ConstString("long"), eBasicTypeLong); - g_type_map.Append(ConstString("long int"), eBasicTypeLong); - g_type_map.Append(ConstString("unsigned long"), eBasicTypeUnsignedLong); - g_type_map.Append(ConstString("unsigned long int"), - eBasicTypeUnsignedLong); + {"long", eBasicTypeLong}, + {"long int", eBasicTypeLong}, + {"unsigned long", eBasicTypeUnsignedLong}, + {"unsigned long int", eBasicTypeUnsignedLong}, // "long long" - g_type_map.Append(ConstString("long long"), eBasicTypeLongLong); - g_type_map.Append(ConstString("long long int"), eBasicTypeLongLong); - g_type_map.Append(ConstString("unsigned long long"), - eBasicTypeUnsignedLongLong); - g_type_map.Append(ConstString("unsigned long long int"), - eBasicTypeUnsignedLongLong); + {"long long", eBasicTypeLongLong}, + {"long long int", eBasicTypeLongLong}, + {"unsigned long long", eBasicTypeUnsignedLongLong}, + {"unsigned long long int", eBasicTypeUnsignedLongLong}, // "int128" - g_type_map.Append(ConstString("__int128_t"), eBasicTypeInt128); - g_type_map.Append(ConstString("__uint128_t"), eBasicTypeUnsignedInt128); + {"__int128_t", eBasicTypeInt128}, + {"__uint128_t", eBasicTypeUnsignedInt128}, // Miscellaneous - g_type_map.Append(ConstString("bool"), eBasicTypeBool); - g_type_map.Append(ConstString("float"), eBasicTypeFloat); - g_type_map.Append(ConstString("double"), eBasicTypeDouble); - g_type_map.Append(ConstString("long double"), eBasicTypeLongDouble); - g_type_map.Append(ConstString("id"), eBasicTypeObjCID); - g_type_map.Append(ConstString("SEL"), eBasicTypeObjCSel); - g_type_map.Append(ConstString("nullptr"), eBasicTypeNullPtr); - g_type_map.Sort(); - }); - - return g_type_map.Find(name, eBasicTypeInvalid); - } - return eBasicTypeInvalid; + {"bool", eBasicTypeBool}, + {"float", eBasicTypeFloat}, + {"double", eBasicTypeDouble}, + {"long double", eBasicTypeLongDouble}, + {"id", eBasicTypeObjCID}, + {"SEL", eBasicTypeObjCSel}, + {"nullptr", eBasicTypeNullPtr}, + }; + + auto iter = g_type_map.find(name); + if (iter == g_type_map.end()) + return eBasicTypeInvalid; + + return iter->second; } uint32_t TypeSystemClang::GetPointerByteSize() { diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h index 7ab588656666b..bafae2e8a1da5 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h @@ -207,7 +207,7 @@ class TypeSystemClang : public TypeSystem { CompilerType GetBasicType(lldb::BasicType type); - static lldb::BasicType GetBasicTypeEnumeration(ConstString name); + static lldb::BasicType GetBasicTypeEnumeration(llvm::StringRef name); CompilerType GetBuiltinTypeForDWARFEncodingAndBitSize(llvm::StringRef type_name, @@ -834,10 +834,6 @@ class TypeSystemClang : public TypeSystem { lldb::BasicType GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) override; - static lldb::BasicType - GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type, - ConstString name); - void ForEachEnumerator( lldb::opaque_compiler_type_t type, std::function<bool(const CompilerType &integer_type, _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits