X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=includes%2FStg.h;h=0344b70fd29996fa5897eb40a0ddfdaa3df4e6ca;hp=1facd5f40594237d64ee8ca9ed0821afa0320b5e;hb=a2a67cd520b9841114d69a87a423dabcb3b4368e;hpb=ab0e778ccfde61aed4c22679b24d175fc6cc9bf3 diff --git a/includes/Stg.h b/includes/Stg.h index 1facd5f..0344b70 100644 --- a/includes/Stg.h +++ b/includes/Stg.h @@ -23,14 +23,27 @@ #ifndef STG_H #define STG_H - -/* If we include "Stg.h" directly, we're in STG code, and we therefore - * get all the global register variables, macros etc. that go along - * with that. If "Stg.h" is included via "Rts.h", we're assumed to - * be in vanilla C. +/* + * If we are compiling a .hc file, then we want all the register + * variables. This is the what happens if you #include "Stg.h" first: + * we assume this is a .hc file, and set IN_STG_CODE==1, which later + * causes the register variables to be enabled in stg/Regs.h. + * + * If instead "Rts.h" is included first, then we are compiling a + * vanilla C file. Everything from Stg.h is provided, except that + * IN_STG_CODE is not defined, and the register variables will not be + * active. */ #ifndef IN_STG_CODE # define IN_STG_CODE 1 + +// Turn on C99 for .hc code. This gives us the INFINITY and NAN +// constants from math.h, which we occasionally need to use in .hc (#1861) +# define _ISOC99_SOURCE + +// We need _BSD_SOURCE so that math.h defines things like gamma +// on Linux +# define _BSD_SOURCE #endif #if IN_STG_CODE == 0 @@ -39,14 +52,18 @@ /* Configuration */ #include "ghcconfig.h" -#include "RtsConfig.h" + +/* The code generator calls the math functions directly in .hc code. + NB. after configuration stuff above, because this sets #defines + that depend on config info, such as __USE_FILE_OFFSET64 */ +#include /* ----------------------------------------------------------------------------- Useful definitions -------------------------------------------------------------------------- */ /* - * The C backend like to refer to labels by just mentioning their + * The C backend likes to refer to labels by just mentioning their * names. Howevver, when a symbol is declared as a variable in C, the * C compiler will implicitly dereference it when it occurs in source. * So we must subvert this behaviour for .hc files by declaring @@ -65,23 +82,65 @@ #define BITS_PER_BYTE 8 #define BITS_IN(x) (BITS_PER_BYTE * sizeof(x)) +/* Compute offsets of struct fields + */ +#define STG_FIELD_OFFSET(s_type, field) ((StgWord)&(((s_type*)0)->field)) + /* * 'Portable' inlining: - * INLINE_HEADER is for inline functions in header files + * INLINE_HEADER is for inline functions in header files (macros) * STATIC_INLINE is for inline functions in source files + * EXTERN_INLINE is for functions that we want to inline sometimes + * (we also compile a static version of the function; see Inlines.c) */ #if defined(__GNUC__) || defined( __INTEL_COMPILER) + # define INLINE_HEADER static inline # define INLINE_ME inline # define STATIC_INLINE INLINE_HEADER + +// The special "extern inline" behaviour is now only supported by gcc +// when _GNUC_GNU_INLINE__ is defined, and you have to use +// __attribute__((gnu_inline)). So when we don't have this, we use +// ordinary static inline. +// +// Apple's gcc defines __GNUC_GNU_INLINE__ without providing +// gnu_inline, so we exclude MacOS X and fall through to the safe +// version. +// +#if defined(__GNUC_GNU_INLINE__) && !defined(__APPLE__) +# if defined(KEEP_INLINES) +# define EXTERN_INLINE inline +# else +# define EXTERN_INLINE extern inline __attribute__((gnu_inline)) +# endif +#else +# if defined(KEEP_INLINES) +# define EXTERN_INLINE +# else +# define EXTERN_INLINE INLINE_HEADER +# endif +#endif + #elif defined(_MSC_VER) + # define INLINE_HEADER __inline static # define INLINE_ME __inline # define STATIC_INLINE INLINE_HEADER + +# if defined(KEEP_INLINES) +# define EXTERN_INLINE __inline +# else +# define EXTERN_INLINE __inline extern +# endif + #else + # error "Don't know how to inline functions with your C compiler." + #endif + /* * GCC attributes */ @@ -97,6 +156,12 @@ #define GNUC3_ATTRIBUTE(at) #endif +#if __GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 3 +#define GNUC_ATTR_HOT __attribute__((hot)) +#else +#define GNUC_ATTR_HOT /* nothing */ +#endif + #define STG_UNUSED GNUC3_ATTRIBUTE(__unused__) /* ----------------------------------------------------------------------------- @@ -104,7 +169,7 @@ -------------------------------------------------------------------------- */ #include "MachDeps.h" -#include "StgTypes.h" +#include "stg/Types.h" /* ----------------------------------------------------------------------------- Shorthand forms @@ -113,24 +178,14 @@ typedef StgChar C_; typedef StgWord W_; typedef StgWord* P_; -typedef P_* PP_; typedef StgInt I_; -typedef StgAddr A_; -typedef const StgWord* D_; -typedef StgFunPtr F_; -typedef StgByteArray B_; -typedef StgClosurePtr L_; - -typedef StgInt64 LI_; -typedef StgWord64 LW_; - -#define IF_(f) static F_ GNUC3_ATTRIBUTE(used) f(void) -#define FN_(f) F_ f(void) -#define EF_(f) extern F_ f(void) - typedef StgWord StgWordArray[]; + #define EI_(X) extern StgWordArray (X) GNU_ATTRIBUTE(aligned (8)) #define II_(X) static StgWordArray (X) GNU_ATTRIBUTE(aligned (8)) +#define IF_(f) static StgFunPtr GNUC3_ATTRIBUTE(used) f(void) +#define FN_(f) StgFunPtr f(void) +#define EF_(f) extern StgFunPtr f(void) /* ----------------------------------------------------------------------------- Tail calls @@ -139,27 +194,26 @@ typedef StgWord StgWordArray[]; to be before all procedures (inline & out-of-line). -------------------------------------------------------------------------- */ -#include "TailCalls.h" +#include "stg/TailCalls.h" /* ----------------------------------------------------------------------------- Other Stg stuff... -------------------------------------------------------------------------- */ -#include "StgDLL.h" -#include "MachRegs.h" -#include "Regs.h" -#include "StgProf.h" /* ToDo: separate out RTS-only stuff from here */ +#include "stg/DLL.h" +#include "stg/MachRegs.h" +#include "stg/Regs.h" +#include "stg/Ticky.h" #if IN_STG_CODE /* * This is included later for RTS sources, after definitions of * StgInfoTable, StgClosure and so on. */ -#include "StgMiscClosures.h" +#include "stg/MiscClosures.h" #endif -/* RTS external interface */ -#include "RtsExternal.h" +#include "stg/SMP.h" // write_barrier() inline is required /* ----------------------------------------------------------------------------- Moving Floats and Doubles @@ -281,7 +335,7 @@ INLINE_HEADER StgDouble PK_DBL(W_ p_src[]) In both cases the memory location might not be 64-bit aligned. -------------------------------------------------------------------------- */ -#ifdef SUPPORT_LONG_LONGS +#if SIZEOF_HSWORD == 4 typedef struct { StgWord dhi; @@ -352,7 +406,7 @@ INLINE_HEADER StgInt64 PK_Int64(W_ p_src[]) return p_src[0]; } -#endif +#endif /* SIZEOF_HSWORD == 4 */ /* ----------------------------------------------------------------------------- Split markers