[clang] [TableGen] Avoid repeated hash lookups (NFC) (PR #111089)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 3 19:59:05 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/111089
None
>From 14a0790867efd134b4ae0ceafeddb58e504929ec Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 3 Oct 2024 08:46:35 -0700
Subject: [PATCH] [TableGen] Avoid repeated hash lookups (NFC)
---
clang/utils/TableGen/MveEmitter.cpp | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
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