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 (CmmProc infos _ _ (ListGraph (b:_)))
= mapLookup (blockId b) infos
topInfoTable _
= Nothing
entryBlocks :: GenCmmDecl a (LabelMap i) (ListGraph b) -> [BlockId]
entryBlocks (CmmProc info _ _ (ListGraph code)) = entries
where
infos = mapKeys info
entries = case code of
[] -> infos
BasicBlock entry _ : _
| entry `elem` infos -> infos
| otherwise -> entry : infos
entryBlocks _ = []