[llvm-exegesis] Add instructions to BenchmarkResult Key.
We want llvm-exegesis to explore instructions (effect of initial register values, effect of operand selection). To enable this a BenchmarkResult muststore all the relevant data in its key. This patch starts adding such data. Here we simply allow to store the generated instructions, following patches will add operands and initial values for registers.
https://reviews.llvm.org/D47764
Authored by: Guilluame Chatelet
llvm-svn: 334008
diff --git a/llvm/unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp b/llvm/unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp
index d3e3a5f..2c12c82 100644
--- a/llvm/unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp
+++ b/llvm/unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp
@@ -16,18 +16,35 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
+using ::testing::AllOf;
+using ::testing::Eq;
+using ::testing::get;
+using ::testing::Pointwise;
+using ::testing::Property;
+
namespace exegesis {
bool operator==(const BenchmarkMeasure &A, const BenchmarkMeasure &B) {
return std::tie(A.Key, A.Value) == std::tie(B.Key, B.Value);
}
+MATCHER(EqMCInst, "") {
+ return get<0>(arg).getOpcode() == get<1>(arg).getOpcode();
+}
+
namespace {
+static constexpr const unsigned kInstrId = 5;
+static constexpr const char kInstrName[] = "Instruction5";
+
TEST(BenchmarkResultTest, WriteToAndReadFromDisk) {
+ BenchmarkResultContext Ctx;
+ Ctx.addInstrEntry(kInstrId, kInstrName);
+
InstructionBenchmark ToDisk;
ToDisk.Key.OpcodeName = "name";
+ ToDisk.Key.Instructions.push_back(llvm::MCInstBuilder(kInstrId));
ToDisk.Key.Mode = InstructionBenchmarkKey::Latency;
ToDisk.Key.Config = "config";
ToDisk.CpuName = "cpu_name";
@@ -43,14 +60,15 @@
EC = llvm::sys::fs::createUniqueDirectory("BenchmarkResultTestDir", Filename);
ASSERT_FALSE(EC);
llvm::sys::path::append(Filename, "data.yaml");
-
- ToDisk.writeYamlOrDie(Filename);
+ ToDisk.writeYamlOrDie(Ctx, Filename);
{
// One-element version.
- const auto FromDisk = InstructionBenchmark::readYamlOrDie(Filename);
+ const auto FromDisk = InstructionBenchmark::readYamlOrDie(Ctx, Filename);
EXPECT_EQ(FromDisk.Key.OpcodeName, ToDisk.Key.OpcodeName);
+ EXPECT_THAT(FromDisk.Key.Instructions,
+ Pointwise(EqMCInst(), ToDisk.Key.Instructions));
EXPECT_EQ(FromDisk.Key.Mode, ToDisk.Key.Mode);
EXPECT_EQ(FromDisk.Key.Config, ToDisk.Key.Config);
EXPECT_EQ(FromDisk.CpuName, ToDisk.CpuName);
@@ -62,10 +80,13 @@
}
{
// Vector version.
- const auto FromDiskVector = InstructionBenchmark::readYamlsOrDie(Filename);
+ const auto FromDiskVector =
+ InstructionBenchmark::readYamlsOrDie(Ctx, Filename);
ASSERT_EQ(FromDiskVector.size(), size_t{1});
const auto FromDisk = FromDiskVector[0];
EXPECT_EQ(FromDisk.Key.OpcodeName, ToDisk.Key.OpcodeName);
+ EXPECT_THAT(FromDisk.Key.Instructions,
+ Pointwise(EqMCInst(), ToDisk.Key.Instructions));
EXPECT_EQ(FromDisk.Key.Mode, ToDisk.Key.Mode);
EXPECT_EQ(FromDisk.Key.Config, ToDisk.Key.Config);
EXPECT_EQ(FromDisk.CpuName, ToDisk.CpuName);