module GHC.CmmToAsm.Utils
( topInfoTable
, entryBlocks
)
where
import GHC.Prelude
import GHC.Cmm.BlockId
import GHC.Cmm.Dataflow.Collections
import GHC.Cmm.Dataflow.Label
import GHC.Cmm hiding (topInfoTable)
topInfoTable :: GenCmmDecl a (LabelMap i) (ListGraph b) -> Maybe i
topInfoTable :: forall a i b. GenCmmDecl a (LabelMap i) (ListGraph b) -> Maybe i
topInfoTable (CmmProc LabelMap i
infos CLabel
_ [GlobalReg]
_ (ListGraph (GenBasicBlock b
b:[GenBasicBlock b]
_)))
= KeyOf LabelMap -> LabelMap i -> Maybe i
forall (map :: * -> *) a.
IsMap map =>
KeyOf map -> map a -> Maybe a
mapLookup (GenBasicBlock b -> BlockId
forall i. GenBasicBlock i -> BlockId
blockId GenBasicBlock b
b) LabelMap i
infos
topInfoTable GenCmmDecl a (LabelMap i) (ListGraph b)
_
= Maybe i
forall a. Maybe a
Nothing
entryBlocks :: GenCmmDecl a (LabelMap i) (ListGraph b) -> [BlockId]
entryBlocks :: forall a i b. GenCmmDecl a (LabelMap i) (ListGraph b) -> [BlockId]
entryBlocks (CmmProc LabelMap i
info CLabel
_ [GlobalReg]
_ (ListGraph [GenBasicBlock b]
code)) = [KeyOf LabelMap]
[BlockId]
entries
where
infos :: [KeyOf LabelMap]
infos = LabelMap i -> [KeyOf LabelMap]
forall (map :: * -> *) a. IsMap map => map a -> [KeyOf map]
mapKeys LabelMap i
info
entries :: [KeyOf LabelMap]
entries = case [GenBasicBlock b]
code of
[] -> [KeyOf LabelMap]
infos
BasicBlock BlockId
entry [b]
_ : [GenBasicBlock b]
_
| BlockId
entry BlockId -> [BlockId] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [KeyOf LabelMap]
[BlockId]
infos -> [KeyOf LabelMap]
infos
| Bool
otherwise -> BlockId
entry BlockId -> [BlockId] -> [BlockId]
forall a. a -> [a] -> [a]
: [KeyOf LabelMap]
[BlockId]
infos
entryBlocks GenCmmDecl a (LabelMap i) (ListGraph b)
_ = []