[llvm] r332221 - [llvm-exegesis] Allow lists of BenchmarkResults to be parsed as std::vector<BenchmarkResult>.
Clement Courbet via llvm-commits
llvm-commits at lists.llvm.org
Mon May 14 02:01:22 PDT 2018
Author: courbet
Date: Mon May 14 02:01:22 2018
New Revision: 332221
URL: http://llvm.org/viewvc/llvm-project?rev=332221&view=rev
Log:
[llvm-exegesis] Allow lists of BenchmarkResults to be parsed as std::vector<BenchmarkResult>.
Modified:
llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp
llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.h
llvm/trunk/unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp
Modified: llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp?rev=332221&r1=332220&r2=332221&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp Mon May 14 02:01:22 2018
@@ -54,18 +54,34 @@ template <> struct MappingTraits<exegesi
} // namespace yaml
} // namespace llvm
+LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(exegesis::InstructionBenchmark)
+
namespace exegesis {
-InstructionBenchmark
-InstructionBenchmark::readYamlOrDie(llvm::StringRef Filename) {
+namespace {
+
+template <typename ObjectOrList>
+ObjectOrList readYamlOrDieCommon(llvm::StringRef Filename) {
std::unique_ptr<llvm::MemoryBuffer> MemBuffer = llvm::cantFail(
llvm::errorOrToExpected(llvm::MemoryBuffer::getFile(Filename)));
llvm::yaml::Input Yin(*MemBuffer);
- InstructionBenchmark Benchmark;
+ ObjectOrList Benchmark;
Yin >> Benchmark;
return Benchmark;
}
+} // namespace
+
+InstructionBenchmark
+InstructionBenchmark::readYamlOrDie(llvm::StringRef Filename) {
+ return readYamlOrDieCommon<InstructionBenchmark>(Filename);
+}
+
+std::vector<InstructionBenchmark>
+InstructionBenchmark::readYamlsOrDie(llvm::StringRef Filename) {
+ return readYamlOrDieCommon<std::vector<InstructionBenchmark>>(Filename);
+}
+
void InstructionBenchmark::writeYamlOrDie(const llvm::StringRef Filename) {
if (Filename == "-") {
llvm::yaml::Output Yout(llvm::outs());
Modified: llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.h?rev=332221&r1=332220&r2=332221&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.h Mon May 14 02:01:22 2018
@@ -43,6 +43,7 @@ struct InstructionBenchmark {
std::string Error;
static InstructionBenchmark readYamlOrDie(llvm::StringRef Filename);
+ static std::vector<InstructionBenchmark> readYamlsOrDie(llvm::StringRef Filename);
// Unfortunately this function is non const because of YAML traits.
void writeYamlOrDie(const llvm::StringRef Filename);
Modified: llvm/trunk/unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp?rev=332221&r1=332220&r2=332221&view=diff
==============================================================================
--- llvm/trunk/unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp (original)
+++ llvm/trunk/unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp Mon May 14 02:01:22 2018
@@ -44,11 +44,24 @@ TEST(BenchmarkResultTest, WriteToAndRead
ToDisk.writeYamlOrDie(Filename);
{
+ // One-element version.
const auto FromDisk = InstructionBenchmark::readYamlOrDie(Filename);
EXPECT_EQ(FromDisk.AsmTmpl.Name, ToDisk.AsmTmpl.Name);
EXPECT_EQ(FromDisk.CpuName, ToDisk.CpuName);
EXPECT_EQ(FromDisk.LLVMTriple, ToDisk.LLVMTriple);
+ EXPECT_EQ(FromDisk.NumRepetitions, ToDisk.NumRepetitions);
+ EXPECT_THAT(FromDisk.Measurements, ToDisk.Measurements);
+ EXPECT_THAT(FromDisk.Error, ToDisk.Error);
+ }
+ {
+ // Vector version.
+ const auto FromDiskVector = InstructionBenchmark::readYamlsOrDie(Filename);
+ ASSERT_EQ(FromDiskVector.size(), 1);
+ const auto FromDisk = FromDiskVector[0];
+ EXPECT_EQ(FromDisk.AsmTmpl.Name, ToDisk.AsmTmpl.Name);
+ EXPECT_EQ(FromDisk.CpuName, ToDisk.CpuName);
+ EXPECT_EQ(FromDisk.LLVMTriple, ToDisk.LLVMTriple);
EXPECT_EQ(FromDisk.NumRepetitions, ToDisk.NumRepetitions);
EXPECT_THAT(FromDisk.Measurements, ToDisk.Measurements);
EXPECT_THAT(FromDisk.Error, ToDisk.Error);
More information about the llvm-commits
mailing list