    -- | LLVM config cache
    module GHC.Driver.LlvmConfigCache
      ( LlvmConfigCache
      , initLlvmConfigCache
      , readLlvmConfigCache
      )
    where

    import GHC.Prelude
    import GHC.CmmToLlvm.Config

    import System.IO.Unsafe

    -- | Cache LLVM configuration read from files in top_dir
    --
    -- See Note [LLVM configuration] in GHC.CmmToLlvm.Config
    --
    -- Currently implemented with unsafe lazy IO. But it could be implemented with
    -- an IORef as the exposed interface is in IO.
    data LlvmConfigCache = LlvmConfigCache LlvmConfig

    initLlvmConfigCache :: FilePath -> IO LlvmConfigCache
    initLlvmConfigCache :: FilePath -> IO LlvmConfigCache
    initLlvmConfigCache FilePath
    top_dir = LlvmConfigCache -> IO LlvmConfigCache
    forall a. a -> IO a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (LlvmConfigCache -> IO LlvmConfigCache)
    -> LlvmConfigCache -> IO LlvmConfigCache
    forall a b. (a -> b) -> a -> b
    $ LlvmConfig -> LlvmConfigCache
    LlvmConfigCache (IO LlvmConfig -> LlvmConfig
    forall a. IO a -> a
    unsafePerformIO (IO LlvmConfig -> LlvmConfig) -> IO LlvmConfig -> LlvmConfig
    forall a b. (a -> b) -> a -> b
    $ FilePath -> IO LlvmConfig
    initLlvmConfig FilePath
    top_dir)

    readLlvmConfigCache :: LlvmConfigCache -> IO LlvmConfig
    readLlvmConfigCache :: LlvmConfigCache -> IO LlvmConfig
    readLlvmConfigCache (LlvmConfigCache !LlvmConfig
    config) = LlvmConfig -> IO LlvmConfig
    forall a. a -> IO a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure LlvmConfig
    config