Skip to content

Commit 6a8fcb0

Browse files
[TableGen] Avoid repeated hash lookups (NFC) (llvm#111089)
1 parent 2997a67 commit 6a8fcb0

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

clang/utils/TableGen/MveEmitter.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -994,32 +994,36 @@ class EmitterBase {
994994
const VectorType *getVectorType(const ScalarType *ST, unsigned Lanes) {
995995
std::tuple<ScalarTypeKind, unsigned, unsigned> key(ST->kind(),
996996
ST->sizeInBits(), Lanes);
997-
if (VectorTypes.find(key) == VectorTypes.end())
998-
VectorTypes[key] = std::make_unique<VectorType>(ST, Lanes);
999-
return VectorTypes[key].get();
997+
auto [It, Inserted] = VectorTypes.try_emplace(key);
998+
if (Inserted)
999+
It->second = std::make_unique<VectorType>(ST, Lanes);
1000+
return It->second.get();
10001001
}
10011002
const VectorType *getVectorType(const ScalarType *ST) {
10021003
return getVectorType(ST, 128 / ST->sizeInBits());
10031004
}
10041005
const MultiVectorType *getMultiVectorType(unsigned Registers,
10051006
const VectorType *VT) {
10061007
std::pair<std::string, unsigned> key(VT->cNameBase(), Registers);
1007-
if (MultiVectorTypes.find(key) == MultiVectorTypes.end())
1008-
MultiVectorTypes[key] = std::make_unique<MultiVectorType>(Registers, VT);
1009-
return MultiVectorTypes[key].get();
1008+
auto [It, Inserted] = MultiVectorTypes.try_emplace(key);
1009+
if (Inserted)
1010+
It->second = std::make_unique<MultiVectorType>(Registers, VT);
1011+
return It->second.get();
10101012
}
10111013
const PredicateType *getPredicateType(unsigned Lanes) {
10121014
unsigned key = Lanes;
1013-
if (PredicateTypes.find(key) == PredicateTypes.end())
1014-
PredicateTypes[key] = std::make_unique<PredicateType>(Lanes);
1015-
return PredicateTypes[key].get();
1015+
auto [It, Inserted] = PredicateTypes.try_emplace(key);
1016+
if (Inserted)
1017+
It->second = std::make_unique<PredicateType>(Lanes);
1018+
return It->second.get();
10161019
}
10171020
const PointerType *getPointerType(const Type *T, bool Const) {
10181021
PointerType PT(T, Const);
10191022
std::string key = PT.cName();
1020-
if (PointerTypes.find(key) == PointerTypes.end())
1021-
PointerTypes[key] = std::make_unique<PointerType>(PT);
1022-
return PointerTypes[key].get();
1023+
auto [It, Inserted] = PointerTypes.try_emplace(key);
1024+
if (Inserted)
1025+
It->second = std::make_unique<PointerType>(PT);
1026+
return It->second.get();
10231027
}
10241028

10251029
// Methods to construct a type from various pieces of Tablegen. These are

0 commit comments

Comments
 (0)