module CmmCallConv (
  ParamLocation(..),
  assignArgumentsPos,
  assignStack,
  realArgRegsCover
) where

import GhcPrelude

import CmmExpr
import SMRep
import Cmm (Convention(..))
import PprCmm ()

import DynFlags
import Platform
import Outputable

-- Calculate the 'GlobalReg' or stack locations for function call
-- parameters as used by the Cmm calling convention.

data ParamLocation
  = RegisterParam GlobalReg
  | StackParam ByteOff

instance Outputable ParamLocation where
  ppr :: ParamLocation -> SDoc
ppr (RegisterParam g :: GlobalReg
g) = GlobalReg -> SDoc
forall a. Outputable a => a -> SDoc
ppr GlobalReg
g
  ppr (StackParam p :: ByteOff
p)    = ByteOff -> SDoc
forall a. Outputable a => a -> SDoc
ppr ByteOff
p

-- |
-- Given a list of arguments, and a function that tells their types,
-- return a list showing where each argument is passed
--
assignArgumentsPos :: DynFlags
                   -> ByteOff           -- stack offset to start with
                   -> Convention
                   -> (a -> CmmType)    -- how to get a type from an arg
                   -> [a]               -- args
                   -> (
                        ByteOff              -- bytes of stack args
                      , [(a, ParamLocation)] -- args and locations
                      )

assignArgumentsPos :: DynFlags
-> ByteOff
-> Convention
-> (a -> CmmType)
-> [a]
-> (ByteOff, [(a, ParamLocation)])
assignArgumentsPos dflags :: DynFlags
dflags off :: ByteOff
off conv :: Convention
conv arg_ty :: a -> CmmType
arg_ty reps :: [a]
reps = (ByteOff
stk_off, [(a, ParamLocation)]
assignments)
    where
      regs :: AvailRegs
regs = case ([a]
reps, Convention
conv) of
               (_,   NativeNodeCall)   -> DynFlags -> AvailRegs
getRegsWithNode DynFlags
dflags
               (_,   NativeDirectCall) -> DynFlags -> AvailRegs
getRegsWithoutNode DynFlags
dflags
               ([_], NativeReturn)     -> DynFlags -> AvailRegs
allRegs DynFlags
dflags
               (_,   NativeReturn)     -> DynFlags -> AvailRegs
getRegsWithNode DynFlags
dflags
               -- GC calling convention *must* put values in registers
               (_,   GC)               -> DynFlags -> AvailRegs
allRegs DynFlags
dflags
               (_,   Slow)             -> AvailRegs
nodeOnly
      -- The calling conventions first assign arguments to registers,
      -- then switch to the stack when we first run out of registers
      -- (even if there are still available registers for args of a
      -- different type).  When returning an unboxed tuple, we also
      -- separate the stack arguments by pointerhood.
      (reg_assts :: [(a, ParamLocation)]
reg_assts, stk_args :: [a]
stk_args)  = [(a, ParamLocation)]
-> [a] -> AvailRegs -> ([(a, ParamLocation)], [a])
assign_regs [] [a]
reps AvailRegs
regs
      (stk_off :: ByteOff
stk_off,   stk_assts :: [(a, ParamLocation)]
stk_assts) = DynFlags
-> ByteOff
-> (a -> CmmType)
-> [a]
-> (ByteOff, [(a, ParamLocation)])
forall a.
DynFlags
-> ByteOff
-> (a -> CmmType)
-> [a]
-> (ByteOff, [(a, ParamLocation)])
assignStack DynFlags
dflags ByteOff
off a -> CmmType
arg_ty [a]
stk_args
      assignments :: [(a, ParamLocation)]
assignments = [(a, ParamLocation)]
reg_assts [(a, ParamLocation)]
-> [(a, ParamLocation)] -> [(a, ParamLocation)]
forall a. [a] -> [a] -> [a]
++ [(a, ParamLocation)]
stk_assts

      assign_regs :: [(a, ParamLocation)]
-> [a] -> AvailRegs -> ([(a, ParamLocation)], [a])
assign_regs assts :: [(a, ParamLocation)]
assts []     _    = ([(a, ParamLocation)]
assts, [])
      assign_regs assts :: [(a, ParamLocation)]
