1 -----------------------------------------------------------------------------
5 -- (c) The University of Glasgow 2004-2006
7 -----------------------------------------------------------------------------
10 GenCmm(..), GenCmmTop(..),
11 CmmInfoTable(..), HasStaticClosure, ClosureTypeInfo(..), ConstrDescription,
12 ProfilingInfo(..), ClosureTypeTag,
13 CmmActual, CmmActuals, CmmFormal, CmmFormals, ForeignHint(..),
14 CmmStatic(..), Section(..),
17 #include "HsVersions.h"
27 -- A [[BlockId]] is a local label.
28 -- Local labels must be unique within an entire compilation unit, not
29 -- just a single top-level item, because local labels map one-to-one
30 -- with assembly-language labels.
32 -----------------------------------------------------------------------------
34 -----------------------------------------------------------------------------
36 -- A file is a list of top-level chunks. These may be arbitrarily
37 -- re-orderd during code generation.
39 -- GenCmm is abstracted over
40 -- d, the type of static data elements in CmmData
41 -- h, the static info preceding the code of a CmmProc
42 -- g, the control-flow graph of a CmmProc
44 -- We expect there to be two main instances of this type:
45 -- (a) C--, i.e. populated with various C-- constructs
46 -- (Cmm and RawCmm in OldCmm.hs)
47 -- (b) Native code, populated with data/instructions
49 -- A second family of instances based on Hoopl is in Cmm.hs.
51 newtype GenCmm d h g = Cmm [GenCmmTop d h g]
53 -- | A top-level chunk, abstracted over the type of the contents of
54 -- the basic blocks (Cmm or instructions are the likely instantiations).
56 = CmmProc -- A procedure
57 h -- Extra header such as the info table
58 CLabel -- Used to generate both info & entry labels
59 g -- Control-flow graph for the procedure's code
61 | CmmData -- Static data
66 -- A basic block containing a single label, at the beginning.
67 -- The list of basic blocks in a top-level code block may be re-ordered.
68 -- Fall-through is not allowed: there must be an explicit jump at the
69 -- end of each basic block, but the code generator might rearrange basic
70 -- blocks in order to turn some jumps into fallthroughs.
73 -----------------------------------------------------------------------------
75 -----------------------------------------------------------------------------
77 -- Info table as a haskell data type
84 | CmmNonInfoTable -- Procedure doesn't need an info table
86 type HasStaticClosure = Bool
88 -- TODO: The GC target shouldn't really be part of CmmInfo
89 -- as it doesn't appear in the resulting info table.
90 -- It should be factored out.
93 = ConstrInfo ClosureLayout ConstrTag ConstrDescription
94 | FunInfo ClosureLayout C_SRT FunArity ArgDescr SlowEntry
95 | ThunkInfo ClosureLayout C_SRT
96 | ThunkSelectorInfo SelectorOffset C_SRT
98 [Maybe LocalReg] -- Stack layout: Just x, an item x
99 -- Nothing: a 1-word gap
100 -- Start of list is the *young* end
103 -- TODO: These types may need refinement
104 data ProfilingInfo = ProfilingInfo CmmLit CmmLit -- closure_type, closure_desc
105 type ClosureTypeTag = StgHalfWord
106 type ClosureLayout = (StgHalfWord, StgHalfWord) -- ptrs, nptrs
107 type ConstrTag = StgHalfWord
108 type ConstrDescription = CmmLit
109 type FunArity = StgHalfWord
110 type SlowEntry = CmmLit
111 -- We would like this to be a CLabel but
112 -- for now the parser sets this to zero on an INFO_TABLE_FUN.
113 type SelectorOffset = StgWord
115 type CmmActual = CmmExpr
116 type CmmFormal = LocalReg
117 type CmmActuals = [CmmActual]
118 type CmmFormals = [CmmFormal]
121 = NoHint | AddrHint | SignedHint
123 -- Used to give extra per-argument or per-result
124 -- information needed by foreign calling conventions
126 -----------------------------------------------------------------------------
128 -----------------------------------------------------------------------------
134 | RelocatableReadOnlyData
136 | ReadOnlyData16 -- .rodata.cst16 on x86_64, 16-byte aligned
137 | OtherSection String
140 = CmmStaticLit CmmLit
141 -- a literal value, size given by cmmLitRep of the literal.
142 | CmmUninitialised Int
143 -- uninitialised data, N bytes long
145 -- align to next N-byte boundary (N must be a power of 2).
146 | CmmDataLabel CLabel
147 -- label the current position in this section.
149 -- string of 8-bit values only, not zero terminated.