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

via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 7 10:54:17 PST 2024


Author: Kazu Hirata
Date: 2024-11-07T10:54:12-08:00
New Revision: 7bd9be2e0a74e6d17ec3f95ff364a4461dec4dbe

URL: https://github.com/llvm/llvm-project/commit/7bd9be2e0a74e6d17ec3f95ff364a4461dec4dbe
DIFF: https://github.com/llvm/llvm-project/commit/7bd9be2e0a74e6d17ec3f95ff364a4461dec4dbe.diff

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

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

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/HIPUtility.cpp

Removed: 
    


################################################################################
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