Skip to content

Commit 8a855d6

Browse files
[SPIRV] Avoid repeated hash lookups (NFC) (#130241)
1 parent 8bf13af commit 8a855d6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,8 +1008,8 @@ SPIRVType *SPIRVGlobalRegistry::findSPIRVType(
10081008
Register Reg = DT.find(Ty, &MIRBuilder.getMF());
10091009
if (Reg.isValid())
10101010
return getSPIRVTypeForVReg(Reg);
1011-
if (ForwardPointerTypes.contains(Ty))
1012-
return ForwardPointerTypes[Ty];
1011+
if (auto It = ForwardPointerTypes.find(Ty); It != ForwardPointerTypes.end())
1012+
return It->second;
10131013
return restOfCreateSPIRVType(Ty, MIRBuilder, AccQual, EmitIR);
10141014
}
10151015

@@ -1103,14 +1103,15 @@ SPIRVType *SPIRVGlobalRegistry::createSPIRVType(
11031103
// Null pointer means we have a loop in type definitions, make and
11041104
// return corresponding OpTypeForwardPointer.
11051105
if (SpvElementType == nullptr) {
1106-
if (!ForwardPointerTypes.contains(Ty))
1107-
ForwardPointerTypes[Ty] = getOpTypeForwardPointer(SC, MIRBuilder);
1108-
return ForwardPointerTypes[Ty];
1106+
auto [It, Inserted] = ForwardPointerTypes.try_emplace(Ty);
1107+
if (Inserted)
1108+
It->second = getOpTypeForwardPointer(SC, MIRBuilder);
1109+
return It->second;
11091110
}
11101111
// If we have forward pointer associated with this type, use its register
11111112
// operand to create OpTypePointer.
1112-
if (ForwardPointerTypes.contains(Ty)) {
1113-
Register Reg = getSPIRVTypeID(ForwardPointerTypes[Ty]);
1113+
if (auto It = ForwardPointerTypes.find(Ty); It != ForwardPointerTypes.end()) {
1114+
Register Reg = getSPIRVTypeID(It->second);
11141115
return getOpTypePointer(SC, SpvElementType, MIRBuilder, Reg);
11151116
}
11161117

0 commit comments

Comments
 (0)