]> granicus.if.org Git - postgresql/commitdiff
Add pg_attribute_always_inline.
authorAndres Freund <andres@anarazel.de>
Wed, 13 Dec 2017 23:34:20 +0000 (15:34 -0800)
committerAndres Freund <andres@anarazel.de>
Wed, 13 Dec 2017 23:46:02 +0000 (15:46 -0800)
Sometimes it is useful to be able to insist that the compiler inline a
function that its normal cost analysis would not normally choose to inline.
This can be useful for instantiating different variants of a function that
remove branches of code by constant folding.

Author: Thomas Munro
Reviewed-By: Andres Freund
Discussion: https://postgr.es/m/CAEepm=09rr65VN+cAV5FgyM_z=D77Xy8Fuc9CDDDYbq3pQUezg@mail.gmail.com

src/include/c.h

index a61428843a8886eba4024e1f0be80d5acd1c89f2..11fcffbae3954da4941d005f36fa8cbe92ecc746 100644 (file)
 #define pg_attribute_noreturn()
 #endif
 
+/* GCC, Sunpro and XLC support always_inline via __attribute__ */
+#if defined(__GNUC__)
+#define pg_attribute_always_inline __attribute__((always_inline))
+/* msvc via a special keyword */
+#elif defined(_MSC_VER)
+#define pg_attribute_always_inline __forceinline
+#else
+#define pg_attribute_always_inline
+#endif
+
 /*
  * Forcing a function not to be inlined can be useful if it's the slow path of
  * a performance-critical function, or should be visible in profiles to allow