[llvm] efdd660 - [SPIRV] Avoid repeated hash lookups (NFC) (#129826)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 5 00:45:31 PST 2025
Author: Kazu Hirata
Date: 2025-03-05T00:45:28-08:00
New Revision: efdd66034f455f3f493d4b1e4ed265b67470af01
URL: https://github.com/llvm/llvm-project/commit/efdd66034f455f3f493d4b1e4ed265b67470af01
DIFF: https://github.com/llvm/llvm-project/commit/efdd66034f455f3f493d4b1e4ed265b67470af01.diff
LOG: [SPIRV] Avoid repeated hash lookups (NFC) (#129826)
Added:
Modified:
llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
Removed:
################################################################################
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