[llvm] [SPIRV] Avoid repeated hash lookups (NFC) (PR #129826)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 4 20:50:44 PST 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/129826
None
>From ddc23cf71f1c0ebbd7a5cc979e035f8b3d880ee3 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 4 Mar 2025 07:36:55 -0800
Subject: [PATCH] [SPIRV] Avoid repeated hash lookups (NFC)
---
llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp | 23 ++++++++++---------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
index 6d7fe408f9a14..32f817866d421 100644
--- a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
@@ -399,11 +399,11 @@ MCRegister SPIRVModuleAnalysis::handleFunctionOrParameter(
F = dyn_cast<Argument>(GObj)->getParent();
assert(F && "Expected a reference to a function or an argument");
IsFunDef = !F->isDeclaration();
- auto It = GlobalToGReg.find(GObj);
- if (It != GlobalToGReg.end())
+ auto [It, Inserted] = GlobalToGReg.try_emplace(GObj);
+ if (!Inserted)
return It->second;
MCRegister GReg = MAI.getNextIDRegister();
- GlobalToGReg[GObj] = GReg;
+ It->second = GReg;
if (!IsFunDef)
MAI.MS[SPIRV::MB_ExtFuncDecls].push_back(&MI);
return GReg;
@@ -413,11 +413,11 @@ MCRegister
SPIRVModuleAnalysis::handleTypeDeclOrConstant(const MachineInstr &MI,
InstrGRegsMap &SignatureToGReg) {
InstrSignature MISign = instrToSignature(MI, MAI, false);
- auto It = SignatureToGReg.find(MISign);
- if (It != SignatureToGReg.end())
+ auto [It, Inserted] = SignatureToGReg.try_emplace(MISign);
+ if (!Inserted)
return It->second;
MCRegister GReg = MAI.getNextIDRegister();
- SignatureToGReg[MISign] = GReg;
+ It->second = GReg;
MAI.MS[SPIRV::MB_TypeConstVars].push_back(&MI);
return GReg;
}
@@ -428,11 +428,11 @@ MCRegister SPIRVModuleAnalysis::handleVariable(
MAI.GlobalVarList.push_back(&MI);
const Value *GObj = GR->getGlobalObject(MF, MI.getOperand(0).getReg());
assert(GObj && "Unregistered global definition");
- auto It = GlobalToGReg.find(GObj);
- if (It != GlobalToGReg.end())
+ auto [It, Inserted] = GlobalToGReg.try_emplace(GObj);
+ if (!Inserted)
return It->second;
MCRegister GReg = MAI.getNextIDRegister();
- GlobalToGReg[GObj] = GReg;
+ It->second = GReg;
MAI.MS[SPIRV::MB_TypeConstVars].push_back(&MI);
return GReg;
}
@@ -605,8 +605,9 @@ void SPIRVModuleAnalysis::numberRegistersGlobally(const Module &M) {
if (MI.getOpcode() != SPIRV::OpExtInst)
continue;
auto Set = MI.getOperand(2).getImm();
- if (!MAI.ExtInstSetMap.contains(Set))
- MAI.ExtInstSetMap[Set] = MAI.getNextIDRegister();
+ auto [It, Inserted] = MAI.ExtInstSetMap.try_emplace(Set);
+ if (Inserted)
+ It->second = MAI.getNextIDRegister();
}
}
}
More information about the llvm-commits
mailing list