assts (r :: a
r:rs :: [a]
rs) regs :: AvailRegs
regs | CmmType -> Bool
isVecType CmmType
ty   = ([(a, ParamLocation)], [a])
vec
                                    | CmmType -> Bool
isFloatType CmmType
ty = ([(a, ParamLocation)], [a])
float
                                    | Bool
otherwise      = ([(a, ParamLocation)], [a])
int
        where vec :: ([(a, ParamLocation)], [a])
vec = case (Width
w, AvailRegs
regs) of
                      (W128, (vs :: [VGcPtr -> GlobalReg]
vs, fs :: [GlobalReg]
fs, ds :: [GlobalReg]
ds, ls :: [GlobalReg]
ls, s :: ByteOff
s:ss :: [ByteOff]
ss))
                          | Width -> DynFlags -> Bool
passVectorInReg Width
W128 DynFlags
dflags -> (ParamLocation, AvailRegs) -> ([(a, ParamLocation)], [a])
k (GlobalReg -> ParamLocation
RegisterParam (ByteOff -> GlobalReg
XmmReg ByteOff
s), ([VGcPtr -> GlobalReg]
vs, [GlobalReg]
fs, [GlobalReg]
ds, [GlobalReg]
ls, [ByteOff]
ss))
                      (W256, (vs :: [VGcPtr -> GlobalReg]
vs, fs :: [GlobalReg]
fs, ds :: [GlobalReg]
ds, ls :: [GlobalReg]
ls, s :: ByteOff
s:ss :: [ByteOff]
ss))
                          | Width -> DynFlags -> Bool
passVectorInReg Width
W256 DynFlags
dflags -> (ParamLocation, AvailRegs) -> ([(a, ParamLocation)], [a])
k (GlobalReg -> ParamLocation
RegisterParam (ByteOff -> GlobalReg
YmmReg ByteOff
s), ([VGcPtr -> GlobalReg]
vs, [GlobalReg]
fs, [GlobalReg]
ds, [GlobalReg]
ls, [ByteOff]
ss))
                      (W512, (vs :: [VGcPtr -> GlobalReg]
vs, fs :: [GlobalReg]
fs, ds :: [GlobalReg]
ds, ls :: [GlobalReg]
ls, s :: ByteOff
s:ss :: [ByteOff]
ss))
                          | Width -> DynFlags -> Bool
passVectorInReg Width
W512 DynFlags
dflags -> (ParamLocation, AvailRegs) -> ([(a, ParamLocation)], [a])
k (GlobalReg -> ParamLocation
RegisterParam (ByteOff -> GlobalReg
ZmmReg ByteOff
s), ([VGcPtr -> GlobalReg]
vs, [GlobalReg]
fs, [GlobalReg]
ds, [GlobalReg]
ls, [ByteOff]
ss))
                      _ -> ([(a, ParamLocation)]
assts, (a
ra -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
rs))
              float :: ([(a, ParamLocation)], [a])
float = case (Width
w, AvailRegs
regs) of
                        (W32, (vs :: [VGcPtr -> GlobalReg]
vs, fs :: [GlobalReg]
fs, ds :: [GlobalReg]
ds, ls :: [GlobalReg]
ls, s :: ByteOff
s:ss :: [ByteOff]
ss))
                            | Bool
passFloatInXmm          -> (ParamLocation, AvailRegs) -> ([(a, ParamLocation)], [a])
k (GlobalReg -> ParamLocation
RegisterParam (ByteOff -> GlobalReg
FloatReg ByteOff
s), ([VGcPtr -> GlobalReg]
vs, [GlobalReg]
fs, [GlobalReg]
ds, [GlobalReg]
ls, [ByteOff]
ss))
                        (W32, (vs :: [VGcPtr -> GlobalReg]
vs, f :: GlobalReg
f:fs :: [GlobalReg]
fs, ds :: [GlobalReg]
ds, ls :: [GlobalReg]
ls, ss :: [ByteOff]
ss))
                            | Bool -> Bool
