7 #include "HsVersions.h"
14 import StaticFlags (opt_Unregisterised)
17 -- Calculate the 'GlobalReg' or stack locations for function call
18 -- parameters as used by the Cmm calling convention.
21 = RegisterParam GlobalReg
24 type ArgumentFormat a = [(a, ParamLocation)]
26 assignArguments :: (a -> MachRep) -> [a] -> ArgumentFormat a
27 assignArguments f reps = assignArguments' reps 0 availRegs
29 assignArguments' [] offset availRegs = []
30 assignArguments' (r:rs) offset availRegs =
31 (r,assignment):assignArguments' rs new_offset remaining
33 (assignment, new_offset, remaining) =
34 assign_reg (f r) offset availRegs
36 argumentsSize :: (a -> MachRep) -> [a] -> WordOff
37 argumentsSize f reps = maximum (0 : map arg_top args)
39 args = assignArguments f reps
41 arg_top (a, StackParam offset) = -offset
42 arg_top (_, RegisterParam _) = 0
44 -----------------------------------------------------------------------------
45 -- Local information about the registers available
47 type AvailRegs = ( [GlobalReg] -- available vanilla regs.
48 , [GlobalReg] -- floats
49 , [GlobalReg] -- doubles
50 , [GlobalReg] -- longs (int64 and word64)
53 -- Vanilla registers can contain pointers, Ints, Chars.
54 -- Floats and doubles have separate register supplies.
56 -- We take these register supplies from the *real* registers, i.e. those
57 -- that are guaranteed to map to machine registers.
59 useVanillaRegs | opt_Unregisterised = 0
60 | otherwise = mAX_Real_Vanilla_REG
61 useFloatRegs | opt_Unregisterised = 0
62 | otherwise = mAX_Real_Float_REG
63 useDoubleRegs | opt_Unregisterised = 0
64 | otherwise = mAX_Real_Double_REG
65 useLongRegs | opt_Unregisterised = 0
66 | otherwise = mAX_Real_Long_REG
68 availRegs = (regList VanillaReg useVanillaRegs,
69 regList FloatReg useFloatRegs,
70 regList DoubleReg useDoubleRegs,
71 regList LongReg useLongRegs)
73 regList f max = map f [1 .. max]
75 slot_size :: LocalReg -> Int
77 ((machRepByteWidth (localRegRep reg) - 1) `div` wORD_SIZE) + 1
79 slot_size' :: MachRep -> Int
80 slot_size' reg = ((machRepByteWidth reg - 1) `div` wORD_SIZE) + 1
82 assign_reg :: MachRep -> WordOff -> AvailRegs -> (ParamLocation, WordOff, AvailRegs)
83 assign_reg I8 off (v:vs, fs, ds, ls) = (RegisterParam $ v, off, (vs, fs, ds, ls))
84 assign_reg I16 off (v:vs, fs, ds, ls) = (RegisterParam $ v, off, (vs, fs, ds, ls))
85 assign_reg I32 off (v:vs, fs, ds, ls) = (RegisterParam $ v, off, (vs, fs, ds, ls))
86 assign_reg I64 off (vs, fs, ds, l:ls) = (RegisterParam $ l, off, (vs, fs, ds, ls))
87 assign_reg I128 off _ = panic "I128 is not a supported register type"
88 assign_reg F32 off (vs, f:fs, ds, ls) = (RegisterParam $ f, off, (vs, fs, ds, ls))
89 assign_reg F64 off (vs, fs, d:ds, ls) = (RegisterParam $ d, off, (vs, fs, ds, ls))
90 assign_reg F80 off _ = panic "F80 is not a supported register type"
91 assign_reg reg off _ = (StackParam $ off - size, off - size, ([], [], [], [])) where size = slot_size' reg