[libcxx] r344167 - Add test macros for always_inline and noinline

Eric Fiselier eric at efcs.ca
Wed Oct 10 11:22:23 PDT 2018


Author: ericwf
Date: Wed Oct 10 11:22:23 2018
New Revision: 344167

URL: http://llvm.org/viewvc/llvm-project?rev=344167&view=rev
Log:
Add test macros for always_inline and noinline

Modified:
    libcxx/trunk/benchmarks/stringstream.bench.cpp
    libcxx/trunk/benchmarks/unordered_set_operations.bench.cpp
    libcxx/trunk/test/support/test_macros.h

Modified: libcxx/trunk/benchmarks/stringstream.bench.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/benchmarks/stringstream.bench.cpp?rev=344167&r1=344166&r2=344167&view=diff
==============================================================================
--- libcxx/trunk/benchmarks/stringstream.bench.cpp (original)
+++ libcxx/trunk/benchmarks/stringstream.bench.cpp Wed Oct 10 11:22:23 2018
@@ -1,7 +1,9 @@
 #include "benchmark/benchmark.h"
+#include "test_macros.h"
 
 #include <sstream>
-double __attribute__((noinline)) istream_numbers();
+
+TEST_NOINLINE double istream_numbers();
 
 double istream_numbers() {
   const char *a[] = {

Modified: libcxx/trunk/benchmarks/unordered_set_operations.bench.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/benchmarks/unordered_set_operations.bench.cpp?rev=344167&r1=344166&r2=344167&view=diff
==============================================================================
--- libcxx/trunk/benchmarks/unordered_set_operations.bench.cpp (original)
+++ libcxx/trunk/benchmarks/unordered_set_operations.bench.cpp Wed Oct 10 11:22:23 2018
@@ -9,25 +9,26 @@
 
 #include "ContainerBenchmarks.hpp"
 #include "GenerateInput.hpp"
+#include "test_macros.h"
 
 using namespace ContainerBenchmarks;
 
 constexpr std::size_t TestNumInputs = 1024;
 
 template <class _Size>
-inline __attribute__((__always_inline__))
+inline TEST_ALWAYS_INLINE
 _Size loadword(const void* __p) {
     _Size __r;
     std::memcpy(&__r, __p, sizeof(__r));
     return __r;
 }
 
-inline __attribute__((__always_inline__))
+inline TEST_ALWAYS_INLINE
 std::size_t rotate_by_at_least_1(std::size_t __val, int __shift) {
     return (__val >> __shift) | (__val << (64 - __shift));
 }
 
-inline __attribute__((__always_inline__))
+inline TEST_ALWAYS_INLINE
 std::size_t hash_len_16(std::size_t __u, std::size_t __v) {
     const  std::size_t __mul = 0x9ddfea08eb382d69ULL;
     std::size_t __a = (__u ^ __v) * __mul;
@@ -40,7 +41,7 @@ std::size_t hash_len_16(std::size_t __u,
 
 
 template <std::size_t _Len>
-inline __attribute__((__always_inline__))
+inline TEST_ALWAYS_INLINE
 std::size_t hash_len_0_to_8(const char* __s) {
     static_assert(_Len == 4 || _Len == 8, "");
     const uint64_t __a = loadword<uint32_t>(__s);
@@ -50,7 +51,7 @@ std::size_t hash_len_0_to_8(const char*
 
 struct UInt32Hash {
   UInt32Hash() = default;
-  inline __attribute__((__always_inline__))
+  inline TEST_ALWAYS_INLINE
   std::size_t operator()(uint32_t data) const {
       return hash_len_0_to_8<4>(reinterpret_cast<const char*>(&data));
   }
@@ -58,7 +59,7 @@ struct UInt32Hash {
 
 struct UInt64Hash {
   UInt64Hash() = default;
-  inline __attribute__((__always_inline__))
+  inline TEST_ALWAYS_INLINE
   std::size_t operator()(uint64_t data) const {
       return hash_len_0_to_8<8>(reinterpret_cast<const char*>(&data));
   }
@@ -66,7 +67,7 @@ struct UInt64Hash {
 
 struct UInt128Hash {
   UInt128Hash() = default;
-  inline __attribute__((__always_inline__))
+  inline TEST_ALWAYS_INLINE
   std::size_t operator()(__uint128_t data) const {
       const __uint128_t __mask = static_cast<std::size_t>(-1);
       const std::size_t __a = (std::size_t)(data & __mask);
@@ -77,7 +78,7 @@ struct UInt128Hash {
 
 struct UInt32Hash2 {
   UInt32Hash2() = default;
-  inline __attribute__((__always_inline__))
+  inline TEST_ALWAYS_INLINE
   std::size_t operator()(uint32_t data) const {
       const uint32_t __m = 0x5bd1e995;
       const uint32_t __r = 24;
@@ -97,7 +98,7 @@ struct UInt32Hash2 {
 
 struct UInt64Hash2 {
   UInt64Hash2() = default;
-  inline __attribute__((__always_inline__))
+  inline TEST_ALWAYS_INLINE
   std::size_t operator()(uint64_t data) const {
       return hash_len_0_to_8<8>(reinterpret_cast<const char*>(&data));
   }

Modified: libcxx/trunk/test/support/test_macros.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/test_macros.h?rev=344167&r1=344166&r2=344167&view=diff
==============================================================================
--- libcxx/trunk/test/support/test_macros.h (original)
+++ libcxx/trunk/test/support/test_macros.h Wed Oct 10 11:22:23 2018
@@ -281,6 +281,16 @@ inline void DoNotOptimize(Tp const& valu
 }
 #endif
 
+#if defined(__GNUC__)
+#define TEST_ALWAYS_INLINE __attribute__((always_inline))
+#define TEST_NOINLINE __attribute__((noinline))
+#elif defined(_MSC_VER)
+#define TEST_ALWAYS_INLINE __forceinline
+#define TEST_NOINLINE __declspec(noinline)
+#else
+#define TEST_ALWAYS_INLINE
+#define TEST_NOINLINE
+#endif
 
 #if defined(__GNUC__)
 #pragma GCC diagnostic pop




More information about the libcxx-commits mailing list