not Bool
passFloatInXmm      -> (ParamLocation, AvailRegs) -> ([(a, ParamLocation)], [a])
k (GlobalReg -> ParamLocation
RegisterParam GlobalReg
f, ([VGcPtr -> GlobalReg]
vs, [GlobalReg]
fs, [GlobalReg]
ds, [GlobalReg]
ls, [ByteOff]
ss))
                        (W64, (vs :: [VGcPtr -> GlobalReg]
vs, fs :: [GlobalReg]
fs, ds :: [GlobalReg]
ds, ls :: [GlobalReg]
ls, s :: ByteOff
s:ss :: [ByteOff]
ss))
                            | Bool
passFloatInXmm          -> (ParamLocation, AvailRegs) -> ([(a, ParamLocation)], [a])
k (GlobalReg -> ParamLocation
RegisterParam (ByteOff -> GlobalReg
DoubleReg ByteOff
s), ([VGcPtr -> GlobalReg]
vs, [GlobalReg]
fs, [GlobalReg]
ds, [GlobalReg]
ls, [ByteOff]
ss))
                        (W64, (vs :: [VGcPtr -> GlobalReg]
vs, fs :: [GlobalReg]
fs, d :: GlobalReg
d:ds :: [GlobalReg]
ds, ls :: [GlobalReg]
ls, ss :: [ByteOff]
ss))
                            | Bool -> Bool
not Bool
passFloatInXmm      -> (ParamLocation, AvailRegs) -> ([(a, ParamLocation)], [a])
k (GlobalReg -> ParamLocation
RegisterParam GlobalReg
d, ([VGcPtr -> GlobalReg]
vs, [GlobalReg]
fs, [GlobalReg]
ds, [GlobalReg]
ls, [ByteOff]
ss))
                        (W80, _) -> String -> ([(a, ParamLocation)], [a])
forall a. String -> a
panic "F80 unsupported register type"
                        _ -> ([(a, ParamLocation)]
assts, (a
ra -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
rs))
              int :: ([(a, ParamLocation)], [a])
int = case (Width
w, AvailRegs
regs) of
                      (W128, _) -> String -> ([(a, ParamLocation)], [a])
forall a. String -> a
panic "W128 unsupported register type"
                      (_, (v :: VGcPtr -> GlobalReg
v:vs :: [VGcPtr -> GlobalReg]
vs, fs :: [GlobalReg]
fs, ds :: [GlobalReg]
ds, ls :: [GlobalReg]
ls, ss :: [ByteOff]
ss)) | Width -> ByteOff
widthInBits Width
w ByteOff -> ByteOff -> Bool
forall a. Ord a => a -> a -> Bool
<= Width -> ByteOff
widthInBits (DynFlags -> Width
wordWidth DynFlags
dflags)
                          -> (ParamLocation, AvailRegs) -> ([(a, ParamLocation)], [a])
k (GlobalReg -> ParamLocation
RegisterParam (VGcPtr -> GlobalReg
v VGcPtr
gcp), ([VGcPtr -> GlobalReg]
vs, [GlobalReg]
fs, [GlobalReg]
ds, [GlobalReg]
ls, [ByteOff]
ss))
                      (_, (vs :: [VGcPtr -> GlobalReg]
vs, fs :: [GlobalReg]
fs, ds :: [GlobalReg]
ds, l :: GlobalReg
l:ls :: [GlobalReg]
ls, ss :: [ByteOff]
ss)) | Width -> ByteOff
widthInBits Width
w ByteOff -> ByteOff -> Bool
forall a. Ord a => a -> a -> Bool
> Width -> ByteOff
widthInBits (DynFlags -> Width
wordWidth DynFlags
dflags)
                          -> (ParamLocation, AvailRegs) -> ([(a, ParamLocation)], [a])
k (GlobalReg -> ParamLocation
RegisterParam GlobalReg
l, ([VGcPtr -> GlobalReg]
vs, [GlobalReg]
fs, [GlobalReg]
ds, [GlobalReg]
ls, [ByteOff]
ss))
                      _   -> ([(a, ParamLocation)]
assts, (a
ra -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
rs))
              k :: (ParamLocation, AvailRegs) -> ([(a, ParamLocation)], [a])
