summaryrefslogtreecommitdiff
path: root/libc/benchmarks
diff options
context:
space:
mode:
authorGuillaume Chatelet <gchatelet@google.com>2021-09-30 13:10:45 +0000
committerGuillaume Chatelet <gchatelet@google.com>2021-09-30 13:11:33 +0000
commitadc18ad6ac67658a237ffb345623f4cf78b9c3c8 (patch)
tree961021af18e69a23866bf5e9f6b872e7d2717989 /libc/benchmarks
parentdea48079b90d40f2087435b778544dffb0ab1793 (diff)
downloadllvm-adc18ad6ac67658a237ffb345623f4cf78b9c3c8.tar.gz
[libc] move benchmark function registration to a different file
Diffstat (limited to 'libc/benchmarks')
-rw-r--r--libc/benchmarks/CMakeLists.txt1
-rw-r--r--libc/benchmarks/LibcDefaultImplementations.cpp46
-rw-r--r--libc/benchmarks/LibcFunctionPrototypes.h38
-rw-r--r--libc/benchmarks/LibcMemoryBenchmark.h27
-rw-r--r--libc/benchmarks/LibcMemoryGoogleBenchmarkMain.cpp45
5 files changed, 100 insertions, 57 deletions
diff --git a/libc/benchmarks/CMakeLists.txt b/libc/benchmarks/CMakeLists.txt
index 2f06836b0fad..18e5fc0c255c 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 000000000000..bf362f2b7c4f
--- /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 000000000000..e856c9138157
--- /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 7badf046a25c..eaba899544e2 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 e48b3a79c06c..0941c739bc6f 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 @@ private:
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());