diff options
Diffstat (limited to 'compiler/GHC/CmmToAsm/Utils.hs')
-rw-r--r-- | compiler/GHC/CmmToAsm/Utils.hs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/compiler/GHC/CmmToAsm/Utils.hs b/compiler/GHC/CmmToAsm/Utils.hs new file mode 100644 index 0000000000..648805f210 --- /dev/null +++ b/compiler/GHC/CmmToAsm/Utils.hs @@ -0,0 +1,33 @@ +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) + +-- | Returns the info table associated with the CmmDecl's entry point, +-- if any. +topInfoTable :: GenCmmDecl a (LabelMap i) (ListGraph b) -> Maybe i +topInfoTable (CmmProc infos _ _ (ListGraph (b:_))) + = mapLookup (blockId b) infos +topInfoTable _ + = Nothing + +-- | Return the list of BlockIds in a CmmDecl that are entry points +-- for this proc (i.e. they may be jumped to from outside this proc). +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 _ : _ -- first block is the entry point + | entry `elem` infos -> infos + | otherwise -> entry : infos +entryBlocks _ = [] |