k (asst :: ParamLocation
asst, regs' :: AvailRegs
regs') = [(a, ParamLocation)]
-> [a] -> AvailRegs -> ([(a, ParamLocation)], [a])
assign_regs ((a
r, ParamLocation
asst) (a, ParamLocation) -> [(a, ParamLocation)] -> [(a, ParamLocation)]
forall a. a -> [a] -> [a]
: [(a, ParamLocation)]
assts) [a]
rs AvailRegs
regs'
              ty :: CmmType
ty = a -> CmmType
arg_ty a
r
              w :: Width
w  = CmmType -> Width
typeWidth CmmType
ty
              gcp :: VGcPtr
gcp | CmmType -> Bool
isGcPtrType CmmType
ty = VGcPtr
VGcPtr
                  | Bool
otherwise      = VGcPtr
VNonGcPtr
              passFloatInXmm :: Bool
passFloatInXmm = DynFlags -> Bool
passFloatArgsInXmm DynFlags
dflags

passFloatArgsInXmm :: DynFlags -> Bool
passFloatArgsInXmm :: DynFlags -> Bool
passFloatArgsInXmm dflags :: DynFlags
dflags = case Platform -> Arch
platformArch (DynFlags -> Platform
targetPlatform DynFlags
dflags) of
                              ArchX86_64 -> Bool
True
                              _          -> Bool
False

-- We used to spill vector registers to the stack since the LLVM backend didn't
-- support vector registers in its calling convention. However, this has now
-- been fixed. This function remains only as a convenient way to re-enable
-- spilling when debugging code generation.
passVectorInReg :: Width -> DynFlags -> Bool
passVectorInReg :: Width -> DynFlags -> Bool
passVectorInReg _ _ = Bool
True

assignStack :: DynFlags -> ByteOff -> (a -> CmmType) -> [a]
            -> (
                 ByteOff              -- bytes of stack args
               , [(a, ParamLocation)] -- args and locations
               )
assignStack :: DynFlags
-> ByteOff
-> (a -> CmmType)
-> [a]
-> (ByteOff, [(a, ParamLocation)])
assignStack dflags :: DynFlags
dflags offset :: ByteOff
offset arg_ty :: a -> CmmType
arg_ty args :: [a]
args = ByteOff
-> [(a, ParamLocation)] -> [a] -> (ByteOff, [(a, ParamLocation)])
assign_stk ByteOff
offset [] ([a] -> [a]
forall a. [a] -> [a]
reverse [a]
args)
 where
      assign_stk :: ByteOff
-> [(a, ParamLocation)] -> [a] -> (ByteOff, [(a, ParamLocation)])
assign_stk offset :: ByteOff
offset assts :: [(a, ParamLocation)]
assts [] = (ByteOff
offset, [(a, ParamLocation)]
assts)
      assign_stk offset :: ByteOff
offset assts :: [(a, ParamLocation)]
assts (r :: a
r:rs :: [a]
rs)
        = ByteOff
-> [(a, ParamLocation)] -> [a] -> (ByteOff, [(a, ParamLocation)])
assign_stk ByteOff
off' ((a
r, ByteOff -> ParamLocation
StackParam ByteOff
off') (a, ParamLocation) -> [(a, ParamLocation)] -> [(a, ParamLocation)]
forall a. a -> [a] -> [a]
: [(a, ParamLocation)]
assts) [a]
rs
        where w :: Width
w    = CmmType -> Width
typeWidth (a -> CmmType
arg_ty a
r)
              off' :: ByteOff
off' = ByteOff
offset ByteOff -> ByteOff -> ByteOff
forall a. Num a => a -> a -> a
+ ByteOff
size
              -- Stack arguments always take a whole number of words, we never
              -- pack them unlike constructor fields.
              size :: ByteOff
size = DynFlags -> ByteOff -> ByteOff
roundUpToWords DynFlags
dflags (Width -> ByteOff
widthInBytes Width
w)

-----------------------------------------------------------------------------
-- Local information about the registers available

type AvailRegs = ( [VGcPtr -> GlobalReg]   -- available vanilla regs.
                 , [GlobalReg]   -- floats
                 , [GlobalReg]   -- doubles
                 , [GlobalReg]   -- longs (int64 and word64)
                 , [Int]         -- XMM (floats and doubles)
                 )

