module GHC.CmmToAsm.Utils
( topInfoTable
, entryBlocks
)
where
import GHC.Prelude
import GHC.Cmm.BlockId
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
_ [GlobalRegUse]
_ (ListGraph (GenBasicBlock b
b:[GenBasicBlock b]
_)))
= Label -> LabelMap i -> Maybe i
forall a. Label -> LabelMap a -> Maybe a
mapLookup (GenBasicBlock b -> Label
forall i. GenBasicBlock i -> Label
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) -> [Label]
entryBlocks (CmmProc LabelMap i
info CLabel
_ [GlobalRegUse]
_ (ListGraph [GenBasicBlock b]
code)) = [Label]
entries
where
infos :: [Label]
infos = LabelMap i -> [Label]
forall a. LabelMap a -> [Label]
mapKeys LabelMap i
info
entries :: [Label]
entries = case [GenBasicBlock b]
code of
[] -> [Label]
infos
BasicBlock Label
entry [b]
_ : [GenBasicBlock b]
_
| Label
entry Label -> [Label] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Label]
infos -> [Label]
infos
| Bool
otherwise -> Label
entry Label -> [Label] -> [Label]
forall a. a -> [a] -> [a]
: [Label]
infos
entryBlocks GenCmmDecl a (LabelMap i) (ListGraph b)
_ = []