[clang] [Tablegen] Avoid repeated hash lookps (NFC) (PR #107961)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 9 20:44:54 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/107961

None

>From c995b27c81f0342ebbb44ce3dbf98d8415e507e4 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 9 Sep 2024 07:34:57 -0700
Subject: [PATCH] [Tablegen] Avoid repeated hash lookps (NFC)

---
 .../TableGen/ClangOpenCLBuiltinEmitter.cpp     | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)

diff --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index 968b3e0661a8f3..74c3a856ab6937 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -510,10 +510,7 @@ void BuiltinNameEmitter::GetOverloads() {
   std::vector<Record *> Builtins = Records.getAllDerivedDefinitions("Builtin");
   for (const auto *B : Builtins) {
     StringRef BName = B->getValueAsString("Name");
-    if (!FctOverloadMap.contains(BName)) {
-      FctOverloadMap.insert(std::make_pair(
-          BName, std::vector<std::pair<const Record *, unsigned>>{}));
-    }
+    FctOverloadMap.try_emplace(BName);
 
     auto Signature = B->getValueAsListOfDefs("Signature");
     // Reuse signatures to avoid unnecessary duplicates.
@@ -812,17 +809,8 @@ static void OCL2Qual(Sema &S, const OpenCLTypeStruct &Ty,
 
   // Map an image type name to its 3 access-qualified types (RO, WO, RW).
   StringMap<SmallVector<Record *, 3>> ImageTypesMap;
-  for (auto *IT : ImageTypes) {
-    auto Entry = ImageTypesMap.find(IT->getValueAsString("Name"));
-    if (Entry == ImageTypesMap.end()) {
-      SmallVector<Record *, 3> ImageList;
-      ImageList.push_back(IT);
-      ImageTypesMap.insert(
-          std::make_pair(IT->getValueAsString("Name"), ImageList));
-    } else {
-      Entry->second.push_back(IT);
-    }
-  }
+  for (auto *IT : ImageTypes)
+    ImageTypesMap[IT->getValueAsString("Name")].push_back(IT);
 
   // Emit the cases for the image types.  For an image type name, there are 3
   // corresponding QualTypes ("RO", "WO", "RW").  The "AccessQualifier" field



More information about the cfe-commits mailing list