-- Vanilla registers can contain pointers, Ints, Chars.
-- Floats and doubles have separate register supplies.
--
-- We take these register supplies from the *real* registers, i.e. those
-- that are guaranteed to map to machine registers.

getRegsWithoutNode, getRegsWithNode :: DynFlags -> AvailRegs
getRegsWithoutNode :: DynFlags -> AvailRegs
getRegsWithoutNode dflags :: DynFlags
dflags =
  ( ((VGcPtr -> GlobalReg) -> Bool)
-> [VGcPtr -> GlobalReg] -> [VGcPtr -> GlobalReg]
forall a. (a -> Bool) -> [a] -> [a]
filter (\r :: VGcPtr -> GlobalReg
r -> VGcPtr -> GlobalReg
r VGcPtr
VGcPtr GlobalReg -> GlobalReg -> Bool
forall a. Eq a => a -> a -> Bool
/= GlobalReg
node) (DynFlags -> [VGcPtr -> GlobalReg]
realVanillaRegs DynFlags
dflags)
  , DynFlags -> [GlobalReg]
realFloatRegs DynFlags
dflags
  , DynFlags -> [GlobalReg]
realDoubleRegs DynFlags
dflags
  , DynFlags -> [GlobalReg]
realLongRegs DynFlags
dflags
  , DynFlags -> [ByteOff]
realXmmRegNos DynFlags
dflags)

-- getRegsWithNode uses R1/node even if it isn't a register
getRegsWithNode :: DynFlags -> AvailRegs
getRegsWithNode dflags :: DynFlags
dflags =
  ( if [VGcPtr -> GlobalReg] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (DynFlags -> [VGcPtr -> GlobalReg]
realVanillaRegs DynFlags
dflags)
    then [ByteOff -> VGcPtr -> GlobalReg
VanillaReg 1]
    else DynFlags -> [VGcPtr -> GlobalReg]
realVanillaRegs DynFlags
dflags
  , DynFlags -> [GlobalReg]
realFloatRegs DynFlags
dflags
  , DynFlags -> [GlobalReg]
realDoubleRegs DynFlags
dflags
  , DynFlags -> [GlobalReg]
realLongRegs DynFlags
dflags
  , DynFlags -> [ByteOff]
realXmmRegNos DynFlags
dflags)

allFloatRegs, allDoubleRegs, allLongRegs :: DynFlags -> [GlobalReg]
allVanillaRegs :: DynFlags -> [VGcPtr -> GlobalReg]
allXmmRegs :: DynFlags -> [Int]

allVanillaRegs :: DynFlags -> [VGcPtr -> GlobalReg]
allVanillaRegs dflags :: DynFlags
dflags = (ByteOff -> VGcPtr -> GlobalReg)
-> [ByteOff] -> [VGcPtr -> GlobalReg]
forall a b. (a -> b) -> [a] -> [b]
map ByteOff -> VGcPtr -> GlobalReg
VanillaReg ([ByteOff] -> [VGcPtr -> GlobalReg])
-> [ByteOff] -> [VGcPtr -> GlobalReg]
forall a b. (a -> b) -> a -> b
$ ByteOff -> [ByteOff]
regList (DynFlags -> ByteOff
mAX_Vanilla_REG DynFlags
dflags)
allFloatRegs :: DynFlags -> [GlobalReg]
allFloatRegs   dflags :: DynFlags
dflags = (ByteOff -> GlobalReg) -> [ByteOff] -> [GlobalReg]
forall a b. (a -> b) -> [a] -> [b]
map ByteOff -> GlobalReg
FloatReg   ([ByteOff] -> [GlobalReg]) -> [ByteOff] -> [GlobalReg]
forall a b. (a -> b) -> a -> b
$ ByteOff -> [ByteOff]
regList (DynFlags -> ByteOff
mAX_Float_REG   DynFlags
dflags)
allDoubleRegs :: DynFlags -> [GlobalReg]
allDoubleRegs  dflags :: DynFlags
dflags = (ByteOff -> GlobalReg) -> [ByteOff] -> [GlobalReg]
forall a b. (a -> b) -> [a] -> [b]
map ByteOff -> GlobalReg
DoubleReg  ([ByteOff] -> [GlobalReg]) -> [ByteOff] -> [GlobalReg]
forall a b. (a -> b) -> a -> b
$ ByteOff -> [ByteOff]
regList (DynFlags -> ByteOff
mAX_Double_REG  DynFlags
dflags)
allLongRegs :: DynFlags -> [GlobalReg]
allLongRegs    dflags :: DynFlags
dflags = (ByteOff -> GlobalReg) -> [ByteOff] -> [GlobalReg]
forall a b. (a -> b) -> [a] -> [b]
map ByteOff -> GlobalReg
LongReg    ([ByteOff] -> [GlobalReg]) -> [ByteOff] -> [GlobalReg]
forall a b. (a -> b) -> a -> b
$ ByteOff -> [ByteOff]
regList (DynFlags -> ByteOff
mAX_Long_REG    DynFlags
dflags)
allXmmRegs :: DynFlags -> [ByteOff]
allXmmRegs     dflags :: DynFlags
dflags =                  ByteOff -> [ByteOff]
regList (DynFlags -> ByteOff
mAX_XMM_REG     DynFlags
dflags)

