module GHC.CmmToAsm.Reg.Linear.StackMap (
StackSlot,
StackMap(..),
emptyStackMap,
getStackSlotFor,
getStackUse
)
where
import GHC.Prelude
import GHC.Types.Unique.FM
import GHC.Types.Unique
import GHC.CmmToAsm.Format
type StackSlot = Int
data StackMap
= StackMap
{
StackMap -> Int
stackMapNextFreeSlot :: !Int
, StackMap -> UniqFM Unique (Int, Int)
stackMapAssignment :: UniqFM Unique (StackSlot, Int) }
emptyStackMap :: StackMap
emptyStackMap :: StackMap
emptyStackMap = Int -> UniqFM Unique (Int, Int) -> StackMap
StackMap Int
0 UniqFM Unique (Int, Int)
forall {k} (key :: k) elt. UniqFM key elt
emptyUFM
getStackSlotFor :: StackMap -> Format -> Unique -> (StackMap, Int)
getStackSlotFor :: StackMap -> Format -> Unique -> (StackMap, Int)
getStackSlotFor fs :: StackMap
fs@(StackMap Int
freeSlot UniqFM Unique (Int, Int)
reserved) Format
fmt Unique
regUnique
| Just (Int
slot, Int
nbSlots) <- UniqFM Unique (Int, Int) -> Unique -> Maybe (Int, Int)
forall key elt. Uniquable key => UniqFM key elt -> key -> Maybe elt
lookupUFM UniqFM Unique (Int, Int)
reserved Unique
regUnique
, Int
nbNeededSlots Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
nbSlots
= (StackMap
fs, Int
slot)
| Bool
otherwise
= (Int -> UniqFM Unique (Int, Int) -> StackMap
StackMap (Int
freeSlotInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
nbNeededSlots) (UniqFM Unique (Int, Int)
-> Unique -> (Int, Int) -> UniqFM Unique (Int, Int)
forall key elt.
Uniquable key =>
UniqFM key elt -> key -> elt -> UniqFM key elt
addToUFM UniqFM Unique (Int, Int)
reserved Unique
regUnique (Int
freeSlot, Int
nbNeededSlots)), Int
freeSlot)
where
!nbNeededSlots :: Int
nbNeededSlots = (Format -> Int
formatInBytes Format
fmt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
7) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
8
getStackUse :: StackMap -> Int
getStackUse :: StackMap -> Int
getStackUse (StackMap Int
freeSlot UniqFM Unique (Int, Int)
_) = Int
freeSlot