aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
diff options
context:
space:
mode:
authorClement Courbet <courbet@google.com>2022-09-12 10:13:14 +0200
committerClement Courbet <courbet@google.com>2022-09-22 11:11:18 +0200
commitcc61c822e05c51e494c50d1e72f963750116ef08 (patch)
treeeb6984e1d1433752236b96cb18156335d98300b9 /llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
parent983cb53845efde4b2a142a3e520ebe30c6673515 (diff)
downloadllvm-cc61c822e05c51e494c50d1e72f963750116ef08.zip
llvm-cc61c822e05c51e494c50d1e72f963750116ef08.tar.gz
llvm-cc61c822e05c51e494c50d1e72f963750116ef08.tar.bz2
[llvm-exegesis] Support analyzing results from a different target.
We were using the native triple to parse the benchmarks. Use the triple from the benchmarks file. Right now this still only allows analyzing files produced by the current target until D133605 is in. This also makes the `Analysis` class much less ad-hoc. Differential Revision: https://reviews.llvm.org/D133697
Diffstat (limited to 'llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp')
-rw-r--r--llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp86
1 files changed, 54 insertions, 32 deletions
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
index dbf0769..698c77d5 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -327,47 +327,69 @@ struct MappingContextTraits<exegesis::InstructionBenchmark, YamlContext> {
}
};
+template <> struct MappingTraits<exegesis::InstructionBenchmark::TripleAndCpu> {
+ static void mapping(IO &Io,
+ exegesis::InstructionBenchmark::TripleAndCpu &Obj) {
+ assert(!Io.outputting() && "can only read TripleAndCpu");
+ // Read triple.
+ Io.mapRequired("llvm_triple", Obj.LLVMTriple);
+ Io.mapRequired("cpu_name", Obj.CpuName);
+ // Drop everything else.
+ }
+};
+
} // namespace yaml
namespace exegesis {
-Expected<InstructionBenchmark>
-InstructionBenchmark::readYaml(const LLVMState &State, StringRef Filename) {
- if (auto ExpectedMemoryBuffer =
- errorOrToExpected(MemoryBuffer::getFile(Filename, /*IsText=*/true))) {
- yaml::Input Yin(*ExpectedMemoryBuffer.get());
- YamlContext Context(State);
- InstructionBenchmark Benchmark;
- if (Yin.setCurrentDocument())
- yaml::yamlize(Yin, Benchmark, /*unused*/ true, Context);
- if (!Context.getLastError().empty())
- return make_error<Failure>(Context.getLastError());
- return Benchmark;
- } else {
- return ExpectedMemoryBuffer.takeError();
+Expected<std::set<InstructionBenchmark::TripleAndCpu>>
+InstructionBenchmark::readTriplesAndCpusFromYamls(MemoryBufferRef Buffer) {
+ // We're only mapping a field, drop other fields and silence the corresponding
+ // warnings.
+ yaml::Input Yin(
+ Buffer, nullptr, +[](const SMDiagnostic &, void *Context) {});
+ Yin.setAllowUnknownKeys(true);
+ std::set<TripleAndCpu> Result;
+ yaml::EmptyContext Context;
+ while (Yin.setCurrentDocument()) {
+ TripleAndCpu TC;
+ yamlize(Yin, TC, /*unused*/ true, Context);
+ if (Yin.error())
+ return errorCodeToError(Yin.error());
+ Result.insert(TC);
+ Yin.nextDocument();
}
+ return Result;
+}
+
+Expected<InstructionBenchmark>
+InstructionBenchmark::readYaml(const LLVMState &State, MemoryBufferRef Buffer) {
+ yaml::Input Yin(Buffer);
+ YamlContext Context(State);
+ InstructionBenchmark Benchmark;
+ if (Yin.setCurrentDocument())
+ yaml::yamlize(Yin, Benchmark, /*unused*/ true, Context);
+ if (!Context.getLastError().empty())
+ return make_error<Failure>(Context.getLastError());
+ return Benchmark;
}
Expected<std::vector<InstructionBenchmark>>
-InstructionBenchmark::readYamls(const LLVMState &State, StringRef Filename) {
- if (auto ExpectedMemoryBuffer =
- errorOrToExpected(MemoryBuffer::getFile(Filename, /*IsText=*/true))) {
- yaml::Input Yin(*ExpectedMemoryBuffer.get());
- YamlContext Context(State);
- std::vector<InstructionBenchmark> Benchmarks;
- while (Yin.setCurrentDocument()) {
- Benchmarks.emplace_back();
- yamlize(Yin, Benchmarks.back(), /*unused*/ true, Context);
- if (Yin.error())
- return errorCodeToError(Yin.error());
- if (!Context.getLastError().empty())
- return make_error<Failure>(Context.getLastError());
- Yin.nextDocument();
- }
- return Benchmarks;
- } else {
- return ExpectedMemoryBuffer.takeError();
+InstructionBenchmark::readYamls(const LLVMState &State,
+ MemoryBufferRef Buffer) {
+ yaml::Input Yin(Buffer);
+ YamlContext Context(State);
+ std::vector<InstructionBenchmark> Benchmarks;
+ while (Yin.setCurrentDocument()) {
+ Benchmarks.emplace_back();
+ yamlize(Yin, Benchmarks.back(), /*unused*/ true, Context);
+ if (Yin.error())
+ return errorCodeToError(Yin.error());
+ if (!Context.getLastError().empty())
+ return make_error<Failure>(Context.getLastError());
+ Yin.nextDocument();
}
+ return Benchmarks;
}
Error InstructionBenchmark::writeYamlTo(const LLVMState &State,