realFloatRegs, realDoubleRegs, realLongRegs :: DynFlags -> [GlobalReg]
realVanillaRegs :: DynFlags -> [VGcPtr -> GlobalReg]
realXmmRegNos :: DynFlags -> [Int]

realVanillaRegs :: DynFlags -> [VGcPtr -> GlobalReg]
realVanillaRegs dflags :: DynFlags
dflags = (ByteOff -> VGcPtr -> GlobalReg)
-> [ByteOff] -> [VGcPtr -> GlobalReg]
forall a b. (a -> b) -> [a] -> [b]
map ByteOff -> VGcPtr -> GlobalReg
VanillaReg ([ByteOff] -> [VGcPtr -> GlobalReg])
-> [ByteOff] -> [VGcPtr -> GlobalReg]
forall a b. (a -> b) -> a -> b
$ ByteOff -> [ByteOff]
regList (DynFlags -> ByteOff
mAX_Real_Vanilla_REG DynFlags
dflags)
realFloatRegs :: DynFlags -> [GlobalReg]
realFloatRegs   dflags :: DynFlags
dflags = (ByteOff -> GlobalReg) -> [ByteOff] -> [GlobalReg]
forall a b. (a -> b) -> [a] -> [b]
map ByteOff -> GlobalReg
FloatReg   ([ByteOff] -> [GlobalReg]) -> [ByteOff] -> [GlobalReg]
forall a b. (a -> b) -> a -> b
$ ByteOff -> [ByteOff]
regList (DynFlags -> ByteOff
mAX_Real_Float_REG   DynFlags
dflags)
realDoubleRegs :: DynFlags -> [GlobalReg]
realDoubleRegs  dflags :: DynFlags
dflags = (ByteOff -> GlobalReg) -> [ByteOff] -> [GlobalReg]
forall a b. (a -> b) -> [a] -> [b]
map ByteOff -> GlobalReg
DoubleReg  ([ByteOff] -> [GlobalReg]) -> [ByteOff] -> [GlobalReg]
forall a b. (a -> b) -> a -> b
$ ByteOff -> [ByteOff]
regList (DynFlags -> ByteOff
mAX_Real_Double_REG  DynFlags
dflags)
realLongRegs :: DynFlags -> [GlobalReg]
realLongRegs    dflags :: DynFlags
dflags = (ByteOff -> GlobalReg) -> [ByteOff] -> [GlobalReg]
forall a b. (a -> b) -> [a] -> [b]
map ByteOff -> GlobalReg
LongReg    ([ByteOff] -> [GlobalReg]) -> [ByteOff] -> [GlobalReg]
forall a b. (a -> b) -> a -> b
$ ByteOff -> [ByteOff]
regList (DynFlags -> ByteOff
mAX_Real_Long_REG    DynFlags
dflags)

realXmmRegNos :: DynFlags -> [ByteOff]
realXmmRegNos dflags :: DynFlags
dflags
    | DynFlags -> Bool
isSse2Enabled DynFlags
dflags = ByteOff -> [ByteOff]
regList (DynFlags -> ByteOff
mAX_Real_XMM_REG     DynFlags
dflags)
    | Bool
otherwise            = []

