-- | Cmm compilation configuration

{-# LANGUAGE DerivingStrategies         #-}

module GHC.Cmm.Config
  ( CmmConfig(..)
  , cmmPlatform
  ) where

import GHC.Prelude

import GHC.Platform
import GHC.Platform.Profile


data CmmConfig = CmmConfig
  { CmmConfig -> Profile
cmmProfile             :: !Profile -- ^ Target Profile
  , CmmConfig -> Bool
cmmOptControlFlow      :: !Bool    -- ^ Optimize Cmm Control Flow or not
  , CmmConfig -> Bool
cmmDoLinting           :: !Bool    -- ^ Do Cmm Linting Optimization or not
  , CmmConfig -> Bool
cmmOptElimCommonBlks   :: !Bool    -- ^ Eliminate common blocks or not
  , CmmConfig -> Bool
cmmOptSink             :: !Bool    -- ^ Perform sink after stack layout or not
  , CmmConfig -> Bool
cmmOptThreadSanitizer  :: !Bool    -- ^ Instrument memory accesses for ThreadSanitizer
  , CmmConfig -> Bool
cmmGenStackUnwindInstr :: !Bool    -- ^ Generate stack unwinding instructions (for debugging)
  , CmmConfig -> Bool
cmmExternalDynamicRefs :: !Bool    -- ^ Generate code to link against dynamic libraries
  , CmmConfig -> Bool
cmmDoCmmSwitchPlans    :: !Bool    -- ^ Should the Cmm pass replace Stg switch statements
  , CmmConfig -> Bool
cmmSplitProcPoints     :: !Bool    -- ^ Should Cmm split proc points or not
  , CmmConfig -> Bool
cmmAllowMul2           :: !Bool    -- ^ Does this platform support mul2
  , CmmConfig -> Bool
cmmOptConstDivision    :: !Bool    -- ^ Should we optimize constant divisors
  }

-- | retrieve the target Cmm platform
cmmPlatform :: CmmConfig -> Platform
cmmPlatform :: CmmConfig -> Platform
cmmPlatform = Profile -> Platform
profilePlatform (Profile -> Platform)
-> (CmmConfig -> Profile) -> CmmConfig -> Platform
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CmmConfig -> Profile
cmmProfile