module Futhark.IR.Traversals
(
Mapper (..),
identityMapper,
mapExpM,
mapExp,
Walker (..),
identityWalker,
walkExpM,
)
where
import Control.Monad
import Control.Monad.Identity
import Data.Bitraversable
import Data.Foldable (traverse_)
import Futhark.IR.Prop.Scope
import Futhark.IR.Prop.Types (mapOnType)
import Futhark.IR.Syntax
data Mapper frep trep m = Mapper
{ Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp :: SubExp -> m SubExp,
Mapper frep trep m -> Scope trep -> Body frep -> m (Body trep)
mapOnBody :: Scope trep -> Body frep -> m (Body trep),
Mapper frep trep m -> VName -> m VName
mapOnVName :: VName -> m VName,
Mapper frep trep m -> RetType frep -> m (RetType trep)
mapOnRetType :: RetType frep -> m (RetType trep),
Mapper frep trep m -> BranchType frep -> m (BranchType trep)
mapOnBranchType :: BranchType frep -> m (BranchType trep),
Mapper frep trep m -> FParam frep -> m (FParam trep)
mapOnFParam :: FParam frep -> m (FParam trep),
Mapper frep trep m -> LParam frep -> m (LParam trep)
mapOnLParam :: LParam frep -> m (LParam trep),
Mapper frep trep m -> Op frep -> m (Op trep)
mapOnOp :: Op frep -> m (Op trep)
}
identityMapper :: Monad m => Mapper rep rep m
identityMapper :: Mapper rep rep m
identityMapper =
Mapper :: forall frep trep (m :: * -> *).
(SubExp -> m SubExp)
-> (Scope trep -> Body frep -> m (Body trep))
-> (VName -> m VName)
-> (RetType frep -> m (RetType trep))
-> (BranchType frep -> m (BranchType trep))
-> (FParam frep -> m (FParam trep))
-> (LParam frep -> m (LParam trep))
-> (Op frep -> m (Op trep))
-> Mapper frep trep m
Mapper
{ mapOnSubExp :: SubExp -> m SubExp
mapOnSubExp = SubExp -> m SubExp
forall (m :: * -> *) a. Monad m => a -> m a
return,
mapOnBody :: Scope rep -> Body rep -> m (Body rep)
mapOnBody = (Body rep -> m (Body rep)) -> Scope rep -> Body rep -> m (Body rep)
forall a b. a -> b -> a
const Body rep -> m (Body rep)
forall (m :: * -> *) a. Monad m => a -> m a
return,
mapOnVName :: VName -> m VName
mapOnVName = VName -> m VName
forall (m :: * -> *) a. Monad m => a -> m a
return,
mapOnRetType :: RetType rep -> m (RetType rep)
mapOnRetType = RetType rep -> m (RetType rep)
forall (m :: * -> *) a. Monad m => a -> m a
return,
mapOnBranchType :: BranchType rep -> m (BranchType rep)
mapOnBranchType = BranchType rep -> m (BranchType rep)
forall (m :: * -> *) a. Monad m => a -> m a
return,
mapOnFParam :: FParam rep -> m (FParam rep)
mapOnFParam = FParam rep -> m (FParam rep)
forall (m :: * -> *) a. Monad m => a -> m a
return,
mapOnLParam :: LParam rep -> m (LParam rep)
mapOnLParam = LParam rep -> m (LParam rep)
forall (m :: * -> *) a. Monad m => a -> m a
return,
mapOnOp :: Op rep -> m (Op rep)
mapOnOp = Op rep -> m (Op rep)
forall (m :: * -> *) a. Monad m => a -> m a
return
}
mapExpM ::
(Applicative m, Monad m) =>
Mapper frep trep m ->
Exp frep ->
m (Exp trep)
mapExpM :: Mapper frep trep m -> Exp frep -> m (Exp trep)
mapExpM Mapper frep trep m
tv (BasicOp (SubExp SubExp
se)) =
BasicOp -> Exp trep
forall rep. BasicOp -> ExpT rep
BasicOp (BasicOp -> Exp trep) -> m BasicOp -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (SubExp -> BasicOp
SubExp (SubExp -> BasicOp) -> m SubExp -> m BasicOp
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv SubExp
se)
mapExpM Mapper frep trep m
tv (BasicOp (ArrayLit [SubExp]
els Type
rowt)) =
BasicOp -> Exp trep
forall rep. BasicOp -> ExpT rep
BasicOp
(BasicOp -> Exp trep) -> m BasicOp -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ( [SubExp] -> Type -> BasicOp
ArrayLit ([SubExp] -> Type -> BasicOp) -> m [SubExp] -> m (Type -> BasicOp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (SubExp -> m SubExp) -> [SubExp] -> m [SubExp]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv) [SubExp]
els
m (Type -> BasicOp) -> m Type -> m BasicOp
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (SubExp -> m SubExp) -> Type -> m Type
forall (m :: * -> *) u.
Monad m =>
(SubExp -> m SubExp) -> TypeBase Shape u -> m (TypeBase Shape u)
mapOnType (Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv) Type
rowt
)
mapExpM Mapper frep trep m
tv (BasicOp (BinOp BinOp
bop SubExp
x SubExp
y)) =
BasicOp -> Exp trep
forall rep. BasicOp -> ExpT rep
BasicOp (BasicOp -> Exp trep) -> m BasicOp -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (BinOp -> SubExp -> SubExp -> BasicOp
BinOp BinOp
bop (SubExp -> SubExp -> BasicOp) -> m SubExp -> m (SubExp -> BasicOp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv SubExp
x m (SubExp -> BasicOp) -> m SubExp -> m BasicOp
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv SubExp
y)
mapExpM Mapper frep trep m
tv (BasicOp (CmpOp CmpOp
op SubExp
x SubExp
y)) =
BasicOp -> Exp trep
forall rep. BasicOp -> ExpT rep
BasicOp (BasicOp -> Exp trep) -> m BasicOp -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (CmpOp -> SubExp -> SubExp -> BasicOp
CmpOp CmpOp
op (SubExp -> SubExp -> BasicOp) -> m SubExp -> m (SubExp -> BasicOp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv SubExp
x m (SubExp -> BasicOp) -> m SubExp -> m BasicOp
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv SubExp
y)
mapExpM Mapper frep trep m
tv (BasicOp (ConvOp ConvOp
conv SubExp
x)) =
BasicOp -> Exp trep
forall rep. BasicOp -> ExpT rep
BasicOp (BasicOp -> Exp trep) -> m BasicOp -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ConvOp -> SubExp -> BasicOp
ConvOp ConvOp
conv (SubExp -> BasicOp) -> m SubExp -> m BasicOp
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv SubExp
x)
mapExpM Mapper frep trep m
tv (BasicOp (UnOp UnOp
op SubExp
x)) =
BasicOp -> Exp trep
forall rep. BasicOp -> ExpT rep
BasicOp (BasicOp -> Exp trep) -> m BasicOp -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (UnOp -> SubExp -> BasicOp
UnOp UnOp
op (SubExp -> BasicOp) -> m SubExp -> m BasicOp
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv SubExp
x)
mapExpM Mapper frep trep m
tv (If SubExp
c BodyT frep
texp BodyT frep
fexp (IfDec [BranchType frep]
ts IfSort
s)) =
SubExp
-> BodyT trep -> BodyT trep -> IfDec (BranchType trep) -> Exp trep
forall rep.
SubExp
-> BodyT rep -> BodyT rep -> IfDec (BranchType rep) -> ExpT rep
If (SubExp
-> BodyT trep -> BodyT trep -> IfDec (BranchType trep) -> Exp trep)
-> m SubExp
-> m (BodyT trep
-> BodyT trep -> IfDec (BranchType trep) -> Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv SubExp
c m (BodyT trep -> BodyT trep -> IfDec (BranchType trep) -> Exp trep)
-> m (BodyT trep)
-> m (BodyT trep -> IfDec (BranchType trep) -> Exp trep)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mapper frep trep m -> Scope trep -> BodyT frep -> m (BodyT trep)
forall frep trep (m :: * -> *).
Mapper frep trep m -> Scope trep -> Body frep -> m (Body trep)
mapOnBody Mapper frep trep m
tv Scope trep
forall a. Monoid a => a
mempty BodyT frep
texp m (BodyT trep -> IfDec (BranchType trep) -> Exp trep)
-> m (BodyT trep) -> m (IfDec (BranchType trep) -> Exp trep)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mapper frep trep m -> Scope trep -> BodyT frep -> m (BodyT trep)
forall frep trep (m :: * -> *).
Mapper frep trep m -> Scope trep -> Body frep -> m (Body trep)
mapOnBody Mapper frep trep m
tv Scope trep
forall a. Monoid a => a
mempty BodyT frep
fexp
m (IfDec (BranchType trep) -> Exp trep)
-> m (IfDec (BranchType trep)) -> m (Exp trep)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ([BranchType trep] -> IfSort -> IfDec (BranchType trep)
forall rt. [rt] -> IfSort -> IfDec rt
IfDec ([BranchType trep] -> IfSort -> IfDec (BranchType trep))
-> m [BranchType trep] -> m (IfSort -> IfDec (BranchType trep))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (BranchType frep -> m (BranchType trep))
-> [BranchType frep] -> m [BranchType trep]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Mapper frep trep m -> BranchType frep -> m (BranchType trep)
forall frep trep (m :: * -> *).
Mapper frep trep m -> BranchType frep -> m (BranchType trep)
mapOnBranchType Mapper frep trep m
tv) [BranchType frep]
ts m (IfSort -> IfDec (BranchType trep))
-> m IfSort -> m (IfDec (BranchType trep))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IfSort -> m IfSort
forall (f :: * -> *) a. Applicative f => a -> f a
pure IfSort
s)
mapExpM Mapper frep trep m
tv (Apply Name
fname [(SubExp, Diet)]
args [RetType frep]
ret (Safety, SrcLoc, [SrcLoc])
loc) = do
[(SubExp, Diet)]
args' <- [(SubExp, Diet)]
-> ((SubExp, Diet) -> m (SubExp, Diet)) -> m [(SubExp, Diet)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [(SubExp, Diet)]
args (((SubExp, Diet) -> m (SubExp, Diet)) -> m [(SubExp, Diet)])
-> ((SubExp, Diet) -> m (SubExp, Diet)) -> m [(SubExp, Diet)]
forall a b. (a -> b) -> a -> b
$ \(SubExp
arg, Diet
d) ->
(,) (SubExp -> Diet -> (SubExp, Diet))
-> m SubExp -> m (Diet -> (SubExp, Diet))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv SubExp
arg m (Diet -> (SubExp, Diet)) -> m Diet -> m (SubExp, Diet)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Diet -> m Diet
forall (f :: * -> *) a. Applicative f => a -> f a
pure Diet
d
Name
-> [(SubExp, Diet)]
-> [RetType trep]
-> (Safety, SrcLoc, [SrcLoc])
-> Exp trep
forall rep.
Name
-> [(SubExp, Diet)]
-> [RetType rep]
-> (Safety, SrcLoc, [SrcLoc])
-> ExpT rep
Apply Name
fname [(SubExp, Diet)]
args' ([RetType trep] -> (Safety, SrcLoc, [SrcLoc]) -> Exp trep)
-> m [RetType trep] -> m ((Safety, SrcLoc, [SrcLoc]) -> Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (RetType frep -> m (RetType trep))
-> [RetType frep] -> m [RetType trep]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Mapper frep trep m -> RetType frep -> m (RetType trep)
forall frep trep (m :: * -> *).
Mapper frep trep m -> RetType frep -> m (RetType trep)
mapOnRetType Mapper frep trep m
tv) [RetType frep]
ret m ((Safety, SrcLoc, [SrcLoc]) -> Exp trep)
-> m (Safety, SrcLoc, [SrcLoc]) -> m (Exp trep)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Safety, SrcLoc, [SrcLoc]) -> m (Safety, SrcLoc, [SrcLoc])
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Safety, SrcLoc, [SrcLoc])
loc
mapExpM Mapper frep trep m
tv (BasicOp (Index VName
arr Slice SubExp
slice)) =
BasicOp -> Exp trep
forall rep. BasicOp -> ExpT rep
BasicOp
(BasicOp -> Exp trep) -> m BasicOp -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ( VName -> Slice SubExp -> BasicOp
Index (VName -> Slice SubExp -> BasicOp)
-> m VName -> m (Slice SubExp -> BasicOp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> VName -> m VName
forall frep trep (m :: * -> *).
Mapper frep trep m -> VName -> m VName
mapOnVName Mapper frep trep m
tv VName
arr
m (Slice SubExp -> BasicOp) -> m (Slice SubExp) -> m BasicOp
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (SubExp -> m SubExp) -> Slice SubExp -> m (Slice SubExp)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv) Slice SubExp
slice
)
mapExpM Mapper frep trep m
tv (BasicOp (Update Safety
safety VName
arr Slice SubExp
slice SubExp
se)) =
BasicOp -> Exp trep
forall rep. BasicOp -> ExpT rep
BasicOp
(BasicOp -> Exp trep) -> m BasicOp -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ( Safety -> VName -> Slice SubExp -> SubExp -> BasicOp
Update Safety
safety (VName -> Slice SubExp -> SubExp -> BasicOp)
-> m VName -> m (Slice SubExp -> SubExp -> BasicOp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> VName -> m VName
forall frep trep (m :: * -> *).
Mapper frep trep m -> VName -> m VName
mapOnVName Mapper frep trep m
tv VName
arr
m (Slice SubExp -> SubExp -> BasicOp)
-> m (Slice SubExp) -> m (SubExp -> BasicOp)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (SubExp -> m SubExp) -> Slice SubExp -> m (Slice SubExp)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv) Slice SubExp
slice
m (SubExp -> BasicOp) -> m SubExp -> m BasicOp
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv SubExp
se
)
mapExpM Mapper frep trep m
tv (BasicOp (FlatIndex VName
arr FlatSlice SubExp
slice)) =
BasicOp -> Exp trep
forall rep. BasicOp -> ExpT rep
BasicOp
(BasicOp -> Exp trep) -> m BasicOp -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ( VName -> FlatSlice SubExp -> BasicOp
FlatIndex (VName -> FlatSlice SubExp -> BasicOp)
-> m VName -> m (FlatSlice SubExp -> BasicOp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> VName -> m VName
forall frep trep (m :: * -> *).
Mapper frep trep m -> VName -> m VName
mapOnVName Mapper frep trep m
tv VName
arr
m (FlatSlice SubExp -> BasicOp)
-> m (FlatSlice SubExp) -> m BasicOp
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (SubExp -> m SubExp) -> FlatSlice SubExp -> m (FlatSlice SubExp)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv) FlatSlice SubExp
slice
)
mapExpM Mapper frep trep m
tv (BasicOp (FlatUpdate VName
arr FlatSlice SubExp
slice VName
se)) =
BasicOp -> Exp trep
forall rep. BasicOp -> ExpT rep
BasicOp
(BasicOp -> Exp trep) -> m BasicOp -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ( VName -> FlatSlice SubExp -> VName -> BasicOp
FlatUpdate (VName -> FlatSlice SubExp -> VName -> BasicOp)
-> m VName -> m (FlatSlice SubExp -> VName -> BasicOp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> VName -> m VName
forall frep trep (m :: * -> *).
Mapper frep trep m -> VName -> m VName
mapOnVName Mapper frep trep m
tv VName
arr
m (FlatSlice SubExp -> VName -> BasicOp)
-> m (FlatSlice SubExp) -> m (VName -> BasicOp)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (SubExp -> m SubExp) -> FlatSlice SubExp -> m (FlatSlice SubExp)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv) FlatSlice SubExp
slice
m (VName -> BasicOp) -> m VName -> m BasicOp
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mapper frep trep m -> VName -> m VName
forall frep trep (m :: * -> *).
Mapper frep trep m -> VName -> m VName
mapOnVName Mapper frep trep m
tv VName
se
)
mapExpM Mapper frep trep m
tv (BasicOp (Iota SubExp
n SubExp
x SubExp
s IntType
et)) =
BasicOp -> Exp trep
forall rep. BasicOp -> ExpT rep
BasicOp (BasicOp -> Exp trep) -> m BasicOp -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (SubExp -> SubExp -> SubExp -> IntType -> BasicOp
Iota (SubExp -> SubExp -> SubExp -> IntType -> BasicOp)
-> m SubExp -> m (SubExp -> SubExp -> IntType -> BasicOp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv SubExp
n m (SubExp -> SubExp -> IntType -> BasicOp)
-> m SubExp -> m (SubExp -> IntType -> BasicOp)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv SubExp
x m (SubExp -> IntType -> BasicOp)
-> m SubExp -> m (IntType -> BasicOp)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv SubExp
s m (IntType -> BasicOp) -> m IntType -> m BasicOp
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IntType -> m IntType
forall (f :: * -> *) a. Applicative f => a -> f a
pure IntType
et)
mapExpM Mapper frep trep m
tv (BasicOp (Replicate Shape
shape SubExp
vexp)) =
BasicOp -> Exp trep
forall rep. BasicOp -> ExpT rep
BasicOp (BasicOp -> Exp trep) -> m BasicOp -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Shape -> SubExp -> BasicOp
Replicate (Shape -> SubExp -> BasicOp) -> m Shape -> m (SubExp -> BasicOp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> Shape -> m Shape
forall (m :: * -> *) frep trep.
Monad m =>
Mapper frep trep m -> Shape -> m Shape
mapOnShape Mapper frep trep m
tv Shape
shape m (SubExp -> BasicOp) -> m SubExp -> m BasicOp
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv SubExp
vexp)
mapExpM Mapper frep trep m
tv (BasicOp (Scratch PrimType
t [SubExp]
shape)) =
BasicOp -> Exp trep
forall rep. BasicOp -> ExpT rep
BasicOp (BasicOp -> Exp trep) -> m BasicOp -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (PrimType -> [SubExp] -> BasicOp
Scratch PrimType
t ([SubExp] -> BasicOp) -> m [SubExp] -> m BasicOp
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (SubExp -> m SubExp) -> [SubExp] -> m [SubExp]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv) [SubExp]
shape)
mapExpM Mapper frep trep m
tv (BasicOp (Reshape ShapeChange SubExp
shape VName
arrexp)) =
BasicOp -> Exp trep
forall rep. BasicOp -> ExpT rep
BasicOp
(BasicOp -> Exp trep) -> m BasicOp -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ( ShapeChange SubExp -> VName -> BasicOp
Reshape
(ShapeChange SubExp -> VName -> BasicOp)
-> m (ShapeChange SubExp) -> m (VName -> BasicOp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (DimChange SubExp -> m (DimChange SubExp))
-> ShapeChange SubExp -> m (ShapeChange SubExp)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ((SubExp -> m SubExp) -> DimChange SubExp -> m (DimChange SubExp)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv)) ShapeChange SubExp
shape
m (VName -> BasicOp) -> m VName -> m BasicOp
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mapper frep trep m -> VName -> m VName
forall frep trep (m :: * -> *).
Mapper frep trep m -> VName -> m VName
mapOnVName Mapper frep trep m
tv VName
arrexp
)
mapExpM Mapper frep trep m
tv (BasicOp (Rearrange [Int]
perm VName
e)) =
BasicOp -> Exp trep
forall rep. BasicOp -> ExpT rep
BasicOp (BasicOp -> Exp trep) -> m BasicOp -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([Int] -> VName -> BasicOp
Rearrange [Int]
perm (VName -> BasicOp) -> m VName -> m BasicOp
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> VName -> m VName
forall frep trep (m :: * -> *).
Mapper frep trep m -> VName -> m VName
mapOnVName Mapper frep trep m
tv VName
e)
mapExpM Mapper frep trep m
tv (BasicOp (Rotate [SubExp]
es VName
e)) =
BasicOp -> Exp trep
forall rep. BasicOp -> ExpT rep
BasicOp (BasicOp -> Exp trep) -> m BasicOp -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([SubExp] -> VName -> BasicOp
Rotate ([SubExp] -> VName -> BasicOp)
-> m [SubExp] -> m (VName -> BasicOp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (SubExp -> m SubExp) -> [SubExp] -> m [SubExp]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv) [SubExp]
es m (VName -> BasicOp) -> m VName -> m BasicOp
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mapper frep trep m -> VName -> m VName
forall frep trep (m :: * -> *).
Mapper frep trep m -> VName -> m VName
mapOnVName Mapper frep trep m
tv VName
e)
mapExpM Mapper frep trep m
tv (BasicOp (Concat Int
i VName
x [VName]
ys SubExp
size)) =
BasicOp -> Exp trep
forall rep. BasicOp -> ExpT rep
BasicOp
(BasicOp -> Exp trep) -> m BasicOp -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ( Int -> VName -> [VName] -> SubExp -> BasicOp
Concat Int
i
(VName -> [VName] -> SubExp -> BasicOp)
-> m VName -> m ([VName] -> SubExp -> BasicOp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> VName -> m VName
forall frep trep (m :: * -> *).
Mapper frep trep m -> VName -> m VName
mapOnVName Mapper frep trep m
tv VName
x
m ([VName] -> SubExp -> BasicOp)
-> m [VName] -> m (SubExp -> BasicOp)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (VName -> m VName) -> [VName] -> m [VName]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Mapper frep trep m -> VName -> m VName
forall frep trep (m :: * -> *).
Mapper frep trep m -> VName -> m VName
mapOnVName Mapper frep trep m
tv) [VName]
ys
m (SubExp -> BasicOp) -> m SubExp -> m BasicOp
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv SubExp
size
)
mapExpM Mapper frep trep m
tv (BasicOp (Copy VName
e)) =
BasicOp -> Exp trep
forall rep. BasicOp -> ExpT rep
BasicOp (BasicOp -> Exp trep) -> m BasicOp -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (VName -> BasicOp
Copy (VName -> BasicOp) -> m VName -> m BasicOp
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> VName -> m VName
forall frep trep (m :: * -> *).
Mapper frep trep m -> VName -> m VName
mapOnVName Mapper frep trep m
tv VName
e)
mapExpM Mapper frep trep m
tv (BasicOp (Manifest [Int]
perm VName
e)) =
BasicOp -> Exp trep
forall rep. BasicOp -> ExpT rep
BasicOp (BasicOp -> Exp trep) -> m BasicOp -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([Int] -> VName -> BasicOp
Manifest [Int]
perm (VName -> BasicOp) -> m VName -> m BasicOp
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> VName -> m VName
forall frep trep (m :: * -> *).
Mapper frep trep m -> VName -> m VName
mapOnVName Mapper frep trep m
tv VName
e)
mapExpM Mapper frep trep m
tv (BasicOp (Assert SubExp
e ErrorMsg SubExp
msg (SrcLoc, [SrcLoc])
loc)) =
BasicOp -> Exp trep
forall rep. BasicOp -> ExpT rep
BasicOp (BasicOp -> Exp trep) -> m BasicOp -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (SubExp -> ErrorMsg SubExp -> (SrcLoc, [SrcLoc]) -> BasicOp
Assert (SubExp -> ErrorMsg SubExp -> (SrcLoc, [SrcLoc]) -> BasicOp)
-> m SubExp -> m (ErrorMsg SubExp -> (SrcLoc, [SrcLoc]) -> BasicOp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv SubExp
e m (ErrorMsg SubExp -> (SrcLoc, [SrcLoc]) -> BasicOp)
-> m (ErrorMsg SubExp) -> m ((SrcLoc, [SrcLoc]) -> BasicOp)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (SubExp -> m SubExp) -> ErrorMsg SubExp -> m (ErrorMsg SubExp)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv) ErrorMsg SubExp
msg m ((SrcLoc, [SrcLoc]) -> BasicOp)
-> m (SrcLoc, [SrcLoc]) -> m BasicOp
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (SrcLoc, [SrcLoc]) -> m (SrcLoc, [SrcLoc])
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SrcLoc, [SrcLoc])
loc)
mapExpM Mapper frep trep m
tv (BasicOp (Opaque OpaqueOp
op SubExp
e)) =
BasicOp -> Exp trep
forall rep. BasicOp -> ExpT rep
BasicOp (BasicOp -> Exp trep) -> m BasicOp -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (OpaqueOp -> SubExp -> BasicOp
Opaque OpaqueOp
op (SubExp -> BasicOp) -> m SubExp -> m BasicOp
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv SubExp
e)
mapExpM Mapper frep trep m
tv (BasicOp (UpdateAcc VName
v [SubExp]
is [SubExp]
ses)) =
BasicOp -> Exp trep
forall rep. BasicOp -> ExpT rep
BasicOp
(BasicOp -> Exp trep) -> m BasicOp -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ( VName -> [SubExp] -> [SubExp] -> BasicOp
UpdateAcc
(VName -> [SubExp] -> [SubExp] -> BasicOp)
-> m VName -> m ([SubExp] -> [SubExp] -> BasicOp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> VName -> m VName
forall frep trep (m :: * -> *).
Mapper frep trep m -> VName -> m VName
mapOnVName Mapper frep trep m
tv VName
v
m ([SubExp] -> [SubExp] -> BasicOp)
-> m [SubExp] -> m ([SubExp] -> BasicOp)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (SubExp -> m SubExp) -> [SubExp] -> m [SubExp]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv) [SubExp]
is
m ([SubExp] -> BasicOp) -> m [SubExp] -> m BasicOp
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (SubExp -> m SubExp) -> [SubExp] -> m [SubExp]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv) [SubExp]
ses
)
mapExpM Mapper frep trep m
tv (WithAcc [(Shape, [VName], Maybe (Lambda frep, [SubExp]))]
inputs Lambda frep
lam) =
[(Shape, [VName], Maybe (Lambda trep, [SubExp]))]
-> Lambda trep -> Exp trep
forall rep.
[(Shape, [VName], Maybe (Lambda rep, [SubExp]))]
-> Lambda rep -> ExpT rep
WithAcc ([(Shape, [VName], Maybe (Lambda trep, [SubExp]))]
-> Lambda trep -> Exp trep)
-> m [(Shape, [VName], Maybe (Lambda trep, [SubExp]))]
-> m (Lambda trep -> Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Shape, [VName], Maybe (Lambda frep, [SubExp]))
-> m (Shape, [VName], Maybe (Lambda trep, [SubExp])))
-> [(Shape, [VName], Maybe (Lambda frep, [SubExp]))]
-> m [(Shape, [VName], Maybe (Lambda trep, [SubExp]))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Shape, [VName], Maybe (Lambda frep, [SubExp]))
-> m (Shape, [VName], Maybe (Lambda trep, [SubExp]))
forall (t :: * -> * -> *) (t :: * -> *) (t :: * -> *)
(t :: * -> *).
(Bitraversable t, Traversable t, Traversable t, Traversable t) =>
(Shape, t VName, t (t (Lambda frep) (t SubExp)))
-> m (Shape, t VName, t (t (Lambda trep) (t SubExp)))
onInput [(Shape, [VName], Maybe (Lambda frep, [SubExp]))]
inputs m (Lambda trep -> Exp trep) -> m (Lambda trep) -> m (Exp trep)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mapper frep trep m -> Lambda frep -> m (Lambda trep)
forall (m :: * -> *) frep trep.
Monad m =>
Mapper frep trep m -> Lambda frep -> m (Lambda trep)
mapOnLambda Mapper frep trep m
tv Lambda frep
lam
where
onInput :: (Shape, t VName, t (t (Lambda frep) (t SubExp)))
-> m (Shape, t VName, t (t (Lambda trep) (t SubExp)))
onInput (Shape
shape, t VName
vs, t (t (Lambda frep) (t SubExp))
op) =
(,,) (Shape
-> t VName
-> t (t (Lambda trep) (t SubExp))
-> (Shape, t VName, t (t (Lambda trep) (t SubExp))))
-> m Shape
-> m (t VName
-> t (t (Lambda trep) (t SubExp))
-> (Shape, t VName, t (t (Lambda trep) (t SubExp))))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> Shape -> m Shape
forall (m :: * -> *) frep trep.
Monad m =>
Mapper frep trep m -> Shape -> m Shape
mapOnShape Mapper frep trep m
tv Shape
shape m (t VName
-> t (t (Lambda trep) (t SubExp))
-> (Shape, t VName, t (t (Lambda trep) (t SubExp))))
-> m (t VName)
-> m (t (t (Lambda trep) (t SubExp))
-> (Shape, t VName, t (t (Lambda trep) (t SubExp))))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (VName -> m VName) -> t VName -> m (t VName)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Mapper frep trep m -> VName -> m VName
forall frep trep (m :: * -> *).
Mapper frep trep m -> VName -> m VName
mapOnVName Mapper frep trep m
tv) t VName
vs
m (t (t (Lambda trep) (t SubExp))
-> (Shape, t VName, t (t (Lambda trep) (t SubExp))))
-> m (t (t (Lambda trep) (t SubExp)))
-> m (Shape, t VName, t (t (Lambda trep) (t SubExp)))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (t (Lambda frep) (t SubExp) -> m (t (Lambda trep) (t SubExp)))
-> t (t (Lambda frep) (t SubExp))
-> m (t (t (Lambda trep) (t SubExp)))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Lambda frep -> m (Lambda trep))
-> (t SubExp -> m (t SubExp))
-> t (Lambda frep) (t SubExp)
-> m (t (Lambda trep) (t SubExp))
forall (t :: * -> * -> *) (f :: * -> *) a c b d.
(Bitraversable t, Applicative f) =>
(a -> f c) -> (b -> f d) -> t a b -> f (t c d)
bitraverse (Mapper frep trep m -> Lambda frep -> m (Lambda trep)
forall (m :: * -> *) frep trep.
Monad m =>
Mapper frep trep m -> Lambda frep -> m (Lambda trep)
mapOnLambda Mapper frep trep m
tv) ((SubExp -> m SubExp) -> t SubExp -> m (t SubExp)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv))) t (t (Lambda frep) (t SubExp))
op
mapExpM Mapper frep trep m
tv (DoLoop [(FParam frep, SubExp)]
merge LoopForm frep
form BodyT frep
loopbody) = do
[Param (FParamInfo trep)]
params' <- (FParam frep -> m (Param (FParamInfo trep)))
-> [FParam frep] -> m [Param (FParamInfo trep)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Mapper frep trep m -> FParam frep -> m (Param (FParamInfo trep))
forall frep trep (m :: * -> *).
Mapper frep trep m -> FParam frep -> m (FParam trep)
mapOnFParam Mapper frep trep m
tv) [FParam frep]
params
LoopForm trep
form' <- Mapper frep trep m -> LoopForm frep -> m (LoopForm trep)
forall (m :: * -> *) frep trep.
Monad m =>
Mapper frep trep m -> LoopForm frep -> m (LoopForm trep)
mapOnLoopForm Mapper frep trep m
tv LoopForm frep
form
let scope :: Scope trep
scope = LoopForm trep -> Scope trep
forall rep a. Scoped rep a => a -> Scope rep
scopeOf LoopForm trep
form' Scope trep -> Scope trep -> Scope trep
forall a. Semigroup a => a -> a -> a
<> [Param (FParamInfo trep)] -> Scope trep
forall rep dec. (FParamInfo rep ~ dec) => [Param dec] -> Scope rep
scopeOfFParams [Param (FParamInfo trep)]
params'
[(Param (FParamInfo trep), SubExp)]
-> LoopForm trep -> BodyT trep -> Exp trep
forall rep.
[(FParam rep, SubExp)] -> LoopForm rep -> BodyT rep -> ExpT rep
DoLoop
([(Param (FParamInfo trep), SubExp)]
-> LoopForm trep -> BodyT trep -> Exp trep)
-> m [(Param (FParamInfo trep), SubExp)]
-> m (LoopForm trep -> BodyT trep -> Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([Param (FParamInfo trep)]
-> [SubExp] -> [(Param (FParamInfo trep), SubExp)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Param (FParamInfo trep)]
params' ([SubExp] -> [(Param (FParamInfo trep), SubExp)])
-> m [SubExp] -> m [(Param (FParamInfo trep), SubExp)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (SubExp -> m SubExp) -> [SubExp] -> m [SubExp]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv) [SubExp]
args)
m (LoopForm trep -> BodyT trep -> Exp trep)
-> m (LoopForm trep) -> m (BodyT trep -> Exp trep)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> LoopForm trep -> m (LoopForm trep)
forall (f :: * -> *) a. Applicative f => a -> f a
pure LoopForm trep
form'
m (BodyT trep -> Exp trep) -> m (BodyT trep) -> m (Exp trep)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mapper frep trep m -> Scope trep -> BodyT frep -> m (BodyT trep)
forall frep trep (m :: * -> *).
Mapper frep trep m -> Scope trep -> Body frep -> m (Body trep)
mapOnBody Mapper frep trep m
tv Scope trep
scope BodyT frep
loopbody
where
([FParam frep]
params, [SubExp]
args) = [(FParam frep, SubExp)] -> ([FParam frep], [SubExp])
forall a b. [(a, b)] -> ([a], [b])
unzip [(FParam frep, SubExp)]
merge
mapExpM Mapper frep trep m
tv (Op Op frep
op) =
Op trep -> Exp trep
forall rep. Op rep -> ExpT rep
Op (Op trep -> Exp trep) -> m (Op trep) -> m (Exp trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> Op frep -> m (Op trep)
forall frep trep (m :: * -> *).
Mapper frep trep m -> Op frep -> m (Op trep)
mapOnOp Mapper frep trep m
tv Op frep
op
mapOnShape :: Monad m => Mapper frep trep m -> Shape -> m Shape
mapOnShape :: Mapper frep trep m -> Shape -> m Shape
mapOnShape Mapper frep trep m
tv (Shape [SubExp]
ds) = [SubExp] -> Shape
forall d. [d] -> ShapeBase d
Shape ([SubExp] -> Shape) -> m [SubExp] -> m Shape
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (SubExp -> m SubExp) -> [SubExp] -> m [SubExp]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv) [SubExp]
ds
mapOnLoopForm ::
Monad m =>
Mapper frep trep m ->
LoopForm frep ->
m (LoopForm trep)
mapOnLoopForm :: Mapper frep trep m -> LoopForm frep -> m (LoopForm trep)
mapOnLoopForm Mapper frep trep m
tv (ForLoop VName
i IntType
it SubExp
bound [(LParam frep, VName)]
loop_vars) =
VName
-> IntType -> SubExp -> [(LParam trep, VName)] -> LoopForm trep
forall rep.
VName -> IntType -> SubExp -> [(LParam rep, VName)] -> LoopForm rep
ForLoop (VName
-> IntType -> SubExp -> [(LParam trep, VName)] -> LoopForm trep)
-> m VName
-> m (IntType -> SubExp -> [(LParam trep, VName)] -> LoopForm trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> VName -> m VName
forall frep trep (m :: * -> *).
Mapper frep trep m -> VName -> m VName
mapOnVName Mapper frep trep m
tv VName
i m (IntType -> SubExp -> [(LParam trep, VName)] -> LoopForm trep)
-> m IntType
-> m (SubExp -> [(LParam trep, VName)] -> LoopForm trep)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IntType -> m IntType
forall (f :: * -> *) a. Applicative f => a -> f a
pure IntType
it m (SubExp -> [(LParam trep, VName)] -> LoopForm trep)
-> m SubExp -> m ([(LParam trep, VName)] -> LoopForm trep)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv SubExp
bound
m ([(LParam trep, VName)] -> LoopForm trep)
-> m [(LParam trep, VName)] -> m (LoopForm trep)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ([LParam trep] -> [VName] -> [(LParam trep, VName)]
forall a b. [a] -> [b] -> [(a, b)]
zip ([LParam trep] -> [VName] -> [(LParam trep, VName)])
-> m [LParam trep] -> m ([VName] -> [(LParam trep, VName)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (LParam frep -> m (LParam trep))
-> [LParam frep] -> m [LParam trep]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Mapper frep trep m -> LParam frep -> m (LParam trep)
forall frep trep (m :: * -> *).
Mapper frep trep m -> LParam frep -> m (LParam trep)
mapOnLParam Mapper frep trep m
tv) [LParam frep]
loop_lparams m ([VName] -> [(LParam trep, VName)])
-> m [VName] -> m [(LParam trep, VName)]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (VName -> m VName) -> [VName] -> m [VName]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Mapper frep trep m -> VName -> m VName
forall frep trep (m :: * -> *).
Mapper frep trep m -> VName -> m VName
mapOnVName Mapper frep trep m
tv) [VName]
loop_arrs)
where
([LParam frep]
loop_lparams, [VName]
loop_arrs) = [(LParam frep, VName)] -> ([LParam frep], [VName])
forall a b. [(a, b)] -> ([a], [b])
unzip [(LParam frep, VName)]
loop_vars
mapOnLoopForm Mapper frep trep m
tv (WhileLoop VName
cond) =
VName -> LoopForm trep
forall rep. VName -> LoopForm rep
WhileLoop (VName -> LoopForm trep) -> m VName -> m (LoopForm trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> VName -> m VName
forall frep trep (m :: * -> *).
Mapper frep trep m -> VName -> m VName
mapOnVName Mapper frep trep m
tv VName
cond
mapOnLambda ::
Monad m =>
Mapper frep trep m ->
Lambda frep ->
m (Lambda trep)
mapOnLambda :: Mapper frep trep m -> Lambda frep -> m (Lambda trep)
mapOnLambda Mapper frep trep m
tv (Lambda [LParam frep]
params BodyT frep
body [Type]
ret) = do
[Param (LParamInfo trep)]
params' <- (LParam frep -> m (Param (LParamInfo trep)))
-> [LParam frep] -> m [Param (LParamInfo trep)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Mapper frep trep m -> LParam frep -> m (Param (LParamInfo trep))
forall frep trep (m :: * -> *).
Mapper frep trep m -> LParam frep -> m (LParam trep)
mapOnLParam Mapper frep trep m
tv) [LParam frep]
params
[Param (LParamInfo trep)] -> BodyT trep -> [Type] -> Lambda trep
forall rep. [LParam rep] -> BodyT rep -> [Type] -> LambdaT rep
Lambda [Param (LParamInfo trep)]
params'
(BodyT trep -> [Type] -> Lambda trep)
-> m (BodyT trep) -> m ([Type] -> Lambda trep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mapper frep trep m -> Scope trep -> BodyT frep -> m (BodyT trep)
forall frep trep (m :: * -> *).
Mapper frep trep m -> Scope trep -> Body frep -> m (Body trep)
mapOnBody Mapper frep trep m
tv ([Param (LParamInfo trep)] -> Scope trep
forall rep dec. (LParamInfo rep ~ dec) => [Param dec] -> Scope rep
scopeOfLParams [Param (LParamInfo trep)]
params') BodyT frep
body
m ([Type] -> Lambda trep) -> m [Type] -> m (Lambda trep)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Type -> m Type) -> [Type] -> m [Type]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ((SubExp -> m SubExp) -> Type -> m Type
forall (m :: * -> *) u.
Monad m =>
(SubExp -> m SubExp) -> TypeBase Shape u -> m (TypeBase Shape u)
mapOnType (Mapper frep trep m -> SubExp -> m SubExp
forall frep trep (m :: * -> *).
Mapper frep trep m -> SubExp -> m SubExp
mapOnSubExp Mapper frep trep m
tv)) [Type]
ret
mapExp :: Mapper frep trep Identity -> Exp frep -> Exp trep
mapExp :: Mapper frep trep Identity -> Exp frep -> Exp trep
mapExp Mapper frep trep Identity
m = Identity (Exp trep) -> Exp trep
forall a. Identity a -> a
runIdentity (Identity (Exp trep) -> Exp trep)
-> (Exp frep -> Identity (Exp trep)) -> Exp frep -> Exp trep
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Mapper frep trep Identity -> Exp frep -> Identity (Exp trep)
forall (m :: * -> *) frep trep.
(Applicative m, Monad m) =>
Mapper frep trep m -> Exp frep -> m (Exp trep)
mapExpM Mapper frep trep Identity
m
data Walker rep m = Walker
{ Walker rep m -> SubExp -> m ()
walkOnSubExp :: SubExp -> m (),
Walker rep m -> Scope rep -> Body rep -> m ()
walkOnBody :: Scope rep -> Body rep -> m (),
Walker rep m -> VName -> m ()
walkOnVName :: VName -> m (),
Walker rep m -> RetType rep -> m ()
walkOnRetType :: RetType rep -> m (),
Walker rep m -> BranchType rep -> m ()
walkOnBranchType :: BranchType rep -> m (),
Walker rep m -> FParam rep -> m ()
walkOnFParam :: FParam rep -> m (),
Walker rep m -> LParam rep -> m ()
walkOnLParam :: LParam rep -> m (),
Walker rep m -> Op rep -> m ()
walkOnOp :: Op rep -> m ()
}
identityWalker :: Monad m => Walker rep m
identityWalker :: Walker rep m
identityWalker =
Walker :: forall rep (m :: * -> *).
(SubExp -> m ())
-> (Scope rep -> Body rep -> m ())
-> (VName -> m ())
-> (RetType rep -> m ())
-> (BranchType rep -> m ())
-> (FParam rep -> m ())
-> (LParam rep -> m ())
-> (Op rep -> m ())
-> Walker rep m
Walker
{ walkOnSubExp :: SubExp -> m ()
walkOnSubExp = m () -> SubExp -> m ()
forall a b. a -> b -> a
const (m () -> SubExp -> m ()) -> m () -> SubExp -> m ()
forall a b. (a -> b) -> a -> b
$ () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return (),
walkOnBody :: Scope rep -> Body rep -> m ()
walkOnBody = (Body rep -> m ()) -> Scope rep -> Body rep -> m ()
forall a b. a -> b -> a
const ((Body rep -> m ()) -> Scope rep -> Body rep -> m ())
-> (Body rep -> m ()) -> Scope rep -> Body rep -> m ()
forall a b. (a -> b) -> a -> b
$ m () -> Body rep -> m ()
forall a b. a -> b -> a
const (m () -> Body rep -> m ()) -> m () -> Body rep -> m ()
forall a b. (a -> b) -> a -> b
$ () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return (),
walkOnVName :: VName -> m ()
walkOnVName = m () -> VName -> m ()
forall a b. a -> b -> a
const (m () -> VName -> m ()) -> m () -> VName -> m ()
forall a b. (a -> b) -> a -> b
$ () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return (),
walkOnRetType :: RetType rep -> m ()
walkOnRetType = m () -> RetType rep -> m ()
forall a b. a -> b -> a
const (m () -> RetType rep -> m ()) -> m () -> RetType rep -> m ()
forall a b. (a -> b) -> a -> b
$ () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return (),
walkOnBranchType :: BranchType rep -> m ()
walkOnBranchType = m () -> BranchType rep -> m ()
forall a b. a -> b -> a
const (m () -> BranchType rep -> m ()) -> m () -> BranchType rep -> m ()
forall a b. (a -> b) -> a -> b
$ () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return (),
walkOnFParam :: FParam rep -> m ()
walkOnFParam = m () -> FParam rep -> m ()
forall a b. a -> b -> a
const (m () -> FParam rep -> m ()) -> m () -> FParam rep -> m ()
forall a b. (a -> b) -> a -> b
$ () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return (),
walkOnLParam :: LParam rep -> m ()
walkOnLParam = m () -> LParam rep -> m ()
forall a b. a -> b -> a
const (m () -> LParam rep -> m ()) -> m () -> LParam rep -> m ()
forall a b. (a -> b) -> a -> b
$ () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return (),
walkOnOp :: Op rep -> m ()
walkOnOp = m () -> Op rep -> m ()
forall a b. a -> b -> a
const (m () -> Op rep -> m ()) -> m () -> Op rep -> m ()
forall a b. (a -> b) -> a -> b
$ () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
}
walkOnShape :: Monad m => Walker rep m -> Shape -> m ()
walkOnShape :: Walker rep m -> Shape -> m ()
walkOnShape Walker rep m
tv (Shape [SubExp]
ds) = (SubExp -> m ()) -> [SubExp] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv) [SubExp]
ds
walkOnType :: Monad m => Walker rep m -> Type -> m ()
walkOnType :: Walker rep m -> Type -> m ()
walkOnType Walker rep m
_ Prim {} = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
walkOnType Walker rep m
tv (Acc VName
acc Shape
ispace [Type]
ts NoUniqueness
_) = do
Walker rep m -> VName -> m ()
forall rep (m :: * -> *). Walker rep m -> VName -> m ()
walkOnVName Walker rep m
tv VName
acc
(SubExp -> m ()) -> Shape -> m ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ (Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv) Shape
ispace
(Type -> m ()) -> [Type] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Walker rep m -> Type -> m ()
forall (m :: * -> *) rep. Monad m => Walker rep m -> Type -> m ()
walkOnType Walker rep m
tv) [Type]
ts
walkOnType Walker rep m
_ Mem {} = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
walkOnType Walker rep m
tv (Array PrimType
_ Shape
shape NoUniqueness
_) = Walker rep m -> Shape -> m ()
forall (m :: * -> *) rep. Monad m => Walker rep m -> Shape -> m ()
walkOnShape Walker rep m
tv Shape
shape
walkOnLoopForm :: Monad m => Walker rep m -> LoopForm rep -> m ()
walkOnLoopForm :: Walker rep m -> LoopForm rep -> m ()
walkOnLoopForm Walker rep m
tv (ForLoop VName
i IntType
_ SubExp
bound [(LParam rep, VName)]
loop_vars) =
Walker rep m -> VName -> m ()
forall rep (m :: * -> *). Walker rep m -> VName -> m ()
walkOnVName Walker rep m
tv VName
i m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv SubExp
bound
m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (LParam rep -> m ()) -> [LParam rep] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Walker rep m -> LParam rep -> m ()
forall rep (m :: * -> *). Walker rep m -> LParam rep -> m ()
walkOnLParam Walker rep m
tv) [LParam rep]
loop_lparams
m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (VName -> m ()) -> [VName] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Walker rep m -> VName -> m ()
forall rep (m :: * -> *). Walker rep m -> VName -> m ()
walkOnVName Walker rep m
tv) [VName]
loop_arrs
where
([LParam rep]
loop_lparams, [VName]
loop_arrs) = [(LParam rep, VName)] -> ([LParam rep], [VName])
forall a b. [(a, b)] -> ([a], [b])
unzip [(LParam rep, VName)]
loop_vars
walkOnLoopForm Walker rep m
tv (WhileLoop VName
cond) =
Walker rep m -> VName -> m ()
forall rep (m :: * -> *). Walker rep m -> VName -> m ()
walkOnVName Walker rep m
tv VName
cond
walkOnLambda :: Monad m => Walker rep m -> Lambda rep -> m ()
walkOnLambda :: Walker rep m -> Lambda rep -> m ()
walkOnLambda Walker rep m
tv (Lambda [LParam rep]
params BodyT rep
body [Type]
ret) = do
(LParam rep -> m ()) -> [LParam rep] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Walker rep m -> LParam rep -> m ()
forall rep (m :: * -> *). Walker rep m -> LParam rep -> m ()
walkOnLParam Walker rep m
tv) [LParam rep]
params
Walker rep m -> Scope rep -> BodyT rep -> m ()
forall rep (m :: * -> *).
Walker rep m -> Scope rep -> Body rep -> m ()
walkOnBody Walker rep m
tv ([LParam rep] -> Scope rep
forall rep dec. (LParamInfo rep ~ dec) => [Param dec] -> Scope rep
scopeOfLParams [LParam rep]
params) BodyT rep
body
(Type -> m ()) -> [Type] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Walker rep m -> Type -> m ()
forall (m :: * -> *) rep. Monad m => Walker rep m -> Type -> m ()
walkOnType Walker rep m
tv) [Type]
ret
walkExpM :: Monad m => Walker rep m -> Exp rep -> m ()
walkExpM :: Walker rep m -> Exp rep -> m ()
walkExpM Walker rep m
tv (BasicOp (SubExp SubExp
se)) =
Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv SubExp
se
walkExpM Walker rep m
tv (BasicOp (ArrayLit [SubExp]
els Type
rowt)) =
(SubExp -> m ()) -> [SubExp] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv) [SubExp]
els m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Walker rep m -> Type -> m ()
forall (m :: * -> *) rep. Monad m => Walker rep m -> Type -> m ()
walkOnType Walker rep m
tv Type
rowt
walkExpM Walker rep m
tv (BasicOp (BinOp BinOp
_ SubExp
x SubExp
y)) =
Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv SubExp
x m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv SubExp
y
walkExpM Walker rep m
tv (BasicOp (CmpOp CmpOp
_ SubExp
x SubExp
y)) =
Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv SubExp
x m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv SubExp
y
walkExpM Walker rep m
tv (BasicOp (ConvOp ConvOp
_ SubExp
x)) =
Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv SubExp
x
walkExpM Walker rep m
tv (BasicOp (UnOp UnOp
_ SubExp
x)) =
Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv SubExp
x
walkExpM Walker rep m
tv (If SubExp
c BodyT rep
texp BodyT rep
fexp (IfDec [BranchType rep]
ts IfSort
_)) = do
Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv SubExp
c
Walker rep m -> Scope rep -> BodyT rep -> m ()
forall rep (m :: * -> *).
Walker rep m -> Scope rep -> Body rep -> m ()
walkOnBody Walker rep m
tv Scope rep
forall a. Monoid a => a
mempty BodyT rep
texp
Walker rep m -> Scope rep -> BodyT rep -> m ()
forall rep (m :: * -> *).
Walker rep m -> Scope rep -> Body rep -> m ()
walkOnBody Walker rep m
tv Scope rep
forall a. Monoid a => a
mempty BodyT rep
fexp
(BranchType rep -> m ()) -> [BranchType rep] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Walker rep m -> BranchType rep -> m ()
forall rep (m :: * -> *). Walker rep m -> BranchType rep -> m ()
walkOnBranchType Walker rep m
tv) [BranchType rep]
ts
walkExpM Walker rep m
tv (Apply Name
_ [(SubExp, Diet)]
args [RetType rep]
ret (Safety, SrcLoc, [SrcLoc])
_) =
((SubExp, Diet) -> m ()) -> [(SubExp, Diet)] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv (SubExp -> m ())
-> ((SubExp, Diet) -> SubExp) -> (SubExp, Diet) -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SubExp, Diet) -> SubExp
forall a b. (a, b) -> a
fst) [(SubExp, Diet)]
args m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (RetType rep -> m ()) -> [RetType rep] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Walker rep m -> RetType rep -> m ()
forall rep (m :: * -> *). Walker rep m -> RetType rep -> m ()
walkOnRetType Walker rep m
tv) [RetType rep]
ret
walkExpM Walker rep m
tv (BasicOp (Index VName
arr Slice SubExp
slice)) =
Walker rep m -> VName -> m ()
forall rep (m :: * -> *). Walker rep m -> VName -> m ()
walkOnVName Walker rep m
tv VName
arr m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (SubExp -> m ()) -> Slice SubExp -> m ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ (Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv) Slice SubExp
slice
walkExpM Walker rep m
tv (BasicOp (Update Safety
_ VName
arr Slice SubExp
slice SubExp
se)) =
Walker rep m -> VName -> m ()
forall rep (m :: * -> *). Walker rep m -> VName -> m ()
walkOnVName Walker rep m
tv VName
arr
m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (SubExp -> m ()) -> Slice SubExp -> m ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ (Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv) Slice SubExp
slice
m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv SubExp
se
walkExpM Walker rep m
tv (BasicOp (FlatIndex VName
arr FlatSlice SubExp
slice)) =
Walker rep m -> VName -> m ()
forall rep (m :: * -> *). Walker rep m -> VName -> m ()
walkOnVName Walker rep m
tv VName
arr m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (SubExp -> m ()) -> FlatSlice SubExp -> m ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ (Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv) FlatSlice SubExp
slice
walkExpM Walker rep m
tv (BasicOp (FlatUpdate VName
arr FlatSlice SubExp
slice VName
se)) =
Walker rep m -> VName -> m ()
forall rep (m :: * -> *). Walker rep m -> VName -> m ()
walkOnVName Walker rep m
tv VName
arr
m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (SubExp -> m ()) -> FlatSlice SubExp -> m ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ (Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv) FlatSlice SubExp
slice
m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Walker rep m -> VName -> m ()
forall rep (m :: * -> *). Walker rep m -> VName -> m ()
walkOnVName Walker rep m
tv VName
se
walkExpM Walker rep m
tv (BasicOp (Iota SubExp
n SubExp
x SubExp
s IntType
_)) =
Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv SubExp
n m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv SubExp
x m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv SubExp
s
walkExpM Walker rep m
tv (BasicOp (Replicate Shape
shape SubExp
vexp)) =
Walker rep m -> Shape -> m ()
forall (m :: * -> *) rep. Monad m => Walker rep m -> Shape -> m ()
walkOnShape Walker rep m
tv Shape
shape m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv SubExp
vexp
walkExpM Walker rep m
tv (BasicOp (Scratch PrimType
_ [SubExp]
shape)) =
(SubExp -> m ()) -> [SubExp] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv) [SubExp]
shape
walkExpM Walker rep m
tv (BasicOp (Reshape ShapeChange SubExp
shape VName
arrexp)) =
(DimChange SubExp -> m ()) -> ShapeChange SubExp -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ ((SubExp -> m ()) -> DimChange SubExp -> m ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ (Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv)) ShapeChange SubExp
shape m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Walker rep m -> VName -> m ()
forall rep (m :: * -> *). Walker rep m -> VName -> m ()
walkOnVName Walker rep m
tv VName
arrexp
walkExpM Walker rep m
tv (BasicOp (Rearrange [Int]
_ VName
e)) =
Walker rep m -> VName -> m ()
forall rep (m :: * -> *). Walker rep m -> VName -> m ()
walkOnVName Walker rep m
tv VName
e
walkExpM Walker rep m
tv (BasicOp (Rotate [SubExp]
es VName
e)) =
(SubExp -> m ()) -> [SubExp] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv) [SubExp]
es m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Walker rep m -> VName -> m ()
forall rep (m :: * -> *). Walker rep m -> VName -> m ()
walkOnVName Walker rep m
tv VName
e
walkExpM Walker rep m
tv (BasicOp (Concat Int
_ VName
x [VName]
ys SubExp
size)) =
Walker rep m -> VName -> m ()
forall rep (m :: * -> *). Walker rep m -> VName -> m ()
walkOnVName Walker rep m
tv VName
x m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (VName -> m ()) -> [VName] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Walker rep m -> VName -> m ()
forall rep (m :: * -> *). Walker rep m -> VName -> m ()
walkOnVName Walker rep m
tv) [VName]
ys m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv SubExp
size
walkExpM Walker rep m
tv (BasicOp (Copy VName
e)) =
Walker rep m -> VName -> m ()
forall rep (m :: * -> *). Walker rep m -> VName -> m ()
walkOnVName Walker rep m
tv VName
e
walkExpM Walker rep m
tv (BasicOp (Manifest [Int]
_ VName
e)) =
Walker rep m -> VName -> m ()
forall rep (m :: * -> *). Walker rep m -> VName -> m ()
walkOnVName Walker rep m
tv VName
e
walkExpM Walker rep m
tv (BasicOp (Assert SubExp
e ErrorMsg SubExp
msg (SrcLoc, [SrcLoc])
_)) =
Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv SubExp
e m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (SubExp -> m ()) -> ErrorMsg SubExp -> m ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ (Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv) ErrorMsg SubExp
msg
walkExpM Walker rep m
tv (BasicOp (Opaque OpaqueOp
_ SubExp
e)) =
Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv SubExp
e
walkExpM Walker rep m
tv (BasicOp (UpdateAcc VName
v [SubExp]
is [SubExp]
ses)) = do
Walker rep m -> VName -> m ()
forall rep (m :: * -> *). Walker rep m -> VName -> m ()
walkOnVName Walker rep m
tv VName
v
(SubExp -> m ()) -> [SubExp] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv) [SubExp]
is
(SubExp -> m ()) -> [SubExp] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv) [SubExp]
ses
walkExpM Walker rep m
tv (WithAcc [(Shape, [VName], Maybe (Lambda rep, [SubExp]))]
inputs Lambda rep
lam) = do
[(Shape, [VName], Maybe (Lambda rep, [SubExp]))]
-> ((Shape, [VName], Maybe (Lambda rep, [SubExp])) -> m ()) -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [(Shape, [VName], Maybe (Lambda rep, [SubExp]))]
inputs (((Shape, [VName], Maybe (Lambda rep, [SubExp])) -> m ()) -> m ())
-> ((Shape, [VName], Maybe (Lambda rep, [SubExp])) -> m ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \(Shape
shape, [VName]
vs, Maybe (Lambda rep, [SubExp])
op) -> do
Walker rep m -> Shape -> m ()
forall (m :: * -> *) rep. Monad m => Walker rep m -> Shape -> m ()
walkOnShape Walker rep m
tv Shape
shape
(VName -> m ()) -> [VName] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Walker rep m -> VName -> m ()
forall rep (m :: * -> *). Walker rep m -> VName -> m ()
walkOnVName Walker rep m
tv) [VName]
vs
((Lambda rep, [SubExp]) -> m ((), [()]))
-> Maybe (Lambda rep, [SubExp]) -> m ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ ((Lambda rep -> m ())
-> ([SubExp] -> m [()]) -> (Lambda rep, [SubExp]) -> m ((), [()])
forall (t :: * -> * -> *) (f :: * -> *) a c b d.
(Bitraversable t, Applicative f) =>
(a -> f c) -> (b -> f d) -> t a b -> f (t c d)
bitraverse (Walker rep m -> Lambda rep -> m ()
forall (m :: * -> *) rep.
Monad m =>
Walker rep m -> Lambda rep -> m ()
walkOnLambda Walker rep m
tv) ((SubExp -> m ()) -> [SubExp] -> m [()]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv))) Maybe (Lambda rep, [SubExp])
op
Walker rep m -> Lambda rep -> m ()
forall (m :: * -> *) rep.
Monad m =>
Walker rep m -> Lambda rep -> m ()
walkOnLambda Walker rep m
tv Lambda rep
lam
walkExpM Walker rep m
tv (DoLoop [(FParam rep, SubExp)]
merge LoopForm rep
form BodyT rep
loopbody) = do
(FParam rep -> m ()) -> [FParam rep] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Walker rep m -> FParam rep -> m ()
forall rep (m :: * -> *). Walker rep m -> FParam rep -> m ()
walkOnFParam Walker rep m
tv) [FParam rep]
params
Walker rep m -> LoopForm rep -> m ()
forall (m :: * -> *) rep.
Monad m =>
Walker rep m -> LoopForm rep -> m ()
walkOnLoopForm Walker rep m
tv LoopForm rep
form
(SubExp -> m ()) -> [SubExp] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Walker rep m -> SubExp -> m ()
forall rep (m :: * -> *). Walker rep m -> SubExp -> m ()
walkOnSubExp Walker rep m
tv) [SubExp]
args
let scope :: Scope rep
scope = [FParam rep] -> Scope rep
forall rep dec. (FParamInfo rep ~ dec) => [Param dec] -> Scope rep
scopeOfFParams [FParam rep]
params Scope rep -> Scope rep -> Scope rep
forall a. Semigroup a => a -> a -> a
<> LoopForm rep -> Scope rep
forall rep a. Scoped rep a => a -> Scope rep
scopeOf LoopForm rep
form
Walker rep m -> Scope rep -> BodyT rep -> m ()
forall rep (m :: * -> *).
Walker rep m -> Scope rep -> Body rep -> m ()
walkOnBody Walker rep m
tv Scope rep
scope BodyT rep
loopbody
where
([FParam rep]
params, [SubExp]
args) = [(FParam rep, SubExp)] -> ([FParam rep], [SubExp])
forall a b. [(a, b)] -> ([a], [b])
unzip [(FParam rep, SubExp)]
merge
walkExpM Walker rep m
tv (Op Op rep
op) =
Walker rep m -> Op rep -> m ()
forall rep (m :: * -> *). Walker rep m -> Op rep -> m ()
walkOnOp Walker rep m
tv Op rep
op