regList :: Int -> [Int]
regList :: ByteOff -> [ByteOff]
regList n :: ByteOff
n = [1 .. ByteOff
n]

allRegs :: DynFlags -> AvailRegs
allRegs :: DynFlags -> AvailRegs
allRegs dflags :: DynFlags
dflags = (DynFlags -> [VGcPtr -> GlobalReg]
allVanillaRegs DynFlags
dflags,
                  DynFlags -> [GlobalReg]
allFloatRegs DynFlags
dflags,
                  DynFlags -> [GlobalReg]
allDoubleRegs DynFlags
dflags,
                  DynFlags -> [GlobalReg]
allLongRegs DynFlags
dflags,
                  DynFlags -> [ByteOff]
allXmmRegs DynFlags
dflags)

nodeOnly :: AvailRegs
nodeOnly :: AvailRegs
nodeOnly = ([ByteOff -> VGcPtr -> GlobalReg
VanillaReg 1], [], [], [], [])

-- This returns the set of global registers that *cover* the machine registers
-- used for argument passing. On platforms where registers can overlap---right
-- now just x86-64, where Float and Double registers overlap---passing this set
-- of registers is guaranteed to preserve the contents of all live registers. We
-- only use this functionality in hand-written C-- code in the RTS.
realArgRegsCover :: DynFlags -> [GlobalReg]
realArgRegsCover :: DynFlags -> [GlobalReg]
realArgRegsCover dflags :: DynFlags
dflags
    | DynFlags -> Bool
passFloatArgsInXmm DynFlags
dflags = ((VGcPtr -> GlobalReg) -> GlobalReg)
-> [VGcPtr -> GlobalReg] -> [GlobalReg]
forall a b. (a -> b) -> [a] -> [b]
map ((VGcPtr -> GlobalReg) -> VGcPtr -> GlobalReg
forall a b. (a -> b) -> a -> b
$VGcPtr
VGcPtr) (DynFlags -> [VGcPtr -> GlobalReg]
realVanillaRegs DynFlags
dflags) [GlobalReg] -> [GlobalReg] -> [GlobalReg]
forall a. [a] -> [a] -> [a]
++
                                  DynFlags -> [GlobalReg]
realLongRegs DynFlags
dflags [GlobalReg] -> [GlobalReg] -> [GlobalReg]
forall a. [a] -> [a] -> [a]
++
                                  (ByteOff -> GlobalReg) -> [ByteOff] -> [GlobalReg]
forall a b. (a -> b) -> [a] -> [b]
map ByteOff -> GlobalReg
XmmReg (DynFlags -> [ByteOff]
realXmmRegNos DynFlags
dflags)
    | Bool
otherwise                 = ((VGcPtr -> GlobalReg) -> GlobalReg)
-> [VGcPtr -> GlobalReg] -> [GlobalReg]
forall a b. (a -> b) -> [a] -> [b]
map ((VGcPtr -> GlobalReg) -> VGcPtr -> GlobalReg
forall a b. (a -> b) -> a -> b
$VGcPtr
VGcPtr) (DynFlags -> [VGcPtr -> GlobalReg]
realVanillaRegs DynFlags
dflags) [GlobalReg] -> [GlobalReg] -> [GlobalReg]
forall a. [a] -> [a] -> [a]
++
                                  DynFlags -> [GlobalReg]
realFloatRegs DynFlags
dflags [GlobalReg] -> [GlobalReg] -> [GlobalReg]
forall a. [a] -> [a] -> [a]
++
                                  DynFlags -> [GlobalReg]
realDoubleRegs DynFlags
dflags [GlobalReg] -> [GlobalReg] -> [GlobalReg]
forall a. [a] -> [a] -> [a]
++
                                  DynFlags -> [GlobalReg]
realLongRegs DynFlags
dflags [GlobalReg] -> [GlobalReg] -> [GlobalReg]
forall a. [a] -> [a] -> [a]
++
                                  (ByteOff -> GlobalReg) -> [ByteOff] -> [GlobalReg]
forall a b. (a -> b) -> [a] -> [b]
map ByteOff -> GlobalReg
XmmReg (DynFlags -> [ByteOff]
realXmmRegNos DynFlags
dflags)