Define pg_attribute_cold and pg_attribute_hot macros
authorDavid Rowley <drowley@postgresql.org>
Mon, 23 Nov 2020 22:29:28 +0000 (11:29 +1300)
committerDavid Rowley <drowley@postgresql.org>
Mon, 23 Nov 2020 22:29:28 +0000 (11:29 +1300)
For compilers supporting __has_attribute and __has_attribute (hot/cold).

__has_attribute is supported on gcc >= 5, clang >= 2.9 and icc >= 17.

A followup commit will implement some usages of these macros.

Author: David Rowley
Reviewed-by: Andres Freund, Peter Eisentraut
Discussion: https://postgr.es/m/CAApHDvrVpasrEzLL2er7p9iwZFZ%3DJj6WisePcFeunwfrV0js_A%40mail.gmail.com

src/include/c.h

index d5dc3632f74dfb48e38d7aece57ec0fd549f0e12..ff7c2eddcec6ff6b32f3204b349d06c6ff4b5ec7 100644 (file)
 #define pg_noinline
 #endif
 
+/*
+ * Marking certain functions as "hot" or "cold" can be useful to assist the
+ * compiler in arranging the assembly code in a more efficient way.
+ */
+#if defined(__has_attribute) && __has_attribute (cold)
+#define pg_attribute_cold __attribute__((cold))
+#else
+#define pg_attribute_cold
+#endif
+
+#if defined(__has_attribute) && __has_attribute (hot)
+#define pg_attribute_hot __attribute__((hot))
+#else
+#define pg_attribute_hot
+#endif
+
 /*
  * Mark a point as unreachable in a portable fashion.  This should preferably
  * be something that the compiler understands, to aid code generation.