From b4623557bb3c8bec7232e4e68a8be8cf28fbbda6 Mon Sep 17 00:00:00 2001 From: simonmar Date: Wed, 3 Oct 2001 13:57:42 +0000 Subject: [PATCH] [project @ 2001-10-03 13:57:42 by simonmar] Tidy up ghc/includes/Constants and related things. Now all the constants that the compiler needs to know, such as header size, update frame size, info table size and so on are generated automatically into a header file, DeriviedConstants.h, by a small C program in the same way as NativeDefs.h. The C code in the RTS is expected to use sizeof() directly (it already does). Also tidied up the constants in MachDeps.h - all the constants representing the sizes of various types are named SIZEOF_, to match the constants defined in config.h. PrelStorable.lhs now doesn't contain any special knowledge about GHC's conventions as regards the size of certain types, this is all in MachDeps.h. --- ghc/compiler/codeGen/CgStackery.lhs | 11 ++-- ghc/compiler/main/Constants.lhs | 22 ++++---- ghc/includes/Block.h | 4 +- ghc/includes/Closures.h | 42 +-------------- ghc/includes/Constants.h | 99 ++++------------------------------- ghc/includes/InfoTables.h | 26 ++++----- ghc/includes/MachDeps.h | 78 ++++++++++++++++++++------- ghc/includes/Makefile | 23 ++++++-- ghc/includes/StgProf.h | 65 +++++++++++------------ ghc/includes/StgTypes.h | 4 +- ghc/includes/mkDerivedConstants.c | 61 +++++++++++++++++++++ ghc/lib/std/PrelNum.lhs | 8 +-- ghc/lib/std/PrelStorable.lhs | 16 +++--- 13 files changed, 230 insertions(+), 229 deletions(-) create mode 100644 ghc/includes/mkDerivedConstants.c diff --git a/ghc/compiler/codeGen/CgStackery.lhs b/ghc/compiler/codeGen/CgStackery.lhs index 896cfc7..a75b7e7 100644 --- a/ghc/compiler/codeGen/CgStackery.lhs +++ b/ghc/compiler/codeGen/CgStackery.lhs @@ -1,7 +1,7 @@ % % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998 % -% $Id: CgStackery.lhs,v 1.19 2001/09/12 15:52:40 sewardj Exp $ +% $Id: CgStackery.lhs,v 1.20 2001/10/03 13:57:42 simonmar Exp $ % \section[CgStackery]{Stack management functions} @@ -27,8 +27,9 @@ import AbsCUtils ( mkAbstractCs, getAmodeRep ) import PrimRep ( getPrimRepSize, PrimRep(..), isFollowableRep ) import CmdLineOpts ( opt_SccProfilingOn, opt_GranMacros ) import Panic ( panic ) -import Constants ( uF_SIZE, sCC_UF_SIZE, gRAN_UF_SIZE, - sEQ_FRAME_SIZE, sCC_SEQ_FRAME_SIZE, gRAN_SEQ_FRAME_SIZE ) +import Constants ( uF_SIZE, pROF_UF_SIZE, gRAN_UF_SIZE, + sEQ_FRAME_SIZE, pROF_SEQ_FRAME_SIZE, + gRAN_SEQ_FRAME_SIZE ) import Util ( sortLt ) import IOExts ( trace ) @@ -222,11 +223,11 @@ getFinalStackHW fcode = do \end{code} \begin{code} -updateFrameSize | opt_SccProfilingOn = sCC_UF_SIZE +updateFrameSize | opt_SccProfilingOn = pROF_UF_SIZE | opt_GranMacros = trace ("updateFrameSize = " ++ (show gRAN_UF_SIZE))gRAN_UF_SIZE | otherwise = uF_SIZE -seqFrameSize | opt_SccProfilingOn = sCC_SEQ_FRAME_SIZE +seqFrameSize | opt_SccProfilingOn = pROF_SEQ_FRAME_SIZE | opt_GranMacros = gRAN_SEQ_FRAME_SIZE | otherwise = sEQ_FRAME_SIZE \end{code} diff --git a/ghc/compiler/main/Constants.lhs b/ghc/compiler/main/Constants.lhs index 0e6a179..daa1c84 100644 --- a/ghc/compiler/main/Constants.lhs +++ b/ghc/compiler/main/Constants.lhs @@ -34,14 +34,14 @@ module Constants ( mAX_FAMILY_SIZE_FOR_VEC_RETURNS, uF_SIZE, - sCC_UF_SIZE, + pROF_UF_SIZE, gRAN_UF_SIZE, -- HWL uF_RET, uF_SU, uF_UPDATEE, sEQ_FRAME_SIZE, - sCC_SEQ_FRAME_SIZE, + pROF_SEQ_FRAME_SIZE, gRAN_SEQ_FRAME_SIZE, -- HWL mAX_Vanilla_REG, @@ -81,6 +81,8 @@ module Constants ( #include "../includes/config.h" #include "../includes/MachRegs.h" #include "../includes/Constants.h" +#include "../includes/MachDeps.h" +#include "../includes/DerivedConstants.h" -- import Util \end{code} @@ -146,10 +148,10 @@ mAX_FAMILY_SIZE_FOR_VEC_RETURNS = (MAX_VECTORED_RTN::Int) -- pretty arbitrary -- If you change this, you may need to change runtimes/standard/Update.lhc -- The update frame sizes -uF_SIZE = (NOSCC_UF_SIZE::Int) +uF_SIZE = (STD_UF_SIZE::Int) -- Same again, with profiling -sCC_UF_SIZE = (SCC_UF_SIZE::Int) +pROF_UF_SIZE = (PROF_UF_SIZE::Int) -- Same again, with gransim gRAN_UF_SIZE = (GRAN_UF_SIZE::Int) @@ -163,8 +165,8 @@ uF_UPDATEE = (UF_UPDATEE::Int) Seq frame sizes. \begin{code} -sEQ_FRAME_SIZE = (NOSCC_SEQ_FRAME_SIZE::Int) -sCC_SEQ_FRAME_SIZE = (SCC_SEQ_FRAME_SIZE::Int) +sEQ_FRAME_SIZE = (STD_SEQ_FRAME_SIZE::Int) +pROF_SEQ_FRAME_SIZE = (PROF_SEQ_FRAME_SIZE::Int) gRAN_SEQ_FRAME_SIZE = (GRAN_SEQ_FRAME_SIZE::Int) \end{code} @@ -207,9 +209,9 @@ tICKY_ITBL_SIZE = (TICKY_ITBL_SIZE :: Int) Size of a double in StgWords. \begin{code} -dOUBLE_SIZE = (DOUBLE_SIZE :: Int) -wORD64_SIZE = (WORD64_SIZE :: Int) -iNT64_SIZE = (INT64_SIZE :: Int) +dOUBLE_SIZE = (SIZEOF_DOUBLE `quot` SIZEOF_HSWORD :: Int) +wORD64_SIZE = (8 `quot` SIZEOF_HSWORD :: Int) +iNT64_SIZE = wORD64_SIZE \end{code} This tells the native code generator the size of the spill @@ -229,7 +231,7 @@ rESERVED_STACK_WORDS = (RESERVED_STACK_WORDS :: Int) Size of a word, in bytes \begin{code} -wORD_SIZE = (WORD_SIZE :: Int) +wORD_SIZE = (SIZEOF_HSWORD :: Int) \end{code} Size of a storage manager block (in bytes). diff --git a/ghc/includes/Block.h b/ghc/includes/Block.h index 599dc27..1f84f78 100644 --- a/ghc/includes/Block.h +++ b/ghc/includes/Block.h @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $Id: Block.h,v 1.9 2001/07/23 17:23:19 simonmar Exp $ + * $Id: Block.h,v 1.10 2001/10/03 13:57:42 simonmar Exp $ * * (c) The GHC Team, 1998-1999 * @@ -16,6 +16,7 @@ /* Block related constants (4k blocks) */ +#define BLOCK_SIZE (1<DerivedConstants.h + +CLEAN_FILES += DerivedConstants.h + +# --------------------------------------------------------------------------- +# Make NativeDefs.h for the NCG + +all :: NativeDefs.h + +mkNativeHdr.o : DerivedConstants.h + +mkNativeHdr : mkNativeHdr.o + $(CC) -o $@ $(CC_OPTS) $(LD_OPTS) mkNativeHdr.o NativeDefs.h : mkNativeHdr ./mkNativeHdr >NativeDefs.h diff --git a/ghc/includes/StgProf.h b/ghc/includes/StgProf.h index f19f4d2..46f8491 100644 --- a/ghc/includes/StgProf.h +++ b/ghc/includes/StgProf.h @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $Id: StgProf.h,v 1.10 2000/05/12 13:01:04 simonmar Exp $ + * $Id: StgProf.h,v 1.11 2001/10/03 13:57:42 simonmar Exp $ * * (c) The GHC Team, 1998 * @@ -9,33 +9,9 @@ #ifndef STGPROF_H #define STGPROF_H -#if !defined(PROFILING) - -#define CCS_ALLOC(ccs, amount) doNothing() -#define ENTER_CC_PAP_CL(r) doNothing() -#define ENTER_CCS_PAP_CL(r) doNothing() - -#else /* PROFILING... */ - -/* ----------------------------------------------------------------------------- - * Constants - * ---------------------------------------------------------------------------*/ - -#define EMPTY_STACK NULL -#define EMPTY_TABLE NULL - -/* Constants used to set sumbsumed flag on CostCentres */ - -#define CC_IS_CAF 'c' /* 'c' => *is* a CAF cc */ -#define CC_IS_BORING 'B' /* 'B' => *not* a CAF/sub cc */ - /* ----------------------------------------------------------------------------- * Data Structures * ---------------------------------------------------------------------------*/ -/* - * CostCentre - */ - typedef struct _CostCentre { int ccID; @@ -44,7 +20,7 @@ typedef struct _CostCentre { /* used for accumulating costs at the end of the run... */ unsigned long time_ticks; - unsigned long mem_alloc; + unsigned long long mem_alloc; char is_caf; @@ -52,11 +28,6 @@ typedef struct _CostCentre { } CostCentre; - -/* - * CostCentreStack - */ - typedef struct _CostCentreStack { int ccsID; @@ -64,20 +35,46 @@ typedef struct _CostCentreStack { struct _CostCentreStack *prevStack; struct _IndexTable *indexTable; - unsigned long scc_count; + unsigned long long scc_count; unsigned long time_ticks; - unsigned long mem_alloc; + unsigned long long mem_alloc; unsigned long mem_resid; unsigned long inherited_ticks; - unsigned long inherited_alloc; + unsigned long long inherited_alloc; CostCentre *root; } CostCentreStack; +/* ----------------------------------------------------------------------------- + * The rest is PROFILING only... + * ---------------------------------------------------------------------------*/ +#if !defined(PROFILING) + +#define CCS_ALLOC(ccs, amount) doNothing() +#define ENTER_CC_PAP_CL(r) doNothing() +#define ENTER_CCS_PAP_CL(r) doNothing() + +#else /* PROFILING... */ + +/* ----------------------------------------------------------------------------- + * Constants + * ---------------------------------------------------------------------------*/ + +#define EMPTY_STACK NULL +#define EMPTY_TABLE NULL + +/* Constants used to set sumbsumed flag on CostCentres */ + +#define CC_IS_CAF 'c' /* 'c' => *is* a CAF cc */ +#define CC_IS_BORING 'B' /* 'B' => *not* a CAF/sub cc */ + +/* ----------------------------------------------------------------------------- + * Data Structures + * ---------------------------------------------------------------------------*/ /* * IndexTable */ diff --git a/ghc/includes/StgTypes.h b/ghc/includes/StgTypes.h index fd9401d..e864d81 100644 --- a/ghc/includes/StgTypes.h +++ b/ghc/includes/StgTypes.h @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $Id: StgTypes.h,v 1.17 2001/07/26 03:08:39 ken Exp $ + * $Id: StgTypes.h,v 1.18 2001/10/03 13:57:42 simonmar Exp $ * * (c) The GHC Team, 1998-2000 * @@ -25,7 +25,7 @@ StgCode, StgArray, StgByteArray, StgStablePtr, StgFunPtr, StgUnion. - * WARNING: Keep this file and HsFFI.h in synch! + * WARNING: Keep this file, MachDeps.h, and HsFFI.h in synch! * * NOTE: assumes #include "config.h" * diff --git a/ghc/includes/mkDerivedConstants.c b/ghc/includes/mkDerivedConstants.c new file mode 100644 index 0000000..fc0e591 --- /dev/null +++ b/ghc/includes/mkDerivedConstants.c @@ -0,0 +1,61 @@ +/* -------------------------------------------------------------------------- + * $Id: mkDerivedConstants.c,v 1.1 2001/10/03 13:57:42 simonmar Exp $ + * + * (c) The GHC Team, 1992-1998 + * + * Generate a header for the native code generator + * + * ------------------------------------------------------------------------*/ + +#include "Rts.h" + +#define OFFSET(s_type, field) ((unsigned int)&(((s_type*)0)->field)) + +int +main(int argc, char *argv[]) +{ + printf("-- This file is created automatically. Do not edit by hand.\n\n"); + + printf("#define STD_HDR_SIZE %d\n", sizeofW(StgHeader)); + printf("#define PROF_HDR_SIZE %d\n", sizeofW(StgProfHeader)); + printf("#define GRAN_HDR_SIZE %d\n", sizeofW(StgGranHeader)); + printf("#define PAR_HDR_SIZE %d\n", sizeofW(StgParHeader)); + printf("#define TICKY_HDR_SIZE %d\n", sizeofW(StgTickyHeader)); + + printf("#define ARR_WORDS_HDR_SIZE %d\n", + sizeofW(StgArrWords) - sizeofW(StgHeader)); + + printf("#define ARR_PTRS_HDR_SIZE %d\n", + sizeofW(StgMutArrPtrs) - sizeofW(StgHeader)); + + printf("#define STD_ITBL_SIZE %d\n", sizeofW(StgInfoTable)); + printf("#define PROF_ITBL_SIZE %d\n", sizeofW(StgProfInfo)); + printf("#define GRAN_ITBL_SIZE %d\n", 0); + printf("#define PAR_ITBL_SIZE %d\n", sizeofW(StgParInfo)); + printf("#define TICKY_ITBL_SIZE %d\n", sizeofW(StgTickyInfo)); + + printf("#define STD_UF_SIZE %d\n", sizeofW(StgUpdateFrame)); + printf("#define GRAN_UF_SIZE %d\n", + sizeofW(StgUpdateFrame) + sizeofW(StgGranHeader)); + printf("#define PROF_UF_SIZE %d\n", + sizeofW(StgUpdateFrame) + sizeofW(StgProfHeader)); + + printf("#define UF_RET %d\n", + OFFSET(StgUpdateFrame,header.info)); + + printf("#define UF_SU %d\n", + OFFSET(StgUpdateFrame,link) / sizeof(W_)); + + printf("#define UF_UPDATEE %d\n", + OFFSET(StgUpdateFrame,updatee) / sizeof(W_)); + + printf("#define STD_SEQ_FRAME_SIZE %d\n", sizeofW(StgSeqFrame)); + printf("#define GRAN_SEQ_FRAME_SIZE %d\n", + sizeofW(StgSeqFrame) + sizeofW(StgGranHeader)); + printf("#define PROF_SEQ_FRAME_SIZE %d\n", + sizeofW(StgSeqFrame) + sizeofW(StgProfHeader)); + + printf("#define BLOCK_SIZE %d\n", BLOCK_SIZE); + printf("#define MBLOCK_SIZE %d\n", MBLOCK_SIZE); + return 0; +} diff --git a/ghc/lib/std/PrelNum.lhs b/ghc/lib/std/PrelNum.lhs index a874a8e..6707bd5 100644 --- a/ghc/lib/std/PrelNum.lhs +++ b/ghc/lib/std/PrelNum.lhs @@ -1,5 +1,5 @@ % ------------------------------------------------------------------------------ -% $Id: PrelNum.lhs,v 1.40 2001/07/24 06:31:35 ken Exp $ +% $Id: PrelNum.lhs,v 1.41 2001/10/03 13:57:42 simonmar Exp $ % % (c) The University of Glasgow, 1994-2000 % @@ -19,12 +19,12 @@ and the type {-# OPTIONS -fno-implicit-prelude #-} #include "MachDeps.h" -#if WORD_SIZE_IN_BYTES == 4 +#if SIZEOF_HSWORD == 4 #define LEFTMOST_BIT 2147483648 -#elif WORD_SIZE_IN_BYTES == 8 +#elif SIZEOF_HSWORD == 8 #define LEFTMOST_BIT 9223372036854775808 #else -#error Please define LEFTMOST_BIT to be 2^(WORD_SIZE_IN_BYTES*8-1) +#error Please define LEFTMOST_BIT to be 2^(SIZEOF_HSWORD*8-1) #endif module PrelNum where diff --git a/ghc/lib/std/PrelStorable.lhs b/ghc/lib/std/PrelStorable.lhs index 0166232..b5f9089 100644 --- a/ghc/lib/std/PrelStorable.lhs +++ b/ghc/lib/std/PrelStorable.lhs @@ -1,5 +1,5 @@ % ----------------------------------------------------------------------------- -% $Id: PrelStorable.lhs,v 1.9 2001/08/17 17:18:54 apt Exp $ +% $Id: PrelStorable.lhs,v 1.10 2001/10/03 13:57:42 simonmar Exp $ % % (c) The FFI task force, 2000 % @@ -106,25 +106,25 @@ instance Storable (T) where { \ STORABLE(Char,SIZEOF_INT32,ALIGNMENT_INT32, readWideCharOffPtr,writeWideCharOffPtr) -STORABLE(Int,SIZEOF_LONG,ALIGNMENT_LONG, +STORABLE(Int,SIZEOF_HSINT,ALIGNMENT_HSINT, readIntOffPtr,writeIntOffPtr) -STORABLE(Word,SIZEOF_LONG,ALIGNMENT_LONG, +STORABLE(Word,SIZEOF_HSWORD,ALIGNMENT_HSWORD, readWordOffPtr,writeWordOffPtr) -STORABLE((Ptr a),SIZEOF_VOID_P,ALIGNMENT_VOID_P, +STORABLE((Ptr a),SIZEOF_HSPTR,ALIGNMENT_HSPTR, readPtrOffPtr,writePtrOffPtr) -STORABLE((FunPtr a),SIZEOF_VOID_P,ALIGNMENT_VOID_P, +STORABLE((FunPtr a),SIZEOF_HSFUNPTR,ALIGNMENT_HSFUNPTR, readFunPtrOffPtr,writeFunPtrOffPtr) -STORABLE((StablePtr a),SIZEOF_VOID_P,ALIGNMENT_VOID_P, +STORABLE((StablePtr a),SIZEOF_HSSTABLEPTR,ALIGNMENT_HSSTABLEPTR, readStablePtrOffPtr,writeStablePtrOffPtr) -STORABLE(Float,SIZEOF_FLOAT,ALIGNMENT_FLOAT, +STORABLE(Float,SIZEOF_HSFLOAT,ALIGNMENT_HSFLOAT, readFloatOffPtr,writeFloatOffPtr) -STORABLE(Double,SIZEOF_DOUBLE,ALIGNMENT_DOUBLE, +STORABLE(Double,SIZEOF_HSDOUBLE,ALIGNMENT_HSDOUBLE, readDoubleOffPtr,writeDoubleOffPtr) STORABLE(Word8,SIZEOF_WORD8,ALIGNMENT_WORD8, -- 1.7.10.4