{-# LANGUAGE CPP #-}
{-# OPTIONS_HADDOCK hide #-}
module Data.Array.Accelerate.Trafo (
convertAcc, convertAccWith,
Afunction, ArraysFunctionR,
convertAfun, convertAfunWith,
Function, EltFunctionR,
convertExp, convertFun,
) where
import Data.Array.Accelerate.Sugar.Array ( ArraysR )
import Data.Array.Accelerate.Sugar.Elt ( EltR )
import Data.Array.Accelerate.Smart
import Data.Array.Accelerate.Trafo.Config
import Data.Array.Accelerate.Trafo.Delayed
import Data.Array.Accelerate.Trafo.Sharing ( Afunction, ArraysFunctionR, Function, EltFunctionR )
import qualified Data.Array.Accelerate.AST as AST
import qualified Data.Array.Accelerate.Trafo.Fusion as Fusion
import qualified Data.Array.Accelerate.Trafo.LetSplit as LetSplit
import qualified Data.Array.Accelerate.Trafo.Simplify as Rewrite
import qualified Data.Array.Accelerate.Trafo.Sharing as Sharing
import Control.DeepSeq
#ifdef ACCELERATE_DEBUG
import Text.Printf
import System.IO.Unsafe
import Data.Array.Accelerate.Debug.Flags hiding ( when )
import Data.Array.Accelerate.Debug.Timed
#endif
convertAcc :: Acc arrs -> DelayedAcc (ArraysR arrs)
convertAcc = convertAccWith defaultOptions
convertAccWith :: Config -> Acc arrs -> DelayedAcc (ArraysR arrs)
convertAccWith config
= phase "array-fusion" (Fusion.convertAccWith config)
. phase "array-split-lets" LetSplit.convertAcc
. phase "sharing-recovery" (Sharing.convertAccWith config)
convertAfun :: Afunction f => f -> DelayedAfun (ArraysFunctionR f)
convertAfun = convertAfunWith defaultOptions
convertAfunWith :: Afunction f => Config -> f -> DelayedAfun (ArraysFunctionR f)
convertAfunWith config
= phase "array-fusion" (Fusion.convertAfunWith config)
. phase "array-split-lets" LetSplit.convertAfun
. phase "sharing-recovery" (Sharing.convertAfunWith config)
convertExp :: Exp e -> AST.Exp () (EltR e)
convertExp
= phase "exp-simplify" Rewrite.simplifyExp
. phase "sharing-recovery" Sharing.convertExp
convertFun :: Function f => f -> AST.Fun () (EltFunctionR f)
convertFun
= phase "exp-simplify" Rewrite.simplifyFun
. phase "sharing-recovery" Sharing.convertFun
phase :: NFData b => String -> (a -> b) -> a -> b
#ifdef ACCELERATE_DEBUG
phase n f x = unsafePerformIO $ do
enabled <- getFlag dump_phases
if enabled
then timed dump_phases (\wall cpu -> printf "phase %s: %s" n (elapsed wall cpu)) (return $!! f x)
else return (f x)
#else
phase _ f = f
#endif