[Git][ghc/ghc][wip/kill-pre-c11] 2 commits: WIP: always assume __GNUC__ >= 4

Cheng Shao (@TerrorJack) gitlab at gitlab.haskell.org
Sun Jun 9 09:16:22 UTC 2024



Cheng Shao pushed to branch wip/kill-pre-c11 at Glasgow Haskell Compiler / GHC


Commits:
abf49dc8 by Cheng Shao at 2024-06-09T09:11:03+00:00
WIP: always assume __GNUC__ >= 4

- - - - -
68514576 by Cheng Shao at 2024-06-09T09:16:04+00:00
WIP

- - - - -


11 changed files:

- libraries/ghc-prim/cbits/atomic.c
- libraries/ghc-prim/cbits/ctz.c
- rts/Hash.c
- rts/RtsStartup.c
- rts/RtsSymbols.c
- rts/include/Rts.h
- rts/include/Stg.h
- rts/include/rts/Types.h
- rts/include/stg/DLL.h
- rts/sm/BlockAlloc.c
- rts/sm/Evac.h


Changes:

=====================================
libraries/ghc-prim/cbits/atomic.c
=====================================
@@ -163,7 +163,7 @@ hs_atomic_and64(StgWord x, StgWord64 val)
 #pragma GCC diagnostic push
 #if defined(__clang__)
 #pragma GCC diagnostic ignored "-Wsync-fetch-and-nand-semantics-changed"
-#elif defined(__GNUC__)
+#else
 #pragma GCC diagnostic ignored "-Wsync-nand"
 #endif
 


=====================================
libraries/ghc-prim/cbits/ctz.c
=====================================
@@ -31,7 +31,7 @@ hs_ctz32(StgWord x)
 StgWord
 hs_ctz64(StgWord64 x)
 {
-#if defined(__GNUC__) && (defined(i386_HOST_ARCH) || defined(powerpc_HOST_ARCH))
+#if defined(i386_HOST_ARCH) || defined(powerpc_HOST_ARCH)
   /* On Linux/i386, the 64bit `__builtin_ctzll()` intrinsic doesn't
      get inlined by GCC but rather a short `__ctzdi2` runtime function
      is inserted when needed into compiled object files.


=====================================
rts/Hash.c
=====================================
@@ -14,18 +14,6 @@
 #include "Hash.h"
 #include "RtsUtils.h"
 
-/* This file needs to be compiled with vectorization enabled.  Unfortunately
-   since we compile these things these days with cabal we can no longer
-   specify optimization per file.  So we have to resort to pragmas.  */
-#if defined(__GNUC__) || defined(__GNUG__)
-#if !defined(__clang__)
-#if !defined(DEBUG)
-#pragma GCC push_options
-#pragma GCC optimize ("O3")
-#endif
-#endif
-#endif
-
 #define XXH_INLINE_ALL
 
 #include "xxhash.h"
@@ -563,12 +551,3 @@ int keyCountHashTable (HashTable *table)
 {
     return table->kcount;
 }
-
-
-#if defined(__GNUC__) || defined(__GNUG__)
-#if !defined(__clang__)
-#if !defined(DEBUG)
-#pragma GCC pop_options
-#endif
-#endif
-#endif


=====================================
rts/RtsStartup.c
=====================================
@@ -123,13 +123,7 @@ void _fpreset(void)
     x86_init_fpu();
 }
 
-#if defined(__GNUC__)
 void __attribute__((alias("_fpreset"))) fpreset(void);
-#else
-void fpreset(void) {
-    _fpreset();
-}
-#endif
 
 /* Set the console's CodePage to UTF-8 if using the new I/O manager and the CP
    is still the default one.  */


=====================================
rts/RtsSymbols.c
=====================================
@@ -956,7 +956,7 @@ extern char **environ;
       RTS_INTCHAR_SYMBOLS
 
 // 64-bit support functions in libgcc.a
-#if defined(__GNUC__) && SIZEOF_VOID_P <= 4 && !defined(_ABIN32)
+#if SIZEOF_VOID_P <= 4 && !defined(_ABIN32)
 #define RTS_LIBGCC_SYMBOLS                             \
       SymI_NeedsProto(__divdi3)                        \
       SymI_NeedsProto(__udivdi3)                       \
