{-# LANGUAGE CPP #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-top-binds #-}
{-# OPTIONS_GHC -fobject-code #-}
module Data.Array.Accelerate.Debug.Flags (
Value,
unfolding_use_threshold,
max_simplifier_iterations,
getValue,
setValue,
Flag(..),
seq_sharing, acc_sharing, exp_sharing, array_fusion, simplify, inplace, flush_cache, force_recomp,
fast_math, fast_permute_const, debug, verbose, dump_phases, dump_sharing, dump_fusion,
dump_simpl_stats, dump_simpl_iterations, dump_vectorisation, dump_dot,
dump_simpl_dot, dump_gc, dump_gc_stats, dump_cc, dump_ld, dump_asm, dump_exec,
dump_sched,
getFlag,
setFlag, setFlags,
clearFlag, clearFlags,
when,
unless,
__cmd_line_flags,
) where
import Control.Monad.IO.Class ( MonadIO, liftIO )
import Data.Bits
import Data.Int
import Data.Word
import Foreign.Ptr
import Foreign.Storable
import Language.Haskell.TH.Syntax
import System.Directory
import System.FilePath
import qualified Control.Monad as M
newtype Flag = Flag Int
newtype Value = Value (Ptr Word32)
instance Enum Flag where
toEnum = Flag
fromEnum (Flag x) = x
instance Show Flag where
show (Flag x) =
case x of
0 -> "seq-sharing"
1 -> "acc-sharing"
2 -> "exp-sharing"
3 -> "fusion"
4 -> "simplify"
5 -> "inplace"
6 -> "fast-math"
7 -> "fast-permute-const"
8 -> "flush_cache"
9 -> "force-recomp"
10 -> "debug"
11 -> "verbose"
12 -> "dump-phases"
13 -> "dump-sharing"
14 -> "dump-fusion"
15 -> "dump-simpl_stats"
16 -> "dump-simpl_iterations"
17 -> "dump-vectorisation"
18 -> "dump-dot"
19 -> "dump-simpl_dot"
20 -> "dump-gc"
21 -> "dump-gc_stats"
22 -> "dump-cc"
23 -> "dump-ld"
24 -> "dump-asm"
25 -> "dump-exec"
26 -> "dump-sched"
_ -> show x
{-# INLINEABLE when #-}
when :: MonadIO m => Flag -> m () -> m ()
#if ACCELERATE_DEBUG
when f action = do
yes <- liftIO $ getFlag f
M.when yes action
#else
when _ _ = return ()
#endif
{-# INLINEABLE unless #-}
unless :: MonadIO m => Flag -> m () -> m ()
#ifdef ACCELERATE_DEBUG
unless f action = do
yes <- liftIO $ getFlag f
M.unless yes action
#else
unless _ _ = return ()
#endif
setValue :: Value -> Word32 -> IO ()
setValue (Value f) v = poke f v
getValue :: Value -> IO Word32
getValue (Value f) = peek f
getFlag :: Flag -> IO Bool
getFlag (Flag i) = do
flags <- peek __cmd_line_flags
return $! testBit flags i
setFlag :: Flag -> IO ()
setFlag (Flag i) = do
flags <- peek __cmd_line_flags
poke __cmd_line_flags (setBit flags i)
clearFlag :: Flag -> IO ()
clearFlag (Flag i) = do
flags <- peek __cmd_line_flags
poke __cmd_line_flags (clearBit flags i)
setFlags :: [Flag] -> IO ()
setFlags = mapM_ setFlag
clearFlags :: [Flag] -> IO ()
clearFlags = mapM_ clearFlag
foreign import ccall "&__cmd_line_flags" __cmd_line_flags :: Ptr Word32
foreign import ccall "&__unfolding_use_threshold" unfolding_use_threshold :: Value
foreign import ccall "&__max_simplifier_iterations" max_simplifier_iterations :: Value
seq_sharing = Flag 0
acc_sharing = Flag 1
exp_sharing = Flag 2
array_fusion = Flag 3
simplify = Flag 4
inplace = Flag 5
fast_math = Flag 6
fast_permute_const = Flag 7
flush_cache = Flag 8
force_recomp = Flag 9
debug = Flag 10
verbose = Flag 11
dump_phases = Flag 12
dump_sharing = Flag 13
dump_fusion = Flag 14
dump_simpl_stats = Flag 15
dump_simpl_iterations = Flag 16
dump_vectorisation = Flag 17
dump_dot = Flag 18
dump_simpl_dot = Flag 19
dump_gc = Flag 20
dump_gc_stats = Flag 21
dump_cc = Flag 22
dump_ld = Flag 23
dump_asm = Flag 24
dump_exec = Flag 25
dump_sched = Flag 26
runQ $ do
addForeignFilePath LangC "cbits/flags.c"
return []