[clang] 6a8fcb0 - [TableGen] Avoid repeated hash lookups (NFC) (#111089)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 4 07:37:34 PDT 2024
Author: Kazu Hirata
Date: 2024-10-04T07:37:31-07:00
New Revision: 6a8fcb0fa899af0b65caa3605fbed359189bed2f
URL: https://github.com/llvm/llvm-project/commit/6a8fcb0fa899af0b65caa3605fbed359189bed2f
DIFF: https://github.com/llvm/llvm-project/commit/6a8fcb0fa899af0b65caa3605fbed359189bed2f.diff
LOG: [TableGen] Avoid repeated hash lookups (NFC) (#111089)
Added:
Modified:
clang/utils/TableGen/MveEmitter.cpp
Removed:
################################################################################
diff --git a/clang/utils/TableGen/MveEmitter.cpp b/clang/utils/TableGen/MveEmitter.cpp
index 57e6353e60a141..915e914d6b9287 100644
--- a/clang/utils/TableGen/MveEmitter.cpp
+++ b/clang/utils/TableGen/MveEmitter.cpp
@@ -994,9 +994,10 @@ class EmitterBase {
const VectorType *getVectorType(const ScalarType *ST, unsigned Lanes) {
std::tuple<ScalarTypeKind, unsigned, unsigned> key(ST->kind(),
ST->sizeInBits(), Lanes);
- if (VectorTypes.find(key) == VectorTypes.end())
- VectorTypes[key] = std::make_unique<VectorType>(ST, Lanes);
- return VectorTypes[key].get();
+ auto [It, Inserted] = VectorTypes.try_emplace(key);
+ if (Inserted)
+ It->second = std::make_unique<VectorType>(ST, Lanes);
+ return It->second.get();
}
const VectorType *getVectorType(const ScalarType *ST) {
return getVectorType(ST, 128 / ST->sizeInBits());
@@ -1004,22 +1005,25 @@ class EmitterBase {
const MultiVectorType *getMultiVectorType(unsigned Registers,
const VectorType *VT) {
std::pair<std::string, unsigned> key(VT->cNameBase(), Registers);
- if (MultiVectorTypes.find(key) == MultiVectorTypes.end())
- MultiVectorTypes[key] = std::make_unique<MultiVectorType>(Registers, VT);
- return MultiVectorTypes[key].get();
+ auto [It, Inserted] = MultiVectorTypes.try_emplace(key);
+ if (Inserted)
+ It->second = std::make_unique<MultiVectorType>(Registers, VT);
+ return It->second.get();
}
const PredicateType *getPredicateType(unsigned Lanes) {
unsigned key = Lanes;
- if (PredicateTypes.find(key) == PredicateTypes.end())
- PredicateTypes[key] = std::make_unique<PredicateType>(Lanes);
- return PredicateTypes[key].get();
+ auto [It, Inserted] = PredicateTypes.try_emplace(key);
+ if (Inserted)
+ It->second = std::make_unique<PredicateType>(Lanes);
+ return It->second.get();
}
const PointerType *getPointerType(const Type *T, bool Const) {
PointerType PT(T, Const);
std::string key = PT.cName();
- if (PointerTypes.find(key) == PointerTypes.end())
- PointerTypes[key] = std::make_unique<PointerType>(PT);
- return PointerTypes[key].get();
+ auto [It, Inserted] = PointerTypes.try_emplace(key);
+ if (Inserted)
+ It->second = std::make_unique<PointerType>(PT);
+ return It->second.get();
}
// Methods to construct a type from various pieces of Tablegen. These are
More information about the cfe-commits
mailing list