{-# 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 :: Int -> Flag
toEnum = Int -> Flag
Flag
fromEnum :: Flag -> Int
fromEnum (Flag Int
x) = Int
x
instance Show Flag where
show :: Flag -> String
show (Flag Int
x) =
case Int
x of
Int
0 -> String
"seq-sharing"
Int
1 -> String
"acc-sharing"
Int
2 -> String
"exp-sharing"
Int
3 -> String
"fusion"
Int
4 -> String
"simplify"
Int
5 -> String
"inplace"
Int
6 -> String
"fast-math"
Int
7 -> String
"fast-permute-const"
Int
8 -> String
"flush_cache"
Int
9 -> String
"force-recomp"
Int
10 -> String
"debug"
Int
11 -> String
"verbose"
Int
12 -> String
"dump-phases"
Int
13 -> String
"dump-sharing"
Int
14 -> String
"dump-fusion"
Int
15 -> String
"dump-simpl_stats"
Int
16 -> String
"dump-simpl_iterations"
Int
17 -> String
"dump-vectorisation"
Int
18 -> String
"dump-dot"
Int
19 -> String
"dump-simpl_dot"
Int
20 -> String
"dump-gc"
Int
21 -> String
"dump-gc_stats"
Int
22 -> String
"dump-cc"
Int
23 -> String
"dump-ld"
Int
24 -> String
"dump-asm"
Int
25 -> String
"dump-exec"
Int
26 -> String
"dump-sched"
Int
_ -> Int -> String
forall a. Show a => a -> String
show Int
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 :: Flag -> m () -> m ()
when Flag
_ m ()
_ = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
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 :: Flag -> m () -> m ()
unless Flag
_ m ()
_ = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#endif
setValue :: Value -> Word32 -> IO ()
setValue :: Value -> Word32 -> IO ()
setValue (Value Ptr Word32
f) Word32
v = Ptr Word32 -> Word32 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr Word32
f Word32
v
getValue :: Value -> IO Word32
getValue :: Value -> IO Word32
getValue (Value Ptr Word32
f) = Ptr Word32 -> IO Word32
forall a. Storable a => Ptr a -> IO a
peek Ptr Word32
f
getFlag :: Flag -> IO Bool
getFlag :: Flag -> IO Bool
getFlag (Flag Int
i) = do
Word32
flags <- Ptr Word32 -> IO Word32
forall a. Storable a => Ptr a -> IO a
peek Ptr Word32
__cmd_line_flags
Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> IO Bool) -> Bool -> IO Bool
forall a b. (a -> b) -> a -> b
$! Word32 -> Int -> Bool
forall a. Bits a => a -> Int -> Bool
testBit Word32
flags Int
i
setFlag :: Flag -> IO ()
setFlag :: Flag -> IO ()
setFlag (Flag Int
i) = do
Word32
flags <- Ptr Word32 -> IO Word32
forall a. Storable a => Ptr a -> IO a
peek Ptr Word32
__cmd_line_flags
Ptr Word32 -> Word32 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr Word32
__cmd_line_flags (Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
setBit Word32
flags Int
i)
clearFlag :: Flag -> IO ()
clearFlag :: Flag -> IO ()
clearFlag (Flag Int
i) = do
Word32
flags <- Ptr Word32 -> IO Word32
forall a. Storable a => Ptr a -> IO a
peek Ptr Word32
__cmd_line_flags
Ptr Word32 -> Word32 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr Word32
__cmd_line_flags (Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
clearBit Word32
flags Int
i)
setFlags :: [Flag] -> IO ()
setFlags :: [Flag] -> IO ()
setFlags = (Flag -> IO ()) -> [Flag] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Flag -> IO ()
setFlag
clearFlags :: [Flag] -> IO ()
clearFlags :: [Flag] -> IO ()
clearFlags = (Flag -> IO ()) -> [Flag] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Flag -> IO ()
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
seq_sharing = Int -> Flag
Flag Int
0
acc_sharing :: Flag
acc_sharing = Int -> Flag
Flag Int
1
exp_sharing :: Flag
exp_sharing = Int -> Flag
Flag Int
2
array_fusion :: Flag
array_fusion = Int -> Flag
Flag Int
3
simplify :: Flag
simplify = Int -> Flag
Flag Int
4
inplace :: Flag
inplace = Int -> Flag
Flag Int
5
fast_math :: Flag
fast_math = Int -> Flag
Flag Int
6
fast_permute_const :: Flag
fast_permute_const = Int -> Flag
Flag Int
7
flush_cache :: Flag
flush_cache = Int -> Flag
Flag Int
8
force_recomp :: Flag
force_recomp = Int -> Flag
Flag Int
9
debug :: Flag
debug = Int -> Flag
Flag Int
10
verbose :: Flag
verbose = Int -> Flag
Flag Int
11
dump_phases :: Flag
dump_phases = Int -> Flag
Flag Int
12
dump_sharing :: Flag
dump_sharing = Int -> Flag
Flag Int
13
dump_fusion :: Flag
dump_fusion = Int -> Flag
Flag Int
14
dump_simpl_stats :: Flag
dump_simpl_stats = Int -> Flag
Flag Int
15
dump_simpl_iterations :: Flag
dump_simpl_iterations = Int -> Flag
Flag Int
16
dump_vectorisation :: Flag
dump_vectorisation = Int -> Flag
Flag Int
17
dump_dot :: Flag
dump_dot = Int -> Flag
Flag Int
18
dump_simpl_dot :: Flag
dump_simpl_dot = Int -> Flag
Flag Int
19
dump_gc :: Flag
dump_gc = Int -> Flag
Flag Int
20
dump_gc_stats :: Flag
dump_gc_stats = Int -> Flag
Flag Int
21
dump_cc :: Flag
dump_cc = Int -> Flag
Flag Int
22
dump_ld :: Flag
dump_ld = Int -> Flag
Flag Int
23
dump_asm :: Flag
dump_asm = Int -> Flag
Flag Int
24
dump_exec :: Flag
dump_exec = Int -> Flag
Flag Int
25
dump_sched :: Flag
dump_sched = Int -> Flag
Flag Int
26
runQ $ do
addForeignFilePath LangC "cbits/flags.c"
return []