From 2c2e0f6e483f32b061d48f7567d72b1f5960140a Mon Sep 17 00:00:00 2001 From: Elizabeth Smith Date: Wed, 16 Apr 2014 13:45:37 -0700 Subject: [PATCH] MSVC always_inline and noinline __attributes__ translation Summary: Provide translations for gcc always_inline and noinline attribute Change to using a macro from portability.h for attributes for using always_inline and noinline for cross platform support Test Plan: fbmake runtests Reviewed By: delong.j@fb.com FB internal diff: D1279652 --- folly/Portability.h | 17 +++++++++++++++++ folly/detail/MemoryIdler.cpp | 2 +- .../exception_tracer/ExceptionTracerLib.cpp | 2 +- folly/experimental/symbolizer/SignalHandler.cpp | 2 +- folly/experimental/symbolizer/Symbolizer.h | 4 ++-- .../symbolizer/test/StackTraceTest.cpp | 4 ++-- .../symbolizer/test/SymbolizerTest.cpp | 2 +- 7 files changed, 25 insertions(+), 8 deletions(-) diff --git a/folly/Portability.h b/folly/Portability.h index ab41ef4c..d7ef09bd 100644 --- a/folly/Portability.h +++ b/folly/Portability.h @@ -50,6 +50,23 @@ struct MaxAlign { char c; } __attribute__((aligned)); # define FOLLY_NORETURN #endif +// noinline +#ifdef _MSC_VER +# define FOLLY_NOINLINE __declspec(noinline) +#elif defined(__clang__) || defined(__GNUC__) +# define FOLLY_NOINLINE __attribute__((noinline)) +#else +# define FOLLY_NOINLINE +#endif + +// always inline +#ifdef _MSC_VER +# define FOLLY_ALWAYS_INLINE __forceinline +#elif defined(__clang__) || defined(__GNUC__) +# define FOLLY_ALWAYS_INLINE inline __attribute__((always_inline)) +#else +# define FOLLY_ALWAYS_INLINE +#endif // portable version check #ifndef __GNUC_PREREQ diff --git a/folly/detail/MemoryIdler.cpp b/folly/detail/MemoryIdler.cpp index 680a7562..2d026e48 100644 --- a/folly/detail/MemoryIdler.cpp +++ b/folly/detail/MemoryIdler.cpp @@ -130,7 +130,7 @@ static void fetchStackLimits() { assert((tls_stackLimit & (s_pageSize - 1)) == 0); } -static __attribute__((noinline)) uintptr_t getStackPtr() { +FOLLY_NOINLINE static uintptr_t getStackPtr() { char marker; auto rv = uintptr_t(&marker); return rv; diff --git a/folly/experimental/exception_tracer/ExceptionTracerLib.cpp b/folly/experimental/exception_tracer/ExceptionTracerLib.cpp index 61803e7d..b04983bc 100644 --- a/folly/experimental/exception_tracer/ExceptionTracerLib.cpp +++ b/folly/experimental/exception_tracer/ExceptionTracerLib.cpp @@ -96,7 +96,7 @@ extern "C" StackTraceStack* getExceptionStackTraceStack() { namespace { // Make sure we're counting stack frames correctly, don't inline. -void addActiveException() __attribute__((noinline)); +FOLLY_NOINLINE void addActiveException(); void addActiveException() { pthread_once(&initialized, initialize); diff --git a/folly/experimental/symbolizer/SignalHandler.cpp b/folly/experimental/symbolizer/SignalHandler.cpp index 79f17f98..f8e03a7b 100644 --- a/folly/experimental/symbolizer/SignalHandler.cpp +++ b/folly/experimental/symbolizer/SignalHandler.cpp @@ -198,7 +198,7 @@ constexpr size_t kDefaultCapacity = 500; auto gSignalSafeElfCache = new SignalSafeElfCache(kDefaultCapacity); } // namespace -void dumpStackTrace(bool symbolize) __attribute__((noinline)); +FOLLY_NOINLINE void dumpStackTrace(bool symbolize); void dumpStackTrace(bool symbolize) { SCOPE_EXIT { fsyncNoInt(STDERR_FILENO); }; diff --git a/folly/experimental/symbolizer/Symbolizer.h b/folly/experimental/symbolizer/Symbolizer.h index b4e96902..00006141 100644 --- a/folly/experimental/symbolizer/Symbolizer.h +++ b/folly/experimental/symbolizer/Symbolizer.h @@ -91,14 +91,14 @@ bool fixFrameArray(FrameArray& fa, ssize_t n) { // Always inline these functions; they don't do much, and unittests rely // on them never showing up in a stack trace. template -inline bool getStackTrace(FrameArray& fa) __attribute__((always_inline)); +FOLLY_ALWAYS_INLINE bool getStackTrace(FrameArray& fa); template inline bool getStackTrace(FrameArray& fa) { return detail::fixFrameArray(fa, getStackTrace(fa.addresses, N)); } template -inline bool getStackTraceSafe(FrameArray& fa) __attribute__((always_inline)); +FOLLY_ALWAYS_INLINE bool getStackTraceSafe(FrameArray& fa); template inline bool getStackTraceSafe(FrameArray& fa) { diff --git a/folly/experimental/symbolizer/test/StackTraceTest.cpp b/folly/experimental/symbolizer/test/StackTraceTest.cpp index a7241256..7bd19df9 100644 --- a/folly/experimental/symbolizer/test/StackTraceTest.cpp +++ b/folly/experimental/symbolizer/test/StackTraceTest.cpp @@ -23,8 +23,8 @@ using namespace folly; using namespace folly::symbolizer; -void foo1() __attribute__((noinline)); -void foo2() __attribute__((noinline)); +FOLLY_NOINLINE void foo1(); +FOLLY_NOINLINE void foo2(); void verifyStackTraces() { constexpr size_t kMaxAddresses = 100; diff --git a/folly/experimental/symbolizer/test/SymbolizerTest.cpp b/folly/experimental/symbolizer/test/SymbolizerTest.cpp index cd2ab95b..d283dc82 100644 --- a/folly/experimental/symbolizer/test/SymbolizerTest.cpp +++ b/folly/experimental/symbolizer/test/SymbolizerTest.cpp @@ -55,7 +55,7 @@ int comparator(const void* ap, const void* bp) { } // Test stack frames... -void bar() __attribute__((noinline)); +FOLLY_NOINLINE void bar(); void bar() { int a[2] = {1, 2}; -- 2.34.1