[PATCH] D46523: [llvm-exegesis] Allow lists of BenchmarkResults to be parsed as std::vector<BenchmarkResult>.

Clement Courbet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 7 06:02:04 PDT 2018


courbet created this revision.
Herald added a subscriber: tschuett.

Repository:
  rL LLVM

https://reviews.llvm.org/D46523

Files:
  tools/llvm-exegesis/lib/BenchmarkResult.cpp
  tools/llvm-exegesis/lib/BenchmarkResult.h
  unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp


Index: unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp
===================================================================
--- unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp
+++ unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp
@@ -44,6 +44,7 @@
   ToDisk.writeYamlOrDie(Filename);
 
   {
+    // One-element version.
     const auto FromDisk = InstructionBenchmark::readYamlOrDie(Filename);
 
     EXPECT_EQ(FromDisk.AsmTmpl.Name, ToDisk.AsmTmpl.Name);
@@ -53,6 +54,18 @@
     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);
+  }
 }
 
 } // namespace
Index: tools/llvm-exegesis/lib/BenchmarkResult.h
===================================================================
--- tools/llvm-exegesis/lib/BenchmarkResult.h
+++ tools/llvm-exegesis/lib/BenchmarkResult.h
@@ -43,6 +43,7 @@
   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);
Index: tools/llvm-exegesis/lib/BenchmarkResult.cpp
===================================================================
--- tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -54,18 +54,34 @@
 } // 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());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46523.145453.patch
Type: text/x-patch
Size: 3065 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180507/a2c50390/attachment.bin>


More information about the llvm-commits mailing list