{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
module Futhark.IR.MC
( MC,
simplifyProg,
module Futhark.IR.Prop,
module Futhark.IR.Traversals,
module Futhark.IR.Pretty,
module Futhark.IR.Syntax,
module Futhark.IR.SegOp,
module Futhark.IR.SOACS.SOAC,
module Futhark.IR.MC.Op,
)
where
import Futhark.Builder
import Futhark.Construct
import Futhark.IR.MC.Op
import Futhark.IR.Pretty
import Futhark.IR.Prop
import Futhark.IR.SOACS.SOAC hiding (HistOp (..))
import qualified Futhark.IR.SOACS.Simplify as SOAC
import Futhark.IR.SegOp
import Futhark.IR.Syntax
import Futhark.IR.Traversals
import qualified Futhark.Optimise.Simplify as Simplify
import qualified Futhark.Optimise.Simplify.Engine as Engine
import Futhark.Optimise.Simplify.Rules
import Futhark.Pass
import qualified Futhark.TypeCheck as TypeCheck
data MC
instance RepTypes MC where
type Op MC = MCOp MC (SOAC MC)
instance ASTRep MC where
expTypesFromPat :: Pat MC -> m [BranchType MC]
expTypesFromPat = [ExtType] -> m [ExtType]
forall (m :: * -> *) a. Monad m => a -> m a
return ([ExtType] -> m [ExtType])
-> (PatT Type -> [ExtType]) -> PatT Type -> m [ExtType]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatT Type -> [ExtType]
forall dec. Typed dec => PatT dec -> [ExtType]
expExtTypesFromPat
instance TypeCheck.CheckableOp MC where
checkOp :: OpWithAliases (Op MC) -> TypeM MC ()
checkOp = (SOAC (Aliases MC) -> TypeM MC ())
-> MCOp (Aliases MC) (SOAC (Aliases MC)) -> TypeM MC ()
forall rep op.
Checkable rep =>
(op -> TypeM rep ()) -> MCOp (Aliases rep) op -> TypeM rep ()
typeCheckMCOp SOAC (Aliases MC) -> TypeM MC ()
forall rep. Checkable rep => SOAC (Aliases rep) -> TypeM rep ()
typeCheckSOAC
instance TypeCheck.Checkable MC
instance Buildable MC where
mkBody :: Stms MC -> Result -> Body MC
mkBody = BodyDec MC -> Stms MC -> Result -> Body MC
forall rep. BodyDec rep -> Stms rep -> Result -> BodyT rep
Body ()
mkExpPat :: [Ident] -> Exp MC -> Pat MC
mkExpPat [Ident]
idents Exp MC
_ = [Ident] -> PatT Type
basicPat [Ident]
idents
mkExpDec :: Pat MC -> Exp MC -> ExpDec MC
mkExpDec Pat MC
_ Exp MC
_ = ()
mkLetNames :: [VName] -> Exp MC -> m (Stm MC)
mkLetNames = [VName] -> Exp MC -> m (Stm MC)
forall rep (m :: * -> *).
(ExpDec rep ~ (), LetDec rep ~ Type, MonadFreshNames m,
TypedOp (Op rep), HasScope rep m) =>
[VName] -> Exp rep -> m (Stm rep)
simpleMkLetNames
instance BuilderOps MC
instance BuilderOps (Engine.Wise MC)
instance PrettyRep MC
simpleMC :: Simplify.SimpleOps MC
simpleMC :: SimpleOps MC
simpleMC = SimplifyOp MC (Op MC) -> SimpleOps MC
forall rep.
(SimplifiableRep rep, Buildable rep) =>
SimplifyOp rep (Op rep) -> SimpleOps rep
Simplify.bindableSimpleOps (SimplifyOp MC (Op MC) -> SimpleOps MC)
-> SimplifyOp MC (Op MC) -> SimpleOps MC
forall a b. (a -> b) -> a -> b
$ SimplifyOp MC (SOAC MC)
-> MCOp MC (SOAC MC)
-> SimpleM
MC (MCOp (Wise MC) (OpWithWisdom (SOAC MC)), Stms (Wise MC))
forall rep op.
(SimplifiableRep rep, BodyDec rep ~ ()) =>
SimplifyOp rep op
-> MCOp rep op
-> SimpleM rep (MCOp (Wise rep) (OpWithWisdom op), Stms (Wise rep))
simplifyMCOp SimplifyOp MC (SOAC MC)
forall rep. SimplifiableRep rep => SimplifyOp rep (SOAC rep)
SOAC.simplifySOAC
simplifyProg :: Prog MC -> PassM (Prog MC)
simplifyProg :: Prog MC -> PassM (Prog MC)
simplifyProg = SimpleOps MC
-> RuleBook (Wise MC)
-> HoistBlockers MC
-> Prog MC
-> PassM (Prog MC)
forall rep.
SimplifiableRep rep =>
SimpleOps rep
-> RuleBook (Wise rep)
-> HoistBlockers rep
-> Prog rep
-> PassM (Prog rep)
Simplify.simplifyProg SimpleOps MC
simpleMC RuleBook (Wise MC)
rules HoistBlockers MC
forall rep. HoistBlockers rep
blockers
where
blockers :: HoistBlockers rep
blockers = HoistBlockers rep
forall rep. HoistBlockers rep
Engine.noExtraHoistBlockers
rules :: RuleBook (Wise MC)
rules = RuleBook (Wise MC)
forall rep. (BuilderOps rep, Aliased rep) => RuleBook rep
standardRules RuleBook (Wise MC) -> RuleBook (Wise MC) -> RuleBook (Wise MC)
forall a. Semigroup a => a -> a -> a
<> RuleBook (Wise MC)
forall rep.
(HasSegOp rep, BuilderOps rep, Buildable rep) =>
RuleBook rep
segOpRules
instance HasSegOp MC where
type SegOpLevel MC = ()
asSegOp :: Op MC -> Maybe (SegOp (SegOpLevel MC) MC)
asSegOp = Maybe (SegOp () MC) -> MCOp MC (SOAC MC) -> Maybe (SegOp () MC)
forall a b. a -> b -> a
const Maybe (SegOp () MC)
forall a. Maybe a
Nothing
segOp :: SegOp (SegOpLevel MC) MC -> Op MC
segOp = Maybe (SegOp () MC) -> SegOp () MC -> MCOp MC (SOAC MC)
forall rep op. Maybe (SegOp () rep) -> SegOp () rep -> MCOp rep op
ParOp Maybe (SegOp () MC)
forall a. Maybe a
Nothing
instance HasSegOp (Engine.Wise MC) where
type SegOpLevel (Engine.Wise MC) = ()
asSegOp :: Op (Wise MC) -> Maybe (SegOp (SegOpLevel (Wise MC)) (Wise MC))
asSegOp = Maybe (SegOp () (Wise MC))
-> MCOp (Wise MC) (SOAC (Wise MC)) -> Maybe (SegOp () (Wise MC))
forall a b. a -> b -> a
const Maybe (SegOp () (Wise MC))
forall a. Maybe a
Nothing
segOp :: SegOp (SegOpLevel (Wise MC)) (Wise MC) -> Op (Wise MC)
segOp = Maybe (SegOp () (Wise MC))
-> SegOp () (Wise MC) -> MCOp (Wise MC) (SOAC (Wise MC))
forall rep op. Maybe (SegOp () rep) -> SegOp () rep -> MCOp rep op
ParOp Maybe (SegOp () (Wise MC))
forall a. Maybe a
Nothing