[llvm] c1a155b - [llvm-exegesis] Refactor BenchmarkMeasure instantiation in tests

Aiden Grossman via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 26 17:02:47 PST 2024


Author: Aiden Grossman
Date: 2024-01-26T17:00:57-08:00
New Revision: c1a155bf785152abc72b77608261a3d0e6c776a6

URL: https://github.com/llvm/llvm-project/commit/c1a155bf785152abc72b77608261a3d0e6c776a6
DIFF: https://github.com/llvm/llvm-project/commit/c1a155bf785152abc72b77608261a3d0e6c776a6.diff

LOG: [llvm-exegesis] Refactor BenchmarkMeasure instantiation in tests

This patch refactors the instantiation of BenchmarkMeasure within all
the unit tests to use BenchmarkMeasure::Create rather than through
direct struct instantialization. This allows us to change what values
are stored in BenchmarkMeasure without getting compiler warnings on
every instantiation in the unit tests, and is also just a cleanup in
general as the Create function didn't seem to exist at the time the unit
tests were originally written.

Added: 
    

Modified: 
    llvm/unittests/tools/llvm-exegesis/ClusteringTest.cpp
    llvm/unittests/tools/llvm-exegesis/Mips/BenchmarkResultTest.cpp
    llvm/unittests/tools/llvm-exegesis/X86/BenchmarkResultTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/tools/llvm-exegesis/ClusteringTest.cpp b/llvm/unittests/tools/llvm-exegesis/ClusteringTest.cpp
