    -----------------------------------------------------------------------------
    --
    -- Code generation for coverage
    --
    -- (c) Galois Connections, Inc. 2006
    --
    -----------------------------------------------------------------------------

    module GHC.StgToCmm.Hpc ( initHpc, mkTickBox ) where

    import GHC.Prelude
    import GHC.Platform

    import GHC.Driver.Session

    import GHC.StgToCmm.Monad
    import GHC.StgToCmm.Utils

    import GHC.Cmm.Graph
    import GHC.Cmm.Expr
    import GHC.Cmm.CLabel
    import GHC.Cmm.Utils

    import GHC.Unit.Module
    import GHC.Types.HpcInfo

    import Control.Monad

    mkTickBox :: Platform -> Module -> Int -> CmmAGraph
    mkTickBox :: Platform -> Module -> Int -> CmmAGraph
    mkTickBox Platform
    platform Module
    mod Int
    n
      = CmmExpr -> CmmExpr -> CmmAGraph
    mkStore CmmExpr
    tick_box (MachOp -> [CmmExpr] -> CmmExpr
    CmmMachOp (Width -> MachOp
    MO_Add Width
    W64)
                                    [ CmmExpr -> CmmType -> AlignmentSpec -> CmmExpr
    CmmLoad CmmExpr
    tick_box CmmType
    b64 AlignmentSpec
    NaturallyAligned
                                    , CmmLit -> CmmExpr
    CmmLit (Integer -> Width -> CmmLit
    CmmInt Integer
    1 Width
    W64)
                                    ])
      where
        tick_box :: CmmExpr
    tick_box = Platform -> Width -> CmmExpr -> Int -> CmmExpr
    cmmIndex Platform
    platform Width
    W64
                            (CmmLit -> CmmExpr
    CmmLit forall a b. (a -> b) -> a -> b
    $ CLabel -> CmmLit
    CmmLabel forall a b. (a -> b) -> a -> b
    $ Module -> CLabel
    mkHpcTicksLabel forall a b. (a -> b) -> a -> b
    $ Module
    mod)
                            Int
    n

    -- | Emit top-level tables for HPC and return code to initialise
    initHpc :: Module -> HpcInfo -> FCode ()
    initHpc :: Module -> HpcInfo -> FCode ()
    initHpc Module
    _ (NoHpcInfo {})
      = forall (m :: * -> *) a. Monad m => a -> m a
    return ()
    initHpc Module
    this_mod (HpcInfo Int
    tickCount Int
    _hashNo)
      = do DynFlags
    dflags <- forall (m :: * -> *). HasDynFlags m => m DynFlags
    getDynFlags
           forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    when (GeneralFlag -> DynFlags -> Bool
    gopt GeneralFlag
    Opt_Hpc DynFlags
    dflags) forall a b. (a -> b) -> a -> b
    $
               CLabel -> [CmmLit] -> FCode ()
    emitDataLits (Module -> CLabel
    mkHpcTicksLabel Module
    this_mod)
                            [ (Integer -> Width -> CmmLit
    CmmInt Integer
    0 Width
    W64)
                            | Int
    _ <- forall a. Int -> [a] -> [a]
    take Int
    tickCount [Int
    0 :: Int ..]
                            ]