@@ -967,7 +967,7 @@ extern char **environ;
       SymI_NeedsProto(__ashrdi3)                       \
       SymI_NeedsProto(__lshrdi3)                       \
       SymI_NeedsProto(__fixunsdfdi)
-#elif defined(__GNUC__) && SIZEOF_VOID_P == 8
+#elif SIZEOF_VOID_P == 8
 #define RTS_LIBGCC_SYMBOLS                             \
       SymI_NeedsProto(__udivti3)                       \
       SymI_NeedsProto(__umodti3)


=====================================
rts/include/Rts.h
=====================================
@@ -54,39 +54,22 @@ extern "C" {
 #include "rts/Types.h"
 #include "rts/Time.h"
 
-#if __GNUC__ >= 3
 #define ATTRIBUTE_ALIGNED(n) __attribute__((aligned(n)))
-#else
-#define ATTRIBUTE_ALIGNED(n) /*nothing*/
-#endif
 
 // Symbols that are extern, but private to the RTS, are declared
 // with visibility "hidden" to hide them outside the RTS shared
 // library.
 #if defined(HAS_VISIBILITY_HIDDEN)
-#define RTS_PRIVATE  GNUC3_ATTRIBUTE(visibility("hidden"))
+#define RTS_PRIVATE  __attribute__((visibility("hidden")))
 #else
 #define RTS_PRIVATE  /* disabled: RTS_PRIVATE */
 #endif
 
-#if __GNUC__ >= 4
 #define RTS_UNLIKELY(p) __builtin_expect((p),0)
-#else
-#define RTS_UNLIKELY(p) (p)
-#endif
 
-#if __GNUC__ >= 4
 #define RTS_LIKELY(p) __builtin_expect(!!(p), 1)
-#else
-#define RTS_LIKELY(p) (p)
-#endif
 
-/* __builtin_unreachable is supported since GNU C 4.5 */
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
 #define RTS_UNREACHABLE __builtin_unreachable()
-#else
-#define RTS_UNREACHABLE abort()
-#endif
 
 /* Prefetch primitives */
 #define prefetchForRead(ptr) __builtin_prefetch(ptr, 0)
@@ -377,17 +360,8 @@ TICK_VAR(2)
    Useful macros and inline functions
    -------------------------------------------------------------------------- */
 
-#if defined(__GNUC__)
-#define SUPPORTS_TYPEOF
-#endif
-
-#if defined(SUPPORTS_TYPEOF)
 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
-#else
-#define stg_min(a,b) ((a) <= (b) ? (a) : (b))
-#define stg_max(a,b) ((a) <= (b) ? (b) : (a))
-#endif
 
 /* -------------------------------------------------------------------------- */
 


=====================================
rts/include/Stg.h
=====================================
@@ -128,67 +128,42 @@
 #  define EXTERN_INLINE static inline
 # endif
 
-/*
- * GCC attributes
- */
-#if defined(__GNUC__)
-#define GNU_ATTRIBUTE(at) __attribute__((at))
-#else
-#define GNU_ATTRIBUTE(at)
-#endif
-
-#if __GNUC__ >= 3
-#define GNUC3_ATTRIBUTE(at) __attribute__((at))
-#else
-#define GNUC3_ATTRIBUTE(at)
-#endif
-
 /* Used to mark a switch case that falls-through */
 #if (defined(__GNUC__) && __GNUC__ >= 7)
 // N.B. Don't enable fallthrough annotations when compiling with Clang.
 // Apparently clang doesn't enable implicitly fallthrough warnings by default
 // http://llvm.org/viewvc/llvm-project?revision=167655&view=revision
 // when compiling C and the attribute cause warnings of their own (#16019).
-#define FALLTHROUGH GNU_ATTRIBUTE(fallthrough)
+#define FALLTHROUGH __attribute__((fallthrough))
 #else
 #define FALLTHROUGH ((void)0)
 #endif /* __GNUC__ >= 7 */
 
-#if !defined(DEBUG) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
+#if !defined(DEBUG)
 #define GNUC_ATTR_HOT __attribute__((hot))
 #else
 #define GNUC_ATTR_HOT /* nothing */
 #endif
 
-#define STG_UNUSED    GNUC3_ATTRIBUTE(__unused__)
-#define STG_USED      GNUC3_ATTRIBUTE(__used__)
-#define STG_WARN_UNUSED_RESULT GNUC3_ATTRIBUTE(warn_unused_result)
+#define STG_UNUSED    __attribute__((__unused__))
+#define STG_USED      __attribute__((__used__))
+#define STG_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
 
 /* Prevent functions from being optimized.
    See Note [Windows Stack allocations] */
 #if defined(__clang__)
 #define STG_NO_OPTIMIZE __attribute__((optnone))
-#elif defined(__GNUC__) || defined(__GNUG__)
-#define STG_NO_OPTIMIZE __attribute__((optimize("O0")))
 #else
-#define STG_NO_OPTIMIZE /* nothing */
+#define STG_NO_OPTIMIZE __attribute__((optimize("O0")))
 #endif
 
-// Mark a function as accepting a printf-like format string.
-#if !defined(__GNUC__) && defined(mingw32_HOST_OS)
-/* On Win64, if we say "printf" then gcc thinks we are going to use
-   MS format specifiers like %I64d rather than %llu */
-#define STG_PRINTF_ATTR(fmt_arg, rest) GNUC3_ATTRIBUTE(format(gnu_printf, fmt_arg, rest))
-#else
-/* However, on OS X, "gnu_printf" isn't recognised */
-#define STG_PRINTF_ATTR(fmt_arg, rest) GNUC3_ATTRIBUTE(format(printf, fmt_arg, rest))
-#endif
+#define STG_PRINTF_ATTR(fmt_arg, rest) __attribute__((format(printf, fmt_arg, rest)))
 
 #define STG_RESTRICT __restrict__
 
-#define STG_NORETURN GNU_ATTRIBUTE(__noreturn__)
+#define STG_NORETURN __attribute__((__noreturn__))
 
-#define STG_MALLOC GNUC3_ATTRIBUTE(__malloc__)
+#define STG_MALLOC __attribute__((__malloc__))
 
 /* Instead of relying on GCC version checks to expand attributes,
  * use `__has_attribute` which is supported by GCC >= 5 and Clang. Hence, the
@@ -204,13 +179,9 @@
 # define stg__has_attribute(attr) (0)
 #endif
 
-#ifdef __GNUC__
 # define STG_GNUC_GUARD_VERSION(major, minor) \
     ((__GNUC__ > (major)) || \
       ((__GNUC__ == (major)) && (__GNUC_MINOR__ >= (minor))))
-#else
-# define STG_GNUC_GUARD_VERSION(major, minor) (0)
-#endif
 
 /*
  * The versions of the `__malloc__` attribute which take arguments are only
@@ -280,8 +251,8 @@ typedef StgFunPtr       F_;
 #define EB_(X)    extern const char X[]
 #define IB_(X)    static const char X[]
 /* static (non-heap) closures (requires alignment for pointer tagging): */
-#define EC_(X)    extern       StgWordArray (X) GNU_ATTRIBUTE(aligned (SIZEOF_VOID_P))
-#define IC_(X)    static       StgWordArray (X) GNU_ATTRIBUTE(aligned (SIZEOF_VOID_P))
+#define EC_(X)    extern       StgWordArray (X) __attribute__((aligned (SIZEOF_VOID_P)))
+#define IC_(X)    static       StgWordArray (X) __attribute__((aligned (SIZEOF_VOID_P)))
 /* writable data (does not require alignment): */
 #define ERW_(X)   extern       StgWordArray (X)
 #define IRW_(X)   static       StgWordArray (X)
@@ -289,7 +260,7 @@ typedef StgFunPtr       F_;
 #define ERO_(X)   extern const StgWordArray (X)
 #define IRO_(X)   static const StgWordArray (X)
 /* stg-native functions: */
-#define IF_(f)    static StgFunPtr GNUC3_ATTRIBUTE(used) f(void)
+#define IF_(f)    static StgFunPtr __attribute__((used)) f(void)
 #define FN_(f)           StgFunPtr f(void)
 #define EF_(f)           StgFunPtr f(void) /* External Cmm functions */
 /* foreign functions: */


=====================================
rts/include/rts/Types.h
=====================================
@@ -19,12 +19,8 @@
 // Deprecated, use uint32_t instead.
 typedef unsigned int nat __attribute__((deprecated));  /* uint32_t */
 
-/* ullong (64|128-bit) type: only include if needed (not ANSI) */
-#if defined(__GNUC__)
+/* ullong (64|128-bit) type */
 #define LL(x) (x##LL)
-#else
-#define LL(x) (x##L)
-#endif
 
 typedef struct StgClosure_   StgClosure;
 typedef struct StgInfoTable_ StgInfoTable;


=====================================
rts/include/stg/DLL.h
=====================================
@@ -21,7 +21,7 @@
 #    define DLL_IMPORT_DATA_REF(x) (_imp__##x)
 #    define DLL_IMPORT_DATA_VARNAME(x) *_imp__##x
 #  endif
-#  if __GNUC__ && !defined(__declspec)
+#  if !defined(__declspec)
 #    define DLLIMPORT
 #  else
 #    define DLLIMPORT __declspec(dllimport)


=====================================
rts/sm/BlockAlloc.c
=====================================
@@ -274,19 +274,9 @@ STATIC_INLINE uint32_t
 log_2(W_ n)
 {
     ASSERT(n > 0 && n < (1<<NUM_FREE_LISTS));
-#if defined(__GNUC__)
     return CLZW(n) ^ (sizeof(StgWord)*8 - 1);
     // generates good code on x86.  __builtin_clz() compiles to bsr+xor, but
     // we want just bsr, so the xor here cancels out gcc's xor.
-#else
-    W_ i, x;
-    x = n;
-    for (i=0; i < NUM_FREE_LISTS; i++) {
-        x = x >> 1;
-        if (x == 0) return i;
-    }
-    return NUM_FREE_LISTS;
-#endif
 }
 
 // log base 2 (ceiling), needs to support up to (2^NUM_FREE_LISTS)-1
@@ -294,18 +284,8 @@ STATIC_INLINE uint32_t
 log_2_ceil(W_ n)
 {
     ASSERT(n > 0 && n < (1<<NUM_FREE_LISTS));
-#if defined(__GNUC__)
     uint32_t r = log_2(n);
     return (n & (n-1)) ? r+1 : r;
-#else
-    W_ i, x;
-    x = 1;
-    for (i=0; i < MAX_FREE_LIST; i++) {
-        if (x >= n) return i;
-        x = x << 1;
-    }
-    return MAX_FREE_LIST;
-#endif
 }
 
 STATIC_INLINE void


=====================================
rts/sm/Evac.h
=====================================
@@ -6,7 +6,7 @@
  *
  * Documentation on the architecture of the Garbage Collector can be
  * found in the online commentary:
- * 
+ *
  *   https://gitlab.haskell.org/ghc/ghc/wikis/commentary/rts/storage/gc
  *
  * ---------------------------------------------------------------------------*/
@@ -25,7 +25,7 @@
 //         registers EAX, EDX, and ECX instead of on the stack. Functions that
 //         take a variable number of arguments will continue to be passed all of
 //         their arguments on the stack.
-#if __GNUC__ >= 2 && (defined(x86_64_HOST_ARCH) || defined(i386_HOST_ARCH))
+#if defined(x86_64_HOST_ARCH) || defined(i386_HOST_ARCH)
 #define REGPARM1 __attribute__((regparm(1)))
 #else
 #define REGPARM1



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/41919b3380b8fad4dca6dbe98afd9b1dce977365...68514576e148d644dddddae3432b99f1ce4bea0d

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/41919b3380b8fad4dca6dbe98afd9b1dce977365...68514576e148d644dddddae3432b99f1ce4bea0d
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240609/df98629c/attachment-0001.html>


More information about the ghc-commits mailing list