index 26bb6c5d2e4c2f0..f914800056c364d 100644
--- a/llvm/unittests/tools/llvm-exegesis/ClusteringTest.cpp
+++ b/llvm/unittests/tools/llvm-exegesis/ClusteringTest.cpp
@@ -31,18 +31,23 @@ TEST(ClusteringTest, Clusters3D) {
   std::vector<Benchmark> Points(6);
 
   // Cluster around (x=0, y=1, z=2): points {0, 3}.
-  Points[0].Measurements = {
-      {"x", 0.01, 0.0, {}}, {"y", 1.02, 0.0, {}}, {"z", 1.98, 0.0, {}}};
-  Points[3].Measurements = {
-      {"x", -0.01, 0.0, {}}, {"y", 1.02, 0.0, {}}, {"z", 1.98, 0.0, {}}};
+  Points[0].Measurements = {BenchmarkMeasure::Create("x", 0.01, {}),
+                            BenchmarkMeasure::Create("y", 1.02, {}),
+                            BenchmarkMeasure::Create("z", 1.98, {})};
+  Points[3].Measurements = {BenchmarkMeasure::Create("x", -0.01, {}),
+                            BenchmarkMeasure::Create("y", 1.02, {}),
+                            BenchmarkMeasure::Create("z", 1.98, {})};
   // Cluster around (x=1, y=1, z=2): points {1, 4}.
-  Points[1].Measurements = {
-      {"x", 1.01, 0.0, {}}, {"y", 1.02, 0.0, {}}, {"z", 1.98, 0.0, {}}};
-  Points[4].Measurements = {
-      {"x", 0.99, 0.0, {}}, {"y", 1.02, 0.0, {}}, {"z", 1.98, 0.0, {}}};
+  Points[1].Measurements = {BenchmarkMeasure::Create("x", 1.01, {}),
+                            BenchmarkMeasure::Create("y", 1.02, {}),
+                            BenchmarkMeasure::Create("z", 1.98, {})};
+  Points[4].Measurements = {BenchmarkMeasure::Create("x", 0.99, {}),
+                            BenchmarkMeasure::Create("y", 1.02, {}),
+                            BenchmarkMeasure::Create("z", 1.98, {})};
   // Cluster around (x=0, y=0, z=0): points {5}, marked as noise.
-  Points[5].Measurements = {
-      {"x", 0.0, 0.0, {}}, {"y", 0.01, 0.0, {}}, {"z", -0.02, 0.0, {}}};
+  Points[5].Measurements = {BenchmarkMeasure::Create("x", 0.0, {}),
+                            BenchmarkMeasure::Create("y", 0.01, {}),
+                            BenchmarkMeasure::Create("z", -0.02, {})};
   // Error cluster: points {2}
   Points[2].Error = "oops";
 
@@ -70,9 +75,11 @@ TEST(ClusteringTest, Clusters3D) {
 
 TEST(ClusteringTest, Clusters3D_InvalidSize) {
   std::vector<Benchmark> Points(6);
-  Points[0].Measurements = {
-      {"x", 0.01, 0.0, {}}, {"y", 1.02, 0.0, {}}, {"z", 1.98, 0.0, {}}};
-  Points[1].Measurements = {{"y", 1.02, 0.0, {}}, {"z", 1.98, 0.0, {}}};
+  Points[0].Measurements = {BenchmarkMeasure::Create("x", 0.01, {}),
+                            BenchmarkMeasure::Create("y", 1.02, {}),
+                            BenchmarkMeasure::Create("z", 1.98, {})};
+  Points[1].Measurements = {BenchmarkMeasure::Create("y", 1.02, {}),
+                            BenchmarkMeasure::Create("z", 1.98, {})};
   auto Error =
       BenchmarkClustering::create(
           Points, BenchmarkClustering::ModeE::Dbscan, 2, 0.25)
@@ -83,8 +90,10 @@ TEST(ClusteringTest, Clusters3D_InvalidSize) {
 
 TEST(ClusteringTest, Clusters3D_InvalidOrder) {
   std::vector<Benchmark> Points(6);
-  Points[0].Measurements = {{"x", 0.01, 0.0, {}}, {"y", 1.02, 0.0, {}}};
-  Points[1].Measurements = {{"y", 1.02, 0.0, {}}, {"x", 1.98, 0.0, {}}};
+  Points[0].Measurements = {BenchmarkMeasure::Create("x", 0.01, {}),
+                            BenchmarkMeasure::Create("y", 1.02, {})};
+  Points[1].Measurements = {BenchmarkMeasure::Create("y", 1.02, {}),
+                            BenchmarkMeasure::Create("x", 1.98, {})};
   auto Error =
       BenchmarkClustering::create(
           Points, BenchmarkClustering::ModeE::Dbscan, 2, 0.25)
@@ -110,9 +119,9 @@ TEST(ClusteringTest, Ordering) {
 TEST(ClusteringTest, Ordering1) {
   std::vector<Benchmark> Points(3);
 
-  Points[0].Measurements = {{"x", 0.0, 0.0, {}}};
-  Points[1].Measurements = {{"x", 1.0, 0.0, {}}};
-  Points[2].Measurements = {{"x", 2.0, 0.0, {}}};
+  Points[0].Measurements = {BenchmarkMeasure::Create("x", 0.0, {})};
+  Points[1].Measurements = {BenchmarkMeasure::Create("x", 1.0, {})};
+  Points[2].Measurements = {BenchmarkMeasure::Create("x", 2.0, {})};
 
   auto Clustering = BenchmarkClustering::create(
       Points, BenchmarkClustering::ModeE::Dbscan, 2, 1.1);
@@ -124,9 +133,9 @@ TEST(ClusteringTest, Ordering1) {
 TEST(ClusteringTest, Ordering2) {
   std::vector<Benchmark> Points(3);
 
-  Points[0].Measurements = {{"x", 0.0, 0.0, {}}};
-  Points[1].Measurements = {{"x", 2.0, 0.0, {}}};
-  Points[2].Measurements = {{"x", 1.0, 0.0, {}}};
+  Points[0].Measurements = {BenchmarkMeasure::Create("x", 0.0, {})};
+  Points[1].Measurements = {BenchmarkMeasure::Create("x", 2.0, {})};
+  Points[2].Measurements = {BenchmarkMeasure::Create("x", 1.0, {})};
 
   auto Clustering = BenchmarkClustering::create(
       Points, BenchmarkClustering::ModeE::Dbscan, 2, 1.1);

diff  --git a/llvm/unittests/tools/llvm-exegesis/Mips/BenchmarkResultTest.cpp b/llvm/unittests/tools/llvm-exegesis/Mips/BenchmarkResultTest.cpp
index 3d02b8f648411d7..9e2016d0d348229 100644
--- a/llvm/unittests/tools/llvm-exegesis/Mips/BenchmarkResultTest.cpp
+++ b/llvm/unittests/tools/llvm-exegesis/Mips/BenchmarkResultTest.cpp
@@ -65,8 +65,8 @@ TEST_F(MipsBenchmarkResultTest, WriteToAndReadFromDisk) {
   ToDisk.CpuName = "cpu_name";
   ToDisk.LLVMTriple = "llvm_triple";
   ToDisk.NumRepetitions = 1;
-  ToDisk.Measurements.push_back(BenchmarkMeasure{"a", 1, 1, {}});
-  ToDisk.Measurements.push_back(BenchmarkMeasure{"b", 2, 2, {}});
+  ToDisk.Measurements.push_back(BenchmarkMeasure::Create("a", 1, {}));
+  ToDisk.Measurements.push_back(BenchmarkMeasure::Create("b", 2, {}));
   ToDisk.Error = "error";
   ToDisk.Info = "info";
 
@@ -124,10 +124,10 @@ TEST_F(MipsBenchmarkResultTest, WriteToAndReadFromDisk) {
 
 TEST_F(MipsBenchmarkResultTest, PerInstructionStats) {
   PerInstructionStats Stats;
-  Stats.push(BenchmarkMeasure{"a", 0.5, 0.0, {}});
-  Stats.push(BenchmarkMeasure{"a", 1.5, 0.0, {}});
-  Stats.push(BenchmarkMeasure{"a", -1.0, 0.0, {}});
-  Stats.push(BenchmarkMeasure{"a", 0.0, 0.0, {}});
+  Stats.push(BenchmarkMeasure::Create("a", 0.5, {}));
+  Stats.push(BenchmarkMeasure::Create("a", 1.5, {}));
+  Stats.push(BenchmarkMeasure::Create("a", -1.0, {}));
+  Stats.push(BenchmarkMeasure::Create("a", 0.0, {}));
   EXPECT_EQ(Stats.min(), -1.0);
   EXPECT_EQ(Stats.max(), 1.5);
   EXPECT_EQ(Stats.avg(), 0.25); // (0.5+1.5-1.0+0.0) / 4

diff  --git a/llvm/unittests/tools/llvm-exegesis/X86/BenchmarkResultTest.cpp b/llvm/unittests/tools/llvm-exegesis/X86/BenchmarkResultTest.cpp
index fafd08131dffc60..415b22f911463ee 100644
--- a/llvm/unittests/tools/llvm-exegesis/X86/BenchmarkResultTest.cpp
+++ b/llvm/unittests/tools/llvm-exegesis/X86/BenchmarkResultTest.cpp
@@ -84,8 +84,8 @@ TEST(BenchmarkResultTest, WriteToAndReadFromDisk) {
   ToDisk.CpuName = "cpu_name";
   ToDisk.LLVMTriple = "llvm_triple";
   ToDisk.NumRepetitions = 1;
-  ToDisk.Measurements.push_back(BenchmarkMeasure{"a", 1, 1, {}});
-  ToDisk.Measurements.push_back(BenchmarkMeasure{"b", 2, 2, {}});
+  ToDisk.Measurements.push_back(BenchmarkMeasure::Create("a", 1, {}));
+  ToDisk.Measurements.push_back(BenchmarkMeasure::Create("b", 2, {}));
   ToDisk.Error = "error";
   ToDisk.Info = "info";
 
@@ -162,10 +162,10 @@ TEST(BenchmarkResultTest, WriteToAndReadFromDisk) {
 
 TEST(BenchmarkResultTest, PerInstructionStats) {
   PerInstructionStats Stats;
-  Stats.push(BenchmarkMeasure{"a", 0.5, 0.0, {}});
-  Stats.push(BenchmarkMeasure{"a", 1.5, 0.0, {}});
-  Stats.push(BenchmarkMeasure{"a", -1.0, 0.0, {}});
-  Stats.push(BenchmarkMeasure{"a", 0.0, 0.0, {}});
+  Stats.push(BenchmarkMeasure::Create("a", 0.5, {}));
+  Stats.push(BenchmarkMeasure::Create("a", 1.5, {}));
+  Stats.push(BenchmarkMeasure::Create("a", -1.0, {}));
+  Stats.push(BenchmarkMeasure::Create("a", 0.0, {}));
   EXPECT_EQ(Stats.min(), -1.0);
   EXPECT_EQ(Stats.max(), 1.5);
   EXPECT_EQ(Stats.avg(), 0.25); // (0.5+1.5-1.0+0.0) / 4


        


More information about the llvm-commits mailing list