Improve implementation of pg_attribute_always_inline.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 24 Jan 2018 04:07:13 +0000 (23:07 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 24 Jan 2018 04:07:13 +0000 (23:07 -0500)
Avoid compiler warnings on MSVC (which doesn't want to see both
__forceinline and inline) and ancient GCC (which doesn't have
__attribute__((always_inline))).

Don't force inline-ing when building at -O0, as the programmer is probably
hoping for exact source-to-object-line correspondence in that case.
(For the moment this only works for GCC; maybe we can extend it later.)

Make pg_attribute_always_inline be syntactically a drop-in replacement
for inline, rather than an additional wart.

And improve the comments.

Thomas Munro and Michail Nikolaev, small tweaks by me

Discussion: https://postgr.es/m/32278.1514863068@sss.pgh.pa.us
Discussion: https://postgr.es/m/CANtu0oiYp74brgntKOxgg1FK5+t8uQ05guSiFU6FYz_5KUhr6Q@mail.gmail.com

src/backend/executor/nodeHashjoin.c
src/include/c.h

index 8f2b634b124ad7ad5fcacd14ad6b4c10cb1f13d9..03d78042fa092b15d43cd7a70a197b0fc61e6562 100644 (file)
@@ -161,8 +161,7 @@ static void ExecParallelHashJoinPartitionOuter(HashJoinState *node);
  *                       the other one is "outer".
  * ----------------------------------------------------------------
  */
-pg_attribute_always_inline
-static inline TupleTableSlot *
+static pg_attribute_always_inline TupleTableSlot *
 ExecHashJoinImpl(PlanState *pstate, bool parallel)
 {
        HashJoinState *node = castNode(HashJoinState, pstate);
index 34a7fa67b45e9f3d44a173934ef6b2b55957ea78..9b7fe87f32b65274d129f5b9930afaae35e54438 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 */
+/*
+ * Use "pg_attribute_always_inline" in place of "inline" for functions that
+ * we wish to force inlining of, even when the compiler's heuristics would
+ * choose not to.  But, if possible, don't force inlining in unoptimized
+ * debug builds.
+ */
+#if (defined(__GNUC__) && __GNUC__ > 3 && defined(__OPTIMIZE__)) || defined(__SUNPRO_C) || defined(__IBMC__)
+/* GCC > 3, Sunpro and XLC support always_inline via __attribute__ */
+#define pg_attribute_always_inline __attribute__((always_inline)) inline
 #elif defined(_MSC_VER)
+/* MSVC has a special keyword for this */
 #define pg_attribute_always_inline __forceinline
 #else
-#define pg_attribute_always_inline
+/* Otherwise, the best we can do is to say "inline" */
+#define pg_attribute_always_inline inline
 #endif
 
 /*