Skip to content
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

[lld][RISCV] Avoid second map lookup in mergeArch. NFC #84687

Merged
merged 1 commit into from
Mar 12, 2024

Conversation

topperc
Copy link
Collaborator

@topperc topperc commented Mar 10, 2024

Instead of using find and then an inserting into the map, we can use insert and fix up the version using the iterator if the insert fails.

Instead of using find and then an inserting into the map, we can
use insert and fix up the version using the iterator if the insert
fails.
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 10, 2024

@llvm/pr-subscribers-lld

@llvm/pr-subscribers-lld-elf

Author: Craig Topper (topperc)

Changes

Instead of using find and then an inserting into the map, we can use insert and fix up the version using the iterator if the insert fails.


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

1 Files Affected:

  • (modified) lld/ELF/Arch/RISCV.cpp (+4-4)
diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index 4798c86f7d1b61..20de1b9b7bde96 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -1074,12 +1074,12 @@ static void mergeArch(RISCVISAInfo::OrderedExtensionMap &mergedExts,
     mergedXlen = info.getXLen();
   } else {
     for (const auto &ext : info.getExtensions()) {
-      if (auto it = mergedExts.find(ext.first); it != mergedExts.end()) {
-        if (std::tie(it->second.Major, it->second.Minor) >=
+      auto p = mergedExts.insert(ext);
+      if (!p.second) {
+        if (std::tie(p.first->second.Major, p.first->second.Minor) <
             std::tie(ext.second.Major, ext.second.Minor))
-          continue;
+          p.first->second = ext.second;
       }
-      mergedExts[ext.first] = ext.second;
     }
   }
 }

@topperc topperc merged commit 8d61f82 into llvm:main Mar 12, 2024
7 checks passed
@topperc topperc deleted the pr/mergeArch branch March 12, 2024 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants