Skip to content

[TableGen] Use heterogenous lookups with std::map (NFC) #115994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

kazutakahirata
Copy link
Contributor

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

Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.
@kazutakahirata kazutakahirata requested a review from nikic November 13, 2024 05:25
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Nov 13, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 13, 2024

@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/115994.diff

1 Files Affected:

  • (modified) clang/utils/TableGen/MveEmitter.cpp (+2-2)
diff --git a/clang/utils/TableGen/MveEmitter.cpp b/clang/utils/TableGen/MveEmitter.cpp
index 51e570944b49b6..5ae894d8e0718c 100644
--- a/clang/utils/TableGen/MveEmitter.cpp
+++ b/clang/utils/TableGen/MveEmitter.cpp
@@ -471,7 +471,7 @@ class Result {
 
 public:
   virtual ~Result() = default;
-  using Scope = std::map<std::string, Ptr>;
+  using Scope = std::map<std::string, Ptr, std::less<>>;
   virtual void genCode(raw_ostream &OS, CodeGenParamAllocator &) const = 0;
   virtual bool hasIntegerConstantValue() const { return false; }
   virtual uint32_t integerConstantValue() const { return 0; }
@@ -1278,7 +1278,7 @@ Result::Ptr EmitterBase::getCodeForDagArg(const DagInit *D, unsigned ArgNum,
     if (!isa<UnsetInit>(Arg))
       PrintFatalError(
           "dag operator argument should not have both a value and a name");
-    auto it = Scope.find(std::string(Name));
+    auto it = Scope.find(Name);
     if (it == Scope.end())
       PrintFatalError("unrecognized variable name '" + Name + "'");
     return it->second;

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

@kazutakahirata kazutakahirata merged commit 1884ffc into llvm:main Nov 13, 2024
10 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_heterogenous_TableGen branch November 13, 2024 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants