[libc-commits] [libc] adc18ad - [libc] move benchmark function registration to a different file

Guillaume Chatelet via libc-commits libc-commits at lists.llvm.org
Thu Sep 30 06:11:46 PDT 2021


Author: Guillaume Chatelet
Date: 2021-09-30T13:11:33Z
New Revision: adc18ad6ac67658a237ffb345623f4cf78b9c3c8

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

LOG: [libc] move benchmark function registration to a different file

Added: 
    libc/benchmarks/LibcDefaultImplementations.cpp
    libc/benchmarks/LibcFunctionPrototypes.h

Modified: 
    libc/benchmarks/CMakeLists.txt
    libc/benchmarks/LibcMemoryBenchmark.h
    libc/benchmarks/LibcMemoryGoogleBenchmarkMain.cpp

Removed: 
    


################################################################################
diff  --git a/libc/benchmarks/CMakeLists.txt b/libc/benchmarks/CMakeLists.txt
index 2f06836b0fadd..18e5fc0c255c9 100644
--- a/libc/benchmarks/CMakeLists.txt
+++ b/libc/benchmarks/CMakeLists.txt
@@ -183,6 +183,7 @@ add_libc_multi_impl_benchmark(bcmp)
 add_executable(libc.benchmarks.memory_functions.opt_host
   EXCLUDE_FROM_ALL
   LibcMemoryGoogleBenchmarkMain.cpp
+  LibcDefaultImplementations.cpp
 )
 
 target_link_libraries(libc.benchmarks.memory_functions.opt_host

diff  --git a/libc/benchmarks/LibcDefaultImplementations.cpp b/libc/benchmarks/LibcDefaultImplementations.cpp
new file mode 100644
index 0000000000000..bf362f2b7c4f1
--- /dev/null
+++ b/libc/benchmarks/LibcDefaultImplementations.cpp
@@ -0,0 +1,46 @@
+#include "LibcFunctionPrototypes.h"
+#include "llvm/ADT/ArrayRef.h"
+#include <cstddef>
+
+namespace __llvm_libc {
+
+extern void *memcpy(void *__restrict, const void *__restrict, size_t);
+extern void *memset(void *, int, size_t);
+extern void bzero(void *, size_t);
+extern int memcmp(const void *, const void *, size_t);
+extern int bcmp(const void *, const void *, size_t);
+
+} // namespace __llvm_libc
+
+// List of implementations to test.
+
+using llvm::libc_benchmarks::BzeroConfiguration;
+using llvm::libc_benchmarks::MemcmpConfiguration;
+using llvm::libc_benchmarks::MemcpyConfiguration;
+using llvm::libc_benchmarks::MemsetConfiguration;
+
+llvm::ArrayRef<MemcpyConfiguration> getMemcpyConfigurations() {
+  static constexpr MemcpyConfiguration kMemcpyConfigurations[] = {
+      {__llvm_libc::memcpy, "__llvm_libc::memcpy"}};
+  return llvm::makeArrayRef(kMemcpyConfigurations);
+}
+llvm::ArrayRef<MemcmpConfiguration> getMemcmpConfigurations() {
+  static constexpr MemcmpConfiguration kMemcmpConfigurations[] = {
+      {__llvm_libc::memcmp, "__llvm_libc::memcmp"}};
+  return llvm::makeArrayRef(kMemcmpConfigurations);
+}
+llvm::ArrayRef<MemcmpConfiguration> getBcmpConfigurations() {
+  static constexpr MemcmpConfiguration kBcmpConfigurations[] = {
+      {__llvm_libc::bcmp, "__llvm_libc::bcmp"}};
+  return llvm::makeArrayRef(kBcmpConfigurations);
+}
+llvm::ArrayRef<MemsetConfiguration> getMemsetConfigurations() {
+  static constexpr MemsetConfiguration kMemsetConfigurations[] = {
+      {__llvm_libc::memset, "__llvm_libc::memset"}};
+  return llvm::makeArrayRef(kMemsetConfigurations);
+}
+llvm::ArrayRef<BzeroConfiguration> getBzeroConfigurations() {
+  static constexpr BzeroConfiguration kBzeroConfigurations[] = {
+      {__llvm_libc::bzero, "__llvm_libc::bzero"}};
+  return llvm::makeArrayRef(kBzeroConfigurations);
+}
\ No newline at end of file

diff  --git a/libc/benchmarks/LibcFunctionPrototypes.h b/libc/benchmarks/LibcFunctionPrototypes.h
new file mode 100644
index 0000000000000..e856c9138157e
--- /dev/null
+++ b/libc/benchmarks/LibcFunctionPrototypes.h
@@ -0,0 +1,38 @@
+#ifndef LLVM_LIBC_BENCHMARKS_LIBC_FUNCTION_PROTOTYPES_H
+#define LLVM_LIBC_BENCHMARKS_LIBC_FUNCTION_PROTOTYPES_H
+
+#include "llvm/ADT/StringRef.h"
+
+namespace llvm {
+namespace libc_benchmarks {
+
+/// Memory function prototype and configuration.
+using MemcpyFunction = void *(*)(void *__restrict, const void *__restrict,
+                                 size_t);
+struct MemcpyConfiguration {
+  MemcpyFunction Function;
+  llvm::StringRef Name;
+};
+
+using MemsetFunction = void *(*)(void *, int, size_t);
+struct MemsetConfiguration {
+  MemsetFunction Function;
+  llvm::StringRef Name;
+};
+
+using BzeroFunction = void (*)(void *, size_t);
+struct BzeroConfiguration {
+  BzeroFunction Function;
+  llvm::StringRef Name;
+};
+
+using MemcmpFunction = int (*)(const void *, const void *, size_t);
+struct MemcmpConfiguration {
+  MemcmpFunction Function;
+  llvm::StringRef Name;
+};
+
+} // namespace libc_benchmarks
+} // namespace llvm
+
+#endif /* LLVM_LIBC_BENCHMARKS_LIBC_FUNCTION_PROTOTYPES_H */

diff  --git a/libc/benchmarks/LibcMemoryBenchmark.h b/libc/benchmarks/LibcMemoryBenchmark.h
index 7badf046a25c3..eaba899544e25 100644
--- a/libc/benchmarks/LibcMemoryBenchmark.h
+++ b/libc/benchmarks/LibcMemoryBenchmark.h
@@ -13,6 +13,7 @@
 #define LLVM_LIBC_UTILS_BENCHMARK_MEMORY_BENCHMARK_H
 
 #include "LibcBenchmark.h"
+#include "LibcFunctionPrototypes.h"
 #include "MemorySizeDistributions.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Alignment.h"
@@ -186,32 +187,6 @@ struct ParameterBatch {
   std::vector<ParameterType> Parameters;
 };
 
-/// Memory function prototype and configuration.
-using MemcpyFunction = void *(*)(void *__restrict, const void *__restrict,
-                                 size_t);
-struct MemcpyConfiguration {
-  MemcpyFunction Function;
-  llvm::StringRef Name;
-};
-
-using MemsetFunction = void *(*)(void *, int, size_t);
-struct MemsetConfiguration {
-  MemsetFunction Function;
-  llvm::StringRef Name;
-};
-
-using BzeroFunction = void (*)(void *, size_t);
-struct BzeroConfiguration {
-  BzeroFunction Function;
-  llvm::StringRef Name;
-};
-
-using MemcmpFunction = int (*)(const void *, const void *, size_t);
-struct MemcmpConfiguration {
-  MemcmpFunction Function;
-  llvm::StringRef Name;
-};
-
 /// Provides source and destination buffers for the Copy operation as well as
 /// the associated size distributions.
 struct CopySetup : public ParameterBatch {

diff  --git a/libc/benchmarks/LibcMemoryGoogleBenchmarkMain.cpp b/libc/benchmarks/LibcMemoryGoogleBenchmarkMain.cpp
index e48b3a79c06c4..0941c739bc6fb 100644
--- a/libc/benchmarks/LibcMemoryGoogleBenchmarkMain.cpp
+++ b/libc/benchmarks/LibcMemoryGoogleBenchmarkMain.cpp
@@ -22,32 +22,6 @@ using llvm::libc_benchmarks::MemsetConfiguration;
 using llvm::libc_benchmarks::OffsetDistribution;
 using llvm::libc_benchmarks::SetSetup;
 
-namespace __llvm_libc {
-
-extern void *memcpy(void *__restrict, const void *__restrict, size_t);
-extern void *memset(void *, int, size_t);
-extern void bzero(void *, size_t);
-extern int memcmp(const void *, const void *, size_t);
-extern int bcmp(const void *, const void *, size_t);
-
-} // namespace __llvm_libc
-
-// List of implementations to test.
-static constexpr MemcpyConfiguration kMemcpyConfigurations[] = {
-    {__llvm_libc::memcpy, "__llvm_libc::memcpy"}};
-
-static constexpr MemcmpConfiguration kMemcmpConfigurations[] = {
-    {__llvm_libc::memcmp, "__llvm_libc::memcmp"}};
-
-static constexpr MemcmpConfiguration kBcmpConfigurations[] = {
-    {__llvm_libc::bcmp, "__llvm_libc::bcmp"}};
-
-static constexpr MemsetConfiguration kMemsetConfigurations[] = {
-    {__llvm_libc::memset, "__llvm_libc::memset"}};
-
-static constexpr BzeroConfiguration kBzeroConfigurations[] = {
-    {__llvm_libc::bzero, "__llvm_libc::bzero"}};
-
 // Alignment to use for when accessing the buffers.
 static constexpr Align kBenchmarkAlignment = Align::Constant<1>();
 
@@ -116,13 +90,22 @@ template <typename SetupType, typename ConfigurationType> struct Runner {
         benchmark->Args({DistIndex, ConfIndex});                               \
   })
 
+extern llvm::ArrayRef<MemcpyConfiguration> getMemcpyConfigurations();
 BENCHMARK_MEMORY_FUNCTION(BM_Memcpy, CopySetup, MemcpyConfiguration,
-                          llvm::makeArrayRef(kMemcpyConfigurations));
+                          getMemcpyConfigurations());
+
+extern llvm::ArrayRef<MemcmpConfiguration> getMemcmpConfigurations();
 BENCHMARK_MEMORY_FUNCTION(BM_Memcmp, ComparisonSetup, MemcmpConfiguration,
-                          llvm::makeArrayRef(kMemcmpConfigurations));
+                          getMemcmpConfigurations());
+
+extern llvm::ArrayRef<MemcmpConfiguration> getBcmpConfigurations();
 BENCHMARK_MEMORY_FUNCTION(BM_Bcmp, ComparisonSetup, MemcmpConfiguration,
-                          llvm::makeArrayRef(kBcmpConfigurations));
+                          getBcmpConfigurations());
+
+extern llvm::ArrayRef<MemsetConfiguration> getMemsetConfigurations();
 BENCHMARK_MEMORY_FUNCTION(BM_Memset, SetSetup, MemsetConfiguration,
-                          llvm::makeArrayRef(kMemsetConfigurations));
+                          getMemsetConfigurations());
+
+extern llvm::ArrayRef<BzeroConfiguration> getBzeroConfigurations();
 BENCHMARK_MEMORY_FUNCTION(BM_Bzero, SetSetup, BzeroConfiguration,
-                          llvm::makeArrayRef(kBzeroConfigurations));
+                          getBzeroConfigurations());


        


More information about the libc-commits mailing list