The idea is to later use these macros to mark the
  if (dump_enabled_p ())
parts of the compiler as cold, in the hope of helping non-PGO builds
of gcc.

I haven't measured it yet, though.

gcc/ChangeLog:
        * system.h (GCC_LIKELY, GCC_UNLIKELY): New macros, adapted from
        libgfortran.h.
---
 gcc/system.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/gcc/system.h b/gcc/system.h
index 88dffcc..195acb8 100644
--- a/gcc/system.h
+++ b/gcc/system.h
@@ -720,6 +720,18 @@ extern int vsnprintf (char *, size_t, const char *, 
va_list);
 #define __builtin_expect(a, b) (a)
 #endif
 
+/* The following macros can be used to annotate conditions which are likely or
+   unlikely to be true.  Avoid using them when a condition is only slightly
+   more likely/less unlikely than average to avoid the performance penalties of
+   branch misprediction. In addition, as __builtin_expect overrides the 
compiler
+   heuristic, do not use in conditions where one of the branches ends with a
+   call to a function with __attribute__((noreturn)): the compiler internal
+   heuristic will mark this branch as much less likely as GCC_UNLIKELY() would
+   do.  */
+
+#define GCC_LIKELY(X)       __builtin_expect(!!(X), 1)
+#define GCC_UNLIKELY(X)     __builtin_expect(!!(X), 0)
+
 /* Some of the headers included by <memory> can use "abort" within a
    namespace, e.g. "_VSTD::abort();", which fails after we use the
    preprocessor to redefine "abort" as "fancy_abort" below.
-- 
1.8.5.3

Reply via email to