[llvm] [llvm-exegesis] Add did-you-mean hint for unknown opcodes (PR #203463)

Min-Yih Hsu via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 12 09:50:29 PDT 2026


================
@@ -156,11 +158,44 @@ struct YamlContext {
     return InstrName;
   }
 
+  std::optional<StringRef> findNearestOpcodeName(StringRef InstrName) const {
+    unsigned BestDistance = 2;
+    StringRef Nearest;
+
+    for (const auto &Entry : OpcodeNameToOpcodeIdx) {
+      StringRef Candidate = Entry.getFirst();
+
+      size_t CandidateSize = Candidate.size();
+      size_t InstrSize = InstrName.size();
+      size_t AbsDiff = CandidateSize > InstrSize ? CandidateSize - InstrSize
+                                                 : InstrSize - CandidateSize;
+
+      if (AbsDiff >= BestDistance)
+        continue;
+
+      unsigned Distance =
----------------
mshockwave wrote:

I don't think edit distance here will ever be zero, right? In that case could we bail out as soon as BestDistance is one, to avoid scanning the rest of the table?

https://github.com/llvm/llvm-project/pull/203463


More information about the llvm-commits mailing list