[clang] [Driver] Use heterogenous lookups with std::set (NFC) (PR #115259)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 6 20:21:05 PST 2024


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

Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.


>From b2db4f214c295b54ed14c662e27587346a28d210 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 6 Nov 2024 08:55:41 -0800
Subject: [PATCH] [Driver] Use heterogenous lookups with std::set (NFC)

Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.
---
 clang/lib/Driver/ToolChains/HIPUtility.cpp | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/HIPUtility.cpp b/clang/lib/Driver/ToolChains/HIPUtility.cpp
index c8075cbfe36b35..3f81c3cb0f80e8 100644
--- a/clang/lib/Driver/ToolChains/HIPUtility.cpp
+++ b/clang/lib/Driver/ToolChains/HIPUtility.cpp
@@ -148,8 +148,8 @@ class HIPUndefinedFatBinSymbols {
   bool Verbose;
   std::set<std::string> FatBinSymbols;
   std::set<std::string> GPUBinHandleSymbols;
-  std::set<std::string> DefinedFatBinSymbols;
-  std::set<std::string> DefinedGPUBinHandleSymbols;
+  std::set<std::string, std::less<>> DefinedFatBinSymbols;
+  std::set<std::string, std::less<>> DefinedGPUBinHandleSymbols;
   const std::string FatBinPrefix = "__hip_fatbin";
   const std::string GPUBinHandlePrefix = "__hip_gpubin_handle";
 
@@ -260,11 +260,10 @@ class HIPUndefinedFatBinSymbols {
 
       // Add undefined symbols if they are not in the defined sets
       if (isFatBinSymbol &&
-          DefinedFatBinSymbols.find(Name.str()) == DefinedFatBinSymbols.end())
+          DefinedFatBinSymbols.find(Name) == DefinedFatBinSymbols.end())
         FatBinSymbols.insert(Name.str());
-      else if (isGPUBinHandleSymbol &&
-               DefinedGPUBinHandleSymbols.find(Name.str()) ==
-                   DefinedGPUBinHandleSymbols.end())
+      else if (isGPUBinHandleSymbol && DefinedGPUBinHandleSymbols.find(Name) ==
+                                           DefinedGPUBinHandleSymbols.end())
         GPUBinHandleSymbols.insert(Name.str());
     }
   }



More information about the cfe-commits mailing list