Implement unboxed sum primitive type
[ghc.git] / compiler / cmm / CmmExpr.hs
1 {-# LANGUAGE CPP #-}
2 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE FlexibleInstances #-}
4 {-# LANGUAGE MultiParamTypeClasses #-}
5 {-# LANGUAGE UndecidableInstances #-}
6
7 module CmmExpr
8 ( CmmExpr(..), cmmExprType, cmmExprWidth, maybeInvertCmmExpr
9 , CmmArg(..)
10 , CmmReg(..), cmmRegType
11 , CmmLit(..), cmmLitType
12 , LocalReg(..), localRegType
13 , GlobalReg(..), isArgReg, globalRegType, spReg, hpReg, spLimReg, nodeReg, node, baseReg
14 , VGcPtr(..)
15
16 , DefinerOfRegs, UserOfRegs
17 , foldRegsDefd, foldRegsUsed, filterRegsUsed
18 , foldLocalRegsDefd, foldLocalRegsUsed
19
20 , RegSet, LocalRegSet, GlobalRegSet
21 , emptyRegSet, elemRegSet, extendRegSet, deleteFromRegSet, mkRegSet
22 , plusRegSet, minusRegSet, timesRegSet, sizeRegSet, nullRegSet
23 , regSetToList
24
25 , Area(..)
26 , module CmmMachOp
27 , module CmmType
28 )
29 where
30
31 #include "HsVersions.h"
32
33 import BlockId
34 import CLabel
35 import CmmMachOp
36 import CmmType
37 import DynFlags
38 import Outputable (panic)
39 import Type
40 import Unique
41
42 import Data.Set (Set)
43 import qualified Data.Set as Set
44
45 -----------------------------------------------------------------------------
46 -- CmmExpr
47 -- An expression. Expressions have no side effects.
48 -----------------------------------------------------------------------------
49
50 data CmmExpr
51 = CmmLit CmmLit -- Literal
52 | CmmLoad !CmmExpr !CmmType -- Read memory location
53 | CmmReg !CmmReg -- Contents of register
54 | CmmMachOp MachOp [CmmExpr] -- Machine operation (+, -, *, etc.)
55 | CmmStackSlot Area {-# UNPACK #-} !Int
56 -- addressing expression of a stack slot
57 -- See Note [CmmStackSlot aliasing]
58 | CmmRegOff !CmmReg Int
59 -- CmmRegOff reg i
60 -- ** is shorthand only, meaning **
61 -- CmmMachOp (MO_Add rep) [x, CmmLit (CmmInt (fromIntegral i) rep)]
62 -- where rep = typeWidth (cmmRegType reg)
63
64 instance Eq CmmExpr where -- Equality ignores the types
65 CmmLit l1 == CmmLit l2 = l1==l2
66 CmmLoad e1 _ == CmmLoad e2 _ = e1==e2
67 CmmReg r1 == CmmReg r2 = r1==r2
68 CmmRegOff r1 i1 == CmmRegOff r2 i2 = r1==r2 && i1==i2
69 CmmMachOp op1 es1 == CmmMachOp op2 es2 = op1==op2 && es1==es2
70 CmmStackSlot a1 i1 == CmmStackSlot a2 i2 = a1==a2 && i1==i2
71 _e1 == _e2 = False
72
73 data CmmReg
74 = CmmLocal {-# UNPACK #-} !LocalReg
75 | CmmGlobal GlobalReg
76 deriving( Eq, Ord )
77
78 data CmmArg
79 = CmmExprArg CmmExpr
80 | CmmRubbishArg Type -- See StgRubbishArg in StgSyn.hs
81
82 -- | A stack area is either the stack slot where a variable is spilled
83 -- or the stack space where function arguments and results are passed.
84 data Area
85 = Old -- See Note [Old Area]
86 | Young {-# UNPACK #-} !BlockId -- Invariant: must be a continuation BlockId
87 -- See Note [Continuation BlockId] in CmmNode.
88 deriving (Eq, Ord)
89
90 {- Note [Old Area]
91 ~~~~~~~~~~~~~~~~~~
92 There is a single call area 'Old', allocated at the extreme old
93 end of the stack frame (ie just younger than the return address)
94 which holds:
95 * incoming (overflow) parameters,
96 * outgoing (overflow) parameter to tail calls,
97 * outgoing (overflow) result values
98 * the update frame (if any)
99
100 Its size is the max of all these requirements. On entry, the stack
101 pointer will point to the youngest incoming parameter, which is not
102 necessarily at the young end of the Old area.
103
104 End of note -}
105
106
107 {- Note [CmmStackSlot aliasing]
108 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109 When do two CmmStackSlots alias?
110
111 - T[old+N] aliases with U[young(L)+M] for all T, U, L, N and M
112 - T[old+N] aliases with U[old+M] only if the areas actually overlap
113
114 Or more informally, different Areas may overlap with each other.
115
116 An alternative semantics, that we previously had, was that different
117 Areas do not overlap. The problem that lead to redefining the
118 semantics of stack areas is described below.
119
120 e.g. if we had
121
122 x = Sp[old + 8]
123 y = Sp[old + 16]
124
125 Sp[young(L) + 8] = L
126 Sp[young(L) + 16] = y
127 Sp[young(L) + 24] = x
128 call f() returns to L
129
130 if areas semantically do not overlap, then we might optimise this to
131
132 Sp[young(L) + 8] = L
133 Sp[young(L) + 16] = Sp[old + 8]
134 Sp[young(L) + 24] = Sp[old + 16]
135 call f() returns to L
136
137 and now young(L) cannot be allocated at the same place as old, and we
138 are doomed to use more stack.
139
140 - old+8 conflicts with young(L)+8
141 - old+16 conflicts with young(L)+16 and young(L)+8
142
143 so young(L)+8 == old+24 and we get
144
145 Sp[-8] = L
146 Sp[-16] = Sp[8]
147 Sp[-24] = Sp[0]
148 Sp -= 24
149 call f() returns to L
150
151 However, if areas are defined to be "possibly overlapping" in the
152 semantics, then we cannot commute any loads/stores of old with
153 young(L), and we will be able to re-use both old+8 and old+16 for
154 young(L).
155
156 x = Sp[8]
157 y = Sp[0]
158
159 Sp[8] = L
160 Sp[0] = y
161 Sp[-8] = x
162 Sp = Sp - 8
163 call f() returns to L
164
165 Now, the assignments of y go away,
166
167 x = Sp[8]
168 Sp[8] = L
169 Sp[-8] = x
170 Sp = Sp - 8
171 call f() returns to L
172 -}
173
174 data CmmLit
175 = CmmInt !Integer Width
176 -- Interpretation: the 2's complement representation of the value
177 -- is truncated to the specified size. This is easier than trying
178 -- to keep the value within range, because we don't know whether
179 -- it will be used as a signed or unsigned value (the CmmType doesn't
180 -- distinguish between signed & unsigned).
181 | CmmFloat Rational Width
182 | CmmVec [CmmLit] -- Vector literal
183 | CmmLabel CLabel -- Address of label
184 | CmmLabelOff CLabel Int -- Address of label + byte offset
185
186 -- Due to limitations in the C backend, the following
187 -- MUST ONLY be used inside the info table indicated by label2
188 -- (label2 must be the info label), and label1 must be an
189 -- SRT, a slow entrypoint or a large bitmap (see the Mangler)
190 -- Don't use it at all unless tablesNextToCode.
191 -- It is also used inside the NCG during when generating
192 -- position-independent code.
193 | CmmLabelDiffOff CLabel CLabel Int -- label1 - label2 + offset
194
195 | CmmBlock {-# UNPACK #-} !BlockId -- Code label
196 -- Invariant: must be a continuation BlockId
197 -- See Note [Continuation BlockId] in CmmNode.
198
199 | CmmHighStackMark -- A late-bound constant that stands for the max
200 -- #bytes of stack space used during a procedure.
201 -- During the stack-layout pass, CmmHighStackMark
202 -- is replaced by a CmmInt for the actual number
203 -- of bytes used
204 deriving Eq
205
206 cmmExprType :: DynFlags -> CmmExpr -> CmmType
207 cmmExprType dflags (CmmLit lit) = cmmLitType dflags lit
208 cmmExprType _ (CmmLoad _ rep) = rep
209 cmmExprType dflags (CmmReg reg) = cmmRegType dflags reg
210 cmmExprType dflags (CmmMachOp op args) = machOpResultType dflags op (map (cmmExprType dflags) args)
211 cmmExprType dflags (CmmRegOff reg _) = cmmRegType dflags reg
212 cmmExprType dflags (CmmStackSlot _ _) = bWord dflags -- an address
213 -- Careful though: what is stored at the stack slot may be bigger than
214 -- an address
215
216 cmmLitType :: DynFlags -> CmmLit -> CmmType
217 cmmLitType _ (CmmInt _ width) = cmmBits width
218 cmmLitType _ (CmmFloat _ width) = cmmFloat width
219 cmmLitType _ (CmmVec []) = panic "cmmLitType: CmmVec []"
220 cmmLitType cflags (CmmVec (l:ls)) = let ty = cmmLitType cflags l
221 in if all (`cmmEqType` ty) (map (cmmLitType cflags) ls)
222 then cmmVec (1+length ls) ty
223 else panic "cmmLitType: CmmVec"
224 cmmLitType dflags (CmmLabel lbl) = cmmLabelType dflags lbl
225 cmmLitType dflags (CmmLabelOff lbl _) = cmmLabelType dflags lbl
226 cmmLitType dflags (CmmLabelDiffOff {}) = bWord dflags
227 cmmLitType dflags (CmmBlock _) = bWord dflags
228 cmmLitType dflags (CmmHighStackMark) = bWord dflags
229
230 cmmLabelType :: DynFlags -> CLabel -> CmmType
231 cmmLabelType dflags lbl
232 | isGcPtrLabel lbl = gcWord dflags
233 | otherwise = bWord dflags
234
235 cmmExprWidth :: DynFlags -> CmmExpr -> Width
236 cmmExprWidth dflags e = typeWidth (cmmExprType dflags e)
237
238 --------
239 --- Negation for conditional branches
240
241 maybeInvertCmmExpr :: CmmExpr -> Maybe CmmExpr
242 maybeInvertCmmExpr (CmmMachOp op args) = do op' <- maybeInvertComparison op
243 return (CmmMachOp op' args)
244 maybeInvertCmmExpr _ = Nothing
245
246 -----------------------------------------------------------------------------
247 -- Local registers
248 -----------------------------------------------------------------------------
249
250 data LocalReg
251 = LocalReg {-# UNPACK #-} !Unique CmmType
252 -- ^ Parameters:
253 -- 1. Identifier
254 -- 2. Type
255
256 instance Eq LocalReg where
257 (LocalReg u1 _) == (LocalReg u2 _) = u1 == u2
258
259 -- This is non-deterministic but we do not currently support deterministic
260 -- code-generation. See Note [Unique Determinism and code generation]
261 -- See Note [No Ord for Unique]
262 instance Ord LocalReg where
263 compare (LocalReg u1 _) (LocalReg u2 _) = nonDetCmpUnique u1 u2
264
265 instance Uniquable LocalReg where
266 getUnique (LocalReg uniq _) = uniq
267
268 cmmRegType :: DynFlags -> CmmReg -> CmmType
269 cmmRegType _ (CmmLocal reg) = localRegType reg
270 cmmRegType dflags (CmmGlobal reg) = globalRegType dflags reg
271
272 localRegType :: LocalReg -> CmmType
273 localRegType (LocalReg _ rep) = rep
274
275 -----------------------------------------------------------------------------
276 -- Register-use information for expressions and other types
277 -----------------------------------------------------------------------------
278
279 -- | Sets of registers
280
281 -- These are used for dataflow facts, and a common operation is taking
282 -- the union of two RegSets and then asking whether the union is the
283 -- same as one of the inputs. UniqSet isn't good here, because
284 -- sizeUniqSet is O(n) whereas Set.size is O(1), so we use ordinary
285 -- Sets.
286
287 type RegSet r = Set r
288 type LocalRegSet = RegSet LocalReg
289 type GlobalRegSet = RegSet GlobalReg
290
291 emptyRegSet :: RegSet r
292 nullRegSet :: RegSet r -> Bool
293 elemRegSet :: Ord r => r -> RegSet r -> Bool
294 extendRegSet :: Ord r => RegSet r -> r -> RegSet r
295 deleteFromRegSet :: Ord r => RegSet r -> r -> RegSet r
296 mkRegSet :: Ord r => [r] -> RegSet r
297 minusRegSet, plusRegSet, timesRegSet :: Ord r => RegSet r -> RegSet r -> RegSet r
298 sizeRegSet :: RegSet r -> Int
299 regSetToList :: RegSet r -> [r]
300
301 emptyRegSet = Set.empty
302 nullRegSet = Set.null
303 elemRegSet = Set.member
304 extendRegSet = flip Set.insert
305 deleteFromRegSet = flip Set.delete
306 mkRegSet = Set.fromList
307 minusRegSet = Set.difference
308 plusRegSet = Set.union
309 timesRegSet = Set.intersection
310 sizeRegSet = Set.size
311 regSetToList = Set.toList
312
313 class Ord r => UserOfRegs r a where
314 foldRegsUsed :: DynFlags -> (b -> r -> b) -> b -> a -> b
315
316 foldLocalRegsUsed :: UserOfRegs LocalReg a
317 => DynFlags -> (b -> LocalReg -> b) -> b -> a -> b
318 foldLocalRegsUsed = foldRegsUsed
319
320 class Ord r => DefinerOfRegs r a where
321 foldRegsDefd :: DynFlags -> (b -> r -> b) -> b -> a -> b
322
323 foldLocalRegsDefd :: DefinerOfRegs LocalReg a
324 => DynFlags -> (b -> LocalReg -> b) -> b -> a -> b
325 foldLocalRegsDefd = foldRegsDefd
326
327 filterRegsUsed :: UserOfRegs r e => DynFlags -> (r -> Bool) -> e -> RegSet r
328 filterRegsUsed dflags p e =
329 foldRegsUsed dflags
330 (\regs r -> if p r then extendRegSet regs r else regs)
331 emptyRegSet e
332
333 instance UserOfRegs LocalReg CmmReg where
334 foldRegsUsed _ f z (CmmLocal reg) = f z reg
335 foldRegsUsed _ _ z (CmmGlobal _) = z
336
337 instance DefinerOfRegs LocalReg CmmReg where
338 foldRegsDefd _ f z (CmmLocal reg) = f z reg
339 foldRegsDefd _ _ z (CmmGlobal _) = z
340
341 instance UserOfRegs GlobalReg CmmReg where
342 foldRegsUsed _ _ z (CmmLocal _) = z
343 foldRegsUsed _ f z (CmmGlobal reg) = f z reg
344
345 instance DefinerOfRegs GlobalReg CmmReg where
346 foldRegsDefd _ _ z (CmmLocal _) = z
347 foldRegsDefd _ f z (CmmGlobal reg) = f z reg
348
349 instance Ord r => UserOfRegs r r where
350 foldRegsUsed _ f z r = f z r
351
352 instance Ord r => DefinerOfRegs r r where
353 foldRegsDefd _ f z r = f z r
354
355 instance Ord r => UserOfRegs r (RegSet r) where
356 foldRegsUsed _ f = Set.fold (flip f)
357
358 instance (Ord r, UserOfRegs r CmmReg) => UserOfRegs r CmmExpr where
359 -- The (Ord r) in the context is necessary here
360 -- See Note [Recursive superclasses] in TcInstDcls
361 foldRegsUsed dflags f z e = expr z e
362 where expr z (CmmLit _) = z
363 expr z (CmmLoad addr _) = foldRegsUsed dflags f z addr
364 expr z (CmmReg r) = foldRegsUsed dflags f z r
365 expr z (CmmMachOp _ exprs) = foldRegsUsed dflags f z exprs
366 expr z (CmmRegOff r _) = foldRegsUsed dflags f z r
367 expr z (CmmStackSlot _ _) = z
368
369 instance UserOfRegs r a => UserOfRegs r (Maybe a) where
370 foldRegsUsed dflags f z (Just x) = foldRegsUsed dflags f z x
371 foldRegsUsed _ _ z Nothing = z
372
373 instance UserOfRegs r a => UserOfRegs r [a] where
374 foldRegsUsed _ _ set [] = set
375 foldRegsUsed dflags f set (x:xs) = foldRegsUsed dflags f (foldRegsUsed dflags f set x) xs
376
377 instance DefinerOfRegs r a => DefinerOfRegs r [a] where
378 foldRegsDefd _ _ set [] = set
379 foldRegsDefd dflags f set (x:xs) = foldRegsDefd dflags f (foldRegsDefd dflags f set x) xs
380
381 instance DefinerOfRegs r a => DefinerOfRegs r (Maybe a) where
382 foldRegsDefd _ _ set Nothing = set
383 foldRegsDefd dflags f set (Just x) = foldRegsDefd dflags f set x
384
385 -----------------------------------------------------------------------------
386 -- Global STG registers
387 -----------------------------------------------------------------------------
388
389 data VGcPtr = VGcPtr | VNonGcPtr deriving( Eq, Show )
390
391 -----------------------------------------------------------------------------
392 -- Global STG registers
393 -----------------------------------------------------------------------------
394 {-
395 Note [Overlapping global registers]
396
397 The backend might not faithfully implement the abstraction of the STG
398 machine with independent registers for different values of type
399 GlobalReg. Specifically, certain pairs of registers (r1, r2) may
400 overlap in the sense that a store to r1 invalidates the value in r2,
401 and vice versa.
402
403 Currently this occurs only on the x86_64 architecture where FloatReg n
404 and DoubleReg n are assigned the same microarchitectural register, in
405 order to allow functions to receive more Float# or Double# arguments
406 in registers (as opposed to on the stack).
407
408 There are no specific rules about which registers might overlap with
409 which other registers, but presumably it's safe to assume that nothing
410 will overlap with special registers like Sp or BaseReg.
411
412 Use CmmUtils.regsOverlap to determine whether two GlobalRegs overlap
413 on a particular platform. The instance Eq GlobalReg is syntactic
414 equality of STG registers and does not take overlap into
415 account. However it is still used in UserOfRegs/DefinerOfRegs and
416 there are likely still bugs there, beware!
417 -}
418
419 data GlobalReg
420 -- Argument and return registers
421 = VanillaReg -- pointers, unboxed ints and chars
422 {-# UNPACK #-} !Int -- its number
423 VGcPtr
424
425 | FloatReg -- single-precision floating-point registers
426 {-# UNPACK #-} !Int -- its number
427
428 | DoubleReg -- double-precision floating-point registers
429 {-# UNPACK #-} !Int -- its number
430
431 | LongReg -- long int registers (64-bit, really)
432 {-# UNPACK #-} !Int -- its number
433
434 | XmmReg -- 128-bit SIMD vector register
435 {-# UNPACK #-} !Int -- its number
436
437 | YmmReg -- 256-bit SIMD vector register
438 {-# UNPACK #-} !Int -- its number
439
440 | ZmmReg -- 512-bit SIMD vector register
441 {-# UNPACK #-} !Int -- its number
442
443 -- STG registers
444 | Sp -- Stack ptr; points to last occupied stack location.
445 | SpLim -- Stack limit
446 | Hp -- Heap ptr; points to last occupied heap location.
447 | HpLim -- Heap limit register
448 | CCCS -- Current cost-centre stack
449 | CurrentTSO -- pointer to current thread's TSO
450 | CurrentNursery -- pointer to allocation area
451 | HpAlloc -- allocation count for heap check failure
452
453 -- We keep the address of some commonly-called
454 -- functions in the register table, to keep code
455 -- size down:
456 | EagerBlackholeInfo -- stg_EAGER_BLACKHOLE_info
457 | GCEnter1 -- stg_gc_enter_1
458 | GCFun -- stg_gc_fun
459
460 -- Base offset for the register table, used for accessing registers
461 -- which do not have real registers assigned to them. This register
462 -- will only appear after we have expanded GlobalReg into memory accesses
463 -- (where necessary) in the native code generator.
464 | BaseReg
465
466 -- The register used by the platform for the C stack pointer. This is
467 -- a break in the STG abstraction used exclusively to setup stack unwinding
468 -- information.
469 | MachSp
470
471 -- The is a dummy register used to indicate to the stack unwinder where
472 -- a routine would return to.
473 | UnwindReturnReg
474
475 -- Base Register for PIC (position-independent code) calculations
476 -- Only used inside the native code generator. It's exact meaning differs
477 -- from platform to platform (see module PositionIndependentCode).
478 | PicBaseReg
479
480 deriving( Show )
481
482 instance Eq GlobalReg where
483 VanillaReg i _ == VanillaReg j _ = i==j -- Ignore type when seeking clashes
484 FloatReg i == FloatReg j = i==j
485 DoubleReg i == DoubleReg j = i==j
486 LongReg i == LongReg j = i==j
487 XmmReg i == XmmReg j = i==j
488 YmmReg i == YmmReg j = i==j
489 ZmmReg i == ZmmReg j = i==j
490 Sp == Sp = True
491 SpLim == SpLim = True
492 Hp == Hp = True
493 HpLim == HpLim = True
494 CCCS == CCCS = True
495 CurrentTSO == CurrentTSO = True
496 CurrentNursery == CurrentNursery = True
497 HpAlloc == HpAlloc = True
498 EagerBlackholeInfo == EagerBlackholeInfo = True
499 GCEnter1 == GCEnter1 = True
500 GCFun == GCFun = True
501 BaseReg == BaseReg = True
502 MachSp == MachSp = True
503 UnwindReturnReg == UnwindReturnReg = True
504 PicBaseReg == PicBaseReg = True
505 _r1 == _r2 = False
506
507 instance Ord GlobalReg where
508 compare (VanillaReg i _) (VanillaReg j _) = compare i j
509 -- Ignore type when seeking clashes
510 compare (FloatReg i) (FloatReg j) = compare i j
511 compare (DoubleReg i) (DoubleReg j) = compare i j
512 compare (LongReg i) (LongReg j) = compare i j
513 compare (XmmReg i) (XmmReg j) = compare i j
514 compare (YmmReg i) (YmmReg j) = compare i j
515 compare (ZmmReg i) (ZmmReg j) = compare i j
516 compare Sp Sp = EQ
517 compare SpLim SpLim = EQ
518 compare Hp Hp = EQ
519 compare HpLim HpLim = EQ
520 compare CCCS CCCS = EQ
521 compare CurrentTSO CurrentTSO = EQ
522 compare CurrentNursery CurrentNursery = EQ
523 compare HpAlloc HpAlloc = EQ
524 compare EagerBlackholeInfo EagerBlackholeInfo = EQ
525 compare GCEnter1 GCEnter1 = EQ
526 compare GCFun GCFun = EQ
527 compare BaseReg BaseReg = EQ
528 compare MachSp MachSp = EQ
529 compare UnwindReturnReg UnwindReturnReg = EQ
530 compare PicBaseReg PicBaseReg = EQ
531 compare (VanillaReg _ _) _ = LT
532 compare _ (VanillaReg _ _) = GT
533 compare (FloatReg _) _ = LT
534 compare _ (FloatReg _) = GT
535 compare (DoubleReg _) _ = LT
536 compare _ (DoubleReg _) = GT
537 compare (LongReg _) _ = LT
538 compare _ (LongReg _) = GT
539 compare (XmmReg _) _ = LT
540 compare _ (XmmReg _) = GT
541 compare (YmmReg _) _ = LT
542 compare _ (YmmReg _) = GT
543 compare (ZmmReg _) _ = LT
544 compare _ (ZmmReg _) = GT
545 compare Sp _ = LT
546 compare _ Sp = GT
547 compare SpLim _ = LT
548 compare _ SpLim = GT
549 compare Hp _ = LT
550 compare _ Hp = GT
551 compare HpLim _ = LT
552 compare _ HpLim = GT
553 compare CCCS _ = LT
554 compare _ CCCS = GT
555 compare CurrentTSO _ = LT
556 compare _ CurrentTSO = GT
557 compare CurrentNursery _ = LT
558 compare _ CurrentNursery = GT
559 compare HpAlloc _ = LT
560 compare _ HpAlloc = GT
561 compare GCEnter1 _ = LT
562 compare _ GCEnter1 = GT
563 compare GCFun _ = LT
564 compare _ GCFun = GT
565 compare BaseReg _ = LT
566 compare _ BaseReg = GT
567 compare MachSp _ = LT
568 compare _ MachSp = GT
569 compare UnwindReturnReg _ = LT
570 compare _ UnwindReturnReg = GT
571 compare EagerBlackholeInfo _ = LT
572 compare _ EagerBlackholeInfo = GT
573
574 -- convenient aliases
575 baseReg, spReg, hpReg, spLimReg, nodeReg :: CmmReg
576 baseReg = CmmGlobal BaseReg
577 spReg = CmmGlobal Sp
578 hpReg = CmmGlobal Hp
579 spLimReg = CmmGlobal SpLim
580 nodeReg = CmmGlobal node
581
582 node :: GlobalReg
583 node = VanillaReg 1 VGcPtr
584
585 globalRegType :: DynFlags -> GlobalReg -> CmmType
586 globalRegType dflags (VanillaReg _ VGcPtr) = gcWord dflags
587 globalRegType dflags (VanillaReg _ VNonGcPtr) = bWord dflags
588 globalRegType _ (FloatReg _) = cmmFloat W32
589 globalRegType _ (DoubleReg _) = cmmFloat W64
590 globalRegType _ (LongReg _) = cmmBits W64
591 globalRegType _ (XmmReg _) = cmmVec 4 (cmmBits W32)
592 globalRegType _ (YmmReg _) = cmmVec 8 (cmmBits W32)
593 globalRegType _ (ZmmReg _) = cmmVec 16 (cmmBits W32)
594
595 globalRegType dflags Hp = gcWord dflags
596 -- The initialiser for all
597 -- dynamically allocated closures
598 globalRegType dflags _ = bWord dflags
599
600 isArgReg :: GlobalReg -> Bool
601 isArgReg (VanillaReg {}) = True
602 isArgReg (FloatReg {}) = True
603 isArgReg (DoubleReg {}) = True
604 isArgReg (LongReg {}) = True
605 isArgReg (XmmReg {}) = True
606 isArgReg (YmmReg {}) = True
607 isArgReg (ZmmReg {}) = True
608 isArgReg _ = False