Repository navigation
[llvm-exegesis] Add did-you-mean hint for unknown opcodes - #203463
Conversation
Signed-off-by: quanyeyang <[email protected]>
|
Hello @quanyeyang 👋 Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.
Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description. Frequently asked questionsHow do I add reviewers? This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically. You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using What if there are no comments? If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers. Are any special GitHub settings required to contribute to LLVM? We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details. If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse. Thank you, |
|
@llvm/pr-subscribers-tools-llvm-exegesis Author: Quanye Yang (quanyeyang) ChangesFixes #203199 When skipping a benchmark entry with an unknown opcode name, suggest the Example: And Tested with:
2 Files Affected:
diff --git a/llvm/test/tools/llvm-exegesis/X86/analysis-unknown-opcode-did-you-mean.test b/llvm/test/tools/llvm-exegesis/X86/analysis-unknown-opcode-did-you-mean.test
new file mode 100644
index 0000000000000..32fe6c965ba72
--- /dev/null
+++ b/llvm/test/tools/llvm-exegesis/X86/analysis-unknown-opcode-did-you-mean.test
@@ -0,0 +1,39 @@
+# Verify that skipping an entry with a misspelled opcode name includes a
+# "did you mean ?" hint when a close match exists.
+
+# RUN: llvm-exegesis -mode=analysis -benchmarks-file=%s -analysis-clusters-output-file=- -analysis-clustering-epsilon=0.1 -analysis-inconsistency-epsilon=0.1 -analysis-numpoints=1 2> %t.err | FileCheck -check-prefix=CHECK-CLUSTERS %s
+# RUN: FileCheck -check-prefix=CHECK-WARN %s < %t.err
+
+# CHECK-WARN: warning: skipping benchmark entry: No opcode with name 'VADDPDYrrr' - did you mean 'VADDPDYrr' ?
+# CHECK-WARN: warning: skipped 1 benchmark entries that could not be parsed
+
+# CHECK-CLUSTERS: {{^}}cluster_id,opcode_name,config,sched_class,
+# CHECK-CLUSTERS-NEXT: {{^}}0,
+
+---
+mode: uops
+key:
+ instructions:
+ - 'VADDPDYrrr RAX'
+ config: ''
+ register_initial_values: []
+cpu_name: znver3
+llvm_triple: x86_64-pc-linux-gnu
+num_repetitions: 10000
+measurements: []
+error: ''
+...
+---
+mode: uops
+key:
+ instructions:
+ - 'CMOV16rm AX AX RDI i_0x1 %noreg i_0x0 %noreg i_0x0'
+ config: ''
+ register_initial_values: []
+cpu_name: znver3
+llvm_triple: x86_64-pc-linux-gnu
+num_repetitions: 10000
+measurements:
+ - { key: NumMicroOps, value: 1.0146, per_snippet_value: 14.2044 }
+error: ''
+...
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
index 1d1a376d3505b..018cbcb7941e4 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -16,11 +16,13 @@
#include "llvm/ADT/bit.h"
#include "llvm/ObjectYAML/YAML.h"
#include "llvm/Support/Errc.h"
+#include "llvm/Support/Error.h"
#include "llvm/Support/FileOutputBuffer.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
+#include <optional>
static constexpr char kIntegerPrefix[] = "i_0x";
static constexpr char kDoublePrefix[] = "f_";
@@ -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 =
+ InstrName.edit_distance(Candidate, /*AllowReplacements=*/true,
+ /*MaxEditDistance=*/BestDistance - 1);
+
+ if (Distance < BestDistance) {
+ BestDistance = Distance;
+ Nearest = Candidate;
+ }
+ }
+
+ if (BestDistance <= 1 && !Nearest.empty())
+ return Nearest;
+ return std::nullopt;
+ }
+
unsigned getInstrOpcode(StringRef InstrName) {
auto Iter = OpcodeNameToOpcodeIdx.find(InstrName);
if (Iter != OpcodeNameToOpcodeIdx.end())
return Iter->second;
- ErrorStream << "No opcode with name '" << InstrName << "'\n";
+ ErrorStream << "No opcode with name '" << InstrName << "'";
+ if (std::optional<StringRef> Nearest = findNearestOpcodeName(InstrName))
+ ErrorStream << " - did you mean '" << *Nearest << "' ?";
+ ErrorStream << "\n";
return 0;
}
|
|
|
||
| size_t CandidateSize = Candidate.size(); | ||
| size_t InstrSize = InstrName.size(); | ||
| size_t AbsDiff = CandidateSize > InstrSize ? CandidateSize - InstrSize |
There was a problem hiding this comment.
In llvm/lib/Option/OptTable.cpp, OptTable::internalFindNearest(), the codes are like:
size_t CandidateSize = CandidatePrefix.size() + CandidateName.size(),
NormalizedSize = NormalizedName.size();
size_t AbsDiff = CandidateSize > NormalizedSize
? CandidateSize - NormalizedSize
: NormalizedSize - CandidateSize;or we can change the codes like?
size_t AbsDiff = std::abs(static_cast<ptrdiff_t>(CandidateSize) -
static_cast<ptrdiff_t>(InstrSize));There was a problem hiding this comment.
size_t AbsDiff = std::abs(static_cast<ptrdiff_t>(CandidateSize) -
static_cast<ptrdiff_t>(InstrSize));
yeah, something like this. I just checked LLVM's own llvm/Support/MathExtras.h, and I think llvm::AbsoluteDifference might be better because you can pass unsigned type: AbsoluteDifference(CandidateSize, InstrSize)
I only saw changes on one of these test files. Do you forget to |
Signed-off-by: quanyeyang <[email protected]>
I didn't change |
mshockwave
left a comment
There was a problem hiding this comment.
LGTM w/ the AbsoluteDifference comment fixed
Signed-off-by: quanyeyang <[email protected]>
|
@quanyeyang Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/159/builds/49158 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/175/builds/40943 Here is the relevant piece of the build log for the reference |
Fixes llvm#203199 When skipping a benchmark entry with an unknown opcode name, suggest the nearest matching opcode if the edit distance is <= 1 (similar to OptTable::findNearest). Example: ```text warning: skipping benchmark entry: No opcode with name 'VADDPDYrrr' - did you mean 'VADDPDYrr' ? ``` And Tested with: - `llvm-lit llvm/test/tools/llvm-exegesis/X86/analysis-unknown-opcode-did-you-mean.test` - `llvm-lit llvm/test/tools/llvm-exegesis/X86/analysis-skip-unknown-opcode.test` --------- Signed-off-by: quanyeyang <[email protected]>
Fixes #203199
When skipping a benchmark entry with an unknown opcode name, suggest the
nearest matching opcode if the edit distance is <= 1 (similar to
OptTable::findNearest).
Example:
And Tested with:
llvm-lit llvm/test/tools/llvm-exegesis/X86/analysis-unknown-opcode-did-you-mean.testllvm-lit llvm/test/tools/llvm-exegesis/X86/analysis-skip-unknown-opcode.test