Commit b4623557 authored by simonmar's avatar simonmar

[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_<foo>, 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.
parent e205a0ce
%
% (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}
......
......@@ -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).
......
/* -----------------------------------------------------------------------------
* $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<<BLOCK_SHIFT)
#define BLOCK_SIZE_W (BLOCK_SIZE/sizeof(W_))
#define BLOCK_MASK (BLOCK_SIZE-1)
......@@ -24,6 +25,7 @@
/* Megablock related constants (1M megablocks) */
#define MBLOCK_SIZE (1<<MBLOCK_SHIFT)
#define MBLOCK_SIZE_W (MBLOCK_SIZE/sizeof(W_))
#define MBLOCK_MASK (MBLOCK_SIZE-1)
......
/* ----------------------------------------------------------------------------
* $Id: Closures.h,v 1.27 2001/08/29 17:24:25 qrczak Exp $
* $Id: Closures.h,v 1.28 2001/10/03 13:57:42 simonmar Exp $
*
* (c) The GHC Team, 1998-1999
*
......@@ -19,56 +19,26 @@
The profiling header
-------------------------------------------------------------------------- */
#ifdef PROFILING
typedef struct {
CostCentreStack *ccs;
} StgProfHeader;
#else /* !PROFILING */
typedef struct {
/* empty */
} StgProfHeader;
#endif /* PROFILING */
/* -----------------------------------------------------------------------------
The parallel header
-------------------------------------------------------------------------- */
#ifdef PAR
typedef struct {
/* StgWord ga; */ /* nope! global addresses are managed via a hash table */
} StgParHeader;
#else /* !PAR */
typedef struct {
/* empty */
} StgParHeader;
#endif /* PAR */
/* -----------------------------------------------------------------------------
The GranSim header
-------------------------------------------------------------------------- */
#if defined(GRAN)
typedef struct {
StgWord procs; /* bitmask indicating on which PEs this closure resides */
} StgGranHeader;
#else /* !GRAN */
typedef struct {
/* empty */
} StgGranHeader;
#endif /* GRAN */
/* -----------------------------------------------------------------------------
The ticky-ticky header
......@@ -88,20 +58,10 @@ typedef struct {
info tables to be @_Evacuate_1@ and @_Scavenge_1_0@.
-------------------------------------------------------------------------- */
#ifdef TICKY_TICKY
typedef struct {
/* old: W_ updated; */
} StgTickyHeader;
#else /* !TICKY_TICKY */
typedef struct {
/* empty */
} StgTickyHeader;
#endif /* TICKY_TICKY */
/* -----------------------------------------------------------------------------
The full fixed-size closure header
......
/* ----------------------------------------------------------------------------
* $Id: Constants.h,v 1.17 2001/08/01 08:20:33 simonmar Exp $
* $Id: Constants.h,v 1.18 2001/10/03 13:57:42 simonmar Exp $
*
* (c) The GHC Team, 1998-1999
*
* Constants
*
* NOTE: this information is used by both the compiler and the RTS,
* and *must* be kept up-to-date with respect to the rest of the
* world.
* NOTE: this information is used by both the compiler and the RTS.
* Some of it is tweakable, and some of it must be kept up to date
* with various other parts of the system.
*
* Constants which are derived automatically from other definitions in
* the system (eg. structure sizes) are generated into the file
* DerivedConstants.h by a C program (mkDerivedConstantsHdr).
*
* -------------------------------------------------------------------------- */
#ifndef CONSTANTS_H
#define CONSTANTS_H
/* -----------------------------------------------------------------------------
Header Sizes
NOTE: keep these in line with the real definitions in Closures.h
HWL: checked GRAN_HDR_SIZE; ok
-------------------------------------------------------------------------- */
#define STD_HDR_SIZE 1
#define PROF_HDR_SIZE 1
#define GRAN_HDR_SIZE 1
#define PAR_HDR_SIZE 0
#define TICKY_HDR_SIZE 0
#define ARR_WORDS_HDR_SIZE 1
#define ARR_PTRS_HDR_SIZE 2
/* -----------------------------------------------------------------------------
Info Table sizes
The native code generator needs to know these things, and can't use
the C sizeof() function.
NOTE: keep these in line with the real definitions in InfoTables.h
NOTE: the PROF, and GRAN values are *wrong* (ToDo)
HWL: checked GRAN_ITBL_SIZE; ok
-------------------------------------------------------------------------- */
#define STD_ITBL_SIZE 3
#define PROF_ITBL_SIZE 1
#define GRAN_ITBL_SIZE 1
#define PAR_ITBL_SIZE 0
#define TICKY_ITBL_SIZE 0
/* -----------------------------------------------------------------------------
Minimum closure sizes
......@@ -101,32 +71,6 @@
#define MAX_SPEC_FUN_SIZE 2
#define MAX_SPEC_CONSTR_SIZE 2
/* -----------------------------------------------------------------------------
Update Frame Layout
GranSim uses an additional word as bitmask in the update frame; actually,
not really necessary, but uses standard closure layout that way
NB: UF_RET etc are *wrong* in a GranSim setup; should be increased by 1
if compiling for GranSim (currently not used in compiler) -- HWL
-------------------------------------------------------------------------- */
#define NOSCC_UF_SIZE 3
#define GRAN_UF_SIZE 4
#define SCC_UF_SIZE 4
#define UF_RET 0
#define UF_SU 1
#define UF_UPDATEE 2
/* -----------------------------------------------------------------------------
SEQ frame size
I don't think seq frames really need sccs --SDM
They don't need a GranSim bitmask either, but who cares anyway -- HWL
-------------------------------------------------------------------------- */
#define NOSCC_SEQ_FRAME_SIZE 2
#define GRAN_SEQ_FRAME_SIZE 3
#define SCC_SEQ_FRAME_SIZE 3
/* -----------------------------------------------------------------------------
STG Registers.
......@@ -140,27 +84,6 @@
/* register is only used for returning (unboxed) 64-bit vals */
#define MAX_LONG_REG 1
/*---- The size of an StgDouble, in StgWords. */
#if SIZEOF_VOID_P == SIZEOF_DOUBLE
#define DOUBLE_SIZE 1
#else
#define DOUBLE_SIZE 2
#endif
/*---- The size of Stg{Int,Word}64e, in StgWords. */
#if SIZEOF_VOID_P == 8
#define WORD64_SIZE 1
#define INT64_SIZE 1
#else
#define WORD64_SIZE 2
#define INT64_SIZE 2
#endif
/*---- The size of StgWord, in bytes. */
#define WORD_SIZE SIZEOF_VOID_P
/*---- Maximum number of constructors in a data type for direct-returns. */
#define MAX_VECTORED_RTN 8
......@@ -220,12 +143,10 @@
Storage manager constants
-------------------------------------------------------------------------- */
/* The size of a block */
#define BLOCK_SIZE 0x1000
/* The size of a block (2^BLOCK_SHIFT bytes) */
#define BLOCK_SHIFT 12
/* The size of a megablock */
#define MBLOCK_SIZE 0x100000
/* The size of a megablock (2^MBLOCK_SHIFT bytes) */
#define MBLOCK_SHIFT 20
/* the largest size an object can be before we give it a block of its
......
/* ----------------------------------------------------------------------------
* $Id: InfoTables.h,v 1.22 2001/08/29 17:24:25 qrczak Exp $
* $Id: InfoTables.h,v 1.23 2001/10/03 13:57:42 simonmar Exp $
*
* (c) The GHC Team, 1998-1999
*
......@@ -14,21 +14,11 @@
Profiling info
-------------------------------------------------------------------------- */
#ifdef PROFILING
typedef struct {
char *closure_type;
char *closure_desc;
} StgProfInfo;
#else /* !PROFILING */
typedef struct {
/* empty */
} StgProfInfo;
#endif /* PROFILING */
/* -----------------------------------------------------------------------------
Parallelism info
-------------------------------------------------------------------------- */
......@@ -42,13 +32,12 @@ typedef struct {
StgInfoTable *rbh_infoptr; /* infoptr to the RBH */
} StgParInfo;
#else /* !PAR */
#endif /* 0 */
typedef struct {
/* empty */
} StgParInfo;
#endif /* PAR */
/*
Copied from ghc-0.29; ToDo: check this code -- HWL
......@@ -97,6 +86,14 @@ typedef struct {
#endif
/* -----------------------------------------------------------------------------
Ticky info
-------------------------------------------------------------------------- */
typedef struct {
/* empty */
} StgTickyInfo;
/* -----------------------------------------------------------------------------
Debugging info
-------------------------------------------------------------------------- */
......@@ -217,6 +214,9 @@ typedef struct _StgInfoTable {
#ifdef PROFILING
StgProfInfo prof;
#endif
#ifdef TICKY
StgTickyInfo ticky;
#endif
#ifdef DEBUG_CLOSURE
StgDebugInfo debug;
#endif
......
/* -----------------------------------------------------------------------------
* $Id: MachDeps.h,v 1.6 2001/08/17 17:18:53 apt Exp $
* $Id: MachDeps.h,v 1.7 2001/10/03 13:57:42 simonmar Exp $
*
* (c) The GRASP/AQUA Project, Glasgow University, 1998
* (c) The GHC Team, 1998-1999
* (c) The University of Glasgow 2001
*
* Definitions that characterise machine specific properties of basic
* Stg types provided as unboxed types (mirrors the typedefs in
* StgTypes.)
* types (C & Haskell).
*
* NB: Keep in sync with HsFFI.h and StgTypes.h.
* NB: THIS FILE IS INCLUDED IN HASKELL SOURCE!
* ---------------------------------------------------------------------------*/
#ifndef MACHDEPS_H
#define MACHDEPS_H
/* Sizes of C types come from here... */
#include "config.h"
/* Sizes of Haskell types follow. These sizes correspond to:
* - the number of bytes in the primitive type (eg. Int#)
* - the number of bytes in the external representation (eg. HsInt)
* - the scale offset used by writeFooOffAddr#
*
* In the heap, the type may take up more space: eg. SIZEOF_INT8 == 1,
* but it takes up SIZEOF_HSWORD (4 or 8) bytes in the heap.
*/
/* First, check some assumptions.. */
#if SIZEOF_CHAR != 1
#error GHC untested on this architecture: sizeof(char) != 1
#endif
#define CHAR_SIZE_IN_BYTES 1
#define ADDR_SIZE_IN_BYTES SIZEOF_VOID_P
#define INT_SIZE_IN_BYTES SIZEOF_LONG
#define WORD_SIZE_IN_BYTES SIZEOF_LONG
#ifndef WORD_SIZE_IN_BITS
#if WORD_SIZE_IN_BYTES == 4
#define WORD_SIZE_IN_BITS 32
#else
#define WORD_SIZE_IN_BITS 64
#if SIZEOF_SHORT != 2
#error GHC untested on this architecture: sizeof(short) != 2
#endif
#if SIZEOF_UNSIGNED_INT != 4
#error GHC untested on this architecture: sizeof(unsigned int) != 4
#endif
#define FLOAT_SIZE_IN_BYTES SIZEOF_FLOAT
#define DOUBLE_SIZE_IN_BYTES SIZEOF_DOUBLE
#define SIZEOF_HSCHAR SIZEOF_WORD32
#define ALIGNMENT_HSCHAR ALIGNMENT_WORD32
#define SIZEOF_HSINT SIZEOF_VOID_P
#define ALIGNMENT_HSINT ALIGNMENT_VOID_P
#define SIZEOF_HSWORD SIZEOF_VOID_P
#define ALIGNMENT_HSWORD ALIGNMENT_VOID_P
#define SIZEOF_HSDOUBLE SIZEOF_DOUBLE
#define ALIGNMENT_HSDOUBLE ALIGNMENT_DOUBLE
#define SIZEOF_HSFLOAT SIZEOF_FLOAT
#define ALIGNMENT_HSFLOAT ALIGNMENT_FLOAT
#define SIZEOF_HSPTR SIZEOF_VOID_P
#define ALIGNMENT_HSPTR ALIGNMENT_VOID_P
#define SIZEOF_HSFUNPTR SIZEOF_VOID_P
#define ALIGNMENT_HSFUNPTR ALIGNMENT_VOID_P
#define SIZEOF_HSFOREIGNPTR SIZEOF_VOID_P
#define ALIGNMENT_HSFOREIGNPTR ALIGNMENT_VOID_P
#define SIZEOF_HSSTABLEPTR SIZEOF_VOID_P
#define ALIGNMENT_HSSTABLEPTR ALIGNMENT_VOID_P
#define SIZEOF_INT8 SIZEOF_CHAR
#define ALIGNMENT_INT8 ALIGNMENT_CHAR
#define SIZEOF_WORD8 SIZEOF_UNSIGNED_CHAR
#define ALIGNMENT_WORD8 ALIGNMENT_UNSIGNED_CHAR
#define SIZEOF_INT16 SIZEOF_SHORT
#define ALIGNMENT_INT16 ALIGNMENT_SHORT
#define SIZEOF_WORD16 SIZEOF_UNSIGNED_SHORT
#define ALIGNMENT_WORD16 ALIGNMENT_UNSIGNED_SHORT
#if SIZEOF_UNSIGNED_INT == 4
#define SIZEOF_INT32 SIZEOF_INT
#define ALIGNMENT_INT32 ALIGNMENT_INT
#define SIZEOF_WORD32 SIZEOF_UNSIGNED_INT
#define ALIGNMENT_WORD32 ALIGNMENT_UNSIGNED_INT
#else
#error GHC untested on this architecture: sizeof(unsigned int) != 4
#endif
#if HAVE_LONG_LONG && SIZEOF_VOID_P < 8
/* assume long long is 64 bits */
......@@ -68,4 +100,12 @@
#error GHC untested on this architecture: sizeof(void *) < 8 and no long longs.
#endif
#ifndef WORD_SIZE_IN_BITS
#if SIZEOF_HSWORD == 4
#define WORD_SIZE_IN_BITS 32
#else
#define WORD_SIZE_IN_BITS 64
#endif
#endif
#endif /* MACHDEPS_H */
# -----------------------------------------------------------------------------
# $Id: Makefile,v 1.15 2001/07/16 21:01:58 qrczak Exp $
# $Id: Makefile,v 1.16 2001/10/03 13:57:42 simonmar Exp $
#
TOP = ..
......@@ -64,8 +64,25 @@ endif
# ---------------------------------------------------------------------------
# Make NativeDefs.h for the NCG
C_PROG = mkNativeHdr
C_SRCS = mkNativeHdr.c
all :: DerivedConstants.h
mkDerivedConstantsHdr : mkDerivedConstants.o
$(CC) -o $@ $(CC_OPTS) $(LD_OPTS) mkDerivedConstants.o
DerivedConstants.h : mkDerivedConstantsHdr
./mkDerivedConstantsHdr >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
......
/* -----------------------------------------------------------------------------
* $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
*/
......
/* -----------------------------------------------------------------------------