[llvm] [SPIRV][NFC] Use DenseMap's lookup instead of find (PR #164237)

Juan Manuel Martinez CaamaƱo via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 20 04:38:00 PDT 2025


https://github.com/jmmartinez created https://github.com/llvm/llvm-project/pull/164237

[lookup](https://llvm.org/doxygen/classllvm_1_1DenseMapBase.html#a0b2ca98dc28c61793ff5c90d23e5f14e) does a find and returns the default if no matching element was found. Its implementation is:

```cpp
/// lookup - Return the entry for the specified key, or a default
/// constructed value if no such entry exists.
[[nodiscard]] ValueT lookup(const_arg_type_t<KeyT> Val) const {
  if (const BucketT *Bucket = doFind(Val))
    return Bucket->getSecond();
  return ValueT();
}
```

>From f7e77fc42b0763bafb636d2976d7f6326990b59b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?= <juamarti at amd.com>
Date: Mon, 20 Oct 2025 12:02:27 +0200
Subject: [PATCH] [SPIRV][NFC] Use DenseMap's lookup instead of find

---
 llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h
index d8376cd1aeb5a..2d19f6de604e4 100644
--- a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h
+++ b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h
@@ -169,9 +169,7 @@ struct ModuleAnalysisInfo {
 
   MCRegister getFuncReg(const Function *F) {
     assert(F && "Function is null");
-    auto FuncPtrRegPair = FuncMap.find(F);
-    return FuncPtrRegPair == FuncMap.end() ? MCRegister()
-                                           : FuncPtrRegPair->second;
+    return FuncMap.lookup(F);
   }
   MCRegister getExtInstSetReg(unsigned SetNum) { return ExtInstSetMap[SetNum]; }
   InstrList &getMSInstrs(unsigned MSType) { return MS[MSType]; }



More information about the llvm-commits mailing list