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